Changeset View
Changeset View
Standalone View
Standalone View
sys/ufs/ffs/ffs_balloc.c
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, | ||||
/* | /* | ||||
* The first UFS_NDADDR blocks are direct blocks | * The first UFS_NDADDR blocks are direct blocks | ||||
*/ | */ | ||||
if (lbn < UFS_NDADDR) { | if (lbn < UFS_NDADDR) { | ||||
if (flags & BA_METAONLY) | if (flags & BA_METAONLY) | ||||
panic("ffs_balloc_ufs1: BA_METAONLY for direct block"); | panic("ffs_balloc_ufs1: BA_METAONLY for direct block"); | ||||
nb = dp->di_db[lbn]; | nb = dp->di_db[lbn]; | ||||
if (nb != 0 && ip->i_size >= smalllblktosize(fs, lbn + 1)) { | if (nb != 0 && ip->i_size >= smalllblktosize(fs, lbn + 1)) { | ||||
error = bread(vp, lbn, fs->fs_bsize, NOCRED, &bp); | if ((flags & BA_CLRBUF) == 0) { | ||||
mckusick: This is backwards. It should be "if (flags & BA_CLRBUF) != 0)".
BA_CLRBUF is set when not all… | |||||
if (error) { | error = bread(vp, lbn, fs->fs_bsize, NOCRED, | ||||
&bp); | |||||
if (error != 0) | |||||
return (error); | return (error); | ||||
} else { | |||||
bp = getblk(vp, lbn, fs->fs_bsize, 0, 0, | |||||
gbflags); | |||||
if (bp == NULL) | |||||
return (EIO); | |||||
vfs_bio_clrbuf(bp); | |||||
} | } | ||||
bp->b_blkno = fsbtodb(fs, nb); | bp->b_blkno = fsbtodb(fs, nb); | ||||
*bpp = bp; | *bpp = bp; | ||||
return (0); | return (0); | ||||
} | } | ||||
if (nb != 0) { | if (nb != 0) { | ||||
/* | /* | ||||
* Consider need to reallocate a fragment. | * Consider need to reallocate a fragment. | ||||
▲ Show 20 Lines • Show All 577 Lines • ▼ Show 20 Lines | ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, | ||||
/* | /* | ||||
* The first UFS_NDADDR blocks are direct blocks | * The first UFS_NDADDR blocks are direct blocks | ||||
*/ | */ | ||||
if (lbn < UFS_NDADDR) { | if (lbn < UFS_NDADDR) { | ||||
if (flags & BA_METAONLY) | if (flags & BA_METAONLY) | ||||
panic("ffs_balloc_ufs2: BA_METAONLY for direct block"); | panic("ffs_balloc_ufs2: BA_METAONLY for direct block"); | ||||
nb = dp->di_db[lbn]; | nb = dp->di_db[lbn]; | ||||
if (nb != 0 && ip->i_size >= smalllblktosize(fs, lbn + 1)) { | if (nb != 0 && ip->i_size >= smalllblktosize(fs, lbn + 1)) { | ||||
if ((flags & BA_CLRBUF) == 0) { | |||||
mckusickUnsubmitted Not Done Inline ActionsSame comment here: This is backwards. It should be "if (flags & BA_CLRBUF) != 0)". mckusick: Same comment here: This is backwards. It should be "if (flags & BA_CLRBUF) != 0)". | |||||
error = bread_gb(vp, lbn, fs->fs_bsize, NOCRED, | error = bread_gb(vp, lbn, fs->fs_bsize, NOCRED, | ||||
gbflags, &bp); | gbflags, &bp); | ||||
if (error) { | if (error != 0) | ||||
return (error); | return (error); | ||||
} else { | |||||
bp = getblk(vp, lbn, fs->fs_bsize, 0, 0, | |||||
gbflags); | |||||
if (bp == NULL) | |||||
return (EIO); | |||||
vfs_bio_clrbuf(bp); | |||||
} | } | ||||
bp->b_blkno = fsbtodb(fs, nb); | bp->b_blkno = fsbtodb(fs, nb); | ||||
*bpp = bp; | *bpp = bp; | ||||
return (0); | return (0); | ||||
} | } | ||||
if (nb != 0) { | if (nb != 0) { | ||||
/* | /* | ||||
* Consider need to reallocate a fragment. | * Consider need to reallocate a fragment. | ||||
▲ Show 20 Lines • Show All 396 Lines • Show Last 20 Lines |
This is backwards. It should be "if (flags & BA_CLRBUF) != 0)".
BA_CLRBUF is set when not all of the buffer will be written so we need to clear it so that the unwritten part will be zero. Here where the block is already allocated, we need to read it when not all of it will be written and can getblk it when BA_CLRBUF is cleared because we will write all of it.