- if (ioctl(fd, MTIOCTOP, &op) != 0)
- perror_msg_and_die("%s", file);
+ default:
+ mode = O_RDONLY;
+ break;
+ }
+
+ fd = bb_xopen3(file, mode, 0);
+
+ switch (code->value) {
+ case MTTELL:
+ if (ioctl(fd, MTIOCPOS, &position) < 0)
+ bb_perror_msg_and_die("%s", file);
+ printf ("At block %d.\n", (int) position.mt_blkno);
+ break;
+
+ default:
+ if (ioctl(fd, MTIOCTOP, &op) != 0)
+ bb_perror_msg_and_die("%s", file);
+ break;
+ }