From 5e2372f7211e467141b4939f21d1f81da257c059 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Mar 1997 11:59:39 +0000 Subject: Import some CSRG 4.4BSD-Lite2 components for sbin onto vendor branch. (note that some of these have already been imported, this is a no-op) --- sbin/restore/dirs.c | 58 ++++---- sbin/restore/interactive.c | 51 ++++--- sbin/restore/main.c | 31 ++-- sbin/restore/restore.8 | 343 ++++++++++++++++++++++++--------------------- sbin/restore/restore.c | 46 +++++- sbin/restore/restore.h | 6 +- sbin/restore/symtab.c | 25 ++-- sbin/restore/tape.c | 96 ++++++++----- sbin/restore/utilities.c | 43 +++++- 9 files changed, 427 insertions(+), 272 deletions(-) (limited to 'sbin/restore') diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index 5a2651c..d6c12d3 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -37,7 +37,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)dirs.c 8.2 (Berkeley) 1/21/94"; +static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95"; #endif /* not lint */ #include @@ -45,9 +45,9 @@ static char sccsid[] = "@(#)dirs.c 8.2 (Berkeley) 1/21/94"; #include #include -#include #include #include +#include #include #include @@ -56,6 +56,8 @@ static char sccsid[] = "@(#)dirs.c 8.2 (Berkeley) 1/21/94"; #include #include +#include + #include "pathnames.h" #include "restore.h" #include "extern.h" @@ -79,9 +81,10 @@ static struct inotab *inotab[HASHSIZE]; struct modeinfo { ino_t ino; struct timeval timep[2]; - short mode; - short uid; - short gid; + mode_t mode; + uid_t uid; + gid_t gid; + int flags; }; /* @@ -256,7 +259,7 @@ treescan(pname, ino, todo) /* * a zero inode signals end of directory */ - while (dp != NULL && dp->d_ino != 0) { + while (dp != NULL) { locname[namelen] = '\0'; if (namelen + dp->d_namlen >= MAXPATHLEN) { fprintf(stderr, "%s%s: name exceeds %d char\n", @@ -269,8 +272,6 @@ treescan(pname, ino, todo) dp = rst_readdir(dirp); bpt = rst_telldir(dirp); } - if (dp == NULL) - fprintf(stderr, "corrupted directory: %s.\n", locname); } /* @@ -318,7 +319,7 @@ searchdir(inum, name) len = strlen(name); do { dp = rst_readdir(dirp); - if (dp == NULL || dp->d_ino == 0) + if (dp == NULL) return (NULL); } while (dp->d_namlen != len || strncmp(dp->d_name, name, len) != 0); return (dp); @@ -348,14 +349,17 @@ putdir(buf, size) } else { for (loc = 0; loc < size; ) { dp = (struct direct *)(buf + loc); - if (oldinofmt) { - if (Bcvt) { - swabst((u_char *)"l2s", (u_char *) dp); - } - } else { - if (Bcvt) { - swabst((u_char *)"ls", (u_char *) dp); - } + 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 + dp->d_type = DT_UNKNOWN; } i = DIRBLKSIZ - (loc & (DIRBLKSIZ - 1)); if ((dp->d_reclen & 0x3) != 0 || @@ -407,7 +411,7 @@ putent(dp) (void) fwrite(dirbuf, 1, DIRBLKSIZ, df); dirloc = 0; } - bcopy((char *)dp, dirbuf + dirloc, (long)dp->d_reclen); + memmove(dirbuf + dirloc, dp, (long)dp->d_reclen); prev = dirloc; dirloc += dp->d_reclen; } @@ -430,7 +434,7 @@ dcvt(odp, ndp) register struct direct *ndp; { - bzero((char *)ndp, (long)(sizeof *ndp)); + memset(ndp, 0, (long)(sizeof *ndp)); ndp->d_ino = odp->d_ino; ndp->d_type = DT_UNKNOWN; (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ); @@ -492,8 +496,8 @@ rst_readdir(dirp) return (NULL); } dirp->dd_loc += dp->d_reclen; - if (dp->d_ino == 0 && strcmp(dp->d_name, "/") != 0) - continue; + if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0) + return (NULL); if (dp->d_ino >= maxino) { dprintf(stderr, "corrupted directory: bad inum %d\n", dp->d_ino); @@ -612,6 +616,7 @@ 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; } @@ -636,7 +641,7 @@ genliteraldir(name, ino) itp = inotablookup(ino); if (itp == NULL) panic("Cannot find directory inode %d named %s\n", ino, name); - if ((ofile = creat(name, 0666)) < 0) { + if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { fprintf(stderr, "%s: ", name); (void) fflush(stderr); fprintf(stderr, "cannot create file: %s\n", strerror(errno)); @@ -704,11 +709,12 @@ allocinotab(ino, dip, seekpt) if (mf == NULL) return (itp); node.ino = ino; - node.timep[0].tv_sec = dip->di_atime.ts_sec; - node.timep[0].tv_usec = dip->di_atime.ts_nsec / 1000; - node.timep[1].tv_sec = dip->di_mtime.ts_sec; - node.timep[1].tv_usec = dip->di_mtime.ts_nsec / 1000; + 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.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); diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c index 1b9616c..76aa74f 100644 --- a/sbin/restore/interactive.c +++ b/sbin/restore/interactive.c @@ -32,16 +32,16 @@ */ #ifndef lint -static char sccsid[] = "@(#)interactive.c 8.1 (Berkeley) 6/5/93"; +static char sccsid[] = "@(#)interactive.c 8.5 (Berkeley) 5/1/95"; #endif /* not lint */ #include #include #include -#include #include #include +#include #include #include @@ -85,7 +85,7 @@ static void formatf __P((struct afile *, int)); static void getcmd __P((char *, char *, char *, struct arglist *)); struct dirent *glob_readdir __P((RST_DIR *dirp)); static int glob_stat __P((const char *, struct stat *)); -static void mkentry __P((struct direct *, struct afile *)); +static void mkentry __P((char *, struct direct *, struct afile *)); static void printlist __P((char *, char *)); /* @@ -496,15 +496,17 @@ printlist(name, basename) register struct direct *dp; struct afile single; RST_DIR *dirp; - int entries, len; + int entries, len, namelen; + char locname[MAXPATHLEN + 1]; dp = pathsearch(name); - if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)) + if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) || + (!vflag && dp->d_ino == WINO)) return; if ((dirp = rst_opendir(name)) == NULL) { entries = 1; list = &single; - mkentry(dp, list); + mkentry(name, dp, list); len = strlen(basename) + 1; if (strlen(name) - len > single.len) { freename(single.fname); @@ -526,17 +528,28 @@ 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 || dp->d_ino == 0) + if (dp == NULL) break; if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) continue; - if (vflag == 0 && - (strcmp(dp->d_name, ".") == 0 || + if (!vflag && (dp->d_ino == WINO || + strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)) continue; - mkentry(dp, listp++); - entries++; + 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++; + } } rst_closedir(dirp); if (entries == 0) { @@ -559,7 +572,8 @@ printlist(name, basename) * Read the contents of a directory. */ static void -mkentry(dp, fp) +mkentry(name, dp, fp) + char *name; struct direct *dp; register struct afile *fp; { @@ -574,7 +588,7 @@ mkentry(dp, fp) fp->len = cp - fp->fname; if (dflag && TSTINO(fp->fnum, dumpmap) == 0) fp->prefix = '^'; - else if ((np = lookupino(fp->fnum)) != NULL && (np->e_flags & NEW)) + else if ((np = lookupname(name)) != NULL && (np->e_flags & NEW)) fp->prefix = '*'; else fp->prefix = ' '; @@ -602,6 +616,10 @@ mkentry(dp, fp) fp->postfix = '#'; break; + case DT_WHT: + fp->postfix = '%'; + break; + case DT_UNKNOWN: case DT_DIR: if (inodetype(dp->d_ino) == NODE) @@ -697,7 +715,7 @@ glob_readdir(dirp) static struct dirent adirent; while ((dp = rst_readdir(dirp)) != NULL) { - if (dp->d_ino == 0) + if (!vflag && dp->d_ino == WINO) continue; if (dflag || TSTINO(dp->d_ino, dumpmap)) break; @@ -706,7 +724,7 @@ glob_readdir(dirp) return (NULL); adirent.d_fileno = dp->d_ino; adirent.d_namlen = dp->d_namlen; - bcopy(dp->d_name, adirent.d_name, dp->d_namlen + 1); + memmove(adirent.d_name, dp->d_name, dp->d_namlen + 1); return (&adirent); } @@ -721,7 +739,8 @@ glob_stat(name, stp) register struct direct *dp; dp = pathsearch(name); - if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)) + if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) || + (!vflag && dp->d_ino == WINO)) 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 e2d8eeb..57620fe 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.2 (Berkeley) 1/7/94"; +static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95"; #endif /* not lint */ #include #include -#include #include +#include #include #include @@ -54,6 +54,7 @@ static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/7/94"; #include #include #include +#include #include "pathnames.h" #include "restore.h" @@ -66,7 +67,7 @@ long dumpnum = 1; long volno = 0; long ntrec; char *dumpmap; -char *clrimap; +char *usedinomap; ino_t maxino; time_t dumptime; time_t dumpdate; @@ -271,12 +272,12 @@ main(argc, argv) static void usage() { - (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"); + (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 ...]"); done(1); } @@ -311,17 +312,20 @@ obsolete(argcp, argvp) argv += 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 ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL) err(1, NULL); nargv[0][0] = '-'; nargv[0][1] = *ap; (void)strcpy(&nargv[0][2], *argv); - if (*argv != NULL) - ++argv; + ++argv; ++nargv; break; default: @@ -342,4 +346,7 @@ obsolete(argcp, argvp) /* Copy remaining arguments. */ while (*nargv++ = *argv++); + + /* Update argument count. */ + *argcp = nargv - *argvp - 1; } diff --git a/sbin/restore/restore.8 b/sbin/restore/restore.8 index dfe7d68..6ad1b46 100644 --- a/sbin/restore/restore.8 +++ b/sbin/restore/restore.8 @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)restore.8 8.2 (Berkeley) 12/11/93 +.\" @(#)restore.8 8.4 (Berkeley) 5/1/95 .\" -.Dd December 11, 1993 +.Dd May 1, 1995 .Dt RESTORE 8 .Os BSD 4 .Sh NAME @@ -39,8 +39,43 @@ .Nd "restore files or file systems from backups made with dump" .Sh SYNOPSIS .Nm restore -.Ar key -.Op Ar name Ar ... +.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.) .Sh DESCRIPTION The .Nm restore @@ -56,109 +91,17 @@ 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 -.Cm h -key is specified (see below), +.Fl h +flag is specified (see below), the appearance of a directory name refers to the files and (recursively) subdirectories of that directory. .Pp -The function portion of -the key is specified by one of the following letters: +Exactly one of the following flags is required: .Bl -tag -width Ds -.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 +.It Fl i This mode allows interactive restoration of files from a dump. After reading in the directory information from the dump, .Nm restore @@ -174,8 +117,8 @@ files to be extracted. If a directory is specified, then it and all its descendents are added to the extraction list (unless the -.Cm h -key is specified on the command line). +.Fl h +flag is specified on the command line). Files that are on the extraction list are prepended with a ``*'' when they are listed by .Ic ls . @@ -187,8 +130,8 @@ files to be extracted. If a directory is specified, then it and all its descendents are deleted from the extraction list (unless the -.Cm h -key is specified on the command line). +.Fl h +flag 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. @@ -205,7 +148,8 @@ 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 key is set the inode number of each entry is also listed. +If the verbose +flag 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 @@ -218,93 +162,170 @@ 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 -.Cm v -key is toggled. -When set, the verbose key causes the +.Fl v +flag is toggled. +When set, the verbose flag 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 characters may be used in addition to the letter -that selects the function desired. +The following additional options may be specified: .Bl -tag -width Ds -.It Cm b -The next argument to -.Nm restore -is used as the block size of the media (in kilobytes). +.It Fl b Ar blocksize +The number of kilobytes per dump record. If the .Fl b option is not specified, .Nm restore -tries to determine the media block size dynamically. -.It Cm f -The next argument to +tries to determine the block size dynamically. +.It Fl c +Normally, .Nm restore -is used as the name of the archive instead -of -.Pa /dev/rmt? . +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). 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 Cm h -.Nm Restore -extracts the actual directory, +.It Fl h +Extract the actual directory, rather than the files that it references. This prevents hierarchical restoration of complete subtrees from the dump. -.It Cm m -.Nm Restore -will extract by inode numbers rather than by file name. +.It Fl m +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 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 +.It Fl s Ar fileno +Read from the specified +.Ar fileno +on a multi-file tape. +File numbering starts at 1. +.It Fl v Normally .Nm restore does its work silently. The -.Cm v +.Fl v (verbose) -key causes it to type the name of each file it treats +flag causes it to type the name of each file it treats preceded by its file type. -.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. +.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. .El .Sh DIAGNOSTICS -Complaints about bad key characters. -.Pp Complaints if it gets a read error. If -.Cm y +.Fl y has been specified, or the user responds .Ql y , .Nm restore @@ -314,10 +335,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 -.Cm x +.Fl x or -.Cm i -key has been specified, +.Fl i +flag 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 @@ -390,12 +411,12 @@ information passed between incremental restores. .Sh BUGS .Nm Restore can get confused when doing incremental restores from -dump that were made on active file systems. +dumps 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, it has no control over inode allocation; -thus a full restore must be done to get a new set of directories +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. .Sh HISTORY diff --git a/sbin/restore/restore.c b/sbin/restore/restore.c index dea964c..b628997 100644 --- a/sbin/restore/restore.c +++ b/sbin/restore/restore.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)restore.c 8.1 (Berkeley) 6/5/93"; +static char sccsid[] = "@(#)restore.c 8.3 (Berkeley) 9/13/94"; #endif /* not lint */ #include @@ -85,6 +85,8 @@ 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; @@ -124,9 +126,13 @@ deletefile(name, ino, type) if (TSTINO(ino, dumpmap) == 0) return (descend); - ep = lookupino(ino); - if (ep != NULL) + ep = lookupname(name); + if (ep != NULL) { ep->e_flags &= ~NEW; + ep->e_flags |= REMOVED; + if (ep->e_type != NODE) + freeentry(ep); + } return (descend); } @@ -146,21 +152,38 @@ deletefile(name, ino, type) 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; - register ino_t i; + register struct entry *ep, *nextep; + register ino_t i, mydirino; 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, clrimap)) + if (TSTINO(i, usedinomap)) continue; for ( ; ep != NULL; ep = ep->e_links) { dprintf(stdout, "%s: REMOVE\n", myname(ep)); @@ -745,6 +768,15 @@ 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); @@ -776,7 +808,7 @@ checkrestore() register ino_t i; vprintf(stdout, "Check the symbol table.\n"); - for (i = ROOTINO; i < maxino; i++) { + for (i = WINO; 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/restore.h b/sbin/restore/restore.h index 2202ccd..8dbcee8 100644 --- a/sbin/restore/restore.h +++ b/sbin/restore/restore.h @@ -35,7 +35,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)restore.h 8.2 (Berkeley) 1/21/94 + * @(#)restore.h 8.3 (Berkeley) 9/13/94 */ /* @@ -53,7 +53,7 @@ extern int yflag; /* always try to recover from tape errors */ * Global variables */ extern char *dumpmap; /* map of inodes on this dump tape */ -extern char *clrimap; /* map of inodes to be deleted */ +extern char *usedinomap; /* map of inodes that are in use on this fs */ extern ino_t maxino; /* highest numbered inode in this file system */ extern long dumpnum; /* location of the dump on this tape */ extern long volno; /* current volume being read */ @@ -129,6 +129,8 @@ typedef struct rstdirdesc RST_DIR; */ #define TSTINO(ino, map) \ (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY))) +#define SETINO(ino, map) \ + map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY) #define dprintf if (dflag) fprintf #define vprintf if (vflag) fprintf diff --git a/sbin/restore/symtab.c b/sbin/restore/symtab.c index 3895ec0..16b1d84 100644 --- a/sbin/restore/symtab.c +++ b/sbin/restore/symtab.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)symtab.c 8.1 (Berkeley) 6/5/93"; +static char sccsid[] = "@(#)symtab.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ /* @@ -83,7 +83,7 @@ lookupino(inum) { register struct entry *ep; - if (inum < ROOTINO || inum >= maxino) + if (inum < WINO || 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 < ROOTINO || inum >= maxino) + if (inum < WINO || 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 < ROOTINO || inum >= maxino) + if (inum < WINO || inum >= maxino) panic("deleteino: out of range %d\n", inum); prev = &entry[inum % entrytblsize]; for (next = *prev; next != NULL; next = next->e_next) { @@ -174,7 +174,7 @@ lookupparent(name) struct entry *ep; char *tailindex; - tailindex = rindex(name, '/'); + tailindex = strrchr(name, '/'); if (tailindex == NULL) return (NULL); *tailindex = '\0'; @@ -199,7 +199,7 @@ myname(ep) for (cp = &namebuf[MAXPATHLEN - 2]; cp > &namebuf[ep->e_namlen]; ) { cp -= ep->e_namlen; - bcopy(ep->e_name, cp, (long)ep->e_namlen); + memmove(cp, ep->e_name, (long)ep->e_namlen); if (ep == lookupino(ROOTINO)) return (cp); *(--cp) = '/'; @@ -229,7 +229,7 @@ addentry(name, inum, type) if (freelist != NULL) { np = freelist; freelist = np->e_next; - bzero((char *)np, (long)sizeof(struct entry)); + memset(np, 0, (long)sizeof(struct entry)); } else { np = (struct entry *)calloc(1, sizeof(struct entry)); if (np == NULL) @@ -246,7 +246,7 @@ addentry(name, inum, type) addino(ROOTINO, np); return (np); } - np->e_name = savename(rindex(name, '/') + 1); + np->e_name = savename(strrchr(name, '/') + 1); np->e_namlen = strlen(np->e_name); np->e_parent = ep; np->e_sibling = ep->e_entries; @@ -330,7 +330,7 @@ moveentry(ep, newname) ep->e_sibling = np->e_entries; np->e_entries = ep; } - cp = rindex(newname, '/') + 1; + cp = strrchr(newname, '/') + 1; freename(ep->e_name); ep->e_name = savename(cp); ep->e_namlen = strlen(cp); @@ -470,7 +470,7 @@ dumpsymtable(filename, checkpt) * Assign indicies to each entry * Write out the string entries */ - for (i = ROOTINO; i < maxino; i++) { + for (i = WINO; 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,10 +482,9 @@ dumpsymtable(filename, checkpt) */ tep = &temp; stroff = 0; - for (i = ROOTINO; i < maxino; i++) { + for (i = WINO; i <= maxino; i++) { for (ep = lookupino(i); ep != NULL; ep = ep->e_links) { - bcopy((char *)ep, (char *)tep, - (long)sizeof(struct entry)); + memmove(tep, ep, (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 368c59c..a8d833f 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -37,7 +37,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)tape.c 8.3 (Berkeley) 4/1/94"; +static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95"; #endif /* not lint */ #include @@ -119,9 +119,9 @@ setinput(source) terminal = stdin; #ifdef RRESTORE - if (index(source, ':')) { + if (strchr(source, ':')) { host = source; - source = index(host, ':'); + source = strchr(host, ':'); *source++ = '\0'; if (rmthost(host) == 0) done(1); @@ -250,8 +250,8 @@ setup() dprintf(stdout, "maxino = %d\n", maxino); map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY)); if (map == NULL) - panic("no memory for file removal list\n"); - clrimap = map; + panic("no memory for active inode map\n"); + usedinomap = map; curfile.action = USING; getfile(xtrmap, xtrmapskip); if (spcl.c_type != TS_BITS) { @@ -264,6 +264,13 @@ 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); } /* @@ -500,17 +507,19 @@ int extractfile(name) char *name; { - int mode; + int flags; + mode_t mode; struct timeval timep[2]; struct entry *ep; curfile.name = name; curfile.action = USING; - timep[0].tv_sec = curfile.dip->di_atime.ts_sec; - timep[0].tv_usec = curfile.dip->di_atime.ts_nsec / 1000; - timep[1].tv_sec = curfile.dip->di_mtime.ts_sec; - timep[1].tv_usec = curfile.dip->di_mtime.ts_nsec / 1000; + 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; mode = curfile.dip->di_mode; + flags = curfile.dip->di_flags; switch (mode & IFMT) { default: @@ -560,6 +569,26 @@ extractfile(name) } (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); + if (Nflag) { + skipfile(); + return (GOOD); + } + 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); @@ -570,7 +599,8 @@ extractfile(name) skipfile(); return (GOOD); } - if ((ofile = creat(name, 0666)) < 0) { + if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, + 0666)) < 0) { fprintf(stderr, "%s: cannot create file: %s\n", name, strerror(errno)); skipfile(); @@ -578,6 +608,7 @@ 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); @@ -621,7 +652,7 @@ getfile(fill, skip) { register int i; int curblk = 0; - long size = spcl.c_dinode.di_size; + quad_t size = spcl.c_dinode.di_size; static char clearedbuf[MAXBSIZE]; char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE]; char junk[TP_BSIZE]; @@ -638,20 +669,19 @@ loop: if (spcl.c_addr[i]) { readtape(&buf[curblk++][0]); if (curblk == fssize / TP_BSIZE) { - (*fill)((char *)buf, size > TP_BSIZE ? - (long) (fssize) : - (curblk - 1) * TP_BSIZE + size); + (*fill)((char *)buf, (long)(size > TP_BSIZE ? + fssize : (curblk - 1) * TP_BSIZE + size)); curblk = 0; } } else { if (curblk > 0) { - (*fill)((char *)buf, size > TP_BSIZE ? - (long) (curblk * TP_BSIZE) : - (curblk - 1) * TP_BSIZE + size); + (*fill)((char *)buf, (long)(size > TP_BSIZE ? + curblk * TP_BSIZE : + (curblk - 1) * TP_BSIZE + size)); curblk = 0; } - (*skip)(clearedbuf, size > TP_BSIZE ? - (long) TP_BSIZE : size); + (*skip)(clearedbuf, (long)(size > TP_BSIZE ? + TP_BSIZE : size)); } if ((size -= TP_BSIZE) <= 0) { for (i++; i < spcl.c_count; i++) @@ -668,7 +698,7 @@ loop: curfile.name, blksread); } if (curblk > 0) - (*fill)((char *)buf, (curblk * TP_BSIZE) + size); + (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size)); findinode(&spcl); gettingfile = 0; } @@ -752,7 +782,7 @@ xtrmap(buf, size) long size; { - bcopy(buf, map, size); + memmove(map, buf, size); map += size; } @@ -795,7 +825,7 @@ readtape(buf) int cnt, seek_failed; if (blkcnt < numtrec) { - bcopy(&tapebuf[(blkcnt++ * TP_BSIZE)], buf, (long)TP_BSIZE); + memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE); blksread++; tpblksread++; return; @@ -867,7 +897,7 @@ getmore: if (!yflag && !reply("continue")) done(1); i = ntrec * TP_BSIZE; - bzero(tapebuf, i); + memset(tapebuf, 0, i); #ifdef RRESTORE if (host) seek_failed = (rmtseek(i, 1) < 0); @@ -898,10 +928,10 @@ getmore: panic("partial block read: %d should be %d\n", rd, ntrec * TP_BSIZE); terminateinput(); - bcopy((char *)&endoftapemark, &tapebuf[rd], (long)TP_BSIZE); + memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE); } blkcnt = 0; - bcopy(&tapebuf[(blkcnt++ * TP_BSIZE)], buf, (long)TP_BSIZE); + memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE); blksread++; tpblksread++; } @@ -1009,7 +1039,7 @@ gethead(buf) goto good; } readtape((char *)(&u_ospcl.s_ospcl)); - bzero((char *)buf, (long)TP_BSIZE); + memset(buf, 0, (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; @@ -1024,11 +1054,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.ts_sec = u_ospcl.s_ospcl.c_dinode.odi_atime; - buf->c_dinode.di_mtime.ts_sec = u_ospcl.s_ospcl.c_dinode.odi_mtime; - buf->c_dinode.di_ctime.ts_sec = u_ospcl.s_ospcl.c_dinode.odi_ctime; + 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_count = u_ospcl.s_ospcl.c_count; - bcopy(u_ospcl.s_ospcl.c_addr, buf->c_addr, (long)256); + memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256); if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC || checksum((int *)(&u_ospcl.s_ospcl)) == FAIL) return(FAIL); @@ -1119,10 +1149,10 @@ accthdr(header) goto newcalc; switch (prevtype) { case TS_BITS: - fprintf(stderr, "Dump mask header"); + fprintf(stderr, "Dumped inodes map header"); break; case TS_CLRI: - fprintf(stderr, "Remove mask header"); + fprintf(stderr, "Used inodes map header"); break; case TS_INODE: fprintf(stderr, "File header, ino %d", previno); diff --git a/sbin/restore/utilities.c b/sbin/restore/utilities.c index 31fd11c..29ac8bd 100644 --- a/sbin/restore/utilities.c +++ b/sbin/restore/utilities.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)utilities.c 8.2 (Berkeley) 3/25/94"; +static char sccsid[] = "@(#)utilities.c 8.5 (Berkeley) 4/28/95"; #endif /* not lint */ #include @@ -61,7 +61,7 @@ pathcheck(name) struct entry *ep; char *start; - start = index(name, '/'); + start = strchr(name, '/'); if (start == 0) return; for (cp = start; *cp != '\0'; cp++) { @@ -230,6 +230,45 @@ 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 -- cgit v1.1