Subject: UPDATE 970418: patch to allow subdir dump(8)s
To: None <current-users@NetBSD.ORG>
From: Luke Mewburn <lukem@connect.com.au>
List: current-users
Date: 04/18/1997 16:47:16
Here's a patch to allow you to dump(8) a subset of files on a
filesystem.

I.e, if you have /home as a mountpoint, you could do
	dump 0f $TAPE /home/user1 /home/user2 /home/user3/foo
to just backup the directories or files referenced.

The patch also adds support for printing status information upon
receipt of a SIGINFO signal (refer to "stty status").

Could interested people test these in various situations, and get back
to me? I'd like to put these in the source tree soon. Thanks.


Index: dump.8
===================================================================
RCS file: /cvsroot/src/sbin/dump/dump.8,v
retrieving revision 1.15
diff -c -r1.15 dump.8
*** dump.8	1997/04/15 07:00:45	1.15
--- dump.8	1997/04/18 06:38:19
***************
*** 34,47 ****
  .\"
  .\"     @(#)dump.8	8.1 (Berkeley) 6/16/93
  .\"
! .Dd June 16, 1993
  .Dt DUMP 8
  .Os BSD 4
  .Sh NAME
  .Nm dump
  .Nd filesystem backup
  .Sh SYNOPSIS
! .Nm dump
  .Op Fl 0123456789cnu
  .Op Fl B Ar records
  .Op Fl b Ar blocksize
--- 34,47 ----
  .\"
  .\"     @(#)dump.8	8.1 (Berkeley) 6/16/93
  .\"
! .Dd April 18, 1997
  .Dt DUMP 8
  .Os BSD 4
  .Sh NAME
  .Nm dump
  .Nd filesystem backup
  .Sh SYNOPSIS
! .Nm
  .Op Fl 0123456789cnu
  .Op Fl B Ar records
  .Op Fl b Ar blocksize
***************
*** 50,56 ****
  .Op Fl h Ar level
  .Op Fl s Ar feet
  .Op Fl T Ar date
! .Ar filesystem
  .Nm dump
  .Op Fl W Li \&| Fl w
  .Pp
--- 50,56 ----
  .Op Fl h Ar level
  .Op Fl s Ar feet
  .Op Fl T Ar date
! .Ar files-to-dump
  .Nm dump
  .Op Fl W Li \&| Fl w
  .Pp
***************
*** 60,66 ****
  option syntax is implemented for backward compatibility, but
  is not documented here.)
  .Sh DESCRIPTION
! .Nm Dump
  examines files
  on a filesystem
  and determines which files
--- 60,66 ----
  option syntax is implemented for backward compatibility, but
  is not documented here.)
  .Sh DESCRIPTION
! .Nm
  examines files
  on a filesystem
  and determines which files
***************
*** 81,86 ****
--- 81,98 ----
  By default, the same output file name is used for each volume
  after prompting the operator to change media.
  .Pp
+ .Ar files-to-dump
+ is either a mountpoint of a filesystem,
+ or a list of files and directories on a single filesystem to be backed
+ up as a subset of the filesystem.
+ In the former case, either the path to a mounted filesystem,
+ or the device of an unmounted filesystem can be used.
+ In the latter case, certain restrictions are placed on the backup:
+ .Fl u
+ is ignored, the only dump level that is supported is
+ .Fl 0 ,
+ and all of the files must reside on the same filesystem.
+ .Pp
  The following options are supported by
  .Nm dump :
  .Bl -tag -width Ds
***************
*** 134,140 ****
  .Dq host:file ,
  or
  .Dq user@host:file ,
! .Nm dump
  writes to the named file on the remote host using
  .Xr rmt 8 .
  .It Fl h Ar level
--- 146,152 ----
  .Dq host:file ,
  or
  .Dq user@host:file ,
! .Nm
  writes to the named file on the remote host using
  .Xr rmt 8 .
  .It Fl h Ar level
***************
*** 149,155 ****
  but full backups retain them.
  .It Fl n
  Whenever
! .Nm dump
  requires operator attention,
  notify all operators in the group
  .Dq operator
--- 161,167 ----
  but full backups retain them.
  .It Fl n
  Whenever
! .Nm
  requires operator attention,
  notify all operators in the group
  .Dq operator
***************
*** 159,165 ****
  Attempt to calculate the amount of tape needed
  at a particular density.
  If this amount is exceeded,
! .Nm dump
  prompts for a new tape.
  It is recommended to be a bit conservative on this option.
  The default tape length is 2300 feet.
--- 171,177 ----
  Attempt to calculate the amount of tape needed
  at a particular density.
  If this amount is exceeded,
! .Nm
  prompts for a new tape.
  It is recommended to be a bit conservative on this option.
  The default tape length is 2300 feet.
***************
*** 194,201 ****
  .Pa /etc/dumpdates
  may be edited to change any of the fields,
  if necessary.
  .It Fl W
! .Nm Dump
  tells the operator what file systems need to be dumped.
  This information is gleaned from the files
  .Pa /etc/dumpdates
--- 206,217 ----
  .Pa /etc/dumpdates
  may be edited to change any of the fields,
  if necessary.
+ If a list of files or subdirectories is being dumped
+ (as opposed to and entire filesystem), then
+ .Fl u
+ is ignored.
  .It Fl W
! .Nm
  tells the operator what file systems need to be dumped.
  This information is gleaned from the files
  .Pa /etc/dumpdates
***************
*** 204,210 ****
  The
  .Fl W
  flag causes
! .Nm dump
  to print out, for each file system in
  .Pa /etc/dumpdates
  the most recent dump date and level,
--- 220,226 ----
  The
  .Fl W
  flag causes
! .Nm
  to print out, for each file system in
  .Pa /etc/dumpdates
  the most recent dump date and level,
***************
*** 212,224 ****
  If the
  .Fl W
  flag is set, all other options are ignored, and
! .Nm dump
  exits immediately.
  .It Fl w
  Is like W, but prints only those filesystems which need to be dumped.
  .El
  .Pp
! .Nm Dump
  requires operator intervention on these conditions:
  end of tape,
  end of dump,
--- 228,240 ----
  If the
  .Fl W
  flag is set, all other options are ignored, and
! .Nm
  exits immediately.
  .It Fl w
  Is like W, but prints only those filesystems which need to be dumped.
  .El
  .Pp
! .Nm
  requires operator intervention on these conditions:
  end of tape,
  end of dump,
***************
*** 228,242 ****
  In addition to alerting all operators implied by the
  .Fl n
  flag,
! .Nm dump
  interacts with the operator on
  .Nm dump Ns 's
  control terminal at times when
! .Nm dump
  can no longer proceed,
  or if something is grossly wrong.
  All questions
! .Nm dump
  poses
  .Em must
  be answered by typing
--- 244,258 ----
  In addition to alerting all operators implied by the
  .Fl n
  flag,
! .Nm
  interacts with the operator on
  .Nm dump Ns 's
  control terminal at times when
! .Nm
  can no longer proceed,
  or if something is grossly wrong.
  All questions
! .Nm
  poses
  .Em must
  be answered by typing
***************
*** 246,262 ****
  appropriately.
  .Pp
  Since making a dump involves a lot of time and effort for full dumps,
! .Nm dump
  checkpoints itself at the start of each tape volume.
  If writing that volume fails for some reason,
! .Nm dump
  will,
  with operator permission,
  restart itself from the checkpoint
  after the old tape has been rewound and removed,
  and a new tape has been mounted.
  .Pp
! .Nm Dump
  tells the operator what is going on at periodic intervals,
  including usually low estimates of the number of blocks to write,
  the number of tapes it will take, the time to completion, and
--- 262,278 ----
  appropriately.
  .Pp
  Since making a dump involves a lot of time and effort for full dumps,
! .Nm
  checkpoints itself at the start of each tape volume.
  If writing that volume fails for some reason,
! .Nm
  will,
  with operator permission,
  restart itself from the checkpoint
  after the old tape has been rewound and removed,
  and a new tape has been mounted.
  .Pp
