- if (!read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) {
- if (dev_state(dev, ST_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_name(dev), jcr->VolumeName);
- if (!mount_cb(jcr, dev, block)) {
- Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
- 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;
- ok = record_cb(jcr, dev, block, trec);
- free_record(trec);
- break;
- }
- /*
- * 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);
- position_to_first_file(jcr, dev);
- /* 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;