From 2bfd8a2678bcb013a5171bf618575a2bfee51ff7 Mon Sep 17 00:00:00 2001 From: lukem Date: Fri, 31 Aug 2001 03:15:45 +0000 Subject: [PATCH] More fixes from FreeBSD (with changes): - Cast blk argument to lblktosize() to (off_t), to prevent 32 bit overflow. whilst almost every use in ffs used this for small blknos, there are potential issues, and it's safer this way. (as discussed with chuq) - Use 64bit (off_t) math to calculate if we have hit our freespace() limit. Necessary for coherent results on filesystems bigger than 0.5Tb. - Use lblktosize() in blksize() and dblksize(), to make it obvious what's happening - Remove sblksize() - nothing uses it --- sys/ufs/ffs/fs.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h index 973f0734d853..99afedab7882 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -1,4 +1,4 @@ -/* $NetBSD: fs.h,v 1.16 2001/08/30 14:37:25 lukem Exp $ */ +/* $NetBSD: fs.h,v 1.17 2001/08/31 03:15:45 lukem Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -476,8 +476,8 @@ struct ocg { ((loc) & (fs)->fs_qbmask) #define fragoff(fs, loc) /* calculates (loc % fs->fs_fsize) */ \ ((loc) & (fs)->fs_qfmask) -#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \ - ((blk) << (fs)->fs_bshift) +#define lblktosize(fs, blk) /* calculates ((off_t)blk * fs->fs_bsize) */ \ + ((off_t)(blk) << (fs)->fs_bshift) #define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ ((loc) >> (fs)->fs_bshift) #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ @@ -501,23 +501,20 @@ struct ocg { */ #define freespace(fs, percentreserved) \ (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \ - (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100)) + (fs)->fs_cstotal.cs_nffree - \ + ((off_t)((fs)->fs_dsize) * (percentreserved) / 100)) /* * Determining the size of a file block in the file system. */ #define blksize(fs, ip, lbn) \ - (((lbn) >= NDADDR || (ip)->i_ffs_size >= ((lbn) + 1) << (fs)->fs_bshift) \ + (((lbn) >= NDADDR || (ip)->i_ffs_size >= lblktosize(fs, (lbn) + 1)) \ ? (fs)->fs_bsize \ : (fragroundup(fs, blkoff(fs, (ip)->i_ffs_size)))) #define dblksize(fs, dip, lbn) \ - (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \ + (((lbn) >= NDADDR || (dip)->di_size >= lblktosize(fs, (lbn) + 1)) \ ? (fs)->fs_bsize \ : (fragroundup(fs, blkoff(fs, (dip)->di_size)))) -#define sblksize(fs, size, lbn) \ - (((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \ - ? (fs)->fs_bsize \ - : (fragroundup(fs, blkoff(fs, (size))))) /* * Number of disk sectors per block/fragment; assumes DEV_BSIZE byte