]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dvd.c
Make bad Storage check in is_on_same_storage non-fatal
[bacula/bacula] / bacula / src / stored / dvd.c
index 8a45fd78c3917d8538039d1a065671b07ab406e9..b0c7656a67c4c71e32bd229717e2e16beaa778e6 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2005-2011 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.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  *
  *   dvd.c  -- Routines specific to DVD devices (and
@@ -5,21 +32,6 @@
  *
  *    Nicolas Boichat, MMV
  *
- *   Version $Id$
- */
-/*
-   Copyright (C) 2005-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
-
  */
 
 #include "bacula.h"
@@ -56,7 +68,7 @@ static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name)
       pm_strcat(archive_name, "/");
    }
 
-   pm_strcat(archive_name, dev->VolCatInfo.VolCatName);
+   pm_strcat(archive_name, dev->getVolCatName());
    /* if part > 1, append .# to the filename (where # is the part number) */
    if (dev->part > 1) {
       pm_strcat(archive_name, ".");
@@ -86,7 +98,7 @@ bool DEVICE::update_freespace()
    /* The device must be mounted in order to dvd-freespace to work */
    mount(1);
    
-   sm_check(__FILE__, __LINE__, false);
+   Dsm_check(400);
    icmd = device->free_space_command;
    
    if (!icmd) {
@@ -131,7 +143,7 @@ bool DEVICE::update_freespace()
       free_space_errno = EPIPE;
       clear_freespace_ok();         /* no valid freespace */
       Mmsg2(errmsg, _("Cannot run free space command. Results=%s ERR=%s\n"), 
-            results, be.strerror(status));
+            results, be.bstrerror(status));
       
       if (--timeout > 0) {
          Dmsg4(40, "Cannot get free space on device %s. free_space=%s, "
@@ -153,7 +165,7 @@ bool DEVICE::update_freespace()
    free_pool_memory(results);
    Dmsg4(29, "leave update_freespace: free_space=%s freespace_ok=%d free_space_errno=%d have_media=%d\n", 
       edit_uint64(free_space, ed1), !!is_freespace_ok(), free_space_errno, !!have_media());
-   sm_check(__FILE__, __LINE__, false);
+   Dsm_check(400);
    return ok;
 }
 
@@ -197,7 +209,7 @@ bool dvd_write_part(DCR *dcr)
       unlink(archive_name.c_str());
       dev->set_part_spooled(false);
       Dmsg1(29, "========= unlink(%s)\n", archive_name.c_str());
-      sm_check(__FILE__, __LINE__, false);
+      Dsm_check(400);
       return true;
    }
    
@@ -210,7 +222,7 @@ bool dvd_write_part(DCR *dcr)
    
    dev->clear_freespace_ok();             /* need to update freespace */
 
-   sm_check(__FILE__, __LINE__, false);
+   Dsm_check(400);
    Dmsg3(29, "dvd_write_part: device is %s, part is %d, is_mounted=%d\n", dev->print_name(), dev->part, dev->is_mounted());
    icmd = dev->device->write_part_command;
    
@@ -241,7 +253,7 @@ bool dvd_write_part(DCR *dcr)
    }
 
    Dmsg2(20, "Write part: cmd=%s timeout=%d\n", ocmd.c_str(), timeout);
-   status = run_program_full_output(ocmd.c_str(), timeout, results.c_str());
+   status = run_program_full_output(ocmd.c_str(), timeout, results.addr());
    Dmsg2(20, "Write part status=%d result=%s\n", status, results.c_str());
 
    dev->blank_dvd = false;
@@ -253,9 +265,9 @@ bool dvd_write_part(DCR *dcr)
       Dmsg1(100, "%s\n", dev->errmsg);
       dev->dev_errno = EIO;
       if (!dev->truncating) {
-         mark_volume_in_error(dcr);
+         dcr->mark_volume_in_error();
       }
-      sm_check(__FILE__, __LINE__, false);
+      Dsm_check(400);
       return false;
    }
    Jmsg(dcr->jcr, M_INFO, 0, _("Part %d (%lld bytes) written to DVD.\n"), dev->part, dev->part_size);
@@ -272,14 +284,14 @@ bool dvd_write_part(DCR *dcr)
    unlink(archive_name.c_str());
    dev->set_part_spooled(false);
    Dmsg1(29, "========= unlink(%s)\n", archive_name.c_str());
