]> git.wh0rd.org - dump.git/blobdiff - restore/restore.c
Another set of fixes for file not found at end of tape.
[dump.git] / restore / restore.c
index 773b709783d0c2b76f453b875606c8b8cf5b02bd..618380489adf50aebbf160cc07d0f56ac471549f 100644 (file)
@@ -2,8 +2,8 @@
  *     Ported to Linux's Second Extended File System as part of the
  *     dump and restore backup suit
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
- *      Stelian Pop <pop@cybercable.fr>, 1999 
- *
+ *     Stelian Pop <pop@noos.fr>, 1999-2000
+ *     Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
  */
 
 /*
  */
 
 #ifndef lint
-#if 0
-static char sccsid[] = "@(#)restore.c  8.3 (Berkeley) 9/13/94";
-#endif
 static const char rcsid[] =
-       "$Id: restore.c,v 1.2 1999/10/11 12:53:24 stelian Exp $";
+       "$Id: restore.c,v 1.20 2001/12/24 15:53:41 stelian Exp $";
 #endif /* not lint */
 
+#include <config.h>
 #include <sys/types.h>
 
 #ifdef __linux__
+#include <sys/param.h>
 #include <sys/time.h>
+#include <time.h>
+#ifdef HAVE_EXT2FS_EXT2_FS_H
+#include <ext2fs/ext2_fs.h>
+#else
 #include <linux/ext2_fs.h>
+#endif
 #include <bsdcompat.h>
 #else  /* __linux__ */
 #include <ufs/ufs/dinode.h>
@@ -74,17 +78,26 @@ static char *keyval __P((int));
  * List entries on the tape.
  */
 long
-listfile(name, ino, type)
-       char *name;
-       ino_t ino;
-       int type;
+listfile(char *name, dump_ino_t ino, int type)
 {
        long descend = hflag ? GOOD : FAIL;
+#ifdef USE_QFA
+       long tnum;
+       long tpos;
+#endif
 
        if (TSTINO(ino, dumpmap) == 0)
                return (descend);
-       vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir ");
-       fprintf(stdout, "%10ld\t%s\n", ino, name);
+       Vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir ");
+#ifdef USE_QFA
+       if (tapeposflag) {      /* add QFA positions to output */
+               (void)Inode2Tapepos(ino, &tnum, &tpos, 1);
+               fprintf(stdout, "%10lu\t%ld\t%ld\t%s\n", (unsigned long)ino, 
+                       tnum, tpos, name);
+       }
+       else
+#endif
+               fprintf(stdout, "%10lu\t%s\n", (unsigned long)ino, name);
        return (descend);
 }
 
@@ -93,23 +106,20 @@ listfile(name, ino, type)
  * Request that new entries be extracted.
  */
 long
