resolve conflicts from lite-2 merge.

This commit is contained in:
lukem 1997-09-16 16:44:43 +00:00
parent 83bd421ad4
commit e111111128
14 changed files with 326 additions and 259 deletions

View File

@ -1,12 +1,12 @@
# $NetBSD: Makefile,v 1.16 1997/05/08 21:11:10 gwr Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $NetBSD: Makefile,v 1.17 1997/09/16 16:44:43 lukem Exp $
# @(#)Makefile 8.2 (Berkeley) 4/27/95
PROG= fsck_ffs
MAN= fsck_ffs.8
SRCS= dir.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \
pass5.c fsutil.c setup.c utilities.c ffs_subr.c ffs_tables.c
.PATH: ${.CURDIR}/../../sys/ufs/ffs ${.CURDIR}/../fsck
CFLAGS+=-I${.CURDIR}/../fsck
CFLAGS+=-I${.CURDIR}/../fsck -g
.if make(install)
SUBDIR+= SMM.doc

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.22 1997/09/14 14:36:29 lukem Exp $ */
/* $NetBSD: dir.c,v 1.23 1997/09/16 16:44:48 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,20 +36,20 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dir.c 8.5 (Berkeley) 12/8/94";
static char sccsid[] = "@(#)dir.c 8.8 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: dir.c,v 1.22 1997/09/14 14:36:29 lukem Exp $");
__RCSID("$NetBSD: dir.c,v 1.23 1997/09/16 16:44:48 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <string.h>
#include "fsck.h"
@ -68,13 +68,14 @@ struct odirtemplate odirhead = {
0, DIRBLKSIZ - 12, 2, ".."
};
static int chgino __P((struct inodesc *));
static int dircheck __P((struct inodesc *, struct direct *));
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 *));
/*
* Propagate connected state through the tree.
@ -126,7 +127,7 @@ dirscan(idesc)
char dbuf[DIRBLKSIZ];
if (idesc->id_type != DATA)
errexit("wrong type to dirscan %d\n", idesc->id_type);
errx(EEXIT, "wrong type to dirscan %d", idesc->id_type);
if (idesc->id_entryno == 0 &&
(idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)
idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ);
@ -138,7 +139,7 @@ dirscan(idesc)
idesc->id_loc = 0;
for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {
dsize = dp->d_reclen;
memcpy(dbuf, dp, (size_t)dsize);
memmove(dbuf, dp, (size_t)dsize);
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (!newinofmt) {
struct direct *tdp = (struct direct *)dbuf;
@ -163,7 +164,7 @@ dirscan(idesc)
}
# endif
bp = getdirblk(idesc->id_blkno, blksiz);
memcpy(bp->b_un.b_buf + idesc->id_loc - dsize, dbuf,
memmove(bp->b_un.b_buf + idesc->id_loc - dsize, dbuf,
(size_t)dsize);
dirty(bp);
sbdirty();
@ -239,7 +240,7 @@ dpok:
* Verify that a directory entry is valid.
* This is a superset of the checks made in the kernel.
*/
int
static int
dircheck(idesc, dp)
struct inodesc *idesc;
struct direct *dp;
@ -373,7 +374,7 @@ mkentry(idesc)
else
dirp->d_type = 0;
dirp->d_namlen = newent.d_namlen;
memcpy(dirp->d_name, idesc->id_name, (size_t)dirp->d_namlen + 1);
memmove(dirp->d_name, idesc->id_name, (size_t)newent.d_namlen + 1);
# if (BYTE_ORDER == LITTLE_ENDIAN)
/*
* If the entry was split, dirscan() will only reverse the byte
@ -577,7 +578,7 @@ expanddir(dp, name)
struct dinode *dp;
char *name;
{
daddr_t lastbn, newblk;
ufs_daddr_t lastbn, newblk;
struct bufarea *bp;
char *cp, firstblk[DIRBLKSIZ];
@ -594,21 +595,21 @@ expanddir(dp, name)
(long)dblksize(&sblock, dp, lastbn + 1));
if (bp->b_errs)
goto bad;
memcpy(firstblk, bp->b_un.b_buf, DIRBLKSIZ);
memmove(firstblk, bp->b_un.b_buf, DIRBLKSIZ);
bp = getdirblk(newblk, sblock.fs_bsize);
if (bp->b_errs)
goto bad;
memcpy(bp->b_un.b_buf, firstblk, DIRBLKSIZ);
memmove(bp->b_un.b_buf, firstblk, DIRBLKSIZ);
for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
cp < &bp->b_un.b_buf[sblock.fs_bsize];
cp += DIRBLKSIZ)
memcpy(cp, &emptydir, sizeof emptydir);
memmove(cp, &emptydir, sizeof emptydir);
dirty(bp);
bp = getdirblk(dp->di_db[lastbn + 1],
(long)dblksize(&sblock, dp, lastbn + 1));
if (bp->b_errs)
goto bad;
memcpy(bp->b_un.b_buf, &emptydir, sizeof emptydir);
memmove(bp->b_un.b_buf, &emptydir, sizeof emptydir);
pwarn("NO SPACE LEFT IN %s", name);
if (preen)
printf(" (EXPANDED)\n");
@ -629,7 +630,7 @@ bad:
/*
* allocate a new directory
*/
int
ino_t
allocdir(parent, request, mode)
ino_t parent, request;
int mode;
@ -653,11 +654,11 @@ allocdir(parent, request, mode)
freeino(ino);
return (0);
}
memcpy(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate));
memmove(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate));
for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
cp < &bp->b_un.b_buf[sblock.fs_fsize];
cp += DIRBLKSIZ)
memcpy(cp, &emptydir, sizeof emptydir);
memmove(cp, &emptydir, sizeof emptydir);
dirty(bp);
dp->di_nlink = 2;
inodirty();
@ -731,7 +732,7 @@ lftempname(bufp, ino)
*/
static struct bufarea *
getdirblk(blkno, size)
daddr_t blkno;
ufs_daddr_t blkno;
long size;
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.6 1996/09/27 22:45:12 christos Exp $ */
/* $NetBSD: extern.h,v 1.7 1997/09/16 16:44:52 lukem Exp $ */
/*
* Copyright (c) 1994 James A. Jegers
@ -24,51 +24,64 @@
* 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 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((char *));
struct dinode * getnextinode __P((ino_t));
void catch __P((int));
void catchquit __P((int));
void voidquit __P((int));
void adjust __P((struct inodesc *, int));
ufs_daddr_t allocblk __P((long));
ino_t allocdir __P((ino_t, ino_t, int));
ino_t allocino __P((ino_t request, int type));
void blkerror __P((ino_t, char *, ufs_daddr_t));
char *blockcheck __P((char *));
int bread __P((int, char *, ufs_daddr_t, long));
void bufinit __P((void));
void bwrite __P((int, char *, ufs_daddr_t, long));
void cacheino __P((struct dinode *, ino_t));
void catch __P((int));
void catchquit __P((int));
int changeino __P((ino_t, char *, ino_t));
int chkrange __P((ufs_daddr_t, int));
void ckfini __P((int));
int ckinode __P((struct dinode *, struct inodesc *));
void clri __P((struct inodesc *, char *, int));
struct dinode * getnextinode __P((ino_t));
void direrror __P((ino_t, char *));
int dirscan __P((struct inodesc *));
int dofix __P((struct inodesc *, char *));
void ffs_clrblock __P((struct fs *, u_char *, ufs_daddr_t));
void ffs_fragacct __P((struct fs *, int, int32_t [], int));
int ffs_isblock __P((struct fs *, u_char *, ufs_daddr_t));
void ffs_setblock __P((struct fs *, u_char *, ufs_daddr_t));
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((ufs_daddr_t, long));
void freeino __P((ino_t));
void freeinodebuf __P((void));
int ftypeok __P((struct dinode *));
int ftypeok __P((struct dinode *dp));
void getblk __P((struct bufarea *bp, ufs_daddr_t blk, long size));
struct bufarea *getdatablk __P((ufs_daddr_t, long));
struct inoinfo *getinoinfo __P((ino_t));
struct dinode *getnextinode __P((ino_t));
struct dinode *ginode __P((ino_t));
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 panic __P((const char *fmt, ...));
void pass1 __P((void));
void pass1b __P((void));
int pass1check __P((struct inodesc *));
void pass2 __P((void));
void pass3 __P((void));
void pass4 __P((void));
int pass4check __P((struct inodesc *));
void pass5 __P((void));
void pfatal __P((const char *fmt, ...));
void pinode __P((ino_t));
void propagate __P((void));
void pwarn __P((const char *fmt, ...));
int reply __P((char *));
void resetinodebuf __P((void));
int setup __P((char *));
void voidquit __P((int));

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsck.h,v 1.13 1996/10/11 20:15:46 thorpej Exp $ */
/* $NetBSD: fsck.h,v 1.14 1997/09/16 16:44:56 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -32,9 +32,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)fsck.h 8.1 (Berkeley) 6/5/93
* @(#)fsck.h 8.4 (Berkeley) 5/9/95
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#define MAXDUP 10 /* limit on dup blks (per inode) */
#define MAXBAD 10 /* limit on bad blks (per inode) */
#define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */
@ -55,20 +59,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 */
ufs_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 fs *b_fs; /* super block */
struct cg *b_cg; /* cylinder group */
struct dinode *b_dinode; /* inode block */
char *b_buf; /* buffer space */
ufs_daddr_t *b_indir; /* indirect block */
struct fs *b_fs; /* super block */
struct cg *b_cg; /* cylinder group */
struct dinode *b_dinode; /* inode block */
} b_un;
char b_dirty;
char b_dirty;
};
#define B_INUSE 1
@ -79,12 +83,11 @@ struct bufarea sblk; /* file system superblock */
struct bufarea cgblk; /* cylinder group blocks */
struct bufarea *pdirbp; /* current directory contents */
struct bufarea *pbp; /* current inode block */
struct bufarea *getdatablk __P((daddr_t, long));
#define dirty(bp) (bp)->b_dirty = 1
#define initbarea(bp) \
(bp)->b_dirty = 0; \
(bp)->b_bno = (daddr_t)-1; \
(bp)->b_bno = (ufs_daddr_t)-1; \
(bp)->b_flags = 0;
#define sbdirty() sblk.b_dirty = 1
@ -100,9 +103,9 @@ struct inodesc {
__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 */
ufs_daddr_t id_blkno; /* current block number being examined */
int id_numfrags; /* number of frags contained in block */
quad_t id_filesize; /* for DATA nodes, the size of the directory */
u_int64_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 */
@ -136,7 +139,7 @@ struct inodesc {
*/
struct dups {
struct dups *next;
daddr_t dup;
ufs_daddr_t dup;
};
struct dups *duplist; /* head of dup list */
struct dups *muldup; /* end of unique duplicate dup block numbers */
@ -161,7 +164,7 @@ struct inoinfo {
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 */
ufs_daddr_t i_blks[1]; /* actually longer */
} **inphead, **inpsort;
long numdirs, listmax, inplast;
@ -183,20 +186,20 @@ 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 */
ufs_daddr_t maxfsblock; /* number of blocks in the file system */
char *blockmap; /* ptr to primary blk allocation map */
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 */
u_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 */
daddr_t n_blks; /* number of blocks in use */
daddr_t n_files; /* number of files in use */
ufs_daddr_t n_blks; /* number of blocks in use */
ufs_daddr_t n_files; /* number of files in use */
#define clearinode(dp) (*(dp) = zino)
struct dinode zino;
@ -211,7 +214,4 @@ struct dinode zino;
#define ALTERED 0x08
#define FOUND 0x10
struct dinode *ginode __P((ino_t));
struct inoinfo *getinoinfo __P((ino_t));
void getblk __P((struct bufarea *, daddr_t, long));
ino_t allocino __P((ino_t, int));
#define EEXIT 8 /* Standard error exit. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: inode.c,v 1.25 1997/09/16 08:37:05 mrg Exp $ */
/* $NetBSD: inode.c,v 1.26 1997/09/16 16:45:01 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,18 +36,21 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: inode.c,v 1.25 1997/09/16 08:37:05 mrg Exp $");
__RCSID("$NetBSD: inode.c,v 1.26 1997/09/16 16:45:01 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#ifndef SMALL
#include <err.h>
#include <pwd.h>
#endif
#include <stdio.h>
@ -158,8 +161,8 @@ iblock(idesc, ilevel, isize)
long ilevel;
u_int64_t isize;
{
daddr_t *ap;
daddr_t *aplim;
ufs_daddr_t *ap;
ufs_daddr_t *aplim;
struct bufarea *bp;
int i, n, (*func) __P((struct inodesc *)), nif;
u_int64_t sizepb;
@ -241,7 +244,7 @@ iblock(idesc, ilevel, isize)
*/
int
chkrange(blk, cnt)
daddr_t blk;
ufs_daddr_t blk;
int cnt;
{
int c;
@ -280,10 +283,10 @@ struct dinode *
ginode(inumber)
ino_t inumber;
{
daddr_t iblk;
ufs_daddr_t iblk;
if (inumber < ROOTINO || inumber > maxino)
errexit("bad inode number %d to ginode\n", inumber);
errx(EEXIT, "bad inode number %d to ginode", inumber);
if (startinum == 0 ||
inumber < startinum || inumber >= startinum + INOPB(&sblock)) {
iblk = ino_to_fsba(&sblock, inumber);
@ -308,11 +311,11 @@ getnextinode(inumber)
ino_t inumber;
{
long size;
daddr_t dblk;
ufs_daddr_t dblk;
static struct dinode *dp;
if (inumber != nextino++ || inumber > maxino)
errexit("bad inode number %d to nextinode\n", inumber);
errx(EEXIT, "bad inode number %d to nextinode", inumber);
if (inumber >= lastinum) {
readcnt++;
dblk = fsbtodb(&sblock, ino_to_fsba(&sblock, lastinum));
@ -350,7 +353,7 @@ resetinodebuf()
}
if (inodebuf == NULL &&
(inodebuf = (struct dinode *)malloc((unsigned)inobufsize)) == NULL)
errexit("Cannot allocate space for inode buffer\n");
errx(EEXIT, "Cannot allocate space for inode buffer");
while (nextino < ROOTINO)
(void)getnextinode(nextino);
}
@ -384,7 +387,7 @@ cacheino(dp, inumber)
if (blks > NDADDR)
blks = NDADDR + NIADDR;
inp = (struct inoinfo *)
malloc(sizeof(*inp) + (blks - 1) * sizeof(daddr_t));
malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs_daddr_t));
if (inp == NULL)
return;
inpp = &inphead[inumber % numdirs];
@ -398,14 +401,14 @@ cacheino(dp, inumber)
inp->i_dotdot = (ino_t)0;
inp->i_number = inumber;
inp->i_isize = dp->di_size;
inp->i_numblks = blks * sizeof(daddr_t);
memcpy(&inp->i_blks[0], &dp->di_db[0], (size_t)inp->i_numblks);
inp->i_numblks = blks * sizeof(ufs_daddr_t);
memmove(&inp->i_blks[0], &dp->di_db[0], (size_t)inp->i_numblks);
if (inplast == listmax) {
listmax += 100;
inpsort = (struct inoinfo **)realloc((char *)inpsort,
(unsigned)listmax * sizeof(struct inoinfo *));
if (inpsort == NULL)
errexit("cannot increase directory list");
errx(EEXIT, "cannot increase directory list");
}
inpsort[inplast++] = inp;
}
@ -424,7 +427,7 @@ getinoinfo(inumber)
continue;
return (inp);
}
errexit("cannot find inode %d\n", inumber);
errx(EEXIT, "cannot find inode %d", inumber);
return ((struct inoinfo *)0);
}
@ -485,7 +488,7 @@ findname(idesc)
if (dirp->d_ino != idesc->id_parent)
return (KEEPON);
memcpy(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
memmove(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
return (STOP|FOUND);
}
@ -538,7 +541,7 @@ void
blkerror(ino, type, blk)
ino_t ino;
char *type;
daddr_t blk;
ufs_daddr_t blk;
{
pfatal("%d %s I=%u", blk, type, ino);
@ -558,7 +561,7 @@ blkerror(ino, type, blk)
return;
default:
errexit("BAD STATE %d TO BLKERR", statemap[ino]);
errx(EEXIT, "BAD STATE %d TO BLKERR", statemap[ino]);
/* NOTREACHED */
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.24 1997/09/14 14:36:32 lukem Exp $ */
/* $NetBSD: main.c,v 1.25 1997/09/16 16:45:05 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -41,19 +41,22 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\n\
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
#else
__RCSID("$NetBSD: main.c,v 1.24 1997/09/14 14:36:32 lukem Exp $");
__RCSID("$NetBSD: main.c,v 1.25 1997/09/16 16:45:05 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/mount.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <ctype.h>
#include <err.h>
#include <fstab.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
@ -108,7 +111,7 @@ main(argc, argv)
case 'm':
lfmode = argtoi('m', "mode", optarg, 8);
if (lfmode &~ 07777)
errexit("bad mode to -m: %o\n", lfmode);
errx(EEXIT, "bad mode to -m: %o", lfmode);
printf("** lost+found creation mode %o\n", lfmode);
break;
@ -162,7 +165,7 @@ argtoi(flag, req, str, base)
ret = (int)strtol(str, &cp, base);
if (cp == str || *cp)
errexit("-%c flag requires a %s\n", flag, req);
errx(EEXIT, "-%c flag requires a %s", flag, req);
return (ret);
}
@ -176,10 +179,10 @@ checkfilesys(filesys, mntpt, auxdata, child)
long auxdata;
int child;
{
daddr_t n_ffree, n_bfree;
ufs_daddr_t n_ffree, n_bfree;
struct dups *dp;
struct zlncnt *zlnp;
int cylno;
int cylno, flags;
if (preen && child)
(void)signal(SIGQUIT, voidquit);
@ -190,6 +193,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
case 0:
if (preen)
pfatal("CAN'T CHECK FILE SYSTEM.");
/* fall through */
case -1:
return (0);
}
@ -291,7 +295,19 @@ checkfilesys(filesys, mntpt, auxdata, child)
bwrite(fswritefd, (char *)&sblock,
fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE);
}
ckfini(1);
if (!hotroot()) {
ckfini(1);
} else {
struct statfs stfs_buf;
/*
* Check to see if root is mounted read-write.
*/
if (statfs("/", &stfs_buf) == 0)
flags = stfs_buf.f_flags;
else
flags = 0;
ckfini(flags & MNT_RDONLY);
}
free(blockmap);
free(statemap);
free((char *)lncntp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass1.c,v 1.18 1997/09/16 08:37:06 mrg Exp $ */
/* $NetBSD: pass1.c,v 1.19 1997/09/16 16:45:09 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,28 +36,28 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
static char sccsid[] = "@(#)pass1.c 8.6 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: pass1.c,v 1.18 1997/09/16 08:37:06 mrg Exp $");
__RCSID("$NetBSD: pass1.c,v 1.19 1997/09/16 16:45:09 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <string.h>
#include "fsck.h"
#include "extern.h"
#include "fsutil.h"
static daddr_t badblk;
static daddr_t dupblk;
static ufs_daddr_t badblk;
static ufs_daddr_t dupblk;
static void checkinode __P((ino_t, struct inodesc *));
void
@ -111,13 +111,15 @@ checkinode(inumber, idesc)
struct zlncnt *zlnp;
int ndb, j;
mode_t mode;
char *symbuf;
char symbuf[MAXSYMLINKLEN];
dp = getnextinode(inumber);
mode = dp->di_mode & IFMT;
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)) ||
if (memcmp(dp->di_db, zino.di_db,
NDADDR * sizeof(ufs_daddr_t)) ||
memcmp(dp->di_ib, zino.di_ib,
NIADDR * sizeof(ufs_daddr_t)) ||
dp->di_mode || dp->di_size) {
pfatal("PARTIALLY ALLOCATED INODE I=%u", inumber);
if (reply("CLEAR") == 1) {
@ -131,7 +133,8 @@ checkinode(inumber, idesc)
}
lastino = inumber;
if (/* dp->di_size < 0 || */
dp->di_size + sblock.fs_bsize - 1 < dp->di_size) {
dp->di_size + sblock.fs_bsize - 1 < dp->di_size ||
(mode == IFDIR && dp->di_size > MAXDIRSIZE)) {
if (debug)
printf("bad size %qu:",(unsigned long long)dp->di_size);
goto unknown;
@ -162,11 +165,10 @@ checkinode(inumber, idesc)
if (doinglevel2 &&
dp->di_size > 0 && dp->di_size < MAXSYMLINKLEN &&
dp->di_blocks != 0) {
symbuf = alloca(secsize);
if (bread(fsreadfd, symbuf,
fsbtodb(&sblock, dp->di_db[0]),
(long)secsize) != 0)
errexit("cannot read symlink");
errx(EEXIT, "cannot read symlink");
if (debug) {
symbuf[dp->di_size] = 0;
printf("convert symlink %u(%s) of size %qd\n",
@ -174,7 +176,7 @@ checkinode(inumber, idesc)
(unsigned long long)dp->di_size);
}
dp = ginode(inumber);
memcpy(dp->di_shortlink, symbuf, (long)dp->di_size);
memmove(dp->di_shortlink, symbuf, (long)dp->di_size);
dp->di_blocks = 0;
inodirty();
}
@ -217,7 +219,7 @@ checkinode(inumber, idesc)
if (zlnp == NULL) {
pfatal("LINK COUNT TABLE OVERFLOW");
if (reply("CONTINUE") == 0)
errexit("%s", "");
exit(EEXIT);
} else {
zlnp->zlncnt = inumber;
zlnp->next = zlnhead;
@ -275,7 +277,7 @@ pass1check(idesc)
{
int res = KEEPON;
int anyout, nfrags;
daddr_t blkno = idesc->id_blkno;
ufs_daddr_t blkno = idesc->id_blkno;
struct dups *dlp;
struct dups *new;
@ -287,7 +289,7 @@ pass1check(idesc)
if (preen)
printf(" (SKIPPING)\n");
else if (reply("CONTINUE") == 0)
errexit("%s", "");
exit(EEXIT);
return (STOP);
}
}
@ -305,14 +307,14 @@ pass1check(idesc)
if (preen)
printf(" (SKIPPING)\n");
else if (reply("CONTINUE") == 0)
errexit("%s", "");
exit(EEXIT);
return (STOP);
}
new = (struct dups *)malloc(sizeof(struct dups));
if (new == NULL) {
pfatal("DUP TABLE OVERFLOW.");
if (reply("CONTINUE") == 0)
errexit("%s", "");
exit(EEXIT);
return (STOP);
}
new->dup = blkno;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass1b.c,v 1.11 1997/09/14 14:36:33 lukem Exp $ */
/* $NetBSD: pass1b.c,v 1.12 1997/09/16 16:45:12 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,23 +36,25 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
static char sccsid[] = "@(#)pass1b.c 8.4 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: pass1b.c,v 1.11 1997/09/14 14:36:33 lukem Exp $");
__RCSID("$NetBSD: pass1b.c,v 1.12 1997/09/16 16:45:12 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <string.h>
#include "fsck.h"
#include "extern.h"
static int pass1bcheck __P((struct inodesc *));
static struct dups *duphead;
static int pass1bcheck __P((struct inodesc *));
void
pass1b()
@ -88,7 +90,7 @@ pass1bcheck(idesc)
{
struct dups *dlp;
int nfrags, res = KEEPON;
daddr_t blkno = idesc->id_blkno;
ufs_daddr_t blkno = idesc->id_blkno;
for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
if (chkrange(blkno, 1))

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass2.c,v 1.19 1997/09/16 08:37:07 mrg Exp $ */
/* $NetBSD: pass2.c,v 1.20 1997/09/16 16:45:16 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,20 +36,20 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)pass2.c 8.6 (Berkeley) 10/27/94";
static char sccsid[] = "@(#)pass2.c 8.9 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: pass2.c,v 1.19 1997/09/16 08:37:07 mrg Exp $");
__RCSID("$NetBSD: pass2.c,v 1.20 1997/09/16 16:45:16 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <string.h>
#include "fsck.h"
@ -58,8 +58,8 @@ __RCSID("$NetBSD: pass2.c,v 1.19 1997/09/16 08:37:07 mrg Exp $");
#define MINDIRSIZE (sizeof (struct dirtemplate))
static int pass2check __P((struct inodesc *));
static int blksort __P((const void *, const void *));
static int pass2check __P((struct inodesc *));
void
pass2()
@ -76,9 +76,9 @@ pass2()
case USTATE:
pfatal("ROOT INODE UNALLOCATED");
if (reply("ALLOCATE") == 0)
errexit("%s", "");
exit(EEXIT);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errexit("CANNOT ALLOCATE ROOT INODE\n");
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
case DCLEAR:
@ -86,11 +86,11 @@ pass2()
if (reply("REALLOCATE")) {
freeino(ROOTINO);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errexit("CANNOT ALLOCATE ROOT INODE\n");
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
}
if (reply("CONTINUE") == 0)
errexit("%s", "");
exit(EEXIT);
break;
case FSTATE:
@ -99,11 +99,11 @@ pass2()
if (reply("REALLOCATE")) {
freeino(ROOTINO);
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errexit("CANNOT ALLOCATE ROOT INODE\n");
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
break;
}
if (reply("FIX") == 0)
errexit("%s", "");
exit(EEXIT);
dp = ginode(ROOTINO);
dp->di_mode &= ~IFMT;
dp->di_mode |= IFDIR;
@ -114,8 +114,9 @@ pass2()
break;
default:
errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]);
errx(EEXIT, "BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]);
}
statemap[ROOTINO] = DFOUND;
if (newinofmt) {
statemap[WINO] = FSTATE;
typemap[WINO] = DT_WHT;
@ -130,6 +131,7 @@ pass2()
memset(&curino, 0, sizeof(struct inodesc));
curino.id_type = DATA;
curino.id_func = pass2check;
dp = &dino;
inpend = &inpsort[inplast];
for (inpp = inpsort; inpp < inpend; inpp++) {
inp = *inpp;
@ -142,6 +144,7 @@ pass2()
dp = ginode(inp->i_number);
dp->di_size = inp->i_isize;
inodirty();
dp = &dino;
}
} else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) {
getpathname(pathbuf, inp->i_number, inp->i_number);
@ -152,17 +155,18 @@ pass2()
inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ);
if (preen || reply("ADJUST") == 1) {
dp = ginode(inp->i_number);
dp->di_size = inp->i_isize;
dp->di_size = roundup(inp->i_isize, DIRBLKSIZ);
inodirty();
dp = &dino;
}
}
memset(&dino, 0, sizeof(struct dinode));
dino.di_mode = IFDIR;
dino.di_size = inp->i_isize;
memcpy(&dino.di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks);
dp->di_size = inp->i_isize;
memmove(&dp->di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks);
curino.id_number = inp->i_number;
curino.id_parent = inp->i_parent;
(void)ckinode(&dino, &curino);
(void)ckinode(dp, &curino);
}
/*
* Now that the parents of all directories have been found,
@ -172,6 +176,9 @@ pass2()
inp = *inpp;
if (inp->i_parent == 0 || inp->i_isize == 0)
continue;
if (statemap[inp->i_parent] == DFOUND &&
statemap[inp->i_number] == DSTATE)
statemap[inp->i_number] = DFOUND;
if (inp->i_dotdot == inp->i_parent ||
inp->i_dotdot == (ino_t)-1)
continue;
@ -264,13 +271,13 @@ pass2check(idesc)
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
} else if (dirp->d_reclen < 2 * entrysize) {
proto.d_reclen = dirp->d_reclen;
memcpy(dirp, &proto, (size_t)entrysize);
memmove(dirp, &proto, (size_t)entrysize);
if (reply("FIX") == 1)
ret |= ALTERED;
} else {
n = dirp->d_reclen - entrysize;
proto.d_reclen = entrysize;
memcpy(dirp, &proto, (size_t)entrysize);
memmove(dirp, &proto, (size_t)entrysize);
idesc->id_entryno++;
lncntp[dirp->d_ino]--;
dirp = (struct direct *)((char *)(dirp) + entrysize);
@ -338,7 +345,7 @@ chk1:
inp->i_dotdot = inp->i_parent;
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
proto.d_reclen = dirp->d_reclen;
memcpy(dirp, &proto, (size_t)entrysize);
memmove(dirp, &proto, (size_t)entrysize);
if (reply("FIX") == 1)
ret |= ALTERED;
}
@ -412,6 +419,10 @@ again:
goto again;
case DSTATE:
if (statemap[idesc->id_number] == DFOUND)
statemap[dirp->d_ino] = DFOUND;
/* fall through */
case DFOUND:
inp = getinoinfo(dirp->d_ino);
if (inp->i_parent != 0 && idesc->id_entryno > 2) {
@ -442,7 +453,7 @@ again:
break;
default:
errexit("BAD STATE %d FOR INODE I=%d",
errx(EEXIT, "BAD STATE %d FOR INODE I=%d",
statemap[dirp->d_ino], dirp->d_ino);
}
}
@ -456,9 +467,10 @@ again:
* Routine to sort disk blocks.
*/
static int
blksort(inpp1, inpp2)
const void *inpp1, *inpp2;
blksort(arg1, arg2)
const void *arg1, *arg2;
{
return ((* (struct inoinfo **) inpp1)->i_blks[0] -
(* (struct inoinfo **) inpp2)->i_blks[0]);
return ((*(struct inoinfo **)arg1)->i_blks[0] -
(*(struct inoinfo **)arg2)->i_blks[0]);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass3.c,v 1.9 1997/09/14 14:36:35 lukem Exp $ */
/* $NetBSD: pass3.c,v 1.10 1997/09/16 16:45:19 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,16 +36,18 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
static char sccsid[] = "@(#)pass3.c 8.2 (Berkeley) 4/27/95";
#else
__RCSID("$NetBSD: pass3.c,v 1.9 1997/09/14 14:36:35 lukem Exp $");
__RCSID("$NetBSD: pass3.c,v 1.10 1997/09/16 16:45:19 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include "fsck.h"
#include "extern.h"

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass4.c,v 1.12 1997/09/14 14:36:36 lukem Exp $ */
/* $NetBSD: pass4.c,v 1.13 1997/09/16 16:45:23 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,17 +36,19 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
static char sccsid[] = "@(#)pass4.c 8.4 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: pass4.c,v 1.12 1997/09/14 14:36:36 lukem Exp $");
__RCSID("$NetBSD: pass4.c,v 1.13 1997/09/16 16:45:23 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <stdlib.h>
#include <err.h>
#include <string.h>
#include "fsutil.h"
@ -106,7 +108,7 @@ pass4()
break;
default:
errexit("BAD STATE %d FOR INODE I=%d",
errx(EEXIT, "BAD STATE %d FOR INODE I=%d",
statemap[inumber], inumber);
}
}
@ -118,7 +120,7 @@ pass4check(idesc)
{
struct dups *dlp;
int nfrags, res = KEEPON;
daddr_t blkno = idesc->id_blkno;
ufs_daddr_t blkno = idesc->id_blkno;
for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
if (chkrange(blkno, 1)) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass5.c,v 1.17 1997/09/14 14:36:36 lukem Exp $ */
/* $NetBSD: pass5.c,v 1.18 1997/09/16 16:45:28 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,17 +36,19 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)pass5.c 8.6 (Berkeley) 11/30/94";
static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: pass5.c,v 1.17 1997/09/14 14:36:36 lukem Exp $");
__RCSID("$NetBSD: pass5.c,v 1.18 1997/09/16 16:45:28 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
#include <err.h>
#include <string.h>
#include "fsutil.h"
@ -59,8 +61,8 @@ pass5()
int c, blk, frags, basesize, sumsize, mapsize, savednrpos = 0;
struct fs *fs = &sblock;
struct cg *cg = &cgrp;
daddr_t dbase, dmax;
daddr_t d;
ufs_daddr_t dbase, dmax;
ufs_daddr_t d;
long i, j;
struct csum *cs;
struct csum cstotal;
@ -155,7 +157,8 @@ pass5()
break;
default:
errexit("UNKNOWN ROTATIONAL TABLE FORMAT %d\n",
sumsize = 0; /* keep lint happy */
errx(EEXIT, "UNKNOWN ROTATIONAL TABLE FORMAT %d",
fs->fs_postblformat);
}
memset(&idesc[0], 0, sizeof idesc);
@ -228,8 +231,8 @@ pass5()
default:
if (j < ROOTINO)
break;
errexit("BAD STATE %d FOR INODE I=%ld",
statemap[j], j);
errx(EEXIT, "BAD STATE %d FOR INODE I=%ld",
statemap[j], (long)j);
}
}
if (c == 0)
@ -297,27 +300,27 @@ pass5()
cs = &fs->fs_cs(fs, c);
if (memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0 &&
dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
memcpy(cs, &newcg->cg_cs, sizeof *cs);
memmove(cs, &newcg->cg_cs, sizeof *cs);
sbdirty();
}
if (doinglevel1) {
memcpy(cg, newcg, (size_t)fs->fs_cgsize);
memmove(cg, newcg, (size_t)fs->fs_cgsize);
cgdirty();
continue;
}
if (memcmp(cg_inosused(newcg),
cg_inosused(cg), mapsize) != 0 &&
cg_inosused(cg), mapsize) != 0 &&
dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
memcpy(cg_inosused(cg), cg_inosused(newcg),
memmove(cg_inosused(cg), cg_inosused(newcg),
(size_t)mapsize);
cgdirty();
}
if ((memcmp(newcg, cg, basesize) != 0 ||
memcmp(&cg_blktot(newcg)[0],
&cg_blktot(cg)[0], sumsize) != 0) &&
&cg_blktot(cg)[0], sumsize) != 0) &&
dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
memcpy(cg, newcg, (size_t)basesize);
memcpy(&cg_blktot(cg)[0],
memmove(cg, newcg, (size_t)basesize);
memmove(&cg_blktot(cg)[0],
&cg_blktot(newcg)[0], (size_t)sumsize);
cgdirty();
}
@ -326,7 +329,7 @@ pass5()
fs->fs_nrpos = savednrpos;
if (memcmp(&cstotal, &fs->fs_cstotal, sizeof *cs) != 0
&& dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
memcpy(&fs->fs_cstotal, &cstotal, sizeof *cs);
memmove(&fs->fs_cstotal, &cstotal, sizeof *cs);
fs->fs_ronly = 0;
fs->fs_fmod = 0;
sbdirty();

View File

@ -1,4 +1,4 @@
/* $NetBSD: setup.c,v 1.29 1997/09/16 08:37:08 mrg Exp $ */
/* $NetBSD: setup.c,v 1.30 1997/09/16 16:45:33 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,27 +36,27 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)setup.c 8.5 (Berkeley) 11/23/94";
static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95";
#else
__RCSID("$NetBSD: setup.c,v 1.29 1997/09/16 08:37:08 mrg Exp $");
__RCSID("$NetBSD: setup.c,v 1.30 1997/09/16 16:45:33 lukem Exp $");
#endif
#endif /* not lint */
#define DKTYPENAMES
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/disklabel.h>
#include <sys/file.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <string.h>
#include "fsck.h"
#include "extern.h"
@ -66,11 +66,16 @@ struct bufarea asblk;
#define altsblock (*asblk.b_un.b_fs)
#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
void badsb __P((int, char *));
int calcsb __P((char *, int, struct fs *));
static void badsb __P((int, char *));
static int calcsb __P((char *, int, struct fs *));
static struct disklabel *getdisklabel __P((char *, int));
static int readsb __P((int));
/*
* Read in a superblock finding an alternate if necessary.
* Return 1 if successful, 0 if unsuccessful, -1 if filesystem
* is already clean (preen mode only).
*/
int
setup(dev)
char *dev;
@ -117,8 +122,8 @@ setup(dev)
sblk.b_un.b_buf = malloc(SBSIZE);
asblk.b_un.b_buf = malloc(SBSIZE);
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)
errx(EEXIT, "cannot allocate space for superblock");
if ((lp = getdisklabel(NULL, fsreadfd)) != NULL)
dev_bsize = secsize = lp->d_secsize;
else
dev_bsize = secsize = DEV_BSIZE;
@ -126,6 +131,7 @@ setup(dev)
* Read in the superblock, looking for alternates if necessary
*/
if (readsb(1) == 0) {
skipclean = 0;
if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
return(0);
if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
@ -321,7 +327,7 @@ setup(dev)
dirty(&asblk);
}
if (asblk.b_dirty && !bflag) {
memcpy(&altsblock, &sblock, (size_t)sblock.fs_sbsize);
memmove(&altsblock, &sblock, (size_t)sblock.fs_sbsize);
flush(fswritefd, &asblk);
}
/*
@ -337,7 +343,7 @@ setup(dev)
size) != 0 && !asked) {
pfatal("BAD SUMMARY INFORMATION");
if (reply("CONTINUE") == 0)
errexit("%s", "");
exit(EEXIT);
asked++;
}
}
@ -396,7 +402,7 @@ static int
readsb(listerr)
int listerr;
{
daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
ufs_daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
return (0);
@ -438,6 +444,7 @@ readsb(listerr)
return (0);
altsblock.fs_firstfield = sblock.fs_firstfield;
altsblock.fs_fscktime = sblock.fs_fscktime;
altsblock.fs_unused_1 = sblock.fs_unused_1;
altsblock.fs_time = sblock.fs_time;
altsblock.fs_cstotal = sblock.fs_cstotal;
altsblock.fs_cgrotor = sblock.fs_cgrotor;
@ -450,13 +457,11 @@ readsb(listerr)
altsblock.fs_optim = sblock.fs_optim;
altsblock.fs_rotdelay = sblock.fs_rotdelay;
altsblock.fs_maxbpg = sblock.fs_maxbpg;
memcpy(altsblock.fs_csp, sblock.fs_csp,
sizeof sblock.fs_csp);
memmove(altsblock.fs_csp, sblock.fs_csp, sizeof sblock.fs_csp);
altsblock.fs_maxcluster = sblock.fs_maxcluster;
memcpy(altsblock.fs_fsmnt, sblock.fs_fsmnt,
sizeof sblock.fs_fsmnt);
memcpy(altsblock.fs_sparecon, sblock.fs_sparecon,
sizeof sblock.fs_sparecon);
memmove(altsblock.fs_fsmnt, sblock.fs_fsmnt, sizeof sblock.fs_fsmnt);
memmove(altsblock.fs_sparecon,
sblock.fs_sparecon, sizeof sblock.fs_sparecon);
/*
* The following should not have to be copied.
*/
@ -492,7 +497,7 @@ readsb(listerr)
return (1);
}
void
static void
badsb(listerr, s)
int listerr;
char *s;
@ -511,7 +516,7 @@ badsb(listerr, s)
* can be used. Do NOT attempt to use other macros without verifying that
* their needed information is available!
*/
int
static int
calcsb(dev, devfd, fs)
char *dev;
int devfd;
@ -576,7 +581,7 @@ getdisklabel(s, fd)
if (s == NULL)
return ((struct disklabel *)NULL);
pwarn("ioctl (GCINFO): %s\n", strerror(errno));
errexit("%s: can't read disk label\n", s);
errx(EEXIT, "%s: can't read disk label", s);
}
return (&lab);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: utilities.c,v 1.19 1997/09/14 14:36:38 lukem Exp $ */
/* $NetBSD: utilities.c,v 1.20 1997/09/16 16:45:37 lukem Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -36,22 +36,22 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95";
#else
__RCSID("$NetBSD: utilities.c,v 1.19 1997/09/14 14:36:38 lukem Exp $");
__RCSID("$NetBSD: utilities.c,v 1.20 1997/09/16 16:45:37 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <err.h>
#include <string.h>
#include "fsutil.h"
#include "fsck.h"
@ -59,7 +59,7 @@ __RCSID("$NetBSD: utilities.c,v 1.19 1997/09/14 14:36:38 lukem Exp $");
long diskreads, totalreads; /* Disk cache statistics */
static void rwerror __P((char *, daddr_t));
static void rwerror __P((char *, ufs_daddr_t));
int
ftypeok(dp)
@ -129,7 +129,7 @@ bufinit()
pbp = pdirbp = (struct bufarea *)0;
bufp = malloc((unsigned int)sblock.fs_bsize);
if (bufp == 0)
errexit("cannot allocate buffer pool\n");
errx(EEXIT, "cannot allocate buffer pool");
cgblk.b_un.b_buf = bufp;
initbarea(&cgblk);
bufhead.b_next = bufhead.b_prev = &bufhead;
@ -142,7 +142,7 @@ bufinit()
if (bp == NULL || bufp == NULL) {
if (i >= MINBUFS)
break;
errexit("cannot allocate buffer pool\n");
errx(EEXIT, "cannot allocate buffer pool");
}
bp->b_un.b_buf = bufp;
bp->b_prev = &bufhead;
@ -159,7 +159,7 @@ bufinit()
*/
struct bufarea *
getdatablk(blkno, size)
daddr_t blkno;
ufs_daddr_t blkno;
long size;
{
struct bufarea *bp;
@ -171,7 +171,7 @@ getdatablk(blkno, size)
if ((bp->b_flags & B_INUSE) == 0)
break;
if (bp == &bufhead)
errexit("deadlocked buffer pool\n");
errx(EEXIT, "deadlocked buffer pool");
getblk(bp, blkno, size);
/* fall through */
foundit:
@ -189,10 +189,10 @@ foundit:
void
getblk(bp, blk, size)
struct bufarea *bp;
daddr_t blk;
ufs_daddr_t blk;
long size;
{
daddr_t dblk;
ufs_daddr_t dblk;
dblk = fsbtodb(&sblock, blk);
if (bp->b_bno != dblk) {
@ -233,14 +233,14 @@ flush(fd, bp)
static void
rwerror(mesg, blk)
char *mesg;
daddr_t blk;
ufs_daddr_t blk;
{
if (preen == 0)
printf("\n");
pfatal("CANNOT %s: BLK %d", mesg, blk);
if (reply("CONTINUE") == 0)
errexit("Program terminated\n");
exit(EEXIT);
}
void
@ -248,7 +248,7 @@ ckfini(markclean)
int markclean;
{
struct bufarea *bp, *nbp;
int cnt = 0;
int ofsmodified, cnt = 0;
if (fswritefd < 0) {
(void)close(fsreadfd);
@ -271,7 +271,7 @@ ckfini(markclean)
free((char *)bp);
}
if (bufhead.b_size != cnt)
errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt);
errx(EEXIT, "Panic: lost %d buffers", bufhead.b_size - cnt);
pbp = pdirbp = (struct bufarea *)0;
if (markclean && (sblock.fs_clean & FS_ISCLEAN) == 0) {
/*
@ -284,7 +284,12 @@ ckfini(markclean)
if (markclean) {
sblock.fs_clean = FS_ISCLEAN;
sbdirty();
ofsmodified = fsmodified;
flush(fswritefd, &sblk);
fsmodified = ofsmodified;
if (!preen)
printf(
"\n***** FILE SYSTEM MARKED CLEAN *****\n");
}
}
if (debug)
@ -298,7 +303,7 @@ int
bread(fd, buf, blk, size)
int fd;
char *buf;
daddr_t blk;
ufs_daddr_t blk;
long size;
{
char *cp;
@ -337,7 +342,7 @@ void
bwrite(fd, buf, blk, size)
int fd;
char *buf;
daddr_t blk;
ufs_daddr_t blk;
long size;
{
int i;
@ -370,7 +375,7 @@ bwrite(fd, buf, blk, size)
/*
* allocate a data block with the specified number of fragments
*/
int
ufs_daddr_t
allocblk(frags)
long frags;
{
@ -403,7 +408,7 @@ allocblk(frags)
*/
void
freeblk(blkno, frags)
daddr_t blkno;
ufs_daddr_t blkno;
long frags;
{
struct inodesc idesc;
@ -460,7 +465,7 @@ getpathname(namebuf, curdir, ino)
break;
len = strlen(namebuf);
cp -= len;
memcpy(cp, namebuf, (size_t)len);
memmove(cp, namebuf, (size_t)len);
*--cp = '/';
if (cp < &namebuf[MAXNAMLEN])
break;
@ -469,12 +474,12 @@ getpathname(namebuf, curdir, ino)
busy = 0;
if (ino != ROOTINO)
*--cp = '?';
memcpy(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp));
memmove(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp));
}
void
catch(n)
int n;
catch(sig)
int sig;
{
if (!doinglevel2)
ckfini(0);
@ -487,8 +492,8 @@ catch(n)
* so that reboot sequence may be interrupted.
*/
void
catchquit(n)
int n;
catchquit(sig)
int sig;
{
extern returntosingle;
@ -502,8 +507,8 @@ catchquit(n)
* Used by child processes in preen.
*/
void
voidquit(n)
int n;
voidquit(sig)
int sig;
{
sleep(1);
@ -547,7 +552,8 @@ dofix(idesc, msg)
return (0);
default:
errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
errx(EEXIT, "UNKNOWN INODESC FIX MODE %d", idesc->id_fix);
}
/* NOTREACHED */
return (0);
}