Index: head/usr.sbin/makefs/ffs.c =================================================================== --- head/usr.sbin/makefs/ffs.c +++ head/usr.sbin/makefs/ffs.c @@ -143,7 +143,6 @@ fsnode *, fsinfo_t *); -int sectorsize; /* XXX: for buf.c::getblk() */ /* publicly visible functions */ void @@ -429,8 +428,6 @@ printf("ffs_validate: dir %s; %lld bytes, %lld inodes\n", dir, (long long)fsopts->size, (long long)fsopts->inodes); } - sectorsize = fsopts->sectorsize; /* XXX - see earlier */ - /* now check calculated sizes vs requested sizes */ if (fsopts->maxsize > 0 && fsopts->size > fsopts->maxsize) { errx(1, "`%s' size of %lld is larger than the maxsize of %lld.", @@ -480,13 +477,13 @@ int i, bufsize; off_t bufrem; time_t tstamp; + int oflags = O_RDWR | O_CREAT | O_TRUNC; assert (image != NULL); assert (fsopts != NULL); /* create image */ - if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0666)) - == -1) { + if ((fsopts->fd = open(image, oflags, 0666)) == -1) { warn("Can't open `%s' for writing", image); return (-1); } @@ -878,6 +875,7 @@ struct inode in; struct buf * bp; ffs_opt_t *ffs_opts = fsopts->fs_specific; + struct vnode vp = { fsopts, NULL }; assert (din != NULL); assert (buf != NULL); @@ -890,6 +888,7 @@ p = NULL; in.i_fs = (struct fs *)fsopts->superblock; + in.i_devvp = &vp; if (debug & DEBUG_FS_WRITE_FILE) { printf( @@ -910,7 +909,6 @@ else memcpy(&in.i_din.ffs2_din, &din->ffs2_din, sizeof(in.i_din.ffs2_din)); - in.i_fd = fsopts->fd; if (DIP(din, size) == 0) goto write_inode_and_leave; /* mmm, cheating */ Index: head/usr.sbin/makefs/ffs/buf.h =================================================================== --- head/usr.sbin/makefs/ffs/buf.h +++ head/usr.sbin/makefs/ffs/buf.h @@ -43,13 +43,12 @@ #include #include +struct makefs_fsinfo; struct ucred; struct vnode { - int fd; - void *fs; + struct makefs_fsinfo *fs; void *v_data; - int offset; }; struct buf { @@ -58,8 +57,7 @@ long b_bcount; daddr_t b_blkno; daddr_t b_lblkno; - int b_fd; - void * b_fs; + struct makefs_fsinfo *b_fs; TAILQ_ENTRY(buf) b_tailq; }; Index: head/usr.sbin/makefs/ffs/buf.c =================================================================== --- head/usr.sbin/makefs/ffs/buf.c +++ head/usr.sbin/makefs/ffs/buf.c @@ -52,8 +52,6 @@ #include "makefs.h" #include "buf.h" -extern int sectorsize; /* XXX: from ffs.c & mkfs.c */ - static TAILQ_HEAD(buftailhead,buf) buftail; int @@ -62,6 +60,7 @@ { off_t offset; ssize_t rv; + fsinfo_t *fsinfo = vp->fs; assert (bpp != NULL); @@ -69,15 +68,15 @@ printf("%s: blkno %lld size %d\n", __func__, (long long)blkno, size); *bpp = getblk(vp, blkno, size, 0, 0, 0); - offset = (*bpp)->b_blkno * sectorsize; /* XXX */ + offset = (*bpp)->b_blkno * fsinfo->sectorsize; if (debug & DEBUG_BUF_BREAD) printf("%s: blkno %lld offset %lld bcount %ld\n", __func__, (long long)(*bpp)->b_blkno, (long long) offset, (*bpp)->b_bcount); - if (lseek((*bpp)->b_fd, offset, SEEK_SET) == -1) + if (lseek((*bpp)->b_fs->fd, offset, SEEK_SET) == -1) err(1, "%s: lseek %lld (%lld)", __func__, (long long)(*bpp)->b_blkno, (long long)offset); - rv = read((*bpp)->b_fd, (*bpp)->b_data, (*bpp)->b_bcount); + rv = read((*bpp)->b_fs->fd, (*bpp)->b_data, (*bpp)->b_bcount); if (debug & DEBUG_BUF_BREAD) printf("%s: read %ld (%lld) returned %d\n", __func__, (*bpp)->b_bcount, (long long)offset, (int)rv); @@ -126,16 +125,17 @@ { off_t offset; ssize_t rv; + fsinfo_t *fs = bp->b_fs; assert (bp != NULL); - offset = bp->b_blkno * sectorsize; /* XXX */ + offset = bp->b_blkno * fs->sectorsize; if (debug & DEBUG_BUF_BWRITE) printf("bwrite: blkno %lld offset %lld bcount %ld\n", (long long)bp->b_blkno, (long long) offset, bp->b_bcount); - if (lseek(bp->b_fd, offset, SEEK_SET) == -1) + if (lseek(bp->b_fs->fd, offset, SEEK_SET) == -1) return (errno); - rv = write(bp->b_fd, bp->b_data, bp->b_bcount); + rv = write(bp->b_fs->fd, bp->b_data, bp->b_bcount); if (debug & DEBUG_BUF_BWRITE) printf("bwrite: write %ld (offset %lld) returned %lld\n", bp->b_bcount, (long long)offset, (long long)rv); @@ -198,7 +198,6 @@ bp = ecalloc(1, sizeof(*bp)); bp->b_bufsize = 0; bp->b_blkno = bp->b_lblkno = blkno; - bp->b_fd = vp->fd; bp->b_fs = vp->fs; bp->b_data = NULL; TAILQ_INSERT_HEAD(&buftail, bp, b_tailq); Index: head/usr.sbin/makefs/ffs/ffs_alloc.c =================================================================== --- head/usr.sbin/makefs/ffs/ffs_alloc.c +++ head/usr.sbin/makefs/ffs/ffs_alloc.c @@ -297,11 +297,10 @@ int error, frags, allocsiz, i; struct fs *fs = ip->i_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) return (0); - error = bread(&vp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, + error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, NULL, &bp); if (error) { brelse(bp, 0); @@ -433,7 +432,6 @@ int i, error, cg, blk, frags, bbase; struct fs *fs = ip->i_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 || fragnum(fs, bno) + numfrags(fs, size) > fs->fs_frag) { @@ -446,7 +444,7 @@ (uintmax_t)ip->i_number); return; } - error = bread(&vp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, + error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, NULL, &bp); if (error) { brelse(bp, 0); Index: head/usr.sbin/makefs/ffs/ffs_balloc.c =================================================================== --- head/usr.sbin/makefs/ffs/ffs_balloc.c +++ head/usr.sbin/makefs/ffs/ffs_balloc.c @@ -89,7 +89,6 @@ int32_t *allocblk, allociblk[UFS_NIADDR + 1]; int32_t *allocib; const int needswap = UFS_FSNEEDSWAP(fs); - struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 }; lbn = lblkno(fs, offset); size = blkoff(fs, offset) + bufsize; @@ -134,8 +133,8 @@ */ if (bpp != NULL) { - error = bread(&vp, lbn, fs->fs_bsize, NULL, - bpp); + error = bread(ip->i_devvp, lbn, fs->fs_bsize, + NULL, bpp); if (error) { brelse(*bpp, 0); return (error); @@ -160,8 +159,8 @@ */ if (bpp != NULL) { - error = bread(&vp, lbn, osize, NULL, - bpp); + error = bread(ip->i_devvp, lbn, osize, + NULL, bpp); if (error) { brelse(*bpp, 0); return (error); @@ -190,7 +189,7 @@ if (error) return (error); if (bpp != NULL) { - bp = getblk(&vp, lbn, nsize, 0, 0, 0); + bp = getblk(ip->i_devvp, lbn, nsize, 0, 0, 0); bp->b_blkno = fsbtodb(fs, newb); clrbuf(bp); *bpp = bp; @@ -228,7 +227,7 @@ return error; nb = newb; *allocblk++ = nb; - bp = getblk(&vp, indirs[1].in_lbn, fs->fs_bsize, 0, 0, 0); + bp = getblk(ip->i_devvp, indirs[1].in_lbn, fs->fs_bsize, 0, 0, 0); bp->b_blkno = fsbtodb(fs, nb); clrbuf(bp); /* @@ -246,7 +245,8 @@ */ for (i = 1;;) { - error = bread(&vp, indirs[i].in_lbn, fs->fs_bsize, NULL, &bp); + error = bread(ip->i_devvp, indirs[i].in_lbn, fs->fs_bsize, + NULL, &bp); if (error) { brelse(bp, 0); return error; @@ -269,7 +269,7 @@ } nb = newb; *allocblk++ = nb; - nbp = getblk(&vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0, 0); + nbp = getblk(ip->i_devvp, indirs[i].in_lbn, fs->fs_bsize, 0, 0, 0); nbp->b_blkno = fsbtodb(fs, nb); clrbuf(nbp); /* @@ -300,7 +300,7 @@ nb = newb; *allocblk++ = nb; if (bpp != NULL) { - nbp = getblk(&vp, lbn, fs->fs_bsize, 0, 0, 0); + nbp = getblk(ip->i_devvp, lbn, fs->fs_bsize, 0, 0, 0); nbp->b_blkno = fsbtodb(fs, nb); clrbuf(nbp); *bpp = nbp; @@ -316,7 +316,7 @@ } brelse(bp, 0); if (bpp != NULL) { - error = bread(&vp, lbn, (int)fs->fs_bsize, NULL, &nbp); + error = bread(ip->i_devvp, lbn, (int)fs->fs_bsize, NULL, &nbp); if (error) { brelse(nbp, 0); return error; @@ -340,7 +340,6 @@ int64_t *allocblk, allociblk[UFS_NIADDR + 1]; int64_t *allocib; const int needswap = UFS_FSNEEDSWAP(fs); - struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 }; lbn = lblkno(fs, offset); size = blkoff(fs, offset) + bufsize; @@ -385,8 +384,8 @@ */ if (bpp != NULL) { - error = bread(&vp, lbn, fs->fs_bsize, NULL, - bpp); + error = bread(ip->i_devvp, lbn, fs->fs_bsize, + NULL, bpp); if (error) { brelse(*bpp, 0); return (error); @@ -411,8 +410,8 @@ */ if (bpp != NULL) { - error = bread(&vp, lbn, osize, NULL, - bpp); + error = bread(ip->i_devvp, lbn, osize, + NULL, bpp); if (error) { brelse(*bpp, 0); return (error); @@ -441,7 +440,7 @@ if (error) return (error); if (bpp != NULL) { - bp = getblk(&vp, lbn, nsize, 0, 0, 0); + bp = getblk(ip->i_devvp, lbn, nsize, 0, 0, 0); bp->b_blkno = fsbtodb(fs, newb); clrbuf(bp); *bpp = bp; @@ -479,7 +478,7 @@ return error; nb = newb; *allocblk++ = nb; - bp = getblk(&vp, indirs[1].in_lbn, fs->fs_bsize, 0, 0, 0); + bp = getblk(ip->i_devvp, indirs[1].in_lbn, fs->fs_bsize, 0, 0, 0); bp->b_blkno = fsbtodb(fs, nb); clrbuf(bp); /* @@ -497,7 +496,8 @@ */ for (i = 1;;) { - error = bread(&vp, indirs[i].in_lbn, fs->fs_bsize, NULL, &bp); + error = bread(ip->i_devvp, indirs[i].in_lbn, fs->fs_bsize, + NULL, &bp); if (error) { brelse(bp, 0); return error; @@ -520,7 +520,7 @@ } nb = newb; *allocblk++ = nb; - nbp = getblk(&vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0, 0); + nbp = getblk(ip->i_devvp, indirs[i].in_lbn, fs->fs_bsize, 0, 0, 0); nbp->b_blkno = fsbtodb(fs, nb); clrbuf(nbp); /* @@ -551,7 +551,7 @@ nb = newb; *allocblk++ = nb; if (bpp != NULL) { - nbp = getblk(&vp, lbn, fs->fs_bsize, 0, 0, 0); + nbp = getblk(ip->i_devvp, lbn, fs->fs_bsize, 0, 0, 0); nbp->b_blkno = fsbtodb(fs, nb); clrbuf(nbp); *bpp = nbp; @@ -567,7 +567,7 @@ } brelse(bp, 0); if (bpp != NULL) { - error = bread(&vp, lbn, (int)fs->fs_bsize, NULL, &nbp); + error = bread(ip->i_devvp, lbn, (int)fs->fs_bsize, NULL, &nbp); if (error) { brelse(nbp, 0); return error; Index: head/usr.sbin/makefs/ffs/ufs_inode.h =================================================================== --- head/usr.sbin/makefs/ffs/ufs_inode.h +++ head/usr.sbin/makefs/ffs/ufs_inode.h @@ -45,9 +45,9 @@ struct inode { ino_t i_number; /* The identity of the inode. */ + struct vnode *i_devvp; /* vnode pointer (contains fsopts) */ struct fs *i_fs; /* File system */ union dinode i_din; - int i_fd; /* File descriptor */ uint64_t i_size; };