30 size =
sizeof(buffer);
34 printf(
"End of tape reached.\n");
38 printf(
"End of File marker found, skipping...\n");
41 printf(
"Cannot read from tape, status=%X\n",
status);
51 f = fopen(
"/tmp/.mt",
"w");
52 fwrite(buffer,
sizeof(buffer), 1, f);
54 system(
"file /tmp/.mt > /tmp/.mtf");
55 f = fopen(
"/tmp/.mtf",
"r");
57 memset(buffer, 0,
sizeof(buffer));
58 fread(buffer,
sizeof(buffer), 1, f);
61 if (strchr(buffer,
'\n'))
62 *strchr(buffer,
'\n') = 0;
63 if (strchr(buffer,
'\r'))
64 *strchr(buffer,
'\r') = 0;
66 printf(
"Found file: ");
69 if (strchr(buffer,
':'))
70 printf(
"%s", strchr(buffer,
':') + 2);
79 printf(
"File on tape is no MIDAS data\n");
85 printf(
"Found run #%d at block#:%d recorded on %s", event->
serial_number,
91 printf(
"Spooling tape...\r");
95 printf(
"Error spooling tape\n");
122 printf(
"End of tape reached.\n");
125 printf(
"End of File marker found, skipping...\n");
133 printf(
"Data on tape is no MIDAS data\n");
135 printf(
"Skipping file...\r");
150 printf(
"Copy run to file %s\n",
str);
153 fh = open(
str, O_RDWR | O_CREAT | O_TRUNC |
O_BINARY, 0644);
155 printf(
"Cannot open file %s\n",
str);
165 if (
verbose && size > mb + 1024 * 1024) {
167 printf(
"%d MB\r", size / 1024 / 1024);
177 printf(
"%d MB\n", size / 1024 / 1024);
193 INT i,
n, fh, size, mb;
199 for (
i = count1;
i <= count2;
i++) {
208 printf(
"Cannot open file %s\n",
str);
213 printf(
"Copy file %s to tape\n",
str);
221 if (
verbose && size > mb + 1024 * 1024) {
223 printf(
"%d MB\r", size / 1024 / 1024);
233 printf(
"%d MB\n", size / 1024 / 1024);
246int main(
int argc,
char *argv[])
249 char cmd[100], tape_name[256],
file_name[256];
254 strcpy(tape_name,
"\\\\.\\tape0");
255#elif defined(OS_UNIX)
256 strcpy(tape_name,
"/dev/tape");
258 strcpy(tape_name,
"mka0:");
260#error This program cannot be compiled under this operating system
270 if (getenv(
"TAPE") != NULL)
271 strcpy(tape_name, getenv(
"TAPE"));
274 for (
i = 1;
i < argc;
i++) {
275 if (argv[
i][0] ==
'-' && argv[
i][1] ==
'v')
277 else if (argv[
i][0] ==
'-') {
278 if (
i + 1 >= argc || argv[
i + 1][0] ==
'-')
280 if (argv[
i][1] ==
'f')
281 strcpy(tape_name, argv[++
i]);
282 else if (argv[
i][1] ==
'd')
286 }
else if (cmd[0] == 0)
287 strcpy(cmd, argv[
i]);
288 else if (count1 == -100)
289 count1 = atoi(argv[
i]);
291 count2 = atoi(argv[
i]);
300 if (strcmp(cmd,
"status") == 0) {
307 printf(
"Cannot open tape %s.\n", tape_name);
311 if (strcmp(cmd,
"rewind") == 0)
314 else if (strcmp(cmd,
"online") == 0)
317 else if (strcmp(cmd,
"offline") == 0)
320 else if (strcmp(cmd,
"eof") == 0 || strcmp(cmd,
"weof") == 0) {
324 printf(
"Cannot open tape %s.\n", tape_name);
328 for (
i = 0;
i < count1;
i++)
332 else if (strcmp(cmd,
"fsf") == 0 || strcmp(cmd,
"ff") == 0)
335 else if (strcmp(cmd,
"fsr") == 0 || strcmp(cmd,
"fr") == 0)
338 else if (strcmp(cmd,
"bsf") == 0 || strcmp(cmd,
"bf") == 0)
341 else if (strcmp(cmd,
"bsr") == 0 || strcmp(cmd,
"br") == 0)
344 else if (strcmp(cmd,
"seod") == 0)
347 else if (strcmp(cmd,
"dir") == 0)
350 else if (strcmp(cmd,
"backup") == 0) {
354 printf(
"Cannot open tape %s.\n", tape_name);
360 else if (strcmp(cmd,
"restore") == 0)
365 printf(
"usage: mtape [-f tape_device] [-d file] [-v] command [count] [last]\n\n");
366 printf(
"Following commands are available:\n");
367 printf(
" status Print status information about tape\n");
368 printf(
" rewind Rewind tape\n");
370 (
" eof,weof Write <count> End-of-File marks at the current tape position\n");
371 printf(
" fsf,ff Forward spaces <count> files\n");
372 printf(
" fsr,fr Forward spaces <count> records\n");
373 printf(
" bsf,bf Backspaces <count> files\n");
374 printf(
" bsr,br Backspaces <count> records\n");
375 printf(
" rewind Rewind tape\n");
376 printf(
" offline Places the tape offline (unload)\n");
377 printf(
" online Places the tape online (load)\n");
378 printf(
" seod Space to end of recorded data\n\n");
379 printf(
"Following commands only work with tapes written in MIDAS format:\n");
380 printf(
" dir List next [count] runs on MIDAS tape\n");
383 (
" Copy runs with numbers [count] to [last] from disk to tape.\n");
384 printf(
" If [-d file] is not given, runxxxxx.mid is used where\n");
385 printf(
" xxxxx is the run number. If [file] contains %%05d, it\n");
386 printf(
" is replaced by the run number.\n");
387 printf(
" restore\n");
388 printf(
" Copy next [count] files from tape to disk.\n");
389 printf(
" If [-d file] is not given, runxxxxx.mid is used where\n");
390 printf(
" xxxxx is the run number. If [file] contains %%05d, it\n");
391 printf(
" is replaced by the run number.\n");
396 printf(
"Error performing operation\n");
398 printf(
"Error performing operation, status code = %d\n",
status);
INT ss_tape_rskip(INT channel, INT count)
INT ss_tape_write(INT channel, void *pdata, INT count)
INT ss_tape_rewind(INT channel)
INT ss_tape_fskip(INT channel, INT count)
INT ss_tape_close(INT channel)
INT ss_tape_get_blockn(INT channel)
INT ss_tape_status(char *path)
INT ss_tape_mount(INT channel)
INT ss_tape_spool(INT channel)
INT ss_tape_read(INT channel, void *pdata, INT *count)
INT ss_tape_unmount(INT channel)
INT ss_tape_write_eof(INT channel)
INT ss_tape_open(char *path, INT oflag, INT *channel)
INT cm_set_msg_print(INT system_mask, INT user_mask, int(*func)(const char *))
#define write(n, a, f, d)
INT tape_dir(INT channel, INT count)
INT tape_backup(INT channel, INT count1, INT count2, char *file_name)
INT tape_restore(INT channel, INT count, char *file_name)