Merge "fs_mgr: adding fs_mgr_get_slot_suffix() public API" am: b26f48f135

am: 4c96971cee

Change-Id: Icad63b84bb6de85b1a73db84a784ad8b5bdb0f38
This commit is contained in:
Bowgo Tsai 2017-04-13 13:50:49 +00:00 committed by android-build-merger
commit e203dbb2f6
5 changed files with 45 additions and 37 deletions

View file

@ -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 // 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 // of HASH partitions into fs_mgr_avb_verify_data, which is not required as
// fs_mgr only deals with HASHTREE partitions. // fs_mgr only deals with HASHTREE partitions.
const char *requested_partitions[] = {nullptr}; const char* requested_partitions[] = {nullptr};
std::string ab_suffix; std::string ab_suffix = fs_mgr_get_slot_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);
}
AvbSlotVerifyResult verify_result = AvbSlotVerifyResult verify_result =
avb_slot_verify(fs_mgr_avb_ops, requested_partitions, ab_suffix.c_str(), 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); fs_mgr_vbmeta_prop.allow_verification_error, &fs_mgr_avb_verify_data);

View file

@ -526,7 +526,7 @@ static struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file)
cnt++; cnt++;
} }
/* If an A/B partition, modify block device to be the real block device */ /* 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"; LERROR << "Error updating for slotselect";
goto err; goto err;
} }

View file

@ -41,8 +41,6 @@
#define PWARNING PLOG(WARNING) << FS_MGR_TAG #define PWARNING PLOG(WARNING) << FS_MGR_TAG
#define PERROR PLOG(ERROR) << 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 CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000"
#define WAIT_TIMEOUT 20 #define WAIT_TIMEOUT 20
@ -114,10 +112,8 @@ __BEGIN_DECLS
int fs_mgr_set_blk_ro(const char *blockdev); int fs_mgr_set_blk_ro(const char *blockdev);
int fs_mgr_test_access(const char *device); 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_dt_compatible();
bool is_device_secure(); bool is_device_secure();
__END_DECLS
#endif /* __CORE_FS_MGR_PRIV_H */ #endif /* __CORE_FS_MGR_PRIV_H */

View file

@ -16,37 +16,47 @@
#include <stdio.h> #include <stdio.h>
#include <string>
#include "fs_mgr.h" #include "fs_mgr.h"
#include "fs_mgr_priv.h" #include "fs_mgr_priv.h"
// Updates |fstab| for slot_suffix. Returns 0 on success, -1 on error. // Returns "_a" or "_b" based on two possible values in kernel cmdline:
int fs_mgr_update_for_slotselect(struct fstab *fstab) // - 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 n;
int got_suffix = 0; std::string ab_suffix;
std::string suffix;
for (n = 0; n < fstab->num_entries; n++) { for (n = 0; n < fstab->num_entries; n++) {
if (fstab->recs[n].fs_mgr_flags & MF_SLOTSELECT) { if (fstab->recs[n].fs_mgr_flags & MF_SLOTSELECT) {
char *tmp; char *tmp;
if (ab_suffix.empty()) {
if (!got_suffix) { ab_suffix = fs_mgr_get_slot_suffix();
std::string slot; // Returns false as non A/B devices should not have MF_SLOTSELECT.
if (fs_mgr_get_boot_config("slot", &slot)) { if (ab_suffix.empty()) return false;
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 (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, ab_suffix.c_str()) > 0) {
if (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, suffix.c_str()) > 0) {
free(fstab->recs[n].blk_device); free(fstab->recs[n].blk_device);
fstab->recs[n].blk_device = tmp; fstab->recs[n].blk_device = tmp;
} else { } else {
return -1; return false;
} }
} }
} }
return 0; return true;
} }

View file

@ -22,6 +22,12 @@
#include <stdbool.h> #include <stdbool.h>
#include <linux/dm-ioctl.h> #include <linux/dm-ioctl.h>
// C++ only headers
// TODO: move this into separate header files under include/fs_mgr/*.h
#ifdef __cplusplus
#include <string>
#endif
// Magic number at start of verity metadata // Magic number at start of verity metadata
#define VERITY_METADATA_MAGIC_NUMBER 0xb001b001 #define VERITY_METADATA_MAGIC_NUMBER 0xb001b001
@ -29,9 +35,7 @@
// turn verity off in userdebug builds. // turn verity off in userdebug builds.
#define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 // "VOFF" #define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 // "VOFF"
#ifdef __cplusplus __BEGIN_DECLS
extern "C" {
#endif
// Verity modes // Verity modes
enum verity_mode { enum verity_mode {
@ -139,8 +143,12 @@ int fs_mgr_do_format(struct fstab_rec *fstab, bool reserve_footer);
#define FS_MGR_SETUP_VERITY_SUCCESS 0 #define FS_MGR_SETUP_VERITY_SUCCESS 0
int fs_mgr_setup_verity(struct fstab_rec *fstab, bool wait_for_verity_dev); 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 #ifdef __cplusplus
} std::string fs_mgr_get_slot_suffix();
#endif #endif
#endif /* __CORE_FS_MGR_H */ #endif /* __CORE_FS_MGR_H */