3 * Bacula Tape manipulation program
5 * Has various tape manipulation commands -- mostly for
6 * use in determining how tapes really work.
8 * Kern Sibbald, April MM
10 * Note, this program reads stored.conf, and will only
11 * talk to devices that are configured.
17 Copyright (C) 2000-2003 Kern Sibbald and John Walker
19 This program is free software; you can redistribute it and/or
20 modify it under the terms of the GNU General Public License as
21 published by the Free Software Foundation; either version 2 of
22 the License, or (at your option) any later version.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received a copy of the GNU General Public
30 License along with this program; if not, write to the Free
31 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
40 /* External subroutines */
41 extern void free_config_resources();
43 /* Exported variables */
46 int bsize = TAPE_BSIZE;
47 char VolName[MAX_NAME_LENGTH];
50 DEVRES *device = NULL;
53 /* Forward referenced subroutines */
54 static void do_tape_cmds();
55 static void helpcmd();
56 static void scancmd();
57 static void rewindcmd();
58 static void clearcmd();
62 static void fillcmd();
63 static void qfillcmd();
64 static void statcmd();
65 static void unfillcmd();
66 static int flush_block(DEV_BLOCK *block, int dump);
67 static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
68 static int my_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block);
69 static void scan_blocks();
70 static void set_volume_name(char *VolName, int volnum);
71 static void rawfill_cmd();
72 static void bfill_cmd();
75 /* Static variables */
76 #define CONFIG_FILE "bacula-sd.conf"
79 static BSR *bsr = NULL;
80 static char cmd[1000];
81 static int signals = TRUE;
84 static uint64_t vol_size;
85 static uint64_t VolBytes;
88 static int32_t file_index;
89 static int end_of_tape = 0;
90 static uint32_t LastBlock = 0;
91 static uint32_t eot_block;
92 static uint32_t eot_block_len;
93 static uint32_t eot_FileIndex;
94 static int dumped = 0;
95 static DEV_BLOCK *last_block = NULL;
96 static DEV_BLOCK *this_block = NULL;
97 static uint32_t last_file = 0;
98 static uint32_t last_block_num = 0;
99 static uint32_t BlockNumber = 0;
100 static int simple = FALSE;
102 static char *VolumeName = NULL;
105 static JCR *jcr = NULL;
109 static void terminate_btape(int sig);
110 int get_cmd(char *prompt);
113 /*********************************************************************
115 * Main Bacula Pool Creation Program
118 int main(int argc, char *argv[])
124 if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) {
125 Emsg2(M_ABORT, 0, "Tape block size (%d) not multiple of system size (%d)\n",
126 TAPE_BSIZE, DEV_BSIZE);
128 if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) {
129 Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE);
132 printf("Tape block granularity is %d bytes.\n", TAPE_BSIZE);
134 working_directory = "/tmp";
135 my_name_is(argc, argv, "btape");
136 init_msg(NULL, NULL);
138 while ((ch = getopt(argc, argv, "b:c:d:sv?")) != -1) {
140 case 'b': /* bootstrap file */
141 bsr = parse_bsr(NULL, optarg);
142 // dump_bsr(bsr, true);
145 case 'c': /* specify config file */
146 if (configfile != NULL) {
149 configfile = bstrdup(optarg);
152 case 'd': /* set debug level */
153 debug_level = atoi(optarg);
154 if (debug_level <= 0) {
180 init_signals(terminate_btape);
183 if (configfile == NULL) {
184 configfile = bstrdup(CONFIG_FILE);
187 daemon_start_time = time(NULL);
189 parse_config(configfile);
192 /* See if we can open a device */
194 Pmsg0(000, "No archive name specified.\n");
197 } else if (argc != 1) {
198 Pmsg0(000, "Improper number of arguments specified.\n");
203 jcr = setup_jcr("btape", argv[0], bsr, NULL);
204 dev = setup_to_access_device(jcr, 0); /* acquire for write */
208 block = new_block(dev);
210 if (!(dev->state & ST_OPENED)) {
211 Dmsg0(129, "Opening device.\n");
212 if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
213 Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
219 Dmsg1(129, "open_dev %s OK\n", dev_name(dev));
223 Dmsg0(200, "Do tape commands\n");
231 static void terminate_btape(int stat)
234 sm_check(__FILE__, __LINE__, False);
238 free_config_resources();
244 if (debug_level > 10)
245 print_memory_pool_stats();
255 free_block(last_block);
258 free_block(this_block);
262 close_memory_pool(); /* free memory in pool */
274 * Write a label to the tape
276 static void labelcmd()
282 for (device=NULL; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
283 if (strcmp(device->device_name, dev->dev_name) == 0) {
284 jcr->device = device; /* Arggg a bit of duplication here */
286 dev->device = device;
293 Pmsg2(0, "Could not find device %s in %s\n", dev->dev_name, configfile);
298 strcpy(cmd, VolumeName);
300 if (!get_cmd("Enter Volume Name: ")) {
305 if (!(dev->state & ST_OPENED)) {
306 if (!open_device(dev)) {
307 Pmsg1(0, "Device open failed. ERR=%s\n", strerror_dev(dev));
310 write_volume_label_to_dev(jcr, device, cmd, "Default");
314 * Read the tape label
316 static void readlabelcmd()
318 int save_debug_level = debug_level;
322 block = new_block(dev);
323 stat = read_dev_volume_label(jcr, dev, block);
326 Pmsg0(0, "Volume has no label.\n");
329 Pmsg0(0, "Volume label read correctly.\n");
332 Pmsg1(0, "I/O error on device: ERR=%s", strerror_dev(dev));
335 Pmsg0(0, "Volume name error\n");
337 case VOL_CREATE_ERROR:
338 Pmsg1(0, "Error creating label. ERR=%s", strerror_dev(dev));
340 case VOL_VERSION_ERROR:
341 Pmsg0(0, "Volume version error.\n");
343 case VOL_LABEL_ERROR:
344 Pmsg0(0, "Bad Volume label type.\n");
347 Pmsg0(0, "Unknown error.\n");
352 dump_volume_label(dev);
353 debug_level = save_debug_level;
359 * Load the tape should have prevously been taken
360 * off line, otherwise this command is not necessary.
362 static void loadcmd()
365 if (!load_dev(dev)) {
366 Pmsg1(0, "Bad status from load. ERR=%s\n", strerror_dev(dev));
368 Pmsg1(0, "Loaded %s\n", dev_name(dev));
374 static void rewindcmd()
376 if (!rewind_dev(dev)) {
377 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
378 clrerror_dev(dev, -1);
380 Pmsg1(0, "Rewound %s\n", dev_name(dev));
385 * Clear any tape error
387 static void clearcmd()
389 clrerror_dev(dev, -1);
393 * Write and end of file on the tape
395 static void weofcmd()
399 if ((stat = weof_dev(dev, 1)) < 0) {
400 Pmsg2(0, "Bad status from weof %d. ERR=%s\n", stat, strerror_dev(dev));
403 Pmsg1(0, "Wrote EOF to %s\n", dev_name(dev));
408 /* Go to the end of the medium -- raw command
409 * The idea was orginally that the end of the Bacula
410 * medium would be flagged differently. This is not
411 * currently the case. So, this is identical to the
417 Pmsg1(0, _("Bad status from MTEOD. ERR=%s\n"), strerror_dev(dev));
420 Pmsg0(0, _("Moved to end of medium.\n"));
425 * Go to the end of the medium (either hardware determined
426 * or defined by two eofs.
440 if ((stat=bsf_dev(dev, 1)) < 0) {
441 Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror(errno));
443 Pmsg0(0, _("Backspaced one file.\n"));
454 if ((stat=bsr_dev(dev, 1)) < 0) {
455 Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), strerror(errno));
457 Pmsg0(0, _("Backspaced one record.\n"));
462 * List device capabilities as defined in the
467 printf(_("Device capabilities:\n"));
468 printf("%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
469 printf("%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
470 printf("%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
471 printf("%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
472 printf("%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
473 printf("%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
474 printf("%sREM ", dev->capabilities & CAP_REM ? "" : "!");
475 printf("%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
476 printf("%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
477 printf("%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
478 printf("%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
479 printf("%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
482 printf(_("Device status:\n"));
483 printf("%sOPENED ", dev->state & ST_OPENED ? "" : "!");
484 printf("%sTAPE ", dev->state & ST_TAPE ? "" : "!");
485 printf("%sLABEL ", dev->state & ST_LABEL ? "" : "!");
486 printf("%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
487 printf("%sAPPEND ", dev->state & ST_APPEND ? "" : "!");
488 printf("%sREAD ", dev->state & ST_READ ? "" : "!");
489 printf("%sEOT ", dev->state & ST_EOT ? "" : "!");
490 printf("%sWEOT ", dev->state & ST_WEOT ? "" : "!");
491 printf("%sEOF ", dev->state & ST_EOF ? "" : "!");
492 printf("%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
493 printf("%sSHORT ", dev->state & ST_SHORT ? "" : "!");
496 printf(_("Device parameters:\n"));
497 printf("Device name: %s\n", dev->dev_name);
498 printf("File=%u block=%u\n", dev->file, dev->block_num);
499 printf("Min block=%u Max block=%u\n", dev->min_block_size, dev->max_block_size);
507 * Test writting larger and larger records.
508 * This is a torture test for records.
510 static void rectestcmd()
516 Pmsg0(0, "Test writting larger and larger records.\n"
517 "This is a torture test for records.\nI am going to write\n"
518 "larger and larger records. It will stop when the record size\n"
519 "plus the header exceeds the block size (by default about 64K)\n");
522 get_cmd("Do you want to continue? (y/n): ");
524 Pmsg0(000, "Command aborted.\n");
528 sm_check(__FILE__, __LINE__, False);
529 block = new_block(dev);
532 for (i=1; i<500000; i++) {
533 rec->data = check_pool_memory_size(rec->data, i);
534 memset(rec->data, i & 0xFF, i);
536 sm_check(__FILE__, __LINE__, False);
537 if (write_record_to_block(block, rec)) {
540 Pmsg2(0, "Block %d i=%d\n", blkno, i);
544 sm_check(__FILE__, __LINE__, False);
548 sm_check(__FILE__, __LINE__, False);
552 * This test attempts to re-read a block written by Bacula
553 * normally at the end of the tape. Bacula will then back up
554 * over the two eof marks, backup over the record and reread
555 * it to make sure it is valid. Bacula can skip this validation
556 * if you set "Backward space record = no"
558 static int re_read_block_test()
565 if (!(dev->capabilities & CAP_BSR)) {
566 Pmsg0(-1, _("Skipping read backwards test because BSR turned off.\n"));
570 Pmsg0(-1, _("\n=== Write, backup, and re-read test ===\n\n"
571 "I'm going to write three records and two eof's\n"
572 "then backup over the eof's and re-read the last record.\n"
573 "Bacula does this after writing the last block on the\n"
574 "tape to verify that the block was written correctly.\n"
575 "It is not an *essential* feature ...\n\n"));
577 block = new_block(dev);
579 rec->data = check_pool_memory_size(rec->data, block->buf_len);
580 len = rec->data_len = block->buf_len-100;
581 memset(rec->data, 1, rec->data_len);
582 if (!write_record_to_block(block, rec)) {
583 Pmsg0(0, _("Error writing record to block.\n"));
586 if (!write_block_to_dev(jcr, dev, block)) {
587 Pmsg0(0, _("Error writing block to device.\n"));
590 Pmsg1(0, _("Wrote first record of %d bytes.\n"), rec->data_len);
592 memset(rec->data, 2, rec->data_len);
593 if (!write_record_to_block(block, rec)) {
594 Pmsg0(0, _("Error writing record to block.\n"));
597 if (!write_block_to_dev(jcr, dev, block)) {
598 Pmsg0(0, _("Error writing block to device.\n"));
601 Pmsg1(0, _("Wrote second record of %d bytes.\n"), rec->data_len);
603 memset(rec->data, 3, rec->data_len);
604 if (!write_record_to_block(block, rec)) {
605 Pmsg0(0, _("Error writing record to block.\n"));
608 if (!write_block_to_dev(jcr, dev, block)) {
609 Pmsg0(0, _("Error writing block to device.\n"));
612 Pmsg1(0, _("Wrote third record of %d bytes.\n"), rec->data_len);
616 if (bsf_dev(dev, 1) != 0) {
617 Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror(dev->dev_errno));
620 if (bsf_dev(dev, 1) != 0) {
621 Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror(dev->dev_errno));
624 Pmsg0(0, "Backspaced over two EOFs OK.\n");
625 if (bsr_dev(dev, 1) != 0) {
626 Pmsg1(0, _("Backspace record failed! ERR=%s\n"), strerror(dev->dev_errno));
629 Pmsg0(0, "Backspace record OK.\n");
630 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
631 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
634 memset(rec->data, 0, rec->data_len);
635 if (!read_record_from_block(block, rec)) {
636 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
639 for (int i=0; i<len; i++) {
640 if (rec->data[i] != 3) {
641 Pmsg0(0, _("Bad data in record. Test failed!\n"));
645 Pmsg0(0, _("\nBlock re-read correct. Test succeeded!\n"));
646 Pmsg0(-1, _("=== End Write, backup, and re-read test ===\n\n"));
654 Pmsg0(0, _("This is not terribly serious since Bacula only uses\n"
655 "this function to verify the last block written to the\n"
656 "tape. Bacula will skip the last block verification\n"
658 "Backward Space Record = No\n\n"
659 "to your Storage daemon's Device resource definition.\n"));
665 * This test writes some records, then writes an end of file,
666 * rewinds the tape, moves to the end of the data and attepts
667 * to append to the tape. This function is essential for
668 * Bacula to be able to write multiple jobs to the tape.
670 static int append_test()
672 Pmsg0(-1, _("\n\n=== Append files test ===\n\n"
673 "This test is essential to Bacula.\n\n"
674 "I'm going to write one record in file 0,\n"
675 " two records in file 1,\n"
676 " and three records in file 2\n\n"));
679 weofcmd(); /* end file 0 */
682 weofcmd(); /* end file 1 */
686 weofcmd(); /* end file 2 */
688 Pmsg0(0, _("Now moving to end of medium.\n"));
690 Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
691 dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
693 if (dev->file != 3) {
697 Pmsg0(-1, _("\nNow the important part, I am going to attempt to append to the tape.\n\n"));
701 Pmsg0(-1, _("Done appending, there should be no I/O errors\n\n"));
702 Pmsg0(-1, "Doing Bacula scan of blocks:\n");
704 Pmsg0(-1, _("End scanning the tape.\n"));
705 Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
706 dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
708 if (dev->file != 4) {
716 * This is a general test of Bacula's functions
717 * needed to read and write the tape.
719 static void testcmd()
723 stat = append_test();
724 if (stat == 1) { /* OK get out */
727 if (stat == -1) { /* first test failed */
728 if (dev_cap(dev, CAP_EOM)) {
729 Pmsg0(-1, "\nAppend test failed. Attempting again.\n"
730 "Setting \"Hardware End of Medium = no\" and retrying append test.\n\n");
731 dev->capabilities &= ~CAP_EOM; /* turn off eom */
732 stat = append_test();
734 Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
735 " Hardware End of Medium = No\n\n"
736 "to your Device resource in the Storage conf file.\n");
740 Pmsg0(-1, "\n\nThat appears not to have corrected the problem.\n");
743 /* Wrong count after append */
745 Pmsg0(-1, "\n\nIt looks like the append failed. Attempting again.\n"
746 "Setting \"BSF at EOM = yes\" and retrying append test.\n");
747 dev->capabilities |= CAP_BSFATEOM; /* backspace on eom */
748 stat = append_test();
750 Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
751 " Hardware End of Medium = No\n"
752 " BSF at EOM = yes\n\n"
753 "to your Device resource in the Storage conf file.\n");
758 Pmsg0(-1, "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
759 "Unable to correct the problem. You MUST fix this\n"
760 "problem before Bacula can use your tape drive correctly\n");
761 Pmsg0(-1, "\nPerhaps running Bacula in fixed block mode will work.\n"
762 "Do so by setting:\n\n"
763 "Minimum Block Size = nnn\n"
764 "Maximum Block Size = nnn\n\n"
765 "in your Storage daemon's Device definition.\n"
766 "nnn must match your tape driver's block size.\n"
767 "This, however, is not really an ideal solution.\n");
772 Pmsg0(-1, _("\nThe above Bacula scan should have output identical to what follows.\n"
773 "Please double check it ...\n"
774 "=== Sample correct output ===\n"
775 "1 block of 64448 bytes in file 1\n"
776 "End of File mark.\n"
777 "2 blocks of 64448 bytes in file 2\n"
778 "End of File mark.\n"
779 "3 blocks of 64448 bytes in file 3\n"
780 "End of File mark.\n"
781 "1 block of 64448 bytes in file 4\n"
782 "End of File mark.\n"
783 "Total files=4, blocks=7, bytes = 451136\n"
784 "=== End sample correct output ===\n\n"));
786 Pmsg0(-1, _("If the above scan output is not identical to the\n"
787 "sample output, you MUST correct the problem\n"
788 "or Bacula will not be able to write multiple Jobs to \n"
792 re_read_block_test();
795 Pmsg0(-1, _("\n=== End Append files test ===\n"));
799 /* Forward space a file */
802 if (!fsf_dev(dev, 1)) {
803 Pmsg1(0, "Bad status from fsf. ERR=%s\n", strerror_dev(dev));
806 Pmsg0(0, "Forward spaced one file.\n");
809 /* Forward space a record */
812 if (!fsr_dev(dev, 1)) {
813 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
816 Pmsg0(0, "Forward spaced one record.\n");
821 * Write a Bacula block to the tape
829 sm_check(__FILE__, __LINE__, False);
830 block = new_block(dev);
832 dump_block(block, "test");
834 i = block->buf_len - 100;
836 rec->data = check_pool_memory_size(rec->data, i);
837 memset(rec->data, i & 0xFF, i);
839 sm_check(__FILE__, __LINE__, False);
840 if (!write_record_to_block(block, rec)) {
841 Pmsg0(0, _("Error writing record to block.\n"));
844 if (!write_block_to_dev(jcr, dev, block)) {
845 Pmsg0(0, _("Error writing block to device.\n"));
848 Pmsg1(0, _("Wrote one record of %d bytes.\n"), i);
850 Pmsg0(0, _("Wrote block to device.\n"));
853 sm_check(__FILE__, __LINE__, False);
856 sm_check(__FILE__, __LINE__, False);
860 * Read a record from the tape
867 if (!get_cmd("Enter length to read: ")) {
871 if (len < 0 || len > 1000000) {
872 Pmsg0(0, _("Bad length entered, using default of 1024 bytes.\n"));
875 buf = (char *)malloc(len);
876 stat = read(dev->fd, buf, len);
877 if (stat > 0 && stat <= len) {
880 Pmsg3(0, _("Read of %d bytes gives stat=%d. ERR=%s\n"),
881 len, stat, strerror(errno));
887 * Scan tape by reading block by block. Report what is
888 * on the tape. Note, this command does raw reads, and as such
889 * will not work with fixed block size devices.
891 static void scancmd()
894 int blocks, tot_blocks, tot_files;
900 blocks = block_size = tot_blocks = 0;
902 if (dev->state & ST_EOT) {
903 Pmsg0(0, "End of tape\n");
907 tot_files = dev->file;
908 Pmsg1(0, _("Starting scan at file %u\n"), dev->file);
910 if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) {
911 clrerror_dev(dev, -1);
912 Mmsg2(&dev->errmsg, "read error on %s. ERR=%s.\n",
913 dev->dev_name, strerror(dev->dev_errno));
914 Pmsg2(0, "Bad status from read %d. ERR=%s\n", stat, strerror_dev(dev));
916 printf("%d block%s of %d bytes in file %d\n",
917 blocks, blocks>1?"s":"", block_size, dev->file);
920 Dmsg1(200, "read status = %d\n", stat);
922 if (stat != block_size) {
925 printf("%d block%s of %d bytes in file %d\n",
926 blocks, blocks>1?"s":"", block_size, dev->file);
931 if (stat == 0) { /* EOF */
933 printf("End of File mark.\n");
934 /* Two reads of zero means end of tape */
935 if (dev->state & ST_EOF)
936 dev->state |= ST_EOT;
938 dev->state |= ST_EOF;
941 if (dev->state & ST_EOT) {
942 printf("End of tape\n");
945 } else { /* Got data */
946 dev->state &= ~ST_EOF;
953 tot_files = dev->file - tot_files;
954 printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
955 edit_uint64_with_commas(bytes, ec1));
960 * Scan tape by reading Bacula block by block. Report what is
961 * on the tape. This function reads Bacula blocks, so if your
962 * Device resource is correctly defined, it should work with
963 * either variable or fixed block sizes.
965 static void scan_blocks()
967 int blocks, tot_blocks, tot_files;
973 block = new_block(dev);
974 blocks = block_size = tot_blocks = 0;
978 tot_files = dev->file;
980 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
981 Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
982 if (dev->state & ST_EOT) {
984 printf("%d block%s of %d bytes in file %d\n",
985 blocks, blocks>1?"s":"", block_size, dev->file);
990 if (dev->state & ST_EOF) {
992 printf("%d block%s of %d bytes in file %d\n",
993 blocks, blocks>1?"s":"", block_size, dev->file);
996 printf(_("End of File mark.\n"));
999 if (dev->state & ST_SHORT) {
1001 printf("%d block%s of %d bytes in file %d\n",
1002 blocks, blocks>1?"s":"", block_size, dev->file);
1005 printf(_("Short block read.\n"));
1008 printf(_("Error reading block. ERR=%s\n"), strerror_dev(dev));
1011 if (block->block_len != block_size) {
1013 printf("%d block%s of %d bytes in file %d\n",
1014 blocks, blocks>1?"s":"", block_size, dev->file);
1017 block_size = block->block_len;
1021 bytes += block->block_len;
1022 Dmsg6(100, "Blk_blk=%u dev_blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
1023 block->BlockNumber, dev->block_num, block->block_len, block->BlockVer,
1024 block->VolSessionId, block->VolSessionTime);
1026 DEV_RECORD *rec = new_record();
1027 read_record_from_block(block, rec);
1028 Pmsg8(-1, "Blk_block: %u dev_blk=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
1029 block->BlockNumber, dev->block_num, block->block_len,
1030 FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
1031 stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
1034 } else if (verbose > 1) {
1035 dump_block(block, "");
1041 tot_files = dev->file - tot_files;
1042 printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
1043 edit_uint64_with_commas(bytes, ec1));
1047 static void statcmd()
1053 debug = debug_level;
1055 if (!status_dev(dev, &status)) {
1056 Pmsg2(0, "Bad status from status %d. ERR=%s\n", stat, strerror_dev(dev));
1059 dump_volume_label(dev);
1061 debug_level = debug;
1066 * First we label the tape, then we fill
1067 * it with data get a new tape and write a few blocks.
1069 static void fillcmd()
1080 This command simulates Bacula writing to a tape.\n\
1081 It requires either one or two blank tapes, which it\n\
1082 will label and write. It will print a status approximately\n\
1083 every 322 MB, and write an EOF every 3.2 GB. If you have\n\
1084 selected the simple test option, after writing the first tape\n\
1085 it will rewind it and re-read the last block written.\n\
1086 If you have selected the multiple tape test, when the first tape\n\
1087 fills, it will ask for a second, and after writing a few more \n\
1088 blocks, it will stop. Then it will begin re-reading the\n\
1090 This may take a long time -- hours! ...\n\n");
1092 get_cmd("Insert a blank tape then indicate if you want\n"
1093 "to run the simplified test (s) with one tape or\n"
1094 "the complete multiple tape (m) test: (s/m) ");
1095 if (cmd[0] == 's') {
1096 Pmsg0(-1, "Simple test (single tape) selected.\n");
1098 } else if (cmd[0] == 'm') {
1099 Pmsg0(-1, "Complete multiple tape test selected.\n");
1102 Pmsg0(000, "Command aborted.\n");
1106 set_volume_name("TestVolume1", 1);
1111 Dmsg1(20, "Begin append device=%s\n", dev_name(dev));
1113 block = new_block(dev);
1116 * Acquire output device for writing. Note, after acquiring a
1117 * device, we MUST release it, which is done at the end of this
1120 Dmsg0(100, "just before acquire_device\n");
1121 if (!(dev=acquire_device_for_append(jcr, dev, block))) {
1122 set_jcr_job_status(jcr, JS_ErrorTerminated);
1127 Dmsg0(100, "Just after acquire_device_for_append\n");
1129 * Write Begin Session Record
1131 if (!write_session_label(jcr, block, SOS_LABEL)) {
1132 set_jcr_job_status(jcr, JS_ErrorTerminated);
1133 Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
1137 Pmsg0(-1, "Wrote Start Of Session label.\n");
1139 memset(&rec, 0, sizeof(rec));
1140 rec.data = get_memory(100000); /* max record size */
1142 #define REC_SIZE 32768
1143 rec.data_len = REC_SIZE;
1146 * Generate data as if from File daemon, write to device
1148 jcr->VolFirstIndex = 0;
1149 time(&jcr->run_time); /* start counting time for rates */
1150 Pmsg0(-1, "Begin writing Bacula records to first tape ...\n");
1151 Pmsg1(-1, "Block num = %d\n", dev->block_num);
1152 for (file_index = 0; ok && !job_canceled(jcr); ) {
1153 rec.VolSessionId = jcr->VolSessionId;
1154 rec.VolSessionTime = jcr->VolSessionTime;
1155 rec.FileIndex = ++file_index;
1156 rec.Stream = STREAM_FILE_DATA;
1159 * Fill the buffer with the file_index negated. Negation ensures that
1160 * more bits are turned on.
1162 uint64_t *lp = (uint64_t *)rec.data;
1163 for (uint32_t i=0; i < (rec.data_len-sizeof(uint64_t))/sizeof(uint64_t); i++) {
1164 *lp++ = ~file_index;
1167 Dmsg4(250, "before writ_rec FI=%d SessId=%d Strm=%s len=%d\n",
1168 rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream, rec.FileIndex),
1171 while (!write_record_to_block(block, &rec)) {
1173 * When we get here we have just filled a block
1175 Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
1178 /* Write block to tape */
1179 if (!flush_block(block, 1)) {
1183 /* Every 5000 blocks (approx 322MB) report where we are.
1185 if ((block->BlockNumber % 5000) == 0) {
1187 now -= jcr->run_time;
1191 kbs = (double)dev->VolCatInfo.VolCatBytes / (1000.0 * (double)now);
1192 Pmsg4(-1, "Wrote block=%u, blk_num=%d VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
1194 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), (float)kbs);
1196 /* Every 15000 blocks (approx 1GB) write an EOF.
1198 if ((block->BlockNumber % 15000) == 0) {
1199 Pmsg0(-1, "Flush block, write EOF\n");
1200 flush_block(block, 0);
1204 /* Get out after writing 10 blocks to the second tape */
1205 if (++BlockNumber > 10 && stop != 0) { /* get out */
1210 Pmsg0(000, _("Not OK\n"));
1213 jcr->JobBytes += rec.data_len; /* increment bytes this job */
1214 Dmsg4(190, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
1215 FI_to_ascii(rec.FileIndex), rec.VolSessionId,
1216 stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
1218 /* Get out after writing 10 blocks to the second tape */
1219 if (BlockNumber > 10 && stop != 0) { /* get out */
1220 Pmsg0(-1, "Done writing ...\n");
1225 Dmsg0(100, "Write_end_session_label()\n");
1226 /* Create Job status for end of session label */
1227 if (!job_canceled(jcr) && ok) {
1228 set_jcr_job_status(jcr, JS_Terminated);
1230 set_jcr_job_status(jcr, JS_ErrorTerminated);
1232 if (!write_session_label(jcr, block, EOS_LABEL)) {
1233 Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev));
1236 /* Write out final block of this session */
1237 if (!write_block_to_device(jcr, dev, block)) {
1238 Pmsg0(-1, _("Set ok=FALSE after write_block_to_device.\n"));
1241 Pmsg0(-1, "Wrote End Of Session label.\n");
1244 /* Release the device */
1245 if (!release_device(jcr, dev)) {
1246 Pmsg0(-1, _("Error in release_device\n"));
1251 free_memory(rec.data);
1253 dump_block(last_block, _("Last block written to tape.\n"));
1255 Pmsg0(-1, _("\n\nDone filling tape. Now beginning re-read of tape ...\n"));
1261 * Read two tapes written by the "fill" command and ensure
1262 * that the data is valid. If stop==1 we simulate full read back
1263 * of two tapes. If stop==-1 we simply read the last block and
1264 * verify that it is correct.
1266 static void unfillcmd()
1273 block = new_block(dev);
1275 dev->capabilities |= CAP_ANONVOLS; /* allow reading any volume */
1276 dev->capabilities &= ~CAP_LABEL; /* don't label anything here */
1281 /* Close device so user can use autochanger if desired */
1282 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
1285 force_close_dev(dev);
1286 get_cmd(_("Mount first tape. Press enter when ready: "));
1289 set_volume_name("TestVolume1", 1);
1291 create_vol_list(jcr);
1293 dev->state &= ~ST_READ;
1294 if (!acquire_device_for_read(jcr, dev, block)) {
1295 Pmsg1(-1, "%s", dev->errmsg);
1300 time(&jcr->run_time); /* start counting time for rates */
1304 /* Read all records and then second tape */
1305 read_records(jcr, dev, record_cb, my_mount_next_read_volume);
1308 * Simplified test, we simply fsf to file, then read the
1309 * last block and make sure it is the same as the saved block.
1311 Pmsg0(000, "Rewinding tape ...\n");
1312 if (!rewind_dev(dev)) {
1313 Pmsg1(-1, _("Error rewinding: ERR=%s\n"), strerror_dev(dev));
1316 if (last_file > 0) {
1317 Pmsg1(000, "Forward spacing to last file=%u\n", last_file);
1318 if (!fsf_dev(dev, last_file)) {
1319 Pmsg1(-1, _("Error in FSF: ERR=%s\n"), strerror_dev(dev));
1323 Pmsg1(-1, _("Forward space to file %u complete. Reading blocks ...\n"),
1325 Pmsg1(-1, _("Now reading to block %u.\n"), last_block_num);
1326 for (uint32_t i=0; i <= last_block_num; i++) {
1327 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
1328 Pmsg1(-1, _("Error reading blocks: ERR=%s\n"), strerror_dev(dev));
1329 Pmsg2(-1, _("Wanted block %u error at block %u\n"), last_block_num, i);
1332 if (i > 0 && i % 1000 == 0) {
1333 Pmsg1(-1, _("At block %u\n"), i);
1337 dump_block(last_block, _("Last block written"));
1338 dump_block(block, _("Block read back"));
1339 Pmsg0(-1, _("Except for the buffer address, the contents of\n"
1340 "the above two block dumps should be the same.\n"
1341 "If not you have a problem ...\n"));
1348 Pmsg0(000, _("Done with reread of fill data.\n"));
1352 * We are called here from "unfill" for each record on the tape.
1354 static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
1356 SESSION_LABEL label;
1358 if (stop > 1 && !dumped) { /* on second tape */
1360 dump_block(block, "First block on second tape");
1361 Pmsg4(-1, "Blk: FileIndex=%d: block=%u size=%d vol=%s\n",
1362 rec->FileIndex, block->BlockNumber, block->block_len, dev->VolHdr.VolName);
1363 Pmsg6(-1, " Rec: VId=%d VT=%d FI=%s Strm=%s len=%d state=%x\n",
1364 rec->VolSessionId, rec->VolSessionTime,
1365 FI_to_ascii(rec->FileIndex), stream_to_ascii(rec->Stream, rec->FileIndex),
1366 rec->data_len, rec->state);
1368 if (rec->FileIndex < 0) {
1370 dump_label_record(dev, rec, 1);
1372 switch (rec->FileIndex) {
1374 Pmsg0(-1, "Volume is prelabeled. This tape cannot be scanned.\n");
1377 unser_volume_label(dev, rec);
1378 Pmsg3(-1, "VOL_LABEL: block=%u size=%d vol=%s\n", block->BlockNumber,
1379 block->block_len, dev->VolHdr.VolName);
1383 unser_session_label(&label, rec);
1384 Pmsg1(-1, "SOS_LABEL: JobId=%u\n", label.JobId);
1387 unser_session_label(&label, rec);
1388 Pmsg2(-1, "EOS_LABEL: block=%u JobId=%u\n", block->BlockNumber,
1392 Pmsg0(-1, "EOM_LABEL:\n");
1394 case EOT_LABEL: /* end of all tapes */
1397 if (LastBlock != block->BlockNumber) {
1398 VolBytes += block->block_len;
1400 LastBlock = block->BlockNumber;
1402 now -= jcr->run_time;
1406 kbs = (double)VolBytes / (1000 * now);
1407 Pmsg3(000, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
1408 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
1410 Pmsg0(000, "End of all tapes.\n");
1418 if (++file_index != rec->FileIndex) {
1419 Pmsg3(000, "Incorrect FileIndex in Block %u. Got %d, expected %d.\n",
1420 block->BlockNumber, rec->FileIndex, file_index);
1423 * Now check that the right data is in the record.
1425 uint64_t *lp = (uint64_t *)rec->data;
1426 uint64_t val = ~file_index;
1427 for (uint32_t i=0; i < (REC_SIZE-sizeof(uint64_t))/sizeof(uint64_t); i++) {
1429 Pmsg2(000, "Record %d contains bad data in Block %u.\n",
1430 file_index, block->BlockNumber);
1435 if (LastBlock != block->BlockNumber) {
1436 VolBytes += block->block_len;
1438 if ((block->BlockNumber != LastBlock) && (block->BlockNumber % 50000) == 0) {
1441 now -= jcr->run_time;
1445 kbs = (double)VolBytes / (1000 * now);
1446 Pmsg3(000, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
1447 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
1449 LastBlock = block->BlockNumber;
1451 Pmsg1(000, "End of all blocks. Block=%u\n", block->BlockNumber);
1459 * Write current block to tape regardless of whether or
1460 * not it is full. If the tape fills, attempt to
1461 * acquire another tape.
1463 static int flush_block(DEV_BLOCK *block, int dump)
1468 uint32_t this_file, this_block_num;
1471 this_block = new_block(dev);
1474 free_memory(this_block->buf);
1475 memcpy(this_block, block, sizeof(DEV_BLOCK));
1476 this_block->buf = get_memory(block->buf_len);
1477 memcpy(this_block->buf, block->buf, this_block->buf_len);
1478 this_file = dev->file;
1479 this_block_num = dev->block_num;
1480 if (!write_block_to_dev(jcr, dev, block)) {
1481 Pmsg3(000, "Block not written: FileIndex=%u Block=%u Size=%u\n",
1482 (unsigned)file_index, block->BlockNumber, block->block_len);
1483 Pmsg2(000, "last_block_num=%u this_block_num=%d\n", last_block_num,
1486 dump_block(block, "Block not written");
1489 eot_block = block->BlockNumber;
1490 eot_block_len = block->block_len;
1491 eot_FileIndex = file_index;
1494 now -= jcr->run_time;
1498 kbs = (double)dev->VolCatInfo.VolCatBytes / (1000 * now);
1499 vol_size = dev->VolCatInfo.VolCatBytes;
1500 Pmsg2(000, "End of tape. VolumeCapacity=%s. Write rate = %.1f KB/s\n",
1501 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), kbs);
1504 stop = -1; /* stop, but do simplified test */
1506 /* Full test in progress */
1507 if (!fixup_device_block_write_error(jcr, dev, block)) {
1508 Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev));
1514 BlockNumber = 0; /* start counting for second tape */
1517 return 1; /* end of tape reached */
1521 * Toggle between two allocated blocks for efficiency.
1522 * Switch blocks so that the block just successfully written is
1523 * always in last_block.
1525 tblock = last_block;
1526 last_block = this_block;
1527 this_block = tblock;
1528 last_file = this_file;
1529 last_block_num = this_block_num;
1537 * First we label the tape, then we fill
1538 * it with data get a new tape and write a few blocks.
1540 static void qfillcmd()
1546 Pmsg0(0, "Test writing blocks of 64512 bytes to tape.\n");
1548 get_cmd("How many blocks do you want to write? (1000): ");
1555 sm_check(__FILE__, __LINE__, False);
1556 block = new_block(dev);
1559 i = block->buf_len - 100;
1561 rec->data = check_pool_memory_size(rec->data, i);
1562 memset(rec->data, i & 0xFF, i);
1565 Pmsg1(0, "Begin writing %d Bacula blocks to tape ...\n", count);
1566 for (i=0; i < count; i++) {
1571 if (!write_record_to_block(block, rec)) {
1572 Pmsg0(0, _("Error writing record to block.\n"));
1575 if (!write_block_to_dev(jcr, dev, block)) {
1576 Pmsg0(0, _("Error writing block to device.\n"));
1587 sm_check(__FILE__, __LINE__, False);
1590 sm_check(__FILE__, __LINE__, False);
1595 * Fill a tape using raw write() command
1597 static void rawfill_cmd()
1602 uint32_t block_num = 0;
1606 block = new_block(dev);
1607 fd = open("/dev/urandom", O_RDONLY);
1609 read(fd, block->buf, block->buf_len);
1611 Pmsg0(0, "Cannot open /dev/urandom.\n");
1615 p = (uint32_t *)block->buf;
1616 Pmsg1(0, "Begin writing raw blocks of %u bytes.\n", block->buf_len);
1619 stat = write(dev->fd, block->buf, block->buf_len);
1620 if (stat == (int)block->buf_len) {
1621 if ((block_num++ % 100) == 0) {
1631 printf("Write failed at block %u. stat=%d ERR=%s\n", block_num, stat,
1632 strerror(my_errno));
1639 * Fill a tape using raw write() command
1641 static void bfill_cmd()
1644 uint32_t block_num = 0;
1649 block = new_block(dev);
1650 fd = open("/dev/urandom", O_RDONLY);
1652 read(fd, block->buf, block->buf_len);
1654 Pmsg0(0, "Cannot open /dev/urandom.\n");
1658 p = (uint32_t *)block->buf;
1659 Pmsg1(0, "Begin writing Bacula blocks of %u bytes.\n", block->buf_len);
1662 block->binbuf = block->buf_len;
1663 block->bufp = block->buf + block->binbuf;
1664 if (!write_block_to_dev(jcr, dev, block)) {
1667 if ((block_num++ % 100) == 0) {
1674 printf("Write failed at block %u.\n", block_num);
1680 struct cmdstruct { char *key; void (*func)(); char *help; };
1681 static struct cmdstruct commands[] = {
1682 {"bsf", bsfcmd, "backspace file"},
1683 {"bsr", bsrcmd, "backspace record"},
1684 {"bfill", bfill_cmd, "fill tape using Bacula writes"},
1685 {"cap", capcmd, "list device capabilities"},
1686 {"clear", clearcmd, "clear tape errors"},
1687 {"eod", eodcmd, "go to end of Bacula data for append"},
1688 {"eom", eomcmd, "go to the physical end of medium"},
1689 {"fill", fillcmd, "fill tape, write onto second volume"},
1690 {"unfill", unfillcmd, "read filled tape"},
1691 {"fsf", fsfcmd, "forward space a file"},
1692 {"fsr", fsrcmd, "forward space a record"},
1693 {"help", helpcmd, "print this command"},
1694 {"label", labelcmd, "write a Bacula label to the tape"},
1695 {"load", loadcmd, "load a tape"},
1696 {"quit", quitcmd, "quit btape"},
1697 {"rawfill", rawfill_cmd, "use write() to fill tape"},
1698 {"readlabel", readlabelcmd, "read and print the Bacula tape label"},
1699 {"rectest", rectestcmd, "test record handling functions"},
1700 {"rewind", rewindcmd, "rewind the tape"},
1701 {"scan", scancmd, "read() tape block by block to EOT and report"},
1702 {"scanblocks", scan_blocks, "Bacula read block by block to EOT and report"},
1703 {"status", statcmd, "print tape status"},
1704 {"test", testcmd, "General test Bacula tape functions"},
1705 {"weof", weofcmd, "write an EOF on the tape"},
1706 {"wr", wrcmd, "write a single Bacula block"},
1707 {"rr", rrcmd, "read a single record"},
1708 {"qfill", qfillcmd, "quick fill command"},
1710 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
1718 while (get_cmd("*")) {
1719 sm_check(__FILE__, __LINE__, False);
1721 for (i=0; i<comsize; i++) /* search for command */
1722 if (fstrsch(cmd, commands[i].key)) {
1723 (*commands[i].func)(); /* go execute command */
1728 Pmsg1(0, _("%s is an illegal command\n"), cmd);
1734 static void helpcmd()
1738 printf(_(" Command Description\n ======= ===========\n"));
1739 for (i=0; i<comsize; i++)
1740 printf(" %-10s %s\n", commands[i].key, commands[i].help);
1747 "\nVersion: " VERSION " (" BDATE ")\n\n"
1748 "Usage: btape [-c config_file] [-d debug_level] [device_name]\n"
1749 " -c <file> set configuration file to file\n"
1750 " -dnn set debug level to nn\n"
1751 " -s turn off signals\n"
1752 " -t open the default tape device\n"
1753 " -? print this message.\n"
1759 * Get next input command from terminal. This
1760 * routine is REALLY primitive, and should be enhanced
1761 * to have correct backspacing, etc.
1764 get_cmd(char *prompt)
1768 fprintf(stdout, prompt);
1770 /* We really should turn off echoing and pretty this
1774 while ((ch = fgetc(stdin)) != EOF) {
1776 strip_trailing_junk(cmd);
1778 } else if (ch == 4 || ch == 0xd3 || ch == 0x8) {
1791 /* Dummies to replace askdir.c */
1792 int dir_get_volume_info(JCR *jcr, enum get_vol_info_rw writing) { return 1;}
1793 int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel) { return 1; }
1794 int dir_create_jobmedia_record(JCR *jcr) { return 1; }
1795 int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;}
1796 int dir_send_job_status(JCR *jcr) {return 1;}
1800 int dir_find_next_appendable_volume(JCR *jcr)
1805 int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
1807 /* Close device so user can use autochanger if desired */
1808 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
1811 force_close_dev(dev);
1812 Pmsg1(-1, "%s", dev->errmsg); /* print reason */
1813 fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
1814 jcr->VolumeName, dev_name(dev));
1819 int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev)
1821 /* Close device so user can use autochanger if desired */
1822 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
1825 force_close_dev(dev);
1826 fprintf(stderr, "Mount next Volume on device %s and press return when ready: ",
1829 set_volume_name("TestVolume2", 2);
1837 static int my_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
1841 Pmsg1(000, "End of Volume \"%s\"\n", jcr->VolumeName);
1843 if (LastBlock != block->BlockNumber) {
1844 VolBytes += block->block_len;
1846 LastBlock = block->BlockNumber;
1848 now -= jcr->run_time;
1852 kbs = (double)VolBytes / (1000.0 * (double)now);
1853 Pmsg3(-1, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
1854 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
1856 if (strcmp(jcr->VolumeName, "TestVolume2") == 0) {
1862 set_volume_name("TestVolume2", 2);
1864 create_vol_list(jcr);
1866 dev->state &= ~ST_READ;
1867 if (!acquire_device_for_read(jcr, dev, block)) {
1868 Pmsg2(0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev), jcr->VolumeName);
1871 return 1; /* next volume mounted */
1874 static void set_volume_name(char *VolName, int volnum)
1876 VolumeName = VolName;
1878 pm_strcpy(&jcr->VolumeName, VolName);
1879 bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName));