- /*
- * See if we have a fresh tape or tape with data.
- *
- * Note, if the LabelType is PRE_LABEL, it was labeled
- * but never written. If so, rewrite the label but set as
- * VOL_LABEL. We rewind and return the label (reconstructed)
- * in the block so that in the case of a new tape, data can
- * be appended just after the block label. If we are writing
- * an second volume, the calling routine will write the label
- * before writing the overflow block.
- *
- * If the tape is marked as Recycle, we rewrite the label.
- */
- if (dev->VolHdr.LabelType == PRE_LABEL || recycle) {
- Dmsg1(90, "ready_for_append found freshly labeled volume. dev=%x\n", dev);
- dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
- write_volume_label_to_block(jcr, dev, block);
- /*
- * Write the block now to ensure we have write permission.
- * It is better to find out now rather than later.
- */
- dev->VolCatInfo.VolCatBytes = 0;
- if (!rewind_dev(dev)) {
- Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- }
- if (!write_block_to_dev(dev, block)) {
- Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- return 0;
- }
- if (!rewind_dev(dev)) {
- Jmsg2(jcr, M_ERROR, 0, _("Unable to rewind device %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- return 0;
- }
- /* Recreate a correct volume label and return it in the block */
- write_volume_label_to_block(jcr, dev, block);
- dev->VolCatInfo.VolCatJobs = 1;
- dev->VolCatInfo.VolCatFiles = 1;
- dev->VolCatInfo.VolCatErrors = 0;
- dev->VolCatInfo.VolCatBlocks = 1;
- if (recycle) {
- dev->VolCatInfo.VolCatMounts++;
- dev->VolCatInfo.VolCatRecycles++;
- } else {
- dev->VolCatInfo.VolCatMounts = 1;
- dev->VolCatInfo.VolCatRecycles = 0;
- dev->VolCatInfo.VolCatWrites = 1;
- dev->VolCatInfo.VolCatReads = 1;
- }
- strcpy(dev->VolCatInfo.VolCatStatus, "Append");
- dir_update_volume_info(jcr, &dev->VolCatInfo);
- if (recycle) {
- Jmsg(jcr, M_INFO, 0, _("Recycled volume %s on device %s, all previous data lost.\n"),
- jcr->VolumeName, dev_name(dev));
- } else {
- Jmsg(jcr, M_INFO, 0, _("Wrote label to prelabeled Volume %s on device %s\n"),
- jcr->VolumeName, dev_name(dev));
- }
-
- } else {
- /* OK, at this point, we have a valid Bacula label, but
- * we need to position to the end of the volume.
- */
- Dmsg0(20, "Device previously written, moving to end of data\n");
- Jmsg(jcr, M_INFO, 0, _("Volume %s previously written, moving to end of data.\n"),
- jcr->VolumeName);
- if (!eod_dev(dev)) {
- Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- Jmsg(jcr, M_INFO, 0, _("Marking Volume %s in Error in Catalog.\n"),
- jcr->VolumeName);
- strcpy(dev->VolCatInfo.VolCatStatus, "Error");
- dir_update_volume_info(jcr, &dev->VolCatInfo);
- return 0;
- }
- /* *****FIXME**** we might do some checking for files too */
- if (dev_is_tape(dev)) {
- Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume at file=%d.\n"), dev_file(dev));
- if (dev->VolCatInfo.VolCatFiles != dev_file(dev) + 1) {
- /* ****FIXME**** this should refuse to write on tape */
- Jmsg(jcr, M_INFO, 0, _("Hey! Num files mismatch! Catalog Files=%d\n"), dev->VolCatInfo.VolCatFiles);
- }
- }
- /* Return an empty block */
- empty_block(block); /* we used it for reading so set for write */
- }
- dev->state |= ST_APPEND;
- Dmsg0(100, "Normal return from read_dev_for_append\n");
- return 1;