- 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:
christos 1996-09-27 22:38:37 +00:00
parent d1bae5c5d5
commit 7dfca7604a
6 changed files with 88 additions and 123 deletions

View File

@ -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 PROG= fsck
SRCS= fsck.c util.c preen.c SRCS= fsck.c fsutil.c preen.c
MAN= fsck.8 MAN= fsck.8
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -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 *)));

View File

@ -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. * 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/param.h>
#include <sys/mount.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 <unistd.h>
#include "pathnames.h" #include "pathnames.h"
#include "extern.h" #include "fsutil.h"
#include "util.h"
static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST; static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
@ -68,13 +67,13 @@ struct entry {
TAILQ_ENTRY(entry) entries; TAILQ_ENTRY(entry) entries;
}; };
static int preen = 0, maxrun = 0; static int maxrun = 0;
int debug = 0, verbose = 0;
static char *options = NULL; static char *options = NULL;
static int flags = 0;
int main __P((int, char *[])); 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 int selected __P((const char *));
static void addoption __P((char *)); static void addoption __P((char *));
static const char *getoptions __P((const 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 char *catopt __P((char *, const char *, int));
static void mangle __P((char *, int *, const char **)); static void mangle __P((char *, int *, const char **));
static void usage __P((void)); static void usage __P((void));
static int isok __P((struct fstab *)); static void *isok __P((struct fstab *));
int int
@ -100,17 +99,12 @@ main(argc, argv)
while ((i = getopt(argc, argv, "dvpnyl:t:T:")) != -1) while ((i = getopt(argc, argv, "dvpnyl:t:T:")) != -1)
switch (i) { switch (i) {
#ifdef DEBUG
# define DEBUGOPT "d"
case 'd': case 'd':
debug++; flags |= CHECK_DEBUG;
break; break;
#else
# define DEBUGOPT ""
#endif
case 'v': case 'v':
verbose++; flags |= CHECK_VERBOSE;
break; break;
case 'y': case 'y':
@ -140,7 +134,7 @@ main(argc, argv)
case 'p': case 'p':
options = catopt(options, "-p", 1); options = catopt(options, "-p", 1);
preen++; flags |= CHECK_PREEN;
break; break;
case '?': case '?':
@ -153,7 +147,7 @@ main(argc, argv)
argv += optind; argv += optind;
if (argc == 0) if (argc == 0)
return checkfstab(preen, maxrun, isok, checkfs); return checkfstab(flags, maxrun, isok, checkfs);
#define BADTYPE(type) \ #define BADTYPE(type) \
(strcmp(type, FSTAB_RO) && \ (strcmp(type, FSTAB_RO) && \
@ -180,35 +174,36 @@ main(argc, argv)
*argv); *argv);
} }
rval |= checkfs(type, blockcheck(spec), NULL); rval |= checkfs(type, blockcheck(spec), *argv, NULL);
} }
return rval; return rval;
} }
static int static void *
isok(fs) isok(fs)
struct fstab *fs; struct fstab *fs;
{ {
if (fs->fs_passno == 0) if (fs->fs_passno == 0)
return 0; return NULL;
if (BADTYPE(fs->fs_type)) if (BADTYPE(fs->fs_type))
return 0; return NULL;
if (!selected(fs->fs_vfstype)) if (!selected(fs->fs_vfstype))
return 0; return NULL;
return 1; return fs;
} }
static int static int
checkfs(vfstype, spec, pidp) checkfs(vfstype, spec, mntpt, ap)
const char *vfstype, *spec; const char *vfstype, *spec, *mntpt;
pid_t *pidp; void *ap;
{ {
pid_t *pidp = ap;
/* List of directories containing fsck_xxx subcommands. */ /* List of directories containing fsck_xxx subcommands. */
static const char *edirs[] = { static const char *edirs[] = {
_PATH_SBIN, _PATH_SBIN,
@ -246,9 +241,9 @@ checkfs(vfstype, spec, pidp)
argv[argc++] = spec; argv[argc++] = spec;
if (debug || verbose) { if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) {
(void)printf("start %swait fsck_%s", pidp ? "no" : "", (void)printf("start %s %swait fsck_%s", mntpt,
vfstype); pidp ? "no" : "", vfstype);
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
(void)printf(" %s", argv[i]); (void)printf(" %s", argv[i]);
(void)printf("\n"); (void)printf("\n");
@ -262,10 +257,8 @@ checkfs(vfstype, spec, pidp)
return (1); return (1);
case 0: /* Child. */ case 0: /* Child. */
#ifdef DEBUG if (flags & CHECK_DEBUG)
if (debug)
_exit(0); _exit(0);
#endif
/* Go find an executable. */ /* Go find an executable. */
edir = edirs; edir = edirs;
@ -460,9 +453,9 @@ usage()
{ {
extern char *__progname; extern char *__progname;
static const char common[] = 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", (void)fprintf(stderr, "Usage: %s %s [special|node]...\n",
__progname, DEBUGOPT, common); __progname, common);
exit(1); exit(1);
} }

View File

@ -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 * Copyright (c) 1990, 1993
@ -32,6 +32,9 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 <stdio.h>
#include <string.h> #include <string.h>
@ -48,7 +51,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "util.h" #include "fsutil.h"
static const char *dev = NULL; static const char *dev = NULL;
static int hot = 0; static int hot = 0;
@ -112,7 +115,7 @@ vmsg(fatal, fmt, ap)
(void) vprintf(fmt, ap); (void) vprintf(fmt, ap);
if (!fatal && preen) if (fatal && preen)
(void) printf("\n"); (void) printf("\n");
if (fatal && preen) { if (fatal && preen) {

View File

@ -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. * Copyright (c) 1996 Christos Zoulas. All rights reserved.
@ -46,3 +46,11 @@ void setcdevname __P((const char *, int));
int hotroot __P((void)); int hotroot __P((void));
void *emalloc __P((size_t)); void *emalloc __P((size_t));
char *estrdup __P((const char *)); 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 *)));

View File

@ -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 * Copyright (c) 1990, 1993
@ -37,7 +37,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)preen.c 8.3 (Berkeley) 12/6/94"; static char sccsid[] = "@(#)preen.c 8.3 (Berkeley) 12/6/94";
#else #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
#endif /* not lint */ #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 <unistd.h>
#include <err.h> #include <err.h>
#include "util.h" #include "fsutil.h"
#include "extern.h"
struct partentry { struct partentry {
TAILQ_ENTRY(partentry) p_entries; 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 */ char *p_type; /* filesystem type */
}; };
@ -77,18 +77,16 @@ TAILQ_HEAD(disk, diskentry) diskh;
static int nrun = 0, ndisks = 0; static int nrun = 0, ndisks = 0;
static struct diskentry *finddisk __P((const char *)); 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 *, static int startdisk __P((struct diskentry *,
int (*)(const char *, const char *, pid_t *))); int (*)(const char *, const char *, const char *, void *)));
#ifdef DEBUG
static void printpart __P((void)); static void printpart __P((void));
#endif
int int
checkfstab(preen, maxrun, docheck, chkit) checkfstab(flags, maxrun, docheck, chkit)
int preen, maxrun; int flags, maxrun;
int (*docheck) __P((struct fstab *)); void *(*docheck) __P((struct fstab *));
int (*chkit) __P((const char *, const char *, pid_t *)); int (*chkit) __P((const char *, const char *, const char *, void *));
{ {
struct fstab *fs; struct fstab *fs;
struct diskentry *d, *nextdisk; struct diskentry *d, *nextdisk;
@ -107,24 +105,23 @@ checkfstab(preen, maxrun, docheck, chkit)
return (8); return (8);
} }
while ((fs = getfsent()) != 0) { while ((fs = getfsent()) != 0) {
if ((*docheck)(fs) == 0) if ((*docheck)(fs) == NULL)
continue; continue;
name = blockcheck(fs->fs_spec); name = blockcheck(fs->fs_spec);
#ifdef DEBUG if (flags & CHECK_DEBUG)
if (debug > 1)
printf("pass %d, name %s\n", passno, name); 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 (name == NULL) {
if (preen) if (flags & CHECK_PREEN)
return 8; return 8;
else else
continue; continue;
} }
sumstatus = (*chkit)(fs->fs_vfstype, sumstatus = (*chkit)(fs->fs_vfstype,
name, NULL); name, fs->fs_file, NULL);
if (sumstatus) if (sumstatus)
return (sumstatus); return (sumstatus);
@ -135,19 +132,17 @@ checkfstab(preen, maxrun, docheck, chkit)
sumstatus |= 8; sumstatus |= 8;
continue; continue;
} }
addpart(fs->fs_vfstype, name); addpart(fs->fs_vfstype, name, fs->fs_file);
} }
} }
if (preen == 0) if ((flags & CHECK_PREEN) == 0)
return (0); return 0;
} }
#ifdef DEBUG if (flags & CHECK_DEBUG)
if (debug > 1)
printpart(); printpart();
#endif
if (preen) { if (flags & CHECK_PREEN) {
if (maxrun == 0) if (maxrun == 0)
maxrun = ndisks; maxrun = ndisks;
if (maxrun > ndisks) if (maxrun > ndisks)
@ -177,14 +172,16 @@ checkfstab(preen, maxrun, docheck, chkit)
p = d->d_part.tqh_first; p = d->d_part.tqh_first;
if (debug || verbose) if (flags & (CHECK_DEBUG|CHECK_VERBOSE))
(void) printf("done %s(%s) = %x\n", p->p_name, (void) printf("done %s: %s (%s) = %x\n",
p->p_type, status); p->p_type, p->p_devname, p->p_mntpt,
status);
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
(void) fprintf(stderr, (void) fprintf(stderr,
"%s (%s): EXITED WITH SIGNAL %d\n", "%s: %s (%s): EXITED WITH SIGNAL %d\n",
p->p_name, p->p_type, WTERMSIG(status)); p->p_type, p->p_devname, p->p_mntpt,
WTERMSIG(status));
retcode = 8; retcode = 8;
} }
@ -195,7 +192,7 @@ checkfstab(preen, maxrun, docheck, chkit)
sumstatus |= retcode; sumstatus |= retcode;
} else { } else {
free(p->p_type); free(p->p_type);
free(p->p_name); free(p->p_devname);
free(p); free(p);
} }
d->d_pid = 0; d->d_pid = 0;
@ -235,8 +232,8 @@ checkfstab(preen, maxrun, docheck, chkit)
for (; p; p = p->p_entries.tqe_next) for (; p; p = p->p_entries.tqe_next)
(void) fprintf(stderr, (void) fprintf(stderr,
"%s (%s)%s", p->p_name, p->p_type, "%s: %s (%s)%s", p->p_type, p->p_devname,
p->p_entries.tqe_next ? ", " : "\n"); p->p_mntpt, p->p_entries.tqe_next ? ", " : "\n");
return sumstatus; return sumstatus;
} }
@ -279,7 +276,6 @@ finddisk(name)
} }
#ifdef DEBUG
static void static void
printpart() printpart()
{ {
@ -290,28 +286,28 @@ printpart()
(void) printf("disk %s: ", d->d_name); (void) printf("disk %s: ", d->d_name);
for (p = d->d_part.tqh_first; p != NULL; for (p = d->d_part.tqh_first; p != NULL;
p = p->p_entries.tqe_next) p = p->p_entries.tqe_next)
(void) printf("%s ", p->p_name); (void) printf("%s ", p->p_devname);
(void) printf("\n"); (void) printf("\n");
} }
} }
#endif
static void static void
addpart(type, name) addpart(type, devname, mntpt)
const char *type, *name; const char *type, *devname, *mntpt;
{ {
struct diskentry *d = finddisk(name); struct diskentry *d = finddisk(devname);
struct partentry *p; struct partentry *p;
for (p = d->d_part.tqh_first; p != NULL; p = p->p_entries.tqe_next) for (p = d->d_part.tqh_first; p != NULL; p = p->p_entries.tqe_next)
if (strcmp(p->p_name, name) == 0) { if (strcmp(p->p_devname, devname) == 0) {
warnx("%s in fstab more than once!\n", name); warnx("%s in fstab more than once!\n", devname);
return; return;
} }
p = emalloc(sizeof(*p)); p = emalloc(sizeof(*p));
p->p_name = estrdup(name); p->p_devname = estrdup(devname);
p->p_mntpt = estrdup(mntpt);
p->p_type = estrdup(type); p->p_type = estrdup(type);
TAILQ_INSERT_TAIL(&d->d_part, p, p_entries); TAILQ_INSERT_TAIL(&d->d_part, p, p_entries);
@ -321,13 +317,13 @@ addpart(type, name)
static int static int
startdisk(d, checkit) startdisk(d, checkit)
register struct diskentry *d; 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; register struct partentry *p = d->d_part.tqh_first;
int rv; int rv;
while ((rv = (*checkit)(p->p_type, p->p_name, &d->d_pid)) != 0 && while ((rv = (*checkit)(p->p_type, p->p_devname, p->p_mntpt,
nrun > 0) &d->d_pid)) != 0 && nrun > 0)
sleep(10); sleep(10);
if (rv == 0) if (rv == 0)