X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Ftape.c;h=553abbc8e99fef89f0d75fc27bdbd2a612451a3c;hp=145bc653026512b689759411a32075073bbc3a2e;hb=206f768c7a7a4bca1c4acc3c686d55578c0cb919;hpb=6d834d255f34e3cb62466ba5646fc362ee28d6be diff --git a/restore/tape.c b/restore/tape.c index 145bc65..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.71 2003/02/17 10:31:45 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 @@ -301,8 +301,14 @@ setup(void) 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 */ } @@ -557,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; @@ -601,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 */ } @@ -1425,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; /* @@ -1458,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. @@ -1466,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) @@ -1594,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. @@ -1863,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; @@ -1908,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 @@ -2654,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 == 1024) { + 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);