summaryrefslogtreecommitdiffstats
path: root/src/H5FDcore.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-07 02:51:54 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-07 02:51:54 (GMT)
commitfda704377ebca6f980d7e842935977bb45f34d34 (patch)
tree6055a171c97afb62157e3f61f6bf8942dd9bab26 /src/H5FDcore.c
parentfb1059e507cab041e2fd6bf294b12843a1ddf1c7 (diff)
downloadhdf5-fda704377ebca6f980d7e842935977bb45f34d34.zip
hdf5-fda704377ebca6f980d7e842935977bb45f34d34.tar.gz
hdf5-fda704377ebca6f980d7e842935977bb45f34d34.tar.bz2
[svn-r17971] Description:
Allow the core VFD to properly support opening backing store files through symbolic links and have the external links in the file be treated in the same way as for the sec2 driver. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.2 (amazon) in debug mode Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
Diffstat (limited to 'src/H5FDcore.c')
-rw-r--r--src/H5FDcore.c105
1 files changed, 67 insertions, 38 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index a08abdd..2d754f5 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -398,29 +398,29 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id,
FUNC_ENTER_NOAPI(H5FD_core_open, NULL)
/* Check arguments */
- if (!name || !*name)
+ if(!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name")
- if (0==maxaddr || HADDR_UNDEF==maxaddr)
+ if(0 == maxaddr || HADDR_UNDEF == maxaddr)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr")
if(ADDR_OVERFLOW(maxaddr))
HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "maxaddr overflow")
- assert(H5P_DEFAULT != fapl_id);
- if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
- fa = (H5FD_core_fapl_t *)H5P_get_driver_info(plist);
+ HDassert(H5P_DEFAULT != fapl_id);
+ if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
+ fa = (H5FD_core_fapl_t *)H5P_get_driver_info(plist);
/* Build the open flags */
o_flags = (H5F_ACC_RDWR & flags) ? O_RDWR : O_RDONLY;
- if (H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC;
- if (H5F_ACC_CREAT & flags) o_flags |= O_CREAT;
- if (H5F_ACC_EXCL & flags) o_flags |= O_EXCL;
+ if(H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC;
+ if(H5F_ACC_CREAT & flags) o_flags |= O_CREAT;
+ if(H5F_ACC_EXCL & flags) o_flags |= O_EXCL;
/* Open backing store. The only case that backing store is off is when
* the backing_store flag is off and H5F_ACC_CREAT is on. */
if(fa->backing_store || !(H5F_ACC_CREAT & flags)) {
- if (fa && (fd=HDopen(name, o_flags, 0666))<0)
+ if(fa && (fd = HDopen(name, o_flags, 0666)) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file")
- }
+ } /* end if */
/* Create the new file struct */
if(NULL == (file = (H5FD_core_t *)H5MM_calloc(sizeof(H5FD_core_t))))
@@ -441,35 +441,34 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id,
/* If an existing file is opened, load the whole file into memory. */
if(!(H5F_ACC_CREAT & flags)) {
- unsigned char *x=NULL;
size_t size;
- if (HDfstat(file->fd, &sb)<0)
+ /* stat() file to retrieve its size */
+ if(HDfstat(file->fd, &sb) < 0)
HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file")
-
size = (size_t)sb.st_size;
+ /* Check if we should allocate the memory buffer and read in existing data */
if(size) {
- if (NULL==file->mem)
- x = (unsigned char*)H5MM_malloc(size);
-
- if (!x)
+ /* Allocate memory for the file's data */
+ if(NULL == (file->mem = (unsigned char*)H5MM_malloc(size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory block")
- file->mem = x;
+ /* Set up data structures */
file->eof = size;
- if(HDread(file->fd, file->mem, size)<0)
+ /* Read in existing data */
+ if(HDread(file->fd, file->mem, size) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read file")
- }
- }
+ } /* end if */
+ } /* end if */
/* Set return value */
- ret_value=(H5FD_t *)file;
+ ret_value = (H5FD_t *)file;
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_core_open() */
/*-------------------------------------------------------------------------
@@ -576,13 +575,12 @@ done:
*
*-------------------------------------------------------------------------
*/
-/* ARGSUSED */
static herr_t
-H5FD_core_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
+H5FD_core_query(const H5FD_t * _file, unsigned long *flags /* out */)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ const H5FD_core_t *file = (const H5FD_core_t*)_file;
- FUNC_ENTER_NOAPI(H5FD_core_query, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_core_query)
/* Set the VFL feature flags that this driver supports */
if(flags) {
@@ -591,10 +589,13 @@ H5FD_core_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
*flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
*flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
*flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
+
+ /* If the backing store is open, a POSIX file handle is available */
+ if(file->fd >= 0 && file->backing_store)
+ *flags |= H5FD_FEAT_POSIX_COMPAT_HANDLE; /* VFD handle is POSIX I/O call compatible */
} /* end if */
-done:
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FD_core_query() */
@@ -622,9 +623,8 @@ done:
static haddr_t
H5FD_core_get_eoa(const H5FD_t *_file, H5FD_mem_t UNUSED type)
{
- haddr_t ret_value; /* Return value */
-
const H5FD_core_t *file = (const H5FD_core_t*)_file;
+ haddr_t ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5FD_core_get_eoa, HADDR_UNDEF)
@@ -726,23 +726,52 @@ done:
*
*-------------------------------------------------------------------------
*/
-/* ARGSUSED */
static herr_t
-H5FD_core_get_handle(H5FD_t *_file, hid_t UNUSED fapl, void** file_handle)
+H5FD_core_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle)
{
- H5FD_core_t *file = (H5FD_core_t *)_file;
- herr_t ret_value = SUCCEED;
+ H5FD_core_t *file = (H5FD_core_t *)_file; /* core VFD info */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_core_get_handle, FAIL)
+ /* Check args */
if(!file_handle)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file handle not valid")
- *file_handle = &(file->mem);
+ /* Check for non-default FAPL */
+ if(H5P_FILE_ACCESS_DEFAULT != fapl && H5P_DEFAULT != fapl) {
+ H5P_genplist_t *plist; /* Property list pointer */
+
+ /* Get the FAPL */
+ if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl)))
+ HGOTO_ERROR(H5E_VFL, H5E_BADTYPE, FAIL, "not a file access property list")
+
+ /* Check if private property for retrieving the backing store POSIX
+ * file descriptor is set. (This should not be set except within the
+ * library) QAK - 2009/12/04
+ */
+ if(H5P_exist_plist(plist, H5F_ACS_WANT_POSIX_FD_NAME) > 0) {
+ hbool_t want_posix_fd; /* Setting for retrieving file descriptor from core VFD */
+
+ /* Get property */
+ if(H5P_get(plist, H5F_ACS_WANT_POSIX_FD_NAME, &want_posix_fd) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get property of retrieving file descriptor")
+
+ /* If property is set, pass back the file descriptor instead of the memory address */
+ if(want_posix_fd)
+ *file_handle = &(file->fd);
+ else
+ *file_handle = &(file->mem);
+ } /* end if */
+ else
+ *file_handle = &(file->mem);
+ } /* end if */
+ else
+ *file_handle = &(file->mem);
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_core_get_handle() */
/*-------------------------------------------------------------------------