From: Ben Gras Date: Sun, 19 Jun 2005 22:28:05 +0000 (+0000) Subject: Made mkfs a little smarter about how to report empty devices. X-Git-Tag: v3.1.0~729 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=34a9677a5bf570f7b65f463af64b6cfa4eeab492;p=minix.git 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. --- 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]);