]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/scan.c
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / stored / scan.c
index 80f8f76957a5b008ce9429d6422cace71aeed9e9..d5afc0e80bd1b45d3dc953ece8445917bb5af34c 100644 (file)
@@ -1,3 +1,21 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2016 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
 /*
  *
  *   scan.c scan a directory (on a removable file) for a valid
@@ -5,21 +23,6 @@
  *
  *    Kern Sibbald, MMVI
  *
- *   Version $Id$
- */
-/*
-   Copyright (C) 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"
@@ -36,13 +39,17 @@ bool DEVICE::scan_dir_for_volume(DCR *dcr)
    int name_max;
    char *mount_point;
    VOLUME_CAT_INFO dcrVolCatInfo, devVolCatInfo;
+   char VolumeName[MAX_NAME_LENGTH];
    struct stat statp;
    bool found = false;
    POOL_MEM fname(PM_FNAME);
    bool need_slash = false;
    int len;
 
-   
+   dcrVolCatInfo = dcr->VolCatInfo;     /* structure assignment */
+   devVolCatInfo = VolCatInfo;          /* structure assignment */
+   bstrncpy(VolumeName, dcr->VolumeName, sizeof(VolumeName));
+
    name_max = pathconf(".", _PC_NAME_MAX);
    if (name_max < 1024) {
       name_max = 1024;
@@ -53,15 +60,15 @@ bool DEVICE::scan_dir_for_volume(DCR *dcr)
    } else {
       mount_point = device->device_name;
    }
-      
+
    if (!(dp = opendir(mount_point))) {
       berrno be;
       dev_errno = errno;
-      Dmsg3(29, "scan_dir_for_vol: failed to open dir %s (dev=%s), ERR=%s\n", 
-            mount_point, print_name(), be.strerror());
+      Dmsg3(29, "scan_dir_for_vol: failed to open dir %s (dev=%s), ERR=%s\n",
+            mount_point, print_name(), be.bstrerror());
       goto get_out;
    }
-   
+
    len = strlen(mount_point);
    if (len > 0) {
       need_slash = !IsPathSeparator(mount_point[len - 1]);
@@ -70,15 +77,15 @@ bool DEVICE::scan_dir_for_volume(DCR *dcr)
    for ( ;; ) {
       if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) {
          dev_errno = EIO;
-         Dmsg2(129, "scan_dir_for_vol: failed to find suitable file in dir %s (dev=%s)\n", 
+         Dmsg2(129, "scan_dir_for_vol: failed to find suitable file in dir %s (dev=%s)\n",
                mount_point, print_name());
          break;
       }
-      if (strcmp(result->d_name, ".") == 0 || 
+      if (strcmp(result->d_name, ".") == 0 ||
           strcmp(result->d_name, "..") == 0) {
          continue;
       }
-       
+
       if (!is_volume_name_legal(result->d_name)) {
          continue;
       }
@@ -98,8 +105,6 @@ bool DEVICE::scan_dir_for_volume(DCR *dcr)
        *  this volume is really OK. If not, put back the desired
        *  volume name, mark it not in changer and continue.
        */
-      dcrVolCatInfo = dcr->VolCatInfo;     /* structure assignment */
-      devVolCatInfo = VolCatInfo;          /* structure assignment */
       /* Check if this is a valid Volume in the pool */
       bstrncpy(dcr->VolumeName, result->d_name, sizeof(dcr->VolumeName));
       if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE)) {
@@ -114,9 +119,15 @@ bool DEVICE::scan_dir_for_volume(DCR *dcr)
    }
    free(entry);
    closedir(dp);
-   
+
 get_out:
-   sm_check(__FILE__, __LINE__, false);
+   if (!found) {
+      /* Restore VolumeName we really wanted */
+      bstrncpy(dcr->VolumeName, VolumeName, sizeof(dcr->VolumeName));
+      dcr->VolCatInfo = dcrVolCatInfo;     /* structure assignment */
+      VolCatInfo = devVolCatInfo;          /* structure assignment */
+   }
+   Dsm_check(100);
    return found;
 }