Adding GSI fstab entries when needed
In ReadFstabFromFile(), currently it always adds 'system_gsi' and
'userdata_gsi' fstab entries when running in Live GSI. As the API
might be used to load a fstab file without "/system" and/or "/data",
it's better to replace "/system" with 'system_gsi' and "/data" with
'userdata_gsi', instead of adding 'system_gsi' and 'userdata_gsi'
unconditionally.
Bug: 124640105
Test: boot a Live GSI, then `atest libfs_avb_device_test`
Change-Id: I52928f95b9ebd12ce09ffd538caf96a2de430dbc
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp
index 4659add..82d9144 100644
--- a/fs_mgr/fs_mgr_fstab.cpp
+++ b/fs_mgr/fs_mgr_fstab.cpp
@@ -607,10 +607,14 @@
return userdata;
}
-void EraseFstabEntry(Fstab* fstab, const std::string& mount_point) {
+bool EraseFstabEntry(Fstab* fstab, const std::string& mount_point) {
auto iter = std::remove_if(fstab->begin(), fstab->end(),
[&](const auto& entry) { return entry.mount_point == mount_point; });
- fstab->erase(iter, fstab->end());
+ if (iter != fstab->end()) {
+ fstab->erase(iter, fstab->end());
+ return true;
+ }
+ return false;
}
void TransformFstabForGsi(Fstab* fstab) {
@@ -628,11 +632,13 @@
userdata = BuildGsiUserdataFstabEntry();
}
- EraseFstabEntry(fstab, "/system");
- EraseFstabEntry(fstab, "/data");
+ if (EraseFstabEntry(fstab, "/system")) {
+ fstab->emplace_back(BuildGsiSystemFstabEntry());
+ }
- fstab->emplace_back(BuildGsiSystemFstabEntry());
- fstab->emplace_back(userdata);
+ if (EraseFstabEntry(fstab, "/data")) {
+ fstab->emplace_back(userdata);
+ }
}
} // namespace