-addfile(name, ino, type)
-       char *name;
-       ino_t ino;
-       int type;
+addfile(char *name, dump_ino_t ino, int type)
 {
-       register struct entry *ep;
+       register struct entry *ep, *np;
        long descend = hflag ? GOOD : FAIL;
        char buf[100];
 
        if (TSTINO(ino, dumpmap) == 0) {
-               dprintf(stdout, "%s: not on the tape\n", name);
+               Dprintf(stdout, "%s: not on the tape\n", name);
                return (descend);
        }
        if (ino == WINO && command == 'i' && !vflag)
                return (descend);
        if (!mflag) {
-               (void) sprintf(buf, "./%lu", ino);
+               (void) snprintf(buf, sizeof(buf), "./%lu", (unsigned long)ino);
                name = buf;
                if (type == NODE) {
                        (void) genliteraldir(name, ino);
@@ -123,6 +133,11 @@ addfile(name, ino, type)
                        return (descend);
                }
                type |= LINK;
+               for (np = ep->e_links; np; np = np->e_links)
+                       if (strcmp(name, myname(np)) == 0) {
+                               np->e_flags |= NEW;
+                               return (descend);
+                       }
        }
        ep = addentry(name, ino, type);
        if (type == NODE)
@@ -137,10 +152,7 @@ addfile(name, ino, type)
  */
 /* ARGSUSED */
 long
-deletefile(name, ino, type)
-       char *name;
-       ino_t ino;
-       int type;
+deletefile(char *name, dump_ino_t ino, int type)
 {
        long descend = hflag ? GOOD : FAIL;
        struct entry *ep;
@@ -178,14 +190,14 @@ static struct entry *removelist;
  *     Remove directories from the lookup chains.
  */
 void
-removeoldleaves()
+removeoldleaves(void)
 {
        register struct entry *ep, *nextep;
-       register ino_t i, mydirino;
+       register dump_ino_t i, mydirino;
 
-       vprintf(stdout, "Mark entries to be removed.\n");
+       Vprintf(stdout, "Mark entries to be removed.\n");
        if ((ep = lookupino(WINO))) {
-               vprintf(stdout, "Delete whiteouts\n");
+               Vprintf(stdout, "Delete whiteouts\n");
                for ( ; ep != NULL; ep = nextep) {
                        nextep = ep->e_links;
                        mydirino = ep->e_parent->e_ino;
@@ -211,7 +223,7 @@ removeoldleaves()
                if (TSTINO(i, usedinomap))
                        continue;
                for ( ; ep != NULL; ep = ep->e_links) {
-                       dprintf(stdout, "%s: REMOVE\n", myname(ep));
+                       Dprintf(stdout, "%s: REMOVE\n", myname(ep));
                        if (ep->e_type == LEAF) {
                                removeleaf(ep);
                                freeentry(ep);
@@ -235,10 +247,7 @@ removeoldleaves()
  *     Renames are done at the same time.
  */
 long
-nodeupdates(name, ino, type)
-       char *name;
-       ino_t ino;
-       int type;
+nodeupdates(char *name, dump_ino_t ino, int type)
 {
        register struct entry *ep, *np, *ip;
        long descend = GOOD;
@@ -304,7 +313,7 @@ nodeupdates(name, ino, type)
                        removeleaf(np);
                        freeentry(np);
                } else {
-                       dprintf(stdout, "name/inode conflict, mktempname %s\n",
+                       Dprintf(stdout, "name/inode conflict, mktempname %s\n",
                                myname(np));
                        mktempname(np);
                }
@@ -332,7 +341,7 @@ nodeupdates(name, ino, type)
         */
        case INOFND|NAMEFND:
                ip->e_flags |= KEEP;
-               dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+               Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
                        flagvalues(ip));
                break;
 
@@ -368,7 +377,7 @@ nodeupdates(name, ino, type)
                if (type == NODE)
                        newnode(ep);
                ep->e_flags |= NEW|KEEP;
-               dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+               Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
                        flagvalues(ep));
                break;
 
@@ -392,7 +401,7 @@ nodeupdates(name, ino, type)
                        renameit(myname(ip), name);
                        moveentry(ip, name);
                        ip->e_flags |= KEEP;
-                       dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+                       Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
                                flagvalues(ip));
                        break;
                }
@@ -405,7 +414,7 @@ nodeupdates(name, ino, type)
                }
                ep = addentry(name, ino, type|LINK);
                ep->e_flags |= NEW;
-               dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
+               Dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
                        flagvalues(ep));
                break;
 
@@ -422,14 +431,14 @@ nodeupdates(name, ino, type)
                        if (type == NODE)
                                newnode(ep);
                        ep->e_flags |= NEW|KEEP;
-                       dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
+                       Dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
                                flagvalues(ep));
                        break;
                }
                if (type == LEAF && lookuptype != LINK)
                        np->e_flags |= EXTRACT;
                np->e_flags |= KEEP;
-               dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+               Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
                        flagvalues(np));
                break;
 
