get input from a pipe to work
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 28 Feb 1983 08:31:16 +0000 (00:31 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 28 Feb 1983 08:31:16 +0000 (00:31 -0800)
SCCS-vsn: sbin/restore/restore.c 3.3
SCCS-vsn: sbin/restore/tape.c 3.4
SCCS-vsn: sbin/restore/utilities.c 3.3

usr/src/sbin/restore/restore.c
usr/src/sbin/restore/tape.c
usr/src/sbin/restore/utilities.c

index d93b397..e561443 100644 (file)
@@ -1,7 +1,7 @@
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
-static char sccsid[] = "@(#)restore.c  3.2     (Berkeley)      83/02/27";
+static char sccsid[] = "@(#)restore.c  3.3     (Berkeley)      83/02/27";
 #endif
 
 #include "restore.h"
 #endif
 
 #include "restore.h"
@@ -438,7 +438,7 @@ createfiles()
 
        vprintf(stdout, "Extract requested files\n");
        curfile.action = SKIP;
 
        vprintf(stdout, "Extract requested files\n");
        curfile.action = SKIP;
-       getvol((long)0);
+       getvol((long)1);
        first = lowerbnd(ROOTINO);
        last = upperbnd(maxino - 1);
        for (;;) {
        first = lowerbnd(ROOTINO);
        last = upperbnd(maxino - 1);
        for (;;) {
@@ -466,7 +466,7 @@ createfiles()
                        ep->e_flags &= ~NEW;
                        next = lowerbnd(next + 1);
                }
                        ep->e_flags &= ~NEW;
                        next = lowerbnd(next + 1);
                }
-               if (next == curfile.ino) {
+               if (next == curfile.ino && next <= last) {
                        ep = lookupino(next);
                        if (ep == NIL)
                                panic("corrupted symbol table\n");
                        ep = lookupino(next);
                        if (ep == NIL)
                                panic("corrupted symbol table\n");
index 50f0360..a8fc7fe 100644 (file)
@@ -1,7 +1,7 @@
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
-static char sccsid[] = "@(#)tape.c     3.3     (Berkeley)      83/02/27";
+static char sccsid[] = "@(#)tape.c     3.4     (Berkeley)      83/02/27";
 #endif
 
 #include "restore.h"
 #endif
 
 #include "restore.h"
@@ -184,7 +184,7 @@ getvol(nextvol)
                dumpnum = 1;
        }
        if (pipein) {
                dumpnum = 1;
        }
        if (pipein) {
-               if (volno != 1 || newvol != 1)
+               if (volno != 1 || nextvol != 1)
                        panic("Changing volumes on pipe input?\n");
                return;
        }
                        panic("Changing volumes on pipe input?\n");
                return;
        }
@@ -481,20 +481,36 @@ readtape(b)
        char *b;
 {
        register long i;
        char *b;
 {
        register long i;
-       long newvol;
+       long rd, cnt, newvol;
 
        if (bct >= NTREC) {
                for (i = 0; i < NTREC; i++)
                        ((struct s_spcl *)&tbf[i*TP_BSIZE])->c_magic = 0;
                bct = 0;
 
        if (bct >= NTREC) {
                for (i = 0; i < NTREC; i++)
                        ((struct s_spcl *)&tbf[i*TP_BSIZE])->c_magic = 0;
                bct = 0;
+               cnt = NTREC*TP_BSIZE;
+               rd = 0;
+       getmore:
 #ifdef RRESTOR
 #ifdef RRESTOR
-               if ((i = rmtread(tbf, NTREC*TP_BSIZE)) < 0)
+               i = rmtread(&tbf[rd], cnt);
 #else
 #else
-               if ((i = read(mt, tbf, NTREC*TP_BSIZE)) < 0)
+               i = read(mt, &tbf[rd], cnt);
 #endif
 #endif
-                       {
+               if (i > 0 && i != NTREC*TP_BSIZE) {
+                       if (!pipein)
+                               panic("partial block read: %d should be %d\n",
+                                       i, NTREC*TP_BSIZE);
+                       rd += i;
+                       cnt -= i;
+                       if (cnt > 0)
+                               goto getmore;
+                       i = rd;
+               }
+               if (i < 0) {
                        fprintf(stderr, "Tape read error while ");
                        switch (curfile.action) {
                        fprintf(stderr, "Tape read error while ");
                        switch (curfile.action) {
+                       default:
+                               fprintf(stderr, "trying to set up tape\n");
+                               break;
                        case UNKNOWN:
                                fprintf(stderr, "trying to resyncronize\n");
                                break;
                        case UNKNOWN:
                                fprintf(stderr, "trying to resyncronize\n");
                                break;
@@ -798,7 +814,35 @@ checksum(b)
        return(GOOD);
 }
 
        return(GOOD);
 }
 
+/*
+ * respond to interrupts
+ */
+onintr()
+{
+       if (pipein || reply("restore interrupted, continue") == FAIL)
+               done(1);
+       if (signal(SIGINT, onintr) == SIG_IGN)
+               signal(SIGINT, SIG_IGN);
+       if (signal(SIGTERM, onintr) == SIG_IGN)
+               signal(SIGTERM, SIG_IGN);
+}
+
+/*
+ * handle unexpected inconsistencies
+ */
+/* VARARGS1 */
+panic(msg, d1, d2)
+       char *msg;
+       long d1, d2;
+{
+
+       fprintf(stderr, msg, d1, d2);
+       if (pipein || reply("abort") == GOOD)
+               abort();
+}
+
 #ifdef RRESTOR
 #ifdef RRESTOR
+/* VARARGS1 */
 msg(cp, a1, a2, a3)
        char *cp;
 {
 msg(cp, a1, a2, a3)
        char *cp;
 {
index 2f95e81..03f7e97 100644 (file)
@@ -1,7 +1,7 @@
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
-static char sccsid[] = "@(#)utilities.c        3.2     (Berkeley)      83/02/27";
+static char sccsid[] = "@(#)utilities.c        3.3     (Berkeley)      83/02/27";
 #endif
 
 #include "restore.h"
 #endif
 
 #include "restore.h"
@@ -106,6 +106,10 @@ newnode(np)
                badentry(np, "newnode: not a node");
        cp = myname(np);
        if (mkdir(cp, 0777) < 0) {
                badentry(np, "newnode: not a node");
        cp = myname(np);
        if (mkdir(cp, 0777) < 0) {
+               if (command == 'x') {
+                       perror(cp);
+                       return;
+               }
                perror("newnode");
                panic("Cannot make node %s\n", cp);
        }
                perror("newnode");
                panic("Cannot make node %s\n", cp);
        }
@@ -267,30 +271,6 @@ badentry(ep, msg)
        panic("flags: %s\n", &flagbuf[1]);
 }
 
        panic("flags: %s\n", &flagbuf[1]);
 }
 
-/*
- * respond to interrupts
- */
-onintr()
-{
-       if (reply("restore interrupted, continue"))
-               return;
-       done(1);
-}
-
-/*
- * handle unexpected inconsistencies
- */
-/* VARARGS1 */
-panic(msg, d1, d2)
-       char *msg;
-       long d1, d2;
-{
-
-       fprintf(stderr, msg, d1, d2);
-       if (reply("abort"))
-               abort();
-}
-
 /*
  * elicit a reply
  */
 /*
  * elicit a reply
  */