--- dump/restore/extern.h.orig	2004-11-19 09:11:17.000000000 +0100
+++ dump/restore/extern.h	2004-11-19 16:19:51.740275880 +0100
@@ -107,6 +107,7 @@
 void	 	 runcmdshell __P((void));
 char		*savename __P((char *));
 void	 	 setdirmodes __P((int));
+void		 setfilesys __P((struct s_spcl *));
 void		 setinput __P((char *));
 void		 setup __P((void));
 void	 	 skipdirs __P((void));
--- dump/restore/main.c.orig	2004-11-19 08:26:31.000000000 +0100
+++ dump/restore/main.c	2004-11-19 16:20:45.852049640 +0100
@@ -90,8 +90,8 @@
                                 otherwise just print a message using msg */
 
 int	aflag = 0, bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
-int	hflag = 1, mflag = 1, Mflag = 0, Nflag = 0, Vflag = 0, zflag = 0;
-int	uflag = 0, lflag = 0, Lflag = 0, oflag = 0;
+int	gflag = 0, hflag = 1, mflag = 1, Mflag = 0, Nflag = 0, Vflag = 0;
+int	uflag = 0, lflag = 0, Lflag = 0, oflag = 0, zflag = 0;
 int	ufs2flag = 0;
 char	*Afile = NULL;
 int	dokerberos = 0;
@@ -176,7 +176,7 @@
 		;                                                               
 	obsolete(&argc, &argv);
 	while ((ch = getopt(argc, argv, 
-		"aA:b:CcdD:f:F:hi"
+		"aA:b:CcdD:f:F:ghi"
 #ifdef KERBEROS
 		"k"
 #endif
@@ -223,6 +223,9 @@
 		case 'F':
 			bot_script = optarg;
 			break;
+		case 'g':
+			gflag = 1;
+			break;
 		case 'h':
 			hflag = 0;
 			break;
@@ -330,6 +333,8 @@
 	
 	if (Afile && command != 'i' && command != 'x' && command != 't')
 		errx(1, "A option is not valid for %c command", command);
+	if (gflag && command == 'R' && filesys[0] == '\0')
+		errx(1, "g option does require the D option for R command");
 
 	if (signal(SIGINT, onintr) == SIG_IGN)
 		(void) signal(SIGINT, SIG_IGN);
@@ -420,11 +425,6 @@
 		compare_ignore_not_found = 0;
 		compare_errors = 0;
 		setup();
-		printf("filesys = %s\n", filesys);
-		if (STAT(filesys, &stbuf) < 0)
-			err(1, "cannot stat directory %s", filesys);
-		if (chdir(filesys) < 0)
-			err(1, "cannot cd to %s", filesys);
 		compare_ignore_not_found = dumptime > 0;
 		initsymtable((char *)0);
 		extractdirs(0);
@@ -490,6 +490,7 @@
 	 */
 	case 'R':
 		aflag = 1; 	/* in -r or -R mode, -a is default */
+		setfilesys(NULL);
 		initsymtable(symtbl);
 		skipmaps();
 		skipdirs();
@@ -674,29 +675,31 @@
 		"usage:"
 		"\t%s -C [-cd" kerbflag "lMvVy] [-b blocksize] [-D filesystem] [-f file]\n"
 		"\t%s    [-F script] [-L limit] [-s fileno]\n"
-		"\t%s -i [-acdh" kerbflag "lmMouvVy] [-A file] [-b blocksize] [-f file]\n"
-		"\t%s    [-F script] " qfaflag "[-s fileno]\n"
+		"\t%s -i [-acdgh" kerbflag "lmMouvVy] [-A file] [-D filesystem] [-b blocksize]\n"
+		"\t%s    [-f file] [-F script] " qfaflag "[-s fileno]\n"
 #ifdef USE_QFA
-		"\t%s -P file [-acdh" kerbflag "lmMuvVy] [-A file] [-b blocksize]\n"
-		"\t%s    [-f file] [-F script] [-s fileno] [-X filelist] [file ...]\n"
-#endif
-		"\t%s -r [-cd" kerbflag "lMuvVy] [-b blocksize] [-f file] [-F script]\n"
-		"\t%s    [-s fileno] [-T directory]\n"
-		"\t%s -R [-cd" kerbflag "lMuvVy] [-b blocksize] [-f file] [-F script]\n"
-		"\t%s    [-s fileno] [-T directory]\n"
+		"\t%s -P file [-acdgh" kerbflag "lmMuvVy] [-A file] [-b blocksize]\n"
+		"\t%s    [-D filesystem] [-f file] [-F script] [-s fileno]\n"
+		"\t%s    [-X filelist] [file ...]\n"
+#endif
+		"\t%s -r [-cdg" kerbflag "lMuvVy] [-b blocksize] [-D filesystem] [-f file]\n"
+		"\t%s    [-F script] [-s fileno] [-T directory]\n"
+		"\t%s -R [-cdg" kerbflag "lMuvVy] [-b blocksize] [-D filesystem] [-f file]\n"
+		"\t%s    [-F script] [-s fileno] [-T directory]\n"
 		"\t%s -t [-cdh" kerbflag "lMuvVy] [-A file] [-b blocksize] [-f file]\n"
 		"\t%s    [-F script] " qfaflag "[-s fileno] [-X filelist] [file ...]\n"
-		"\t%s -x [-acdh" kerbflag "lmMouvVy] [-A file] [-b blocksize] [-f file]\n"
-		"\t%s    [-F script] " qfaflag "[-s fileno] [-X filelist] [file ...]\n",
+		"\t%s -x [-acdgh" kerbflag "lmMouvVy] [-A file] [-b blocksize] [-D filesystem]\n"
+		"\t%s    [-f file] [-F script] " qfaflag "[-s fileno] [-X filelist]\n"
+		"\t%s    [file ...]\n",
 		__progname, white, 
 		__progname, white, 
 #ifdef USE_QFA
-		__progname, white, 
+		__progname, white, white,
 #endif
 		__progname, white,
 		__progname, white, 
 		__progname, white, 
-		__progname, white);
+		__progname, white, white);
 	exit(1);
 }
 
