[Midnightbsd-cvs] src [11223] trunk/sbin/fsck: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jul 1 17:07:14 EDT 2018


Revision: 11223
          http://svnweb.midnightbsd.org/src/?rev=11223
Author:   laffer1
Date:     2018-07-01 17:07:13 -0400 (Sun, 01 Jul 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sbin/fsck/Makefile
    trunk/sbin/fsck/fsck.8
    trunk/sbin/fsck/fsck.c
    trunk/sbin/fsck/fsutil.c
    trunk/sbin/fsck/fsutil.h
    trunk/sbin/fsck/preen.c

Property Changed:
----------------
    trunk/sbin/fsck/fsck.8

Modified: trunk/sbin/fsck/Makefile
===================================================================
--- trunk/sbin/fsck/Makefile	2018-07-01 21:06:48 UTC (rev 11222)
+++ trunk/sbin/fsck/Makefile	2018-07-01 21:07:13 UTC (rev 11223)
@@ -1,9 +1,9 @@
+# $MidnightBSD$
 #	$NetBSD: Makefile,v 1.14 1996/09/27 22:38:37 christos Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/sbin/fsck/Makefile 241807 2012-10-21 12:01:19Z uqs $
 
 PROG=	fsck
 SRCS=	fsck.c fsutil.c preen.c
-WARNS?=	2
 MAN=	fsck.8
 
 .include <bsd.prog.mk>

Modified: trunk/sbin/fsck/fsck.8
===================================================================
--- trunk/sbin/fsck/fsck.8	2018-07-01 21:06:48 UTC (rev 11222)
+++ trunk/sbin/fsck/fsck.8	2018-07-01 21:07:13 UTC (rev 11223)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"	$NetBSD: fsck.8,v 1.19 1999/03/10 00:08:33 erh Exp $
 .\"
 .\" Copyright (c) 1996 Christos Zoulas.  All rights reserved.
@@ -27,9 +28,9 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/fsck/fsck.8 316209 2017-03-30 02:38:38Z sevan $
 .\"
-.Dd January 25, 2009
+.Dd October 5, 2016
 .Dt FSCK 8
 .Os
 .Sh NAME
@@ -41,6 +42,7 @@
 .Op Fl B | F
 .Op Fl T Ar fstype : Ns Ar fsoptions
 .Op Fl t Ar fstype
+.Op Fl c Ar fstab
 .Oo Ar special | node Oc ...
 .Sh DESCRIPTION
 The
@@ -110,6 +112,18 @@
 of the device name that ends in a digit; the remaining characters are assumed
 to be the partition and slice designators.
 .Pp
+If the
+.Fl t
+or
+.Fl T
+flags are not specified,
+.Nm
+will attempt to determine the file system type and call the
+appropriated file system check utility.
+Failure to detect the file system type will cause
+.Nm
+to fail with a message that the partition has an unknown file system type.
+.Pp
 The options are as follows:
 .Bl -tag -width indent
 .It Fl C
@@ -117,6 +131,10 @@
 .Dq clean
 flag is set in the superblock and skip file system checks if file system was
 properly dismounted and marked clean.
+.It Fl c Ar fstab
+Specify the
+.Pa fstab
+file to use.
 .It Fl d
 Debugging mode.
 Just print the commands without executing them.
@@ -212,3 +230,15 @@
 .Xr fsck_ffs 8 ,
 .Xr fsck_msdosfs 8 ,
 .Xr mount 8
+.Sh HISTORY
+A
+.Nm
+utility appeared in
+.Bx 4.0 .
+It was reimplemented as a filesystem independent wrapper in
+.Nx 1.3
+and first appeared in
+.Fx 5.0 .
+The original filesystem specific utility became
+.Xr fsck_ffs 8
+at this point.


Property changes on: trunk/sbin/fsck/fsck.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/fsck/fsck.c
===================================================================
--- trunk/sbin/fsck/fsck.c	2018-07-01 21:06:48 UTC (rev 11222)
+++ trunk/sbin/fsck/fsck.c	2018-07-01 21:07:13 UTC (rev 11223)
@@ -1,4 +1,5 @@
-/*	$NetBSD: fsck.c,v 1.21 1999/04/22 04:20:53 abs Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: fsck.c,v 1.30 2003/08/07 10:04:15 agc Exp $	*/
 
 /*
  * Copyright (c) 1996 Christos Zoulas. All rights reserved.
@@ -13,11 +14,7 @@
  * 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 the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -35,18 +32,17 @@
  *
  * From: @(#)mount.c	8.19 (Berkeley) 4/19/94
  * From: $NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp 
- * $NetBSD: fsck.c,v 1.21 1999/04/22 04:20:53 abs Exp $
+ * $NetBSD: fsck.c,v 1.30 2003/08/07 10:04:15 agc Exp $
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/fsck/fsck.c 275179 2014-11-27 08:41:31Z ae $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/queue.h>
 #include <sys/wait.h>
-#define FSTYPENAMES
-#include <sys/disklabel.h>
+#include <sys/disk.h>
 #include <sys/ioctl.h>
 
 #include <ctype.h>
@@ -65,7 +61,7 @@
 
 static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
 
-TAILQ_HEAD(fstypelist, entry) opthead, selhead;
+static TAILQ_HEAD(fstypelist, entry) opthead, selhead;
 
 struct entry {
 	char *type;
@@ -77,7 +73,7 @@
 static int flags = 0;
 static int forceflag = 0;
 
-static int checkfs(const char *, const char *, const char *, char *, pid_t *);
+static int checkfs(const char *, const char *, const char *, const char *, pid_t *);
 static int selected(const char *);
 static void addoption(char *);
 static const char *getoptions(const char *);
@@ -84,11 +80,22 @@
 static void addentry(struct fstypelist *, const char *, const char *);
 static void maketypelist(char *);
 static void catopt(char **, const char *);
-static void mangle(char *, int *, const char ***, int *);
-static const char *getfslab(const char *);
+static void mangle(char *, int *, const char ** volatile *, int *);
+static const char *getfstype(const char *);
 static void usage(void) __dead2;
 static int isok(struct fstab *);
 
+static struct {
+	const char *ptype;
+	const char *name;
+} ptype_map[] = {
+	{ "ufs",	"ffs" },
+	{ "ffs",	"ffs" },
+	{ "fat",	"msdosfs" },
+	{ "efi",	"msdosfs" },
+	{ NULL,		NULL },
+};
+
 int
 main(int argc, char *argv[])
 {
@@ -96,6 +103,7 @@
 	int i, rval = 0;
 	const char *vfstype = NULL;
 	char globopt[3];
+	const char *etc_fstab;
 
 	globopt[0] = '-';
 	globopt[2] = '\0';
@@ -103,7 +111,8 @@
 	TAILQ_INIT(&selhead);
 	TAILQ_INIT(&opthead);
 
-	while ((i = getopt(argc, argv, "BCdvpfFnyl:t:T:")) != -1)
+	etc_fstab = NULL;
+	while ((i = getopt(argc, argv, "BCdvpfFnyl:t:T:c:")) != -1)
 		switch (i) {
 		case 'B':
 			if (flags & CHECK_BACKGRD)
@@ -160,6 +169,10 @@
 			vfstype = optarg;
 			break;
 
+		case 'c':
+			etc_fstab = optarg;
+			break;
+
 		case '?':
 		default:
 			usage();
@@ -169,6 +182,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (etc_fstab != NULL)
+		setfstab(etc_fstab);
+
 	if (argc == 0)
 		return checkfstab(flags, isok, checkfs);
 
@@ -182,6 +198,7 @@
 		char device[MAXPATHLEN];
 		struct statfs *mntp;
 
+		mntpt = NULL;
 		spec = *argv;
 		cp = strrchr(spec, '/');
 		if (cp == 0) {
@@ -197,7 +214,7 @@
 		if ((fs = getfsfile(spec)) == NULL &&
 		    (fs = getfsspec(spec)) == NULL) {
 			if (vfstype == NULL)
-				vfstype = getfslab(spec);
+				vfstype = getfstype(spec);
 			if (vfstype == NULL)
 				errx(1, "Could not determine filesystem type");
 			type = vfstype;
@@ -280,9 +297,9 @@
 
 static int
 checkfs(const char *pvfstype, const char *spec, const char *mntpt,
-    char *auxopt, pid_t *pidp)
+    const char *auxopt, pid_t *pidp)
 {
-	const char **argv;
+	const char ** volatile argv;
 	pid_t pid;
 	int argc, i, status, maxargc;
 	char *optbuf, execbase[MAXPATHLEN];
@@ -306,8 +323,8 @@
 	 */
 	vfstype = strdup(pvfstype);
 	if (vfstype == NULL)
-		perror("strdup(pvfstype)"); 
-	for (i = 0; i < strlen(vfstype); i++) {
+		perr("strdup(pvfstype)");
+	for (i = 0; i < (int)strlen(vfstype); i++) {
 		vfstype[i] = tolower(vfstype[i]);
 		if (vfstype[i] == ' ')
 			vfstype[i] = '_';
@@ -356,7 +373,7 @@
 			_exit(0);
 
 		/* Go find an executable. */
-		execvP(execbase, _PATH_SYSPATH, (char * const *)argv);
+		execvP(execbase, _PATH_SYSPATH, __DECONST(char * const *, argv));
 		if (spec)
 			warn("exec %s for %s in %s", execbase, spec, _PATH_SYSPATH);
 		else
@@ -493,7 +510,7 @@
 
 
 static void
-mangle(char *options, int *argcp, const char ***argvp, int *maxargcp)
+mangle(char *opts, int *argcp, const char ** volatile *argvp, int *maxargcp)
 {
 	char *p, *s;
 	int argc, maxargc;
@@ -503,7 +520,7 @@
 	argv = *argvp;
 	maxargc = *maxargcp;
 
-	for (s = options; (p = strsep(&s, ",")) != NULL;) {
+	for (s = opts; (p = strsep(&s, ",")) != NULL;) {
 		/* Always leave space for one more argument and the NULL. */
 		if (argc >= maxargc - 3) {
 			maxargc <<= 1;
@@ -529,41 +546,27 @@
 	*maxargcp = maxargc;
 }
 
-
-const static char *
-getfslab(const char *str)
+static const char *
+getfstype(const char *str)
 {
-	struct disklabel dl;
-	int fd;
-	char p;
-	const char *vfstype;
-	u_char t;
+	struct diocgattr_arg attr;
+	int fd, i;
 
-	/* deduce the file system type from the disk label */
 	if ((fd = open(str, O_RDONLY)) == -1)
 		err(1, "cannot open `%s'", str);
 
-	if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
+	strncpy(attr.name, "PART::type", sizeof(attr.name));
+	memset(&attr.value, 0, sizeof(attr.value));
+	attr.len = sizeof(attr.value);
+	if (ioctl(fd, DIOCGATTR, &attr) == -1) {
 		(void) close(fd);
 		return(NULL);
 	}
-
 	(void) close(fd);
-
-	p = str[strlen(str) - 1];
-
-	if ((p - 'a') >= dl.d_npartitions)
-		errx(1, "partition `%s' is not defined on disk", str);
-
-	if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES) 
-		errx(1, "partition `%s' is not of a legal vfstype",
-		    str);
-
-	if ((vfstype = fstypenames[t]) == NULL)
-		errx(1, "vfstype `%s' on partition `%s' is not supported",
-		    fstypenames[t], str);
-
-	return vfstype;
+	for (i = 0; ptype_map[i].ptype != NULL; i++)
+		if (strstr(attr.value.str, ptype_map[i].ptype) != NULL)
+			return (ptype_map[i].name);
+	return (NULL);
 }
 
 
@@ -571,7 +574,7 @@
 usage(void)
 {
 	static const char common[] =
-	    "[-Cdfnpvy] [-B | -F] [-T fstype:fsoptions] [-t fstype]";
+	    "[-Cdfnpvy] [-B | -F] [-T fstype:fsoptions] [-t fstype] [-c fstab]";
 
 	(void)fprintf(stderr, "usage: %s %s [special | node] ...\n",
 	    getprogname(), common);

Modified: trunk/sbin/fsck/fsutil.c
===================================================================
--- trunk/sbin/fsck/fsutil.c	2018-07-01 21:06:48 UTC (rev 11222)
+++ trunk/sbin/fsck/fsutil.c	2018-07-01 21:07:13 UTC (rev 11223)
@@ -1,4 +1,5 @@
-/*	$NetBSD: fsutil.c,v 1.7 1998/07/30 17:41:03 thorpej Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: fsutil.c,v 1.15 2006/06/05 16:52:05 christos Exp $	*/
 
 /*
  * Copyright (c) 1990, 1993
@@ -12,7 +13,7 @@
  * 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -31,9 +32,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fsutil.c,v 1.7 1998/07/30 17:41:03 thorpej Exp $");
+__RCSID("$NetBSD: fsutil.c,v 1.15 2006/06/05 16:52:05 christos Exp $");
 #endif /* not lint */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/fsck/fsutil.c 241806 2012-10-21 12:01:11Z uqs $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -110,9 +111,13 @@
 }
 
 void
-perror(const char *s)
+perr(const char *fmt, ...)
 {
-	pfatal("%s (%s)", s, strerror(errno));
+	va_list ap;
+
+	va_start(ap, fmt);
+	vmsg(1, fmt, ap);
+	va_end(ap);
 }
 
 void
@@ -132,18 +137,15 @@
 	struct stat stslash, stchar;
 
 	if (stat("/", &stslash) < 0) {
-		perror("/");
-		printf("Can't stat root\n");
+		perr("Can't stat `/'");
 		return (origname);
 	}
 	if (stat(origname, &stchar) < 0) {
-		perror(origname);
-		printf("Can't stat %s\n", origname);
+		perr("Can't stat %s\n", origname);
 		return (origname);
 	}
 	if (!S_ISCHR(stchar.st_mode)) {
-		perror(origname);
-		printf("%s is not a char device\n", origname);
+		perr("%s is not a char device\n", origname);
 	}
 	return (origname);
 }
@@ -156,7 +158,7 @@
 {
 	struct stat devstat, mntdevstat;
 	char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
-	char *devname;
+	char *dev_name;
 	struct statfs *mntbuf, *statfsp;
 	int i, mntsize, isdev;
 
@@ -169,10 +171,10 @@
 	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
 	for (i = 0; i < mntsize; i++) {
 		statfsp = &mntbuf[i];
-		devname = statfsp->f_mntfromname;
-		if (*devname != '/') {
+		dev_name = statfsp->f_mntfromname;
+		if (*dev_name != '/') {
 			strcpy(device, _PATH_DEV);
-			strcat(device, devname);
+			strcat(device, dev_name);
 			strcpy(statfsp->f_mntfromname, device);
 		}
 		if (isdev == 0) {
@@ -180,7 +182,7 @@
 				continue;
 			return (statfsp);
 		}
-		if (stat(devname, &mntdevstat) == 0 &&
+		if (stat(dev_name, &mntdevstat) == 0 &&
 		    mntdevstat.st_rdev == devstat.st_rdev)
 			return (statfsp);
 	}

Modified: trunk/sbin/fsck/fsutil.h
===================================================================
--- trunk/sbin/fsck/fsutil.h	2018-07-01 21:06:48 UTC (rev 11222)
+++ trunk/sbin/fsck/fsutil.h	2018-07-01 21:07:13 UTC (rev 11223)
@@ -1,4 +1,5 @@
-/*	$NetBSD: fsutil.h,v 1.4 1998/07/26 20:02:36 mycroft Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: fsutil.h,v 1.114 2009/10/21 01:07:46 snj Exp $	*/
 
 /*
  * Copyright (c) 1996 Christos Zoulas.  All rights reserved.
@@ -11,11 +12,6 @@
  * 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
@@ -28,12 +24,12 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/fsck/fsutil.h 241807 2012-10-21 12:01:19Z uqs $
  */
 
-void perror(const char *);
 void pfatal(const char *, ...) __printflike(1, 2);
 void pwarn(const char *, ...) __printflike(1, 2);
+void perr(const char *, ...) __printflike(1, 2);
 void panic(const char *, ...) __dead2 __printflike(1, 2);
 const char *devcheck(const char *);
 const char *cdevname(void);
@@ -52,4 +48,4 @@
 
 struct fstab;
 int checkfstab(int, int (*)(struct fstab *), 
-    int (*) (const char *, const char *, const char *, char *, pid_t *));
+    int (*) (const char *, const char *, const char *, const char *, pid_t *));

Modified: trunk/sbin/fsck/preen.c
===================================================================
--- trunk/sbin/fsck/preen.c	2018-07-01 21:06:48 UTC (rev 11222)
+++ trunk/sbin/fsck/preen.c	2018-07-01 21:07:13 UTC (rev 11223)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $	*/
 
 /*
@@ -28,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/fsck/preen.c 241807 2012-10-21 12:01:19Z uqs $
  */
 
 #include <sys/cdefs.h>
@@ -62,7 +63,7 @@
 	char		  	*p_type;	/* file system type */
 };
 
-TAILQ_HEAD(part, partentry) badh;
+static TAILQ_HEAD(part, partentry) badh;
 
 struct diskentry {
 	TAILQ_ENTRY(diskentry) 	    d_entries;
@@ -71,7 +72,7 @@
 	int			    d_pid;	/* 0 or pid of fsck proc */
 };
 
-TAILQ_HEAD(disk, diskentry) diskh;
+static TAILQ_HEAD(disk, diskentry) diskh;
 
 static int nrun = 0, ndisks = 0;
 
@@ -78,12 +79,12 @@
 static struct diskentry *finddisk(const char *);
 static void addpart(const char *, const char *, const char *);
 static int startdisk(struct diskentry *, 
-    int (*)(const char *, const char *, const char *, char *, pid_t *));
+    int (*)(const char *, const char *, const char *, const char *, pid_t *));
 static void printpart(void);
 
 int
 checkfstab(int flags, int (*docheck)(struct fstab *), 
-    int (*checkit)(const char *, const char *, const char *, char *, pid_t *))
+    int (*checkit)(const char *, const char *, const char *, const char *, pid_t *))
 {
 	struct fstab *fs;
 	struct diskentry *d, *nextdisk;
@@ -295,19 +296,19 @@
 
 
 static void
-addpart(const char *type, const char *devname, const char *mntpt)
+addpart(const char *type, const char *dev, const char *mntpt)
 {
-	struct diskentry *d = finddisk(devname);
+	struct diskentry *d = finddisk(dev);
 	struct partentry *p;
 
 	TAILQ_FOREACH(p, &d->d_part, p_entries)
-		if (strcmp(p->p_devname, devname) == 0) {
-			warnx("%s in fstab more than once!\n", devname);
+		if (strcmp(p->p_devname, dev) == 0) {
+			warnx("%s in fstab more than once!\n", dev);
 			return;
 		}
 
 	p = emalloc(sizeof(*p));
-	p->p_devname = estrdup(devname);
+	p->p_devname = estrdup(dev);
 	p->p_mntpt = estrdup(mntpt);
 	p->p_type = estrdup(type);
 
@@ -317,7 +318,7 @@
 
 static int
 startdisk(struct diskentry *d, int (*checkit)(const char *, const char *,
-    const char *, char *, pid_t *))
+    const char *, const char *, pid_t *))
 {
 	struct partentry *p = TAILQ_FIRST(&d->d_part);
 	int rv;



More information about the Midnightbsd-cvs mailing list