Subject: bin/9753: dump(8) ignores fstab when dumping named filesystems.
To: None <netbsd-bugs@netbsd.org>
From: John Darrow <John.P.Darrow@wheaton.edu>
List: netbsd-bugs
Date: 04/05/2000 14:58:21
Date: Mon, 3 Apr 2000 00:53:05 -0700 (PDT)
From: The Grey Wolf <greywolf@starwolf.com>
Reply-To: greywolf@starwolf.com
To: gnats-bugs@gnats.netbsd.org
Subject: dump(8) ignores fstab when dumping named filesystems.


>Number:         9753
>Category:       bin
>Synopsis:       dump(8) ignores fstab when dumping named filesystems.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 03 01:06:00 PDT 2000
>Closed-Date:    
>Last-Modified:  
>Originator:     The Grey Wolf
>Release:        <NetBSD-current source date> 1.4X of 31 March 2000
>Organization:
Star Wolf Innovations


>Environment:

	
	Machine: SPARCstation 5	(sun4m)
	OS: NetBSD 1.4X
	Target: sparc/sun4m
	Libraries: less-than-current
System: NetBSD starwolf.com 1.4X NetBSD 1.4X (STARWOLF)	#9: Fri Mar 31 00:43:30 PST 2000 root@:/usr/src/sys/arch/sparc/compile/STARWOLF sparc


>Description:
	dump(8) will, when asked to dump a filesystem which is not mounted,
	dump the on-disk subdirectory as a sub-file/sub-directory dump,
	ignoring the entry in /etc/fstab
>How-To-Repeat:
	NetBSD# umount /usr
	NetBSD# dump 0f /dev/null /usr
	  DUMP: Dumping sub-files/directories from /
	  DUMP: Dumping file/directory /usr
	  DUMP: Date of this level 0 dump: Mon Apr  3 00:43:33 2000
	  DUMP: Date of last level 0 dump: the epoch
	  DUMP: Dumping a subset of /dev/rsd3a (a subset of /) to /dev/null
	  DUMP: Label: none
	  DUMP: mapping (Pass I) [regular files]
	  DUMP: mapping (Pass II) [directories]
	  DUMP: estimated 24 tape blocks on 0.00 tape(s)
	  DUMP: Volume 1 started at: Mon Apr  3 00:43:35 2000
	  DUMP: dumping (Pass III) [directories]
	  DUMP: dumping (Pass IV) [regular files]
	  DUMP: 21 tape blocks on 1 volume
	  DUMP: Volume 1 completed at: Mon Apr  3 00:43:35 2000
	  DUMP: Date of this level 0 dump: Mon Apr  3 00:43:33 2000
	  DUMP: Date this dump completed:  Mon Apr  3 00:43:35 2000
	  DUMP: Average transfer rate: 0KB/s
	  DUMP: Closing /dev/null
	  DUMP: DUMP IS DONE
	NetBSD#


	This is obviously not the desired result.  I'd rather it went
	into /etc/fstab to (try to) get the named filesystem.
>Fix:
	Find enclosed two patches -- one for the code, one for the
	manual page.


	I wasn't sure which letter to use, so I picked D (for Disregard or
	Direct).  Feel free to pick a better letter, word it better,
	whatever.


	And yeah, running getfsfile(fs) preceding getfstab could probably
	have been handled a bit better, but seeing as we really need to
	look at /etc/fstab NOW rather than later...


	The construction may not be perfect; I have tried to maintain KNF
	(ANF?) format throughout the change, and I have no doubt the code
	is something of a hack, but the concept is there, and I'd really
	like to see it implemented.


	Here are the patches:
# -- cut here --
--- main.c.orig	Fri Oct  1 04:13:27 1999
+++ main.c	Mon Apr  3 00:36:53 2000
@@ -86,6 +86,7 @@
 int	density = 0;		/* density in bytes/0.1" */
 int	ntrec = NTREC;		/* # tape blocks in each tape record */
 int	cartridge = 0;		/* Assume non-cartridge tape */
+int	nolookup = 0;		/* Do fstab/mount lookups for given path */
 long	dev_bsize = 1;		/* recalculated below */
 long	blocksperfile = 0;	/* output blocks per file */
 char	*host = NULL;		/* remote host (if any) */
