From 34a9677a5bf570f7b65f463af64b6cfa4eeab492 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Sun, 19 Jun 2005 22:28:05 +0000 Subject: [PATCH] Made mkfs a little smarter about how to report empty devices. Also a little smarter about manually specified number of blocks that is larger than the device capacity. --- commands/simple/mkfs.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/commands/simple/mkfs.c b/commands/simple/mkfs.c index c5d0b4c80..705deda6d 100755 --- a/commands/simple/mkfs.c +++ b/commands/simple/mkfs.c @@ -141,7 +141,7 @@ int argc; char *argv[]; { int nread, mode, usrid, grpid, ch; - block_t blocks; + block_t blocks, maxblocks; block_t i; ino_t root_inum; ino_t inodes; @@ -225,13 +225,30 @@ char *argv[]; bzero(zero, block_size); /* Determine the size of the device if not specified as -b or proto. */ - if (argc - optind == 1 && blocks == 0) blocks = sizeup(argv[optind]); + maxblocks = sizeup(argv[optind]); + if (argc - optind == 1 && blocks == 0) { + blocks = maxblocks; + /* blocks == 0 is checked later, but leads to a funny way of + * reporting a 0-sized device (displays usage). + */ + if(blocks < 1) { + fprintf(stderr, "%s: this device can't hold a filesystem.\n", + progname); + return 1; + } + } /* The remaining args must be 'special proto', or just 'special' if the * no. of blocks has already been specified. */ if (argc - optind != 2 && (argc - optind != 1 || blocks == 0)) usage(); + if (blocks > maxblocks) { + fprintf(stderr, "%s: number of blocks too large for device.\n", + progname); + return 1; + } + /* Check special. */ check_mtab(argv[optind]); -- 2.44.0