- Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h> - Change checkfstab so that the checkit function takes the name of the mount point too (needed by quotacheck). - Remove globals debug, verbose and preen
This commit is contained in:
parent
d1bae5c5d5
commit
7dfca7604a
|
@ -1,7 +1,7 @@
|
|||
# $NetBSD: Makefile,v 1.13 1996/09/23 16:11:32 christos Exp $
|
||||
# $NetBSD: Makefile,v 1.14 1996/09/27 22:38:37 christos Exp $
|
||||
|
||||
PROG= fsck
|
||||
SRCS= fsck.c util.c preen.c
|
||||
SRCS= fsck.c fsutil.c preen.c
|
||||
MAN= fsck.8
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/* $NetBSD: extern.h,v 1.6 1996/09/23 16:11:32 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Christos Zoulas.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
extern int debug, verbose;
|
||||
|
||||
int checkfstab __P((int, int, int (*)(struct fstab *),
|
||||
int (*) (const char *, const char *, pid_t *)));
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: fsck.c,v 1.3 1996/09/27 21:51:03 cgd Exp $ */
|
||||
/* $NetBSD: fsck.c,v 1.4 1996/09/27 22:38:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
|
||||
|
@ -38,7 +38,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
static char rcsid[] = "$NetBSD: fsck.c,v 1.3 1996/09/27 21:51:03 cgd Exp $";
|
||||
static char rcsid[] = "$NetBSD: fsck.c,v 1.4 1996/09/27 22:38:40 christos Exp $";
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
|
@ -55,8 +55,7 @@ static char rcsid[] = "$NetBSD: fsck.c,v 1.3 1996/09/27 21:51:03 cgd Exp $";
|
|||
#include <unistd.h>
|
||||
|
||||
#include "pathnames.h"
|
||||
#include "extern.h"
|
||||
#include "util.h"
|
||||
#include "fsutil.h"
|
||||
|
||||
static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
|
||||
|
||||
|
@ -68,13 +67,13 @@ struct entry {
|
|||
TAILQ_ENTRY(entry) entries;
|
||||
};
|
||||
|
||||
static int preen = 0, maxrun = 0;
|
||||
int debug = 0, verbose = 0;
|
||||
static int maxrun = 0;
|
||||
static char *options = NULL;
|
||||
static int flags = 0;
|
||||
|
||||
int main __P((int, char *[]));
|
||||
|
||||
static int checkfs __P((const char *, const char *, pid_t *));
|
||||
static int checkfs __P((const char *, const char *, const char *, void *));
|
||||
static int selected __P((const char *));
|
||||
static void addoption __P((char *));
|
||||
static const char *getoptions __P((const char *));
|
||||
|
@ -83,7 +82,7 @@ static void maketypelist __P((char *));
|
|||
static char *catopt __P((char *, const char *, int));
|
||||
static void mangle __P((char *, int *, const char **));
|
||||
static void usage __P((void));
|
||||
static int isok __P((struct fstab *));
|
||||
static void *isok __P((struct fstab *));
|
||||
|
||||
|
||||
int
|
||||
|
@ -100,17 +99,12 @@ main(argc, argv)
|
|||
|
||||
while ((i = getopt(argc, argv, "dvpnyl:t:T:")) != -1)
|
||||
switch (i) {
|
||||
#ifdef DEBUG
|
||||
# define DEBUGOPT "d"
|
||||
case 'd':
|
||||
debug++;
|
||||
flags |= CHECK_DEBUG;
|
||||
break;
|
||||
#else
|
||||
# define DEBUGOPT ""
|
||||
#endif
|
||||
|
||||
case 'v':
|
||||
verbose++;
|
||||
flags |= CHECK_VERBOSE;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
|
@ -140,7 +134,7 @@ main(argc, argv)
|
|||
|
||||
case 'p':
|
||||
options = catopt(options, "-p", 1);
|
||||
preen++;
|
||||
flags |= CHECK_PREEN;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
|
@ -153,7 +147,7 @@ main(argc, argv)
|
|||
argv += optind;
|
||||
|
||||
if (argc == 0)
|
||||
return checkfstab(preen, maxrun, isok, checkfs);
|
||||
return checkfstab(flags, maxrun, isok, checkfs);
|
||||
|
||||
#define BADTYPE(type) \
|
||||
(strcmp(type, FSTAB_RO) && \
|
||||
|
@ -180,35 +174,36 @@ main(argc, argv)
|
|||
*argv);
|
||||
}
|
||||
|
||||
rval |= checkfs(type, blockcheck(spec), NULL);
|
||||
rval |= checkfs(type, blockcheck(spec), *argv, NULL);
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
static void *
|
||||
isok(fs)
|
||||
struct fstab *fs;
|
||||
{
|
||||
if (fs->fs_passno == 0)
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
if (BADTYPE(fs->fs_type))
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
if (!selected(fs->fs_vfstype))
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
return 1;
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
checkfs(vfstype, spec, pidp)
|
||||
const char *vfstype, *spec;
|
||||
pid_t *pidp;
|
||||
checkfs(vfstype, spec, mntpt, ap)
|
||||
const char *vfstype, *spec, *mntpt;
|
||||
void *ap;
|
||||
{
|
||||
pid_t *pidp = ap;
|
||||
/* List of directories containing fsck_xxx subcommands. */
|
||||
static const char *edirs[] = {
|
||||
_PATH_SBIN,
|
||||
|
@ -246,9 +241,9 @@ checkfs(vfstype, spec, pidp)
|
|||
|
||||
argv[argc++] = spec;
|
||||
|
||||
if (debug || verbose) {
|
||||
(void)printf("start %swait fsck_%s", pidp ? "no" : "",
|
||||
vfstype);
|
||||
if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) {
|
||||
(void)printf("start %s %swait fsck_%s", mntpt,
|
||||
pidp ? "no" : "", vfstype);
|
||||
for (i = 1; i < argc; i++)
|
||||
(void)printf(" %s", argv[i]);
|
||||
(void)printf("\n");
|
||||
|
@ -262,10 +257,8 @@ checkfs(vfstype, spec, pidp)
|
|||
return (1);
|
||||
|
||||
case 0: /* Child. */
|
||||
#ifdef DEBUG
|
||||
if (debug)
|
||||
if (flags & CHECK_DEBUG)
|
||||
_exit(0);
|
||||
#endif
|
||||
|
||||
/* Go find an executable. */
|
||||
edir = edirs;
|
||||
|
@ -460,9 +453,9 @@ usage()
|
|||
{
|
||||
extern char *__progname;
|
||||
static const char common[] =
|
||||
"pvlyn] [-T fstype:fsoptions] [-t fstype]";
|
||||
"[-dpvlyn] [-T fstype:fsoptions] [-t fstype]";
|
||||
|
||||
(void)fprintf(stderr, "Usage: %s [-%s%s [special|node]...\n",
|
||||
__progname, DEBUGOPT, common);
|
||||
(void)fprintf(stderr, "Usage: %s %s [special|node]...\n",
|
||||
__progname, common);
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: util.c,v 1.1 1996/09/23 16:11:35 christos Exp $ */
|
||||
/* $NetBSD: fsutil.c,v 1.1 1996/09/27 22:38:41 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -32,6 +32,9 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$NetBSD: fsutil.c,v 1.1 1996/09/27 22:38:41 christos Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -48,7 +51,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "fsutil.h"
|
||||
|
||||
static const char *dev = NULL;
|
||||
static int hot = 0;
|
||||
|
@ -112,7 +115,7 @@ vmsg(fatal, fmt, ap)
|
|||
|
||||
(void) vprintf(fmt, ap);
|
||||
|
||||
if (!fatal && preen)
|
||||
if (fatal && preen)
|
||||
(void) printf("\n");
|
||||
|
||||
if (fatal && preen) {
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: util.h,v 1.1 1996/09/23 16:11:36 christos Exp $ */
|
||||
/* $NetBSD: fsutil.h,v 1.1 1996/09/27 22:38:42 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
|
||||
|
@ -46,3 +46,11 @@ void setcdevname __P((const char *, int));
|
|||
int hotroot __P((void));
|
||||
void *emalloc __P((size_t));
|
||||
char *estrdup __P((const char *));
|
||||
|
||||
#define CHECK_PREEN 1
|
||||
#define CHECK_VERBOSE 2
|
||||
#define CHECK_DEBUG 4
|
||||
|
||||
struct fstab;
|
||||
int checkfstab __P((int, int, void *(*)(struct fstab *),
|
||||
int (*) (const char *, const char *, const char *, void *)));
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: preen.c,v 1.13 1996/09/23 16:11:35 christos Exp $ */
|
||||
/* $NetBSD: preen.c,v 1.14 1996/09/27 22:38:43 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)preen.c 8.3 (Berkeley) 12/6/94";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: preen.c,v 1.13 1996/09/23 16:11:35 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: preen.c,v 1.14 1996/09/27 22:38:43 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -54,12 +54,12 @@ static char rcsid[] = "$NetBSD: preen.c,v 1.13 1996/09/23 16:11:35 christos Exp
|
|||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "extern.h"
|
||||
#include "fsutil.h"
|
||||
|
||||
struct partentry {
|
||||
TAILQ_ENTRY(partentry) p_entries;
|
||||
char *p_name; /* device name */
|
||||
char *p_devname; /* device name */
|
||||
char *p_mntpt; /* mount point */
|
||||
char *p_type; /* filesystem type */
|
||||
};
|
||||
|
||||
|
@ -77,18 +77,16 @@ TAILQ_HEAD(disk, diskentry) diskh;
|
|||
static int nrun = 0, ndisks = 0;
|
||||
|
||||
static struct diskentry *finddisk __P((const char *));
|
||||
static void addpart __P((const char *, const char *));
|
||||
static void addpart __P((const char *, const char *, const char *));
|
||||
static int startdisk __P((struct diskentry *,
|
||||
int (*)(const char *, const char *, pid_t *)));
|
||||
#ifdef DEBUG
|
||||
int (*)(const char *, const char *, const char *, void *)));
|
||||
static void printpart __P((void));
|
||||
#endif
|
||||
|
||||
int
|
||||
checkfstab(preen, maxrun, docheck, chkit)
|
||||
int preen, maxrun;
|
||||
int (*docheck) __P((struct fstab *));
|
||||
int (*chkit) __P((const char *, const char *, pid_t *));
|
||||
checkfstab(flags, maxrun, docheck, chkit)
|
||||
int flags, maxrun;
|
||||
void *(*docheck) __P((struct fstab *));
|
||||
int (*chkit) __P((const char *, const char *, const char *, void *));
|
||||
{
|
||||
struct fstab *fs;
|
||||
struct diskentry *d, *nextdisk;
|
||||
|
@ -107,24 +105,23 @@ checkfstab(preen, maxrun, docheck, chkit)
|
|||
return (8);
|
||||
}
|
||||
while ((fs = getfsent()) != 0) {
|
||||
if ((*docheck)(fs) == 0)
|
||||
if ((*docheck)(fs) == NULL)
|
||||
continue;
|
||||
|
||||
name = blockcheck(fs->fs_spec);
|
||||
#ifdef DEBUG
|
||||
if (debug > 1)
|
||||
if (flags & CHECK_DEBUG)
|
||||
printf("pass %d, name %s\n", passno, name);
|
||||
#endif
|
||||
|
||||
if (preen == 0 || (passno == 1 && fs->fs_passno == 1)) {
|
||||
if ((flags & CHECK_PREEN) == 0 ||
|
||||
(passno == 1 && fs->fs_passno == 1)) {
|
||||
if (name == NULL) {
|
||||
if (preen)
|
||||
if (flags & CHECK_PREEN)
|
||||
return 8;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
sumstatus = (*chkit)(fs->fs_vfstype,
|
||||
name, NULL);
|
||||
name, fs->fs_file, NULL);
|
||||
|
||||
if (sumstatus)
|
||||
return (sumstatus);
|
||||
|
@ -135,19 +132,17 @@ checkfstab(preen, maxrun, docheck, chkit)
|
|||
sumstatus |= 8;
|
||||
continue;
|
||||
}
|
||||
addpart(fs->fs_vfstype, name);
|
||||
addpart(fs->fs_vfstype, name, fs->fs_file);
|
||||
}
|
||||
}
|
||||
if (preen == 0)
|
||||
return (0);
|
||||
if ((flags & CHECK_PREEN) == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (debug > 1)
|
||||
if (flags & CHECK_DEBUG)
|
||||
printpart();
|
||||
#endif
|
||||
|
||||
if (preen) {
|
||||
if (flags & CHECK_PREEN) {
|
||||
if (maxrun == 0)
|
||||
maxrun = ndisks;
|
||||
if (maxrun > ndisks)
|
||||
|
@ -177,14 +172,16 @@ checkfstab(preen, maxrun, docheck, chkit)
|
|||
|
||||
p = d->d_part.tqh_first;
|
||||
|
||||
if (debug || verbose)
|
||||
(void) printf("done %s(%s) = %x\n", p->p_name,
|
||||
p->p_type, status);
|
||||
if (flags & (CHECK_DEBUG|CHECK_VERBOSE))
|
||||
(void) printf("done %s: %s (%s) = %x\n",
|
||||
p->p_type, p->p_devname, p->p_mntpt,
|
||||
status);
|
||||
|
||||
if (WIFSIGNALED(status)) {
|
||||
(void) fprintf(stderr,
|
||||
"%s (%s): EXITED WITH SIGNAL %d\n",
|
||||
p->p_name, p->p_type, WTERMSIG(status));
|
||||
"%s: %s (%s): EXITED WITH SIGNAL %d\n",
|
||||
p->p_type, p->p_devname, p->p_mntpt,
|
||||
WTERMSIG(status));
|
||||
retcode = 8;
|
||||
}
|
||||
|
||||
|
@ -195,7 +192,7 @@ checkfstab(preen, maxrun, docheck, chkit)
|
|||
sumstatus |= retcode;
|
||||
} else {
|
||||
free(p->p_type);
|
||||
free(p->p_name);
|
||||
free(p->p_devname);
|
||||
free(p);
|
||||
}
|
||||
d->d_pid = 0;
|
||||
|
@ -235,8 +232,8 @@ checkfstab(preen, maxrun, docheck, chkit)
|
|||
|
||||
for (; p; p = p->p_entries.tqe_next)
|
||||
(void) fprintf(stderr,
|
||||
"%s (%s)%s", p->p_name, p->p_type,
|
||||
p->p_entries.tqe_next ? ", " : "\n");
|
||||
"%s: %s (%s)%s", p->p_type, p->p_devname,
|
||||
p->p_mntpt, p->p_entries.tqe_next ? ", " : "\n");
|
||||
|
||||
return sumstatus;
|
||||
}
|
||||
|
@ -279,7 +276,6 @@ finddisk(name)
|
|||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
printpart()
|
||||
{
|
||||
|
@ -290,28 +286,28 @@ printpart()
|
|||
(void) printf("disk %s: ", d->d_name);
|
||||
for (p = d->d_part.tqh_first; p != NULL;
|
||||
p = p->p_entries.tqe_next)
|
||||
(void) printf("%s ", p->p_name);
|
||||
(void) printf("%s ", p->p_devname);
|
||||
(void) printf("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
addpart(type, name)
|
||||
const char *type, *name;
|
||||
addpart(type, devname, mntpt)
|
||||
const char *type, *devname, *mntpt;
|
||||
{
|
||||
struct diskentry *d = finddisk(name);
|
||||
struct diskentry *d = finddisk(devname);
|
||||
struct partentry *p;
|
||||
|
||||
for (p = d->d_part.tqh_first; p != NULL; p = p->p_entries.tqe_next)
|
||||
if (strcmp(p->p_name, name) == 0) {
|
||||
warnx("%s in fstab more than once!\n", name);
|
||||
if (strcmp(p->p_devname, devname) == 0) {
|
||||
warnx("%s in fstab more than once!\n", devname);
|
||||
return;
|
||||
}
|
||||
|
||||
p = emalloc(sizeof(*p));
|
||||
p->p_name = estrdup(name);
|
||||
p->p_devname = estrdup(devname);
|
||||
p->p_mntpt = estrdup(mntpt);
|
||||
p->p_type = estrdup(type);
|
||||
|
||||
TAILQ_INSERT_TAIL(&d->d_part, p, p_entries);
|
||||
|
@ -321,13 +317,13 @@ addpart(type, name)
|
|||
static int
|
||||
startdisk(d, checkit)
|
||||
register struct diskentry *d;
|
||||
int (*checkit) __P((const char *, const char *, pid_t *));
|
||||
int (*checkit) __P((const char *, const char *, const char *, void *));
|
||||
{
|
||||
register struct partentry *p = d->d_part.tqh_first;
|
||||
int rv;
|
||||
|
||||
while ((rv = (*checkit)(p->p_type, p->p_name, &d->d_pid)) != 0 &&
|
||||
nrun > 0)
|
||||
while ((rv = (*checkit)(p->p_type, p->p_devname, p->p_mntpt,
|
||||
&d->d_pid)) != 0 && nrun > 0)
|
||||
sleep(10);
|
||||
|
||||
if (rv == 0)
|
||||
|
|
Loading…
Reference in New Issue