X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Frestore.c;h=780fd76f04bdd0a3d61297acf9719c0295a6a805;hp=1b04fea6b9b8b43e81275461eaab2c90e680c222;hb=f6e1ffa4b425c735543d6c87f93c2e4bf207f1bb;hpb=5d2a3d246d400d45dfd4c49ddb588c69fb60873d diff --git a/restore/restore.c b/restore/restore.c index 1b04fea..780fd76 100644 --- a/restore/restore.c +++ b/restore/restore.c @@ -18,11 +18,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. 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. * @@ -41,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: restore.c,v 1.26 2002/01/25 15:08:59 stelian Exp $"; + "$Id: restore.c,v 1.39 2010/03/22 16:08:10 stelian Exp $"; #endif /* not lint */ #include @@ -58,11 +54,20 @@ static const char rcsid[] = #endif #include #else /* __linux__ */ +#ifdef sunos +#include +#include +#else #include +#endif #endif /* __linux__ */ +#include + +#include #include #include +#include #ifdef __linux__ #include @@ -140,7 +145,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); @@ -152,7 +161,7 @@ addfile(char *name, dump_ino_t ino, int type) */ /* ARGSUSED */ long -deletefile(char *name, dump_ino_t ino, int type) +deletefile(char *name, dump_ino_t ino, UNUSED(int type)) { long descend = hflag ? GOOD : FAIL; struct entry *ep; @@ -210,8 +219,11 @@ removeoldleaves(void) continue; #ifdef __linux__ (void)fprintf(stderr, "BUG! Should call delwhiteout\n"); +#else +#ifdef sunos #else delwhiteout(ep); +#endif #endif freeentry(ep); } @@ -554,25 +566,40 @@ keyval(int key) /* * Find unreferenced link names. + * + * This also takes care of directories which were missed by removeoldleaves(), + * because their inode has been reused, but excluded from the dump. */ void findunreflinks(void) { struct entry *ep, *np; dump_ino_t i; + int j; 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, - "%s: remove unreferenced name\n", - myname(np)); - removeleaf(np); - freeentry(np); + if (ep->e_entries == NULL) + continue; + for (j = 0; j < dirhash_size; j++) { + for (np = ep->e_entries[j]; np != NULL; np = np->e_sibling) { + if ((np->e_flags & ~TMPNAME) == 0) { + Dprintf(stdout, + "%s: remove unreferenced name\n", + myname(np)); + if (np->e_type == LEAF) { + removeleaf(np); + freeentry(np); + } else { + np->e_flags |= TMPNAME; + deleteino(np->e_ino); + np->e_next = removelist; + removelist = np; + } + } } } } @@ -580,15 +607,30 @@ findunreflinks(void) * Any leaves remaining in removed directories is unreferenced. */ for (ep = removelist; ep != NULL; ep = ep->e_next) { - for (np = ep->e_entries; np != NULL; np = np->e_sibling) { - if (np->e_type == LEAF) { - if (np->e_flags != 0) - badentry(np, "unreferenced with flags"); - Dprintf(stdout, - "%s: remove unreferenced name\n", - myname(np)); - removeleaf(np); - freeentry(np); + if (ep->e_entries == NULL) + continue; + for (j = 0; j < dirhash_size; j++) { + for (np = ep->e_entries[j]; np != NULL; np = np->e_sibling) { + if (np->e_type == LEAF) { + if (np->e_flags != 0) + badentry(np, "unreferenced with flags"); + Dprintf(stdout, + "%s: remove unreferenced name\n", + myname(np)); + removeleaf(np); + freeentry(np); + } else { + if ((np->e_flags & ~TMPNAME) != 0) + badentry(np, "unreferenced with flags"); + + if (np->e_flags == 0) { + Dprintf(stdout, + "%s: remove unreferenced name\n", + myname(np)); + np->e_next = ep->e_next; + ep->e_next = np; + } + } } } } @@ -614,10 +656,19 @@ removeoldnodes(void) change = 0; prev = &removelist; for (ep = removelist; ep != NULL; ep = *prev) { + int docont = 0; if (ep->e_entries != NULL) { - prev = &ep->e_next; - continue; + int i; + for (i = 0; i < dirhash_size; i++) { + if (ep->e_entries[i] != NULL) { + prev = &ep->e_next; + docont = 1; + break; + } + } } + if (docont) + continue; *prev = ep->e_next; removenode(ep); freeentry(ep); @@ -639,7 +690,10 @@ compare_entry(struct entry *ep, int do_compare) badentry(ep, "unexpected file on tape"); do_compare_error; } - if (do_compare) (void) comparefile(myname(ep)); + if (do_compare) { + (void) comparefile(myname(ep)); + skipxattr(); + } ep->e_flags &= ~(NEW|EXTRACT); } @@ -683,7 +737,6 @@ 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; } @@ -739,6 +792,7 @@ createleaves(char *symtabfile) struct entry *ep; dump_ino_t first; long curvol; + int doremove; if (command == 'R') { Vprintf(stdout, "Continue extraction of new leaves\n"); @@ -789,18 +843,20 @@ createleaves(char *symtabfile) * be removed since its type may change from one leaf type * to another (e.g. "file" to "character special"). */ - if ((ep->e_flags & EXTRACT) != 0) { - removeleaf(ep); - ep->e_flags &= ~REMOVED; - } - (void) extractfile(myname(ep)); + if ((ep->e_flags & EXTRACT) != 0) + doremove = 1; + else + doremove = 0; + (void) extractfile(ep, doremove); + skipxattr(); ep->e_flags &= ~(NEW|EXTRACT); + /* * We checkpoint the restore after every tape reel, so * as to simplify the amount of work required by the * 'R' command. */ - next: +next: if (curvol != volno) { dumpsymtable(symtabfile, volno); skipmaps(); @@ -840,8 +896,9 @@ createfiles(void) long curvol; #ifdef USE_QFA long tnum, tmpcnt; - long long tpos, curtpos; + long long tpos, curtpos = 0; time_t tistart, tiend, titaken; + int volChg; #endif Vprintf(stdout, "Extract requested files\n"); @@ -903,33 +960,40 @@ createfiles(void) #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); + /* get tape position for inode */ + (void)Inode2Tapepos(next, &tnum, &tpos, 0); if (tpos != 0) { - if (tnum != volno) + if (tnum != volno) { (void)RequestVol(tnum); + volChg = 1; + } else { + volChg = 0; + } if (GetTapePos(&curtpos) == 0) { /* curtpos +1000 ???, some drives * might be too slow */ - if (tpos > curtpos) { + if (((tpos > (curtpos + 1000)) && (volChg == 0)) || ((tpos != curtpos) && (volChg == 1))) { + volChg = 0; #ifdef DEBUG_QFA - msg("positioning tape %ld from %lld to %lld for inode %10lu ...\n", volno, curtpos, tpos, (unsigned long)next); + msg("positioning tape %ld from %lld to %lld for inode %lu ...\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); + if (GetTapePos(&curtpos) == 0) { + msg("before resnyc at tape position %lld (%ld, %ld, %s)\n", curtpos, next, curfile.ino, curfile.name); + } #endif - (void)ReReadFromTape(); + ReReadInodeFromTape(next); #ifdef DEBUG_QFA - if (GetTapePos(&curtpos) == 0) - msg("after resync at tape position %ld\n", curtpos); + if (GetTapePos(&curtpos) == 0) { + msg("after resnyc at tape position %lld (%ld, %ld, %s)\n", curtpos, next, curfile.ino, curfile.name); + } #endif } + } else { +#ifdef DEBUG_QFA + msg("already at tape %ld position %ld for inode %lu ...\n", volno, tpos, (unsigned long)next); +#endif } } } @@ -939,7 +1003,7 @@ createfiles(void) if (volinfo[1] == ROOTINO) { int i, goodvol = 1; - for (i = 1; i < TP_NINOS && volinfo[i] != 0; ++i) + for (i = 1; i < (int)TP_NINOS && volinfo[i] != 0; ++i) if (volinfo[i] < next) goodvol = i; @@ -989,8 +1053,11 @@ createfiles(void) 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); +#ifdef USE_QFA + if (!createtapeposflag) +#endif + fprintf(stderr, "%s: (inode %lu) not found on tape\n", + myname(ep), (unsigned long)next); ep->e_flags &= ~NEW; next = lowerbnd(next); } @@ -1002,7 +1069,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)) != (ssize_t)strlen(gTps)) + warn("error writing tapepos file.\n"); + skipfile(); + } else { +#endif /* USE_QFA */ + (void) extractfile(ep, 0); + skipxattr(); + +#ifdef USE_QFA + } +#endif /* USE_QFA */ ep->e_flags &= ~NEW; if (volno != curvol) skipmaps(); @@ -1027,8 +1110,11 @@ createlinks(void) continue; #ifdef __linux__ (void)fprintf(stderr, "BUG! Should call addwhiteout\n"); +#else +#ifdef sunos #else (void) addwhiteout(myname(ep)); +#endif #endif ep->e_flags &= ~NEW; }