Update fs_mgr_update_verity_state() for new C++ Fstab
Bug: 62292478
Test: boot and check verity state
Change-Id: I4912a16ada9a6d72480d7ac905654b764c5d18b6
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index 60ce452..316ff5e 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -1533,7 +1533,8 @@
return true;
}
-bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> callback) {
+bool fs_mgr_update_verity_state(
+ std::function<void(const std::string& mount_point, int mode)> callback) {
if (!callback) {
return false;
}
@@ -1543,27 +1544,25 @@
return false;
}
- std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
- fs_mgr_free_fstab);
- if (!fstab) {
+ Fstab fstab;
+ if (!ReadDefaultFstab(&fstab)) {
LERROR << "Failed to read default fstab";
return false;
}
DeviceMapper& dm = DeviceMapper::Instance();
- for (int i = 0; i < fstab->num_entries; i++) {
- auto fsrec = &fstab->recs[i];
- if (!fs_mgr_is_verified(fsrec) && !fs_mgr_is_avb(fsrec)) {
+ for (const auto& entry : fstab) {
+ if (!entry.fs_mgr_flags.verify && !entry.fs_mgr_flags.avb) {
continue;
}
std::string mount_point;
- if (!strcmp(fsrec->mount_point, "/")) {
+ if (entry.mount_point == "/") {
// In AVB, the dm device name is vroot instead of system.
- mount_point = fs_mgr_is_avb(fsrec) ? "vroot" : "system";
+ mount_point = entry.fs_mgr_flags.avb ? "vroot" : "system";
} else {
- mount_point = basename(fsrec->mount_point);
+ mount_point = basename(entry.mount_point.c_str());
}
if (dm.GetState(mount_point) == DmDeviceState::INVALID) {
@@ -1574,7 +1573,7 @@
const char* status;
std::vector<DeviceMapper::TargetInfo> table;
if (!dm.GetTableStatus(mount_point, &table) || table.empty() || table[0].data.empty()) {
- if (!fs_mgr_is_verifyatboot(fsrec)) {
+ if (!entry.fs_mgr_flags.verify_at_boot) {
PERROR << "Failed to query DM_TABLE_STATUS for " << mount_point;
continue;
}
@@ -1588,7 +1587,7 @@
// instead of [partition.vroot.verified].
if (mount_point == "vroot") mount_point = "system";
if (*status == 'C' || *status == 'V') {
- callback(fsrec, mount_point.c_str(), mode, *status);
+ callback(mount_point, mode);
}
}
diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp
index 649c8bf..d2d8dc1 100644
--- a/fs_mgr/fs_mgr_overlayfs.cpp
+++ b/fs_mgr/fs_mgr_overlayfs.cpp
@@ -277,9 +277,8 @@
std::vector<std::string> fs_mgr_overlayfs_verity_enabled_list() {
std::vector<std::string> ret;
- fs_mgr_update_verity_state([&ret](fstab_rec*, const char* mount_point, int, int) {
- ret.emplace_back(mount_point);
- });
+ fs_mgr_update_verity_state(
+ [&ret](const std::string& mount_point, int) { ret.emplace_back(mount_point); });
return ret;
}
diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h
index 80f97fc..c1dc731 100644
--- a/fs_mgr/include/fs_mgr.h
+++ b/fs_mgr/include/fs_mgr.h
@@ -50,10 +50,6 @@
MOUNT_MODE_LATE = 2
};
-// Callback function for verity status
-typedef void fs_mgr_verity_state_callback(fstab_rec* fstab, const char* mount_point, int mode,
- int status);
-
#define FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED 7
#define FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION 6
#define FS_MGR_MNTALL_DEV_FILE_ENCRYPTED 5
@@ -77,7 +73,8 @@
fstab_rec const* fs_mgr_get_crypt_entry(fstab const* fstab);
void fs_mgr_get_crypt_info(fstab* fstab, char* key_loc, char* real_blk_device, size_t size);
bool fs_mgr_load_verity_state(int* mode);
-bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> callback);
+bool fs_mgr_update_verity_state(
+ std::function<void(const std::string& mount_point, int mode)> callback);
bool fs_mgr_swapon_all(const Fstab& fstab);
bool fs_mgr_update_logical_partition(struct fstab_rec* rec);
diff --git a/init/builtins.cpp b/init/builtins.cpp
index b382126..2bebe76 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -734,13 +734,10 @@
return Success();
}
-static void verity_update_property(fstab_rec *fstab, const char *mount_point,
- int mode, int status) {
- property_set("partition."s + mount_point + ".verified", std::to_string(mode));
-}
-
static Result<Success> do_verity_update_state(const BuiltinArguments& args) {
- if (!fs_mgr_update_verity_state(verity_update_property)) {
+ if (!fs_mgr_update_verity_state([](const std::string& mount_point, int mode) {
+ property_set("partition." + mount_point + ".verified", std::to_string(mode));
+ })) {
return Error() << "fs_mgr_update_verity_state() failed";
}
return Success();