- return VOL_OK;
-}
-
-/* Read the volume label by guessing the volume name. (only for DVD devices)
- * write is true if we are reading the label before writing to the device.
- *
- * If the volume name cannot be guessed :
- * Writing : returns the label of the current file (on the harddisk).
- * Reading : returns an error
- */
-int read_dvd_volume_label(DCR *dcr, bool write)
-{
- int vol_label_status;
- DEVICE *dev = dcr->dev;
- JCR *jcr = dcr->jcr;
- Dmsg3(100, "Enter: dvd_volume_label device=%s vol=%s dev_Vol=%s\n",
- dev->print_name(), dcr->VolumeName, dev->VolHdr.VolumeName);
-
- if (!dev->is_dvd()) {
- Jmsg1(jcr, M_ABORT, 0, _("Device %s is not a DVD.\n"), dev->print_name());
- return -1; /* for compiler, won't get here */
- }
-
- if (!write && (dcr->VolCatInfo.VolCatParts == 0)) {
- Dmsg0(100, "Leave read_dvd_volume_label !writing, and VolCatParts == 0\n");
- return read_dev_volume_label(dcr);
- }
-
- /*
- * For mounted devices, try to guess the Volume name
- * and read the label if possible.
- */
- if (!can_open_mounted_dev(dev)) {
- if (!write || dcr->VolCatInfo.VolCatParts > 0) {
- Mmsg2(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula labeled Volume."),
- dev->print_name(), dcr->VolumeName);
- Dmsg0(100, "Leave read_dvd_volume_label VOL_NO_LABEL (!open_mounted_dev)\n");
- return VOL_NO_LABEL;
- }
-
- /* At this point, we are writing */
- if (dev->free_space_errno < 0) {
- Dmsg0(100, "Exit: read_dvd_volume_label !free_space VOL_NO_MEDIA\n");
- Mmsg2(jcr->errmsg, _("free_space error on %s. The current medium is probably not writable: ERR=%s.\n"),
- dev->print_name(), dev->errmsg);
- return VOL_NO_MEDIA;
- }
-
- /*
- * If we can't guess the name, and we are writing,
- * just reopen the right file with open_first_part.
- */
- if (open_first_part(dev, OPEN_READ_WRITE) < 0) {
- berrno be;
- Mmsg2(jcr->errmsg, _("open_first_part error on %s: ERR=%s.\n"),
- dev->print_name(), be.strerror());
- Dmsg0(100, "Leave read_dvd_volume_label VOL_IO_ERROR (!open_mounted_dev && !open_first_part)\n");
- return VOL_IO_ERROR;
- }
-
- Dmsg0(100, "Leave read_dvd_volume_label !open_mounted_dev\n");
- return read_dev_volume_label(dcr);
-
- } else {
- /*
- * If we get here, we can open the mounted device
- */
- if (write && dcr->dev->free_space_errno < 0) {
- Dmsg0(100, "Leave read_dvd_volume_label !free_space VOL_NO_MEDIA\n");
- Mmsg2(jcr->errmsg, _("free_space error on %s. The current medium is probably not writable: ERR=%s.\n"),
- dev->print_name(), dev->errmsg);
- return VOL_NO_MEDIA;
- }
-
- if (!write || dcr->VolCatInfo.VolCatParts > 0) {
- Dmsg0(100, "Exit: read_dvd_volume_label (open_mounted_dev && (!write || dcr->VolCatInfo.VolCatParts > 0))\n");
- return read_dev_volume_label(dcr);
- }
-
- /* At this point, we are writing */
- if (open_first_part(dcr->dev, OPEN_READ_WRITE) < 0) {
- berrno be;
- Mmsg2(jcr->errmsg, _("open_first_part error on %s: ERR=%s.\n"),
- dev->print_name(), be.strerror());
- Dmsg0(100, "Leave read_dvd_volume_label VOL_IO_ERROR (open_mounted_dev && !open_first_part)\n");
- return VOL_IO_ERROR;
- }
- vol_label_status = read_dev_volume_label(dcr);
-
- /* When writing, if the guessed volume name is not the right volume name,
- * report the error, otherwise, just continue with the right file.
- */
- if (vol_label_status != VOL_NAME_ERROR) {
- Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && !VOL_NAME_ERROR)\n");
- dev->clear_labeled();
- return read_dev_volume_label(dcr);
- } else {
- Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && VOL_NAME_ERROR)\n");
- return vol_label_status;