]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/label.c
kes Close bat console windows first to eliminate error message
[bacula/bacula] / bacula / src / stored / label.c
index 19ca8badcdc1a868c3d4583c8f157f6b83ea83e4..5ec6a72b68141e9a2821a0b83e2352e152727c5d 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2008 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.
@@ -119,7 +119,6 @@ int read_dev_volume_label(DCR *dcr)
    bstrncpy(dev->VolHdr.Id, "**error**", sizeof(dev->VolHdr.Id));
 
   /* Read ANSI/IBM label if so requested */
-  
   want_ansi_label = dcr->VolCatInfo.LabelType != B_BACULA_LABEL ||
                     dcr->device->label_type != B_BACULA_LABEL;
   if (want_ansi_label || dev->has_cap(CAP_CHECKLABELS)) {
@@ -258,6 +257,7 @@ int read_dev_volume_label(DCR *dcr)
    return VOL_OK;
 
 bail_out:
+   volume_unused(dcr);                /* mark volume "released" */
    empty_block(block);
    dev->rewind(dcr);
    Dmsg1(150, "return %d\n", stat);
@@ -316,13 +316,15 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
    Dmsg0(150, "write_volume_label()\n");
    empty_block(dcr->block);
 
-   /* If relabeling, truncate the device */
-   if (relabel && !dev->truncate(dcr)) {
-      goto bail_out;
-   }
-
-   if (relabel && !dev->is_tape()) {
-      dev->close_part(dcr);              /* make sure DVD/file closed for rename */
+   if (relabel) {
+      volume_unused(dcr);             /* mark current volume unused */
+      /* Truncate device */
+      if (!dev->truncate(dcr)) {
+         goto bail_out;
+      }
+      if (!dev->is_tape()) {
+         dev->close_part(dcr);        /* make sure DVD/file closed for rename */
+      }
    }
 
    /* Set the new filename for open, ... */
@@ -344,6 +346,9 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
       }
    }
 
+   /* Temporarily mark in append state to enable writing */
+   dev->set_append();
+
    /* Create PRE_LABEL or VOL_LABEL if DVD */
    create_volume_label(dev, VolName, PoolName, dvdnow);
 
@@ -364,8 +369,6 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
    create_volume_label_record(dcr, dcr->rec);
    dcr->rec->Stream = 0;
 
-   /* Temporarily mark in append state to enable writing */
-   dev->set_append();
    if (!write_record_to_block(dcr->block, dcr->rec)) {
       Dmsg2(130, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
       goto bail_out;
@@ -408,6 +411,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
    return true;
 
 bail_out:
+   volume_unused(dcr);
    dev->clear_volhdr();
    dev->clear_append();               /* remove append since this is PRE_LABEL */
    return false;
@@ -505,7 +509,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle)
    }
    Dmsg0(150, "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 */
+   if (!dir_update_volume_info(dcr, true, true)) {  /* indicate doing relabel */
       return false;
    }
    if (recycle) {
@@ -698,13 +702,7 @@ bool write_session_label(DCR *dcr, int label)
    Dmsg1(130, "session_label record=%x\n", rec);
    switch (label) {
    case SOS_LABEL:
-      if (dev->is_tape()) {
-         dcr->StartBlock = dev->block_num;
-         dcr->StartFile  = dev->file;
-      } else {
-         dcr->StartBlock = (uint32_t)dev->file_addr;
-         dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
-      }
+      set_start_vol_position(dcr);
       break;
    case EOS_LABEL:
       if (dev->is_tape()) {
@@ -716,7 +714,7 @@ bool write_session_label(DCR *dcr, int label)
       }
       break;
    default:
-      Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
+      Jmsg1(jcr, M_ABORT, 0, _("Bad Volume session label = %d\n"), label);
       break;
    }
    create_session_label(dcr, rec, label);
@@ -733,16 +731,11 @@ bool write_session_label(DCR *dcr, int label)
       Dmsg0(150, "Cannot write session label to block.\n");
       if (!write_block_to_device(dcr)) {
          Dmsg0(130, "Got session label write_block_to_dev error.\n");
-         /* ****FIXME***** errno is not set here */
-         Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
-                           dev_vol_name(dev), strerror(errno));
          free_record(rec);
          return false;
       }
    }
    if (!write_record_to_block(block, rec)) {
-      Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
-                        dev_vol_name(dev), strerror(errno));
       free_record(rec);
       return false;
    }