--- dump/restore/restore.8.in.orig	2004-11-19 08:50:04.000000000 +0100
+++ dump/restore/restore.8.in	2004-11-19 08:58:16.000000000 +0100
@@ -42,9 +42,10 @@
 [\fB\-T \fIdirectory\fR]
 .PP
 .B restore \-i
-[\fB\-acdhklmMNouvVy\fR]
+[\fB\-acdghklmMNouvVy\fR]
 [\fB\-A \fIfile\fR]
 [\fB\-b \fIblocksize\fR]
+[\fB\-D \fIfilesystem\fR]
 [\fB\-f \fIfile\fR]
 [\fB\-F \fIscript\fR]
 [\fB\-Q \fIfile\fR]
@@ -53,9 +54,10 @@
 .PP
 .B restore \-P 
 .I file
-[\fB\-acdhklmMNuvVy\fR]
+[\fB\-acdghklmMNuvVy\fR]
 [\fB\-A \fIfile\fR]
 [\fB\-b \fIblocksize\fR]
+[\fB\-D \fIfilesystem\fR]
 [\fB\-f \fIfile\fR]
 [\fB\-F \fIscript\fR]
 [\fB\-s \fIfileno\fR]
@@ -64,16 +66,18 @@
 [ \fIfile ... \fR]
 .PP
 .B restore \-R
-[\fB\-cdklMNuvVy\fR]
+[\fB\-cdgklMNuvVy\fR]
 [\fB\-b \fIblocksize\fR]
+[\fB\-D \fIfilesystem\fR]
 [\fB\-f \fIfile\fR]
 [\fB\-F \fIscript\fR]
 [\fB\-s \fIfileno\fR]
 [\fB\-T \fIdirectory\fR]
 .PP
 .B restore \-r 
-[\fB\-cdklMNuvVy\fR]
+[\fB\-cdgklMNuvVy\fR]
 [\fB\-b \fIblocksize\fR]
+[\fB\-D \fIfilesystem\fR]
 [\fB\-f \fIfile\fR]
 [\fB\-F \fIscript\fR]
 [\fB\-s \fIfileno\fR]
