Merge "Update fs_mgr_update_verity_state() for new C++ Fstab"
This commit is contained in:
commit
ac1812ddb5
4 changed files with 18 additions and 26 deletions
|
|
@ -1533,7 +1533,8 @@ bool fs_mgr_load_verity_state(int* mode) {
|
||||||
return true;
|
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) {
|
if (!callback) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1543,27 +1544,25 @@ bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> call
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
|
Fstab fstab;
|
||||||
fs_mgr_free_fstab);
|
if (!ReadDefaultFstab(&fstab)) {
|
||||||
if (!fstab) {
|
|
||||||
LERROR << "Failed to read default fstab";
|
LERROR << "Failed to read default fstab";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceMapper& dm = DeviceMapper::Instance();
|
DeviceMapper& dm = DeviceMapper::Instance();
|
||||||
|
|
||||||
for (int i = 0; i < fstab->num_entries; i++) {
|
for (const auto& entry : fstab) {
|
||||||
auto fsrec = &fstab->recs[i];
|
if (!entry.fs_mgr_flags.verify && !entry.fs_mgr_flags.avb) {
|
||||||
if (!fs_mgr_is_verified(fsrec) && !fs_mgr_is_avb(fsrec)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string mount_point;
|
std::string mount_point;
|
||||||
if (!strcmp(fsrec->mount_point, "/")) {
|
if (entry.mount_point == "/") {
|
||||||
// In AVB, the dm device name is vroot instead of system.
|
// 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 {
|
} else {
|
||||||
mount_point = basename(fsrec->mount_point);
|
mount_point = basename(entry.mount_point.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dm.GetState(mount_point) == DmDeviceState::INVALID) {
|
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;
|
const char* status;
|
||||||
std::vector<DeviceMapper::TargetInfo> table;
|
std::vector<DeviceMapper::TargetInfo> table;
|
||||||
if (!dm.GetTableStatus(mount_point, &table) || table.empty() || table[0].data.empty()) {
|
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;
|
PERROR << "Failed to query DM_TABLE_STATUS for " << mount_point;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1588,7 +1587,7 @@ bool fs_mgr_update_verity_state(std::function<fs_mgr_verity_state_callback> call
|
||||||
// instead of [partition.vroot.verified].
|
// instead of [partition.vroot.verified].
|
||||||
if (mount_point == "vroot") mount_point = "system";
|
if (mount_point == "vroot") mount_point = "system";
|
||||||
if (*status == 'C' || *status == 'V') {
|
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> fs_mgr_overlayfs_verity_enabled_list() {
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
fs_mgr_update_verity_state([&ret](fstab_rec*, const char* mount_point, int, int) {
|
fs_mgr_update_verity_state(
|
||||||
ret.emplace_back(mount_point);
|
[&ret](const std::string& mount_point, int) { ret.emplace_back(mount_point); });
|
||||||
});
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,6 @@ enum mount_mode {
|
||||||
MOUNT_MODE_LATE = 2
|
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_IS_METADATA_ENCRYPTED 7
|
||||||
#define FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION 6
|
#define FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION 6
|
||||||
#define FS_MGR_MNTALL_DEV_FILE_ENCRYPTED 5
|
#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);
|
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);
|
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_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_swapon_all(const Fstab& fstab);
|
||||||
bool fs_mgr_update_logical_partition(struct fstab_rec* rec);
|
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();
|
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) {
|
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 Error() << "fs_mgr_update_verity_state() failed";
|
||||||
}
|
}
|
||||||
return Success();
|
return Success();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue