return true;
#endif
ASSERT(block->binbuf == ((uint32_t) (block->bufp - block->buf)));
+ ASSERT(dev->is_open());
/* dump_block(block, "before write"); */
if (dev->at_weot()) {
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
DEV_BLOCK *block = dcr->block;
+
+ ASSERT(dev->is_open());
if (dev->at_eot()) {
return false;
}
}
dev->rewind(dcr);
- write_new_volume_label_to_dev(dcr, cmd, "Default", false,/*no relabel*/ true /* label dvd now */);
+ write_new_volume_label_to_dev(dcr, cmd, "Default", true /* label dvd now */);
Pmsg1(-1, _("Wrote Volume label for volume \"%s\".\n"), cmd);
}
DEVICE *dev = dcr->dev;
int label_status;
int mode;
- const char *volname = (relabel == 1) ? oldname : newname;
+ const char *volname = (relabel == 0) ? newname : oldname;
char ed1[50];
steal_device_lock(dev, &hold, BST_WRITING_LABEL);
Dmsg1(100, "Stole device %s lock, writing label.\n", dev->print_name());
-
Dmsg0(90, "try_autoload_device - looking for volume_info\n");
+ if (relabel && dev->is_dvd()) {
+ /* Fake at least one partition to ensure that we look for the old volume */
+ dcr->VolCatInfo.VolCatParts = 1;
+ }
+
if (!try_autoload_device(dcr->jcr, slot, volname)) {
goto bail_out; /* error */
}
} else {
mode = CREATE_READ_WRITE;
}
-
- if (relabel) {
- dev->truncating = true; /* let open() know we will truncate it */
+ if (dev->is_dvd()) {
+ bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName));
}
- /* Set old volume name for open if relabeling */
- bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName));
+
if (dev->open(dcr, mode) < 0) {
bnet_fsend(dir, _("3910 Unable to open device %s: ERR=%s\n"),
dev->print_name(), dev->strerror());
/* See what we have for a Volume */
label_status = read_dev_volume_label(dcr);
- /* Set new volume name */
- bstrncpy(dcr->VolCatInfo.VolCatName, newname, sizeof(dcr->VolCatInfo.VolCatName));
switch(label_status) {
case VOL_NAME_ERROR:
case VOL_VERSION_ERROR:
bnet_fsend(dir, _("3922 Cannot relabel an ANSI/IBM labeled Volume.\n"));
break;
}
+ if (relabel && dev->is_dvd()) {
+ /* Save dev VolumeName */
+ bstrncpy(dcr->VolumeName, dev->VolCatInfo.VolCatName, sizeof(dcr->VolumeName));
+ /* Use new name for DVD truncation */
+ bstrncpy(dev->VolCatInfo.VolCatName, newname, sizeof(dev->VolCatInfo.VolCatName));
+ if (!dev->truncate(dcr)) {
+ bnet_fsend(dir, _("3912 Failed to truncate previous DVD volume.\n"));
+ /* Restore device VolName */
+ bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName));
+ break;
+ }
+ /* Restore device VolName */
+ bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName));
+ }
+ free_volume(dev); /* release old volume name */
/* Fall through wanted! */
case VOL_IO_ERROR:
case VOL_NO_LABEL:
- if (!write_new_volume_label_to_dev(dcr, newname, poolname,
- relabel, true /* write dvd now */)) {
+ if (!write_new_volume_label_to_dev(dcr, newname, poolname, true /* write dvd now */)) {
bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), dev->bstrerror());
break;
}
* This routine should be used only when labeling a blank tape.
*/
bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
- const char *PoolName, bool relabel, bool dvdnow)
+ const char *PoolName, bool dvdnow)
{
DEVICE *dev = dcr->dev;
Dmsg0(99, "write_volume_label()\n");
empty_block(dcr->block);
- /* If relabeling, truncate the device */
- if (relabel && !dev->truncate(dcr)) {
- goto bail_out;
- }
-
- if (relabel) {
- dev->close_part(dcr); /* make sure closed for rename */
- }
-
- /* Set the new filename for open, ... */
- bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName));
- bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName));
- Dmsg1(150, "New VolName=%s\n", VolName);
if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
/* If device is not tape, attempt to create it */
if (dev->is_tape() || dev->open(dcr, CREATE_READ_WRITE) < 0) {
/* Now commit block to DVD if we should write now */
if (dev->is_dvd() && dvdnow) {
- Dmsg1(150, "New VolName=%s\n", dev->VolCatInfo.VolCatName);
if (!dvd_write_part(dcr)) {
Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
goto bail_out;
Dmsg0(150, "Create volume label\n");
/* Create a new Volume label and write it to the device */
if (!write_new_volume_label_to_dev(dcr, dcr->VolumeName,
- dcr->pool_name, false, /* no relabel */ false /* defer DVD label */)) {
+ dcr->pool_name, false /* defer DVD label */)) {
Dmsg0(150, "!write_vol_label\n");
mark_volume_in_error(dcr);
return try_next_vol;
int read_dvd_volume_label(DCR *dcr, bool write);
void create_session_label(DCR *dcr, DEV_RECORD *rec, int label);
void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName, bool dvdnow);
-bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
- const char *PoolName, bool relabel, bool dvdnow);
+bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName, bool dvdnow);
#define ANSI_VOL_LABEL 0
#define ANSI_EOF_LABEL 1
#define ANSI_EOV_LABEL 2