]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/mount.c
- Fix ANSI labels to put EOF1 and EOF2 after each file mark.
[bacula/bacula] / bacula / src / stored / mount.c
index cf678ae0a61827d74d0e39d9505be7adb26e7c53..a7485b04489eb9955900ee07ee062161d9ae8951 100644 (file)
@@ -30,8 +30,6 @@
 #include "bacula.h"                   /* pull in global headers */
 #include "stored.h"                   /* pull in Storage Deamon headers */
 
-static bool rewrite_volume_label(DCR *dcr, bool recycle);
-
 
 /*
  * If release is set, we rewind the current volume,
@@ -70,7 +68,7 @@ mount_next_vol:
       dcr->VolCatInfo.Slot = 0;
       if (!dir_ask_sysop_to_mount_volume(dcr)) {
          Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
-             dev_name(dev));
+             dev->print_name());
         return false;
       }
    }
@@ -158,7 +156,8 @@ mount_next_vol:
    /* Ensure the device is open */
    /* If we have a dvd that requires mount, we first want to guess
     * which Volume is loaded, so we continue (if the wrong device is
-    * loaded, open_device would fail). */
+    * loaded, open_device just below would fail. 
+    */
    if (!dev->is_dvd()) {
       if (!open_device(dcr)) {
         if (dev->poll) {
@@ -215,7 +214,7 @@ read_volume:
       /* If not removable, Volume is broken */
       if (!dev_cap(dev, CAP_REM)) {
          Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
-           dcr->VolumeName, dev_name(dev));
+           dcr->VolumeName, dev->print_name());
         mark_volume_in_error(dcr);
         goto mount_next_vol;
       }
@@ -286,14 +285,17 @@ read_volume:
            return false;
         }
          Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"),
-           dcr->VolumeName, dev_name(dev));
+           dcr->VolumeName, dev->print_name());
         goto read_volume;      /* read label we just wrote */
       }
       /* If not removable, Volume is broken */
       if (!dev_cap(dev, CAP_REM)) {
          Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
-           dcr->VolumeName, dev_name(dev));
+           dcr->VolumeName, dev->print_name());
         mark_volume_in_error(dcr);
+        if (autochanger) {
+           mark_volume_not_inchanger(dcr);
+        }
         goto mount_next_vol;
       }
       /* NOTE! Fall-through wanted. */
@@ -340,8 +342,8 @@ read_volume:
       Jmsg(jcr, M_INFO, 0, _("Volume \"%s\" previously written, moving to end of data.\n"),
         dcr->VolumeName);
       if (!eod_dev(dev)) {
-         Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device \"%s\". ERR=%s\n"),
-           dev_name(dev), strerror_dev(dev));
+         Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device %s: ERR=%s\n"),
+           dev->print_name(), strerror_dev(dev));
         mark_volume_in_error(dcr);
         goto mount_next_vol;
       }
@@ -375,86 +377,6 @@ read_volume:
    return true;
 }
 
-/*
- * Write a volume label.
- *  Returns: true if OK
- *          false if unable to write it
- */
-static bool rewrite_volume_label(DCR *dcr, bool recycle)
-{
-   DEVICE *dev = dcr->dev;
-   JCR *jcr = dcr->jcr;
-
-   Dmsg1(190, "set append found freshly labeled volume. dev=%x\n", dev);
-   dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
-   dev->state |= ST_APPEND;
-   if (!write_volume_label_to_block(dcr)) {
-      Dmsg0(200, "Error from write volume label.\n");
-      return false;
-   }
-   /*
-    * If we are not dealing with a streaming device,
-    *  write the block now to ensure we have write permission.
-    *  It is better to find out now rather than later.
-    */
-   if (!dev_cap(dev, CAP_STREAM)) {
-      if (!rewind_dev(dev)) {
-         Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device \"%s\". ERR=%s\n"),
-              dev_name(dev), strerror_dev(dev));
-      }
-      if (recycle) {
-        if (!truncate_dev(dev)) {
-            Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device \"%s\". ERR=%s\n"),
-                 dev_name(dev), strerror_dev(dev));
-        }
-      }
-      /* Attempt write to check write permission */
-      Dmsg0(200, "Attempt to write to device.\n");
-      if (!write_ansi_ibm_label(dcr, dev->VolHdr.VolName)) {
-        return false;
-      }
-      if (!write_block_to_dev(dcr)) {
-         Jmsg2(jcr, M_ERROR, 0, _("Unable to write device \"%s\". ERR=%s\n"),
-           dev_name(dev), strerror_dev(dev));
-         Dmsg0(200, "===ERROR write block to dev\n");
-        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;
-   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;
-   }
-   Dmsg0(100, "dir_update_vol_info. Set Append\n");
-   bstrncpy(dev->VolCatInfo.VolCatStatus, "Append", sizeof(dev->VolCatInfo.VolCatStatus));
-   if (!dir_update_volume_info(dcr, true)) {  /* indicate doing relabel */
-      return false;
-   }
-   if (recycle) {
-      Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\" on device \"%s\", all previous data lost.\n"),
-        dcr->VolumeName, dev_name(dev));
-   } else {
-      Jmsg(jcr, M_INFO, 0, _("Wrote label to prelabeled Volume \"%s\" on device \"%s\"\n"),
-        dcr->VolumeName, dev_name(dev));
-   }
-   /*
-    * End writing real Volume label (from pre-labeled tape), or recycling
-    *  the volume.
-    */
-   Dmsg0(200, "OK from rewite vol label.\n");
-   return true;
-}
 
 
 /*
@@ -486,7 +408,7 @@ bool mount_next_read_volume(DCR *dcr)
       close_dev(dev);
       dev->state &= ~ST_READ;
       if (!acquire_device_for_read(jcr, dev)) {
-         Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev),
+         Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev->print_name(),
               dcr->VolumeName);
         return false;
       }
@@ -518,6 +440,7 @@ void release_volume(DCR *dcr)
    memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
    /* Force re-read of label */
    dev->state &= ~(ST_LABEL|ST_READ|ST_APPEND);
+   dev->label_type = B_BACULA_LABEL;
    dcr->VolumeName[0] = 0;
 
    if (dev->is_open() && (!dev->is_tape() || !dev_cap(dev, CAP_ALWAYSOPEN))) {