ext2_inode.c (187395) | ext2_inode.c (202283) |
---|---|
1/*- 2 * modified for Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/*- 8 * Copyright (c) 1982, 1986, 1989, 1993 --- 19 unchanged lines hidden (view full) --- 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)ffs_inode.c 8.5 (Berkeley) 12/30/93 | 1/*- 2 * modified for Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/*- 8 * Copyright (c) 1982, 1986, 1989, 1993 --- 19 unchanged lines hidden (view full) --- 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)ffs_inode.c 8.5 (Berkeley) 12/30/93 |
36 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_inode.c 187395 2009-01-18 14:04:56Z stas $ | 36 * $FreeBSD: head/sys/fs/ext2fs/ext2_inode.c 202283 2010-01-14 14:30:54Z lulf $ |
37 */ 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/mount.h> 42#include <sys/bio.h> 43#include <sys/buf.h> 44#include <sys/vnode.h> 45#include <sys/malloc.h> 46 47#include <vm/vm.h> 48#include <vm/vm_extern.h> 49 | 37 */ 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/mount.h> 42#include <sys/bio.h> 43#include <sys/buf.h> 44#include <sys/vnode.h> 45#include <sys/malloc.h> 46 47#include <vm/vm.h> 48#include <vm/vm_extern.h> 49 |
50#include <gnu/fs/ext2fs/inode.h> 51#include <gnu/fs/ext2fs/ext2_mount.h> 52#include <gnu/fs/ext2fs/ext2_fs.h> 53#include <gnu/fs/ext2fs/ext2_fs_sb.h> 54#include <gnu/fs/ext2fs/fs.h> 55#include <gnu/fs/ext2fs/ext2_extern.h> | 50#include 51#include 52#include <fs/ext2fs/ext2fs.h> 53#include <fs/ext2fs/fs.h> 54#include <fs/ext2fs/ext2_extern.h> |
56 57static int ext2_indirtrunc(struct inode *, int32_t, int32_t, int32_t, int, 58 long *); 59 60/* 61 * Update the access, modified, and inode change times as specified by the 62 * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. Write the inode 63 * to disk if the IN_MODIFIED flag is set (it may be set initially, or by 64 * the timestamp update). The IN_LAZYMOD flag is set to force a write 65 * later if not now. If we write now, then clear both IN_MODIFIED and 66 * IN_LAZYMOD to reflect the presumably successful write, and if waitfor is 67 * set, then wait for the write to complete. 68 */ 69int 70ext2_update(vp, waitfor) 71 struct vnode *vp; 72 int waitfor; 73{ | 55 56static int ext2_indirtrunc(struct inode *, int32_t, int32_t, int32_t, int, 57 long *); 58 59/* 60 * Update the access, modified, and inode change times as specified by the 61 * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. Write the inode 62 * to disk if the IN_MODIFIED flag is set (it may be set initially, or by 63 * the timestamp update). The IN_LAZYMOD flag is set to force a write 64 * later if not now. If we write now, then clear both IN_MODIFIED and 65 * IN_LAZYMOD to reflect the presumably successful write, and if waitfor is 66 * set, then wait for the write to complete. 67 */ 68int 69ext2_update(vp, waitfor) 70 struct vnode *vp; 71 int waitfor; 72{ |
74 struct ext2_sb_info *fs; | 73 struct m_ext2fs *fs; |
75 struct buf *bp; 76 struct inode *ip; 77 int error; 78 | 74 struct buf *bp; 75 struct inode *ip; 76 int error; 77 |
78 ASSERT_VOP_ELOCKED(vp, "ext2_update"); |
|
79 ext2_itimes(vp); 80 ip = VTOI(vp); | 79 ext2_itimes(vp); 80 ip = VTOI(vp); |
81 if ((ip->i_flag & IN_MODIFIED) == 0) | 81 if ((ip->i_flag & IN_MODIFIED) == 0 && waitfor == 0) |
82 return (0); | 82 return (0); |
83 ip->i_flag &= ~(IN_LAZYMOD | IN_MODIFIED); 84 if (vp->v_mount->mnt_flag & MNT_RDONLY) 85 return (0); | 83 ip->i_flag &= ~(IN_LAZYACCESS | IN_LAZYMOD | IN_MODIFIED); |
86 fs = ip->i_e2fs; | 84 fs = ip->i_e2fs; |
85 if(fs->e2fs_ronly) 86 return (0); |
|
87 if ((error = bread(ip->i_devvp, 88 fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), | 87 if ((error = bread(ip->i_devvp, 88 fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), |
89 (int)fs->s_blocksize, NOCRED, &bp)) != 0) { | 89 (int)fs->e2fs_bsize, NOCRED, &bp)) != 0) { |
90 brelse(bp); 91 return (error); 92 } | 90 brelse(bp); 91 return (error); 92 } |
93 ext2_i2ei(ip, (struct ext2_inode *)((char *)bp->b_data + | 93 ext2_i2ei(ip, (struct ext2fs_dinode *)((char *)bp->b_data + |
94 EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number))); 95 if (waitfor && (vp->v_mount->mnt_kern_flag & MNTK_ASYNC) == 0) 96 return (bwrite(bp)); 97 else { 98 bdwrite(bp); 99 return (0); 100 } 101} --- 13 unchanged lines hidden (view full) --- 115 struct ucred *cred; 116 struct thread *td; 117{ 118 struct vnode *ovp = vp; 119 int32_t lastblock; 120 struct inode *oip; 121 int32_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR]; 122 int32_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR]; | 94 EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number))); 95 if (waitfor && (vp->v_mount->mnt_kern_flag & MNTK_ASYNC) == 0) 96 return (bwrite(bp)); 97 else { 98 bdwrite(bp); 99 return (0); 100 } 101} --- 13 unchanged lines hidden (view full) --- 115 struct ucred *cred; 116 struct thread *td; 117{ 118 struct vnode *ovp = vp; 119 int32_t lastblock; 120 struct inode *oip; 121 int32_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR]; 122 int32_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR]; |
123 struct ext2_sb_info *fs; | 123 struct bufobj *bo; 124 struct m_ext2fs *fs; |
124 struct buf *bp; 125 int offset, size, level; 126 long count, nblocks, blocksreleased = 0; 127 int aflags, error, i, allerror; 128 off_t osize; | 125 struct buf *bp; 126 int offset, size, level; 127 long count, nblocks, blocksreleased = 0; 128 int aflags, error, i, allerror; 129 off_t osize; |
129/* 130printf("ext2_truncate called %d to %d\n", VTOI(ovp)->i_number, length); 131*/ /* 132 * negative file sizes will totally break the code below and 133 * are not meaningful anyways. 134 */ 135 if (length < 0) 136 return EFBIG; | |
137 138 oip = VTOI(ovp); | 130 131 oip = VTOI(ovp); |
132 bo = &ovp->v_bufobj; 133 134 ASSERT_VOP_LOCKED(vp, "ext2_truncate"); 135 136 if (length < 0) 137 return (EINVAL); 138 |
|
139 if (ovp->v_type == VLNK && 140 oip->i_size < ovp->v_mount->mnt_maxsymlinklen) { 141#ifdef DIAGNOSTIC 142 if (length != 0) 143 panic("ext2_truncate: partial truncate of symlink"); 144#endif 145 bzero((char *)&oip->i_shortlink, (u_int)oip->i_size); 146 oip->i_size = 0; 147 oip->i_flag |= IN_CHANGE | IN_UPDATE; 148 return (ext2_update(ovp, 1)); 149 } 150 if (oip->i_size == length) { 151 oip->i_flag |= IN_CHANGE | IN_UPDATE; 152 return (ext2_update(ovp, 0)); 153 } 154 fs = oip->i_e2fs; 155 osize = oip->i_size; | 139 if (ovp->v_type == VLNK && 140 oip->i_size < ovp->v_mount->mnt_maxsymlinklen) { 141#ifdef DIAGNOSTIC 142 if (length != 0) 143 panic("ext2_truncate: partial truncate of symlink"); 144#endif 145 bzero((char *)&oip->i_shortlink, (u_int)oip->i_size); 146 oip->i_size = 0; 147 oip->i_flag |= IN_CHANGE | IN_UPDATE; 148 return (ext2_update(ovp, 1)); 149 } 150 if (oip->i_size == length) { 151 oip->i_flag |= IN_CHANGE | IN_UPDATE; 152 return (ext2_update(ovp, 0)); 153 } 154 fs = oip->i_e2fs; 155 osize = oip->i_size; |
156 ext2_discard_prealloc(oip); | |
157 /* 158 * Lengthen the size of the file. We must ensure that the 159 * last byte of the file is allocated. Since the smallest | 156 /* 157 * Lengthen the size of the file. We must ensure that the 158 * last byte of the file is allocated. Since the smallest |
160 * value of oszie is 0, length will be at least 1. | 159 * value of osize is 0, length will be at least 1. |
161 */ 162 if (osize < length) { | 160 */ 161 if (osize < length) { |
163 if (length > oip->i_e2fs->fs_maxfilesize) | 162 if (length > oip->i_e2fs->e2fs_maxfilesize) |
164 return (EFBIG); | 163 return (EFBIG); |
164 vnode_pager_setsize(ovp, length); |
|
165 offset = blkoff(fs, length - 1); 166 lbn = lblkno(fs, length - 1); 167 aflags = B_CLRBUF; 168 if (flags & IO_SYNC) 169 aflags |= B_SYNC; | 165 offset = blkoff(fs, length - 1); 166 lbn = lblkno(fs, length - 1); 167 aflags = B_CLRBUF; 168 if (flags & IO_SYNC) 169 aflags |= B_SYNC; |
170 vnode_pager_setsize(ovp, length); 171 if ((error = ext2_balloc(oip, lbn, offset + 1, cred, &bp, 172 aflags)) != 0) | 170 error = ext2_balloc(oip, lbn, offset + 1, cred, &bp, aflags); 171 if (error) { 172 vnode_pager_setsize(vp, osize); |
173 return (error); | 173 return (error); |
174 } |
|
174 oip->i_size = length; | 175 oip->i_size = length; |
175 if (aflags & IO_SYNC) | 176 if (bp->b_bufsize == fs->e2fs_bsize) 177 bp->b_flags |= B_CLUSTEROK; 178 if (aflags & B_SYNC) |
176 bwrite(bp); | 179 bwrite(bp); |
180 else if (ovp->v_mount->mnt_flag & MNT_ASYNC) 181 bdwrite(bp); |
|
177 else 178 bawrite(bp); 179 oip->i_flag |= IN_CHANGE | IN_UPDATE; 180 return (ext2_update(ovp, 1)); 181 } 182 /* 183 * Shorten the size of the file. If the file is not being 184 * truncated to a block boundry, the contents of the --- 5 unchanged lines hidden (view full) --- 190 offset = blkoff(fs, length); 191 if (offset == 0) { 192 oip->i_size = length; 193 } else { 194 lbn = lblkno(fs, length); 195 aflags = B_CLRBUF; 196 if (flags & IO_SYNC) 197 aflags |= B_SYNC; | 182 else 183 bawrite(bp); 184 oip->i_flag |= IN_CHANGE | IN_UPDATE; 185 return (ext2_update(ovp, 1)); 186 } 187 /* 188 * Shorten the size of the file. If the file is not being 189 * truncated to a block boundry, the contents of the --- 5 unchanged lines hidden (view full) --- 195 offset = blkoff(fs, length); 196 if (offset == 0) { 197 oip->i_size = length; 198 } else { 199 lbn = lblkno(fs, length); 200 aflags = B_CLRBUF; 201 if (flags & IO_SYNC) 202 aflags |= B_SYNC; |
198 if ((error = ext2_balloc(oip, lbn, offset, cred, &bp, 199 aflags)) != 0) | 203 error = ext2_balloc(oip, lbn, offset, cred, &bp, aflags); 204 if (error) |
200 return (error); 201 oip->i_size = length; 202 size = blksize(fs, oip, lbn); 203 bzero((char *)bp->b_data + offset, (u_int)(size - offset)); 204 allocbuf(bp, size); | 205 return (error); 206 oip->i_size = length; 207 size = blksize(fs, oip, lbn); 208 bzero((char *)bp->b_data + offset, (u_int)(size - offset)); 209 allocbuf(bp, size); |
205 if (aflags & IO_SYNC) | 210 if (bp->b_bufsize == fs->e2fs_bsize) 211 bp->b_flags |= B_CLUSTEROK; 212 if (aflags & B_SYNC) |
206 bwrite(bp); | 213 bwrite(bp); |
214 else if (ovp->v_mount->mnt_flag & MNT_ASYNC) 215 bdwrite(bp); |
|
207 else 208 bawrite(bp); 209 } 210 /* 211 * Calculate index into inode's block list of 212 * last direct and indirect blocks (if any) 213 * which we want to keep. Lastblock is -1 when 214 * the file is truncated to 0. 215 */ | 216 else 217 bawrite(bp); 218 } 219 /* 220 * Calculate index into inode's block list of 221 * last direct and indirect blocks (if any) 222 * which we want to keep. Lastblock is -1 when 223 * the file is truncated to 0. 224 */ |
216 lastblock = lblkno(fs, length + fs->s_blocksize - 1) - 1; | 225 lastblock = lblkno(fs, length + fs->e2fs_bsize - 1) - 1; |
217 lastiblock[SINGLE] = lastblock - NDADDR; 218 lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs); 219 lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs); | 226 lastiblock[SINGLE] = lastblock - NDADDR; 227 lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs); 228 lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs); |
220 nblocks = btodb(fs->s_blocksize); | 229 nblocks = btodb(fs->e2fs_bsize); |
221 /* 222 * Update file and block pointers on disk before we start freeing 223 * blocks. If we crash before free'ing blocks below, the blocks 224 * will be returned to the free list. lastiblock values are also 225 * normalized to -1 for calls to ext2_indirtrunc below. 226 */ 227 bcopy((caddr_t)&oip->i_db[0], (caddr_t)oldblks, sizeof oldblks); 228 for (level = TRIPLE; level >= SINGLE; level--) --- 10 unchanged lines hidden (view full) --- 239 * Having written the new inode to disk, save its new configuration 240 * and put back the old block pointers long enough to process them. 241 * Note that we save the new block configuration so we can check it 242 * when we are done. 243 */ 244 bcopy((caddr_t)&oip->i_db[0], (caddr_t)newblks, sizeof newblks); 245 bcopy((caddr_t)oldblks, (caddr_t)&oip->i_db[0], sizeof oldblks); 246 oip->i_size = osize; | 230 /* 231 * Update file and block pointers on disk before we start freeing 232 * blocks. If we crash before free'ing blocks below, the blocks 233 * will be returned to the free list. lastiblock values are also 234 * normalized to -1 for calls to ext2_indirtrunc below. 235 */ 236 bcopy((caddr_t)&oip->i_db[0], (caddr_t)oldblks, sizeof oldblks); 237 for (level = TRIPLE; level >= SINGLE; level--) --- 10 unchanged lines hidden (view full) --- 248 * Having written the new inode to disk, save its new configuration 249 * and put back the old block pointers long enough to process them. 250 * Note that we save the new block configuration so we can check it 251 * when we are done. 252 */ 253 bcopy((caddr_t)&oip->i_db[0], (caddr_t)newblks, sizeof newblks); 254 bcopy((caddr_t)oldblks, (caddr_t)&oip->i_db[0], sizeof oldblks); 255 oip->i_size = osize; |
247 error = vtruncbuf(ovp, cred, td, length, (int)fs->s_blocksize); | 256 error = vtruncbuf(ovp, cred, td, length, (int)fs->e2fs_bsize); |
248 if (error && (allerror == 0)) 249 allerror = error; | 257 if (error && (allerror == 0)) 258 allerror = error; |
250 | 259 vnode_pager_setsize(ovp, length); 260 |
251 /* 252 * Indirect blocks first. 253 */ 254 indir_lbn[SINGLE] = -NDADDR; 255 indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) - 1; 256 indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1; 257 for (level = TRIPLE; level >= SINGLE; level--) { 258 bn = oip->i_ib[level]; 259 if (bn != 0) { 260 error = ext2_indirtrunc(oip, indir_lbn[level], 261 fsbtodb(fs, bn), lastiblock[level], level, &count); 262 if (error) 263 allerror = error; 264 blocksreleased += count; 265 if (lastiblock[level] < 0) { 266 oip->i_ib[level] = 0; | 261 /* 262 * Indirect blocks first. 263 */ 264 indir_lbn[SINGLE] = -NDADDR; 265 indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) - 1; 266 indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1; 267 for (level = TRIPLE; level >= SINGLE; level--) { 268 bn = oip->i_ib[level]; 269 if (bn != 0) { 270 error = ext2_indirtrunc(oip, indir_lbn[level], 271 fsbtodb(fs, bn), lastiblock[level], level, &count); 272 if (error) 273 allerror = error; 274 blocksreleased += count; 275 if (lastiblock[level] < 0) { 276 oip->i_ib[level] = 0; |
267 ext2_blkfree(oip, bn, fs->s_frag_size); | 277 ext2_blkfree(oip, bn, fs->e2fs_fsize); |
268 blocksreleased += nblocks; 269 } 270 } 271 if (lastiblock[level] >= 0) 272 goto done; 273 } 274 275 /* --- 44 unchanged lines hidden (view full) --- 320done: 321#ifdef DIAGNOSTIC 322 for (level = SINGLE; level <= TRIPLE; level++) 323 if (newblks[NDADDR + level] != oip->i_ib[level]) 324 panic("itrunc1"); 325 for (i = 0; i < NDADDR; i++) 326 if (newblks[i] != oip->i_db[i]) 327 panic("itrunc2"); | 278 blocksreleased += nblocks; 279 } 280 } 281 if (lastiblock[level] >= 0) 282 goto done; 283 } 284 285 /* --- 44 unchanged lines hidden (view full) --- 330done: 331#ifdef DIAGNOSTIC 332 for (level = SINGLE; level <= TRIPLE; level++) 333 if (newblks[NDADDR + level] != oip->i_ib[level]) 334 panic("itrunc1"); 335 for (i = 0; i < NDADDR; i++) 336 if (newblks[i] != oip->i_db[i]) 337 panic("itrunc2"); |
328 VI_LOCK(ovp); 329 if (length == 0 && (ovp->v_bufobj.bo_dirty.bv_cnt != 0 || 330 ovp->v_bufobj.bo_clean.bv_cnt != 0)) | 338 BO_LOCK(bo); 339 if (length == 0 && (bo->bo_dirty.bv_cnt != 0 || 340 bo->bo_clean.bv_cnt != 0)) |
331 panic("itrunc3"); | 341 panic("itrunc3"); |
332 VI_UNLOCK(ovp); | 342 BO_UNLOCK(bo); |
333#endif /* DIAGNOSTIC */ 334 /* 335 * Put back the real size. 336 */ 337 oip->i_size = length; 338 oip->i_blocks -= blocksreleased; 339 if (oip->i_blocks < 0) /* sanity */ 340 oip->i_blocks = 0; --- 16 unchanged lines hidden (view full) --- 357ext2_indirtrunc(ip, lbn, dbn, lastbn, level, countp) 358 struct inode *ip; 359 int32_t lbn, lastbn; 360 int32_t dbn; 361 int level; 362 long *countp; 363{ 364 struct buf *bp; | 343#endif /* DIAGNOSTIC */ 344 /* 345 * Put back the real size. 346 */ 347 oip->i_size = length; 348 oip->i_blocks -= blocksreleased; 349 if (oip->i_blocks < 0) /* sanity */ 350 oip->i_blocks = 0; --- 16 unchanged lines hidden (view full) --- 367ext2_indirtrunc(ip, lbn, dbn, lastbn, level, countp) 368 struct inode *ip; 369 int32_t lbn, lastbn; 370 int32_t dbn; 371 int level; 372 long *countp; 373{ 374 struct buf *bp; |
365 struct ext2_sb_info *fs = ip->i_e2fs; | 375 struct m_ext2fs *fs = ip->i_e2fs; |
366 struct vnode *vp; 367 int32_t *bap, *copy, nb, nlbn, last; 368 long blkcount, factor; 369 int i, nblocks, blocksreleased = 0; 370 int error = 0, allerror = 0; 371 372 /* 373 * Calculate index in current block of last 374 * block to be kept. -1 indicates the entire 375 * block so we need not calculate the index. 376 */ 377 factor = 1; 378 for (i = SINGLE; i < level; i++) 379 factor *= NINDIR(fs); 380 last = lastbn; 381 if (lastbn > 0) 382 last /= factor; | 376 struct vnode *vp; 377 int32_t *bap, *copy, nb, nlbn, last; 378 long blkcount, factor; 379 int i, nblocks, blocksreleased = 0; 380 int error = 0, allerror = 0; 381 382 /* 383 * Calculate index in current block of last 384 * block to be kept. -1 indicates the entire 385 * block so we need not calculate the index. 386 */ 387 factor = 1; 388 for (i = SINGLE; i < level; i++) 389 factor *= NINDIR(fs); 390 last = lastbn; 391 if (lastbn > 0) 392 last /= factor; |
383 nblocks = btodb(fs->s_blocksize); | 393 nblocks = btodb(fs->e2fs_bsize); |
384 /* 385 * Get buffer of block pointers, zero those entries corresponding 386 * to blocks to be free'd, and update on disk copy first. Since 387 * double(triple) indirect before single(double) indirect, calls 388 * to bmap on these blocks will fail. However, we already have 389 * the on disk address, so we have to set the b_blkno field 390 * explicitly instead of letting bread do everything for us. 391 */ 392 vp = ITOV(ip); | 394 /* 395 * Get buffer of block pointers, zero those entries corresponding 396 * to blocks to be free'd, and update on disk copy first. Since 397 * double(triple) indirect before single(double) indirect, calls 398 * to bmap on these blocks will fail. However, we already have 399 * the on disk address, so we have to set the b_blkno field 400 * explicitly instead of letting bread do everything for us. 401 */ 402 vp = ITOV(ip); |
393 bp = getblk(vp, lbn, (int)fs->s_blocksize, 0, 0, 0); | 403 bp = getblk(vp, lbn, (int)fs->e2fs_bsize, 0, 0, 0); |
394 if (bp->b_flags & (B_DONE | B_DELWRI)) { 395 } else { 396 bp->b_iocmd = BIO_READ; 397 if (bp->b_bcount > bp->b_bufsize) 398 panic("ext2_indirtrunc: bad buffer size"); 399 bp->b_blkno = dbn; 400 vfs_busy_pages(bp, 0); 401 bp->b_iooffset = dbtob(bp->b_blkno); 402 bstrategy(bp); 403 error = bufwait(bp); 404 } 405 if (error) { 406 brelse(bp); 407 *countp = 0; 408 return (error); 409 } 410 411 bap = (int32_t *)bp->b_data; | 404 if (bp->b_flags & (B_DONE | B_DELWRI)) { 405 } else { 406 bp->b_iocmd = BIO_READ; 407 if (bp->b_bcount > bp->b_bufsize) 408 panic("ext2_indirtrunc: bad buffer size"); 409 bp->b_blkno = dbn; 410 vfs_busy_pages(bp, 0); 411 bp->b_iooffset = dbtob(bp->b_blkno); 412 bstrategy(bp); 413 error = bufwait(bp); 414 } 415 if (error) { 416 brelse(bp); 417 *countp = 0; 418 return (error); 419 } 420 421 bap = (int32_t *)bp->b_data; |
412 copy = malloc(fs->s_blocksize, M_TEMP, M_WAITOK); 413 bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->s_blocksize); | 422 copy = malloc(fs->e2fs_bsize, M_TEMP, M_WAITOK); 423 bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->e2fs_bsize); |
414 bzero((caddr_t)&bap[last + 1], 415 (u_int)(NINDIR(fs) - (last + 1)) * sizeof (int32_t)); 416 if (last == -1) 417 bp->b_flags |= B_INVAL; 418 error = bwrite(bp); 419 if (error) 420 allerror = error; 421 bap = copy; --- 7 unchanged lines hidden (view full) --- 429 if (nb == 0) 430 continue; 431 if (level > SINGLE) { 432 if ((error = ext2_indirtrunc(ip, nlbn, 433 fsbtodb(fs, nb), (int32_t)-1, level - 1, &blkcount)) != 0) 434 allerror = error; 435 blocksreleased += blkcount; 436 } | 424 bzero((caddr_t)&bap[last + 1], 425 (u_int)(NINDIR(fs) - (last + 1)) * sizeof (int32_t)); 426 if (last == -1) 427 bp->b_flags |= B_INVAL; 428 error = bwrite(bp); 429 if (error) 430 allerror = error; 431 bap = copy; --- 7 unchanged lines hidden (view full) --- 439 if (nb == 0) 440 continue; 441 if (level > SINGLE) { 442 if ((error = ext2_indirtrunc(ip, nlbn, 443 fsbtodb(fs, nb), (int32_t)-1, level - 1, &blkcount)) != 0) 444 allerror = error; 445 blocksreleased += blkcount; 446 } |
437 ext2_blkfree(ip, nb, fs->s_blocksize); | 447 ext2_blkfree(ip, nb, fs->e2fs_bsize); |
438 blocksreleased += nblocks; 439 } 440 441 /* 442 * Recursively free last partial block. 443 */ 444 if (level > SINGLE && lastbn >= 0) { 445 last = lastbn % factor; --- 20 unchanged lines hidden (view full) --- 466 struct thread *a_td; 467 } */ *ap; 468{ 469 struct vnode *vp = ap->a_vp; 470 struct inode *ip = VTOI(vp); 471 struct thread *td = ap->a_td; 472 int mode, error = 0; 473 | 448 blocksreleased += nblocks; 449 } 450 451 /* 452 * Recursively free last partial block. 453 */ 454 if (level > SINGLE && lastbn >= 0) { 455 last = lastbn % factor; --- 20 unchanged lines hidden (view full) --- 476 struct thread *a_td; 477 } */ *ap; 478{ 479 struct vnode *vp = ap->a_vp; 480 struct inode *ip = VTOI(vp); 481 struct thread *td = ap->a_td; 482 int mode, error = 0; 483 |
474 ext2_discard_prealloc(ip); | |
475 if (prtactive && vrefcnt(vp) != 0) 476 vprint("ext2_inactive: pushing active", vp); 477 478 /* 479 * Ignore inodes related to stale file handles. 480 */ 481 if (ip->i_mode == 0) 482 goto out; --- 46 unchanged lines hidden --- | 484 if (prtactive && vrefcnt(vp) != 0) 485 vprint("ext2_inactive: pushing active", vp); 486 487 /* 488 * Ignore inodes related to stale file handles. 489 */ 490 if (ip->i_mode == 0) 491 goto out; --- 46 unchanged lines hidden --- |