* Ported to Linux's Second Extended File System as part of the
* dump and restore backup suit
* Remy Card <card@Linux.EU.Org>, 1994-1997
- * Stelian Pop <pop@noos.fr>, 1999-2000
- * Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 2000
+ * Stelian Pop <stelian@popies.net>, 1999-2000
+ * Stelian Pop <stelian@popies.net> - Alcôve <www.alcove.com>, 2000-2002
*/
/*
#ifndef lint
static const char rcsid[] =
- "$Id: tape.c,v 1.46 2001/08/16 15:24:22 stelian Exp $";
+ "$Id: tape.c,v 1.54 2002/01/22 11:12:28 stelian Exp $";
#endif /* not lint */
#include <config.h>
#endif /* USE_QFA */
static long fssize = MAXBSIZE;
static int mt = -1;
-static int pipein = 0;
+int pipein = 0;
static int magtapein = 0; /* input is from magtape */
static char magtape[MAXPATHLEN];
static char magtapeprefix[MAXPATHLEN];
#ifdef RRESTORE
if (strchr(source, ':')) {
+#ifdef USE_QFA
+ if (tapeposflag)
+ errx(1, "cannot use -Q option on remote media");
+#endif
host = source;
source = strchr(host, ':');
*source++ = '\0';
again:
if (pipein)
exit(1); /* pipes do not get a second chance */
- if (command == 'R' || command == 'r' || curfile.action != SKIP) {
+ if (aflag || curfile.action != SKIP) {
newvol = nextvol;
wantnext = 1;
} else {
fprintf(stderr, "\n");
}
do {
- fprintf(stderr, "Specify next volume #: ");
+ fprintf(stderr, "Specify next volume # (none if no more volumes): ");
(void) fflush(stderr);
(void) fgets(buf, TP_BSIZE, terminal);
} while (!feof(terminal) && buf[0] == '\n');
if (feof(terminal))
exit(1);
+ if (!strcmp(buf, "none\n")) {
+ terminateinput();
+ return;
+ }
newvol = atoi(buf);
if (newvol <= 0) {
fprintf(stderr,
if (STAT(tapefile, &sbuf_tape) != 0) {
panic("Can't lstat tmp file %s: %s\n", tapefile,
strerror(errno));
- compare_errors = 1;
+ do_compare_error;
}
if (sbuf_disk->st_size != sbuf_tape.st_size) {
fprintf(stderr,
"%s: size changed from %ld to %ld.\n",
diskfile, (long)sbuf_tape.st_size, (long)sbuf_disk->st_size);
- compare_errors = 1;
+ do_compare_error;
#ifdef COMPARE_FAIL_KEEP_FILE
return (0);
#else
if ((fd_tape = OPEN(tapefile, O_RDONLY)) < 0) {
panic("Can't open %s: %s\n", tapefile, strerror(errno));
- compare_errors = 1;
+ do_compare_error;
}
if ((fd_disk = OPEN(diskfile, O_RDONLY)) < 0) {
close(fd_tape);
panic("Can't open %s: %s\n", diskfile, strerror(errno));
- compare_errors = 1;
+ do_compare_error;
}
if (do_cmpfiles(fd_tape, fd_disk, sbuf_tape.st_size)) {
diskfile);
close(fd_tape);
close(fd_disk);
- compare_errors = 1;
+ do_compare_error;
#ifdef COMPARE_FAIL_KEEP_FILE
/* rename the file to live in /tmp */
/* rename `tapefile' to /tmp/<basename of diskfile> */
if ((r = LSTAT(name, &sb)) != 0) {
warn("%s: does not exist (%d)", name, r);
- compare_errors = 1;
+ do_compare_error;
skipfile();
return;
}
if (sb.st_mode != mode) {
fprintf(stderr, "%s: mode changed from 0%o to 0%o.\n",
name, mode & 07777, sb.st_mode & 07777);
- compare_errors = 1;
+ do_compare_error;
}
switch (mode & IFMT) {
default:
if (!(sb.st_mode & S_IFLNK)) {
fprintf(stderr, "%s: is no longer a symbolic link\n",
name);
- compare_errors = 1;
+ do_compare_error;
return;
}
lnkbuf[0] = '\0';
fprintf(stderr,
"%s: zero length symbolic link (ignored)\n",
name);
- compare_errors = 1;
+ do_compare_error;
return;
}
if ((lsize = readlink(name, lbuf, MAXPATHLEN)) < 0) {
panic("readlink of %s failed: %s", name,
strerror(errno));
- compare_errors = 1;
+ do_compare_error;
}
lbuf[lsize] = 0;
if (strcmp(lbuf, lnkbuf) != 0) {
fprintf(stderr,
"%s: symbolic link changed from %s to %s.\n",
name, lnkbuf, lbuf);
- compare_errors = 1;
+ do_compare_error;
return;
}
return;
if (!(sb.st_mode & (S_IFCHR|S_IFBLK))) {
fprintf(stderr, "%s: no longer a special file\n",
name);
- compare_errors = 1;
+ do_compare_error;
skipfile();
return;
}
(int)curfile.dip->di_rdev & 0xff,
((int)sb.st_rdev >> 8) & 0xff,
(int)sb.st_rdev & 0xff);
- compare_errors = 1;
+ do_compare_error;
}
skipfile();
return;
if ((ifile = OPEN(name, O_RDONLY)) < 0) {
panic("Can't open %s: %s\n", name, strerror(errno));
skipfile();
- compare_errors = 1;
+ do_compare_error;
}
else {
cmperror = 0;
}
}
if (cmperror)
- compare_errors = 1;
+ do_compare_error;
close(ifile);
}
#else
/* read the block prefix */
ret = read_a_block(mt, tapebuf, PREFIXSIZE, &rl);
+
+ if (Vflag && (ret == 0 || rl < PREFIXSIZE || tpb->length == 0))
+ ret = 0;
if (ret <= 0)
goto readerr;
/* need to know if input is really from a tape */
#ifdef RRESTORE
if (host)
- magtapein = rmtioctl(MTNOP, 1) != -1;
+ magtapein = !lflag;
else
#endif
magtapein = ioctl(mt, MTIOCGET, (char *)&mt_stat) == 0;
}
- Vprintf(stdout,"Input is from %s\n", magtapein? "tape": "file/pipe");
+ Vprintf(stdout,"Input is from %s\n",
+ magtapein ? "tape" :
+ Vflag ? "multi-volume (no tape)" : "file/pipe");
}
/*
{
int err = 0;
- *pos = 0;
- if (ioctl(mt, MTIOCPOS, pos) == -1) {
+ if (magtapein) {
+ *pos = 0;
+ err = (ioctl(mt, MTIOCPOS, pos) < 0);
+ }
+ else {
+ *pos = lseek(mt, 0, SEEK_CUR);
+ err = (*pos < 0);
+ }
+ if (err) {
err = errno;
fprintf(stdout, "[%ld] error: %d (getting tapepos: %ld)\n",
(unsigned long)getpid(), err, *pos);
GotoTapePos(long pos)
{
int err = 0;
- struct mt_pos buf;
- buf.mt_op = MTSEEK;
- buf.mt_count = pos;
- if (ioctl(mt, MTIOCTOP, &buf) == -1) {
+ if (magtapein) {
+ struct mt_pos buf;
+ buf.mt_op = MTSEEK;
+ buf.mt_count = pos;
+ err = (ioctl(mt, MTIOCTOP, &buf) < 0);
+ }
+ else {
+ pos = lseek(mt, pos, SEEK_SET);
+ err = (pos < 0);
+ }
+ if (err) {
err = errno;
fprintf(stdout, "[%ld] error: %d (setting tapepos: %ld)\n",
(unsigned long)getpid(), err, pos);