fs_mgr: make changes needed to port vold to new Fstab interface
Particularly, capitulate that GetEntryForMountPoint() would be cleaner than std::find_if() and update the rest of system/core to use it. Test: build Change-Id: I982b5a8552d44852d3ab22c20db83afcd4dd652b
This commit is contained in:
parent
accdf0e9c7
commit
2e545f8b2f
6 changed files with 41 additions and 27 deletions
|
@ -998,9 +998,7 @@ static bool IsMountPointMounted(const std::string& mount_point) {
|
|||
if (!ReadFstabFromFile("/proc/mounts", &fstab)) {
|
||||
return false;
|
||||
}
|
||||
auto it = std::find_if(fstab.begin(), fstab.end(),
|
||||
[&](const auto& entry) { return entry.mount_point == mount_point; });
|
||||
return it != fstab.end();
|
||||
return GetEntryForMountPoint(&fstab, mount_point) != nullptr;
|
||||
}
|
||||
|
||||
// When multiple fstab records share the same mount_point, it will try to mount each
|
||||
|
@ -1384,6 +1382,15 @@ int fs_mgr_do_mount(fstab* fstab, const char* n_name, char* n_blk_device, char*
|
|||
needs_checkpoint);
|
||||
}
|
||||
|
||||
int fs_mgr_do_mount(Fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point) {
|
||||
return fs_mgr_do_mount_helper(fstab, n_name, n_blk_device, tmp_mount_point, -1);
|
||||
}
|
||||
|
||||
int fs_mgr_do_mount(Fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point,
|
||||
bool needs_checkpoint) {
|
||||
return fs_mgr_do_mount_helper(fstab, n_name, n_blk_device, tmp_mount_point, needs_checkpoint);
|
||||
}
|
||||
|
||||
/*
|
||||
* mount a tmpfs filesystem at the given point.
|
||||
* return 0 on success, non-zero on failure.
|
||||
|
|
|
@ -787,10 +787,8 @@ void fs_mgr_free_fstab(struct fstab *fstab)
|
|||
free(fstab);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the fstab_rec* whose mount_point is path.
|
||||
* Returns nullptr if not found.
|
||||
*/
|
||||
// Returns the fstab_rec* whose mount_point is path.
|
||||
// Returns nullptr if not found.
|
||||
struct fstab_rec* fs_mgr_get_entry_for_mount_point(struct fstab* fstab, const std::string& path) {
|
||||
if (!fstab) {
|
||||
return nullptr;
|
||||
|
@ -803,6 +801,20 @@ struct fstab_rec* fs_mgr_get_entry_for_mount_point(struct fstab* fstab, const st
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path) {
|
||||
if (fstab == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto& entry : *fstab) {
|
||||
if (entry.mount_point == path) {
|
||||
return &entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::set<std::string> fs_mgr_get_boot_devices() {
|
||||
// First check the kernel commandline, then try the device tree otherwise
|
||||
std::string dt_file_name = get_android_dt_dir() + "/boot_devices";
|
||||
|
|
|
@ -564,9 +564,8 @@ std::vector<std::string> fs_mgr_candidate_list(Fstab* fstab, const char* mount_p
|
|||
if (std::find(verity.begin(), verity.end(), "system") != verity.end()) return mounts;
|
||||
|
||||
// confirm that fstab is missing system
|
||||
if (std::find_if(fstab->begin(), fstab->end(), [](const auto& entry) {
|
||||
return entry.mount_point == "/" || entry.mount_point == "/system ";
|
||||
}) != fstab->end()) {
|
||||
if (GetEntryForMountPoint(fstab, "/") != nullptr ||
|
||||
GetEntryForMountPoint(fstab, "/system") != nullptr) {
|
||||
return mounts;
|
||||
}
|
||||
|
||||
|
@ -847,9 +846,7 @@ bool fs_mgr_overlayfs_mount_all(Fstab* fstab) {
|
|||
std::vector<std::string> fs_mgr_overlayfs_required_devices(Fstab* fstab) {
|
||||
if (fs_mgr_overlayfs_invalid()) return {};
|
||||
|
||||
if (std::find_if(fstab->begin(), fstab->end(), [](const auto& entry) {
|
||||
return entry.mount_point == kScratchMountPoint;
|
||||
}) != fstab->end()) {
|
||||
if (GetEntryForMountPoint(fstab, kScratchMountPoint) != nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -889,9 +886,7 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool*
|
|||
if (overlay_mount_point == kScratchMountPoint) {
|
||||
if (!fs_mgr_overlayfs_setup_scratch(fstab, change)) continue;
|
||||
} else {
|
||||
if (std::find_if(fstab.begin(), fstab.end(), [&overlay_mount_point](const auto& entry) {
|
||||
return entry.mount_point == overlay_mount_point;
|
||||
}) == fstab.end()) {
|
||||
if (GetEntryForMountPoint(&fstab, overlay_mount_point) == nullptr) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,8 @@ FstabEntry* GetEntryForPath(Fstab* fstab, const std::string& path) {
|
|||
if (path.empty()) return nullptr;
|
||||
std::string str(path);
|
||||
while (true) {
|
||||
auto it = std::find_if(fstab->begin(), fstab->end(),
|
||||
[&str](const auto& entry) { return entry.mount_point == str; });
|
||||
if (it != fstab->end()) return &*it;
|
||||
auto entry = GetEntryForMountPoint(fstab, str);
|
||||
if (entry != nullptr) return entry;
|
||||
if (str == "/") break;
|
||||
auto slash = str.find_last_of('/');
|
||||
if (slash == std::string::npos) break;
|
||||
|
@ -65,10 +64,8 @@ static MountState GetMountState(const std::string& mount_point) {
|
|||
return MountState::ERROR;
|
||||
}
|
||||
|
||||
auto mv = std::find_if(
|
||||
mounted_fstab.begin(), mounted_fstab.end(),
|
||||
[&mount_point](const auto& entry) { return entry.mount_point == mount_point; });
|
||||
if (mv != mounted_fstab.end()) {
|
||||
auto mv = GetEntryForMountPoint(&mounted_fstab, mount_point);
|
||||
if (mv != nullptr) {
|
||||
return MountState::MOUNTED;
|
||||
}
|
||||
return MountState::NOT_MOUNTED;
|
||||
|
@ -178,9 +175,8 @@ std::string GetSystemRoot() {
|
|||
return "";
|
||||
}
|
||||
|
||||
auto it = std::find_if(fstab.begin(), fstab.end(),
|
||||
[](const auto& entry) { return entry.mount_point == kSystemRoot; });
|
||||
if (it == fstab.end()) {
|
||||
auto entry = GetEntryForMountPoint(&fstab, kSystemRoot);
|
||||
if (entry == nullptr) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
|
|
|
@ -65,9 +65,11 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode);
|
|||
#define FS_MGR_DOMNT_FAILED (-1)
|
||||
#define FS_MGR_DOMNT_BUSY (-2)
|
||||
#define FS_MGR_DOMNT_SUCCESS 0
|
||||
|
||||
int fs_mgr_do_mount(fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point);
|
||||
int fs_mgr_do_mount(fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point,
|
||||
bool needs_checkpoint);
|
||||
int fs_mgr_do_mount(Fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point);
|
||||
int fs_mgr_do_mount(Fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point,
|
||||
bool need_cp);
|
||||
int fs_mgr_do_mount_one(const FstabEntry& entry, const std::string& mount_point = "");
|
||||
int fs_mgr_do_mount_one(fstab_rec* rec);
|
||||
|
|
|
@ -184,6 +184,8 @@ bool ReadFstabFromFile(const std::string& path, Fstab* fstab);
|
|||
bool ReadFstabFromDt(Fstab* fstab, bool log = true);
|
||||
bool ReadDefaultFstab(Fstab* fstab);
|
||||
|
||||
FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path);
|
||||
|
||||
// Temporary conversion functions.
|
||||
FstabEntry FstabRecToFstabEntry(const fstab_rec* fstab_rec);
|
||||
Fstab LegacyFstabToFstab(const struct fstab* legacy_fstab);
|
||||
|
|
Loading…
Reference in a new issue