- bstrncpy(dcr->VolumeName, dev->VolHdr.VolumeName, sizeof(dcr->VolumeName));
- if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE) &&
- !(dir_find_next_appendable_volume(dcr) &&
- strcmp(dev->VolHdr.VolumeName, dcr->VolumeName) == 0)) { /* wrong tape mounted */
- Dmsg2(190, "Wrong tape mounted: %s. wants:%s\n", dev->VolHdr.VolumeName,
- dcr->VolumeName);
- /* Release volume reserved by dir_find_next_appendable_volume() */
- if (dcr->VolumeName[0]) {
- free_unused_volume(dcr);
- }
- if (dev->num_writers != 0) {
- Jmsg3(jcr, M_FATAL, 0, _("Wanted to append to Volume \"%s\", but device %s is busy writing on \"%s\" .\n"),
- dcr->VolumeName, dev->print_name(), dev->VolHdr.VolumeName);
- Dmsg3(200, "Wanted to append to Volume \"%s\", but device %s is busy writing on \"%s\" .\n",
- dcr->VolumeName, dev->print_name(), dev->VolHdr.VolumeName);
- goto get_out;
- }
- /* Wrong tape mounted, release it, then fall through to get correct one */
- Dmsg0(190, "Wrong tape mounted, release and try mount.\n");
- release = true;
- do_mount = true;
- } else {
- /*
- * At this point, the correct tape is already mounted, so
- * we do not need to do mount_next_write_volume(), unless
- * we need to recycle the tape.
- */
- recycle = strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0;
- Dmsg1(190, "Correct tape mounted. recycle=%d\n", recycle);
- if (recycle && dev->num_writers != 0) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot recycle volume \"%s\""
- " on device %s because it is in use by another job.\n"),
- dev->VolHdr.VolumeName, dev->print_name());
- goto get_out;
- }
- if (dev->num_writers == 0) {
- memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
- }
-
- /*
- * Insanity check
- *
- * Check to see if the tape position as defined by the OS is
- * the same as our concept. If it is not, we bail out, because
- * it means the user has probably manually rewound the tape.
- * Note, we check only if num_writers == 0, but this code will
- * also work fine for any number of writers. If num_writers > 0,
- * we probably should cancel all jobs using this device, or
- * perhaps even abort the SD, or at a minimum, mark the tape
- * in error. Another strategy with num_writers == 0, would be
- * to rewind the tape and do a new eod() request.
- */
- if (dev->is_tape() && dev->num_writers == 0) {
- int32_t file = dev->get_os_tape_file();
- if (file >= 0 && file != (int32_t)dev->get_file()) {
- Jmsg(jcr, M_FATAL, 0, _("Invalid tape position on volume \"%s\""
- " on device %s. Expected %d, got %d\n"),
- dev->VolHdr.VolumeName, dev->print_name(), dev->get_file(), file);
- goto get_out;
- }
- }
- }
- } else {
- /* Not already in append mode, so mount the device */
- Dmsg0(190, "Not in append mode, try mount.\n");
- ASSERT(dev->num_writers == 0);
- do_mount = true;