+
+ switch (check_volume_label(ask, autochanger)) {
+ case check_next_vol:
+ goto mount_next_vol;
+ case check_read_vol:
+ goto read_volume;
+ case check_error:
+ goto bail_out;
+ case check_ok:
+ break;
+ }
+
+ /*
+ * See if we have a fresh tape or a tape with data.
+ *
+ * Note, if the LabelType is PRE_LABEL, it was labeled
+ * but never written. If so, rewrite the label but set as
+ * VOL_LABEL. We rewind and return the label (reconstructed)
+ * in the block so that in the case of a new tape, data can
+ * be appended just after the block label. If we are writing
+ * a second volume, the calling routine will write the label
+ * before writing the overflow block.
+ *
+ * If the tape is marked as Recycle, we rewrite the label.
+ */
+ recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0;
+ if (dev->VolHdr.LabelType == PRE_LABEL || recycle) {
+ if (!rewrite_volume_label(dcr, recycle)) {
+ mark_volume_in_error();
+ goto mount_next_vol;
+ }
+ } else {
+ /*
+ * OK, at this point, we have a valid Bacula label, but
+ * we need to position to the end of the volume, since we are
+ * just now putting it into append mode.
+ */
+ Dmsg0(200, "Device previously written, moving to end of data\n");
+ Jmsg(jcr, M_INFO, 0, _("Volume \"%s\" previously written, moving to end of data.\n"),
+ VolumeName);
+
+ if (!dev->eod(dcr)) {
+ Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device %s: ERR=%s\n"),
+ dev->print_name(), dev->bstrerror());
+ mark_volume_in_error();
+ goto mount_next_vol;
+ }
+ if (!is_eod_valid()) {
+ goto mount_next_vol;
+ }
+
+ dev->VolCatInfo.VolCatMounts++; /* Update mounts */
+ Dmsg1(150, "update volinfo mounts=%d\n", dev->VolCatInfo.VolCatMounts);
+ if (!dir_update_volume_info(dcr, false, false)) {
+ goto bail_out;
+ }
+
+ /* Return an empty block */
+ empty_block(block); /* we used it for reading so set for write */
+ }
+ dev->set_append();
+ Dmsg1(150, "set APPEND, normal return from mount_next_write_volume. dev=%s\n",
+ dev->print_name());
+
+ unlock_volumes();
+ return true;
+
+bail_out:
+ unlock_volumes();
+ return false;
+}
+
+int DCR::check_volume_label(bool &ask, bool &autochanger)
+{
+ int vol_label_status;