+/*
+ * Read the first block and get the blocksize from it. Test
+ * for a compressed dump tape/file. setup() will make the final
+ * determination by checking the compressed flag if gethead()
+ * finds a valid header. The test here is necessary to offset the buffer
+ * by the size of the compressed prefix. zflag is set here so that
+ * readtape_set can set the correct function pointer for readtape().
+ * Note that the first block of each tape/file is not compressed
+ * and does not have a prefix.
+ */
+static void
+findtapeblksize(void)
+{
+ long i;
+ size_t len;
+ struct tapebuf *tpb = (struct tapebuf *) tapebuf;
+ struct s_spcl *spclpt = (struct s_spcl *) tapebuf;
+
+ for (i = 0; i < ntrec; i++)
+ ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
+ blkcnt = 0;
+ tbufptr = tapebuf;
+ /*
+ * For a pipe or file, read in the first record. For a tape, read
+ * the first block.
+ */
+ len = magtapein ? ntrec * TP_BSIZE : TP_BSIZE;
+
+ if (read_a_block(mt, tapebuf, len, &i) <= 0)
+ errx(1, "Tape read error on first record");
+
+ /*
+ * If the input is from a file or a pipe, we read TP_BSIZE
+ * bytes looking for a dump header. If the dump is compressed
+ * we need to read in the rest of the block, as determined
+ * by c_ntrec in the dump header. The first block of the
+ * dump is not compressed and does not have a prefix.
+ */
+ if (!magtapein) {
+ if (spclpt->c_type == TS_TAPE
+ && spclpt->c_flags & DR_COMPRESSED) {
+ /* It's a compressed dump file, read in the */
+ /* rest of the block based on spclpt->c_ntrec. */
+ if (spclpt->c_ntrec > ntrec)
+ errx(1, "Tape blocksize is too large, use "
+ "\'-b %d\' ", spclpt->c_ntrec);
+ ntrec = spclpt->c_ntrec;
+ len = (ntrec - 1) * TP_BSIZE;
+ zflag = 1;
+ }
+ 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 && i % TP_BSIZE != 0))
+ errx(1,"Error reading dump file header");
+ tbufptr = tapebuf;
+ numtrec = ntrec;
+ Vprintf(stdout, "Input block size is %ld\n", ntrec);
+ return;
+ } /* if (!magtapein) */
+
+ /*
+ * If the input is a tape, we tried to read ntrec * TP_BSIZE bytes.
+ * If the value of ntrec is too large, we read less than
+ * what we asked for; adjust the value of ntrec and test for
+ * a compressed dump tape.
+ */
+
+ if (i % TP_BSIZE != 0) {
+ /* may be old format compressed dump tape with a prefix */
+ spclpt = (struct s_spcl *) tpb->buf;
+ if (i % TP_BSIZE == PREFIXSIZE
+ && tpb->compressed == 0
+ && spclpt->c_type == TS_TAPE
+ && spclpt->c_flags & DR_COMPRESSED) {
+ zflag = 1;
+ tbufptr = tpb->buf;
+ if (tpb->length > bufsize)
+ errx(1, "Tape blocksize is too large, use "
+ "\'-b %d\' ", tpb->length / TP_BSIZE);
+ }
+ else
+ errx(1, "Tape block size (%ld) is not a multiple of dump block size (%d)",
+ i, TP_BSIZE);
+ }