openmode = 0;
}
+/*
+ * This call closes the device, but it is used in DVD handling
+ * where we close one part and then open the next part. The
+ * difference between close_part() and close() is that close_part()
+ * saves the state information of the device (e.g. the Volume lable,
+ * the Volume Catalog record, ... This permits opening and closing
+ * the Volume parts multiple times without losing track of what the
+ * main Volume parameters are.
+ */
+void DEVICE::close_part(DCR *dcr)
+{
+ VOLUME_LABEL saveVolHdr;
+ VOLUME_CAT_INFO saveVolCatInfo; /* Volume Catalog Information */
+
+
+ memcpy(&saveVolHdr, &VolHdr, sizeof(saveVolHdr));
+ memcpy(&saveVolCatInfo, &VolCatInfo, sizeof(saveVolCatInfo));
+ close(); /* close current part */
+ memcpy(&VolHdr, &saveVolHdr, sizeof(VolHdr));
+ memcpy(&VolCatInfo, &saveVolCatInfo, sizeof(VolCatInfo));
+ memcpy(&dcr->VolCatInfo, &saveVolCatInfo, sizeof(dcr->VolCatInfo));
+}
+
+
bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */
int dvd_open_next_part(DCR *dcr)
{
DEVICE *dev = dcr->dev;
- VOLUME_LABEL VolHdr;
Dmsg6(29, "Enter: == open_next_part part=%d npart=%d dev=%s vol=%s mode=%d file_addr=%d\n",
dev->part, dev->num_dvd_parts, dev->print_name(),
return dev->fd;
}
- /*
- * Note, when we close, the Volume header is zeroed. Since
- * we reopen, but are in fact opening the same volume without
- * re-reading the Volume header, we simply save and restore it.
- */
- memcpy(&VolHdr, &dev->VolHdr, sizeof(VolHdr));
- dev->close(); /* close current part */
- memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ dev->close_part(dcr); /* close current part */
/*
* If we have a spooled part open, write it to the
if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
return -1;
}
- /* Restore Volume header record */
- memcpy(&dev->VolHdr, &VolHdr, sizeof(dev->VolHdr));
dev->set_labeled(); /* all next parts are "labeled" */
return dev->fd;
int dvd_open_first_part(DCR *dcr, int mode)
{
DEVICE *dev = dcr->dev;
- VOLUME_LABEL VolHdr;
Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_dvd_parts=%d append=%d\n", dev->print_name(),
dev->VolCatInfo.VolCatName, dev->openmode, dev->num_dvd_parts, dev->can_append());
- /*
- * Note, when we close, the Volume header is zeroed. Since
- * we reopen, but are in fact opening the same volume without
- * re-reading the Volume header, we simply save and restore it.
- */
- memcpy(&VolHdr, &dev->VolHdr, sizeof(VolHdr));
- dev->close();
- memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ dev->close_part(dcr);
Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName,
mode);
dev->part = 1;
dev->part_start = 0;
-
- /* Restore Volume header record */
- memcpy(&dev->VolHdr, &VolHdr, sizeof(dev->VolHdr));
if (dev->open(dcr, mode) < 0) {
Dmsg0(400, "open dev() failed\n");
return -1;
{
DEVICE* dev = dcr->dev;
- dev->close();
- memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ dev->close_part(dcr);
if (!unmount_dvd(dev, 1)) {
Dmsg0(400, "truncate_dvd: Failed to unmount DVD\n");
return false;
}
- dev->close();
- memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ dev->close_part(dcr);
Dmsg0(400, "truncate_dvd: Opening first part (2)...\n");
filename.c_str(), be.strerror());
return false;
}
- Dmsg2(99, "check_can_write_on_non_blank_dvd: size of %s is %d\n",
+ Dmsg2(99, "check_can_write_on_non_blank_dvd: size of %s is %lld\n",
filename.c_str(), filestat.st_size);
matched = filestat.st_size == 0;
}