diff --git a/fs_mgr/fs_mgr_avb.cpp b/fs_mgr/fs_mgr_avb.cpp index 7512eb934..3576b9caa 100644 --- a/fs_mgr/fs_mgr_avb.cpp +++ b/fs_mgr/fs_mgr_avb.cpp @@ -489,15 +489,9 @@ int fs_mgr_load_vbmeta_images(struct fstab* fstab) { // Sets requested_partitions to nullptr as it's to copy the contents // of HASH partitions into fs_mgr_avb_verify_data, which is not required as // fs_mgr only deals with HASHTREE partitions. - const char *requested_partitions[] = {nullptr}; - std::string ab_suffix; - std::string slot; - if (fs_mgr_get_boot_config("slot", &slot)) { - ab_suffix = "_" + slot; - } else { - // remove slot_suffix once bootloaders update to new androidboot.slot param - fs_mgr_get_boot_config("slot_suffix", &ab_suffix); - } + const char* requested_partitions[] = {nullptr}; + std::string ab_suffix = fs_mgr_get_slot_suffix(); + AvbSlotVerifyResult verify_result = avb_slot_verify(fs_mgr_avb_ops, requested_partitions, ab_suffix.c_str(), fs_mgr_vbmeta_prop.allow_verification_error, &fs_mgr_avb_verify_data); diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index a9a0df79e..c231a23c9 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -572,7 +572,7 @@ static struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file) cnt++; } /* If an A/B partition, modify block device to be the real block device */ - if (fs_mgr_update_for_slotselect(fstab) != 0) { + if (!fs_mgr_update_for_slotselect(fstab)) { LERROR << "Error updating for slotselect"; goto err; } diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h index 377d2ecb0..dedffd8d1 100644 --- a/fs_mgr/fs_mgr_priv.h +++ b/fs_mgr/fs_mgr_priv.h @@ -41,8 +41,6 @@ #define PWARNING PLOG(WARNING) << FS_MGR_TAG #define PERROR PLOG(ERROR) << FS_MGR_TAG -__BEGIN_DECLS - #define CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000" #define WAIT_TIMEOUT 20 @@ -114,10 +112,8 @@ __BEGIN_DECLS int fs_mgr_set_blk_ro(const char *blockdev); int fs_mgr_test_access(const char *device); -int fs_mgr_update_for_slotselect(struct fstab *fstab); +bool fs_mgr_update_for_slotselect(struct fstab *fstab); bool is_dt_compatible(); bool is_device_secure(); -__END_DECLS - #endif /* __CORE_FS_MGR_PRIV_H */ diff --git a/fs_mgr/fs_mgr_slotselect.cpp b/fs_mgr/fs_mgr_slotselect.cpp index 7a4547334..9ca15e237 100644 --- a/fs_mgr/fs_mgr_slotselect.cpp +++ b/fs_mgr/fs_mgr_slotselect.cpp @@ -16,37 +16,47 @@ #include +#include + #include "fs_mgr.h" #include "fs_mgr_priv.h" -// Updates |fstab| for slot_suffix. Returns 0 on success, -1 on error. -int fs_mgr_update_for_slotselect(struct fstab *fstab) -{ +// Returns "_a" or "_b" based on two possible values in kernel cmdline: +// - androidboot.slot = a or b OR +// - androidboot.slot_suffix = _a or _b +// TODO: remove slot_suffix once it's deprecated. +std::string fs_mgr_get_slot_suffix() { + std::string slot; + std::string ab_suffix; + + if (fs_mgr_get_boot_config("slot", &slot)) { + ab_suffix = "_" + slot; + } else if (!fs_mgr_get_boot_config("slot_suffix", &ab_suffix)) { + ab_suffix = ""; + } + return ab_suffix; +} + +// Updates |fstab| for slot_suffix. Returns true on success, false on error. +bool fs_mgr_update_for_slotselect(struct fstab *fstab) { int n; - int got_suffix = 0; - std::string suffix; + std::string ab_suffix; for (n = 0; n < fstab->num_entries; n++) { if (fstab->recs[n].fs_mgr_flags & MF_SLOTSELECT) { char *tmp; - - if (!got_suffix) { - std::string slot; - if (fs_mgr_get_boot_config("slot", &slot)) { - suffix = "_" + slot; - } else if (!fs_mgr_get_boot_config("slot_suffix", &suffix)) { - // remove slot_suffix once bootloaders update to new androidboot.slot param - return -1; - } + if (ab_suffix.empty()) { + ab_suffix = fs_mgr_get_slot_suffix(); + // Returns false as non A/B devices should not have MF_SLOTSELECT. + if (ab_suffix.empty()) return false; } - - if (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, suffix.c_str()) > 0) { + if (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, ab_suffix.c_str()) > 0) { free(fstab->recs[n].blk_device); fstab->recs[n].blk_device = tmp; } else { - return -1; + return false; } } } - return 0; + return true; } diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index 2fd5f65a4..ec6a415f6 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -22,6 +22,12 @@ #include #include +// C++ only headers +// TODO: move this into separate header files under include/fs_mgr/*.h +#ifdef __cplusplus +#include +#endif + // Magic number at start of verity metadata #define VERITY_METADATA_MAGIC_NUMBER 0xb001b001 @@ -29,9 +35,7 @@ // turn verity off in userdebug builds. #define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 // "VOFF" -#ifdef __cplusplus -extern "C" { -#endif +__BEGIN_DECLS // Verity modes enum verity_mode { @@ -142,8 +146,12 @@ int fs_mgr_do_format(struct fstab_rec *fstab, bool reserve_footer); #define FS_MGR_SETUP_VERITY_SUCCESS 0 int fs_mgr_setup_verity(struct fstab_rec *fstab, bool wait_for_verity_dev); +__END_DECLS + +// C++ only functions +// TODO: move this into separate header files under include/fs_mgr/*.h #ifdef __cplusplus -} +std::string fs_mgr_get_slot_suffix(); #endif #endif /* __CORE_FS_MGR_H */