From b97e998acde1a307cb5139ac726afef0b686411f Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Mon, 25 Mar 1985 02:11:17 -0800 Subject: [PATCH] dynamically calculate tape block size unless specified on command line SCCS-vsn: sbin/restore/tape.c 3.27 SCCS-vsn: sbin/restore/restore.h 3.12 SCCS-vsn: sbin/restore/main.c 3.16 SCCS-vsn: sbin/restore/symtab.c 3.17 --- usr/src/sbin/restore/main.c | 7 +- usr/src/sbin/restore/restore.h | 3 +- usr/src/sbin/restore/symtab.c | 6 +- usr/src/sbin/restore/tape.c | 166 ++++++++++++++++++++++----------- 4 files changed, 120 insertions(+), 62 deletions(-) diff --git a/usr/src/sbin/restore/main.c b/usr/src/sbin/restore/main.c index 04c74c7946..49ed06d07a 100644 --- a/usr/src/sbin/restore/main.c +++ b/usr/src/sbin/restore/main.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)main.c 3.15 (Berkeley) 85/01/18"; +static char sccsid[] = "@(#)main.c 3.16 (Berkeley) 85/03/24"; #endif /* Copyright (c) 1983 Regents of the University of California */ @@ -26,12 +26,12 @@ static char sccsid[] = "@(#)main.c 3.15 (Berkeley) 85/01/18"; #include #include -int cvtflag = 0, dflag = 0, vflag = 0, yflag = 0; +int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0; int hflag = 1, mflag = 1; char command = '\0'; long dumpnum = 1; long volno = 0; -long ntrec = NTREC; +long ntrec; char *dumpmap; char *clrimap; ino_t maxino; @@ -103,6 +103,7 @@ usage: /* * change default tape blocksize */ + bflag++; if (argc < 1) { fprintf(stderr, "missing block size\n"); done(1); diff --git a/usr/src/sbin/restore/restore.h b/usr/src/sbin/restore/restore.h index 6aba26db9b..947d77e576 100644 --- a/usr/src/sbin/restore/restore.h +++ b/usr/src/sbin/restore/restore.h @@ -1,4 +1,4 @@ -/* restore.h 3.11 85/02/18 */ +/* restore.h 3.12 85/03/24 */ #include #include @@ -10,6 +10,7 @@ * Flags */ extern int cvtflag; /* convert from old to new tape format */ +extern int bflag; /* set input block size */ extern int dflag; /* print out debugging info */ extern int hflag; /* restore heirarchies */ extern int mflag; /* restore by name instead of inode number */ diff --git a/usr/src/sbin/restore/symtab.c b/usr/src/sbin/restore/symtab.c index 3ecdd1cd31..07fd2ea1d3 100644 --- a/usr/src/sbin/restore/symtab.c +++ b/usr/src/sbin/restore/symtab.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)symtab.c 3.16 (Berkeley) 85/01/18"; +static char sccsid[] = "@(#)symtab.c 3.17 (Berkeley) 85/03/24"; #endif /* Copyright (c) 1983 Regents of the University of California */ @@ -386,6 +386,7 @@ struct symtableheader { time_t dumptime; time_t dumpdate; ino_t maxino; + long ntrec; }; /* @@ -463,6 +464,7 @@ dumpsymtable(filename, checkpt) hdr.stringsize = stroff; hdr.dumptime = dumptime; hdr.dumpdate = dumpdate; + hdr.ntrec = ntrec; (void) fwrite((char *)&hdr, sizeof(struct symtableheader), 1, fd); if (ferror(fd)) { perror("fwrite"); @@ -536,6 +538,8 @@ initsymtable(filename) curfile.action = SKIP; dumptime = hdr.dumptime; dumpdate = hdr.dumpdate; + if (!bflag) + newtapebuf(hdr.ntrec); getvol(hdr.volno); break; default: diff --git a/usr/src/sbin/restore/tape.c b/usr/src/sbin/restore/tape.c index c0b381084a..57d941b58e 100644 --- a/usr/src/sbin/restore/tape.c +++ b/usr/src/sbin/restore/tape.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)tape.c 3.26 (Berkeley) 85/02/18"; +static char sccsid[] = "@(#)tape.c 3.27 (Berkeley) 85/03/24"; #endif /* Copyright (c) 1983 Regents of the University of California */ @@ -40,11 +40,10 @@ setinput(source) #endif RRESTORE flsht(); - tbf = (char *)malloc(ntrec * TP_BSIZE); - if (tbf == NULL) { - fprintf(stderr, "Cannot allocate space for tape buffer\n"); - done(1); - } + if (bflag) + newtapebuf(ntrec); + else + newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC); terminal = stdin; #ifdef RRESTORE host = source; @@ -80,6 +79,24 @@ nohost: #endif RRESTORE } +newtapebuf(size) + long size; +{ + static tbfsize = -1; + + ntrec = size; + if (size <= tbfsize) + return; + if (tbf != NULL) + free(tbf); + tbf = (char *)malloc(size * TP_BSIZE); + if (tbf == NULL) { + fprintf(stderr, "Cannot allocate space for tape buffer\n"); + done(1); + } + tbfsize = size; +} + /* * Verify that the tape drive can be accessed and * that it actually is a dump tape. @@ -106,6 +123,8 @@ setup() volno = 1; setdumpnum(); flsht(); + if (!pipein && !bflag) + findtapeblksize(); if (gethead(&spcl) == FAIL) { bct--; /* push back this block */ cvtflag++; @@ -572,77 +591,110 @@ readtape(b) long rd, newvol; int cnt; - if (bct >= ntrec) { - for (i = 0; i < ntrec; i++) - ((struct s_spcl *)&tbf[i*TP_BSIZE])->c_magic = 0; - bct = 0; - cnt = ntrec*TP_BSIZE; - rd = 0; - getmore: + if (bct < ntrec) { + bcopy(&tbf[(bct++*TP_BSIZE)], b, (long)TP_BSIZE); + blksread++; + return; + } + for (i = 0; i < ntrec; i++) + ((struct s_spcl *)&tbf[i*TP_BSIZE])->c_magic = 0; + bct = 0; + cnt = ntrec*TP_BSIZE; + rd = 0; +getmore: #ifdef RRESTORE - i = rmtread(&tbf[rd], cnt); + i = rmtread(&tbf[rd], cnt); #else - i = read(mt, &tbf[rd], cnt); + i = read(mt, &tbf[rd], cnt); #endif - if (i > 0 && i != ntrec*TP_BSIZE) { - if (!pipein) - panic("partial block read: %d should be %d\n", - i, ntrec*TP_BSIZE); + if (i > 0 && i != ntrec*TP_BSIZE) { + if (pipein) { rd += i; cnt -= i; if (cnt > 0) goto getmore; i = rd; + } else { + if (i % TP_BSIZE != 0) + panic("partial block read: %d should be %d\n", + i, ntrec * TP_BSIZE); + bcopy((char *)&endoftapemark, &tbf[i], + (long)TP_BSIZE); } - if (i < 0) { - fprintf(stderr, "Tape read error while "); - switch (curfile.action) { - default: - fprintf(stderr, "trying to set up tape\n"); - break; - case UNKNOWN: - fprintf(stderr, "trying to resyncronize\n"); - break; - case USING: - fprintf(stderr, "restoring %s\n", curfile.name); - break; - case SKIP: - fprintf(stderr, "skipping over inode %d\n", - curfile.ino); - break; - } - if (!yflag && !reply("continue")) - done(1); - i = ntrec*TP_BSIZE; - bzero(tbf, i); + } + if (i < 0) { + fprintf(stderr, "Tape read error while "); + switch (curfile.action) { + default: + fprintf(stderr, "trying to set up tape\n"); + break; + case UNKNOWN: + fprintf(stderr, "trying to resyncronize\n"); + break; + case USING: + fprintf(stderr, "restoring %s\n", curfile.name); + break; + case SKIP: + fprintf(stderr, "skipping over inode %d\n", + curfile.ino); + break; + } + if (!yflag && !reply("continue")) + done(1); + i = ntrec*TP_BSIZE; + bzero(tbf, i); #ifdef RRESTORE - if (rmtseek(i, 1) < 0) + if (rmtseek(i, 1) < 0) #else - if (lseek(mt, i, 1) == (long)-1) + if (lseek(mt, i, 1) == (long)-1) #endif - { - perror("continuation failed"); - done(1); - } + { + perror("continuation failed"); + done(1); } - if (i == 0) { - if (pipein) { - bcopy((char *)&endoftapemark, b, - (long)TP_BSIZE); - flsht(); - return; - } - newvol = volno + 1; - volno = 0; - getvol(newvol); - readtape(b); + } + if (i == 0) { + if (pipein) { + bcopy((char *)&endoftapemark, b, + (long)TP_BSIZE); + flsht(); return; } + newvol = volno + 1; + volno = 0; + getvol(newvol); + readtape(b); + return; } bcopy(&tbf[(bct++*TP_BSIZE)], b, (long)TP_BSIZE); blksread++; } +findtapeblksize() +{ + register long i; + + for (i = 0; i < ntrec; i++) + ((struct s_spcl *)&tbf[i * TP_BSIZE])->c_magic = 0; + bct = 0; +#ifdef RRESTORE + i = rmtread(tbf, ntrec * TP_BSIZE); +#else + i = read(mt, tbf, ntrec * TP_BSIZE); +#endif + if (i <= 0) { + perror("Tape read error"); + done(1); + } + if (i % TP_BSIZE != 0) { + fprintf(stderr, "Tape block size (%d) %s (%d)\n", + i, "is not a multiple of dump block size", TP_BSIZE); + done(1); + } + ntrec = i / TP_BSIZE; + vprintf(stdout, "Tape block size is %d\n", ntrec); +} + flsht() { -- 2.20.1