X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Frestore.c;h=eba23e13e939584427390ba50949fa4a9249a5c4;hp=2c1089248180076059f675994228debd44b8a85a;hb=792ff63acf448f21a3ef2869e4bbcdbf4f7f87f2;hpb=ec387a1267f4cac7625cd5b6d1c1f080d39085b3 diff --git a/restore/restore.c b/restore/restore.c index 2c10892..eba23e1 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 - * + * Stelian Pop , 1999-2000 + * Stelian Pop - AlcĂ´ve , 2000-2002 */ /* @@ -37,23 +37,35 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $Id: restore.c,v 1.5 1999/10/11 13:31:13 stelian Exp $ */ +#ifndef lint +static const char rcsid[] = + "$Id: restore.c,v 1.28 2002/02/04 11:21:20 stelian Exp $"; +#endif /* not lint */ + +#include #include #ifdef __linux__ #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 @@ -69,14 +81,26 @@ static char *keyval __P((int)); * List entries on the tape. */ long -listfile(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 long tpos; +#endif if (TSTINO(ino, dumpmap) == 0) return (descend); Vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir "); - fprintf(stdout, "%10lu\t%s\n", (unsigned long)ino, name); +#ifdef USE_QFA + if (tapeposflag) { /* add QFA positions to output */ + (void)Inode2Tapepos(ino, &tnum, &tpos, 1); + fprintf(stdout, "%10lu\t%ld\t%lld\t%s\n", (unsigned long)ino, + tnum, tpos, name); + } + else +#endif + fprintf(stdout, "%10lu\t%s\n", (unsigned long)ino, name); return (descend); } @@ -85,9 +109,9 @@ listfile(char *name, ino_t ino, int type) * Request that new entries be extracted. */ long -addfile(char *name, ino_t ino, int type) +addfile(char *name, dump_ino_t ino, int type) { - register struct entry *ep; + struct entry *ep, *np; long descend = hflag ? GOOD : FAIL; char buf[100]; @@ -112,9 +136,18 @@ addfile(char *name, ino_t ino, int 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); +#ifdef USE_QFA + if ((type == NODE) && (!createtapeposflag)) +#else if (type == NODE) +#endif newnode(ep); ep->e_flags |= NEW; return (descend); @@ -126,7 +159,7 @@ addfile(char *name, ino_t ino, int type) */ /* ARGSUSED */ long -deletefile(char *name, ino_t ino, int type) +deletefile(char *name, dump_ino_t ino, int type) { long descend = hflag ? GOOD : FAIL; struct entry *ep; @@ -166,8 +199,8 @@ static struct entry *removelist; void removeoldleaves(void) { - register struct entry *ep, *nextep; - register 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))) { @@ -221,9 +254,9 @@ removeoldleaves(void) * Renames are done at the same time. */ long -nodeupdates(char *name, ino_t ino, int type) +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; @@ -475,10 +508,11 @@ nodeupdates(char *name, ino_t ino, int 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 %lu) not found on tape\n", name, (unsigned long)ino); + do_compare_error; break; /* @@ -531,8 +565,8 @@ keyval(int key) void findunreflinks(void) { - register struct entry *ep, *np; - register ino_t i; + struct entry *ep, *np; + dump_ino_t i; Vprintf(stdout, "Find unreferenced names.\n"); for (i = ROOTINO; i < maxino; i++) { @@ -579,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"); @@ -608,8 +642,10 @@ removeoldnodes(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"); + do_compare_error; + } if (do_compare) (void) comparefile(myname(ep)); ep->e_flags &= ~(NEW|EXTRACT); } @@ -620,8 +656,8 @@ compare_entry(struct entry *ep, int do_compare) void compareleaves(void) { - register struct entry *ep; - ino_t first; + struct entry *ep; + dump_ino_t first; long curvol; first = lowerbnd(ROOTINO); @@ -640,6 +676,7 @@ compareleaves(void) if (ep == NULL) panic("%d: bad first\n", first); fprintf(stderr, "%s: not found on tape\n", myname(ep)); + do_compare_error; ep->e_flags &= ~(NEW|EXTRACT); first = lowerbnd(first); } @@ -653,12 +690,15 @@ compareleaves(void) if (first != curfile.ino) { fprintf(stderr, "expected next file %ld, got %lu\n", (long)first, (unsigned long)curfile.ino); + do_compare_error; skipfile(); goto next; } ep = lookupino(curfile.ino); - if (ep == NULL) + if (ep == NULL) { panic("unknown file on tape\n"); + do_compare_error; + } compare_entry(ep, 1); for (ep = ep->e_links; ep != NULL; ep = ep->e_links) { compare_entry(ep, 0); @@ -675,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); + } } /* @@ -684,8 +743,8 @@ compareleaves(void) void createleaves(char *symtabfile) { - register struct entry *ep; - ino_t first; + struct entry *ep; + dump_ino_t first; long curvol; if (command == 'R') { @@ -709,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); } @@ -754,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); + } } /* @@ -763,18 +842,34 @@ createleaves(char *symtabfile) void createfiles(void) { - register 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, 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); last = upperbnd(maxino - 1); for (;;) { +#ifdef USE_QFA + tmpcnt = 1; +#endif first = lowerbnd(first); last = upperbnd(last); /* @@ -788,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(); } @@ -798,13 +907,79 @@ createfiles(void) * 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 %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 resync at tape position %lld (%ld, %ld, %s)\n", curtpos, next, curfile.ino, curfile.name); +#endif + ReReadInodeFromTape(next); +#ifdef DEBUG_QFA + if (GetTapePos(&curtpos) == 0) + msg("after resync at tape position %lld (%ld, %ld, %s)\n", curtpos, next, curfile.ino, curfile.name); +#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; - 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 @@ -825,7 +1000,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); } @@ -837,7 +1016,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(); @@ -851,8 +1046,8 @@ createfiles(void) void createlinks(void) { - register struct entry *np, *ep; - register ino_t i; + struct entry *np, *ep; + dump_ino_t i; char name[BUFSIZ]; if ((ep = lookupino(WINO))) { @@ -895,8 +1090,8 @@ createlinks(void) void checkrestore(void) { - register struct entry *ep; - register ino_t i; + struct entry *ep; + dump_ino_t i; Vprintf(stdout, "Check the symbol table.\n"); for (i = WINO; i < maxino; i++) { @@ -915,7 +1110,7 @@ checkrestore(void) * A paranoid check that things are as they should be. */ long -verifyfile(char *name, ino_t ino, int type) +verifyfile(char *name, dump_ino_t ino, int type) { struct entry *np, *ep; long descend = GOOD;