diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2009-12-07 02:51:54 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2009-12-07 02:51:54 (GMT) |
commit | fda704377ebca6f980d7e842935977bb45f34d34 (patch) | |
tree | 6055a171c97afb62157e3f61f6bf8942dd9bab26 /src/H5F.c | |
parent | fb1059e507cab041e2fd6bf294b12843a1ddf1c7 (diff) | |
download | hdf5-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/H5F.c')
-rw-r--r-- | src/H5F.c | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -69,6 +69,8 @@ static size_t H5F_get_objects(const H5F_t *f, unsigned types, size_t max_objs, h static int H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key); static H5F_t *H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf); +static herr_t H5F_build_actual_name(const H5F_t *f, const H5P_genplist_t *fapl, + const char *name, char ** /*out*/ actual_name); static herr_t H5F_dest(H5F_t *f, hid_t dxpl_id); static herr_t H5F_close(H5F_t *f); @@ -1142,7 +1144,8 @@ H5F_dest(H5F_t *f, hid_t dxpl_id) *------------------------------------------------------------------------- */ H5F_t * -H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t dxpl_id) +H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, + hid_t dxpl_id) { H5F_t *file = NULL; /*the success return value */ H5F_file_t *shared = NULL; /*shared part of `file' */ @@ -1312,7 +1315,7 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t d HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to build extpath") /* Formulate the actual file name, after following symlinks, etc. */ - if(H5F_build_actual_name(file, name, &file->actual_name) < 0) + if(H5F_build_actual_name(file, a_plist, name, &file->actual_name) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to build actual name") /* Success */ @@ -2147,15 +2150,18 @@ H5F_decr_nopen_objs(H5F_t *f) * *------------------------------------------------------------------------- */ -herr_t -H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out*/) +static herr_t +H5F_build_actual_name(const H5F_t *f, const H5P_genplist_t *fapl, const char *name, + char **actual_name/*out*/) { + hid_t new_fapl_id = -1; /* ID for duplicated FAPL */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5F_build_actual_name) /* Sanity check */ HDassert(f); + HDassert(fapl); HDassert(name); HDassert(actual_name); @@ -2176,10 +2182,12 @@ H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out* /* Check for symbolic link */ if(S_IFLNK == (lst.st_mode & S_IFMT)) { + H5P_genplist_t *new_fapl; /* Duplicated FAPL */ int *fd; /* POSIX I/O file descriptor */ h5_stat_t st; /* Stat info from stat() call */ h5_stat_t fst; /* Stat info from fstat() call */ char realname[PATH_MAX]; /* Fully resolved path name of file */ + hbool_t want_posix_fd; /* Flag for retrieving file descriptor from VFD */ /* Perform a sanity check that the file or link wasn't switched * between when we opened it and when we called lstat(). This is @@ -2187,8 +2195,19 @@ H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out* * here: https://www.securecoding.cert.org/confluence/display/seccode/POS35-C.+Avoid+race+conditions+while+checking+for+the+existence+of+a+symbolic+link */ + /* Copy the FAPL object to modify */ + if((new_fapl_id = H5P_copy_plist(fapl, FALSE)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "unable to copy file access property list") + if(NULL == (new_fapl = (H5P_genplist_t *)H5I_object(new_fapl_id))) + HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL, "can't get property list") + + /* Set the character encoding on the new property list */ + want_posix_fd = TRUE; + if(H5P_set(new_fapl, H5F_ACS_WANT_POSIX_FD_NAME, &want_posix_fd) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set character encoding") + /* Retrieve the file handle */ - if(H5F_get_vfd_handle(f, H5P_DEFAULT, (void **)&fd) < 0) + if(H5F_get_vfd_handle(f, new_fapl_id, (void **)&fd) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve POSIX file descriptor") /* Stat the filename we're resolving */ @@ -2222,6 +2241,9 @@ H5F_build_actual_name(const H5F_t *f, const char *name, char **actual_name/*out* } /* end else */ done: + if(new_fapl_id > 0 && H5Pclose(new_fapl_id) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, FAIL, "can't close duplicated FAPL") + FUNC_LEAVE_NOAPI(ret_value) } /* H5F_build_actual_name() */ |