-   sm_check(__FILE__, __LINE__, false);
+   Dsm_check(400);
    
    /* growisofs umounted the device, so remount it (it will update the free space) */
    dev->clear_mounted();
    dev->mount(1);
    Jmsg(dcr->jcr, M_INFO, 0, _("Remaining free space %s on %s\n"), 
       edit_uint64_with_commas(dev->free_space, ed1), dev->print_name());
-   sm_check(__FILE__, __LINE__, false);
+   Dsm_check(400);
    return true;
 }
 
@@ -295,7 +307,7 @@ int dvd_open_next_part(DCR *dcr)
 
    Dmsg6(29, "Enter: == open_next_part part=%d npart=%d dev=%s vol=%s mode=%d file_addr=%d\n", 
       dev->part, dev->num_dvd_parts, dev->print_name(),
-         dev->VolCatInfo.VolCatName, dev->openmode, dev->file_addr);
+         dev->getVolCatName(), dev->openmode, dev->file_addr);
    if (!dev->is_dvd()) {
       Dmsg1(100, "Device %s is not dvd!!!!\n", dev->print_name()); 
       return -1;
@@ -305,7 +317,7 @@ int dvd_open_next_part(DCR *dcr)
    if (dev->can_append() && (dev->part > dev->num_dvd_parts) && 
        (dev->part_size == 0)) {
       Dmsg0(29, "open_next_part exited immediately (dev->part_size == 0).\n");
-      return dev->fd;
+      return dev->fd();
    }
 
    dev->close_part(dcr);               /* close current part */
@@ -363,14 +375,14 @@ int dvd_open_next_part(DCR *dcr)
             dev->set_part_spooled(false);
             dev->dev_errno = errno;
             Mmsg2(dev->errmsg, _("open_next_part can't unlink existing part %s, ERR=%s\n"), 
-                   archive_name.c_str(), be.strerror());
+                   archive_name.c_str(), be.bstrerror());
             return -1;
          }
       }
 #endif
    }
 
-   Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName
+   Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName()
          dev->openmode);
 
    /* Open next part.  Note, this sets part_size for part opened. */
@@ -379,7 +391,7 @@ int dvd_open_next_part(DCR *dcr)
    } 
    dev->set_labeled();                   /* all next parts are "labeled" */
    
