blob: 38d62eacda7df11c339ca28546acc7e34d13604e [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() {
Bowgo Tsaid998b822017-03-10 18:25:34 +080031 struct fstab* fstab = fs_mgr_read_fstab_default();
Alex Deymofb905d92016-06-03 19:26:58 -070032 if (fstab != nullptr)
33 return fstab;
34
Bowgo Tsaieb895c92017-03-29 15:59:25 +080035 fstab = fs_mgr_read_fstab("/fstab.device");
Alex Deymofb905d92016-06-03 19:26:58 -070036 return fstab;
37}
38
39} // namespace
40
41namespace utils {
42
43bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
44 struct fstab* fstab;
45 struct fstab_rec* record;
46
47 fstab = OpenFSTab();
48 if (fstab == nullptr) {
49 LOG(ERROR) << "Error opening fstab file.";
50 return false;
51 }
52 record = fs_mgr_get_entry_for_mount_point(fstab, mount_point.c_str());
53 if (record == nullptr) {
54 LOG(ERROR) << "Error finding " << mount_point << " entry in fstab file.";
55 fs_mgr_free_fstab(fstab);
56 return false;
57 }
58
59 *device = base::FilePath(record->blk_device);
60 fs_mgr_free_fstab(fstab);
61 return true;
62}
63
64} // namespace utils
65
66} // namespace chromeos_update_engine