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 g_fprintf(stderr, _("calling tapefd_rewind()\n"));
74 if(0 != (r = tapefd_rewind(fd))) {
78 g_fprintf(stderr, _("calling tapefd_fsf(%lld)\n"), (long long)count);
80 return tapefd_fsf(fd, count);
89 g_fprintf(stderr, _("calling tapefd_fsf(%lld)\n"), (long long)-count);
91 return tapefd_fsf(fd, -count);
100 struct am_mt_status stat;
102 (void)count; /* Quiet unused parameter warning */
105 g_fprintf(stderr, _("calling tapefd_status()\n"));
107 if((ret = tapefd_status(fd, &stat)) != 0) {
110 g_printf(_("%s status:"), tapename);
111 if(stat.online_valid) {
113 fputs(_(" ONLINE"), stdout);
115 fputs(_(" OFFLINE"), stdout);
118 if(stat.bot_valid && stat.bot) {
119 fputs(_(" BOT"), stdout);
121 if(stat.eot_valid && stat.eot) {
122 fputs(_(" EOT"), stdout);
124 if(stat.protected_valid && stat.protected) {
125 fputs(_(" PROTECTED"), stdout);
127 if(stat.device_status_valid) {
128 g_printf(_(" ds == 0x%0*lx"),
129 stat.device_status_size * 2,
130 (unsigned long)stat.device_status);
132 if(stat.error_status_valid) {
133 g_printf(_(" er == 0x%0*lx"),
134 stat.error_status_size * 2,
135 (unsigned long)stat.error_status);
137 if(stat.fileno_valid) {
138 g_printf(_(" fileno == %ld"), stat.fileno);
140 if(stat.blkno_valid) {
141 g_printf(_(" blkno == %ld"), stat.blkno);
151 g_fprintf(stderr, _("usage: %s [-d] [-f|-t device] command [count]\n"), pgm);
169 * Configure program for internationalization:
170 * 1) Only set the message locale for now.
171 * 2) Set textdomain for all amanda related programs to "amanda"
172 * We don't want to be forced to support dozens of message catalogs.
174 setlocale(LC_MESSAGES, "C");
175 textdomain("amanda");
177 fprintf(stderr, _("ammt is deprecated\n"));
179 /* Don't die when child closes pipe */
180 signal(SIGPIPE, SIG_IGN);
182 if((pgm = strrchr(argv[0], '/')) != NULL) {
187 tapename = getenv("TAPE");
188 while(-1 != (ch = getopt(argc, argv, "df:t:"))) {
192 g_fprintf(stderr, _("debug mode!\n"));
196 tapename = stralloc(optarg);
209 * Compute the minimum abbreviation for each command.
211 for(i = 0; cmd[i].name; i++) {
212 cmd[i].min_chars = (size_t)1;
214 for(j = 0; cmd[j].name; j++) {
218 if(0 == strncmp(cmd[i].name, cmd[j].name,
223 if(0 == cmd[j].name) {
229 g_fprintf(stderr, _("syntax: %-20s -> %*.*s\n"),
231 (int)cmd[i].min_chars,
232 (int)cmd[i].min_chars,
238 * Process the command.
241 j = strlen(argv[optind]);
242 for(i = 0; cmd[i].name; i++) {
243 if(0 == strncmp(cmd[i].name, argv[optind], j)) {
244 if(j >= cmd[i].min_chars) {
250 if(0 == cmd[i].name) {
251 g_fprintf(stderr, _("%s: %s command: %s\n"), pgm, s, argv[optind]);
256 g_fprintf(stderr, _("%s: -f device or -t device is required\n"), pgm);
260 g_fprintf(stderr, _("tapename is \"%s\"\n"), tapename);
264 if(optind < argc && cmd[i].count) {
265 count = OFF_T_ATOI(argv[optind]);
269 g_fprintf(stderr, _("calling tape_open(\"%s\",%d)\n"), tapename, cmd[i].flags);
271 if((fd = tape_open(tapename, cmd[i].flags, 0)) < 0) {
276 g_fprintf(stderr, _("processing %s(%lld)\n"),
277 cmd[i].name, (long long)count);
279 if(0 != (*cmd[i].func)(fd, count)) {
283 (void)tapefd_close(fd);
290 g_fprintf(stderr, _("%s %s"), tapename, cmd[i].name);
292 g_fprintf(stderr, " %lld", (long long)count);
295 perror(_(" failed"));
296 return (1); /* exit */