diff options
author | bde <bde@FreeBSD.org> | 1997-03-22 09:33:55 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1997-03-22 09:33:55 +0000 |
commit | 90027d0150af2b72f6ae09f8db21175330453548 (patch) | |
tree | 973a404b9c78ed1947989290047a49a753b11a22 /sys/ufs | |
parent | 60e14681284303aa19c383bd113f78d75db543e8 (diff) | |
download | FreeBSD-src-90027d0150af2b72f6ae09f8db21175330453548.zip FreeBSD-src-90027d0150af2b72f6ae09f8db21175330453548.tar.gz |
Merged enough of lfs from Lite2 for mkdep of LINT to work again.
Diffstat (limited to 'sys/ufs')
-rw-r--r-- | sys/ufs/lfs/lfs.h | 288 | ||||
-rw-r--r-- | sys/ufs/lfs/lfs_inode.c | 109 |
2 files changed, 218 insertions, 179 deletions
diff --git a/sys/ufs/lfs/lfs.h b/sys/ufs/lfs/lfs.h index 8d92afa..fa0fed7 100644 --- a/sys/ufs/lfs/lfs.h +++ b/sys/ufs/lfs/lfs.h @@ -30,8 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)lfs.h 8.3 (Berkeley) 9/23/93 - * $Id$ + * @(#)lfs.h 8.9 (Berkeley) 5/8/95 + * $Id: lfs.h,v 1.9 1997/02/22 09:47:15 peter Exp $ */ #ifndef _UFS_LFS_LFS_H_ @@ -59,14 +59,15 @@ /* On-disk and in-memory checkpoint segment usage structure. */ typedef struct segusage SEGUSE; struct segusage { - u_long su_nbytes; /* number of live bytes */ - u_long su_lastmod; /* SEGUSE last modified timestamp */ - u_short su_nsums; /* number of summaries in segment */ - u_short su_ninos; /* number of inode blocks in seg */ -#define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ -#define SEGUSE_DIRTY 0x2 /* segment has data in it */ -#define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ - u_long su_flags; + u_int32_t su_nbytes; /* number of live bytes */ + u_int32_t su_lastmod; /* SEGUSE last modified timestamp */ + u_int16_t su_nsums; /* number of summaries in segment */ + u_int16_t su_ninos; /* number of inode blocks in seg */ + +#define SEGUSE_ACTIVE 0x01 /* segment is currently being written */ +#define SEGUSE_DIRTY 0x02 /* segment has data in it */ +#define SEGUSE_SUPERBLOCK 0x04 /* segment contains a superblock */ + u_int32_t su_flags; }; #define SEGUPB(fs) (1 << (fs)->lfs_sushift) @@ -76,100 +77,102 @@ struct segusage { /* On-disk file information. One per file with data blocks in the segment. */ typedef struct finfo FINFO; struct finfo { - u_long fi_nblocks; /* number of blocks */ - u_long fi_version; /* version number */ - u_long fi_ino; /* inode number */ - daddr_t fi_blocks[1]; /* array of logical block numbers */ + u_int32_t fi_nblocks; /* number of blocks */ + u_int32_t fi_version; /* version number */ + u_int32_t fi_ino; /* inode number */ + u_int32_t fi_lastlength; /* length of last block in array */ + ufs_daddr_t fi_blocks[1]; /* array of logical block numbers */ }; /* On-disk and in-memory super block. */ struct lfs { #define LFS_MAGIC 0x070162 - u_long lfs_magic; /* magic number */ + u_int32_t lfs_magic; /* magic number */ #define LFS_VERSION 1 - u_long lfs_version; /* version number */ + u_int32_t lfs_version; /* version number */ - u_long lfs_size; /* number of blocks in fs */ - u_long lfs_ssize; /* number of blocks per segment */ - u_long lfs_dsize; /* number of disk blocks in fs */ - u_long lfs_bsize; /* file system block size */ - u_long lfs_fsize; /* size of frag blocks in fs */ - u_long lfs_frag; /* number of frags in a block in fs */ + u_int32_t lfs_size; /* number of blocks in fs */ + u_int32_t lfs_ssize; /* number of blocks per segment */ + u_int32_t lfs_dsize; /* number of disk blocks in fs */ + u_int32_t lfs_bsize; /* file system block size */ + u_int32_t lfs_fsize; /* size of frag blocks in fs */ + u_int32_t lfs_frag; /* number of frags in a block in fs */ /* Checkpoint region. */ - ino_t lfs_free; /* start of the free list */ - u_long lfs_bfree; /* number of free disk blocks */ - u_long lfs_nfiles; /* number of allocated inodes */ - long lfs_avail; /* blocks available for writing */ - u_long lfs_uinodes; /* inodes in cache not yet on disk */ - daddr_t lfs_idaddr; /* inode file disk address */ - ino_t lfs_ifile; /* inode file inode number */ - daddr_t lfs_lastseg; /* address of last segment written */ - daddr_t lfs_nextseg; /* address of next segment to write */ - daddr_t lfs_curseg; /* current segment being written */ - daddr_t lfs_offset; /* offset in curseg for next partial */ - daddr_t lfs_lastpseg; /* address of last partial written */ - u_long lfs_tstamp; /* time stamp */ - long lfs_maxsymlinklen; /* max length of an internal symlink */ + ino_t lfs_free; /* start of the free list */ + u_int32_t lfs_bfree; /* number of free disk blocks */ + u_int32_t lfs_nfiles; /* number of allocated inodes */ + int32_t lfs_avail; /* blocks available for writing */ + u_int32_t lfs_uinodes; /* inodes in cache not yet on disk */ + ufs_daddr_t lfs_idaddr; /* inode file disk address */ + ino_t lfs_ifile; /* inode file inode number */ + ufs_daddr_t lfs_lastseg; /* address of last segment written */ + ufs_daddr_t lfs_nextseg; /* address of next segment to write */ + ufs_daddr_t lfs_curseg; /* current segment being written */ + ufs_daddr_t lfs_offset; /* offset in curseg for next partial */ + ufs_daddr_t lfs_lastpseg; /* address of last partial written */ + u_int32_t lfs_tstamp; /* time stamp */ /* These are configuration parameters. */ - u_long lfs_minfree; /* minimum percentage of free blocks */ + u_int32_t lfs_minfree; /* minimum percentage of free blocks */ /* These fields can be computed from the others. */ - u_quad_t lfs_maxfilesize; /* maximum representable file size */ - u_long lfs_dbpseg; /* disk blocks per segment */ - u_long lfs_inopb; /* inodes per block */ - u_long lfs_ifpb; /* IFILE entries per block */ - u_long lfs_sepb; /* SEGUSE entries per block */ - u_long lfs_nindir; /* indirect pointers per block */ - u_long lfs_nseg; /* number of segments */ - u_long lfs_nspf; /* number of sectors per fragment */ - u_long lfs_cleansz; /* cleaner info size in blocks */ - u_long lfs_segtabsz; /* segment table size in blocks */ - - u_long lfs_segmask; /* calculate offset within a segment */ - u_long lfs_segshift; /* fast mult/div for segments */ - u_long lfs_bmask; /* calc block offset from file offset */ - u_long lfs_bshift; /* calc block number from file offset */ - u_long lfs_ffmask; /* calc frag offset from file offset */ - u_long lfs_ffshift; /* fast mult/div for frag from file */ - u_long lfs_fbmask; /* calc frag offset from block offset */ - u_long lfs_fbshift; /* fast mult/div for frag from block */ - u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ - u_long lfs_sushift; /* fast mult/div for segusage table */ + u_int64_t lfs_maxfilesize; /* maximum representable file size */ + u_int32_t lfs_dbpseg; /* disk blocks per segment */ + u_int32_t lfs_inopb; /* inodes per block */ + u_int32_t lfs_ifpb; /* IFILE entries per block */ + u_int32_t lfs_sepb; /* SEGUSE entries per block */ + u_int32_t lfs_nindir; /* indirect pointers per block */ + u_int32_t lfs_nseg; /* number of segments */ + u_int32_t lfs_nspf; /* number of sectors per fragment */ + u_int32_t lfs_cleansz; /* cleaner info size in blocks */ + u_int32_t lfs_segtabsz; /* segment table size in blocks */ + + u_int32_t lfs_segmask; /* calculate offset within a segment */ + u_int32_t lfs_segshift; /* fast mult/div for segments */ + u_int64_t lfs_bmask; /* calc block offset from file offset */ + u_int32_t lfs_bshift; /* calc block number from file offset */ + u_int64_t lfs_ffmask; /* calc frag offset from file offset */ + u_int32_t lfs_ffshift; /* fast mult/div for frag from file */ + u_int64_t lfs_fbmask; /* calc frag offset from block offset */ + u_int32_t lfs_fbshift; /* fast mult/div for frag from block */ + u_int32_t lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ + u_int32_t lfs_sushift; /* fast mult/div for segusage table */ + + int32_t lfs_maxsymlinklen; /* max length of an internal symlink */ #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ #define LFS_MAXNUMSB 10 /* superblock disk offsets */ - daddr_t lfs_sboffs[LFS_MAXNUMSB]; + ufs_daddr_t lfs_sboffs[LFS_MAXNUMSB]; + +/* Checksum -- last valid disk field. */ + u_int32_t lfs_cksum; /* checksum for superblock checking */ /* These fields are set at mount time and are meaningless on disk. */ - struct segment *lfs_sp; /* current segment being written */ - struct vnode *lfs_ivnode; /* vnode for the ifile */ - u_long lfs_seglock; /* single-thread the segment writer */ - pid_t lfs_lockpid; /* pid of lock holder */ - u_long lfs_iocount; /* number of ios pending */ - u_long lfs_writer; /* don't allow any dirops to start */ - u_long lfs_dirops; /* count of active directory ops */ - u_long lfs_doifile; /* Write ifile blocks on next write */ - u_long lfs_nactive; /* Number of segments since last ckp */ - u_char lfs_fmod; /* super block modified flag */ - u_char lfs_clean; /* file system is clean flag */ - u_char lfs_ronly; /* mounted read-only flag */ - u_char lfs_flags; /* currently unused flag */ - u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ - u_char pad[3]; /* long-align */ - u_char pad2[156]; /* Block align */ - -/* Checksum; valid on disk. */ - u_long lfs_cksum; /* checksum for superblock checking */ + struct segment *lfs_sp; /* current segment being written */ + struct vnode *lfs_ivnode; /* vnode for the ifile */ + u_long lfs_seglock; /* single-thread the segment writer */ + pid_t lfs_lockpid; /* pid of lock holder */ + u_long lfs_iocount; /* number of ios pending */ + u_long lfs_writer; /* don't allow any dirops to start */ + u_long lfs_dirops; /* count of active directory ops */ + u_long lfs_doifile; /* Write ifile blocks on next write */ + u_long lfs_nactive; /* Number of segments since last ckp */ + int8_t lfs_fmod; /* super block modified flag */ + int8_t lfs_clean; /* file system is clean flag */ + int8_t lfs_ronly; /* mounted read-only flag */ + int8_t lfs_flags; /* currently unused flag */ + u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ + + int32_t lfs_pad[40]; /* round to 512 bytes */ }; /* - * Inode 0 is the out-of-band inode number, inode 1 is the inode number for - * the IFILE, the root inode is 2 and the lost+found inode is 3. + * Inode 0: out-of-band inode number + * Inode 1: IFILE inode number + * Inode 2: root inode + * Inode 3: lost+found inode number */ - -/* Fixed inode numbers. */ #define LFS_UNUSED_INUM 0 /* out of band inode number */ #define LFS_IFILE_INUM 1 /* IFILE inode number */ #define LOSTFOUNDINO 3 /* lost+found inode number */ @@ -188,10 +191,10 @@ struct lfs { typedef struct ifile IFILE; struct ifile { - u_long if_version; /* inode version number */ + u_int32_t if_version; /* inode version number */ #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ - daddr_t if_daddr; /* inode disk address */ - ino_t if_nextfree; /* next-unallocated inode */ + ufs_daddr_t if_daddr; /* inode disk address */ + ino_t if_nextfree; /* next-unallocated inode */ }; /* @@ -199,8 +202,8 @@ struct ifile { * to pass information between the cleaner and the kernel. */ typedef struct _cleanerinfo { - u_long clean; /* K: number of clean segments */ - u_long dirty; /* K: number of dirty segments */ + u_int32_t clean; /* K: number of clean segments */ + u_int32_t dirty; /* K: number of dirty segments */ } CLEANERINFO; #define CLEANSIZE_SU(fs) \ @@ -215,16 +218,19 @@ typedef struct _cleanerinfo { /* On-disk segment summary information */ typedef struct segsum SEGSUM; struct segsum { - u_long ss_sumsum; /* check sum of summary block */ - u_long ss_datasum; /* check sum of data */ - daddr_t ss_next; /* next segment */ - u_long ss_create; /* creation time stamp */ - u_short ss_nfinfo; /* number of file info structures */ - u_short ss_ninos; /* number of inodes in summary */ + u_int32_t ss_sumsum; /* check sum of summary block */ + u_int32_t ss_datasum; /* check sum of data */ + u_int32_t ss_magic; /* segment summary magic number */ +#define SS_MAGIC 0x061561 + ufs_daddr_t ss_next; /* next segment */ + u_int32_t ss_create; /* creation time stamp */ + u_int16_t ss_nfinfo; /* number of file info structures */ + u_int16_t ss_ninos; /* number of inodes in summary */ + #define SS_DIROP 0x01 /* segment begins a dirop */ #define SS_CONT 0x02 /* more partials to finish this write*/ - u_short ss_flags; /* used for directory operations */ - u_short ss_pad; /* extra space */ + u_int16_t ss_flags; /* used for directory operations */ + u_int16_t ss_pad; /* extra space */ /* FINFO's and inode daddr's... */ }; @@ -234,26 +240,48 @@ struct segsum { /* INOPB is the number of inodes in a secondary storage block. */ #define INOPB(fs) ((fs)->lfs_inopb) -#define blksize(fs) ((fs)->lfs_bsize) -#define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) +#define blksize(fs, ip, lbn) \ + (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->lfs_bshift) \ + ? (fs)->lfs_bsize \ + : (fragroundup(fs, blkoff(fs, (ip)->i_size)))) +#define blkoff(fs, loc) ((int)((loc) & (fs)->lfs_bmask)) +#define fragoff(fs, loc) /* calculates (loc % fs->lfs_fsize) */ \ + ((int)((loc) & (fs)->lfs_ffmask)) #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) #define dbtofsb(fs, b) ((b) >> (fs)->lfs_fsbtodb) +#define fragstodb(fs, b) ((b) << (fs)->lfs_fsbtodb - (fs)->lfs_fbshift) +#define dbtofrags(fs, b) ((b) >> (fs)->lfs_fsbtodb - (fs)->lfs_fbshift) #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) -#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ - ((loc) >> (fs)->lfs_bshift) - +#define numfrags(fs, loc) /* calculates (loc / fs->lfs_fsize) */ \ + ((loc) >> (fs)->lfs_ffshift) +#define blkroundup(fs, size) /* calculates roundup(size, fs->lfs_bsize) */ \ + ((int)(((size) + (fs)->lfs_bmask) & (~(fs)->lfs_bmask))) +#define fragroundup(fs, size) /* calculates roundup(size, fs->lfs_fsize) */ \ + ((int)(((size) + (fs)->lfs_ffmask) & (~(fs)->lfs_ffmask))) +#define fragstoblks(fs, frags) /* calculates (frags / fs->lfs_frag) */ \ + ((frags) >> (fs)->lfs_fbshift) +#define blkstofrags(fs, blks) /* calculates (blks * fs->lfs_frag) */ \ + ((blks) << (fs)->lfs_fbshift) +#define fragnum(fs, fsb) /* calculates (fsb % fs->lfs_frag) */ \ + ((fsb) & ((fs)->lfs_frag - 1)) +#define blknum(fs, fsb) /* calculates rounddown(fsb, fs->lfs_frag) */ \ + ((fsb) &~ ((fs)->lfs_frag - 1)) +#define dblksize(fs, dip, lbn) \ + (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->lfs_bshift)\ + ? (fs)->lfs_bsize \ + : (fragroundup(fs, blkoff(fs, (dip)->di_size)))) #define datosn(fs, daddr) /* disk address to segment number */ \ (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) #define sntoda(fs, sn) /* segment number to disk address */ \ - ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ + ((ufs_daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ (fs)->lfs_sboffs[0])) /* Read in the block with the cleaner info from the ifile. */ #define LFS_CLEANERINFO(CP, F, BP) { \ VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \ if (bread((F)->lfs_ivnode, \ - (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ + (ufs_daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ panic("lfs: ifile read"); \ (CP) = (CLEANERINFO *)(BP)->b_data; \ } @@ -293,8 +321,8 @@ struct segsum { * the segment usage table, plus an ifile page. */ #define LFS_FITS(fs, db) \ - ((long)((db + ((fs)->lfs_uinodes + INOPB((fs))) / INOPB((fs)) + \ - fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE + \ + ((int32_t)((db + ((fs)->lfs_uinodes + INOPB((fs))) / \ + INOPB((fs)) + fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE + \ (fs)->lfs_segtabsz)) < (fs)->lfs_avail) /* Determine if a buffer belongs to the ifile */ @@ -306,32 +334,34 @@ struct segsum { */ typedef struct block_info { ino_t bi_inode; /* inode # */ - daddr_t bi_lbn; /* logical block w/in file */ - daddr_t bi_daddr; /* disk address of block */ + ufs_daddr_t bi_lbn; /* logical block w/in file */ + ufs_daddr_t bi_daddr; /* disk address of block */ time_t bi_segcreate; /* origin segment create time */ int bi_version; /* file version number */ void *bi_bp; /* data buffer */ + int bi_size; /* size of the block (if fragment) */ } BLOCK_INFO; /* In-memory description of a segment about to be written. */ struct segment { - struct lfs *fs; /* file system pointer */ + struct lfs *fs; /* file system pointer */ struct buf **bpp; /* pointer to buffer array */ struct buf **cbpp; /* pointer to next available bp */ struct buf **start_bpp; /* pointer to first bp in this set */ - struct buf *ibp; /* buffer pointer to inode page */ - struct finfo *fip; /* current fileinfo pointer */ - struct vnode *vp; /* vnode being gathered */ - void *segsum; /* segment summary info */ - u_long ninodes; /* number of inodes in this segment */ - u_long seg_bytes_left; /* bytes left in segment */ - u_long sum_bytes_left; /* bytes left in summary block */ - u_long seg_number; /* number of this segment */ - daddr_t *start_lbp; /* beginning lbn for this set */ + struct buf *ibp; /* buffer pointer to inode page */ + struct finfo *fip; /* current fileinfo pointer */ + struct vnode *vp; /* vnode being gathered */ + void *segsum; /* segment summary info */ + u_int32_t ninodes; /* number of inodes in this segment */ + u_int32_t seg_bytes_left; /* bytes left in segment */ + u_int32_t sum_bytes_left; /* bytes left in summary block */ + u_int32_t seg_number; /* number of this segment */ + ufs_daddr_t *start_lbp; /* beginning lbn for this set */ + #define SEGM_CKP 0x01 /* doing a checkpoint */ #define SEGM_CLEAN 0x02 /* cleaner call; don't sort */ #define SEGM_SYNC 0x04 /* wait for segment */ - u_long seg_flags; /* run-time flags for this segment */ + u_int16_t seg_flags; /* run-time flags for this segment */ }; #define ISSPACE(F, BB, C) \ @@ -348,18 +378,18 @@ struct segment { #ifdef DOSTATS /* Statistics Counters */ struct lfs_stats { - int segsused; - int psegwrites; - int psyncwrites; - int pcleanwrites; - int blocktot; - int cleanblocks; - int ncheckpoints; - int nwrites; - int nsync_writes; - int wait_exceeded; - int write_exceeded; - int flush_invoked; + u_int segsused; + u_int psegwrites; + u_int psyncwrites; + u_int pcleanwrites; + u_int blocktot; + u_int cleanblocks; + u_int ncheckpoints; + u_int nwrites; + u_int nsync_writes; + u_int wait_exceeded; + u_int write_exceeded; + u_int flush_invoked; }; extern struct lfs_stats lfs_stats; #endif diff --git a/sys/ufs/lfs/lfs_inode.c b/sys/ufs/lfs/lfs_inode.c index 8948a5e..48297dc 100644 --- a/sys/ufs/lfs/lfs_inode.c +++ b/sys/ufs/lfs/lfs_inode.c @@ -30,8 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)lfs_inode.c 8.5 (Berkeley) 12/30/93 - * $Id: lfs_inode.c,v 1.15 1997/02/22 09:47:21 peter Exp $ + * @(#)lfs_inode.c 8.9 (Berkeley) 5/8/95 + * $Id: lfs_inode.c,v 1.16 1997/03/22 06:53:37 bde Exp $ */ #include "opt_quota.h" @@ -58,12 +58,6 @@ #include <ufs/lfs/lfs.h> #include <ufs/lfs/lfs_extern.h> -int -lfs_init() -{ - return (ufs_init()); -} - /* Search a block for a specific dinode. */ struct dinode * lfs_ifind(fs, ino, dip) @@ -114,13 +108,13 @@ lfs_update(ap) return(0); if (ip->i_flag & IN_ACCESS) - ip->i_atime.tv_sec = ap->a_access->tv_sec; + ip->i_atime = ap->a_access->tv_sec; if (ip->i_flag & IN_UPDATE) { - ip->i_mtime.tv_sec = ap->a_modify->tv_sec; + ip->i_mtime = ap->a_modify->tv_sec; (ip)->i_modrev++; } if (ip->i_flag & IN_CHANGE) - ip->i_ctime.tv_sec = time.tv_sec; + ip->i_ctime = time.tv_sec; ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); if (!(ip->i_flag & IN_MODIFIED)) @@ -139,22 +133,22 @@ lfs_update(ap) #define UPDATE_SEGUSE \ if (lastseg != -1) { \ LFS_SEGENTRY(sup, fs, lastseg, sup_bp); \ - if ((num << fs->lfs_bshift) > sup->su_nbytes) \ + if (num > sup->su_nbytes) \ panic("lfs_truncate: negative bytes in segment %d", \ lastseg); \ - sup->su_nbytes -= num << fs->lfs_bshift; \ + sup->su_nbytes -= num; \ e1 = VOP_BWRITE(sup_bp); \ - blocksreleased += num; \ + fragsreleased += numfrags(fs, num); \ } -#define SEGDEC { \ +#define SEGDEC(S) { \ if (daddr != 0) { \ if (lastseg != (seg = datosn(fs, daddr))) { \ UPDATE_SEGUSE; \ - num = 1; \ + num = (S); \ lastseg = seg; \ } else \ - ++num; \ + num += (S); \ } \ } @@ -175,7 +169,7 @@ lfs_truncate(ap) { register struct indir *inp; register int i; - register daddr_t *daddrp; + register ufs_daddr_t *daddrp; register struct vnode *vp = ap->a_vp; off_t length = ap->a_length; struct buf *bp, *sup_bp; @@ -185,9 +179,10 @@ lfs_truncate(ap) struct lfs *fs; struct indir a[NIADDR + 2], a_end[NIADDR + 2]; SEGUSE *sup; - daddr_t daddr, lastblock, lbn, olastblock; - long off, a_released, blocksreleased, i_released; - int e1, e2, depth, lastseg, num, offset, seg, size; + ufs_daddr_t daddr, lastblock, lbn, olastblock; + ufs_daddr_t oldsize_lastblock, oldsize_newlast, newsize; + long off, a_released, fragsreleased, i_released; + int e1, e2, depth, lastseg, num, offset, seg, freesize; ip = VTOI(vp); gettime(&tv); @@ -223,23 +218,28 @@ lfs_truncate(ap) * Update the size of the file. If the file is not being truncated to * a block boundry, the contents of the partial block following the end * of the file must be zero'ed in case it ever become accessable again - * because of subsequent file growth. + * because of subsequent file growth. For this part of the code, + * oldsize_newlast refers to the old size of the new last block in the file. */ offset = blkoff(fs, length); + lbn = lblkno(fs, length); + oldsize_newlast = blksize(fs, ip, lbn); + + /* Now set oldsize to the current size of the current last block */ + oldsize_lastblock = blksize(fs, ip, olastblock); if (offset == 0) ip->i_size = length; else { - lbn = lblkno(fs, length); #ifdef QUOTA if (e1 = getinoquota(ip)) return (e1); #endif - if (e1 = bread(vp, lbn, fs->lfs_bsize, NOCRED, &bp)) + if (e1 = bread(vp, lbn, oldsize_newlast, NOCRED, &bp)) return (e1); ip->i_size = length; - size = blksize(fs); - bzero((char *)bp->b_data + offset, (u_int)(size - offset)); - allocbuf(bp, size); + newsize = blksize(fs, ip, lbn); + bzero((char *)bp->b_data + offset, (u_int)(newsize - offset)); + allocbuf(bp, newsize); if (e1 = VOP_BWRITE(bp)) return (e1); } @@ -247,20 +247,24 @@ lfs_truncate(ap) * Modify sup->su_nbyte counters for each deleted block; keep track * of number of blocks removed for ip->i_blocks. */ - blocksreleased = 0; + fragsreleased = 0; num = 0; lastseg = -1; for (lbn = olastblock; lbn >= lastblock;) { /* XXX use run length from bmap array to make this faster */ ufs_bmaparray(vp, lbn, &daddr, a, &depth, NULL, NULL); - if (lbn == olastblock) + if (lbn == olastblock) { for (i = NIADDR + 2; i--;) a_end[i] = a[i]; + freesize = oldsize_lastblock; + } else + freesize = fs->lfs_bsize; + switch (depth) { case 0: /* Direct block. */ daddr = ip->i_db[lbn]; - SEGDEC; + SEGDEC(freesize); ip->i_db[lbn] = 0; --lbn; break; @@ -282,19 +286,20 @@ lfs_truncate(ap) inp->in_lbn, fs->lfs_bsize, NOCRED, &bp)) panic("lfs_truncate: bread bno %d", inp->in_lbn); - daddrp = (daddr_t *)bp->b_data + inp->in_off; + daddrp = (ufs_daddr_t *)bp->b_data + + inp->in_off; for (i = inp->in_off; i++ <= a_end[depth].in_off;) { daddr = *daddrp++; - SEGDEC; + SEGDEC(freesize); } a_end[depth].in_off = NINDIR(fs) - 1; if (inp->in_off == 0) brelse (bp); else { - bzero((daddr_t *)bp->b_data + + bzero((ufs_daddr_t *)bp->b_data + inp->in_off, fs->lfs_bsize - - inp->in_off * sizeof(daddr_t)); + inp->in_off * sizeof(ufs_daddr_t)); if (e1 = VOP_BWRITE(bp)) return (e1); } @@ -302,7 +307,7 @@ lfs_truncate(ap) if (depth == 0 && a[1].in_off == 0) { off = a[0].in_off; daddr = ip->i_ib[off]; - SEGDEC; + SEGDEC(freesize); ip->i_ib[off] = 0; } if (lbn == lastblock || lbn <= NDADDR) @@ -324,13 +329,14 @@ lfs_truncate(ap) } #ifdef DIAGNOSTIC - if (ip->i_blocks < fsbtodb(fs, blocksreleased)) { - printf("lfs_truncate: block count < 0\n"); - blocksreleased = ip->i_blocks; + if (ip->i_blocks < fragstodb(fs, fragsreleased)) { + printf("lfs_truncate: frag count < 0\n"); + fragsreleased = dbtofrags(fs, ip->i_blocks); + panic("lfs_truncate: frag count < 0\n"); } #endif - ip->i_blocks -= fsbtodb(fs, blocksreleased); - fs->lfs_bfree += fsbtodb(fs, blocksreleased); + ip->i_blocks -= fragstodb(fs, fragsreleased); + fs->lfs_bfree += fragstodb(fs, fragsreleased); ip->i_flag |= IN_CHANGE | IN_UPDATE; /* * Traverse dirty block list counting number of dirty buffers @@ -341,7 +347,7 @@ lfs_truncate(ap) i_released = 0; for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = bp->b_vnbufs.le_next) if (bp->b_flags & B_LOCKED) { - ++a_released; + a_released += numfrags(fs, bp->b_bcount); /* * XXX * When buffers are created in the cache, their block @@ -354,25 +360,28 @@ lfs_truncate(ap) * here. */ if (bp->b_blkno == bp->b_lblkno) - ++i_released; + i_released += numfrags(fs, bp->b_bcount); } - blocksreleased = fsbtodb(fs, i_released); + fragsreleased = i_released; #ifdef DIAGNOSTIC - if (blocksreleased > ip->i_blocks) { + if (fragsreleased > dbtofrags(fs, ip->i_blocks)) { printf("lfs_inode: Warning! %s\n", - "more blocks released from inode than are in inode"); - blocksreleased = ip->i_blocks; + "more frags released from inode than are in inode"); + fragsreleased = dbtofrags(fs, ip->i_blocks); + panic("lfs_inode: Warning. More frags released\n"); } #endif - fs->lfs_bfree += blocksreleased; - ip->i_blocks -= blocksreleased; + fs->lfs_bfree += fragstodb(fs, fragsreleased); + ip->i_blocks -= fragstodb(fs, fragsreleased); #ifdef DIAGNOSTIC - if (length == 0 && ip->i_blocks != 0) + if (length == 0 && ip->i_blocks != 0) { printf("lfs_inode: Warning! %s%ld%s\n", "Truncation to zero, but ", ip->i_blocks, " blocks left on inode"); + panic("lfs_inode"); + } #endif - fs->lfs_avail += fsbtodb(fs, a_released); + fs->lfs_avail += fragstodb(fs, a_released); e1 = vinvalbuf(vp, (length > 0) ? V_SAVE : 0, ap->a_cred, ap->a_p, 0, 0); e2 = VOP_UPDATE(vp, &tv, &tv, 0); |