! .Nm
  tells the operator what is going on at periodic intervals,
  including usually low estimates of the number of blocks to write,
  the number of tapes it will take, the time to completion, and
***************
*** 264,270 ****
  The output is verbose,
  so that others know that the terminal
  controlling
! .Nm dump
  is busy,
  and will be for some time.
  .Pp
--- 280,286 ----
  The output is verbose,
  so that others know that the terminal
  controlling
! .Nm
  is busy,
  and will be for some time.
  .Pp
***************
*** 301,306 ****
--- 317,335 ----
  .Pp
  After several months or so, the daily and weekly tapes should get
  rotated out of the dump cycle and fresh tapes brought in.
+ .Pp
+ If
+ .Nm
+ receives a
+ .Dv SIGINFO
+ signal
+ (see the
+ .Dq status
+ argument of
+ .Xr stty 1 )
+ whilst a backup is in progress, statistics on the amount completed,
+ current transfer rate, and estimated finished time, will be written
+ to the standard error output.
  .Sh FILES
  .Bl -tag -width /etc/dumpdates -compact
  .It Pa /dev/rst0
***************
*** 316,329 ****
  .Em operator
  .El
  .Sh SEE ALSO
  .Xr restore 8 ,
  .Xr rmt 8 ,
! .Xr dump 5 ,
! .Xr fstab 5
  .Sh DIAGNOSTICS
  Many, and verbose.
  .Pp
! Dump exits with zero status on success.
  Startup errors are indicated with an exit code of 1;
  abnormal termination is indicated with an exit code of 3.
  .Sh BUGS
--- 345,360 ----
  .Em operator
  .El
  .Sh SEE ALSO
+ .Xr dump 5 ,
+ .Xr fstab 5 ,
  .Xr restore 8 ,
  .Xr rmt 8 ,
! .Xr stty 1
  .Sh DIAGNOSTICS
  Many, and verbose.
  .Pp
! .Nm
! exits with zero status on success.
  Startup errors are indicated with an exit code of 1;
  abnormal termination is indicated with an exit code of 3.
  .Sh BUGS
***************
*** 333,339 ****
  reels already written just hang around until the entire tape
  is written.
  .Pp
! .Nm Dump
  with the
  .Fl W
  or
--- 364,370 ----
  reels already written just hang around until the entire tape
  is written.
  .Pp
! .Nm
  with the
  .Fl W
  or
***************
*** 344,351 ****
  even if listed in
  .Pa /etc/fstab .
  .Pp
  It would be nice if
! .Nm dump
  knew about the dump sequence,
  kept track of the tapes scribbled on,
  told the operator which tape to mount when,
--- 375,387 ----
  even if listed in
  .Pa /etc/fstab .
  .Pp
+ When dumping a list of files or subdirectories, access privileges are
+ required to scan the directory (as this is done via the
+ .Xr fts 3
+ routines rather than directly accessing the filesystem).
+ .Pp
  It would be nice if
! .Nm
  knew about the dump sequence,
  kept track of the tapes scribbled on,
  told the operator which tape to mount when,
***************
*** 354,358 ****
  .Xr restore .
  .Sh HISTORY
  A
! .Nm dump
  command appeared in Version 6 AT&T UNIX.
--- 390,394 ----
  .Xr restore .
  .Sh HISTORY
  A
! .Nm
  command appeared in Version 6 AT&T UNIX.
Index: dump.h
===================================================================
RCS file: /cvsroot/src/sbin/dump/dump.h,v
retrieving revision 1.10
diff -c -r1.10 dump.h
*** dump.h	1997/04/10 05:36:23	1.10
--- dump.h	1997/04/18 06:38:20
***************
*** 101,113 ****
  void	quit __P((const char *fmt, ...));
  void	set_operators __P((void));
  time_t	do_stats __P((void));
  void	timeest __P((void));
  time_t	unctime __P((char *str));
  
  /* mapping routines */
  struct	dinode;
  long	blockest __P((struct dinode *dp));
! int	mapfiles __P((ino_t maxino, long *tapesize));
  int	mapdirs __P((ino_t maxino, long *tapesize));
  
  /* file dumping routines */
