- if (!read_block_from_device(jcr, dev, block)) {
- Dmsg0(20, "!read_record()\n");
- if (dev->state & ST_EOT) {
- DEV_RECORD *trec = new_record();
-
- Dmsg3(100, "EOT. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec),
- block->BlockNumber, rec->remainder);
- if (!mount_cb(jcr, dev, block)) {
- Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec),
- block->BlockNumber, rec->remainder);
- ok = FALSE;
- /*
- * Create EOT Label so that Media record may
- * be properly updated because this is the last
- * tape.
- */
- trec->FileIndex = EOT_LABEL;
- trec->File = dev->file;
- trec->Block = rec->Block; /* return block last read */
- record_cb(jcr, dev, block, trec);
- free_record(trec);
- break;
- }
- Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec),
- block->BlockNumber, rec->remainder);
- /*
- * We just have a new tape up, now read the label (first record)
- * and pass it off to the callback routine, then continue
- * most likely reading the previous record.
- */
- read_block_from_device(jcr, dev, block);
- read_record_from_block(block, trec);
- get_session_record(dev, trec, &sessrec);
- record_cb(jcr, dev, block, trec);
- free_record(trec);
- goto next_record;
- }
- if (dev->state & ST_EOF) {
- Emsg2(M_INFO, 0, "Got EOF on device %s, Volume \"%s\"\n",
- dev_name(dev), jcr->VolumeName);
- Dmsg0(20, "read_record got eof. try again\n");
- continue;
- }
- if (dev->state & ST_SHORT) {
- Emsg0(M_INFO, 0, dev->errmsg);
- continue;
- }
-// display_error_status();
- ok = FALSE;
- break;
+ if (!read_block_from_device(dcr, CHECK_BLOCK_NUMBERS)) {
+ if (dev->at_eot()) {
+ DEV_RECORD *trec = new_record();
+ Jmsg(jcr, M_INFO, 0, "End of Volume at file %u on device %s, Volume \"%s\"\n",
+ dev->file, dev->print_name(), dcr->VolumeName);
+ if (!mount_cb(dcr)) {
+ Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
+ ok = false; /* Stop everything */
+ /*
+ * Create EOT Label so that Media record may
+ * be properly updated because this is the last
+ * tape.
+ */
+ trec->FileIndex = EOT_LABEL;
+ trec->File = dev->file;
+ ok = record_cb(dcr, trec);
+ free_record(trec);
+ if (jcr->mount_next_volume) {
+ jcr->mount_next_volume = false;
+ dev->clear_eot();
+ }
+ break;
+ }
+ jcr->mount_next_volume = false;
+ /*
+ * We just have a new tape up, now read the label (first record)
+ * and pass it off to the callback routine, then continue
+ * most likely reading the previous record.
+ */
+ read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK);
+ read_record_from_block(block, trec);
+ handle_session_record(dev, trec, &sessrec);
+ ok = record_cb(dcr, trec);
+ free_record(trec);
+ position_to_first_file(jcr, dev);
+ /* After reading label, we must read first data block */
+ continue;
+
+ } else if (dev->at_eof()) {
+ if (verbose) {
+ Jmsg(jcr, M_INFO, 0, "Got EOF at file %u on device %s, Volume \"%s\"\n",
+ dev->file, dev->print_name(), dcr->VolumeName);
+ }
+ Dmsg3(200, "Got EOF at file %u on device %s, Volume \"%s\"\n",
+ dev->file, dev->print_name(), dcr->VolumeName);
+ continue;
+ } else if (dev_state(dev, ST_SHORT)) {
+ Jmsg1(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ continue;
+ } else {
+ /* I/O error or strange end of tape */
+ display_tape_error_status(jcr, dev);
+ if (forge_on || jcr->ignore_label_errors) {
+ dev->fsr(1); /* try skipping bad record */
+ Pmsg0(000, "Did fsr\n");
+ continue; /* try to continue */
+ }
+ ok = false; /* stop everything */
+ break;
+ }