kern/77181: newfs -g largevalue, mkdir, panic

Bruce Evans bde at
Tue Feb 8 02:40:37 PST 2005

The following reply was made to PR kern/77181; it has been noted by GNATS.

From: Bruce Evans <bde at>
To: Peter Much <pmc at>
Cc: FreeBSD-gnats-submit at, freebsd-bugs at
Subject: Re: kern/77181: newfs -g largevalue, mkdir, panic
Date: Tue, 8 Feb 2005 21:31:40 +1100 (EST)

 On Sun, 6 Feb 2005, Peter Much wrote:
 > >Description:
 > 	create 5G filesystem on gvinum drive (single drive, no mirror, no stripe).
 > 	newfs -g 104857600 -U
 > 	mount it, and mkdir some directories.
 > 	panic, integer divide fault.
 There is another PR or two about this.  I have the following note about
 fixing it someday:
 Index: ffs_alloc.c
 RCS file: /home/ncvs/src/sys/ufs/ffs/ffs_alloc.c,v
 retrieving revision 1.121
 diff -u -2 -r1.121 ffs_alloc.c
 --- ffs_alloc.c	16 Jun 2004 09:47:25 -0000	1.121
 +++ ffs_alloc.c	28 Oct 2004 15:12:47 -0000
 @@ -964,4 +991,11 @@
  		minbfree = 1;
  	cgsize = fs->fs_fsize * fs->fs_fpg;
 +	/*
 +	 * XXX the following multiplication can overflow, since newfs can
 +	 * be abused to set fs_avgfilesize and fs_avgfpdir to preposterous
 +	 * values.  For the particular preposterous values of (64M, 64),
 +	 * the multiplication overflows to 0 and then dirsize = 0 sometimes
 +	 * causes division by 0.
 +	 */
  	dirsize = fs->fs_avgfilesize * fs->fs_avgfpdir;
  	curdirsize = avgndir ? (cgsize - avgbfree * fs->fs_bsize) / avgndir : 0;
 This should be fixed primarily in newfs.  newfs should refuse to create
 file systems that cannot work.  It already limits many parameters.  Something
 (fsck or the kernel or both) should check for and fix such parameters, since
 they may occur in old file systems.
 > >Fix:
 > 	Now I dont use the -g option. Actually I just found it and
 > 	thought, lets try it out - have not yet researched what it
 > 	functionally does. And I know that my value is way large and
 > 	is not in good match with the blocksize.
 Another fix is to not use the -g option (or -h option) :-).  I've never
 used them.  These options came with the new `dirpref' algorithm on
 2001/04/10 (to help control that algorithm), so I guess there has not
 been much use of them.  See the cvs log message for newfs.c 1.35 for
 vastly many more details than are in the man page.
 > 	(And now I put kerneldebugger back into my config - btw,
 > 	there seems no longer anywhere the nice explanations for such
 > 	options as was in the former LINT file - where one could
 > 	easily pick what could be eventually needed.)
 Try the NOTES file.

More information about the freebsd-bugs mailing list