@@ -134,7 +135,7 @@

 
 	obsolete(&argc, &argv);
 	while ((ch = getopt(argc, argv,
-	    "0123456789B:b:cd:f:h:k:L:nr:s:ST:uWw")) != -1)
+	    "0123456789B:b:cDd:f:h:k:L:nr:s:ST:uWw")) != -1)
 		switch (ch) {
 		/* dump level */
 		case '0': case '1': case '2': case '3': case '4':
@@ -161,6 +162,10 @@
 				ntrec = HIGHDENSITYTREC;
 			break;

 
+		case 'D':		/* disregard fstab, mount table */
+			nolookup = 1;
+			break;
+
 		case 'f':		/* output file */
 			tape = optarg;
 			break;
@@ -189,6 +194,7 @@
 				    labelstr);
 			}
 			break;
+
 		case 'n':		/* notify operators */
 			notify = 1;
 			break;
@@ -244,24 +250,43 @@
 	for (i = 0; i < argc; i++) {
 		struct stat sb;
 		struct statfs fsbuf;
+		struct fstab *fse;
+		char *fs;
+
+
+		fs = argv[i];

 
-		if (lstat(argv[i], &sb) == -1) {
-			msg("Cannot lstat %s: %s\n", argv[i], strerror(errno));
+		if (lstat(fs, &sb) == -1) {
+			msg("Cannot lstat %s: %s\n", fs, strerror(errno));
 			exit(X_ABORT);
 		}
 		if (!S_ISDIR(sb.st_mode) && !S_ISREG(sb.st_mode))
 			break;
-		if (statfs(argv[i], &fsbuf) == -1) {
-			msg("Cannot statfs %s: %s\n", argv[i], strerror(errno));
+		if (statfs(fs, &fsbuf) == -1) {
+			msg("Cannot statfs %s: %s\n", fs, strerror(errno));
 			exit(X_ABORT);
 		}
-		if (strcmp(argv[i], fsbuf.f_mntonname) == 0) {
+		if (strcmp(fs, fsbuf.f_mntonname) == 0) {
 			if (dirlist != 0) {
 				msg("Can't dump a mountpoint and a filelist\n");
 				exit(X_ABORT);
 			}
 			break;		/* exit if sole mountpoint */
 		}
+		else {	/* if the disk doesn't match */
+			if (nolookup == 0) { /* and we want to match fstab */
+				if ((fse = getfsfile(fs)) !=
+				     (struct fstab *) NULL) {
+					if ((fs = strdup(rawname(fse->fs_spec))) ==
+						NULL) {
+						msg("Cannot malloc fsname\n");
+						exit(X_ABORT);
+					}
+				break;
+				}
+			}
+		}
+		    
 		if (!disk) {
 			if ((toplevel = strdup(fsbuf.f_mntonname)) == NULL) {
 				msg("Cannot malloc diskname\n");
@@ -276,14 +301,16 @@
 				msg("Subdir dump is done at level 0\n");
 				level = '0';
 			}
-			msg("Dumping sub files/directories from %s\n", disk);
-		} else {
+			msg("Dumping sub-files/directories from %s\n", disk);
+		}
+		  else {
 			if (strcmp(disk, fsbuf.f_mntonname) != 0) {
-				msg("%s is not on %s\n", argv[i], disk);
+				msg("%s is not on %s\n", fs, disk);
 				exit(X_ABORT);
 			}
+
 		}
-		msg("Dumping file/directory %s\n", argv[i]);
+		msg("Dumping file/directory %s\n", fs);
 		dirlist++;
 	}
 	if (dirlist == 0) {
--- dump.8.orig	Mon Apr  3 00:39:07 2000
+++ dump.8	Mon Apr  3 00:39:14 2000
@@ -43,7 +43,7 @@
 .Nd filesystem backup
 .Sh SYNOPSIS
 .Nm ""
-.Op Fl 0123456789cnSu
+.Op Fl 0123456789DcnSu
 .Op Fl B Ar records
 .Op Fl b Ar blocksize
 .Op Fl d Ar density
@@ -121,6 +121,12 @@
 .It Fl c
 Modify the calculation of the default density and tape size to be more
 appropriate for cartridge tapes.
+.It Fl D
+Disregard the fstab entry for the named filesystem.  Normally, the
+kernel mount table is consulted for filesystem-device mappings, followed
+by a lookup in /etc/fstab in the event the named filesystem is not
+mounted.  The D flag will instruct dump to ignore the entry in
+/etc/fstab and dump the named path as a subdirectory.
 .It Fl d Ar density
 Set tape density to
 .Ar density .
>Release-Note:
>Audit-Trail:
>Unformatted: