BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / restore / interactive.c
index 1b9616c..76aa74f 100644 (file)
  */
 
 #ifndef lint
  */
 
 #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 <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>
@@ -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     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 *));
 
 /*
@@ -496,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);
@@ -526,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) {
@@ -559,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;
 {
@@ -574,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 = ' ';
@@ -602,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)
@@ -697,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;
@@ -706,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);
 }
 
@@ -721,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;