From nobody@FreeBSD.ORG Sat Jul 24 11:52:07 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 7764614DE6; Sat, 24 Jul 1999 11:52:07 -0700 (PDT)
Message-Id: <19990724185207.7764614DE6@hub.freebsd.org>
Date: Sat, 24 Jul 1999 11:52:07 -0700 (PDT)
From: bob@pmr.com
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: Confusing error msg when dumping a filesystem by mount point thats not in /etc/fstab
X-Send-Pr-Version: www-1.0

>Number:         12789
>Category:       bin
>Synopsis:       Confusing error msg when dumping a filesystem by mount point thats not in /etc/fstab
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 24 12:00:01 PDT 1999
>Closed-Date:    Fri Nov 16 14:14:05 PST 2001
>Last-Modified:  Fri Nov 16 14:17:11 PST 2001
>Originator:     Bob Willcox
>Release:        3.2-stable
>Organization:
Power Micro Research
>Environment:
FreeBSD luke.pmr.com 3.2-STABLE FreeBSD 3.2-STABLE #7: Tue Jul 20 12:00:05 CDT 1999     bob@luke.pmr.com:/usr/src/sys/compile/LUKE  i386

>Description:
When dumping a filesystem by specifying its mount point (rather than its
special file name) if there is no entry in fstab for the filesystem dump
fails with what can be a misleading error message.

For example if I dump /bsd (which has no fstab entry I get):

bob@luke-pf /usr/src/sbin/dump> dump -0ab 32 -f /dev/null /bsd                 
  DUMP: Date of this level 0 dump: Sat Jul 24 13:21:19 1999
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /bsd to /dev/null
  DUMP: bad sblock magic number

What has happened here is that dump, because it did not find an entry
for /bsd in /etc/fstab has opened the directory /bsd and tried to dump
it (and, of course, failed since it has no superblock).




>How-To-Repeat:
Run dump against a mounted filesystem that has no entry in /etc/fstab
and specifify its mount point rather than the special file path.
>Fix:
I have implemented a simple additional check to see that the open file
(should be the filesystem) isn't a directory (as it will be in this case).
If it is a directory, the changed code prints a warning message to assist
the user in diagnosing what he has done wrong.

The output from dump will now look like this:

bob@luke-pf /usr/src/sbin/dump> /usr/obj/usr/src/sbin/dump/dump -0ab 32 -f /d >
  DUMP: Date of this level 0 dump: Sat Jul 24 13:47:39 1999
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /bsd to /dev/null
  DUMP: WARNING: /bsd will be processed as a directory, not a filesystem
  DUMP: bad sblock magic number
  DUMP: The ENTIRE dump is aborted.

There are, no doubt, other and likely better ways to solve this problem
but this worked for me (next time I won't spend so much time tracking
down what's really wrong).

Here is a patch for the change should you be interested:

Index: src/sbin/dump/main.c
===================================================================
RCS file: /usr/cvs/FreeBSD/src/sbin/dump/main.c,v
retrieving revision 1.18
diff -u -r1.18 main.c
--- main.c      1998/09/16 20:52:12     1.18
+++ main.c      1999/07/24 18:47:32
@@ -68,6 +68,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/stat.h>

 #include "dump.h"
 #include "pathnames.h"
@@ -104,6 +105,7 @@
        register int ch;
        int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1;
        ino_t maxino;
+       struct stat sb;

        spcl.c_date = 0;
        (void)time((time_t *)&spcl.c_date);
@@ -327,6 +333,11 @@
                msg("Cannot open %s\n", disk);
                exit(X_STARTUP);
        }
+       if (fstat(diskfd, &sb))
+               quit("unable to fstat filesystem");
+       if (S_ISDIR(sb.st_mode))
+               msg("WARNING: %s will be processed as a directory, not a filesystem\n",
+                       disk);
        sync();
        sblock = (struct fs *)sblock_buf;
        bread(SBOFF, (char *) sblock, SBSIZE);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: iedowse 
State-Changed-When: Fri Nov 16 14:14:05 PST 2001 
State-Changed-Why:  

Committed (with slight adjustments), thanks! This should have 
been fixed years ago. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=12789 
>Unformatted:
