diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-03-08 23:42:09 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-03-09 01:03:41 +0100 |
| commit | abb212dd5fbb33168f583f36b67f29f659a91bb4 (patch) | |
| tree | e9d246178f71bf314efb8f06f7419a2dc4aefa76 | |
| parent | 6d34064b3a4b07218b01f6cc7700ee2ce68a7542 (diff) | |
Add progress reporting for formatting.
| -rw-r--r-- | include/ext4_mkfs.h | 5 | ||||
| -rw-r--r-- | src/ext4_mkfs.c | 14 |
2 files changed, 13 insertions, 6 deletions
diff --git a/include/ext4_mkfs.h b/include/ext4_mkfs.h index 16a05f8..697d645 100644 --- a/include/ext4_mkfs.h +++ b/include/ext4_mkfs.h @@ -71,8 +71,11 @@ struct ext4_mkfs_info { int ext4_mkfs_read_info(struct ext4_blockdev *bd, struct ext4_mkfs_info *info); +/* Callback to report progress from 0 to 1 */ +typedef void (*ext4_progress)(void*, float); + int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd, - struct ext4_mkfs_info *info, int fs_type); + struct ext4_mkfs_info *info, int fs_type, ext4_progress progress, void* progress_context); #ifdef __cplusplus } diff --git a/src/ext4_mkfs.c b/src/ext4_mkfs.c index a62e4cf..c6b8938 100644 --- a/src/ext4_mkfs.c +++ b/src/ext4_mkfs.c @@ -299,7 +299,7 @@ static void fill_sb(struct fs_aux_info *aux_info, struct ext4_mkfs_info *info) static int write_bgroups(struct ext4_fs *fs, struct ext4_blockdev *bd, struct fs_aux_info *aux_info, - struct ext4_mkfs_info *info) + struct ext4_mkfs_info *info, ext4_progress progress, void* progress_context) { /* size of the group descriptor */ uint32_t dsc_size = ext4_sb_get_desc_size(aux_info->sb); @@ -369,6 +369,10 @@ static int write_bgroups(struct ext4_fs *fs, struct ext4_blockdev *bd, struct fs int r = EOK; for (uint32_t i = 0; i < aux_info->groups; i++) { + if (progress) { + progress(progress_context, (float) i / aux_info->groups); + } + uint64_t bg_start_block = aux_info->first_data_block + aux_info->first_data_block + i * info->blocks_per_group; uint32_t blk_off = 0; @@ -457,7 +461,7 @@ Finish: return r; } -static int mkfs_init(struct ext4_fs *fs, struct ext4_blockdev *bd, struct ext4_mkfs_info *info) +static int mkfs_init(struct ext4_fs *fs, struct ext4_blockdev *bd, struct ext4_mkfs_info *info, ext4_progress progress, void* progress_context) { int r; struct fs_aux_info aux_info; @@ -470,7 +474,7 @@ static int mkfs_init(struct ext4_fs *fs, struct ext4_blockdev *bd, struct ext4_m fill_sb(&aux_info, info); memcpy(&fs->sb, aux_info.sb, sizeof(struct ext4_sblock)); - r = write_bgroups(fs, bd, &aux_info, info); + r = write_bgroups(fs, bd, &aux_info, info, progress, progress_context); if (r != EOK) goto Finish; @@ -651,7 +655,7 @@ static int create_journal_inode(struct ext4_fs *fs, } int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd, - struct ext4_mkfs_info *info, int fs_type) + struct ext4_mkfs_info *info, int fs_type, ext4_progress progress, void* progress_context) { int r; @@ -778,7 +782,7 @@ int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd, fs->bdev = bd; fs->read_only = false; - r = mkfs_init(fs, bd, info); + r = mkfs_init(fs, bd, info, progress, progress_context); if (r != EOK) goto cache_fini; |
