blob: a4f1ea8486dee140e437b23d2ed19455550ac8f6 [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
19#include <cutils/properties.h>
20#include <fs_mgr.h>
21
22using std::string;
23
24namespace chromeos_update_engine {
25
26namespace {
27
28// Open the appropriate fstab file and fallback to /fstab.device if
29// that's what's being used.
30static struct fstab* OpenFSTab() {
31 char propbuf[PROPERTY_VALUE_MAX];
32 struct fstab* fstab;
33
34 property_get("ro.hardware", propbuf, "");
35 string fstab_name = string("/fstab.") + propbuf;
36 fstab = fs_mgr_read_fstab(fstab_name.c_str());
37 if (fstab != nullptr)
38 return fstab;
39
40 fstab = fs_mgr_read_fstab("/fstab.device");
41 return fstab;
42}
43
44} // namespace
45
46namespace utils {
47
48bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
49 struct fstab* fstab;
50 struct fstab_rec* record;
51
52 fstab = OpenFSTab();
53 if (fstab == nullptr) {
54 LOG(ERROR) << "Error opening fstab file.";
55 return false;
56 }
57 record = fs_mgr_get_entry_for_mount_point(fstab, mount_point.c_str());
58 if (record == nullptr) {
59 LOG(ERROR) << "Error finding " << mount_point << " entry in fstab file.";
60 fs_mgr_free_fstab(fstab);
61 return false;
62 }
63
64 *device = base::FilePath(record->blk_device);
65 fs_mgr_free_fstab(fstab);
66 return true;
67}
68
69} // namespace utils
70
71} // namespace chromeos_update_engine