diff options
Diffstat (limited to 'src/H5Fint.c')
-rw-r--r-- | src/H5Fint.c | 109 |
1 files changed, 82 insertions, 27 deletions
diff --git a/src/H5Fint.c b/src/H5Fint.c index 2412559..f144ba4 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -37,6 +37,7 @@ #include "H5Pprivate.h" /* Property lists */ #include "H5SMprivate.h" /* Shared Object Header Messages */ #include "H5Tprivate.h" /* Datatypes */ +#include "H5VLprivate.h" /* VOL plugins */ /****************/ @@ -73,9 +74,12 @@ typedef struct H5F_olist_t { /* Local Prototypes */ /********************/ -static int H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key); +/* private prototypes */ +static H5F_t *H5F_new(H5F_file_t *shared, unsigned flags, 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);/* Declare a free list to manage the H5F_t struct */ + const char *name, char ** /*out*/ actual_name); +static herr_t H5F_dest(H5F_t *f, hid_t dxpl_id, hbool_t flush); /*********************/ @@ -274,7 +278,8 @@ done: *--------------------------------------------------------------------------- */ herr_t -H5F_get_objects(const H5F_t *f, unsigned types, size_t max_nobjs, hid_t *obj_id_list, hbool_t app_ref, size_t *obj_id_count_ptr) +H5F_get_objects(const H5F_t *f, unsigned types, size_t max_nobjs, hid_t *obj_id_list, + hbool_t app_ref, size_t *obj_id_count_ptr) { size_t obj_id_count=0; /* Number of open IDs */ H5F_olist_t olist; /* Structure to hold search results */ @@ -380,7 +385,7 @@ done: * *------------------------------------------------------------------------- */ -static int +int H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key) { H5F_olist_t *olist = (H5F_olist_t *)key; /* Alias for search info */ @@ -430,6 +435,7 @@ H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key) case H5I_DATASPACE: case H5I_REFERENCE: case H5I_VFL: + case H5I_VOL: case H5I_GENPROP_CLS: case H5I_GENPROP_LST: case H5I_ERROR_CLASS: @@ -497,28 +503,34 @@ done: *------------------------------------------------------------------------- */ htri_t -H5F_is_hdf5(const char *name) +H5F_is_hdf5(const char *name, hid_t fapl_id) { - H5FD_t *file = NULL; /* Low-level file struct */ + H5F_t *file = NULL; /* Low-level file struct */ haddr_t sig_addr; /* Addess of hdf5 file signature */ htri_t ret_value = FAIL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* Open the file at the virtual file layer */ - if(NULL == (file = H5FD_open(name, H5F_ACC_RDONLY, H5P_FILE_ACCESS_DEFAULT, HADDR_UNDEF))) - HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to open file") + //if(NULL == (file = H5FD_open(name, H5F_ACC_RDONLY, fapl_id, HADDR_UNDEF))) + //HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to open file") + + /* Open the file */ + if(NULL == (file = H5F_open(name, H5F_ACC_RDONLY, H5P_FILE_CREATE_DEFAULT, + fapl_id, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FALSE, "unable to open file") /* The file is an hdf5 file if the hdf5 file signature can be found */ - if(H5FD_locate_signature(file, H5AC_ind_dxpl_g, &sig_addr) < 0) - HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable to locate file signature") + if(H5FD_locate_signature(file->shared->lf, H5AC_ind_dxpl_g, &sig_addr) < 0) + HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FALSE, "unable to locate file signature") ret_value = (HADDR_UNDEF != sig_addr); done: /* Close the file */ if(file) - if(H5FD_close(file) < 0 && ret_value >= 0) - HDONE_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file") + //if(H5FD_close(file) < 0 && ret_value >= 0) + if(H5F_close(file) < 0 && ret_value >= 0) + HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "unable to close file") FUNC_LEAVE_NOAPI(ret_value) } /* end H5F_is_hdf5() */ @@ -546,7 +558,7 @@ done: * *------------------------------------------------------------------------- */ -H5F_t * +static H5F_t * H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf) { H5F_t *f = NULL, *ret_value = NULL; @@ -555,7 +567,7 @@ H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t if(NULL == (f = H5FL_CALLOC(H5F_t))) HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate top file structure") - f->file_id = -1; + f->id_exists = FALSE; if(shared) { HDassert(lf == NULL); @@ -717,7 +729,7 @@ done: * *------------------------------------------------------------------------- */ -herr_t +static herr_t H5F_dest(H5F_t *f, hid_t dxpl_id, hbool_t flush) { herr_t ret_value = SUCCEED; /* Return value */ @@ -1212,7 +1224,6 @@ H5F_close(H5F_t *f) /* Sanity check */ HDassert(f); - HDassert(f->file_id > 0); /* This routine should only be called when a file ID's ref count drops to zero */ /* Perform checks for "semi" file close degree here, since closing the * file is not allowed if there are objects still open */ @@ -1233,7 +1244,7 @@ H5F_close(H5F_t *f) } /* end if */ /* Reset the file ID for this file */ - f->file_id = -1; + f->id_exists = FALSE; /* Attempt to close the file/mount hierarchy */ if(H5F_try_close(f) < 0) @@ -1407,6 +1418,50 @@ done: /*------------------------------------------------------------------------- + * Function: H5F_reopen + * + * Purpose: Reopen a file. The new file handle which is returned points + * to the same file as the specified file handle. Both handles + * share caches and other information. The only difference + * between the handles is that the new handle is not mounted + * anywhere and no files are mounted on it. + * + * Return: Success: New file ID + * + * Failure: FAIL + * + * Programmer: Robb Matzke + * Friday, October 16, 1998 + * + * Modifications: + * Quincey Koziol, May 14, 2002 + * Keep old file's read/write intent in reopened file. + * + *------------------------------------------------------------------------- + */ +H5F_t * +H5F_reopen(H5F_t *f) +{ + H5F_t *ret_value = NULL; + + FUNC_ENTER_NOAPI_NOINIT + + /* Get a new "top level" file struct, sharing the same "low level" file struct */ + /* Get a new "top level" file struct, sharing the same "low level" file struct */ + if(NULL == (ret_value = H5F_new(f->shared, 0, H5P_FILE_CREATE_DEFAULT, + H5P_FILE_ACCESS_DEFAULT, NULL))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to reopen file") + + /* Duplicate old file's names */ + ret_value->open_name = H5MM_xstrdup(f->open_name); + ret_value->actual_name = H5MM_xstrdup(f->actual_name); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5F_reopen() */ + + +/*------------------------------------------------------------------------- * Function: H5F_get_id * * Purpose: Get the file ID, incrementing it, or "resurrecting" it as @@ -1428,17 +1483,17 @@ H5F_get_id(H5F_t *file, hbool_t app_ref) HDassert(file); - if(file->file_id == -1) { - /* Get an atom for the file */ - if((file->file_id = H5I_register(H5I_FILE, file, app_ref)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file") - } else { - /* Increment reference count on atom. */ - if(H5I_inc_ref(file->file_id, app_ref) < 0) + if (FAIL == (ret_value = H5I_get_id(file, H5I_FILE))) { + /* resurrect the ID - Register an ID with the native plugin */ + if((ret_value = H5VL_native_register(H5I_FILE, file, app_ref)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") + file->id_exists = TRUE; + } + else { + /* Increment ref count on existing ID */ + if(H5I_inc_ref(ret_value, app_ref) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed") - } /* end else */ - - ret_value = file->file_id; + } done: FUNC_LEAVE_NOAPI(ret_value) |