- if (!read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) {
- Dmsg0(20, "!read_record()\n");
- if (dev_state(dev, 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);
- Jmsg(jcr, M_INFO, 0, "End of Volume at file %u on device %s, Volume \"%s\"\n",
- dev->file, dev_name(dev), jcr->VolumeName);
- if (!mount_cb(jcr, dev, block)) {
- Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
- 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 */
- ok = 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, NO_BLOCK_NUMBER_CHECK);
- read_record_from_block(block, trec);
- handle_session_record(dev, trec, &sessrec);
- ok = record_cb(jcr, dev, block, trec);
- free_record(trec);
- /*
- * Now find and position to first file and block
- * on this tape.
- */
- if (jcr->bsr) {
- BSR *bsr;
-
- jcr->bsr->reposition = true;
- bsr = find_next_bsr(jcr->bsr, dev);
- if (bsr) {
- Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"),
- bsr->volfile->sfile, bsr->volblock->sblock);
- Dmsg4(100, "Reposition new from (file:block) %d:%d to %d:%d\n",
- dev->file, dev->block_num, bsr->volfile->sfile,
- bsr->volblock->sblock);
- reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock);
- Dmsg2(100, "Now at (file:block) %d:%d\n",
- dev->file, dev->block_num);
- }
- }
- /* After reading label, we must read first data block */
- continue;
+ 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);
+ volume_unused(dcr); /* mark volume unused */
+ 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;
+ /*
+ * The Device can change at the end of a tape, so refresh it
+ * and the block from the dcr.
+ */
+ dev = dcr->dev;
+ block = dcr->block;
+ /*
+ * 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(dcr, block, trec);
+ handle_session_record(dev, trec, &sessrec);
+ ok = record_cb(dcr, trec);
+ free_record(trec);
+ position_to_first_file(jcr, dcr);
+ /* After reading label, we must read first data block */
+ continue;