From b688d917cd5ec52b1d841ee2a349ba6bac422ec2 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Mon, 28 Jan 2019 12:34:33 -0800 Subject: [PATCH] Remove the rest of users of the old style fstab And deprecate one more old style function that is not used after this change. Test: boot, disable and enable verity Change-Id: Id509f479850120352b4ea4dc3b6c40f6e8e2e53e --- adb/daemon/remount_service.cpp | 18 +++++++++++------- adb/daemon/set_verity_enable_state_service.cpp | 14 ++++++-------- fastboot/device/flashing.cpp | 18 ++++++++++-------- fs_mgr/fs_mgr.cpp | 13 ------------- fs_mgr/include/fs_mgr.h | 1 - 5 files changed, 27 insertions(+), 37 deletions(-) diff --git a/adb/daemon/remount_service.cpp b/adb/daemon/remount_service.cpp index 3c9dd0413..b26c691ca 100644 --- a/adb/daemon/remount_service.cpp +++ b/adb/daemon/remount_service.cpp @@ -75,16 +75,20 @@ static std::string find_proc_mount(const char* dir) { // Returns the device used to mount a directory in the fstab. static std::string find_fstab_mount(const char* dir) { - std::unique_ptr fstab(fs_mgr_read_fstab_default(), - fs_mgr_free_fstab); - struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab.get(), dir); - if (!rec) { + Fstab fstab; + if (!ReadDefaultFstab(&fstab)) { return ""; } - if (fs_mgr_is_logical(rec)) { - fs_mgr_update_logical_partition(rec); + + auto entry = std::find_if(fstab.begin(), fstab.end(), + [&dir](const auto& entry) { return entry.mount_point == dir; }); + if (entry == fstab.end()) { + return ""; } - return rec->blk_device; + if (entry->fs_mgr_flags.logical) { + fs_mgr_update_logical_partition(&(*entry)); + } + return entry->blk_device; } // The proc entry for / is full of lies, so check fstab instead. diff --git a/adb/daemon/set_verity_enable_state_service.cpp b/adb/daemon/set_verity_enable_state_service.cpp index 3676de538..f5c28c652 100644 --- a/adb/daemon/set_verity_enable_state_service.cpp +++ b/adb/daemon/set_verity_enable_state_service.cpp @@ -41,8 +41,6 @@ #include "fec/io.h" -struct fstab *fstab; - #ifdef ALLOW_ADBD_DISABLE_VERITY static const bool kAllowDisableVerity = true; #else @@ -213,18 +211,18 @@ void set_verity_enabled_state_service(unique_fd fd, bool enable) { // Not using AVB - assume VB1.0. // read all fstab entries at once from all sources - if (!fstab) fstab = fs_mgr_read_fstab_default(); - if (!fstab) { + Fstab fstab; + if (!ReadDefaultFstab(&fstab)) { WriteFdExactly(fd.get(), "Failed to read fstab\n"); suggest_run_adb_root(fd.get()); return; } // Loop through entries looking for ones that verity manages. - for (int i = 0; i < fstab->num_entries; i++) { - if (fs_mgr_is_verified(&fstab->recs[i])) { - if (set_verity_enabled_state(fd.get(), fstab->recs[i].blk_device, - fstab->recs[i].mount_point, enable)) { + for (const auto& entry : fstab) { + if (entry.fs_mgr_flags.verify) { + if (set_verity_enabled_state(fd.get(), entry.blk_device.c_str(), + entry.mount_point.c_str(), enable)) { any_changed = true; } } diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp index f737405c1..99854c99f 100644 --- a/fastboot/device/flashing.cpp +++ b/fastboot/device/flashing.cpp @@ -52,15 +52,17 @@ void WipeOverlayfsForPartition(FastbootDevice* device, const std::string& partit // Following appears to have a first time 2% impact on flashing speeds. // Convert partition_name to a validated mount point and wipe. - std::unique_ptr fstab(fs_mgr_read_fstab_default(), - fs_mgr_free_fstab); - for (auto i = 0; i < fstab->num_entries; i++) { - const auto mount_point = fstab->recs[i].mount_point; - if (!mount_point) continue; - auto partition = android::base::Basename(mount_point); - if ("/"s == mount_point) partition = "system"; + Fstab fstab; + ReadDefaultFstab(&fstab); + + for (const auto& entry : fstab) { + auto partition = android::base::Basename(entry.mount_point); + if ("/" == entry.mount_point) { + partition = "system"; + } + if ((partition + device->GetCurrentSlot()) == partition_name) { - fs_mgr_overlayfs_teardown(mount_point); + fs_mgr_overlayfs_teardown(entry.mount_point.c_str()); } } } diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index ded367839..26ce3b255 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -889,19 +889,6 @@ bool fs_mgr_update_logical_partition(FstabEntry* entry) { return true; } -bool fs_mgr_update_logical_partition(struct fstab_rec* rec) { - auto entry = FstabRecToFstabEntry(rec); - - if (!fs_mgr_update_logical_partition(&entry)) { - return false; - } - - free(rec->blk_device); - rec->blk_device = strdup(entry.blk_device.c_str()); - - return true; -} - class CheckpointManager { public: CheckpointManager(int needs_checkpoint = -1) : needs_checkpoint_(needs_checkpoint) {} diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index e87332f30..1685e5034 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -79,7 +79,6 @@ bool fs_mgr_update_verity_state( std::function callback); bool fs_mgr_swapon_all(const Fstab& fstab); bool fs_mgr_update_logical_partition(FstabEntry* entry); -bool fs_mgr_update_logical_partition(struct fstab_rec* rec); int fs_mgr_do_format(const FstabEntry& entry, bool reserve_footer); int fs_mgr_do_format(fstab_rec* rec, bool reserve_footer);