X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Futilities.c;h=838ebe76ec284e9089a3cdf117a41ae8a2846d10;hp=7c3bcd8b1dcbeb183fee5af349557a719ebd4aa6;hb=83a6b4df0b7b7aecc0d3940549d0d480adff35a6;hpb=ddd2ef55b78a62c4bc3daad18bef8a90e85a2052 diff --git a/restore/utilities.c b/restore/utilities.c index 7c3bcd8..838ebe7 100644 --- a/restore/utilities.c +++ b/restore/utilities.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 */ /* @@ -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. * @@ -40,35 +36,35 @@ */ #ifndef lint -#if 0 -static char sccsid[] = "@(#)utilities.c 8.5 (Berkeley) 4/28/95"; -#endif static const char rcsid[] = - "$Id: utilities.c,v 1.3 1999/10/11 12:59:21 stelian Exp $"; + "$Id: utilities.c,v 1.22 2003/03/30 15:40:40 stelian Exp $"; #endif /* not lint */ +#include +#include +#include +#include +#include +#include + #include #include #ifdef __linux__ #include +#include +#ifdef HAVE_EXT2FS_EXT2_FS_H +#include +#else #include +#endif +#include #include #else /* __linux__ */ #include #include #endif /* __linux__ */ -#include -#include -#include -#include -#include - -#ifdef __linux__ -#include -#endif - #include "restore.h" #include "extern.h" @@ -78,7 +74,7 @@ static const char rcsid[] = void pathcheck(char *name) { - register char *cp; + char *cp; struct entry *ep; char *start; @@ -157,7 +153,6 @@ void newnode(struct entry *np) { char *cp; - if (np->e_type != NODE) badentry(np, "newnode: not a node"); cp = myname(np); @@ -237,7 +232,7 @@ linkit(char *existing, char *new, int type) if (!Nflag && (ret = link(existing, new)) < 0) { -#ifndef __linux__ +#if !defined(__linux__) && !defined(sunos) struct stat s; /* @@ -249,6 +244,18 @@ linkit(char *existing, char *new, int type) ret = link(existing, new); chflags(existing, s.st_flags); } +#else + unsigned long s; + + /* + * Most likely, the immutable or append-only attribute + * is set. Clear the attributes and try again. + */ + if (fgetflags (existing, &s) != -1 && + fsetflags (existing, 0) != -1) { + ret = link(existing, new); + fsetflags(existing, s); + } #endif if (ret < 0) { warn("warning: cannot create hard link %s->%s", @@ -265,7 +272,7 @@ linkit(char *existing, char *new, int type) return (GOOD); } -#ifndef __linux__ +#if !defined(__linux__) && !defined(sunos) /* * Create a whiteout. */ @@ -305,10 +312,10 @@ delwhiteout(struct entry *ep) /* * find lowest number file (above "start") that needs to be extracted */ -ino_t -lowerbnd(ino_t start) +dump_ino_t +lowerbnd(dump_ino_t start) { - register struct entry *ep; + struct entry *ep; for ( ; start < maxino; start++) { ep = lookupino(start); @@ -323,10 +330,10 @@ lowerbnd(ino_t start) /* * find highest number file (below "start") that needs to be extracted */ -ino_t -upperbnd(ino_t start) +dump_ino_t +upperbnd(dump_ino_t start) { - register struct entry *ep; + struct entry *ep; for ( ; start > ROOTINO; start--) { ep = lookupino(start); @@ -391,11 +398,11 @@ flagvalues(struct entry *ep) /* * Check to see if a name is on a dump tape. */ -ino_t +dump_ino_t dirlookup(const char *name) { struct direct *dp; - ino_t ino; + dump_ino_t ino; ino = ((dp = pathsearch(name)) == NULL) ? 0 : dp->d_ino; @@ -459,3 +466,98 @@ panic(fmt, va_alist) exit(1); } } + +#ifdef USE_QFA +/* + * search for ino in QFA file + * + * if exactmatch: + * if ino found return tape number and tape position + * if ino not found return tnum=0 and tpos=0 + * + * if not exactmatch: + * if ino found return tape number and tape position + * if ino not found return tape number and tape position of last smaller ino + * if no smaller inode found return tnum=0 and tpos=0 + */ +int +Inode2Tapepos(dump_ino_t ino, long *tnum, long long *tpos, int exactmatch) +{ + char *p, *pp; + char numbuff[32]; + unsigned long tmpino; + long tmptnum; + long long tmptpos; + + *tpos = 0; + *tnum = 0; + if (fseek(gTapeposfp, gSeekstart, SEEK_SET) == -1) + return errno; + while (fgets(gTps, sizeof(gTps), gTapeposfp) != NULL) { + gTps[strlen(gTps) - 1] = 0; /* delete end of line */ + p = gTps; + bzero(numbuff, sizeof(numbuff)); + pp = numbuff; + /* read inode */ + while ((*p != 0) && (*p != '\t')) + *pp++ = *p++; + tmpino = atol(numbuff); + if (*p == 0) + return 1; /* may NOT happen */ + p++; + bzero(numbuff, sizeof(numbuff)); + pp = numbuff; + /* read tapenum */ + while ((*p != 0) && (*p != '\t')) + *pp++ = *p++; + if (*p == 0) + return 1; /* may NOT happen */ + tmptnum = atol(numbuff); + p++; + bzero(numbuff, sizeof(numbuff)); + pp = numbuff; + /* read tapepos */ + while ((*p != 0) && (*p != '\t')) + *pp++ = *p++; + tmptpos = atoll(numbuff); + + if (exactmatch) { + if (tmpino == ino) { + *tnum = tmptnum; + *tpos = tmptpos; + return 0; + } + } else { + if (tmpino > ino) { + return 0; + } else { + *tnum = tmptnum; + *tpos = tmptpos; + } + } + } + return 0; +} +#endif /* USE_QFA */ + +void resizemaps(dump_ino_t oldmax, dump_ino_t newmax) +{ + char *map; + + if (usedinomap) { + map = calloc((unsigned)1, (unsigned)howmany(newmax, NBBY)); + if (map == NULL) + errx(1, "no memory for active inode map"); + memcpy(map, usedinomap, howmany(oldmax, NBBY)); + free(usedinomap); + usedinomap = map; + } + if (dumpmap) { + map = calloc((unsigned)1, (unsigned)howmany(newmax, NBBY)); + if (map == NULL) + errx(1, "no memory for file dump list"); + memcpy(map, dumpmap, howmany(oldmax, NBBY)); + free(dumpmap); + dumpmap = map; + } +}