pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/sysutils/mtscan Import mtscan, a program written by Ed...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3523afc1913d
branches:  trunk
changeset: 488400:3523afc1913d
user:      agc <agc%pkgsrc.org@localhost>
date:      Sun Jan 30 11:18:48 2005 +0000

description:
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:

 sysutils/mtscan/DESCR          |    4 +
 sysutils/mtscan/Makefile       |   24 +++
 sysutils/mtscan/PLIST          |    2 +
 sysutils/mtscan/files/mtscan.c |  311 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 341 insertions(+), 0 deletions(-)

diffs (truncated from 357 to 300 lines):

diff -r 99e5a33727eb -r 3523afc1913d sysutils/mtscan/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/mtscan/DESCR     Sun Jan 30 11:18:48 2005 +0000
@@ -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 -r 99e5a33727eb -r 3523afc1913d sysutils/mtscan/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/mtscan/Makefile  Sun Jan 30 11:18:48 2005 +0000
@@ -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@localhost
+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 -r 99e5a33727eb -r 3523afc1913d sysutils/mtscan/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/mtscan/PLIST     Sun Jan 30 11:18:48 2005 +0000
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2005/01/30 11:18:48 agc Exp $
+bin/mtscan
diff -r 99e5a33727eb -r 3523afc1913d sysutils/mtscan/files/mtscan.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/mtscan/files/mtscan.c    Sun Jan 30 11:18:48 2005 +0000
@@ -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;



Home | Main Index | Thread Index | Old Index