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-2004 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];
48 bool forge_on = false;
51 * If you change the format of the state file,
52 * increment this value
54 static uint32_t btape_state_level = 2;
57 DEVRES *device = NULL;
60 /* Forward referenced subroutines */
61 static void do_tape_cmds();
62 static void helpcmd();
63 static void scancmd();
64 static void rewindcmd();
65 static void clearcmd();
69 static void fillcmd();
70 static void qfillcmd();
71 static void statcmd();
72 static void unfillcmd();
73 static int flush_block(DEV_BLOCK *block, int dump);
75 static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
77 static int quickie_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
78 static bool compare_blocks(DEV_BLOCK *last_block, DEV_BLOCK *block);
79 static int my_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block);
80 static void scan_blocks();
81 static void set_volume_name(char *VolName, int volnum);
82 static void rawfill_cmd();
83 static void bfill_cmd();
84 static bool open_the_device();
85 static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd);
86 static void autochangercmd();
87 static void do_unfill();
90 /* Static variables */
91 #define CONFIG_FILE "bacula-sd.conf"
94 #define MAX_CMD_ARGS 30
97 static char *argk[MAX_CMD_ARGS];
98 static char *argv[MAX_CMD_ARGS];
101 static int quickie_count = 0;
102 static BSR *bsr = NULL;
103 static int signals = TRUE;
106 static uint64_t vol_size;
107 static uint64_t VolBytes;
110 static int32_t file_index;
111 static int end_of_tape = 0;
112 static uint32_t LastBlock = 0;
113 static uint32_t eot_block;
114 static uint32_t eot_block_len;
115 static uint32_t eot_FileIndex;
116 static int dumped = 0;
117 static DEV_BLOCK *last_block1 = NULL;
118 static DEV_BLOCK *last_block2 = NULL;
119 static DEV_BLOCK *last_block = NULL;
120 static DEV_BLOCK *this_block = NULL;
121 static DEV_BLOCK *first_block = NULL;
122 static uint32_t last_file1 = 0;
123 static uint32_t last_file2 = 0;
124 static uint32_t last_file = 0;
125 static uint32_t last_block_num1 = 0;
126 static uint32_t last_block_num2 = 0;
127 static uint32_t last_block_num = 0;
128 static uint32_t BlockNumber = 0;
129 static bool simple = true;
131 static char *VolumeName = NULL;
132 static int vol_num = 0;
134 static JCR *jcr = NULL;
138 static void terminate_btape(int sig);
139 int get_cmd(char *prompt);
142 /*********************************************************************
144 * Main Bacula Pool Creation Program
147 int main(int margc, char *margv[])
152 if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) {
153 Emsg2(M_ABORT, 0, "Tape block size (%d) not multiple of system size (%d)\n",
154 TAPE_BSIZE, DEV_BSIZE);
156 if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) {
157 Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE);
160 printf("Tape block granularity is %d bytes.\n", TAPE_BSIZE);
162 working_directory = "/tmp";
163 my_name_is(margc, margv, "btape");
164 init_msg(NULL, NULL);
166 while ((ch = getopt(margc, margv, "b:c:d:psv?")) != -1) {
168 case 'b': /* bootstrap file */
169 bsr = parse_bsr(NULL, optarg);
170 // dump_bsr(bsr, true);
173 case 'c': /* specify config file */
174 if (configfile != NULL) {
177 configfile = bstrdup(optarg);
180 case 'd': /* set debug level */
181 debug_level = atoi(optarg);
182 if (debug_level <= 0) {
209 cmd = get_pool_memory(PM_FNAME);
210 args = get_pool_memory(PM_FNAME);
213 init_signals(terminate_btape);
216 if (configfile == NULL) {
217 configfile = bstrdup(CONFIG_FILE);
220 daemon_start_time = time(NULL);
222 parse_config(configfile);
225 /* See if we can open a device */
227 Pmsg0(000, "No archive name specified.\n");
230 } else if (margc != 1) {
231 Pmsg0(000, "Improper number of arguments specified.\n");
236 jcr = setup_jcr("btape", margv[0], bsr, NULL);
237 dev = setup_to_access_device(jcr, 0); /* acquire for write */
241 if (!open_the_device()) {
245 Dmsg0(200, "Do tape commands\n");
253 static void terminate_btape(int stat)
256 sm_check(__FILE__, __LINE__, false);
260 free_config_resources();
262 free_pool_memory(args);
266 free_pool_memory(cmd);
274 if (debug_level > 10)
275 print_memory_pool_stats();
285 free_block(this_block);
289 close_memory_pool(); /* free memory in pool */
295 static bool open_the_device()
299 block = new_block(dev);
301 if (!(dev->state & ST_OPENED)) {
302 Dmsg1(200, "Opening device %s\n", jcr->VolumeName);
303 if (open_dev(dev, jcr->VolumeName, OPEN_READ_WRITE) < 0) {
304 Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
310 Pmsg1(000, "open_dev %s OK\n", dev_name(dev));
323 * Write a label to the tape
325 static void labelcmd()
328 pm_strcpy(&cmd, VolumeName);
330 if (!get_cmd("Enter Volume Name: ")) {
335 if (!(dev->state & ST_OPENED)) {
336 if (!first_open_device(dev)) {
337 Pmsg1(0, "Device open failed. ERR=%s\n", strerror_dev(dev));
341 write_volume_label_to_dev(jcr, jcr->device, cmd, "Default");
342 Pmsg1(-1, "Wrote Volume label for volume \"%s\".\n", cmd);
346 * Read the tape label
348 static void readlabelcmd()
350 int save_debug_level = debug_level;
354 block = new_block(dev);
355 stat = read_dev_volume_label(jcr, dev, block);
358 Pmsg0(0, "Volume has no label.\n");
361 Pmsg0(0, "Volume label read correctly.\n");
364 Pmsg1(0, "I/O error on device: ERR=%s", strerror_dev(dev));
367 Pmsg0(0, "Volume name error\n");
369 case VOL_CREATE_ERROR:
370 Pmsg1(0, "Error creating label. ERR=%s", strerror_dev(dev));
372 case VOL_VERSION_ERROR:
373 Pmsg0(0, "Volume version error.\n");
375 case VOL_LABEL_ERROR:
376 Pmsg0(0, "Bad Volume label type.\n");
379 Pmsg0(0, "Unknown error.\n");
384 dump_volume_label(dev);
385 debug_level = save_debug_level;
391 * Load the tape should have prevously been taken
392 * off line, otherwise this command is not necessary.
394 static void loadcmd()
397 if (!load_dev(dev)) {
398 Pmsg1(0, "Bad status from load. ERR=%s\n", strerror_dev(dev));
400 Pmsg1(0, "Loaded %s\n", dev_name(dev));
406 static void rewindcmd()
408 if (!rewind_dev(dev)) {
409 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
410 clrerror_dev(dev, -1);
412 Pmsg1(0, "Rewound %s\n", dev_name(dev));
417 * Clear any tape error
419 static void clearcmd()
421 clrerror_dev(dev, -1);
425 * Write and end of file on the tape
427 static void weofcmd()
438 if ((stat = weof_dev(dev, num)) < 0) {
439 Pmsg2(0, "Bad status from weof %d. ERR=%s\n", stat, strerror_dev(dev));
442 Pmsg3(0, "Wrote %d EOF%s to %s\n", num, num==1?"":"s", dev_name(dev));
447 /* Go to the end of the medium -- raw command
448 * The idea was orginally that the end of the Bacula
449 * medium would be flagged differently. This is not
450 * currently the case. So, this is identical to the
456 Pmsg1(0, "%s", strerror_dev(dev));
459 Pmsg0(0, _("Moved to end of medium.\n"));
464 * Go to the end of the medium (either hardware determined
465 * or defined by two eofs.
485 if (!bsf_dev(dev, num)) {
486 Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror_dev(dev));
488 Pmsg2(0, _("Backspaced %d file%s.\n"), num, num==1?"":"s");
504 if (!bsr_dev(dev, num)) {
505 Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), strerror_dev(dev));
507 Pmsg2(0, _("Backspaced %d record%s.\n"), num, num==1?"":"s");
512 * List device capabilities as defined in the
517 printf(_("Configured device capabilities:\n"));
518 printf("%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
519 printf("%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
520 printf("%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
521 printf("%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
522 printf("%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
523 printf("%sFASTFSF ", dev->capabilities & CAP_FASTFSF ? "" : "!");
524 printf("%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
525 printf("%sREM ", dev->capabilities & CAP_REM ? "" : "!");
526 printf("%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
527 printf("%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
528 printf("%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
529 printf("%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
530 printf("%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
533 printf(_("Device status:\n"));
534 printf("%sOPENED ", dev->state & ST_OPENED ? "" : "!");
535 printf("%sTAPE ", dev->state & ST_TAPE ? "" : "!");
536 printf("%sLABEL ", dev->state & ST_LABEL ? "" : "!");
537 printf("%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
538 printf("%sAPPEND ", dev->state & ST_APPEND ? "" : "!");
539 printf("%sREAD ", dev->state & ST_READ ? "" : "!");
540 printf("%sEOT ", dev->state & ST_EOT ? "" : "!");
541 printf("%sWEOT ", dev->state & ST_WEOT ? "" : "!");
542 printf("%sEOF ", dev->state & ST_EOF ? "" : "!");
543 printf("%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
544 printf("%sSHORT ", dev->state & ST_SHORT ? "" : "!");
547 printf(_("Device parameters:\n"));
548 printf("Device name: %s\n", dev->dev_name);
549 printf("File=%u block=%u\n", dev->file, dev->block_num);
550 printf("Min block=%u Max block=%u\n", dev->min_block_size, dev->max_block_size);
558 * Test writting larger and larger records.
559 * This is a torture test for records.
561 static void rectestcmd()
567 Pmsg0(0, "Test writting larger and larger records.\n"
568 "This is a torture test for records.\nI am going to write\n"
569 "larger and larger records. It will stop when the record size\n"
570 "plus the header exceeds the block size (by default about 64K)\n");
573 get_cmd("Do you want to continue? (y/n): ");
575 Pmsg0(000, "Command aborted.\n");
579 sm_check(__FILE__, __LINE__, false);
580 block = new_block(dev);
583 for (i=1; i<500000; i++) {
584 rec->data = check_pool_memory_size(rec->data, i);
585 memset(rec->data, i & 0xFF, i);
587 sm_check(__FILE__, __LINE__, false);
588 if (write_record_to_block(block, rec)) {
591 Pmsg2(0, "Block %d i=%d\n", blkno, i);
595 sm_check(__FILE__, __LINE__, false);
599 sm_check(__FILE__, __LINE__, false);
603 * This test attempts to re-read a block written by Bacula
604 * normally at the end of the tape. Bacula will then back up
605 * over the two eof marks, backup over the record and reread
606 * it to make sure it is valid. Bacula can skip this validation
607 * if you set "Backward space record = no"
609 static int re_read_block_test()
616 if (!(dev->capabilities & CAP_BSR)) {
617 Pmsg0(-1, _("Skipping read backwards test because BSR turned off.\n"));
621 Pmsg0(-1, _("\n=== Write, backup, and re-read test ===\n\n"
622 "I'm going to write three records and an EOF\n"
623 "then backup over the EOF and re-read the last record.\n"
624 "Bacula does this after writing the last block on the\n"
625 "tape to verify that the block was written correctly.\n\n"
626 "This is not an *essential* feature ...\n\n"));
628 block = new_block(dev);
630 rec->data = check_pool_memory_size(rec->data, block->buf_len);
631 len = rec->data_len = block->buf_len-100;
632 memset(rec->data, 1, rec->data_len);
633 if (!write_record_to_block(block, rec)) {
634 Pmsg0(0, _("Error writing record to block.\n"));
637 if (!write_block_to_dev(jcr->dcr, block)) {
638 Pmsg0(0, _("Error writing block to device.\n"));
641 Pmsg1(0, _("Wrote first record of %d bytes.\n"), rec->data_len);
643 memset(rec->data, 2, rec->data_len);
644 if (!write_record_to_block(block, rec)) {
645 Pmsg0(0, _("Error writing record to block.\n"));
648 if (!write_block_to_dev(jcr->dcr, block)) {
649 Pmsg0(0, _("Error writing block to device.\n"));
652 Pmsg1(0, _("Wrote second record of %d bytes.\n"), rec->data_len);
654 memset(rec->data, 3, rec->data_len);
655 if (!write_record_to_block(block, rec)) {
656 Pmsg0(0, _("Error writing record to block.\n"));
659 if (!write_block_to_dev(jcr->dcr, block)) {
660 Pmsg0(0, _("Error writing block to device.\n"));
663 Pmsg1(0, _("Wrote third record of %d bytes.\n"), rec->data_len);
666 if (dev_cap(dev, CAP_TWOEOF)) {
669 if (!bsf_dev(dev, 1)) {
670 Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
673 if (dev_cap(dev, CAP_TWOEOF)) {
674 if (!bsf_dev(dev, 1)) {
675 Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
679 Pmsg0(0, "Backspaced over EOF OK.\n");
680 if (!bsr_dev(dev, 1)) {
681 Pmsg1(0, _("Backspace record failed! ERR=%s\n"), strerror_dev(dev));
684 Pmsg0(0, "Backspace record OK.\n");
685 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
686 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
689 memset(rec->data, 0, rec->data_len);
690 if (!read_record_from_block(block, rec)) {
691 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
694 for (int i=0; i<len; i++) {
695 if (rec->data[i] != 3) {
696 Pmsg0(0, _("Bad data in record. Test failed!\n"));
700 Pmsg0(0, _("\nBlock re-read correct. Test succeeded!\n"));
701 Pmsg0(-1, _("=== End Write, backup, and re-read test ===\n\n"));
709 Pmsg0(0, _("This is not terribly serious since Bacula only uses\n"
710 "this function to verify the last block written to the\n"
711 "tape. Bacula will skip the last block verification\n"
713 "Backward Space Record = No\n\n"
714 "to your Storage daemon's Device resource definition.\n"));
721 * This test writes Bacula blocks to the tape in
722 * several files. It then rewinds the tape and attepts
723 * to read these blocks back checking the data.
725 static int write_read_test()
733 Pmsg0(-1, _("\n=== Write, rewind, and re-read test ===\n\n"
734 "I'm going to write 1000 records and an EOF\n"
735 "then write 1000 records and an EOF, then rewind,\n"
736 "and re-read the data to verify that it is correct.\n\n"
737 "This is an *essential* feature ...\n\n"));
738 block = new_block(dev);
740 if (!rewind_dev(dev)) {
741 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
744 rec->data = check_pool_memory_size(rec->data, block->buf_len);
745 rec->data_len = block->buf_len-100;
746 len = rec->data_len/sizeof(i);
747 for (i=1; i<=1000; i++) {
748 p = (int *)rec->data;
749 for (j=0; j<len; j++) {
752 if (!write_record_to_block(block, rec)) {
753 Pmsg0(0, _("Error writing record to block.\n"));
756 if (!write_block_to_dev(jcr->dcr, block)) {
757 Pmsg0(0, _("Error writing block to device.\n"));
761 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
763 for (i=1001; i<=2000; i++) {
764 p = (int *)rec->data;
765 for (j=0; j<len; j++) {
768 if (!write_record_to_block(block, rec)) {
769 Pmsg0(0, _("Error writing record to block.\n"));
772 if (!write_block_to_dev(jcr->dcr, block)) {
773 Pmsg0(0, _("Error writing block to device.\n"));
777 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
779 if (dev_cap(dev, CAP_TWOEOF)) {
782 if (!rewind_dev(dev)) {
783 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
786 Pmsg0(0, "Rewind OK.\n");
788 for (i=1; i<=2000; i++) {
790 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
791 if (dev_state(dev, ST_EOF)) {
792 Pmsg0(-1, _("Got EOF on tape.\n"));
795 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
798 memset(rec->data, 0, rec->data_len);
799 if (!read_record_from_block(block, rec)) {
800 Pmsg1(0, _("Read record failed! ERR=%s\n"), strerror(dev->dev_errno));
803 p = (int *)rec->data;
804 for (j=0; j<len; j++) {
806 Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
812 if (i == 1000 || i == 2000) {
813 Pmsg0(-1, _("1000 blocks re-read correctly.\n"));
816 Pmsg0(-1, _("=== Test Succeeded. End Write, rewind, and re-read test ===\n\n"));
826 * This test writes Bacula blocks to the tape in
827 * several files. It then rewinds the tape and attepts
828 * to read these blocks back checking the data.
830 static int position_test()
838 int file = 0, blk = 0;
841 Pmsg0(-1, _("\n=== Write, rewind, and position test ===\n\n"
842 "I'm going to write 1000 records and an EOF\n"
843 "then write 1000 records and an EOF, then rewind,\n"
844 "and position to a few blocks and verify that it is correct.\n\n"
845 "This is an *essential* feature ...\n\n"));
846 block = new_block(dev);
848 if (!rewind_dev(dev)) {
849 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
852 rec->data = check_pool_memory_size(rec->data, block->buf_len);
853 rec->data_len = block->buf_len-100;
854 len = rec->data_len/sizeof(i);
855 for (i=1; i<=1000; i++) {
856 p = (int *)rec->data;
857 for (j=0; j<len; j++) {
860 if (!write_record_to_block(block, rec)) {
861 Pmsg0(0, _("Error writing record to block.\n"));
864 if (!write_block_to_dev(jcr->dcr, block)) {
865 Pmsg0(0, _("Error writing block to device.\n"));
869 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
871 for (i=1001; i<=2000; i++) {
872 p = (int *)rec->data;
873 for (j=0; j<len; j++) {
876 if (!write_record_to_block(block, rec)) {
877 Pmsg0(0, _("Error writing record to block.\n"));
880 if (!write_block_to_dev(jcr->dcr, block)) {
881 Pmsg0(0, _("Error writing block to device.\n"));
885 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
887 if (dev_cap(dev, CAP_TWOEOF)) {
890 if (!rewind_dev(dev)) {
891 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
894 Pmsg0(0, "Rewind OK.\n");
898 /* Set up next item to read based on where we are */
934 Pmsg2(-1, "Reposition to file:block %d:%d\n", file, blk);
935 if (!reposition_dev(dev, file, blk)) {
936 Pmsg0(0, "Reposition error.\n");
940 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
941 if (dev_state(dev, ST_EOF)) {
942 Pmsg0(-1, _("Got EOF on tape.\n"));
945 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
948 memset(rec->data, 0, rec->data_len);
949 if (!read_record_from_block(block, rec)) {
950 Pmsg1(0, _("Read record failed! ERR=%s\n"), strerror(dev->dev_errno));
953 p = (int *)rec->data;
954 for (j=0; j<len; j++) {
956 Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
961 Pmsg0(-1, _("Block re-read correctly.\n"));
963 Pmsg0(-1, _("=== Test Succeeded. End Write, rewind, and re-read test ===\n\n"));
976 * This test writes some records, then writes an end of file,
977 * rewinds the tape, moves to the end of the data and attepts
978 * to append to the tape. This function is essential for
979 * Bacula to be able to write multiple jobs to the tape.
981 static int append_test()
983 Pmsg0(-1, _("\n\n=== Append files test ===\n\n"
984 "This test is essential to Bacula.\n\n"
985 "I'm going to write one record in file 0,\n"
986 " two records in file 1,\n"
987 " and three records in file 2\n\n"));
991 weofcmd(); /* end file 0 */
994 weofcmd(); /* end file 1 */
998 weofcmd(); /* end file 2 */
999 if (dev_cap(dev, CAP_TWOEOF)) {
1003 Pmsg0(0, _("Now moving to end of medium.\n"));
1005 Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
1006 dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
1008 if (dev->file != 3) {
1012 Pmsg0(-1, _("\nNow the important part, I am going to attempt to append to the tape.\n\n"));
1015 if (dev_cap(dev, CAP_TWOEOF)) {
1019 Pmsg0(-1, _("Done appending, there should be no I/O errors\n\n"));
1020 Pmsg0(-1, "Doing Bacula scan of blocks:\n");
1022 Pmsg0(-1, _("End scanning the tape.\n"));
1023 Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
1024 dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
1026 if (dev->file != 4) {
1034 * This test exercises the autochanger
1036 static int autochanger_test()
1038 POOLMEM *results, *changer;
1039 int slot, status, loaded;
1043 if (!dev_cap(dev, CAP_AUTOCHANGER)) {
1046 if (!(jcr->device && jcr->device->changer_name && jcr->device->changer_command)) {
1047 Pmsg0(-1, "\nAutochanger enabled, but no name or no command device specified.\n");
1051 Pmsg0(-1, "\nAh, I see you have an autochanger configured.\n"
1052 "To test the autochanger you must have a blank tape\n"
1053 " that I can write on in Slot 1.\n");
1054 if (!get_cmd("\nDo you wish to continue with the Autochanger test? (y/n): ")) {
1057 if (cmd[0] != 'y' && cmd[0] != 'Y') {
1061 Pmsg0(-1, _("\n\n=== Autochanger test ===\n\n"));
1063 results = get_pool_memory(PM_MESSAGE);
1064 changer = get_pool_memory(PM_FNAME);
1068 jcr->VolCatInfo.Slot = slot;
1069 /* Find out what is loaded, zero means device is unloaded */
1070 Pmsg0(-1, _("3301 Issuing autochanger \"loaded\" command.\n"));
1071 changer = edit_device_codes(jcr, changer, jcr->device->changer_command,
1073 status = run_program(changer, timeout, results);
1074 Dmsg3(100, "run_prog: %s stat=%d result=%s\n", changer, status, results);
1076 loaded = atoi(results);
1078 Pmsg1(-1, _("3991 Bad autochanger \"load slot\" status=%d.\n"), status);
1079 loaded = -1; /* force unload */
1083 Pmsg1(-1, "Slot %d loaded. I am going to unload it.\n", loaded);
1085 Pmsg0(-1, "Nothing loaded into the drive. OK.\n");
1087 Dmsg1(100, "Results from loaded query=%s\n", results);
1089 offline_or_rewind_dev(dev);
1090 /* We are going to load a new tape, so close the device */
1091 force_close_dev(dev);
1092 Pmsg0(-1, _("3302 Issuing autochanger \"unload\" command.\n"));
1093 changer = edit_device_codes(jcr, changer,
1094 jcr->device->changer_command, "unload");
1095 status = run_program(changer, timeout, NULL);
1096 Pmsg2(-1, "unload status=%s %d\n", status==0?"OK":"Bad", status);
1102 Pmsg1(-1, _("3303 Issuing autochanger \"load slot %d\" command.\n"), slot);
1103 changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "load");
1104 Dmsg1(200, "Changer=%s\n", changer);
1105 status = run_program(changer, timeout, NULL);
1107 Pmsg1(-1, _("3304 Autochanger \"load slot %d\" status is OK.\n"), slot);
1109 Pmsg1(-1, _("3992 Bad autochanger \"load slot\" status=%d.\n"), status);
1113 if (!open_the_device()) {
1116 bmicrosleep(sleep_time, 0);
1117 if (!rewind_dev(dev)) {
1118 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
1119 clrerror_dev(dev, -1);
1120 Pmsg0(-1, "\nThe test failed, probably because you need to put\n"
1121 "a longer sleep time in the mtx-script in the load) case.\n"
1122 "Adding a 30 second sleep and trying again ...\n");
1126 Pmsg1(0, "Rewound %s\n", dev_name(dev));
1129 if ((status = weof_dev(dev, 1)) < 0) {
1130 Pmsg2(0, "Bad status from weof %d. ERR=%s\n", status, strerror_dev(dev));
1133 Pmsg1(0, "Wrote EOF to %s\n", dev_name(dev));
1137 Pmsg1(-1, "\nThe test worked this time. Please add:\n\n"
1139 "to your mtx-changer script in the load) case.\n\n",
1142 Pmsg0(-1, "\nThe test autochanger worked!!\n\n");
1145 free_pool_memory(changer);
1146 free_pool_memory(results);
1151 free_pool_memory(changer);
1152 free_pool_memory(results);
1153 Pmsg0(-1, "You must correct this error or the Autochanger will not work.\n");
1157 static void autochangercmd()
1164 * This test assumes that the append test has been done,
1165 * then it tests the fsf function.
1167 static int fsf_test()
1169 bool set_off = false;
1171 Pmsg0(-1, _("\n\n=== Forward space files test ===\n\n"
1172 "This test is essential to Bacula.\n\n"
1173 "I'm going to write five files then test forward spacing\n\n"));
1177 weofcmd(); /* end file 0 */
1180 weofcmd(); /* end file 1 */
1184 weofcmd(); /* end file 2 */
1187 weofcmd(); /* end file 3 */
1189 weofcmd(); /* end file 4 */
1190 if (dev_cap(dev, CAP_TWOEOF)) {
1196 Pmsg0(0, _("Now forward spacing 1 file.\n"));
1197 if (!fsf_dev(dev, 1)) {
1198 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1201 Pmsg2(-1, _("We should be in file 1. I am at file %d. This is %s\n"),
1202 dev->file, dev->file == 1 ? "correct!" : "NOT correct!!!!");
1204 if (dev->file != 1) {
1208 Pmsg0(0, _("Now forward spacing 2 files.\n"));
1209 if (!fsf_dev(dev, 2)) {
1210 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1213 Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
1214 dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
1216 if (dev->file != 3) {
1221 Pmsg0(0, _("Now forward spacing 4 files.\n"));
1222 if (!fsf_dev(dev, 4)) {
1223 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1226 Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
1227 dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
1229 if (dev->file != 4) {
1233 Pmsg0(-1, "The test worked this time. Please add:\n\n"
1234 " Fast Forward Space File = no\n\n"
1235 "to your Device resource for this drive.\n");
1239 Pmsg0(0, _("Now forward spacing 1 more file.\n"));
1240 if (!fsf_dev(dev, 1)) {
1241 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1243 Pmsg2(-1, _("We should be in file 5. I am at file %d. This is %s\n"),
1244 dev->file, dev->file == 5 ? "correct!" : "NOT correct!!!!");
1245 if (dev->file != 5) {
1248 Pmsg0(-1, _("\n=== End Forward space files test ===\n\n"));
1252 Pmsg0(-1, _("\nThe forward space file test failed.\n"));
1253 if (dev_cap(dev, CAP_FASTFSF)) {
1254 Pmsg0(-1, "You have Fast Forward Space File enabled.\n"
1255 "I am turning it off then retrying the test.\n");
1256 dev->capabilities &= ~CAP_FASTFSF;
1260 Pmsg0(-1, "You must correct this error or Bacula will not work.\n");
1269 * This is a general test of Bacula's functions
1270 * needed to read and write the tape.
1272 static void testcmd()
1276 if (!write_read_test()) {
1279 if (!position_test()) {
1283 stat = append_test();
1284 if (stat == 1) { /* OK get out */
1287 if (stat == -1) { /* first test failed */
1288 if (dev_cap(dev, CAP_EOM) || dev_cap(dev, CAP_FASTFSF)) {
1289 Pmsg0(-1, "\nAppend test failed. Attempting again.\n"
1290 "Setting \"Hardware End of Medium = no\n"
1291 " and \"Fast Forward Space File = no\n"
1292 "and retrying append test.\n\n");
1293 dev->capabilities &= ~CAP_EOM; /* turn off eom */
1294 dev->capabilities &= ~CAP_FASTFSF; /* turn off fast fsf */
1295 stat = append_test();
1297 Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
1298 " Hardware End of Medium = No\n\n"
1299 " Fast Forward Space File = No\n"
1300 "to your Device resource in the Storage conf file.\n");
1304 Pmsg0(-1, "\n\nThat appears *NOT* to have corrected the problem.\n");
1307 /* Wrong count after append */
1309 Pmsg0(-1, "\n\nIt looks like the append failed. Attempting again.\n"
1310 "Setting \"BSF at EOM = yes\" and retrying append test.\n");
1311 dev->capabilities |= CAP_BSFATEOM; /* backspace on eom */
1312 stat = append_test();
1314 Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
1315 " Hardware End of Medium = No\n"
1316 " Fast Forward Space File = No\n"
1317 " BSF at EOM = yes\n\n"
1318 "to your Device resource in the Storage conf file.\n");
1325 Pmsg0(-1, "\nAppend test failed.\n\n");
1326 Pmsg0(-1, "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
1327 "Unable to correct the problem. You MUST fix this\n"
1328 "problem before Bacula can use your tape drive correctly\n");
1329 Pmsg0(-1, "\nPerhaps running Bacula in fixed block mode will work.\n"
1330 "Do so by setting:\n\n"
1331 "Minimum Block Size = nnn\n"
1332 "Maximum Block Size = nnn\n\n"
1333 "in your Storage daemon's Device definition.\n"
1334 "nnn must match your tape driver's block size, which\n"
1335 "can be determined by reading your tape manufacturers\n"
1336 "information, and the information on your kernel dirver.\n"
1337 "Fixed block sizes, however, are not normally an ideal solution.\n");
1342 Pmsg0(-1, _("\nThe above Bacula scan should have output identical to what follows.\n"
1343 "Please double check it ...\n"
1344 "=== Sample correct output ===\n"
1345 "1 block of 64448 bytes in file 1\n"
1346 "End of File mark.\n"
1347 "2 blocks of 64448 bytes in file 2\n"
1348 "End of File mark.\n"
1349 "3 blocks of 64448 bytes in file 3\n"
1350 "End of File mark.\n"
1351 "1 block of 64448 bytes in file 4\n"
1352 "End of File mark.\n"
1353 "Total files=4, blocks=7, bytes = 451,136\n"
1354 "=== End sample correct output ===\n\n"));
1356 Pmsg0(-1, _("If the above scan output is not identical to the\n"
1357 "sample output, you MUST correct the problem\n"
1358 "or Bacula will not be able to write multiple Jobs to \n"
1362 re_read_block_test();
1365 fsf_test(); /* do fast forward space file test */
1367 autochanger_test(); /* do autochanger test */
1371 /* Forward space a file */
1372 static void fsfcmd()
1376 num = atoi(argk[1]);
1381 if (!fsf_dev(dev, num)) {
1382 Pmsg1(0, "Bad status from fsf. ERR=%s\n", strerror_dev(dev));
1385 Pmsg2(0, "Forward spaced %d file%s.\n", num, num==1?"":"s");
1388 /* Forward space a record */
1389 static void fsrcmd()
1393 num = atoi(argk[1]);
1398 if (!fsr_dev(dev, num)) {
1399 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1402 Pmsg2(0, "Forward spaced %d record%s.\n", num, num==1?"":"s");
1407 * Write a Bacula block to the tape
1415 sm_check(__FILE__, __LINE__, false);
1416 block = new_block(dev);
1418 dump_block(block, "test");
1420 i = block->buf_len - 100;
1422 rec->data = check_pool_memory_size(rec->data, i);
1423 memset(rec->data, i & 0xFF, i);
1425 sm_check(__FILE__, __LINE__, false);
1426 if (!write_record_to_block(block, rec)) {
1427 Pmsg0(0, _("Error writing record to block.\n"));
1430 if (!write_block_to_dev(jcr->dcr, block)) {
1431 Pmsg0(0, _("Error writing block to device.\n"));
1434 Pmsg1(0, _("Wrote one record of %d bytes.\n"), i);
1436 Pmsg0(0, _("Wrote block to device.\n"));
1439 sm_check(__FILE__, __LINE__, false);
1442 sm_check(__FILE__, __LINE__, false);
1446 * Read a record from the tape
1453 if (!get_cmd("Enter length to read: ")) {
1457 if (len < 0 || len > 1000000) {
1458 Pmsg0(0, _("Bad length entered, using default of 1024 bytes.\n"));
1461 buf = (char *)malloc(len);
1462 stat = read(dev->fd, buf, len);
1463 if (stat > 0 && stat <= len) {
1466 Pmsg3(0, _("Read of %d bytes gives stat=%d. ERR=%s\n"),
1467 len, stat, strerror(errno));
1473 * Scan tape by reading block by block. Report what is
1474 * on the tape. Note, this command does raw reads, and as such
1475 * will not work with fixed block size devices.
1477 static void scancmd()
1480 int blocks, tot_blocks, tot_files;
1486 blocks = block_size = tot_blocks = 0;
1488 if (dev->state & ST_EOT) {
1489 Pmsg0(0, "End of tape\n");
1492 update_pos_dev(dev);
1493 tot_files = dev->file;
1494 Pmsg1(0, _("Starting scan at file %u\n"), dev->file);
1496 if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) {
1497 clrerror_dev(dev, -1);
1498 Mmsg2(&dev->errmsg, "read error on %s. ERR=%s.\n",
1499 dev->dev_name, strerror(dev->dev_errno));
1500 Pmsg2(0, "Bad status from read %d. ERR=%s\n", stat, strerror_dev(dev));
1502 printf("%d block%s of %d bytes in file %d\n",
1503 blocks, blocks>1?"s":"", block_size, dev->file);
1506 Dmsg1(200, "read status = %d\n", stat);
1508 if (stat != block_size) {
1509 update_pos_dev(dev);
1511 printf("%d block%s of %d bytes in file %d\n",
1512 blocks, blocks>1?"s":"", block_size, dev->file);
1517 if (stat == 0) { /* EOF */
1518 update_pos_dev(dev);
1519 printf("End of File mark.\n");
1520 /* Two reads of zero means end of tape */
1521 if (dev->state & ST_EOF)
1522 dev->state |= ST_EOT;
1524 dev->state |= ST_EOF;
1527 if (dev->state & ST_EOT) {
1528 printf("End of tape\n");
1531 } else { /* Got data */
1532 dev->state &= ~ST_EOF;
1538 update_pos_dev(dev);
1539 tot_files = dev->file - tot_files;
1540 printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
1541 edit_uint64_with_commas(bytes, ec1));
1546 * Scan tape by reading Bacula block by block. Report what is
1547 * on the tape. This function reads Bacula blocks, so if your
1548 * Device resource is correctly defined, it should work with
1549 * either variable or fixed block sizes.
1551 static void scan_blocks()
1553 int blocks, tot_blocks, tot_files;
1554 uint32_t block_size;
1559 block = new_block(dev);
1560 blocks = block_size = tot_blocks = 0;
1563 update_pos_dev(dev);
1564 tot_files = dev->file;
1566 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
1567 Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
1568 if (dev->state & ST_EOT) {
1570 printf("%d block%s of %d bytes in file %d\n",
1571 blocks, blocks>1?"s":"", block_size, dev->file);
1576 if (dev->state & ST_EOF) {
1578 printf("%d block%s of %d bytes in file %d\n",
1579 blocks, blocks>1?"s":"", block_size, dev->file);
1582 printf(_("End of File mark.\n"));
1585 if (dev->state & ST_SHORT) {
1587 printf("%d block%s of %d bytes in file %d\n",
1588 blocks, blocks>1?"s":"", block_size, dev->file);
1591 printf(_("Short block read.\n"));
1594 printf(_("Error reading block. ERR=%s\n"), strerror_dev(dev));
1597 if (block->block_len != block_size) {
1599 printf("%d block%s of %d bytes in file %d\n",
1600 blocks, blocks>1?"s":"", block_size, dev->file);
1603 block_size = block->block_len;
1607 bytes += block->block_len;
1608 Dmsg6(100, "Blk_blk=%u dev_blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
1609 block->BlockNumber, dev->block_num, block->block_len, block->BlockVer,
1610 block->VolSessionId, block->VolSessionTime);
1612 DEV_RECORD *rec = new_record();
1613 read_record_from_block(block, rec);
1614 Pmsg8(-1, "Blk_block: %u dev_blk=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
1615 block->BlockNumber, dev->block_num, block->block_len,
1616 FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
1617 stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
1620 } else if (verbose > 1) {
1621 dump_block(block, "");
1627 tot_files = dev->file - tot_files;
1628 printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
1629 edit_uint64_with_commas(bytes, ec1));
1633 static void statcmd()
1635 int debug = debug_level;
1637 Pmsg2(0, "Device status: %u. ERR=%s\n", status_dev(dev), strerror_dev(dev));
1639 dump_volume_label(dev);
1641 debug_level = debug;
1646 * First we label the tape, then we fill
1647 * it with data get a new tape and write a few blocks.
1649 static void fillcmd()
1656 uint32_t min_block_size;
1666 This command simulates Bacula writing to a tape.\n\
1667 It requires either one or two blank tapes, which it\n\
1668 will label and write.\n\n\
1669 If you have an autochanger configured, it will use\n\
1670 the tapes that are in slots 1 and 2, otherwise, you will\n\
1671 be prompted to insert the tapes when necessary.\n\n\
1672 It will print a status approximately\n\
1673 every 322 MB, and write an EOF every 3.2 GB. If you have\n\
1674 selected the simple test option, after writing the first tape\n\
1675 it will rewind it and re-read the last block written.\n\n\
1676 If you have selected the multiple tape test, when the first tape\n\
1677 fills, it will ask for a second, and after writing a few more \n\
1678 blocks, it will stop. Then it will begin re-reading the\n\
1680 This may take a long time -- hours! ...\n\n");
1682 get_cmd("Do you want to run the simplified test (s) with one tape\n"
1683 "or the complete multiple tape (m) test: (s/m) ");
1684 if (cmd[0] == 's') {
1685 Pmsg0(-1, "Simple test (single tape) selected.\n");
1687 } else if (cmd[0] == 'm') {
1688 Pmsg0(-1, "Multiple tape test selected.\n");
1691 Pmsg0(000, "Command aborted.\n");
1695 Dmsg1(20, "Begin append device=%s\n", dev_name(dev));
1696 Dmsg1(20, "MaxVolSize=%s\n", edit_uint64(dev->max_volume_size, ec1));
1698 /* Use fixed block size to simplify read back */
1699 min_block_size = dev->min_block_size;
1700 dev->min_block_size = dev->max_block_size;
1703 * Acquire output device for writing. Note, after acquiring a
1704 * device, we MUST release it, which is done at the end of this
1707 Dmsg0(100, "just before acquire_device\n");
1708 if (!acquire_device_for_append(jcr)) {
1709 set_jcr_job_status(jcr, JS_ErrorTerminated);
1712 block = jcr->dcr->block;
1714 Dmsg0(100, "Just after acquire_device_for_append\n");
1716 * Write Begin Session Record
1718 if (!write_session_label(jcr, block, SOS_LABEL)) {
1719 set_jcr_job_status(jcr, JS_ErrorTerminated);
1720 Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
1724 Pmsg0(-1, "Wrote Start Of Session label.\n");
1726 memset(&rec, 0, sizeof(rec));
1727 rec.data = get_memory(100000); /* max record size */
1729 #define REC_SIZE 32768
1730 rec.data_len = REC_SIZE;
1733 * Put some random data in the record
1735 fd = open("/dev/urandom", O_RDONLY);
1737 read(fd, rec.data, rec.data_len);
1740 uint32_t *p = (uint32_t *)rec.data;
1741 srandom(time(NULL));
1742 for (i=0; i<rec.data_len/sizeof(uint32_t); i++) {
1748 * Generate data as if from File daemon, write to device
1750 jcr->dcr->VolFirstIndex = 0;
1751 time(&jcr->run_time); /* start counting time for rates */
1753 Pmsg0(-1, "Begin writing Bacula records to tape ...\n");
1755 Pmsg0(-1, "Begin writing Bacula records to first tape ...\n");
1757 for (file_index = 0; ok && !job_canceled(jcr); ) {
1758 rec.VolSessionId = jcr->VolSessionId;
1759 rec.VolSessionTime = jcr->VolSessionTime;
1760 rec.FileIndex = ++file_index;
1761 rec.Stream = STREAM_FILE_DATA;
1763 /* Mix up the data just a bit */
1764 uint32_t *lp = (uint32_t *)rec.data;
1766 for (i=1; i < (rec.data_len-sizeof(uint32_t))/sizeof(uint32_t)-1; i++) {
1770 Dmsg4(250, "before write_rec FI=%d SessId=%d Strm=%s len=%d\n",
1771 rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream, rec.FileIndex),
1774 while (!write_record_to_block(block, &rec)) {
1776 * When we get here we have just filled a block
1778 Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
1781 /* Write block to tape */
1782 if (!flush_block(block, 1)) {
1786 /* Every 5000 blocks (approx 322MB) report where we are.
1788 if ((block->BlockNumber % 5000) == 0) {
1790 now -= jcr->run_time;
1792 now = 1; /* prevent divide error */
1794 kbs = (double)dev->VolCatInfo.VolCatBytes / (1000.0 * (double)now);
1795 Pmsg4(-1, "Wrote blk_block=%u, dev_blk_num=%u VolBytes=%s rate=%.1f KB/s\n",
1796 block->BlockNumber, dev->block_num,
1797 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), (float)kbs);
1799 /* Every 15000 blocks (approx 1GB) write an EOF.
1801 if ((block->BlockNumber % 15000) == 0) {
1802 Pmsg0(-1, "Flush block, write EOF\n");
1803 flush_block(block, 0);
1807 /* Get out after writing 10 blocks to the second tape */
1808 if (++BlockNumber > 10 && stop != 0) { /* get out */
1813 Pmsg0(000, _("Not OK\n"));
1816 jcr->JobBytes += rec.data_len; /* increment bytes this job */
1817 Dmsg4(190, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
1818 FI_to_ascii(rec.FileIndex), rec.VolSessionId,
1819 stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
1821 /* Get out after writing 10 blocks to the second tape */
1822 if (BlockNumber > 10 && stop != 0) { /* get out */
1823 Pmsg0(-1, "Done writing ...\n");
1828 Dmsg0(100, "Write_end_session_label()\n");
1829 /* Create Job status for end of session label */
1830 if (!job_canceled(jcr) && ok) {
1831 set_jcr_job_status(jcr, JS_Terminated);
1833 set_jcr_job_status(jcr, JS_ErrorTerminated);
1835 if (!write_session_label(jcr, block, EOS_LABEL)) {
1836 Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev));
1839 /* Write out final block of this session */
1840 if (!write_block_to_device(jcr->dcr, block)) {
1841 Pmsg0(-1, _("Set ok=false after write_block_to_device.\n"));
1844 Pmsg0(-1, _("Wrote End Of Session label.\n"));
1846 /* Save last block info for second tape */
1847 last_block_num2 = last_block_num;
1848 last_file2 = last_file;
1850 free_block(last_block2);
1852 last_block2 = dup_block(last_block);
1855 sprintf(buf, "%s/btape.state", working_directory);
1856 fd = open(buf, O_CREAT|O_TRUNC|O_WRONLY, 0640);
1858 write(fd, &btape_state_level, sizeof(btape_state_level));
1859 write(fd, &simple, sizeof(simple));
1860 write(fd, &last_block_num1, sizeof(last_block_num1));
1861 write(fd, &last_block_num2, sizeof(last_block_num2));
1862 write(fd, &last_file1, sizeof(last_file1));
1863 write(fd, &last_file2, sizeof(last_file2));
1864 write(fd, last_block1->buf, last_block1->buf_len);
1865 write(fd, last_block2->buf, last_block2->buf_len);
1866 write(fd, first_block->buf, first_block->buf_len);
1868 Pmsg2(-1, "Wrote state file last_block_num1=%d last_block_num2=%d\n",
1869 last_block_num1, last_block_num2);
1871 Pmsg2(-1, _("Could not create state file: %s ERR=%s\n"), buf,
1875 /* Release the device */
1876 if (!release_device(jcr)) {
1877 Pmsg0(-1, _("Error in release_device\n"));
1882 Pmsg2(-1, _("\n\nDone filling tape%s. Now beginning re-read of %stape ...\n"),
1883 simple?"":"s", simple?"":"first ");
1887 dev->min_block_size = min_block_size;
1888 free_memory(rec.data);
1892 * Read two tapes written by the "fill" command and ensure
1893 * that the data is valid. If stop==1 we simulate full read back
1894 * of two tapes. If stop==-1 we simply read the last block and
1895 * verify that it is correct.
1897 static void unfillcmd()
1901 last_block1 = new_block(dev);
1902 last_block2 = new_block(dev);
1903 first_block = new_block(dev);
1904 sprintf(buf, "%s/btape.state", working_directory);
1905 fd = open(buf, O_RDONLY);
1907 uint32_t state_level;
1908 read(fd, &state_level, sizeof(btape_state_level));
1909 read(fd, &simple, sizeof(simple));
1910 read(fd, &last_block_num1, sizeof(last_block_num1));
1911 read(fd, &last_block_num2, sizeof(last_block_num2));
1912 read(fd, &last_file1, sizeof(last_file1));
1913 read(fd, &last_file2, sizeof(last_file2));
1914 read(fd, last_block1->buf, last_block1->buf_len);
1915 read(fd, last_block2->buf, last_block2->buf_len);
1916 read(fd, first_block->buf, first_block->buf_len);
1918 if (state_level != btape_state_level) {
1919 Pmsg0(-1, "\nThe state file level has changed. You must redo\n"
1920 "the fill command.\n");
1924 Pmsg2(-1, "\nCould not find the state file: %s ERR=%s\n"
1925 "You must redo the fill command.\n", buf, strerror(errno));
1932 static void do_unfill()
1940 block = new_block(dev);
1942 Dmsg0(20, "Enter do_unfill\n");
1943 dev->capabilities |= CAP_ANONVOLS; /* allow reading any volume */
1944 dev->capabilities &= ~CAP_LABEL; /* don't label anything here */
1948 time(&jcr->run_time); /* start counting time for rates */
1952 free_block(last_block);
1954 last_block_num = last_block_num1;
1955 last_file = last_file1;
1956 last_block = last_block1;
1959 /* Multiple Volume tape */
1960 /* Close device so user can use autochanger if desired */
1961 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
1964 autochanger = autoload_device(jcr, dev, 1, NULL);
1966 force_close_dev(dev);
1967 get_cmd(_("Mount first tape. Press enter when ready: "));
1971 set_volume_name("TestVolume1", 1);
1973 create_vol_list(jcr);
1975 dev->state &= ~ST_READ;
1976 if (!acquire_device_for_read(jcr)) {
1977 Pmsg1(-1, "%s", dev->errmsg);
1982 * We now have the first tape mounted.
1983 * Note, re-reading last block may have caused us to
1984 * loose track of where we are (block number unknown).
1986 rewind_dev(dev); /* get to a known place on tape */
1987 /* Read the first 1000 records */
1988 Pmsg0(-1, _("Reading the first 1000 records.\n"));
1989 read_records(jcr, dev, quickie_cb, my_mount_next_read_volume);
1990 Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
1991 last_file, last_block_num);
1992 if (!reposition_dev(dev, last_file, last_block_num)) {
1993 Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev));
1995 Pmsg1(-1, _("Reading block %u.\n"), last_block_num);
1996 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
1997 Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
2000 if (compare_blocks(last_block, block)) {
2002 Pmsg0(-1, _("\nThe last block on the tape matches. Test succeeded.\n\n"));
2004 Pmsg0(-1, _("\nThe last block of the first tape matches.\n\n"));
2011 /* restore info for last block on second Volume */
2012 last_block_num = last_block_num2;
2013 last_file = last_file2;
2014 last_block = last_block2;
2016 /* Multiple Volume tape */
2017 /* Close device so user can use autochanger if desired */
2018 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
2023 set_volume_name("TestVolume2", 2);
2025 create_vol_list(jcr);
2026 autochanger = autoload_device(jcr, dev, 1, NULL);
2028 force_close_dev(dev);
2029 get_cmd(_("Mount second tape. Press enter when ready: "));
2032 dev->state &= ~ST_READ;
2033 if (!acquire_device_for_read(jcr)) {
2034 Pmsg1(-1, "%s", dev->errmsg);
2038 /* Space to "first" block which is last block not written
2039 * on the previous tape.
2041 Pmsg2(-1, _("Reposition from %u:%u to 0:1\n"), dev->file, dev->block_num);
2042 if (!reposition_dev(dev, 0, 1)) {
2043 Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev));
2046 Pmsg1(-1, _("Reading block %d.\n"), dev->block_num);
2047 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
2048 Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
2051 if (compare_blocks(first_block, block)) {
2052 Pmsg0(-1, _("\nThe first block on the second tape matches.\n\n"));
2055 /* Now find and compare the last block */
2056 Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
2057 last_file, last_block_num);
2058 if (!reposition_dev(dev, last_file, last_block_num)) {
2059 Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev));
2062 Pmsg1(-1, _("Reading block %d.\n"), dev->block_num);
2063 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
2064 Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
2067 if (compare_blocks(last_block, block)) {
2068 Pmsg0(-1, _("\nThe last block on the second tape matches. Test succeeded.\n\n"));
2073 free_block(last_block1);
2074 free_block(last_block2);
2075 free_block(first_block);
2078 /* Read 1000 records then stop */
2079 static int quickie_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
2082 return quickie_count <= 1000;
2085 static bool compare_blocks(DEV_BLOCK *last_block, DEV_BLOCK *block)
2088 uint32_t CheckSum, block_len;
2091 p = last_block->buf;
2093 unser_begin(q, BLKHDR2_LENGTH);
2094 unser_uint32(CheckSum);
2095 unser_uint32(block_len);
2096 while (q < (block->buf+block_len)) {
2103 dump_block(last_block, _("Last block written"));
2105 dump_block(block, _("Block read back"));
2106 Pmsg1(-1, "\n\nThe blocks differ at byte %u\n", p - last_block->buf);
2107 Pmsg0(-1, "\n\n!!!! The last block written and the block\n"
2108 "that was read back differ. The test FAILED !!!!\n"
2109 "This must be corrected before you use Bacula\n"
2110 "to write multi-tape Volumes.!!!!\n");
2114 dump_block(last_block, _("Last block written"));
2115 dump_block(block, _("Block read back"));
2125 * Write current block to tape regardless of whether or
2126 * not it is full. If the tape fills, attempt to
2127 * acquire another tape.
2129 static int flush_block(DEV_BLOCK *block, int dump)
2134 uint32_t this_file, this_block_num;
2137 this_block = new_block(dev);
2140 last_block = new_block(dev);
2143 this_file = dev->file;
2144 this_block_num = dev->block_num;
2145 if (!write_block_to_dev(jcr->dcr, block)) {
2146 Pmsg3(000, "Last block at: %u:%u this_dev_block_num=%d\n",
2147 last_file, last_block_num, this_block_num);
2150 * This is 1st tape, so save first tape info separate
2151 * from second tape info
2153 last_block_num1 = last_block_num;
2154 last_file1 = last_file;
2155 last_block1 = dup_block(last_block);
2156 last_block2 = dup_block(last_block);
2157 first_block = dup_block(block); /* first block second tape */
2160 Pmsg3(000, "Block not written: FileIndex=%u blk_block=%u Size=%u\n",
2161 (unsigned)file_index, block->BlockNumber, block->block_len);
2162 dump_block(last_block, "Last block written");
2164 dump_block(block, "Block not written");
2167 eot_block = block->BlockNumber;
2168 eot_block_len = block->block_len;
2169 eot_FileIndex = file_index;
2173 now -= jcr->run_time;
2175 now = 1; /* don't divide by zero */
2177 kbs = (double)dev->VolCatInfo.VolCatBytes / (1000 * now);
2178 vol_size = dev->VolCatInfo.VolCatBytes;
2179 Pmsg2(000, "End of tape. VolumeCapacity=%s. Write rate = %.1f KB/s\n",
2180 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), kbs);
2183 stop = -1; /* stop, but do simplified test */
2185 /* Full test in progress */
2186 if (!fixup_device_block_write_error(jcr, dev, block)) {
2187 Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev));
2192 BlockNumber = 0; /* start counting for second tape */
2195 return 1; /* end of tape reached */
2198 /* Save contents after write so that the header is serialized */
2199 memcpy(this_block->buf, block->buf, this_block->buf_len);
2202 * Toggle between two allocated blocks for efficiency.
2203 * Switch blocks so that the block just successfully written is
2204 * always in last_block.
2206 tblock = last_block;
2207 last_block = this_block;
2208 this_block = tblock;
2209 last_file = this_file;
2210 last_block_num = this_block_num;
2218 * First we label the tape, then we fill
2219 * it with data get a new tape and write a few blocks.
2221 static void qfillcmd()
2227 Pmsg0(0, "Test writing blocks of 64512 bytes to tape.\n");
2229 get_cmd("How many blocks do you want to write? (1000): ");
2236 sm_check(__FILE__, __LINE__, false);
2237 block = new_block(dev);
2240 i = block->buf_len - 100;
2242 rec->data = check_pool_memory_size(rec->data, i);
2243 memset(rec->data, i & 0xFF, i);
2246 Pmsg1(0, "Begin writing %d Bacula blocks to tape ...\n", count);
2247 for (i=0; i < count; i++) {
2252 if (!write_record_to_block(block, rec)) {
2253 Pmsg0(0, _("Error writing record to block.\n"));
2256 if (!write_block_to_dev(jcr->dcr, block)) {
2257 Pmsg0(0, _("Error writing block to device.\n"));
2263 if (dev_cap(dev, CAP_TWOEOF)) {
2270 sm_check(__FILE__, __LINE__, false);
2273 sm_check(__FILE__, __LINE__, false);
2278 * Fill a tape using raw write() command
2280 static void rawfill_cmd()
2285 uint32_t block_num = 0;
2290 block = new_block(dev);
2291 fd = open("/dev/urandom", O_RDONLY);
2293 read(fd, block->buf, block->buf_len);
2296 uint32_t *p = (uint32_t *)block->buf;
2297 srandom(time(NULL));
2298 for (i=0; i<block->buf_len/sizeof(uint32_t); i++) {
2302 p = (uint32_t *)block->buf;
2303 Pmsg1(0, "Begin writing raw blocks of %u bytes.\n", block->buf_len);
2306 stat = write(dev->fd, block->buf, block->buf_len);
2307 if (stat == (int)block->buf_len) {
2308 if ((block_num++ % 100) == 0) {
2313 for (i=1; i<(block->buf_len-sizeof(uint32_t))/sizeof(uint32_t)-1; i++) {
2322 printf("Write failed at block %u. stat=%d ERR=%s\n", block_num, stat,
2323 strerror(my_errno));
2330 * Fill a tape using raw write() command
2332 static void bfill_cmd()
2335 uint32_t block_num = 0;
2341 block = new_block(dev);
2342 fd = open("/dev/urandom", O_RDONLY);
2344 read(fd, block->buf, block->buf_len);
2347 uint32_t *p = (uint32_t *)block->buf;
2348 srandom(time(NULL));
2349 for (i=0; i<block->buf_len/sizeof(uint32_t); i++) {
2353 p = (uint32_t *)block->buf;
2354 Pmsg1(0, "Begin writing Bacula blocks of %u bytes.\n", block->buf_len);
2357 block->binbuf = block->buf_len;
2358 block->bufp = block->buf + block->binbuf;
2359 if (!write_block_to_dev(jcr->dcr, block)) {
2362 if ((block_num++ % 100) == 0) {
2367 for (i=1; i<(block->buf_len/sizeof(uint32_t)-1); i++) {
2373 printf("Write failed at block %u.\n", block_num);
2379 struct cmdstruct { char *key; void (*func)(); char *help; };
2380 static struct cmdstruct commands[] = {
2381 {"autochanger", autochangercmd, "test autochanger"},
2382 {"bsf", bsfcmd, "backspace file"},
2383 {"bsr", bsrcmd, "backspace record"},
2384 {"bfill", bfill_cmd, "fill tape using Bacula writes"},
2385 {"cap", capcmd, "list device capabilities"},
2386 {"clear", clearcmd, "clear tape errors"},
2387 {"eod", eodcmd, "go to end of Bacula data for append"},
2388 {"eom", eomcmd, "go to the physical end of medium"},
2389 {"fill", fillcmd, "fill tape, write onto second volume"},
2390 {"unfill", unfillcmd, "read filled tape"},
2391 {"fsf", fsfcmd, "forward space a file"},
2392 {"fsr", fsrcmd, "forward space a record"},
2393 {"help", helpcmd, "print this command"},
2394 {"label", labelcmd, "write a Bacula label to the tape"},
2395 {"load", loadcmd, "load a tape"},
2396 {"quit", quitcmd, "quit btape"},
2397 {"rawfill", rawfill_cmd, "use write() to fill tape"},
2398 {"readlabel", readlabelcmd, "read and print the Bacula tape label"},
2399 {"rectest", rectestcmd, "test record handling functions"},
2400 {"rewind", rewindcmd, "rewind the tape"},
2401 {"scan", scancmd, "read() tape block by block to EOT and report"},
2402 {"scanblocks", scan_blocks, "Bacula read block by block to EOT and report"},
2403 {"status", statcmd, "print tape status"},
2404 {"test", testcmd, "General test Bacula tape functions"},
2405 {"weof", weofcmd, "write an EOF on the tape"},
2406 {"wr", wrcmd, "write a single Bacula block"},
2407 {"rr", rrcmd, "read a single record"},
2408 {"qfill", qfillcmd, "quick fill command"},
2410 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
2418 while (get_cmd("*")) {
2419 sm_check(__FILE__, __LINE__, false);
2421 parse_args(cmd, &args, &argc, argk, argv, MAX_CMD_ARGS);
2422 for (i=0; i<comsize; i++) /* search for command */
2423 if (argc > 0 && fstrsch(argk[0], commands[i].key)) {
2424 (*commands[i].func)(); /* go execute command */
2429 Pmsg1(0, _("%s is an illegal command\n"), cmd);
2435 static void helpcmd()
2439 printf(_("Interactive commands:\n"));
2440 printf(_(" Command Description\n ======= ===========\n"));
2441 for (i=0; i<comsize; i++)
2442 printf(" %-10s %s\n", commands[i].key, commands[i].help);
2449 "\nVersion: " VERSION " (" BDATE ")\n\n"
2450 "Usage: btape <options> <device_name>\n"
2451 " -b <file> specify bootstrap file\n"
2452 " -c <file> set configuration file to file\n"
2453 " -d <nn> set debug level to nn\n"
2454 " -p proceed inspite of I/O errors\n"
2455 " -s turn off signals\n"
2457 " -? print this message.\n"
2463 * Get next input command from terminal. This
2464 * routine is REALLY primitive, and should be enhanced
2465 * to have correct backspacing, etc.
2468 get_cmd(char *prompt)
2472 fprintf(stdout, prompt);
2474 /* We really should turn off echoing and pretty this
2478 while ((ch = fgetc(stdin)) != EOF) {
2480 strip_trailing_junk(cmd);
2482 } else if (ch == 4 || ch == 0xd3 || ch == 0x8) {
2495 /* Dummies to replace askdir.c */
2496 int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;}
2497 int dir_send_job_status(JCR *jcr) {return 1;}
2499 int dir_update_volume_info(JCR *jcr, DEVICE *dev, int relabel)
2505 int dir_get_volume_info(JCR *jcr, enum get_vol_info_rw writing)
2507 Dmsg0(20, "Enter dir_get_volume_info\n");
2508 bstrncpy(jcr->VolCatInfo.VolCatName, jcr->VolumeName, sizeof(jcr->VolCatInfo.VolCatName));
2512 int dir_create_jobmedia_record(JCR *jcr)
2514 jcr->dcr->WroteVol = false;
2519 int dir_find_next_appendable_volume(JCR *jcr)
2521 Dmsg1(20, "Enter dir_find_next_appendable_volume. stop=%d\n", stop);
2522 return jcr->VolumeName[0] != 0;
2525 int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
2527 Dmsg0(20, "Enter dir_ask_sysop_to_mount_volume\n");
2528 if (jcr->VolumeName[0] == 0) {
2529 return dir_ask_sysop_to_create_appendable_volume(jcr, dev);
2531 /* Close device so user can use autochanger if desired */
2532 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
2535 force_close_dev(dev);
2536 Pmsg1(-1, "%s", dev->errmsg); /* print reason */
2537 if (jcr->VolumeName[0] == 0 || strcmp(jcr->VolumeName, "TestVolume2") == 0) {
2538 fprintf(stderr, "Mount second Volume on device %s and press return when ready: ",
2541 fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
2542 jcr->VolumeName, dev_name(dev));
2548 int dir_ask_sysop_to_create_appendable_volume(JCR *jcr, DEVICE *dev)
2551 Dmsg0(20, "Enter dir_ask_sysop_to_create_appendable_volume\n");
2553 set_volume_name("TestVolume1", 1);
2555 set_volume_name("TestVolume2", 2);
2557 /* Close device so user can use autochanger if desired */
2558 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
2561 autochanger = autoload_device(jcr, dev, 1, NULL);
2563 force_close_dev(dev);
2564 fprintf(stderr, "Mount blank Volume on device %s and press return when ready: ",
2568 open_device(jcr, dev);
2575 static int my_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
2579 Dmsg0(20, "Enter my_mount_next_read_volume\n");
2580 Pmsg1(000, "End of Volume \"%s\"\n", jcr->VolumeName);
2582 if (LastBlock != block->BlockNumber) {
2583 VolBytes += block->block_len;
2585 LastBlock = block->BlockNumber;
2587 now -= jcr->run_time;
2591 kbs = (double)VolBytes / (1000.0 * (double)now);
2592 Pmsg3(-1, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
2593 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
2595 if (strcmp(jcr->VolumeName, "TestVolume2") == 0) {
2601 set_volume_name("TestVolume2", 2);
2603 create_vol_list(jcr);
2605 dev->state &= ~ST_READ;
2606 if (!acquire_device_for_read(jcr)) {
2607 Pmsg2(0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev), jcr->VolumeName);
2610 return 1; /* next volume mounted */
2613 static void set_volume_name(char *VolName, int volnum)
2615 DCR *dcr = jcr->dcr;
2616 VolumeName = VolName;
2618 pm_strcpy(&jcr->VolumeName, VolName);
2619 bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName));
2620 bstrncpy(jcr->VolCatInfo.VolCatName, VolName, sizeof(jcr->VolCatInfo.VolCatName));
2621 bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName));
2622 bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName));
2623 jcr->VolCatInfo.Slot = volnum;
2624 dcr->VolCatInfo.Slot = volnum;
2628 * Edit codes into ChangerCommand
2630 * %a = archive device name
2631 * %c = changer device name
2632 * %f = Client's name
2640 * omsg = edited output message
2641 * imsg = input string containing edit codes (%x)
2642 * cmd = command string (load, unload, ...)
2645 static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd)
2652 Dmsg1(400, "edit_device_codes: %s\n", imsg);
2653 for (p=imsg; *p; p++) {
2660 str = dev_name(jcr->device->dev);
2663 str = NPRT(jcr->device->changer_name);
2669 sprintf(add, "%d", jcr->VolCatInfo.Slot - 1);
2673 sprintf(add, "%d", jcr->VolCatInfo.Slot);
2676 case 'j': /* Job name */
2680 str = NPRT(jcr->VolumeName);
2683 str = NPRT(jcr->client_name);
2698 Dmsg1(400, "add_str %s\n", str);
2699 pm_strcat(&omsg, (char *)str);
2700 Dmsg1(400, "omsg=%s\n", omsg);
2707 * We are called here from "unfill" for each record on the tape.
2709 static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
2711 SESSION_LABEL label;
2713 if (stop > 1 && !dumped) { /* on second tape */
2716 dump_block(block, "First block on second tape");
2718 Pmsg4(-1, "Blk: FileIndex=%d: block=%u size=%d vol=%s\n",
2719 rec->FileIndex, block->BlockNumber, block->block_len, dev->VolHdr.VolName);
2720 Pmsg6(-1, " Rec: VId=%d VT=%d FI=%s Strm=%s len=%d state=%x\n",
2721 rec->VolSessionId, rec->VolSessionTime,
2722 FI_to_ascii(rec->FileIndex), stream_to_ascii(rec->Stream, rec->FileIndex),
2723 rec->data_len, rec->state);
2725 if (rec->FileIndex < 0) {
2727 dump_label_record(dev, rec, 1);
2729 switch (rec->FileIndex) {
2731 Pmsg0(-1, "Volume is prelabeled. This tape cannot be scanned.\n");
2734 unser_volume_label(dev, rec);
2735 Pmsg3(-1, "VOL_LABEL: block=%u size=%d vol=%s\n", block->BlockNumber,
2736 block->block_len, dev->VolHdr.VolName);
2740 unser_session_label(&label, rec);
2741 Pmsg1(-1, "SOS_LABEL: JobId=%u\n", label.JobId);
2744 unser_session_label(&label, rec);
2745 Pmsg2(-1, "EOS_LABEL: block=%u JobId=%u\n", block->BlockNumber,
2749 Pmsg0(-1, "EOM_LABEL:\n");
2751 case EOT_LABEL: /* end of all tapes */
2754 if (LastBlock != block->BlockNumber) {
2755 VolBytes += block->block_len;
2757 LastBlock = block->BlockNumber;
2759 now -= jcr->run_time;
2763 kbs = (double)VolBytes / (1000 * now);
2764 Pmsg3(000, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
2765 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
2767 Pmsg0(000, "End of all tapes.\n");
2775 if (++file_index != rec->FileIndex) {
2776 Pmsg3(000, "Incorrect FileIndex in Block %u. Got %d, expected %d.\n",
2777 block->BlockNumber, rec->FileIndex, file_index);
2779 if (LastBlock != block->BlockNumber) {
2780 VolBytes += block->block_len;
2782 if ((block->BlockNumber != LastBlock) && (block->BlockNumber % 50000) == 0) {
2785 now -= jcr->run_time;
2789 kbs = (double)VolBytes / (1000 * now);
2790 Pmsg3(000, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
2791 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
2793 LastBlock = block->BlockNumber;
2795 Pmsg1(000, "End of all blocks. Block=%u\n", block->BlockNumber);