Submitted by: phk, added to by bde

Fix all the warnings from `gcc -Wall'.
This commit is contained in:
Bruce Evans 1995-04-02 14:52:29 +00:00
parent 15519b2f58
commit 31f4ab50bc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=7585
40 changed files with 797 additions and 226 deletions

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,6 +40,7 @@ static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
@ -56,12 +57,20 @@ struct odirtemplate odirhead = {
0, DIRBLKSIZ - 12, 2, ".." 0, DIRBLKSIZ - 12, 2, ".."
}; };
struct direct *fsck_readdir();
struct bufarea *getdirblk(); static int chgino __P((struct inodesc *idesc));
static int dircheck __P((struct inodesc *idesc, struct direct *dp));
static int expanddir __P((struct dinode *dp, char *name));
static void freedir __P((ino_t ino, ino_t parent));
static struct direct * fsck_readdir __P((struct inodesc *idesc));
static struct bufarea * getdirblk __P((daddr_t blkno, long size));
static int lftempname __P((char *bufp, ino_t ino));
static int mkentry __P((struct inodesc *idesc));
/* /*
* Propagate connected state through the tree. * Propagate connected state through the tree.
*/ */
void
propagate() propagate()
{ {
register struct inoinfo **inpp, *inp; register struct inoinfo **inpp, *inp;
@ -87,6 +96,7 @@ propagate()
/* /*
* Scan each entry in a directory block. * Scan each entry in a directory block.
*/ */
int
dirscan(idesc) dirscan(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {
@ -206,6 +216,7 @@ fsck_readdir(idesc)
* Verify that a directory entry is valid. * Verify that a directory entry is valid.
* This is a superset of the checks made in the kernel. * This is a superset of the checks made in the kernel.
*/ */
int
dircheck(idesc, dp) dircheck(idesc, dp)
struct inodesc *idesc; struct inodesc *idesc;
register struct direct *dp; register struct direct *dp;
@ -248,6 +259,7 @@ dircheck(idesc, dp)
return (0); return (0);
} }
void
direrror(ino, errmesg) direrror(ino, errmesg)
ino_t ino; ino_t ino;
char *errmesg; char *errmesg;
@ -256,6 +268,7 @@ direrror(ino, errmesg)
fileerror(ino, ino, errmesg); fileerror(ino, ino, errmesg);
} }
void
fileerror(cwd, ino, errmesg) fileerror(cwd, ino, errmesg)
ino_t cwd, ino; ino_t cwd, ino;
char *errmesg; char *errmesg;
@ -279,6 +292,7 @@ fileerror(cwd, ino, errmesg)
pfatal("NAME=%s\n", pathbuf); pfatal("NAME=%s\n", pathbuf);
} }
void
adjust(idesc, lcnt) adjust(idesc, lcnt)
register struct inodesc *idesc; register struct inodesc *idesc;
short lcnt; short lcnt;
@ -309,6 +323,7 @@ adjust(idesc, lcnt)
} }
} }
int
mkentry(idesc) mkentry(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -345,6 +360,7 @@ mkentry(idesc)
return (ALTERED|STOP); return (ALTERED|STOP);
} }
int
chgino(idesc) chgino(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -360,6 +376,7 @@ chgino(idesc)
return (ALTERED|STOP); return (ALTERED|STOP);
} }
int
linkup(orphan, parentdir) linkup(orphan, parentdir)
ino_t orphan; ino_t orphan;
ino_t parentdir; ino_t parentdir;
@ -369,7 +386,6 @@ linkup(orphan, parentdir)
ino_t oldlfdir; ino_t oldlfdir;
struct inodesc idesc; struct inodesc idesc;
char tempname[BUFSIZ]; char tempname[BUFSIZ];
extern int pass4check();
bzero((char *)&idesc, sizeof(struct inodesc)); bzero((char *)&idesc, sizeof(struct inodesc));
dp = ginode(orphan); dp = ginode(orphan);
@ -467,6 +483,7 @@ linkup(orphan, parentdir)
/* /*
* fix an entry in a directory. * fix an entry in a directory.
*/ */
int
changeino(dir, name, newnum) changeino(dir, name, newnum)
ino_t dir; ino_t dir;
char *name; char *name;
@ -487,6 +504,7 @@ changeino(dir, name, newnum)
/* /*
* make an entry in a directory * make an entry in a directory
*/ */
int
makeentry(parent, ino, name) makeentry(parent, ino, name)
ino_t parent, ino; ino_t parent, ino;
char *name; char *name;
@ -522,6 +540,7 @@ makeentry(parent, ino, name)
/* /*
* Attempt to expand the size of a directory * Attempt to expand the size of a directory
*/ */
int
expanddir(dp, name) expanddir(dp, name)
register struct dinode *dp; register struct dinode *dp;
char *name; char *name;
@ -578,6 +597,7 @@ expanddir(dp, name)
/* /*
* allocate a new directory * allocate a new directory
*/ */
int
allocdir(parent, request, mode) allocdir(parent, request, mode)
ino_t parent, request; ino_t parent, request;
int mode; int mode;
@ -633,6 +653,7 @@ allocdir(parent, request, mode)
/* /*
* free a directory inode * free a directory inode
*/ */
static void
freedir(ino, parent) freedir(ino, parent)
ino_t ino, parent; ino_t ino, parent;
{ {
@ -649,6 +670,7 @@ freedir(ino, parent)
/* /*
* generate a temporary name for the lost+found directory. * generate a temporary name for the lost+found directory.
*/ */
int
lftempname(bufp, ino) lftempname(bufp, ino)
char *bufp; char *bufp;
ino_t ino; ino_t ino;

View File

@ -179,13 +179,14 @@ char havesb; /* superblock has been read */
int fsmodified; /* 1 => write done to file system */ int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */ int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */ int fswritefd; /* file descriptor for writing file system */
int returntosingle; /* return to single user mode */
daddr_t maxfsblock; /* number of blocks in the file system */ daddr_t maxfsblock; /* number of blocks in the file system */
char *blockmap; /* ptr to primary blk allocation map */ char *blockmap; /* ptr to primary blk allocation map */
ino_t maxino; /* number of inodes in file system */ ino_t maxino; /* number of inodes in file system */
ino_t lastino; /* last inode in use */ ino_t lastino; /* last inode in use */
char *statemap; /* ptr to inode state table */ char *statemap; /* ptr to inode state table */
char *typemap; /* ptr to inode type table */ unsigned char *typemap; /* ptr to inode type table */
short *lncntp; /* ptr to link count table */ short *lncntp; /* ptr to link count table */
ino_t lfdir; /* lost & found directory inode number */ ino_t lfdir; /* lost & found directory inode number */
@ -208,9 +209,84 @@ struct dinode zino;
#define ALTERED 0x08 #define ALTERED 0x08
#define FOUND 0x10 #define FOUND 0x10
time_t time(); /* dir.c */
struct dinode *ginode(); void adjust __P((struct inodesc *idesc, short lcnt));
struct inoinfo *getinoinfo(); int allocdir __P((ino_t parent, ino_t request, int mode));
void getblk(); int changeino __P((ino_t dir, char *name, ino_t newnum));
ino_t allocino(); void direrror __P((ino_t ino, char *errmesg));
int findino(); int dirscan __P((struct inodesc *idesc));
void fileerror __P((ino_t cwd, ino_t ino, char *errmesg));
int linkup __P((ino_t orphan, ino_t parentdir));
int makeentry __P((ino_t parent, ino_t ino, char *name));
void propagate __P((void));
/* ffs_subr.c */
void ffs_fragacct __P((struct fs *fs, int fragmap, long *fraglist, int cnt));
/* inode.c */
ino_t allocino __P((ino_t request, int type));
void blkerror __P((ino_t ino, char *type, daddr_t blk));
void cacheino __P((struct dinode *dp, ino_t inumber));
int chkrange __P((daddr_t blk, int cnt));
int ckinode __P((struct dinode *dp, struct inodesc *idesc));
void clri __P((struct inodesc *idesc, char *type, int flag));
int findino __P((struct inodesc *idesc));
void freeino __P((ino_t ino));
void freeinodebuf __P((void));
struct dinode * ginode __P((ino_t inumber));
struct inoinfo * getinoinfo __P((ino_t inumber));
struct dinode * getnextinode __P((ino_t inumber));
void inodirty __P((void));
void inocleanup __P((void));
void pinode __P((ino_t ino));
void resetinodebuf __P((void));
int findname __P((struct inodesc *idesc));
/* pass1.c */
void pass1 __P((void));
int pass1check __P((struct inodesc *idesc));
/* pass1b.c */
void pass1b __P((void));
/* pass2.c */
void pass2 __P((void));
/* pass3.c */
void pass3 __P((void));
/* pass4.c */
void pass4 __P((void));
int pass4check __P((struct inodesc *idesc));
/* pass5.c */
void pass5 __P((void));
/* preen.c */
char *blockcheck __P((char *name));
int checkfstab __P((int preen, int maxrun,int (*docheck)(), int (*chkit)()));
/* setup.c */
int setup __P((char *dev));
/* utilities.c */
int allocblk __P((long frags));
int bread __P((int fd, char *buf, daddr_t blk, long size));
void bufinit __P((void));
void bwrite __P((int fd, char *buf, daddr_t blk, long size));
void catch __P((int));
void catchquit __P((int));
void ckfini __P((void));
int dofix __P((struct inodesc *idesc, char *msg));
__dead void errexit __P((const char *s1, ...)) __dead2;
void flush __P((int fd, struct bufarea *bp));
void freeblk __P((daddr_t blkno, long frags));
int ftypeok __P((struct dinode *dp));
void getblk __P((struct bufarea *bp, daddr_t blk, long size));
struct bufarea * getdatablk __P((daddr_t blkno, long size));
void getpathname __P((char *namebuf, ino_t curdir, ino_t ino));
__dead void panic __P((const char *, ...)) __dead2;
void pfatal __P((const char *s1, ...));
void pwarn __P((const char *s1, ...));
int reply __P((char *question));
void voidquit __P((int));

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95"; static const char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -41,12 +41,16 @@ static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
static ino_t startinum; static ino_t startinum;
static int iblock __P((struct inodesc *idesc, long ilevel, quad_t isize));
int
ckinode(dp, idesc) ckinode(dp, idesc)
struct dinode *dp; struct dinode *dp;
register struct inodesc *idesc; register struct inodesc *idesc;
@ -99,6 +103,7 @@ ckinode(dp, idesc)
return (KEEPON); return (KEEPON);
} }
static int
iblock(idesc, ilevel, isize) iblock(idesc, ilevel, isize)
struct inodesc *idesc; struct inodesc *idesc;
long ilevel; long ilevel;
@ -110,7 +115,6 @@ iblock(idesc, ilevel, isize)
int i, n, (*func)(), nif; int i, n, (*func)(), nif;
quad_t sizepb; quad_t sizepb;
char buf[BUFSIZ]; char buf[BUFSIZ];
extern int dirscan(), pass1check();
if (idesc->id_type == ADDR) { if (idesc->id_type == ADDR) {
func = idesc->id_func; func = idesc->id_func;
@ -164,6 +168,7 @@ iblock(idesc, ilevel, isize)
* Check that a block in a legal block number. * Check that a block in a legal block number.
* Return 0 if in range, 1 if out of range. * Return 0 if in range, 1 if out of range.
*/ */
int
chkrange(blk, cnt) chkrange(blk, cnt)
daddr_t blk; daddr_t blk;
int cnt; int cnt;
@ -253,6 +258,7 @@ getnextinode(inumber)
return (dp++); return (dp++);
} }
void
resetinodebuf() resetinodebuf()
{ {
@ -278,6 +284,7 @@ resetinodebuf()
(void)getnextinode(nextino); (void)getnextinode(nextino);
} }
void
freeinodebuf() freeinodebuf()
{ {
@ -293,6 +300,7 @@ freeinodebuf()
* *
* Enter inodes into the cache. * Enter inodes into the cache.
*/ */
void
cacheino(dp, inumber) cacheino(dp, inumber)
register struct dinode *dp; register struct dinode *dp;
ino_t inumber; ino_t inumber;
@ -352,6 +360,7 @@ getinoinfo(inumber)
/* /*
* Clean up all the inode cache structure. * Clean up all the inode cache structure.
*/ */
void
inocleanup() inocleanup()
{ {
register struct inoinfo **inpp; register struct inoinfo **inpp;
@ -365,12 +374,13 @@ inocleanup()
inphead = inpsort = NULL; inphead = inpsort = NULL;
} }
void
inodirty() inodirty()
{ {
dirty(pbp); dirty(pbp);
} }
void
clri(idesc, type, flag) clri(idesc, type, flag)
register struct inodesc *idesc; register struct inodesc *idesc;
char *type; char *type;
@ -395,6 +405,7 @@ clri(idesc, type, flag)
} }
} }
int
findname(idesc) findname(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -406,6 +417,7 @@ findname(idesc)
return (STOP|FOUND); return (STOP|FOUND);
} }
int
findino(idesc) findino(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -421,6 +433,7 @@ findino(idesc)
return (KEEPON); return (KEEPON);
} }
void
pinode(ino) pinode(ino)
ino_t ino; ino_t ino;
{ {
@ -446,6 +459,7 @@ pinode(ino)
printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
} }
void
blkerror(ino, type, blk) blkerror(ino, type, blk)
ino_t ino; ino_t ino;
char *type; char *type;
@ -526,11 +540,11 @@ allocino(request, type)
/* /*
* deallocate an inode * deallocate an inode
*/ */
void
freeino(ino) freeino(ino)
ino_t ino; ino_t ino;
{ {
struct inodesc idesc; struct inodesc idesc;
extern int pass4check();
struct dinode *dp; struct dinode *dp;
bzero((char *)&idesc, sizeof(struct inodesc)); bzero((char *)&idesc, sizeof(struct inodesc));

View File

@ -32,13 +32,13 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1980, 1986, 1993\n\ "@(#) Copyright (c) 1980, 1986, 1993\n\
The Regents of the University of California. All rights reserved.\n"; The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94"; static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -49,22 +49,24 @@ static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <fstab.h> #include <fstab.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include "fsck.h" #include "fsck.h"
static int argtoi __P((int flag, char *req, char *str, int base));
static int docheck __P((struct fstab *fsp));
static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
int child));
void catch(), catchquit(), voidquit(); int
int returntosingle;
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
int ch; int ch;
int ret, maxrun = 0; int ret, maxrun = 0;
extern int docheck(), checkfilesys(); extern char *optarg;
extern char *optarg, *blockcheck();
extern int optind; extern int optind;
sync(); sync();
@ -135,6 +137,7 @@ main(argc, argv)
exit(ret); exit(ret);
} }
int
argtoi(flag, req, str, base) argtoi(flag, req, str, base)
int flag; int flag;
char *req, *str; char *req, *str;
@ -152,6 +155,7 @@ argtoi(flag, req, str, base)
/* /*
* Determine whether a filesystem should be checked. * Determine whether a filesystem should be checked.
*/ */
int
docheck(fsp) docheck(fsp)
register struct fstab *fsp; register struct fstab *fsp;
{ {
@ -168,9 +172,11 @@ docheck(fsp)
* Check the specified filesystem. * Check the specified filesystem.
*/ */
/* ARGSUSED */ /* ARGSUSED */
int
checkfilesys(filesys, mntpt, auxdata, child) checkfilesys(filesys, mntpt, auxdata, child)
char *filesys, *mntpt; char *filesys, *mntpt;
long auxdata; long auxdata;
int child;
{ {
daddr_t n_ffree, n_bfree; daddr_t n_ffree, n_bfree;
struct dups *dp; struct dups *dp;
@ -255,7 +261,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
n_bfree = sblock.fs_cstotal.cs_nbfree; n_bfree = sblock.fs_cstotal.cs_nbfree;
pwarn("%ld files, %ld used, %ld free ", pwarn("%ld files, %ld used, %ld free ",
n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree); n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
printf("(%ld frags, %ld blocks, %d.%d%% fragmentation)\n", printf("(%ld frags, %ld blocks, %ld.%ld%% fragmentation)\n",
n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize, n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize,
((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10); ((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10);
if (debug && if (debug &&

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,15 +40,17 @@ static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
static daddr_t badblk; static daddr_t badblk;
static daddr_t dupblk; static daddr_t dupblk;
int pass1check();
struct dinode *getnextinode();
static void checkinode __P((ino_t inumber, struct inodesc *idesc));
void
pass1() pass1()
{ {
ino_t inumber; ino_t inumber;
@ -87,6 +89,7 @@ pass1()
freeinodebuf(); freeinodebuf();
} }
void
checkinode(inumber, idesc) checkinode(inumber, idesc)
ino_t inumber; ino_t inumber;
register struct inodesc *idesc; register struct inodesc *idesc;
@ -148,7 +151,7 @@ checkinode(inumber, idesc)
errexit("cannot read symlink"); errexit("cannot read symlink");
if (debug) { if (debug) {
symbuf[dp->di_size] = 0; symbuf[dp->di_size] = 0;
printf("convert symlink %d(%s) of size %d\n", printf("convert symlink %ld(%s) of size %ld\n",
inumber, symbuf, (long)dp->di_size); inumber, symbuf, (long)dp->di_size);
} }
dp = ginode(inumber); dp = ginode(inumber);
@ -247,6 +250,7 @@ checkinode(inumber, idesc)
} }
} }
int
pass1check(idesc) pass1check(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
int pass1bcheck(); int pass1bcheck();
static struct dups *duphead; static struct dups *duphead;
void
pass1b() pass1b()
{ {
register int c, i; register int c, i;
@ -72,6 +73,7 @@ pass1b()
} }
} }
int
pass1bcheck(idesc) pass1bcheck(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94"; static const char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,6 +40,7 @@ static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
@ -48,6 +49,7 @@ static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
int pass2check(), blksort(); int pass2check(), blksort();
void
pass2() pass2()
{ {
register struct dinode *dp; register struct dinode *dp;
@ -189,6 +191,7 @@ pass2()
propagate(); propagate();
} }
int
pass2check(idesc) pass2check(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -422,6 +425,7 @@ pass2check(idesc)
/* /*
* Routine to sort disk blocks. * Routine to sort disk blocks.
*/ */
int
blksort(inpp1, inpp2) blksort(inpp1, inpp2)
struct inoinfo **inpp1, **inpp2; struct inoinfo **inpp1, **inpp2;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -41,6 +41,7 @@ static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include "fsck.h" #include "fsck.h"
void
pass3() pass3()
{ {
register struct inoinfo **inpp, *inp; register struct inoinfo **inpp, *inp;

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
int pass4check(); int pass4check();
void
pass4() pass4()
{ {
register ino_t inumber; register ino_t inumber;
@ -103,6 +104,7 @@ pass4()
} }
} }
int
pass4check(idesc) pass4check(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,19 +32,21 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass5.c 8.2 (Berkeley) 2/2/94"; static const char sccsid[] = "@(#)pass5.c 8.2 (Berkeley) 2/2/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/time.h> #include <sys/time.h>
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
void
pass5() pass5()
{ {
int c, blk, frags, basesize, sumsize, mapsize, savednrpos; int c, blk, frags, basesize, sumsize, mapsize, savednrpos = 0;
register struct fs *fs = &sblock; register struct fs *fs = &sblock;
register struct cg *cg = &cgrp; register struct cg *cg = &cgrp;
daddr_t dbase, dmax; daddr_t dbase, dmax;

View File

@ -32,19 +32,20 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <ufs/ufs/dinode.h>
#include <fstab.h> #include <fstab.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h"
char *rawname(), *unrawname(), *blockcheck();
struct part { struct part {
struct part *next; /* forward link of partitions on disk */ struct part *next; /* forward link of partitions on disk */
@ -60,9 +61,16 @@ struct disk {
int pid; /* If != 0, pid of proc working on */ int pid; /* If != 0, pid of proc working on */
} *disks; } *disks;
static void addpart __P((char *name, char *fsname, long auxdata));
static int startdisk __P((struct disk *dk, int (*checkit)()));
static struct disk *finddisk __P((char *name));
static char *unrawname __P((char *name));
static char *rawname __P((char *name));
int nrun, ndisks; int nrun, ndisks;
char hotroot; char hotroot;
int
checkfstab(preen, maxrun, docheck, chkit) checkfstab(preen, maxrun, docheck, chkit)
int preen, maxrun; int preen, maxrun;
int (*docheck)(), (*chkit)(); int (*docheck)(), (*chkit)();
@ -84,10 +92,12 @@ checkfstab(preen, maxrun, docheck, chkit)
while ((fsp = getfsent()) != 0) { while ((fsp = getfsent()) != 0) {
if ((auxdata = (*docheck)(fsp)) == 0) if ((auxdata = (*docheck)(fsp)) == 0)
continue; continue;
if (preen == 0 || passno == 1 && fsp->fs_passno == 1) { if (!preen || (passno == 1 && fsp->fs_passno == 1)) {
if (name = blockcheck(fsp->fs_spec)) { name = blockcheck(fsp->fs_spec);
if (sumstatus = (*chkit)(name, if (name) {
fsp->fs_file, auxdata, 0)) sumstatus = (*chkit)(name,
fsp->fs_file, auxdata, 0);
if (sumstatus)
return (sumstatus); return (sumstatus);
} else if (preen) } else if (preen)
return (8); return (8);
@ -111,7 +121,8 @@ checkfstab(preen, maxrun, docheck, chkit)
maxrun = ndisks; maxrun = ndisks;
nextdisk = disks; nextdisk = disks;
for (passno = 0; passno < maxrun; ++passno) { for (passno = 0; passno < maxrun; ++passno) {
while (ret = startdisk(nextdisk, chkit) && nrun > 0) while ((ret = startdisk(nextdisk, chkit)) != 0 &&
nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -150,8 +161,8 @@ checkfstab(preen, maxrun, docheck, chkit)
if (nextdisk == NULL) { if (nextdisk == NULL) {
if (dk->part) { if (dk->part) {
while (ret = startdisk(dk, chkit) && while ((ret = startdisk(dk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -164,8 +175,8 @@ checkfstab(preen, maxrun, docheck, chkit)
nextdisk->pid == 0) nextdisk->pid == 0)
break; break;
} }
while (ret = startdisk(nextdisk, chkit) && while ((ret = startdisk(nextdisk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -192,7 +203,7 @@ finddisk(name)
{ {
register struct disk *dk, **dkp; register struct disk *dk, **dkp;
register char *p; register char *p;
size_t len; size_t len = 0;
for (p = name + strlen(name) - 1; p >= name; --p) for (p = name + strlen(name) - 1; p >= name; --p)
if (isdigit(*p)) { if (isdigit(*p)) {
@ -225,6 +236,7 @@ finddisk(name)
return (dk); return (dk);
} }
void
addpart(name, fsname, auxdata) addpart(name, fsname, auxdata)
char *name, *fsname; char *name, *fsname;
long auxdata; long auxdata;
@ -256,6 +268,7 @@ addpart(name, fsname, auxdata)
pt->auxdata = auxdata; pt->auxdata = auxdata;
} }
int
startdisk(dk, checkit) startdisk(dk, checkit)
register struct disk *dk; register struct disk *dk;
int (*checkit)(); int (*checkit)();

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94"; static const char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94";
#endif /* not lint */ #endif /* not lint */
#define DKTYPENAMES #define DKTYPENAMES
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94";
#include <sys/disklabel.h> #include <sys/disklabel.h>
#include <sys/file.h> #include <sys/file.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -54,8 +55,13 @@ struct bufarea asblk;
#define altsblock (*asblk.b_un.b_fs) #define altsblock (*asblk.b_un.b_fs)
#define POWEROF2(num) (((num) & ((num) - 1)) == 0) #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
struct disklabel *getdisklabel(); static int readsb __P((int listerr));
static void badsb __P((int listerr, char *s));
static int calcsb __P((char *dev, int devfd, struct fs *fs));
static struct disklabel * getdisklabel __P((char *s, int fd));
int
setup(dev) setup(dev)
char *dev; char *dev;
{ {
@ -99,7 +105,8 @@ setup(dev)
asblk.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) if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
errexit("cannot allocate space for superblock\n"); errexit("cannot allocate space for superblock\n");
if (lp = getdisklabel((char *)NULL, fsreadfd)) lp = getdisklabel((char *)NULL, fsreadfd);
if (lp)
dev_bsize = secsize = lp->d_secsize; dev_bsize = secsize = lp->d_secsize;
else else
dev_bsize = secsize = DEV_BSIZE; dev_bsize = secsize = DEV_BSIZE;
@ -297,6 +304,7 @@ setup(dev)
/* /*
* Read in the super block and its summary info. * Read in the super block and its summary info.
*/ */
static int
readsb(listerr) readsb(listerr)
int listerr; int listerr;
{ {
@ -380,6 +388,7 @@ readsb(listerr)
return (1); return (1);
} }
static void
badsb(listerr, s) badsb(listerr, s)
int listerr; int listerr;
char *s; char *s;
@ -398,6 +407,7 @@ badsb(listerr, s)
* can be used. Do NOT attempt to use other macros without verifying that * can be used. Do NOT attempt to use other macros without verifying that
* their needed information is available! * their needed information is available!
*/ */
int
calcsb(dev, devfd, fs) calcsb(dev, devfd, fs)
char *dev; char *dev;
int devfd; int devfd;
@ -409,7 +419,7 @@ calcsb(dev, devfd, fs)
int i; int i;
cp = index(dev, '\0') - 1; cp = index(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); pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
return (0); return (0);
} }

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -42,12 +42,17 @@ static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h" #include "fsck.h"
long diskreads, totalreads; /* Disk cache statistics */ long diskreads, totalreads; /* Disk cache statistics */
static void rwerror __P((char *mesg, daddr_t blk));
int
ftypeok(dp) ftypeok(dp)
struct dinode *dp; struct dinode *dp;
{ {
@ -69,6 +74,7 @@ ftypeok(dp)
} }
} }
int
reply(question) reply(question)
char *question; char *question;
{ {
@ -104,6 +110,7 @@ reply(question)
/* /*
* Malloc buffers and set up cache. * Malloc buffers and set up cache.
*/ */
void
bufinit() bufinit()
{ {
register struct bufarea *bp; register struct bufarea *bp;
@ -188,6 +195,7 @@ getblk(bp, blk, size)
} }
} }
void
flush(fd, bp) flush(fd, bp)
int fd; int fd;
register struct bufarea *bp; register struct bufarea *bp;
@ -213,6 +221,7 @@ flush(fd, bp)
} }
} }
void
rwerror(mesg, blk) rwerror(mesg, blk)
char *mesg; char *mesg;
daddr_t blk; daddr_t blk;
@ -225,6 +234,7 @@ rwerror(mesg, blk)
errexit("Program terminated\n"); errexit("Program terminated\n");
} }
void
ckfini() ckfini()
{ {
register struct bufarea *bp, *nbp; register struct bufarea *bp, *nbp;
@ -260,6 +270,7 @@ ckfini()
(void)close(fswritefd); (void)close(fswritefd);
} }
int
bread(fd, buf, blk, size) bread(fd, buf, blk, size)
int fd; int fd;
char *buf; char *buf;
@ -298,6 +309,7 @@ bread(fd, buf, blk, size)
return (errs); return (errs);
} }
void
bwrite(fd, buf, blk, size) bwrite(fd, buf, blk, size)
int fd; int fd;
char *buf; char *buf;
@ -334,6 +346,7 @@ bwrite(fd, buf, blk, size)
/* /*
* allocate a data block with the specified number of fragments * allocate a data block with the specified number of fragments
*/ */
int
allocblk(frags) allocblk(frags)
long frags; long frags;
{ {
@ -364,6 +377,7 @@ allocblk(frags)
/* /*
* Free a previously allocated block * Free a previously allocated block
*/ */
void
freeblk(blkno, frags) freeblk(blkno, frags)
daddr_t blkno; daddr_t blkno;
long frags; long frags;
@ -378,6 +392,7 @@ freeblk(blkno, frags)
/* /*
* Find a pathname * Find a pathname
*/ */
void
getpathname(namebuf, curdir, ino) getpathname(namebuf, curdir, ino)
char *namebuf; char *namebuf;
ino_t curdir, ino; ino_t curdir, ino;
@ -386,7 +401,6 @@ getpathname(namebuf, curdir, ino)
register char *cp; register char *cp;
struct inodesc idesc; struct inodesc idesc;
static int busy = 0; static int busy = 0;
extern int findname();
if (curdir == ino && ino == ROOTINO) { if (curdir == ino && ino == ROOTINO) {
(void)strcpy(namebuf, "/"); (void)strcpy(namebuf, "/");
@ -435,7 +449,8 @@ getpathname(namebuf, curdir, ino)
} }
void void
catch() catch(x)
int x;
{ {
if (!doinglevel2) if (!doinglevel2)
ckfini(); ckfini();
@ -448,10 +463,9 @@ catch()
* so that reboot sequence may be interrupted. * so that reboot sequence may be interrupted.
*/ */
void void
catchquit() catchquit(x)
int x;
{ {
extern returntosingle;
printf("returning to single-user after filesystem check\n"); printf("returning to single-user after filesystem check\n");
returntosingle = 1; returntosingle = 1;
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
@ -462,7 +476,8 @@ catchquit()
* Used by child processes in preen. * Used by child processes in preen.
*/ */
void void
voidquit() voidquit(x)
int x;
{ {
sleep(1); sleep(1);
@ -473,6 +488,7 @@ voidquit()
/* /*
* determine whether an inode should be fixed. * determine whether an inode should be fixed.
*/ */
int
dofix(idesc, msg) dofix(idesc, msg)
register struct inodesc *idesc; register struct inodesc *idesc;
char *msg; char *msg;
@ -506,15 +522,19 @@ dofix(idesc, msg)
default: default:
errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix); errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
return (0);
} }
/* NOTREACHED */ /* NOTREACHED */
} }
/* VARARGS1 */ /* VARARGS1 */
errexit(s1, s2, s3, s4) __dead void
char *s1; errexit(const char *s1, ...)
{ {
printf(s1, s2, s3, s4); va_list ap;
va_start(ap,s1);
vfprintf(stdout, s1, ap);
va_end(ap);
exit(8); exit(8);
} }
@ -523,19 +543,22 @@ errexit(s1, s2, s3, s4)
* Die if preening, otherwise just print message and continue. * Die if preening, otherwise just print message and continue.
*/ */
/* VARARGS1 */ /* VARARGS1 */
pfatal(s, a1, a2, a3) void
char *s; pfatal(const char *s, ...)
{ {
va_list ap;
va_start(ap,s);
if (preen) { if (preen) {
printf("%s: ", cdevname); printf("%s: ", cdevname);
printf(s, a1, a2, a3); vfprintf(stdout, s, ap);
printf("\n"); printf("\n");
printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n", printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n",
cdevname); cdevname);
exit(8); exit(8);
} }
printf(s, a1, a2, a3); vfprintf(stdout, s, ap);
va_end(ap);
} }
/* /*
@ -543,24 +566,31 @@ pfatal(s, a1, a2, a3)
* or a warning (preceded by filename) when preening. * or a warning (preceded by filename) when preening.
*/ */
/* VARARGS1 */ /* VARARGS1 */
pwarn(s, a1, a2, a3, a4, a5, a6) void
char *s; pwarn(const char *s, ...)
{ {
va_list ap;
va_start(ap,s);
if (preen) if (preen)
printf("%s: ", cdevname); printf("%s: ", cdevname);
printf(s, a1, a2, a3, a4, a5, a6); vfprintf(stdout, s, ap);
va_end(ap);
} }
#ifndef lint #ifndef lint
/* /*
* Stub for routines from kernel. * Stub for routines from kernel.
*/ */
panic(s) __dead void
char *s; #ifdef __STDC__
panic(const char *fmt, ...)
#else
panic(fmt, va_alist)
char *fmt;
#endif
{ {
pfatal("INTERNAL INCONSISTENCY:"); pfatal("INTERNAL INCONSISTENCY:");
errexit(s); errexit(fmt);
} }
#endif #endif

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,6 +40,7 @@ static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
@ -56,12 +57,20 @@ struct odirtemplate odirhead = {
0, DIRBLKSIZ - 12, 2, ".." 0, DIRBLKSIZ - 12, 2, ".."
}; };
struct direct *fsck_readdir();
struct bufarea *getdirblk(); static int chgino __P((struct inodesc *idesc));
static int dircheck __P((struct inodesc *idesc, struct direct *dp));
static int expanddir __P((struct dinode *dp, char *name));
static void freedir __P((ino_t ino, ino_t parent));
static struct direct * fsck_readdir __P((struct inodesc *idesc));
static struct bufarea * getdirblk __P((daddr_t blkno, long size));
static int lftempname __P((char *bufp, ino_t ino));
static int mkentry __P((struct inodesc *idesc));
/* /*
* Propagate connected state through the tree. * Propagate connected state through the tree.
*/ */
void
propagate() propagate()
{ {
register struct inoinfo **inpp, *inp; register struct inoinfo **inpp, *inp;
@ -87,6 +96,7 @@ propagate()
/* /*
* Scan each entry in a directory block. * Scan each entry in a directory block.
*/ */
int
dirscan(idesc) dirscan(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {
@ -206,6 +216,7 @@ fsck_readdir(idesc)
* Verify that a directory entry is valid. * Verify that a directory entry is valid.
* This is a superset of the checks made in the kernel. * This is a superset of the checks made in the kernel.
*/ */
int
dircheck(idesc, dp) dircheck(idesc, dp)
struct inodesc *idesc; struct inodesc *idesc;
register struct direct *dp; register struct direct *dp;
@ -248,6 +259,7 @@ dircheck(idesc, dp)
return (0); return (0);
} }
void
direrror(ino, errmesg) direrror(ino, errmesg)
ino_t ino; ino_t ino;
char *errmesg; char *errmesg;
@ -256,6 +268,7 @@ direrror(ino, errmesg)
fileerror(ino, ino, errmesg); fileerror(ino, ino, errmesg);
} }
void
fileerror(cwd, ino, errmesg) fileerror(cwd, ino, errmesg)
ino_t cwd, ino; ino_t cwd, ino;
char *errmesg; char *errmesg;
@ -279,6 +292,7 @@ fileerror(cwd, ino, errmesg)
pfatal("NAME=%s\n", pathbuf); pfatal("NAME=%s\n", pathbuf);
} }
void
adjust(idesc, lcnt) adjust(idesc, lcnt)
register struct inodesc *idesc; register struct inodesc *idesc;
short lcnt; short lcnt;
@ -309,6 +323,7 @@ adjust(idesc, lcnt)
} }
} }
int
mkentry(idesc) mkentry(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -345,6 +360,7 @@ mkentry(idesc)
return (ALTERED|STOP); return (ALTERED|STOP);
} }
int
chgino(idesc) chgino(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -360,6 +376,7 @@ chgino(idesc)
return (ALTERED|STOP); return (ALTERED|STOP);
} }
int
linkup(orphan, parentdir) linkup(orphan, parentdir)
ino_t orphan; ino_t orphan;
ino_t parentdir; ino_t parentdir;
@ -369,7 +386,6 @@ linkup(orphan, parentdir)
ino_t oldlfdir; ino_t oldlfdir;
struct inodesc idesc; struct inodesc idesc;
char tempname[BUFSIZ]; char tempname[BUFSIZ];
extern int pass4check();
bzero((char *)&idesc, sizeof(struct inodesc)); bzero((char *)&idesc, sizeof(struct inodesc));
dp = ginode(orphan); dp = ginode(orphan);
@ -467,6 +483,7 @@ linkup(orphan, parentdir)
/* /*
* fix an entry in a directory. * fix an entry in a directory.
*/ */
int
changeino(dir, name, newnum) changeino(dir, name, newnum)
ino_t dir; ino_t dir;
char *name; char *name;
@ -487,6 +504,7 @@ changeino(dir, name, newnum)
/* /*
* make an entry in a directory * make an entry in a directory
*/ */
int
makeentry(parent, ino, name) makeentry(parent, ino, name)
ino_t parent, ino; ino_t parent, ino;
char *name; char *name;
@ -522,6 +540,7 @@ makeentry(parent, ino, name)
/* /*
* Attempt to expand the size of a directory * Attempt to expand the size of a directory
*/ */
int
expanddir(dp, name) expanddir(dp, name)
register struct dinode *dp; register struct dinode *dp;
char *name; char *name;
@ -578,6 +597,7 @@ expanddir(dp, name)
/* /*
* allocate a new directory * allocate a new directory
*/ */
int
allocdir(parent, request, mode) allocdir(parent, request, mode)
ino_t parent, request; ino_t parent, request;
int mode; int mode;
@ -633,6 +653,7 @@ allocdir(parent, request, mode)
/* /*
* free a directory inode * free a directory inode
*/ */
static void
freedir(ino, parent) freedir(ino, parent)
ino_t ino, parent; ino_t ino, parent;
{ {
@ -649,6 +670,7 @@ freedir(ino, parent)
/* /*
* generate a temporary name for the lost+found directory. * generate a temporary name for the lost+found directory.
*/ */
int
lftempname(bufp, ino) lftempname(bufp, ino)
char *bufp; char *bufp;
ino_t ino; ino_t ino;

View File

@ -179,13 +179,14 @@ char havesb; /* superblock has been read */
int fsmodified; /* 1 => write done to file system */ int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */ int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */ int fswritefd; /* file descriptor for writing file system */
int returntosingle; /* return to single user mode */
daddr_t maxfsblock; /* number of blocks in the file system */ daddr_t maxfsblock; /* number of blocks in the file system */
char *blockmap; /* ptr to primary blk allocation map */ char *blockmap; /* ptr to primary blk allocation map */
ino_t maxino; /* number of inodes in file system */ ino_t maxino; /* number of inodes in file system */
ino_t lastino; /* last inode in use */ ino_t lastino; /* last inode in use */
char *statemap; /* ptr to inode state table */ char *statemap; /* ptr to inode state table */
char *typemap; /* ptr to inode type table */ unsigned char *typemap; /* ptr to inode type table */
short *lncntp; /* ptr to link count table */ short *lncntp; /* ptr to link count table */
ino_t lfdir; /* lost & found directory inode number */ ino_t lfdir; /* lost & found directory inode number */
@ -208,9 +209,84 @@ struct dinode zino;
#define ALTERED 0x08 #define ALTERED 0x08
#define FOUND 0x10 #define FOUND 0x10
time_t time(); /* dir.c */
struct dinode *ginode(); void adjust __P((struct inodesc *idesc, short lcnt));
struct inoinfo *getinoinfo(); int allocdir __P((ino_t parent, ino_t request, int mode));
void getblk(); int changeino __P((ino_t dir, char *name, ino_t newnum));
ino_t allocino(); void direrror __P((ino_t ino, char *errmesg));
int findino(); int dirscan __P((struct inodesc *idesc));
void fileerror __P((ino_t cwd, ino_t ino, char *errmesg));
int linkup __P((ino_t orphan, ino_t parentdir));
int makeentry __P((ino_t parent, ino_t ino, char *name));
void propagate __P((void));
/* ffs_subr.c */
void ffs_fragacct __P((struct fs *fs, int fragmap, long *fraglist, int cnt));
/* inode.c */
ino_t allocino __P((ino_t request, int type));
void blkerror __P((ino_t ino, char *type, daddr_t blk));
void cacheino __P((struct dinode *dp, ino_t inumber));
int chkrange __P((daddr_t blk, int cnt));
int ckinode __P((struct dinode *dp, struct inodesc *idesc));
void clri __P((struct inodesc *idesc, char *type, int flag));
int findino __P((struct inodesc *idesc));
void freeino __P((ino_t ino));
void freeinodebuf __P((void));
struct dinode * ginode __P((ino_t inumber));
struct inoinfo * getinoinfo __P((ino_t inumber));
struct dinode * getnextinode __P((ino_t inumber));
void inodirty __P((void));
void inocleanup __P((void));
void pinode __P((ino_t ino));
void resetinodebuf __P((void));
int findname __P((struct inodesc *idesc));
/* pass1.c */
void pass1 __P((void));
int pass1check __P((struct inodesc *idesc));
/* pass1b.c */
void pass1b __P((void));
/* pass2.c */
void pass2 __P((void));
/* pass3.c */
void pass3 __P((void));
/* pass4.c */
void pass4 __P((void));
int pass4check __P((struct inodesc *idesc));
/* pass5.c */
void pass5 __P((void));
/* preen.c */
char *blockcheck __P((char *name));
int checkfstab __P((int preen, int maxrun,int (*docheck)(), int (*chkit)()));
/* setup.c */
int setup __P((char *dev));
/* utilities.c */
int allocblk __P((long frags));
int bread __P((int fd, char *buf, daddr_t blk, long size));
void bufinit __P((void));
void bwrite __P((int fd, char *buf, daddr_t blk, long size));
void catch __P((int));
void catchquit __P((int));
void ckfini __P((void));
int dofix __P((struct inodesc *idesc, char *msg));
__dead void errexit __P((const char *s1, ...)) __dead2;
void flush __P((int fd, struct bufarea *bp));
void freeblk __P((daddr_t blkno, long frags));
int ftypeok __P((struct dinode *dp));
void getblk __P((struct bufarea *bp, daddr_t blk, long size));
struct bufarea * getdatablk __P((daddr_t blkno, long size));
void getpathname __P((char *namebuf, ino_t curdir, ino_t ino));
__dead void panic __P((const char *, ...)) __dead2;
void pfatal __P((const char *s1, ...));
void pwarn __P((const char *s1, ...));
int reply __P((char *question));
void voidquit __P((int));

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95"; static const char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -41,12 +41,16 @@ static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
static ino_t startinum; static ino_t startinum;
static int iblock __P((struct inodesc *idesc, long ilevel, quad_t isize));
int
ckinode(dp, idesc) ckinode(dp, idesc)
struct dinode *dp; struct dinode *dp;
register struct inodesc *idesc; register struct inodesc *idesc;
@ -99,6 +103,7 @@ ckinode(dp, idesc)
return (KEEPON); return (KEEPON);
} }
static int
iblock(idesc, ilevel, isize) iblock(idesc, ilevel, isize)
struct inodesc *idesc; struct inodesc *idesc;
long ilevel; long ilevel;
@ -110,7 +115,6 @@ iblock(idesc, ilevel, isize)
int i, n, (*func)(), nif; int i, n, (*func)(), nif;
quad_t sizepb; quad_t sizepb;
char buf[BUFSIZ]; char buf[BUFSIZ];
extern int dirscan(), pass1check();
if (idesc->id_type == ADDR) { if (idesc->id_type == ADDR) {
func = idesc->id_func; func = idesc->id_func;
@ -164,6 +168,7 @@ iblock(idesc, ilevel, isize)
* Check that a block in a legal block number. * Check that a block in a legal block number.
* Return 0 if in range, 1 if out of range. * Return 0 if in range, 1 if out of range.
*/ */
int
chkrange(blk, cnt) chkrange(blk, cnt)
daddr_t blk; daddr_t blk;
int cnt; int cnt;
@ -253,6 +258,7 @@ getnextinode(inumber)
return (dp++); return (dp++);
} }
void
resetinodebuf() resetinodebuf()
{ {
@ -278,6 +284,7 @@ resetinodebuf()
(void)getnextinode(nextino); (void)getnextinode(nextino);
} }
void
freeinodebuf() freeinodebuf()
{ {
@ -293,6 +300,7 @@ freeinodebuf()
* *
* Enter inodes into the cache. * Enter inodes into the cache.
*/ */
void
cacheino(dp, inumber) cacheino(dp, inumber)
register struct dinode *dp; register struct dinode *dp;
ino_t inumber; ino_t inumber;
@ -352,6 +360,7 @@ getinoinfo(inumber)
/* /*
* Clean up all the inode cache structure. * Clean up all the inode cache structure.
*/ */
void
inocleanup() inocleanup()
{ {
register struct inoinfo **inpp; register struct inoinfo **inpp;
@ -365,12 +374,13 @@ inocleanup()
inphead = inpsort = NULL; inphead = inpsort = NULL;
} }
void
inodirty() inodirty()
{ {
dirty(pbp); dirty(pbp);
} }
void
clri(idesc, type, flag) clri(idesc, type, flag)
register struct inodesc *idesc; register struct inodesc *idesc;
char *type; char *type;
@ -395,6 +405,7 @@ clri(idesc, type, flag)
} }
} }
int
findname(idesc) findname(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -406,6 +417,7 @@ findname(idesc)
return (STOP|FOUND); return (STOP|FOUND);
} }
int
findino(idesc) findino(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -421,6 +433,7 @@ findino(idesc)
return (KEEPON); return (KEEPON);
} }
void
pinode(ino) pinode(ino)
ino_t ino; ino_t ino;
{ {
@ -446,6 +459,7 @@ pinode(ino)
printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
} }
void
blkerror(ino, type, blk) blkerror(ino, type, blk)
ino_t ino; ino_t ino;
char *type; char *type;
@ -526,11 +540,11 @@ allocino(request, type)
/* /*
* deallocate an inode * deallocate an inode
*/ */
void
freeino(ino) freeino(ino)
ino_t ino; ino_t ino;
{ {
struct inodesc idesc; struct inodesc idesc;
extern int pass4check();
struct dinode *dp; struct dinode *dp;
bzero((char *)&idesc, sizeof(struct inodesc)); bzero((char *)&idesc, sizeof(struct inodesc));

View File

@ -32,13 +32,13 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1980, 1986, 1993\n\ "@(#) Copyright (c) 1980, 1986, 1993\n\
The Regents of the University of California. All rights reserved.\n"; The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94"; static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -49,22 +49,24 @@ static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <fstab.h> #include <fstab.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include "fsck.h" #include "fsck.h"
static int argtoi __P((int flag, char *req, char *str, int base));
static int docheck __P((struct fstab *fsp));
static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
int child));
void catch(), catchquit(), voidquit(); int
int returntosingle;
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
int ch; int ch;
int ret, maxrun = 0; int ret, maxrun = 0;
extern int docheck(), checkfilesys(); extern char *optarg;
extern char *optarg, *blockcheck();
extern int optind; extern int optind;
sync(); sync();
@ -135,6 +137,7 @@ main(argc, argv)
exit(ret); exit(ret);
} }
int
argtoi(flag, req, str, base) argtoi(flag, req, str, base)
int flag; int flag;
char *req, *str; char *req, *str;
@ -152,6 +155,7 @@ argtoi(flag, req, str, base)
/* /*
* Determine whether a filesystem should be checked. * Determine whether a filesystem should be checked.
*/ */
int
docheck(fsp) docheck(fsp)
register struct fstab *fsp; register struct fstab *fsp;
{ {
@ -168,9 +172,11 @@ docheck(fsp)
* Check the specified filesystem. * Check the specified filesystem.
*/ */
/* ARGSUSED */ /* ARGSUSED */
int
checkfilesys(filesys, mntpt, auxdata, child) checkfilesys(filesys, mntpt, auxdata, child)
char *filesys, *mntpt; char *filesys, *mntpt;
long auxdata; long auxdata;
int child;
{ {
daddr_t n_ffree, n_bfree; daddr_t n_ffree, n_bfree;
struct dups *dp; struct dups *dp;
@ -255,7 +261,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
n_bfree = sblock.fs_cstotal.cs_nbfree; n_bfree = sblock.fs_cstotal.cs_nbfree;
pwarn("%ld files, %ld used, %ld free ", pwarn("%ld files, %ld used, %ld free ",
n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree); n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
printf("(%ld frags, %ld blocks, %d.%d%% fragmentation)\n", printf("(%ld frags, %ld blocks, %ld.%ld%% fragmentation)\n",
n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize, n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize,
((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10); ((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10);
if (debug && if (debug &&

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,15 +40,17 @@ static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
static daddr_t badblk; static daddr_t badblk;
static daddr_t dupblk; static daddr_t dupblk;
int pass1check();
struct dinode *getnextinode();
static void checkinode __P((ino_t inumber, struct inodesc *idesc));
void
pass1() pass1()
{ {
ino_t inumber; ino_t inumber;
@ -87,6 +89,7 @@ pass1()
freeinodebuf(); freeinodebuf();
} }
void
checkinode(inumber, idesc) checkinode(inumber, idesc)
ino_t inumber; ino_t inumber;
register struct inodesc *idesc; register struct inodesc *idesc;
@ -148,7 +151,7 @@ checkinode(inumber, idesc)
errexit("cannot read symlink"); errexit("cannot read symlink");
if (debug) { if (debug) {
symbuf[dp->di_size] = 0; symbuf[dp->di_size] = 0;
printf("convert symlink %d(%s) of size %d\n", printf("convert symlink %ld(%s) of size %ld\n",
inumber, symbuf, (long)dp->di_size); inumber, symbuf, (long)dp->di_size);
} }
dp = ginode(inumber); dp = ginode(inumber);
@ -247,6 +250,7 @@ checkinode(inumber, idesc)
} }
} }
int
pass1check(idesc) pass1check(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
int pass1bcheck(); int pass1bcheck();
static struct dups *duphead; static struct dups *duphead;
void
pass1b() pass1b()
{ {
register int c, i; register int c, i;
@ -72,6 +73,7 @@ pass1b()
} }
} }
int
pass1bcheck(idesc) pass1bcheck(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94"; static const char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,6 +40,7 @@ static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
@ -48,6 +49,7 @@ static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
int pass2check(), blksort(); int pass2check(), blksort();
void
pass2() pass2()
{ {
register struct dinode *dp; register struct dinode *dp;
@ -189,6 +191,7 @@ pass2()
propagate(); propagate();
} }
int
pass2check(idesc) pass2check(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -422,6 +425,7 @@ pass2check(idesc)
/* /*
* Routine to sort disk blocks. * Routine to sort disk blocks.
*/ */
int
blksort(inpp1, inpp2) blksort(inpp1, inpp2)
struct inoinfo **inpp1, **inpp2; struct inoinfo **inpp1, **inpp2;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -41,6 +41,7 @@ static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include "fsck.h" #include "fsck.h"
void
pass3() pass3()
{ {
register struct inoinfo **inpp, *inp; register struct inoinfo **inpp, *inp;

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
int pass4check(); int pass4check();
void
pass4() pass4()
{ {
register ino_t inumber; register ino_t inumber;
@ -103,6 +104,7 @@ pass4()
} }
} }
int
pass4check(idesc) pass4check(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,19 +32,21 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass5.c 8.2 (Berkeley) 2/2/94"; static const char sccsid[] = "@(#)pass5.c 8.2 (Berkeley) 2/2/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/time.h> #include <sys/time.h>
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
void
pass5() pass5()
{ {
int c, blk, frags, basesize, sumsize, mapsize, savednrpos; int c, blk, frags, basesize, sumsize, mapsize, savednrpos = 0;
register struct fs *fs = &sblock; register struct fs *fs = &sblock;
register struct cg *cg = &cgrp; register struct cg *cg = &cgrp;
daddr_t dbase, dmax; daddr_t dbase, dmax;

View File

@ -32,19 +32,20 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <ufs/ufs/dinode.h>
#include <fstab.h> #include <fstab.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h"
char *rawname(), *unrawname(), *blockcheck();
struct part { struct part {
struct part *next; /* forward link of partitions on disk */ struct part *next; /* forward link of partitions on disk */
@ -60,9 +61,16 @@ struct disk {
int pid; /* If != 0, pid of proc working on */ int pid; /* If != 0, pid of proc working on */
} *disks; } *disks;
static void addpart __P((char *name, char *fsname, long auxdata));
static int startdisk __P((struct disk *dk, int (*checkit)()));
static struct disk *finddisk __P((char *name));
static char *unrawname __P((char *name));
static char *rawname __P((char *name));
int nrun, ndisks; int nrun, ndisks;
char hotroot; char hotroot;
int
checkfstab(preen, maxrun, docheck, chkit) checkfstab(preen, maxrun, docheck, chkit)
int preen, maxrun; int preen, maxrun;
int (*docheck)(), (*chkit)(); int (*docheck)(), (*chkit)();
@ -84,10 +92,12 @@ checkfstab(preen, maxrun, docheck, chkit)
while ((fsp = getfsent()) != 0) { while ((fsp = getfsent()) != 0) {
if ((auxdata = (*docheck)(fsp)) == 0) if ((auxdata = (*docheck)(fsp)) == 0)
continue; continue;
if (preen == 0 || passno == 1 && fsp->fs_passno == 1) { if (!preen || (passno == 1 && fsp->fs_passno == 1)) {
if (name = blockcheck(fsp->fs_spec)) { name = blockcheck(fsp->fs_spec);
if (sumstatus = (*chkit)(name, if (name) {
fsp->fs_file, auxdata, 0)) sumstatus = (*chkit)(name,
fsp->fs_file, auxdata, 0);
if (sumstatus)
return (sumstatus); return (sumstatus);
} else if (preen) } else if (preen)
return (8); return (8);
@ -111,7 +121,8 @@ checkfstab(preen, maxrun, docheck, chkit)
maxrun = ndisks; maxrun = ndisks;
nextdisk = disks; nextdisk = disks;
for (passno = 0; passno < maxrun; ++passno) { for (passno = 0; passno < maxrun; ++passno) {
while (ret = startdisk(nextdisk, chkit) && nrun > 0) while ((ret = startdisk(nextdisk, chkit)) != 0 &&
nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -150,8 +161,8 @@ checkfstab(preen, maxrun, docheck, chkit)
if (nextdisk == NULL) { if (nextdisk == NULL) {
if (dk->part) { if (dk->part) {
while (ret = startdisk(dk, chkit) && while ((ret = startdisk(dk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -164,8 +175,8 @@ checkfstab(preen, maxrun, docheck, chkit)
nextdisk->pid == 0) nextdisk->pid == 0)
break; break;
} }
while (ret = startdisk(nextdisk, chkit) && while ((ret = startdisk(nextdisk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -192,7 +203,7 @@ finddisk(name)
{ {
register struct disk *dk, **dkp; register struct disk *dk, **dkp;
register char *p; register char *p;
size_t len; size_t len = 0;
for (p = name + strlen(name) - 1; p >= name; --p) for (p = name + strlen(name) - 1; p >= name; --p)
if (isdigit(*p)) { if (isdigit(*p)) {
@ -225,6 +236,7 @@ finddisk(name)
return (dk); return (dk);
} }
void
addpart(name, fsname, auxdata) addpart(name, fsname, auxdata)
char *name, *fsname; char *name, *fsname;
long auxdata; long auxdata;
@ -256,6 +268,7 @@ addpart(name, fsname, auxdata)
pt->auxdata = auxdata; pt->auxdata = auxdata;
} }
int
startdisk(dk, checkit) startdisk(dk, checkit)
register struct disk *dk; register struct disk *dk;
int (*checkit)(); int (*checkit)();

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94"; static const char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94";
#endif /* not lint */ #endif /* not lint */
#define DKTYPENAMES #define DKTYPENAMES
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94";
#include <sys/disklabel.h> #include <sys/disklabel.h>
#include <sys/file.h> #include <sys/file.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -54,8 +55,13 @@ struct bufarea asblk;
#define altsblock (*asblk.b_un.b_fs) #define altsblock (*asblk.b_un.b_fs)
#define POWEROF2(num) (((num) & ((num) - 1)) == 0) #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
struct disklabel *getdisklabel(); static int readsb __P((int listerr));
static void badsb __P((int listerr, char *s));
static int calcsb __P((char *dev, int devfd, struct fs *fs));
static struct disklabel * getdisklabel __P((char *s, int fd));
int
setup(dev) setup(dev)
char *dev; char *dev;
{ {
@ -99,7 +105,8 @@ setup(dev)
asblk.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) if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
errexit("cannot allocate space for superblock\n"); errexit("cannot allocate space for superblock\n");
if (lp = getdisklabel((char *)NULL, fsreadfd)) lp = getdisklabel((char *)NULL, fsreadfd);
if (lp)
dev_bsize = secsize = lp->d_secsize; dev_bsize = secsize = lp->d_secsize;
else else
dev_bsize = secsize = DEV_BSIZE; dev_bsize = secsize = DEV_BSIZE;
@ -297,6 +304,7 @@ setup(dev)
/* /*
* Read in the super block and its summary info. * Read in the super block and its summary info.
*/ */
static int
readsb(listerr) readsb(listerr)
int listerr; int listerr;
{ {
@ -380,6 +388,7 @@ readsb(listerr)
return (1); return (1);
} }
static void
badsb(listerr, s) badsb(listerr, s)
int listerr; int listerr;
char *s; char *s;
@ -398,6 +407,7 @@ badsb(listerr, s)
* can be used. Do NOT attempt to use other macros without verifying that * can be used. Do NOT attempt to use other macros without verifying that
* their needed information is available! * their needed information is available!
*/ */
int
calcsb(dev, devfd, fs) calcsb(dev, devfd, fs)
char *dev; char *dev;
int devfd; int devfd;
@ -409,7 +419,7 @@ calcsb(dev, devfd, fs)
int i; int i;
cp = index(dev, '\0') - 1; cp = index(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); pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
return (0); return (0);
} }

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -42,12 +42,17 @@ static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h" #include "fsck.h"
long diskreads, totalreads; /* Disk cache statistics */ long diskreads, totalreads; /* Disk cache statistics */
static void rwerror __P((char *mesg, daddr_t blk));
int
ftypeok(dp) ftypeok(dp)
struct dinode *dp; struct dinode *dp;
{ {
@ -69,6 +74,7 @@ ftypeok(dp)
} }
} }
int
reply(question) reply(question)
char *question; char *question;
{ {
@ -104,6 +110,7 @@ reply(question)
/* /*
* Malloc buffers and set up cache. * Malloc buffers and set up cache.
*/ */
void
bufinit() bufinit()
{ {
register struct bufarea *bp; register struct bufarea *bp;
@ -188,6 +195,7 @@ getblk(bp, blk, size)
} }
} }
void
flush(fd, bp) flush(fd, bp)
int fd; int fd;
register struct bufarea *bp; register struct bufarea *bp;
@ -213,6 +221,7 @@ flush(fd, bp)
} }
} }
void
rwerror(mesg, blk) rwerror(mesg, blk)
char *mesg; char *mesg;
daddr_t blk; daddr_t blk;
@ -225,6 +234,7 @@ rwerror(mesg, blk)
errexit("Program terminated\n"); errexit("Program terminated\n");
} }
void
ckfini() ckfini()
{ {
register struct bufarea *bp, *nbp; register struct bufarea *bp, *nbp;
@ -260,6 +270,7 @@ ckfini()
(void)close(fswritefd); (void)close(fswritefd);
} }
int
bread(fd, buf, blk, size) bread(fd, buf, blk, size)
int fd; int fd;
char *buf; char *buf;
@ -298,6 +309,7 @@ bread(fd, buf, blk, size)
return (errs); return (errs);
} }
void
bwrite(fd, buf, blk, size) bwrite(fd, buf, blk, size)
int fd; int fd;
char *buf; char *buf;
@ -334,6 +346,7 @@ bwrite(fd, buf, blk, size)
/* /*
* allocate a data block with the specified number of fragments * allocate a data block with the specified number of fragments
*/ */
int
allocblk(frags) allocblk(frags)
long frags; long frags;
{ {
@ -364,6 +377,7 @@ allocblk(frags)
/* /*
* Free a previously allocated block * Free a previously allocated block
*/ */
void
freeblk(blkno, frags) freeblk(blkno, frags)
daddr_t blkno; daddr_t blkno;
long frags; long frags;
@ -378,6 +392,7 @@ freeblk(blkno, frags)
/* /*
* Find a pathname * Find a pathname
*/ */
void
getpathname(namebuf, curdir, ino) getpathname(namebuf, curdir, ino)
char *namebuf; char *namebuf;
ino_t curdir, ino; ino_t curdir, ino;
@ -386,7 +401,6 @@ getpathname(namebuf, curdir, ino)
register char *cp; register char *cp;
struct inodesc idesc; struct inodesc idesc;
static int busy = 0; static int busy = 0;
extern int findname();
if (curdir == ino && ino == ROOTINO) { if (curdir == ino && ino == ROOTINO) {
(void)strcpy(namebuf, "/"); (void)strcpy(namebuf, "/");
@ -435,7 +449,8 @@ getpathname(namebuf, curdir, ino)
} }
void void
catch() catch(x)
int x;
{ {
if (!doinglevel2) if (!doinglevel2)
ckfini(); ckfini();
@ -448,10 +463,9 @@ catch()
* so that reboot sequence may be interrupted. * so that reboot sequence may be interrupted.
*/ */
void void
catchquit() catchquit(x)
int x;
{ {
extern returntosingle;
printf("returning to single-user after filesystem check\n"); printf("returning to single-user after filesystem check\n");
returntosingle = 1; returntosingle = 1;
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
@ -462,7 +476,8 @@ catchquit()
* Used by child processes in preen. * Used by child processes in preen.
*/ */
void void
voidquit() voidquit(x)
int x;
{ {
sleep(1); sleep(1);
@ -473,6 +488,7 @@ voidquit()
/* /*
* determine whether an inode should be fixed. * determine whether an inode should be fixed.
*/ */
int
dofix(idesc, msg) dofix(idesc, msg)
register struct inodesc *idesc; register struct inodesc *idesc;
char *msg; char *msg;
@ -506,15 +522,19 @@ dofix(idesc, msg)
default: default:
errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix); errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
return (0);
} }
/* NOTREACHED */ /* NOTREACHED */
} }
/* VARARGS1 */ /* VARARGS1 */
errexit(s1, s2, s3, s4) __dead void
char *s1; errexit(const char *s1, ...)
{ {
printf(s1, s2, s3, s4); va_list ap;
va_start(ap,s1);
vfprintf(stdout, s1, ap);
va_end(ap);
exit(8); exit(8);
} }
@ -523,19 +543,22 @@ errexit(s1, s2, s3, s4)
* Die if preening, otherwise just print message and continue. * Die if preening, otherwise just print message and continue.
*/ */
/* VARARGS1 */ /* VARARGS1 */
pfatal(s, a1, a2, a3) void
char *s; pfatal(const char *s, ...)
{ {
va_list ap;
va_start(ap,s);
if (preen) { if (preen) {
printf("%s: ", cdevname); printf("%s: ", cdevname);
printf(s, a1, a2, a3); vfprintf(stdout, s, ap);
printf("\n"); printf("\n");
printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n", printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n",
cdevname); cdevname);
exit(8); exit(8);
} }
printf(s, a1, a2, a3); vfprintf(stdout, s, ap);
va_end(ap);
} }
/* /*
@ -543,24 +566,31 @@ pfatal(s, a1, a2, a3)
* or a warning (preceded by filename) when preening. * or a warning (preceded by filename) when preening.
*/ */
/* VARARGS1 */ /* VARARGS1 */
pwarn(s, a1, a2, a3, a4, a5, a6) void
char *s; pwarn(const char *s, ...)
{ {
va_list ap;
va_start(ap,s);
if (preen) if (preen)
printf("%s: ", cdevname); printf("%s: ", cdevname);
printf(s, a1, a2, a3, a4, a5, a6); vfprintf(stdout, s, ap);
va_end(ap);
} }
#ifndef lint #ifndef lint
/* /*
* Stub for routines from kernel. * Stub for routines from kernel.
*/ */
panic(s) __dead void
char *s; #ifdef __STDC__
panic(const char *fmt, ...)
#else
panic(fmt, va_alist)
char *fmt;
#endif
{ {
pfatal("INTERNAL INCONSISTENCY:"); pfatal("INTERNAL INCONSISTENCY:");
errexit(s); errexit(fmt);
} }
#endif #endif

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,6 +40,7 @@ static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
@ -56,12 +57,20 @@ struct odirtemplate odirhead = {
0, DIRBLKSIZ - 12, 2, ".." 0, DIRBLKSIZ - 12, 2, ".."
}; };
struct direct *fsck_readdir();
struct bufarea *getdirblk(); static int chgino __P((struct inodesc *idesc));
static int dircheck __P((struct inodesc *idesc, struct direct *dp));
static int expanddir __P((struct dinode *dp, char *name));
static void freedir __P((ino_t ino, ino_t parent));
static struct direct * fsck_readdir __P((struct inodesc *idesc));
static struct bufarea * getdirblk __P((daddr_t blkno, long size));
static int lftempname __P((char *bufp, ino_t ino));
static int mkentry __P((struct inodesc *idesc));
/* /*
* Propagate connected state through the tree. * Propagate connected state through the tree.
*/ */
void
propagate() propagate()
{ {
register struct inoinfo **inpp, *inp; register struct inoinfo **inpp, *inp;
@ -87,6 +96,7 @@ propagate()
/* /*
* Scan each entry in a directory block. * Scan each entry in a directory block.
*/ */
int
dirscan(idesc) dirscan(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {
@ -206,6 +216,7 @@ fsck_readdir(idesc)
* Verify that a directory entry is valid. * Verify that a directory entry is valid.
* This is a superset of the checks made in the kernel. * This is a superset of the checks made in the kernel.
*/ */
int
dircheck(idesc, dp) dircheck(idesc, dp)
struct inodesc *idesc; struct inodesc *idesc;
register struct direct *dp; register struct direct *dp;
@ -248,6 +259,7 @@ dircheck(idesc, dp)
return (0); return (0);
} }
void
direrror(ino, errmesg) direrror(ino, errmesg)
ino_t ino; ino_t ino;
char *errmesg; char *errmesg;
@ -256,6 +268,7 @@ direrror(ino, errmesg)
fileerror(ino, ino, errmesg); fileerror(ino, ino, errmesg);
} }
void
fileerror(cwd, ino, errmesg) fileerror(cwd, ino, errmesg)
ino_t cwd, ino; ino_t cwd, ino;
char *errmesg; char *errmesg;
@ -279,6 +292,7 @@ fileerror(cwd, ino, errmesg)
pfatal("NAME=%s\n", pathbuf); pfatal("NAME=%s\n", pathbuf);
} }
void
adjust(idesc, lcnt) adjust(idesc, lcnt)
register struct inodesc *idesc; register struct inodesc *idesc;
short lcnt; short lcnt;
@ -309,6 +323,7 @@ adjust(idesc, lcnt)
} }
} }
int
mkentry(idesc) mkentry(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -345,6 +360,7 @@ mkentry(idesc)
return (ALTERED|STOP); return (ALTERED|STOP);
} }
int
chgino(idesc) chgino(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -360,6 +376,7 @@ chgino(idesc)
return (ALTERED|STOP); return (ALTERED|STOP);
} }
int
linkup(orphan, parentdir) linkup(orphan, parentdir)
ino_t orphan; ino_t orphan;
ino_t parentdir; ino_t parentdir;
@ -369,7 +386,6 @@ linkup(orphan, parentdir)
ino_t oldlfdir; ino_t oldlfdir;
struct inodesc idesc; struct inodesc idesc;
char tempname[BUFSIZ]; char tempname[BUFSIZ];
extern int pass4check();
bzero((char *)&idesc, sizeof(struct inodesc)); bzero((char *)&idesc, sizeof(struct inodesc));
dp = ginode(orphan); dp = ginode(orphan);
@ -467,6 +483,7 @@ linkup(orphan, parentdir)
/* /*
* fix an entry in a directory. * fix an entry in a directory.
*/ */
int
changeino(dir, name, newnum) changeino(dir, name, newnum)
ino_t dir; ino_t dir;
char *name; char *name;
@ -487,6 +504,7 @@ changeino(dir, name, newnum)
/* /*
* make an entry in a directory * make an entry in a directory
*/ */
int
makeentry(parent, ino, name) makeentry(parent, ino, name)
ino_t parent, ino; ino_t parent, ino;
char *name; char *name;
@ -522,6 +540,7 @@ makeentry(parent, ino, name)
/* /*
* Attempt to expand the size of a directory * Attempt to expand the size of a directory
*/ */
int
expanddir(dp, name) expanddir(dp, name)
register struct dinode *dp; register struct dinode *dp;
char *name; char *name;
@ -578,6 +597,7 @@ expanddir(dp, name)
/* /*
* allocate a new directory * allocate a new directory
*/ */
int
allocdir(parent, request, mode) allocdir(parent, request, mode)
ino_t parent, request; ino_t parent, request;
int mode; int mode;
@ -633,6 +653,7 @@ allocdir(parent, request, mode)
/* /*
* free a directory inode * free a directory inode
*/ */
static void
freedir(ino, parent) freedir(ino, parent)
ino_t ino, parent; ino_t ino, parent;
{ {
@ -649,6 +670,7 @@ freedir(ino, parent)
/* /*
* generate a temporary name for the lost+found directory. * generate a temporary name for the lost+found directory.
*/ */
int
lftempname(bufp, ino) lftempname(bufp, ino)
char *bufp; char *bufp;
ino_t ino; ino_t ino;

View File

@ -179,13 +179,14 @@ char havesb; /* superblock has been read */
int fsmodified; /* 1 => write done to file system */ int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */ int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */ int fswritefd; /* file descriptor for writing file system */
int returntosingle; /* return to single user mode */
daddr_t maxfsblock; /* number of blocks in the file system */ daddr_t maxfsblock; /* number of blocks in the file system */
char *blockmap; /* ptr to primary blk allocation map */ char *blockmap; /* ptr to primary blk allocation map */
ino_t maxino; /* number of inodes in file system */ ino_t maxino; /* number of inodes in file system */
ino_t lastino; /* last inode in use */ ino_t lastino; /* last inode in use */
char *statemap; /* ptr to inode state table */ char *statemap; /* ptr to inode state table */
char *typemap; /* ptr to inode type table */ unsigned char *typemap; /* ptr to inode type table */
short *lncntp; /* ptr to link count table */ short *lncntp; /* ptr to link count table */
ino_t lfdir; /* lost & found directory inode number */ ino_t lfdir; /* lost & found directory inode number */
@ -208,9 +209,84 @@ struct dinode zino;
#define ALTERED 0x08 #define ALTERED 0x08
#define FOUND 0x10 #define FOUND 0x10
time_t time(); /* dir.c */
struct dinode *ginode(); void adjust __P((struct inodesc *idesc, short lcnt));
struct inoinfo *getinoinfo(); int allocdir __P((ino_t parent, ino_t request, int mode));
void getblk(); int changeino __P((ino_t dir, char *name, ino_t newnum));
ino_t allocino(); void direrror __P((ino_t ino, char *errmesg));
int findino(); int dirscan __P((struct inodesc *idesc));
void fileerror __P((ino_t cwd, ino_t ino, char *errmesg));
int linkup __P((ino_t orphan, ino_t parentdir));
int makeentry __P((ino_t parent, ino_t ino, char *name));
void propagate __P((void));
/* ffs_subr.c */
void ffs_fragacct __P((struct fs *fs, int fragmap, long *fraglist, int cnt));
/* inode.c */
ino_t allocino __P((ino_t request, int type));
void blkerror __P((ino_t ino, char *type, daddr_t blk));
void cacheino __P((struct dinode *dp, ino_t inumber));
int chkrange __P((daddr_t blk, int cnt));
int ckinode __P((struct dinode *dp, struct inodesc *idesc));
void clri __P((struct inodesc *idesc, char *type, int flag));
int findino __P((struct inodesc *idesc));
void freeino __P((ino_t ino));
void freeinodebuf __P((void));
struct dinode * ginode __P((ino_t inumber));
struct inoinfo * getinoinfo __P((ino_t inumber));
struct dinode * getnextinode __P((ino_t inumber));
void inodirty __P((void));
void inocleanup __P((void));
void pinode __P((ino_t ino));
void resetinodebuf __P((void));
int findname __P((struct inodesc *idesc));
/* pass1.c */
void pass1 __P((void));
int pass1check __P((struct inodesc *idesc));
/* pass1b.c */
void pass1b __P((void));
/* pass2.c */
void pass2 __P((void));
/* pass3.c */
void pass3 __P((void));
/* pass4.c */
void pass4 __P((void));
int pass4check __P((struct inodesc *idesc));
/* pass5.c */
void pass5 __P((void));
/* preen.c */
char *blockcheck __P((char *name));
int checkfstab __P((int preen, int maxrun,int (*docheck)(), int (*chkit)()));
/* setup.c */
int setup __P((char *dev));
/* utilities.c */
int allocblk __P((long frags));
int bread __P((int fd, char *buf, daddr_t blk, long size));
void bufinit __P((void));
void bwrite __P((int fd, char *buf, daddr_t blk, long size));
void catch __P((int));
void catchquit __P((int));
void ckfini __P((void));
int dofix __P((struct inodesc *idesc, char *msg));
__dead void errexit __P((const char *s1, ...)) __dead2;
void flush __P((int fd, struct bufarea *bp));
void freeblk __P((daddr_t blkno, long frags));
int ftypeok __P((struct dinode *dp));
void getblk __P((struct bufarea *bp, daddr_t blk, long size));
struct bufarea * getdatablk __P((daddr_t blkno, long size));
void getpathname __P((char *namebuf, ino_t curdir, ino_t ino));
__dead void panic __P((const char *, ...)) __dead2;
void pfatal __P((const char *s1, ...));
void pwarn __P((const char *s1, ...));
int reply __P((char *question));
void voidquit __P((int));

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95"; static const char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -41,12 +41,16 @@ static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
static ino_t startinum; static ino_t startinum;
static int iblock __P((struct inodesc *idesc, long ilevel, quad_t isize));
int
ckinode(dp, idesc) ckinode(dp, idesc)
struct dinode *dp; struct dinode *dp;
register struct inodesc *idesc; register struct inodesc *idesc;
@ -99,6 +103,7 @@ ckinode(dp, idesc)
return (KEEPON); return (KEEPON);
} }
static int
iblock(idesc, ilevel, isize) iblock(idesc, ilevel, isize)
struct inodesc *idesc; struct inodesc *idesc;
long ilevel; long ilevel;
@ -110,7 +115,6 @@ iblock(idesc, ilevel, isize)
int i, n, (*func)(), nif; int i, n, (*func)(), nif;
quad_t sizepb; quad_t sizepb;
char buf[BUFSIZ]; char buf[BUFSIZ];
extern int dirscan(), pass1check();
if (idesc->id_type == ADDR) { if (idesc->id_type == ADDR) {
func = idesc->id_func; func = idesc->id_func;
@ -164,6 +168,7 @@ iblock(idesc, ilevel, isize)
* Check that a block in a legal block number. * Check that a block in a legal block number.
* Return 0 if in range, 1 if out of range. * Return 0 if in range, 1 if out of range.
*/ */
int
chkrange(blk, cnt) chkrange(blk, cnt)
daddr_t blk; daddr_t blk;
int cnt; int cnt;
@ -253,6 +258,7 @@ getnextinode(inumber)
return (dp++); return (dp++);
} }
void
resetinodebuf() resetinodebuf()
{ {
@ -278,6 +284,7 @@ resetinodebuf()
(void)getnextinode(nextino); (void)getnextinode(nextino);
} }
void
freeinodebuf() freeinodebuf()
{ {
@ -293,6 +300,7 @@ freeinodebuf()
* *
* Enter inodes into the cache. * Enter inodes into the cache.
*/ */
void
cacheino(dp, inumber) cacheino(dp, inumber)
register struct dinode *dp; register struct dinode *dp;
ino_t inumber; ino_t inumber;
@ -352,6 +360,7 @@ getinoinfo(inumber)
/* /*
* Clean up all the inode cache structure. * Clean up all the inode cache structure.
*/ */
void
inocleanup() inocleanup()
{ {
register struct inoinfo **inpp; register struct inoinfo **inpp;
@ -365,12 +374,13 @@ inocleanup()
inphead = inpsort = NULL; inphead = inpsort = NULL;
} }
void
inodirty() inodirty()
{ {
dirty(pbp); dirty(pbp);
} }
void
clri(idesc, type, flag) clri(idesc, type, flag)
register struct inodesc *idesc; register struct inodesc *idesc;
char *type; char *type;
@ -395,6 +405,7 @@ clri(idesc, type, flag)
} }
} }
int
findname(idesc) findname(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -406,6 +417,7 @@ findname(idesc)
return (STOP|FOUND); return (STOP|FOUND);
} }
int
findino(idesc) findino(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -421,6 +433,7 @@ findino(idesc)
return (KEEPON); return (KEEPON);
} }
void
pinode(ino) pinode(ino)
ino_t ino; ino_t ino;
{ {
@ -446,6 +459,7 @@ pinode(ino)
printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
} }
void
blkerror(ino, type, blk) blkerror(ino, type, blk)
ino_t ino; ino_t ino;
char *type; char *type;
@ -526,11 +540,11 @@ allocino(request, type)
/* /*
* deallocate an inode * deallocate an inode
*/ */
void
freeino(ino) freeino(ino)
ino_t ino; ino_t ino;
{ {
struct inodesc idesc; struct inodesc idesc;
extern int pass4check();
struct dinode *dp; struct dinode *dp;
bzero((char *)&idesc, sizeof(struct inodesc)); bzero((char *)&idesc, sizeof(struct inodesc));

View File

@ -32,13 +32,13 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1980, 1986, 1993\n\ "@(#) Copyright (c) 1980, 1986, 1993\n\
The Regents of the University of California. All rights reserved.\n"; The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94"; static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -49,22 +49,24 @@ static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <fstab.h> #include <fstab.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include "fsck.h" #include "fsck.h"
static int argtoi __P((int flag, char *req, char *str, int base));
static int docheck __P((struct fstab *fsp));
static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
int child));
void catch(), catchquit(), voidquit(); int
int returntosingle;
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
int ch; int ch;
int ret, maxrun = 0; int ret, maxrun = 0;
extern int docheck(), checkfilesys(); extern char *optarg;
extern char *optarg, *blockcheck();
extern int optind; extern int optind;
sync(); sync();
@ -135,6 +137,7 @@ main(argc, argv)
exit(ret); exit(ret);
} }
int
argtoi(flag, req, str, base) argtoi(flag, req, str, base)
int flag; int flag;
char *req, *str; char *req, *str;
@ -152,6 +155,7 @@ argtoi(flag, req, str, base)
/* /*
* Determine whether a filesystem should be checked. * Determine whether a filesystem should be checked.
*/ */
int
docheck(fsp) docheck(fsp)
register struct fstab *fsp; register struct fstab *fsp;
{ {
@ -168,9 +172,11 @@ docheck(fsp)
* Check the specified filesystem. * Check the specified filesystem.
*/ */
/* ARGSUSED */ /* ARGSUSED */
int
checkfilesys(filesys, mntpt, auxdata, child) checkfilesys(filesys, mntpt, auxdata, child)
char *filesys, *mntpt; char *filesys, *mntpt;
long auxdata; long auxdata;
int child;
{ {
daddr_t n_ffree, n_bfree; daddr_t n_ffree, n_bfree;
struct dups *dp; struct dups *dp;
@ -255,7 +261,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
n_bfree = sblock.fs_cstotal.cs_nbfree; n_bfree = sblock.fs_cstotal.cs_nbfree;
pwarn("%ld files, %ld used, %ld free ", pwarn("%ld files, %ld used, %ld free ",
n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree); n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
printf("(%ld frags, %ld blocks, %d.%d%% fragmentation)\n", printf("(%ld frags, %ld blocks, %ld.%ld%% fragmentation)\n",
n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize, n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize,
((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10); ((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10);
if (debug && if (debug &&

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,15 +40,17 @@ static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
static daddr_t badblk; static daddr_t badblk;
static daddr_t dupblk; static daddr_t dupblk;
int pass1check();
struct dinode *getnextinode();
static void checkinode __P((ino_t inumber, struct inodesc *idesc));
void
pass1() pass1()
{ {
ino_t inumber; ino_t inumber;
@ -87,6 +89,7 @@ pass1()
freeinodebuf(); freeinodebuf();
} }
void
checkinode(inumber, idesc) checkinode(inumber, idesc)
ino_t inumber; ino_t inumber;
register struct inodesc *idesc; register struct inodesc *idesc;
@ -148,7 +151,7 @@ checkinode(inumber, idesc)
errexit("cannot read symlink"); errexit("cannot read symlink");
if (debug) { if (debug) {
symbuf[dp->di_size] = 0; symbuf[dp->di_size] = 0;
printf("convert symlink %d(%s) of size %d\n", printf("convert symlink %ld(%s) of size %ld\n",
inumber, symbuf, (long)dp->di_size); inumber, symbuf, (long)dp->di_size);
} }
dp = ginode(inumber); dp = ginode(inumber);
@ -247,6 +250,7 @@ checkinode(inumber, idesc)
} }
} }
int
pass1check(idesc) pass1check(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
int pass1bcheck(); int pass1bcheck();
static struct dups *duphead; static struct dups *duphead;
void
pass1b() pass1b()
{ {
register int c, i; register int c, i;
@ -72,6 +73,7 @@ pass1b()
} }
} }
int
pass1bcheck(idesc) pass1bcheck(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94"; static const char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -40,6 +40,7 @@ static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
@ -48,6 +49,7 @@ static char sccsid[] = "@(#)pass2.c 8.2 (Berkeley) 2/27/94";
int pass2check(), blksort(); int pass2check(), blksort();
void
pass2() pass2()
{ {
register struct dinode *dp; register struct dinode *dp;
@ -189,6 +191,7 @@ pass2()
propagate(); propagate();
} }
int
pass2check(idesc) pass2check(idesc)
struct inodesc *idesc; struct inodesc *idesc;
{ {
@ -422,6 +425,7 @@ pass2check(idesc)
/* /*
* Routine to sort disk blocks. * Routine to sort disk blocks.
*/ */
int
blksort(inpp1, inpp2) blksort(inpp1, inpp2)
struct inoinfo **inpp1, **inpp2; struct inoinfo **inpp1, **inpp2;
{ {

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -41,6 +41,7 @@ static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include "fsck.h" #include "fsck.h"
void
pass3() pass3()
{ {
register struct inoinfo **inpp, *inp; register struct inoinfo **inpp, *inp;

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
int pass4check(); int pass4check();
void
pass4() pass4()
{ {
register ino_t inumber; register ino_t inumber;
@ -103,6 +104,7 @@ pass4()
} }
} }
int
pass4check(idesc) pass4check(idesc)
register struct inodesc *idesc; register struct inodesc *idesc;
{ {

View File

@ -32,19 +32,21 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)pass5.c 8.2 (Berkeley) 2/2/94"; static const char sccsid[] = "@(#)pass5.c 8.2 (Berkeley) 2/2/94";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/time.h> #include <sys/time.h>
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "fsck.h" #include "fsck.h"
void
pass5() pass5()
{ {
int c, blk, frags, basesize, sumsize, mapsize, savednrpos; int c, blk, frags, basesize, sumsize, mapsize, savednrpos = 0;
register struct fs *fs = &sblock; register struct fs *fs = &sblock;
register struct cg *cg = &cgrp; register struct cg *cg = &cgrp;
daddr_t dbase, dmax; daddr_t dbase, dmax;

View File

@ -32,19 +32,20 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <ufs/ufs/dinode.h>
#include <fstab.h> #include <fstab.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h"
char *rawname(), *unrawname(), *blockcheck();
struct part { struct part {
struct part *next; /* forward link of partitions on disk */ struct part *next; /* forward link of partitions on disk */
@ -60,9 +61,16 @@ struct disk {
int pid; /* If != 0, pid of proc working on */ int pid; /* If != 0, pid of proc working on */
} *disks; } *disks;
static void addpart __P((char *name, char *fsname, long auxdata));
static int startdisk __P((struct disk *dk, int (*checkit)()));
static struct disk *finddisk __P((char *name));
static char *unrawname __P((char *name));
static char *rawname __P((char *name));
int nrun, ndisks; int nrun, ndisks;
char hotroot; char hotroot;
int
checkfstab(preen, maxrun, docheck, chkit) checkfstab(preen, maxrun, docheck, chkit)
int preen, maxrun; int preen, maxrun;
int (*docheck)(), (*chkit)(); int (*docheck)(), (*chkit)();
@ -84,10 +92,12 @@ checkfstab(preen, maxrun, docheck, chkit)
while ((fsp = getfsent()) != 0) { while ((fsp = getfsent()) != 0) {
if ((auxdata = (*docheck)(fsp)) == 0) if ((auxdata = (*docheck)(fsp)) == 0)
continue; continue;
if (preen == 0 || passno == 1 && fsp->fs_passno == 1) { if (!preen || (passno == 1 && fsp->fs_passno == 1)) {
if (name = blockcheck(fsp->fs_spec)) { name = blockcheck(fsp->fs_spec);
if (sumstatus = (*chkit)(name, if (name) {
fsp->fs_file, auxdata, 0)) sumstatus = (*chkit)(name,
fsp->fs_file, auxdata, 0);
if (sumstatus)
return (sumstatus); return (sumstatus);
} else if (preen) } else if (preen)
return (8); return (8);
@ -111,7 +121,8 @@ checkfstab(preen, maxrun, docheck, chkit)
maxrun = ndisks; maxrun = ndisks;
nextdisk = disks; nextdisk = disks;
for (passno = 0; passno < maxrun; ++passno) { for (passno = 0; passno < maxrun; ++passno) {
while (ret = startdisk(nextdisk, chkit) && nrun > 0) while ((ret = startdisk(nextdisk, chkit)) != 0 &&
nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -150,8 +161,8 @@ checkfstab(preen, maxrun, docheck, chkit)
if (nextdisk == NULL) { if (nextdisk == NULL) {
if (dk->part) { if (dk->part) {
while (ret = startdisk(dk, chkit) && while ((ret = startdisk(dk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -164,8 +175,8 @@ checkfstab(preen, maxrun, docheck, chkit)
nextdisk->pid == 0) nextdisk->pid == 0)
break; break;
} }
while (ret = startdisk(nextdisk, chkit) && while ((ret = startdisk(nextdisk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -192,7 +203,7 @@ finddisk(name)
{ {
register struct disk *dk, **dkp; register struct disk *dk, **dkp;
register char *p; register char *p;
size_t len; size_t len = 0;
for (p = name + strlen(name) - 1; p >= name; --p) for (p = name + strlen(name) - 1; p >= name; --p)
if (isdigit(*p)) { if (isdigit(*p)) {
@ -225,6 +236,7 @@ finddisk(name)
return (dk); return (dk);
} }
void
addpart(name, fsname, auxdata) addpart(name, fsname, auxdata)
char *name, *fsname; char *name, *fsname;
long auxdata; long auxdata;
@ -256,6 +268,7 @@ addpart(name, fsname, auxdata)
pt->auxdata = auxdata; pt->auxdata = auxdata;
} }
int
startdisk(dk, checkit) startdisk(dk, checkit)
register struct disk *dk; register struct disk *dk;
int (*checkit)(); int (*checkit)();

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94"; static const char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94";
#endif /* not lint */ #endif /* not lint */
#define DKTYPENAMES #define DKTYPENAMES
@ -45,6 +45,7 @@ static char sccsid[] = "@(#)setup.c 8.2 (Berkeley) 2/21/94";
#include <sys/disklabel.h> #include <sys/disklabel.h>
#include <sys/file.h> #include <sys/file.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -54,8 +55,13 @@ struct bufarea asblk;
#define altsblock (*asblk.b_un.b_fs) #define altsblock (*asblk.b_un.b_fs)
#define POWEROF2(num) (((num) & ((num) - 1)) == 0) #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
struct disklabel *getdisklabel(); static int readsb __P((int listerr));
static void badsb __P((int listerr, char *s));
static int calcsb __P((char *dev, int devfd, struct fs *fs));
static struct disklabel * getdisklabel __P((char *s, int fd));
int
setup(dev) setup(dev)
char *dev; char *dev;
{ {
@ -99,7 +105,8 @@ setup(dev)
asblk.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) if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
errexit("cannot allocate space for superblock\n"); errexit("cannot allocate space for superblock\n");
if (lp = getdisklabel((char *)NULL, fsreadfd)) lp = getdisklabel((char *)NULL, fsreadfd);
if (lp)
dev_bsize = secsize = lp->d_secsize; dev_bsize = secsize = lp->d_secsize;
else else
dev_bsize = secsize = DEV_BSIZE; dev_bsize = secsize = DEV_BSIZE;
@ -297,6 +304,7 @@ setup(dev)
/* /*
* Read in the super block and its summary info. * Read in the super block and its summary info.
*/ */
static int
readsb(listerr) readsb(listerr)
int listerr; int listerr;
{ {
@ -380,6 +388,7 @@ readsb(listerr)
return (1); return (1);
} }
static void
badsb(listerr, s) badsb(listerr, s)
int listerr; int listerr;
char *s; char *s;
@ -398,6 +407,7 @@ badsb(listerr, s)
* can be used. Do NOT attempt to use other macros without verifying that * can be used. Do NOT attempt to use other macros without verifying that
* their needed information is available! * their needed information is available!
*/ */
int
calcsb(dev, devfd, fs) calcsb(dev, devfd, fs)
char *dev; char *dev;
int devfd; int devfd;
@ -409,7 +419,7 @@ calcsb(dev, devfd, fs)
int i; int i;
cp = index(dev, '\0') - 1; cp = index(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); pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
return (0); return (0);
} }

View File

@ -32,7 +32,7 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -42,12 +42,17 @@ static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h" #include "fsck.h"
long diskreads, totalreads; /* Disk cache statistics */ long diskreads, totalreads; /* Disk cache statistics */
static void rwerror __P((char *mesg, daddr_t blk));
int
ftypeok(dp) ftypeok(dp)
struct dinode *dp; struct dinode *dp;
{ {
@ -69,6 +74,7 @@ ftypeok(dp)
} }
} }
int
reply(question) reply(question)
char *question; char *question;
{ {
@ -104,6 +110,7 @@ reply(question)
/* /*
* Malloc buffers and set up cache. * Malloc buffers and set up cache.
*/ */
void
bufinit() bufinit()
{ {
register struct bufarea *bp; register struct bufarea *bp;
@ -188,6 +195,7 @@ getblk(bp, blk, size)
} }
} }
void
flush(fd, bp) flush(fd, bp)
int fd; int fd;
register struct bufarea *bp; register struct bufarea *bp;
@ -213,6 +221,7 @@ flush(fd, bp)
} }
} }
void
rwerror(mesg, blk) rwerror(mesg, blk)
char *mesg; char *mesg;
daddr_t blk; daddr_t blk;
@ -225,6 +234,7 @@ rwerror(mesg, blk)
errexit("Program terminated\n"); errexit("Program terminated\n");
} }
void
ckfini() ckfini()
{ {
register struct bufarea *bp, *nbp; register struct bufarea *bp, *nbp;
@ -260,6 +270,7 @@ ckfini()
(void)close(fswritefd); (void)close(fswritefd);
} }
int
bread(fd, buf, blk, size) bread(fd, buf, blk, size)
int fd; int fd;
char *buf; char *buf;
@ -298,6 +309,7 @@ bread(fd, buf, blk, size)
return (errs); return (errs);
} }
void
bwrite(fd, buf, blk, size) bwrite(fd, buf, blk, size)
int fd; int fd;
char *buf; char *buf;
@ -334,6 +346,7 @@ bwrite(fd, buf, blk, size)
/* /*
* allocate a data block with the specified number of fragments * allocate a data block with the specified number of fragments
*/ */
int
allocblk(frags) allocblk(frags)
long frags; long frags;
{ {
@ -364,6 +377,7 @@ allocblk(frags)
/* /*
* Free a previously allocated block * Free a previously allocated block
*/ */
void
freeblk(blkno, frags) freeblk(blkno, frags)
daddr_t blkno; daddr_t blkno;
long frags; long frags;
@ -378,6 +392,7 @@ freeblk(blkno, frags)
/* /*
* Find a pathname * Find a pathname
*/ */
void
getpathname(namebuf, curdir, ino) getpathname(namebuf, curdir, ino)
char *namebuf; char *namebuf;
ino_t curdir, ino; ino_t curdir, ino;
@ -386,7 +401,6 @@ getpathname(namebuf, curdir, ino)
register char *cp; register char *cp;
struct inodesc idesc; struct inodesc idesc;
static int busy = 0; static int busy = 0;
extern int findname();
if (curdir == ino && ino == ROOTINO) { if (curdir == ino && ino == ROOTINO) {
(void)strcpy(namebuf, "/"); (void)strcpy(namebuf, "/");
@ -435,7 +449,8 @@ getpathname(namebuf, curdir, ino)
} }
void void
catch() catch(x)
int x;
{ {
if (!doinglevel2) if (!doinglevel2)
ckfini(); ckfini();
@ -448,10 +463,9 @@ catch()
* so that reboot sequence may be interrupted. * so that reboot sequence may be interrupted.
*/ */
void void
catchquit() catchquit(x)
int x;
{ {
extern returntosingle;
printf("returning to single-user after filesystem check\n"); printf("returning to single-user after filesystem check\n");
returntosingle = 1; returntosingle = 1;
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
@ -462,7 +476,8 @@ catchquit()
* Used by child processes in preen. * Used by child processes in preen.
*/ */
void void
voidquit() voidquit(x)
int x;
{ {
sleep(1); sleep(1);
@ -473,6 +488,7 @@ voidquit()
/* /*
* determine whether an inode should be fixed. * determine whether an inode should be fixed.
*/ */
int
dofix(idesc, msg) dofix(idesc, msg)
register struct inodesc *idesc; register struct inodesc *idesc;
char *msg; char *msg;
@ -506,15 +522,19 @@ dofix(idesc, msg)
default: default:
errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix); errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
return (0);
} }
/* NOTREACHED */ /* NOTREACHED */
} }
/* VARARGS1 */ /* VARARGS1 */
errexit(s1, s2, s3, s4) __dead void
char *s1; errexit(const char *s1, ...)
{ {
printf(s1, s2, s3, s4); va_list ap;
va_start(ap,s1);
vfprintf(stdout, s1, ap);
va_end(ap);
exit(8); exit(8);
} }
@ -523,19 +543,22 @@ errexit(s1, s2, s3, s4)
* Die if preening, otherwise just print message and continue. * Die if preening, otherwise just print message and continue.
*/ */
/* VARARGS1 */ /* VARARGS1 */
pfatal(s, a1, a2, a3) void
char *s; pfatal(const char *s, ...)
{ {
va_list ap;
va_start(ap,s);
if (preen) { if (preen) {
printf("%s: ", cdevname); printf("%s: ", cdevname);
printf(s, a1, a2, a3); vfprintf(stdout, s, ap);
printf("\n"); printf("\n");
printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n", printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n",
cdevname); cdevname);
exit(8); exit(8);
} }
printf(s, a1, a2, a3); vfprintf(stdout, s, ap);
va_end(ap);
} }
/* /*
@ -543,24 +566,31 @@ pfatal(s, a1, a2, a3)
* or a warning (preceded by filename) when preening. * or a warning (preceded by filename) when preening.
*/ */
/* VARARGS1 */ /* VARARGS1 */
pwarn(s, a1, a2, a3, a4, a5, a6) void
char *s; pwarn(const char *s, ...)
{ {
va_list ap;
va_start(ap,s);
if (preen) if (preen)
printf("%s: ", cdevname); printf("%s: ", cdevname);
printf(s, a1, a2, a3, a4, a5, a6); vfprintf(stdout, s, ap);
va_end(ap);
} }
#ifndef lint #ifndef lint
/* /*
* Stub for routines from kernel. * Stub for routines from kernel.
*/ */
panic(s) __dead void
char *s; #ifdef __STDC__
panic(const char *fmt, ...)
#else
panic(fmt, va_alist)
char *fmt;
#endif
{ {
pfatal("INTERNAL INCONSISTENCY:"); pfatal("INTERNAL INCONSISTENCY:");
errexit(s); errexit(fmt);
} }
#endif #endif

View File

@ -32,19 +32,20 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93"; static const char sccsid[] = "@(#)preen.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <ufs/ufs/dinode.h>
#include <fstab.h> #include <fstab.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include "fsck.h"
char *rawname(), *unrawname(), *blockcheck();
struct part { struct part {
struct part *next; /* forward link of partitions on disk */ struct part *next; /* forward link of partitions on disk */
@ -60,9 +61,16 @@ struct disk {
int pid; /* If != 0, pid of proc working on */ int pid; /* If != 0, pid of proc working on */
} *disks; } *disks;
static void addpart __P((char *name, char *fsname, long auxdata));
static int startdisk __P((struct disk *dk, int (*checkit)()));
static struct disk *finddisk __P((char *name));
static char *unrawname __P((char *name));
static char *rawname __P((char *name));
int nrun, ndisks; int nrun, ndisks;
char hotroot; char hotroot;
int
checkfstab(preen, maxrun, docheck, chkit) checkfstab(preen, maxrun, docheck, chkit)
int preen, maxrun; int preen, maxrun;
int (*docheck)(), (*chkit)(); int (*docheck)(), (*chkit)();
@ -84,10 +92,12 @@ checkfstab(preen, maxrun, docheck, chkit)
while ((fsp = getfsent()) != 0) { while ((fsp = getfsent()) != 0) {
if ((auxdata = (*docheck)(fsp)) == 0) if ((auxdata = (*docheck)(fsp)) == 0)
continue; continue;
if (preen == 0 || passno == 1 && fsp->fs_passno == 1) { if (!preen || (passno == 1 && fsp->fs_passno == 1)) {
if (name = blockcheck(fsp->fs_spec)) { name = blockcheck(fsp->fs_spec);
if (sumstatus = (*chkit)(name, if (name) {
fsp->fs_file, auxdata, 0)) sumstatus = (*chkit)(name,
fsp->fs_file, auxdata, 0);
if (sumstatus)
return (sumstatus); return (sumstatus);
} else if (preen) } else if (preen)
return (8); return (8);
@ -111,7 +121,8 @@ checkfstab(preen, maxrun, docheck, chkit)
maxrun = ndisks; maxrun = ndisks;
nextdisk = disks; nextdisk = disks;
for (passno = 0; passno < maxrun; ++passno) { for (passno = 0; passno < maxrun; ++passno) {
while (ret = startdisk(nextdisk, chkit) && nrun > 0) while ((ret = startdisk(nextdisk, chkit)) != 0 &&
nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -150,8 +161,8 @@ checkfstab(preen, maxrun, docheck, chkit)
if (nextdisk == NULL) { if (nextdisk == NULL) {
if (dk->part) { if (dk->part) {
while (ret = startdisk(dk, chkit) && while ((ret = startdisk(dk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -164,8 +175,8 @@ checkfstab(preen, maxrun, docheck, chkit)
nextdisk->pid == 0) nextdisk->pid == 0)
break; break;
} }
while (ret = startdisk(nextdisk, chkit) && while ((ret = startdisk(nextdisk, chkit)) != 0
nrun > 0) && nrun > 0)
sleep(10); sleep(10);
if (ret) if (ret)
return (ret); return (ret);
@ -192,7 +203,7 @@ finddisk(name)
{ {
register struct disk *dk, **dkp; register struct disk *dk, **dkp;
register char *p; register char *p;
size_t len; size_t len = 0;
for (p = name + strlen(name) - 1; p >= name; --p) for (p = name + strlen(name) - 1; p >= name; --p)
if (isdigit(*p)) { if (isdigit(*p)) {
@ -225,6 +236,7 @@ finddisk(name)
return (dk); return (dk);
} }
void
addpart(name, fsname, auxdata) addpart(name, fsname, auxdata)
char *name, *fsname; char *name, *fsname;
long auxdata; long auxdata;
@ -256,6 +268,7 @@ addpart(name, fsname, auxdata)
pt->auxdata = auxdata; pt->auxdata = auxdata;
} }
int
startdisk(dk, checkit) startdisk(dk, checkit)
register struct disk *dk; register struct disk *dk;
int (*checkit)(); int (*checkit)();