@@ -453,7 +462,7 @@ nodeupdates(name, ino, type)
                }
                if (ip->e_type == LEAF) {
                        /* changing from leaf to node */
-                       for (ip = lookupino(ino); ip != NULL; ip = ip->e_links) {
+                       for ( ; ip != NULL; ip = ip->e_links) {
                                if (ip->e_type != LEAF)
                                        badentry(ip, "NODE and LEAF links to same inode");
                                removeleaf(ip);
@@ -471,7 +480,7 @@ nodeupdates(name, ino, type)
                        ip = addentry(name, ino, type);
                }
                ip->e_flags |= NEW|KEEP;
-               dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+               Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
                        flagvalues(ip));
                break;
 
@@ -480,7 +489,7 @@ nodeupdates(name, ino, type)
         * Ignore it.
         */
        case NAMEFND:
-               dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
+               Dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
                        name);
                descend = FAIL;
                break;
@@ -492,10 +501,11 @@ nodeupdates(name, ino, type)
         * for it, we discard the name knowing that it will be on the
         * next incremental tape.
         */
-       case NULL:
+       case 0:
                if (compare_ignore_not_found) break;
-               fprintf(stderr, "%s: (inode %ld) not found on tape\n",
-                       name, ino);
+               fprintf(stderr, "%s: (inode %lu) not found on tape\n",
+                       name, (unsigned long)ino);
+               compare_errors = 1;
                break;
 
        /*
@@ -525,8 +535,7 @@ nodeupdates(name, ino, type)
  * Calculate the active flags in a key.
  */
 static char *
