date and time created 87/02/15 16:03:36 by lepreau
[unix-history] / usr / src / usr.bin / mt / mt.c
index d924036..ed56855 100644 (file)
@@ -1,4 +1,19 @@
-static char *sccsid = "@(#)mt.c        4.3 (Berkeley) 81/11/12";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)mt.c       5.2 (Berkeley) %G%";
+#endif not lint
+
 /*
  * mt --
  *   magnetic tape manipulation program
 /*
  * mt --
  *   magnetic tape manipulation program
@@ -10,7 +25,6 @@ static        char *sccsid = "@(#)mt.c        4.3 (Berkeley) 81/11/12";
 #include <sys/ioctl.h>
 
 #define        equal(s1,s2)    (strcmp(s1, s2) == 0)
 #include <sys/ioctl.h>
 
 #define        equal(s1,s2)    (strcmp(s1, s2) == 0)
-#define        DEFTAPE         "/dev/rmt12"
 
 struct commands {
        char *c_name;
 
 struct commands {
        char *c_name;
@@ -42,17 +56,17 @@ main(argc, argv)
        register char *cp;
        register struct commands *comp;
 
        register char *cp;
        register struct commands *comp;
 
-       if (argc < 2) {
-               fprintf(stderr, "usage: mt [ -f device ] command [ count ]\n");
-               exit(1);
-       }
-       if ((equal(argv[1], "-t") || equal(argv[1], "-f")) && argc > 2) {
+       if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) {
                argc -= 2;
                tape = argv[2];
                argv += 2;
        } else
                if ((tape = getenv("TAPE")) == NULL)
                        tape = DEFTAPE;
                argc -= 2;
                tape = argv[2];
                argv += 2;
        } else
                if ((tape = getenv("TAPE")) == NULL)
                        tape = DEFTAPE;
+       if (argc < 2) {
+               fprintf(stderr, "usage: mt [ -f device ] command [ count ]\n");
+               exit(1);
+       }
        cp = argv[1];
        for (comp = com; comp->c_name != NULL; comp++)
                if (strncmp(cp, comp->c_name, strlen(cp)) == 0)
        cp = argv[1];
        for (comp = com; comp->c_name != NULL; comp++)
                if (strncmp(cp, comp->c_name, strlen(cp)) == 0)
@@ -73,7 +87,7 @@ main(argc, argv)
                        exit(1);
                }
                if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) {
                        exit(1);
                }
                if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) {
-                       fprintf(stderr, "%s %d ", comp->c_name,
+                       fprintf(stderr, "%s %s %d ", tape, comp->c_name,
                                mt_com.mt_count);
                        perror("failed");
                        exit(2);
                                mt_com.mt_count);
                        perror("failed");
                        exit(2);
@@ -87,12 +101,24 @@ main(argc, argv)
        }
 }
 
        }
 }
 
-#include <sys/mtreg.h>
-#include <sys/utreg.h>
-#include <sys/htreg.h>
-#include <sys/tmreg.h>
+#ifdef vax
+#include <vaxmba/mtreg.h>
+#include <vaxmba/htreg.h>
+
+#include <vaxuba/utreg.h>
+#include <vaxuba/tmreg.h>
 #undef b_repcnt                /* argh */
 #undef b_repcnt                /* argh */
-#include <sys/tsreg.h>
+#include <vaxuba/tsreg.h>
+#endif
+
+#ifdef sun
+#include <sundev/tmreg.h>
+#include <sundev/arreg.h>
+#endif
+
+#ifdef tahoe
+#include <tahoevba/cyreg.h>
+#endif
 
 struct tape_desc {
        short   t_type;         /* type of magtape device */
 
 struct tape_desc {
        short   t_type;         /* type of magtape device */
@@ -100,11 +126,20 @@ struct tape_desc {
        char    *t_dsbits;      /* "drive status" register */
        char    *t_erbits;      /* "error" register */
 } tapes[] = {
        char    *t_dsbits;      /* "drive status" register */
        char    *t_erbits;      /* "error" register */
 } tapes[] = {
+#ifdef vax
        { MT_ISTS,      "ts11",         0,              TSXS0_BITS },
        { MT_ISHT,      "tm03",         HTDS_BITS,      HTER_BITS },
        { MT_ISTM,      "tm11",         0,              TMER_BITS },
        { MT_ISMT,      "tu78",         MTDS_BITS,      0 },
        { MT_ISUT,      "tu45",         UTDS_BITS,      UTER_BITS },
        { MT_ISTS,      "ts11",         0,              TSXS0_BITS },
        { MT_ISHT,      "tm03",         HTDS_BITS,      HTER_BITS },
        { MT_ISTM,      "tm11",         0,              TMER_BITS },
        { MT_ISMT,      "tu78",         MTDS_BITS,      0 },
        { MT_ISUT,      "tu45",         UTDS_BITS,      UTER_BITS },
+#endif
+#ifdef sun
+       { MT_ISCPC,     "TapeMaster",   TMS_BITS,       0 },
+       { MT_ISAR,      "Archive",      ARCH_CTRL_BITS, ARCH_BITS },
+#endif
+#ifdef tahoe
+       { MT_ISCY,      "cipher",       CYS_BITS,       CYCW_BITS },
+#endif
        { 0 }
 };
 
        { 0 }
 };
 
@@ -123,23 +158,28 @@ status(bp)
                printf("unknown tape drive type (%d)\n", bp->mt_type);
                return;
        }
                printf("unknown tape drive type (%d)\n", bp->mt_type);
                return;
        }
-       printf("%s tape drive\n", mt->t_name);
+       printf("%s tape drive, residual=%d\n", mt->t_name, bp->mt_resid);
        printreg("ds", bp->mt_dsreg, mt->t_dsbits);
        printreg("ds", bp->mt_dsreg, mt->t_dsbits);
-       printreg(" er", bp->mt_erreg, mt->t_erbits);
-       printf("\nresidual=%d\n", bp->mt_resid);
+       printreg("\ner", bp->mt_erreg, mt->t_erbits);
+       putchar('\n');
 }
 
 /*
  * Print a register a la the %b format of the kernel's printf
  */
 printreg(s, v, bits)
 }
 
 /*
  * Print a register a la the %b format of the kernel's printf
  */
 printreg(s, v, bits)
-       char *s, *bits;
-       unsigned short v;
+       char *s;
+       register char *bits;
+       register unsigned short v;
 {
        register int i, any = 0;
        register char c;
 
 {
        register int i, any = 0;
        register char c;
 
-       printf("%s=%o", s, v);
+       if (bits && *bits == 8)
+               printf("%s=%o", s, v);
+       else
+               printf("%s=%x", s, v);
+       bits++;
        if (v && bits) {
                putchar('<');
                while (i = *bits++) {
        if (v && bits) {
                putchar('<');
                while (i = *bits++) {
@@ -153,7 +193,6 @@ printreg(s, v, bits)
                                for (; *bits > 32; bits++)
                                        ;
                }
                                for (; *bits > 32; bits++)
                                        ;
                }
-               if (any)
-                       putchar('>');
+               putchar('>');
        }
 }
        }
 }