+ Dmsg1(190, "ready_for_append found freshly labeled volume. dev=%x\n", dev);
+ dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
+ if (!write_volume_label_to_block(dcr, block)) {
+ return false;
+ }
+ /*
+ * If we are not dealing with a streaming device,
+ * write the block now to ensure we have write permission.
+ * It is better to find out now rather than later.
+ */
+ if (!dev_cap(dev, CAP_STREAM)) {
+ if (!rewind_dev(dev)) {
+ Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device \"%s\". ERR=%s\n"),
+ dev_name(dev), strerror_dev(dev));
+ }
+ if (recycle) {
+ if (!truncate_dev(dev)) {
+ Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device \"%s\". ERR=%s\n"),
+ dev_name(dev), strerror_dev(dev));
+ }
+ }
+ /* Attempt write to check write permission */
+ if (!write_block_to_dev(dcr, block)) {
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to write device \"%s\". ERR=%s\n"),
+ dev_name(dev), strerror_dev(dev));
+ return false;
+ }
+ }
+ /* Set or reset Volume statistics */
+ dev->VolCatInfo.VolCatJobs = 0;
+ dev->VolCatInfo.VolCatFiles = 0;
+ dev->VolCatInfo.VolCatBytes = 1;
+ dev->VolCatInfo.VolCatErrors = 0;
+ dev->VolCatInfo.VolCatBlocks = 0;
+ dev->VolCatInfo.VolCatRBytes = 0;
+ if (recycle) {
+ dev->VolCatInfo.VolCatMounts++;
+ dev->VolCatInfo.VolCatRecycles++;
+ } else {
+ dev->VolCatInfo.VolCatMounts = 1;
+ dev->VolCatInfo.VolCatRecycles = 0;
+ dev->VolCatInfo.VolCatWrites = 1;
+ dev->VolCatInfo.VolCatReads = 1;
+ }
+ Dmsg0(100, "dir_update_vol_info. Set Append\n");
+ bstrncpy(dev->VolCatInfo.VolCatStatus, "Append", sizeof(dev->VolCatInfo.VolCatStatus));
+ dir_update_volume_info(dcr, true); /* indicate doing relabel */
+ if (recycle) {
+ Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\" on device \"%s\", all previous data lost.\n"),
+ jcr->VolumeName, dev_name(dev));
+ } else {
+ Jmsg(jcr, M_INFO, 0, _("Wrote label to prelabeled Volume \"%s\" on device \"%s\"\n"),
+ jcr->VolumeName, dev_name(dev));
+ }
+ /*
+ * End writing real Volume label (from pre-labeled tape), or recycling
+ * the volume.
+ */
+ return true;
+}
+
+
+/*
+ * Mark volume in error in catalog
+ */
+void mark_volume_in_error(JCR *jcr, DEVICE *dev)
+{
+ Jmsg(jcr, M_INFO, 0, _("Marking Volume \"%s\" in Error in Catalog.\n"),
+ jcr->VolumeName);
+ bstrncpy(dev->VolCatInfo.VolCatStatus, "Error", sizeof(dev->VolCatInfo.VolCatStatus));
+ Dmsg0(100, "dir_update_vol_info. Set Error.\n");
+ dir_update_volume_info(jcr->dcr, false);
+}
+
+/*
+ * If we are reading, we come here at the end of the tape
+ * and see if there are more volumes to be mounted.
+ */
+bool mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)