X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Ftape.c;h=553abbc8e99fef89f0d75fc27bdbd2a612451a3c;hp=2bb447239bed286d20afbe0de2cb57f2afdf7215;hb=206f768c7a7a4bca1c4acc3c686d55578c0cb919;hpb=5bf65105dbaf0bb3d6fb4ccb3d8790bda496d861 diff --git a/restore/tape.c b/restore/tape.c index 2bb4472..553abbc 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -23,11 +23,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. * @@ -46,7 +42,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.67 2003/01/10 14:42:51 stelian Exp $"; + "$Id: tape.c,v 1.74 2003/03/31 09:42:59 stelian Exp $"; #endif /* not lint */ #include @@ -88,6 +84,10 @@ static const char rcsid[] = #include #endif /* HAVE_BZLIB */ +#ifdef HAVE_LZO +#include +#endif /* HAVE_LZO */ + #include "restore.h" #include "extern.h" #include "pathnames.h" @@ -106,7 +106,7 @@ static int numtrec; static char *tapebuf; /* input buffer for read */ static int bufsize; /* buffer size without prefix */ static char *tbufptr = NULL; /* active tape buffer */ -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) static char *comprbuf; /* uncompress work buf */ static size_t comprlen; /* size including prefix */ #endif @@ -154,7 +154,7 @@ static void xtrmapskip __P((char *, size_t)); static void xtrskip __P((char *, size_t)); static void setmagtapein __P((void)); -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) static void newcomprbuf __P((int)); static void (*readtape_func) __P((char *)); static void readtape_set __P((char *)); @@ -243,7 +243,7 @@ newtapebuf(long size) tapebufsize = size; } -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) static void newcomprbuf(int size) { @@ -257,7 +257,7 @@ newcomprbuf(int size) if (comprbuf == NULL) errx(1, "Cannot allocate space for decompress buffer"); } -#endif /* HAVE_ZLIB || HAVE_BZLIB */ +#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */ /* * Verify that the tape drive can be accessed and @@ -286,7 +286,7 @@ setup(void) temptape = magtape; #ifdef RRESTORE - if (host) + if (!Afile && host) mt = rmtopen(temptape, O_RDONLY); else #endif @@ -295,14 +295,20 @@ setup(void) else mt = OPEN(temptape, O_RDONLY, 0); if (mt < 0) - err(1, "%s", magtape); + err(1, "%s", temptape); if (!Afile) { volno = 1; setmagtapein(); setdumpnum(); } -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) readtape_func = readtape_set; +#if defined(HAVE_LZO) + if (lzo_init() != LZO_E_OK) { + msg("internal error - lzo_init failed \n"); + exit(1); + } +#endif #endif FLUSHTAPEBUF(); findtapeblksize(); @@ -318,7 +324,7 @@ setup(void) if (zflag) { fprintf(stderr, "Dump tape is compressed.\n"); -#if !defined(HAVE_ZLIB) && !defined(HAVE_BZLIB) +#if !defined(HAVE_ZLIB) && !defined(HAVE_BZLIB) && !defined(HAVE_LZO) errx(1,"This restore version doesn't support decompression"); #endif /* !HAVE_ZLIB && !HAVE_BZLIB */ } @@ -502,6 +508,13 @@ again: return; } closemt(); + + /* + * if using an archive file, reset its name so readtape() + * could properly use remote access. + */ + Afile = NULL; + if (Mflag) { snprintf(magtape, MAXPATHLEN, "%s%03ld", magtapeprefix, newvol); magtape[MAXPATHLEN - 1] = '\0'; @@ -550,7 +563,7 @@ again: } gethdr: setmagtapein(); -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) readtape_func = readtape_set; #endif volno = newvol; @@ -594,7 +607,7 @@ gethdr: */ if (zflag) { fprintf(stderr, "Dump tape is compressed.\n"); -#if !defined(HAVE_ZLIB) && !defined(HAVE_BZLIB) +#if !defined(HAVE_ZLIB) && !defined(HAVE_BZLIB) && !defined(HAVE_LZO) errx(1,"This restore version doesn't support decompression"); #endif /* !HAVE_ZLIB && !HAVE_BZLIB */ } @@ -1266,6 +1279,16 @@ comparefile(char *name) struct STAT stemp; #endif + curfile.name = name; + curfile.action = USING; + mode = curfile.dip->di_mode; + + if ((mode & IFMT) == IFSOCK) { + Vprintf(stdout, "skipped socket %s\n", name); + skipfile(); + return; + } + if ((r = LSTAT(name, &sb)) != 0) { warn("%s: does not exist (%d)", name, r); do_compare_error; @@ -1273,10 +1296,6 @@ comparefile(char *name) return; } - curfile.name = name; - curfile.action = USING; - mode = curfile.dip->di_mode; - Vprintf(stdout, "comparing %s (size: %ld, mode: 0%o)\n", name, (long)sb.st_size, mode); @@ -1412,7 +1431,7 @@ comparefile(char *name) /* NOTREACHED */ } -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) static void (*readtape_func)(char *) = readtape_set; /* @@ -1445,7 +1464,7 @@ readtape_set(char *buf) readtape(buf); } -#endif /* HAVE_ZLIB || HAVE_BZLIB */ +#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */ /* * This is the original readtape(), it's used for reading uncompressed input. @@ -1453,7 +1472,7 @@ readtape_set(char *buf) * Handle read errors, and end of media. */ static void -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) readtape_uncompr(char *buf) #else readtape(char *buf) @@ -1481,7 +1500,7 @@ readtape(char *buf) #endif getmore: #ifdef RRESTORE - if (host) + if (!Afile && host) i = rmtread(&tapebuf[rd], cnt); else #endif @@ -1543,7 +1562,7 @@ getmore: i = ntrec * TP_BSIZE; memset(tapebuf, 0, (size_t)i); #ifdef RRESTORE - if (host) + if (!Afile && host) seek_failed = (rmtseek(i, 1) < 0); else #endif @@ -1581,7 +1600,7 @@ getmore: tpblksread++; } -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) /* * Read a compressed format block from a file or pipe and uncompress it. @@ -1850,6 +1869,29 @@ decompress_tapebuf(struct tapebuf *tpbin, int readsize) cresult = 0; #endif /* HAVE_BZLIB */ } + if (tpbin->flags == COMPRESS_LZO) { +#ifndef HAVE_LZO + errx(1,"This restore version doesn't support lzo decompression"); +#else + cresult = lzo1x_decompress(tpbin->buf, blocklen, + comprbuf, (lzo_uintp) &worklen,NULL); + output = comprbuf; + switch (cresult) { + case LZO_E_OK: + break; + case LZO_E_ERROR: + case LZO_E_EOF_NOT_FOUND: + reason = "data error"; + break; + default: + reason = "unknown"; + } + if (cresult == LZO_E_OK) + cresult = 1; + else + cresult = 0; +#endif /* HAVE_LZO */ + } } else { output = tpbin->buf; @@ -1895,7 +1937,7 @@ msg_read_error(char *m) break; } } -#endif /* HAVE_ZLIB || HAVE_BZLIB */ +#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */ /* * Read the first block and get the blocksize from it. Test @@ -2024,7 +2066,7 @@ static int read_a_block(int fd, char *buf, size_t len, long *lengthread) size = len; while (size > 0) { #ifdef RRESTORE - if (host) + if (!Afile && host) i = rmtread(buf, size); else #endif @@ -2048,7 +2090,7 @@ closemt(void) if (mt < 0) return; #ifdef RRESTORE - if (host) + if (!Afile && host) rmtclose(); else #endif @@ -2072,7 +2114,8 @@ setmagtapein(void) { magtapein = ioctl(mt, MTIOCGET, (char *)&mt_stat) == 0; } - Vprintf(stdout,"Input is from %s\n", + Vprintf(stdout,"Input is from a %s %s\n", + host ? "remote" : "local", magtapein ? "tape" : Vflag ? "multi-volume (no tape)" : "file/pipe"); } @@ -2640,13 +2683,12 @@ ReReadInodeFromTape(dump_ino_t theino) do { cntloop++; gethead(&spcl); - } while (!(spcl.c_inumber == theino && spcl.c_type == TS_INODE && spcl.c_date == dumpdate) && (cntloop < 32)); + } while (!(spcl.c_inumber == theino && spcl.c_type == TS_INODE && spcl.c_date == dumpdate) && (cntloop < ntrec)); #ifdef DEBUG_QFA fprintf(stderr, "%ld reads\n", cntloop); - if (cntloop == 32) { + if (cntloop == ntrec) { fprintf(stderr, "DEBUG: bufsize %d\n", bufsize); fprintf(stderr, "DEBUG: ntrec %ld\n", ntrec); - fprintf(stderr, "DEBUG: %ld reads\n", cntloop); } #endif findinode(&spcl);