--- 101,115 ----
  void	quit __P((const char *fmt, ...));
  void	set_operators __P((void));
  time_t	do_stats __P((void));
+ void	statussig __P((int));
  void	timeest __P((void));
  time_t	unctime __P((char *str));
  
  /* mapping routines */
  struct	dinode;
  long	blockest __P((struct dinode *dp));
! int	mapfiles __P((ino_t maxino, long *tapesize, char *disk,
! 		    char * const *dirv));
  int	mapdirs __P((ino_t maxino, long *tapesize));
  
  /* file dumping routines */
Index: main.c
===================================================================
RCS file: /cvsroot/src/sbin/dump/main.c,v
retrieving revision 1.11
diff -c -r1.11 main.c
*** main.c	1997/04/15 01:09:51	1.11
--- main.c	1997/04/18 06:38:22
***************
*** 49,54 ****
--- 49,57 ----
  
  #include <sys/param.h>
  #include <sys/time.h>
+ #include <sys/stat.h>
+ #include <sys/mount.h>
+ 
  #ifdef sunos
  #include <sys/vnode.h>
  
***************
*** 110,115 ****
--- 113,120 ----
  	int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1;
  	ino_t maxino;
  	time_t tnow;
+ 	int dirlist;
+ 	char *toplevel;
  
  	uid = getuid();
  	euid = geteuid();
***************
*** 204,217 ****
  		(void)fprintf(stderr, "Must specify disk or filesystem\n");
  		exit(X_ABORT);
  	}
