ffs_dirpref() calculates dirsize = (fs->fs_avgfilesize * fs->fs_avgfpdir).
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 9 Aug 2004 19:41:04 +0000 (19:41 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 9 Aug 2004 19:41:04 +0000 (19:41 +0000)
commit06a1dad18a624e8c7da33b17cb565888ccb38ddf
tree9dce1a0362eae29e885e9f2d631f3f24eae794ad
parented1d998165fb5760400a470019cb3332e216f9c4
ffs_dirpref() calculates dirsize = (fs->fs_avgfilesize * fs->fs_avgfpdir).
However, these two paramters can be set by the sysop such that they easily
overflow a 32 bit integer.  Use 64 bit arithmatic to prevent the overflow
and special-case values > 0x7fffffff to simply set maxcontigdirs to 1 rather
then waste time doing further 64 bit arithmatic.

Note that NetBSD also changed 'cgsize' to a 64 bit integer, but fails to
properly cast at least one of the arguments in both the dirsize and cgsize
multiplication which means that the overflow bug in NetBSD has not actually
been fixed.

This patch does not change the cgsize calculation yet, it requires more
review.

Source: NetBSD ffs_alloc.c/1.74 from Barry Bouwsma of Tiengen.
sys/vfs/ufs/ffs_alloc.c