585
586 ufsvfsp = ip->i_ufsvfs;
587 /*
588 * unnecessary when logging; allocation blocks are kept up-to-date
589 */
590 if (TRANS_ISTRANS(ufsvfsp))
591 return (0);
592
593 fs = ufsvfsp->vfs_fs;
594 bsize = fs->fs_bsize;
595 lbn = (daddr_t)lblkno(fs, ip->i_size - 1);
596 if (lbn < NDADDR)
597 return (0); /* No indirect blocks used */
598 if (lbn < NDADDR + NINDIR(fs)) {
599 /* File has one indirect block. */
600 blkflush(ip->i_dev, (daddr_t)fsbtodb(fs, ip->i_ib[0]));
601 return (0);
602 }
603
604 /* Write out all the first level indirect blocks */
605 for (i = 0; i <= NIADDR; i++) {
606 if ((blkno = ip->i_ib[i]) == 0)
607 continue;
608 blkflush(ip->i_dev, (daddr_t)fsbtodb(fs, blkno));
609 }
610 /* Write out second level of indirect blocks */
611 if ((blkno = ip->i_ib[1]) == 0)
612 return (0);
613 bp = UFS_BREAD(ufsvfsp, ip->i_dev, (daddr_t)fsbtodb(fs, blkno), bsize);
614 if (bp->b_flags & B_ERROR) {
615 brelse(bp);
616 return (EIO);
617 }
618 bap = bp->b_un.b_daddr;
619 clbn = NDADDR + NINDIR(fs);
620 for (i = 0; i < NINDIR(fs); i++) {
621 if (clbn > lbn)
622 break;
623 clbn += NINDIR(fs);
624 if ((blkno = bap[i]) == 0)
625 continue;
|
585
586 ufsvfsp = ip->i_ufsvfs;
587 /*
588 * unnecessary when logging; allocation blocks are kept up-to-date
589 */
590 if (TRANS_ISTRANS(ufsvfsp))
591 return (0);
592
593 fs = ufsvfsp->vfs_fs;
594 bsize = fs->fs_bsize;
595 lbn = (daddr_t)lblkno(fs, ip->i_size - 1);
596 if (lbn < NDADDR)
597 return (0); /* No indirect blocks used */
598 if (lbn < NDADDR + NINDIR(fs)) {
599 /* File has one indirect block. */
600 blkflush(ip->i_dev, (daddr_t)fsbtodb(fs, ip->i_ib[0]));
601 return (0);
602 }
603
604 /* Write out all the first level indirect blocks */
605 for (i = 0; i < NIADDR; i++) {
606 if ((blkno = ip->i_ib[i]) == 0)
607 continue;
608 blkflush(ip->i_dev, (daddr_t)fsbtodb(fs, blkno));
609 }
610 /* Write out second level of indirect blocks */
611 if ((blkno = ip->i_ib[1]) == 0)
612 return (0);
613 bp = UFS_BREAD(ufsvfsp, ip->i_dev, (daddr_t)fsbtodb(fs, blkno), bsize);
614 if (bp->b_flags & B_ERROR) {
615 brelse(bp);
616 return (EIO);
617 }
618 bap = bp->b_un.b_daddr;
619 clbn = NDADDR + NINDIR(fs);
620 for (i = 0; i < NINDIR(fs); i++) {
621 if (clbn > lbn)
622 break;
623 clbn += NINDIR(fs);
624 if ((blkno = bap[i]) == 0)
625 continue;
|