makefs: make buf generic
it has nothing to do with ffs and will eventually be moved. gc sectorsize. This is a corrected version of r317744. NetBSD versions: ffs.c 1.58 ffs/buf.c 1.14 1.18 ffs/buf.h 1.8 Submitted by: Siva Mahadevan <smahadevan@freebsdfoundation.org> Obtained from: NetBSD Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D10803
This commit is contained in:
parent
3a268233e8
commit
6160cc37f4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=318902
@ -143,7 +143,6 @@ static void *ffs_build_dinode2(struct ufs2_dinode *, dirbuf_t *, fsnode *,
|
||||
fsnode *, fsinfo_t *);
|
||||
|
||||
|
||||
int sectorsize; /* XXX: for buf.c::getblk() */
|
||||
/* publicly visible functions */
|
||||
|
||||
void
|
||||
@ -429,8 +428,6 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
|
||||
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 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
|
||||
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 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
|
||||
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 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
|
||||
p = NULL;
|
||||
|
||||
in.i_fs = (struct fs *)fsopts->superblock;
|
||||
in.i_devvp = &vp;
|
||||
|
||||
if (debug & DEBUG_FS_WRITE_FILE) {
|
||||
printf(
|
||||
@ -910,7 +909,6 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
|
||||
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 */
|
||||
|
@ -52,8 +52,6 @@ __FBSDID("$FreeBSD$");
|
||||
#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 @@ bread(struct vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused,
|
||||
{
|
||||
off_t offset;
|
||||
ssize_t rv;
|
||||
fsinfo_t *fsinfo = vp->fs;
|
||||
|
||||
assert (bpp != NULL);
|
||||
|
||||
@ -69,15 +68,15 @@ bread(struct vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused,
|
||||
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 @@ bwrite(struct buf *bp)
|
||||
{
|
||||
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 @@ getblk(struct vnode *vp, daddr_t blkno, int size, int u1 __unused,
|
||||
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);
|
||||
|
@ -43,13 +43,12 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
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 @@ struct buf {
|
||||
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;
|
||||
};
|
||||
|
@ -297,11 +297,10 @@ ffs_alloccg(struct inode *ip, int cg, daddr_t bpref, int size)
|
||||
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 @@ ffs_blkfree(struct inode *ip, daddr_t bno, long size)
|
||||
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 @@ ffs_blkfree(struct inode *ip, daddr_t bno, long size)
|
||||
(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);
|
||||
|
@ -89,7 +89,6 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
*/
|
||||
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
*/
|
||||
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
*/
|
||||
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
}
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
}
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
*/
|
||||
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
*/
|
||||
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
*/
|
||||
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
}
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
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 @@ ffs_balloc_ufs2(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
|
||||
}
|
||||
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;
|
||||
|
@ -45,9 +45,9 @@ union dinode {
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user