Skip to content

Commit

Permalink
fs: ext2: Use the UUID library
Browse files Browse the repository at this point in the history
Use the sys/uuid.h library to generate and hold the ext2 UUID.

Signed-off-by: Simone Orru <[email protected]>
  • Loading branch information
sorru94 committed Oct 3, 2024
1 parent a04219d commit 214931f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
4 changes: 3 additions & 1 deletion include/zephyr/fs/ext2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <stdint.h>

#include <zephyr/sys/uuid.h>

/** @brief Configuration used to format ext2 file system.
*
* If a field is set to 0 then default value is used.
Expand All @@ -27,7 +29,7 @@ struct ext2_cfg {
uint32_t block_size;
uint32_t fs_size; /* Number of blocks that we want to take. */
uint32_t bytes_per_inode;
uint8_t uuid[16];
struct uuid uuid;
uint8_t volume_name[17]; /* If first byte is 0 then name ext2" is given. */
bool set_uuid;
};
Expand Down
15 changes: 5 additions & 10 deletions subsys/fs/ext2/ext2_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ static void validate_config(struct ext2_cfg *cfg)
}

if (!cfg->set_uuid) {
/* Generate random UUID */
sys_rand_get(cfg->uuid, 16);

/* Set version of UUID (ver. 4 variant 1) */
cfg->uuid[6] = (cfg->uuid[6] & 0x0f) | 0x40;
cfg->uuid[8] = (cfg->uuid[8] & 0x3f) | 0x80;
uuid_generate_v4(&cfg->uuid);
}
}

Expand Down Expand Up @@ -98,9 +93,8 @@ int ext2_format(struct ext2_data *fs, struct ext2_cfg *cfg)
int rc, ret = 0;

validate_config(cfg);
LOG_INF("[Config] blk_sz:%d fs_sz:%d ino_bytes:%d uuid:'%s' vol:'%s'",
cfg->block_size, cfg->fs_size, cfg->bytes_per_inode, cfg->uuid,
cfg->volume_name);
LOG_INF("[Config] blk_sz:%d fs_sz:%d ino_bytes:%d uuid:'%s' vol:'%s'", cfg->block_size,
cfg->fs_size, cfg->bytes_per_inode, cfg->uuid.val, cfg->volume_name);

uint32_t fs_memory = cfg->fs_size ? MIN(cfg->fs_size, fs->device_size) : fs->device_size;

Expand Down Expand Up @@ -248,7 +242,8 @@ int ext2_format(struct ext2_data *fs, struct ext2_cfg *cfg)
sb->s_journal_dev = sys_cpu_to_le32(0);
sb->s_last_orphan = sys_cpu_to_le32(0);

memcpy(sb->s_uuid, cfg->uuid, 16);

uuid_to_buffer(cfg->uuid, sb->s_uuid);

Check notice on line 246 in subsys/fs/ext2/ext2_format.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/fs/ext2/ext2_format.c:246 -
strcpy(sb->s_volume_name, cfg->volume_name);

if (ext2_write_block(fs, sb_block) < 0) {
Expand Down
4 changes: 2 additions & 2 deletions subsys/fs/ext2/ext2_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ struct ext2_disk_superblock {
uint32_t s_feature_compat;
uint32_t s_feature_incompat;
uint32_t s_feature_ro_compat;
uint8_t s_uuid[16];
uint8_t s_uuid[UUID_SIZE];
uint8_t s_volume_name[16];
uint8_t s_last_mounted[64];
uint32_t s_algo_bitmap;
uint8_t s_prealloc_blocks;
uint8_t s_prealloc_dir_blocks;
uint8_t s_align[2];
uint8_t s_journal_uuid[16];
uint8_t s_journal_uuid[UUID_SIZE];
uint32_t s_journal_inum;
uint32_t s_journal_dev;
uint32_t s_last_orphan;
Expand Down

0 comments on commit 214931f

Please sign in to comment.