From 71bc2e8b772695c00b2ed550565724afddd6fb7e Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 29 Aug 2019 15:11:04 -0400 Subject: [PATCH 2/2] make_ext4fs: allow setting a specific UUID The UUID was previously only reproducibly generated using a combination of a fixed namespace and the label of the partition. This change allows projects to specify a desired UUID instead. Signed-off-by: Samuel Dionne-Riel --- ext4_sb.h | 3 +++ ext4_utils.c | 13 ++++++++++++- make_ext4fs.c | 5 +++++ make_ext4fs_main.c | 9 +++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ext4_sb.h b/ext4_sb.h index d6416a7..68f5cb1 100644 --- a/ext4_sb.h +++ b/ext4_sb.h @@ -18,6 +18,7 @@ #define _EXT4_UTILS_EXT4_SB_H_ #include "ext4_kernel_headers.h" +#include #define EXT4_SUPER_MAGIC 0xEF53 @@ -42,6 +43,8 @@ struct fs_info { uint32_t reserve_pcnt; const char *label; uint8_t no_journal; + bool with_uuid; + uint8_t uuid[16]; }; int ext4_parse_sb(struct ext4_super_block *sb, struct fs_info *info); diff --git a/ext4_utils.c b/ext4_utils.c index 1a886d7..e8e60fb 100644 --- a/ext4_utils.c +++ b/ext4_utils.c @@ -221,7 +221,13 @@ void ext4_fill_in_sb() sb->s_feature_compat = info.feat_compat; sb->s_feature_incompat = info.feat_incompat; sb->s_feature_ro_compat = info.feat_ro_compat; - generate_uuid("extandroid/make_ext4fs", info.label, sb->s_uuid); + if (info.with_uuid) { + memset(sb->s_uuid, 0, sizeof(sb->s_uuid)); + memcpy(sb->s_uuid, info.uuid, sizeof(sb->s_uuid)); + } + else { + generate_uuid("extandroid/make_ext4fs", info.label, sb->s_uuid); + } memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name)); strncpy(sb->s_volume_name, info.label, sizeof(sb->s_volume_name)); memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted)); @@ -521,6 +527,11 @@ int read_ext(int fd, int verbose) printf(" Inodes per group: %d\n", info.inodes_per_group); printf(" Inode size: %d\n", info.inode_size); printf(" Label: %s\n", info.label); + if (info.with_uuid) { + char uuid[UUID_STR_LEN] = ""; + uuid_to_string(info.uuid, uuid); + printf(" UUID: %s\n", uuid); + } printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks); printf(" Block groups: %d\n", aux_info.groups); printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); diff --git a/make_ext4fs.c b/make_ext4fs.c index 051052b..ac38d15 100644 --- a/make_ext4fs.c +++ b/make_ext4fs.c @@ -451,6 +451,11 @@ int make_ext4fs_internal(int fd, const char *_directory, printf(" Inode size: %d\n", info.inode_size); printf(" Journal blocks: %d\n", info.journal_blocks); printf(" Label: %s\n", info.label); + if (info.with_uuid) { + char uuid[UUID_STR_LEN] = ""; + uuid_to_string(info.uuid, uuid); + printf(" UUID: %s\n", uuid); + } ext4_create_fs_aux_info(); diff --git a/make_ext4fs_main.c b/make_ext4fs_main.c index 88254c3..e957a03 100644 --- a/make_ext4fs_main.c +++ b/make_ext4fs_main.c @@ -27,6 +27,7 @@ #include "ext4_utils.h" #include "canned_fs_config.h" +#include "uuid.h" extern struct fs_info info; @@ -35,7 +36,7 @@ static void usage(char *path) { fprintf(stderr, "%s [ -l ] [ -j ] [ -b ]\n", basename(path)); fprintf(stderr, " [ -g ] [ -i ] [ -I ]\n"); - fprintf(stderr, " [ -m ] [ -L