diff options
author | mckusick <mckusick@FreeBSD.org> | 2002-11-30 18:28:26 +0000 |
---|---|---|
committer | mckusick <mckusick@FreeBSD.org> | 2002-11-30 18:28:26 +0000 |
commit | b52fe76381f5a430ac048bbceed2ef12f7372fc9 (patch) | |
tree | c972d64e51343676c8cdf9bab266290bd41df6ba /sbin/newfs/mkfs.c | |
parent | 7e6582e5c1372b582051a77dfcafc1c10c1489f5 (diff) | |
download | FreeBSD-src-b52fe76381f5a430ac048bbceed2ef12f7372fc9.zip FreeBSD-src-b52fe76381f5a430ac048bbceed2ef12f7372fc9.tar.gz |
Add some more checks to newfs so that it will not build filesystems
that the kernel will refuse to mount. Specifically it now enforces
the MAXBSIZE blocksize limit. This update also fixes a problem where
newfs could segment fault if the selected fragment size was too large.
PR: bin/30959
Submitted by: Ceri Davies <setantae@submonkey.net>
Sponsored by: DARPA & NAI Labs.
Diffstat (limited to 'sbin/newfs/mkfs.c')
-rw-r--r-- | sbin/newfs/mkfs.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 837f608..625efb5 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -136,19 +136,6 @@ mkfs(struct partition *pp, char *fsys) randinit = 1; srandomdev(); } - /* - * allocate space for superblock, cylinder group map, and - * two sets of inode blocks. - */ - if (bsize < SBLOCKSIZE) - iobufsize = SBLOCKSIZE + 3 * bsize; - else - iobufsize = 4 * bsize; - if ((iobuf = malloc(iobufsize)) == 0) { - printf("Cannot allocate I/O buffer\n"); - exit(38); - } - bzero(iobuf, iobufsize); sblock.fs_old_flags = FS_FLAGS_UPDATED; sblock.fs_flags = 0; if (Uflag) @@ -195,11 +182,21 @@ mkfs(struct partition *pp, char *fsys) sblock.fs_fsize, sectorsize); sblock.fs_fsize = sectorsize; } + if (sblock.fs_bsize > MAXBSIZE) { + printf("decreasing block size from %d to maximum (%d)\n", + sblock.fs_bsize, MAXBSIZE); + sblock.fs_bsize = MAXBSIZE; + } if (sblock.fs_bsize < MINBSIZE) { printf("increasing block size from %d to minimum (%d)\n", sblock.fs_bsize, MINBSIZE); sblock.fs_bsize = MINBSIZE; } + if (sblock.fs_fsize > MAXBSIZE) { + printf("decreasing fragment size from %d to maximum (%d)\n", + sblock.fs_fsize, MAXBSIZE); + sblock.fs_fsize = MAXBSIZE; + } if (sblock.fs_bsize < sblock.fs_fsize) { printf("increasing block size from %d to fragment size (%d)\n", sblock.fs_bsize, sblock.fs_fsize); @@ -297,7 +294,7 @@ mkfs(struct partition *pp, char *fsys) */ origdensity = density; for (;;) { - fragsperinode = numfrags(&sblock, density); + fragsperinode = MAX(numfrags(&sblock, density), 1); minfpg = fragsperinode * INOPB(&sblock); if (minfpg > sblock.fs_size) minfpg = sblock.fs_size; @@ -444,6 +441,19 @@ mkfs(struct partition *pp, char *fsys) i = 0; width = charsperline(); /* + * allocate space for superblock, cylinder group map, and + * two sets of inode blocks. + */ + if (sblock.fs_bsize < SBLOCKSIZE) + iobufsize = SBLOCKSIZE + 3 * sblock.fs_bsize; + else + iobufsize = 4 * sblock.fs_bsize; + if ((iobuf = malloc(iobufsize)) == 0) { + printf("Cannot allocate I/O buffer\n"); + exit(38); + } + bzero(iobuf, iobufsize); + /* * Make a copy of the superblock into the buffer that we will be * writing out in each cylinder group. */ |