! 	disk = *argv++;
! 	argc--;
! 	if (argc >= 1) {
! 		(void)fprintf(stderr, "Unknown arguments to dump:");
! 		while (argc--)
! 			(void)fprintf(stderr, " %s", *argv++);
! 		(void)fprintf(stderr, "\n");
! 		exit(X_ABORT);
  	}
  	if (Tflag && uflag) {
  	        (void)fprintf(stderr,
--- 209,274 ----
  		(void)fprintf(stderr, "Must specify disk or filesystem\n");
  		exit(X_ABORT);
  	}
! 
! 	/*
! 	 *	determine if disk is a subdirectory, and setup appropriately
! 	 */
! 	dirlist = 0;
! 	toplevel = NULL;
! 	for (i = 0; i < argc; i++) {
! 		struct stat sb;
! 		struct statfs fsbuf;
! 
! 		if (lstat(argv[i], &sb) == -1) {
! 			msg("Cannot lstat %s: %s\n", argv[i], 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));
! 			exit(X_ABORT);
! 		}
! 		if (strcmp(argv[i], 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 */
! 		}
! 		if (!disk) {
! 			if ((toplevel = strdup(fsbuf.f_mntonname)) == NULL) {
! 				msg("Cannot malloc diskname\n");
! 				exit(X_ABORT);
! 			}
! 			disk = toplevel;
! 			if (uflag) {
! 				msg("Ignoring u flag for subdir dump\n");
! 				uflag = 0;
! 			}
! 			if (level > '0') {
! 				msg("Subdir dump is done at level 0\n");
! 				level = '0';
! 			}
! 			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);
! 				exit(X_ABORT);
! 			}
! 		}
! 		msg("Dumping file/directory %s\n", argv[i]);
! 		dirlist++;
! 	}
! 	if (dirlist == 0) {
! 		disk = *argv++;
! 		if (argc != 1) {
! 			(void)fprintf(stderr, "Excess arguments to dump:");
! 			while (--argc)
! 				(void)fprintf(stderr, " %s", *argv++);
! 			(void)fprintf(stderr, "\n");
! 			exit(X_ABORT);
! 		}
  	}
  	if (Tflag && uflag) {
  	        (void)fprintf(stderr,
***************
*** 272,277 ****
--- 329,335 ----
  
  	set_operators();	/* /etc/group snarfed */
  	getfstab();		/* /etc/fstab snarfed */
+ 
  	/*
  	 *	disk can be either the full special file name,
  	 *	the suffix of the special file name,
***************
*** 282,288 ****
  	if (dt != NULL) {
  		disk = rawname(dt->fs_spec);
  		(void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
! 		(void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
  	} else {
  		(void)strncpy(spcl.c_dev, disk, NAMELEN);
  		(void)strncpy(spcl.c_filesys, "an unlisted file system",
--- 340,350 ----
  	if (dt != NULL) {
  		disk = rawname(dt->fs_spec);
  		(void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
! 		if (dirlist != 0)
! 			(void)snprintf(spcl.c_filesys, NAMELEN,
! 			    "a subset of %s", dt->fs_file);
! 		else
! 			(void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
  	} else {
  		(void)strncpy(spcl.c_dev, disk, NAMELEN);
  		(void)strncpy(spcl.c_filesys, "an unlisted file system",
***************
*** 336,343 ****
  
  	nonodump = spcl.c_level < honorlevel;
  
  	msg("mapping (Pass I) [regular files]\n");
! 	anydirskipped = mapfiles(maxino, &tapesize);
  
  	msg("mapping (Pass II) [directories]\n");
  	while (anydirskipped) {
--- 398,408 ----
  
  	nonodump = spcl.c_level < honorlevel;
  
+ 	(void)signal(SIGINFO, statussig);
+ 
  	msg("mapping (Pass I) [regular files]\n");
! 	anydirskipped = mapfiles(maxino, &tapesize, toplevel,
! 	    (dirlist ? argv : NULL));
  
  	msg("mapping (Pass II) [directories]\n");
  	while (anydirskipped) {
***************
*** 452,458 ****
  	msg("Date of this level %c dump: %s", level,
  		spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
  	msg("Date this dump completed:  %s", ctime(&tnow));
! 	msg("Average transfer rate: %ldK/s\n", xferrate / tapeno);
  	putdumptime();
  	trewind();
  	broadcast("DUMP IS DONE!\7\7\n");
--- 517,523 ----
  	msg("Date of this level %c dump: %s", level,
  		spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
  	msg("Date this dump completed:  %s", ctime(&tnow));
! 	msg("Average transfer rate: %ld KB/s\n", xferrate / tapeno);
  	putdumptime();
  	trewind();
  	broadcast("DUMP IS DONE!\7\7\n");
***************
*** 559,565 ****
  	/* Allocate space for new arguments. */
  	if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
  	    (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
! 		err(1, NULL);
  
  	*nargv++ = *argv;
  	argv += 2;
--- 624,630 ----
  	/* Allocate space for new arguments. */
  	if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
  	    (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
! 		err(1, "malloc");
  
  	*nargv++ = *argv;
  	argv += 2;
***************
*** 578,584 ****
  				usage();
  			}
  			if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
! 				err(1, NULL);
  			nargv[0][0] = '-';
  			nargv[0][1] = *ap;
  			(void)strcpy(&nargv[0][2], *argv);
--- 643,649 ----
  				usage();
  			}
  			if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
! 				err(1, "malloc");
  			nargv[0][0] = '-';
  			nargv[0][1] = *ap;
  			(void)strcpy(&nargv[0][2], *argv);
***************
*** 602,608 ****
  	}
  
  	/* Copy remaining arguments. */
! 	while (*nargv++ = *argv++);
  
  	/* Update argument count. */
  	*argcp = nargv - *argvp - 1;
--- 667,674 ----
  	}
  
  	/* Copy remaining arguments. */
! 	while ((*nargv++ = *argv++) != NULL)
! 		;
  
  	/* Update argument count. */
  	*argcp = nargv - *argvp - 1;
