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 --- 23 unchanged lines hidden (view full) --- 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)ffs_inode.c 8.5 (Berkeley) 12/30/93 |
40 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_inode.c 96877 2002-05-18 19:12:38Z iedowse $ |
41 */ 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/mount.h> 46#include <sys/bio.h> 47#include <sys/buf.h> 48#include <sys/vnode.h> --- 4 unchanged lines hidden (view full) --- 53 54#include <gnu/ext2fs/inode.h> 55#include <gnu/ext2fs/ext2_mount.h> 56#include <gnu/ext2fs/ext2_fs.h> 57#include <gnu/ext2fs/ext2_fs_sb.h> 58#include <gnu/ext2fs/fs.h> 59#include <gnu/ext2fs/ext2_extern.h> 60 |
61static int ext2_indirtrunc(struct inode *, int32_t, int32_t, int32_t, int, |
62 long *); 63 64/* 65 * Update the access, modified, and inode change times as specified by the 66 * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. Write the inode 67 * to disk if the IN_MODIFIED flag is set (it may be set initially, or by 68 * the timestamp update). The IN_LAZYMOD flag is set to force a write 69 * later if not now. If we write now, then clear both IN_MODIFIED and --- 49 unchanged lines hidden (view full) --- 119ext2_truncate(vp, length, flags, cred, td) 120 struct vnode *vp; 121 off_t length; 122 int flags; 123 struct ucred *cred; 124 struct thread *td; 125{ 126 struct vnode *ovp = vp; |
127 int32_t lastblock; |
128 struct inode *oip; |
129 int32_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR]; 130 int32_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR]; |
131 struct ext2_sb_info *fs; 132 struct buf *bp; 133 int offset, size, level; 134 long count, nblocks, blocksreleased = 0; 135 int aflags, error, i, allerror; 136 off_t osize; 137/* 138printf("ext2_truncate called %d to %d\n", VTOI(ovp)->i_number, length); --- 216 unchanged lines hidden (view full) --- 355 * blocks. 356 * 357 * NB: triple indirect blocks are untested. 358 */ 359 360static int 361ext2_indirtrunc(ip, lbn, dbn, lastbn, level, countp) 362 struct inode *ip; |
363 int32_t lbn, lastbn; 364 int32_t dbn; |
365 int level; 366 long *countp; 367{ 368 struct buf *bp; 369 struct ext2_sb_info *fs = ip->i_e2fs; 370 struct vnode *vp; |
371 int32_t *bap, *copy, nb, nlbn, last; |
372 long blkcount, factor; 373 int i, nblocks, blocksreleased = 0; 374 int error = 0, allerror = 0; 375 376 /* 377 * Calculate index in current block of last 378 * block to be kept. -1 indicates the entire 379 * block so we need not calculate the index. --- 26 unchanged lines hidden (view full) --- 406 error = bufwait(bp); 407 } 408 if (error) { 409 brelse(bp); 410 *countp = 0; 411 return (error); 412 } 413 |
414 bap = (int32_t *)bp->b_data; 415 MALLOC(copy, int32_t *, fs->s_blocksize, M_TEMP, M_WAITOK); |
416 bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->s_blocksize); 417 bzero((caddr_t)&bap[last + 1], |
418 (u_int)(NINDIR(fs) - (last + 1)) * sizeof (int32_t)); |
419 if (last == -1) 420 bp->b_flags |= B_INVAL; 421 error = bwrite(bp); 422 if (error) 423 allerror = error; 424 bap = copy; 425 426 /* 427 * Recursively free totally unused blocks. 428 */ 429 for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last; 430 i--, nlbn += factor) { 431 nb = bap[i]; 432 if (nb == 0) 433 continue; 434 if (level > SINGLE) { 435 if ((error = ext2_indirtrunc(ip, nlbn, |
436 fsbtodb(fs, nb), (int32_t)-1, level - 1, &blkcount)) != 0) |
437 allerror = error; 438 blocksreleased += blkcount; 439 } 440 ext2_blkfree(ip, nb, fs->s_blocksize); 441 blocksreleased += nblocks; 442 } 443 444 /* --- 107 unchanged lines hidden --- |