From jin@adv-pc-1.lbl.gov  Fri Jul 25 14:56:18 1997
Received: from adv-pc-1.lbl.gov (adv-pc-1.lbl.gov [128.3.196.189])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id OAA26835
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Jul 1997 14:56:17 -0700 (PDT)
Received: (from jin@localhost)
	by adv-pc-1.lbl.gov (8.8.5/8.8.5) id OAA00641;
	Fri, 25 Jul 1997 14:56:15 -0700 (PDT)
Message-Id: <199707252156.OAA00641@adv-pc-1.lbl.gov>
Date: Fri, 25 Jul 1997 14:56:15 -0700 (PDT)
From: "Jin Guojun[ITG]" <jin@adv-pc-1.lbl.gov>
Reply-To: jin@adv-pc-1.lbl.gov
To: FreeBSD-gnats-submit@freebsd.org
Subject: dump fials for dumping subdirectory
X-Send-Pr-Version: 3.2

>Number:         4167
>Category:       bin
>Synopsis:       dump fials for dumping subdirectory
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 25 15:00:01 PDT 1997
>Closed-Date:    Sun Oct 12 14:46:00 MEST 1997
>Last-Modified:  Sun Oct 12 14:48:28 MEST 1997
>Originator:     Jin Guojun[ITG]
>Release:        FreeBSD all-RELEASE i386
>Organization:
>Environment:

	all FreeBSD RELEASEs

>Description:

	dump only dumps on the root of a file system.

>How-To-Repeat:

# uname -r
2.2.2-RELEASE

# dump 0f - src
  DUMP: Date of this level 0 dump: Fri Jul 25 14:10:19 1997
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping src to standard output
  DUMP: bad sblock magic number
  DUMP: The ENTIRE dump is aborted.
# dump 0f - /data/src | (cd /X/src ; restore xf -)
  DUMP: Date of this level 0 dump: Fri Jul 25 14:10:58 1997
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /data/src to standard output
  DUMP: bad sblock magic number
  DUMP: The ENTIRE dump is aborted.
Tape is not a dump tape
# dump 0f - /data | (cd /X/src ; restore xf -)
  DUMP: Date of this level 0 dump: Fri Jul 25 14:11:22 1997
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /dev/rsd0s2e (/data) to standard output
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 408089 tape blocks.
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: 82.06% done, finished in 0:02
  DUMP: DUMP: 408117 tape blocks
  DUMP: finished in 707 seconds, throughput 577 KBytes/sec
  DUMP: DUMP IS DONE
set owner/mode for '.'? [yn] y


# uname -r
3.0-970618-SNAP
# dump 0f - /usr/src/sys | more
  DUMP: Date of this level 0 dump: Fri Jul 25 14:18:12 1997
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /usr/src/sys to standard output
  DUMP: bad sblock magic number
  DUMP: The ENTIRE dump is aborted.
# dump 0f - /usr/src | more
  DUMP: Date of this level 0 dump: Fri Jul 25 14:18:25 1997
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /usr/src to standard output
  DUMP: bad sblock magic number
  DUMP: The ENTIRE dump is aborted.
#  dump 0f - /usr | more
  DUMP: Date of this level 0 dump: Fri Jul 25 14:23:32 1997
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /dev/rwd0s2e (/usr) to standard output
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 358154 tape blocks.
  DUMP: dumping (Pass III) [directories]


>Fix:
	
---------------- /usr/src/sbin/dump/main.c ----------
Line 337:
	if ((diskfd = open(disk, O_RDONLY)) < 0) {
		msg("Cannot open %s\n", disk);
		exit(X_ABORT);
	}
	sync();
	sblock = (struct fs *)sblock_buf;
	bread(SBOFF, (char *) sblock, SBSIZE);
	if (sblock->fs_magic != FS_MAGIC)
		quit("bad sblock magic number\n");
Line 347: ...
-----------------------

The variable "disk" on line 338 needs to be replaced as

	open(disk, ...)  ==>  open(get_rawdisk(disk), ...)

by using following routines.

-------------------- raw-dev.c ----------------------
#include "something may need"
#include <sys/stat.h>
#include <sys/mount.h>

static
subpath(full, sub)
register char	*full, *sub;
{
if (full && sub)	{
register int	len = strlen(sub);
	return	!strncmp(sub, full, len);
}
}


char *
get_rawdisk(name)
char *name;
{
long	mntsize, i;
struct statfs *mntbuf;
static char	cwd[256];

	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
	if (*name != '/' && cwd[0] == '\0')	{
		if (!getwd(cwd))	{
			cwd[0] = 0;
			return	0;
		}
		name = cwd;
	}
	for (i=mntsize; i--;)
		if (!strcmp(mntbuf[i].f_mntonname, name)	||
			subpath(name, mntbuf[i].f_mntonname))	{
		register char* cp=mntbuf[i].f_mntfromname;
			if (!strncmp(cp, "/dev/", 5))
				bcopy(cp+5, cp+6, strlen(cp)-5),
				cp[5] = 'r';
			return	cp;
		}
return (0);
}
---------------- end of raw-dev.c ------------------------

Hopefully, this will not break other things.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: joerg 
State-Changed-When: Sun Oct 12 14:46:00 MEST 1997 
State-Changed-Why:  

It seems to be intention that dump(8) only accepts the root of a 
filesystem.  This can be argued about, but most people who specify a 
subdirectory would expect it to dump data beginning right at this 
subdirectory, so the suggested change is IMHO counter-intuitive. 

If someone would offer a patch that makes dump(8) work on subdirs, i 
certainly wouldn't mind... 
>Unformatted:
