* 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.
*
#ifndef lint
static const char rcsid[] =
- "$Id: restore.c,v 1.23 2002/01/16 10:53:28 stelian Exp $";
+ "$Id: restore.c,v 1.36 2005/03/18 22:12:55 stelian Exp $";
#endif /* not lint */
#include <config.h>
#endif
#include <bsdcompat.h>
#else /* __linux__ */
+#ifdef sunos
+#include <sys/fcntl.h>
+#include <bsdcompat.h>
+#else
#include <ufs/ufs/dinode.h>
+#endif
#endif /* __linux__ */
+#include <protocols/dumprestore.h>
+
+#include <compaterr.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#ifdef __linux__
#include <ext2fs/ext2fs.h>
long descend = hflag ? GOOD : FAIL;
#ifdef USE_QFA
long tnum;
- long tpos;
+ long long tpos;
#endif
if (TSTINO(ino, dumpmap) == 0)
#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
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];
}
}
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);
*/
/* 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;
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))) {
continue;
#ifdef __linux__
(void)fprintf(stderr, "BUG! Should call delwhiteout\n");
+#else
+#ifdef sunos
#else
delwhiteout(ep);
+#endif
#endif
freeentry(ep);
}
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;
void
findunreflinks(void)
{
- register struct entry *ep, *np;
- register dump_ino_t i;
+ 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 == 0) {
+ Dprintf(stdout,
+ "%s: remove unreferenced name\n",
+ myname(np));
+ removeleaf(np);
+ freeentry(np);
+ }
}
}
}
* 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);
+ }
}
}
}
void
removeoldnodes(void)
{
- register struct entry *ep, **prev;
+ struct entry *ep, **prev;
long change;
Vprintf(stdout, "Remove old nodes (directories).\n");
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);
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);
}
void
compareleaves(void)
{
- register struct entry *ep;
+ struct entry *ep;
dump_ino_t first;
long curvol;
void
createleaves(char *symtabfile)
{
- register struct entry *ep;
+ struct entry *ep;
dump_ino_t first;
long curvol;
+ int doremove;
if (command == 'R') {
Vprintf(stdout, "Continue extraction of new leaves\n");
* 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();
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 = 0;
time_t tistart, tiend, titaken;
+ int volChg;
#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);
#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 %ld to %ld 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
}
}
}
}
+ else
#endif /* USA_QFA */
+ if (volinfo[1] == ROOTINO) {
+ int i, goodvol = 1;
+
+ for (i = 1; i < (int)TP_NINOS && volinfo[i] != 0; ++i)
+ if (volinfo[i] < next)
+ goodvol = i;
+
+ if (goodvol != volno)
+ RequestVol(goodvol);
+ }
do {
curvol = volno;
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);
}
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();
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))) {
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;
}
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++) {