Converting .tap files to real tapes

From: Christopher McNabb <cmcnabb_at_4mcnabb.net>
Date: Thu Feb 27 17:55:01 2003

I've hacked together a 2.11 BSD C program (nothing special, should work
on other *nixen) that takes a .tap tape file and spits it onto a real
tape. I've tested it with both a TK50 and a TS05 tape drive. It even
successfully wrote a bootable TK50 format XXDP 2.5 tape. I'm going to
be cleaning up the code and posting it on the web, but for those who
can't wait, here is the raw code. It is left as an exercise to the
reader to figure out where my MUA breaks the source code lines.

------------ Cut Here --------------------
/* detap.c - 2003 by Christopher L McNabb */

#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/inode.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>

main(argc, argv)
int argc;
char *argv[];
{
        int infile,outfile,ctr;
        long int offset;
        long int records=1;
        long int filecnt=1;
        long int reclen;
        long int reclen2;
        void* buffer;
        struct mtop tapeeof,taperew;

        ctr = 0;
        taperew.mt_op = MTREW;
        taperew.mt_count = 1;
        tapeeof.mt_op = MTWEOF;
        tapeeof.mt_count = 1;
        if(argc < 3)
        {
                printf("Usage: %s infile outdev\n",argv[0]);
                exit(-1);
        }
        infile=open(argv[1],O_RDONLY);
        if(infile < 0)
        {
                printf("Could not open %s\n",argv[1]);
                exit(-1);
        }
        outfile=open(argv[2],O_CREAT | O_RDWR | O_TRUNC,IREAD | IWRITE);
        if(outfile < 0)
        {
                printf("Could not open %s\n",argv[2]);
                exit(-1);
        }
        printf("Rewinding Tape\n");
        if( 0 > ioctl(outfile,MTIOCTOP,&taperew))
        {
                printf("\nMTIOCOP REW ERROR\n");
                exit(-1);
        }
        offset = 0;
        read(infile,&reclen,4);
        while(1)
        {
                ctr ++;
                if(reclen == 0)
                {
                        filecnt++;
                        if(0 > ioctl(outfile,MTIOCTOP,&tapeeof))
                        {
                                printf("\nMTIOCTOP EOF ERR\n");
                                exit(-1);
                        }
                        read(infile,&reclen,4);
                        if(reclen == 0)
                        {
                                printf("\nEnd of Tape\n");
                                close(outfile);
                                ioctl(outfile,MTIOCTOP,&taperew);
                                break;
                        }
                        records=1;
                        continue;
                }
                buffer = malloc(reclen);
                read(infile,buffer,reclen);
                read(infile,&reclen2,4);
                if(reclen != reclen2)
                {
                        lseek(infile,-3,L_INCR);
                        read(infile,&reclen2,4);
                        if(reclen != reclen2)
                        {
                                printf("\nHdr1 and Hdr2 do not match\n");
                                exit(-1);
                        }
                }
                write(outfile,buffer,reclen);
                fprintf(stdout,"Total Records: %6d File: %6ld Record: %6ld Record
Length: %6u\r",ctr,filecnt,records,reclen);
                fflush(stdout);
                free(buffer);
                records++;
                read(infile,&reclen,4);
        }
        close(infile);
        close(outfile);
}

------------------- SNIP --------------------------
-- 
Christopher L McNabb
Operating Systems Analyst         Email: cmcnabb_at_4mcnabb.net
Virginia Tech                     ICBM:  37.1356N 80.4272N
GMRS: WPSR255                     ARS:   N2UX  Grid Sq: EM97SD
Received on Thu Feb 27 2003 - 17:55:01 GMT

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:35:57 BST