diff options
author | agc <agc@pkgsrc.org> | 2005-01-30 11:18:48 +0000 |
---|---|---|
committer | agc <agc@pkgsrc.org> | 2005-01-30 11:18:48 +0000 |
commit | 13883b168bf824fcc4c1687158bf72415260dd17 (patch) | |
tree | c9e80f6feb519a6732a07802ffbd3d685522c0e2 /sysutils | |
parent | fb83ce3406e84d26c957ee819f3dc469478f5187 (diff) | |
download | pkgsrc-13883b168bf824fcc4c1687158bf72415260dd17.tar.gz |
Import mtscan, a program written by Ed Gould, to scan a magtape and report
the record and file-mark structure, into the Packages Collection.
Made available by Ed in:
http://mail-index.netbsd.org/port-i386/2005/01/29/0011.html
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/mtscan/DESCR | 4 | ||||
-rw-r--r-- | sysutils/mtscan/Makefile | 24 | ||||
-rw-r--r-- | sysutils/mtscan/PLIST | 2 | ||||
-rw-r--r-- | sysutils/mtscan/files/mtscan.c | 311 |
4 files changed, 341 insertions, 0 deletions
diff --git a/sysutils/mtscan/DESCR b/sysutils/mtscan/DESCR new file mode 100644 index 00000000000..11d810b8451 --- /dev/null +++ b/sysutils/mtscan/DESCR @@ -0,0 +1,4 @@ +mtscan was written by Ed Gould, and scans a magtape, reporting the +record and file-mark structure it finds. + +If the tape has data stored after a double-EOF, run with the -F flag. diff --git a/sysutils/mtscan/Makefile b/sysutils/mtscan/Makefile new file mode 100644 index 00000000000..e882e2cbfd7 --- /dev/null +++ b/sysutils/mtscan/Makefile @@ -0,0 +1,24 @@ +# $NetBSD: Makefile,v 1.1.1.1 2005/01/30 11:18:48 agc Exp $ + +DISTNAME= mtscan-20050129 +CATEGORIES= sysutils +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= tech-pkg@NetBSD.org +HOMEPAGE= http://mail-index.netbsd.org/port-i386/2005/01/29/0011.html +COMMENT= Magtape scanner - reports record and file-mark structure + +NO_BUILDLINK= # defined +NO_CHECKSUM= # defined + +do-extract: + ${CP} -R ${FILESDIR} ${WRKSRC} + +do-build: + cd ${WRKSRC} && ${CC} -O2 -DMTIO -o mtscan mtscan.c -ltermcap + +do-install: + ${INSTALL_PROGRAM} ${WRKSRC}/mtscan ${PREFIX}/bin + +.include "../../mk/bsd.pkg.mk" diff --git a/sysutils/mtscan/PLIST b/sysutils/mtscan/PLIST new file mode 100644 index 00000000000..080a3aee950 --- /dev/null +++ b/sysutils/mtscan/PLIST @@ -0,0 +1,2 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2005/01/30 11:18:48 agc Exp $ +bin/mtscan diff --git a/sysutils/mtscan/files/mtscan.c b/sysutils/mtscan/files/mtscan.c new file mode 100644 index 00000000000..8ebc5095eef --- /dev/null +++ b/sysutils/mtscan/files/mtscan.c @@ -0,0 +1,311 @@ +/* + * mtscan - scan a mag tape for record structure + */ + +#include <stdlib.h> + +#include <stdio.h> +#include <signal.h> +#include <errno.h> +#include <sys/file.h> + +#if MACH +#include <mach.h> +#endif + +#ifdef MTIO +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/mtio.h> +#endif + +#if i386 && !defined(BIGBUFFERS) +#define BUFLEN (32L * 1024L) +#else +#define BUFLEN (64L * 1024L) +#endif + +#define MAXBUF (256L * 1024L) + +#define BIG 5000 + +const char *tape = "/dev/rst0"; +char *buf; +int files = 1; +long buflen = BUFLEN; +int big = BIG; +int quiet = 0; +char termcap[1024]; + +char *backspace(int); +void done(int); + +extern int tgetent(char *, char *); +extern int tgetflag(char *); + +#define qprintf if(!quiet) printf + +int +main( + int argc, + char * const *argv +) { + int i; + int n; + int mt; + int eflag = 0; + int fflag = 0; + int hardcopy = 1; + int previous; + int repeat = 0; + int first; + int preveof = 0; + int nfiles = 0; + long nrec = 1000000L; + long count = 0; + char *term; + extern int optind; + extern char *optarg; +#ifdef MTIO + int rewind = 0; + int rewindafter = 0; + int unload = 0; + int unload_err = 0; + struct mtop mtop; +#endif + + if(isatty(fileno(stdout)) && (term = getenv("TERM")) != NULL && + tgetent(termcap, term) > 0) + hardcopy = tgetflag("hc"); + while((i = getopt(argc, argv, "B:b:eFf:hn:qrsUu")) != -1) { + switch(i) { + + case 'B': + big = atoi(optarg); + break; + + case 'b': + buflen = atol(optarg); + if(buflen > MAXBUF) { + fprintf(stderr, + "Buffer (%ld) too big, set to %ld\n", + buflen, MAXBUF); + buflen = MAXBUF; + } + break; + + case 'e': + eflag++; + break; + + case 'F': + fflag++; + break; + + case 'f': + nfiles = atoi(optarg); + break; + + case 'h': + hardcopy++; + break; + + case 'n': + nrec = atol(optarg); + break; + + case 'q': + quiet++; + break; + + case 's': + hardcopy = 0; + break; + +#ifdef MTIO + case 'R': + rewindafter++; + break; + + case 'r': + rewind++; + break; + + case 'U': + unload_err++; + break; + + case 'u': + unload++; + break; +#endif + + case '?': + default: + fprintf(stderr, "unknown flag '%c'\n", i); + exit(1); + } + } +#if MACH + if(vm_allocate(task_self(), (vm_address_t *)&buf, buflen, 1) != + KERN_SUCCESS) { + perror("vm_allocate"); + exit(1); + } +#else + buf = malloc(buflen); + if(buf == NULL) { + perror("no memory"); + exit(1); + } +#endif + if(optind < argc) + tape = argv[optind++]; + mt = open(tape, O_RDONLY, 0); + if(mt < 0) { + perror(tape); + exit(1); + } +#ifdef MTIO + if(rewind) { + bzero(&mtop, sizeof(mtop)); + mtop.mt_op = MTREW; + if(ioctl(mt, MTIOCTOP, &mtop) < 0) { + perror("MTIOCTOP rewind"); + exit(1); + } + } + if(optind < argc) { + bzero(&mtop, sizeof(mtop)); + mtop.mt_op = MTFSF; + mtop.mt_count = atoi(argv[optind++]); + files += mtop.mt_count; + if(ioctl(mt, MTIOCTOP, &mtop) < 0) { + perror("MTIOCTOP skip files"); + exit(1); + } + } +#endif + if(optind < argc) { + fprintf(stderr, "arg count\n"); + exit(1); + } + signal(SIGINT, done); + i = 0; + previous = -1; + first = 1; + while(count < nrec) { + n = read(mt, buf, buflen); + i++; + count++; + if(n != previous) { + if(repeat > 0) { + qprintf(" \r same through record %d\n", + i-1); + fflush(stdout); + } + repeat = 0; + first = 1; + previous = -1; + } + if(n < 0) { + if(repeat > 0) + qprintf("\n"); + qprintf("error record %d", i); + if(eflag) { + qprintf(" ignored\n"); + fflush(stdout); + repeat = 0; + first = 1; + previous = -1; + continue; + } else { + qprintf("\n"); + fflush(stdout); + break; + } + } + if(n == 0) { + if(repeat > 0) + qprintf("\n"); + qprintf("End of file %d\n", files); + fflush(stdout); + i = 0; + previous = -1; + repeat = 0; + if(preveof && !fflag) + break; + if(nfiles && (files >= nfiles)) + break; + files++; + } else { + if(n == previous) { + repeat++; + if((n > big || i%10 == 0) && !hardcopy) { + if(first) { + qprintf(" same through record "); + first = 0; + } + qprintf("%d%s", i, backspace(i)); + } + } else + qprintf("record %d is length %d\n", i, n); + fflush(stdout); + previous = n; + } + preveof = n==0; + } + qprintf("\n\n%d file%s read.\n", files, files==1?"":"s"); +#ifdef MTIO + if(rewindafter) { + bzero(&mtop, sizeof(mtop)); + mtop.mt_op = MTREW; + if(ioctl(mt, MTIOCTOP, &mtop) < 0) { + perror("MTIOCTOP rewind after"); + exit(1); + } + } + if(unload) { + bzero(&mtop, sizeof(mtop)); + mtop.mt_op = MTOFFL; + if(ioctl(mt, MTIOCTOP, &mtop) < 0) { + perror("MTIOCTOP offline"); + exit(1); + } + } +#endif + if(nfiles && (files != nfiles)) { + if(unload_err) { + bzero(&mtop, sizeof(mtop)); + mtop.mt_op = MTOFFL; + if(ioctl(mt, MTIOCTOP, &mtop) < 0) { + perror("MTIOCTOP offline after error"); + exit(1); + } + } + return(1); + } + return(0); +} + +char * +backspace(int n) { + static char bs[32]; + int log10; + + for(log10 = 0; n; n /= 10) + log10++; + bs[log10] = '\0'; + while(log10-- > 0) + bs[log10] = '\010'; + return(bs); +} + +void +done(int s) { + if(s) + qprintf("\nInterrupted.\n"); + qprintf("\n\n%d file%s read.\n", files, files==1?"":"s"); + fflush(stdout); + exit(s); +} |