X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Frestore.c;h=2a398fc18816e9c7e5ada0ca2fb4c11c856d139b;hp=0be2db19a30c4052b2572437ef37f6a6c4b3da72;hb=fe0e02857a1ff7db4bf8cb28780de7ecf2f24234;hpb=94616addaa56883f49e6c1b5834af0e1a6952f93 diff --git a/restore/restore.c b/restore/restore.c index 0be2db1..2a398fc 100644 --- a/restore/restore.c +++ b/restore/restore.c @@ -2,8 +2,8 @@ * Ported to Linux's Second Extended File System as part of the * dump and restore backup suit * Remy Card , 1994-1997 - * Stelian Pop , 1999-2000 - * Stelian Pop - Alcôve , 2000 + * Stelian Pop , 1999-2000 + * Stelian Pop - Alcôve , 2000-2002 */ /* @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: restore.c,v 1.17 2001/04/26 08:28:29 stelian Exp $"; + "$Id: restore.c,v 1.27 2002/02/04 11:18:46 stelian Exp $"; #endif /* not lint */ #include @@ -51,14 +51,21 @@ static const char rcsid[] = #include #include #include +#ifdef HAVE_EXT2FS_EXT2_FS_H +#include +#else #include +#endif #include #else /* __linux__ */ #include #endif /* __linux__ */ +#include +#include #include #include +#include #ifdef __linux__ #include @@ -79,7 +86,7 @@ listfile(char *name, dump_ino_t ino, int type) long descend = hflag ? GOOD : FAIL; #ifdef USE_QFA long tnum; - long tpos; + long long tpos; #endif if (TSTINO(ino, dumpmap) == 0) @@ -88,7 +95,7 @@ listfile(char *name, dump_ino_t ino, int type) #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, + fprintf(stdout, "%10lu\t%ld\t%lld\t%s\n", (unsigned long)ino, tnum, tpos, name); } else @@ -104,7 +111,7 @@ listfile(char *name, dump_ino_t ino, int type) long addfile(char *name, dump_ino_t ino, int type) { - register struct entry *ep, *np; + struct entry *ep, *np; long descend = hflag ? GOOD : FAIL; char buf[100]; @@ -136,7 +143,11 @@ addfile(char *name, dump_ino_t ino, int type) } } ep = addentry(name, ino, type); +#ifdef USE_QFA + if ((type == NODE) && (!createtapeposflag)) +#else if (type == NODE) +#endif newnode(ep); ep->e_flags |= NEW; return (descend); @@ -188,8 +199,8 @@ static struct entry *removelist; void removeoldleaves(void) { - register struct entry *ep, *nextep; - register dump_ino_t i, mydirino; + struct entry *ep, *nextep; + dump_ino_t i, mydirino; Vprintf(stdout, "Mark entries to be removed.\n"); if ((ep = lookupino(WINO))) { @@ -245,7 +256,7 @@ removeoldleaves(void) long nodeupdates(char *name, dump_ino_t ino, int type) { - register struct entry *ep, *np, *ip; + struct entry *ep, *np, *ip; long descend = GOOD; int lookuptype = 0; int key = 0; @@ -501,7 +512,7 @@ nodeupdates(char *name, dump_ino_t ino, int type) if (compare_ignore_not_found) break; fprintf(stderr, "%s: (inode %lu) not found on tape\n", name, (unsigned long)ino); - compare_errors = 1; + do_compare_error; break; /* @@ -554,8 +565,8 @@ keyval(int key) void findunreflinks(void) { - register struct entry *ep, *np; - register dump_ino_t i; + struct entry *ep, *np; + dump_ino_t i; Vprintf(stdout, "Find unreferenced names.\n"); for (i = ROOTINO; i < maxino; i++) { @@ -602,7 +613,7 @@ findunreflinks(void) void removeoldnodes(void) { - register struct entry *ep, **prev; + struct entry *ep, **prev; long change; Vprintf(stdout, "Remove old nodes (directories).\n"); @@ -633,7 +644,7 @@ compare_entry(struct entry *ep, int do_compare) { if ((ep->e_flags & (NEW|EXTRACT)) == 0) { badentry(ep, "unexpected file on tape"); - compare_errors = 1; + do_compare_error; } if (do_compare) (void) comparefile(myname(ep)); ep->e_flags &= ~(NEW|EXTRACT); @@ -645,7 +656,7 @@ compare_entry(struct entry *ep, int do_compare) void compareleaves(void) { - register struct entry *ep; + struct entry *ep; dump_ino_t first; long curvol; @@ -665,7 +676,7 @@ compareleaves(void) if (ep == NULL) panic("%d: bad first\n", first); fprintf(stderr, "%s: not found on tape\n", myname(ep)); - compare_errors = 1; + do_compare_error; ep->e_flags &= ~(NEW|EXTRACT); first = lowerbnd(first); } @@ -679,14 +690,14 @@ compareleaves(void) if (first != curfile.ino) { fprintf(stderr, "expected next file %ld, got %lu\n", (long)first, (unsigned long)curfile.ino); - compare_errors = 1; + do_compare_error; skipfile(); goto next; } ep = lookupino(curfile.ino); if (ep == NULL) { panic("unknown file on tape\n"); - compare_errors = 1; + do_compare_error; } compare_entry(ep, 1); for (ep = ep->e_links; ep != NULL; ep = ep->e_links) { @@ -704,6 +715,25 @@ compareleaves(void) 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); + do_compare_error; + ep->e_flags &= ~(NEW|EXTRACT); + first = lowerbnd(first); + } } /* @@ -713,7 +743,7 @@ compareleaves(void) void createleaves(char *symtabfile) { - register struct entry *ep; + struct entry *ep; dump_ino_t first; long curvol; @@ -738,7 +768,8 @@ createleaves(char *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); } @@ -783,6 +814,25 @@ createleaves(char *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); + do_compare_error; + ep->e_flags &= ~(NEW|EXTRACT); + first = lowerbnd(first); + } } /* @@ -792,17 +842,26 @@ createleaves(char *symtabfile) void createfiles(void) { - register dump_ino_t first, next, last; - register struct entry *ep; + dump_ino_t first, next, last; + struct entry *ep; long curvol; #ifdef USE_QFA - long tnum, tpos, curtpos, tmpcnt; + long tnum, tmpcnt; + long long tpos, curtpos; time_t tistart, tiend, titaken; #endif Vprintf(stdout, "Extract requested files\n"); curfile.action = SKIP; - getvol((long)1); +#ifdef USE_QFA + if (tapeposflag) + curfile.ino = 0; + else +#endif + if (volinfo[1] == ROOTINO) + curfile.ino = 0; + else + getvol((long)1); skipmaps(); skipdirs(); first = lowerbnd(ROOTINO); @@ -824,7 +883,21 @@ createfiles(void) */ while (curfile.ino > last) { curfile.action = SKIP; - getvol((long)0); + if (!pipein) + getvol((long)0); + if (curfile.ino == maxino) { + next = lowerbnd(first); + 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(); } @@ -849,26 +922,46 @@ createfiles(void) if (GetTapePos(&curtpos) == 0) { /* curtpos +1000 ???, some drives * might be too slow */ - if (tpos > curtpos) { + if (tpos != curtpos) { #ifdef DEBUG_QFA - msg("positioning tape %ld from %ld to %ld for inode %10lu ...\n", volno, curtpos, tpos, (unsigned long)next); + msg("positioning tape %ld from %lld to %lld 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); + msg("before resync at tape position %lld (%ld, %ld, %s)\n", curtpos, next, curfile.ino, curfile.name); #endif - (void)ReReadFromTape(); +msg("bobo1\n"); + ReReadInodeFromTape(next); #ifdef DEBUG_QFA - if (GetTapePos(&curtpos) == 0) - msg("after resync at tape position %ld\n", curtpos); +msg("bobo2\n"); + if (GetTapePos(&curtpos) == 0) { +msg("bobo3\n"); + msg("after resync at tape position %lld (%ld, %ld, %s)\n", curtpos, next, curfile.ino, curfile.name); +msg("bobo4\n"); + } #endif } } +#ifdef DEBUG_QFA + else + msg("already at tape %ld position %ld for inode %10lu ...\n", volno, tpos, (unsigned long)next); +#endif } } } + else #endif /* USA_QFA */ + if (volinfo[1] == ROOTINO) { + int i, goodvol = 1; + + for (i = 1; i < TP_NINOS && volinfo[i] != 0; ++i) + if (volinfo[i] < next) + goodvol = i; + + if (goodvol != volno) + RequestVol(goodvol); + } do { curvol = volno; @@ -912,7 +1005,11 @@ createfiles(void) ep = lookupino(next); if (ep == NULL) panic("corrupted symbol table\n"); - fprintf(stderr, "%s: not found on tape\n", myname(ep)); +#ifdef USE_QFA + if (!createtapeposflag) + fprintf(stderr, "%s: (inode %lu) not found on tape\n", + myname(ep), (unsigned long)next); +#endif ep->e_flags &= ~NEW; next = lowerbnd(next); } @@ -924,7 +1021,23 @@ createfiles(void) ep = lookupino(next); if (ep == NULL) panic("corrupted symbol table\n"); - (void) extractfile(myname(ep)); +#ifdef USE_QFA + if (createtapeposflag) { +#ifdef DEBUG_QFA + msg("inode %ld at tapepos %ld\n", curfile.ino, curtapepos); +#endif + sprintf(gTps, "%ld\t%ld\t%lld\n", (unsigned long)curfile.ino, volno, curtapepos); + if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) + warn("error writing tapepos file.\n"); + skipfile(); + } + else { + msg("restoring %s\n", myname(ep)); +#endif /* USE_QFA */ + (void) extractfile(myname(ep)); +#ifdef USE_QFA + } +#endif /* USE_QFA */ ep->e_flags &= ~NEW; if (volno != curvol) skipmaps(); @@ -938,8 +1051,8 @@ createfiles(void) void createlinks(void) { - register struct entry *np, *ep; - register dump_ino_t i; + struct entry *np, *ep; + dump_ino_t i; char name[BUFSIZ]; if ((ep = lookupino(WINO))) { @@ -982,8 +1095,8 @@ createlinks(void) void checkrestore(void) { - register struct entry *ep; - register dump_ino_t i; + struct entry *ep; + dump_ino_t i; Vprintf(stdout, "Check the symbol table.\n"); for (i = WINO; i < maxino; i++) {