Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
This commit is contained in:
dholland 2015-08-12 18:28:00 +00:00
parent 1c8e2a4061
commit b1828e0ba3
38 changed files with 841 additions and 506 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: coalesce.c,v 1.31 2015/08/12 18:25:51 dholland Exp $ */
/* $NetBSD: coalesce.c,v 1.32 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
@ -109,13 +109,14 @@ const char *coalesce_return[] = {
"No such error"
};
static struct ulfs1_dinode *
static union lfs_dinode *
get_dinode(struct clfs *fs, ino_t ino)
{
IFILE *ifp;
daddr_t daddr;
struct ubuf *bp;
struct ulfs1_dinode *dip, *r;
union lfs_dinode *dip, *r;
unsigned i;
lfs_ientry(&ifp, fs, ino, &bp);
daddr = lfs_if_getdaddr(fs, ifp);
@ -125,16 +126,26 @@ get_dinode(struct clfs *fs, ino_t ino)
return NULL;
bread(fs->clfs_devvp, daddr, lfs_sb_getibsize(fs), 0, &bp);
for (dip = (struct ulfs1_dinode *)bp->b_data;
dip < (struct ulfs1_dinode *)(bp->b_data + lfs_sb_getibsize(fs)); dip++)
if (dip->di_inumber == ino) {
r = (struct ulfs1_dinode *)malloc(sizeof(*r));
for (i = 0; i < LFS_INOPB(fs); i++) {
dip = DINO_IN_BLOCK(fs, bp->b_data, i);
if (lfs_dino_getinumber(fs, dip) == ino) {
r = malloc(sizeof(*r));
if (r == NULL)
break;
memcpy(r, dip, sizeof(*r));
/*
* Don't just assign the union, as if we're
* 32-bit and it's the last inode in the block
* that will run off the end of the buffer.
*/
if (fs->lfs_is64) {
r->u_64 = dip->u_64;
} else {
r->u_32 = dip->u_32;
}
brelse(bp, 0);
return r;
}
}
brelse(bp, 0);
return NULL;
}
@ -149,7 +160,7 @@ clean_inode(struct clfs *fs, ino_t ino)
BLOCK_INFO *bip = NULL, *tbip;
CLEANERINFO cip;
struct ubuf *bp;
struct ulfs1_dinode *dip;
union lfs_dinode *dip;
struct clfs_seguse *sup;
struct lfs_fcntl_markv /* {
BLOCK_INFO *blkiov;
@ -166,7 +177,7 @@ clean_inode(struct clfs *fs, ino_t ino)
return COALESCE_NOINODE;
/* Compute file block size, set up for bmapv */
onb = nb = lfs_lblkno(fs, dip->di_size);
onb = nb = lfs_lblkno(fs, lfs_dino_getsize(fs, dip));
/* XXX for now, don't do any file small enough to have fragments */
if (nb < ULFS_NDADDR) {
@ -176,16 +187,17 @@ clean_inode(struct clfs *fs, ino_t ino)
/* Sanity checks */
#if 0 /* di_size is uint64_t -- this is a noop */
if (dip->di_size < 0) {
dlog("ino %d, negative size (%" PRId64 ")", ino, dip->di_size);
if (lfs_dino_getsize(fs, dip) < 0) {
dlog("ino %d, negative size (%" PRId64 ")", ino,
lfs_dino_getsize(fs, dip));
free(dip);
return COALESCE_BADSIZE;
}
#endif
if (nb > dip->di_blocks) {
if (nb > lfs_dino_getblocks(fs, dip)) {
dlog("ino %ju, computed blocks %jd > held blocks %ju",
(uintmax_t)ino, (intmax_t)nb,
(uintmax_t)dip->di_blocks);
(uintmax_t)lfs_dino_getblocks(fs, dip));
free(dip);
return COALESCE_BADBLOCKSIZE;
}
@ -220,7 +232,7 @@ clean_inode(struct clfs *fs, ino_t ino)
memset(bip + i, 0, sizeof(BLOCK_INFO));
bip[i].bi_inode = ino;
bip[i].bi_lbn = i;
bip[i].bi_version = dip->di_gen;
bip[i].bi_version = lfs_dino_getgen(fs, dip);
/* Don't set the size, but let lfs_bmap fill it in */
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_cleanerd.c,v 1.49 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_cleanerd.c,v 1.50 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -420,7 +420,7 @@ parse_pseg(struct clfs *fs, daddr_t daddr, BLOCK_INFO **bipp, int *bic)
daddr_t idaddr, odaddr;
FINFO *fip;
struct ubuf *ifbp;
struct ulfs1_dinode *dip;
union lfs_dinode *dip;
u_int32_t ck, vers;
int fic, inoc, obic;
size_t sumstart;
@ -489,16 +489,16 @@ parse_pseg(struct clfs *fs, daddr_t daddr, BLOCK_INFO **bipp, int *bic)
if (inoc < lfs_ss_getninos(fs, ssp) && *iaddrp == daddr) {
cp = fd_ptrget(fs->clfs_devvp, daddr);
ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck);
dip = (struct ulfs1_dinode *)cp;
for (i = 0; i < lfs_sb_getinopb(fs); i++) {
if (dip[i].di_inumber == 0)
dip = DINO_IN_BLOCK(fs, cp, i);
if (lfs_dino_getinumber(fs, dip) == 0)
break;
/*
* Check currency before adding it
*/
#ifndef REPAIR_ZERO_FINFO
lfs_ientry(&ifp, fs, dip[i].di_inumber, &ifbp);
lfs_ientry(&ifp, fs, lfs_dino_getinumber(fs, dip), &ifbp);
idaddr = lfs_if_getdaddr(fs, ifp);
brelse(ifbp, 0);
if (idaddr != daddr)
@ -518,13 +518,13 @@ parse_pseg(struct clfs *fs, daddr_t daddr, BLOCK_INFO **bipp, int *bic)
*bipp = bip;
return 0x0;
}
bip[*bic - 1].bi_inode = dip[i].di_inumber;
bip[*bic - 1].bi_inode = lfs_dino_getinumber(fs, dip);
bip[*bic - 1].bi_lbn = LFS_UNUSED_LBN;
bip[*bic - 1].bi_daddr = daddr;
bip[*bic - 1].bi_segcreate = lfs_ss_getcreate(fs, ssp);
bip[*bic - 1].bi_version = dip[i].di_gen;
bip[*bic - 1].bi_bp = &(dip[i]);
bip[*bic - 1].bi_size = LFS_DINODE1_SIZE;
bip[*bic - 1].bi_version = lfs_dino_getgen(fs, dip);
bip[*bic - 1].bi_bp = dip;
bip[*bic - 1].bi_size = DINOSIZE(fs);
}
inoc += i;
daddr += lfs_btofsb(fs, lfs_sb_getibsize(fs));

View File

@ -1,4 +1,4 @@
/* $NetBSD: dump.h,v 1.52 2015/07/28 05:09:34 dholland Exp $ */
/* $NetBSD: dump.h,v 1.53 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 1980, 1993
@ -43,8 +43,8 @@ union dinode {
struct ufs1_dinode dp1;
struct ufs2_dinode dp2;
#ifdef DUMP_LFS
struct ulfs1_dinode dlp1;
struct ulfs2_dinode dlp2;
struct lfs32_dinode dlp32;
struct lfs64_dinode dlp64;
#endif
};
#define DIP(dp, field) \

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_inode.c,v 1.24 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: lfs_inode.c,v 1.25 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993, 1994
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95";
#else
__RCSID("$NetBSD: lfs_inode.c,v 1.24 2015/08/12 18:25:52 dholland Exp $");
__RCSID("$NetBSD: lfs_inode.c,v 1.25 2015/08/12 18:28:00 dholland Exp $");
#endif
#endif /* not lint */
@ -196,7 +196,7 @@ fs_mapinodes(ino_t maxino, u_int64_t *tapesz, int *anydirskipped)
#define T_UNITS (LFS_NINDIR(fs)*LFS_NINDIR(fs))
static daddr_t
lfs_bmap(struct lfs *fs, struct ulfs1_dinode *idinode, daddr_t lbn)
lfs_bmap(struct lfs *fs, union lfs_dinode *idinode, daddr_t lbn)
{
daddr_t residue, up;
int off=0;
@ -204,7 +204,7 @@ lfs_bmap(struct lfs *fs, struct ulfs1_dinode *idinode, daddr_t lbn)
up = UNASSIGNED; /* XXXGCC -Wunitialized [sh3] */
if(lbn > 0 && lbn > lfs_lblkno(fs, idinode->di_size)) {
if(lbn > 0 && lbn > lfs_lblkno(fs, lfs_dino_getsize(fs, idinode))) {
return UNASSIGNED;
}
/*
@ -217,13 +217,13 @@ lfs_bmap(struct lfs *fs, struct ulfs1_dinode *idinode, daddr_t lbn)
lbn *= -1;
if (lbn == ULFS_NDADDR) {
/* printf("lbn %d: single indir base\n", -lbn); */
return idinode->di_ib[0]; /* single indirect */
return lfs_dino_getib(fs, idinode, 0); /* single indirect */
} else if(lbn == BASE_DINDIR+1) {
/* printf("lbn %d: double indir base\n", -lbn); */
return idinode->di_ib[1]; /* double indirect */
return lfs_dino_getib(fs, idinode, 1); /* double indirect */
} else if(lbn == BASE_TINDIR+2) {
/* printf("lbn %d: triple indir base\n", -lbn); */
return idinode->di_ib[2]; /* triple indirect */
return lfs_dino_getib(fs, idinode, 2); /* triple indirect */
}
/*
@ -233,7 +233,7 @@ lfs_bmap(struct lfs *fs, struct ulfs1_dinode *idinode, daddr_t lbn)
residue = (lbn-ULFS_NDADDR) % LFS_NINDIR(fs);
if(residue == 1) {
/* Double indirect. Parent is the triple. */
up = idinode->di_ib[2];
up = lfs_dino_getib(fs, idinode, 2);
off = (lbn-2-BASE_TINDIR)/(LFS_NINDIR(fs)*LFS_NINDIR(fs));
if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
return UNASSIGNED;
@ -260,7 +260,7 @@ lfs_bmap(struct lfs *fs, struct ulfs1_dinode *idinode, daddr_t lbn)
} else {
/* Direct block. Its parent must be a single indirect. */
if (lbn < ULFS_NDADDR)
return idinode->di_db[lbn];
return lfs_dino_getdb(fs, idinode, lbn);
else {
/* Parent is an indirect block. */
up = -(((lbn-ULFS_NDADDR) / D_UNITS) * D_UNITS + ULFS_NDADDR);
@ -284,14 +284,18 @@ lfs_ientry(ino_t ino)
daddr_t lbn;
daddr_t blkno;
union dinode *dp;
struct ulfs1_dinode *ldp;
union lfs_dinode *ldp;
unsigned index;
lbn = ino/lfs_sb_getifpb(sblock) + lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock);
dp = getino(lfs_sb_getifile(sblock));
/* XXX XXX this is horribly unsafe */
ldp = (struct ulfs1_dinode *)dp;
blkno = lfs_bmap(sblock, ldp ,lbn);
/* XXX this is foolish */
if (sblock->lfs_is64) {
ldp = (union lfs_dinode *)&dp->dlp64;
} else {
ldp = (union lfs_dinode *)&dp->dlp32;
}
blkno = lfs_bmap(sblock, ldp, lbn);
if (blkno != ifblkno)
bread(LFS_FSBTODB(sblock, blkno), ifileblock,
lfs_sb_getbsize(sblock));
@ -306,14 +310,18 @@ lfs_ientry(ino_t ino)
}
/* Search a block for a specific dinode. */
static struct ulfs1_dinode *
lfs_ifind(struct lfs *fs, ino_t ino, struct ulfs1_dinode *dip)
static union lfs_dinode *
lfs_ifind(struct lfs *fs, ino_t ino, void *block)
{
int cnt;
union lfs_dinode *dip;
unsigned i, num;
for (cnt = 0; cnt < LFS_INOPB(fs); cnt++)
if(dip[cnt].di_inumber == ino)
return &(dip[cnt]);
num = LFS_INOPB(fs);
for (i = num; i-- > 0; ) {
dip = DINO_IN_BLOCK(fs, block, i);
if (lfs_dino_getinumber(fs, dip) == ino)
return dip;
}
return NULL;
}
@ -322,19 +330,32 @@ getino(ino_t inum)
{
static daddr_t inoblkno;
daddr_t blkno;
static struct ulfs1_dinode inoblock[MAXBSIZE / sizeof (struct ulfs1_dinode)];
static union {
char space[MAXBSIZE];
struct lfs64_dinode u_64[MAXBSIZE/sizeof(struct lfs64_dinode)];
struct lfs32_dinode u_32[MAXBSIZE/sizeof(struct lfs32_dinode)];
} inoblock;
static union dinode ifile_dinode; /* XXX fill this in */
static union dinode empty_dinode; /* Always stays zeroed */
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
ino_t inum2;
if(inum == lfs_sb_getifile(sblock)) {
/* Load the ifile inode if not already */
if(ifile_dinode.dlp1.di_inumber == 0) {
inum2 = sblock->lfs_is64 ?
ifile_dinode.dlp64.di_inumber :
ifile_dinode.dlp32.di_inumber;
if (inum2 == 0) {
blkno = lfs_sb_getidaddr(sblock);
bread(LFS_FSBTODB(sblock, blkno), (char *)inoblock,
bread(LFS_FSBTODB(sblock, blkno), inoblock.space,
(int)lfs_sb_getbsize(sblock));
dp = lfs_ifind(sblock, inum, inoblock);
ifile_dinode.dlp1 = *dp; /* Structure copy */
dp = lfs_ifind(sblock, inum, inoblock.space);
/* Structure copy */
if (sblock->lfs_is64) {
ifile_dinode.dlp64 = dp->u_64;
} else {
ifile_dinode.dlp32 = dp->u_32;
}
}
return &ifile_dinode;
}
@ -345,15 +366,10 @@ getino(ino_t inum)
return &empty_dinode;
if(blkno != inoblkno) {
bread(LFS_FSBTODB(sblock, blkno), (char *)inoblock,
bread(LFS_FSBTODB(sblock, blkno), inoblock.space,
(int)lfs_sb_getbsize(sblock));
#ifdef notyet
if (needswap)
for (i = 0; i < MAXINOPB; i++)
ffs_dinode_swap(&inoblock[i], &inoblock[i]);
#endif
}
return (void *)lfs_ifind(sblock, inum, inoblock);
return (void *)lfs_ifind(sblock, inum, inoblock.space);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.35 2015/07/28 05:09:34 dholland Exp $ */
/* $NetBSD: dir.c,v 1.36 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -81,7 +81,7 @@ struct lfs_odirtemplate odirhead = {
.dotdot_name = ".."
};
static int expanddir(struct uvnode *, struct ulfs1_dinode *, char *);
static int expanddir(struct uvnode *, union lfs_dinode *, char *);
static void freedir(ino_t, ino_t);
static struct lfs_direct *fsck_readdir(struct uvnode *, struct inodesc *);
static int lftempname(char *, ino_t);
@ -327,19 +327,25 @@ void
adjust(struct inodesc *idesc, short lcnt)
{
struct uvnode *vp;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
/*
* XXX: (1) since lcnt is apparently a delta, rename it; (2)
* why is it a value to *subtract*? that is unnecessarily
* confusing.
*/
vp = vget(fs, idesc->id_number);
dp = VTOD(vp);
if (dp->di_nlink == lcnt) {
if (lfs_dino_getnlink(fs, dp) == lcnt) {
if (linkup(idesc->id_number, (ino_t) 0) == 0)
clri(idesc, "UNREF", 0);
} else {
pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname :
((dp->di_mode & LFS_IFMT) == LFS_IFDIR ? "DIR" : "FILE"));
((lfs_dino_getmode(fs, dp) & LFS_IFMT) == LFS_IFDIR ? "DIR" : "FILE"));
pinode(idesc->id_number);
printf(" COUNT %d SHOULD BE %d",
dp->di_nlink, dp->di_nlink - lcnt);
lfs_dino_getnlink(fs, dp), lfs_dino_getnlink(fs, dp) - lcnt);
if (preen) {
if (lcnt < 0) {
printf("\n");
@ -348,7 +354,8 @@ adjust(struct inodesc *idesc, short lcnt)
printf(" (ADJUSTED)\n");
}
if (preen || reply("ADJUST") == 1) {
dp->di_nlink -= lcnt;
lfs_dino_setnlink(fs, dp,
lfs_dino_getnlink(fs, dp) - lcnt);
inodirty(VTOI(vp));
}
}
@ -395,7 +402,7 @@ chgino(struct inodesc *idesc)
int
linkup(ino_t orphan, ino_t parentdir)
{
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
int lostdir;
ino_t oldlfdir;
struct inodesc idesc;
@ -405,10 +412,10 @@ linkup(ino_t orphan, ino_t parentdir)
memset(&idesc, 0, sizeof(struct inodesc));
vp = vget(fs, orphan);
dp = VTOD(vp);
lostdir = (dp->di_mode & LFS_IFMT) == LFS_IFDIR;
lostdir = (lfs_dino_getmode(fs, dp) & LFS_IFMT) == LFS_IFDIR;
pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
pinode(orphan);
if (preen && dp->di_size == 0)
if (preen && lfs_dino_getsize(fs, dp) == 0)
return (0);
if (preen)
printf(" (RECONNECTED)\n");
@ -447,7 +454,7 @@ linkup(ino_t orphan, ino_t parentdir)
}
vp = vget(fs, lfdir);
dp = VTOD(vp);
if ((dp->di_mode & LFS_IFMT) != LFS_IFDIR) {
if ((lfs_dino_getmode(fs, dp) & LFS_IFMT) != LFS_IFDIR) {
pfatal("lost+found IS NOT A DIRECTORY");
if (reply("REALLOCATE") == 0)
return (0);
@ -523,10 +530,11 @@ changeino(ino_t dir, const char *name, ino_t newnum)
int
makeentry(ino_t parent, ino_t ino, const char *name)
{
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct inodesc idesc;
char pathbuf[MAXPATHLEN + 1];
struct uvnode *vp;
uint64_t size;
if (parent < ULFS_ROOTINO || parent >= maxino ||
ino < ULFS_ROOTINO || ino >= maxino)
@ -540,8 +548,10 @@ makeentry(ino_t parent, ino_t ino, const char *name)
idesc.id_name = name;
vp = vget(fs, parent);
dp = VTOD(vp);
if (dp->di_size % LFS_DIRBLKSIZ) {
dp->di_size = roundup(dp->di_size, LFS_DIRBLKSIZ);
size = lfs_dino_getsize(fs, dp);
if (size % LFS_DIRBLKSIZ) {
size = roundup(size, LFS_DIRBLKSIZ);
lfs_dino_setsize(fs, dp, size);
inodirty(VTOI(vp));
}
if ((ckinode(dp, &idesc) & ALTERED) != 0)
@ -558,22 +568,25 @@ makeentry(ino_t parent, ino_t ino, const char *name)
* Attempt to expand the size of a directory
*/
static int
expanddir(struct uvnode *vp, struct ulfs1_dinode *dp, char *name)
expanddir(struct uvnode *vp, union lfs_dinode *dp, char *name)
{
daddr_t lastbn;
struct ubuf *bp;
char *cp, firstblk[LFS_DIRBLKSIZ];
lastbn = lfs_lblkno(fs, dp->di_size);
if (lastbn >= ULFS_NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0)
lastbn = lfs_lblkno(fs, lfs_dino_getsize(fs, dp));
if (lastbn >= ULFS_NDADDR - 1 || lfs_dino_getdb(fs, dp, lastbn) == 0 ||
lfs_dino_getsize(fs, dp) == 0)
return (0);
dp->di_db[lastbn + 1] = dp->di_db[lastbn];
dp->di_db[lastbn] = 0;
lfs_dino_setdb(fs, dp, lastbn + 1, lfs_dino_getdb(fs, dp, lastbn));
lfs_dino_setdb(fs, dp, lastbn, 0);
bp = getblk(vp, lastbn, lfs_sb_getbsize(fs));
VOP_BWRITE(bp);
dp->di_size += lfs_sb_getbsize(fs);
dp->di_blocks += lfs_btofsb(fs, lfs_sb_getbsize(fs));
bread(vp, dp->di_db[lastbn + 1],
lfs_dino_setsize(fs, dp,
lfs_dino_getsize(fs, dp) + lfs_sb_getbsize(fs));
lfs_dino_setblocks(fs, dp,
lfs_dino_getblocks(fs, dp) + lfs_btofsb(fs, lfs_sb_getbsize(fs)));
bread(vp, lfs_dino_getdb(fs, dp, lastbn + 1),
(long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp);
if (bp->b_flags & B_ERROR)
goto bad;
@ -587,7 +600,7 @@ expanddir(struct uvnode *vp, struct ulfs1_dinode *dp, char *name)
cp += LFS_DIRBLKSIZ)
memcpy(cp, &emptydir, sizeof emptydir);
VOP_BWRITE(bp);
bread(vp, dp->di_db[lastbn + 1],
bread(vp, lfs_dino_getdb(fs, dp, lastbn + 1),
(long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp);
if (bp->b_flags & B_ERROR)
goto bad;
@ -601,10 +614,12 @@ expanddir(struct uvnode *vp, struct ulfs1_dinode *dp, char *name)
inodirty(VTOI(vp));
return (1);
bad:
dp->di_db[lastbn] = dp->di_db[lastbn + 1];
dp->di_db[lastbn + 1] = 0;
dp->di_size -= lfs_sb_getbsize(fs);
dp->di_blocks -= lfs_btofsb(fs, lfs_sb_getbsize(fs));
lfs_dino_setdb(fs, dp, lastbn, lfs_dino_getdb(fs, dp, lastbn + 1));
lfs_dino_setdb(fs, dp, lastbn + 1, 0);
lfs_dino_setsize(fs, dp,
lfs_dino_getsize(fs, dp) - lfs_sb_getbsize(fs));
lfs_dino_setblocks(fs, dp,
lfs_dino_getblocks(fs, dp) - lfs_btofsb(fs, lfs_sb_getbsize(fs)));
return (0);
}
@ -616,7 +631,7 @@ allocdir(ino_t parent, ino_t request, int mode)
{
ino_t ino;
char *cp;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct ubuf *bp;
struct lfs_dirtemplate *dirp;
struct uvnode *vp;
@ -627,7 +642,7 @@ allocdir(ino_t parent, ino_t request, int mode)
dirp->dotdot_ino = parent;
vp = vget(fs, ino);
dp = VTOD(vp);
bread(vp, dp->di_db[0], lfs_sb_getfsize(fs), 0, &bp);
bread(vp, lfs_dino_getdb(fs, dp, 0), lfs_sb_getfsize(fs), 0, &bp);
if (bp->b_flags & B_ERROR) {
brelse(bp, 0);
freeino(ino);
@ -639,10 +654,10 @@ allocdir(ino_t parent, ino_t request, int mode)
cp += LFS_DIRBLKSIZ)
memcpy(cp, &emptydir, sizeof emptydir);
VOP_BWRITE(bp);
dp->di_nlink = 2;
lfs_dino_setnlink(fs, dp, 2);
inodirty(VTOI(vp));
if (ino == ULFS_ROOTINO) {
lncntp[ino] = dp->di_nlink;
lncntp[ino] = lfs_dino_getnlink(fs, dp);
cacheino(dp, ino);
return (ino);
}
@ -653,12 +668,12 @@ allocdir(ino_t parent, ino_t request, int mode)
cacheino(dp, ino);
statemap[ino] = statemap[parent];
if (statemap[ino] == DSTATE) {
lncntp[ino] = dp->di_nlink;
lncntp[ino] = lfs_dino_getnlink(fs, dp);
lncntp[parent]++;
}
vp = vget(fs, parent);
dp = VTOD(vp);
dp->di_nlink++;
lfs_dino_setnlink(fs, dp, lfs_dino_getnlink(fs, dp) + 1);
inodirty(VTOI(vp));
return (ino);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.11 2013/06/08 02:12:56 dholland Exp $ */
/* $NetBSD: extern.h,v 1.12 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1994 James A. Jegers
@ -28,13 +28,13 @@ void adjust(struct inodesc *, short);
int allocblk(long);
int allocdir(ino_t, ino_t, int);
void blkerror(ino_t, const char *, daddr_t);
void cacheino(struct ulfs1_dinode *, ino_t);
void cacheino(union lfs_dinode *, ino_t);
int changeino(ino_t, const char *, ino_t);
struct fstab;
void checkinode(ino_t, struct inodesc *);
int chkrange(daddr_t, int);
void ckfini(int);
int ckinode(struct ulfs1_dinode *, struct inodesc *);
int ckinode(union lfs_dinode *, struct inodesc *);
void clri(struct inodesc *, const char *, int);
int dircheck(struct inodesc *, struct lfs_direct *);
void direrror(ino_t, const char *);
@ -47,7 +47,7 @@ void flush(int, struct ubufarea *);
void freeblk(daddr_t, long);
void freeino(ino_t);
void freeinodebuf(void);
int ftypeok(struct ulfs1_dinode *);
int ftypeok(union lfs_dinode *);
void getpathname(char *, size_t, ino_t, ino_t);
void inocleanup(void);
void inodirty(struct inode *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsck.h,v 1.20 2013/06/08 02:12:56 dholland Exp $ */
/* $NetBSD: fsck.h,v 1.21 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -101,7 +101,8 @@ struct ubufarea {
int32_t *b_indir; /* indirect block */
struct lfs *b_fs; /* super block */
struct cg *b_cg;/* cylinder group */
struct ulfs1_dinode *b_dinode; /* inode block */
struct lfs32_dinode *b_dinode32; /* inode block */
struct lfs64_dinode *b_dinode64; /* inode block */
} b_un;
char b_dirty;
};
@ -128,7 +129,7 @@ struct inodesc {
daddr_t id_blkno; /* current block number being examined */
daddr_t id_lblkno; /* current logical block number */
int id_numfrags; /* number of frags contained in block */
quad_t id_filesize; /* for DATA nodes, the size of the directory */
off_t id_filesize; /* for DATA nodes, the size of the directory */
int id_loc; /* for DATA nodes, current location in dir */
int id_entryno; /* for DATA nodes, current entry number */
struct lfs_direct *id_dirp; /* for DATA nodes, ptr to current entry */
@ -206,7 +207,7 @@ int Uflag; /* resolve user names */
ino_t allocino(ino_t, int);
int ino_to_fsba(struct lfs *, ino_t);
struct ulfs1_dinode *ginode(ino_t);
union lfs_dinode *ginode(ino_t);
struct inoinfo *getinoinfo(ino_t);
daddr_t lfs_ino_daddr(ino_t);
void clearinode(ino_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsck_vars.h,v 1.13 2013/06/06 00:52:50 dholland Exp $ */
/* $NetBSD: fsck_vars.h,v 1.14 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -76,6 +76,4 @@ extern int lfmode; /* lost & found directory creation mode */
extern daddr_t n_blks; /* number of blocks in use */
extern ino_t n_files; /* number of files in use */
extern struct ulfs1_dinode zino;
extern int no_roll_forward; /* Don't roll forward */

View File

@ -1,4 +1,4 @@
/* $NetBSD: inode.c,v 1.58 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: inode.c,v 1.59 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -98,7 +98,7 @@ int lfs_maxino(void);
* Get a dinode of a given inum.
* XXX combine this function with vget.
*/
struct ulfs1_dinode *
union lfs_dinode *
ginode(ino_t ino)
{
struct uvnode *vp;
@ -116,21 +116,22 @@ ginode(ino_t ino)
daddr = lfs_if_getdaddr(fs, ifp);
segno = lfs_dtosn(fs, daddr);
din_table[ino] = daddr;
seg_table[segno].su_nbytes += LFS_DINODE1_SIZE;
seg_table[segno].su_nbytes += DINOSIZE(fs);
brelse(bp, 0);
}
return (VTOI(vp)->i_din.ffs1_din);
// XXX bogus cast
return (union lfs_dinode *)(VTOI(vp)->i_din.ffs1_din);
}
/*
* Check validity of held blocks in an inode, recursing through all blocks.
*/
int
ckinode(struct ulfs1_dinode *dp, struct inodesc *idesc)
ckinode(union lfs_dinode *dp, struct inodesc *idesc)
{
ulfs_daddr_t *ap, lbn;
ulfs_daddr_t lbn, pbn;
long ret, n, ndb, offset;
struct ulfs1_dinode dino;
union lfs_dinode dino;
u_int64_t remsize, sizepb;
mode_t mode;
char pathbuf[MAXPATHLEN + 1];
@ -139,30 +140,31 @@ ckinode(struct ulfs1_dinode *dp, struct inodesc *idesc)
if (idesc->id_fix != IGNORE)
idesc->id_fix = DONTKNOW;
idesc->id_entryno = 0;
idesc->id_filesize = dp->di_size;
mode = dp->di_mode & LFS_IFMT;
idesc->id_filesize = lfs_dino_getsize(fs, dp);
mode = lfs_dino_getmode(fs, dp) & LFS_IFMT;
if (mode == LFS_IFBLK || mode == LFS_IFCHR ||
(mode == LFS_IFLNK && (dp->di_size < lfs_sb_getmaxsymlinklen(fs) ||
(mode == LFS_IFLNK && (lfs_dino_getsize(fs, dp) < lfs_sb_getmaxsymlinklen(fs) ||
(lfs_sb_getmaxsymlinklen(fs) == 0 &&
dp->di_blocks == 0))))
lfs_dino_getblocks(fs, dp) == 0))))
return (KEEPON);
/* XXX is this safe if we're 32-bit? */
dino = *dp;
ndb = howmany(dino.di_size, lfs_sb_getbsize(fs));
ndb = howmany(lfs_dino_getsize(fs, &dino), lfs_sb_getbsize(fs));
thisvp = vget(fs, idesc->id_number);
for (lbn = 0; lbn < ULFS_NDADDR; lbn++) {
ap = dino.di_db + lbn;
pbn = lfs_dino_getdb(fs, &dino, lbn);
if (thisvp)
idesc->id_numfrags =
lfs_numfrags(fs, VTOI(thisvp)->i_lfs_fragsize[lbn]);
else {
if (--ndb == 0 && (offset = lfs_blkoff(fs, dino.di_size)) != 0) {
if (--ndb == 0 && (offset = lfs_blkoff(fs, lfs_dino_getsize(fs, &dino))) != 0) {
idesc->id_numfrags =
lfs_numfrags(fs, lfs_fragroundup(fs, offset));
} else
idesc->id_numfrags = lfs_sb_getfrag(fs);
}
if (*ap == 0) {
if (pbn == 0) {
if (idesc->id_type == DATA && ndb >= 0) {
/* An empty block in a directory XXX */
getpathname(pathbuf, sizeof(pathbuf),
@ -172,8 +174,8 @@ ckinode(struct ulfs1_dinode *dp, struct inodesc *idesc)
if (reply("ADJUST LENGTH") == 1) {
vp = vget(fs, idesc->id_number);
dp = VTOD(vp);
dp->di_size = (ap - &dino.di_db[0]) *
lfs_sb_getbsize(fs);
lfs_dino_setsize(fs, dp,
lbn * lfs_sb_getbsize(fs));
printf(
"YOU MUST RERUN FSCK AFTERWARDS\n");
rerun = 1;
@ -183,8 +185,8 @@ ckinode(struct ulfs1_dinode *dp, struct inodesc *idesc)
}
continue;
}
idesc->id_blkno = *ap;
idesc->id_lblkno = ap - &dino.di_db[0];
idesc->id_blkno = pbn;
idesc->id_lblkno = lbn;
if (idesc->id_type == ADDR) {
ret = (*idesc->id_func) (idesc);
} else
@ -193,11 +195,12 @@ ckinode(struct ulfs1_dinode *dp, struct inodesc *idesc)
return (ret);
}
idesc->id_numfrags = lfs_sb_getfrag(fs);
remsize = dino.di_size - lfs_sb_getbsize(fs) * ULFS_NDADDR;
remsize = lfs_dino_getsize(fs, &dino) - lfs_sb_getbsize(fs) * ULFS_NDADDR;
sizepb = lfs_sb_getbsize(fs);
for (ap = &dino.di_ib[0], n = 1; n <= ULFS_NIADDR; ap++, n++) {
if (*ap) {
idesc->id_blkno = *ap;
for (n = 1; n <= ULFS_NIADDR; n++) {
pbn = lfs_dino_getib(fs, &dino, n-1);
if (pbn) {
idesc->id_blkno = pbn;
ret = iblock(idesc, n, remsize);
if (ret & STOP)
return (ret);
@ -211,7 +214,8 @@ ckinode(struct ulfs1_dinode *dp, struct inodesc *idesc)
if (reply("ADJUST LENGTH") == 1) {
vp = vget(fs, idesc->id_number);
dp = VTOD(vp);
dp->di_size -= remsize;
lfs_dino_setsize(fs, dp,
lfs_dino_getsize(fs, dp) - remsize);
remsize = 0;
printf(
"YOU MUST RERUN FSCK AFTERWARDS\n");
@ -355,13 +359,13 @@ chkrange(daddr_t blk, int cnt)
* Enter inodes into the cache.
*/
void
cacheino(struct ulfs1_dinode * dp, ino_t inumber)
cacheino(union lfs_dinode *dp, ino_t inumber)
{
struct inoinfo *inp;
struct inoinfo **inpp, **ninpsort;
unsigned int blks;
unsigned int blks, i;
blks = howmany(dp->di_size, lfs_sb_getbsize(fs));
blks = howmany(lfs_dino_getsize(fs, dp), lfs_sb_getbsize(fs));
if (blks > ULFS_NDADDR)
blks = ULFS_NDADDR + ULFS_NIADDR;
inp = emalloc(sizeof(*inp) + (blks - 1) * sizeof(ulfs_daddr_t));
@ -375,10 +379,15 @@ cacheino(struct ulfs1_dinode * dp, ino_t inumber)
inp->i_parent = (ino_t) 0;
inp->i_dotdot = (ino_t) 0;
inp->i_number = inumber;
inp->i_isize = dp->di_size;
inp->i_isize = lfs_dino_getsize(fs, dp);
inp->i_numblks = blks * sizeof(ulfs_daddr_t);
memcpy(&inp->i_blks[0], &dp->di_db[0], (size_t) inp->i_numblks);
for (i=0; i<blks && i<ULFS_NDADDR; i++) {
inp->i_blks[i] = lfs_dino_getdb(fs, dp, i);
}
for (; i<blks; i++) {
inp->i_blks[i] = lfs_dino_getib(fs, dp, i - ULFS_NDADDR);
}
if (inplast == listmax) {
ninpsort = erealloc(inpsort,
(listmax + 100) * sizeof(struct inoinfo *));
@ -480,9 +489,9 @@ clearinode(ino_t inumber)
SEGUSE *sup;
u_int32_t oldsn = lfs_dtosn(fs, daddr);
seg_table[oldsn].su_nbytes -= LFS_DINODE1_SIZE;
seg_table[oldsn].su_nbytes -= DINOSIZE(fs);
LFS_SEGENTRY(sup, fs, oldsn, bp);
sup->su_nbytes -= LFS_DINODE1_SIZE;
sup->su_nbytes -= DINOSIZE(fs);
LFS_WRITESEGENTRY(sup, fs, oldsn, bp); /* Ifile */
}
}
@ -524,7 +533,7 @@ findino(struct inodesc * idesc)
void
pinode(ino_t ino)
{
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct passwd *pw;
printf(" I=%llu ", (unsigned long long)ino);
@ -534,16 +543,16 @@ pinode(ino_t ino)
if (dp) {
printf(" OWNER=");
#ifndef SMALL
if (Uflag && (pw = getpwuid((int) dp->di_uid)) != 0)
if (Uflag && (pw = getpwuid(lfs_dino_getuid(fs, dp))) != 0)
printf("%s ", pw->pw_name);
else
#endif
printf("%u ", (unsigned) dp->di_uid);
printf("MODE=%o\n", dp->di_mode);
printf("%u ", (unsigned)lfs_dino_getuid(fs, dp));
printf("MODE=%o\n", lfs_dino_getmode(fs, dp));
if (preen)
printf("%s: ", cdevname());
printf("SIZE=%llu ", (unsigned long long) dp->di_size);
printf("MTIME=%s ", print_mtime(dp->di_mtime));
printf("SIZE=%ju ", (uintmax_t) lfs_dino_getsize(fs, dp));
printf("MTIME=%s ", print_mtime(lfs_dino_getmtime(fs, dp)));
}
}
@ -583,7 +592,7 @@ ino_t
allocino(ino_t request, int type)
{
ino_t ino;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
time_t t;
struct uvnode *vp;
struct ubuf *bp;
@ -612,15 +621,17 @@ allocino(ino_t request, int type)
vp = lfs_valloc(fs, ino);
if (vp == NULL)
return (0);
dp = (VTOI(vp)->i_din.ffs1_din);
// XXX bogus cast
dp = (union lfs_dinode *)(VTOI(vp)->i_din.ffs1_din);
bp = getblk(vp, 0, lfs_sb_getfsize(fs));
VOP_BWRITE(bp);
dp->di_mode = type;
lfs_dino_setmode(fs, dp, type);
(void) time(&t);
dp->di_atime = t;
dp->di_mtime = dp->di_ctime = dp->di_atime;
dp->di_size = lfs_sb_getfsize(fs);
dp->di_blocks = lfs_btofsb(fs, lfs_sb_getfsize(fs));
lfs_dino_setatime(fs, dp, t);
lfs_dino_setctime(fs, dp, t);
lfs_dino_setmtime(fs, dp, t);
lfs_dino_setsize(fs, dp, lfs_sb_getfsize(fs));
lfs_dino_setblocks(fs, dp, lfs_btofsb(fs, lfs_sb_getfsize(fs)));
n_files++;
inodirty(VTOI(vp));
typemap[ino] = LFS_IFTODT(type);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs.c,v 1.55 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs.c,v 1.56 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
@ -310,22 +310,24 @@ lfs_vop_bmap(struct uvnode * vp, daddr_t lbn, daddr_t * daddrp)
}
/* Search a block for a specific dinode. */
struct ulfs1_dinode *
lfs_ifind(struct lfs * fs, ino_t ino, struct ubuf * bp)
union lfs_dinode *
lfs_ifind(struct lfs *fs, ino_t ino, struct ubuf *bp)
{
struct ulfs1_dinode *dip = (struct ulfs1_dinode *) bp->b_data;
struct ulfs1_dinode *ldip, *fin;
union lfs_dinode *ldip;
unsigned i, num;
fin = dip + LFS_INOPB(fs);
num = LFS_INOPB(fs);
/*
* Read the inode block backwards, since later versions of the
* inode will supercede earlier ones. Though it is unlikely, it is
* possible that the same inode will appear in the same inode block.
*/
for (ldip = fin - 1; ldip >= dip; --ldip)
if (ldip->di_inumber == ino)
for (i = num; i-- > 0; ) {
ldip = DINO_IN_BLOCK(fs, bp->b_data, i);
if (lfs_dino_getinumber(fs, ldip) == ino)
return (ldip);
}
return NULL;
}
@ -338,7 +340,7 @@ lfs_raw_vget(struct lfs * fs, ino_t ino, int fd, ulfs_daddr_t daddr)
{
struct uvnode *vp;
struct inode *ip;
struct ulfs1_dinode *dip;
union lfs_dinode *dip;
struct ubuf *bp;
int i, hash;
@ -354,7 +356,9 @@ lfs_raw_vget(struct lfs * fs, ino_t ino, int fd, ulfs_daddr_t daddr)
ip = ecalloc(1, sizeof(*ip));
ip->i_din.ffs1_din = ecalloc(1, sizeof(*ip->i_din.ffs1_din));
dip = ecalloc(1, sizeof(*dip));
// XXX bogus cast
ip->i_din.ffs1_din = (struct lfs32_dinode *)dip;
/* Initialize the inode -- from lfs_vcreate. */
ip->inode_ext.lfs = ecalloc(1, sizeof(*ip->inode_ext.lfs));
@ -377,7 +381,12 @@ lfs_raw_vget(struct lfs * fs, ino_t ino, int fd, ulfs_daddr_t daddr)
free(vp);
return NULL;
}
memcpy(ip->i_din.ffs1_din, dip, sizeof(*dip));
// XXX this should go away
if (fs->lfs_is64) {
memcpy(ip->i_din.ffs2_din, &dip->u_64, sizeof(dip->u_64));
} else {
memcpy(ip->i_din.ffs1_din, &dip->u_32, sizeof(dip->u_32));
}
brelse(bp, 0);
}
ip->i_number = ino;

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_user.h,v 1.9 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_user.h,v 1.10 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
@ -72,7 +72,8 @@ typedef int32_t ulfs_daddr_t;
/* Convert between inode pointers and vnode pointers. */
#define VTOI(vp) ((struct inode *)(vp)->v_data)
#define VTOD(vp) (VTOI(vp)->i_din.ffs1_din)
// XXX bogus cast
#define VTOD(vp) ((union lfs_dinode *)(VTOI(vp)->i_din.ffs1_din))
#define sbdirty() ++fsdirty
@ -88,7 +89,7 @@ struct lfs *lfs_init(int, daddr_t, daddr_t, int, int);
struct lfs *lfs_verify(struct lfs *, struct lfs *, struct uvnode *, int);
int check_summary(struct lfs *, union segsum *, ulfs_daddr_t, int, struct uvnode *, void (*)(ulfs_daddr_t, union finfo *));
ulfs_daddr_t try_verify(struct lfs *, struct uvnode *, ulfs_daddr_t, int);
struct ulfs1_dinode *lfs_ifind(struct lfs *, ino_t, struct ubuf *);
union lfs_dinode *lfs_ifind(struct lfs *, ino_t, struct ubuf *);
void call_panic(const char *, ...);
void my_vpanic(int, const char *, va_list);
int extend_ifile(struct lfs *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass1.c,v 1.41 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: pass1.c,v 1.42 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -90,7 +90,7 @@ pass1(void)
ino_t inumber;
int i;
struct inodesc idesc;
struct ulfs1_dinode *tinode;
union lfs_dinode *tinode;
IFILE *ifp;
struct ubuf *bp;
struct ino_daddr **dins;
@ -131,7 +131,7 @@ pass1(void)
if (inumber == 0 || dins[i]->daddr == 0)
continue;
tinode = ginode(inumber);
if (tinode && (tinode->di_mode & LFS_IFMT) == LFS_IFDIR)
if (tinode && (lfs_dino_getmode(fs, tinode) & LFS_IFMT) == LFS_IFDIR)
numdirs++;
}
@ -159,15 +159,41 @@ pass1(void)
free(dins);
}
static int
nonzero_db(union lfs_dinode *dip)
{
unsigned i;
for (i=0; i<ULFS_NDADDR; i++) {
if (lfs_dino_getdb(fs, dip, i) != 0) {
return 1;
}
}
return 0;
}
static int
nonzero_ib(union lfs_dinode *dip)
{
unsigned i;
for (i=0; i<ULFS_NIADDR; i++) {
if (lfs_dino_getib(fs, dip, i) != 0) {
return 1;
}
}
return 0;
}
void
checkinode(ino_t inumber, struct inodesc * idesc)
{
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct uvnode *vp;
struct zlncnt *zlnp;
struct ubuf *bp;
IFILE *ifp;
int ndb, j;
int64_t ndb, j;
mode_t mode;
vp = vget(fs, inumber);
@ -180,14 +206,13 @@ checkinode(ino_t inumber, struct inodesc * idesc)
statemap[inumber] = USTATE;
return;
}
mode = dp->di_mode & LFS_IFMT;
mode = lfs_dino_getmode(fs, dp) & LFS_IFMT;
/* XXX - LFS doesn't have this particular problem (?) */
if (mode == 0) {
if (memcmp(dp->di_db, zino.di_db, ULFS_NDADDR * sizeof(ulfs_daddr_t)) ||
memcmp(dp->di_ib, zino.di_ib, ULFS_NIADDR * sizeof(ulfs_daddr_t)) ||
dp->di_mode || dp->di_size) {
pwarn("mode=o%o, ifmt=o%o\n", dp->di_mode, mode);
if (nonzero_db(dp) || nonzero_ib(dp) ||
lfs_dino_getmode(fs, dp) || lfs_dino_getsize(fs, dp)) {
pwarn("mode=o%o, ifmt=o%o\n", lfs_dino_getmode(fs, dp), mode);
pfatal("PARTIALLY ALLOCATED INODE I=%llu",
(unsigned long long)inumber);
if (reply("CLEAR") == 1) {
@ -200,25 +225,25 @@ checkinode(ino_t inumber, struct inodesc * idesc)
return;
}
lastino = inumber;
if (/* dp->di_size < 0 || */
dp->di_size + lfs_sb_getbsize(fs) - 1 < dp->di_size) {
if (/* lfs_dino_getsize(fs, dp) < 0 || */
lfs_dino_getsize(fs, dp) + lfs_sb_getbsize(fs) - 1 < lfs_dino_getsize(fs, dp)) {
if (debug)
printf("bad size %llu:",
(unsigned long long) dp->di_size);
printf("bad size %ju:",
(uintmax_t)lfs_dino_getsize(fs, dp));
goto unknown;
}
if (!preen && mode == LFS_IFMT && reply("HOLD BAD BLOCK") == 1) {
vp = vget(fs, inumber);
dp = VTOD(vp);
dp->di_size = lfs_sb_getfsize(fs);
dp->di_mode = LFS_IFREG | 0600;
lfs_dino_setsize(fs, dp, lfs_sb_getfsize(fs));
lfs_dino_setmode(fs, dp, LFS_IFREG | 0600);
inodirty(VTOI(vp));
}
ndb = howmany(dp->di_size, lfs_sb_getbsize(fs));
ndb = howmany(lfs_dino_getsize(fs, dp), lfs_sb_getbsize(fs));
if (ndb < 0) {
if (debug)
printf("bad size %llu ndb %d:",
(unsigned long long) dp->di_size, ndb);
printf("bad size %ju ndb %jd:",
(uintmax_t)lfs_dino_getsize(fs, dp), (intmax_t)ndb);
goto unknown;
}
if (mode == LFS_IFBLK || mode == LFS_IFCHR)
@ -228,9 +253,9 @@ checkinode(ino_t inumber, struct inodesc * idesc)
* Fake ndb value so direct/indirect block checks below
* will detect any garbage after symlink string.
*/
if (dp->di_size < lfs_sb_getmaxsymlinklen(fs) ||
(lfs_sb_getmaxsymlinklen(fs) == 0 && dp->di_blocks == 0)) {
ndb = howmany(dp->di_size, sizeof(ulfs_daddr_t));
if (lfs_dino_getsize(fs, dp) < lfs_sb_getmaxsymlinklen(fs) ||
(lfs_sb_getmaxsymlinklen(fs) == 0 && lfs_dino_getblocks(fs, dp) == 0)) {
ndb = howmany(lfs_dino_getsize(fs, dp), sizeof(ulfs_daddr_t));
if (ndb > ULFS_NDADDR) {
j = ndb - ULFS_NDADDR;
for (ndb = 1; j > 1; j--)
@ -240,33 +265,37 @@ checkinode(ino_t inumber, struct inodesc * idesc)
}
}
for (j = ndb; j < ULFS_NDADDR; j++)
if (dp->di_db[j] != 0) {
if (lfs_dino_getdb(fs, dp, j) != 0) {
if (debug)
printf("bad direct addr for size %lld lbn %d: 0x%x\n",
(long long)dp->di_size, j, (unsigned)dp->di_db[j]);
printf("bad direct addr for size %ju lbn %jd: 0x%jx\n",
(uintmax_t)lfs_dino_getsize(fs, dp),
(intmax_t)j,
(intmax_t)lfs_dino_getdb(fs, dp, j));
goto unknown;
}
for (j = 0, ndb -= ULFS_NDADDR; ndb > 0; j++)
ndb /= LFS_NINDIR(fs);
for (; j < ULFS_NIADDR; j++)
if (dp->di_ib[j] != 0) {
if (lfs_dino_getib(fs, dp, j) != 0) {
if (debug)
printf("bad indirect addr for size %lld # %d: 0x%x\n",
(long long)dp->di_size, j, (unsigned)dp->di_ib[j]);
printf("bad indirect addr for size %ju # %jd: 0x%jx\n",
(uintmax_t)lfs_dino_getsize(fs, dp),
(intmax_t)j,
(intmax_t)lfs_dino_getib(fs, dp, j));
goto unknown;
}
if (ftypeok(dp) == 0)
goto unknown;
n_files++;
lncntp[inumber] = dp->di_nlink;
if (dp->di_nlink <= 0) {
lncntp[inumber] = lfs_dino_getnlink(fs, dp);
if (lfs_dino_getnlink(fs, dp) <= 0) {
zlnp = emalloc(sizeof *zlnp);
zlnp->zlncnt = inumber;
zlnp->next = zlnhead;
zlnhead = zlnp;
}
if (mode == LFS_IFDIR) {
if (dp->di_size == 0)
if (lfs_dino_getsize(fs, dp) == 0)
statemap[inumber] = DCLEAR;
else
statemap[inumber] = DSTATE;
@ -279,7 +308,7 @@ checkinode(ino_t inumber, struct inodesc * idesc)
* to rewrite blocks from a file whose directory operation (removal)
* is in progress.
*/
if (dp->di_nlink <= 0) {
if (lfs_dino_getnlink(fs, dp) <= 0) {
LFS_IENTRY(ifp, fs, inumber, bp);
if (lfs_if_getnextfree(fs, ifp) == LFS_ORPHAN_NEXTFREE) {
statemap[inumber] = (mode == LFS_IFDIR ? DCLEAR : FCLEAR);
@ -292,19 +321,21 @@ checkinode(ino_t inumber, struct inodesc * idesc)
brelse(bp, 0);
}
/* XXX: why VTOD(vp) instead of dp here? */
typemap[inumber] = LFS_IFTODT(mode);
badblk = dupblk = 0;
idesc->id_number = inumber;
(void) ckinode(VTOD(vp), idesc);
if (dp->di_blocks != idesc->id_entryno) {
pwarn("INCORRECT BLOCK COUNT I=%llu (%d SHOULD BE %d)",
(unsigned long long)inumber, dp->di_blocks,
if (lfs_dino_getblocks(fs, dp) != idesc->id_entryno) {
pwarn("INCORRECT BLOCK COUNT I=%llu (%ju SHOULD BE %d)",
(unsigned long long)inumber, lfs_dino_getblocks(fs, dp),
idesc->id_entryno);
if (preen)
printf(" (CORRECTED)\n");
else if (reply("CORRECT") == 0)
return;
VTOI(vp)->i_ffs1_blocks = idesc->id_entryno;
lfs_dino_setblocks(fs, VTOD(vp), idesc->id_entryno);
inodirty(VTOI(vp));
}
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass2.c,v 1.25 2015/06/16 23:58:30 christos Exp $ */
/* $NetBSD: pass2.c,v 1.26 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,6 +36,7 @@
#include <sys/buf.h>
#include <ufs/lfs/lfs.h>
#include <ufs/lfs/lfs_accessors.h>
#include <ufs/lfs/lfs_inode.h>
#include <err.h>
@ -59,13 +60,15 @@ static int blksort(const void *, const void *);
void
pass2(void)
{
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct uvnode *vp;
struct inoinfo **inpp, *inp;
struct inoinfo **inpend;
struct inodesc curino;
struct ulfs1_dinode dino;
union lfs_dinode dino;
char pathbuf[MAXPATHLEN + 1];
uint16_t mode;
unsigned ii;
switch (statemap[ULFS_ROOTINO]) {
@ -102,8 +105,10 @@ pass2(void)
errx(EEXIT, "%s", "");
vp = vget(fs, ULFS_ROOTINO);
dp = VTOD(vp);
dp->di_mode &= ~LFS_IFMT;
dp->di_mode |= LFS_IFDIR;
mode = lfs_dino_getmode(fs, dp);
mode &= ~LFS_IFMT;
mode |= LFS_IFDIR;
lfs_dino_setmode(fs, dp, mode);
inodirty(VTOI(vp));
break;
@ -136,7 +141,7 @@ pass2(void)
if (reply("FIX") == 1) {
vp = vget(fs, inp->i_number);
dp = VTOD(vp);
dp->di_size = inp->i_isize;
lfs_dino_setsize(fs, dp, inp->i_isize);
inodirty(VTOI(vp));
}
} else if ((inp->i_isize & (LFS_DIRBLKSIZ - 1)) != 0) {
@ -150,14 +155,21 @@ pass2(void)
if (preen || reply("ADJUST") == 1) {
vp = vget(fs, inp->i_number);
dp = VTOD(vp);
dp->di_size = inp->i_isize;
lfs_dino_setsize(fs, dp, inp->i_isize);
inodirty(VTOI(vp));
}
}
memset(&dino, 0, sizeof(struct ulfs1_dinode));
dino.di_mode = LFS_IFDIR;
dino.di_size = inp->i_isize;
memcpy(&dino.di_db[0], &inp->i_blks[0], (size_t) inp->i_numblks);
memset(&dino, 0, sizeof(dino));
lfs_dino_setmode(fs, &dino, LFS_IFDIR);
lfs_dino_setsize(fs, &dino, inp->i_isize);
for (ii = 0; ii < inp->i_numblks / sizeof(inp->i_blks[0]) &&
ii < ULFS_NDADDR; ii++) {
lfs_dino_setdb(fs, &dino, ii, inp->i_blks[ii]);
}
for (; ii < inp->i_numblks / sizeof(inp->i_blks[0]); ii++) {
lfs_dino_setib(fs, &dino, ii - ULFS_NDADDR,
inp->i_blks[ii]);
}
curino.id_number = inp->i_number;
curino.id_parent = inp->i_parent;
(void) ckinode(&dino, &curino);
@ -203,7 +215,7 @@ pass2check(struct inodesc * idesc)
struct lfs_direct *dirp = idesc->id_dirp;
struct inoinfo *inp;
int n, entrysize, ret = 0;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
const char *errmsg;
struct lfs_direct proto;
char namebuf[MAXPATHLEN + 1];
@ -381,8 +393,8 @@ again:
break;
dp = ginode(dirp->d_ino);
statemap[dirp->d_ino] =
(dp->di_mode & LFS_IFMT) == LFS_IFDIR ? DSTATE : FSTATE;
lncntp[dirp->d_ino] = dp->di_nlink;
(lfs_dino_getmode(fs, dp) & LFS_IFMT) == LFS_IFDIR ? DSTATE : FSTATE;
lncntp[dirp->d_ino] = lfs_dino_getnlink(fs, dp);
goto again;
case DSTATE:

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass4.c,v 1.25 2015/07/28 05:09:34 dholland Exp $ */
/* $NetBSD: pass4.c,v 1.26 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -82,7 +82,7 @@ pass4(void)
{
ino_t inumber;
struct zlncnt *zlnp;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct inodesc idesc;
int n;
@ -119,7 +119,7 @@ pass4(void)
if (check_orphan(&idesc))
break;
dp = ginode(inumber);
if (dp->di_size == 0) {
if (lfs_dino_getsize(fs, dp) == 0) {
const char * msg = (lncntp[inumber] ?
"ZERO LENGTH" : "UNREF ZERO LENGTH");
clri(&idesc, msg, 1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass6.c,v 1.41 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: pass6.c,v 1.42 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -235,9 +235,9 @@ remove_ino(struct uvnode *vp, ino_t ino)
vp = lfs_raw_vget(fs, ino, fs->lfs_ivnode->v_fd, daddr);
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
sup->su_nbytes -= LFS_DINODE1_SIZE;
sup->su_nbytes -= DINOSIZE(fs);
VOP_BWRITE(sbp);
seg_table[lfs_dtosn(fs, daddr)].su_nbytes -= LFS_DINODE1_SIZE;
seg_table[lfs_dtosn(fs, daddr)].su_nbytes -= DINOSIZE(fs);
} else
brelse(bp, 0);
@ -329,7 +329,7 @@ pass6check(struct inodesc * idesc)
}
static void
account_indir(struct uvnode *vp, struct ulfs1_dinode *dp, daddr_t ilbn, daddr_t daddr, int lvl)
account_indir(struct uvnode *vp, union lfs_dinode *dp, daddr_t ilbn, daddr_t daddr, int lvl)
{
struct ubuf *bp;
int32_t *dap, *odap, *buf, *obuf;
@ -376,21 +376,21 @@ account_indir(struct uvnode *vp, struct ulfs1_dinode *dp, daddr_t ilbn, daddr_t
* Account block changes between new found inode and existing inode.
*/
static void
account_block_changes(struct ulfs1_dinode *dp)
account_block_changes(union lfs_dinode *dp)
{
int i;
daddr_t lbn, off, odaddr;
struct uvnode *vp;
struct inode *ip;
vp = vget(fs, dp->di_inumber);
vp = vget(fs, lfs_dino_getinumber(fs, dp));
ip = (vp ? VTOI(vp) : NULL);
/* Check direct block holdings between existing and new */
for (i = 0; i < ULFS_NDADDR; i++) {
odaddr = (ip ? ip->i_ffs1_db[i] : 0x0);
if (dp->di_db[i] > 0 && dp->di_db[i] != odaddr)
rfw_update_single(vp, i, dp->di_db[i],
if (lfs_dino_getdb(fs, dp, i) > 0 && lfs_dino_getdb(fs, dp, i) != odaddr)
rfw_update_single(vp, i, lfs_dino_getdb(fs, dp, i),
lfs_dblksize(fs, dp, i));
}
@ -398,10 +398,10 @@ account_block_changes(struct ulfs1_dinode *dp)
off = 0;
for (i = 0; i < ULFS_NIADDR; i++) {
odaddr = (ip ? ip->i_ffs1_ib[i] : 0x0);
if (dp->di_ib[i] > 0 && dp->di_ib[i] != odaddr) {
if (lfs_dino_getib(fs, dp, i) > 0 && lfs_dino_getib(fs, dp, i) != odaddr) {
lbn = -(ULFS_NDADDR + off + i);
rfw_update_single(vp, i, dp->di_ib[i], lfs_sb_getbsize(fs));
account_indir(vp, dp, lbn, dp->di_ib[i], i);
rfw_update_single(vp, i, lfs_dino_getib(fs, dp, i), lfs_sb_getbsize(fs));
account_indir(vp, dp, lbn, lfs_dino_getib(fs, dp, i), i);
}
if (off == 0)
off = LFS_NINDIR(fs);
@ -418,14 +418,14 @@ account_block_changes(struct ulfs1_dinode *dp)
* free list accounting is done.
*/
static void
readdress_inode(struct ulfs1_dinode *dp, ulfs_daddr_t daddr)
readdress_inode(union lfs_dinode *dp, ulfs_daddr_t daddr)
{
IFILE *ifp;
SEGUSE *sup;
struct ubuf *bp;
int sn;
ulfs_daddr_t odaddr;
ino_t thisino = dp->di_inumber;
ino_t thisino = lfs_dino_getinumber(fs, dp);
struct uvnode *vp;
/* Recursively check all block holdings, account changes */
@ -439,28 +439,34 @@ readdress_inode(struct ulfs1_dinode *dp, ulfs_daddr_t daddr)
VOP_BWRITE(bp);
if (debug)
pwarn("readdress ino %d from 0x%x to 0x%x mode %o nlink %d\n",
(int)dp->di_inumber,
pwarn("readdress ino %ju from 0x%x to 0x%x mode %o nlink %d\n",
(uintmax_t)lfs_dino_getinumber(fs, dp),
(unsigned)odaddr,
(unsigned)daddr,
(int)dp->di_mode, (int)dp->di_nlink);
(int)lfs_dino_getmode(fs, dp),
(int)lfs_dino_getnlink(fs, dp));
/* Copy over preexisting in-core inode, if any */
vp = vget(fs, thisino);
memcpy(VTOI(vp)->i_din.ffs1_din, dp, sizeof(*dp));
/* XXX this is lame */
if (fs->lfs_is64) {
memcpy(VTOI(vp)->i_din.ffs2_din, &dp->u_64, sizeof(dp->u_64));
} else {
memcpy(VTOI(vp)->i_din.ffs1_din, &dp->u_32, sizeof(dp->u_32));
}
/* Finally account the inode itself */
sn = lfs_dtosn(fs, odaddr);
LFS_SEGENTRY(sup, fs, sn, bp);
sup->su_nbytes -= LFS_DINODE1_SIZE;
sup->su_nbytes -= DINOSIZE(fs);
VOP_BWRITE(bp);
seg_table[sn].su_nbytes -= LFS_DINODE1_SIZE;
seg_table[sn].su_nbytes -= DINOSIZE(fs);
sn = lfs_dtosn(fs, daddr);
LFS_SEGENTRY(sup, fs, sn, bp);
sup->su_nbytes += LFS_DINODE1_SIZE;
sup->su_nbytes += DINOSIZE(fs);
VOP_BWRITE(bp);
seg_table[sn].su_nbytes += LFS_DINODE1_SIZE;
seg_table[sn].su_nbytes += DINOSIZE(fs);
}
/*
@ -519,9 +525,9 @@ alloc_inode(ino_t thisino, ulfs_daddr_t daddr)
/* Account for new location */
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), bp);
sup->su_nbytes += LFS_DINODE1_SIZE;
sup->su_nbytes += DINOSIZE(fs);
VOP_BWRITE(bp);
seg_table[lfs_dtosn(fs, daddr)].su_nbytes += LFS_DINODE1_SIZE;
seg_table[lfs_dtosn(fs, daddr)].su_nbytes += DINOSIZE(fs);
}
/*
@ -550,9 +556,10 @@ pass6(void)
SEGUSE *sup;
SEGSUM *sp;
struct ubuf *bp, *ibp, *sbp, *cbp;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
struct inodesc idesc;
int i, j, bc, hassuper;
unsigned k;
int nnewfiles, ndelfiles, nmvfiles;
int sn, curseg;
char *ibbuf;
@ -658,17 +665,16 @@ pass6(void)
brelse(ibp, 0);
j = 0;
for (dp = (struct ulfs1_dinode *)ibbuf;
dp < (struct ulfs1_dinode *)ibbuf + LFS_INOPB(fs);
++dp) {
if (dp->di_inumber == 0 ||
dp->di_inumber == lfs_sb_getifile(fs))
for (k = 0; k < LFS_INOPB(fs); k++) {
dp = DINO_IN_BLOCK(fs, ibbuf, k);
if (lfs_dino_getinumber(fs, dp) == 0 ||
lfs_dino_getinumber(fs, dp) == lfs_sb_getifile(fs))
continue;
/* Basic sanity checks */
if (dp->di_nlink < 0
if (lfs_dino_getnlink(fs, dp) < 0
#if 0
|| dp->di_u.inumber < 0
|| dp->di_size < 0
|| lfs_dino_getinumber(fs, dp) < 0
|| lfs_dino_getsize(fs, dp) < 0
#endif
) {
pwarn("BAD INODE AT 0x%" PRIx32 "\n",
@ -678,15 +684,15 @@ pass6(void)
goto out;
}
vp = vget(fs, dp->di_inumber);
vp = vget(fs, lfs_dino_getinumber(fs, dp));
/*
* Four cases:
* (1) Invalid inode (nlink == 0).
* If currently allocated, remove.
*/
if (dp->di_nlink == 0) {
remove_ino(vp, dp->di_inumber);
if (lfs_dino_getnlink(fs, dp) == 0) {
remove_ino(vp, lfs_dino_getinumber(fs, dp));
++ndelfiles;
continue;
}
@ -700,7 +706,7 @@ pass6(void)
if (!(lfs_ss_getflags(fs, sp) & SS_DIROP))
pfatal("NEW FILE IN NON-DIROP PARTIAL SEGMENT");
else {
inums[j++] = dp->di_inumber;
inums[j++] = lfs_dino_getinumber(fs, dp);
nnewfiles++;
}
continue;
@ -710,12 +716,16 @@ pass6(void)
* allocated inode. Delete old file
* and proceed as in (2).
*/
if (vp && VTOI(vp)->i_ffs1_gen < dp->di_gen) {
remove_ino(vp, dp->di_inumber);
if (vp && (
fs->lfs_is64 ?
VTOI(vp)->i_ffs2_gen :
VTOI(vp)->i_ffs1_gen
) < lfs_dino_getgen(fs, dp)) {
remove_ino(vp, lfs_dino_getinumber(fs, dp));
if (!(lfs_ss_getflags(fs, sp) & SS_DIROP))
pfatal("NEW FILE VERSION IN NON-DIROP PARTIAL SEGMENT");
else {
inums[j++] = dp->di_inumber;
inums[j++] = lfs_dino_getinumber(fs, dp);
ndelfiles++;
nnewfiles++;
}
@ -728,24 +738,28 @@ pass6(void)
* only. We'll pick up any new
* blocks when we do the block pass.
*/
if (vp && VTOI(vp)->i_ffs1_gen == dp->di_gen) {
if (vp && (
fs->lfs_is64 ?
VTOI(vp)->i_ffs2_gen :
VTOI(vp)->i_ffs1_gen
) == lfs_dino_getgen(fs, dp)) {
nmvfiles++;
readdress_inode(dp, ibdaddr);
/* Update with new info */
VTOD(vp)->di_mode = dp->di_mode;
VTOD(vp)->di_nlink = dp->di_nlink;
lfs_dino_setmode(fs, VTOD(vp), lfs_dino_getmode(fs, dp));
lfs_dino_setnlink(fs, VTOD(vp), lfs_dino_getmode(fs, dp));
/* XXX size is important */
VTOD(vp)->di_size = dp->di_size;
VTOD(vp)->di_atime = dp->di_atime;
VTOD(vp)->di_atimensec = dp->di_atimensec;
VTOD(vp)->di_mtime = dp->di_mtime;
VTOD(vp)->di_mtimensec = dp->di_mtimensec;
VTOD(vp)->di_ctime = dp->di_ctime;
VTOD(vp)->di_ctimensec = dp->di_ctimensec;
VTOD(vp)->di_flags = dp->di_flags;
VTOD(vp)->di_uid = dp->di_uid;
VTOD(vp)->di_gid = dp->di_gid;
lfs_dino_setsize(fs, VTOD(vp), lfs_dino_getsize(fs, dp));
lfs_dino_setatime(fs, VTOD(vp), lfs_dino_getatime(fs, dp));
lfs_dino_setatimensec(fs, VTOD(vp), lfs_dino_getatimensec(fs, dp));
lfs_dino_setmtime(fs, VTOD(vp), lfs_dino_getmtime(fs, dp));
lfs_dino_setmtimensec(fs, VTOD(vp), lfs_dino_getmtimensec(fs, dp));
lfs_dino_setctime(fs, VTOD(vp), lfs_dino_getctime(fs, dp));
lfs_dino_setctimensec(fs, VTOD(vp), lfs_dino_getctimensec(fs, dp));
lfs_dino_setflags(fs, VTOD(vp), lfs_dino_getflags(fs, dp));
lfs_dino_setuid(fs, VTOD(vp), lfs_dino_getuid(fs, dp));
lfs_dino_setgid(fs, VTOD(vp), lfs_dino_getgid(fs, dp));
inodirty(VTOI(vp));
}
}
@ -756,10 +770,15 @@ pass6(void)
/* We'll get the blocks later */
if (debug)
pwarn("alloc ino %d nlink %d\n",
(int)inums[j], VTOD(vp)->di_nlink);
memset(VTOD(vp)->di_db, 0, (ULFS_NDADDR + ULFS_NIADDR) *
sizeof(ulfs_daddr_t));
VTOD(vp)->di_blocks = 0;
(int)inums[j], lfs_dino_getnlink(fs, VTOD(vp)));
for (k=0; k<ULFS_NDADDR; k++) {
lfs_dino_setdb(fs, VTOD(vp), k, 0);
}
for (k=0; k<ULFS_NIADDR; k++) {
lfs_dino_setib(fs, VTOD(vp), k, 0);
}
lfs_dino_setblocks(fs, VTOD(vp), 0);
vp->v_uflag |= VU_DIROP;
inodirty(VTOI(vp));

View File

@ -1,4 +1,4 @@
/* $NetBSD: segwrite.c,v 1.40 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: segwrite.c,v 1.41 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
@ -248,7 +248,7 @@ int
lfs_writeinode(struct lfs * fs, struct segment * sp, struct inode * ip)
{
struct ubuf *bp, *ibp;
struct ulfs1_dinode *cdp;
union lfs_dinode *cdp;
IFILE *ifp;
SEGUSE *sup;
SEGSUM *ssp;
@ -277,8 +277,12 @@ lfs_writeinode(struct lfs * fs, struct segment * sp, struct inode * ip)
gotblk++;
/* Zero out inode numbers */
for (i = 0; i < LFS_INOPB(fs); ++i)
((struct ulfs1_dinode *) sp->ibp->b_data)[i].di_inumber = 0;
for (i = 0; i < LFS_INOPB(fs); ++i) {
union lfs_dinode *tmpdip;
tmpdip = DINO_IN_BLOCK(fs, sp->ibp->b_data, i);
lfs_dino_setinumber(fs, tmpdip, 0);
}
++sp->start_bpp;
lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
@ -305,20 +309,29 @@ lfs_writeinode(struct lfs * fs, struct segment * sp, struct inode * ip)
* already been gathered.
*/
if (ip->i_number == LFS_IFILE_INUM && sp->idp) {
*(sp->idp) = *ip->i_din.ffs1_din;
// XXX weak
if (fs->lfs_is64) {
sp->idp->u_64 = *ip->i_din.ffs2_din;
} else {
sp->idp->u_32 = *ip->i_din.ffs1_din;
}
ip->i_lfs_osize = ip->i_ffs1_size;
return 0;
}
bp = sp->ibp;
cdp = ((struct ulfs1_dinode *) bp->b_data) + (sp->ninodes % LFS_INOPB(fs));
*cdp = *ip->i_din.ffs1_din;
cdp = DINO_IN_BLOCK(fs, bp->b_data, sp->ninodes % LFS_INOPB(fs));
// XXX weak
if (fs->lfs_is64) {
cdp->u_64 = *ip->i_din.ffs2_din;
} else {
cdp->u_32 = *ip->i_din.ffs1_din;
}
/* If all blocks are goig to disk, update the "size on disk" */
ip->i_lfs_osize = ip->i_ffs1_size;
if (ip->i_number == LFS_IFILE_INUM) /* We know sp->idp == NULL */
sp->idp = ((struct ulfs1_dinode *) bp->b_data) +
(sp->ninodes % LFS_INOPB(fs));
sp->idp = DINO_IN_BLOCK(fs, bp->b_data, sp->ninodes % LFS_INOPB(fs));
if (gotblk) {
LFS_LOCK_BUF(bp);
assert(!(bp->b_flags & B_INVAL));
@ -356,7 +369,7 @@ lfs_writeinode(struct lfs * fs, struct segment * sp, struct inode * ip)
if (daddr != LFS_UNUSED_DADDR) {
u_int32_t oldsn = lfs_dtosn(fs, daddr);
LFS_SEGENTRY(sup, fs, oldsn, bp);
sup->su_nbytes -= LFS_DINODE1_SIZE;
sup->su_nbytes -= DINOSIZE(fs);
redo_ifile =
(ino == LFS_IFILE_INUM && !(bp->b_flags & B_GATHERED));
if (redo_ifile)
@ -801,7 +814,7 @@ lfs_writeseg(struct lfs * fs, struct segment * sp)
lfs_ss_setflags(fs, ssp, lfs_ss_getflags(fs, ssp) | SS_RFW);
ninos = (lfs_ss_getninos(fs, ssp) + LFS_INOPB(fs) - 1) / LFS_INOPB(fs);
sup->su_nbytes += lfs_ss_getninos(fs, ssp) * LFS_DINODE1_SIZE;
sup->su_nbytes += lfs_ss_getninos(fs, ssp) * DINOSIZE(fs);
if (lfs_sb_getversion(fs) == 1)
sup->su_olastmod = write_time;

View File

@ -1,4 +1,4 @@
/* $NetBSD: setup.c,v 1.54 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: setup.c,v 1.55 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -439,7 +439,7 @@ setup(const char *dev)
/* Initialize Ifile entry */
din_table[lfs_sb_getifile(fs)] = lfs_sb_getidaddr(fs);
seg_table[lfs_dtosn(fs, lfs_sb_getidaddr(fs))].su_nbytes += LFS_DINODE1_SIZE;
seg_table[lfs_dtosn(fs, lfs_sb_getidaddr(fs))].su_nbytes += DINOSIZE(fs);
#ifndef VERBOSE_BLOCKMAP
bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));

View File

@ -1,4 +1,4 @@
/* $NetBSD: utilities.c,v 1.40 2015/07/28 05:09:34 dholland Exp $ */
/* $NetBSD: utilities.c,v 1.41 2015/08/12 18:28:00 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -63,9 +63,9 @@ long diskreads, totalreads; /* Disk cache statistics */
extern off_t locked_queue_bytes;
int
ftypeok(struct ulfs1_dinode * dp)
ftypeok(union lfs_dinode * dp)
{
switch (dp->di_mode & LFS_IFMT) {
switch (lfs_dino_getmode(fs, dp) & LFS_IFMT) {
case LFS_IFDIR:
case LFS_IFREG:
@ -78,7 +78,7 @@ ftypeok(struct ulfs1_dinode * dp)
default:
if (debug)
pwarn("bad file type 0%o\n", dp->di_mode);
pwarn("bad file type 0%o\n", lfs_dino_getmode(fs, dp));
return (0);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vars.c,v 1.17 2013/06/08 02:16:03 dholland Exp $ */
/* $NetBSD: vars.c,v 1.18 2015/08/12 18:28:00 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
* All rights reserved.
@ -77,6 +77,4 @@ int lfmode; /* lost & found directory creation mode */
daddr_t n_blks; /* number of blocks in use */
ino_t n_files; /* number of files in use */
struct ulfs1_dinode zino;
int no_roll_forward = 0; /* don't roll forward */

View File

@ -1,4 +1,4 @@
/* $NetBSD: make_lfs.c,v 1.42 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: make_lfs.c,v 1.43 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -62,7 +62,7 @@
#if 0
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
#else
__RCSID("$NetBSD: make_lfs.c,v 1.42 2015/08/12 18:25:52 dholland Exp $");
__RCSID("$NetBSD: make_lfs.c,v 1.43 2015/08/12 18:28:01 dholland Exp $");
#endif
#endif /* not lint */
@ -134,10 +134,9 @@ static const struct dlfs dlfs32_default = {
.dlfs_minfree = MINFREE,
.dlfs_maxfilesize = 0,
.dlfs_fsbpseg = 0,
.dlfs_inopb = DFL_LFSBLOCK/sizeof(struct ulfs1_dinode),
.dlfs_inopb = DFL_LFSBLOCK/sizeof(struct lfs32_dinode),
.dlfs_ifpb = DFL_LFSBLOCK/sizeof(IFILE32),
.dlfs_sepb = DFL_LFSBLOCK/sizeof(SEGUSE),
/* XXX ondisk32 */
.dlfs_nindir = DFL_LFSBLOCK/sizeof(int32_t),
.dlfs_nseg = 0,
.dlfs_nspf = 0,
@ -200,7 +199,7 @@ static const struct dlfs64 dlfs64_default = {
.dlfs_minfree = MINFREE,
.dlfs_maxfilesize = 0,
.dlfs_fsbpseg = 0,
.dlfs_inopb = DFL_LFSBLOCK/sizeof(struct ulfs1_dinode),
.dlfs_inopb = DFL_LFSBLOCK/sizeof(struct lfs64_dinode),
.dlfs_ifpb = DFL_LFSBLOCK/sizeof(IFILE64),
.dlfs_sepb = DFL_LFSBLOCK/sizeof(SEGUSE),
.dlfs_nindir = DFL_LFSBLOCK/sizeof(int64_t),
@ -217,7 +216,7 @@ static const struct dlfs64 dlfs64_default = {
.dlfs_blktodb = 0,
.dlfs_sushift = 0,
.dlfs_sboffs = { 0 },
.dlfs_maxsymlinklen = ULFS1_MAXSYMLINKLEN,
.dlfs_maxsymlinklen = ULFS2_MAXSYMLINKLEN,
.dlfs_nclean = 0,
.dlfs_fsmnt = { 0 },
.dlfs_pflags = LFS_PF_CLEAN,
@ -259,7 +258,7 @@ struct lfs_direct lfs_lf_dir[] = {
#endif
void pwarn(const char *, ...);
static void make_dinode(ino_t, struct ulfs1_dinode *, int, struct lfs *);
static void make_dinode(ino_t, union lfs_dinode *, int, struct lfs *);
static void make_dir( void *, struct lfs_direct *, int);
static uint64_t maxfilesize(int);
@ -284,23 +283,29 @@ maxfilesize(int bshift)
* directory.
*/
static void
make_dinode(ino_t ino, struct ulfs1_dinode *dip, int nfrags, struct lfs *fs)
make_dinode(ino_t ino, union lfs_dinode *dip, int nfrags, struct lfs *fs)
{
int i;
int nblocks, bb, base, factor, lvl;
time_t t;
nblocks = howmany(nfrags, lfs_sb_getfrag(fs));
if (nblocks >= ULFS_NDADDR)
nfrags = roundup(nfrags, lfs_sb_getfrag(fs));
dip->di_nlink = 1;
dip->di_blocks = nfrags;
lfs_dino_setnlink(fs, dip, 1);
lfs_dino_setblocks(fs, dip, nfrags);
dip->di_size = (nfrags << lfs_sb_getffshift(fs));
dip->di_atime = dip->di_mtime = dip->di_ctime = lfs_sb_gettstamp(fs);
dip->di_atimensec = dip->di_mtimensec = dip->di_ctimensec = 0;
dip->di_inumber = ino;
dip->di_gen = 1;
lfs_dino_setsize(fs, dip, nfrags << lfs_sb_getffshift(fs));
t = lfs_sb_gettstamp(fs);
lfs_dino_setatime(fs, dip, t);
lfs_dino_setmtime(fs, dip, t);
lfs_dino_setctime(fs, dip, t);
lfs_dino_setatimensec(fs, dip, 0);
lfs_dino_setmtimensec(fs, dip, 0);
lfs_dino_setctimensec(fs, dip, 0);
lfs_dino_setinumber(fs, dip, ino);
lfs_dino_setgen(fs, dip, 1);
if (ULFS_NDADDR < nblocks) {
/* Count up how many indirect blocks we need, recursively */
@ -311,21 +316,22 @@ make_dinode(ino_t ino, struct ulfs1_dinode *dip, int nfrags, struct lfs *fs)
ifibc += bb;
--bb;
}
dip->di_blocks += lfs_blkstofrags(fs, ifibc);
lfs_dino_setblocks(fs, dip,
lfs_dino_getblocks(fs, dip) + lfs_blkstofrags(fs, ifibc));
}
/* Assign the block addresses for the ifile */
for (i = 0; i < MIN(nblocks,ULFS_NDADDR); i++) {
dip->di_db[i] = 0x0;
lfs_dino_setdb(fs, dip, i, 0x0);
}
if (nblocks > ULFS_NDADDR) {
dip->di_ib[0] = 0x0;
lfs_dino_setib(fs, dip, 0, 0x0);
bb = howmany(nblocks - ULFS_NDADDR, LFS_NINDIR(fs)) - 1;
factor = LFS_NINDIR(fs);
base = -ULFS_NDADDR - factor;
lvl = 1;
while (bb > 0) {
dip->di_ib[lvl] = 0x0;
lfs_dino_setib(fs, dip, lvl, 0x0);
bb = howmany(bb, LFS_NINDIR(fs));
--bb;
factor *= LFS_NINDIR(fs);
@ -363,7 +369,7 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
int resvseg, int version, daddr_t start, int ibsize, int interleave,
u_int32_t roll_id)
{
struct ulfs1_dinode *dip; /* Pointer to a disk inode */
union lfs_dinode *dip; /* Pointer to a disk inode */
CLEANERINFO *cip; /* Segment cleaner information table */
IFILE *ipall; /* Pointer to array of ifile structures */
IFILE64 *ip64 = NULL;
@ -413,6 +419,7 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
} else {
fs->lfs_dlfs_u.u_32 = dlfs32_default;
}
fs->lfs_is64 = is64;
fs->lfs_ivnode = vp;
fs->lfs_devvp = save_devvp;
@ -528,11 +535,11 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
lfs_sb_setssize(fs, ssize);
lfs_sb_setibsize(fs, ibsize);
}
lfs_sb_setinopb(fs, lfs_sb_getibsize(fs) / sizeof(struct ulfs1_dinode));
lfs_sb_setinopb(fs, lfs_sb_getibsize(fs) / DINOSIZE(fs));
lfs_sb_setminfree(fs, minfree);
if (version > 1) {
lfs_sb_setinopf(fs, secsize/LFS_DINODE1_SIZE);
lfs_sb_setinopf(fs, secsize/DINOSIZE(fs));
lfs_sb_setinterleave(fs, interleave);
if (roll_id == 0)
roll_id = arc4random();
@ -694,17 +701,23 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
* Initialize the Ifile inode. Do this before we do anything
* with the Ifile or segment tables.
*/
dip = VTOI(fs->lfs_ivnode)->i_din.ffs1_din = (struct ulfs1_dinode *)
malloc(sizeof(*dip));
dip = malloc(sizeof(*dip));
if (dip == NULL)
err(1, NULL);
// XXX lame
if (fs->lfs_is64) {
VTOI(fs->lfs_ivnode)->i_din.ffs2_din = &dip->u_64;
} else {
VTOI(fs->lfs_ivnode)->i_din.ffs1_din = &dip->u_32;
}
memset(dip, 0, sizeof(*dip));
dip->di_mode = LFS_IFREG | 0600;
dip->di_flags = SF_IMMUTABLE;
lfs_dino_setmode(fs, dip, LFS_IFREG | 0600);
lfs_dino_setflags(fs, dip, SF_IMMUTABLE);
make_dinode(LFS_IFILE_INUM, dip,
lfs_blkstofrags(fs, lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs) + 1), fs);
dip->di_size = (lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs) + 1) << lfs_sb_getbshift(fs);
for (i = 0; i < ULFS_NDADDR && i < (dip->di_size >> lfs_sb_getbshift(fs)); i++)
lfs_dino_setsize(fs, dip, (lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs) + 1) << lfs_sb_getbshift(fs));
for (i = 0; i < ULFS_NDADDR && i < (lfs_dino_getsize(fs, dip) >> lfs_sb_getbshift(fs)); i++)
VTOI(fs->lfs_ivnode)->i_lfs_fragsize[i] = lfs_sb_getbsize(fs);
/*
@ -762,17 +775,21 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
/* Initialize root directory */
vp = lfs_raw_vget(fs, ULFS_ROOTINO, devfd, 0x0);
dip = VTOI(vp)->i_din.ffs1_din;
// XXX bogus cast
dip = (union lfs_dinode *)VTOI(vp)->i_din.ffs1_din;
make_dinode(ULFS_ROOTINO, dip, howmany(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs)), fs);
dip->di_mode = LFS_IFDIR | UMASK;
VTOI(vp)->i_lfs_osize = dip->di_size = LFS_DIRBLKSIZ;
lfs_dino_setmode(fs, dip, LFS_IFDIR | UMASK);
VTOI(vp)->i_lfs_osize = LFS_DIRBLKSIZ;
#ifdef MAKE_LF_DIR
VTOI(vp)->i_nlink = dip->di_nlink = 3;
VTOI(vp)->i_nlink = 3;
#else
VTOI(vp)->i_nlink = dip->di_nlink = 2;
VTOI(vp)->i_nlink = 2;
#endif
VTOI(vp)->i_lfs_effnblks = dip->di_blocks =
VTOI(vp)->i_lfs_effnblks =
lfs_btofsb(fs, roundup(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs)));
lfs_dino_setsize(fs, dip, VTOI(vp)->i_lfs_osize);
lfs_dino_setnlink(fs, dip, VTOI(vp)->i_nlink);
lfs_dino_setblocks(fs, dip, VTOI(vp)->i_lfs_effnblks);
for (i = 0; i < ULFS_NDADDR && i < howmany(LFS_DIRBLKSIZ, lfs_sb_getbsize(fs)); i++)
VTOI(vp)->i_lfs_fragsize[i] = lfs_sb_getbsize(fs);
if (LFS_DIRBLKSIZ < lfs_sb_getbsize(fs))

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfsv1.c,v 1.13 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: lfsv1.c,v 1.14 2015/08/12 18:28:01 dholland Exp $ */
#define LIBSA_LFS
#define REQUIRED_LFS_VERSION 1
@ -13,7 +13,7 @@
#define ufs_ls lfsv1_ls
#endif
#define ufs_dinode ulfs1_dinode
#define ufs_dinode lfs32_dinode
#define fs_bsize lfs_dlfs_u.u_32.dlfs_ibsize

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfsv2.c,v 1.13 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: lfsv2.c,v 1.14 2015/08/12 18:28:01 dholland Exp $ */
#define LIBSA_LFS
#define REQUIRED_LFS_VERSION 2
@ -13,7 +13,7 @@
#define ufs_ls lfsv2_ls
#endif
#define ufs_dinode ulfs1_dinode
#define ufs_dinode lfs32_dinode
#define fs_bsize lfs_dlfs_u.u_32.dlfs_bsize

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs.c,v 1.71 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: ufs.c,v 1.72 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1993
@ -114,6 +114,9 @@ struct salfs {
#define STRUCT_LFS struct salfs
#include <ufs/lfs/lfs_accessors.h>
/* override this to avoid a mess with the dinode accessors */
#define lfs_dino_getsize(fs, dp) ((dp)->di_size)
typedef struct salfs FS;
#define fs_magic lfs_dlfs_u.u_32.dlfs_magic
#define fs_maxsymlinklen lfs_dlfs_u.u_32.dlfs_maxsymlinklen

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs.h,v 1.179 2015/08/12 18:27:18 dholland Exp $ */
/* $NetBSD: lfs.h,v 1.180 2015/08/12 18:28:01 dholland Exp $ */
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
/* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */
@ -353,7 +353,7 @@ struct lfs_odirtemplate {
* are defined by types with precise widths.
*/
struct ulfs1_dinode {
struct lfs32_dinode {
u_int16_t di_mode; /* 0: IFMT, permissions; see below. */
int16_t di_nlink; /* 2: File link count. */
u_int32_t di_inumber; /* 4: Inode number. */
@ -374,7 +374,7 @@ struct ulfs1_dinode {
u_int64_t di_modrev; /* 120: i_modrev for NFSv4 */
};
struct ulfs2_dinode {
struct lfs64_dinode {
u_int16_t di_mode; /* 0: IFMT, permissions; see below. */
int16_t di_nlink; /* 2: File link count. */
u_int32_t di_uid; /* 4: File owner. */
@ -402,6 +402,11 @@ struct ulfs2_dinode {
u_int64_t di_spare[1]; /* 244: Reserved; currently unused */
};
union lfs_dinode {
struct lfs64_dinode u_64;
struct lfs32_dinode u_32;
};
/*
* The di_db fields may be overlaid with other information for
* file types that do not have associated disk storage. Block
@ -412,8 +417,8 @@ struct ulfs2_dinode {
#define di_rdev di_db[0]
/* Size of the on-disk inode. */
#define LFS_DINODE1_SIZE (sizeof(struct ulfs1_dinode)) /* 128 */
#define LFS_DINODE2_SIZE (sizeof(struct ulfs2_dinode))
//#define LFS_DINODE1_SIZE (sizeof(struct ulfs1_dinode)) /* 128 */
//#define LFS_DINODE2_SIZE (sizeof(struct ulfs2_dinode))
/* File types, found in the upper bits of di_mode. */
#define LFS_IFMT 0170000 /* Mask of file type. */
@ -1007,7 +1012,7 @@ struct segment {
struct buf **cbpp; /* pointer to next available bp */
struct buf **start_bpp; /* pointer to first bp in this set */
struct buf *ibp; /* buffer pointer to inode page */
struct ulfs1_dinode *idp; /* pointer to ifile dinode */
union lfs_dinode *idp; /* pointer to ifile dinode */
FINFO *fip; /* current fileinfo pointer */
struct vnode *vp; /* vnode being gathered */
void *segsum; /* segment summary info */

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_accessors.h,v 1.12 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_accessors.h,v 1.13 2015/08/12 18:28:01 dholland Exp $ */
/* from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp */
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
@ -160,6 +160,9 @@
#define STRUCT_LFS struct lfs
#endif
/*
* dinodes
*/
/*
* Maximum length of a symlink that can be stored within the inode.
@ -171,6 +174,95 @@
((ip)->i_ump->um_fstype == ULFS1) ? \
ULFS1_MAXSYMLINKLEN : ULFS2_MAXSYMLINKLEN
#define DINOSIZE(fs) ((fs)->lfs_is64 ? sizeof(struct lfs64_dinode) : sizeof(struct lfs32_dinode))
#define DINO_IN_BLOCK(fs, base, ix) \
((union lfs_dinode *)((char *)(base) + DINOSIZE(fs) * (ix)))
#define LFS_DEF_DINO_ACCESSOR(type, type32, field) \
static __unused inline type \
lfs_dino_get##field(STRUCT_LFS *fs, union lfs_dinode *dip) \
{ \
if (fs->lfs_is64) { \
return dip->u_64.di_##field; \
} else { \
return dip->u_32.di_##field; \
} \
} \
static __unused inline void \
lfs_dino_set##field(STRUCT_LFS *fs, union lfs_dinode *dip, type val) \
{ \
if (fs->lfs_is64) { \
type *p = &dip->u_64.di_##field; \
(void)p; \
dip->u_64.di_##field = val; \
} else { \
type32 *p = &dip->u_32.di_##field; \
(void)p; \
dip->u_32.di_##field = val; \
} \
} \
LFS_DEF_DINO_ACCESSOR(uint16_t, uint16_t, mode);
LFS_DEF_DINO_ACCESSOR(int16_t, int16_t, nlink);
LFS_DEF_DINO_ACCESSOR(uint64_t, uint32_t, inumber);
LFS_DEF_DINO_ACCESSOR(uint64_t, uint64_t, size);
LFS_DEF_DINO_ACCESSOR(int64_t, int32_t, atime);
LFS_DEF_DINO_ACCESSOR(int32_t, int32_t, atimensec);
LFS_DEF_DINO_ACCESSOR(int64_t, int32_t, mtime);
LFS_DEF_DINO_ACCESSOR(int32_t, int32_t, mtimensec);
LFS_DEF_DINO_ACCESSOR(int64_t, int32_t, ctime);
LFS_DEF_DINO_ACCESSOR(int32_t, int32_t, ctimensec);
LFS_DEF_DINO_ACCESSOR(uint32_t, uint32_t, flags);
LFS_DEF_DINO_ACCESSOR(uint64_t, uint32_t, blocks);
LFS_DEF_DINO_ACCESSOR(int32_t, int32_t, gen);
LFS_DEF_DINO_ACCESSOR(uint32_t, uint32_t, uid);
LFS_DEF_DINO_ACCESSOR(uint32_t, uint32_t, gid);
static __unused inline daddr_t
lfs_dino_getdb(STRUCT_LFS *fs, union lfs_dinode *dip, unsigned ix)
{
KASSERT(ix < ULFS_NDADDR);
if (fs->lfs_is64) {
return dip->u_64.di_db[ix];
} else {
return dip->u_32.di_db[ix];
}
}
static __unused inline daddr_t
lfs_dino_getib(STRUCT_LFS *fs, union lfs_dinode *dip, unsigned ix)
{
KASSERT(ix < ULFS_NIADDR);
if (fs->lfs_is64) {
return dip->u_64.di_ib[ix];
} else {
return dip->u_32.di_ib[ix];
}
}
static __unused inline void
lfs_dino_setdb(STRUCT_LFS *fs, union lfs_dinode *dip, unsigned ix, daddr_t val)
{
KASSERT(ix < ULFS_NDADDR);
if (fs->lfs_is64) {
dip->u_64.di_db[ix] = val;
} else {
dip->u_32.di_db[ix] = val;
}
}
static __unused inline void
lfs_dino_setib(STRUCT_LFS *fs, union lfs_dinode *dip, unsigned ix, daddr_t val)
{
KASSERT(ix < ULFS_NIADDR);
if (fs->lfs_is64) {
dip->u_64.di_ib[ix] = val;
} else {
dip->u_32.di_ib[ix] = val;
}
}
/*
* "struct buf" associated definitions
*/
@ -895,9 +987,9 @@ lfs_btofsb(STRUCT_LFS *fs, uint64_t b)
#define lfs_blknum(fs, fsb) /* calculates rounddown(fsb, fs->lfs_frag) */ \
((fsb) &~ ((fs)->lfs_frag - 1))
#define lfs_dblksize(fs, dp, lbn) \
(((lbn) >= ULFS_NDADDR || (dp)->di_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
(((lbn) >= ULFS_NDADDR || lfs_dino_getsize(fs, dp) >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
? lfs_sb_getbsize(fs) \
: (lfs_fragroundup(fs, lfs_blkoff(fs, (dp)->di_size))))
: (lfs_fragroundup(fs, lfs_blkoff(fs, lfs_dino_getsize(fs, dp)))))
#define lfs_segsize(fs) (lfs_sb_getversion(fs) == 1 ? \
lfs_lblktosize((fs), lfs_sb_getssize(fs)) : \

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_alloc.c,v 1.126 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: lfs_alloc.c,v 1.127 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.126 2015/08/12 18:25:52 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.127 2015/08/12 18:28:01 dholland Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -531,17 +531,17 @@ lfs_vfree(struct vnode *vp, ino_t ino, int mode)
if (old_iaddr != LFS_UNUSED_DADDR) {
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, old_iaddr), bp);
#ifdef DIAGNOSTIC
if (sup->su_nbytes < sizeof (struct ulfs1_dinode)) {
if (sup->su_nbytes < DINOSIZE(fs)) {
printf("lfs_vfree: negative byte count"
" (segment %" PRIu32 " short by %d)\n",
lfs_dtosn(fs, old_iaddr),
(int)sizeof (struct ulfs1_dinode) -
(int)DINOSIZE(fs) -
sup->su_nbytes);
panic("lfs_vfree: negative byte count");
sup->su_nbytes = sizeof (struct ulfs1_dinode);
sup->su_nbytes = DINOSIZE(fs);
}
#endif
sup->su_nbytes -= sizeof (struct ulfs1_dinode);
sup->su_nbytes -= DINOSIZE(fs);
LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, old_iaddr), bp); /* Ifile */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_bio.c,v 1.133 2015/08/02 18:08:13 dholland Exp $ */
/* $NetBSD: lfs_bio.c,v 1.134 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.133 2015/08/02 18:08:13 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.134 2015/08/12 18:28:01 dholland Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -601,7 +601,7 @@ lfs_flush(struct lfs *fs, int flags, int only_onefs)
}
#define INOCOUNT(fs) howmany(lfs_sb_getuinodes(fs), LFS_INOPB(fs))
#define INOBYTES(fs) (lfs_sb_getuinodes(fs) * sizeof (struct ulfs1_dinode))
#define INOBYTES(fs) (lfs_sb_getuinodes(fs) * DINOSIZE(fs))
/*
* make sure that we don't have too many locked buffers.

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_debug.c,v 1.51 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_debug.c,v 1.52 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.51 2015/08/12 18:27:01 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.52 2015/08/12 18:28:01 dholland Exp $");
#ifdef DEBUG
@ -191,26 +191,26 @@ lfs_dump_super(struct lfs *lfsp)
}
void
lfs_dump_dinode(struct ulfs1_dinode *dip)
lfs_dump_dinode(struct lfs *fs, union lfs_dinode *dip)
{
int i;
printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n",
"mode ", dip->di_mode,
"nlink ", dip->di_nlink,
"uid ", dip->di_uid,
"gid ", dip->di_gid,
"size ", (long long)dip->di_size,
"blocks ", dip->di_blocks);
printf("inum %d\n", dip->di_inumber);
printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%ju\t%s%ju\n",
"mode ", lfs_dino_getmode(fs, dip),
"nlink ", lfs_dino_getnlink(fs, dip),
"uid ", lfs_dino_getuid(fs, dip),
"gid ", lfs_dino_getgid(fs, dip),
"size ", (uintmax_t)lfs_dino_getsize(fs, dip),
"blocks ", (uintmax_t)lfs_dino_getblocks(fs, dip));
printf("inum %ju\n", (uintmax_t)lfs_dino_getinumber(fs, dip));
printf("Direct Addresses\n");
for (i = 0; i < ULFS_NDADDR; i++) {
printf("\t%x", dip->di_db[i]);
printf("\t%jx", (intmax_t)lfs_dino_getdb(fs, dip, i));
if ((i % 6) == 5)
printf("\n");
}
for (i = 0; i < ULFS_NIADDR; i++)
printf("\t%x", dip->di_ib[i]);
printf("\t%jx", (intmax_t)lfs_dino_getib(fs, dip, i));
printf("\n");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_extern.h,v 1.109 2015/08/12 18:23:47 dholland Exp $ */
/* $NetBSD: lfs_extern.h,v 1.110 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -85,18 +85,21 @@ MALLOC_DECLARE(M_SEGMENT);
#define LFS_IGNORE_LAZY_SYNC 9
#define LFS_MAXID 10
/* not ours */
struct fid;
struct mount;
struct nameidata;
struct proc;
struct statvfs;
struct timeval;
struct inode;
struct uio;
struct mbuf;
struct ulfs1_dinode;
struct buf;
struct vnode;
/* ours */
struct inode;
union lfs_dinode;
struct dlfs;
struct lfs;
struct segment;
@ -152,7 +155,7 @@ int lfs_reserve(struct lfs *, struct vnode *, struct vnode *, int);
int lfs_bwrite_log(struct buf *, const char *, int);
void lfs_dumplog(void);
void lfs_dump_super(struct lfs *);
void lfs_dump_dinode(struct ulfs1_dinode *);
void lfs_dump_dinode(struct lfs *, union lfs_dinode *);
void lfs_check_bpp(struct lfs *, struct segment *, char *, int);
void lfs_check_segsum(struct lfs *, struct segment *, char *, int);
void lfs_debug_log(int, const char *, ...);
@ -162,7 +165,7 @@ void lfs_debug_log(int, const char *, ...);
int lfs_update(struct vnode *, const struct timespec *, const struct timespec *,
int);
int lfs_truncate(struct vnode *, off_t, int, kauth_cred_t);
struct ulfs1_dinode *lfs_ifind(struct lfs *, ino_t, struct buf *);
union lfs_dinode *lfs_ifind(struct lfs *, ino_t, struct buf *);
void lfs_finalize_ino_seguse(struct lfs *, struct inode *);
void lfs_finalize_fs_seguse(struct lfs *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_inode.c,v 1.143 2015/08/02 20:23:21 dholland Exp $ */
/* $NetBSD: lfs_inode.c,v 1.144 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.143 2015/08/02 20:23:21 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.144 2015/08/12 18:28:01 dholland Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -97,11 +97,12 @@ static int lfs_blkfree (struct lfs *, struct inode *, daddr_t, size_t, long *, s
static int lfs_vtruncbuf(struct vnode *, daddr_t, bool, int);
/* Search a block for a specific dinode. */
struct ulfs1_dinode *
union lfs_dinode *
lfs_ifind(struct lfs *fs, ino_t ino, struct buf *bp)
{
struct ulfs1_dinode *dip = (struct ulfs1_dinode *)bp->b_data;
struct ulfs1_dinode *ldip, *fin;
char *base = bp->b_data;
union lfs_dinode *ldip;
unsigned num, i;
ASSERT_NO_SEGLOCK(fs);
/*
@ -109,12 +110,14 @@ lfs_ifind(struct lfs *fs, ino_t ino, struct buf *bp)
* inode will supercede earlier ones. Though it is unlikely, it is
* possible that the same inode will appear in the same inode block.
*/
fin = dip + LFS_INOPB(fs);
for (ldip = fin - 1; ldip >= dip; --ldip)
if (ldip->di_inumber == ino)
num = LFS_INOPB(fs);
for (i = num; i-- > 0; ) {
ldip = (union lfs_dinode *)(base + i * DINOSIZE(fs));
if (lfs_dino_getinumber(fs, ldip) == ino)
return (ldip);
}
printf("searched %d entries\n", (int)(fin - dip));
printf("searched %u entries\n", num);
printf("offset is 0x%jx (seg %d)\n", (uintmax_t)lfs_sb_getoffset(fs),
lfs_dtosn(fs, lfs_sb_getoffset(fs)));
printf("block is 0x%jx (seg %d)\n",

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_inode.h,v 1.8 2015/08/02 18:12:41 dholland Exp $ */
/* $NetBSD: lfs_inode.h,v 1.9 2015/08/12 18:28:01 dholland Exp $ */
/* from NetBSD: ulfs_inode.h,v 1.5 2013/06/06 00:51:50 dholland Exp */
/* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */
@ -153,8 +153,8 @@ struct inode {
* The on-disk dinode itself.
*/
union {
struct ulfs1_dinode *ffs1_din; /* 128 bytes of the on-disk dinode. */
struct ulfs2_dinode *ffs2_din;
struct lfs32_dinode *ffs1_din; /* 128 bytes of the on-disk dinode. */
struct lfs64_dinode *ffs2_din;
} i_din;
};
@ -175,6 +175,7 @@ struct inode {
#define i_ffs1_rdev i_din.ffs1_din->di_rdev
#define i_ffs1_size i_din.ffs1_din->di_size
#define i_ffs1_uid i_din.ffs1_din->di_uid
#define i_ffs1_modrev i_din.ffs1_din->di_modrev
#define i_ffs2_atime i_din.ffs2_din->di_atime
#define i_ffs2_atimensec i_din.ffs2_din->di_atimensec
@ -199,6 +200,8 @@ struct inode {
#define i_ffs2_kernflags i_din.ffs2_din->di_kernflags
#define i_ffs2_extsize i_din.ffs2_din->di_extsize
#define i_ffs2_extb i_din.ffs2_din->di_extb
#define i_ffs2_inumber i_din.ffs2_din->di_inumber
#define i_ffs2_modrev i_din.ffs2_din->di_modrev
/* These flags are kept in i_flag. */
#define IN_ACCESS 0x0001 /* Access time update request. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_rfw.c,v 1.28 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_rfw.c,v 1.29 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.28 2015/08/12 18:27:01 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.29 2015/08/12 18:28:01 dholland Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -256,12 +256,13 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
{
struct vnode *devvp, *vp;
struct inode *ip;
struct ulfs1_dinode *dip;
union lfs_dinode *dip;
struct buf *dbp, *ibp;
int error;
daddr_t daddr;
IFILE *ifp;
SEGUSE *sup;
unsigned i, num;
devvp = VTOI(fs->lfs_ivnode)->i_devvp;
@ -275,10 +276,12 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
DLOG((DLOG_RF, "update_inoblk: bread returned %d\n", error));
return error;
}
dip = ((struct ulfs1_dinode *)(dbp->b_data)) + LFS_INOPB(fs);
while (--dip >= (struct ulfs1_dinode *)dbp->b_data) {
if (dip->di_inumber > LFS_IFILE_INUM) {
error = lfs_rf_valloc(fs, dip->di_inumber, dip->di_gen,
num = LFS_INOPB(fs);
for (i = num; i-- > 0; ) {
dip = (union lfs_dinode *)((char *)dbp->b_data + i * DINOSIZE(fs));
if (lfs_dino_getinumber(fs, dip) > LFS_IFILE_INUM) {
error = lfs_rf_valloc(fs, lfs_dino_getinumber(fs, dip),
lfs_dino_getgen(fs, dip),
l, &vp);
if (error) {
DLOG((DLOG_RF, "update_inoblk: lfs_rf_valloc"
@ -286,21 +289,42 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
continue;
}
ip = VTOI(vp);
if (dip->di_size != ip->i_size)
lfs_truncate(vp, dip->di_size, 0, NOCRED);
if (lfs_dino_getsize(fs, dip) != ip->i_size)
lfs_truncate(vp, lfs_dino_getsize(fs, dip), 0,
NOCRED);
/* Get mode, link count, size, and times */
memcpy(ip->i_din.ffs1_din, dip,
offsetof(struct ulfs1_dinode, di_db[0]));
/* XXX: ugly, simplify */
if (fs->lfs_is64) {
/*
* XXX what about di_extb?
*/
memcpy(ip->i_din.ffs2_din, dip,
offsetof(struct lfs64_dinode, di_db[0]));
/* Then the rest, except di_blocks */
ip->i_ffs2_modrev = dip->u_64.di_modrev;
ip->i_ffs2_inumber = dip->u_64.di_inumber;
memset(ip->i_din.ffs2_din->di_spare, 0,
sizeof(ip->i_din.ffs2_din->di_spare));
} else {
memcpy(ip->i_din.ffs1_din, dip,
offsetof(struct lfs32_dinode, di_db[0]));
/* Then the rest, except di_blocks */
ip->i_ffs1_flags = dip->u_32.di_flags;
ip->i_ffs1_gen = dip->u_32.di_gen;
ip->i_ffs1_uid = dip->u_32.di_uid;
ip->i_ffs1_gid = dip->u_32.di_gid;
ip->i_ffs1_modrev = dip->u_32.di_modrev;
}
/* Then the rest, except di_blocks */
ip->i_flags = ip->i_ffs1_flags = dip->di_flags;
ip->i_gen = ip->i_ffs1_gen = dip->di_gen;
ip->i_uid = ip->i_ffs1_uid = dip->di_uid;
ip->i_gid = ip->i_ffs1_gid = dip->di_gid;
ip->i_flags = lfs_dino_getflags(fs, dip);
ip->i_gen = lfs_dino_getgen(fs, dip);
ip->i_uid = lfs_dino_getuid(fs, dip);
ip->i_gid = lfs_dino_getgid(fs, dip);
ip->i_mode = ip->i_ffs1_mode;
ip->i_nlink = ip->i_ffs1_nlink;
ip->i_size = ip->i_ffs1_size;
ip->i_mode = lfs_dino_getmode(fs, dip);
ip->i_nlink = lfs_dino_getnlink(fs, dip);
ip->i_size = lfs_dino_getsize(fs, dip);
LFS_SET_UINO(ip, IN_CHANGE | IN_UPDATE);
@ -310,7 +334,7 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
vput(vp);
/* Record change in location */
LFS_IENTRY(ifp, fs, dip->di_inumber, ibp);
LFS_IENTRY(ifp, fs, lfs_dino_getinumber(fs, dip), ibp);
daddr = lfs_if_getdaddr(fs, ifp);
lfs_if_setdaddr(fs, ifp, LFS_DBTOFSB(fs, dbp->b_blkno));
error = LFS_BWRITE_LOG(ibp); /* Ifile */
@ -319,14 +343,14 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
if (daddr > 0) {
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr),
ibp);
sup->su_nbytes -= sizeof (struct ulfs1_dinode);
sup->su_nbytes -= DINOSIZE(fs);
LFS_WRITESEGENTRY(sup, fs,
lfs_dtosn(fs, daddr),
ibp);
}
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, LFS_DBTOFSB(fs, dbp->b_blkno)),
ibp);
sup->su_nbytes += sizeof (struct ulfs1_dinode);
sup->su_nbytes += DINOSIZE(fs);
LFS_WRITESEGENTRY(sup, fs,
lfs_dtosn(fs, LFS_DBTOFSB(fs, dbp->b_blkno)),
ibp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_segment.c,v 1.255 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_segment.c,v 1.256 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.255 2015/08/12 18:27:01 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.256 2015/08/12 18:28:01 dholland Exp $");
#define _VFS_VNODE_PRIVATE /* XXX: check for VI_MARKER, this has to go */
@ -1011,27 +1011,25 @@ lfs_update_iaddr(struct lfs *fs, struct segment *sp, struct inode *ip, daddr_t n
#endif
LFS_SEGENTRY(sup, fs, oldsn, bp);
#ifdef DIAGNOSTIC
if (sup->su_nbytes +
sizeof (struct ulfs1_dinode) * ndupino
< sizeof (struct ulfs1_dinode)) {
if (sup->su_nbytes + DINOSIZE(fs) * ndupino < DINOSIZE(fs)) {
printf("lfs_writeinode: negative bytes "
"(segment %" PRIu32 " short by %d, "
"oldsn=%" PRIu32 ", cursn=%" PRIu32
", daddr=%" PRId64 ", su_nbytes=%u, "
"ndupino=%d)\n",
lfs_dtosn(fs, daddr),
(int)sizeof (struct ulfs1_dinode) *
(int)DINOSIZE(fs) *
(1 - sp->ndupino) - sup->su_nbytes,
oldsn, sp->seg_number, daddr,
(unsigned int)sup->su_nbytes,
sp->ndupino);
panic("lfs_writeinode: negative bytes");
sup->su_nbytes = sizeof (struct ulfs1_dinode);
sup->su_nbytes = DINOSIZE(fs);
}
#endif
DLOG((DLOG_SU, "seg %d -= %d for ino %d inode\n",
lfs_dtosn(fs, daddr), sizeof (struct ulfs1_dinode), ino));
sup->su_nbytes -= sizeof (struct ulfs1_dinode);
lfs_dtosn(fs, daddr), DINOSIZE(fs), ino));
sup->su_nbytes -= DINOSIZE(fs);
redo_ifile |=
(ino == LFS_IFILE_INUM && !(bp->b_flags & B_GATHERED));
if (redo_ifile) {
@ -1051,10 +1049,9 @@ int
lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
{
struct buf *bp;
struct ulfs1_dinode *cdp;
union lfs_dinode *cdp;
struct vnode *vp = ITOV(ip);
daddr_t daddr;
int32_t *daddrp; /* XXX ondisk32 */
int i, ndx;
int redo_ifile = 0;
int gotblk = 0;
@ -1100,7 +1097,7 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
break;
if (sp->idp) {
sp->idp->di_inumber = 0;
lfs_dino_setinumber(fs, sp->idp, 0);
sp->idp = NULL;
}
++count;
@ -1126,9 +1123,13 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
gotblk++;
/* Zero out inode numbers */
for (i = 0; i < LFS_INOPB(fs); ++i)
((struct ulfs1_dinode *)sp->ibp->b_data)[i].di_inumber =
0;
for (i = 0; i < LFS_INOPB(fs); ++i) {
union lfs_dinode *tmpdi;
tmpdi = (union lfs_dinode *)((char *)sp->ibp->b_data +
DINOSIZE(fs) * i);
lfs_dino_setinumber(fs, tmpdi, 0);
}
++sp->start_bpp;
lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
@ -1162,14 +1163,22 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
* already been gathered.
*/
if (ip->i_number == LFS_IFILE_INUM && sp->idp) {
*(sp->idp) = *ip->i_din.ffs1_din;
if (fs->lfs_is64) {
sp->idp->u_64 = *ip->i_din.ffs2_din;
} else {
sp->idp->u_32 = *ip->i_din.ffs1_din;
}
ip->i_lfs_osize = ip->i_size;
return 0;
}
bp = sp->ibp;
cdp = ((struct ulfs1_dinode *)bp->b_data) + (sp->ninodes % LFS_INOPB(fs));
*cdp = *ip->i_din.ffs1_din;
cdp = (union lfs_dinode *)((char *)bp->b_data + DINOSIZE(fs) * (sp->ninodes % LFS_INOPB(fs)));
if (fs->lfs_is64) {
cdp->u_64 = *ip->i_din.ffs2_din;
} else {
cdp->u_32 = *ip->i_din.ffs1_din;
}
/*
* This inode is on its way to disk; clear its VU_DIROP status when
@ -1192,12 +1201,12 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
*/
if (sp->seg_flags & SEGM_CLEAN) {
if (vp->v_uflag & VU_DIROP) {
cdp->di_nlink = ip->i_lfs_odnlink;
lfs_dino_setnlink(fs, cdp, ip->i_lfs_odnlink);
/* if (vp->v_type == VDIR) */
cdp->di_size = ip->i_lfs_osize;
lfs_dino_setsize(fs, cdp, ip->i_lfs_osize);
}
} else {
ip->i_lfs_odnlink = cdp->di_nlink;
ip->i_lfs_odnlink = lfs_dino_getnlink(fs, cdp);
ip->i_lfs_osize = ip->i_size;
}
@ -1222,19 +1231,24 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
if (((ip->i_ffs1_mode & LFS_IFMT) == LFS_IFREG ||
(ip->i_ffs1_mode & LFS_IFMT) == LFS_IFDIR) &&
ip->i_size > ((ip->i_lfs_hiblk + 1) << lfs_sb_getbshift(fs))) {
cdp->di_size = (ip->i_lfs_hiblk + 1) << lfs_sb_getbshift(fs);
lfs_dino_setsize(fs, cdp, (ip->i_lfs_hiblk + 1) << lfs_sb_getbshift(fs));
DLOG((DLOG_SEG, "lfs_writeinode: ino %d size %" PRId64 " -> %"
PRId64 "\n", (int)ip->i_number, ip->i_size, cdp->di_size));
PRId64 "\n", (int)ip->i_number, ip->i_size, lfs_dino_getsize(fs, cdp)));
}
if (ip->i_lfs_effnblks != ip->i_ffs1_blocks) {
DLOG((DLOG_SEG, "lfs_writeinode: cleansing ino %d eff %jd != nblk %d)"
" at %jx\n", ip->i_number, (intmax_t)ip->i_lfs_effnblks,
ip->i_ffs1_blocks, (uintmax_t)lfs_sb_getoffset(fs)));
for (daddrp = cdp->di_db; daddrp < cdp->di_ib + ULFS_NIADDR;
daddrp++) {
if (*daddrp == UNWRITTEN) {
for (i=0; i<ULFS_NDADDR; i++) {
if (lfs_dino_getdb(fs, cdp, i) == UNWRITTEN) {
DLOG((DLOG_SEG, "lfs_writeinode: wiping UNWRITTEN\n"));
*daddrp = 0;
lfs_dino_setdb(fs, cdp, i, 0);
}
}
for (i=0; i<ULFS_NIADDR; i++) {
if (lfs_dino_getib(fs, cdp, i) == UNWRITTEN) {
DLOG((DLOG_SEG, "lfs_writeinode: wiping UNWRITTEN\n"));
lfs_dino_setib(fs, cdp, i, 0);
}
}
}
@ -1244,17 +1258,17 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
* Check dinode held blocks against dinode size.
* This should be identical to the check in lfs_vget().
*/
for (i = (cdp->di_size + lfs_sb_getbsize(fs) - 1) >> lfs_sb_getbshift(fs);
for (i = (lfs_dino_getsize(fs, cdp) + lfs_sb_getbsize(fs) - 1) >> lfs_sb_getbshift(fs);
i < ULFS_NDADDR; i++) {
KASSERT(i >= 0);
if ((cdp->di_mode & LFS_IFMT) == LFS_IFLNK)
if ((lfs_dino_getmode(fs, cdp) & LFS_IFMT) == LFS_IFLNK)
continue;
if (((cdp->di_mode & LFS_IFMT) == LFS_IFBLK ||
(cdp->di_mode & LFS_IFMT) == LFS_IFCHR) && i == 0)
if (((lfs_dino_getmode(fs, cdp) & LFS_IFMT) == LFS_IFBLK ||
(lfs_dino_getmode(fs, cdp) & LFS_IFMT) == LFS_IFCHR) && i == 0)
continue;
if (cdp->di_db[i] != 0) {
if (lfs_dino_getdb(fs, cdp, i) != 0) {
# ifdef DEBUG
lfs_dump_dinode(cdp);
lfs_dump_dinode(fs, cdp);
# endif
panic("writing inconsistent inode");
}
@ -1278,8 +1292,7 @@ lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
if (ip->i_number == LFS_IFILE_INUM) {
/* We know sp->idp == NULL */
sp->idp = ((struct ulfs1_dinode *)bp->b_data) +
(sp->ninodes % LFS_INOPB(fs));
sp->idp = DINO_IN_BLOCK(fs, bp, sp->ninodes % LFS_INOPB(fs));
/* Not dirty any more */
mutex_enter(&lfs_lock);
@ -1567,21 +1580,19 @@ lfs_update_single(struct lfs *fs, struct segment *sp,
osize = lfs_sb_getbsize(fs);
LFS_SEGENTRY(sup, fs, oldsn, bp);
#ifdef DIAGNOSTIC
if (sup->su_nbytes + sizeof (struct ulfs1_dinode) * ndupino
< osize) {
if (sup->su_nbytes + DINOSIZE(fs) * ndupino < osize) {
printf("lfs_updatemeta: negative bytes "
"(segment %" PRIu32 " short by %" PRId64
")\n", lfs_dtosn(fs, daddr),
(int64_t)osize -
(sizeof (struct ulfs1_dinode) * ndupino +
sup->su_nbytes));
(DINOSIZE(fs) * ndupino + sup->su_nbytes));
printf("lfs_updatemeta: ino %llu, lbn %" PRId64
", addr = 0x%" PRIx64 "\n",
(unsigned long long)ip->i_number, lbn, daddr);
printf("lfs_updatemeta: ndupino=%d\n", ndupino);
panic("lfs_updatemeta: negative bytes");
sup->su_nbytes = osize -
sizeof (struct ulfs1_dinode) * ndupino;
DINOSIZE(fs) * ndupino;
}
#endif
DLOG((DLOG_SU, "seg %" PRIu32 " -= %d for ino %d lbn %" PRId64
@ -1616,7 +1627,8 @@ lfs_updatemeta(struct segment *sp)
struct lfs *fs;
struct vnode *vp;
daddr_t lbn;
int i, nblocks, nblocks_orig, num;
int i, nblocks, num;
int __diagused nblocks_orig;
int bb;
int bytesleft, size;
unsigned lastlength;
@ -2112,9 +2124,9 @@ lfs_writeseg(struct lfs *fs, struct segment *sp)
ninos = (lfs_ss_getninos(fs, ssp) + LFS_INOPB(fs) - 1) / LFS_INOPB(fs);
DLOG((DLOG_SU, "seg %d += %d for %d inodes\n",
sp->seg_number,
lfs_ss_getninos(fs, ssp) * sizeof (struct ulfs1_dinode),
lfs_ss_getninos(fs, ssp) * DINOSIZE(fs),
lfs_ss_getninos(fs, ssp)));
sup->su_nbytes += lfs_ss_getninos(fs, ssp) * sizeof (struct ulfs1_dinode);
sup->su_nbytes += lfs_ss_getninos(fs, ssp) * DINOSIZE(fs);
/* sup->su_nbytes += lfs_sb_getsumsize(fs); */
if (lfs_sb_getversion(fs) == 1)
sup->su_olastmod = time_second;

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_syscalls.c,v 1.168 2015/08/12 18:25:52 dholland Exp $ */
/* $NetBSD: lfs_syscalls.c,v 1.169 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.168 2015/08/12 18:25:52 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.169 2015/08/12 18:28:01 dholland Exp $");
#ifndef LFS
# define LFS /* for prototypes in syscallargs.h */
@ -447,7 +447,7 @@ lfs_markv(struct lwp *l, fsid_t *fsidp, BLOCK_INFO *blkiov,
/*
* XXX should account indirect blocks and ifile pages as well
*/
if (nblkwritten + lfs_lblkno(fs, ninowritten * sizeof (struct ulfs1_dinode))
if (nblkwritten + lfs_lblkno(fs, ninowritten * DINOSIZE(fs))
> LFS_MARKV_MAX_BLOCKS) {
DLOG((DLOG_CLEAN, "lfs_markv: writing %d blks %d inos\n",
nblkwritten, ninowritten));

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vfsops.c,v 1.339 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: lfs_vfsops.c,v 1.340 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.339 2015/08/12 18:27:01 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.340 2015/08/12 18:28:01 dholland Exp $");
#if defined(_KERNEL_OPT)
#include "opt_lfs.h"
@ -538,10 +538,14 @@ void
lfs_init(void)
{
/*
* XXX: should we use separate pools for 32-bit and 64-bit
* dinodes?
*/
malloc_type_attach(M_SEGMENT);
pool_init(&lfs_inode_pool, sizeof(struct inode), 0, 0, 0,
"lfsinopl", &pool_allocator_nointr, IPL_NONE);
pool_init(&lfs_dinode_pool, sizeof(struct ulfs1_dinode), 0, 0, 0,
pool_init(&lfs_dinode_pool, sizeof(union lfs_dinode), 0, 0, 0,
"lfsdinopl", &pool_allocator_nointr, IPL_NONE);
pool_init(&lfs_inoext_pool, sizeof(struct lfs_inode_ext), 8, 0, 0,
"lfsinoextpl", &pool_allocator_nointr, IPL_NONE);
@ -1471,8 +1475,9 @@ lfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
static void
lfs_init_vnode(struct ulfsmount *ump, ino_t ino, struct vnode *vp)
{
struct lfs *fs = ump->um_lfs;
struct inode *ip;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
ASSERT_NO_SEGLOCK(ump->um_lfs);
@ -1483,11 +1488,17 @@ lfs_init_vnode(struct ulfsmount *ump, ino_t ino, struct vnode *vp)
memset(dp, 0, sizeof(*dp));
ip->inode_ext.lfs = pool_get(&lfs_inoext_pool, PR_WAITOK);
memset(ip->inode_ext.lfs, 0, sizeof(*ip->inode_ext.lfs));
ip->i_din.ffs1_din = dp;
// XXX this should go away
if (fs->lfs_is64) {
ip->i_din.ffs2_din = &dp->u_64;
} else {
ip->i_din.ffs1_din = &dp->u_32;
}
ip->i_ump = ump;
ip->i_vnode = vp;
ip->i_dev = ump->um_dev;
ip->i_number = dp->di_inumber = ino;
lfs_dino_setinumber(fs, dp, ino);
ip->i_number = ino;
ip->i_lfs = ump->um_lfs;
ip->i_lfs_effnblks = 0;
SPLAY_INIT(&ip->i_lfs_lbtree);
@ -1508,7 +1519,8 @@ lfs_deinit_vnode(struct ulfsmount *ump, struct vnode *vp)
struct inode *ip = VTOI(vp);
pool_put(&lfs_inoext_pool, ip->inode_ext.lfs);
pool_put(&lfs_dinode_pool, ip->i_din.ffs1_din);
// XXX bogus cast
pool_put(&lfs_dinode_pool, (union lfs_dinode *)ip->i_din.ffs1_din);
pool_put(&lfs_inode_pool, ip);
vp->v_data = NULL;
}
@ -1522,7 +1534,7 @@ lfs_loadvnode(struct mount *mp, struct vnode *vp,
const void *key, size_t key_len, const void **new_key)
{
struct lfs *fs;
struct ulfs1_dinode *dip;
union lfs_dinode *dip;
struct inode *ip;
struct buf *bp;
IFILE *ifp;
@ -1575,8 +1587,13 @@ lfs_loadvnode(struct mount *mp, struct vnode *vp,
if (curlwp == ump->um_cleaner_thread && ump->um_cleaner_hint != NULL &&
ump->um_cleaner_hint->bi_lbn == LFS_UNUSED_LBN) {
dip = ump->um_cleaner_hint->bi_bp;
error = copyin(dip, ip->i_din.ffs1_din,
sizeof(struct ulfs1_dinode));
if (fs->lfs_is64) {
error = copyin(dip, ip->i_din.ffs2_din,
sizeof(struct lfs64_dinode));
} else {
error = copyin(dip, ip->i_din.ffs1_din,
sizeof(struct lfs32_dinode));
}
if (error) {
lfs_deinit_vnode(ump, vp);
return error;
@ -1620,7 +1637,7 @@ again:
mutex_enter(&lfs_lock);
if (fs->lfs_seglock > 0) {
struct buf **bpp;
struct ulfs1_dinode *dp;
union lfs_dinode *dp;
int i;
for (bpp = fs->lfs_sp->bpp;
@ -1630,12 +1647,13 @@ again:
/* Inode block */
printf("%s: block 0x%" PRIx64 ": ",
__func__, (*bpp)->b_blkno);
dp = (struct ulfs1_dinode *)
(*bpp)->b_data;
for (i = 0; i < LFS_INOPB(fs); i++)
if (dp[i].di_inumber)
printf("%d ",
dp[i].di_inumber);
for (i = 0; i < LFS_INOPB(fs); i++) {
dp = DINO_IN_BLOCK(fs,
(*bpp)->b_data, i);
if (lfs_dino_getinumber(fs, dp))
printf("%ju ",
(uintmax_t)lfs_dino_getinumber(fs, dp));
}
printf("\n");
}
}
@ -1644,7 +1662,11 @@ again:
#endif /* DEBUG */
panic("lfs_loadvnode: dinode not found");
}
*ip->i_din.ffs1_din = *dip;
if (fs->lfs_is64) {
*ip->i_din.ffs2_din = dip->u_64;
} else {
*ip->i_din.ffs1_din = dip->u_32;
}
brelse(bp, 0);
out:
@ -2218,13 +2240,15 @@ lfs_vinit(struct mount *mp, struct vnode **vpp)
i == 0)
continue;
if (ip->i_ffs1_db[i] != 0) {
lfs_dump_dinode(ip->i_din.ffs1_din);
// XXX bogus cast
lfs_dump_dinode(fs, (union lfs_dinode *)ip->i_din.ffs1_din);
panic("inconsistent inode (direct)");
}
}
for ( ; i < ULFS_NDADDR + ULFS_NIADDR; i++) {
if (ip->i_ffs1_ib[i - ULFS_NDADDR] != 0) {
lfs_dump_dinode(ip->i_din.ffs1_din);
// XXX bogus cast
lfs_dump_dinode(fs, (union lfs_dinode *)ip->i_din.ffs1_din);
panic("inconsistent inode (indirect)");
}
}
@ -2237,7 +2261,8 @@ lfs_vinit(struct mount *mp, struct vnode **vpp)
#ifdef DIAGNOSTIC
if (vp->v_type == VNON) {
# ifdef DEBUG
lfs_dump_dinode(ip->i_din.ffs1_din);
// XXX bogus cast
lfs_dump_dinode(fs, (union lfs_dinode *)ip->i_din.ffs1_din);
# endif
panic("lfs_vinit: ino %llu is type VNON! (ifmt=%o)\n",
(unsigned long long)ip->i_number,

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vnops.c,v 1.285 2015/08/12 18:26:27 dholland Exp $ */
/* $NetBSD: lfs_vnops.c,v 1.286 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -125,7 +125,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.285 2015/08/12 18:26:27 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.286 2015/08/12 18:28:01 dholland Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -2102,10 +2102,14 @@ lfs_dump_vop(void *v)
int a_flags;
} */ *ap = v;
struct inode *ip = VTOI(ap->a_vp);
struct lfs *fs = ip->i_lfs;
#ifdef DDB
vfs_vnode_print(ap->a_vp, 0, printf);
#endif
lfs_dump_dinode(VTOI(ap->a_vp)->i_din.ffs1_din);
// XXX bogus cast
lfs_dump_dinode(fs, (union lfs_dinode *)ip->i_din.ffs1_din);
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ulfs_inode.h,v 1.14 2015/07/24 06:59:32 dholland Exp $ */
/* $NetBSD: ulfs_inode.h,v 1.15 2015/08/12 18:28:01 dholland Exp $ */
/* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */
/*
@ -76,7 +76,7 @@ void lfs_unset_dirop(struct lfs *, struct vnode *, const char *);
#define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE)
#define LFS_WAIT_BYTES LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE)
#define LFS_MAX_DIROP ((desiredvnodes >> 2) + (desiredvnodes >> 3))
#define SIZEOF_DIROP(fs) (2 * (lfs_sb_getbsize(fs) + LFS_DINODE1_SIZE))
#define SIZEOF_DIROP(fs) (2 * (lfs_sb_getbsize(fs) + DINOSIZE(fs)))
#define LFS_MAX_FSDIROP(fs) \
(lfs_sb_getnclean(fs) <= lfs_sb_getresvseg(fs) ? 0 : \
((lfs_sb_getnclean(fs) - lfs_sb_getresvseg(fs)) * lfs_sb_getssize(fs)) / \

View File

@ -1,4 +1,4 @@
/* $NetBSD: dumplfs.c,v 1.53 2015/08/12 18:27:01 dholland Exp $ */
/* $NetBSD: dumplfs.c,v 1.54 2015/08/12 18:28:01 dholland Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
#if 0
static char sccsid[] = "@(#)dumplfs.c 8.5 (Berkeley) 5/24/95";
#else
__RCSID("$NetBSD: dumplfs.c,v 1.53 2015/08/12 18:27:01 dholland Exp $");
__RCSID("$NetBSD: dumplfs.c,v 1.54 2015/08/12 18:28:01 dholland Exp $");
#endif
#endif /* not lint */
@ -64,7 +64,7 @@ __RCSID("$NetBSD: dumplfs.c,v 1.53 2015/08/12 18:27:01 dholland Exp $");
static void addseg(char *);
static void dump_cleaner_info(struct lfs *, void *);
static void dump_dinode(struct ulfs1_dinode *);
static void dump_dinode(struct lfs *, union lfs_dinode *);
static void dump_ifile(int, struct lfs *, int, int, daddr_t);
static int dump_ipage_ifile(struct lfs *, int, char *, int);
static int dump_ipage_segusage(struct lfs *, int, char *, int);
@ -275,9 +275,11 @@ static void
dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t addr)
{
char *ipage;
struct ulfs1_dinode *dip, *dpage;
char *dpage;
union lfs_dinode *dip = NULL;
/* XXX ondisk32 */
int32_t *addrp, *dindir, *iaddrp, *indir;
daddr_t pdb;
int block_limit, i, inum, j, nblocks, psize;
psize = lfs_sb_getbsize(lfsp);
@ -288,29 +290,31 @@ dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t
err(1, "malloc");
get(fd, fsbtobyte(lfsp, addr), dpage, psize);
for (dip = dpage + LFS_INOPB(lfsp) - 1; dip >= dpage; --dip)
if (dip->di_inumber == LFS_IFILE_INUM)
for (i = LFS_INOPB(lfsp); i-- > 0; ) {
dip = DINO_IN_BLOCK(lfsp, dpage, i);
if (lfs_dino_getinumber(lfsp, dip) == LFS_IFILE_INUM)
break;
}
if (dip < dpage) {
if (lfs_dino_getinumber(lfsp, dip) != LFS_IFILE_INUM) {
warnx("unable to locate ifile inode at disk address 0x%jx",
(uintmax_t)addr);
return;
}
(void)printf("\nIFILE inode\n");
dump_dinode(dip);
dump_dinode(lfsp, dip);
(void)printf("\nIFILE contents\n");
nblocks = dip->di_size >> lfs_sb_getbshift(lfsp);
nblocks = lfs_dino_getsize(lfsp, dip) >> lfs_sb_getbshift(lfsp);
block_limit = MIN(nblocks, ULFS_NDADDR);
/* Get the direct block */
if ((ipage = malloc(psize)) == NULL)
err(1, "malloc");
for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
i++, addrp++) {
get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
for (inum = 0, i = 0; i < block_limit; i++) {
pdb = lfs_dino_getdb(lfsp, dip, i);
get(fd, fsbtobyte(lfsp, pdb), ipage, psize);
if (i < lfs_sb_getcleansz(lfsp)) {
dump_cleaner_info(lfsp, ipage);
if (do_segentries)
@ -340,7 +344,7 @@ dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t
/* Dump out blocks off of single indirect block */
if (!(indir = malloc(psize)))
err(1, "malloc");
get(fd, fsbtobyte(lfsp, dip->di_ib[0]), indir, psize);
get(fd, fsbtobyte(lfsp, lfs_dino_getib(lfsp, dip, 0)), indir, psize);
block_limit = MIN(i + lfs_sb_getnindir(lfsp), nblocks);
for (addrp = indir; i < block_limit; i++, addrp++) {
if (*addrp == LFS_UNUSED_DADDR)
@ -373,7 +377,7 @@ dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t
/* Get the double indirect block */
if (!(dindir = malloc(psize)))
err(1, "malloc");
get(fd, fsbtobyte(lfsp, dip->di_ib[1]), dindir, psize);
get(fd, fsbtobyte(lfsp, lfs_dino_getib(lfsp, dip, 1)), dindir, psize);
for (iaddrp = dindir, j = 0; j < lfs_sb_getnindir(lfsp); j++, iaddrp++) {
if (*iaddrp == LFS_UNUSED_DADDR)
break;
@ -462,34 +466,35 @@ dump_ipage_segusage(struct lfs *lfsp, int i, char *pp, int tot)
}
static void
dump_dinode(struct ulfs1_dinode *dip)
dump_dinode(struct lfs *fs, union lfs_dinode *dip)
{
int i;
time_t at, mt, ct;
at = dip->di_atime;
mt = dip->di_mtime;
ct = dip->di_ctime;
at = lfs_dino_getatime(fs, dip);
mt = lfs_dino_getmtime(fs, dip);
ct = lfs_dino_getctime(fs, dip);
(void)printf(" %so%o\t%s%d\t%s%d\t%s%d\t%s%llu\n",
"mode ", dip->di_mode,
"nlink ", dip->di_nlink,
"uid ", dip->di_uid,
"gid ", dip->di_gid,
"size ", (long long)dip->di_size);
(void)printf(" %s%s %s%s %s%s",
"atime ", ctime(&at),
"mtime ", ctime(&mt),
"ctime ", ctime(&ct));
(void)printf(" inum %d\n", dip->di_inumber);
(void)printf(" %so%o\t%s%d\t%s%d\t%s%d\t%s%ju\n",
"mode ", lfs_dino_getmode(fs, dip),
"nlink ", lfs_dino_getnlink(fs, dip),
"uid ", lfs_dino_getuid(fs, dip),
"gid ", lfs_dino_getgid(fs, dip),
"size ", (uintmax_t)lfs_dino_getsize(fs, dip));
(void)printf(" %s%s", "atime ", ctime(&at));
(void)printf(" %s%s", "mtime ", ctime(&mt));
(void)printf(" %s%s", "ctime ", ctime(&ct));
(void)printf(" inum %ju\n",
(uintmax_t)lfs_dino_getinumber(fs, dip));
(void)printf(" Direct Addresses\n");
for (i = 0; i < ULFS_NDADDR; i++) {
(void)printf("\t0x%x", dip->di_db[i]);
(void)printf("\t0x%jx", (intmax_t)lfs_dino_getdb(fs, dip, i));
if ((i % 6) == 5)
(void)printf("\n");
}
(void)printf(" Indirect Addresses\n");
for (i = 0; i < ULFS_NIADDR; i++)
(void)printf("\t0x%x", dip->di_ib[i]);
(void)printf("\t0x%jx", (intmax_t)lfs_dino_getib(fs, dip, i));
(void)printf("\n");
}
@ -503,7 +508,8 @@ dump_sum(int fd, struct lfs *lfsp, SEGSUM *sp, int segnum, daddr_t addr)
int ck;
int numbytes, numblocks;
char *datap;
struct ulfs1_dinode *inop;
char *diblock;
union lfs_dinode *dip;
size_t el_size;
u_int32_t datasum;
u_int32_t ssflags;
@ -557,7 +563,7 @@ dump_sum(int fd, struct lfs *lfsp, SEGSUM *sp, int segnum, daddr_t addr)
/* XXX ondisk32 */
dp = (int32_t *)sp;
dp += lfs_sb_getsumsize(lfsp) / sizeof(int32_t);
inop = malloc(lfs_sb_getbsize(lfsp));
diblock = malloc(lfs_sb_getbsize(lfsp));
printf(" Inode addresses:");
numbytes = 0;
numblocks = 0;
@ -565,17 +571,19 @@ dump_sum(int fd, struct lfs *lfsp, SEGSUM *sp, int segnum, daddr_t addr)
++numblocks;
numbytes += lfs_sb_getibsize(lfsp); /* add bytes for inode block */
printf("\t0x%x {", *dp);
get(fd, fsbtobyte(lfsp, *dp), inop, lfs_sb_getibsize(lfsp));
get(fd, fsbtobyte(lfsp, *dp), diblock, lfs_sb_getibsize(lfsp));
for (j = 0; i < lfs_ss_getninos(lfsp, sp) && j < LFS_INOPB(lfsp); j++, i++) {
if (j > 0)
(void)printf(", ");
(void)printf("%dv%d", inop[j].di_inumber, inop[j].di_gen);
dip = DINO_IN_BLOCK(lfsp, diblock, j);
(void)printf("%juv%d", lfs_dino_getinumber(lfsp, dip),
lfs_dino_getgen(lfsp, dip));
}
(void)printf("}");
if (((i/LFS_INOPB(lfsp)) % 4) == 3)
(void)printf("\n");
}
free(inop);
free(diblock);
printf("\n");