BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / restore / interactive.c
index 8b10e2a..76aa74f 100644 (file)
@@ -1,21 +1,47 @@
 /*
 /*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1985, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)interactive.c      5.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)interactive.c      8.5 (Berkeley) 5/1/95";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 
 #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/ufs/dinode.h>
 #include <ufs/ufs/dir.h>
+#include <ufs/ffs/fs.h>
 #include <protocols/dumprestore.h>
 
 #include <setjmp.h>
 #include <protocols/dumprestore.h>
 
 #include <setjmp.h>
@@ -55,12 +81,11 @@ struct arglist {
 
 static char    *copynext __P((char *, char *));
 static int      fcmp __P((const void *, const void *));
 
 static char    *copynext __P((char *, char *));
 static int      fcmp __P((const void *, const void *));
-static char    *fmtentry __P((struct afile *));
 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     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 *));
 
 /*
 static void     printlist __P((char *, char *));
 
 /*
@@ -81,7 +106,7 @@ runcmdshell()
        arglist.glob.gl_flags = GLOB_ALTDIRFUNC;
        arglist.glob.gl_opendir = (void *)rst_opendir;
        arglist.glob.gl_readdir = (void *)glob_readdir;
        arglist.glob.gl_flags = GLOB_ALTDIRFUNC;
        arglist.glob.gl_opendir = (void *)rst_opendir;
        arglist.glob.gl_readdir = (void *)glob_readdir;
-       arglist.glob.gl_closedir = rst_closedir;
+       arglist.glob.gl_closedir = (void *)rst_closedir;
        arglist.glob.gl_lstat = glob_stat;
        arglist.glob.gl_stat = glob_stat;
        canon("/", curdir);
        arglist.glob.gl_lstat = glob_stat;
        arglist.glob.gl_stat = glob_stat;
        canon("/", curdir);
@@ -471,15 +496,17 @@ printlist(name, basename)
        register struct direct *dp;
        struct afile single;
        RST_DIR *dirp;
        register struct direct *dp;
        struct afile single;
        RST_DIR *dirp;
-       int entries, len;
+       int entries, len, namelen;
+       char locname[MAXPATHLEN + 1];
 
        dp = pathsearch(name);
 
        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;
                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);
                len = strlen(basename) + 1;
                if (strlen(name) - len > single.len) {
                        freename(single.fname);
@@ -501,17 +528,28 @@ printlist(name, basename)
                fprintf(stderr, "%s:\n", name);
                entries = 0;
                listp = list;
                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)) {
                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;
                                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;
                             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) {
                }
                rst_closedir(dirp);
                if (entries == 0) {
@@ -534,7 +572,8 @@ printlist(name, basename)
  * Read the contents of a directory.
  */
 static void
  * Read the contents of a directory.
  */
 static void
-mkentry(dp, fp)
+mkentry(name, dp, fp)
+       char *name;
        struct direct *dp;
        register struct afile *fp;
 {
        struct direct *dp;
        register struct afile *fp;
 {
@@ -549,7 +588,7 @@ mkentry(dp, fp)
        fp->len = cp - fp->fname;
        if (dflag && TSTINO(fp->fnum, dumpmap) == 0)
                fp->prefix = '^';
        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 = ' ';
                fp->prefix = '*';
        else
                fp->prefix = ' ';
@@ -577,6 +616,10 @@ mkentry(dp, fp)
                fp->postfix = '#';
                break;
 
                fp->postfix = '#';
                break;
 
+       case DT_WHT:
+               fp->postfix = '%';
+               break;
+
        case DT_UNKNOWN:
        case DT_DIR:
                if (inodetype(dp->d_ino) == NODE)
        case DT_UNKNOWN:
        case DT_DIR:
                if (inodetype(dp->d_ino) == NODE)
@@ -672,7 +715,7 @@ glob_readdir(dirp)
        static struct dirent adirent;
 
        while ((dp = rst_readdir(dirp)) != NULL) {
        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;
                        continue;
                if (dflag || TSTINO(dp->d_ino, dumpmap))
                        break;
@@ -681,7 +724,7 @@ glob_readdir(dirp)
                return (NULL);
        adirent.d_fileno = dp->d_ino;
        adirent.d_namlen = dp->d_namlen;
                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);
 }
 
        return (&adirent);
 }
 
@@ -696,7 +739,8 @@ glob_stat(name, stp)
        register struct direct *dp;
 
        dp = pathsearch(name);
        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;
                return (-1);
        if (inodetype(dp->d_ino) == NODE)
                stp->st_mode = IFDIR;