Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/makefs/ffs/ffs_alloc.c
Show First 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | |||||
ffs_alloccg(struct inode *ip, int cg, daddr_t bpref, int size) | ffs_alloccg(struct inode *ip, int cg, daddr_t bpref, int size) | ||||
{ | { | ||||
struct cg *cgp; | struct cg *cgp; | ||||
struct buf *bp; | struct buf *bp; | ||||
daddr_t bno, blkno; | daddr_t bno, blkno; | ||||
int error, frags, allocsiz, i; | int error, frags, allocsiz, i; | ||||
struct fs *fs = ip->i_fs; | struct fs *fs = ip->i_fs; | ||||
const int needswap = UFS_FSNEEDSWAP(fs); | const int needswap = UFS_FSNEEDSWAP(fs); | ||||
struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 }; | |||||
if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) | if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) | ||||
return (0); | return (0); | ||||
error = bread(ip->i_fd, ip->i_fs, fsbtodb(fs, cgtod(fs, cg)), | error = bread(&vp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, | ||||
(int)fs->fs_cgsize, &bp); | NULL, &bp); | ||||
if (error) { | if (error) { | ||||
brelse(bp); | brelse(bp, 0); | ||||
return (0); | return (0); | ||||
} | } | ||||
cgp = (struct cg *)bp->b_data; | cgp = (struct cg *)bp->b_data; | ||||
if (!cg_chkmagic_swap(cgp, needswap) || | if (!cg_chkmagic_swap(cgp, needswap) || | ||||
(cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) { | (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) { | ||||
brelse(bp); | brelse(bp, 0); | ||||
return (0); | return (0); | ||||
} | } | ||||
if (size == fs->fs_bsize) { | if (size == fs->fs_bsize) { | ||||
bno = ffs_alloccgblk(ip, bp, bpref); | bno = ffs_alloccgblk(ip, bp, bpref); | ||||
bdwrite(bp); | bdwrite(bp); | ||||
return (bno); | return (bno); | ||||
} | } | ||||
/* | /* | ||||
* check to see if any fragments are already available | * check to see if any fragments are already available | ||||
* allocsiz is the size which will be allocated, hacking | * allocsiz is the size which will be allocated, hacking | ||||
* it down to a smaller size if necessary | * it down to a smaller size if necessary | ||||
*/ | */ | ||||
frags = numfrags(fs, size); | frags = numfrags(fs, size); | ||||
for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++) | for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++) | ||||
if (cgp->cg_frsum[allocsiz] != 0) | if (cgp->cg_frsum[allocsiz] != 0) | ||||
break; | break; | ||||
if (allocsiz == fs->fs_frag) { | if (allocsiz == fs->fs_frag) { | ||||
/* | /* | ||||
* no fragments were available, so a block will be | * no fragments were available, so a block will be | ||||
* allocated, and hacked up | * allocated, and hacked up | ||||
*/ | */ | ||||
if (cgp->cg_cs.cs_nbfree == 0) { | if (cgp->cg_cs.cs_nbfree == 0) { | ||||
brelse(bp); | brelse(bp, 0); | ||||
return (0); | return (0); | ||||
} | } | ||||
bno = ffs_alloccgblk(ip, bp, bpref); | bno = ffs_alloccgblk(ip, bp, bpref); | ||||
bpref = dtogd(fs, bno); | bpref = dtogd(fs, bno); | ||||
for (i = frags; i < fs->fs_frag; i++) | for (i = frags; i < fs->fs_frag; i++) | ||||
setbit(cg_blksfree_swap(cgp, needswap), bpref + i); | setbit(cg_blksfree_swap(cgp, needswap), bpref + i); | ||||
i = fs->fs_frag - frags; | i = fs->fs_frag - frags; | ||||
ufs_add32(cgp->cg_cs.cs_nffree, i, needswap); | ufs_add32(cgp->cg_cs.cs_nffree, i, needswap); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
ffs_blkfree(struct inode *ip, daddr_t bno, long size) | ffs_blkfree(struct inode *ip, daddr_t bno, long size) | ||||
{ | { | ||||
struct cg *cgp; | struct cg *cgp; | ||||
struct buf *bp; | struct buf *bp; | ||||
int32_t fragno, cgbno; | int32_t fragno, cgbno; | ||||
int i, error, cg, blk, frags, bbase; | int i, error, cg, blk, frags, bbase; | ||||
struct fs *fs = ip->i_fs; | struct fs *fs = ip->i_fs; | ||||
const int needswap = UFS_FSNEEDSWAP(fs); | const int needswap = UFS_FSNEEDSWAP(fs); | ||||
struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 }; | |||||
if (size > fs->fs_bsize || fragoff(fs, size) != 0 || | if (size > fs->fs_bsize || fragoff(fs, size) != 0 || | ||||
fragnum(fs, bno) + numfrags(fs, size) > fs->fs_frag) { | fragnum(fs, bno) + numfrags(fs, size) > fs->fs_frag) { | ||||
errx(1, "blkfree: bad size: bno %lld bsize %d size %ld", | errx(1, "blkfree: bad size: bno %lld bsize %d size %ld", | ||||
(long long)bno, fs->fs_bsize, size); | (long long)bno, fs->fs_bsize, size); | ||||
} | } | ||||
cg = dtog(fs, bno); | cg = dtog(fs, bno); | ||||
if (bno >= fs->fs_size) { | if (bno >= fs->fs_size) { | ||||
warnx("bad block %lld, ino %ju", (long long)bno, | warnx("bad block %lld, ino %ju", (long long)bno, | ||||
(uintmax_t)ip->i_number); | (uintmax_t)ip->i_number); | ||||
return; | return; | ||||
} | } | ||||
error = bread(ip->i_fd, ip->i_fs, fsbtodb(fs, cgtod(fs, cg)), | error = bread(&vp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, | ||||
(int)fs->fs_cgsize, &bp); | NULL, &bp); | ||||
if (error) { | if (error) { | ||||
brelse(bp); | brelse(bp, 0); | ||||
return; | return; | ||||
} | } | ||||
cgp = (struct cg *)bp->b_data; | cgp = (struct cg *)bp->b_data; | ||||
if (!cg_chkmagic_swap(cgp, needswap)) { | if (!cg_chkmagic_swap(cgp, needswap)) { | ||||
brelse(bp); | brelse(bp, 0); | ||||
return; | return; | ||||
} | } | ||||
cgbno = dtogd(fs, bno); | cgbno = dtogd(fs, bno); | ||||
if (size == fs->fs_bsize) { | if (size == fs->fs_bsize) { | ||||
fragno = fragstoblks(fs, cgbno); | fragno = fragstoblks(fs, cgbno); | ||||
if (!ffs_isfreeblock(fs, cg_blksfree_swap(cgp, needswap), fragno)) { | if (!ffs_isfreeblock(fs, cg_blksfree_swap(cgp, needswap), fragno)) { | ||||
errx(1, "blkfree: freeing free block %lld", | errx(1, "blkfree: freeing free block %lld", | ||||
(long long)bno); | (long long)bno); | ||||
▲ Show 20 Lines • Show All 218 Lines • Show Last 20 Lines |