#include "bacula.h" /* pull in global headers */
#include "stored.h" /* pull in Storage Deamon headers */
-static bool rewrite_volume_label(DCR *dcr, bool recycle);
-
/*
* If release is set, we rewind the current volume,
dcr->VolCatInfo.Slot = 0;
if (!dir_ask_sysop_to_mount_volume(dcr)) {
Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
- dev_name(dev));
+ dev->print_name());
return false;
}
}
/* Ensure the device is open */
/* If we have a dvd that requires mount, we first want to guess
* which Volume is loaded, so we continue (if the wrong device is
- * loaded, open_device would fail). */
+ * loaded, open_device just below would fail.
+ */
if (!dev->is_dvd()) {
if (!open_device(dcr)) {
if (dev->poll) {
/* If not removable, Volume is broken */
if (!dev_cap(dev, CAP_REM)) {
Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
- dcr->VolumeName, dev_name(dev));
+ dcr->VolumeName, dev->print_name());
mark_volume_in_error(dcr);
goto mount_next_vol;
}
return false;
}
Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"),
- dcr->VolumeName, dev_name(dev));
+ dcr->VolumeName, dev->print_name());
goto read_volume; /* read label we just wrote */
}
/* If not removable, Volume is broken */
if (!dev_cap(dev, CAP_REM)) {
Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
- dcr->VolumeName, dev_name(dev));
+ dcr->VolumeName, dev->print_name());
mark_volume_in_error(dcr);
+ if (autochanger) {
+ mark_volume_not_inchanger(dcr);
+ }
goto mount_next_vol;
}
/* NOTE! Fall-through wanted. */
Jmsg(jcr, M_INFO, 0, _("Volume \"%s\" previously written, moving to end of data.\n"),
dcr->VolumeName);
if (!eod_dev(dev)) {
- Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device \"%s\". ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
+ Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device %s: ERR=%s\n"),
+ dev->print_name(), strerror_dev(dev));
mark_volume_in_error(dcr);
goto mount_next_vol;
}
return true;
}
-/*
- * Write a volume label.
- * Returns: true if OK
- * false if unable to write it
- */
-static bool rewrite_volume_label(DCR *dcr, bool recycle)
-{
- DEVICE *dev = dcr->dev;
- JCR *jcr = dcr->jcr;
-
- Dmsg1(190, "set append found freshly labeled volume. dev=%x\n", dev);
- dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
- dev->state |= ST_APPEND;
- if (!write_volume_label_to_block(dcr)) {
- Dmsg0(200, "Error from write volume label.\n");
- 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 */
- Dmsg0(200, "Attempt to write to device.\n");
- if (!write_ansi_ibm_label(dcr, dev->VolHdr.VolName)) {
- return false;
- }
- if (!write_block_to_dev(dcr)) {
- Jmsg2(jcr, M_ERROR, 0, _("Unable to write device \"%s\". ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- Dmsg0(200, "===ERROR write block to dev\n");
- 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));
- if (!dir_update_volume_info(dcr, true)) { /* indicate doing relabel */
- return false;
- }
- if (recycle) {
- Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\" on device \"%s\", all previous data lost.\n"),
- dcr->VolumeName, dev_name(dev));
- } else {
- Jmsg(jcr, M_INFO, 0, _("Wrote label to prelabeled Volume \"%s\" on device \"%s\"\n"),
- dcr->VolumeName, dev_name(dev));
- }
- /*
- * End writing real Volume label (from pre-labeled tape), or recycling
- * the volume.
- */
- Dmsg0(200, "OK from rewite vol label.\n");
- return true;
-}
/*
close_dev(dev);
dev->state &= ~ST_READ;
if (!acquire_device_for_read(jcr, dev)) {
- Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev),
+ Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev->print_name(),
dcr->VolumeName);
return false;
}
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
/* Force re-read of label */
dev->state &= ~(ST_LABEL|ST_READ|ST_APPEND);
+ dev->label_type = B_BACULA_LABEL;
dcr->VolumeName[0] = 0;
if (dev->is_open() && (!dev->is_tape() || !dev_cap(dev, CAP_ALWAYSOPEN))) {