X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=restore%2Ftape.c;h=e5e995d71bfe9fbe7d98521a3b8744efea60f7c2;hb=871ede100ce41d967ebbb4e2d67c6b7587e16f76;hp=d7471a39b6513e9228c75b7d5959a3fb2a7c640f;hpb=43460f04f3920ae39f345a2fb39d000a890a4283;p=dump.git diff --git a/restore/tape.c b/restore/tape.c index d7471a3..e5e995d 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -46,7 +46,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.27 2001/03/19 13:22:49 stelian Exp $"; + "$Id: tape.c,v 1.36 2001/04/27 12:23:23 stelian Exp $"; #endif /* not lint */ #include @@ -82,6 +82,9 @@ static const char rcsid[] = #include "extern.h" #include "pathnames.h" +#ifdef USE_QFA +int noresyncmesg = 0; +#endif /* USE_QFA */ static long fssize = MAXBSIZE; static int mt = -1; static int pipein = 0; @@ -147,7 +150,7 @@ static void readtape_comprtape __P((char *)); static char *decompress_tapebuf __P((struct tapebuf *, int)); static void msg_read_error __P((char *)); #endif -static int read_a_block __P((int, void *, size_t, long *)); +static int read_a_block __P((int, char *, size_t, long *)); #define PREFIXSIZE sizeof(struct tapebuf) #define COMPARE_ONTHEFLY 1 @@ -271,7 +274,12 @@ setup(void) magtapein = rmtioctl(MTNOP, 1) != -1; else #endif - magtapein = ioctl(mt, MTIOCGET, (char *) &mt_stat) == 0; + if (ioctl(mt, MTIOCGET, (char *) &mt_stat) == 0) { + if (mt_stat.mt_dsreg & 0xffff) + magtapein = 1; /* fixed blocksize */ + else + magtapein = 2; /* variable blocksize */ + } } Vprintf(stdout,"Input is from %s\n", magtapein? "tape": "file/pipe"); @@ -488,15 +496,9 @@ gethdr: goto again; } if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) { -#ifdef __linux__ fprintf(stderr, "Wrong dump date\n\tgot: %s", ctime4(&tmpbuf.c_date)); - fprintf(stderr, "\twanted: %s", ctime4(&dumpdate)); -#else - fprintf(stderr, "Wrong dump date\n\tgot: %s", - ctime(&tmpbuf.c_date)); fprintf(stderr, "\twanted: %s", ctime(&dumpdate)); -#endif volno = 0; haderror = 1; goto again; @@ -596,15 +598,9 @@ setdumpnum(void) void printdumpinfo(void) { -#ifdef __linux__ fprintf(stdout, "Dump date: %s", ctime4(&spcl.c_date)); fprintf(stdout, "Dumped from: %s", (spcl.c_ddate == 0) ? "the epoch\n" : ctime4(&spcl.c_ddate)); -#else - fprintf(stdout, "Dump date: %s", ctime(&spcl.c_date)); - fprintf(stdout, "Dumped from: %s", - (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&spcl.c_ddate)); -#endif if (spcl.c_host[0] == '\0') return; fprintf(stdout, "Level %d dump of %s on %s:%s\n", @@ -850,6 +846,11 @@ loop: (*fill)((char *)buf, (size_t)(curblk * TP_BSIZE) + size); last_write_was_hole = 0; } + if (size > 0) { + fprintf(stderr, "Missing blocks at the end of %s, assuming hole\n", curfile.name); + (*skip)(clearedbuf, size); + last_write_was_hole = 1; + } if (last_write_was_hole) { ftruncate(ofile, origsize); } @@ -1249,7 +1250,7 @@ comparefile(char *name) panic("cannot delete tmp file %s: %s\n", tmpfile, strerror(errno)); } - if ((ofile = creat(tmpfile, 0600)) < 0) { + if ((ofile = open(tmpfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) { panic("cannot create file temp file %s: %s\n", name, strerror(errno)); } @@ -1329,8 +1330,6 @@ readtape(char *buf) if (numtrec == 0) numtrec = ntrec; cnt = ntrec * TP_BSIZE; - if (zflag) - cnt += PREFIXSIZE; rd = 0; getmore: #ifdef RRESTORE @@ -1643,12 +1642,9 @@ decompress_tapebuf(struct tapebuf *tpbin, int readsize) } switch (cresult) { case Z_OK: - if (worklen != ntrec * TP_BSIZE) { - /* short block, shouldn't happen, but... */ + numtrec = worklen / TP_BSIZE; + if (worklen % TP_BSIZE != 0) reason = "length mismatch"; - if (worklen % TP_BSIZE == 0) - numtrec = worklen / TP_BSIZE; - } break; case Z_MEM_ERROR: reason = "not enough memory"; @@ -1723,7 +1719,12 @@ findtapeblksize(void) * For a pipe or file, read in the first record. For a tape, read * the first block. */ - len = magtapein ? bufsize + PREFIXSIZE: TP_BSIZE; + if (magtapein == 1) /* fixed blocksize tape, not compressed */ + len = ntrec * TP_BSIZE; + else if (magtapein == 2)/* variable blocksize tape */ + len = bufsize + PREFIXSIZE; + else /* not mag tape */ + len = TP_BSIZE; if (read_a_block(mt, tapebuf, len, &i) <= 0) errx(1, "Tape read error on first record"); @@ -1754,8 +1755,8 @@ findtapeblksize(void) else { /* read in the rest of the block based on bufsize */ len = bufsize - TP_BSIZE; - if (read_a_block(mt, tapebuf+TP_BSIZE, len, &i) <= 0 - || i != len) + if (read_a_block(mt, tapebuf+TP_BSIZE, len, &i) < 0 + || (i != len && i % TP_BSIZE != 0)) errx(1,"Error reading dump file header"); tbufptr = tapebuf; numtrec = ntrec; @@ -1765,11 +1766,12 @@ findtapeblksize(void) } /* - * If the input is a tape, we tried to read PREFIXSIZE + - * ntrec * TP_BSIZE bytes. If it's not a compressed dump tape - * or the value of ntrec is too large, we have read less than - * what we asked for; adjust the value of ntrec and test for - * a compressed dump tape prefix. + * If the input is a variable block size tape, we tried to + * read PREFIXSIZE + ntrec * TP_BSIZE bytes. + * If it's not a compressed dump tape or the value of ntrec is + * too large, we have read less than * what we asked for; + * adjust the value of ntrec and test for * a compressed dump + * tape prefix. */ if (i % TP_BSIZE != 0) { @@ -1796,7 +1798,7 @@ findtapeblksize(void) /* * Read a block of data handling all of the messy details. */ -static int read_a_block(int fd, void *buf, size_t len, long *lengthread) +static int read_a_block(int fd, char *buf, size_t len, long *lengthread) { long i = 1, size; @@ -1993,7 +1995,7 @@ good: static void accthdr(struct s_spcl *header) { - static ino_t previno = 0x7fffffff; + static dump_ino_t previno = 0x7fffffff; static int prevtype; static long predict; long blks, i; @@ -2107,8 +2109,11 @@ findinode(struct s_spcl *header) } } while (header->c_type == TS_ADDR); if (skipcnt > 0) - fprintf(stderr, "resync restore, skipped %ld blocks\n", - skipcnt); +#ifdef USE_QFA + if (!noresyncmesg) +#endif + fprintf(stderr, "resync restore, skipped %ld blocks\n", + skipcnt); skipcnt = 0; } @@ -2262,3 +2267,72 @@ swabl(u_long x) return (x); } #endif + +#ifdef USE_QFA +/* + * get the current position of the tape + */ +int +GetTapePos(long *pos) +{ + int err = 0; + + *pos = 0; + if (ioctl(mt, MTIOCPOS, pos) == -1) { + err = errno; + fprintf(stdout, "[%ld] error: %d (getting tapepos: %ld)\n", + (unsigned long)getpid(), err, *pos); + return err; + } + return err; +} + +typedef struct mt_pos { + short mt_op; + int mt_count; +} MTPosRec, *MTPosPtr; + +/* + * go to specified position on tape + */ +int +GotoTapePos(long pos) +{ + int err = 0; + struct mt_pos buf; + + buf.mt_op = MTSEEK; + buf.mt_count = pos; + if (ioctl(mt, MTIOCTOP, &buf) == -1) { + err = errno; + fprintf(stdout, "[%ld] error: %d (setting tapepos: %ld)\n", + (unsigned long)getpid(), err, pos); + return err; + } + return err; +} + +/* + * read next data from tape to re-sync + */ +void +ReReadFromTape(void) +{ + FLUSHTAPEBUF(); + noresyncmesg = 1; + if (gethead(&spcl) == FAIL) { +#ifdef DEBUG_QFA + fprintf(stdout, "DEBUG 1 gethead failed\n"); +#endif + } + findinode(&spcl); + noresyncmesg = 0; +} + +void +RequestVol(long tnum) +{ + FLUSHTAPEBUF(); + getvol(tnum); +} +#endif /* USE_QFA */