manual page distributed with 4.1BSD
[unix-history] / usr / src / sbin / restore / dirs.c
index 3efa458..97db9c8 100644 (file)
@@ -1,13 +1,12 @@
-/* Copyright (c) 1983 Regents of the University of California */
-
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)dirs.c     3.15    (Berkeley)      83/08/11";
+static char sccsid[] = "@(#)dirs.c     3.20    (Berkeley)      85/02/18";
 #endif
 
 #endif
 
+/* Copyright (c) 1983 Regents of the University of California */
+
 #include "restore.h"
 #include <dumprestor.h>
 #include <sys/file.h>
 #include "restore.h"
 #include <dumprestor.h>
 #include <sys/file.h>
-#include <sys/dir.h>
 
 /*
  * Symbol table of directories read from tape.
 
 /*
  * Symbol table of directories read from tape.
@@ -56,18 +55,6 @@ struct odirect {
        char    d_name[ODIRSIZ];
 };
 
        char    d_name[ODIRSIZ];
 };
 
-/*
- * Structure and routines associated with listing directories.
- */
-struct afile {
-       ino_t   fnum;           /* inode number of file */
-       char    *fname;         /* file name */
-       short   fflags;         /* extraction flags, if any */
-       char    ftype;          /* file type, e.g. LEAF or NODE */
-};
-extern int fcmp();
-extern char *fmtentry();
-
 /*
  *     Extract directory contents, building up a directory structure
  *     on disk for extraction by name.
 /*
  *     Extract directory contents, building up a directory structure
  *     on disk for extraction by name.
@@ -88,7 +75,7 @@ extractdirs(genmode)
        df = fopen(dirfile, "w");
        if (df == 0) {
                fprintf(stderr,
        df = fopen(dirfile, "w");
        if (df == 0) {
                fprintf(stderr,
-                   "restor: %s - cannot create directory temporary\n",
+                   "restore: %s - cannot create directory temporary\n",
                    dirfile);
                perror("fopen");
                done(1);
                    dirfile);
                perror("fopen");
                done(1);
@@ -98,7 +85,7 @@ extractdirs(genmode)
                mf = fopen(modefile, "w");
                if (mf == 0) {
                        fprintf(stderr,
                mf = fopen(modefile, "w");
                if (mf == 0) {
                        fprintf(stderr,
-                           "restor: %s - cannot create modefile \n",
+                           "restore: %s - cannot create modefile \n",
                            modefile);
                        perror("fopen");
                        done(1);
                            modefile);
                        perror("fopen");
                        done(1);
@@ -112,8 +99,7 @@ extractdirs(genmode)
                curfile.name = "<directory file - name unknown>";
                curfile.action = USING;
                ip = curfile.dip;
                curfile.name = "<directory file - name unknown>";
                curfile.action = USING;
                ip = curfile.dip;
-               i = ip->di_mode & IFMT;
-               if (i != IFDIR) {
+               if (ip == NULL || (ip->di_mode & IFMT) != IFDIR) {
                        (void) fclose(df);
                        dirp = opendir(dirfile);
                        if (dirp == NULL)
                        (void) fclose(df);
                        dirp = opendir(dirfile);
                        if (dirp == NULL)
@@ -429,6 +415,24 @@ rst_readdir(dirp)
        }
 }
 
        }
 }
 
+/*
+ * Simulate the opening of a directory
+ */
+DIR *
+rst_opendir(name)
+       char *name;
+{
+       struct inotab *itp;
+       ino_t ino;
+
+       if ((ino = dirlookup(name)) > 0 &&
+           (itp = inotablookup(ino)) != NULL) {
+               rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
+               return (dirp);
+       }
+       return (0);
+}
+
 /*
  * Set the mode, owner, and times for all new or changed directories
  */
 /*
  * Set the mode, owner, and times for all new or changed directories
  */
@@ -440,10 +444,13 @@ setdirmodes()
        char *cp;
        
        vprintf(stdout, "Set directory mode, owner, and times.\n");
        char *cp;
        
        vprintf(stdout, "Set directory mode, owner, and times.\n");
