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
34 static int do_status();
43 { "eof", 0, 1, tapefd_weof, O_RDWR },
44 { "weof", 0, 1, tapefd_weof, O_RDWR },
45 { "fsf", 0, 1, tapefd_fsf, O_RDONLY },
46 { "asf", 0, 0, do_asf, O_RDONLY },
47 { "bsf", 0, 1, do_bsf, O_RDONLY },
48 { "rewind", 0, 0, tapefd_rewind, O_RDONLY },
49 { "offline", 0, 0, tapefd_unload, O_RDONLY },
50 { "rewoffl", 0, 0, tapefd_unload, O_RDONLY },
51 { "status", 0, 0, do_status, O_RDONLY },
56 static int debug_ammt = 0;
58 static char *tapename;
68 fprintf(stderr, "calling tapefd_rewind()\n");
70 if(0 != (r = tapefd_rewind(fd))) {
74 fprintf(stderr, "calling tapefd_fsf(%d)\n", count);
76 return tapefd_fsf(fd, count);
85 fprintf(stderr, "calling tapefd_fsf(%d)\n", -count);
87 return tapefd_fsf(fd, -count);
96 struct am_mt_status stat;
99 fprintf(stderr, "calling tapefd_status()\n");
101 if((ret = tapefd_status(fd, &stat)) != 0) {
104 printf("%s status:", tapename);
105 if(stat.online_valid) {
107 fputs(" ONLINE", stdout);
109 fputs(" OFFLINE", stdout);
112 if(stat.bot_valid && stat.bot) {
113 fputs(" BOT", stdout);
115 if(stat.eot_valid && stat.eot) {
116 fputs(" EOT", stdout);
118 if(stat.protected_valid && stat.protected) {
119 fputs(" PROTECTED", stdout);
121 if(stat.device_status_valid) {
122 printf(" ds == 0x%0*lx",
123 stat.device_status_size * 2,
124 (unsigned long)stat.device_status);
126 if(stat.error_status_valid) {
127 printf(" er == 0x%0*lx",
128 stat.error_status_size * 2,
129 (unsigned long)stat.error_status);
131 if(stat.fileno_valid) {
132 printf(" fileno == %ld", stat.fileno);
134 if(stat.blkno_valid) {
135 printf(" blkno == %ld", stat.blkno);
145 fprintf(stderr, "usage: %s [-d] [-f|-t device] command [count]\n", pgm);
150 main(int argc, char **argv) {
159 if((pgm = strrchr(argv[0], '/')) != NULL) {
164 tapename = getenv("TAPE");
165 while(-1 != (ch = getopt(argc, argv, "df:t:"))) {
169 fprintf(stderr, "debug mode!\n");
173 tapename = stralloc(optarg);
186 * Compute the minimum abbreviation for each command.
188 for(i = 0; cmd[i].name; i++) {
189 cmd[i].min_chars = 1;
191 for(j = 0; cmd[j].name; j++) {
195 if(0 == strncmp(cmd[i].name, cmd[j].name, cmd[i].min_chars)) {
199 if(0 == cmd[j].name) {
205 fprintf(stderr, "syntax: %-20s -> %*.*s\n",
214 * Process the command.
217 j = strlen(argv[optind]);
218 for(i = 0; cmd[i].name; i++) {
219 if(0 == strncmp(cmd[i].name, argv[optind], j)) {
220 if(j >= cmd[i].min_chars) {
226 if(0 == cmd[i].name) {
227 fprintf(stderr, "%s: %s command: %s\n", pgm, s, argv[optind]);
232 fprintf(stderr, "%s: -f device or -t device is required\n", pgm);
236 fprintf(stderr, "tapename is \"%s\"\n", tapename);
240 if(optind < argc && cmd[i].count) {
241 count = atoi(argv[optind]);
245 fprintf(stderr, "calling tape_open(\"%s\",%d)\n", tapename, cmd[i].flags);
247 if((fd = tape_open(tapename, cmd[i].flags)) < 0) {
252 fprintf(stderr, "processing %s(%d)\n", cmd[i].name, count);
254 if(0 != (*cmd[i].func)(fd, count)) {
258 (void)tapefd_close(fd);
265 fprintf(stderr, "%s %s", tapename, cmd[i].name);
267 fprintf(stderr, " %d", count);