Convert to NetBSD source code style

This commit is contained in:
perseant 2000-05-23 01:48:52 +00:00
parent 340761f659
commit 1d2596714b
15 changed files with 1611 additions and 1698 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.2 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: dir.c,v 1.3 2000/05/23 01:48:52 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -37,7 +37,7 @@
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <sys/mount.h> /* XXX */
#include <sys/mount.h> /* XXX */
#include <ufs/lfs/lfs.h>
#include <stdio.h>
@ -48,25 +48,25 @@
#include "fsutil.h"
#include "extern.h"
char *lfname = "lost+found";
int lfmode = 01700;
struct dirtemplate emptydir = { 0, DIRBLKSIZ };
struct dirtemplate dirhead = {
char *lfname = "lost+found";
int lfmode = 01700;
struct dirtemplate emptydir = {0, DIRBLKSIZ};
struct dirtemplate dirhead = {
0, 12, DT_DIR, 1, ".",
0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
};
struct odirtemplate odirhead = {
struct odirtemplate odirhead = {
0, 12, 1, ".",
0, DIRBLKSIZ - 12, 2, ".."
};
static int expanddir __P((struct dinode *, char *));
static void freedir __P((ino_t, ino_t));
static struct direct *fsck_readdir __P((struct inodesc *));
static struct bufarea *getdirblk __P((daddr_t, long));
static int lftempname __P((char *, ino_t));
static int mkentry __P((struct inodesc *));
static int chgino __P((struct inodesc *));
static int expanddir(struct dinode *, char *);
static void freedir(ino_t, ino_t);
static struct direct *fsck_readdir(struct inodesc *);
static struct bufarea *getdirblk(daddr_t, long);
static int lftempname(char *, ino_t);
static int mkentry(struct inodesc *);
static int chgino(struct inodesc *);
/*
* Propagate connected state through the tree.
@ -108,14 +108,13 @@ propagate()
* Scan each entry in a directory block.
*/
int
dirscan(idesc)
register struct inodesc *idesc;
dirscan(struct inodesc * idesc)
{
register struct direct *dp;
register struct bufarea *bp;
int dsize, n;
long blksiz;
char dbuf[DIRBLKSIZ];
int dsize, n;
long blksiz;
char dbuf[DIRBLKSIZ];
if (idesc->id_type != DATA)
errexit("wrong type to dirscan %d\n", idesc->id_type);
@ -133,8 +132,8 @@ dirscan(idesc)
memcpy(dbuf, dp, (size_t)dsize);
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (!newinofmt) {
struct direct *tdp = (struct direct *)dbuf;
u_char tmp;
struct direct *tdp = (struct direct *)dbuf;
u_char tmp;
tmp = tdp->d_namlen;
tdp->d_namlen = tdp->d_type;
@ -145,8 +144,8 @@ dirscan(idesc)
if ((n = (*idesc->id_func)(idesc)) & ALTERED) {
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (!newinofmt && !doinglevel2) {
struct direct *tdp;
u_char tmp;
struct direct *tdp;
u_char tmp;
tdp = (struct direct *)dbuf;
tmp = tdp->d_namlen;
@ -156,11 +155,11 @@ dirscan(idesc)
# endif
bp = getdirblk(idesc->id_blkno, blksiz);
memcpy(bp->b_un.b_buf + idesc->id_loc - dsize, dbuf,
(size_t)dsize);
(size_t)dsize);
dirty(bp);
sbdirty();
}
if (n & STOP)
if (n & STOP)
return (n);
}
return (idesc->id_filesize > 0 ? KEEPON : STOP);
@ -170,12 +169,11 @@ dirscan(idesc)
* get next entry in a directory.
*/
static struct direct *
fsck_readdir(idesc)
register struct inodesc *idesc;
fsck_readdir(struct inodesc * idesc)
{
register struct direct *dp, *ndp;
register struct bufarea *bp;
long size, blksiz, fix, dploc;
long size, blksiz, fix, dploc;
blksiz = idesc->id_numfrags * sblock.lfs_fsize;
bp = getdirblk(idesc->id_blkno, blksiz);
@ -232,27 +230,24 @@ dpok:
* This is a superset of the checks made in the kernel.
*/
int
dircheck(idesc, dp)
struct inodesc *idesc;
register struct direct *dp;
dircheck(struct inodesc * idesc, struct direct * dp)
{
register int size;
register char *cp;
u_char namlen, type;
int spaceleft;
register int size;
register char *cp;
u_char namlen, type;
int spaceleft;
spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
if (dp->d_ino >= maxino ||
dp->d_reclen == 0 ||
dp->d_reclen > spaceleft ||
(dp->d_reclen & 0x3) != 0)
{
pwarn("ino too large, reclen=0, reclen>space, or reclen&3!=0\n");
pwarn("dp->d_ino = 0x%x\tdp->d_reclen = 0x%x\n",
dp->d_ino, dp->d_reclen);
pwarn("maxino = 0x%x\tspaceleft = 0x%x\n", maxino, spaceleft);
return (0);
}
(dp->d_reclen & 0x3) != 0) {
pwarn("ino too large, reclen=0, reclen>space, or reclen&3!=0\n");
pwarn("dp->d_ino = 0x%x\tdp->d_reclen = 0x%x\n",
dp->d_ino, dp->d_reclen);
pwarn("maxino = 0x%x\tspaceleft = 0x%x\n", maxino, spaceleft);
return (0);
}
if (dp->d_ino == 0)
return (1);
size = DIRSIZ(!newinofmt, dp, 0);
@ -271,39 +266,34 @@ dircheck(idesc, dp)
if (dp->d_reclen < size ||
idesc->id_filesize < size ||
namlen > MAXNAMLEN ||
type > 15)
{
printf("reclen<size, filesize<size, namlen too large, or type>15\n");
type > 15) {
printf("reclen<size, filesize<size, namlen too large, or type>15\n");
return (0);
}
}
for (cp = dp->d_name, size = 0; size < namlen; size++)
if (*cp == '\0' || (*cp++ == '/')) {
printf("name contains NUL or /\n");
printf("name contains NUL or /\n");
return (0);
}
}
if (*cp != '\0') {
printf("name size misstated\n");
printf("name size misstated\n");
return (0);
}
}
return (1);
}
void
direrror(ino, errmesg)
ino_t ino;
char *errmesg;
direrror(ino_t ino, char *errmesg)
{
fileerror(ino, ino, errmesg);
}
void
fileerror(cwd, ino, errmesg)
ino_t cwd, ino;
char *errmesg;
fileerror(ino_t cwd, ino_t ino, char *errmesg)
{
register struct dinode *dp;
char pathbuf[MAXPATHLEN + 1];
char pathbuf[MAXPATHLEN + 1];
pwarn("%s ", errmesg);
pinode(ino);
@ -314,21 +304,19 @@ fileerror(cwd, ino, errmesg)
return;
}
dp = ginode(ino);
if(dp==NULL)
pfatal("INO is NULL\n");
else {
if (ftypeok(dp))
pfatal("%s=%s\n",
(dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
else
pfatal("NAME=%s\n", pathbuf);
}
if (dp == NULL)
pfatal("INO is NULL\n");
else {
if (ftypeok(dp))
pfatal("%s=%s\n",
(dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
else
pfatal("NAME=%s\n", pathbuf);
}
}
void
adjust(idesc, lcnt)
register struct inodesc *idesc;
short lcnt;
adjust(struct inodesc * idesc, short lcnt)
{
register struct dinode *dp;
@ -338,10 +326,10 @@ adjust(idesc, lcnt)
clri(idesc, "UNREF", 0);
} else {
pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname :
((dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE"));
((dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE"));
pinode(idesc->id_number);
printf(" COUNT %d SHOULD BE %d",
dp->di_nlink, dp->di_nlink - lcnt);
dp->di_nlink, dp->di_nlink - lcnt);
if (preen) {
if (lcnt < 0) {
printf("\n");
@ -357,12 +345,11 @@ adjust(idesc, lcnt)
}
static int
mkentry(idesc)
struct inodesc *idesc;
mkentry(struct inodesc * idesc)
{
register struct direct *dirp = idesc->id_dirp;
struct direct newent;
int newlen, oldlen;
struct direct newent;
int newlen, oldlen;
newent.d_namlen = strlen(idesc->id_name);
newlen = DIRSIZ(0, &newent, 0);
@ -385,25 +372,24 @@ mkentry(idesc)
memcpy(dirp->d_name, idesc->id_name, (size_t)dirp->d_namlen + 1);
# if (BYTE_ORDER == LITTLE_ENDIAN)
/*
* If the entry was split, dirscan() will only reverse the byte
* order of the original entry, and not the new one, before
* writing it back out. So, we reverse the byte order here if
* necessary.
*/
* If the entry was split, dirscan()will only reverse the byte
* order of the original entry, and not the new one, before
* writing it back out. So, we reverse the byte order here if
* necessary.
*/
if (oldlen != 0 && !newinofmt && !doinglevel2) {
u_char tmp;
u_char tmp;
tmp = dirp->d_namlen;
dirp->d_namlen = dirp->d_type;
dirp->d_type = tmp;
}
# endif
return (ALTERED|STOP);
return (ALTERED | STOP);
}
static int
chgino(idesc)
struct inodesc *idesc;
chgino(struct inodesc * idesc)
{
register struct direct *dirp = idesc->id_dirp;
@ -414,19 +400,17 @@ chgino(idesc)
dirp->d_type = typemap[idesc->id_parent];
else
dirp->d_type = 0;
return (ALTERED|STOP);
return (ALTERED | STOP);
}
int
linkup(orphan, parentdir)
ino_t orphan;
ino_t parentdir;
linkup(ino_t orphan, ino_t parentdir)
{
register struct dinode *dp;
int lostdir;
ino_t oldlfdir;
struct inodesc idesc;
char tempname[BUFSIZ];
int lostdir;
ino_t oldlfdir;
struct inodesc idesc;
char tempname[BUFSIZ];
memset(&idesc, 0, sizeof(struct inodesc));
dp = ginode(orphan);
@ -437,9 +421,8 @@ linkup(orphan, parentdir)
return (0);
if (preen)
printf(" (RECONNECTED)\n");
else
if (reply("RECONNECT") == 0)
return (0);
else if (reply("RECONNECT") == 0)
return (0);
if (lfdir == 0) {
dp = ginode(ROOTINO);
idesc.id_name = lfname;
@ -525,12 +508,9 @@ linkup(orphan, parentdir)
* fix an entry in a directory.
*/
int
changeino(dir, name, newnum)
ino_t dir;
char *name;
ino_t newnum;
changeino(ino_t dir, char *name, ino_t newnum)
{
struct inodesc idesc;
struct inodesc idesc;
memset(&idesc, 0, sizeof(struct inodesc));
idesc.id_type = DATA;
@ -546,14 +526,12 @@ changeino(dir, name, newnum)
* make an entry in a directory
*/
int
makeentry(parent, ino, name)
ino_t parent, ino;
char *name;
makeentry(ino_t parent, ino_t ino, char *name)
{
struct dinode *dp;
struct inodesc idesc;
char pathbuf[MAXPATHLEN + 1];
struct dinode *dp;
struct inodesc idesc;
char pathbuf[MAXPATHLEN + 1];
if (parent < ROOTINO || parent >= maxino ||
ino < ROOTINO || ino >= maxino)
return (0);
@ -582,13 +560,11 @@ makeentry(parent, ino, name)
* Attempt to expand the size of a directory
*/
static int
expanddir(dp, name)
register struct dinode *dp;
char *name;
expanddir(struct dinode * dp, char *name)
{
daddr_t lastbn, newblk;
daddr_t lastbn, newblk;
register struct bufarea *bp;
char *cp, firstblk[DIRBLKSIZ];
char *cp, firstblk[DIRBLKSIZ];
lastbn = lblkno(&sblock, dp->di_size);
if (lastbn >= NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0)
@ -600,7 +576,7 @@ expanddir(dp, name)
dp->di_size += sblock.lfs_bsize;
dp->di_blocks += btodb(sblock.lfs_bsize);
bp = getdirblk(dp->di_db[lastbn + 1],
(long)dblksize(&sblock, dp, lastbn + 1));
(long)dblksize(&sblock, dp, lastbn + 1));
if (bp->b_errs)
goto bad;
memcpy(firstblk, bp->b_un.b_buf, DIRBLKSIZ);
@ -614,7 +590,7 @@ expanddir(dp, name)
memcpy(cp, &emptydir, sizeof emptydir);
dirty(bp);
bp = getdirblk(dp->di_db[lastbn + 1],
(long)dblksize(&sblock, dp, lastbn + 1));
(long)dblksize(&sblock, dp, lastbn + 1));
if (bp->b_errs)
goto bad;
memcpy(bp->b_un.b_buf, &emptydir, sizeof emptydir);
@ -639,21 +615,19 @@ bad:
* allocate a new directory
*/
int
allocdir(parent, request, mode)
ino_t parent, request;
int mode;
allocdir(ino_t parent, ino_t request, int mode)
{
ino_t ino;
char *cp;
struct dinode *dp;
ino_t ino;
char *cp;
struct dinode *dp;
register struct bufarea *bp;
struct dirtemplate *dirp;
ino = allocino(request, IFDIR|mode);
ino = allocino(request, IFDIR | mode);
if (newinofmt)
dirp = &dirhead;
else
dirp = (struct dirtemplate *)&odirhead;
dirp = (struct dirtemplate *) & odirhead;
dirp->dot_ino = ino;
dirp->dotdot_ino = parent;
dp = ginode(ino);
@ -673,7 +647,7 @@ allocdir(parent, request, mode)
if (ino == ROOTINO) {
lncntp[ino] = dp->di_nlink;
cacheino(dp, ino);
return(ino);
return (ino);
}
if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) {
freeino(ino);
@ -695,10 +669,9 @@ allocdir(parent, request, mode)
* free a directory inode
*/
static void
freedir(ino, parent)
ino_t ino, parent;
freedir(ino_t ino, ino_t parent)
{
struct dinode *dp;
struct dinode *dp;
if (ino != parent) {
dp = ginode(parent);
@ -712,13 +685,11 @@ freedir(ino, parent)
* generate a temporary name for the lost+found directory.
*/
static int
lftempname(bufp, ino)
char *bufp;
ino_t ino;
lftempname(char *bufp, ino_t ino)
{
register ino_t in;
register char *cp;
int namlen;
register ino_t in;
register char *cp;
int namlen;
cp = bufp + 2;
for (in = maxino; in > 0; in /= 10)
@ -739,14 +710,12 @@ lftempname(bufp, ino)
* Ensure that it is held until another is requested.
*/
static struct bufarea *
getdirblk(blkno, size)
daddr_t blkno;
long size;
getdirblk(daddr_t blkno, long size)
{
if (pdirbp != 0)
pdirbp->b_flags &= ~B_INUSE;
/* pdirbp = getdatablk(blkno, size); */
pdirbp = getddblk(blkno,size);
pdirbp = getddblk(blkno, size);
return (pdirbp);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.2 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: extern.h,v 1.3 2000/05/23 01:48:52 perseant Exp $ */
/*
* Copyright (c) 1994 James A. Jegers
@ -24,52 +24,52 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
void adjust __P((struct inodesc *, short));
int allocblk __P((long));
int allocdir __P((ino_t, ino_t, int));
void blkerror __P((ino_t, char *, daddr_t));
int bread __P((int, char *, daddr_t, long));
void bufinit __P((void));
void bwrite __P((int, char *, daddr_t, long));
void cacheino __P((struct dinode *, ino_t));
int changeino __P((ino_t, char *, ino_t));
struct fstab;
int chkrange __P((daddr_t, int));
void ckfini __P((int));
int ckinode __P((struct dinode *, struct inodesc *));
void clri __P((struct inodesc *, char *, int));
int dircheck __P((struct inodesc *, struct direct *));
void direrror __P((ino_t, char *));
int dirscan __P((struct inodesc *));
int dofix __P((struct inodesc *, char *));
void fileerror __P((ino_t, ino_t, char *));
int findino __P((struct inodesc *));
int findname __P((struct inodesc *));
void flush __P((int, struct bufarea *));
void freeblk __P((daddr_t, long));
void freeino __P((ino_t));
void freeinodebuf __P((void));
int ftypeok __P((struct dinode *));
void getpathname __P((char *, ino_t, ino_t));
void inocleanup __P((void));
void inodirty __P((void));
int linkup __P((ino_t, ino_t));
int makeentry __P((ino_t, ino_t, char *));
void pass0 __P((void));
void pass1 __P((void));
void pass1b __P((void));
void pass2 __P((void));
void pass3 __P((void));
void pass4 __P((void));
int pass1check __P((struct inodesc *));
int pass4check __P((struct inodesc *));
void pass5 __P((void));
void pinode __P((ino_t));
void propagate __P((void));
int reply __P((char *));
void resetinodebuf __P((void));
int setup __P((const char *));
struct dinode * getnextinode __P((ino_t));
void catch __P((int));
void catchquit __P((int));
void voidquit __P((int));
void adjust(struct inodesc *, short);
int allocblk(long);
int allocdir(ino_t, ino_t, int);
void blkerror(ino_t, char *, daddr_t);
int bread(int, char *, daddr_t, long);
void bufinit(void);
void bwrite(int, char *, daddr_t, long);
void cacheino(struct dinode *, ino_t);
int changeino(ino_t, char *, ino_t);
struct fstab;
int chkrange(daddr_t, int);
void ckfini(int);
int ckinode(struct dinode *, struct inodesc *);
void clri(struct inodesc *, char *, int);
int dircheck(struct inodesc *, struct direct *);
void direrror(ino_t, char *);
int dirscan(struct inodesc *);
int dofix(struct inodesc *, char *);
void fileerror(ino_t, ino_t, char *);
int findino(struct inodesc *);
int findname(struct inodesc *);
void flush(int, struct bufarea *);
void freeblk(daddr_t, long);
void freeino(ino_t);
void freeinodebuf(void);
int ftypeok(struct dinode *);
void getpathname(char *, ino_t, ino_t);
void inocleanup(void);
void inodirty(void);
int linkup(ino_t, ino_t);
int makeentry(ino_t, ino_t, char *);
void pass0(void);
void pass1(void);
void pass1b(void);
void pass2(void);
void pass3(void);
void pass4(void);
int pass1check(struct inodesc *);
int pass4check(struct inodesc *);
void pass5(void);
void pinode(ino_t);
void propagate(void);
int reply(char *);
void resetinodebuf(void);
int setup(const char *);
struct dinode *getnextinode(ino_t);
void catch(int);
void catchquit(int);
void voidquit(int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsck.h,v 1.4 2000/05/16 04:55:59 perseant Exp $ */
/* $NetBSD: fsck.h,v 1.5 2000/05/23 01:48:52 perseant Exp $ */
/*
* Copyright (c) 1997
@ -38,10 +38,10 @@
*/
#ifdef KS_DEBUG
# include <err.h>
# define debug_printf warn
#include <err.h>
#define debug_printf warn
#else
# define debug_printf
#define debug_printf
#endif
#define MAXDUP 10 /* limit on dup blks (per inode) */
@ -64,20 +64,20 @@
* buffer cache structure.
*/
struct bufarea {
struct bufarea *b_next; /* free list queue */
struct bufarea *b_prev; /* free list queue */
daddr_t b_bno;
int b_size;
int b_errs;
int b_flags;
struct bufarea *b_next; /* free list queue */
struct bufarea *b_prev; /* free list queue */
daddr_t b_bno;
int b_size;
int b_errs;
int b_flags;
union {
char *b_buf; /* buffer space */
daddr_t *b_indir; /* indirect block */
struct lfs *b_fs; /* super block */
struct cg *b_cg; /* cylinder group */
struct dinode *b_dinode; /* inode block */
} b_un;
char b_dirty;
char *b_buf; /* buffer space */
daddr_t *b_indir; /* indirect block */
struct lfs *b_fs; /* super block */
struct cg *b_cg; /* cylinder group */
struct dinode *b_dinode; /* inode block */
} b_un;
char b_dirty;
};
#define B_INUSE 1
@ -90,50 +90,35 @@ struct bufarea {
(bp)->b_bno = (daddr_t)-1; \
(bp)->b_flags = 0;
#ifdef OLD
#define blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \
(((size) + ~((fs)->lfs_bmask)) & (fs)->lfs_bmask)
#if 1
#define fragroundup(fs, size) blkroundup((fs), (size))
#else
#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
(((size) + ~((fs)->lfs_fmask)) & (fs)->lfs_fmask)
#endif
#if 1
#define dblksize(fs, dip, lbn) (fs)->lfs_bsize /* XXX - no fragments, yet */
#else
#define dblksize(fs, dip, lbn) \
(((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->lfs_bshift)\
? (fs)->lfs_bsize \
: (fragroundup(fs, blkoff(fs, (dip)->di_size))))
#endif
#endif /* OLD */
#define sbdirty() sblk.b_dirty = 1
#define sblock (*sblk.b_un.b_fs)
/* #define idinode (iblk.b_un.b_dinode) */
#define ifblock (*iblk.b_un.b_dinode)
enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
enum fixstate {
DONTKNOW, NOFIX, FIX, IGNORE
};
struct inodesc {
enum fixstate id_fix; /* policy on fixing errors */
int (*id_func) /* function to be applied to blocks of inode */
__P((struct inodesc *));
ino_t id_number; /* inode number described */
ino_t id_parent; /* for DATA nodes, their parent */
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 */
int id_loc; /* for DATA nodes, current location in dir */
int id_entryno; /* for DATA nodes, current entry number */
struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
char *id_name; /* for DATA nodes, name to find or enter */
char id_type; /* type of descriptor, DATA or ADDR */
enum fixstate id_fix; /* policy on fixing errors */
int (*id_func)(struct inodesc *); /* function to be
* applied to blocks of inode */
ino_t id_number; /* inode number described */
ino_t id_parent; /* for DATA nodes, their parent */
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 */
int id_loc; /* for DATA nodes, current location
* in dir */
int id_entryno; /* for DATA nodes, current entry
* number */
struct direct *id_dirp; /* for DATA nodes, ptr to current
* entry */
char *id_name; /* for DATA nodes, name to find or
* enter */
char id_type; /* type of descriptor, DATA or ADDR */
};
/* file types */
#define DATA 1
@ -141,14 +126,14 @@ struct inodesc {
/*
* Linked list of duplicate blocks.
*
*
* The list is composed of two parts. The first part of the
* list (from duplist through the node pointed to by muldup)
* contains a single copy of each duplicate block that has been
* contains a single copy of each duplicate block that has been
* found. The second part of the list (from muldup to the end)
* contains duplicate blocks that have been found more than once.
* To check if a block has been found as a duplicate it is only
* necessary to search from duplist through muldup. To find the
* necessary to search from duplist through muldup. To find the
* total number of times that a block has been found as a duplicate
* the entire list must be searched for occurences of the block
* in question. The following diagram shows a sample list where
@ -161,42 +146,42 @@ struct inodesc {
* duplist muldup
*/
struct dups {
struct dups *next;
daddr_t dup;
struct dups *next;
daddr_t dup;
};
/*
* Linked list of inodes with zero link counts.
*/
struct zlncnt {
struct zlncnt *next;
ino_t zlncnt;
struct zlncnt *next;
ino_t zlncnt;
};
/*
* Inode cache data structures.
*/
struct inoinfo {
struct inoinfo *i_nexthash; /* next entry in hash chain */
struct inoinfo *i_child, *i_sibling, *i_parentp;
ino_t i_number; /* inode number of this entry */
ino_t i_parent; /* inode number of parent */
ino_t i_dotdot; /* inode number of `..' */
size_t i_isize; /* size of inode */
u_int i_numblks; /* size of block array in bytes */
daddr_t i_blks[1]; /* actually longer */
struct inoinfo *i_nexthash; /* next entry in hash chain */
struct inoinfo *i_child, *i_sibling, *i_parentp;
ino_t i_number; /* inode number of this entry */
ino_t i_parent; /* inode number of parent */
ino_t i_dotdot; /* inode number of `..' */
size_t i_isize; /* size of inode */
u_int i_numblks; /* size of block array in bytes */
daddr_t i_blks[1]; /* actually longer */
} **inphead, **inpsort;
#define clearinode(dp) (*(dp) = zino)
#ifndef VERBOSE_BLOCKMAP
# define setbmap(blkno) setbit(blockmap, blkno)
# define testbmap(blkno) isset(blockmap, blkno)
# define clrbmap(blkno) clrbit(blockmap, blkno)
#define setbmap(blkno) setbit(blockmap, blkno)
#define testbmap(blkno) isset(blockmap, blkno)
#define clrbmap(blkno) clrbit(blockmap, blkno)
#else
# define setbmap(blkno,ino) if(blkno > maxfsblock) raise(1); else blockmap[blkno] = ino
# define testbmap(blkno) blockmap[blkno]
# define clrbmap(blkno) blockmap[blkno] = 0
#define setbmap(blkno,ino) if(blkno > maxfsblock)raise(1); else blockmap[blkno] = ino
#define testbmap(blkno) blockmap[blkno]
#define clrbmap(blkno) blockmap[blkno] = 0
#endif
#define STOP 0x01
@ -205,18 +190,18 @@ struct inoinfo {
#define ALTERED 0x08
#define FOUND 0x10
ino_t allocino __P((ino_t, int));
int ino_to_fsba __P((struct lfs *, ino_t));
struct bufarea *getfileblk __P((struct lfs *, struct dinode *, ino_t));
struct dinode *ginode __P((ino_t));
struct dinode *lfs_ginode __P((ino_t));
struct dinode *lfs_difind __P((struct lfs *, ino_t, struct dinode *));
struct ifile *lfs_ientry __P((ino_t, struct bufarea **));
struct inoinfo *getinoinfo __P((ino_t));
void getblk __P((struct bufarea *, daddr_t, long));
void getdblk __P((struct bufarea *, daddr_t, long));
int check_summary(struct lfs *, SEGSUM *, daddr_t);
SEGUSE *lfs_gseguse(int, struct bufarea **);
daddr_t lfs_ino_daddr(ino_t);
ino_t allocino(ino_t, int);
int ino_to_fsba(struct lfs *, ino_t);
struct bufarea *getfileblk(struct lfs *, struct dinode *, ino_t);
struct dinode *ginode(ino_t);
struct dinode *lfs_ginode(ino_t);
struct dinode *lfs_difind(struct lfs *, ino_t, struct dinode *);
struct ifile *lfs_ientry(ino_t, struct bufarea **);
struct inoinfo *getinoinfo(ino_t);
void getblk(struct bufarea *, daddr_t, long);
void getdblk(struct bufarea *, daddr_t, long);
int check_summary(struct lfs *, SEGSUM *, daddr_t);
SEGUSE *lfs_gseguse(int, struct bufarea **);
daddr_t lfs_ino_daddr(ino_t);
#include "fsck_vars.h"

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsck_vars.h,v 1.2 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: fsck_vars.h,v 1.3 2000/05/23 01:48:53 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -40,57 +40,56 @@ extern struct bufarea sblk; /* file system superblock */
extern struct bufarea iblk; /* ifile on-disk inode block */
extern struct bufarea *pdirbp; /* current directory contents */
extern struct bufarea *pbp; /* current inode block */
extern struct bufarea *getddblk __P((daddr_t, long));
extern struct bufarea *getdatablk __P((daddr_t, long));
extern int iinooff; /* ifile inode offset in block of inodes */
extern struct bufarea *getddblk(daddr_t, long);
extern struct bufarea *getdatablk(daddr_t, long);
extern int iinooff; /* ifile inode offset in block of inodes */
extern struct dups *duplist; /* head of dup list */
extern struct dups *muldup; /* end of unique duplicate dup block numbers */
extern struct zlncnt *zlnhead; /* head of zero link count list */
extern long numdirs, listmax, inplast;
extern long numdirs, listmax, inplast;
extern long dev_bsize; /* computed value of DEV_BSIZE */
extern long secsize; /* actual disk sector size */
extern char nflag; /* assume a no response */
extern char yflag; /* assume a yes response */
extern int bflag; /* location of alternate super block */
extern int debug; /* output debugging info */
extern long dev_bsize; /* computed value of DEV_BSIZE */
extern long secsize; /* actual disk sector size */
extern char nflag; /* assume a no response */
extern char yflag; /* assume a yes response */
extern int bflag; /* location of alternate super block */
extern int debug; /* output debugging info */
#ifdef DEBUG_IFILE
extern int debug_ifile; /* cat ifile and exit */
extern int debug_ifile; /* cat ifile and exit */
#endif
extern int exitonfail;
extern int cvtlevel; /* convert to newer file system format */
extern int doinglevel1; /* converting to new cylinder group format */
extern int doinglevel2; /* converting to new inode format */
extern int newinofmt; /* filesystem has new inode format */
extern int preen; /* just fix normal inconsistencies */
extern char havesb; /* superblock has been read */
extern char skipclean; /* skip clean file systems if preening */
extern int fsmodified; /* 1 => write done to file system */
extern int fsreadfd; /* file descriptor for reading file system */
extern int fswritefd; /* file descriptor for writing file system */
extern int rerun; /* rerun fsck. Only used in non-preen mode */
extern int cvtlevel; /* convert to newer file system format */
extern int doinglevel1; /* converting to new cylinder group format */
extern int doinglevel2; /* converting to new inode format */
extern int newinofmt; /* filesystem has new inode format */
extern int preen; /* just fix normal inconsistencies */
extern char havesb; /* superblock has been read */
extern char skipclean; /* skip clean file systems if preening */
extern int fsmodified; /* 1 => write done to file system */
extern int fsreadfd; /* file descriptor for reading file system */
extern int fswritefd; /* file descriptor for writing file system */
extern int rerun; /* rerun fsck. Only used in non-preen mode */
extern daddr_t maxfsblock; /* number of blocks in the file system */
extern daddr_t maxfsblock; /* number of blocks in the file system */
#ifndef VERBOSE_BLOCKMAP
extern char *blockmap; /* ptr to primary blk allocation map */
extern char *blockmap; /* ptr to primary blk allocation map */
#else
extern ino_t *blockmap; /* ptr to primary blk allocation map */
extern ino_t *blockmap; /* ptr to primary blk allocation map */
#endif
extern ino_t maxino; /* number of inodes in file system */
extern ino_t lastino; /* last inode in use */
extern char *statemap; /* ptr to inode state table */
extern char *typemap; /* ptr to inode type table */
extern int16_t *lncntp; /* ptr to link count table */
extern ino_t maxino; /* number of inodes in file system */
extern ino_t lastino; /* last inode in use */
extern char *statemap; /* ptr to inode state table */
extern char *typemap; /* ptr to inode type table */
extern int16_t *lncntp; /* ptr to link count table */
extern ino_t lfdir; /* lost & found directory inode number */
extern char *lfname; /* lost & found directory name */
extern int lfmode; /* lost & found directory creation mode */
extern ino_t lfdir; /* lost & found directory inode number */
extern char *lfname; /* lost & found directory name */
extern int lfmode; /* lost & found directory creation mode */
extern daddr_t n_blks; /* number of blocks in use */
extern daddr_t n_files; /* number of files in use */
extern struct dinode zino;
extern daddr_t n_blks; /* number of blocks in use */
extern daddr_t n_files; /* number of files in use */
extern struct dinode zino;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.4 2000/05/16 04:55:59 perseant Exp $ */
/* $NetBSD: main.c,v 1.5 2000/05/23 01:48:53 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -52,30 +52,28 @@
#include "extern.h"
#include "fsutil.h"
int returntosingle;
int fake_cleanseg = -1;
int returntosingle;
int fake_cleanseg = -1;
int main __P((int, char *[]));
int main(int, char *[]);
static int argtoi __P((int, char *, char *, int));
static int checkfilesys __P((const char *, char *, long, int));
static int argtoi(int, char *, char *, int);
static int checkfilesys(const char *, char *, long, int);
#if 0
static int docheck __P((struct fstab *));
static int docheck(struct fstab *);
#endif
static void usage __P((void));
static void usage(void);
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char **argv)
{
int ch;
int ret = 0;
char *optstring = "b:C:dm:npy";
int ch;
int ret = 0;
char *optstring = "b:C:dm:npy";
sync();
skipclean = 1;
exitonfail = 0;
exitonfail = 0;
while ((ch = getopt(argc, argv, optstring)) != EOF) {
switch (ch) {
case 'b':
@ -89,12 +87,12 @@ main(argc, argv)
case 'd':
debug++;
break;
case 'e':
exitonfail++;
break;
case 'e':
exitonfail++;
break;
case 'm':
lfmode = argtoi('m', "mode", optarg, 8);
if (lfmode &~ 07777)
if (lfmode & ~07777)
errexit("bad mode to -m: %o\n", lfmode);
printf("** lost+found creation mode %o\n", lfmode);
break;
@ -118,7 +116,7 @@ main(argc, argv)
}
}
#if 0
if(nflag==0) {
if (nflag == 0) {
errexit("fsck_lfs cannot write to the filesystem yet; the -n flag is required.\n");
}
#endif
@ -144,13 +142,10 @@ main(argc, argv)
}
static int
argtoi(flag, req, str, base)
int flag;
char *req, *str;
int base;
argtoi(int flag, char *req, char *str, int base)
{
char *cp;
int ret;
char *cp;
int ret;
ret = (int)strtol(str, &cp, base);
if (cp == str || *cp)
@ -163,8 +158,7 @@ argtoi(flag, req, str, base)
* Determine whether a filesystem should be checked.
*/
static int
docheck(fsp)
register struct fstab *fsp;
docheck(struct fstab * fsp)
{
if ((strcmp(fsp->fs_vfstype, "ufs") &&
@ -182,15 +176,11 @@ docheck(fsp)
*/
/* ARGSUSED */
static int
checkfilesys(filesys, mntpt, auxdata, child)
const char *filesys;
char *mntpt;
long auxdata;
int child;
checkfilesys(const char *filesys, char *mntpt, long auxdata, int child)
{
daddr_t n_ffree=0, n_bfree=0;
struct dups *dp;
struct zlncnt *zlnp;
daddr_t n_ffree = 0, n_bfree = 0;
struct dups *dp;
struct zlncnt *zlnp;
if (preen && child)
(void)signal(SIGQUIT, voidquit);
@ -205,41 +195,40 @@ checkfilesys(filesys, mntpt, auxdata, child)
return (0);
}
if(preen == 0) {
if (preen == 0) {
printf("** Last Mounted on %s\n", sblock.lfs_fsmnt);
if (hotroot())
printf("** Root file system\n");
}
/*
}
/*
* 0: check segment checksums, inode ranges
*/
if (preen == 0)
printf("** Phase 0 - Check Segment Summaries and Inode Free List\n");
pass0();
printf("** Phase 0 - Check Segment Summaries and Inode Free List\n");
pass0();
if (preen==0) {
if (preen == 0) {
/*
* 1: scan inodes tallying blocks used
*/
if (preen == 0)
printf("** Phase 1 - Check Blocks and Sizes\n");
pass1();
/*
* 2: traverse directories from root to mark all connected directories
*/
if (preen == 0)
printf("** Phase 2 - Check Pathnames\n");
pass2();
/*
* 3: scan inodes looking for disconnected directories
*/
if (preen == 0)
printf("** Phase 3 - Check Connectivity\n");
pass3();
/*
* 4: scan inodes looking for disconnected files; check reference counts
*/
@ -262,7 +251,6 @@ checkfilesys(filesys, mntpt, auxdata, child)
n_files, n_blks, n_ffree + sblock.lfs_frag * n_bfree);
putchar('\n');
}
if (debug) {
if (duplist != NULL) {
printf("The following duplicate blocks remain:");
@ -293,15 +281,15 @@ checkfilesys(filesys, mntpt, auxdata, child)
if (rerun)
printf("\n***** PLEASE RERUN FSCK *****\n");
if (hotroot()) {
struct statfs stfs_buf;
struct statfs stfs_buf;
/*
* We modified the root. Do a mount update on
* it, unless it is read-write, so we can continue.
*/
if (statfs("/", &stfs_buf) == 0) {
long flags = stfs_buf.f_flags;
long flags = stfs_buf.f_flags;
struct ufs_args args;
int ret;
int ret;
if (flags & MNT_RDONLY) {
args.fspec = 0;
@ -310,7 +298,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
flags |= MNT_UPDATE | MNT_RELOAD;
ret = mount(MOUNT_LFS, "/", flags, &args);
if (ret == 0)
return(0);
return (0);
}
}
if (!preen)
@ -324,11 +312,10 @@ checkfilesys(filesys, mntpt, auxdata, child)
static void
usage()
{
extern char *__progname;
extern char *__progname;
(void) fprintf(stderr,
"Usage: %s [-dnpy] [-b block] [-m mode] filesystem ...\n",
__progname);
(void)fprintf(stderr,
"Usage: %s [-dnpy] [-b block] [-m mode] filesystem ...\n",
__progname);
exit(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass0.c,v 1.4 2000/05/16 04:55:59 perseant Exp $ */
/* $NetBSD: pass0.c,v 1.5 2000/05/23 01:48:54 perseant Exp $ */
/*
* Copyright (c) 1998 Konrad E. Schroder.
@ -54,268 +54,274 @@
#define CKSEG_VERBOSE 1
#define CKSEG_IGNORECLEAN 2
extern int fake_cleanseg;
void check_segment(int, int, daddr_t, struct lfs *, int,
int (*)(struct lfs *, SEGSUM *, daddr_t));
extern int fake_cleanseg;
void
check_segment(int, int, daddr_t, struct lfs *, int,
int (*)(struct lfs *, SEGSUM *, daddr_t));
/*
* Pass 0. Check the LFS partial segments for valid checksums, correcting
* if necessary. Also check for valid offsets for inode and finfo blocks.
*/
/* XXX more could be done here---consistency between inode-held blocks and
finfo blocks, for one thing. */
/*
* XXX more could be done here---consistency between inode-held blocks and
* finfo blocks, for one thing.
*/
#define dbshift (sblock.lfs_bshift - sblock.lfs_fsbtodb)
void pass0()
void pass0()
{
daddr_t daddr;
IFILE *ifp;
struct bufarea *bp;
ino_t ino, lastino, nextino;
daddr_t daddr;
IFILE *ifp;
struct bufarea *bp;
ino_t ino, lastino, nextino;
/*
* Check the inode free list for inuse inodes.
*
* XXX should also check for cycles or breaks in the list, and be able
* to repair them.
*/
lastino = 0;
ino=sblock.lfs_free;
while(ino) {
ifp = lfs_ientry(ino,&bp);
nextino = ifp->if_nextfree;
daddr = ifp->if_daddr;
bp->b_flags &= ~B_INUSE;
if(daddr) {
printf("! Ino %d with daddr 0x%x is on the free list!\n",
ino, daddr);
if(preen || reply("FIX")==1) {
if(lastino == 0) {
sblock.lfs_free = nextino;
sbdirty();
} else {
ifp = lfs_ientry(lastino,&bp);
ifp->if_nextfree = nextino;
++bp->b_dirty;
bp->b_flags &= ~B_INUSE;
}
ino = nextino;
continue;
}
}
lastino = ino;
ino = nextino;
}
}
static void dump_segsum(SEGSUM *sump, daddr_t addr)
{
printf("Dump partial summary block 0x%x\n",addr);
printf("\tsumsum: %x (%d)\n",sump->ss_sumsum,sump->ss_sumsum);
printf("\tdatasum: %x (%d)\n",sump->ss_datasum,sump->ss_datasum);
printf("\tnext: %x (%d)\n",sump->ss_next,sump->ss_next);
printf("\tcreate: %x (%d)\n",sump->ss_create,sump->ss_create);
printf("\tnfinfo: %x (%d)\n",sump->ss_nfinfo,sump->ss_nfinfo);
printf("\tninos: %x (%d)\n",sump->ss_ninos,sump->ss_ninos);
printf("\tflags: %c%c\n",
sump->ss_flags&SS_DIROP?'d':'-',
sump->ss_flags&SS_CONT?'c':'-');
}
void check_segment(int fd, int segnum, daddr_t addr, struct lfs *fs, int flags, int (*func)(struct lfs *, SEGSUM *, daddr_t))
{
struct lfs *sbp;
SEGSUM *sump=NULL;
SEGUSE *su;
struct bufarea *bp = NULL;
int psegnum=0, ninos=0;
off_t sum_offset, db_ssize;
int bc, su_flags, su_nsums, su_ninos;
db_ssize = sblock.lfs_ssize << sblock.lfs_fsbtodb;
su = lfs_gseguse(segnum, &bp);
su_flags = su->su_flags;
su_nsums = su->su_nsums;
su_ninos = su->su_ninos;
bp->b_flags &= ~B_INUSE;
/* printf("Seg at 0x%x\n",addr); */
if((flags & CKSEG_VERBOSE) && segnum*db_ssize + fs->lfs_sboffs[0] != addr)
pwarn("WARNING: segment begins at 0x%qx, should be 0x%qx\n",
(long long unsigned)addr,
(long long unsigned)(segnum*db_ssize + fs->lfs_sboffs[0]));
sum_offset = ((off_t)addr << dbshift);
/* If this segment should have a superblock, look for one */
if(su_flags & SEGUSE_SUPERBLOCK) {
bp = getddblk(sum_offset >> dbshift, LFS_SBPAD);
sum_offset += LFS_SBPAD;
/* check for a superblock -- XXX this is crude */
sbp = (struct lfs *)(bp->b_un.b_buf);
if(sbp->lfs_magic==LFS_MAGIC) {
#if 0
if(sblock.lfs_tstamp == sbp->lfs_tstamp
&& memcmp(sbp,&sblock,sizeof(*sbp))
&& (flags & CKSEG_VERBOSE))
pwarn("SUPERBLOCK MISMATCH SEGMENT %d\n", segnum);
#endif
} else {
if(flags & CKSEG_VERBOSE)
pwarn("SEGMENT %d SUPERBLOCK INVALID\n",segnum);
/* XXX allow to fix */
}
bp->b_flags &= ~B_INUSE;
}
/* XXX need to also check whether this one *should* be dirty */
if((flags & CKSEG_IGNORECLEAN) && (su_flags & SEGUSE_DIRTY)==0)
return;
while(1) {
if(su_nsums <= psegnum)
break;
bp = getddblk(sum_offset >> dbshift, LFS_SUMMARY_SIZE);
sump = (SEGSUM *)(bp->b_un.b_buf);
if (sump->ss_magic != SS_MAGIC) {
if(flags & CKSEG_VERBOSE)
printf("PARTIAL SEGMENT %d SEGMENT %d BAD PARTIAL SEGMENT MAGIC (0x%x should be 0x%x)\n",
psegnum, segnum, sump->ss_magic, SS_MAGIC);
bp->b_flags &= ~B_INUSE;
break;
}
if(sump->ss_sumsum != cksum(&sump->ss_datasum, LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
if(flags & CKSEG_VERBOSE) {
/* Corrupt partial segment */
pwarn("CORRUPT PARTIAL SEGMENT %d/%d OF SEGMENT %d AT BLK 0x%qx",
psegnum, su_nsums, segnum,
(unsigned long long)sum_offset>>dbshift);
if(db_ssize < (sum_offset>>dbshift) - addr)
pwarn(" (+0x%qx/0x%qx)",
(unsigned long long)(((sum_offset>>dbshift) - addr) -
db_ssize),
(unsigned long long)db_ssize);
else
pwarn(" (-0x%qx/0x%qx)",
(unsigned long long)(db_ssize -
((sum_offset>>dbshift) - addr)),
(unsigned long long)db_ssize);
pwarn("\n");
dump_segsum(sump,sum_offset>>dbshift);
}
/* XXX fix it maybe */
bp->b_flags &= ~B_INUSE;
break; /* XXX could be throwing away data, but if this segsum
* is invalid, how to know where the next summary
* begins? */
}
/*
* Good partial segment
*/
bc = (*func)(&sblock, sump, (daddr_t)(sum_offset>>dbshift));
if(bc) {
sum_offset += LFS_SUMMARY_SIZE + bc;
ninos += (sump->ss_ninos + INOPB(&sblock)-1)/INOPB(&sblock);
psegnum++;
} else {
bp->b_flags &= ~B_INUSE;
break;
* Check the inode free list for inuse inodes.
*
* XXX should also check for cycles or breaks in the list, and be able
* to repair them.
*/
lastino = 0;
ino = sblock.lfs_free;
while (ino) {
ifp = lfs_ientry(ino, &bp);
nextino = ifp->if_nextfree;
daddr = ifp->if_daddr;
bp->b_flags &= ~B_INUSE;
if (daddr) {
printf("! Ino %d with daddr 0x%x is on the free list!\n",
ino, daddr);
if (preen || reply("FIX") == 1) {
if (lastino == 0) {
sblock.lfs_free = nextino;
sbdirty();
} else {
ifp = lfs_ientry(lastino, &bp);
ifp->if_nextfree = nextino;
++bp->b_dirty;
bp->b_flags &= ~B_INUSE;
}
ino = nextino;
continue;
}
}
lastino = ino;
ino = nextino;
}
bp->b_flags &= ~B_INUSE;
}
if(flags & CKSEG_VERBOSE) {
if(ninos != su_ninos)
pwarn("SEGMENT %d has %d ninos, not %d\n",
segnum, ninos, su_ninos);
if(psegnum != su_nsums)
pwarn("SEGMENT %d has %d summaries, not %d\n",
segnum, psegnum, su_nsums);
}
return;
}
int check_summary(struct lfs *fs, SEGSUM *sp, daddr_t pseg_addr)
static void
dump_segsum(SEGSUM * sump, daddr_t addr)
{
FINFO *fp;
int bc; /* Bytes in partial segment */
int nblocks;
daddr_t seg_addr, *dp, *idp, daddr;
struct bufarea *bp;
int i, j, k, datac, len;
long sn;
u_long *datap;
u_int32_t ccksum;
sn = datosn(fs, pseg_addr);
seg_addr = sntoda(fs, sn);
/* printf("Pseg at 0x%x, %d inos, %d finfos\n",addr>>dbshift,sp->ss_ninos,sp->ss_nfinfo); */
/* We've already checked the sumsum, just do the data bounds and sum */
/* 1. Count the blocks. */
nblocks = ((sp->ss_ninos + INOPB(fs) - 1) / INOPB(fs));
bc = nblocks << fs->lfs_bshift;
fp = (FINFO *)(sp + 1);
for(i=0; i<sp->ss_nfinfo; i++) {
nblocks += fp->fi_nblocks;
bc += fp->fi_lastlength + ((fp->fi_nblocks-1) << fs->lfs_bshift);
fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks);
}
datap = (u_long *)malloc(nblocks * sizeof(*datap));
datac = 0;
dp = (daddr_t *)sp;
dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
dp--;
idp = dp;
daddr = pseg_addr + (LFS_SUMMARY_SIZE/dev_bsize);
fp = (FINFO *)(sp + 1);
for(i=0, j=0; i<sp->ss_nfinfo || j<howmany(sp->ss_ninos,INOPB(fs)); i++) {
/* printf("*idp=%x, daddr=%x\n", *idp, daddr); */
if(i >= sp->ss_nfinfo && *idp != daddr) {
pwarn("Not enough inode blocks in pseg at 0x%x: found %d, wanted %d\n",
pseg_addr, j, howmany(sp->ss_ninos,INOPB(fs)));
pwarn("*idp=%x, daddr=%x\n", *idp, daddr);
break;
}
while(j < howmany(sp->ss_ninos,INOPB(fs)) && *idp == daddr) {
bp = getddblk(daddr, (1<<fs->lfs_bshift));
datap[datac++] = ((u_long *)(bp->b_un.b_buf))[0];
bp->b_flags &= ~B_INUSE;
++j;
daddr += (1<<fs->lfs_bshift)/dev_bsize;
--idp;
}
if(i < sp->ss_nfinfo) {
for(k=0; k<fp->fi_nblocks; k++) {
len = (k==fp->fi_nblocks - 1 ? fp->fi_lastlength
: (1<<fs->lfs_bshift));
bp = getddblk(daddr, len);
datap[datac++] = ((u_long *)(bp->b_un.b_buf))[0];
bp->b_flags &= ~B_INUSE;
daddr += len/dev_bsize;
}
fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks);
}
}
if(datac != nblocks) {
pwarn("Partial segment at 0x%x expected %d blocks counted %d\n",
pseg_addr, nblocks, datac);
}
ccksum = cksum(datap, nblocks * sizeof(u_long));
/* Check the data checksum */
if (ccksum != sp->ss_datasum) {
pwarn("Partial segment at 0x%x data checksum mismatch: got 0x%x, expected 0x%x\n",
pseg_addr, sp->ss_datasum, ccksum);
/* return 0; */
}
return bc;
printf("Dump partial summary block 0x%x\n", addr);
printf("\tsumsum: %x (%d)\n", sump->ss_sumsum, sump->ss_sumsum);
printf("\tdatasum: %x (%d)\n", sump->ss_datasum, sump->ss_datasum);
printf("\tnext: %x (%d)\n", sump->ss_next, sump->ss_next);
printf("\tcreate: %x (%d)\n", sump->ss_create, sump->ss_create);
printf("\tnfinfo: %x (%d)\n", sump->ss_nfinfo, sump->ss_nfinfo);
printf("\tninos: %x (%d)\n", sump->ss_ninos, sump->ss_ninos);
printf("\tflags: %c%c\n",
sump->ss_flags & SS_DIROP ? 'd' : '-',
sump->ss_flags & SS_CONT ? 'c' : '-');
}
void
check_segment(int fd, int segnum, daddr_t addr, struct lfs * fs, int flags, int (*func)(struct lfs *, SEGSUM *, daddr_t))
{
struct lfs *sbp;
SEGSUM *sump = NULL;
SEGUSE *su;
struct bufarea *bp = NULL;
int psegnum = 0, ninos = 0;
off_t sum_offset, db_ssize;
int bc, su_flags, su_nsums, su_ninos;
db_ssize = sblock.lfs_ssize << sblock.lfs_fsbtodb;
su = lfs_gseguse(segnum, &bp);
su_flags = su->su_flags;
su_nsums = su->su_nsums;
su_ninos = su->su_ninos;
bp->b_flags &= ~B_INUSE;
/* printf("Seg at 0x%x\n",addr); */
if ((flags & CKSEG_VERBOSE) && segnum * db_ssize + fs->lfs_sboffs[0] != addr)
pwarn("WARNING: segment begins at 0x%qx, should be 0x%qx\n",
(long long unsigned)addr,
(long long unsigned)(segnum * db_ssize + fs->lfs_sboffs[0]));
sum_offset = ((off_t)addr << dbshift);
/* If this segment should have a superblock, look for one */
if (su_flags & SEGUSE_SUPERBLOCK) {
bp = getddblk(sum_offset >> dbshift, LFS_SBPAD);
sum_offset += LFS_SBPAD;
/* check for a superblock -- XXX this is crude */
sbp = (struct lfs *)(bp->b_un.b_buf);
if (sbp->lfs_magic == LFS_MAGIC) {
#if 0
if (sblock.lfs_tstamp == sbp->lfs_tstamp &&
memcmp(sbp, &sblock, sizeof(*sbp)) &&
(flags & CKSEG_VERBOSE))
pwarn("SUPERBLOCK MISMATCH SEGMENT %d\n", segnum);
#endif
} else {
if (flags & CKSEG_VERBOSE)
pwarn("SEGMENT %d SUPERBLOCK INVALID\n", segnum);
/* XXX allow to fix */
}
bp->b_flags &= ~B_INUSE;
}
/* XXX need to also check whether this one *should* be dirty */
if ((flags & CKSEG_IGNORECLEAN) && (su_flags & SEGUSE_DIRTY) == 0)
return;
while (1) {
if (su_nsums <= psegnum)
break;
bp = getddblk(sum_offset >> dbshift, LFS_SUMMARY_SIZE);
sump = (SEGSUM *)(bp->b_un.b_buf);
if (sump->ss_magic != SS_MAGIC) {
if (flags & CKSEG_VERBOSE)
printf("PARTIAL SEGMENT %d SEGMENT %d BAD PARTIAL SEGMENT MAGIC (0x%x should be 0x%x)\n",
psegnum, segnum, sump->ss_magic, SS_MAGIC);
bp->b_flags &= ~B_INUSE;
break;
}
if (sump->ss_sumsum != cksum(&sump->ss_datasum, LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
if (flags & CKSEG_VERBOSE) {
/* Corrupt partial segment */
pwarn("CORRUPT PARTIAL SEGMENT %d/%d OF SEGMENT %d AT BLK 0x%qx",
psegnum, su_nsums, segnum,
(unsigned long long)sum_offset >> dbshift);
if (db_ssize < (sum_offset >> dbshift) - addr)
pwarn(" (+0x%qx/0x%qx)",
(unsigned long long)(((sum_offset >> dbshift) - addr) -
db_ssize),
(unsigned long long)db_ssize);
else
pwarn(" (-0x%qx/0x%qx)",
(unsigned long long)(db_ssize -
((sum_offset >> dbshift) - addr)),
(unsigned long long)db_ssize);
pwarn("\n");
dump_segsum(sump, sum_offset >> dbshift);
}
/* XXX fix it maybe */
bp->b_flags &= ~B_INUSE;
break; /* XXX could be throwing away data, but if
* this segsum is invalid, how to know where
* the next summary begins? */
}
/*
* Good partial segment
*/
bc = (*func)(&sblock, sump, (daddr_t)(sum_offset >> dbshift));
if (bc) {
sum_offset += LFS_SUMMARY_SIZE + bc;
ninos += (sump->ss_ninos + INOPB(&sblock) - 1) / INOPB(&sblock);
psegnum++;
} else {
bp->b_flags &= ~B_INUSE;
break;
}
bp->b_flags &= ~B_INUSE;
}
if (flags & CKSEG_VERBOSE) {
if (ninos != su_ninos)
pwarn("SEGMENT %d has %d ninos, not %d\n",
segnum, ninos, su_ninos);
if (psegnum != su_nsums)
pwarn("SEGMENT %d has %d summaries, not %d\n",
segnum, psegnum, su_nsums);
}
return;
}
int
check_summary(struct lfs * fs, SEGSUM * sp, daddr_t pseg_addr)
{
FINFO *fp;
int bc; /* Bytes in partial segment */
int nblocks;
daddr_t seg_addr, *dp, *idp, daddr;
struct bufarea *bp;
int i, j, k, datac, len;
long sn;
u_long *datap;
u_int32_t ccksum;
sn = datosn(fs, pseg_addr);
seg_addr = sntoda(fs, sn);
/*
* printf("Pseg at 0x%x, %d inos, %d
* finfos\n",addr>>dbshift,sp->ss_ninos,sp->ss_nfinfo);
*/
/* We've already checked the sumsum, just do the data bounds and sum */
/* 1. Count the blocks. */
nblocks = ((sp->ss_ninos + INOPB(fs) - 1) / INOPB(fs));
bc = nblocks << fs->lfs_bshift;
fp = (FINFO *)(sp + 1);
for (i = 0; i < sp->ss_nfinfo; i++) {
nblocks += fp->fi_nblocks;
bc += fp->fi_lastlength + ((fp->fi_nblocks - 1) << fs->lfs_bshift);
fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks);
}
datap = (u_long *)malloc(nblocks * sizeof(*datap));
datac = 0;
dp = (daddr_t *)sp;
dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
dp--;
idp = dp;
daddr = pseg_addr + (LFS_SUMMARY_SIZE / dev_bsize);
fp = (FINFO *)(sp + 1);
for (i = 0, j = 0; i < sp->ss_nfinfo || j < howmany(sp->ss_ninos, INOPB(fs)); i++) {
/* printf("*idp=%x, daddr=%x\n", *idp, daddr); */
if (i >= sp->ss_nfinfo && *idp != daddr) {
pwarn("Not enough inode blocks in pseg at 0x%x: found %d, wanted %d\n",
pseg_addr, j, howmany(sp->ss_ninos, INOPB(fs)));
pwarn("*idp=%x, daddr=%x\n", *idp, daddr);
break;
}
while (j < howmany(sp->ss_ninos, INOPB(fs)) && *idp == daddr) {
bp = getddblk(daddr, (1 << fs->lfs_bshift));
datap[datac++] = ((u_long *)(bp->b_un.b_buf))[0];
bp->b_flags &= ~B_INUSE;
++j;
daddr += (1 << fs->lfs_bshift) / dev_bsize;
--idp;
}
if (i < sp->ss_nfinfo) {
for (k = 0; k < fp->fi_nblocks; k++) {
len = (k == fp->fi_nblocks - 1 ? fp->fi_lastlength
: (1 << fs->lfs_bshift));
bp = getddblk(daddr, len);
datap[datac++] = ((u_long *)(bp->b_un.b_buf))[0];
bp->b_flags &= ~B_INUSE;
daddr += len / dev_bsize;
}
fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks);
}
}
if (datac != nblocks) {
pwarn("Partial segment at 0x%x expected %d blocks counted %d\n",
pseg_addr, nblocks, datac);
}
ccksum = cksum(datap, nblocks * sizeof(u_long));
/* Check the data checksum */
if (ccksum != sp->ss_datasum) {
pwarn("Partial segment at 0x%x data checksum mismatch: got 0x%x, expected 0x%x\n",
pseg_addr, sp->ss_datasum, ccksum);
/* return 0; */
}
return bc;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass1.c,v 1.5 2000/05/16 04:55:59 perseant Exp $ */
/* $NetBSD: pass1.c,v 1.6 2000/05/23 01:48:54 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -50,28 +50,29 @@
#include "extern.h"
#include "fsutil.h"
SEGUSE *seg_table;
SEGUSE *seg_table;
extern daddr_t *din_table;
static daddr_t badblk;
static daddr_t dupblk;
static void checkinode __P((ino_t, struct inodesc *));
static int i_d_cmp(const void *, const void *);
static daddr_t badblk;
static daddr_t dupblk;
static void checkinode(ino_t, struct inodesc *);
static int i_d_cmp(const void *, const void *);
static void bmapcheck(void)
static void
bmapcheck(void)
{
int i;
int i;
if(testbmap(0))
if (testbmap(0))
raise(1);
for(i=0;i<maxfsblock;i++)
if(testbmap(i) > maxino)
for (i = 0; i < maxfsblock; i++)
if (testbmap(i) > maxino)
raise(1);
}
struct ino_daddr {
ino_t ino;
daddr_t daddr;
ino_t ino;
daddr_t daddr;
};
static int
@ -94,29 +95,29 @@ i_d_cmp(const void *va, const void *vb)
void
pass1()
{
ino_t inumber;
int i, total_segments;
struct inodesc idesc;
struct dinode *idinode, *tinode;
struct ifile *ifp;
CLEANERINFO *cp;
ino_t inumber;
int i, total_segments;
struct inodesc idesc;
struct dinode *idinode, *tinode;
struct ifile *ifp;
CLEANERINFO *cp;
struct bufarea *bp;
struct ino_daddr **dins;
idinode = lfs_difind(&sblock,sblock.lfs_ifile,&ifblock);
idinode = lfs_difind(&sblock, sblock.lfs_ifile, &ifblock);
/*
/*
* We now have the ifile's inode block in core. Read out the
* number of segments.
*/
#if 1
if(pbp != 0)
pbp->b_flags &= ~B_INUSE;
pbp = getddblk(idinode->di_db[0], sblock.lfs_bsize);
if (pbp != 0)
pbp->b_flags &= ~B_INUSE;
pbp = getddblk(idinode->di_db[0], sblock.lfs_bsize);
cp = (CLEANERINFO *)(pbp->b_un.b_buf);
cp = (CLEANERINFO *)(pbp->b_un.b_buf);
#endif
total_segments = sblock.lfs_size / sblock.lfs_bsize;
total_segments = sblock.lfs_size / sblock.lfs_bsize;
/*
* Find all allocated blocks, initialize numdirs.
@ -131,49 +132,48 @@ pass1()
if (debug)
printf("creating inode address table...\n");
/* Sort by daddr */
dins = (struct ino_daddr **)malloc((maxino+1) * sizeof(*dins));
for(i=0;i<=maxino;i++) {
dins = (struct ino_daddr **)malloc((maxino + 1) * sizeof(*dins));
for (i = 0; i <= maxino; i++) {
dins[i] = malloc(sizeof(**dins));
dins[i]->ino = i;
dins[i]->daddr = lfs_ino_daddr(i);
}
qsort(dins, maxino+1, sizeof(*dins), i_d_cmp);
qsort(dins, maxino + 1, sizeof(*dins), i_d_cmp);
/* find a value for numdirs, fill in din_table */
if (debug)
printf("counting dirs...\n");
numdirs=0;
for(i=0; i <= maxino; i++) {
numdirs = 0;
for (i = 0; i <= maxino; i++) {
inumber = dins[i]->ino;
if(inumber == 0 || dins[i]->daddr == 0)
if (inumber == 0 || dins[i]->daddr == 0)
continue;
tinode = lfs_ginode(inumber);
if(tinode && (tinode->di_mode & IFMT)==IFDIR)
if (tinode && (tinode->di_mode & IFMT) == IFDIR)
numdirs++;
}
/* from setup.c */
inplast = 0;
listmax = numdirs + 10;
inpsort = (struct inoinfo **)calloc((unsigned)listmax,
sizeof(struct inoinfo *));
inphead = (struct inoinfo **)calloc((unsigned)numdirs,
sizeof(struct inoinfo *));
if (inpsort == NULL || inphead == NULL) {
printf("cannot alloc %lu bytes for inphead\n",
(unsigned long)numdirs * sizeof(struct inoinfo *));
inplast = 0;
listmax = numdirs + 10;
inpsort = (struct inoinfo **)calloc((unsigned) listmax,
sizeof(struct inoinfo *));
inphead = (struct inoinfo **)calloc((unsigned) numdirs,
sizeof(struct inoinfo *));
if (inpsort == NULL || inphead == NULL) {
printf("cannot alloc %lu bytes for inphead\n",
(unsigned long)numdirs * sizeof(struct inoinfo *));
exit(1);
}
}
/* resetinodebuf(); */
if (debug)
printf("counting blocks...\n");
for(i=0; i <= maxino; i++) {
for (i = 0; i <= maxino; i++) {
inumber = dins[i]->ino;
if(inumber == 0 || dins[i]->daddr == 0)
if (inumber == 0 || dins[i]->daddr == 0)
continue;
ifp = lfs_ientry(inumber,&bp);
if(ifp && ifp->if_daddr != LFS_UNUSED_DADDR) {
ifp = lfs_ientry(inumber, &bp);
if (ifp && ifp->if_daddr != LFS_UNUSED_DADDR) {
bp->b_flags &= ~B_INUSE;
checkinode(inumber, &idesc);
} else {
@ -181,7 +181,7 @@ pass1()
statemap[inumber] = USTATE;
}
free(dins[i]);
}
}
free(dins);
bmapcheck();
@ -189,31 +189,28 @@ pass1()
}
static void
checkinode(inumber, idesc)
ino_t inumber;
register struct inodesc *idesc;
checkinode(ino_t inumber, struct inodesc * idesc)
{
register struct dinode *dp;
struct zlncnt *zlnp;
int ndb, j;
mode_t mode;
char *symbuf;
struct zlncnt *zlnp;
int ndb, j;
mode_t mode;
char *symbuf;
/* dp = getnextinode(inumber); */
dp = lfs_ginode(inumber);
if(dp==NULL) {
/* pwarn("Could not find inode %ld\n",(long)inumber); */
statemap[inumber]=USTATE;
return;
}
dp = lfs_ginode(inumber);
if (dp == NULL) {
/* pwarn("Could not find inode %ld\n",(long)inumber); */
statemap[inumber] = USTATE;
return;
}
mode = dp->di_mode & IFMT;
/* XXX - LFS doesn't have this particular problem (?) */
/* XXX - LFS doesn't have this particular problem (?) */
if (mode == 0) {
if (memcmp(dp->di_db, zino.di_db, NDADDR * sizeof(daddr_t)) ||
memcmp(dp->di_ib, zino.di_ib, NIADDR * sizeof(daddr_t)) ||
memcmp(dp->di_ib, zino.di_ib, NIADDR * sizeof(daddr_t)) ||
dp->di_mode || dp->di_size) {
pwarn("mode=o%o, ifmt=o%o\n", dp->di_mode, mode);
pfatal("PARTIALLY ALLOCATED INODE I=%u", inumber);
@ -227,7 +224,7 @@ checkinode(inumber, idesc)
return;
}
lastino = inumber;
if (/* dp->di_size < 0 || */
if ( /* dp->di_size < 0 || */
dp->di_size + sblock.lfs_bsize - 1 < dp->di_size) {
if (debug)
printf("bad size %qu:", (unsigned long long)dp->di_size);
@ -236,14 +233,14 @@ checkinode(inumber, idesc)
if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
dp = ginode(inumber);
dp->di_size = sblock.lfs_fsize;
dp->di_mode = IFREG|0600;
dp->di_mode = IFREG | 0600;
inodirty();
}
ndb = howmany(dp->di_size, sblock.lfs_bsize);
if (ndb < 0) {
if (debug)
printf("bad size %qu ndb %d:",
(unsigned long long)dp->di_size, ndb);
(unsigned long long)dp->di_size, ndb);
goto unknown;
}
if (mode == IFBLK || mode == IFCHR)
@ -252,7 +249,7 @@ checkinode(inumber, idesc)
/*
* Note that the old fastlink format always had di_blocks set
* to 0. Other than that we no longer use the `spare' field
* (which is now the extended uid) for sanity checking, the
* (which is now the extended uid)for sanity checking, the
* new format is the same as the old. We simply ignore the
* conversion altogether. - mycroft, 19MAY1994
*/
@ -261,13 +258,13 @@ checkinode(inumber, idesc)
dp->di_blocks != 0) {
symbuf = alloca(secsize);
if (bread(fsreadfd, symbuf,
fsbtodb(&sblock, dp->di_db[0]),
(long)secsize) != 0)
fsbtodb(&sblock, dp->di_db[0]),
(long)secsize) != 0)
errexit("cannot read symlink");
if (debug) {
symbuf[dp->di_size] = 0;
printf("convert symlink %d(%s) of size %qd\n",
inumber, symbuf, (long long)dp->di_size);
printf("convert symlink %d(%s)of size %qd\n",
inumber, symbuf, (long long)dp->di_size);
}
dp = ginode(inumber);
memcpy(dp->di_shortlink, symbuf, (long)dp->di_size);
@ -301,7 +298,7 @@ checkinode(inumber, idesc)
if (dp->di_ib[j] != 0) {
if (debug)
printf("bad indirect addr: %d\n",
dp->di_ib[j]);
dp->di_ib[j]);
/* goto unknown; */
}
if (ftypeok(dp) == 0)
@ -329,9 +326,9 @@ checkinode(inumber, idesc)
} else
statemap[inumber] = FSTATE;
typemap[inumber] = IFTODT(mode);
#if 0 /* FFS */
#if 0 /* FFS */
if (doinglevel2 &&
(dp->di_ouid != (u_short)-1 || dp->di_ogid != (u_short)-1)) {
(dp->di_ouid != (u_short) - 1 || dp->di_ogid != (u_short) - 1)) {
dp = ginode(inumber);
dp->di_uid = dp->di_ouid;
dp->di_ouid = -1;
@ -346,7 +343,7 @@ checkinode(inumber, idesc)
idesc->id_entryno *= btodb(sblock.lfs_fsize);
if (dp->di_blocks != idesc->id_entryno) {
pwarn("INCORRECT BLOCK COUNT I=%u (%d should be %d)",
inumber, dp->di_blocks, idesc->id_entryno);
inumber, dp->di_blocks, idesc->id_entryno);
if (preen)
printf(" (CORRECTED)\n");
else if (reply("CORRECT") == 0)
@ -368,24 +365,22 @@ unknown:
}
int
pass1check(idesc)
register struct inodesc *idesc;
pass1check(struct inodesc * idesc)
{
int res = KEEPON;
int anyout, nfrags;
daddr_t blkno = idesc->id_blkno;
int res = KEEPON;
int anyout, nfrags;
daddr_t blkno = idesc->id_blkno;
register struct dups *dlp;
struct dups *new;
struct dups *new;
if (!testbmap(blkno)) {
seg_table[datosn(&sblock,blkno)].su_nbytes += idesc->id_numfrags * sblock.lfs_fsize;
seg_table[datosn(&sblock, blkno)].su_nbytes += idesc->id_numfrags * sblock.lfs_fsize;
}
if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
blkerror(idesc->id_number, "BAD", blkno);
if (badblk++ >= MAXBAD) {
pwarn("EXCESSIVE BAD BLKS I=%u",
idesc->id_number);
idesc->id_number);
if (preen)
printf(" (SKIPPING)\n");
else if (reply("CONTINUE") == 0)
@ -401,17 +396,17 @@ pass1check(idesc)
#ifndef VERBOSE_BLOCKMAP
setbmap(blkno);
#else
setbmap(blkno,idesc->id_number);
setbmap(blkno, idesc->id_number);
#endif
} else {
blkerror(idesc->id_number, "DUP", blkno);
#ifdef VERBOSE_BLOCKMAP
pwarn("(lbn %d: Holder is %d)\n", idesc->id_lblkno,
pwarn("(lbn %d: Holder is %d)\n", idesc->id_lblkno,
testbmap(blkno));
#endif
if (dupblk++ >= MAXDUP) {
pwarn("EXCESSIVE DUP BLKS I=%u",
idesc->id_number);
idesc->id_number);
if (preen)
printf(" (SKIPPING)\n");
else if (reply("CONTINUE") == 0)
@ -442,7 +437,7 @@ pass1check(idesc)
/*
* count the number of blocks found in id_entryno
*/
idesc->id_entryno ++;
idesc->id_entryno++;
}
return (res);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass2.c,v 1.3 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: pass2.c,v 1.4 2000/05/23 01:48:54 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -50,8 +50,8 @@
#define MINDIRSIZE (sizeof (struct dirtemplate))
static int pass2check __P((struct inodesc *));
static int blksort __P((const void *, const void *));
static int pass2check(struct inodesc *);
static int blksort(const void *, const void *);
void
pass2()
@ -59,9 +59,9 @@ pass2()
register struct dinode *dp;
register struct inoinfo **inpp, *inp;
struct inoinfo **inpend;
struct inodesc curino;
struct dinode dino;
char pathbuf[MAXPATHLEN + 1];
struct inodesc curino;
struct dinode dino;
char pathbuf[MAXPATHLEN + 1];
switch (statemap[ROOTINO]) {
@ -115,7 +115,7 @@ pass2()
/*
* Sort the directory list into disk block order.
*/
qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort);
qsort((char *)inpsort, (size_t) inplast, sizeof *inpsort, blksort);
/*
* Check the integrity of each directory.
*/
@ -138,7 +138,7 @@ pass2()
} else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) {
getpathname(pathbuf, inp->i_number, inp->i_number);
pwarn("DIRECTORY %s: LENGTH %lu NOT MULTIPLE OF %d",
pathbuf, (unsigned long)inp->i_isize, DIRBLKSIZ);
pathbuf, (unsigned long)inp->i_isize, DIRBLKSIZ);
if (preen)
printf(" (ADJUSTED)\n");
inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ);
@ -155,9 +155,9 @@ pass2()
curino.id_number = inp->i_number;
curino.id_parent = inp->i_parent;
#if 0
printf("checking %ld against %ld\n",
(long)dino.di_inumber,
(long)inp->i_number);
printf("checking %ld against %ld\n",
(long)dino.di_inumber,
(long)inp->i_number);
#endif
(void)ckinode(&dino, &curino);
}
@ -182,7 +182,7 @@ pass2()
continue;
}
fileerror(inp->i_parent, inp->i_number,
"BAD INODE NUMBER FOR '..'");
"BAD INODE NUMBER FOR '..'");
if (reply("FIX") == 0)
continue;
lncntp[inp->i_dotdot]++;
@ -197,17 +197,16 @@ pass2()
}
static int
pass2check(idesc)
struct inodesc *idesc;
pass2check(struct inodesc * idesc)
{
register struct direct *dirp = idesc->id_dirp;
register struct inoinfo *inp;
int n, entrysize, ret = 0;
struct dinode *dp;
char *errmsg;
struct direct proto;
char namebuf[MAXPATHLEN + 1];
char pathbuf[MAXPATHLEN + 1];
int n, entrysize, ret = 0;
struct dinode *dp;
char *errmsg;
struct direct proto;
char namebuf[MAXPATHLEN + 1];
char pathbuf[MAXPATHLEN + 1];
/*
* If converting, set directory entry type.
@ -216,7 +215,7 @@ pass2check(idesc)
dirp->d_type = typemap[dirp->d_ino];
ret |= ALTERED;
}
/*
/*
* check for "."
*/
if (idesc->id_entryno != 0)
@ -246,7 +245,7 @@ pass2check(idesc)
(void)strcpy(proto.d_name, ".");
# if BYTE_ORDER == LITTLE_ENDIAN
if (!newinofmt) {
u_char tmp;
u_char tmp;
tmp = proto.d_type;
proto.d_type = proto.d_namlen;
@ -256,7 +255,7 @@ pass2check(idesc)
entrysize = DIRSIZ(0, &proto, 0);
if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
dirp->d_name);
dirp->d_name);
} else if (dirp->d_reclen < entrysize) {
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
} else if (dirp->d_reclen < 2 * entrysize) {
@ -289,7 +288,7 @@ chk1:
(void)strcpy(proto.d_name, "..");
# if BYTE_ORDER == LITTLE_ENDIAN
if (!newinofmt) {
u_char tmp;
u_char tmp;
tmp = proto.d_type;
proto.d_type = proto.d_namlen;
@ -322,7 +321,7 @@ chk1:
if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
dirp->d_name);
dirp->d_name);
inp->i_dotdot = (ino_t)-1;
} else if (dirp->d_reclen < entrysize) {
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
@ -342,10 +341,10 @@ chk1:
idesc->id_entryno++;
if (dirp->d_ino != 0)
lncntp[dirp->d_ino]--;
return (ret|KEEPON);
return (ret | KEEPON);
chk2:
if (dirp->d_ino == 0)
return (ret|KEEPON);
return (ret | KEEPON);
if (dirp->d_namlen <= 2 &&
dirp->d_name[0] == '.' &&
idesc->id_entryno >= 2) {
@ -369,18 +368,18 @@ chk2:
if (dirp->d_ino > maxino) {
fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE");
n = reply("REMOVE");
} else if(dirp->d_ino == LFS_IFILE_INUM
&& idesc->id_number==ROOTINO) {
if(dirp->d_type != DT_REG) {
fileerror(idesc->id_number, dirp->d_ino,
"BAD TYPE FOR IFILE");
dirp->d_type = DT_REG;
if(reply("FIX") == 1)
ret |= ALTERED;
}
} else if (dirp->d_ino == LFS_IFILE_INUM &&
idesc->id_number == ROOTINO) {
if (dirp->d_type != DT_REG) {
fileerror(idesc->id_number, dirp->d_ino,
"BAD TYPE FOR IFILE");
dirp->d_type = DT_REG;
if (reply("FIX") == 1)
ret |= ALTERED;
}
} else if (newinofmt &&
((dirp->d_ino == WINO && (dirp->d_type != DT_WHT))
|| (dirp->d_ino != WINO && dirp->d_type == DT_WHT))) {
((dirp->d_ino == WINO && (dirp->d_type != DT_WHT)) ||
(dirp->d_ino != WINO && dirp->d_type == DT_WHT))) {
fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY");
dirp->d_ino = WINO;
dirp->d_type = DT_WHT;
@ -413,7 +412,7 @@ again:
break;
dp = ginode(dirp->d_ino);
statemap[dirp->d_ino] =
(dp->di_mode & IFMT) == IFDIR ? DSTATE : FSTATE;
(dp->di_mode & IFMT) == IFDIR ? DSTATE : FSTATE;
lncntp[dirp->d_ino] = dp->di_nlink;
goto again;
@ -422,11 +421,11 @@ again:
inp = getinoinfo(dirp->d_ino);
if (inp->i_parent != 0 && idesc->id_entryno > 2) {
getpathname(pathbuf, idesc->id_number,
idesc->id_number);
idesc->id_number);
getpathname(namebuf, dirp->d_ino, dirp->d_ino);
pwarn("%s %s %s\n", pathbuf,
"IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
namebuf);
"IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
namebuf);
if (preen)
printf(" (IGNORED)\n");
else if ((n = reply("REMOVE")) == 1)
@ -439,7 +438,7 @@ again:
case FSTATE:
if (newinofmt && dirp->d_type != typemap[dirp->d_ino]) {
fileerror(idesc->id_number, dirp->d_ino,
"BAD TYPE VALUE");
"BAD TYPE VALUE");
dirp->d_type = typemap[dirp->d_ino];
if (reply("FIX") == 1)
ret |= ALTERED;
@ -448,23 +447,22 @@ again:
break;
default:
/* errexit */pwarn("BAD STATE %d FOR INODE I=%d",
statemap[dirp->d_ino], dirp->d_ino);
/* errexit */ pwarn("BAD STATE %d FOR INODE I=%d",
statemap[dirp->d_ino], dirp->d_ino);
}
}
if (n == 0)
return (ret|KEEPON);
return (ret | KEEPON);
dirp->d_ino = 0;
return (ret|KEEPON|ALTERED);
return (ret | KEEPON | ALTERED);
}
/*
* Routine to sort disk blocks.
*/
static int
blksort(inpp1, inpp2)
const void *inpp1, *inpp2;
blksort(const void *inpp1, const void *inpp2)
{
return ((* (struct inoinfo **) inpp1)->i_blks[0] -
(* (struct inoinfo **) inpp2)->i_blks[0]);
return ((*(struct inoinfo **)inpp1)->i_blks[0] -
(*(struct inoinfo **)inpp2)->i_blks[0]);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass3.c,v 1.2 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: pass3.c,v 1.3 2000/05/23 01:48:54 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -45,17 +45,17 @@ void
pass3()
{
register struct inoinfo **inpp, *inp;
ino_t orphan;
int loopcnt;
ino_t orphan;
int loopcnt;
for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
inp = *inpp;
if (inp->i_number == ROOTINO ||
!(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
!(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
continue;
if (statemap[inp->i_number] == DCLEAR)
continue;
for (loopcnt = 0; ; loopcnt++) {
for (loopcnt = 0;; loopcnt++) {
orphan = inp->i_number;
if (inp->i_parent == 0 ||
statemap[inp->i_parent] != DSTATE ||

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass4.c,v 1.2 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: pass4.c,v 1.3 2000/05/23 01:48:55 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -48,11 +48,11 @@
void
pass4()
{
register ino_t inumber;
register ino_t inumber;
register struct zlncnt *zlnp;
struct dinode *dp;
struct inodesc idesc;
int n;
struct dinode *dp;
struct inodesc idesc;
int n;
memset(&idesc, 0, sizeof(struct inodesc));
idesc.id_type = ADDR;
@ -99,18 +99,17 @@ pass4()
default:
errexit("BAD STATE %d FOR INODE I=%d",
statemap[inumber], inumber);
statemap[inumber], inumber);
}
}
}
int
pass4check(idesc)
register struct inodesc *idesc;
pass4check(struct inodesc * idesc)
{
register struct dups *dlp;
int nfrags, res = KEEPON;
daddr_t blkno = idesc->id_blkno;
int nfrags, res = KEEPON;
daddr_t blkno = idesc->id_blkno;
for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
if (chkrange(blkno, 1)) {

View File

@ -1,4 +1,40 @@
/* $NetBSD: pass5.c,v 1.3 2000/05/16 04:55:59 perseant Exp $ */
/* $NetBSD: pass5.c,v 1.4 2000/05/23 01:48:55 perseant Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Konrad E. Schroder <perseant@hhhh.org>.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/time.h>
@ -12,37 +48,35 @@
#include "extern.h"
#include "fsutil.h"
extern SEGUSE *seg_table;
extern SEGUSE *seg_table;
void
pass5()
{
SEGUSE *su;
SEGUSE *su;
struct bufarea *bp;
int i;
int i;
/*
* Check segment holdings against actual holdings. Check for
* "clean" segments that contain live data.
*/
for(i=0; i < sblock.lfs_nseg; i++) {
for (i = 0; i < sblock.lfs_nseg; i++) {
su = lfs_gseguse(i, &bp);
if (!(su->su_flags & SEGUSE_DIRTY) &&
seg_table[i].su_nbytes>0)
{
seg_table[i].su_nbytes > 0) {
pwarn("%d bytes contained in 'clean' segment %d\n",
seg_table[i].su_nbytes, i);
if(preen || reply("fix")) {
if (preen || reply("fix")) {
su->su_flags |= SEGUSE_DIRTY;
dirty(bp);
}
}
if ((su->su_flags & SEGUSE_DIRTY) &&
su->su_nbytes != seg_table[i].su_nbytes)
{
su->su_nbytes != seg_table[i].su_nbytes) {
pwarn("segment %d claims %d bytes but has %d\n",
i, su->su_nbytes, seg_table[i].su_nbytes);
if(preen || reply("fix")) {
if (preen || reply("fix")) {
su->su_nbytes = seg_table[i].su_nbytes;
dirty(bp);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: setup.c,v 1.4 2000/05/16 04:55:59 perseant Exp $ */
/* $NetBSD: setup.c,v 1.5 2000/05/23 01:48:55 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -43,7 +43,8 @@
#include <sys/file.h>
#include <ufs/ufs/dinode.h>
#include <sys/mount.h> /* XXX ufs/lfs/lfs.h should include this for us */
#include <sys/mount.h> /* XXX ufs/lfs/lfs.h should include this for
* us */
#include <ufs/lfs/lfs.h>
#include <ufs/lfs/lfs_extern.h>
@ -58,45 +59,45 @@
#include "extern.h"
#include "fsutil.h"
struct bufarea asblk;
daddr_t *din_table;
SEGUSE *seg_table;
struct bufarea asblk;
daddr_t *din_table;
SEGUSE *seg_table;
#define altsblock (*asblk.b_un.b_fs)
#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
void badsb __P((int, char *));
int calcsb __P((const char *, int, struct lfs *));
static struct disklabel *getdisklabel __P((const char *, int));
static int readsb __P((int));
int lfs_maxino(void);
void badsb(int, char *);
int calcsb(const char *, int, struct lfs *);
static struct disklabel *getdisklabel(const char *, int);
static int readsb(int);
int lfs_maxino(void);
static daddr_t try_verify(struct lfs *, struct lfs *);
static daddr_t try_verify(struct lfs *, struct lfs *);
#ifdef DKTYPENAMES
int useless __P((void));
int useless(void);
int
useless(void)
{
char **foo = (char **)dktypenames;
char **bar = (char **)fscknames;
char **foo = (char **)dktypenames;
char **bar = (char **)fscknames;
return foo-bar;
return foo - bar;
}
#endif
static daddr_t
try_verify(struct lfs *osb, struct lfs *nsb)
static daddr_t
try_verify(struct lfs * osb, struct lfs * nsb)
{
daddr_t daddr;
SEGSUM *sp;
char summary[LFS_SUMMARY_SIZE];
int bc, flag;
daddr_t daddr;
SEGSUM *sp;
char summary[LFS_SUMMARY_SIZE];
int bc, flag;
daddr = osb->lfs_offset;
while(daddr != nsb->lfs_offset) {
while (daddr != nsb->lfs_offset) {
flag = 0;
oncemore:
oncemore:
/* Read in summary block */
bread(fsreadfd, summary, daddr, LFS_SUMMARY_SIZE);
sp = (SEGSUM *)summary;
@ -106,21 +107,20 @@ try_verify(struct lfs *osb, struct lfs *nsb)
* XXX should use gseguse, but right now we need to do more
* setup before we can...fix this
*/
if(sp->ss_magic != SS_MAGIC ||
sp->ss_sumsum != cksum(&sp->ss_datasum, LFS_SUMMARY_SIZE -
sizeof(sp->ss_sumsum)))
{
if(flag==0) {
daddr += LFS_SBPAD/dev_bsize;
if (sp->ss_magic != SS_MAGIC ||
sp->ss_sumsum != cksum(&sp->ss_datasum, LFS_SUMMARY_SIZE -
sizeof(sp->ss_sumsum))) {
if (flag == 0) {
daddr += LFS_SBPAD / dev_bsize;
goto oncemore;
}
return 0x0;
}
bc = check_summary(osb, sp, daddr);
if(bc==0)
if (bc == 0)
break;
daddr += (LFS_SUMMARY_SIZE + bc) / dev_bsize;
if(datosn(osb,daddr) != datosn(osb, daddr + (LFS_SUMMARY_SIZE+(1<<osb->lfs_bshift))/dev_bsize)) {
if (datosn(osb, daddr) != datosn(osb, daddr + (LFS_SUMMARY_SIZE + (1 << osb->lfs_bshift)) / dev_bsize)) {
daddr = ((SEGSUM *)summary)->ss_next;
}
}
@ -128,22 +128,21 @@ try_verify(struct lfs *osb, struct lfs *nsb)
}
int
setup(dev)
const char *dev;
setup(const char *dev)
{
long bmapsize;
long bmapsize;
struct disklabel *lp;
#if 0
long i;
off_t sizepb;
long i;
off_t sizepb;
#endif
struct stat statb;
daddr_t daddr;
struct lfs proto;
int doskipclean;
u_int64_t maxfilesize;
struct lfs *sb0, *sb1, *osb, *nsb;
struct dinode *idinode;
struct stat statb;
daddr_t daddr;
struct lfs proto;
int doskipclean;
u_int64_t maxfilesize;
struct lfs *sb0, *sb1, *osb, *nsb;
struct dinode *idinode;
havesb = 0;
fswritefd = -1;
@ -179,7 +178,7 @@ setup(dev)
asblk.b_un.b_buf = malloc(LFS_SBPAD);
if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
errexit("cannot allocate space for superblock\n");
if ((lp = getdisklabel((char *)NULL, fsreadfd)) != NULL)
if ((lp = getdisklabel((char *) NULL, fsreadfd)) != NULL)
dev_bsize = secsize = lp->d_secsize;
else
dev_bsize = secsize = DEV_BSIZE;
@ -189,10 +188,10 @@ setup(dev)
*/
if (readsb(1) == 0) {
if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
return(0);
return (0);
if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
return (0);
#if 0 /* XXX find the LFS way to do this */
#if 0 /* XXX find the LFS way to do this */
for (cg = 0; cg < proto.lfs_ncg; cg++) {
bflag = fsbtodb(&proto, cgsblock(&proto, cg));
if (readsb(0) != 0)
@ -200,25 +199,24 @@ setup(dev)
}
if (cg >= proto.lfs_ncg) {
printf("%s %s\n%s %s\n%s %s\n",
"SEARCH FOR ALTERNATE SUPER-BLOCK",
"FAILED. YOU MUST USE THE",
"-b OPTION TO FSCK_FFS TO SPECIFY THE",
"LOCATION OF AN ALTERNATE",
"SUPER-BLOCK TO SUPPLY NEEDED",
"INFORMATION; SEE fsck_ffs(8).");
return(0);
"SEARCH FOR ALTERNATE SUPER-BLOCK",
"FAILED. YOU MUST USE THE",
"-b OPTION TO FSCK_FFS TO SPECIFY THE",
"LOCATION OF AN ALTERNATE",
"SUPER-BLOCK TO SUPPLY NEEDED",
"INFORMATION; SEE fsck_ffs(8).");
return (0);
}
#else
pwarn("XXX Can't look for alternate superblocks yet\n");
return(0);
return (0);
#endif
doskipclean = 0;
pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
}
bufinit();
if(bflag==0) {
if (bflag == 0) {
/*
* Even if that superblock read in properly, it may not
* be guaranteed to point to a complete checkpoint.
@ -227,27 +225,27 @@ setup(dev)
*/
sb0 = malloc(sizeof(*sb0));
sb1 = malloc(sizeof(*sb1));
memcpy(sb0,&sblock,sizeof(*sb0));
memcpy(sb0, &sblock, sizeof(*sb0));
bflag = sblock.lfs_sboffs[1];
if(readsb(1)==0) {
pwarn("COULDN'T READ ALT SUPERBLOCK AT BLK %d",bflag);
if (readsb(1) == 0) {
pwarn("COULDN'T READ ALT SUPERBLOCK AT BLK %d", bflag);
if (reply("ASSUME PRIMARY SUPERBLOCK IS GOOD") == 0) {
return (0);
} else { /* use primary as good */
memcpy(&sblock,sb0,sizeof(*sb0)); /* XXX cheating? */
} else {/* use primary as good */
memcpy(&sblock, sb0, sizeof(*sb0)); /* XXX cheating? */
}
} else {
memcpy(sb1,&sblock,sizeof(*sb1));
if(debug)
pwarn("sb0 %d, sb1 %d\n",sb0->lfs_tstamp,sblock.lfs_tstamp);
memcpy(sb1, &sblock, sizeof(*sb1));
if (debug)
pwarn("sb0 %d, sb1 %d\n", sb0->lfs_tstamp, sblock.lfs_tstamp);
/*
* Verify the checkpoint of the newer superblock,
* if the timestamp of the two superblocks is
* different. XXX use lfs_offset instead, discover
* how to quickly discover "newness" based on that.
*/
if(sb0->lfs_tstamp != sb1->lfs_tstamp) {
if(sb0->lfs_tstamp > sb1->lfs_tstamp) {
if (sb0->lfs_tstamp != sb1->lfs_tstamp) {
if (sb0->lfs_tstamp > sb1->lfs_tstamp) {
osb = sb1;
nsb = sb0;
} else {
@ -260,32 +258,32 @@ setup(dev)
printf("done.\n");
if (daddr == nsb->lfs_offset) {
pwarn("Checkpoint verified, recovered %d seconds of data\n", nsb->lfs_tstamp - osb->lfs_tstamp);
memcpy(&sblock,nsb,sizeof(*nsb));
memcpy(&sblock, nsb, sizeof(*nsb));
sbdirty();
} else {
pwarn("Checkpoint invalid, lost %d seconds of data\n", nsb->lfs_tstamp - osb->lfs_tstamp);
memcpy(&sblock,osb,sizeof(*osb));
memcpy(&sblock, osb, sizeof(*osb));
}
}
}
free(sb0);
free(sb1);
}
if(debug) {
printf("dev_bsize = %lu\n",dev_bsize);
printf("lfs_bsize = %lu\n",(unsigned long)sblock.lfs_bsize);
printf("lfs_fsize = %lu\n",(unsigned long)sblock.lfs_fsize);
printf("lfs_frag = %lu\n",(unsigned long)sblock.lfs_frag);
printf("INOPB(fs) = %lu\n",(unsigned long)INOPB(&sblock));
/* printf("fsbtodb(fs,1) = %lu\n",fsbtodb(&sblock,1)); */
if (debug) {
printf("dev_bsize = %lu\n", dev_bsize);
printf("lfs_bsize = %lu\n", (unsigned long)sblock.lfs_bsize);
printf("lfs_fsize = %lu\n", (unsigned long)sblock.lfs_fsize);
printf("lfs_frag = %lu\n", (unsigned long)sblock.lfs_frag);
printf("INOPB(fs) = %lu\n", (unsigned long) INOPB(&sblock));
/* printf("fsbtodb(fs,1) = %lu\n",fsbtodb(&sblock,1)); */
}
#if 0 /* FFS-specific fs-clean check */
#if 0 /* FFS-specific fs-clean check */
if (debug)
printf("clean = %d\n", sblock.lfs_clean);
if (sblock.lfs_clean & FS_ISCLEAN) {
if (doskipclean) {
pwarn("%sile system is clean; not checking\n",
preen ? "f" : "** F");
preen ? "f" : "** F");
return (-1);
}
if (!preen)
@ -294,29 +292,28 @@ setup(dev)
maxino = sblock.lfs_ncg * sblock.lfs_ipg;
#else
#if 0
/* XXX - count the number of inodes here */
maxino = sblock.lfs_nfiles+2;
/* XXX - count the number of inodes here */
maxino = sblock.lfs_nfiles + 2;
#else
initbarea(&iblk);
iblk.b_un.b_buf = malloc(sblock.lfs_bsize);
if(bread(fsreadfd, (char *)iblk.b_un.b_buf,
sblock.lfs_idaddr,
(long)sblock.lfs_bsize) != 0)
{
printf("Couldn't read disk block %d\n",sblock.lfs_idaddr);
exit(1);
}
idinode = lfs_difind(&sblock,sblock.lfs_ifile,&ifblock);
initbarea(&iblk);
iblk.b_un.b_buf = malloc(sblock.lfs_bsize);
if (bread(fsreadfd, (char *)iblk.b_un.b_buf,
sblock.lfs_idaddr,
(long)sblock.lfs_bsize) != 0) {
printf("Couldn't read disk block %d\n", sblock.lfs_idaddr);
exit(1);
}
idinode = lfs_difind(&sblock, sblock.lfs_ifile, &ifblock);
maxino = ((idinode->di_size
- (sblock.lfs_cleansz + sblock.lfs_segtabsz) * sblock.lfs_bsize)
/ sblock.lfs_bsize) * sblock.lfs_ifpb - 1;
- (sblock.lfs_cleansz + sblock.lfs_segtabsz) * sblock.lfs_bsize)
/ sblock.lfs_bsize) * sblock.lfs_ifpb - 1;
#endif
if (debug)
printf("maxino=%d\n",maxino);
din_table = (daddr_t *)malloc(maxino*sizeof(*din_table));
memset(din_table,0,maxino*sizeof(*din_table));
seg_table = (SEGUSE *)malloc(sblock.lfs_nseg * sizeof(SEGUSE));
memset(seg_table,0,sblock.lfs_nseg * sizeof(SEGUSE));
printf("maxino=%d\n", maxino);
din_table = (daddr_t *)malloc(maxino * sizeof(*din_table));
memset(din_table, 0, maxino * sizeof(*din_table));
seg_table = (SEGUSE *)malloc(sblock.lfs_nseg * sizeof(SEGUSE));
memset(seg_table, 0, sblock.lfs_nseg * sizeof(SEGUSE));
#endif
maxfsblock = sblock.lfs_size * (sblock.lfs_bsize / dev_bsize);
#if 0
@ -326,43 +323,43 @@ setup(dev)
sizepb *= NINDIR(&sblock);
maxfilesize += sizepb;
}
maxfilesize++; /* XXX */
#else /* LFS way */
{
u_quad_t maxtable[] = {
/* 1 */ -1,
/* 2 */ -1,
/* 4 */ -1,
/* 8 */ -1,
/* 16 */ -1,
/* 32 */ -1,
/* 64 */ -1,
/* 128 */ -1,
/* 256 */ -1,
/* 512 */ NDADDR + 128 + 128 * 128 + 128 * 128 * 128,
/* 1024 */ NDADDR + 256 + 256 * 256 + 256 * 256 * 256,
/* 2048 */ NDADDR + 512 + 512 * 512 + 512 * 512 * 512,
/* 4096 */ NDADDR + 1024 + 1024 * 1024 + 1024 * 1024 * 1024,
/* 8192 */ 1 << 31,
/* 16 K */ 1 << 31,
/* 32 K */ 1 << 31,
};
maxfilesize = maxtable[sblock.lfs_bshift] << sblock.lfs_bshift;
}
maxfilesize++; /* XXX */
#else /* LFS way */
{
u_quad_t maxtable[] = {
/* 1 */ -1,
/* 2 */ -1,
/* 4 */ -1,
/* 8 */ -1,
/* 16 */ -1,
/* 32 */ -1,
/* 64 */ -1,
/* 128 */ -1,
/* 256 */ -1,
/* 512 */ NDADDR + 128 + 128 * 128 + 128 * 128 * 128,
/* 1024 */ NDADDR + 256 + 256 * 256 + 256 * 256 * 256,
/* 2048 */ NDADDR + 512 + 512 * 512 + 512 * 512 * 512,
/* 4096 */ NDADDR + 1024 + 1024 * 1024 + 1024 * 1024 * 1024,
/* 8192 */ 1 << 31,
/* 16 K */ 1 << 31,
/* 32 K */ 1 << 31,
};
maxfilesize = maxtable[sblock.lfs_bshift] << sblock.lfs_bshift;
}
#endif
if ((sblock.lfs_minfree < 0 || sblock.lfs_minfree > 99)) {
pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK",
sblock.lfs_minfree);
sblock.lfs_minfree);
if (reply("SET TO DEFAULT") == 1) {
sblock.lfs_minfree = 10;
sbdirty();
}
}
/* XXX used to be ~(sblock.lfs_bsize - 1) */
/* XXX used to be ~(sblock.lfs_bsize - 1) */
if (sblock.lfs_bmask != sblock.lfs_bsize - 1) {
pwarn("INCORRECT BMASK=%x IN SUPERBLOCK (should be %x)",
(unsigned int)sblock.lfs_bmask,
(unsigned int)sblock.lfs_bsize - 1);
(unsigned int)sblock.lfs_bmask,
(unsigned int)sblock.lfs_bsize - 1);
sblock.lfs_bmask = sblock.lfs_bsize - 1;
if (preen)
printf(" (FIXED)\n");
@ -371,10 +368,10 @@ u_quad_t maxtable[] = {
dirty(&asblk);
}
}
#if 0 /* FFS-specific checks */
#if 0 /* FFS-specific checks */
if (sblock.lfs_fmask != ~(sblock.lfs_fsize - 1)) {
pwarn("INCORRECT FMASK=%x IN SUPERBLOCK",
sblock.lfs_fmask);
sblock.lfs_fmask);
sblock.lfs_fmask = ~(sblock.lfs_fsize - 1);
if (preen)
printf(" (FIXED)\n");
@ -384,63 +381,63 @@ u_quad_t maxtable[] = {
}
}
#endif
if (sblock.lfs_maxfilesize != maxfilesize) {
pwarn("INCORRECT MAXFILESIZE=%qu IN SUPERBLOCK (should be %qu)",
(unsigned long long)sblock.lfs_maxfilesize,
(unsigned long long)maxfilesize);
sblock.lfs_maxfilesize = maxfilesize;
if (preen)
printf(" (FIXED)\n");
if (preen || reply("FIX") == 1) {
sbdirty();
dirty(&asblk);
}
if (sblock.lfs_maxfilesize != maxfilesize) {
pwarn("INCORRECT MAXFILESIZE=%qu IN SUPERBLOCK (should be %qu)",
(unsigned long long)sblock.lfs_maxfilesize,
(unsigned long long)maxfilesize);
sblock.lfs_maxfilesize = maxfilesize;
if (preen)
printf(" (FIXED)\n");
if (preen || reply("FIX") == 1) {
sbdirty();
dirty(&asblk);
}
if (sblock.lfs_maxsymlinklen != MAXSYMLINKLEN) {
pwarn("INCORRECT MAXSYMLINKLEN=%d IN SUPERBLOCK",
sblock.lfs_maxsymlinklen);
sblock.lfs_maxsymlinklen = MAXSYMLINKLEN;
if (preen)
printf(" (FIXED)\n");
if (preen || reply("FIX") == 1) {
sbdirty();
dirty(&asblk);
}
}
if (sblock.lfs_maxsymlinklen != MAXSYMLINKLEN) {
pwarn("INCORRECT MAXSYMLINKLEN=%d IN SUPERBLOCK",
sblock.lfs_maxsymlinklen);
sblock.lfs_maxsymlinklen = MAXSYMLINKLEN;
if (preen)
printf(" (FIXED)\n");
if (preen || reply("FIX") == 1) {
sbdirty();
dirty(&asblk);
}
newinofmt = 1;
}
newinofmt = 1;
/*
* allocate and initialize the necessary maps
*/
#ifndef VERBOSE_BLOCKMAP
bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
blockmap = malloc((unsigned)bmapsize * sizeof (char));
bzero(blockmap, bmapsize * sizeof(char));
blockmap = malloc((unsigned)bmapsize * sizeof(char));
bzero(blockmap, bmapsize * sizeof(char));
#else
bmapsize = maxfsblock*sizeof(ino_t);
blockmap = (ino_t *)malloc(maxfsblock * sizeof (ino_t));
bzero(blockmap, maxfsblock * sizeof(ino_t));
bmapsize = maxfsblock * sizeof(ino_t);
blockmap = (ino_t *)malloc(maxfsblock * sizeof(ino_t));
bzero(blockmap, maxfsblock * sizeof(ino_t));
#endif
if (blockmap == NULL) {
printf("cannot alloc %u bytes for blockmap\n",
(unsigned)bmapsize);
(unsigned)bmapsize);
goto badsblabel;
}
statemap = calloc((unsigned)(maxino + 1), sizeof(char));
if (statemap == NULL) {
printf("cannot alloc %u bytes for statemap\n",
(unsigned)(maxino + 1));
(unsigned)(maxino + 1));
goto badsblabel;
}
typemap = calloc((unsigned)(maxino + 1), sizeof(char));
if (typemap == NULL) {
printf("cannot alloc %u bytes for typemap\n",
(unsigned)(maxino + 1));
(unsigned)(maxino + 1));
goto badsblabel;
}
lncntp = (int16_t *)calloc((unsigned)(maxino + 1), sizeof(int16_t));
if (lncntp == NULL) {
printf("cannot alloc %lu bytes for lncntp\n",
(unsigned long)(maxino + 1) * sizeof(int16_t));
printf("cannot alloc %lu bytes for lncntp\n",
(unsigned long)(maxino + 1) * sizeof(int16_t));
goto badsblabel;
}
return (1);
@ -454,13 +451,12 @@ badsblabel:
* Read in the LFS super block and its summary info.
*/
static int
readsb(listerr)
int listerr;
readsb(int listerr)
{
daddr_t super = bflag ? bflag : LFS_LABELPAD / dev_bsize;
u_int32_t checksum;
daddr_t super = bflag ? bflag : LFS_LABELPAD / dev_bsize;
u_int32_t checksum;
if (bread(fsreadfd, (char *)&sblock, super, (long)LFS_SBPAD) != 0)
if (bread(fsreadfd, (char *) &sblock, super, (long) LFS_SBPAD) != 0)
return (0);
sblk.b_bno = super;
@ -468,27 +464,35 @@ readsb(listerr)
/*
* run a few consistency checks of the super block
*/
if (sblock.lfs_magic != LFS_MAGIC)
{ badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
/* checksum */
checksum = lfs_sb_cksum(&(sblock.lfs_dlfs));
if(sblock.lfs_cksum != checksum)
{
printf("Superblock checksum (%lu) does not match computed checksum %lu\n",
(unsigned long)sblock.lfs_cksum, (unsigned long)checksum);
}
#if 0 /* XXX - replace these checks with appropriate LFS sanity checks */
if (sblock.lfs_ncg < 1)
{ badsb(listerr, "NCG OUT OF RANGE"); return (0); }
if (sblock.lfs_cpg < 1)
{ badsb(listerr, "CPG OUT OF RANGE"); return (0); }
if (sblock.lfs_magic != LFS_MAGIC) {
badsb(listerr, "MAGIC NUMBER WRONG");
return (0);
}
/* checksum */
checksum = lfs_sb_cksum(&(sblock.lfs_dlfs));
if (sblock.lfs_cksum != checksum) {
printf("Superblock checksum (%lu)does not match computed checksum %lu\n",
(unsigned long)sblock.lfs_cksum, (unsigned long) checksum);
}
#if 0 /* XXX - replace these checks with
* appropriate LFS sanity checks */
if (sblock.lfs_ncg < 1) {
badsb(listerr, "NCG OUT OF RANGE");
return (0);
}
if (sblock.lfs_cpg < 1) {
badsb(listerr, "CPG OUT OF RANGE");
return (0);
}
if (sblock.lfs_ncg * sblock.lfs_cpg < sblock.lfs_ncyl ||
(sblock.lfs_ncg - 1) * sblock.lfs_cpg >= sblock.lfs_ncyl)
{ badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
if (sblock.lfs_sbsize > SBSIZE)
{ badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
(sblock.lfs_ncg - 1) * sblock.lfs_cpg >= sblock.lfs_ncyl) {
badsb(listerr, "NCYL LESS THAN NCG*CPG");
return (0);
}
if (sblock.lfs_sbsize > SBSIZE) {
badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
return (0);
}
#endif
/*
* Compute block size that the filesystem is based on,
@ -504,7 +508,8 @@ readsb(listerr)
havesb = 1;
return (1);
}
#if 0 /* XXX - for now skip the alt. superblock test as well */
#if 0 /* XXX - for now skip the alt. superblock
* test as well */
/*
* Set all possible fields that could differ, then do check
* of whole super block against an alternate super block.
@ -528,12 +533,12 @@ readsb(listerr)
altsblock.lfs_rotdelay = sblock.lfs_rotdelay;
altsblock.lfs_maxbpg = sblock.lfs_maxbpg;
memcpy(altsblock.lfs_csp, sblock.lfs_csp,
sizeof sblock.lfs_csp);
sizeof sblock.lfs_csp);
altsblock.lfs_maxcluster = sblock.lfs_maxcluster;
memcpy(altsblock.lfs_fsmnt, sblock.lfs_fsmnt,
sizeof sblock.lfs_fsmnt);
sizeof sblock.lfs_fsmnt);
memcpy(altsblock.lfs_sparecon, sblock.lfs_sparecon,
sizeof sblock.lfs_sparecon);
sizeof sblock.lfs_sparecon);
/*
* The following should not have to be copied.
*/
@ -548,21 +553,21 @@ readsb(listerr)
altsblock.lfs_maxfilesize = sblock.lfs_maxfilesize;
if (memcmp(&sblock, &altsblock, (int)sblock.lfs_sbsize)) {
if (debug) {
long *nlp, *olp, *endlp;
long *nlp, *olp, *endlp;
printf("superblock mismatches\n");
nlp = (long *)&altsblock;
olp = (long *)&sblock;
nlp = (long *) &altsblock;
olp = (long *) &sblock;
endlp = olp + (sblock.lfs_sbsize / sizeof *olp);
for ( ; olp < endlp; olp++, nlp++) {
for (; olp < endlp; olp++, nlp++) {
if (*olp == *nlp)
continue;
printf("offset %d, original %ld, alternate %ld\n",
olp - (long *)&sblock, *olp, *nlp);
olp - (long *) &sblock, *olp, *nlp);
}
}
badsb(listerr,
"VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
"VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
return (0);
}
#endif
@ -571,9 +576,7 @@ readsb(listerr)
}
void
badsb(listerr, s)
int listerr;
char *s;
badsb(int listerr, char *s)
{
if (!listerr)
@ -590,23 +593,20 @@ badsb(listerr, s)
* their needed information is available!
*/
int
calcsb(dev, devfd, fs)
const char *dev;
int devfd;
register struct lfs *fs;
calcsb(const char *dev, int devfd, struct lfs * fs)
{
register struct disklabel *lp;
register struct partition *pp;
register char *cp;
int i;
register char *cp;
int i;
cp = strchr(dev, '\0') - 1;
if ((cp == (char *)-1 || (*cp < 'a' || *cp > 'h')) && !isdigit(*cp)) {
if ((cp == (char *) -1 || (*cp < 'a' || *cp > 'h')) && !isdigit(*cp)) {
pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
return (0);
}
lp = getdisklabel(dev, devfd);
if(lp==NULL) {
if (lp == NULL) {
dev_bsize = DEV_BSIZE;
} else {
if (isdigit(*cp))
@ -615,8 +615,8 @@ calcsb(dev, devfd, fs)
pp = &lp->d_partitions[*cp - 'a'];
if (pp->p_fstype != FS_BSDLFS) {
pfatal("%s: NOT LABELED AS AN LFS FILE SYSTEM (%s)\n",
dev, pp->p_fstype < FSMAXTYPES ?
fstypenames[pp->p_fstype] : "unknown");
dev, pp->p_fstype < FSMAXTYPES ?
fstypenames[pp->p_fstype] : "unknown");
return (0);
}
memset(fs, 0, sizeof(struct lfs));
@ -632,15 +632,13 @@ calcsb(dev, devfd, fs)
}
static struct disklabel *
getdisklabel(s, fd)
const char *s;
int fd;
getdisklabel(const char *s, int fd)
{
static struct disklabel lab;
if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
if (ioctl(fd, DIOCGDINFO, (char *) &lab) < 0) {
if (s == NULL)
return ((struct disklabel *)NULL);
return ((struct disklabel *) NULL);
pwarn("ioctl (GCINFO): %s\n", strerror(errno));
#if 0
errexit("%s: can't read disk label\n", s);

View File

@ -1,4 +1,4 @@
/* $NetBSD: utilities.c,v 1.3 2000/05/16 04:56:00 perseant Exp $ */
/* $NetBSD: utilities.c,v 1.4 2000/05/23 01:48:55 perseant Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -51,23 +51,22 @@
#include "fsck.h"
#include "extern.h"
long diskreads, totalreads; /* Disk cache statistics */
long diskreads, totalreads; /* Disk cache statistics */
static void rwerror __P((char *, daddr_t));
static void rwerror(char *, daddr_t);
int
ftypeok(dp)
struct dinode *dp;
ftypeok(struct dinode * dp)
{
switch (dp->di_mode & IFMT) {
case IFDIR:
case IFREG:
case IFBLK:
case IFCHR:
case IFLNK:
case IFSOCK:
case IFIFO:
case IFDIR:
case IFREG:
case IFBLK:
case IFCHR:
case IFLNK:
case IFSOCK:
case IFIFO:
return (1);
default:
@ -78,11 +77,10 @@ ftypeok(dp)
}
int
reply(question)
char *question;
reply(char *question)
{
int persevere;
char c;
int persevere;
char c;
if (preen)
pfatal("INTERNAL ERROR: GOT TO reply()");
@ -96,9 +94,9 @@ reply(question)
printf("%s? yes\n\n", question);
return (1);
}
do {
do {
printf("%s? [yn] ", question);
(void) fflush(stdout);
(void)fflush(stdout);
c = getc(stdin);
while (c != '\n' && getc(stdin) != '\n')
if (feof(stdin))
@ -117,8 +115,8 @@ void
bufinit()
{
register struct bufarea *bp;
long bufcnt, i;
char *bufp;
long bufcnt, i;
char *bufp;
pbp = pdirbp = (struct bufarea *)0;
bufp = malloc((unsigned int)sblock.lfs_bsize);
@ -152,18 +150,16 @@ bufinit()
* Manage a cache of directory blocks.
*/
struct bufarea *
getddblk(blkno,size)
daddr_t blkno;
long size;
getddblk(daddr_t blkno, long size)
{
register struct bufarea *bp;
for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
if (bp->b_bno == blkno) {
if(bp->b_size <= size)
getdblk(bp,blkno,size);
goto foundit;
}
if (bp->b_size <= size)
getdblk(bp, blkno, size);
goto foundit;
}
for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
if ((bp->b_flags & B_INUSE) == 0)
break;
@ -184,18 +180,13 @@ foundit:
}
struct bufarea *
getdatablk(blkno, size)
daddr_t blkno;
long size;
getdatablk(daddr_t blkno, long size)
{
return getddblk(fsbtodb(&sblock,blkno),size);
return getddblk(fsbtodb(&sblock, blkno), size);
}
void
getdblk(bp, blk, size)
register struct bufarea *bp;
daddr_t blk;
long size;
void
getdblk(struct bufarea * bp, daddr_t blk, long size)
{
if (bp->b_bno != blk) {
flush(fswritefd, bp);
@ -207,44 +198,37 @@ getdblk(bp, blk, size)
}
void
getblk(bp, blk, size)
register struct bufarea *bp;
daddr_t blk;
long size;
getblk(struct bufarea * bp, daddr_t blk, long size)
{
getdblk(bp, fsbtodb(&sblock,blk), size);
getdblk(bp, fsbtodb(&sblock, blk), size);
}
void
flush(fd, bp)
int fd;
register struct bufarea *bp;
flush(int fd, struct bufarea * bp)
{
if (!bp->b_dirty)
return;
if (bp->b_errs != 0)
pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
(bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
bp->b_bno);
(bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
bp->b_bno);
bp->b_dirty = 0;
bp->b_errs = 0;
bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
if (bp != &sblk)
return;
#if 0 /* XXX - FFS */
#if 0 /* XXX - FFS */
for (i = 0, j = 0; i < sblock.lfs_cssize; i += sblock.lfs_bsize, j++) {
bwrite(fswritefd, (char *)sblock.lfs_csp[j],
fsbtodb(&sblock, sblock.lfs_csaddr + j * sblock.lfs_frag),
sblock.lfs_cssize - i < sblock.lfs_bsize ?
sblock.lfs_cssize - i : sblock.lfs_bsize);
fsbtodb(&sblock, sblock.lfs_csaddr + j * sblock.lfs_frag),
sblock.lfs_cssize - i < sblock.lfs_bsize ?
sblock.lfs_cssize - i : sblock.lfs_bsize);
}
#endif
}
static void
rwerror(mesg, blk)
char *mesg;
daddr_t blk;
rwerror(char *mesg, daddr_t blk)
{
if (preen == 0)
@ -255,11 +239,10 @@ rwerror(mesg, blk)
}
void
ckfini(markclean)
int markclean;
ckfini(int markclean)
{
register struct bufarea *bp, *nbp;
int cnt = 0;
int cnt = 0;
if (fswritefd < 0) {
(void)close(fsreadfd);
@ -274,19 +257,18 @@ ckfini(markclean)
flush(fswritefd, &sblk);
}
if (havesb) {
if(sblk.b_bno == LFS_LABELPAD / dev_bsize) {
if (sblk.b_bno == LFS_LABELPAD / dev_bsize) {
/* Do the first alternate */
sblk.b_bno = sblock.lfs_sboffs[1];
sbdirty();
flush(fswritefd, &sblk);
} else if(sblk.b_bno == sblock.lfs_sboffs[1]) {
} else if (sblk.b_bno == sblock.lfs_sboffs[1]) {
/* Do the primary */
sblk.b_bno = LFS_LABELPAD / dev_bsize;
sbdirty();
flush(fswritefd, &sblk);
}
}
/* flush(fswritefd, &cgblk); */
/* free(cgblk.b_un.b_buf); */
for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
@ -311,11 +293,11 @@ ckfini(markclean)
sblock.lfs_clean = 1;
sbdirty();
flush(fswritefd, &sblk);
if(sblk.b_bno == LFS_LABELPAD / dev_bsize) {
if (sblk.b_bno == LFS_LABELPAD / dev_bsize) {
/* Do the first alternate */
sblk.b_bno = sblock.lfs_sboffs[0];
flush(fswritefd, &sblk);
} else if(sblk.b_bno == sblock.lfs_sboffs[0]) {
} else if (sblk.b_bno == sblock.lfs_sboffs[0]) {
/* Do the primary */
sblk.b_bno = LFS_LABELPAD / dev_bsize;
flush(fswritefd, &sblk);
@ -324,29 +306,24 @@ ckfini(markclean)
}
if (debug)
printf("cache missed %ld of %ld (%d%%)\n", diskreads,
totalreads, (int)(diskreads * 100 / totalreads));
totalreads, (int)(diskreads * 100 / totalreads));
(void)close(fsreadfd);
(void)close(fswritefd);
}
int
bread(fd, buf, blk, size)
int fd;
char *buf;
daddr_t blk;
long size;
bread(int fd, char *buf, daddr_t blk, long size)
{
char *cp;
int i, errs;
off_t offset;
char *cp;
int i, errs;
off_t offset;
offset = blk;
offset *= dev_bsize;
if (lseek(fd, offset, 0) < 0) {
rwerror("SEEK", blk);
raise(1);
}
else if (read(fd, buf, (int)size) == size)
} else if (read(fd, buf, (int)size) == size)
return (0);
rwerror("READ", blk);
if (lseek(fd, offset, 0) < 0)
@ -359,8 +336,8 @@ bread(fd, buf, blk, size)
(void)lseek(fd, offset + i + secsize, 0);
if (secsize != dev_bsize && dev_bsize != 1)
printf(" %ld (%ld),",
(blk * dev_bsize + i) / secsize,
blk + i / dev_bsize);
(blk * dev_bsize + i) / secsize,
blk + i / dev_bsize);
else
printf(" %ld,", blk + i / dev_bsize);
errs++;
@ -371,15 +348,11 @@ bread(fd, buf, blk, size)
}
void
bwrite(fd, buf, blk, size)
int fd;
char *buf;
daddr_t blk;
long size;
bwrite(int fd, char *buf, daddr_t blk, long size)
{
int i;
char *cp;
off_t offset;
int i;
char *cp;
off_t offset;
if (fd < 0)
return;
@ -408,8 +381,7 @@ bwrite(fd, buf, blk, size)
* allocate a data block with the specified number of fragments
*/
int
allocblk(frags)
long frags;
allocblk(long frags)
{
#if 1
/*
@ -417,8 +389,8 @@ allocblk(frags)
* a full partial segment write.
*/
return 0;
#else /* 0 */
register int i, j, k;
#else /* 0 */
register int i, j, k;
if (frags <= 0 || frags > sblock.lfs_frag)
return (0);
@ -435,28 +407,26 @@ allocblk(frags)
}
for (k = 0; k < frags; k++) {
#ifndef VERBOSE_BLOCKMAP
setbmap(i + j + k);
setbmap(i + j + k);
#else
setbmap(i + j + k, -1);
setbmap(i + j + k, -1);
#endif
}
}
n_blks += frags;
return (i + j);
}
}
return (0);
#endif /* 0 */
#endif /* 0 */
}
/*
* Free a previously allocated block
*/
void
freeblk(blkno, frags)
daddr_t blkno;
long frags;
freeblk(daddr_t blkno, long frags)
{
struct inodesc idesc;
struct inodesc idesc;
idesc.id_blkno = blkno;
idesc.id_numfrags = frags;
@ -467,14 +437,12 @@ freeblk(blkno, frags)
* Find a pathname
*/
void
getpathname(namebuf, curdir, ino)
char *namebuf;
ino_t curdir, ino;
getpathname(char *namebuf, ino_t curdir, ino_t ino)
{
int len;
register char *cp;
struct inodesc idesc;
static int busy = 0;
int len;
register char *cp;
struct inodesc idesc;
static int busy = 0;
if (curdir == ino && ino == ROOTINO) {
(void)strcpy(namebuf, "/");
@ -501,12 +469,12 @@ getpathname(namebuf, curdir, ino)
idesc.id_name = "..";
if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
break;
namelookup:
namelookup:
idesc.id_number = idesc.id_parent;
idesc.id_parent = ino;
idesc.id_func = findname;
idesc.id_name = namebuf;
if ((ckinode(ginode(idesc.id_number), &idesc)&FOUND) == 0)
if ((ckinode(ginode(idesc.id_number), &idesc) & FOUND) == 0)
break;
len = strlen(namebuf);
cp -= len;
@ -523,8 +491,7 @@ getpathname(namebuf, curdir, ino)
}
void
catch(n)
int n;
catch(int n)
{
if (!doinglevel2)
ckfini(0);
@ -537,10 +504,9 @@ catch(n)
* so that reboot sequence may be interrupted.
*/
void
catchquit(n)
int n;
catchquit(int n)
{
extern int returntosingle;
extern int returntosingle;
printf("returning to single-user after filesystem check\n");
returntosingle = 1;
@ -552,8 +518,7 @@ catchquit(n)
* Used by child processes in preen.
*/
void
voidquit(n)
int n;
voidquit(int n)
{
sleep(1);
@ -565,14 +530,12 @@ voidquit(n)
* determine whether an inode should be fixed.
*/
int
dofix(idesc, msg)
register struct inodesc *idesc;
char *msg;
dofix(struct inodesc * idesc, char *msg)
{
switch (idesc->id_fix) {
case DONTKNOW:
case DONTKNOW:
if (idesc->id_type == DATA)
direrror(idesc->id_number, msg);
else

View File

@ -1,69 +1,68 @@
/* $NetBSD: vars.c,v 1.2 1999/07/03 19:55:03 kleink Exp $ */
/* $NetBSD: vars.c,v 1.3 2000/05/23 01:48:56 perseant Exp $ */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <sys/mount.h> /* XXX */
#include <sys/mount.h> /* XXX */
#include <ufs/lfs/lfs.h>
#include "fsck.h"
/* variables previously of file scope (from fsck.h) */
struct bufarea bufhead; /* head of list of other blks in filesys */
struct bufarea sblk; /* file system superblock */
struct bufarea iblk; /* ifile on-disk inode block */
struct bufarea bufhead; /* head of list of other blks in filesys */
struct bufarea sblk; /* file system superblock */
struct bufarea iblk; /* ifile on-disk inode block */
struct bufarea *pdirbp; /* current directory contents */
struct bufarea *pbp; /* current inode block */
struct bufarea *getdatablk __P((daddr_t, long));
int iinooff; /* ifile inode offset in block of inodes */
struct bufarea *getdatablk(daddr_t, long);
int iinooff; /* ifile inode offset in block of inodes */
struct dups *duplist; /* head of dup list */
struct dups *muldup; /* end of unique duplicate dup block numbers */
struct dups *duplist; /* head of dup list */
struct dups *muldup; /* end of unique duplicate dup block numbers */
struct zlncnt *zlnhead; /* head of zero link count list */
struct zlncnt *zlnhead; /* head of zero link count list */
long numdirs, listmax, inplast;
long numdirs, listmax, inplast;
long dev_bsize; /* computed value of DEV_BSIZE */
long secsize; /* actual disk sector size */
char nflag; /* assume a no response */
char yflag; /* assume a yes response */
int bflag; /* location of alternate super block */
int debug; /* output debugging info */
long dev_bsize; /* computed value of DEV_BSIZE */
long secsize; /* actual disk sector size */
char nflag; /* assume a no response */
char yflag; /* assume a yes response */
int bflag; /* location of alternate super block */
int debug; /* output debugging info */
#ifdef DEBUG_IFILE
int debug_ifile; /* cat the ifile and exit */
int debug_ifile; /* cat the ifile and exit */
#endif
int cvtlevel; /* convert to newer file system format */
int doinglevel1; /* converting to new cylinder group format */
int doinglevel2; /* converting to new inode format */
int exitonfail;
int newinofmt; /* filesystem has new inode format */
int preen; /* just fix normal inconsistencies */
char havesb; /* superblock has been read */
char skipclean; /* skip clean file systems if preening */
int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */
int rerun; /* rerun fsck. Only used in non-preen mode */
int cvtlevel; /* convert to newer file system format */
int doinglevel1; /* converting to new cylinder group format */
int doinglevel2; /* converting to new inode format */
int exitonfail;
int newinofmt; /* filesystem has new inode format */
int preen; /* just fix normal inconsistencies */
char havesb; /* superblock has been read */
char skipclean; /* skip clean file systems if preening */
int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */
int rerun; /* rerun fsck. Only used in non-preen mode */
daddr_t maxfsblock; /* number of blocks in the file system */
daddr_t maxfsblock; /* number of blocks in the file system */
#ifndef VERBOSE_BLOCKMAP
char *blockmap; /* ptr to primary blk allocation map */
char *blockmap; /* ptr to primary blk allocation map */
#else
ino_t *blockmap;
ino_t *blockmap;
#endif
ino_t maxino; /* number of inodes in file system */
ino_t lastino; /* last inode in use */
char *statemap; /* ptr to inode state table */
char *typemap; /* ptr to inode type table */
int16_t *lncntp; /* ptr to link count table */
ino_t maxino; /* number of inodes in file system */
ino_t lastino; /* last inode in use */
char *statemap; /* ptr to inode state table */
char *typemap; /* ptr to inode type table */
int16_t *lncntp; /* ptr to link count table */
ino_t lfdir; /* lost & found directory inode number */
char *lfname; /* lost & found directory name */
int lfmode; /* lost & found directory creation mode */
ino_t lfdir; /* lost & found directory inode number */
char *lfname; /* lost & found directory name */
int lfmode; /* lost & found directory creation mode */
daddr_t n_blks; /* number of blocks in use */
daddr_t n_files; /* number of files in use */
struct dinode zino;
daddr_t n_blks; /* number of blocks in use */
daddr_t n_files; /* number of files in use */
struct dinode zino;