usr.sbin/mkfs: Allow -b SIZE with proto file

Previously, if a proto file was given, the -b argument would be ignored.

Also added:
 - if the number of inodes is not given, then an estimation is used.
 - sanity checks where moved from one special case to the general case.

Change-Id: I2abfa52bf34206c9087c64b5bfc26af866eb47cb
This commit is contained in:
Lionel Sambuc 2013-05-23 18:02:58 +02:00
parent 154b6d7486
commit e1acf37d77

View File

@ -141,7 +141,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int nread, mode, usrid, grpid, ch, extra_space_percent; int nread, mode, usrid, grpid, ch, extra_space_percent;
block_t blocks, maxblocks; block_t blocks, maxblocks, bblocks;
ino_t inodes, root_inum; ino_t inodes, root_inum;
char *token[MAX_TOKENS], line[LINE_LEN], *sfx; char *token[MAX_TOKENS], line[LINE_LEN], *sfx;
struct fs_size fssize; struct fs_size fssize;
@ -151,6 +151,7 @@ main(int argc, char *argv[])
/* Process switches. */ /* Process switches. */
blocks = 0; blocks = 0;
inodes = 0; inodes = 0;
bblocks = 0;
#ifndef MFS_STATIC_BLOCK_SIZE #ifndef MFS_STATIC_BLOCK_SIZE
block_size = 0; block_size = 0;
#endif #endif
@ -179,7 +180,7 @@ main(int argc, char *argv[])
(void)sfx; /* shut up warnings about unused variable...*/ (void)sfx; /* shut up warnings about unused variable...*/
#endif #endif
case 'b': case 'b':
blocks = strtoul(optarg, (char **) NULL, 0); blocks = bblocks = strtoul(optarg, (char **) NULL, 0);
break; break;
case 'd': case 'd':
dflag = 1; dflag = 1;
@ -254,7 +255,11 @@ main(int argc, char *argv[])
/* Determine the size of the device if not specified as -b or proto. */ /* Determine the size of the device if not specified as -b or proto. */
maxblocks = sizeup(argv[optind]); maxblocks = sizeup(argv[optind]);
if (argc - optind == 1 && blocks == 0) { if (bblocks != 0 && bblocks > maxblocks){
errx(4, "Given size -b %d exeeds device capacity(%d)\n", bblocks, maxblocks);
}
if (argc - optind == 1 && bblocks == 0) {
blocks = maxblocks; blocks = maxblocks;
/* blocks == 0 is checked later, but leads to a funny way of /* blocks == 0 is checked later, but leads to a funny way of
* reporting a 0-sized device (displays usage). * reporting a 0-sized device (displays usage).
@ -285,7 +290,16 @@ main(int argc, char *argv[])
/* Read the line with the block and inode counts. */ /* Read the line with the block and inode counts. */
get_line(line, token); get_line(line, token);
if (bblocks == 0){
blocks = strtol(token[0], (char **) NULL, 10); blocks = strtol(token[0], (char **) NULL, 10);
} else {
if(bblocks < strtol(token[0], (char **) NULL, 10)) {
errx(1, "%s: number of blocks given as parameter(%d)"
" is too small for given proto file(%d).",
argv[optind], bblocks,
strtol(token[0], (char **) NULL, 10));
};
}
inodes = strtol(token[1], (char **) NULL, 10); inodes = strtol(token[1], (char **) NULL, 10);
/* Process mode line for root directory. */ /* Process mode line for root directory. */
@ -311,6 +325,14 @@ main(int argc, char *argv[])
blocks = strtoul(optarg, (char **) NULL, 0); blocks = strtoul(optarg, (char **) NULL, 0);
if (blocks == 0) errx(2, "Can't open prototype file"); if (blocks == 0) errx(2, "Can't open prototype file");
} }
/* Make simple file system of the given size, using defaults. */
mode = 040777;
usrid = BIN;
grpid = BINGRP;
simple = 1;
}
if (inodes == 0) { if (inodes == 0) {
long long kb = ((unsigned long long)blocks*block_size) / 1024; long long kb = ((unsigned long long)blocks*block_size) / 1024;
@ -327,16 +349,10 @@ main(int argc, char *argv[])
inodes += inodes_per_block - 1; inodes += inodes_per_block - 1;
inodes = inodes / inodes_per_block * inodes_per_block; inodes = inodes / inodes_per_block * inodes_per_block;
} }
if (blocks < 5) errx(1, "Block count too small"); if (blocks < 5) errx(1, "Block count too small");
if (inodes < 1) errx(1, "Inode count too small"); if (inodes < 1) errx(1, "Inode count too small");
/* Make simple file system of the given size, using defaults. */
mode = 040777;
usrid = BIN;
grpid = BINGRP;
simple = 1;
}
nrblocks = blocks; nrblocks = blocks;
nrinodes = inodes; nrinodes = inodes;