dynamically calculate tape block size unless specified on command line
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 25 Mar 1985 10:11:17 +0000 (02:11 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 25 Mar 1985 10:11:17 +0000 (02:11 -0800)
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
usr/src/sbin/restore/restore.h
usr/src/sbin/restore/symtab.c
usr/src/sbin/restore/tape.c

index 04c74c7..49ed06d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #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 */
 #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 <dumprestor.h>
 #include <signal.h>
 
 #include <dumprestor.h>
 #include <signal.h>
 
-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;
 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;
 char   *dumpmap;
 char   *clrimap;
 ino_t  maxino;
@@ -103,6 +103,7 @@ usage:
                        /*
                         * change default tape blocksize
                         */
                        /*
                         * change default tape blocksize
                         */
+                       bflag++;
                        if (argc < 1) {
                                fprintf(stderr, "missing block size\n");
                                done(1);
                        if (argc < 1) {
                                fprintf(stderr, "missing block size\n");
                                done(1);
index 6aba26d..947d77e 100644 (file)
@@ -1,4 +1,4 @@
-/*     restore.h       3.11    85/02/18        */
+/*     restore.h       3.12    85/03/24        */
 
 #include <stdio.h>
 #include <sys/param.h>
 
 #include <stdio.h>
 #include <sys/param.h>
@@ -10,6 +10,7 @@
  * Flags
  */
 extern int     cvtflag;        /* convert from old to new tape format */
  * 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 */
 extern int     dflag;          /* print out debugging info */
 extern int     hflag;          /* restore heirarchies */
 extern int     mflag;          /* restore by name instead of inode number */
index 3ecdd1c..07fd2ea 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #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 */
 #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;
        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.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");
        (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;
                curfile.action = SKIP;
                dumptime = hdr.dumptime;
                dumpdate = hdr.dumpdate;
+               if (!bflag)
+                       newtapebuf(hdr.ntrec);
                getvol(hdr.volno);
                break;
        default:
                getvol(hdr.volno);
                break;
        default:
index c0b3810..57d941b 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #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 */
 #endif
 
 /* Copyright (c) 1983 Regents of the University of California */
@@ -40,11 +40,10 @@ setinput(source)
 #endif RRESTORE
 
        flsht();
 #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;
        terminal = stdin;
 #ifdef RRESTORE
        host = source;
@@ -80,6 +79,24 @@ nohost:
 #endif RRESTORE
 }
 
 #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.
 /*
  * 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();
        volno = 1;
        setdumpnum();
        flsht();
+       if (!pipein && !bflag)
+               findtapeblksize();
        if (gethead(&spcl) == FAIL) {
                bct--; /* push back this block */
                cvtflag++;
        if (gethead(&spcl) == FAIL) {
                bct--; /* push back this block */
                cvtflag++;
@@ -572,77 +591,110 @@ readtape(b)
        long rd, newvol;
        int cnt;
 
        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
 #ifdef RRESTORE
-               i = rmtread(&tbf[rd], cnt);
+       i = rmtread(&tbf[rd], cnt);
 #else
 #else
-               i = read(mt, &tbf[rd], cnt);
+       i = read(mt, &tbf[rd], cnt);
 #endif
 #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;
                        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
 #ifdef RRESTORE
-                       if (rmtseek(i, 1) < 0)
+               if (rmtseek(i, 1) < 0)
 #else
 #else
-                       if (lseek(mt, i, 1) == (long)-1)
+               if (lseek(mt, i, 1) == (long)-1)
 #endif
 #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;
                }
                        return;
                }
+               newvol = volno + 1;
+               volno = 0;
+               getvol(newvol);
+               readtape(b);
+               return;
        }
        bcopy(&tbf[(bct++*TP_BSIZE)], b, (long)TP_BSIZE);
        blksread++;
 }
 
        }
        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()
 {
 
 flsht()
 {