summaryrefslogtreecommitdiffstats
path: root/sbin/restore
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/restore')
-rw-r--r--sbin/restore/Makefile6
-rw-r--r--sbin/restore/dirs.c106
-rw-r--r--sbin/restore/extern.h4
-rw-r--r--sbin/restore/interactive.c72
-rw-r--r--sbin/restore/main.c46
-rw-r--r--sbin/restore/pathnames.h2
-rw-r--r--sbin/restore/restore.8355
-rw-r--r--sbin/restore/restore.c58
-rw-r--r--sbin/restore/symtab.c34
-rw-r--r--sbin/restore/tape.c125
-rw-r--r--sbin/restore/utilities.c45
11 files changed, 383 insertions, 470 deletions
diff --git a/sbin/restore/Makefile b/sbin/restore/Makefile
index 6d4da1fb..916e6f0 100644
--- a/sbin/restore/Makefile
+++ b/sbin/restore/Makefile
@@ -7,11 +7,9 @@ SRCS= main.c interactive.c restore.c dirs.c symtab.c tape.c utilities.c \
dumprmt.c
BINOWN= root
BINGRP= tty
-BINMODE=6555
-MAN8= restore.0
+BINMODE=2555
+MAN8= restore.8
MLINKS+=restore.8 rrestore.8
.PATH: ${.CURDIR}/../dump
-all: ${PROG} ${MAN8}
-
.include <bsd.prog.mk>
diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c
index d6c12d3..a4038eb 100644
--- a/sbin/restore/dirs.c
+++ b/sbin/restore/dirs.c
@@ -37,7 +37,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95";
+static char sccsid[] = "@(#)dirs.c 8.2 (Berkeley) 1/21/94";
#endif /* not lint */
#include <sys/param.h>
@@ -45,9 +45,9 @@ static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95";
#include <sys/stat.h>
#include <sys/time.h>
+#include <ufs/ffs/fs.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
-#include <ufs/ffs/fs.h>
#include <protocols/dumprestore.h>
#include <errno.h>
@@ -81,10 +81,9 @@ static struct inotab *inotab[HASHSIZE];
struct modeinfo {
ino_t ino;
struct timeval timep[2];
- mode_t mode;
- uid_t uid;
- gid_t gid;
- int flags;
+ short mode;
+ short uid;
+ short gid;
};
/*
@@ -105,9 +104,9 @@ struct rstdirdesc {
static long seekpt;
static FILE *df, *mf;
static RST_DIR *dirp;
-static char dirfile[32] = "#"; /* No file */
-static char modefile[32] = "#"; /* No file */
-static char dot[2] = "."; /* So it can be modified */
+static char dirfile[MAXPATHLEN] = "#"; /* No file */
+static char modefile[MAXPATHLEN] = "#"; /* No file */
+static char dot[2] = "."; /* So it can be modified */
/*
* Format of old style directories.
@@ -143,11 +142,18 @@ extractdirs(genmode)
register struct dinode *ip;
struct inotab *itp;
struct direct nulldir;
+ int fd;
vprintf(stdout, "Extract directories from tape\n");
- (void) sprintf(dirfile, "%s/rstdir%d", _PATH_TMP, dumpdate);
- df = fopen(dirfile, "w");
- if (df == NULL) {
+ (void) sprintf(dirfile, "%srstdir%d", _PATH_TMP, dumpdate);
+ if (command != 'r' && command != 'R') {
+ (void *) strcat(dirfile, "-XXXXXX");
+ fd = mkstemp(dirfile);
+ } else
+ fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
+ if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
fprintf(stderr,
"restore: %s - cannot create directory temporary\n",
dirfile);
@@ -155,9 +161,15 @@ extractdirs(genmode)
done(1);
}
if (genmode != 0) {
- (void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
- mf = fopen(modefile, "w");
- if (mf == NULL) {
+ (void) sprintf(modefile, "%srstmode%d", _PATH_TMP, dumpdate);
+ if (command != 'r' && command != 'R') {
+ (void *) strcat(modefile, "-XXXXXX");
+ fd = mkstemp(modefile);
+ } else
+ fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
+ if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
fprintf(stderr,
"restore: %s - cannot create modefile \n",
modefile);
@@ -202,13 +214,13 @@ void
skipdirs()
{
- while ((curfile.dip->di_mode & IFMT) == IFDIR) {
+ while (curfile.dip && (curfile.dip->di_mode & IFMT) == IFDIR) {
skipfile();
}
}
/*
- * Recursively find names and inumbers of all files in subtree
+ * Recursively find names and inumbers of all files in subtree
* pname and pass them off to be processed.
*/
void
@@ -240,8 +252,9 @@ treescan(pname, ino, todo)
* begin search through the directory
* skipping over "." and ".."
*/
- (void) strncpy(locname, pname, MAXPATHLEN);
- (void) strncat(locname, "/", MAXPATHLEN);
+ (void) strncpy(locname, pname, sizeof(locname) - 1);
+ locname[sizeof(locname) - 1] = '\0';
+ (void) strncat(locname, "/", sizeof(locname) - strlen(locname));
namelen = strlen(locname);
rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
dp = rst_readdir(dirp); /* "." */
@@ -259,11 +272,11 @@ treescan(pname, ino, todo)
/*
* a zero inode signals end of directory
*/
- while (dp != NULL) {
+ while (dp != NULL && dp->d_ino != 0) {
locname[namelen] = '\0';
- if (namelen + dp->d_namlen >= MAXPATHLEN) {
+ if (namelen + dp->d_namlen >= sizeof(locname)) {
fprintf(stderr, "%s%s: name exceeds %d char\n",
- locname, dp->d_name, MAXPATHLEN);
+ locname, dp->d_name, sizeof(locname) - 1);
} else {
(void) strncat(locname, dp->d_name, (int)dp->d_namlen);
treescan(locname, dp->d_ino, todo);
@@ -272,6 +285,8 @@ treescan(pname, ino, todo)
dp = rst_readdir(dirp);
bpt = rst_telldir(dirp);
}
+ if (dp == NULL)
+ fprintf(stderr, "corrupted directory: %s.\n", locname);
}
/*
@@ -319,7 +334,7 @@ searchdir(inum, name)
len = strlen(name);
do {
dp = rst_readdir(dirp);
- if (dp == NULL)
+ if (dp == NULL || dp->d_ino == 0)
return (NULL);
} while (dp->d_namlen != len || strncmp(dp->d_name, name, len) != 0);
return (dp);
@@ -352,13 +367,12 @@ putdir(buf, size)
if (Bcvt)
swabst((u_char *)"ls", (u_char *) dp);
if (oldinofmt && dp->d_ino != 0) {
-# if BYTE_ORDER == BIG_ENDIAN
- if (Bcvt)
- dp->d_namlen = dp->d_type;
-# else
- if (!Bcvt)
- dp->d_namlen = dp->d_type;
-# endif
+#if BYTE_ORDER == BIG_ENDIAN
+ if (Bcvt)
+#else
+ if (!Bcvt)
+#endif
+ dp->d_namlen = dp->d_type;
dp->d_type = DT_UNKNOWN;
}
i = DIRBLKSIZ - (loc & (DIRBLKSIZ - 1));
@@ -411,7 +425,7 @@ putent(dp)
(void) fwrite(dirbuf, 1, DIRBLKSIZ, df);
dirloc = 0;
}
- memmove(dirbuf + dirloc, dp, (long)dp->d_reclen);
+ bcopy((char *)dp, dirbuf + dirloc, (long)dp->d_reclen);
prev = dirloc;
dirloc += dp->d_reclen;
}
@@ -434,7 +448,7 @@ dcvt(odp, ndp)
register struct direct *ndp;
{
- memset(ndp, 0, (long)(sizeof *ndp));
+ bzero((char *)ndp, (long)(sizeof *ndp));
ndp->d_ino = odp->d_ino;
ndp->d_type = DT_UNKNOWN;
(void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
@@ -477,7 +491,7 @@ rst_readdir(dirp)
for (;;) {
if (dirp->dd_loc == 0) {
- dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
+ dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
DIRBLKSIZ);
if (dirp->dd_size <= 0) {
dprintf(stderr, "error reading directory\n");
@@ -496,8 +510,8 @@ rst_readdir(dirp)
return (NULL);
}
dirp->dd_loc += dp->d_reclen;
- if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0)
- return (NULL);
+ if (dp->d_ino == 0 && strcmp(dp->d_name, "/") != 0)
+ continue;
if (dp->d_ino >= maxino) {
dprintf(stderr, "corrupted directory: bad inum %d\n",
dp->d_ino);
@@ -583,9 +597,15 @@ setdirmodes(flags)
struct modeinfo node;
struct entry *ep;
char *cp;
-
+
vprintf(stdout, "Set directory mode, owner, and times.\n");
- (void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
+ if (command == 'r' || command == 'R')
+ (void) sprintf(modefile, "%srstmode%d", _PATH_TMP, dumpdate);
+ if (modefile[0] == '#') {
+ panic("modefile not defined\n");
+ fprintf(stderr, "directory mode, owner, and times not set\n");
+ return;
+ }
mf = fopen(modefile, "r");
if (mf == NULL) {
fprintf(stderr, "fopen: %s\n", strerror(errno));
@@ -616,7 +636,6 @@ setdirmodes(flags)
cp = myname(ep);
(void) chown(cp, node.uid, node.gid);
(void) chmod(cp, node.mode);
- (void) chflags(cp, node.flags);
utimes(cp, node.timep);
ep->e_flags &= ~NEW;
}
@@ -709,12 +728,11 @@ allocinotab(ino, dip, seekpt)
if (mf == NULL)
return (itp);
node.ino = ino;
- node.timep[0].tv_sec = dip->di_atime;
- node.timep[0].tv_usec = dip->di_atimensec / 1000;
- node.timep[1].tv_sec = dip->di_mtime;
- node.timep[1].tv_usec = dip->di_mtimensec / 1000;
+ node.timep[0].tv_sec = dip->di_atime.tv_sec;
+ node.timep[0].tv_usec = dip->di_atime.tv_nsec / 1000;
+ node.timep[1].tv_sec = dip->di_mtime.tv_sec;
+ node.timep[1].tv_usec = dip->di_mtime.tv_nsec / 1000;
node.mode = dip->di_mode;
- node.flags = dip->di_flags;
node.uid = dip->di_uid;
node.gid = dip->di_gid;
(void) fwrite((char *)&node, 1, sizeof(struct modeinfo), mf);
@@ -739,7 +757,7 @@ inotablookup(ino)
/*
* Clean up and exit
*/
-__dead void
+void
done(exitcode)
int exitcode;
{
diff --git a/sbin/restore/extern.h b/sbin/restore/extern.h
index d82569e..c82f997 100644
--- a/sbin/restore/extern.h
+++ b/sbin/restore/extern.h
@@ -36,7 +36,7 @@
struct entry *addentry __P((char *, ino_t, int));
long addfile __P((char *, ino_t, int));
void badentry __P((struct entry *, char *));
-void canon __P((char *, char *));
+void canon __P((char *, char *, int));
void checkrestore __P((void));
void closemt __P((void));
void createfiles __P((void));
@@ -45,7 +45,7 @@ void createlinks __P((void));
long deletefile __P((char *, ino_t, int));
void deleteino __P((ino_t));
ino_t dirlookup __P((const char *));
-__dead void done __P((int));
+void done __P((int)) __dead2;
void dumpsymtable __P((char *, long));
void extractdirs __P((int));
int extractfile __P((char *));
diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c
index 76aa74f..9e8b9ae 100644
--- a/sbin/restore/interactive.c
+++ b/sbin/restore/interactive.c
@@ -32,16 +32,16 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)interactive.c 8.5 (Berkeley) 5/1/95";
+static char sccsid[] = "@(#)interactive.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include <ufs/ffs/fs.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
-#include <ufs/ffs/fs.h>
#include <protocols/dumprestore.h>
#include <setjmp.h>
@@ -82,10 +82,10 @@ struct arglist {
static char *copynext __P((char *, char *));
static int fcmp __P((const void *, const void *));
static void formatf __P((struct afile *, int));
-static void getcmd __P((char *, char *, char *, struct arglist *));
+static void getcmd __P((char *, char *, char *, int, struct arglist *));
struct dirent *glob_readdir __P((RST_DIR *dirp));
static int glob_stat __P((const char *, struct stat *));
-static void mkentry __P((char *, struct direct *, struct afile *));
+static void mkentry __P((struct direct *, struct afile *));
static void printlist __P((char *, char *));
/*
@@ -109,7 +109,7 @@ runcmdshell()
arglist.glob.gl_closedir = (void *)rst_closedir;
arglist.glob.gl_lstat = glob_stat;
arglist.glob.gl_stat = glob_stat;
- canon("/", curdir);
+ canon("/", curdir, sizeof(curdir));
loop:
if (setjmp(reset) != 0) {
if (arglist.freeglob != 0) {
@@ -121,7 +121,7 @@ loop:
volno = 0;
}
runshell = 1;
- getcmd(curdir, cmd, name, &arglist);
+ getcmd(curdir, cmd, name, sizeof(name), &arglist);
switch (cmd[0]) {
/*
* Add elements to the extraction list.
@@ -300,9 +300,10 @@ loop:
* eliminate any embedded ".." components.
*/
static void
-getcmd(curdir, cmd, name, ap)
+getcmd(curdir, cmd, name, size, ap)
char *curdir, *cmd, *name;
struct arglist *ap;
+ int size;
{
register char *cp;
static char input[BUFSIZ];
@@ -357,7 +358,7 @@ getnext:
* If it is an absolute pathname, canonicalize it and return it.
*/
if (rawname[0] == '/') {
- canon(rawname, name);
+ canon(rawname, name, size);
} else {
/*
* For relative pathnames, prepend the current directory to
@@ -366,7 +367,7 @@ getnext:
(void) strcpy(output, curdir);
(void) strcat(output, "/");
(void) strcat(output, rawname);
- canon(output, name);
+ canon(output, name, size);
}
if (glob(name, GLOB_ALTDIRFUNC, NULL, &ap->glob) < 0)
fprintf(stderr, "%s: out of memory\n", ap->cmd);
@@ -438,8 +439,9 @@ copynext(input, output)
* remove any imbedded "." and ".." components.
*/
void
-canon(rawname, canonname)
+canon(rawname, canonname, len)
char *rawname, *canonname;
+ int len;
{
register char *cp, *np;
@@ -449,6 +451,11 @@ canon(rawname, canonname)
(void) strcpy(canonname, ".");
else
(void) strcpy(canonname, "./");
+ if (strlen(canonname) + strlen(rawname) >= len) {
+ fprintf(stderr, "canonname: not enough bufferspace\n");
+ done(1);
+ }
+
(void) strcat(canonname, rawname);
/*
* Eliminate multiple and trailing '/'s
@@ -496,17 +503,15 @@ printlist(name, basename)
register struct direct *dp;
struct afile single;
RST_DIR *dirp;
- int entries, len, namelen;
- char locname[MAXPATHLEN + 1];
+ int entries, len;
dp = pathsearch(name);
- if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
- (!vflag && dp->d_ino == WINO))
+ if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0))
return;
if ((dirp = rst_opendir(name)) == NULL) {
entries = 1;
list = &single;
- mkentry(name, dp, list);
+ mkentry(dp, list);
len = strlen(basename) + 1;
if (strlen(name) - len > single.len) {
freename(single.fname);
@@ -528,28 +533,17 @@ printlist(name, basename)
fprintf(stderr, "%s:\n", name);
entries = 0;
listp = list;
- (void) strncpy(locname, name, MAXPATHLEN);
- (void) strncat(locname, "/", MAXPATHLEN);
- namelen = strlen(locname);
while (dp = rst_readdir(dirp)) {
- if (dp == NULL)
+ if (dp == NULL || dp->d_ino == 0)
break;
if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)
continue;
- if (!vflag && (dp->d_ino == WINO ||
- strcmp(dp->d_name, ".") == 0 ||
+ if (vflag == 0 &&
+ (strcmp(dp->d_name, ".") == 0 ||
strcmp(dp->d_name, "..") == 0))
continue;
- locname[namelen] = '\0';
- if (namelen + dp->d_namlen >= MAXPATHLEN) {
- fprintf(stderr, "%s%s: name exceeds %d char\n",
- locname, dp->d_name, MAXPATHLEN);
- } else {
- (void) strncat(locname, dp->d_name,
- (int)dp->d_namlen);
- mkentry(locname, dp, listp++);
- entries++;
- }
+ mkentry(dp, listp++);
+ entries++;
}
rst_closedir(dirp);
if (entries == 0) {
@@ -572,8 +566,7 @@ printlist(name, basename)
* Read the contents of a directory.
*/
static void
-mkentry(name, dp, fp)
- char *name;
+mkentry(dp, fp)
struct direct *dp;
register struct afile *fp;
{
@@ -588,7 +581,7 @@ mkentry(name, dp, fp)
fp->len = cp - fp->fname;
if (dflag && TSTINO(fp->fnum, dumpmap) == 0)
fp->prefix = '^';
- else if ((np = lookupname(name)) != NULL && (np->e_flags & NEW))
+ else if ((np = lookupino(fp->fnum)) != NULL && (np->e_flags & NEW))
fp->prefix = '*';
else
fp->prefix = ' ';
@@ -616,10 +609,6 @@ mkentry(name, dp, fp)
fp->postfix = '#';
break;
- case DT_WHT:
- fp->postfix = '%';
- break;
-
case DT_UNKNOWN:
case DT_DIR:
if (inodetype(dp->d_ino) == NODE)
@@ -715,7 +704,7 @@ glob_readdir(dirp)
static struct dirent adirent;
while ((dp = rst_readdir(dirp)) != NULL) {
- if (!vflag && dp->d_ino == WINO)
+ if (dp->d_ino == 0)
continue;
if (dflag || TSTINO(dp->d_ino, dumpmap))
break;
@@ -724,7 +713,7 @@ glob_readdir(dirp)
return (NULL);
adirent.d_fileno = dp->d_ino;
adirent.d_namlen = dp->d_namlen;
- memmove(adirent.d_name, dp->d_name, dp->d_namlen + 1);
+ bcopy(dp->d_name, adirent.d_name, dp->d_namlen + 1);
return (&adirent);
}
@@ -739,8 +728,7 @@ glob_stat(name, stp)
register struct direct *dp;
dp = pathsearch(name);
- if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
- (!vflag && dp->d_ino == WINO))
+ if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0))
return (-1);
if (inodetype(dp->d_ino) == NODE)
stp->st_mode = IFDIR;
diff --git a/sbin/restore/main.c b/sbin/restore/main.c
index 57620fe..c2c804f 100644
--- a/sbin/restore/main.c
+++ b/sbin/restore/main.c
@@ -38,14 +38,14 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
+static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/7/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
-#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
+#include <ufs/ufs/dinode.h>
#include <protocols/dumprestore.h>
#include <err.h>
@@ -54,7 +54,6 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include "pathnames.h"
#include "restore.h"
@@ -67,7 +66,7 @@ long dumpnum = 1;
long volno = 0;
long ntrec;
char *dumpmap;
-char *usedinomap;
+char *clrimap;
ino_t maxino;
time_t dumptime;
time_t dumpdate;
@@ -83,13 +82,18 @@ main(argc, argv)
{
int ch;
ino_t ino;
- char *inputdev = _PATH_DEFTAPE;
+ char *inputdev;
char *symtbl = "./restoresymtable";
char *p, name[MAXPATHLEN];
+ /* Temp files should *not* be readable. We set permissions later. */
+ (void) umask(077);
+
if (argc < 2)
usage();
+ if ((inputdev = getenv("TAPE")) == NULL)
+ inputdev = _PATH_DEFTAPE;
obsolete(&argc, &argv);
while ((ch = getopt(argc, argv, "b:cdf:himNRrs:tvxy")) != EOF)
switch(ch) {
@@ -235,7 +239,7 @@ main(argc, argv)
extractdirs(0);
initsymtable((char *)0);
while (argc--) {
- canon(*argv++, name);
+ canon(*argv++, name, sizeof(name));
ino = dirlookup(name);
if (ino == 0)
continue;
@@ -250,7 +254,7 @@ main(argc, argv)
extractdirs(1);
initsymtable((char *)0);
while (argc--) {
- canon(*argv++, name);
+ canon(*argv++, name, sizeof(name));
ino = dirlookup(name);
if (ino == 0)
continue;
@@ -272,12 +276,12 @@ main(argc, argv)
static void
usage()
{
- (void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
- "restore -i [-chmvy] [-b blocksize] [-f file] [-s fileno]",
- "restore -r [-cvy] [-b blocksize] [-f file] [-s fileno]",
- "restore -R [-cvy] [-b blocksize] [-f file] [-s fileno]",
- "restore -x [-chmvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
- "restore -t [-chvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
+ (void)fprintf(stderr, "usage:\t%s%s%s%s%s",
+ "restore tfhsvy [file ...]\n",
+ "\trestore xfhmsvy [file ...]\n",
+ "\trestore ifhmsvy\n",
+ "\trestore rfsvy\n",
+ "\trestore Rfsvy\n");
done(1);
}
@@ -309,23 +313,22 @@ obsolete(argcp, argvp)
err(1, NULL);
*nargv++ = *argv;
- argv += 2;
+ argv += 2, argc -= 2;
for (flags = 0; *ap; ++ap) {
- switch (*ap) {
+ switch(*ap) {
case 'b':
case 'f':
case 's':
- if (*argv == NULL) {
- warnx("option requires an argument -- %c", *ap);
- usage();
- }
+ if (argc < 1)
+ 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);
- ++argv;
+ if (*argv != NULL)
+ ++argv;
++nargv;
break;
default:
@@ -346,7 +349,4 @@ obsolete(argcp, argvp)
/* Copy remaining arguments. */
while (*nargv++ = *argv++);
-
- /* Update argument count. */
- *argcp = nargv - *argvp - 1;
}
diff --git a/sbin/restore/pathnames.h b/sbin/restore/pathnames.h
index b9541f9..f86f349 100644
--- a/sbin/restore/pathnames.h
+++ b/sbin/restore/pathnames.h
@@ -40,4 +40,4 @@
#include <paths.h>
-#define _PATH_DEFTAPE "/dev/rmt8"
+#define _PATH_DEFTAPE "/dev/rst0"
diff --git a/sbin/restore/restore.8 b/sbin/restore/restore.8
index 6ad1b46..5f7e4a8 100644
--- a/sbin/restore/restore.8
+++ b/sbin/restore/restore.8
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)restore.8 8.4 (Berkeley) 5/1/95
-.\"
-.Dd May 1, 1995
+.\" @(#)restore.8 8.2 (Berkeley) 12/11/93
+.\" $Id$
+.\" "
+.Dd December 11, 1993
.Dt RESTORE 8
.Os BSD 4
.Sh NAME
@@ -39,43 +40,8 @@
.Nd "restore files or file systems from backups made with dump"
.Sh SYNOPSIS
.Nm restore
-.Fl i
-.Op Fl chmvy
-.Op Fl b Ar blocksize
-.Op Fl f Ar file
-.Op Fl s Ar fileno
-.Nm restore
-.Fl R
-.Op Fl cvy
-.Op Fl b Ar blocksize
-.Op Fl f Ar file
-.Op Fl s Ar fileno
-.Nm restore
-.Fl r
-.Op Fl cvy
-.Op Fl b Ar blocksize
-.Op Fl f Ar file
-.Op Fl s Ar fileno
-.Nm restore
-.Fl t
-.Op Fl chvy
-.Op Fl b Ar blocksize
-.Op Fl f Ar file
-.Op Fl s Ar fileno
-.Op file ...
-.Nm restore
-.Fl x
-.Op Fl chmvy
-.Op Fl b Ar blocksize
-.Op Fl f Ar file
-.Op Fl s Ar fileno
-.Op file ...
-.Pp
-.in -\\n(iSu
-(The
-.Bx 4.3
-option syntax is implemented for backward compatibility, but
-is not documented here.)
+.Ar key
+.Op Ar name Ar ...
.Sh DESCRIPTION
The
.Nm restore
@@ -91,17 +57,109 @@ works across a network;
to do this see the
.Fl f
flag described below.
+The actions
+of
+.Nm restore
+are controlled by the given
+.Cm key ,
+which
+is a string of characters containing
+at most one function letter and possibly
+one or more function modifiers.
Other arguments to the command are file or directory
names specifying the files that are to be restored.
Unless the
-.Fl h
-flag is specified (see below),
+.Cm h
+key is specified (see below),
the appearance of a directory name refers to
the files and (recursively) subdirectories of that directory.
.Pp
-Exactly one of the following flags is required:
+The function portion of
+the key is specified by one of the following letters:
.Bl -tag -width Ds
-.It Fl i
+.It Cm r
+Restore (rebuild a file system).
+The target file system should be made pristine with
+.Xr newfs 8 ,
+mounted and the
+user
+.Xr cd Ns 'd
+into the pristine file system
+before starting the restoration of the initial level 0 backup. If the
+level 0 restores successfully, the
+.Cm r
+key may be used to restore
+any necessary incremental backups on top of the level 0.
+The
+.Cm r
+key precludes an interactive file extraction and can be
+detrimental to one's health if not used carefully (not to mention
+the disk). An example:
+.Bd -literal -offset indent
+newfs /dev/rrp0g eagle
+mount /dev/rp0g /mnt
+cd /mnt
+
+restore rf /dev/rst8
+.Ed
+.Pp
+Note that
+.Nm restore
+leaves a file
+.Pa restoresymtable
+in the root directory to pass information between incremental
+restore passes.
+This file should be removed when the last incremental has been
+restored.
+.Pp
+.Nm Restore ,
+in conjunction with
+.Xr newfs 8
+and
+.Xr dump 8 ,
+may be used to modify file system parameters
+such as size or block size.
+.It Cm R
+.Nm Restore
+requests a particular tape of a multi volume set on which to restart
+a full restore
+(see the
+.Cm r
+key above).
+This is useful if the restore has been interrupted.
+.It Cm x
+The named files are read from the given media.
+If a named file matches a directory whose contents
+are on the backup
+and the
+.Cm h
+key is not specified,
+the directory is recursively extracted.
+The owner, modification time,
+and mode are restored (if possible).
+If no file argument is given,
+then the root directory is extracted,
+which results in the entire content of the
+backup being extracted,
+unless the
+.Cm h
+key has been specified.
+.It Cm t
+The names of the specified files are listed if they occur
+on the backup.
+If no file argument is given,
+then the root directory is listed,
+which results in the entire content of the
+backup being listed,
+unless the
+.Cm h
+key has been specified.
+Note that the
+.Cm t
+key replaces the function of the old
+.Xr dumpdir 8
+program.
+.It Cm i
This mode allows interactive restoration of files from a dump.
After reading in the directory information from the dump,
.Nm restore
@@ -117,8 +175,8 @@ files to be extracted.
If a directory is specified, then it and all its descendents are
added to the extraction list
(unless the
-.Fl h
-flag is specified on the command line).
+.Cm h
+key is specified on the command line).
Files that are on the extraction list are prepended with a ``*''
when they are listed by
.Ic ls .
@@ -130,8 +188,8 @@ files to be extracted.
If a directory is specified, then it and all its descendents are
deleted from the extraction list
(unless the
-.Fl h
-flag is specified on the command line).
+.Cm h
+key is specified on the command line).
The most expedient way to extract most of the files from a directory
is to add the directory to the extraction list and then delete
those files that are not needed.
@@ -148,8 +206,7 @@ List a summary of the available commands.
List the current or specified directory.
Entries that are directories are appended with a ``/''.
Entries that have been marked for extraction are prepended with a ``*''.
-If the verbose
-flag is set the inode number of each entry is also listed.
+If the verbose key is set the inode number of each entry is also listed.
.It Ic pwd
Print the full pathname of the current working directory.
.It Ic quit
@@ -162,170 +219,93 @@ nothing is extracted from the dump.
This is useful for cleaning up after a restore has been prematurely aborted.
.It Ic verbose
The sense of the
-.Fl v
-flag is toggled.
-When set, the verbose flag causes the
+.Cm v
+key is toggled.
+When set, the verbose key causes the
.Ic ls
command to list the inode numbers of all entries.
It also causes
.Nm restore
to print out information about each file as it is extracted.
.El
-.It Fl R
-.Nm Restore
-requests a particular tape of a multi volume set on which to restart
-a full restore
-(see the
-.Fl r
-flag below).
-This is useful if the restore has been interrupted.
-.It Fl r
-Restore (rebuild a file system).
-The target file system should be made pristine with
-.Xr newfs 8 ,
-mounted and the user
-.Xr cd Ns 'd
-into the pristine file system
-before starting the restoration of the initial level 0 backup. If the
-level 0 restores successfully, the
-.Fl r
-flag may be used to restore
-any necessary incremental backups on top of the level 0.
-The
-.Fl r
-flag precludes an interactive file extraction and can be
-detrimental to one's health if not used carefully (not to mention
-the disk). An example:
-.Bd -literal -offset indent
-newfs /dev/rrp0g eagle
-mount /dev/rp0g /mnt
-cd /mnt
-
-restore rf /dev/rst8
-.Ed
-.Pp
-Note that
-.Nm restore
-leaves a file
-.Pa restoresymtable
-in the root directory to pass information between incremental
-restore passes.
-This file should be removed when the last incremental has been
-restored.
-.Pp
-.Nm Restore ,
-in conjunction with
-.Xr newfs 8
-and
-.Xr dump 8 ,
-may be used to modify file system parameters
-such as size or block size.
-.It Fl t
-The names of the specified files are listed if they occur
-on the backup.
-If no file argument is given,
-then the root directory is listed,
-which results in the entire content of the
-backup being listed,
-unless the
-.Fl h
-flag has been specified.
-Note that the
-.Fl t
-flag replaces the function of the old
-.Xr dumpdir 8
-program.
-.ne 1i
-.It Fl x
-The named files are read from the given media.
-If a named file matches a directory whose contents
-are on the backup
-and the
-.Fl h
-flag is not specified,
-the directory is recursively extracted.
-The owner, modification time,
-and mode are restored (if possible).
-If no file argument is given,
-then the root directory is extracted,
-which results in the entire content of the
-backup being extracted,
-unless the
-.Fl h
-flag has been specified.
.El
.Pp
-The following additional options may be specified:
+The following characters may be used in addition to the letter
+that selects the function desired.
.Bl -tag -width Ds
-.It Fl b Ar blocksize
-The number of kilobytes per dump record.
+.It Cm b
+The next argument to
+.Nm restore
+is used as the block size of the media (in kilobytes).
If the
.Fl b
option is not specified,
.Nm restore
-tries to determine the block size dynamically.
-.It Fl c
-Normally,
+tries to determine the media block size dynamically.
+.It Cm f
+The next argument to
.Nm restore
-will try to determine dynamically whether the dump was made from an
-old (pre-4.4) or new format file sytem. The
-.Fl c
-flag disables this check, and only allows reading a dump in the old
-format.
-.It Fl f Ar file
-Read the backup from
-.Ar file ;
-.Ar file
-may be a special device file
-like
-.Pa /dev/rmt12
-(a tape drive),
-.Pa /dev/rsd1c
-(a disk drive),
-an ordinary file,
-or
-.Ql Fl
-(the standard input).
+is used as the name of the archive instead
+of
+.Pa /dev/rst0 .
If the name of the file is of the form
.Dq host:file ,
-or
-.Dq user@host:file ,
.Nm restore
reads from the named file on the remote host using
.Xr rmt 8 .
+If the name of the file is
+.Ql Fl ,
+.Nm restore
+reads from standard input.
+Thus,
+.Xr dump 8
+and
+.Nm restore
+can be used in a pipeline to dump and restore a file system
+with the command
+.Bd -literal -offset indent
+dump 0f - /usr | (cd /mnt; restore xf -)
+.Ed
.Pp
-.It Fl h
-Extract the actual directory,
+.It Cm h
+.Nm Restore
+extracts the actual directory,
rather than the files that it references.
This prevents hierarchical restoration of complete subtrees
from the dump.
-.It Fl m
-Extract by inode numbers rather than by file name.
+.It Cm m
+.Nm Restore
+will extract by inode numbers rather than by file name.
This is useful if only a few files are being extracted,
and one wants to avoid regenerating the complete pathname
to the file.
-.It Fl s Ar fileno
-Read from the specified
-.Ar fileno
-on a multi-file tape.
-File numbering starts at 1.
-.It Fl v
+.It Cm s
+The next argument to
+.Nm restore
+is a number which
+selects the file on a multi-file dump tape. File numbering
+starts at 1.
+.It Cm v
Normally
.Nm restore
does its work silently.
The
-.Fl v
+.Cm v
(verbose)
-flag causes it to type the name of each file it treats
+key causes it to type the name of each file it treats
preceded by its file type.
-.It Fl y
-Do not ask the user whether to abort the restore in the event of an error.
-Always try to skip over the bad block(s) and continue.
+.It Cm y
+.Nm Restore
+will not ask whether it should abort the restore if it gets an error.
+It will always try to skip over the bad block(s) and continue as
+best it can.
.El
.Sh DIAGNOSTICS
+Complaints about bad key characters.
+.Pp
Complaints if it gets a read error.
If
-.Fl y
+.Cm y
has been specified, or the user responds
.Ql y ,
.Nm restore
@@ -335,10 +315,10 @@ If a backup was made using more than one tape volume,
.Nm restore
will notify the user when it is time to mount the next volume.
If the
-.Fl x
+.Cm x
or
-.Fl i
-flag has been specified,
+.Cm i
+key has been specified,
.Nm restore
will also ask which volume the user wishes to mount.
The fastest way to extract a few files is to
@@ -393,7 +373,7 @@ This message lists the number of blocks that were skipped over.
.El
.Sh FILES
.Bl -tag -width "./restoresymtable" -compact
-.It Pa /dev/rmt?
+.It Pa /dev/rst0
the default tape drive
.It Pa /tmp/rstdir*
file containing directories on the tape.
@@ -404,14 +384,14 @@ information passed between incremental restores.
.El
.Sh SEE ALSO
.Xr dump 8 ,
-.Xr newfs 8 ,
+.Xr ft 8 ,
.Xr mount 8 ,
-.Xr mkfs 8 ,
+.Xr newfs 8 ,
.Xr rmt 8
.Sh BUGS
.Nm Restore
can get confused when doing incremental restores from
-dumps that were made on active file systems.
+dump that were made on active file systems.
.Pp
A level zero dump must be done after a full restore.
Because restore runs in user code,
@@ -419,6 +399,11 @@ it has no control over inode allocation;
thus a full dump must be done to get a new set of directories
reflecting the new inode numbering,
even though the contents of the files is unchanged.
+.Pp
+To do a network restore, you have to run restore as root. This is due
+to the previous security history of dump and restore. (restore is
+written to be setuid root, but we are not certain all bugs are gone
+from the restore code - run setuid at your own risk.)
.Sh HISTORY
The
.Nm restore
diff --git a/sbin/restore/restore.c b/sbin/restore/restore.c
index b628997..97bd6cc 100644
--- a/sbin/restore/restore.c
+++ b/sbin/restore/restore.c
@@ -32,7 +32,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)restore.c 8.3 (Berkeley) 9/13/94";
+static char sccsid[] = "@(#)restore.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */
#include <sys/types.h>
@@ -85,8 +85,6 @@ addfile(name, ino, type)
dprintf(stdout, "%s: not on the tape\n", name);
return (descend);
}
- if (ino == WINO && command == 'i' && !vflag)
- return (descend);
if (!mflag) {
(void) sprintf(buf, "./%u", ino);
name = buf;
@@ -126,17 +124,13 @@ deletefile(name, ino, type)
if (TSTINO(ino, dumpmap) == 0)
return (descend);
- ep = lookupname(name);
- if (ep != NULL) {
+ ep = lookupino(ino);
+ if (ep != NULL)
ep->e_flags &= ~NEW;
- ep->e_flags |= REMOVED;
- if (ep->e_type != NODE)
- freeentry(ep);
- }
return (descend);
}
-/*
+/*
* The following four routines implement the incremental
* restore algorithm. The first removes old entries, the second
* does renames and calculates the extraction list, the third
@@ -145,45 +139,28 @@ deletefile(name, ino, type)
*
* Directories cannot be immediately deleted, as they may have
* other files in them which need to be moved out first. As
- * directories to be deleted are found, they are put on the
+ * directories to be deleted are found, they are put on the
* following deletion list. After all deletions and renames
* are done, this list is actually deleted.
*/
static struct entry *removelist;
/*
- * Remove invalid whiteouts from the old tree.
* Remove unneeded leaves from the old tree.
* Remove directories from the lookup chains.
*/
void
removeoldleaves()
{
- register struct entry *ep, *nextep;
- register ino_t i, mydirino;
+ register struct entry *ep;
+ register ino_t i;
vprintf(stdout, "Mark entries to be removed.\n");
- if (ep = lookupino(WINO)) {
- vprintf(stdout, "Delete whiteouts\n");
- for ( ; ep != NULL; ep = nextep) {
- nextep = ep->e_links;
- mydirino = ep->e_parent->e_ino;
- /*
- * We remove all whiteouts that are in directories
- * that have been removed or that have been dumped.
- */
- if (TSTINO(mydirino, usedinomap) &&
- !TSTINO(mydirino, dumpmap))
- continue;
- delwhiteout(ep);
- freeentry(ep);
- }
- }
for (i = ROOTINO + 1; i < maxino; i++) {
ep = lookupino(i);
if (ep == NULL)
continue;
- if (TSTINO(i, usedinomap))
+ if (TSTINO(i, clrimap))
continue;
for ( ; ep != NULL; ep = ep->e_links) {
dprintf(stdout, "%s: REMOVE\n", myname(ep));
@@ -226,7 +203,7 @@ nodeupdates(name, ino, type)
# define MODECHG 0x8 /* mode of inode changed */
/*
- * This routine is called once for each element in the
+ * This routine is called once for each element in the
* directory hierarchy, with a full path name.
* The "type" value is incorrectly specified as LEAF for
* directories that are not on the dump tape.
@@ -417,7 +394,7 @@ nodeupdates(name, ino, type)
* that we need to rename, so we delete it from the symbol
* table, and put it on the list to be deleted eventually.
* Conversely if a directory is to be created, it must be
- * done immediately, rather than waiting until the
+ * done immediately, rather than waiting until the
* extraction phase.
*/
case ONTAPE|INOFND|MODECHG:
@@ -487,7 +464,7 @@ nodeupdates(name, ino, type)
default:
panic("[%s] %s: impossible state\n", keyval(key), name);
break;
- }
+ }
return (descend);
}
@@ -629,7 +606,7 @@ createleaves(symtabfile)
/*
* If we find files on the tape that have no corresponding
* directory entries, then we must have found a file that
- * was created while the dump was in progress. Since we have
+ * was created while the dump was in progress. Since we have
* no name for it, we discard it knowing that it will be
* on the next incremental tape.
*/
@@ -768,15 +745,6 @@ createlinks()
register ino_t i;
char name[BUFSIZ];
- if (ep = lookupino(WINO)) {
- vprintf(stdout, "Add whiteouts\n");
- for ( ; ep != NULL; ep = ep->e_links) {
- if ((ep->e_flags & NEW) == 0)
- continue;
- (void) addwhiteout(myname(ep));
- ep->e_flags &= ~NEW;
- }
- }
vprintf(stdout, "Add links\n");
for (i = ROOTINO; i < maxino; i++) {
ep = lookupino(i);
@@ -808,7 +776,7 @@ checkrestore()
register ino_t i;
vprintf(stdout, "Check the symbol table.\n");
- for (i = WINO; i < maxino; i++) {
+ for (i = ROOTINO; i < maxino; i++) {
for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
ep->e_flags &= ~KEEP;
if (ep->e_type == NODE)
diff --git a/sbin/restore/symtab.c b/sbin/restore/symtab.c
index 16b1d84..dc779a3 100644
--- a/sbin/restore/symtab.c
+++ b/sbin/restore/symtab.c
@@ -32,7 +32,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)symtab.c 8.3 (Berkeley) 4/28/95";
+static char sccsid[] = "@(#)symtab.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */
/*
@@ -83,7 +83,7 @@ lookupino(inum)
{
register struct entry *ep;
- if (inum < WINO || inum >= maxino)
+ if (inum < ROOTINO || inum >= maxino)
return (NULL);
for (ep = entry[inum % entrytblsize]; ep != NULL; ep = ep->e_next)
if (ep->e_ino == inum)
@@ -101,7 +101,7 @@ addino(inum, np)
{
struct entry **epp;
- if (inum < WINO || inum >= maxino)
+ if (inum < ROOTINO || inum >= maxino)
panic("addino: out of range %d\n", inum);
epp = &entry[inum % entrytblsize];
np->e_ino = inum;
@@ -123,7 +123,7 @@ deleteino(inum)
register struct entry *next;
struct entry **prev;
- if (inum < WINO || inum >= maxino)
+ if (inum < ROOTINO || inum >= maxino)
panic("deleteino: out of range %d\n", inum);
prev = &entry[inum % entrytblsize];
for (next = *prev; next != NULL; next = next->e_next) {
@@ -150,8 +150,11 @@ lookupname(name)
cp = name;
for (ep = lookupino(ROOTINO); ep != NULL; ep = ep->e_entries) {
- for (np = buf; *cp != '/' && *cp != '\0'; )
+ for (np = buf; *cp != '/' && *cp != '\0' &&
+ np < &buf[sizeof(buf)]; )
*np++ = *cp++;
+ if (np == &buf[sizeof(buf)])
+ break;
*np = '\0';
for ( ; ep != NULL; ep = ep->e_sibling)
if (strcmp(ep->e_name, buf) == 0)
@@ -174,7 +177,7 @@ lookupparent(name)
struct entry *ep;
char *tailindex;
- tailindex = strrchr(name, '/');
+ tailindex = rindex(name, '/');
if (tailindex == NULL)
return (NULL);
*tailindex = '\0';
@@ -199,7 +202,7 @@ myname(ep)
for (cp = &namebuf[MAXPATHLEN - 2]; cp > &namebuf[ep->e_namlen]; ) {
cp -= ep->e_namlen;
- memmove(cp, ep->e_name, (long)ep->e_namlen);
+ bcopy(ep->e_name, cp, (long)ep->e_namlen);
if (ep == lookupino(ROOTINO))
return (cp);
*(--cp) = '/';
@@ -229,7 +232,7 @@ addentry(name, inum, type)
if (freelist != NULL) {
np = freelist;
freelist = np->e_next;
- memset(np, 0, (long)sizeof(struct entry));
+ bzero((char *)np, (long)sizeof(struct entry));
} else {
np = (struct entry *)calloc(1, sizeof(struct entry));
if (np == NULL)
@@ -246,7 +249,7 @@ addentry(name, inum, type)
addino(ROOTINO, np);
return (np);
}
- np->e_name = savename(strrchr(name, '/') + 1);
+ np->e_name = savename(rindex(name, '/') + 1);
np->e_namlen = strlen(np->e_name);
np->e_parent = ep;
np->e_sibling = ep->e_entries;
@@ -330,7 +333,7 @@ moveentry(ep, newname)
ep->e_sibling = np->e_entries;
np->e_entries = ep;
}
- cp = strrchr(newname, '/') + 1;
+ cp = rindex(newname, '/') + 1;
freename(ep->e_name);
ep->e_name = savename(cp);
ep->e_namlen = strlen(cp);
@@ -366,7 +369,7 @@ removeentry(ep)
/*
* Table of unused string entries, sorted by length.
- *
+ *
* Entries are allocated in STRTBLINCR sized pieces so that names
* of similar lengths can use the same entry. The value of STRTBLINCR
* is chosen so that every entry has at least enough space to hold
@@ -422,7 +425,7 @@ freename(name)
char *name;
{
struct strhdr *tp, *np;
-
+
tp = &strtblhdr[strlen(name) / STRTBLINCR];
np = (struct strhdr *)name;
np->next = tp->next;
@@ -470,7 +473,7 @@ dumpsymtable(filename, checkpt)
* Assign indicies to each entry
* Write out the string entries
*/
- for (i = WINO; i <= maxino; i++) {
+ for (i = ROOTINO; i < maxino; i++) {
for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
ep->e_index = mynum++;
(void) fwrite(ep->e_name, sizeof(char),
@@ -482,9 +485,10 @@ dumpsymtable(filename, checkpt)
*/
tep = &temp;
stroff = 0;
- for (i = WINO; i <= maxino; i++) {
+ for (i = ROOTINO; i < maxino; i++) {
for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
- memmove(tep, ep, (long)sizeof(struct entry));
+ bcopy((char *)ep, (char *)tep,
+ (long)sizeof(struct entry));
tep->e_name = (char *)stroff;
stroff += allocsize(ep->e_namlen);
tep->e_parent = (struct entry *)ep->e_parent->e_index;
diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c
index a8d833f..79fba3f 100644
--- a/sbin/restore/tape.c
+++ b/sbin/restore/tape.c
@@ -37,7 +37,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
+static char sccsid[] = "@(#)tape.c 8.3 (Berkeley) 4/1/94";
#endif /* not lint */
#include <sys/param.h>
@@ -63,7 +63,7 @@ static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
static long fssize = MAXBSIZE;
static int mt = -1;
static int pipein = 0;
-static char magtape[BUFSIZ];
+static char *magtape;
static int blkcnt;
static int numtrec;
static char *tapebuf;
@@ -119,9 +119,9 @@ setinput(source)
terminal = stdin;
#ifdef RRESTORE
- if (strchr(source, ':')) {
+ if (index(source, ':')) {
host = source;
- source = strchr(host, ':');
+ source = index(host, ':');
*source++ = '\0';
if (rmthost(host) == 0)
done(1);
@@ -146,7 +146,11 @@ setinput(source)
pipein++;
}
setuid(getuid()); /* no longer need or want root privileges */
- (void) strcpy(magtape, source);
+ magtape = strdup(source);
+ if (magtape == NULL) {
+ fprintf(stderr, "Cannot allocate space for magtape buffer\n");
+ done(1);
+ }
}
void
@@ -250,8 +254,8 @@ setup()
dprintf(stdout, "maxino = %d\n", maxino);
map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
if (map == NULL)
- panic("no memory for active inode map\n");
- usedinomap = map;
+ panic("no memory for file removal list\n");
+ clrimap = map;
curfile.action = USING;
getfile(xtrmap, xtrmapskip);
if (spcl.c_type != TS_BITS) {
@@ -264,13 +268,6 @@ setup()
dumpmap = map;
curfile.action = USING;
getfile(xtrmap, xtrmapskip);
- /*
- * If there may be whiteout entries on the tape, pretend that the
- * whiteout inode exists, so that the whiteout entries can be
- * extracted.
- */
- if (oldinofmt == 0)
- SETINO(WINO, dumpmap);
}
/*
@@ -307,7 +304,7 @@ again:
if (command == 'R' || command == 'r' || curfile.action != SKIP) {
newvol = nextvol;
wantnext = 1;
- } else {
+ } else {
newvol = 0;
wantnext = 0;
}
@@ -405,7 +402,7 @@ gethdr:
* If coming to this volume at random, skip to the beginning
* of the next record.
*/
- dprintf(stdout, "read %ld recs, tape starts with %ld\n",
+ dprintf(stdout, "read %ld recs, tape starts with %ld\n",
tpblksread, tmpbuf.c_firstrec);
if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
if (!wantnext) {
@@ -484,7 +481,7 @@ setdumpnum()
#ifdef RRESTORE
if (host)
rmtioctl(MTFSF, dumpnum - 1);
- else
+ else
#endif
if (ioctl(mt, (int)MTIOCTOP, (char *)&tcom) < 0)
fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
@@ -507,19 +504,17 @@ int
extractfile(name)
char *name;
{
- int flags;
- mode_t mode;
+ int mode;
struct timeval timep[2];
struct entry *ep;
curfile.name = name;
curfile.action = USING;
- timep[0].tv_sec = curfile.dip->di_atime;
- timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
- timep[1].tv_sec = curfile.dip->di_mtime;
- timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
+ timep[0].tv_sec = curfile.dip->di_atime.tv_sec;
+ timep[0].tv_usec = curfile.dip->di_atime.tv_nsec / 1000;
+ timep[1].tv_sec = curfile.dip->di_mtime.tv_sec;
+ timep[1].tv_usec = curfile.dip->di_mtime.tv_nsec / 1000;
mode = curfile.dip->di_mode;
- flags = curfile.dip->di_flags;
switch (mode & IFMT) {
default:
@@ -554,41 +549,34 @@ extractfile(name)
}
return (linkit(lnkbuf, name, SYMLINK));
- case IFCHR:
- case IFBLK:
- vprintf(stdout, "extract special file %s\n", name);
- if (Nflag) {
- skipfile();
- return (GOOD);
- }
- if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
- fprintf(stderr, "%s: cannot create special file: %s\n",
- name, strerror(errno));
+ case IFIFO:
+ if (mkfifo(name, mode) < 0) {
+ fprintf(stderr, "%s: cannot create FIFO: %s\n",
+ name, strerror(errno));
skipfile();
return (FAIL);
}
(void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
(void) chmod(name, mode);
- (void) chflags(name, flags);
skipfile();
utimes(name, timep);
return (GOOD);
- case IFIFO:
- vprintf(stdout, "extract fifo %s\n", name);
+ case IFCHR:
+ case IFBLK:
+ vprintf(stdout, "extract special file %s\n", name);
if (Nflag) {
skipfile();
return (GOOD);
}
- if (mkfifo(name, mode) < 0) {
- fprintf(stderr, "%s: cannot create fifo: %s\n",
+ if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
+ fprintf(stderr, "%s: cannot create special file: %s\n",
name, strerror(errno));
skipfile();
return (FAIL);
}
(void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
(void) chmod(name, mode);
- (void) chflags(name, flags);
skipfile();
utimes(name, timep);
return (GOOD);
@@ -608,7 +596,6 @@ extractfile(name)
}
(void) fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid);
(void) fchmod(ofile, mode);
- (void) fchflags(ofile, flags);
getfile(xtrfile, xtrskip);
(void) close(ofile);
utimes(name, timep);
@@ -652,7 +639,7 @@ getfile(fill, skip)
{
register int i;
int curblk = 0;
- quad_t size = spcl.c_dinode.di_size;
+ long size = spcl.c_dinode.di_size;
static char clearedbuf[MAXBSIZE];
char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
char junk[TP_BSIZE];
@@ -669,19 +656,20 @@ loop:
if (spcl.c_addr[i]) {
readtape(&buf[curblk++][0]);
if (curblk == fssize / TP_BSIZE) {
- (*fill)((char *)buf, (long)(size > TP_BSIZE ?
- fssize : (curblk - 1) * TP_BSIZE + size));
+ (*fill)((char *)buf, size > TP_BSIZE ?
+ (long) (fssize) :
+ (curblk - 1) * TP_BSIZE + size);
curblk = 0;
}
} else {
if (curblk > 0) {
- (*fill)((char *)buf, (long)(size > TP_BSIZE ?
- curblk * TP_BSIZE :
- (curblk - 1) * TP_BSIZE + size));
+ (*fill)((char *)buf, size > TP_BSIZE ?
+ (long) (curblk * TP_BSIZE) :
+ (curblk - 1) * TP_BSIZE + size);
curblk = 0;
}
- (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
- TP_BSIZE : size));
+ (*skip)(clearedbuf, size > TP_BSIZE ?
+ (long) TP_BSIZE : size);
}
if ((size -= TP_BSIZE) <= 0) {
for (i++; i < spcl.c_count; i++)
@@ -698,7 +686,7 @@ loop:
curfile.name, blksread);
}
if (curblk > 0)
- (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
+ (*fill)((char *)buf, (curblk * TP_BSIZE) + size);
findinode(&spcl);
gettingfile = 0;
}
@@ -782,7 +770,7 @@ xtrmap(buf, size)
long size;
{
- memmove(map, buf, size);
+ bcopy(buf, map, size);
map += size;
}
@@ -825,7 +813,7 @@ readtape(buf)
int cnt, seek_failed;
if (blkcnt < numtrec) {
- memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
+ bcopy(&tapebuf[(blkcnt++ * TP_BSIZE)], buf, (long)TP_BSIZE);
blksread++;
tpblksread++;
return;
@@ -897,7 +885,7 @@ getmore:
if (!yflag && !reply("continue"))
done(1);
i = ntrec * TP_BSIZE;
- memset(tapebuf, 0, i);
+ bzero(tapebuf, i);
#ifdef RRESTORE
if (host)
seek_failed = (rmtseek(i, 1) < 0);
@@ -928,10 +916,10 @@ getmore:
panic("partial block read: %d should be %d\n",
rd, ntrec * TP_BSIZE);
terminateinput();
- memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
+ bcopy((char *)&endoftapemark, &tapebuf[rd], (long)TP_BSIZE);
}
blkcnt = 0;
- memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
+ bcopy(&tapebuf[(blkcnt++ * TP_BSIZE)], buf, (long)TP_BSIZE);
blksread++;
tpblksread++;
}
@@ -1034,12 +1022,15 @@ gethead(buf)
}
if (checksum((int *)buf) == FAIL)
return (FAIL);
- if (Bcvt)
+ if (Bcvt) {
swabst((u_char *)"8l4s31l", (u_char *)buf);
+ swabst((u_char *)"l",(u_char *) &buf->c_level);
+ swabst((u_char *)"2l",(u_char *) &buf->c_flags);
+ }
goto good;
}
readtape((char *)(&u_ospcl.s_ospcl));
- memset(buf, 0, (long)TP_BSIZE);
+ bzero((char *)buf, (long)TP_BSIZE);
buf->c_type = u_ospcl.s_ospcl.c_type;
buf->c_date = u_ospcl.s_ospcl.c_date;
buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
@@ -1054,11 +1045,11 @@ gethead(buf)
buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
- buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
- buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
- buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
+ buf->c_dinode.di_atime.tv_sec = u_ospcl.s_ospcl.c_dinode.odi_atime;
+ buf->c_dinode.di_mtime.tv_sec = u_ospcl.s_ospcl.c_dinode.odi_mtime;
+ buf->c_dinode.di_ctime.tv_sec = u_ospcl.s_ospcl.c_dinode.odi_ctime;
buf->c_count = u_ospcl.s_ospcl.c_count;
- memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
+ bcopy(u_ospcl.s_ospcl.c_addr, buf->c_addr, (long)256);
if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
return(FAIL);
@@ -1111,7 +1102,7 @@ good:
break;
}
/*
- * If we are restoring a filesystem with old format inodes,
+ * If we are restoring a filesystem with old format inodes,
* copy the uid/gid to the new location.
*/
if (oldinofmt) {
@@ -1149,10 +1140,10 @@ accthdr(header)
goto newcalc;
switch (prevtype) {
case TS_BITS:
- fprintf(stderr, "Dumped inodes map header");
+ fprintf(stderr, "Dump mask header");
break;
case TS_CLRI:
- fprintf(stderr, "Used inodes map header");
+ fprintf(stderr, "Remove mask header");
break;
case TS_INODE:
fprintf(stderr, "File header, ino %d", previno);
@@ -1264,11 +1255,11 @@ checksum(buf)
} else {
/* What happens if we want to read restore tapes
for a 16bit int machine??? */
- do
+ do
i += swabl(*buf++);
while (--j);
}
-
+
if (i != CHECKSUM) {
fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
curfile.ino, curfile.name);
@@ -1345,7 +1336,7 @@ swabst(cp, sp)
case '5': case '6': case '7': case '8': case '9':
n = (n * 10) + (*cp++ - '0');
continue;
-
+
case 's': case 'w': case 'h':
if (n == 0)
n = 1;
diff --git a/sbin/restore/utilities.c b/sbin/restore/utilities.c
index 29ac8bd..b2e442e 100644
--- a/sbin/restore/utilities.c
+++ b/sbin/restore/utilities.c
@@ -32,7 +32,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)utilities.c 8.5 (Berkeley) 4/28/95";
+static char sccsid[] = "@(#)utilities.c 8.2 (Berkeley) 3/25/94";
#endif /* not lint */
#include <sys/param.h>
@@ -61,7 +61,7 @@ pathcheck(name)
struct entry *ep;
char *start;
- start = strchr(name, '/');
+ start = index(name, '/');
if (start == 0)
return;
for (cp = start; *cp != '\0'; cp++) {
@@ -230,45 +230,6 @@ linkit(existing, new, type)
}
/*
- * Create a whiteout.
- */
-int
-addwhiteout(name)
- char *name;
-{
-
- if (!Nflag && mknod(name, S_IFWHT, 0) < 0) {
- fprintf(stderr, "warning: cannot create whiteout %s: %s\n",
- name, strerror(errno));
- return (FAIL);
- }
- vprintf(stdout, "Create whiteout %s\n", name);
- return (GOOD);
-}
-
-/*
- * Delete a whiteout.
- */
-void
-delwhiteout(ep)
- register struct entry *ep;
-{
- char *name;
-
- if (ep->e_type != LEAF)
- badentry(ep, "delwhiteout: not a leaf");
- ep->e_flags |= REMOVED;
- ep->e_flags &= ~TMPNAME;
- name = myname(ep);
- if (!Nflag && undelete(name) < 0) {
- fprintf(stderr, "warning: cannot delete whiteout %s: %s\n",
- name, strerror(errno));
- return;
- }
- vprintf(stdout, "Delete whiteout %s\n", name);
-}
-
-/*
* find lowest number file (above "start") that needs to be extracted
*/
ino_t
@@ -368,7 +329,7 @@ dirlookup(name)
{
struct direct *dp;
ino_t ino;
-
+
ino = ((dp = pathsearch(name)) == NULL) ? 0 : dp->d_ino;
if (ino == 0 || TSTINO(ino, dumpmap) == 0)
OpenPOWER on IntegriCloud