@@ -92,9 +96,10 @@
 [ \fIfile ... \fR]
 .PP
 .B restore \-x 
-[\fB\-adchklmMNouvVy\fR]
+[\fB\-adcghklmMNouvVy\fR]
 [\fB\-A \fIfile\fR]
 [\fB\-b \fIblocksize\fR]
+[\fB\-D \fIfilesystem\fR]
 [\fB\-f \fIfile\fR]
 [\fB\-F \fIscript\fR]
 [\fB\-Q \fIfile\fR]
@@ -331,13 +336,26 @@
 to print debug information.
 .TP
 .BI \-D " filesystem"
-The
-.B \-D
-flag allows the user to specify the filesystem name when using
-.B restore
-with the
+In
 .B \-C
-option to check the backup.
+mode, the
+.B \-D
+option allows the user to specify against which filesystem the 
+comparision should be made (instead of using the one saved into
+the tape header). 
+.IP
+In
+.B \-i, \-P, \-r, \-R
+or
+.B \-x
+modes, if the
+.B \-g
+flag is specified, this options tells restore into which 
+directory the restore should be made (instead of the current
+directory if
+.B \-g
+is not specified, or the filesystem saved into the tape
+header otherwise).
 .TP
 .BI \-f " file"
 Read the backup from
@@ -371,6 +389,17 @@
 reverts back to the real user ID and the real group ID before running the 
 script.
 .TP
+.B \-g
+The
+.B \-g
+(goto) flag tells
+.B restore
+to extract the data into a different directory instead of the current 
+one. The target directory is read from the tape (same directory as the
+one that was saved on the tape), unless the
+.B \-D
+option says otherwise.
+.TP
 .B \-h
 Extract the actual directory, rather than the files that it references. This 
 prevents hierarchical restoration of complete subtrees from the dump.
--- dump/restore/restore.h.orig	2004-11-19 08:40:22.000000000 +0100
+++ dump/restore/restore.h	2004-11-19 08:45:11.000000000 +0100
@@ -52,6 +52,7 @@
 extern int	cvtflag;	/* convert from old to new tape format */
 extern int	bflag;		/* set input block size */
 extern int	dflag;		/* print out debugging info */
+extern int	gflag;		/* go into the directory */
 extern int	hflag;		/* restore heirarchies */
 extern int	lflag;		/* assume remote filename is a regular file */
 extern int	Lflag;		/* compare errors limit */
--- dump/restore/tape.c.orig	2004-11-19 08:34:45.000000000 +0100
+++ dump/restore/tape.c	2004-11-19 16:20:27.015913168 +0100
@@ -373,14 +373,8 @@
 	if (tapeposflag && (unsigned long)spcl.c_date != qfadumpdate)
 		errx(1, "different QFA/dumpdates detected\n");
 #endif
-	if (filesys[0] == '\0') {
-		char *dirptr;
-		strncpy(filesys, spcl.c_filesys, NAMELEN);
-		filesys[NAMELEN - 1] = '\0';
-		dirptr = strstr(filesys, " (dir");
-		if (dirptr != NULL)
-			*dirptr = '\0';
-	}
+	setfilesys(&spcl);
+
 	dumptime = spcl.c_ddate;
 	dumpdate = spcl.c_date;
 	if (STAT(".", &stbuf) < 0)
@@ -791,6 +785,27 @@
 	}
 }
 
+void
+setfilesys(struct s_spcl *s)
+{
+	struct STAT stbuf;
+
+	if (s && filesys[0] == '\0') {
+		char *dirptr;
+		strncpy(filesys, s->c_filesys, NAMELEN);
+		filesys[NAMELEN - 1] = '\0';
+		dirptr = strstr(filesys, " (dir");
+		if (dirptr != NULL)
+			*dirptr = '\0';
+	}
+	if (command == 'C' || gflag) {
+		fprintf(stdout, "filesys = %s\n", filesys);
+		if (STAT(filesys, &stbuf) < 0)
+			err(1, "cannot stat directory %s", filesys);
+		if (chdir(filesys) < 0)
+			err(1, "cannot cd to %s", filesys);
+	}
+}
 
 int
 extractfile(struct entry *ep, int doremove)
