10 #include "output-rait.h"
12 extern char *getenv();
14 #define tape_open rait_open
15 #define tapefd_read rait_read
16 #define tapefd_write rait_write
17 #define tapefd_fsf rait_tapefd_fsf
18 #define tapefd_rewind rait_tapefd_rewind
19 #define tapefd_status rait_tapefd_status
20 #define tapefd_unload rait_tapefd_unload
21 #define tapefd_weof rait_tapefd_weof
22 #define tapefd_setinfo_length(outfd, length)
23 #define tapefd_close rait_close
32 static int do_asf(int fd, off_t count);
33 static int do_bsf(int fd, off_t count);
34 static int do_status(int fd, off_t count);
35 static void usage(void);
41 int (*func)(int, off_t);
44 { "eof", 0, 1, tapefd_weof, O_RDWR },
45 { "weof", 0, 1, tapefd_weof, O_RDWR },
46 { "fsf", 0, 1, tapefd_fsf, O_RDONLY },
47 { "asf", 0, 0, do_asf, O_RDONLY },
48 { "bsf", 0, 1, do_bsf, O_RDONLY },
49 { "rewind", 0, 0, (int (*)(int, off_t))tapefd_rewind,
51 { "offline", 0, 0, (int (*)(int, off_t))tapefd_unload,
53 { "rewoffl", 0, 0, (int (*)(int, off_t))tapefd_unload,
55 { "status", 0, 0, do_status, O_RDONLY },
56 { NULL, 0, 0, NULL, 0 }
60 static int debug_ammt = 0;
62 static char *tapename;
72 fprintf(stderr, "calling tapefd_rewind()\n");
74 if(0 != (r = tapefd_rewind(fd))) {
78 fprintf(stderr, "calling tapefd_fsf(" OFF_T_FMT ")\n",
79 (OFF_T_FMT_TYPE)count);
81 return tapefd_fsf(fd, count);
90 fprintf(stderr, "calling tapefd_fsf(" OFF_T_FMT ")\n",
91 (OFF_T_FMT_TYPE)-count);
93 return tapefd_fsf(fd, -count);
102 struct am_mt_status stat;
104 (void)count; /* Quiet unused parameter warning */
107 fprintf(stderr, "calling tapefd_status()\n");
109 if((ret = tapefd_status(fd, &stat)) != 0) {
112 printf("%s status:", tapename);
113 if(stat.online_valid) {
115 fputs(" ONLINE", stdout);
117 fputs(" OFFLINE", stdout);
120 if(stat.bot_valid && stat.bot) {
121 fputs(" BOT", stdout);
123 if(stat.eot_valid && stat.eot) {
124 fputs(" EOT", stdout);
126 if(stat.protected_valid && stat.protected) {
127 fputs(" PROTECTED", stdout);
129 if(stat.device_status_valid) {
130 printf(" ds == 0x%0*lx",
131 stat.device_status_size * 2,
132 (unsigned long)stat.device_status);
134 if(stat.error_status_valid) {
135 printf(" er == 0x%0*lx",
136 stat.error_status_size * 2,
137 (unsigned long)stat.error_status);
139 if(stat.fileno_valid) {
140 printf(" fileno == %ld", stat.fileno);
142 if(stat.blkno_valid) {
143 printf(" blkno == %ld", stat.blkno);
153 fprintf(stderr, "usage: %s [-d] [-f|-t device] command [count]\n", pgm);
170 /* Don't die when child closes pipe */
171 signal(SIGPIPE, SIG_IGN);
173 if((pgm = strrchr(argv[0], '/')) != NULL) {
178 tapename = getenv("TAPE");
179 while(-1 != (ch = getopt(argc, argv, "df:t:"))) {
183 fprintf(stderr, "debug mode!\n");
187 tapename = stralloc(optarg);
200 * Compute the minimum abbreviation for each command.
202 for(i = 0; cmd[i].name; i++) {
203 cmd[i].min_chars = (size_t)1;
205 for(j = 0; cmd[j].name; j++) {
209 if(0 == strncmp(cmd[i].name, cmd[j].name,
214 if(0 == cmd[j].name) {
220 fprintf(stderr, "syntax: %-20s -> %*.*s\n",
222 (int)cmd[i].min_chars,
223 (int)cmd[i].min_chars,
229 * Process the command.
232 j = strlen(argv[optind]);
233 for(i = 0; cmd[i].name; i++) {
234 if(0 == strncmp(cmd[i].name, argv[optind], j)) {
235 if(j >= cmd[i].min_chars) {
241 if(0 == cmd[i].name) {
242 fprintf(stderr, "%s: %s command: %s\n", pgm, s, argv[optind]);
247 fprintf(stderr, "%s: -f device or -t device is required\n", pgm);
251 fprintf(stderr, "tapename is \"%s\"\n", tapename);
255 if(optind < argc && cmd[i].count) {
256 count = OFF_T_ATOI(argv[optind]);
260 fprintf(stderr, "calling tape_open(\"%s\",%d)\n", tapename, cmd[i].flags);
262 if((fd = tape_open(tapename, cmd[i].flags, 0)) < 0) {
267 fprintf(stderr, "processing %s(" OFF_T_FMT ")\n",
268 cmd[i].name, (OFF_T_FMT_TYPE)count);
270 if(0 != (*cmd[i].func)(fd, count)) {
274 (void)tapefd_close(fd);
281 fprintf(stderr, "%s %s", tapename, cmd[i].name);
283 fprintf(stderr, " " OFF_T_FMT, (OFF_T_FMT_TYPE)count);
287 return (1); /* exit */