-   return dev->fd;
+   return dev->fd();
 }
 
 /*
@@ -392,12 +404,12 @@ static bool dvd_open_first_part(DCR *dcr, int mode)
    DEVICE *dev = dcr->dev;
 
    Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_dvd_parts=%d append=%d\n", dev->print_name(), 
-         dev->VolCatInfo.VolCatName, dev->openmode, dev->num_dvd_parts, dev->can_append());
+         dev->getVolCatName(), dev->openmode, dev->num_dvd_parts, dev->can_append());
 
 
    dev->close_part(dcr);
 
-   Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName
+   Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName()
          mode);
    Dmsg0(100, "Set part=1\n");
    dev->part = 1;
@@ -418,11 +430,16 @@ static bool dvd_open_first_part(DCR *dcr, int mode)
  */
 boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence)
 {
-   DEVICE *dev = dcr->dev;
+   DEVICE *dev;
    boffset_t pos;
    char ed1[50], ed2[50];
+
+   if (!dcr) {                  /* can be NULL when called from rewind(NULL) */
+      return -1;
+   }
+   dev = dcr->dev;
    
-   Dmsg5(400, "Enter lseek_dvd fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd,
+   Dmsg5(400, "Enter lseek_dvd fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd(),
       edit_int64(offset, ed1), whence, dev->part, dev->num_dvd_parts);
 
    switch(whence) {
@@ -434,9 +451,9 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence)
              (uint64_t)offset < dev->part_start+dev->part_size) {
             /* We are staying in the current part, just seek */
 #if defined(HAVE_WIN32)
-            pos = _lseeki64(dev->fd, offset-dev->part_start, SEEK_SET);
+            pos = _lseeki64(dev->fd(), offset-dev->part_start, SEEK_SET);
 #else
-            pos = lseek(dev->fd, offset-dev->part_start, SEEK_SET);
+            pos = lseek(dev->fd(), offset-dev->part_start, SEEK_SET);
 #endif
             if (pos < 0) {
                return pos;
@@ -473,7 +490,7 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence)
       break;
    case SEEK_CUR:
       Dmsg1(400, "lseek_dvd SEEK_CUR to %s\n", edit_int64(offset, ed1));
-      if ((pos = lseek(dev->fd, (off_t)0, SEEK_CUR)) < 0) {
+      if ((pos = lseek(dev->fd(), 0, SEEK_CUR)) < 0) {
          Dmsg0(400, "Seek error.\n");
          return pos;                  
       }
@@ -505,7 +522,7 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence)
        *  right part number, simply seek
        */
       if (dev->is_part_spooled() && dev->part > dev->num_dvd_parts) {
-         if ((pos = lseek(dev->fd, (off_t)0, SEEK_END)) < 0) {
+         if ((pos = lseek(dev->fd(), 0, SEEK_END)) < 0) {
             return pos;   
          } else {
             Dmsg1(400, "lseek_dvd SEEK_END returns %s\n", 
@@ -596,7 +613,7 @@ void dvd_remove_empty_part(DCR *dcr)
       status = stat(archive_name.c_str(), &statp);
       if (status == 0 && statp.st_size == 0) {
          Dmsg3(100, "Unlink empty part in close call make_dvd_filename. part=%d num=%d vol=%s\n", 
-                part_save, dev->num_dvd_parts, dev->VolCatInfo.VolCatName);
+                part_save, dev->num_dvd_parts, dev->getVolCatName());
          Dmsg1(100, "unlink(%s)\n", archive_name.c_str());
          unlink(archive_name.c_str());
          if (part_save == dev->part) {
@@ -673,7 +690,7 @@ bool truncate_dvd(DCR *dcr)
    dcr->VolCatInfo.VolCatBytes = 0;
 
    /* Update catalog */
-   if (!dir_update_volume_info(dcr, false)) {
+   if (!dir_update_volume_info(dcr, false, true)) {
       return false;
    }
    
@@ -707,7 +724,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr)
       berrno be;
       dev->dev_errno = errno;
       Dmsg3(29, "check_can_write_on_non_blank_dvd: failed to open dir %s (dev=%s), ERR=%s\n", 
-            dev->device->mount_point, dev->print_name(), be.strerror());
+            dev->device->mount_point, dev->print_name(), be.bstrerror());
       return false;
    }
    
@@ -720,7 +737,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr)
          break;
       } else {
          Dmsg2(99, "check_can_write_on_non_blank_dvd: found %s (versus %s)\n", 
-               result->d_name, dev->VolCatInfo.VolCatName);
+               result->d_name, dev->getVolCatName());
          if (strcmp(result->d_name, ".") && strcmp(result->d_name, "..") &&
              strcmp(result->d_name, ".keep")) {
             /* Found a file, checking it is empty */
@@ -734,7 +751,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr)
                berrno be;
                dev->dev_errno = errno;
                Dmsg2(29, "check_can_write_on_non_blank_dvd: cannot stat file (file=%s), ERR=%s\n", 
-                  filename.c_str(), be.strerror());
+                  filename.c_str(), be.bstrerror());
                ok = false;
                break;
             }
@@ -771,7 +788,7 @@ int find_num_dvd_parts(DCR *dcr)
       DIR* dp;
       struct dirent *entry, *result;
       int name_max;
-      int len = strlen(dcr->VolCatInfo.VolCatName);
+      int len = strlen(dcr->getVolCatName());
 
       /* Now count the number of parts */
       name_max = pathconf(".", _PC_NAME_MAX);
@@ -783,13 +800,13 @@ int find_num_dvd_parts(DCR *dcr)
          berrno be;
          dev->dev_errno = errno;
          Dmsg3(29, "find_num_dvd_parts: failed to open dir %s (dev=%s), ERR=%s\n", 
-               dev->device->mount_point, dev->print_name(), be.strerror());
+               dev->device->mount_point, dev->print_name(), be.bstrerror());
          goto get_out;
       }
       
       entry = (struct dirent *)malloc(sizeof(struct dirent) + name_max + 1000);
 
-      Dmsg1(100, "Looking for Vol=%s\n", dcr->VolCatInfo.VolCatName);
+      Dmsg1(100, "Looking for Vol=%s\n", dcr->getVolCatName());
       for ( ;; ) {
          int flen;
          bool ignore;
@@ -803,7 +820,7 @@ int find_num_dvd_parts(DCR *dcr)
          ignore = true;
          if (flen >= len) {
             result->d_name[len] = 0;
-            if (strcmp(dcr->VolCatInfo.VolCatName, result->d_name) == 0) {
+            if (strcmp(dcr->getVolCatName(), result->d_name) == 0) {
                num_parts++;
                Dmsg1(100, "find_num_dvd_parts: found part: %s\n", result->d_name);
                ignore = false;