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