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];
50 * If you change the format of the state file,
51 * increment this value
53 static uint32_t btape_state_level = 2;
56 DEVRES *device = NULL;
59 /* Forward referenced subroutines */
60 static void do_tape_cmds();
61 static void helpcmd();
62 static void scancmd();
63 static void rewindcmd();
64 static void clearcmd();
68 static void fillcmd();
69 static void qfillcmd();
70 static void statcmd();
71 static void unfillcmd();
72 static int flush_block(DEV_BLOCK *block, int dump);
74 static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
76 static int quickie_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
77 static bool compare_blocks(DEV_BLOCK *last_block, DEV_BLOCK *block);
78 static int my_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block);
79 static void scan_blocks();
80 static void set_volume_name(char *VolName, int volnum);
81 static void rawfill_cmd();
82 static void bfill_cmd();
83 static bool open_the_device();
84 static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd);
85 static void autochangercmd();
86 static void do_unfill();
89 /* Static variables */
90 #define CONFIG_FILE "bacula-sd.conf"
93 #define MAX_CMD_ARGS 30
96 static char *argk[MAX_CMD_ARGS];
97 static char *argv[MAX_CMD_ARGS];
100 static int quickie_count = 0;
101 static BSR *bsr = NULL;
102 static int signals = TRUE;
105 static uint64_t vol_size;
106 static uint64_t VolBytes;
109 static int32_t file_index;
110 static int end_of_tape = 0;
111 static uint32_t LastBlock = 0;
112 static uint32_t eot_block;
113 static uint32_t eot_block_len;
114 static uint32_t eot_FileIndex;
115 static int dumped = 0;
116 static DEV_BLOCK *last_block1 = NULL;
117 static DEV_BLOCK *last_block2 = NULL;
118 static DEV_BLOCK *last_block = NULL;
119 static DEV_BLOCK *this_block = NULL;
120 static DEV_BLOCK *first_block = NULL;
121 static uint32_t last_file1 = 0;
122 static uint32_t last_file2 = 0;
123 static uint32_t last_file = 0;
124 static uint32_t last_block_num1 = 0;
125 static uint32_t last_block_num2 = 0;
126 static uint32_t last_block_num = 0;
127 static uint32_t BlockNumber = 0;
128 static bool simple = true;
130 static char *VolumeName = NULL;
131 static int vol_num = 0;
133 static JCR *jcr = NULL;
137 static void terminate_btape(int sig);
138 int get_cmd(char *prompt);
141 /*********************************************************************
143 * Main Bacula Pool Creation Program
146 int main(int margc, char *margv[])
151 if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) {
152 Emsg2(M_ABORT, 0, "Tape block size (%d) not multiple of system size (%d)\n",
153 TAPE_BSIZE, DEV_BSIZE);
155 if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) {
156 Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE);
159 printf("Tape block granularity is %d bytes.\n", TAPE_BSIZE);
161 working_directory = "/tmp";
162 my_name_is(margc, margv, "btape");
163 init_msg(NULL, NULL);
165 while ((ch = getopt(margc, margv, "b:c:d:sv?")) != -1) {
167 case 'b': /* bootstrap file */
168 bsr = parse_bsr(NULL, optarg);
169 // dump_bsr(bsr, true);
172 case 'c': /* specify config file */
173 if (configfile != NULL) {
176 configfile = bstrdup(optarg);
179 case 'd': /* set debug level */
180 debug_level = atoi(optarg);
181 if (debug_level <= 0) {
204 cmd = get_pool_memory(PM_FNAME);
205 args = get_pool_memory(PM_FNAME);
208 init_signals(terminate_btape);
211 if (configfile == NULL) {
212 configfile = bstrdup(CONFIG_FILE);
215 daemon_start_time = time(NULL);
217 parse_config(configfile);
220 /* See if we can open a device */
222 Pmsg0(000, "No archive name specified.\n");
225 } else if (margc != 1) {
226 Pmsg0(000, "Improper number of arguments specified.\n");
231 jcr = setup_jcr("btape", margv[0], bsr, NULL);
232 dev = setup_to_access_device(jcr, 0); /* acquire for write */
236 if (!open_the_device()) {
240 Dmsg0(200, "Do tape commands\n");
248 static void terminate_btape(int stat)
251 sm_check(__FILE__, __LINE__, False);
255 free_config_resources();
257 free_pool_memory(args);
261 free_pool_memory(cmd);
269 if (debug_level > 10)
270 print_memory_pool_stats();
280 free_block(this_block);
284 close_memory_pool(); /* free memory in pool */
290 static bool open_the_device()
294 block = new_block(dev);
296 if (!(dev->state & ST_OPENED)) {
297 Dmsg1(200, "Opening device %s\n", jcr->VolumeName);
298 if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
299 Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
305 Dmsg1(000, "open_dev %s OK\n", dev_name(dev));
318 * Write a label to the tape
320 static void labelcmd()
323 pm_strcpy(&cmd, VolumeName);
325 if (!get_cmd("Enter Volume Name: ")) {
330 if (!(dev->state & ST_OPENED)) {
331 if (!first_open_device(dev)) {
332 Pmsg1(0, "Device open failed. ERR=%s\n", strerror_dev(dev));
336 write_volume_label_to_dev(jcr, jcr->device, cmd, "Default");
337 Pmsg1(-1, "Wrote Volume label for volume \"%s\".\n", cmd);
341 * Read the tape label
343 static void readlabelcmd()
345 int save_debug_level = debug_level;
349 block = new_block(dev);
350 stat = read_dev_volume_label(jcr, dev, block);
353 Pmsg0(0, "Volume has no label.\n");
356 Pmsg0(0, "Volume label read correctly.\n");
359 Pmsg1(0, "I/O error on device: ERR=%s", strerror_dev(dev));
362 Pmsg0(0, "Volume name error\n");
364 case VOL_CREATE_ERROR:
365 Pmsg1(0, "Error creating label. ERR=%s", strerror_dev(dev));
367 case VOL_VERSION_ERROR:
368 Pmsg0(0, "Volume version error.\n");
370 case VOL_LABEL_ERROR:
371 Pmsg0(0, "Bad Volume label type.\n");
374 Pmsg0(0, "Unknown error.\n");
379 dump_volume_label(dev);
380 debug_level = save_debug_level;
386 * Load the tape should have prevously been taken
387 * off line, otherwise this command is not necessary.
389 static void loadcmd()
392 if (!load_dev(dev)) {
393 Pmsg1(0, "Bad status from load. ERR=%s\n", strerror_dev(dev));
395 Pmsg1(0, "Loaded %s\n", dev_name(dev));
401 static void rewindcmd()
403 if (!rewind_dev(dev)) {
404 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
405 clrerror_dev(dev, -1);
407 Pmsg1(0, "Rewound %s\n", dev_name(dev));
412 * Clear any tape error
414 static void clearcmd()
416 clrerror_dev(dev, -1);
420 * Write and end of file on the tape
422 static void weofcmd()
433 if ((stat = weof_dev(dev, num)) < 0) {
434 Pmsg2(0, "Bad status from weof %d. ERR=%s\n", stat, strerror_dev(dev));
437 Pmsg3(0, "Wrote %d EOF%s to %s\n", num, num==1?"":"s", dev_name(dev));
442 /* Go to the end of the medium -- raw command
443 * The idea was orginally that the end of the Bacula
444 * medium would be flagged differently. This is not
445 * currently the case. So, this is identical to the
451 Pmsg1(0, "%s", strerror_dev(dev));
454 Pmsg0(0, _("Moved to end of medium.\n"));
459 * Go to the end of the medium (either hardware determined
460 * or defined by two eofs.
480 if (!bsf_dev(dev, num)) {
481 Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror_dev(dev));
483 Pmsg2(0, _("Backspaced %d file%s.\n"), num, num==1?"":"s");
499 if (!bsr_dev(dev, num)) {
500 Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), strerror_dev(dev));
502 Pmsg2(0, _("Backspaced %d record%s.\n"), num, num==1?"":"s");
507 * List device capabilities as defined in the
512 printf(_("Configured device capabilities:\n"));
513 printf("%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
514 printf("%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
515 printf("%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
516 printf("%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
517 printf("%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
518 printf("%sFASTFSF ", dev->capabilities & CAP_FASTFSF ? "" : "!");
519 printf("%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
520 printf("%sREM ", dev->capabilities & CAP_REM ? "" : "!");
521 printf("%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
522 printf("%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
523 printf("%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
524 printf("%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
525 printf("%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
528 printf(_("Device status:\n"));
529 printf("%sOPENED ", dev->state & ST_OPENED ? "" : "!");
530 printf("%sTAPE ", dev->state & ST_TAPE ? "" : "!");
531 printf("%sLABEL ", dev->state & ST_LABEL ? "" : "!");
532 printf("%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
533 printf("%sAPPEND ", dev->state & ST_APPEND ? "" : "!");
534 printf("%sREAD ", dev->state & ST_READ ? "" : "!");
535 printf("%sEOT ", dev->state & ST_EOT ? "" : "!");
536 printf("%sWEOT ", dev->state & ST_WEOT ? "" : "!");
537 printf("%sEOF ", dev->state & ST_EOF ? "" : "!");
538 printf("%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
539 printf("%sSHORT ", dev->state & ST_SHORT ? "" : "!");
542 printf(_("Device parameters:\n"));
543 printf("Device name: %s\n", dev->dev_name);
544 printf("File=%u block=%u\n", dev->file, dev->block_num);
545 printf("Min block=%u Max block=%u\n", dev->min_block_size, dev->max_block_size);
553 * Test writting larger and larger records.
554 * This is a torture test for records.
556 static void rectestcmd()
562 Pmsg0(0, "Test writting larger and larger records.\n"
563 "This is a torture test for records.\nI am going to write\n"
564 "larger and larger records. It will stop when the record size\n"
565 "plus the header exceeds the block size (by default about 64K)\n");
568 get_cmd("Do you want to continue? (y/n): ");
570 Pmsg0(000, "Command aborted.\n");
574 sm_check(__FILE__, __LINE__, False);
575 block = new_block(dev);
578 for (i=1; i<500000; i++) {
579 rec->data = check_pool_memory_size(rec->data, i);
580 memset(rec->data, i & 0xFF, i);
582 sm_check(__FILE__, __LINE__, False);
583 if (write_record_to_block(block, rec)) {
586 Pmsg2(0, "Block %d i=%d\n", blkno, i);
590 sm_check(__FILE__, __LINE__, False);
594 sm_check(__FILE__, __LINE__, False);
598 * This test attempts to re-read a block written by Bacula
599 * normally at the end of the tape. Bacula will then back up
600 * over the two eof marks, backup over the record and reread
601 * it to make sure it is valid. Bacula can skip this validation
602 * if you set "Backward space record = no"
604 static int re_read_block_test()
611 if (!(dev->capabilities & CAP_BSR)) {
612 Pmsg0(-1, _("Skipping read backwards test because BSR turned off.\n"));
616 Pmsg0(-1, _("\n=== Write, backup, and re-read test ===\n\n"
617 "I'm going to write three records and an EOF\n"
618 "then backup over the EOF and re-read the last record.\n"
619 "Bacula does this after writing the last block on the\n"
620 "tape to verify that the block was written correctly.\n\n"
621 "This is not an *essential* feature ...\n\n"));
623 block = new_block(dev);
625 rec->data = check_pool_memory_size(rec->data, block->buf_len);
626 len = rec->data_len = block->buf_len-100;
627 memset(rec->data, 1, rec->data_len);
628 if (!write_record_to_block(block, rec)) {
629 Pmsg0(0, _("Error writing record to block.\n"));
632 if (!write_block_to_dev(jcr->dcr, block)) {
633 Pmsg0(0, _("Error writing block to device.\n"));
636 Pmsg1(0, _("Wrote first record of %d bytes.\n"), rec->data_len);
638 memset(rec->data, 2, rec->data_len);
639 if (!write_record_to_block(block, rec)) {
640 Pmsg0(0, _("Error writing record to block.\n"));
643 if (!write_block_to_dev(jcr->dcr, block)) {
644 Pmsg0(0, _("Error writing block to device.\n"));
647 Pmsg1(0, _("Wrote second record of %d bytes.\n"), rec->data_len);
649 memset(rec->data, 3, rec->data_len);
650 if (!write_record_to_block(block, rec)) {
651 Pmsg0(0, _("Error writing record to block.\n"));
654 if (!write_block_to_dev(jcr->dcr, block)) {
655 Pmsg0(0, _("Error writing block to device.\n"));
658 Pmsg1(0, _("Wrote third record of %d bytes.\n"), rec->data_len);
661 if (dev_cap(dev, CAP_TWOEOF)) {
664 if (!bsf_dev(dev, 1)) {
665 Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
668 if (dev_cap(dev, CAP_TWOEOF)) {
669 if (!bsf_dev(dev, 1)) {
670 Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
674 Pmsg0(0, "Backspaced over EOF OK.\n");
675 if (!bsr_dev(dev, 1)) {
676 Pmsg1(0, _("Backspace record failed! ERR=%s\n"), strerror_dev(dev));
679 Pmsg0(0, "Backspace record OK.\n");
680 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
681 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
684 memset(rec->data, 0, rec->data_len);
685 if (!read_record_from_block(block, rec)) {
686 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
689 for (int i=0; i<len; i++) {
690 if (rec->data[i] != 3) {
691 Pmsg0(0, _("Bad data in record. Test failed!\n"));
695 Pmsg0(0, _("\nBlock re-read correct. Test succeeded!\n"));
696 Pmsg0(-1, _("=== End Write, backup, and re-read test ===\n\n"));
704 Pmsg0(0, _("This is not terribly serious since Bacula only uses\n"
705 "this function to verify the last block written to the\n"
706 "tape. Bacula will skip the last block verification\n"
708 "Backward Space Record = No\n\n"
709 "to your Storage daemon's Device resource definition.\n"));
716 * This test writes Bacula blocks to the tape in
717 * several files. It then rewinds the tape and attepts
718 * to read these blocks back checking the data.
720 static int write_read_test()
728 Pmsg0(-1, _("\n=== Write, rewind, and re-read test ===\n\n"
729 "I'm going to write 1000 records and an EOF\n"
730 "then write 1000 records and an EOF, then rewind,\n"
731 "and re-read the data to verify that it is correct.\n\n"
732 "This is an *essential* feature ...\n\n"));
733 block = new_block(dev);
735 if (!rewind_dev(dev)) {
736 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
739 rec->data = check_pool_memory_size(rec->data, block->buf_len);
740 rec->data_len = block->buf_len-100;
741 len = rec->data_len/sizeof(i);
742 for (i=1; i<=1000; i++) {
743 p = (int *)rec->data;
744 for (j=0; j<len; j++) {
747 if (!write_record_to_block(block, rec)) {
748 Pmsg0(0, _("Error writing record to block.\n"));
751 if (!write_block_to_dev(jcr->dcr, block)) {
752 Pmsg0(0, _("Error writing block to device.\n"));
756 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
758 for (i=1001; i<=2000; i++) {
759 p = (int *)rec->data;
760 for (j=0; j<len; j++) {
763 if (!write_record_to_block(block, rec)) {
764 Pmsg0(0, _("Error writing record to block.\n"));
767 if (!write_block_to_dev(jcr->dcr, block)) {
768 Pmsg0(0, _("Error writing block to device.\n"));
772 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
774 if (dev_cap(dev, CAP_TWOEOF)) {
777 if (!rewind_dev(dev)) {
778 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
781 Pmsg0(0, "Rewind OK.\n");
783 for (i=1; i<=2000; i++) {
785 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
786 if (dev_state(dev, ST_EOF)) {
787 Pmsg0(-1, _("Got EOF on tape.\n"));
790 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
793 memset(rec->data, 0, rec->data_len);
794 if (!read_record_from_block(block, rec)) {
795 Pmsg1(0, _("Read record failed! ERR=%s\n"), strerror(dev->dev_errno));
798 p = (int *)rec->data;
799 for (j=0; j<len; j++) {
801 Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
807 if (i == 1000 || i == 2000) {
808 Pmsg0(-1, _("1000 blocks re-read correctly.\n"));
811 Pmsg0(-1, _("=== Test Succeeded. End Write, rewind, and re-read test ===\n\n"));
821 * This test writes Bacula blocks to the tape in
822 * several files. It then rewinds the tape and attepts
823 * to read these blocks back checking the data.
825 static int position_test()
833 int file = 0, blk = 0;
836 Pmsg0(-1, _("\n=== Write, rewind, and position test ===\n\n"
837 "I'm going to write 1000 records and an EOF\n"
838 "then write 1000 records and an EOF, then rewind,\n"
839 "and position to a few blocks and verify that it is correct.\n\n"
840 "This is an *essential* feature ...\n\n"));
841 block = new_block(dev);
843 if (!rewind_dev(dev)) {
844 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
847 rec->data = check_pool_memory_size(rec->data, block->buf_len);
848 rec->data_len = block->buf_len-100;
849 len = rec->data_len/sizeof(i);
850 for (i=1; i<=1000; i++) {
851 p = (int *)rec->data;
852 for (j=0; j<len; j++) {
855 if (!write_record_to_block(block, rec)) {
856 Pmsg0(0, _("Error writing record to block.\n"));
859 if (!write_block_to_dev(jcr->dcr, block)) {
860 Pmsg0(0, _("Error writing block to device.\n"));
864 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
866 for (i=1001; i<=2000; i++) {
867 p = (int *)rec->data;
868 for (j=0; j<len; j++) {
871 if (!write_record_to_block(block, rec)) {
872 Pmsg0(0, _("Error writing record to block.\n"));
875 if (!write_block_to_dev(jcr->dcr, block)) {
876 Pmsg0(0, _("Error writing block to device.\n"));
880 Pmsg1(0, _("Wrote 1000 blocks of %d bytes.\n"), rec->data_len);
882 if (dev_cap(dev, CAP_TWOEOF)) {
885 if (!rewind_dev(dev)) {
886 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
889 Pmsg0(0, "Rewind OK.\n");
893 /* Set up next item to read based on where we are */
929 Pmsg2(-1, "Reposition to file:block %d:%d\n", file, blk);
930 if (!reposition_dev(dev, file, blk)) {
931 Pmsg0(0, "Reposition error.\n");
935 if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
936 if (dev_state(dev, ST_EOF)) {
937 Pmsg0(-1, _("Got EOF on tape.\n"));
940 Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno));
943 memset(rec->data, 0, rec->data_len);
944 if (!read_record_from_block(block, rec)) {
945 Pmsg1(0, _("Read record failed! ERR=%s\n"), strerror(dev->dev_errno));
948 p = (int *)rec->data;
949 for (j=0; j<len; j++) {
951 Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
956 Pmsg0(-1, _("Block re-read correctly.\n"));
958 Pmsg0(-1, _("=== Test Succeeded. End Write, rewind, and re-read test ===\n\n"));
971 * This test writes some records, then writes an end of file,
972 * rewinds the tape, moves to the end of the data and attepts
973 * to append to the tape. This function is essential for
974 * Bacula to be able to write multiple jobs to the tape.
976 static int append_test()
978 Pmsg0(-1, _("\n\n=== Append files test ===\n\n"
979 "This test is essential to Bacula.\n\n"
980 "I'm going to write one record in file 0,\n"
981 " two records in file 1,\n"
982 " and three records in file 2\n\n"));
986 weofcmd(); /* end file 0 */
989 weofcmd(); /* end file 1 */
993 weofcmd(); /* end file 2 */
994 if (dev_cap(dev, CAP_TWOEOF)) {
998 Pmsg0(0, _("Now moving to end of medium.\n"));
1000 Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
1001 dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
1003 if (dev->file != 3) {
1007 Pmsg0(-1, _("\nNow the important part, I am going to attempt to append to the tape.\n\n"));
1010 if (dev_cap(dev, CAP_TWOEOF)) {
1014 Pmsg0(-1, _("Done appending, there should be no I/O errors\n\n"));
1015 Pmsg0(-1, "Doing Bacula scan of blocks:\n");
1017 Pmsg0(-1, _("End scanning the tape.\n"));
1018 Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
1019 dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
1021 if (dev->file != 4) {
1029 * This test exercises the autochanger
1031 static int autochanger_test()
1033 POOLMEM *results, *changer;
1034 int slot, status, loaded;
1038 if (!dev_cap(dev, CAP_AUTOCHANGER)) {
1041 if (!(jcr->device && jcr->device->changer_name && jcr->device->changer_command)) {
1042 Pmsg0(-1, "\nAutochanger enabled, but no name or no command device specified.\n");
1046 Pmsg0(-1, "\nTo test the autochanger you must have a blank tape in Slot 1.\n"
1047 "I'm going to write on it.\n");
1048 if (!get_cmd("\nDo you wish to continue with the Autochanger test? (y/n): ")) {
1051 if (cmd[0] != 'y' && cmd[0] != 'Y') {
1055 Pmsg0(-1, _("\n\n=== Autochanger test ===\n\n"));
1057 results = get_pool_memory(PM_MESSAGE);
1058 changer = get_pool_memory(PM_FNAME);
1062 jcr->VolCatInfo.Slot = slot;
1063 /* Find out what is loaded, zero means device is unloaded */
1064 Pmsg0(-1, _("3301 Issuing autochanger \"loaded\" command.\n"));
1065 changer = edit_device_codes(jcr, changer, jcr->device->changer_command,
1067 status = run_program(changer, timeout, results);
1068 Dmsg3(100, "run_prog: %s stat=%d result=%s\n", changer, status, results);
1070 loaded = atoi(results);
1072 Pmsg1(-1, _("3991 Bad autochanger \"load slot\" status=%d.\n"), status);
1073 loaded = -1; /* force unload */
1077 Pmsg1(-1, "Slot %d loaded. I am going to unload it.\n", loaded);
1079 Pmsg0(-1, "Nothing loaded into the drive. OK.\n");
1081 Dmsg1(100, "Results from loaded query=%s\n", results);
1083 offline_or_rewind_dev(dev);
1084 /* We are going to load a new tape, so close the device */
1085 force_close_dev(dev);
1086 Pmsg0(-1, _("3302 Issuing autochanger \"unload\" command.\n"));
1087 changer = edit_device_codes(jcr, changer,
1088 jcr->device->changer_command, "unload");
1089 status = run_program(changer, timeout, NULL);
1090 Pmsg2(-1, "unload status=%s %d\n", status==0?"OK":"Bad", status);
1096 Pmsg1(-1, _("3303 Issuing autochanger \"load slot %d\" command.\n"), slot);
1097 changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "load");
1098 Dmsg1(200, "Changer=%s\n", changer);
1099 status = run_program(changer, timeout, NULL);
1101 Pmsg1(-1, _("3304 Autochanger \"load slot %d\" status is OK.\n"), slot);
1103 Pmsg1(-1, _("3992 Bad autochanger \"load slot\" status=%d.\n"), status);
1107 if (!open_the_device()) {
1110 bmicrosleep(sleep_time, 0);
1111 if (!rewind_dev(dev)) {
1112 Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
1113 clrerror_dev(dev, -1);
1114 Pmsg0(-1, "\nThe test failed, probably because you need to put\n"
1115 "a longer sleep time in the mtx-script in the load) case.\n"
1116 "Adding a 30 second sleep and trying again ...\n");
1120 Pmsg1(0, "Rewound %s\n", dev_name(dev));
1123 if ((status = weof_dev(dev, 1)) < 0) {
1124 Pmsg2(0, "Bad status from weof %d. ERR=%s\n", status, strerror_dev(dev));
1127 Pmsg1(0, "Wrote EOF to %s\n", dev_name(dev));
1131 Pmsg1(-1, "\nThe test worked this time. Please add:\n\n"
1133 "to your mtx-changer script in the load) case.\n\n",
1136 Pmsg0(-1, "\nThe test autochanger worked!!\n\n");
1139 free_pool_memory(changer);
1140 free_pool_memory(results);
1145 free_pool_memory(changer);
1146 free_pool_memory(results);
1147 Pmsg0(-1, "You must correct this error or the Autochanger will not work.\n");
1151 static void autochangercmd()
1158 * This test assumes that the append test has been done,
1159 * then it tests the fsf function.
1161 static int fsf_test()
1163 bool set_off = false;
1165 Pmsg0(-1, _("\n\n=== Forward space files test ===\n\n"
1166 "This test is essential to Bacula.\n\n"
1167 "I'm going to write five files then test forward spacing\n\n"));
1171 weofcmd(); /* end file 0 */
1174 weofcmd(); /* end file 1 */
1178 weofcmd(); /* end file 2 */
1181 weofcmd(); /* end file 3 */
1183 weofcmd(); /* end file 4 */
1184 if (dev_cap(dev, CAP_TWOEOF)) {
1190 Pmsg0(0, _("Now forward spacing 1 file.\n"));
1191 if (!fsf_dev(dev, 1)) {
1192 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1195 Pmsg2(-1, _("We should be in file 1. I am at file %d. This is %s\n"),
1196 dev->file, dev->file == 1 ? "correct!" : "NOT correct!!!!");
1198 if (dev->file != 1) {
1202 Pmsg0(0, _("Now forward spacing 2 files.\n"));
1203 if (!fsf_dev(dev, 2)) {
1204 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1207 Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
1208 dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
1210 if (dev->file != 3) {
1215 Pmsg0(0, _("Now forward spacing 4 files.\n"));
1216 if (!fsf_dev(dev, 4)) {
1217 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1220 Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
1221 dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
1223 if (dev->file != 4) {
1227 Pmsg0(-1, "The test worked this time. Please add:\n\n"
1228 " Fast Forward Space File = no\n\n"
1229 "to your Device resource for this drive.\n");
1233 Pmsg0(0, _("Now forward spacing 1 more file.\n"));
1234 if (!fsf_dev(dev, 1)) {
1235 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1237 Pmsg2(-1, _("We should be in file 5. I am at file %d. This is %s\n"),
1238 dev->file, dev->file == 5 ? "correct!" : "NOT correct!!!!");
1239 if (dev->file != 5) {
1246 Pmsg0(-1, _("\nThe forward space file test failed.\n"));
1247 if (dev_cap(dev, CAP_FASTFSF)) {
1248 Pmsg0(-1, "You have Fast Forward Space File enabled.\n"
1249 "I am turning it off then retrying the test.\n");
1250 dev->capabilities &= ~CAP_FASTFSF;
1254 Pmsg0(-1, "You must correct this error or Bacula will not work.\n");
1263 * This is a general test of Bacula's functions
1264 * needed to read and write the tape.
1266 static void testcmd()
1270 if (!write_read_test()) {
1273 if (!position_test()) {
1277 stat = append_test();
1278 if (stat == 1) { /* OK get out */
1281 if (stat == -1) { /* first test failed */
1282 if (dev_cap(dev, CAP_EOM) || dev_cap(dev, CAP_FASTFSF)) {
1283 Pmsg0(-1, "\nAppend test failed. Attempting again.\n"
1284 "Setting \"Hardware End of Medium = no\n"
1285 " and \"Fast Forward Space File = no\n"
1286 "and retrying append test.\n\n");
1287 dev->capabilities &= ~CAP_EOM; /* turn off eom */
1288 dev->capabilities &= ~CAP_FASTFSF; /* turn off fast fsf */
1289 stat = append_test();
1291 Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
1292 " Hardware End of Medium = No\n\n"
1293 " Fast Forward Space File = No\n"
1294 "to your Device resource in the Storage conf file.\n");
1298 Pmsg0(-1, "\n\nThat appears *NOT* to have corrected the problem.\n");
1301 /* Wrong count after append */
1303 Pmsg0(-1, "\n\nIt looks like the append failed. Attempting again.\n"
1304 "Setting \"BSF at EOM = yes\" and retrying append test.\n");
1305 dev->capabilities |= CAP_BSFATEOM; /* backspace on eom */
1306 stat = append_test();
1308 Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
1309 " Hardware End of Medium = No\n"
1310 " Fast Forward Space File = No\n"
1311 " BSF at EOM = yes\n\n"
1312 "to your Device resource in the Storage conf file.\n");
1319 Pmsg0(-1, "\nAppend test failed.\n\n");
1320 Pmsg0(-1, "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
1321 "Unable to correct the problem. You MUST fix this\n"
1322 "problem before Bacula can use your tape drive correctly\n");
1323 Pmsg0(-1, "\nPerhaps running Bacula in fixed block mode will work.\n"
1324 "Do so by setting:\n\n"
1325 "Minimum Block Size = nnn\n"
1326 "Maximum Block Size = nnn\n\n"
1327 "in your Storage daemon's Device definition.\n"
1328 "nnn must match your tape driver's block size, which\n"
1329 "can be determined by reading your tape manufacturers\n"
1330 "information, and the information on your kernel dirver.\n"
1331 "Fixed block sizes, however, are not normally an ideal solution.\n");
1336 Pmsg0(-1, _("\nThe above Bacula scan should have output identical to what follows.\n"
1337 "Please double check it ...\n"
1338 "=== Sample correct output ===\n"
1339 "1 block of 64448 bytes in file 1\n"
1340 "End of File mark.\n"
1341 "2 blocks of 64448 bytes in file 2\n"
1342 "End of File mark.\n"
1343 "3 blocks of 64448 bytes in file 3\n"
1344 "End of File mark.\n"
1345 "1 block of 64448 bytes in file 4\n"
1346 "End of File mark.\n"
1347 "Total files=4, blocks=7, bytes = 451,136\n"
1348 "=== End sample correct output ===\n\n"));
1350 Pmsg0(-1, _("If the above scan output is not identical to the\n"
1351 "sample output, you MUST correct the problem\n"
1352 "or Bacula will not be able to write multiple Jobs to \n"
1356 re_read_block_test();
1359 fsf_test(); /* do fast forward space file test */
1361 autochanger_test(); /* do autochanger test */
1365 /* Forward space a file */
1366 static void fsfcmd()
1370 num = atoi(argk[1]);
1375 if (!fsf_dev(dev, num)) {
1376 Pmsg1(0, "Bad status from fsf. ERR=%s\n", strerror_dev(dev));
1379 Pmsg2(0, "Forward spaced %d file%s.\n", num, num==1?"":"s");
1382 /* Forward space a record */
1383 static void fsrcmd()
1387 num = atoi(argk[1]);
1392 if (!fsr_dev(dev, num)) {
1393 Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
1396 Pmsg2(0, "Forward spaced %d record%s.\n", num, num==1?"":"s");
1401 * Write a Bacula block to the tape
1409 sm_check(__FILE__, __LINE__, False);
1410 block = new_block(dev);
1412 dump_block(block, "test");
1414 i = block->buf_len - 100;
1416 rec->data = check_pool_memory_size(rec->data, i);
1417 memset(rec->data, i & 0xFF, i);
1419 sm_check(__FILE__, __LINE__, False);
1420 if (!write_record_to_block(block, rec)) {
1421 Pmsg0(0, _("Error writing record to block.\n"));
1424 if (!write_block_to_dev(jcr->dcr, block)) {
1425 Pmsg0(0, _("Error writing block to device.\n"));
1428 Pmsg1(0, _("Wrote one record of %d bytes.\n"), i);
1430 Pmsg0(0, _("Wrote block to device.\n"));
1433 sm_check(__FILE__, __LINE__, False);
1436 sm_check(__FILE__, __LINE__, False);
1440 * Read a record from the tape
1447 if (!get_cmd("Enter length to read: ")) {
1451 if (len < 0 || len > 1000000) {
1452 Pmsg0(0, _("Bad length entered, using default of 1024 bytes.\n"));
1455 buf = (char *)malloc(len);
1456 stat = read(dev->fd, buf, len);
1457 if (stat > 0 && stat <= len) {
1460 Pmsg3(0, _("Read of %d bytes gives stat=%d. ERR=%s\n"),
1461 len, stat, strerror(errno));
1467 * Scan tape by reading block by block. Report what is
1468 * on the tape. Note, this command does raw reads, and as such
1469 * will not work with fixed block size devices.
1471 static void scancmd()
1474 int blocks, tot_blocks, tot_files;
1480 blocks = block_size = tot_blocks = 0;
1482 if (dev->state & ST_EOT) {
1483 Pmsg0(0, "End of tape\n");
1486 update_pos_dev(dev);
1487 tot_files = dev->file;
1488 Pmsg1(0, _("Starting scan at file %u\n"), dev->file);
1490 if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) {
1491 clrerror_dev(dev, -1);
1492 Mmsg2(&dev->errmsg, "read error on %s. ERR=%s.\n",
1493 dev->dev_name, strerror(dev->dev_errno));
1494 Pmsg2(0, "Bad status from read %d. ERR=%s\n", stat, strerror_dev(dev));
1496 printf("%d block%s of %d bytes in file %d\n",
1497 blocks, blocks>1?"s":"", block_size, dev->file);
1500 Dmsg1(200, "read status = %d\n", stat);
1502 if (stat != block_size) {
1503 update_pos_dev(dev);
1505 printf("%d block%s of %d bytes in file %d\n",
1506 blocks, blocks>1?"s":"", block_size, dev->file);
1511 if (stat == 0) { /* EOF */
1512 update_pos_dev(dev);
1513 printf("End of File mark.\n");
1514 /* Two reads of zero means end of tape */
1515 if (dev->state & ST_EOF)
1516 dev->state |= ST_EOT;
1518 dev->state |= ST_EOF;
1521 if (dev->state & ST_EOT) {
1522 printf("End of tape\n");
1525 } else { /* Got data */
1526 dev->state &= ~ST_EOF;
1532 update_pos_dev(dev);
1533 tot_files = dev->file - tot_files;
1534 printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
1535 edit_uint64_with_commas(bytes, ec1));
1540 * Scan tape by reading Bacula block by block. Report what is
1541 * on the tape. This function reads Bacula blocks, so if your
1542 * Device resource is correctly defined, it should work with
1543 * either variable or fixed block sizes.
1545 static void scan_blocks()
1547 int blocks, tot_blocks, tot_files;
1548 uint32_t block_size;
1553 block = new_block(dev);
1554 blocks = block_size = tot_blocks = 0;
1557 update_pos_dev(dev);
1558 tot_files = dev->file;
1560 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
1561 Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
1562 if (dev->state & ST_EOT) {
1564 printf("%d block%s of %d bytes in file %d\n",
1565 blocks, blocks>1?"s":"", block_size, dev->file);
1570 if (dev->state & ST_EOF) {
1572 printf("%d block%s of %d bytes in file %d\n",
1573 blocks, blocks>1?"s":"", block_size, dev->file);
1576 printf(_("End of File mark.\n"));
1579 if (dev->state & ST_SHORT) {
1581 printf("%d block%s of %d bytes in file %d\n",
1582 blocks, blocks>1?"s":"", block_size, dev->file);
1585 printf(_("Short block read.\n"));
1588 printf(_("Error reading block. ERR=%s\n"), strerror_dev(dev));
1591 if (block->block_len != block_size) {
1593 printf("%d block%s of %d bytes in file %d\n",
1594 blocks, blocks>1?"s":"", block_size, dev->file);
1597 block_size = block->block_len;
1601 bytes += block->block_len;
1602 Dmsg6(100, "Blk_blk=%u dev_blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
1603 block->BlockNumber, dev->block_num, block->block_len, block->BlockVer,
1604 block->VolSessionId, block->VolSessionTime);
1606 DEV_RECORD *rec = new_record();
1607 read_record_from_block(block, rec);
1608 Pmsg8(-1, "Blk_block: %u dev_blk=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
1609 block->BlockNumber, dev->block_num, block->block_len,
1610 FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
1611 stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
1614 } else if (verbose > 1) {
1615 dump_block(block, "");
1621 tot_files = dev->file - tot_files;
1622 printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
1623 edit_uint64_with_commas(bytes, ec1));
1627 static void statcmd()
1629 int debug = debug_level;
1631 Pmsg2(0, "Device status: %u. ERR=%s\n", status_dev(dev), strerror_dev(dev));
1633 dump_volume_label(dev);
1635 debug_level = debug;
1640 * First we label the tape, then we fill
1641 * it with data get a new tape and write a few blocks.
1643 static void fillcmd()
1650 uint32_t min_block_size;
1660 This command simulates Bacula writing to a tape.\n\
1661 It requires either one or two blank tapes, which it\n\
1662 will label and write.\n\n\
1663 If you have an autochanger configured, it will use\n\
1664 the tapes that are in slots 1 and 2, otherwise, you will\n\
1665 be prompted to insert the tapes when necessary.\n\n\
1666 It will print a status approximately\n\
1667 every 322 MB, and write an EOF every 3.2 GB. If you have\n\
1668 selected the simple test option, after writing the first tape\n\
1669 it will rewind it and re-read the last block written.\n\n\
1670 If you have selected the multiple tape test, when the first tape\n\
1671 fills, it will ask for a second, and after writing a few more \n\
1672 blocks, it will stop. Then it will begin re-reading the\n\
1674 This may take a long time -- hours! ...\n\n");
1676 get_cmd("Do you want to run the simplified test (s) with one tape\n"
1677 "or the complete multiple tape (m) test: (s/m) ");
1678 if (cmd[0] == 's') {
1679 Pmsg0(-1, "Simple test (single tape) selected.\n");
1681 } else if (cmd[0] == 'm') {
1682 Pmsg0(-1, "Multiple tape test selected.\n");
1685 Pmsg0(000, "Command aborted.\n");
1689 Dmsg1(20, "Begin append device=%s\n", dev_name(dev));
1690 Dmsg1(20, "MaxVolSize=%s\n", edit_uint64(dev->max_volume_size, ec1));
1692 /* Use fixed block size to simplify read back */
1693 min_block_size = dev->min_block_size;
1694 dev->min_block_size = dev->max_block_size;
1697 * Acquire output device for writing. Note, after acquiring a
1698 * device, we MUST release it, which is done at the end of this
1701 Dmsg0(100, "just before acquire_device\n");
1702 if (!acquire_device_for_append(jcr)) {
1703 set_jcr_job_status(jcr, JS_ErrorTerminated);
1706 block = jcr->dcr->block;
1708 Dmsg0(100, "Just after acquire_device_for_append\n");
1710 * Write Begin Session Record
1712 if (!write_session_label(jcr, block, SOS_LABEL)) {
1713 set_jcr_job_status(jcr, JS_ErrorTerminated);
1714 Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
1718 Pmsg0(-1, "Wrote Start Of Session label.\n");
1720 memset(&rec, 0, sizeof(rec));
1721 rec.data = get_memory(100000); /* max record size */
1723 #define REC_SIZE 32768
1724 rec.data_len = REC_SIZE;
1727 * Put some random data in the record
1729 fd = open("/dev/urandom", O_RDONLY);
1731 read(fd, rec.data, rec.data_len);
1734 uint32_t *p = (uint32_t *)rec.data;
1735 srandom(time(NULL));
1736 for (i=0; i<rec.data_len/sizeof(uint32_t); i++) {
1742 * Generate data as if from File daemon, write to device
1744 jcr->dcr->VolFirstIndex = 0;
1745 time(&jcr->run_time); /* start counting time for rates */
1747 Pmsg0(-1, "Begin writing Bacula records to tape ...\n");
1749 Pmsg0(-1, "Begin writing Bacula records to first tape ...\n");
1751 for (file_index = 0; ok && !job_canceled(jcr); ) {
1752 rec.VolSessionId = jcr->VolSessionId;
1753 rec.VolSessionTime = jcr->VolSessionTime;
1754 rec.FileIndex = ++file_index;
1755 rec.Stream = STREAM_FILE_DATA;
1757 /* Mix up the data just a bit */
1758 uint32_t *lp = (uint32_t *)rec.data;
1760 for (i=1; i < (rec.data_len-sizeof(uint32_t))/sizeof(uint32_t)-1; i++) {
1764 Dmsg4(250, "before write_rec FI=%d SessId=%d Strm=%s len=%d\n",
1765 rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream, rec.FileIndex),
1768 while (!write_record_to_block(block, &rec)) {
1770 * When we get here we have just filled a block
1772 Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
1775 /* Write block to tape */
1776 if (!flush_block(block, 1)) {
1780 /* Every 5000 blocks (approx 322MB) report where we are.
1782 if ((block->BlockNumber % 5000) == 0) {
1784 now -= jcr->run_time;
1786 now = 1; /* prevent divide error */
1788 kbs = (double)dev->VolCatInfo.VolCatBytes / (1000.0 * (double)now);
1789 Pmsg4(-1, "Wrote blk_block=%u, dev_blk_num=%u VolBytes=%s rate=%.1f KB/s\n",
1790 block->BlockNumber, dev->block_num,
1791 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), (float)kbs);
1793 /* Every 15000 blocks (approx 1GB) write an EOF.
1795 if ((block->BlockNumber % 15000) == 0) {
1796 Pmsg0(-1, "Flush block, write EOF\n");
1797 flush_block(block, 0);
1801 /* Get out after writing 10 blocks to the second tape */
1802 if (++BlockNumber > 10 && stop != 0) { /* get out */
1807 Pmsg0(000, _("Not OK\n"));
1810 jcr->JobBytes += rec.data_len; /* increment bytes this job */
1811 Dmsg4(190, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
1812 FI_to_ascii(rec.FileIndex), rec.VolSessionId,
1813 stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
1815 /* Get out after writing 10 blocks to the second tape */
1816 if (BlockNumber > 10 && stop != 0) { /* get out */
1817 Pmsg0(-1, "Done writing ...\n");
1822 Dmsg0(100, "Write_end_session_label()\n");
1823 /* Create Job status for end of session label */
1824 if (!job_canceled(jcr) && ok) {
1825 set_jcr_job_status(jcr, JS_Terminated);
1827 set_jcr_job_status(jcr, JS_ErrorTerminated);
1829 if (!write_session_label(jcr, block, EOS_LABEL)) {
1830 Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev));
1833 /* Write out final block of this session */
1834 if (!write_block_to_device(jcr->dcr, block)) {
1835 Pmsg0(-1, _("Set ok=FALSE after write_block_to_device.\n"));
1838 Pmsg0(-1, _("Wrote End Of Session label.\n"));
1840 /* Save last block info for second tape */
1841 last_block_num2 = last_block_num;
1842 last_file2 = last_file;
1844 free_block(last_block2);
1846 last_block2 = dup_block(last_block);
1849 sprintf(buf, "%s/btape.state", working_directory);
1850 fd = open(buf, O_CREAT|O_TRUNC|O_WRONLY, 0640);
1852 write(fd, &btape_state_level, sizeof(btape_state_level));
1853 write(fd, &simple, sizeof(simple));
1854 write(fd, &last_block_num1, sizeof(last_block_num1));
1855 write(fd, &last_block_num2, sizeof(last_block_num2));
1856 write(fd, &last_file1, sizeof(last_file1));
1857 write(fd, &last_file2, sizeof(last_file2));
1858 write(fd, last_block1->buf, last_block1->buf_len);
1859 write(fd, last_block2->buf, last_block2->buf_len);
1860 write(fd, first_block->buf, first_block->buf_len);
1862 Pmsg2(-1, "Wrote state file last_block_num1=%d last_block_num2=%d\n",
1863 last_block_num1, last_block_num2);
1865 Pmsg2(-1, _("Could not create state file: %s ERR=%s\n"), buf,
1869 /* Release the device */
1870 if (!release_device(jcr)) {
1871 Pmsg0(-1, _("Error in release_device\n"));
1876 Pmsg2(-1, _("\n\nDone filling tape%s. Now beginning re-read of %stape ...\n"),
1877 simple?"":"s", simple?"":"first ");
1881 dev->min_block_size = min_block_size;
1882 free_memory(rec.data);
1886 * Read two tapes written by the "fill" command and ensure
1887 * that the data is valid. If stop==1 we simulate full read back
1888 * of two tapes. If stop==-1 we simply read the last block and
1889 * verify that it is correct.
1891 static void unfillcmd()
1895 last_block1 = new_block(dev);
1896 last_block2 = new_block(dev);
1897 first_block = new_block(dev);
1898 sprintf(buf, "%s/btape.state", working_directory);
1899 fd = open(buf, O_RDONLY);
1901 uint32_t state_level;
1902 read(fd, &state_level, sizeof(btape_state_level));
1903 read(fd, &simple, sizeof(simple));
1904 read(fd, &last_block_num1, sizeof(last_block_num1));
1905 read(fd, &last_block_num2, sizeof(last_block_num2));
1906 read(fd, &last_file1, sizeof(last_file1));
1907 read(fd, &last_file2, sizeof(last_file2));
1908 read(fd, last_block1->buf, last_block1->buf_len);
1909 read(fd, last_block2->buf, last_block2->buf_len);
1910 read(fd, first_block->buf, first_block->buf_len);
1912 if (state_level != btape_state_level) {
1913 Pmsg0(-1, "\nThe state file level has changed. You must redo\n"
1914 "the fill command.\n");
1918 Pmsg2(-1, "\nCould not find the state file: %s ERR=%s\n"
1919 "You must redo the fill command.\n", buf, strerror(errno));
1926 static void do_unfill()
1934 block = new_block(dev);
1936 Dmsg0(20, "Enter do_unfill\n");
1937 dev->capabilities |= CAP_ANONVOLS; /* allow reading any volume */
1938 dev->capabilities &= ~CAP_LABEL; /* don't label anything here */
1942 time(&jcr->run_time); /* start counting time for rates */
1946 free_block(last_block);
1948 last_block_num = last_block_num1;
1949 last_file = last_file1;
1950 last_block = last_block1;
1953 /* Multiple Volume tape */
1954 /* Close device so user can use autochanger if desired */
1955 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
1958 autochanger = autoload_device(jcr, dev, 1, NULL);
1960 force_close_dev(dev);
1961 get_cmd(_("Mount first tape. Press enter when ready: "));
1965 set_volume_name("TestVolume1", 1);
1967 create_vol_list(jcr);
1969 dev->state &= ~ST_READ;
1970 if (!acquire_device_for_read(jcr)) {
1971 Pmsg1(-1, "%s", dev->errmsg);
1976 * We now have the first tape mounted.
1977 * Note, re-reading last block may have caused us to
1978 * loose track of where we are (block number unknown).
1980 rewind_dev(dev); /* get to a known place on tape */
1981 /* Read the first 1000 records */
1982 Pmsg0(-1, _("Reading the first 1000 records.\n"));
1983 read_records(jcr, dev, quickie_cb, my_mount_next_read_volume);
1984 Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
1985 last_file, last_block_num);
1986 if (!reposition_dev(dev, last_file, last_block_num)) {
1987 Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev));
1989 Pmsg1(-1, _("Reading block %u.\n"), last_block_num);
1990 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
1991 Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
1994 if (compare_blocks(last_block, block)) {
1996 Pmsg0(-1, _("\nThe last block on the tape matches. Test succeeded.\n\n"));
1998 Pmsg0(-1, _("\nThe last block of the first tape matches.\n\n"));
2005 /* restore info for last block on second Volume */
2006 last_block_num = last_block_num2;
2007 last_file = last_file2;
2008 last_block = last_block2;
2010 /* Multiple Volume tape */
2011 /* Close device so user can use autochanger if desired */
2012 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
2017 set_volume_name("TestVolume2", 2);
2019 create_vol_list(jcr);
2020 autochanger = autoload_device(jcr, dev, 1, NULL);
2022 force_close_dev(dev);
2023 get_cmd(_("Mount second tape. Press enter when ready: "));
2026 dev->state &= ~ST_READ;
2027 if (!acquire_device_for_read(jcr)) {
2028 Pmsg1(-1, "%s", dev->errmsg);
2032 /* Space to "first" block which is last block not written
2033 * on the previous tape.
2035 Pmsg2(-1, _("Reposition from %u:%u to 0:1\n"), dev->file, dev->block_num);
2036 if (!reposition_dev(dev, 0, 1)) {
2037 Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev));
2040 Pmsg1(-1, _("Reading block %d.\n"), dev->block_num);
2041 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
2042 Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
2045 if (compare_blocks(first_block, block)) {
2046 Pmsg0(-1, _("\nThe first block on the second tape matches.\n\n"));
2049 /* Now find and compare the last block */
2050 Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
2051 last_file, last_block_num);
2052 if (!reposition_dev(dev, last_file, last_block_num)) {
2053 Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev));
2056 Pmsg1(-1, _("Reading block %d.\n"), dev->block_num);
2057 if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
2058 Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
2061 if (compare_blocks(last_block, block)) {
2062 Pmsg0(-1, _("\nThe last block on the second tape matches. Test succeeded.\n\n"));
2067 free_block(last_block1);
2068 free_block(last_block2);
2069 free_block(first_block);
2072 /* Read 1000 records then stop */
2073 static int quickie_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
2076 return quickie_count <= 1000;
2079 static bool compare_blocks(DEV_BLOCK *last_block, DEV_BLOCK *block)
2082 uint32_t CheckSum, block_len;
2085 p = last_block->buf;
2087 unser_begin(q, BLKHDR2_LENGTH);
2088 unser_uint32(CheckSum);
2089 unser_uint32(block_len);
2090 while (q < (block->buf+block_len)) {
2097 dump_block(last_block, _("Last block written"));
2099 dump_block(block, _("Block read back"));
2100 Pmsg1(-1, "\n\nThe blocks differ at byte %u\n", p - last_block->buf);
2101 Pmsg0(-1, "\n\n!!!! The last block written and the block\n"
2102 "that was read back differ. The test FAILED !!!!\n"
2103 "This must be corrected before you use Bacula\n"
2104 "to write multi-tape Volumes.!!!!\n");
2108 dump_block(last_block, _("Last block written"));
2109 dump_block(block, _("Block read back"));
2119 * Write current block to tape regardless of whether or
2120 * not it is full. If the tape fills, attempt to
2121 * acquire another tape.
2123 static int flush_block(DEV_BLOCK *block, int dump)
2128 uint32_t this_file, this_block_num;
2131 this_block = new_block(dev);
2134 last_block = new_block(dev);
2137 this_file = dev->file;
2138 this_block_num = dev->block_num;
2139 if (!write_block_to_dev(jcr->dcr, block)) {
2140 Pmsg3(000, "Last block at: %u:%u this_dev_block_num=%d\n",
2141 last_file, last_block_num, this_block_num);
2144 * This is 1st tape, so save first tape info separate
2145 * from second tape info
2147 last_block_num1 = last_block_num;
2148 last_file1 = last_file;
2149 last_block1 = dup_block(last_block);
2150 last_block2 = dup_block(last_block);
2151 first_block = dup_block(block); /* first block second tape */
2154 Pmsg3(000, "Block not written: FileIndex=%u blk_block=%u Size=%u\n",
2155 (unsigned)file_index, block->BlockNumber, block->block_len);
2156 dump_block(last_block, "Last block written");
2158 dump_block(block, "Block not written");
2161 eot_block = block->BlockNumber;
2162 eot_block_len = block->block_len;
2163 eot_FileIndex = file_index;
2167 now -= jcr->run_time;
2169 now = 1; /* don't divide by zero */
2171 kbs = (double)dev->VolCatInfo.VolCatBytes / (1000 * now);
2172 vol_size = dev->VolCatInfo.VolCatBytes;
2173 Pmsg2(000, "End of tape. VolumeCapacity=%s. Write rate = %.1f KB/s\n",
2174 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), kbs);
2177 stop = -1; /* stop, but do simplified test */
2179 /* Full test in progress */
2180 if (!fixup_device_block_write_error(jcr, dev, block)) {
2181 Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev));
2186 BlockNumber = 0; /* start counting for second tape */
2189 return 1; /* end of tape reached */
2192 /* Save contents after write so that the header is serialized */
2193 memcpy(this_block->buf, block->buf, this_block->buf_len);
2196 * Toggle between two allocated blocks for efficiency.
2197 * Switch blocks so that the block just successfully written is
2198 * always in last_block.
2200 tblock = last_block;
2201 last_block = this_block;
2202 this_block = tblock;
2203 last_file = this_file;
2204 last_block_num = this_block_num;
2212 * First we label the tape, then we fill
2213 * it with data get a new tape and write a few blocks.
2215 static void qfillcmd()
2221 Pmsg0(0, "Test writing blocks of 64512 bytes to tape.\n");
2223 get_cmd("How many blocks do you want to write? (1000): ");
2230 sm_check(__FILE__, __LINE__, False);
2231 block = new_block(dev);
2234 i = block->buf_len - 100;
2236 rec->data = check_pool_memory_size(rec->data, i);
2237 memset(rec->data, i & 0xFF, i);
2240 Pmsg1(0, "Begin writing %d Bacula blocks to tape ...\n", count);
2241 for (i=0; i < count; i++) {
2246 if (!write_record_to_block(block, rec)) {
2247 Pmsg0(0, _("Error writing record to block.\n"));
2250 if (!write_block_to_dev(jcr->dcr, block)) {
2251 Pmsg0(0, _("Error writing block to device.\n"));
2257 if (dev_cap(dev, CAP_TWOEOF)) {
2264 sm_check(__FILE__, __LINE__, False);
2267 sm_check(__FILE__, __LINE__, False);
2272 * Fill a tape using raw write() command
2274 static void rawfill_cmd()
2279 uint32_t block_num = 0;
2284 block = new_block(dev);
2285 fd = open("/dev/urandom", O_RDONLY);
2287 read(fd, block->buf, block->buf_len);
2290 uint32_t *p = (uint32_t *)block->buf;
2291 srandom(time(NULL));
2292 for (i=0; i<block->buf_len/sizeof(uint32_t); i++) {
2296 p = (uint32_t *)block->buf;
2297 Pmsg1(0, "Begin writing raw blocks of %u bytes.\n", block->buf_len);
2300 stat = write(dev->fd, block->buf, block->buf_len);
2301 if (stat == (int)block->buf_len) {
2302 if ((block_num++ % 100) == 0) {
2307 for (i=1; i<(block->buf_len-sizeof(uint32_t))/sizeof(uint32_t)-1; i++) {
2316 printf("Write failed at block %u. stat=%d ERR=%s\n", block_num, stat,
2317 strerror(my_errno));
2324 * Fill a tape using raw write() command
2326 static void bfill_cmd()
2329 uint32_t block_num = 0;
2335 block = new_block(dev);
2336 fd = open("/dev/urandom", O_RDONLY);
2338 read(fd, block->buf, block->buf_len);
2341 uint32_t *p = (uint32_t *)block->buf;
2342 srandom(time(NULL));
2343 for (i=0; i<block->buf_len/sizeof(uint32_t); i++) {
2347 p = (uint32_t *)block->buf;
2348 Pmsg1(0, "Begin writing Bacula blocks of %u bytes.\n", block->buf_len);
2351 block->binbuf = block->buf_len;
2352 block->bufp = block->buf + block->binbuf;
2353 if (!write_block_to_dev(jcr->dcr, block)) {
2356 if ((block_num++ % 100) == 0) {
2361 for (i=1; i<(block->buf_len/sizeof(uint32_t)-1); i++) {
2367 printf("Write failed at block %u.\n", block_num);
2373 struct cmdstruct { char *key; void (*func)(); char *help; };
2374 static struct cmdstruct commands[] = {
2375 {"autochanger", autochangercmd, "test autochanger"},
2376 {"bsf", bsfcmd, "backspace file"},
2377 {"bsr", bsrcmd, "backspace record"},
2378 {"bfill", bfill_cmd, "fill tape using Bacula writes"},
2379 {"cap", capcmd, "list device capabilities"},
2380 {"clear", clearcmd, "clear tape errors"},
2381 {"eod", eodcmd, "go to end of Bacula data for append"},
2382 {"eom", eomcmd, "go to the physical end of medium"},
2383 {"fill", fillcmd, "fill tape, write onto second volume"},
2384 {"unfill", unfillcmd, "read filled tape"},
2385 {"fsf", fsfcmd, "forward space a file"},
2386 {"fsr", fsrcmd, "forward space a record"},
2387 {"help", helpcmd, "print this command"},
2388 {"label", labelcmd, "write a Bacula label to the tape"},
2389 {"load", loadcmd, "load a tape"},
2390 {"quit", quitcmd, "quit btape"},
2391 {"rawfill", rawfill_cmd, "use write() to fill tape"},
2392 {"readlabel", readlabelcmd, "read and print the Bacula tape label"},
2393 {"rectest", rectestcmd, "test record handling functions"},
2394 {"rewind", rewindcmd, "rewind the tape"},
2395 {"scan", scancmd, "read() tape block by block to EOT and report"},
2396 {"scanblocks", scan_blocks, "Bacula read block by block to EOT and report"},
2397 {"status", statcmd, "print tape status"},
2398 {"test", testcmd, "General test Bacula tape functions"},
2399 {"weof", weofcmd, "write an EOF on the tape"},
2400 {"wr", wrcmd, "write a single Bacula block"},
2401 {"rr", rrcmd, "read a single record"},
2402 {"qfill", qfillcmd, "quick fill command"},
2404 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
2412 while (get_cmd("*")) {
2413 sm_check(__FILE__, __LINE__, False);
2415 parse_args(cmd, &args, &argc, argk, argv, MAX_CMD_ARGS);
2416 for (i=0; i<comsize; i++) /* search for command */
2417 if (argc > 0 && fstrsch(argk[0], commands[i].key)) {
2418 (*commands[i].func)(); /* go execute command */
2423 Pmsg1(0, _("%s is an illegal command\n"), cmd);
2429 static void helpcmd()
2433 printf(_("Interactive commands:\n"));
2434 printf(_(" Command Description\n ======= ===========\n"));
2435 for (i=0; i<comsize; i++)
2436 printf(" %-10s %s\n", commands[i].key, commands[i].help);
2443 "\nVersion: " VERSION " (" BDATE ")\n\n"
2444 "Usage: btape <options> <device_name>\n"
2445 " -b <file> specify bootstrap file\n"
2446 " -c <file> set configuration file to file\n"
2447 " -d <nn> set debug level to nn\n"
2448 " -s turn off signals\n"
2450 " -? print this message.\n"
2456 * Get next input command from terminal. This
2457 * routine is REALLY primitive, and should be enhanced
2458 * to have correct backspacing, etc.
2461 get_cmd(char *prompt)
2465 fprintf(stdout, prompt);
2467 /* We really should turn off echoing and pretty this
2471 while ((ch = fgetc(stdin)) != EOF) {
2473 strip_trailing_junk(cmd);
2475 } else if (ch == 4 || ch == 0xd3 || ch == 0x8) {
2488 /* Dummies to replace askdir.c */
2489 int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;}
2490 int dir_send_job_status(JCR *jcr) {return 1;}
2492 int dir_update_volume_info(JCR *jcr, DEVICE *dev, int relabel)
2498 int dir_get_volume_info(JCR *jcr, enum get_vol_info_rw writing)
2500 Dmsg0(20, "Enter dir_get_volume_info\n");
2501 bstrncpy(jcr->VolCatInfo.VolCatName, jcr->VolumeName, sizeof(jcr->VolCatInfo.VolCatName));
2505 int dir_create_jobmedia_record(JCR *jcr)
2507 jcr->dcr->WroteVol = false;
2512 int dir_find_next_appendable_volume(JCR *jcr)
2514 Dmsg1(20, "Enter dir_find_next_appendable_volume. stop=%d\n", stop);
2515 return jcr->VolumeName[0] != 0;
2518 int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
2520 Dmsg0(20, "Enter dir_ask_sysop_to_mount_volume\n");
2521 if (jcr->VolumeName[0] == 0) {
2522 return dir_ask_sysop_to_create_appendable_volume(jcr, dev);
2524 /* Close device so user can use autochanger if desired */
2525 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
2528 force_close_dev(dev);
2529 Pmsg1(-1, "%s", dev->errmsg); /* print reason */
2530 if (jcr->VolumeName[0] == 0 || strcmp(jcr->VolumeName, "TestVolume2") == 0) {
2531 fprintf(stderr, "Mount second Volume on device %s and press return when ready: ",
2534 fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
2535 jcr->VolumeName, dev_name(dev));
2541 int dir_ask_sysop_to_create_appendable_volume(JCR *jcr, DEVICE *dev)
2544 Dmsg0(20, "Enter dir_ask_sysop_to_create_appendable_volume\n");
2546 set_volume_name("TestVolume1", 1);
2548 set_volume_name("TestVolume2", 2);
2550 /* Close device so user can use autochanger if desired */
2551 if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
2554 autochanger = autoload_device(jcr, dev, 1, NULL);
2556 force_close_dev(dev);
2557 fprintf(stderr, "Mount blank Volume on device %s and press return when ready: ",
2561 open_device(jcr, dev);
2568 static int my_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
2572 Dmsg0(20, "Enter my_mount_next_read_volume\n");
2573 Pmsg1(000, "End of Volume \"%s\"\n", jcr->VolumeName);
2575 if (LastBlock != block->BlockNumber) {
2576 VolBytes += block->block_len;
2578 LastBlock = block->BlockNumber;
2580 now -= jcr->run_time;
2584 kbs = (double)VolBytes / (1000.0 * (double)now);
2585 Pmsg3(-1, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
2586 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
2588 if (strcmp(jcr->VolumeName, "TestVolume2") == 0) {
2594 set_volume_name("TestVolume2", 2);
2596 create_vol_list(jcr);
2598 dev->state &= ~ST_READ;
2599 if (!acquire_device_for_read(jcr)) {
2600 Pmsg2(0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev), jcr->VolumeName);
2603 return 1; /* next volume mounted */
2606 static void set_volume_name(char *VolName, int volnum)
2608 DCR *dcr = jcr->dcr;
2609 VolumeName = VolName;
2611 pm_strcpy(&jcr->VolumeName, VolName);
2612 bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName));
2613 bstrncpy(jcr->VolCatInfo.VolCatName, VolName, sizeof(jcr->VolCatInfo.VolCatName));
2614 bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName));
2615 bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName));
2616 jcr->VolCatInfo.Slot = volnum;
2617 dcr->VolCatInfo.Slot = volnum;
2621 * Edit codes into ChangerCommand
2623 * %a = archive device name
2624 * %c = changer device name
2625 * %f = Client's name
2633 * omsg = edited output message
2634 * imsg = input string containing edit codes (%x)
2635 * cmd = command string (load, unload, ...)
2638 static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd)
2645 Dmsg1(400, "edit_device_codes: %s\n", imsg);
2646 for (p=imsg; *p; p++) {
2653 str = dev_name(jcr->device->dev);
2656 str = NPRT(jcr->device->changer_name);
2662 sprintf(add, "%d", jcr->VolCatInfo.Slot - 1);
2666 sprintf(add, "%d", jcr->VolCatInfo.Slot);
2669 case 'j': /* Job name */
2673 str = NPRT(jcr->VolumeName);
2676 str = NPRT(jcr->client_name);
2691 Dmsg1(400, "add_str %s\n", str);
2692 pm_strcat(&omsg, (char *)str);
2693 Dmsg1(400, "omsg=%s\n", omsg);
2700 * We are called here from "unfill" for each record on the tape.
2702 static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
2704 SESSION_LABEL label;
2706 if (stop > 1 && !dumped) { /* on second tape */
2709 dump_block(block, "First block on second tape");
2711 Pmsg4(-1, "Blk: FileIndex=%d: block=%u size=%d vol=%s\n",
2712 rec->FileIndex, block->BlockNumber, block->block_len, dev->VolHdr.VolName);
2713 Pmsg6(-1, " Rec: VId=%d VT=%d FI=%s Strm=%s len=%d state=%x\n",
2714 rec->VolSessionId, rec->VolSessionTime,
2715 FI_to_ascii(rec->FileIndex), stream_to_ascii(rec->Stream, rec->FileIndex),
2716 rec->data_len, rec->state);
2718 if (rec->FileIndex < 0) {
2720 dump_label_record(dev, rec, 1);
2722 switch (rec->FileIndex) {
2724 Pmsg0(-1, "Volume is prelabeled. This tape cannot be scanned.\n");
2727 unser_volume_label(dev, rec);
2728 Pmsg3(-1, "VOL_LABEL: block=%u size=%d vol=%s\n", block->BlockNumber,
2729 block->block_len, dev->VolHdr.VolName);
2733 unser_session_label(&label, rec);
2734 Pmsg1(-1, "SOS_LABEL: JobId=%u\n", label.JobId);
2737 unser_session_label(&label, rec);
2738 Pmsg2(-1, "EOS_LABEL: block=%u JobId=%u\n", block->BlockNumber,
2742 Pmsg0(-1, "EOM_LABEL:\n");
2744 case EOT_LABEL: /* end of all tapes */
2747 if (LastBlock != block->BlockNumber) {
2748 VolBytes += block->block_len;
2750 LastBlock = block->BlockNumber;
2752 now -= jcr->run_time;
2756 kbs = (double)VolBytes / (1000 * now);
2757 Pmsg3(000, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
2758 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
2760 Pmsg0(000, "End of all tapes.\n");
2768 if (++file_index != rec->FileIndex) {
2769 Pmsg3(000, "Incorrect FileIndex in Block %u. Got %d, expected %d.\n",
2770 block->BlockNumber, rec->FileIndex, file_index);
2772 if (LastBlock != block->BlockNumber) {
2773 VolBytes += block->block_len;
2775 if ((block->BlockNumber != LastBlock) && (block->BlockNumber % 50000) == 0) {
2778 now -= jcr->run_time;
2782 kbs = (double)VolBytes / (1000 * now);
2783 Pmsg3(000, "Read block=%u, VolBytes=%s rate=%.1f KB/s\n", block->BlockNumber,
2784 edit_uint64_with_commas(VolBytes, ec1), (float)kbs);
2786 LastBlock = block->BlockNumber;
2788 Pmsg1(000, "End of all blocks. Block=%u\n", block->BlockNumber);