+/*
+ 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
*
* 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"
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;
} 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]);
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;
}
* 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)) {
}
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;
}