Merge "Use unique points for fstab" am: 1e1893812c am: 1c6d73bfcc

am: 704da32b50

Change-Id: I13c215dc504a3745402327aaead9d7f6d36bc695
gugelfrei
Paul Lawrence 6 years ago committed by android-build-merger
commit cba5a411d1

@ -19,6 +19,7 @@
#include <fstream> #include <fstream>
#include <list> #include <list>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -68,19 +69,19 @@ bool cp_commitChanges() {
// To do this, we walk the list of mounted file systems. // To do this, we walk the list of mounted file systems.
// But we also need to get the matching fstab entries to see // But we also need to get the matching fstab entries to see
// the original flags // the original flags
struct fstab* fstab = fs_mgr_read_fstab_default(); auto fstab_default = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
if (!fstab) return false; fs_mgr_read_fstab_default(), fs_mgr_free_fstab};
if (!fstab_default) return false;
struct fstab* mounts = fs_mgr_read_fstab("/proc/mounts"); auto mounts = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
if (mounts == NULL) { fs_mgr_read_fstab("/proc/mounts"), fs_mgr_free_fstab};
fs_mgr_free_fstab(fstab); if (!mounts) return false;
return false;
}
// Walk mounted file systems // Walk mounted file systems
for (int i = 0; i < mounts->num_entries; ++i) { for (int i = 0; i < mounts->num_entries; ++i) {
const fstab_rec* mount_rec = &mounts->recs[i]; const fstab_rec* mount_rec = &mounts->recs[i];
const fstab_rec* fstab_rec = fs_mgr_get_entry_for_mount_point(fstab, mount_rec->mount_point); const fstab_rec* fstab_rec =
fs_mgr_get_entry_for_mount_point(fstab_default.get(), mount_rec->mount_point);
if (!fstab_rec) continue; if (!fstab_rec) continue;
if (fs_mgr_is_checkpoint_fs(fstab_rec)) { if (fs_mgr_is_checkpoint_fs(fstab_rec)) {
@ -92,8 +93,6 @@ bool cp_commitChanges() {
setBowState(mount_rec->blk_device, "2"); setBowState(mount_rec->blk_device, "2");
} }
} }
fs_mgr_free_fstab(mounts);
fs_mgr_free_fstab(fstab);
return android::base::RemoveFileIfExists(kMetadataCPFile); return android::base::RemoveFileIfExists(kMetadataCPFile);
} }
@ -120,18 +119,18 @@ bool cp_needsCheckpoint(void) {
} }
bool cp_prepareDriveForCheckpoint(const std::string&) { bool cp_prepareDriveForCheckpoint(const std::string&) {
struct fstab* fstab = fs_mgr_read_fstab_default(); auto fstab_default = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
if (!fstab) return false; fs_mgr_read_fstab_default(), fs_mgr_free_fstab};
if (!fstab_default) return false;
struct fstab* mounts = fs_mgr_read_fstab("/proc/mounts"); auto mounts = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
if (mounts == NULL) { fs_mgr_read_fstab("/proc/mounts"), fs_mgr_free_fstab};
fs_mgr_free_fstab(fstab); if (!mounts) return false;
return false;
}
for (int i = 0; i < mounts->num_entries; ++i) { for (int i = 0; i < mounts->num_entries; ++i) {
const fstab_rec* mount_rec = &mounts->recs[i]; const fstab_rec* mount_rec = &mounts->recs[i];
const fstab_rec* fstab_rec = fs_mgr_get_entry_for_mount_point(fstab, mount_rec->mount_point); const fstab_rec* fstab_rec =
fs_mgr_get_entry_for_mount_point(fstab_default.get(), mount_rec->mount_point);
if (!fstab_rec) continue; if (!fstab_rec) continue;
if (fs_mgr_is_checkpoint_blk(fstab_rec)) { if (fs_mgr_is_checkpoint_blk(fstab_rec)) {
@ -152,8 +151,6 @@ bool cp_prepareDriveForCheckpoint(const std::string&) {
setBowState(mount_rec->blk_device, "1"); setBowState(mount_rec->blk_device, "1");
} }
} }
fs_mgr_free_fstab(mounts);
fs_mgr_free_fstab(fstab);
return true; return true;
} }

Loading…
Cancel
Save