]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/label.c
Add comment to crypto.h
[bacula/bacula] / bacula / src / stored / label.c
index da6f9908ad0a0b8a21d060bf44b1af5306520ce6..e7fb9ee89f2b1cf90e90988728dcd3d9b14d067b 100644 (file)
@@ -1,16 +1,7 @@
-/*
- *
- *  label.c  Bacula routines to handle labels
- *
- *   Kern Sibbald, MM
- *
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *  label.c  Bacula routines to handle labels
+ *
+ *   Kern Sibbald, MM
+ *
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"                   /* pull in global headers */
 #include "stored.h"                   /* pull in Storage Deamon headers */
@@ -213,7 +213,12 @@ int read_dev_volume_label(DCR *dcr)
    }
 
    dev->set_labeled();               /* set has Bacula label */
-   new_volume(dcr, dev->VolHdr.VolumeName);
+   if (reserve_volume(dcr, dev->VolHdr.VolumeName) == NULL) {
+      Mmsg2(jcr->errmsg, _("Could not reserve volume %s on %s\n"),
+           dev->VolHdr.VolumeName, dev->print_name());
+      stat = VOL_NAME_ERROR;
+      goto bail_out;
+   }
 
    /* Compare Volume Names */
    Dmsg2(30, "Compare Vol names: VolName=%s hdr=%s\n", VolName?VolName:"*", dev->VolHdr.VolumeName);
@@ -316,8 +321,8 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
       goto bail_out;
    }
 
-   if (relabel) {
-      dev->close_part(dcr);              /* make sure closed for rename */
+   if (relabel && !dev->is_tape()) {
+      dev->close_part(dcr);              /* make sure DVD/file closed for rename */
    }
 
    /* Set the new filename for open, ... */
@@ -332,8 +337,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
    }
    Dmsg1(150, "Label type=%d\n", dev->label_type);
    if (!dev->rewind(dcr)) {
-      free_volume(dev);
-      memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
+      dev->clear_volhdr();
       Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->print_errmsg());
       if (!forge_on) {
          goto bail_out;
@@ -394,13 +398,17 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
    if (debug_level >= 20)  {
       dump_volume_label(dev);
    }
-   new_volume(dcr, VolName);
+   if (reserve_volume(dcr, VolName) == NULL) {
+      Mmsg2(dcr->jcr->errmsg, _("Could not reserve volume %s on %s\n"),
+           dev->VolHdr.VolumeName, dev->print_name());
+      goto bail_out;
+   }
+
    dev->clear_append();               /* remove append since this is PRE_LABEL */
    return true;
 
 bail_out:
-   free_volume(dev);
-   memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
+   dev->clear_volhdr();
    dev->clear_append();               /* remove append since this is PRE_LABEL */
    return false;
 }
@@ -589,8 +597,7 @@ void create_volume_label(DEVICE *dev, const char *VolName,
 
    ASSERT(dev != NULL);
 
-   free_volume(dev);         /* release any old volume */
-   memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
+   dev->clear_volhdr();          /* release any old volume */
 
    bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id));
    dev->VolHdr.VerNum = BaculaTapeVersion;