Implement suggestion from Adam Slattery, (don't default to killing closing bug #1190.
[oweals/busybox.git] / mt.c
diff --git a/mt.c b/mt.c
index cd926272e9c4c1719529d526da0a80898bb3d20b..49dc70ac61e9610a9d6f6ff65c9e3a1c5218cabf 100644 (file)
--- a/mt.c
+++ b/mt.c
@@ -35,7 +35,7 @@ static const struct mt_opcodes opcodes[] = {
        {"ras3", MTRAS3},
        {"reset", MTRESET},
        {"retension", MTRETEN},
-       {"rew", MTREW},
+       {"rewind", MTREW},
        {"seek", MTSEEK},
        {"setblk", MTSETBLK},
        {"setdensity", MTSETDENSITY},
@@ -55,6 +55,7 @@ extern int mt_main(int argc, char **argv)
        const char *file = "/dev/tape";
        const struct mt_opcodes *code = opcodes;
        struct mtop op;
+       struct mtpos position;
        int fd, mode;
        
        if (argc < 2) {
@@ -103,8 +104,18 @@ extern int mt_main(int argc, char **argv)
        if ((fd = open(file, mode, 0)) < 0)
                perror_msg_and_die("%s", file);
 
-       if (ioctl(fd, MTIOCTOP, &op) != 0)
-               perror_msg_and_die("%s", file);
+       switch (code->value) {
+               case MTTELL:
+                       if (ioctl(fd, MTIOCPOS, &position) < 0)
+                               perror_msg_and_die("%s", file);
+                       printf ("At block %d.\n", (int) position.mt_blkno);
+                       break;
+
+               default:
+                       if (ioctl(fd, MTIOCTOP, &op) != 0)
+                               perror_msg_and_die("%s", file);
+                       break;
+       }
 
        return EXIT_SUCCESS;
 }