From: Matthew Dillon Date: Mon, 14 Sep 2009 05:12:25 +0000 (-0700) Subject: ext2fs - A few bug fixes and syntax adjustments. X-Git-Tag: v2.4.0~15 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/c081fe84e993ade17c9aae5cde4bee2b5614653e ext2fs - A few bug fixes and syntax adjustments. * Primarily fix a brelse that needs to be placed before a vx_put instead of after. And use bqrelse() instead of brelse() when retrieving an inode. * Syntax adjustments. * NOTE: Only part of the FreeBSD patch was applied. Submitted-by: "Pedro F. Giffuni" (GSOC project) --- diff --git a/sys/vfs/gnu/ext2fs/ext2_alloc.c b/sys/vfs/gnu/ext2fs/ext2_alloc.c index 4e6eec8708..a8361bc877 100644 --- a/sys/vfs/gnu/ext2fs/ext2_alloc.c +++ b/sys/vfs/gnu/ext2fs/ext2_alloc.c @@ -449,10 +449,11 @@ ext2_blkpref(struct inode *ip, daddr_t lbn, int indx, daddr_t *bap, { int tmp; - /* if the next block is actually what we thought it is, - then set the goal to what we thought it should be - */ - if(ip->i_next_alloc_block == lbn) + /* + * if the next block is actually what we thought it is, + * then set the goal to what we thought it should be + */ + if (ip->i_next_alloc_block == lbn && ip->i_next_alloc_goal != 0) return ip->i_next_alloc_goal; /* now check whether we were provided with an array that basically @@ -463,9 +464,10 @@ ext2_blkpref(struct inode *ip, daddr_t lbn, int indx, daddr_t *bap, if (bap[tmp]) return bap[tmp]; - /* else let's fall back to the blocknr, or, if there is none, - follow the rule that a block should be allocated near its inode - */ + /* + * else let's fall back to the blocknr, or, if there is none, + * follow the rule that a block should be allocated near its inode + */ return blocknr ? blocknr : (daddr_t)(ip->i_block_group * EXT2_BLOCKS_PER_GROUP(ip->i_e2fs)) + diff --git a/sys/vfs/gnu/ext2fs/ext2_inode.c b/sys/vfs/gnu/ext2fs/ext2_inode.c index 7eb179918f..ca84d4cca1 100644 --- a/sys/vfs/gnu/ext2fs/ext2_inode.c +++ b/sys/vfs/gnu/ext2fs/ext2_inode.c @@ -168,7 +168,7 @@ kprintf("ext2_truncate called %d to %d\n", VTOI(ovp)->i_number, length); /* * Lengthen the size of the file. We must ensure that the * last byte of the file is allocated. Since the smallest - * value of oszie is 0, length will be at least 1. + * value of osize is 0, length will be at least 1. */ if (osize < length) { offset = blkoff(fs, length - 1); @@ -177,9 +177,11 @@ kprintf("ext2_truncate called %d to %d\n", VTOI(ovp)->i_number, length); if (flags & IO_SYNC) aflags |= B_SYNC; vnode_pager_setsize(ovp, length); - if ((error = ext2_balloc(oip, lbn, offset + 1, cred, &bp, - aflags)) != 0) + error = ext2_balloc(oip, lbn, offset + 1, cred, &bp, aflags); + if (error) { + vnode_pager_setsize(ovp, osize); return (error); + } oip->i_size = length; if (aflags & IO_SYNC) bwrite(bp); @@ -204,8 +206,8 @@ kprintf("ext2_truncate called %d to %d\n", VTOI(ovp)->i_number, length); aflags = B_CLRBUF; if (flags & IO_SYNC) aflags |= B_SYNC; - if ((error = ext2_balloc(oip, lbn, offset, cred, &bp, - aflags)) != 0) + error = ext2_balloc(oip, lbn, offset, cred, &bp, aflags); + if (error) return (error); oip->i_size = length; size = blksize(fs, oip, lbn); diff --git a/sys/vfs/gnu/ext2fs/ext2_readwrite.c b/sys/vfs/gnu/ext2fs/ext2_readwrite.c index 7c2cec8fe2..a09592ed03 100644 --- a/sys/vfs/gnu/ext2fs/ext2_readwrite.c +++ b/sys/vfs/gnu/ext2fs/ext2_readwrite.c @@ -138,8 +138,8 @@ ext2_read(struct vop_read_args *ap) break; xfersize = size; } - error = - uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio); + error = uiomove((char *)bp->b_data + blkoffset, + (int)xfersize, uio); if (error) break; @@ -245,8 +245,8 @@ ext2_write(struct vop_write_args *ap) * version. */ flags |= B_CLRBUF; - error = ext2_balloc(ip, - lbn, blkoffset + xfersize, ap->a_cred, &bp, flags); + error = ext2_balloc(ip, lbn, blkoffset + xfersize, + ap->a_cred, &bp, flags); if (error) break; @@ -258,10 +258,10 @@ ext2_write(struct vop_write_args *ap) if (size < xfersize) xfersize = size; - error = - uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio); + error = uiomove((char *)bp->b_data + blkoffset, + (int)xfersize, uio); if ((ioflag & IO_VMIO) && - (LIST_FIRST(&bp->b_dep) == NULL)) /* in ext2fs? */ + LIST_FIRST(&bp->b_dep) == NULL) /* in ext2fs? */ bp->b_flags |= B_RELBUF; if (ioflag & IO_SYNC) { diff --git a/sys/vfs/gnu/ext2fs/ext2_vfsops.c b/sys/vfs/gnu/ext2fs/ext2_vfsops.c index b48a9fa131..09b68c61ca 100644 --- a/sys/vfs/gnu/ext2fs/ext2_vfsops.c +++ b/sys/vfs/gnu/ext2fs/ext2_vfsops.c @@ -1184,8 +1184,8 @@ kprintf("ext2_vget(%d) dbn= %d ", ino, fsbtodb(fs, ino_to_fsba(fs, ino))); * still zero, it will be unlinked and returned to the free * list by vput(). */ - vx_put(vp); brelse(bp); + vx_put(vp); *vpp = NULL; return (error); } @@ -1209,7 +1209,7 @@ kprintf("ext2_vget(%d) dbn= %d ", ino, fsbtodb(fs, ino_to_fsba(fs, ino))); #if 0 ext2_print_inode(ip); #endif - brelse(bp); + bqrelse(bp); /* * Initialize the vnode from the inode, check for aliases.