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
This commit is contained in:
Bowgo Tsai 2019-02-18 17:56:58 +08:00
parent f80c326d2e
commit 9bbaa7bbee

View file

@ -607,10 +607,14 @@ FstabEntry BuildGsiUserdataFstabEntry() {
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 @@ void TransformFstabForGsi(Fstab* fstab) {
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