Index: optr.c
===================================================================
RCS file: /cvsroot/src/sbin/dump/optr.c,v
retrieving revision 1.7
diff -c -r1.7 optr.c
*** optr.c	1997/04/15 01:09:52	1.7
--- optr.c	1997/04/18 06:38:23
***************
*** 314,320 ****
  
  	(void) time((time_t *) &tnow);
  	if (tnow >= tschedule) {
! 		tschedule = tnow + 300;
  		if (blockswritten < 500)
  			return;	
  		deltat = tstart_writing - tnow +
--- 314,320 ----
  
  	(void) time((time_t *) &tnow);
  	if (tnow >= tschedule) {
! 		tschedule = tnow + 600;		/* ten minutes */
  		if (blockswritten < 500)
  			return;	
  		deltat = tstart_writing - tnow +
Index: tape.c
===================================================================
RCS file: /cvsroot/src/sbin/dump/tape.c,v
retrieving revision 1.10
diff -c -r1.10 tape.c
*** tape.c	1997/04/15 07:00:49	1.10
--- tape.c	1997/04/18 06:38:26
***************
*** 260,270 ****
  	if (ttaken > 0) {
  		msg("Volume %d took %d:%02d:%02d\n", tapeno,
  		    ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60); 
! 		msg("Volume %d transfer rate: %ldK/s\n", tapeno,
  		    blocks / ttaken);
  		xferrate += blocks / ttaken;
  	}
  	return(tnow);
  }
  
  static void
--- 260,295 ----
  	if (ttaken > 0) {
  		msg("Volume %d took %d:%02d:%02d\n", tapeno,
  		    ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60); 
! 		msg("Volume %d transfer rate: %ld KB/s\n", tapeno,
  		    blocks / ttaken);
  		xferrate += blocks / ttaken;
  	}
  	return(tnow);
+ }
+ 
+ /*
+  * statussig --
+  *	information message upon receipt of SIGINFO
+  *	(derived from optr.c::timeest())
+  */
+ void
+ statussig(notused)
+ 	int notused;
+ {
+ 	time_t	tnow, deltat;
+ 	char	msgbuf[128];
+ 
+ 	if (blockswritten < 500)
+ 		return;	
+ 	(void) time((time_t *) &tnow);
+ 	deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing))
+ 		/ blockswritten * tapesize;
+ 	(void)snprintf(msgbuf, sizeof(msgbuf),
+ 	    "%3.2f%% done at %ld KB/s, finished in %d:%02d\n",
+ 	    (blockswritten * 100.0) / tapesize,
+ 	    (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume),
+ 	    (int)(deltat / 3600), (int)((deltat % 3600) / 60));
+ 	write(STDERR_FILENO, msgbuf, strlen(msgbuf));
  }
  
  static void
Index: traverse.c
===================================================================
RCS file: /cvsroot/src/sbin/dump/traverse.c,v
retrieving revision 1.16
diff -c -r1.16 traverse.c
*** traverse.c	1997/04/15 01:09:54	1.16
--- traverse.c	1997/04/18 06:38:29
***************
*** 59,64 ****
--- 59,66 ----
  #include <protocols/dumprestore.h>
  
  #include <ctype.h>
+ #include <errno.h>
+ #include <fts.h>
  #include <stdio.h>
  #ifdef __STDC__
  #include <string.h>
***************
*** 134,139 ****
--- 136,171 ----
  #endif
  
  /*
+  * Determine if given inode should be dumped
+  */
+ void
+ mapfileino(ino, tapesize, dirskipped)
+ 	ino_t ino;
+ 	long *tapesize;
+ 	int *dirskipped;
+ {
+ 	int mode;
+ 	struct dinode *dp;
+ 
+ 	dp = getino(ino);
+ 	if ((mode = (dp->di_mode & IFMT)) == 0)
+ 		return;
+ 	SETINO(ino, usedinomap);
+ 	if (mode == IFDIR)
+ 		SETINO(ino, dumpdirmap);
+ 	if (WANTTODUMP(dp)) {
+ 		SETINO(ino, dumpinomap);
+ 		if (mode != IFREG && mode != IFDIR && mode != IFLNK)
+ 			*tapesize += 1;
+ 		else
+ 			*tapesize += blockest(dp);
+ 		return;
+ 	}
+ 	if (mode == IFDIR)
+ 		*dirskipped = 1;
+ }
+ 
+ /*
   * Dump pass 1.
   *
   * Walk the inode list for a filesystem to find all allocated inodes
***************
*** 141,172 ****
   * the directories in the filesystem.
   */
  int
