BSD 4_3_Reno release
[unix-history] / usr / src / sbin / restore / tape.c
index 988c444..19c8d76 100644 (file)
@@ -1,12 +1,25 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tape.c     5.12 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)tape.c     5.19 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 #include "restore.h"
 #include <protocols/dumprestore.h>
 
 #include "restore.h"
 #include <protocols/dumprestore.h>
@@ -15,6 +28,7 @@ static char sccsid[] = "@(#)tape.c    5.12 (Berkeley) %G%";
 #include <sys/file.h>
 #include <setjmp.h>
 #include <sys/stat.h>
 #include <sys/file.h>
 #include <setjmp.h>
 #include <sys/stat.h>
+#include "pathnames.h"
 
 static long    fssize = MAXBSIZE;
 static int     mt = -1;
 
 static long    fssize = MAXBSIZE;
 static int     mt = -1;
@@ -41,9 +55,11 @@ static int   Qcvt;           /* Swap quads (for sun) */
 setinput(source)
        char *source;
 {
 setinput(source)
        char *source;
 {
+       extern int errno;
 #ifdef RRESTORE
        char *host, *tape;
 #endif RRESTORE
 #ifdef RRESTORE
        char *host, *tape;
 #endif RRESTORE
+       char *strerror();
 
        flsht();
        if (bflag)
 
        flsht();
        if (bflag)
@@ -70,12 +86,14 @@ nohost:
                 * Since input is coming from a pipe we must establish
                 * our own connection to the terminal.
                 */
                 * Since input is coming from a pipe we must establish
                 * our own connection to the terminal.
                 */
-               terminal = fopen("/dev/tty", "r");
+               terminal = fopen(_PATH_TTY, "r");
                if (terminal == NULL) {
                if (terminal == NULL) {
-                       perror("Cannot open(\"/dev/tty\")");
-                       terminal = fopen("/dev/null", "r");
+                       (void)fprintf(stderr, "Cannot open %s: %s\n",
+                           _PATH_TTY, strerror(errno));
+                       terminal = fopen(_PATH_DEVNULL, "r");
                        if (terminal == NULL) {
                        if (terminal == NULL) {
-                               perror("Cannot open(\"/dev/null\")");
+                           (void)fprintf(stderr, "Cannot open %s: %s\n",
+                               _PATH_DEVNULL, strerror(errno));
                                done(1);
                        }
                }
                                done(1);
                        }
                }
@@ -268,11 +286,22 @@ again:
        }
        closemt();
        fprintf(stderr, "Mount tape volume %d\n", newvol);
        }
        closemt();
        fprintf(stderr, "Mount tape volume %d\n", newvol);
-       fprintf(stderr, "then enter tape name (default: %s) ", magtape);
+       fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
+       fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
        (void) fflush(stderr);
        (void) fgets(tbf, BUFSIZ, terminal);
        if (feof(terminal))
                done(1);
        (void) fflush(stderr);
        (void) fgets(tbf, BUFSIZ, terminal);
        if (feof(terminal))
                done(1);
+       if (!strcmp(tbf, "none\n")) {
+               curfile.name = "<name unknown>";
+               curfile.action = UNKNOWN;
+               curfile.dip = (struct dinode *)NIL;
+               curfile.ino = maxino;
+               if (gettingfile) {
+                       gettingfile = 0;
+                       longjmp(restart, 1);
+               }
+       }
        if (tbf[0] != '\n') {
                (void) strcpy(magtape, tbf);
                magtape[strlen(magtape) - 1] = '\0';
        if (tbf[0] != '\n') {
                (void) strcpy(magtape, tbf);
                magtape[strlen(magtape) - 1] = '\0';
@@ -371,15 +400,17 @@ extractfile(name)
        char *name;
 {
        int mode;
        char *name;
 {
        int mode;
-       time_t timep[2];
+       struct timeval timep[2];
        struct entry *ep;
        extern int xtrlnkfile(), xtrlnkskip();
        extern int xtrfile(), xtrskip();
 
        curfile.name = name;
        curfile.action = USING;
        struct entry *ep;
        extern int xtrlnkfile(), xtrlnkskip();
        extern int xtrfile(), xtrskip();
 
        curfile.name = name;
        curfile.action = USING;
-       timep[0] = curfile.dip->di_atime;
-       timep[1] = curfile.dip->di_mtime;
+       timep[0].tv_sec = curfile.dip->di_atime;
+       timep[0].tv_usec = 0;
+       timep[1].tv_sec = curfile.dip->di_mtime;
+       timep[1].tv_usec = 0;
        mode = curfile.dip->di_mode;
        switch (mode & IFMT) {
 
        mode = curfile.dip->di_mode;
        switch (mode & IFMT) {
 
@@ -418,6 +449,10 @@ extractfile(name)
        case IFCHR:
        case IFBLK:
                vprintf(stdout, "extract special file %s\n", name);
        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: ", name);
                        (void) fflush(stderr);
                if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
                        fprintf(stderr, "%s: ", name);
                        (void) fflush(stderr);
@@ -428,11 +463,15 @@ extractfile(name)
                (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
                (void) chmod(name, mode);
                skipfile();
                (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
                (void) chmod(name, mode);
                skipfile();
-               utime(name, timep);
+               utimes(name, timep);
                return (GOOD);
 
        case IFREG:
                vprintf(stdout, "extract file %s\n", name);
                return (GOOD);
 
        case IFREG:
                vprintf(stdout, "extract file %s\n", name);
+               if (Nflag) {
+                       skipfile();
+                       return (GOOD);
+               }
                if ((ofile = creat(name, 0666)) < 0) {
                        fprintf(stderr, "%s: ", name);
                        (void) fflush(stderr);
                if ((ofile = creat(name, 0666)) < 0) {
                        fprintf(stderr, "%s: ", name);
                        (void) fflush(stderr);
@@ -444,7 +483,7 @@ extractfile(name)
                (void) fchmod(ofile, mode);
                getfile(xtrfile, xtrskip);
                (void) close(ofile);
                (void) fchmod(ofile, mode);
                getfile(xtrfile, xtrskip);
                (void) close(ofile);
-               utime(name, timep);
+               utimes(name, timep);
                return (GOOD);
        }
        /* NOTREACHED */
                return (GOOD);
        }
        /* NOTREACHED */
@@ -541,6 +580,8 @@ xtrfile(buf, size)
        long    size;
 {
 
        long    size;
 {
 
+       if (Nflag)
+               return;
        if (write(ofile, buf, (int) size) == -1) {
                fprintf(stderr, "write error extracting inode %d, name %s\n",
                        curfile.ino, curfile.name);
        if (write(ofile, buf, (int) size) == -1) {
                fprintf(stderr, "write error extracting inode %d, name %s\n",
                        curfile.ino, curfile.name);
@@ -664,7 +705,7 @@ getmore:
                        fprintf(stderr, "trying to set up tape\n");
                        break;
                case UNKNOWN:
                        fprintf(stderr, "trying to set up tape\n");
                        break;
                case UNKNOWN:
-                       fprintf(stderr, "trying to resyncronize\n");
+                       fprintf(stderr, "trying to resynchronize\n");
                        break;
                case USING:
                        fprintf(stderr, "restoring %s\n", curfile.name);
                        break;
                case USING:
                        fprintf(stderr, "restoring %s\n", curfile.name);
@@ -775,7 +816,8 @@ readhdr(b)
 gethead(buf)
        struct s_spcl *buf;
 {
 gethead(buf)
        struct s_spcl *buf;
 {
-       long i, *j;
+       long i;
+       u_long *j;
        union u_ospcl {
                char dummy[TP_BSIZE];
                struct  s_ospcl {
        union u_ospcl {
                char dummy[TP_BSIZE];
                struct  s_ospcl {
@@ -847,7 +889,7 @@ gethead(buf)
        buf->c_magic = NFS_MAGIC;
 
 good:
        buf->c_magic = NFS_MAGIC;
 
 good:
-       j = buf->c_dinode.di_ic.ic_size.val;
+       j = buf->c_dinode.di_qsize.val;
        i = j[1];
        if (buf->c_dinode.di_size == 0 &&
            (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt==0) {
        i = j[1];
        if (buf->c_dinode.di_size == 0 &&
            (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt==0) {