Search Posts:

Program for Reading 9-track Tapes

View Entire Thread

Return to Threads

SHARE
  by Bill Degnan - 07/03/2026 17:56
Tom Hunter sent me a C program for reading 9-track tapes attached via SCSI to a linux PC. I updated it to try 5 times if the tape does not read and then physically move the tape forward a hair to try a new section of tape, assuming the tape is bad. It assumes the location of the 9-track drive in linux is called /dev/nst0. I used this program to read 800, 1600 PE and 6250 bpi tapes in an M4 9914 9-track drive.

/*
* recovertap_v2.c
*
* Tape recovery tool for problematic 9-track SCSI tape drives.
*
* Behavior:
* - Reads from /dev/nst0
* - Writes recovered data to output file
* - On read error (EIO):
* issues SCSI SPACE command via sg_raw
* retries read
* - Never exits on single read error
* - Logs all actions
*
* Compile:
* gcc -Wall -O2 recovertap_v2.c -o recovertap_v2
*
* Run:
* sudo ./recovertap_v2 output.bin
*/

/* replace the weird brackets with real ones.*/
#include 〱stdio.h>
#include 〱stdlib.h>
#include 〱unistd.h>
#include 〱fcntl.h>
#include 〱errno.h>
#include 〱string.h>
#include 〱sys/types.h>
#include 〱sys/stat.h>

#define BSIZE 32768
#define MAX_ERRORS 50

unsigned char buf[BSIZE];

void space_tape()
{
/* Fixed SPACE command we already verified works */
printf(">>> SPACE 10 records
");
system("sg_raw /dev/sg2 11 00 00 00 01 00");
}

int main(int argc, char *argv[])
{
int mt;
FILE *of;
int rc;

long records = 0;
long bytes = 0;
int errors = 0;

if (argc != 2)
{
fprintf(stderr, "Usage: %s output_file
", argv[0]);
return 1;
}

mt = open("/dev/nst0", O_RDONLY);
if (mt < 0)
{
perror("open /dev/nst0");
return 1;
}

of = fopen(argv[1], "wb");
if (!of)
{
perror("open output");
close(mt);
return 1;
}

printf("Starting recovery...
");

while (1)
{
rc = read(mt, buf, BSIZE);

if (rc > 0)
{
errors = 0;

records++;
bytes += rc;

printf("OK Record %ld (%d bytes)
", records, rc);

fwrite(buf, 1, rc, of);
fflush(of);

continue;
}

if (rc == 0)
{
printf("Tape Mark detected
");
continue;
}

/* ERROR CASE */
errors++;

printf("
*** READ ERROR #%d ***
", errors);
printf("errno: %d (%s)
", errno, strerror(errno));

if (errno != EIO)
{
printf("Non-I/O error, stopping.
");
break;
}

/* This is the key recovery mechanism */
sleep(1);
space_tape();

printf("Retrying read...

");

sleep(1);

if (errors >= MAX_ERRORS)
{
printf("Too many consecutive errors. Stopping.
");
break;
}
}

printf("
--- SUMMARY ---
");
printf("Records read : %ld
", records);
printf("Bytes read : %ld
", bytes);
printf("Errors : %d
", errors);

fclose(of);
close(mt);

return 0;
}

Reply

Resources:


Buy a Commodore Computer Poster

Popular Topics and FAQs


  • TM990/101 M
  • Altair 8800bt notes
  • TRS 80 Model 4 Engineering Sample
  • Altos 5-5AD
  • Morrow Wunderbuss Motherboard - Fried!
  • Epson PX-8
  • C64 emulator to run on PC
  • Mac 128K with SAD MAC error 041800
  • IMSAI 8080 With Processor Tech. Cutter
  • Secrecy is the keystone of all tyranny
  • Cromemco System Three
  • Commodore "Coherent"
  • Exatron Stringy Floppy Update
  • TM 990/189 or PP189
  • Lanier Word Processor Model 103
  • Univac 1219 rescue
  • IMSAI 1.4 BASIC vs. MITS 8K BASIC
  • Atari 520ST
  • DEC Information Request Reply Card
  • Amiga 2500 Restoration
  • IBM XT sn 4359455
  • Amiga 2000 with Dual Drives and HD
  • A New 68000 CPU S-100 Board
  • Edmund Scientific Co Ad 1973
  • Micropolis 10xx Drive Inventory
  • Texas Instruments 99/4a with PHP1200
  • MITS Altair 8800b T with Dual Drives
  • Burroughs L5000 Controller Card Photos
  • Digital PDP 11/44
  • TRS 80 Model III Exatron Stringy Floppy
  • Digital PDP-9 The Serious Computer
  • Live long and prosper, Spock
  • PDP 11/40 M7656 Serial Comms
  • 1993 Compaq Deskpro 5/60M
  • 1974/5 TCC-3700 i8080 Computer
  • Processor Tech 3P + S ASR 33 Jumpers
  • Tektronix 4015-1 Graphics Terminal
  • Lear Siegler ADM-3A GraFix Board
  • UNIVAC 1219 USS Midway CV-41
  • Commodore VIC-21
  • Prevent VMS MULTINET SMTP Relay Hijacks
  • NExT Cube Restoration
  • 1976 P.C.C. Features the MAI JOLT 6502
  • 1961 Beckman DEXTIR Computer
  • UNIVAC 1 and UNIVAC File Computer 1
  • Computer Music Using the IBM 7094
  • 1985 PCs Limited Turbo PC
  • Digital Equipment Corporation PDP-8
  • IMSAI 8080 Chase the Lights Variations
  • XYBASIC on the IMSAI 8080
  • Cromemco Dazzler
  • Cramer Intel 8080A Microcomputer
  • Original ACHTUNG Computer Lab Humor
  • Leading Edge Computers
  • Past Issues:


    OA S1100 Typecorder

    This image was selected at random from the archive. Click image for more photos and files from this set.