-keyval(key)
-       int key;
+keyval(int key)
 {
        static char keybuf[32];
 
@@ -547,19 +556,19 @@ keyval(key)
  * Find unreferenced link names.
  */
 void
-findunreflinks()
+findunreflinks(void)
 {
        register struct entry *ep, *np;
-       register ino_t i;
+       register dump_ino_t i;
 
-       vprintf(stdout, "Find unreferenced names.\n");
+       Vprintf(stdout, "Find unreferenced names.\n");
        for (i = ROOTINO; i < maxino; i++) {
                ep = lookupino(i);
                if (ep == NULL || ep->e_type == LEAF || TSTINO(i, dumpmap) == 0)
                        continue;
                for (np = ep->e_entries; np != NULL; np = np->e_sibling) {
                        if (np->e_flags == 0) {
-                               dprintf(stdout,
+                               Dprintf(stdout,
                                    "%s: remove unreferenced name\n",
                                    myname(np));
                                removeleaf(np);
@@ -575,7 +584,7 @@ findunreflinks()
                        if (np->e_type == LEAF) {
                                if (np->e_flags != 0)
                                        badentry(np, "unreferenced with flags");
-                               dprintf(stdout,
+                               Dprintf(stdout,
                                    "%s: remove unreferenced name\n",
                                    myname(np));
                                removeleaf(np);
@@ -595,12 +604,12 @@ findunreflinks()
  * time O(N).
  */
 void
-removeoldnodes()
+removeoldnodes(void)
 {
        register struct entry *ep, **prev;
        long change;
 
-       vprintf(stdout, "Remove old nodes (directories).\n");
+       Vprintf(stdout, "Remove old nodes (directories).\n");
        do      {
                change = 0;
                prev = &removelist;
@@ -623,11 +632,13 @@ removeoldnodes()
 /* current copy of this file on disk.  If do_compare is 0, then just */
 /* make our caller think we did it--this is used to handle hard links */
 /* to files and devices. */
-void
+static void
 compare_entry(struct entry *ep, int do_compare)
 {
-       if ((ep->e_flags & (NEW|EXTRACT)) == 0)
+       if ((ep->e_flags & (NEW|EXTRACT)) == 0) {
                badentry(ep, "unexpected file on tape");
+               compare_errors = 1;
+       }
        if (do_compare) (void) comparefile(myname(ep));
        ep->e_flags &= ~(NEW|EXTRACT);
 }
@@ -636,10 +647,10 @@ compare_entry(struct entry *ep, int do_compare)
  * This is the routine used to compare files for the 'C' command.
  */
 void
-compareleaves()
+compareleaves(void)
 {
        register struct entry *ep;
-       ino_t first;
+       dump_ino_t first;
        long curvol;
 
        first = lowerbnd(ROOTINO);
@@ -658,6 +669,7 @@ compareleaves()
                        if (ep == NULL)
                                panic("%d: bad first\n", first);
                        fprintf(stderr, "%s: not found on tape\n", myname(ep));
+                       compare_errors = 1;
                        ep->e_flags &= ~(NEW|EXTRACT);
                        first = lowerbnd(first);
                }
@@ -669,14 +681,17 @@ compareleaves()
                 * on the next incremental tape.
                 */
                if (first != curfile.ino) {
-                       fprintf(stderr, "expected next file %ld, got %ld\n",
-                               first, curfile.ino);
+                       fprintf(stderr, "expected next file %ld, got %lu\n",
+                               (long)first, (unsigned long)curfile.ino);
+                       compare_errors = 1;
                        skipfile();
                        goto next;
                }
                ep = lookupino(curfile.ino);
-               if (ep == NULL)
+               if (ep == NULL) {
                        panic("unknown file on tape\n");
+                       compare_errors = 1;
+               }
                compare_entry(ep, 1);
                for (ep = ep->e_links; ep != NULL; ep = ep->e_links) {
                        compare_entry(ep, 0);
@@ -693,6 +708,25 @@ compareleaves()
                        curvol = volno;
                }
        }
+       /*
+        * If we encounter the end of the tape and the next available
+        * file is not the one which we expect then we have missed one
+        * or more files. Since we do not request files that were not 
+        * on the tape, the lost files must have been due to a tape 
+        * read error, or a file that was removed while the dump was
+        * in progress.
+        */
+       first = lowerbnd(first);
+       while (first < curfile.ino) {
+               ep = lookupino(first);
+               if (ep == NULL)
+                       panic("%d: bad first\n", first);
+               fprintf(stderr, "%s: (inode %lu) not found on tape\n", 
+                       myname(ep), (unsigned long)first);
+               compare_errors = 1;
+               ep->e_flags &= ~(NEW|EXTRACT);
+               first = lowerbnd(first);
+       }
 }
 
 /*
@@ -700,17 +734,16 @@ compareleaves()
  * Extract new leaves.
  */
 void
-createleaves(symtabfile)
-       char *symtabfile;
+createleaves(char *symtabfile)
 {
        register struct entry *ep;
-       ino_t first;
+       dump_ino_t first;
        long curvol;
 
        if (command == 'R') {
-               vprintf(stdout, "Continue extraction of new leaves\n");
+               Vprintf(stdout, "Continue extraction of new leaves\n");
        } else {
-               vprintf(stdout, "Extract new leaves.\n");
+               Vprintf(stdout, "Extract new leaves.\n");
                dumpsymtable(symtabfile, volno);
        }
        first = lowerbnd(ROOTINO);
@@ -728,7 +761,8 @@ createleaves(symtabfile)
                        ep = lookupino(first);
                        if (ep == NULL)
                                panic("%d: bad first\n", first);
-                       fprintf(stderr, "%s: not found on tape\n", myname(ep));
+                       fprintf(stderr, "%s: (inode %lu) not found on tape\n", 
+                               myname(ep), (unsigned long)first);
                        ep->e_flags &= ~(NEW|EXTRACT);
                        first = lowerbnd(first);
                }
@@ -740,8 +774,8 @@ createleaves(symtabfile)
                 * on the next incremental tape.
                 */
                if (first != curfile.ino) {
-                       fprintf(stderr, "expected next file %ld, got %ld\n",
-                               first, curfile.ino);
+                       fprintf(stderr, "expected next file %ld, got %lu\n",
+                               (long)first, (unsigned long)curfile.ino);
                        skipfile();
                        goto next;
                }
@@ -773,6 +807,25 @@ createleaves(symtabfile)
                        curvol = volno;
                }
        }
+       /*
+        * If we encounter the end of the tape and the next available
+        * file is not the one which we expect then we have missed one
+        * or more files. Since we do not request files that were not 
+        * on the tape, the lost files must have been due to a tape 
+        * read error, or a file that was removed while the dump was
+        * in progress.
+        */
+       first = lowerbnd(first);
+       while (first < curfile.ino) {
+               ep = lookupino(first);
+               if (ep == NULL)
+                       panic("%d: bad first\n", first);
+               fprintf(stderr, "%s: (inode %lu) not found on tape\n", 
+                       myname(ep), (unsigned long)first);
+               compare_errors = 1;
+               ep->e_flags &= ~(NEW|EXTRACT);
+               first = lowerbnd(first);
+       }
 }
 
 /*
@@ -780,13 +833,17 @@ createleaves(symtabfile)
  * Efficiently extract a subset of the files on a tape.
  */
 void
-createfiles()
+createfiles(void)
 {
-       register ino_t first, next, last;
+       register dump_ino_t first, next, last;
        register struct entry *ep;
        long curvol;
+#ifdef USE_QFA
+       long tnum, tpos, curtpos, tmpcnt;
+       time_t tistart, tiend, titaken;
+#endif
 
-       vprintf(stdout, "Extract requested files\n");
+       Vprintf(stdout, "Extract requested files\n");
        curfile.action = SKIP;
        getvol((long)1);
        skipmaps();
@@ -794,6 +851,9 @@ createfiles()
        first = lowerbnd(ROOTINO);
        last = upperbnd(maxino - 1);
        for (;;) {
+#ifdef USE_QFA
+               tmpcnt = 1;
+#endif
                first = lowerbnd(first);
                last = upperbnd(last);
                /*
@@ -807,7 +867,21 @@ createfiles()
                 */
                while (curfile.ino > last) {
                        curfile.action = SKIP;
-                       getvol((long)0);
+                       if (!pipein)
+                               getvol((long)0);
+                       if (curfile.ino == maxino) {
+                               next = lowerbnd(next);
+                               while (next < curfile.ino) {
+                                       ep = lookupino(next);
+                                       if (ep == NULL)
+                                               panic("corrupted symbol table\n");
+                                       fprintf(stderr, "%s: (inode %lu) not found on tape\n", 
+                                               myname(ep), (unsigned long)next);
+                                       ep->e_flags &= ~NEW;
+                                       next = lowerbnd(next);
+                               }
+                               return;
+                       }
                        skipmaps();
                        skipdirs();
                }
@@ -817,13 +891,64 @@ createfiles()
                 * or an out of order volume change is encountered
                 */
                next = lowerbnd(curfile.ino);
+#ifdef USE_QFA
+               tistart = time(NULL);
+               if (tapeposflag) {
+                       /* get tape position for inode (position directly) */
+                       (void)Inode2Tapepos(next, &tnum, &tpos, 1);
+                       if (tpos == 0)
+                               /* get tape position for last available inode
+                                * (position before) */
+                               (void)Inode2Tapepos(next, &tnum, &tpos, 0);
+                       if (tpos != 0) {
+                               if (tnum != volno)
+                                       (void)RequestVol(tnum);
+                               if (GetTapePos(&curtpos) == 0) {
+                                       /*  curtpos +1000 ???, some drives 
+                                        *  might be too slow */
+                                       if (tpos > curtpos) {
+#ifdef DEBUG_QFA
+                                               msg("positioning tape %ld from %ld to %ld for inode %10lu ...\n", volno, curtpos, tpos, (unsigned long)next);
+#endif
+                                               if (GotoTapePos(tpos) == 0) {
+#ifdef DEBUG_QFA
+                                                       if (GetTapePos(&curtpos) == 0)
+                                                               msg("before resnyc at tape position %ld\n", curtpos);
+#endif
+                                                       (void)ReReadFromTape();
+#ifdef DEBUG_QFA
+                                                       if (GetTapePos(&curtpos) == 0)
+                                                               msg("after resync at tape position %ld\n", curtpos);
+#endif
+                                               }
+                                       }
+                               }
+                       }
+               }
+#endif /* USA_QFA */
+
                do      {
                        curvol = volno;
-                       while (next > curfile.ino && volno == curvol)
+                       while (next > curfile.ino && volno == curvol) {
+#ifdef USE_QFA
+                               ++tmpcnt;
+#endif
                                skipfile();
+                       }
                        skipmaps();
                        skipdirs();
                } while (volno == curvol + 1);
+#ifdef USE_QFA
+               tiend = time(NULL);
+               titaken = tiend - tistart;
+#ifdef DEBUG_QFA
+               if (titaken / 60 > 0)
+                       msg("%ld reads took %d:%02d:%02d\n", 
+                               tmpcnt, titaken / 3600, 
+                               (titaken % 3600) / 60, titaken % 60);
+#endif
+#endif /* USE_QFA */
+
                /*
                 * If volume change out of order occurred the
                 * current state must be recalculated
@@ -844,7 +969,8 @@ createfiles()
                        ep = lookupino(next);
                        if (ep == NULL)
                                panic("corrupted symbol table\n");
-                       fprintf(stderr, "%s: not found on tape\n", myname(ep));
+                       fprintf(stderr, "%s: (inode %lu) not found on tape\n", 
+                               myname(ep), (unsigned long)next);
                        ep->e_flags &= ~NEW;
                        next = lowerbnd(next);
                }
@@ -868,14 +994,14 @@ createfiles()
  * Add links.
  */
 void
-createlinks()
+createlinks(void)
 {
        register struct entry *np, *ep;
-       register ino_t i;
+       register dump_ino_t i;
        char name[BUFSIZ];
 
        if ((ep = lookupino(WINO))) {
-               vprintf(stdout, "Add whiteouts\n");
+               Vprintf(stdout, "Add whiteouts\n");
                for ( ; ep != NULL; ep = ep->e_links) {
                        if ((ep->e_flags & NEW) == 0)
                                continue;
@@ -887,7 +1013,7 @@ createlinks()
                        ep->e_flags &= ~NEW;
                }
        }
-       vprintf(stdout, "Add links\n");
+       Vprintf(stdout, "Add links\n");
        for (i = ROOTINO; i < maxino; i++) {
                ep = lookupino(i);
                if (ep == NULL)
@@ -912,18 +1038,18 @@ createlinks()
  * that no temporary names remain.
  */
 void
-checkrestore()
+checkrestore(void)
 {
        register struct entry *ep;
-       register ino_t i;
+       register dump_ino_t i;
 
-       vprintf(stdout, "Check the symbol table.\n");
+       Vprintf(stdout, "Check the symbol table.\n");
        for (i = WINO; i < maxino; i++) {
                for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
                        ep->e_flags &= ~KEEP;
                        if (ep->e_type == NODE)
                                ep->e_flags &= ~(NEW|EXISTED);
-                       if (ep->e_flags != 0)
+                       if (ep->e_flags /* != NULL */)
                                badentry(ep, "incomplete operations");
                }
        }
@@ -934,10 +1060,7 @@ checkrestore()
  * A paranoid check that things are as they should be.
  */
 long
-verifyfile(name, ino, type)
-       char *name;
-       ino_t ino;
-       int type;
+verifyfile(char *name, dump_ino_t ino, int type)
 {
        struct entry *np, *ep;
        long descend = GOOD;