summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5Dvirtual.c319
-rw-r--r--src/H5Fint.c331
-rw-r--r--src/H5Fprivate.h6
-rw-r--r--src/H5Lexternal.c306
4 files changed, 383 insertions, 579 deletions
diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c
index 306fe62..9e1ebe8 100644
--- a/src/H5Dvirtual.c
+++ b/src/H5Dvirtual.c
@@ -147,7 +147,7 @@ H5FL_DEFINE(H5O_storage_virtual_name_seg_t);
H5FL_DEFINE_STATIC(H5D_virtual_held_file_t);
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_check_mapping_pre
*
@@ -217,7 +217,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_check_mapping_pre() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_check_mapping_post
*
@@ -285,7 +285,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_check_mapping_post() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_update_min_dims
*
@@ -344,7 +344,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_update_min_dims() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_check_min_dims
*
@@ -389,7 +389,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_check_min_dims() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_copy_layout
*
@@ -553,7 +553,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_copy_layout() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_reset_layout
*
@@ -637,7 +637,7 @@ H5D__virtual_reset_layout(H5O_layout_t *layout)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_reset_layout() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_copy
*
@@ -683,7 +683,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_copy() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_delete
*
@@ -733,255 +733,6 @@ done:
} /* end H5D__virtual_delete */
-/*--------------------------------------------------------------------------
- * Function: H5D__virtual_build_name
- *
- * Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME
- *
- * Return: Non-negative on success/Negative on failure
- *--------------------------------------------------------------------------*/
-static herr_t
-H5D__virtual_build_name(char *prefix, char *file_name, char **full_name/*out*/)
-{
- size_t prefix_len; /* length of prefix */
- size_t fname_len; /* Length of external link file name */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT
-
- prefix_len = HDstrlen(prefix);
- fname_len = HDstrlen(file_name);
-
- /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
- if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer")
-
- /* Compose the full file name */
- HDsnprintf(*full_name, (prefix_len + fname_len + 2), "%s%s%s", prefix,
- (H5_CHECK_DELIMITER(prefix[prefix_len - 1]) ? "" : H5_DIR_SEPS), file_name);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5D__virtual_build_name() */
-
-
-/*--------------------------------------------------------------------------
- * Function: H5D_getenv_prefix_name --
- *
- * Purpose: Get the first pathname in the list of pathnames stored in env_prefix,
- * which is separated by the environment delimiter.
- * env_prefix is modified to point to the remaining pathnames
- * in the list.
- *
- * Return: A pointer to a pathname
---------------------------------------------------------------------------*/
-static char *
-H5D_getenv_prefix_name(char **env_prefix/*in,out*/)
-{
- char *retptr=NULL;
- char *strret=NULL;
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- strret = HDstrchr(*env_prefix, H5_COLON_SEPC);
- if (strret == NULL) {
- retptr = *env_prefix;
- *env_prefix = strret;
- } else {
- retptr = *env_prefix;
- *env_prefix = strret + 1;
- *strret = '\0';
- }
-
- FUNC_LEAVE_NOAPI(retptr)
-} /* end H5D_getenv_prefix_name() */
-
-/*-------------------------------------------------------------------------
- * Function: H5D__virtual_open_file
- *
- * Purpose: Attempts to open a source dataset file.
- *
- * Return: Non-negative on success/Negative on failure
- *-------------------------------------------------------------------------
- */
-static H5F_t *
-H5D__virtual_open_file(hid_t plist_id, const H5F_t *vdset_file,
- const char *file_name,
- hid_t fapl_id, hid_t dxpl_id)
-{
- H5F_t *src_file = NULL; /* Source file */
- H5F_t *ret_value = NULL; /* Actual return value */
- char *full_name = NULL; /* File name with prefix */
- char *my_prefix = NULL; /* Library's copy of the prefix */
- unsigned intent; /* File access permissions */
- char *actual_file_name = NULL; /* Virtual file's actual name */
- char *temp_file_name = NULL; /* Temporary pointer to file name */
- size_t temp_file_name_len; /* Length of temporary file name */
-
- FUNC_ENTER_STATIC
-
- /* Simplify intent flags for open calls */
- intent = H5F_INTENT(vdset_file);
- intent &= (H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE | H5F_ACC_SWMR_READ);
-
- /* Copy the file name to use */
- if(NULL == (temp_file_name = H5MM_strdup(file_name)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- temp_file_name_len = HDstrlen(temp_file_name);
-
- /* target file_name is an absolute pathname: see RM for detailed description */
- if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) {
- /* Try opening file */
- if(NULL == (src_file = H5F_open(file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
- char *ptr;
-
- H5E_clear_stack(NULL);
-
- /* get last component of file_name */
- H5_GET_LAST_DELIMITER(file_name, ptr)
- HDassert(ptr);
-
- /* Increment past delimiter */
- ptr++;
-
- /* Copy into the temp. file name */
- HDstrncpy(temp_file_name, ptr, temp_file_name_len);
- temp_file_name[temp_file_name_len - 1] = '\0';
- } /* end if */
- } /* end if */
- else if(H5_CHECK_ABS_DRIVE(file_name)) {
- /* Try opening file */
- if(NULL == (src_file = H5F_open(file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
-
- H5E_clear_stack(NULL);
-
- /* strip "<drive-letter>:" */
- HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len);
- temp_file_name[temp_file_name_len - 1] = '\0';
- } /* end if */
- } /* end if */
-
- /* try searching from paths set in the environment variable */
- if(src_file == NULL) {
- char *env_prefix;
-
- if(NULL != (env_prefix = HDgetenv("HDF5_VDS_PREFIX"))) {
- char *tmp_env_prefix, *saved_env;
-
- if(NULL == (saved_env = tmp_env_prefix = H5MM_strdup(env_prefix)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
-
- while((tmp_env_prefix) && (*tmp_env_prefix)) {
- char *out_prefix_name;
-
- out_prefix_name = H5D_getenv_prefix_name(&tmp_env_prefix/*in,out*/);
- if(out_prefix_name && (*out_prefix_name)) {
- if(H5D__virtual_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) {
- saved_env = (char *)H5MM_xfree(saved_env);
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- } /* end if */
-
- src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id);
- full_name = (char *)H5MM_xfree(full_name);
- if(src_file != NULL)
- break;
- H5E_clear_stack(NULL);
- } /* end if */
- } /* end while */
- saved_env = (char *)H5MM_xfree(saved_env);
- } /* end if */
- } /* end if */
-
- /* try searching from property list */
- if(src_file == NULL) {
- size_t size = 0;
- H5E_BEGIN_TRY {
- size = H5Pget_virtual_prefix(plist_id, NULL, 0);
- } H5E_END_TRY;
- if(size <= 0)
- my_prefix = NULL;
- else {
- /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
- if(NULL == (my_prefix = (char *)H5MM_malloc(size + 1)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate prefix buffer")
- if(H5Pget_virtual_prefix(plist_id, my_prefix, size+1) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get vds prefix")
- if(my_prefix) {
- if(H5D__virtual_build_name(my_prefix, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- my_prefix = (char *)H5MM_xfree(my_prefix);
- if(NULL == (src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- full_name = (char *)H5MM_xfree(full_name);
- }
- } /* end if */
- } /* end if */
-
- /* try searching from main file's "extpath": see description in H5F_open() & H5_build_extpath() */
- if(src_file == NULL) {
- char *vdspath;
-
- if(NULL != (vdspath = H5F_EXTPATH(vdset_file))) {
- if(H5D__virtual_build_name(vdspath, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- if(NULL == (src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
- } /* end if */
-
- /* try the relative file_name stored in temp_file_name */
- if(src_file == NULL) {
- if(NULL == (src_file = H5F_open(temp_file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- } /* end if */
-
- /* try the 'resolved' name for the virtual file */
- if(src_file == NULL) {
- char *ptr = NULL;
-
- /* Copy resolved file name */
- if(NULL == (actual_file_name = H5MM_strdup(H5F_ACTUAL_NAME(vdset_file))))
- HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, NULL, "can't duplicate resolved file name string")
-
- /* get last component of file_name */
- H5_GET_LAST_DELIMITER(actual_file_name, ptr)
- if(!ptr)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENFILE, NULL, "unable to open vds file, vds file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
-
- /* Truncate filename portion from actual file name path */
- *ptr = '\0';
-
- /* Build new file name for the external file */
- if(H5D__virtual_build_name(actual_file_name, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't prepend prefix to filename")
- actual_file_name = (char *)H5MM_xfree(actual_file_name);
-
- /* Try opening with the resolved name */
- if(NULL == (src_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENFILE, NULL, "unable to open vds file, vds file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
-
- /* Success */
- ret_value = src_file;
-done:
- if((NULL == ret_value) && src_file)
- if(H5F_try_close(src_file, NULL) < 0)
- HDONE_ERROR(H5E_DATASET, H5E_CANTCLOSEFILE, NULL, "can't close source file")
- if(my_prefix)
- my_prefix = (char *)H5MM_xfree(my_prefix);
- if(full_name)
- full_name = (char *)H5MM_xfree(full_name);
- if(temp_file_name)
- temp_file_name = (char *)H5MM_xfree(temp_file_name);
- if(actual_file_name)
- actual_file_name = (char *)H5MM_xfree(actual_file_name);
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5D__virtual_open_file() */
-
-
/*-------------------------------------------------------------------------
* Function: H5D__virtual_open_source_dset
*
@@ -1000,13 +751,11 @@ H5D__virtual_open_source_dset(const H5D_t *vdset,
H5O_storage_virtual_srcdset_t *source_dset, hid_t dxpl_id)
{
H5F_t *src_file = NULL; /* Source file */
- char *vds_prefix = NULL; /* Source file vds_prefix */
hbool_t src_file_open = FALSE; /* Whether we have opened and need to close src_file */
H5G_loc_t src_root_loc; /* Object location of source file root group */
herr_t ret_value = SUCCEED; /* Return value */
- char *full_name = NULL; /* File name with prefix */
- unsigned intent; /* File access permissions */
hid_t plist_id = -1; /* Property list pointer */
+ unsigned intent; /* File access permissions */
FUNC_ENTER_STATIC
@@ -1019,9 +768,11 @@ H5D__virtual_open_source_dset(const H5D_t *vdset,
/* Check if we need to open the source file */
if(HDstrcmp(source_dset->file_name, ".")) {
- if((plist_id = H5D_get_access_plist(vdset)) < 0)
+ if((plist_id = H5D_get_access_plist((H5D_t *)vdset)) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "Can't get access plist")
- if(NULL == (src_file = H5D__virtual_open_file(plist_id, vdset->oloc.file, source_dset->file_name, vdset->shared->layout.storage.u.virt.source_fapl, dxpl_id)))
+ intent = H5F_INTENT(vdset->oloc.file);
+ if(NULL == (src_file = H5F_prefix_open_file(plist_id, vdset->oloc.file, H5D_ACS_VDS_PREFIX_NAME, source_dset->file_name, intent,
+ vdset->shared->layout.storage.u.virt.source_fapl, dxpl_id)))
H5E_clear_stack(NULL); /* Quick hack until proper support for H5Fopen with missing file is implemented */
else
src_file_open = TRUE;
@@ -1062,13 +813,13 @@ done:
H5Pclose(plist_id);
/* Close source file */
if(src_file_open)
- if(H5F_try_close(src_file, NULL) < 0)
+ if(H5F_efc_close(vdset->oloc.file, src_file) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTCLOSEFILE, FAIL, "can't close source file")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_open_source_dset() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_reset_source_dset
*
@@ -1155,7 +906,7 @@ H5D__virtual_reset_source_dset(H5O_storage_virtual_ent_t *virtual_ent,
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_reset_source_dset() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_str_append
*
@@ -1231,7 +982,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5D__virtual_str_append() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_parse_source_name
*
@@ -1347,7 +1098,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_parse_source_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_copy_parsed_name
*
@@ -1404,7 +1155,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_copy_parsed_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D_virtual_free_parsed_name
*
@@ -1437,7 +1188,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_virtual_free_parsed_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_build_source_name
*
@@ -1539,7 +1290,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_build_source_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_set_extent_unlim
*
@@ -1967,7 +1718,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_set_extent_unlim() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_init_all
*
@@ -2191,7 +1942,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_init_all() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_init
*
@@ -2286,7 +2037,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_init() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_is_space_alloc
*
@@ -2318,7 +2069,7 @@ H5D__virtual_is_space_alloc(const H5O_storage_t H5_ATTR_UNUSED *storage)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_is_space_alloc() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_pre_io
*
@@ -2559,7 +2310,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_pre_io() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_post_io
*
@@ -2609,7 +2360,7 @@ H5D__virtual_post_io(H5O_storage_virtual_t *storage)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_post_io() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_read_one
*
@@ -2666,7 +2417,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_read_one() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_read
*
@@ -2799,7 +2550,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_read() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_write_one
*
@@ -2858,7 +2609,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_write_one() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_write
*
@@ -2935,7 +2686,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_write() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_flush
*
@@ -2983,7 +2734,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_flush() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_hold_source_dset_files
*
@@ -3061,7 +2812,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_hold_source_dset_files() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_refresh_source_dset
*
@@ -3101,7 +2852,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_refresh_source_dsets() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_refresh_source_dsets
*
@@ -3154,7 +2905,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__virtual_refresh_source_dsets() */
-
+
/*-------------------------------------------------------------------------
* Function: H5D__virtual_release_source_dset_files
*
diff --git a/src/H5Fint.c b/src/H5Fint.c
index 8212eb5..b135ce1 100644
--- a/src/H5Fint.c
+++ b/src/H5Fint.c
@@ -30,6 +30,7 @@
#include "H5FDprivate.h" /* File drivers */
#include "H5Gprivate.h" /* Groups */
#include "H5Iprivate.h" /* IDs */
+#include "H5Lprivate.h" /* Links */
#include "H5MFprivate.h" /* File memory management */
#include "H5MMprivate.h" /* Memory management */
#include "H5Pprivate.h" /* Property lists */
@@ -98,7 +99,7 @@ H5FL_DEFINE(H5F_t);
/* Declare a free list to manage the H5F_file_t struct */
H5FL_DEFINE(H5F_file_t);
-
+
/*-------------------------------------------------------------------------
* Function: H5F_get_access_plist
*
@@ -213,7 +214,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_access_plist() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_get_obj_count
*
@@ -241,7 +242,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_obj_count() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_get_obj_ids
*
@@ -268,7 +269,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_obj_ids() */
-
+
/*---------------------------------------------------------------------------
* Function: H5F_get_objects
*
@@ -370,7 +371,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_objects() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_get_objects_cb
*
@@ -479,7 +480,265 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_objects_cb() */
-
+/*--------------------------------------------------------------------------
+ * Function: H5F_build_name
+ *
+ * Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME
+ *
+ * Return: Non-negative on success/Negative on failure
+ *--------------------------------------------------------------------------*/
+herr_t
+H5F_build_name(char *prefix, char *file_name, char **full_name/*out*/)
+{
+ size_t prefix_len; /* length of prefix */
+ size_t fname_len; /* Length of external link file name */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ prefix_len = HDstrlen(prefix);
+ fname_len = HDstrlen(file_name);
+
+ /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
+ if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer")
+
+ /* Compose the full file name */
+ HDsnprintf(*full_name, (prefix_len + fname_len + 2), "%s%s%s", prefix,
+ (H5_CHECK_DELIMITER(prefix[prefix_len - 1]) ? "" : H5_DIR_SEPS), file_name);
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5F_build_name() */
+
+
+/*--------------------------------------------------------------------------
+ * Function: H5F_getenv_prefix_name --
+ *
+ * Purpose: Get the first pathname in the list of pathnames stored in env_prefix,
+ * which is separated by the environment delimiter.
+ * env_prefix is modified to point to the remaining pathnames
+ * in the list.
+ *
+ * Return: A pointer to a pathname
+--------------------------------------------------------------------------*/
+char *
+H5F_getenv_prefix_name(char **env_prefix/*in,out*/)
+{
+ char *retptr=NULL;
+ char *strret=NULL;
+
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ strret = HDstrchr(*env_prefix, H5_COLON_SEPC);
+ if (strret == NULL) {
+ retptr = *env_prefix;
+ *env_prefix = strret;
+ } else {
+ retptr = *env_prefix;
+ *env_prefix = strret + 1;
+ *strret = '\0';
+ }
+
+ FUNC_LEAVE_NOAPI(retptr)
+} /* end H5F_getenv_prefix_name() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_prefix_open_file
+ *
+ * Purpose: Attempts to open a dataset file.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *-------------------------------------------------------------------------
+ */
+H5F_t *
+H5F_prefix_open_file(hid_t plist_id, H5F_t *primary_file, const char *prefix_type,
+ const char *file_name, unsigned file_intent, hid_t fapl_id, hid_t dxpl_id)
+{
+ H5F_t *src_file = NULL; /* Source file */
+ H5F_t *ret_value = NULL; /* Actual return value */
+ char *full_name = NULL; /* File name with prefix */
+ char *my_prefix = NULL; /* Library's copy of the prefix */
+ char *actual_file_name = NULL; /* File's actual name */
+ char *temp_file_name = NULL; /* Temporary pointer to file name */
+ size_t temp_file_name_len; /* Length of temporary file name */
+
+ FUNC_ENTER_STATIC
+
+ /* Simplify intent flags for open calls */
+ file_intent &= (H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE | H5F_ACC_SWMR_READ);
+
+ /* Copy the file name to use */
+ if(NULL == (temp_file_name = H5MM_strdup(file_name)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ temp_file_name_len = HDstrlen(temp_file_name);
+
+ /* target file_name is an absolute pathname: see RM for detailed description */
+ if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) {
+ /* Try opening file */
+ if(NULL == (src_file = H5F_efc_open(primary_file, file_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
+ char *ptr;
+
+ H5E_clear_stack(NULL);
+
+ /* get last component of file_name */
+ H5_GET_LAST_DELIMITER(file_name, ptr)
+ HDassert(ptr);
+
+ /* Increment past delimiter */
+ ptr++;
+
+ /* Copy into the temp. file name */
+ HDstrncpy(temp_file_name, ptr, temp_file_name_len);
+ temp_file_name[temp_file_name_len - 1] = '\0';
+ } /* end if */
+ } /* end if */
+ else if(H5_CHECK_ABS_DRIVE(file_name)) {
+ /* Try opening file */
+ if(NULL == (src_file = H5F_efc_open(primary_file, file_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
+
+ H5E_clear_stack(NULL);
+
+ /* strip "<drive-letter>:" */
+ HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len);
+ temp_file_name[temp_file_name_len - 1] = '\0';
+ } /* end if */
+ } /* end if */
+
+ /* try searching from paths set in the environment variable */
+ if(src_file == NULL) {
+ char *env_prefix;
+
+ if (HDstrcmp(prefix_type, H5D_ACS_VDS_PREFIX_NAME) == 0)
+ env_prefix = HDgetenv("HDF5_VDS_PREFIX");
+ else if (HDstrcmp(prefix_type, H5L_ACS_ELINK_PREFIX_NAME) == 0)
+ env_prefix = HDgetenv("HDF5_EXT_PREFIX");
+ else
+ HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, NULL, "prefix name is not sensible")
+ if(NULL != env_prefix) {
+ char *tmp_env_prefix, *saved_env;
+
+ if(NULL == (saved_env = tmp_env_prefix = H5MM_strdup(env_prefix)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ while((tmp_env_prefix) && (*tmp_env_prefix)) {
+ char *out_prefix_name;
+
+ out_prefix_name = H5F_getenv_prefix_name(&tmp_env_prefix/*in,out*/);
+ if(out_prefix_name && (*out_prefix_name)) {
+ if(H5F_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) {
+ saved_env = (char *)H5MM_xfree(saved_env);
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't prepend prefix to filename")
+ } /* end if */
+
+ src_file = H5F_efc_open(primary_file, full_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id);
+ full_name = (char *)H5MM_xfree(full_name);
+ if(src_file != NULL)
+ break;
+ H5E_clear_stack(NULL);
+ } /* end if */
+ } /* end while */
+ saved_env = (char *)H5MM_xfree(saved_env);
+ } /* end if */
+ } /* end if */
+
+ /* try searching from property list */
+ if(src_file == NULL) {
+ ssize_t size = 0;
+ H5E_BEGIN_TRY {
+ if (HDstrcmp(prefix_type, H5D_ACS_VDS_PREFIX_NAME) == 0)
+ size = H5Pget_virtual_prefix(plist_id, NULL, 0);
+ else if (HDstrcmp(prefix_type, H5L_ACS_ELINK_PREFIX_NAME) == 0)
+ size = H5Pget_elink_prefix(plist_id, NULL, 0);
+ } H5E_END_TRY;
+ if(size <= 0)
+ my_prefix = NULL;
+ else {
+ /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
+ if(NULL == (my_prefix = (char *)H5MM_malloc((size_t)size + 1)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate prefix buffer")
+ if (HDstrcmp(prefix_type, H5D_ACS_VDS_PREFIX_NAME) == 0)
+ size = H5Pget_virtual_prefix(plist_id, my_prefix, (size_t)size+1);
+ else if (HDstrcmp(prefix_type, H5L_ACS_ELINK_PREFIX_NAME) == 0)
+ size = H5Pget_elink_prefix(plist_id, my_prefix, (size_t)size+1);
+ if(size < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get file prefix")
+ if(my_prefix) {
+ if(H5F_build_name(my_prefix, temp_file_name, &full_name/*out*/) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't prepend prefix to filename")
+ my_prefix = (char *)H5MM_xfree(my_prefix);
+ if(NULL == (src_file = H5F_efc_open(primary_file, full_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ H5E_clear_stack(NULL);
+ full_name = (char *)H5MM_xfree(full_name);
+ }
+ }
+ }
+
+ /* try searching from main file's "extpath": see description in H5F_open() & H5_build_extpath() */
+ if(src_file == NULL) {
+ char *dspath;
+
+ if(NULL != (dspath = H5F_EXTPATH(primary_file))) {
+ if(H5F_build_name(dspath, temp_file_name, &full_name/*out*/) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't prepend prefix to filename")
+ if(NULL == (src_file = H5F_efc_open(primary_file, full_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ H5E_clear_stack(NULL);
+ full_name = (char *)H5MM_xfree(full_name);
+ } /* end if */
+ } /* end if */
+
+ /* try the relative file_name stored in temp_file_name */
+ if(src_file == NULL) {
+ if(NULL == (src_file = H5F_efc_open(primary_file, temp_file_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ H5E_clear_stack(NULL);
+ } /* end if */
+
+ /* try the 'resolved' name for the virtual file */
+ if(src_file == NULL) {
+ char *ptr = NULL;
+
+ /* Copy resolved file name */
+ if(NULL == (actual_file_name = H5MM_strdup(H5F_ACTUAL_NAME(primary_file))))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "can't duplicate resolved file name string")
+
+ /* get last component of file_name */
+ H5_GET_LAST_DELIMITER(actual_file_name, ptr)
+ if(!ptr)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file, file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
+
+ /* Truncate filename portion from actual file name path */
+ *ptr = '\0';
+
+ /* Build new file name for the external file */
+ if(H5F_build_name(actual_file_name, temp_file_name, &full_name/*out*/) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't prepend prefix to filename")
+ actual_file_name = (char *)H5MM_xfree(actual_file_name);
+
+ /* Try opening with the resolved name */
+ if(NULL == (src_file = H5F_efc_open(primary_file, full_name, file_intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file, file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
+ full_name = (char *)H5MM_xfree(full_name);
+ } /* end if */
+
+ /* Success */
+ ret_value = src_file;
+done:
+ if((NULL == ret_value) && src_file)
+ if(H5F_efc_close(primary_file, src_file) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, NULL, "can't close source file")
+ if(my_prefix)
+ my_prefix = (char *)H5MM_xfree(my_prefix);
+ if(full_name)
+ full_name = (char *)H5MM_xfree(full_name);
+ if(temp_file_name)
+ temp_file_name = (char *)H5MM_xfree(temp_file_name);
+ if(actual_file_name)
+ actual_file_name = (char *)H5MM_xfree(actual_file_name);
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5F_prefix_open_file() */
+
+
/*-------------------------------------------------------------------------
* Function: H5F__is_hdf5
*
@@ -528,7 +787,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__is_hdf5() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_new
*
@@ -792,7 +1051,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_new() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F__dest
*
@@ -1051,7 +1310,7 @@ H5F__dest(H5F_t *f, hid_t meta_dxpl_id, hid_t raw_dxpl_id, hbool_t flush)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_dest() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_open
*
@@ -1469,7 +1728,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_open() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_flush_phase1
*
@@ -1506,7 +1765,7 @@ H5F__flush_phase1(H5F_t *f, hid_t meta_dxpl_id)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__flush_phase1() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F__flush_phase2
*
@@ -1568,7 +1827,7 @@ H5F__flush_phase2(H5F_t *f, hid_t meta_dxpl_id, hid_t raw_dxpl_id, hbool_t closi
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__flush_phase2() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F__flush
*
@@ -1600,7 +1859,7 @@ H5F__flush(H5F_t *f, hid_t meta_dxpl_id, hid_t raw_dxpl_id, hbool_t closing)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__flush() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_close
*
@@ -1661,7 +1920,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_close() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_try_close
*
@@ -1834,7 +2093,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_try_close() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_get_id
*
@@ -1870,7 +2129,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_id() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_incr_nopen_objs
*
@@ -1891,7 +2150,7 @@ H5F_incr_nopen_objs(H5F_t *f)
FUNC_LEAVE_NOAPI(++f->nopen_objs)
} /* end H5F_incr_nopen_objs() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_decr_nopen_objs
*
@@ -1912,7 +2171,7 @@ H5F_decr_nopen_objs(H5F_t *f)
FUNC_LEAVE_NOAPI(--f->nopen_objs)
} /* end H5F_decr_nopen_objs() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_build_actual_name
*
@@ -2034,7 +2293,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_build_actual_name() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_addr_encode_len
*
@@ -2071,7 +2330,7 @@ H5F_addr_encode_len(size_t addr_len, uint8_t **pp/*in,out*/, haddr_t addr)
FUNC_LEAVE_NOAPI_VOID
} /* end H5F_addr_encode_len() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_addr_encode
*
@@ -2095,7 +2354,7 @@ H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr)
FUNC_LEAVE_NOAPI_VOID
} /* end H5F_addr_encode() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_addr_decode_len
*
@@ -2159,7 +2418,7 @@ H5F_addr_decode_len(size_t addr_len, const uint8_t **pp/*in,out*/, haddr_t *addr
FUNC_LEAVE_NOAPI_VOID
} /* end H5F_addr_decode_len() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_addr_decode
*
@@ -2186,7 +2445,7 @@ H5F_addr_decode(const H5F_t *f, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*o
FUNC_LEAVE_NOAPI_VOID
} /* end H5F_addr_decode() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_grp_btree_shared
*
@@ -2212,7 +2471,7 @@ H5F_set_grp_btree_shared(H5F_t *f, H5UC_t *rc)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5F_set_grp_btree_shared() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_sohm_addr
*
@@ -2237,7 +2496,7 @@ H5F_set_sohm_addr(H5F_t *f, haddr_t addr)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5F_set_sohm_addr() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_sohm_vers
*
@@ -2262,7 +2521,7 @@ H5F_set_sohm_vers(H5F_t *f, unsigned vers)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5F_set_sohm_vers() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_sohm_nindexes
*
@@ -2287,7 +2546,7 @@ H5F_set_sohm_nindexes(H5F_t *f, unsigned nindexes)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5F_set_sohm_nindexes() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_store_msg_crt_idx
*
@@ -2312,7 +2571,7 @@ H5F_set_store_msg_crt_idx(H5F_t *f, hbool_t flag)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5F_set_store_msg_crt_idx() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_get_file_image
*
@@ -2428,7 +2687,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_get_file_image() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_track_metadata_read_retries
*
@@ -2476,7 +2735,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_track_metadata_read_retries() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_retries
*
@@ -2512,7 +2771,7 @@ H5F_set_retries(H5F_t *f)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5F_set_retries() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_object_flush_cb
*
@@ -2542,7 +2801,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_object_flush_cb() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F__set_base_addr
*
@@ -2569,7 +2828,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__set_base_addr() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F__set_eoa
*
@@ -2596,7 +2855,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__set_eoa() */
-
+
/*-------------------------------------------------------------------------
* Function: H5F__set_paged_aggr
*
@@ -2625,7 +2884,7 @@ done:
} /* end H5F__set_paged_aggr() */
#ifdef H5_HAVE_PARALLEL
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_coll_md_read
*
@@ -2650,7 +2909,7 @@ H5F_set_coll_md_read(H5F_t *f, H5P_coll_md_read_flag_t cmr)
} /* H5F_set_coll_md_read() */
#endif /* H5_HAVE_PARALLEL */
-
+
/*-------------------------------------------------------------------------
* Function: H5F_set_latest_flags
*
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 96b8e36..ba94069 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -863,6 +863,12 @@ H5_DLL H5F_t *H5F_efc_open(H5F_t *parent, const char *name, unsigned flags,
hid_t fcpl_id, hid_t fapl_id, hid_t dxpl_id);
H5_DLL herr_t H5F_efc_close(H5F_t *parent, H5F_t *file);
+/* File prefix routines */
+H5_DLL herr_t H5F_build_name(char *prefix, char *file_name, char **full_name);
+H5_DLL char * H5F_getenv_prefix_name(char **env_prefix);
+H5F_t *H5F_prefix_open_file(hid_t plist_id, H5F_t *primary_file, const char *prefix_type,
+ const char *file_name, unsigned file_intent, hid_t fapl_id, hid_t dxpl_id);
+
/* Global heap CWFS routines */
H5_DLL herr_t H5F_cwfs_add(H5F_t *f, struct H5HG_heap_t *heap);
H5_DLL herr_t H5F_cwfs_find_free_heap(H5F_t *f, hid_t dxpl_id, size_t need, haddr_t *addr);
diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c
index b4a173f..bf0a044 100644
--- a/src/H5Lexternal.c
+++ b/src/H5Lexternal.c
@@ -15,7 +15,7 @@
/* Module Setup */
/****************/
-#define H5G_FRIEND /*suppress error about including H5Gpkg */
+#define H5G_FRIEND /*suppress error about including H5Gpkg */
#include "H5Lmodule.h" /* This source code file is part of the H5L module */
@@ -25,8 +25,9 @@
#include "H5private.h" /* Generic Functions */
#include "H5ACprivate.h" /* Metadata cache */
#include "H5Eprivate.h" /* Error handling */
+#include "H5Fprivate.h" /* Files */
#include "H5Gpkg.h" /* Groups */
-#include "H5Iprivate.h" /* IDs */
+#include "H5Iprivate.h" /* IDs */
#include "H5Lpkg.h" /* Links */
#include "H5MMprivate.h" /* Memory management */
#include "H5Opublic.h" /* File objects */
@@ -79,7 +80,7 @@ static ssize_t H5L_extern_query(const char H5_ATTR_UNUSED * link_name, const voi
/* Default External Link link class */
static const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{
H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */
- H5L_TYPE_EXTERNAL, /* Link type id number */
+ H5L_TYPE_EXTERNAL, /* Link type id number */
"external", /* Link name for debugging */
NULL, /* Creation callback */
NULL, /* Move callback */
@@ -89,82 +90,10 @@ static const H5L_class_t H5L_EXTERN_LINK_CLASS[1] = {{
H5L_extern_query /* Query callback */
}};
-
-
-/*--------------------------------------------------------------------------
- * Function: H5L_getenv_prefix_name --
- *
- * Purpose: Get the first pathname in the list of pathnames stored in ENV_PREFIX,
- * which is separated by the environment delimiter.
- * ENV_PREFIX is modified to point to the remaining pathnames
- * in the list.
- *
- * Return: A pointer to a pathname
- *
- * Programmer: Vailin Choi, April 2, 2008
- *
---------------------------------------------------------------------------*/
-static char *
-H5L_getenv_prefix_name(char **env_prefix/*in,out*/)
-{
- char *retptr=NULL;
- char *strret=NULL;
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- strret = HDstrchr(*env_prefix, H5_COLON_SEPC);
- if (strret == NULL) {
- retptr = *env_prefix;
- *env_prefix = strret;
- } else {
- retptr = *env_prefix;
- *env_prefix = strret + 1;
- *strret = '\0';
- }
-
- FUNC_LEAVE_NOAPI(retptr)
-} /* end H5L_getenv_prefix_name() */
-
-
-/*--------------------------------------------------------------------------
- * Function: H5L_build_name
- *
- * Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME
- *
- * Return: Non-negative on success/Negative on failure
- *
- * Programmer: Vailin Choi, April 2, 2008
- *
---------------------------------------------------------------------------*/
-static herr_t
-H5L_build_name(char *prefix, char *file_name, char **full_name/*out*/)
-{
- size_t prefix_len; /* length of prefix */
- size_t fname_len; /* Length of external link file name */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT
-
- prefix_len = HDstrlen(prefix);
- fname_len = HDstrlen(file_name);
-
- /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
- if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer")
-
- /* Compose the full file name */
- HDsnprintf(*full_name, (prefix_len + fname_len + 2), "%s%s%s", prefix,
- (H5_CHECK_DELIMITER(prefix[prefix_len - 1]) ? "" : H5_DIR_SEPS), file_name);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5L_build_name() */
-
-
/*-------------------------------------------------------------------------
- * Function: H5L_extern_traverse
+ * Function: H5L_extern_traverse
*
- * Purpose: Default traversal function for external links. This can
+ * Purpose: Default traversal function for external links. This can
* be overridden using H5Lregister().
*
* Given a filename and path packed into the link udata,
@@ -173,25 +102,25 @@ done:
* link access property list, appends that prefix to the
* filename being opened.
*
- * Return: ID of the opened object on success/Negative on failure
+ * Return: ID of the opened object on success/Negative on failure
*
- * Programmer: James Laird
+ * Programmer: James Laird
* Monday, July 10, 2006
* Modifications:
- * Vailin Choi, April 2, 2008
- * Add handling to search for the target file
- * See description in RM: H5Lcreate_external
+ * Vailin Choi, April 2, 2008
+ * Add handling to search for the target file
+ * See description in RM: H5Lcreate_external
*
- * Vailin Choi; Sept. 12th, 2008; bug #1247
- * Retrieve the file access property list identifer that is set
- * for link access property via H5Pget_elink_fapl().
- * If the return value is H5P_DEFAULT, the parent's file access
- * property is used to H5F_open() the target file;
- * Otherwise, the file access property retrieved from H5Pget_elink_fapl()
- * is used to H5F_open() the target file.
+ * Vailin Choi; Sept. 12th, 2008; bug #1247
+ * Retrieve the file access property list identifer that is set
+ * for link access property via H5Pget_elink_fapl().
+ * If the return value is H5P_DEFAULT, the parent's file access
+ * property is used to H5F_open() the target file;
+ * Otherwise, the file access property retrieved from H5Pget_elink_fapl()
+ * is used to H5F_open() the target file.
*
- * Vailin Choi; Nov 2010
- * Free memory pointed to by tmp_env_prefix for HDF5_EXT_PREFIX case.
+ * Vailin Choi; Nov 2010
+ * Free memory pointed to by tmp_env_prefix for HDF5_EXT_PREFIX case.
*
*-------------------------------------------------------------------------
*/
@@ -200,13 +129,11 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
const void *_udata, size_t H5_ATTR_UNUSED udata_size, hid_t lapl_id)
{
H5P_genplist_t *plist; /* Property list pointer */
- char *my_prefix; /* Library's copy of the prefix */
H5G_loc_t root_loc; /* Location of root group in external file */
H5G_loc_t loc; /* Location of object */
- H5F_t *ext_file = NULL; /* File struct for external file */
+ H5F_t *ext_file = NULL; /* File struct for external file */
const uint8_t *p = (const uint8_t *)_udata; /* Pointer into external link buffer */
const char *file_name; /* Name of file containing external link's object */
- char *full_name = NULL; /* File name with prefix */
const char *obj_name; /* Name external link's object */
size_t fname_len; /* Length of external link file name */
unsigned intent; /* File access permissions */
@@ -215,11 +142,8 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
hid_t ext_obj = -1; /* ID for external link's object */
char *parent_group_name = NULL;/* Temporary pointer to group name */
char local_group_name[H5L_EXT_TRAVERSE_BUF_SIZE]; /* Local buffer to hold group name */
- char *temp_file_name = NULL; /* Temporary pointer to file name */
- size_t temp_file_name_len; /* Length of temporary file name */
- char *actual_file_name = NULL; /* Parent file's actual name */
H5P_genplist_t *fa_plist; /* File access property list pointer */
- H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */
+ H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */
hid_t dxpl_id = H5AC_ind_read_dxpl_id; /* dxpl used by library */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
@@ -266,7 +190,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
intent = H5F_INTENT(loc.oloc->file);
if((fapl_id == H5P_DEFAULT) && ((fapl_id = H5F_get_access_plist(loc.oloc->file, FALSE)) < 0))
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't get parent's file access property list")
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't get parent's file access property list")
/* Get callback_info */
if(H5P_get(plist, H5L_ACS_ELINK_CB_NAME, &cb_info) < 0)
@@ -274,7 +198,7 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
/* Get file access property list */
if(NULL == (fa_plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS)))
- HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
+ HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
/* Make callback if it exists */
if(cb_info.func) {
@@ -314,143 +238,11 @@ H5L_extern_traverse(const char H5_ATTR_UNUSED *link_name, hid_t cur_group,
/* Set file close degree for new file to "weak" */
if(H5P_set(fa_plist, H5F_ACS_CLOSE_DEGREE_NAME, &fc_degree) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set file close degree")
-
- /*
- * Start searching for the target file
- */
-
- /* Simplify intent flags for open calls */
- intent &= (H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE | H5F_ACC_SWMR_READ);
-
- /* Copy the file name to use */
- if(NULL == (temp_file_name = H5MM_strdup(file_name)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- temp_file_name_len = HDstrlen(temp_file_name);
-
- /* target file_name is an absolute pathname: see RM for detailed description */
- if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) {
- /* Try opening file */
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
- char *ptr;
-
- H5E_clear_stack(NULL);
-
- /* get last component of file_name */
- H5_GET_LAST_DELIMITER(file_name, ptr)
- HDassert(ptr);
-
- /* Increment past delimiter */
- ptr++;
-
- /* Copy into the temp. file name */
- HDstrncpy(temp_file_name, ptr, temp_file_name_len);
- temp_file_name[temp_file_name_len - 1] = '\0';
- } /* end if */
- } /* end if */
- else if(H5_CHECK_ABS_DRIVE(file_name)) {
- /* Try opening file */
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id))) {
-
- H5E_clear_stack(NULL);
-
- /* strip "<drive-letter>:" */
- HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len);
- temp_file_name[temp_file_name_len - 1] = '\0';
- } /* end if */
- } /* end if */
-
- /* try searching from paths set in the environment variable */
- if(ext_file == NULL) {
- char *env_prefix;
-
- if(NULL != (env_prefix = HDgetenv("HDF5_EXT_PREFIX"))) {
- char *tmp_env_prefix, *saved_env;
-
- if(NULL == (saved_env = tmp_env_prefix = H5MM_strdup(env_prefix)))
- HGOTO_ERROR(H5E_LINK, H5E_NOSPACE, FAIL, "memory allocation failed")
-
- while((tmp_env_prefix) && (*tmp_env_prefix)) {
- char *out_prefix_name;
-
- out_prefix_name = H5L_getenv_prefix_name(&tmp_env_prefix/*in,out*/);
- if(out_prefix_name && (*out_prefix_name)) {
- if(H5L_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) {
- saved_env = (char *)H5MM_xfree(saved_env);
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
- } /* end if */
-
- ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id);
- full_name = (char *)H5MM_xfree(full_name);
- if(ext_file != NULL)
- break;
- H5E_clear_stack(NULL);
- } /* end if */
- } /* end while */
- saved_env = (char *)H5MM_xfree(saved_env);
- } /* end if */
- } /* end if */
-
- /* try searching from property list */
- if(ext_file == NULL) {
- if(H5P_peek(plist, H5L_ACS_ELINK_PREFIX_NAME, &my_prefix) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external link prefix")
- if(my_prefix) {
- if(H5L_build_name(my_prefix, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
- } /* end if */
-
- /* try searching from main file's "extpath": see description in H5F_open() & H5_build_extpath() */
- if(ext_file == NULL) {
- char *extpath;
-
- if(NULL != (extpath = H5F_EXTPATH(loc.oloc->file))) {
- if(H5L_build_name(extpath, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
- } /* end if */
-
- /* try the relative file_name stored in temp_file_name */
- if(ext_file == NULL) {
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, temp_file_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- H5E_clear_stack(NULL);
- } /* end if */
-
- /* try the 'resolved' name for the parent file (i.e. the name after symlinks
- * were resolved)
- */
- if(ext_file == NULL) {
- char *ptr = NULL;
-
- /* Copy resolved file name */
- if(NULL == (actual_file_name = H5MM_strdup(H5F_ACTUAL_NAME(loc.oloc->file))))
- HGOTO_ERROR(H5E_LINK, H5E_CANTALLOC, FAIL, "can't duplicate resolved file name string")
-
- /* get last component of file_name */
- H5_GET_LAST_DELIMITER(actual_file_name, ptr)
- if(!ptr)
- HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, FAIL, "unable to open external file, external link file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
-
- /* Truncate filename portion from actual file name path */
- *ptr = '\0';
-
- /* Build new file name for the external file */
- if(H5L_build_name(actual_file_name, temp_file_name, &full_name/*out*/) < 0)
- HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename")
-
- /* Try opening with the resolved name */
- if(NULL == (ext_file = H5F_efc_open(loc.oloc->file, full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
- HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, FAIL, "unable to open external file, external link file name = '%s', temp_file_name = '%s'", file_name, temp_file_name)
- full_name = (char *)H5MM_xfree(full_name);
- } /* end if */
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set file close degree")
+ /* Search for the target file */
+ if(NULL == (ext_file = H5F_prefix_open_file(lapl_id, loc.oloc->file, H5L_ACS_ELINK_PREFIX_NAME, file_name, intent, fapl_id, dxpl_id)))
+ HGOTO_ERROR(H5E_LINK, H5E_CANTOPENFILE, FAIL, "unable to open external file, external link file name = '%s'", file_name)
/* Retrieve the "group location" for the file's root group */
if(H5G_root_loc(ext_file, &root_loc) < 0)
@@ -471,10 +263,6 @@ done:
HDONE_ERROR(H5E_LINK, H5E_CANTCLOSEFILE, FAIL, "problem closing external file")
if(parent_group_name && parent_group_name != local_group_name)
parent_group_name = (char *)H5MM_xfree(parent_group_name);
- full_name = (char *)H5MM_xfree(full_name);
- temp_file_name = (char *)H5MM_xfree(temp_file_name);
- actual_file_name = (char *)H5MM_xfree(actual_file_name);
-
if(ret_value < 0) {
/* Close object if it's open and something failed */
if(ext_obj >= 0 && H5I_dec_ref(ext_obj) < 0)
@@ -484,20 +272,20 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5L_extern_traverse() */
-
+
/*-------------------------------------------------------------------------
- * Function: H5L_extern_query
+ * Function: H5L_extern_query
*
- * Purpose: Default query function for external links. This can
+ * Purpose: Default query function for external links. This can
* be overridden using H5Lregister().
*
* Returns the size of the link's user data. If a buffer of
* is provided, copies at most buf_size bytes of the udata
* into it.
*
- * Return: Size of buffer on success/Negative on failure
+ * Return: Size of buffer on success/Negative on failure
*
- * Programmer: James Laird
+ * Programmer: James Laird
* Monday, July 10, 2006
*
*-------------------------------------------------------------------------
@@ -534,23 +322,23 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5L_extern_query() */
-
+
/*-------------------------------------------------------------------------
- * Function: H5Lcreate_external
+ * Function: H5Lcreate_external
*
- * Purpose: Creates an external link from LINK_NAME to OBJ_NAME.
+ * Purpose: Creates an external link from LINK_NAME to OBJ_NAME.
*
* External links are links to objects in other HDF5 files. They
* are allowed to "dangle" like soft links internal to a file.
* FILE_NAME is the name of the file that OBJ_NAME is is contained
* within. If OBJ_NAME is given as a relative path name, the
* path will be relative to the root group of FILE_NAME.
- * LINK_NAME is interpreted relative to LINK_LOC_ID, which is
+ * LINK_NAME is interpreted relative to LINK_LOC_ID, which is
* either a file ID or a group ID.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: Non-negative on success/Negative on failure
*
- * Programmer: Quincey Koziol
+ * Programmer: Quincey Koziol
* Wednesday, May 18, 2005
*
*-------------------------------------------------------------------------
@@ -559,14 +347,14 @@ herr_t
H5Lcreate_external(const char *file_name, const char *obj_name,
hid_t link_loc_id, const char *link_name, hid_t lcpl_id, hid_t lapl_id)
{
- H5G_loc_t link_loc; /* Group location to create link */
- char *norm_obj_name = NULL; /* Pointer to normalized current name */
+ H5G_loc_t link_loc; /* Group location to create link */
+ char *norm_obj_name = NULL; /* Pointer to normalized current name */
void *ext_link_buf = NULL; /* Buffer to contain external link */
size_t buf_size; /* Size of buffer to hold external link */
size_t file_name_len; /* Length of file name string */
size_t norm_obj_name_len; /* Length of normalized object name string */
uint8_t *p; /* Pointer into external link buffer */
- hid_t dxpl_id = H5AC_ind_read_dxpl_id; /* dxpl used by library */
+ hid_t dxpl_id = H5AC_ind_read_dxpl_id; /* dxpl used by library */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
@@ -575,13 +363,13 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
/* Check arguments */
if(!file_name || !*file_name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no file name specified")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no file name specified")
if(!obj_name || !*obj_name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name specified")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name specified")
if(H5G_loc(link_loc_id, &link_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
if(!link_name || !*link_name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no link name specified")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no link name specified")
/* Get normalized copy of the link target */
if(NULL == (norm_obj_name = H5G_normalize(obj_name)))
@@ -616,7 +404,7 @@ done:
FUNC_LEAVE_API(ret_value)
} /* end H5Lcreate_external() */
-
+
/*-------------------------------------------------------------------------
* Function: H5L_register_external
*
@@ -645,7 +433,7 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5L_register_external() */
-
+
/*-------------------------------------------------------------------------
* Function: H5Lunpack_elink_val
*