* 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: tape.c,v 1.66 2002/11/28 08:54:00 stelian Exp $";
+ "$Id: tape.c,v 1.74 2003/03/31 09:42:59 stelian Exp $";
#endif /* not lint */
#include <config.h>
#include <bzlib.h>
#endif /* HAVE_BZLIB */
+#ifdef HAVE_LZO
+#include <minilzo.h>
+#endif /* HAVE_LZO */
+
#include "restore.h"
#include "extern.h"
#include "pathnames.h"
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
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 *));
tapebufsize = size;
}
-#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB)
+#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
static void
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
temptape = magtape;
#ifdef RRESTORE
- if (host)
+ if (!Afile && host)
mt = rmtopen(temptape, O_RDONLY);
else
#endif
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();
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 */
}
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';
}
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;
*/
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 */
}
xtrskip(UNUSED(char *buf), size_t size)
{
- if (LSEEK(ofile, (off_t)size, SEEK_CUR) == -1)
+ if (LSEEK(ofile, (OFF_T)size, SEEK_CUR) == -1)
err(1, "seek error extracting inode %lu, name %s\nlseek",
(unsigned long)curfile.ino, curfile.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;
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);
/* 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;
/*
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.
* 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)
#endif
getmore:
#ifdef RRESTORE
- if (host)
+ if (!Afile && host)
i = rmtread(&tapebuf[rd], cnt);
else
#endif
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
- seek_failed = (LSEEK(mt, i, SEEK_CUR) == (off_t)-1);
+ seek_failed = (LSEEK(mt, i, SEEK_CUR) == (OFF_T)-1);
if (seek_failed) {
warn("continuation failed");
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.
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;
break;
}
}
-#endif /* HAVE_ZLIB || HAVE_BZLIB */
+#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
/*
* Read the first block and get the blocksize from it. Test
size = len;
while (size > 0) {
#ifdef RRESTORE
- if (host)
+ if (!Afile && host)
i = rmtread(buf, size);
else
#endif
if (mt < 0)
return;
#ifdef RRESTORE
- if (host)
+ if (!Afile && host)
rmtclose();
else
#endif
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");
}
#ifdef RDUMP
if (host)
- err = (rmtseek((long)pos, SEEK_SET) < 0);
+ err = (rmtseek(pos, SEEK_SET) < 0);
else
#endif
{
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);