! mapfiles(maxino, tapesize)
  	ino_t maxino;
  	long *tapesize;
  {
  	int mode;
  	ino_t ino;
  	struct dinode *dp;
  	int anydirskipped = 0;
  
! 	for (ino = ROOTINO; ino < maxino; ino++) {
! 		dp = getino(ino);
! 		if ((mode = (dp->di_mode & IFMT)) == 0)
! 			continue;
! 		SETINO(ino, usedinomap);
! 		if (mode == IFDIR)
! 			SETINO(ino, dumpdirmap);
! 		if (WANTTODUMP(dp)) {
! 			SETINO(ino, dumpinomap);
! 			if (mode != IFREG && mode != IFDIR && mode != IFLNK)
! 				*tapesize += 1;
  			else
! 				*tapesize += blockest(dp);
! 			continue;
  		}
- 		if (mode == IFDIR)
- 			anydirskipped = 1;
  	}
  	/*
  	 * Restore gets very upset if the root is not dumped,
--- 173,262 ----
   * the directories in the filesystem.
   */
  int
! mapfiles(maxino, tapesize, disk, dirv)
  	ino_t maxino;
  	long *tapesize;
+ 	char *disk;
+ 	char * const *dirv;
  {
  	int mode;
  	ino_t ino;
  	struct dinode *dp;
  	int anydirskipped = 0;
  
! 	if (dirv != NULL) {
! 		char curdir[MAXPATHLEN];
! 		FTS *dirh;
! 		FTSENT *entry;
! 		int d;
! 
! 		if (getcwd(curdir, sizeof(curdir)) == NULL) {
! 			msg("Can't determine cwd: %s\n", strerror(errno));
! 			dumpabort(0);
! 		}
! 		if ((dirh = fts_open(dirv, FTS_PHYSICAL|FTS_SEEDOT|FTS_XDEV,
! 		    		    (int (*)())NULL)) == NULL) {
! 			msg("fts_open failed: %s\n", strerror(errno));
! 			dumpabort(0);
! 		}
! 		while ((entry = fts_read(dirh)) != NULL) {
! 			switch (entry->fts_info) {
! 			case FTS_DNR:		/* an error */
! 			case FTS_ERR:
! 			case FTS_NS:
! 				msg("Can't fts_read %s: %s\n", entry->fts_path,
! 				    strerror(errno));
! 			case FTS_DP:		/* already seen dir */
! 				continue;
! 			}
! 			mapfileino(entry->fts_statp->st_ino, tapesize,
! 			    &anydirskipped);
! 		}
! 		(void)fts_close(dirh);
! 
! 		/*
! 		 * Add any parent directories
! 		 */
! 		for (d = 0 ; dirv[d] != NULL ; d++) {
! 			char path[MAXPATHLEN];
! 
! 			if (dirv[d][0] != '/')
! 				(void)snprintf(path, sizeof(path), "%s/%s",
! 				    curdir, dirv[d]);
  			else
! 				(void)snprintf(path, sizeof(path), "%s",
! 				    dirv[d]);
! 			while (strcmp(path, disk) != 0) {
! 				char *p;
! 				struct stat sb;
! 
! 				if (*path == '\0')
! 					break;
! 				if ((p = strrchr(path, '/')) == NULL)
! 					break;
! 				if (p == path)
! 					break;
! 				*p = '\0';
! 				if (stat(path, &sb) == -1) {
! 					msg("Can't stat %s: %s\n", path,
! 					    strerror(errno));
! 					break;
! 				}
! 				mapfileino(sb.st_ino, tapesize, &anydirskipped);
! 			}
! 		}
! 
! 		/*
! 		 * Ensure that the root inode actually appears in the
! 		 * file list for a subdir
! 		 */
! 		mapfileino(ROOTINO, tapesize, &anydirskipped);
! 	} else {
! 		ino_t ino;
! 
! 		for (ino = ROOTINO; ino < maxino; ino++) {
! 			mapfileino(ino, tapesize, &anydirskipped);
  		}
  	}
  	/*
  	 * Restore gets very upset if the root is not dumped,