blob: 393e65a067e0686c45d9b1326c4b3226d8dd6052 [file] [log] [blame]
Alex Deymofb905d92016-06-03 19:26:58 -07001//
2// Copyright (C) 2016 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include "update_engine/utils_android.h"
18
Alex Deymofb905d92016-06-03 19:26:58 -070019#include <fs_mgr.h>
20
21using std::string;
22
23namespace chromeos_update_engine {
24
25namespace {
26
27// Open the appropriate fstab file and fallback to /fstab.device if
28// that's what's being used.
29static struct fstab* OpenFSTab() {
Bowgo Tsaid998b822017-03-10 18:25:34 +080030 struct fstab* fstab = fs_mgr_read_fstab_default();
Alex Deymofb905d92016-06-03 19:26:58 -070031 if (fstab != nullptr)
32 return fstab;
33
Bowgo Tsaieb895c92017-03-29 15:59:25 +080034 fstab = fs_mgr_read_fstab("/fstab.device");
Alex Deymofb905d92016-06-03 19:26:58 -070035 return fstab;
36}
37
38} // namespace
39
40namespace utils {
41
42bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
43 struct fstab* fstab;
44 struct fstab_rec* record;
45
46 fstab = OpenFSTab();
47 if (fstab == nullptr) {
48 LOG(ERROR) << "Error opening fstab file.";
49 return false;
50 }
51 record = fs_mgr_get_entry_for_mount_point(fstab, mount_point.c_str());
52 if (record == nullptr) {
53 LOG(ERROR) << "Error finding " << mount_point << " entry in fstab file.";
54 fs_mgr_free_fstab(fstab);
55 return false;
56 }
57
58 *device = base::FilePath(record->blk_device);
59 fs_mgr_free_fstab(fstab);
60 return true;
61}
62
63} // namespace utils
64
65} // namespace chromeos_update_engine