| Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 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 |  | 
| Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 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. | 
|  | 29 | static struct fstab* OpenFSTab() { | 
| Bowgo Tsai | d998b82 | 2017-03-10 18:25:34 +0800 | [diff] [blame] | 30 | struct fstab* fstab = fs_mgr_read_fstab_default(); | 
| Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 31 | if (fstab != nullptr) | 
|  | 32 | return fstab; | 
|  | 33 |  | 
| Bowgo Tsai | eb895c9 | 2017-03-29 15:59:25 +0800 | [diff] [blame] | 34 | fstab = fs_mgr_read_fstab("/fstab.device"); | 
| Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 35 | return fstab; | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | }  // namespace | 
|  | 39 |  | 
|  | 40 | namespace utils { | 
|  | 41 |  | 
|  | 42 | bool 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 |