+       (void) sprintf(modefile, "/tmp/rstmode%d", dumpdate);
        mf = fopen(modefile, "r");
        if (mf == NULL) {
                perror("fopen");
        mf = fopen(modefile, "r");
        if (mf == NULL) {
                perror("fopen");
-               panic("cannot open mode file %s\n", modefile);
+               fprintf(stderr, "cannot open mode file %s\n", modefile);
+               fprintf(stderr, "directory mode, owner, and times not set\n");
+               return;
        }
        clearerr(mf);
        for (;;) {
        }
        clearerr(mf);
        for (;;) {
@@ -454,6 +461,10 @@ setdirmodes()
                if (command == 'i' || command == 'x') {
                        if (ep == NIL)
                                continue;
                if (command == 'i' || command == 'x') {
                        if (ep == NIL)
                                continue;
+                       if (ep->e_flags & EXISTED) {
+                               ep->e_flags &= ~NEW;
+                               continue;
+                       }
                        if (node.ino == ROOTINO &&
                            reply("set owner/mode for '.'") == FAIL)
                                continue;
                        if (node.ino == ROOTINO &&
                            reply("set owner/mode for '.'") == FAIL)
                                continue;
@@ -515,176 +526,6 @@ genliteraldir(name, ino)
        return (GOOD);
 }
 
        return (GOOD);
 }
 
-/*
- * Do an "ls" style listing of a directory
- */
-printlist(name, ino)
-       char *name;
-       ino_t ino;
-{
-       register struct afile *fp;
-       register struct inotab *itp;
-       struct afile *dfp0, *dfplast;
-       struct afile single;
-
-       itp = inotablookup(ino);
-       if (itp == NULL) {
-               single.fnum = ino;
-               single.fname = savename(rindex(name, '/') + 1);
-               dfp0 = &single;
-               dfplast = dfp0 + 1;
-       } else {
-               rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
-               if (getdir(dirp, &dfp0, &dfplast) == FAIL)
-                       return;
-       }
-       qsort((char *)dfp0, dfplast - dfp0, sizeof (struct afile), fcmp);
-       formatf(dfp0, dfplast);
-       for (fp = dfp0; fp < dfplast; fp++)
-               freename(fp->fname);
-}
-
-/*
- * Read the contents of a directory.
- */
-getdir(dirp, pfp0, pfplast)
-       DIR *dirp;
-       struct afile **pfp0, **pfplast;
-{
-       register struct afile *fp;
-       register struct direct *dp;
-       static struct afile *basefp = NULL;
-       static long nent = 20;
-
-       if (basefp == NULL) {
-               basefp = (struct afile *)calloc((unsigned)nent,
-                       sizeof (struct afile));
-               if (basefp == NULL) {
-                       fprintf(stderr, "ls: out of memory\n");
-                       return (FAIL);
-               }
-       }
-       fp = *pfp0 = basefp;
-       *pfplast = *pfp0 + nent;
-       while (dp = rst_readdir(dirp)) {
-               if (dp == NULL || dp->d_ino == 0)
-                       break;
-               if (!dflag && BIT(dp->d_ino, dumpmap) == 0)
-                       continue;
-               if (vflag == 0 &&
-                   (strcmp(dp->d_name, ".") == 0 ||
-                    strcmp(dp->d_name, "..") == 0))
-                       continue;
-               fp->fnum = dp->d_ino;
-               fp->fname = savename(dp->d_name);
-               fp++;
-               if (fp == *pfplast) {
-                       basefp = (struct afile *)realloc((char *)basefp,
-                           (unsigned)(2 * nent * sizeof (struct afile)));
-                       if (basefp == 0) {
-                               fprintf(stderr, "ls: out of memory\n");
-                               return (FAIL);
-                       }
-                       *pfp0 = basefp;
-                       fp = *pfp0 + nent;
-                       *pfplast = fp + nent;
-                       nent *= 2;
-               }
-       }
-       *pfplast = fp;
-       return (GOOD);
-}
-
-/*
- * Print out a pretty listing of a directory
- */
-formatf(fp0, fplast)
-       struct afile *fp0, *fplast;
-{
-       register struct afile *fp;
-       struct entry *np;
-       int width = 0, w, nentry = fplast - fp0;
-       int i, j, len, columns, lines;
-       char *cp;
-
-       if (fp0 == fplast)
-               return;
-       for (fp = fp0; fp < fplast; fp++) {
-               fp->ftype = inodetype(fp->fnum);
-               np = lookupino(fp->fnum);
-               if (np != NIL)
-                       fp->fflags = np->e_flags;
-               else
-                       fp->fflags = 0;
-               len = strlen(fmtentry(fp));
-               if (len > width)
-                       width = len;
-       }
-       width += 2;
-       columns = 80 / width;
-       if (columns == 0)
-               columns = 1;
-       lines = (nentry + columns - 1) / columns;
-       for (i = 0; i < lines; i++) {
-               for (j = 0; j < columns; j++) {
-                       fp = fp0 + j * lines + i;
-                       cp = fmtentry(fp);
-                       fprintf(stderr, "%s", cp);
-                       if (fp + lines >= fplast) {
-                               fprintf(stderr, "\n");
-                               break;
-                       }
-                       w = strlen(cp);
-                       while (w < width) {
-                               w++;
-                               fprintf(stderr, " ");
-                       }
-               }
-       }
-}
-
-/*
- * Comparison routine for qsort.
- */
-fcmp(f1, f2)
-       register struct afile *f1, *f2;
-{
-
-       return (strcmp(f1->fname, f2->fname));
-}
-
-/*
- * Format a directory entry.
- */
-char *
-fmtentry(fp)
-       register struct afile *fp;
-{
-       static char fmtres[BUFSIZ];
-       register char *cp, *dp;
-
-       if (vflag)
-               (void) sprintf(fmtres, "%5d ", fp->fnum);
-       else
-               fmtres[0] = '\0';
-       dp = &fmtres[strlen(fmtres)];
-       if (dflag && BIT(fp->fnum, dumpmap) == 0)
-               *dp++ = '^';
-       else if ((fp->fflags & NEW) != 0)
-               *dp++ = '*';
-       else
-               *dp++ = ' ';
-       for (cp = fp->fname; *cp; cp++)
-               if (!vflag && (*cp < ' ' || *cp >= 0177))
-                       *dp++ = '?';
-               else
-                       *dp++ = *cp;
-       if (fp->ftype == NODE)
-               *dp++ = '/';
-       *dp++ = 0;
-       return (fmtres);
-}
-
 /*
  * Determine the type of an inode
  */
 /*
  * Determine the type of an inode
  */