From c5290fae3937cc83de8a551db9686d1e1964e378 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 11 Apr 2003 22:10:50 -0400 Subject: [PATCH] Mke2fs can be given a minimum block size by passing in a negative number to the -b option. --- debian/changelog | 6 ++++-- misc/ChangeLog | 4 ++++ misc/mke2fs.8.in | 13 ++++++++++--- misc/mke2fs.c | 59 +++++++++++++++++++++++++++++++++++--------------------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7f9bee2..c46b65c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,9 +9,11 @@ e2fsprogs (1.32+1.33-WIP-2003.03.30-3) unstable; urgency=low for a suitable readine library. * Fix bug in mke2fs, which was was incorrectly checking the argument to the -g option if the default block size is used. (Closes: #188319) - * Update man pages. (Addresses Debian bug #188318) + * Update man pages. (Closes: #188318) + * Mke2fs can be given a minimum block size by passing in a negative + number to the -b option. - -- Theodore Y. Ts'o Fri, 11 Apr 2003 13:59:08 -0400 + -- Theodore Y. Ts'o Fri, 11 Apr 2003 22:08:00 -0400 e2fsprogs (1.32+1.33-WIP-2003.03.30-2) unstable; urgency=low diff --git a/misc/ChangeLog b/misc/ChangeLog index 462d94f..fd2e4b2 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,5 +1,9 @@ 2003-04-11 Theodore Ts'o + * mke2fs.c (PRS): If the argument to -b is negative, treat it as a + minimum blocksize. (Feature requested by EVMS developers + for mainframe DASD's that do not support 1k blocksizes.) + * mke2fs.8.in: Document the -g option. (Addresses Debian bug #188318) * mke2fs.c (PRS): Fix bug where mke2fs was incorrectly checking diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in index ea167a4..821f2d0 100644 --- a/misc/mke2fs.8.in +++ b/misc/mke2fs.8.in @@ -142,10 +142,17 @@ option was specified. Specify the size of blocks in bytes. Valid block size vales are 1024, 2048 and 4096 bytes per block. If omitted, .B mke2fs -block-size is determined by the file system size and the expected usage -of the filesystem (see the +block-size is hueristically determined by the file system size and +the expected usage of the filesystem (see the .B \-T -option). +option). If +.I block-size +is negative, then mke2fs will use hueristics to determine the +appropriate block size, with the constraint that the block size will be +at least +.I block-size +bytes. This is useful for certain hardware devices which require that +the blocksize be a multiple of 2k. .TP .B \-c Check the device for bad blocks before creating the file system. If diff --git a/misc/mke2fs.c b/misc/mke2fs.c index f0183ed..f865d43 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -152,6 +152,7 @@ static void set_fs_defaults(const char *fs_type, int megs; int ratio = 0; struct mke2fs_defaults *p; + int use_bsize = 1024; megs = super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) / 1024; if (inode_ratio) @@ -162,23 +163,26 @@ static void set_fs_defaults(const char *fs_type, if ((strcmp(p->type, fs_type) != 0) && (strcmp(p->type, default_str) != 0)) continue; - if ((p->size != 0) && - (megs > p->size)) + if ((p->size != 0) && (megs > p->size)) continue; if (ratio == 0) *inode_ratio = p->inode_ratio < blocksize ? blocksize : p->inode_ratio; - if (blocksize == 0) { - if (p->blocksize == DEF_MAX_BLOCKSIZE) - p->blocksize = sys_page_size; - super->s_log_frag_size = super->s_log_block_size = - int_log2(p->blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); - } + use_bsize = p->blocksize; + } + if (blocksize <= 0) { + if (use_bsize == DEF_MAX_BLOCKSIZE) + use_bsize = sys_page_size; + if ((blocksize < 0) && (use_bsize < (-blocksize))) + use_bsize = -blocksize; + blocksize = use_bsize; + super->s_blocks_count /= blocksize / 1024; } - if (blocksize == 0) - super->s_blocks_count /= EXT2_BLOCK_SIZE(super) / 1024; + super->s_log_frag_size = super->s_log_block_size = + int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); } + /* * Helper function for read_bb_file and test_disk */ @@ -788,7 +792,7 @@ static __u32 ok_features[3] = { static void PRS(int argc, char *argv[]) { - int c; + int b, c; int size; char * tmp; int blocksize = 0; @@ -875,9 +879,10 @@ static void PRS(int argc, char *argv[]) "b:cf:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) switch (c) { case 'b': - blocksize = strtoul(optarg, &tmp, 0); - if (blocksize < EXT2_MIN_BLOCK_SIZE || - blocksize > EXT2_MAX_BLOCK_SIZE || *tmp) { + blocksize = strtol(optarg, &tmp, 0); + b = (blocksize > 0) ? blocksize : -blocksize; + if (b < EXT2_MIN_BLOCK_SIZE || + b > EXT2_MAX_BLOCK_SIZE || *tmp) { com_err(program_name, 0, _("bad block size - %s"), optarg); exit(1); @@ -886,8 +891,10 @@ static void PRS(int argc, char *argv[]) fprintf(stderr, _("Warning: blocksize %d not " "usable on most systems.\n"), blocksize); - param.s_log_block_size = - int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); + if (blocksize > 0) + param.s_log_block_size = + int_log2(blocksize >> + EXT2_MIN_BLOCK_LOG_SIZE); break; case 'c': /* Check for bad blocks */ case 't': /* deprecated */ @@ -1067,7 +1074,7 @@ static void PRS(int argc, char *argv[]) * If there's no blocksize specified and there is a journal * device, use it to figure out the blocksize */ - if (blocksize == 0 && journal_device) { + if (blocksize <= 0 && journal_device) { ext2_filsys jfs; retval = ext2fs_open(journal_device, @@ -1079,6 +1086,13 @@ static void PRS(int argc, char *argv[]) journal_device); exit(1); } + if ((blocksize < 0) && (jfs->blocksize < -blocksize)) { + com_err(program_name, 0, + _("Journal dev blocksize (%d) smaller than" + "minimum blocksize %d\n"), jfs->blocksize, + -blocksize); + exit(1); + } blocksize = jfs->blocksize; param.s_log_block_size = int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); @@ -1153,7 +1167,7 @@ static void PRS(int argc, char *argv[]) } else if (!force && (param.s_blocks_count > dev_size)) { com_err(program_name, 0, - _("Filesystem larger than apparent filesystem size.")); + _("Filesystem larger than apparent device size.")); proceed_question(); } @@ -1172,10 +1186,11 @@ static void PRS(int argc, char *argv[]) param.s_first_meta_bg = atoi(tmp); set_fs_defaults(fs_type, ¶m, blocksize, &inode_ratio); - + blocksize = EXT2_BLOCK_SIZE(¶m); + if (param.s_blocks_per_group) { if (param.s_blocks_per_group < 256 || - param.s_blocks_per_group > 8 * EXT2_BLOCK_SIZE(¶m)) { + param.s_blocks_per_group > 8 * blocksize) { com_err(program_name, 0, _("blocks per group count out of range")); exit(1); @@ -1189,7 +1204,7 @@ static void PRS(int argc, char *argv[]) com_err(program_name, 0, _("bad inode size %d (min %d/max %d)"), inode_size, EXT2_GOOD_OLD_INODE_SIZE, - EXT2_BLOCK_SIZE(¶m)); + blocksize); exit(1); } if (inode_size != EXT2_GOOD_OLD_INODE_SIZE) @@ -1203,7 +1218,7 @@ static void PRS(int argc, char *argv[]) * Calculate number of inodes based on the inode ratio */ param.s_inodes_count = num_inodes ? num_inodes : - ((__u64) param.s_blocks_count * EXT2_BLOCK_SIZE(¶m)) + ((__u64) param.s_blocks_count * blocksize) / inode_ratio; /* -- 1.8.3.1