1 // 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 22 using std::string; 23 24 namespace chromeos_update_engine { 25 26 namespace { 27 28 // Open the appropriate fstab file and fallback to /fstab.device if 29 // that's what's being used. OpenFSTab()30static struct fstab* OpenFSTab() { 31 struct fstab* fstab = fs_mgr_read_fstab_default(); 32 if (fstab != nullptr) 33 return fstab; 34 35 fstab = fs_mgr_read_fstab("/fstab.device"); 36 return fstab; 37 } 38 39 } // namespace 40 41 namespace utils { 42 DeviceForMountPoint(const string & mount_point,base::FilePath * device)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 67