Date: Tue, 13 Aug 2013 15:40:43 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254283 - head/sys/fs/ext2fs Message-ID: <201308131540.r7DFehRl071120@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Tue Aug 13 15:40:43 2013 New Revision: 254283 URL: http://svnweb.freebsd.org/changeset/base/254283 Log: Define ext2fs local types and use them. Add definitions for e2fs_daddr_t, e4fs_daddr_t in addition to the already existing e2fs_lbn_t and adjust them for ext4. Other than making the code more readable these changes should fix problems related to big filesystems. Setting the proper types can be tricky so the process was helped by looking at UFS. In our implementation, logical block numbers can be negative and the code depends on it. In ext2, block numbers are unsigned so it is convenient to keep e2fs_daddr_t unsigned and use the complete 32 bits. In the case of e4fs_daddr_t, while the value should be unsigned, for ext4 we only need to support 48 bits so preserving an extra bit from the sign is not an issue. While here also drop the ext2_setblock() prototype that was never used. Discussed with: mckusick, bde MFC after: 3 weeks Modified: head/sys/fs/ext2fs/ext2_alloc.c head/sys/fs/ext2fs/ext2_balloc.c head/sys/fs/ext2fs/ext2_bmap.c head/sys/fs/ext2fs/ext2_extern.h head/sys/fs/ext2fs/ext2_inode.c head/sys/fs/ext2fs/ext2_subr.c head/sys/fs/ext2fs/ext2_vnops.c head/sys/fs/ext2fs/inode.h Modified: head/sys/fs/ext2fs/ext2_alloc.c ============================================================================== --- head/sys/fs/ext2fs/ext2_alloc.c Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_alloc.c Tue Aug 13 15:40:43 2013 (r254283) @@ -80,8 +80,8 @@ static daddr_t ext2_mapsearch(struct m_ * available block is located. */ int -ext2_alloc(struct inode *ip, int32_t lbn, int32_t bpref, int size, - struct ucred *cred, int32_t *bnp) +ext2_alloc(struct inode *ip, daddr_t lbn, e4fs_daddr_t bpref, int size, + struct ucred *cred, e4fs_daddr_t *bnp) { struct m_ext2fs *fs; struct ext2mount *ump; @@ -166,7 +166,8 @@ ext2_reallocblks(struct vop_reallocblks_ struct cluster_save *buflist; struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp; e2fs_lbn_t start_lbn, end_lbn; - int32_t soff, newblk, blkno; + int soff; + e2fs_daddr_t newblk, blkno; int i, len, start_lvl, end_lvl, pref, ssize; if (doreallocblks == 0) @@ -250,7 +251,7 @@ ext2_reallocblks(struct vop_reallocblks_ /* * Search the block map looking for an allocation of the desired size. */ - if ((newblk = (int32_t)ext2_hashalloc(ip, dtog(fs, pref), pref, + if ((newblk = (e2fs_daddr_t)ext2_hashalloc(ip, dtog(fs, pref), pref, len, ext2_clusteralloc)) == 0){ EXT2_UNLOCK(ump); goto fail; @@ -550,9 +551,9 @@ ext2_dirpref(struct inode *pip) * of the above. Then, blocknr tells us the number of the block * that will hold the pointer */ -int32_t -ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int indx, int32_t *bap, - int32_t blocknr) +e4fs_daddr_t +ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int indx, e2fs_daddr_t *bap, + e2fs_daddr_t blocknr) { int tmp; mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED); @@ -575,7 +576,7 @@ ext2_blkpref(struct inode *ip, e2fs_lbn_ follow the rule that a block should be allocated near its inode */ return blocknr ? blocknr : - (int32_t)(ip->i_block_group * + (e2fs_daddr_t)(ip->i_block_group * EXT2_BLOCKS_PER_GROUP(ip->i_e2fs)) + ip->i_e2fs->e2fs->e2fs_first_dblock; } @@ -955,7 +956,7 @@ gotit: * */ void -ext2_blkfree(struct inode *ip, int32_t bno, long size) +ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long size) { struct m_ext2fs *fs; struct buf *bp; Modified: head/sys/fs/ext2fs/ext2_balloc.c ============================================================================== --- head/sys/fs/ext2fs/ext2_balloc.c Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_balloc.c Tue Aug 13 15:40:43 2013 (r254283) @@ -65,8 +65,8 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t struct buf *bp, *nbp; struct vnode *vp = ITOV(ip); struct indir indirs[NIADDR + 2]; - uint32_t nb, newb; - int32_t *bap, pref; + e4fs_daddr_t nb, newb; + e2fs_daddr_t *bap, pref; int osize, nsize, num, i, error; *bpp = NULL; @@ -195,7 +195,7 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t brelse(bp); return (error); } - bap = (int32_t *)bp->b_data; + bap = (e2fs_daddr_t *)bp->b_data; nb = bap[indirs[i].in_off]; if (i == num) break; Modified: head/sys/fs/ext2fs/ext2_bmap.c ============================================================================== --- head/sys/fs/ext2fs/ext2_bmap.c Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_bmap.c Tue Aug 13 15:40:43 2013 (r254283) @@ -62,7 +62,7 @@ static int ext4_bmapext(struct vnode *, int ext2_bmap(struct vop_bmap_args *ap) { - int64_t blkno; + daddr_t blkno; int error; /* @@ -139,7 +139,7 @@ ext4_bmapext(struct vnode *vp, int32_t b */ int -ext2_bmaparray(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb) +ext2_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, int *runp, int *runb) { struct inode *ip; struct buf *bp; @@ -182,7 +182,7 @@ ext2_bmaparray(struct vnode *vp, int32_t if (*bnp == 0) { *bnp = -1; } else if (runp) { - int32_t bnb = bn; + daddr_t bnb = bn; for (++bn; bn < NDADDR && *runp < maxrun && is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]); ++bn, ++*runp); @@ -190,7 +190,7 @@ ext2_bmaparray(struct vnode *vp, int32_t if (runb && (bn > 0)) { for (--bn; (bn >= 0) && (*runb < maxrun) && is_sequential(ump, ip->i_db[bn], - ip->i_db[bn+1]); + ip->i_db[bn + 1]); --bn, ++*runb); } } @@ -239,19 +239,20 @@ ext2_bmaparray(struct vnode *vp, int32_t } } - daddr = ((int32_t *)bp->b_data)[ap->in_off]; + daddr = ((e2fs_daddr_t *)bp->b_data)[ap->in_off]; if (num == 1 && daddr && runp) { for (bn = ap->in_off + 1; bn < MNINDIR(ump) && *runp < maxrun && is_sequential(ump, - ((int32_t *)bp->b_data)[bn - 1], - ((int32_t *)bp->b_data)[bn]); + ((e2fs_daddr_t *)bp->b_data)[bn - 1], + ((e2fs_daddr_t *)bp->b_data)[bn]); ++bn, ++*runp); bn = ap->in_off; if (runb && bn) { for (--bn; bn >= 0 && *runb < maxrun && - is_sequential(ump, ((int32_t *)bp->b_data)[bn], - ((int32_t *)bp->b_data)[bn+1]); + is_sequential(ump, + ((e2fs_daddr_t *)bp->b_data)[bn], + ((e2fs_daddr_t *)bp->b_data)[bn + 1]); --bn, ++*runb); } } @@ -287,7 +288,7 @@ ext2_bmaparray(struct vnode *vp, int32_t * once with the offset into the page itself. */ int -ext2_getlbns(struct vnode *vp, int32_t bn, struct indir *ap, int *nump) +ext2_getlbns(struct vnode *vp, daddr_t bn, struct indir *ap, int *nump) { long blockcnt; e2fs_lbn_t metalbn, realbn; Modified: head/sys/fs/ext2fs/ext2_extern.h ============================================================================== --- head/sys/fs/ext2fs/ext2_extern.h Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_extern.h Tue Aug 13 15:40:43 2013 (r254283) @@ -49,24 +49,24 @@ struct vfsconf; struct vnode; int ext2_add_entry(struct vnode *, struct ext2fs_direct_2 *); -int ext2_alloc(struct inode *, - int32_t, int32_t, int, struct ucred *, int32_t *); +int ext2_alloc(struct inode *, daddr_t, e4fs_daddr_t, int, + struct ucred *, e4fs_daddr_t *); int ext2_balloc(struct inode *, e2fs_lbn_t, int, struct ucred *, struct buf **, int); int ext2_blkatoff(struct vnode *, off_t, char **, struct buf **); -void ext2_blkfree(struct inode *, int32_t, long); -int32_t ext2_blkpref(struct inode *, e2fs_lbn_t, int, int32_t *, int32_t); +void ext2_blkfree(struct inode *, e4fs_daddr_t, long); +e4fs_daddr_t ext2_blkpref(struct inode *, e2fs_lbn_t, int, e2fs_daddr_t *, + e2fs_daddr_t); int ext2_bmap(struct vop_bmap_args *); -int ext2_bmaparray(struct vnode *, int32_t, int64_t *, int *, int *); +int ext2_bmaparray(struct vnode *, daddr_t, daddr_t *, int *, int *); void ext2_clusteracct(struct m_ext2fs *, char *, int, daddr_t, int); void ext2_dirbad(struct inode *ip, doff_t offset, char *how); void ext2_ei2i(struct ext2fs_dinode *, struct inode *); -int ext2_getlbns(struct vnode *, int32_t, struct indir *, int *); +int ext2_getlbns(struct vnode *, daddr_t, struct indir *, int *); void ext2_i2ei(struct inode *, struct ext2fs_dinode *); void ext2_itimes(struct vnode *vp); int ext2_reallocblks(struct vop_reallocblks_args *); int ext2_reclaim(struct vop_reclaim_args *); -void ext2_setblock(struct m_ext2fs *, u_char *, int32_t); int ext2_truncate(struct vnode *, off_t, int, struct ucred *, struct thread *); int ext2_update(struct vnode *, int); int ext2_valloc(struct vnode *, int, struct ucred *, struct vnode **); Modified: head/sys/fs/ext2fs/ext2_inode.c ============================================================================== --- head/sys/fs/ext2fs/ext2_inode.c Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_inode.c Tue Aug 13 15:40:43 2013 (r254283) @@ -54,8 +54,8 @@ #include <fs/ext2fs/fs.h> #include <fs/ext2fs/ext2_extern.h> -static int ext2_indirtrunc(struct inode *, int32_t, int32_t, int32_t, int, - long *); +static int ext2_indirtrunc(struct inode *, daddr_t, daddr_t, + daddr_t, int, e4fs_daddr_t *); /* * Update the access, modified, and inode change times as specified by the @@ -119,7 +119,7 @@ ext2_truncate(struct vnode *vp, off_t le struct m_ext2fs *fs; struct buf *bp; int offset, size, level; - long count, nblocks, blocksreleased = 0; + e4fs_daddr_t count, nblocks, blocksreleased = 0; int error, i, allerror; off_t osize; @@ -356,16 +356,16 @@ done: */ static int -ext2_indirtrunc(struct inode *ip, int32_t lbn, int32_t dbn, int32_t lastbn, - int level, long *countp) +ext2_indirtrunc(struct inode *ip, daddr_t lbn, daddr_t dbn, + daddr_t lastbn, int level, e4fs_daddr_t *countp) { struct buf *bp; struct m_ext2fs *fs = ip->i_e2fs; struct vnode *vp; - int32_t *bap, *copy, nb, nlbn, last; - long blkcount, factor; - int i, nblocks, blocksreleased = 0; - int error = 0, allerror = 0; + e2fs_daddr_t *bap, *copy; + int i, nblocks, error = 0, allerror = 0; + e2fs_lbn_t nb, nlbn, last; + e4fs_daddr_t blkcount, factor, blocksreleased = 0; /* * Calculate index in current block of last @@ -405,11 +405,11 @@ ext2_indirtrunc(struct inode *ip, int32_ return (error); } - bap = (int32_t *)bp->b_data; + bap = (e2fs_daddr_t *)bp->b_data; copy = malloc(fs->e2fs_bsize, M_TEMP, M_WAITOK); bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->e2fs_bsize); bzero((caddr_t)&bap[last + 1], - (u_int)(NINDIR(fs) - (last + 1)) * sizeof(int32_t)); + (NINDIR(fs) - (last + 1)) * sizeof(e2fs_daddr_t)); if (last == -1) bp->b_flags |= B_INVAL; if (DOINGASYNC(vp)) { Modified: head/sys/fs/ext2fs/ext2_subr.c ============================================================================== --- head/sys/fs/ext2fs/ext2_subr.c Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_subr.c Tue Aug 13 15:40:43 2013 (r254283) @@ -135,7 +135,7 @@ void ext2_checkoverlap(struct buf *bp, struct inode *ip) { struct buf *ebp, *ep; - int32_t start, last; + e4fs_daddr_t start, last; struct vnode *vp; ebp = &buf[nbuf]; Modified: head/sys/fs/ext2fs/ext2_vnops.c ============================================================================== --- head/sys/fs/ext2fs/ext2_vnops.c Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/ext2_vnops.c Tue Aug 13 15:40:43 2013 (r254283) @@ -1329,7 +1329,7 @@ ext2_strategy(struct vop_strategy_args * struct vnode *vp = ap->a_vp; struct inode *ip; struct bufobj *bo; - int64_t blkno; + daddr_t blkno; int error; ip = VTOI(vp); Modified: head/sys/fs/ext2fs/inode.h ============================================================================== --- head/sys/fs/ext2fs/inode.h Tue Aug 13 13:40:31 2013 (r254282) +++ head/sys/fs/ext2fs/inode.h Tue Aug 13 15:40:43 2013 (r254283) @@ -54,9 +54,11 @@ #define NIADDR 3 /* Indirect addresses in inode. */ /* - * The size of physical and logical block numbers and time fields in UFS. + * The size of physical and logical block numbers in EXT2FS. */ -typedef int32_t e2fs_lbn_t; +typedef uint32_t e2fs_daddr_t; +typedef int64_t e2fs_lbn_t; +typedef int64_t e4fs_daddr_t; /* * The inode is used to describe each active (or recently active) file in the
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308131540.r7DFehRl071120>