summaryrefslogtreecommitdiffstats
path: root/sbin/fsck_ifs
diff options
context:
space:
mode:
authoradrian <adrian@FreeBSD.org>2000-10-09 08:26:35 +0000
committeradrian <adrian@FreeBSD.org>2000-10-09 08:26:35 +0000
commit336dc694cc4eb3461d1cdf551d151f5b351c73a8 (patch)
tree61b8bdd5a93b5355390a124017db90a115976961 /sbin/fsck_ifs
parent410d456c0b32b2395ed4144947864144f90c445a (diff)
downloadFreeBSD-src-336dc694cc4eb3461d1cdf551d151f5b351c73a8.zip
FreeBSD-src-336dc694cc4eb3461d1cdf551d151f5b351c73a8.tar.gz
Reviewed by: rwatson, bp
Approved by: rwatson Obtained from: NetBSD-current source tree The beginnings of the fsck wrappers stuff from NetBSD. This particular commit brings a newly repo-copied sbin/fsck_ffs/ (from sbin/fsck/) into fsck wrappers mode. A quick overview (the code reflects this): * Documentation changed to reflect fsck_ffs instead of fsck * Simply acts on a single filesystem, doesn't try to do any multiple filesystem magic - this is done by the fsck wrappers now And then specific to fsck_ffs: * link to /sbin/fsck_4.2bsd and /sbin/fsck_ufs. This is because right now the filesystem is of type ufs not ffs, and that during autodetection the labeltype rather than the VFS type is used - this is because when doing an autodetection of filesystem type in the fsck wrapper program, it does not have any link between label type (4.2bsd, vinum, etc) and VFS string. Note that this shouldn't break a build since the required buildworld Makefile magic and import of the fsck wrapper code into src/sbin/fsck/ will happen in a seperate commit.
Diffstat (limited to 'sbin/fsck_ifs')
-rw-r--r--sbin/fsck_ifs/Makefile9
-rw-r--r--sbin/fsck_ifs/fsck.h5
-rw-r--r--sbin/fsck_ifs/main.c79
-rw-r--r--sbin/fsck_ifs/preen.c42
-rw-r--r--sbin/fsck_ifs/utilities.c53
5 files changed, 95 insertions, 93 deletions
diff --git a/sbin/fsck_ifs/Makefile b/sbin/fsck_ifs/Makefile
index 3155b1a..da0e9f8 100644
--- a/sbin/fsck_ifs/Makefile
+++ b/sbin/fsck_ifs/Makefile
@@ -1,9 +1,12 @@
+# $FreeBSD$
# @(#)Makefile 8.2 (Berkeley) 4/27/95
-PROG= fsck
-MAN8= fsck.8
+PROG= fsck_ffs
+LINKS+= ${BINDIR}/fsck_ffs ${BINDIR}/fsck_ufs
+LINKS+= ${BINDIR}/fsck_ffs ${BINDIR}/fsck_4.2bsd
+MAN8= fsck_ffs.8
SRCS= dir.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \
- pass5.c preen.c setup.c utilities.c ffs_subr.c ffs_tables.c
+ pass5.c setup.c utilities.c ffs_subr.c ffs_tables.c
CFLAGS+=-W
.PATH: ${.CURDIR}/../../sys/ufs/ffs
diff --git a/sbin/fsck_ifs/fsck.h b/sbin/fsck_ifs/fsck.h
index f0280fe..a0be2a4 100644
--- a/sbin/fsck_ifs/fsck.h
+++ b/sbin/fsck_ifs/fsck.h
@@ -205,7 +205,9 @@ char preen; /* just fix normal inconsistencies */
char rerun; /* rerun fsck. Only used in non-preen mode */
int returntosingle; /* 1 => return to single user mode on exit */
char resolved; /* cleared if unresolved changes => not clean */
+int markclean; /* mark file system clean when done */
char havesb; /* superblock has been read */
+char skipclean; /* skip clean file systems if preening */
int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */
@@ -252,9 +254,6 @@ void cacheino __P((struct dinode *dp, ino_t inumber));
void catch __P((int));
void catchquit __P((int));
int changeino __P((ino_t dir, char *name, ino_t newnum));
-int checkfstab __P((int preen, int maxrun,
- int (*docheck)(struct fstab *),
- int (*chkit)(char *, char *, long, int)));
int chkrange __P((ufs_daddr_t blk, int cnt));
void ckfini __P((int markclean));
int ckinode __P((struct dinode *dp, struct inodesc *));
diff --git a/sbin/fsck_ifs/main.c b/sbin/fsck_ifs/main.c
index 6463990..1e8a5b4 100644
--- a/sbin/fsck_ifs/main.c
+++ b/sbin/fsck_ifs/main.c
@@ -62,6 +62,9 @@ static const char rcsid[] =
#include "fsck.h"
+int returntosingle;
+
+static void usage __P((void));
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,
@@ -75,22 +78,22 @@ main(argc, argv)
char *argv[];
{
int ch;
- int ret, maxrun = 0;
struct rlimit rlimit;
+ int ret = 0;
sync();
- while ((ch = getopt(argc, argv, "dfpnNyYb:c:l:m:")) != -1) {
+ skipclean = 1;
+ markclean = 1;
+ while ((ch = getopt(argc, argv, "b:c:dfm:npy")) != -1) {
switch (ch) {
- case 'p':
- preen++;
- break;
-
case 'b':
+ skipclean = 0;
bflag = argtoi('b', "number", optarg, 10);
printf("Alternate super block location: %d\n", bflag);
break;
case 'c':
+ skipclean = 0;
cvtlevel = argtoi('c', "conversion level", optarg, 10);
break;
@@ -99,11 +102,7 @@ main(argc, argv)
break;
case 'f':
- fflag++;
- break;
-
- case 'l':
- maxrun = argtoi('l', "number", optarg, 10);
+ skipclean = 0;
break;
case 'm':
@@ -114,23 +113,29 @@ main(argc, argv)
break;
case 'n':
- case 'N':
nflag++;
yflag = 0;
break;
+ case 'p':
+ preen++;
+ break;
+
case 'y':
- case 'Y':
yflag++;
nflag = 0;
break;
default:
- errx(EEXIT, "%c option?", ch);
+ usage();
}
}
argc -= optind;
argv += optind;
+
+ if (!argc)
+ usage();
+
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
(void)signal(SIGINT, catch);
if (preen)
@@ -143,21 +148,11 @@ main(argc, argv)
rlimit.rlim_cur = rlimit.rlim_max;
(void)setrlimit(RLIMIT_DATA, &rlimit);
}
- if (argc) {
- while (argc-- > 0) {
- char *path = blockcheck(*argv);
-
- if (path == NULL)
- pfatal("Can't check %s\n", *argv);
- else
- (void)checkfilesys(path, 0, 0L, 0);
- ++argv;
- }
- exit(0);
- }
- ret = checkfstab(preen, maxrun, docheck, checkfilesys);
+ while (argc-- > 0)
+ (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
+
if (returntosingle)
- exit(2);
+ ret = 2;
exit(ret);
}
@@ -177,22 +172,6 @@ argtoi(flag, req, str, base)
}
/*
- * Determine whether a filesystem should be checked.
- */
-static int
-docheck(fsp)
- register struct fstab *fsp;
-{
-
- if (strcmp(fsp->fs_vfstype, "ufs") ||
- (strcmp(fsp->fs_type, FSTAB_RW) &&
- strcmp(fsp->fs_type, FSTAB_RO)) ||
- fsp->fs_passno == 0)
- return (0);
- return (1);
-}
-
-/*
* Check the specified filesystem.
*/
/* ARGSUSED */
@@ -415,3 +394,15 @@ getmntpt(name)
}
return (NULL);
}
+
+static void
+usage()
+{
+ extern char *__progname;
+
+ (void) fprintf(stderr,
+ "Usage: %s [-dfnpy] [-B be|le] [-b block] [-c level] [-m mode] "
+ "filesystem ...\n",
+ __progname);
+ exit(1);
+}
diff --git a/sbin/fsck_ifs/preen.c b/sbin/fsck_ifs/preen.c
index e43aada..4ad426f 100644
--- a/sbin/fsck_ifs/preen.c
+++ b/sbin/fsck_ifs/preen.c
@@ -288,45 +288,3 @@ startdisk(dk, checkit)
return (0);
}
-char *
-blockcheck(origname)
- char *origname;
-{
- struct stat stslash, stblock, stchar;
- char *newname, *raw;
- struct fstab *fsinfo;
- int retried = 0, len;
-
- newname = origname;
-retry:
- if (stat(newname, &stblock) < 0) {
- printf("Can't stat %s: %s\n", newname, strerror(errno));
- return (origname);
- }
- switch(stblock.st_mode & S_IFMT) {
- case S_IFCHR:
- case S_IFBLK:
- return(newname);
- case S_IFDIR:
- if (retried)
- break;
-
- len = strlen(origname) - 1;
- if (len > 0 && origname[len] == '/')
- /* remove trailing slash */
- origname[len] = '\0';
- if ((fsinfo = getfsfile(origname)) == NULL) {
- printf("Can't resolve %s to character special device",
- origname);
- return (0);
- }
- newname = fsinfo->fs_spec;
- retried++;
- goto retry;
- }
- /*
- * Not a block or character device, just return name and
- * let the user decide whether to use it.
- */
- return (origname);
-}
diff --git a/sbin/fsck_ifs/utilities.c b/sbin/fsck_ifs/utilities.c
index 0ccd9bb..0e4bde5 100644
--- a/sbin/fsck_ifs/utilities.c
+++ b/sbin/fsck_ifs/utilities.c
@@ -40,13 +40,21 @@ static const char rcsid[] =
#endif /* not lint */
#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <err.h>
+#include <errno.h>
#include <string.h>
+#include <ctype.h>
+#include <fstab.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include "fsck.h"
@@ -561,7 +569,7 @@ dofix(idesc, msg)
if (idesc->id_type == DATA)
direrror(idesc->id_number, msg);
else
- pwarn("%s", msg);
+ pwarn(msg);
if (preen) {
printf(" (SALVAGED)\n");
idesc->id_fix = FIX;
@@ -681,3 +689,46 @@ panic(fmt, va_alist)
va_end(ap);
exit(EEXIT);
}
+
+char *
+blockcheck(origname)
+ char *origname;
+{
+ struct stat stslash, stblock, stchar;
+ char *newname, *raw;
+ struct fstab *fsinfo;
+ int retried = 0, len;
+
+ newname = origname;
+retry:
+ if (stat(newname, &stblock) < 0) {
+ printf("Can't stat %s: %s\n", newname, strerror(errno));
+ return (origname);
+ }
+ switch(stblock.st_mode & S_IFMT) {
+ case S_IFCHR:
+ case S_IFBLK:
+ return(newname);
+ case S_IFDIR:
+ if (retried)
+ break;
+
+ len = strlen(origname) - 1;
+ if (len > 0 && origname[len] == '/')
+ /* remove trailing slash */
+ origname[len] = '\0';
+ if ((fsinfo = getfsfile(origname)) == NULL) {
+ printf("Can't resolve %s to character special device",
+ origname);
+ return (0);
+ }
+ newname = fsinfo->fs_spec;
+ retried++;
+ goto retry;
+ }
+ /*
+ * Not a block or character device, just return name and
+ * let the user decide whether to use it.
+ */
+ return (origname);
+}
OpenPOWER on IntegriCloud