lmc@denelcor.UUCP (09/03/84)
This program will display the format of any tape, giving the record and files sizes. See the manual page. ------------------------------------------------------------------------- : This is a shar archieve. Extract with sh, not csh. : The rest of this file will extract: : ts.l ts.c echo extracting - ts.l sed 's/^X//' > ts.l << 'FUNKYSTUFF' X.TH TS 1 "20 Aug 1984" X.UC 4 X.SH NAME Xts \- tape format synopsis X.SH SYNOPSIS X.B ts X[ X.B \-1...15 X] X.br X.SH DESCRIPTION X.I Ts Xwill read a tape mounted on the Xspecified tape drive an display Xa synopsis of the files and record Xstructure of the tape. The tape Xdrive used is /dev/rmtX, where X Xis specified by the option. Default Xis to /dev/rmt0. X.PP XThe format of the display is: X.nf X.sp X file 0: X Records 0 through 2 (3 records), length = 512 X file 1: X Records 0 through 0 (1 records), length = 512 X Records 1 through 20 (20 records), length = 10240 X End of tape reached. X.sp X.fi XThe signal SIGINT is caught by X.I ts Xand the report is flushed up to the Xlast block read, then X.I ts Xaborts. X.SH DIAGNOSTICS XThe usual usage diagnostic and Xothers for cannot open and tape Xread errors. X.PP XExit status is 0 normally, 1 for Xusage error, 2 for tape read error, Xand 3 for SIGINT caught. X.SH DEFINES X.I MAXBUF Xdefines the maximum size of a tape Xblock. Default at 16000 works with X4.2bsd and S3 on an 11/44. X.SH AUTHOR XLyle McElhaney FUNKYSTUFF echo extracting - ts.c sed 's/^X//' > ts.c << 'FUNKYSTUFF' X/* X * ts - This program outputs a file/record description of a tape's X * structure. X * X * Exits: 0 - normal. X * 1 - usage error. X * 2 - tape read error. X * 3 - SIGINT received. X * X * Copyright (C) 1983, 1984 Lyle McElhaney X * Permission to copy for non-commercial use granted under condition X * that this notice remains intact in the copy. X * X * Address: 2489 W. Ridge Rd., Littleton, CO 80120 X * ....denelcor!lmc X */ X#include <stdio.h> X#include <signal.h> X X#define MAXBUF=16000 X/* This can be whatever maximum the machine/os will take. X * 16000 is allowed on an 11/44 running System 3 Unix (tm). X */ X X#ifndef YES X#define YES 1 X#define NO 0 X#endif X Xchar tape[]="/dev/rmt0\0\0"; Xchar buff[MAXBUF]; XFILE *tapedev; Xlong recno, nrec, fsize, filen; Xextern void sig(); X Xmain (argc, argv) X int argc; X char **argv; X{ X char *p; X int n; X X argv++; X if (argc > 1) { X p = *argv; X if (*p == '-') { X p++; X while (*p != '\0') { X switch (*p++) { X case '2': X case '3': X case '4': X case '5': X case '6': X case '7': X case '8': X case '9': X case '0': X tape[8] = *(p-1); X break; X case '1': X tape[8] = '1'; X if (*p >= '0' && *p <= '5') X tape[9] = *p++; X break; X default: XUsage: X fprintf (stderr, "Usage: ts [-0...15]\n"); X exit (2); X } X } X argc--; X argv++; X } X else goto Usage; X } X X signal (SIGINT, sig); X if ((tapedev = fopen (tape, "r")) == NULL) { X fprintf (stderr, "ts: cannot open %s\n", tape); X exit (2); X } X X filen = 0; X for (;;) { X recno = nrec = 0; X for (;;) { X n = read (fileno (tapedev), buff, sizeof buff); X if (n > 0) { X if (recno == 0) X printf ("File %ld:\n", filen); X else { X if (n != fsize) { X if (recno != 0) X printf (" Records %ld through %ld (%ld records), length = %ld bytes\n", X nrec, recno-1, recno - nrec, n); X nrec = recno; X } X } X fsize = n; X recno ++; X } else goto Out; X } XOut: if (n == 0) { X if (recno != 0) X printf (" Records %ld through %ld (%ld records), length = %ld bytes\n", X nrec, recno-1, recno - nrec, fsize); X } else { X printf ("Tape read error %d in record %ld\n", n, recno); X exit (1); X } X if (recno == 0) break; X filen ++; X } X printf ("End of tape reached.\n"); X fclose (tapedev); X exit (0); X} X Xvoid sig () X{ X printf (" Records %ld through %ld (%ld records), length = %ld bytes\n", X nrec, recno-1, recno - nrec, fsize); X printf ("ts: aborted by interrupt at that point.\n"); X close (tapedev); X exit (3); X} FUNKYSTUFF -- Lyle McElhaney (hao,brl-bmd,nbires,csu-cs,scgvaxd)!denelcor!lmc