Update fs_mgr_update_verity_state() for new C++ Fstab
Bug: 62292478 Test: boot and check verity state Change-Id: I4912a16ada9a6d72480d7ac905654b764c5d18b6
This commit is contained in:
parent
215d1d510e
commit
02eff5cccd
|
@ -1533,7 +1533,8 @@ bool fs_mgr_load_verity_state(int* mode) {
|
|||
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 @@ bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> call
|
|||
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 @@ bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> call
|
|||
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 @@ bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> call
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -277,9 +277,8 @@ bool fs_mgr_overlayfs_already_mounted(const std::string& mount_point, bool overl
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,10 +50,6 @@ enum mount_mode {
|
|||
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 @@ int fs_mgr_do_tmpfs_mount(const char *n_name);
|
|||
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);
|
||||
|
||||
|
|
|
@ -734,13 +734,10 @@ static Result<Success> do_verity_load_state(const BuiltinArguments& args) {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue