empty_block(block);
return VOL_OK;
}
+ Dmsg0(100, "No volume label - bailing out\n");
stat = VOL_NO_LABEL;
goto bail_out;
}
*
* 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 write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
+ const char *PoolName, bool dvdnow)
{
DEVICE *dev = dcr->dev;
}
}
- /* Create PRE_LABEL */
- create_volume_label(dev, VolName, PoolName);
+ /* Create PRE_LABEL or VOL_LABEL if DVD */
+ create_volume_label(dev, VolName, PoolName, dvdnow);
/*
* If we have already detected an ANSI label, re-read it
Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
goto bail_out;
}
+
+ /* Now commit block to DVD if we should write now */
+ if (dev->is_dvd() && dvdnow) {
+ if (!dvd_write_part(dcr)) {
+ Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
+ goto bail_out;
+ }
+ }
+
Dmsg0(99, " Wrote block to device\n");
if (dev->weof(1)) {
{
DEVICE *dev = dcr->dev;
JCR *jcr = dcr->jcr;
- bool can_write = true;
if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
- /* If device is DVD, attempt to create it */
- if (!dev->is_dvd()) {
- return false;
- }
- if (dev->open(dcr, CREATE_READ_WRITE) < 0) {
- /* We forge on for a DVD but don't do any writing */
- can_write = false;
- }
+ return false;
}
Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev);
dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
dev->set_append();
- if (can_write) {
- if (!write_volume_label_to_block(dcr)) {
- Dmsg0(200, "Error from write volume label.\n");
- return false;
- }
+ if (!write_volume_label_to_block(dcr)) {
+ Dmsg0(200, "Error from write volume label.\n");
+ return false;
}
+
+ dev->VolCatInfo.VolCatBytes = 0; /* reset byte count */
+
/*
* If we are not dealing with a streaming device,
* write the block now to ensure we have write permission.
* We do not write the block now if this is an ANSI label. This
* avoids re-writing the ANSI label, which we do not want to do.
*/
- if (can_write && !dev_cap(dev, CAP_STREAM)) {
+ if (!dev_cap(dev, CAP_STREAM)) {
if (!dev->rewind(dcr)) {
- Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s: ERR=%s\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("Rewind error on device %s: ERR=%s\n"),
dev->print_name(), dev->bstrerror());
+ return false;
}
if (recycle) {
if (!dev->truncate(dcr)) {
- Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device %s: ERR=%s\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"),
dev->print_name(), dev->bstrerror());
+ 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;
* End writing real Volume label (from pre-labeled tape), or recycling
* the volume.
*/
- Dmsg0(200, "OK from rewite vol label.\n");
+ Dmsg0(200, "OK from rewrite vol label.\n");
return true;
}
/*
* Create a volume label in memory
*/
-void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName)
+void create_volume_label(DEVICE *dev, const char *VolName,
+ const char *PoolName, bool dvdnow)
{
DEVRES *device = (DEVRES *)dev->device;
bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id));
dev->VolHdr.VerNum = BaculaTapeVersion;
- dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */
+ if (dev->is_dvd() && dvdnow) {
+ /* We do not want to re-label a DVD so write VOL_LABEL now */
+ dev->VolHdr.LabelType = VOL_LABEL;
+ } else {
+ dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */
+ }
bstrncpy(dev->VolHdr.VolumeName, VolName, sizeof(dev->VolHdr.VolumeName));
bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
return false;
}
- Dmsg6(20, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d "
+ Dmsg6(50, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d "
"remainder=%d\n", jcr->JobId,
FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len,
rec->remainder);
free_record(rec);
- Dmsg2(20, "Leave write_session_label Block=%d File=%d\n",
+ Dmsg2(50, "Leave write_session_label Block=%d File=%d\n",
dev->block_num, dev->file);
return true;
}