Skip to content

Commit 828ec04

Browse files
committed
Allow specifying reserved blocks percentage
Signed-off-by: Jo-Philipp Wich <[email protected]>
1 parent 67cbf16 commit 828ec04

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

ext4_sb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct fs_info {
3939
uint16_t feat_compat;
4040
uint16_t feat_incompat;
4141
uint32_t bg_desc_reserve_blocks;
42+
uint32_t reserve_pcnt;
4243
const char *label;
4344
uint8_t no_journal;
4445
};

ext4_utils.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void ext4_fill_in_sb()
191191

192192
sb->s_inodes_count = info.inodes_per_group * aux_info.groups;
193193
sb->s_blocks_count_lo = aux_info.len_blocks;
194-
sb->s_r_blocks_count_lo = 0;
194+
sb->s_r_blocks_count_lo = (aux_info.len_blocks / 100) * info.reserve_pcnt;
195195
sb->s_free_blocks_count_lo = 0;
196196
sb->s_free_inodes_count = 0;
197197
sb->s_first_data_block = aux_info.first_data_block;
@@ -533,4 +533,3 @@ int read_ext(int fd, int verbose)
533533

534534
return 0;
535535
}
536-

make_ext4fs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ int make_ext4fs_internal(int fd, const char *_directory,
456456

457457
printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks);
458458
printf(" Block groups: %d\n", aux_info.groups);
459+
printf(" Reserved blocks: %"PRIu64"\n", (aux_info.len_blocks / 100) * info.reserve_pcnt);
459460
printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks);
460461

461462
ext4_sparse_file = sparse_file_new(info.block_size, info.len);

make_ext4fs_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void usage(char *path)
3535
{
3636
fprintf(stderr, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path));
3737
fprintf(stderr, " [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
38-
fprintf(stderr, " [ -L <label> ] [ -f ]\n");
38+
fprintf(stderr, " [ -m <reserved blocks percent> ] [ -L <label> ] [ -f ]\n");
3939
fprintf(stderr, " [ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]\n");
4040
fprintf(stderr, " [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]\n");
4141
fprintf(stderr, " <filename> [<directory>]\n");
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
5858
time_t fixed_time = -1;
5959
FILE* block_list_file = NULL;
6060

61-
while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:T:C:B:fwzJsctv")) != -1) {
61+
while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:T:C:B:m:fwzJsctv")) != -1) {
6262
switch (opt) {
6363
case 'l':
6464
info.len = parse_num(optarg);
@@ -118,6 +118,9 @@ int main(int argc, char **argv)
118118
exit(EXIT_FAILURE);
119119
}
120120
break;
121+
case 'm':
122+
info.reserve_pcnt = strtoul(optarg, NULL, 0);
123+
break;
121124
default: /* '?' */
122125
usage(argv[0]);
123126
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)