X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Ftape.c;h=df8676362d65c5bbab59772eb0c0c77bcbef02ee;hp=f61fc879ee395b2228fe61d4e510d0348ea96210;hb=103122b3455278bdf377ce24821168be90238fda;hpb=103245b6fea8e7d77722e85ccb404ac1d928987d diff --git a/dump/tape.c b/dump/tape.c index f61fc87..df86763 100644 --- a/dump/tape.c +++ b/dump/tape.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-2000 - * Stelian Pop - Alcôve , 2000 + * Stelian Pop , 1999-2000 + * Stelian Pop - Alcôve , 2000-2002 */ /*- @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.55 2001/09/06 09:00:32 stelian Exp $"; + "$Id: tape.c,v 1.60 2002/01/22 11:12:28 stelian Exp $"; #endif /* not lint */ #include @@ -68,7 +68,6 @@ int write(), read(); #endif #include #include -#include #include #include #ifdef __linux__ @@ -116,6 +115,7 @@ char *nexttape; extern pid_t rshpid; int eot_code = 1; long long tapea_bytes = 0; /* bytes_written at start of current volume */ +static int magtapeout; /* output is really a tape */ static ssize_t atomic_read __P((int, void *, size_t)); static ssize_t atomic_write __P((int, const void *, size_t)); @@ -124,6 +124,10 @@ static void enslave __P((void)); static void flushtape __P((void)); static void killall __P((void)); static void rollforward __P((void)); +#ifdef USE_QFA +static int GetTapePos __P((long *)); +static void MkTapeString __P((struct s_spcl *, long)); +#endif /* * Concurrent dump mods (Caltech) - disk block reading and tape writing @@ -851,6 +855,17 @@ restore_check_point: if (!query("Do you want to retry the open?")) dumpabort(0); } +#ifdef RDUMP + if (!host) +#endif + { + struct mtget mt_stat; + magtapeout = ioctl(tapefd, MTIOCGET, (char *)&mt_stat) == 0; + /* + msg("Output is to %s\n", + magtapeout ? "tape" : "file/pipe"); + */ + } enslave(); /* Share open tape file descriptor with slaves */ @@ -1041,6 +1056,12 @@ doslave(int cmd, int slave_number, int first) union u_spcl *uspclptr; struct s_spcl *spclptr; #endif /* USE_QFA */ + sigset_t set; + + sigemptyset(&set); + sigaddset(&set, SIGUSR2); + sigprocmask(SIG_BLOCK, &set, NULL); + sigemptyset(&set); /* * Need our own seek pointer. @@ -1123,6 +1144,7 @@ doslave(int cmd, int slave_number, int first) if (compressed && do_compress) { comp_buf->length = bufsize; worklen = TP_BSIZE + writesize; + compresult = 1; #ifdef HAVE_ZLIB if (!bzipflag) { compresult = compress2(comp_buf->buf, @@ -1178,29 +1200,25 @@ doslave(int cmd, int slave_number, int first) if (sigsetjmp(jmpbuf, 1) == 0) { ready = 1; if (!caught) - (void) pause(); + sigsuspend(&set); } ready = 0; caught = 0; #ifdef USE_QFA if (gTapeposfd >= 0) { - uspclptr = (union u_spcl *)&slp->tblock[0]; - spclptr = &uspclptr->s_spcl; - if ((spclptr->c_magic == NFS_MAGIC) && - (spclptr->c_type == TS_INODE) && - (spclptr->c_date == gThisDumpDate)) { - /* if an error occured previously don't - * try again */ - if (gtperr == 0) { - if ((gtperr = GetTapePos(&curtapepos)) == 0) { -#ifdef DEBUG_QFA - msg("inode %ld at tapepos %ld\n", spclptr->c_inumber, curtapepos); -#endif - sprintf(gTps, "%ld\t%d\t%ld\n", (unsigned long)spclptr->c_inumber, tapeno, curtapepos); - if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) { - warn("error writing tapepos file.\n"); - } + int i; + for (i = 0; i < ntrec; ++i) { + uspclptr = (union u_spcl *)&slp->tblock[i]; + spclptr = &uspclptr->s_spcl; + if ((spclptr->c_magic == NFS_MAGIC) && + (spclptr->c_type == TS_INODE) && + (spclptr->c_date == gThisDumpDate)) { + /* if an error occured previously don't + * try again */ + if (gtperr == 0) { + if ((gtperr = GetTapePos(&curtapepos)) == 0) + MkTapeString(spclptr, curtapepos); } } } @@ -1301,13 +1319,20 @@ atomic_write(int fd, const void *buf, size_t count) /* * read the current tape position */ -int +static int GetTapePos(long *pos) { int err = 0; - *pos = 0; - if (ioctl(tapefd, MTIOCPOS, pos) == -1) { + if (magtapeout) { + *pos = 0; + err = (ioctl(tapefd, MTIOCPOS, pos) < 0); + } + else { + *pos = lseek(tapefd, 0, SEEK_CUR); + err = (*pos < 0); + } + if (err) { err = errno; msg("[%ld] error: %d (getting tapepos: %ld)\n", getpid(), err, *pos); @@ -1315,4 +1340,21 @@ GetTapePos(long *pos) } return err; } + +static void +MkTapeString(struct s_spcl *spclptr, long curtapepos) { + +#ifdef DEBUG_QFA + msg("inode %ld at tapepos %ld\n", spclptr->c_inumber, curtapepos); +#endif + + snprintf(gTps, sizeof(gTps), "%ld\t%d\t%ld\n", + (unsigned long)spclptr->c_inumber, + tapeno, + curtapepos); + gTps[sizeof(gTps) - 1] = '\0'; + if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) { + warn("error writing tapepos file.\n"); + } +} #endif /* USE_QFA */