From f70f5b17403c20bef94e4c43bdf86e7fd4b88ec8 Mon Sep 17 00:00:00 2001 From: Mohamad Chaarawi Date: Wed, 11 Apr 2012 16:15:15 -0500 Subject: [svn-r22278] make get_vfd go through a generic file callback rearrange routines alphabetically --- src/H5F.c | 55 +- src/H5Fprivate.h | 1 + src/H5L.c | 18 - src/H5VL.c | 1913 +++++++++++++++++------------------ src/H5VLdummy.c | 12 +- src/H5VLnative.c | 2844 +++++++++++++++++++++++++++-------------------------- src/H5VLprivate.h | 13 +- src/H5VLpublic.h | 80 +- 8 files changed, 2534 insertions(+), 2402 deletions(-) diff --git a/src/H5F.c b/src/H5F.c index 93d7cc6..155ab41 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -750,7 +750,7 @@ H5Fget_vfd_handle(hid_t uid, hid_t fapl, void **file_handle) if(!file_handle) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file handle pointer") - if((ret_value = H5VL_file_get(uid, H5VL_FILE_GET_VFD_HANDLE, file_handle, fapl)) < 0) + if((ret_value = H5VL_file_generic(uid, H5VL_FILE_GET_VFD_HANDLE, file_handle, fapl)) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get file handle") done: @@ -805,6 +805,59 @@ done: HDONE_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file") FUNC_LEAVE_API(ret_value) +#if 0 + htri_t ret_value; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("t", "*s", name); + + /* Check args and all the boring stuff. */ + if(!name || !*name) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "no file name specified") + + if((ret_value = H5VL_file_generic(H5VL_FILE_IS_HDF5, &ret_value, name)) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get file handle") + + FUNC_LEAVE_API(ret_value) +#endif +} /* end H5Fis_hdf5() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_is_hdf5 + * + * Purpose: private version of H5Fis_hdf5. + * + * Return: Success: TRUE/FALSE + * + * Failure: Negative + * + * Programmer: Unknown + * + *------------------------------------------------------------------------- + */ +htri_t +H5F_is_hdf5(const char *name) +{ + H5FD_t *file = NULL; /* Low-level file struct */ + htri_t ret_value; /* 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") + + /* The file is an hdf5 file if the hdf5 file signature can be found */ + ret_value = (HADDR_UNDEF != H5F_locate_signature(file, H5AC_ind_dxpl_id)); + +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") + + FUNC_LEAVE_NOAPI(ret_value) } /* end H5Fis_hdf5() */ diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 7e45cfa..bf5e02d 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -534,6 +534,7 @@ H5_DLL hid_t H5F_get_id(H5F_t *file, hbool_t app_ref); H5_DLL herr_t H5F_get_obj_count(const H5F_t *f, unsigned types, hbool_t app_ref, size_t *obj_id_count_ptr); H5_DLL herr_t H5F_get_obj_ids(const H5F_t *f, unsigned types, size_t max_objs, hid_t *oid_list, hbool_t app_ref, size_t *obj_id_count_ptr); H5_DLL struct H5VL_class_t *H5F_get_vol_cls(const H5F_t *f); +H5_DLL htri_t H5F_is_hdf5(const char *name); /* Functions than retrieve values set/cached from the superblock/FCPL */ H5_DLL haddr_t H5F_get_base_addr(const H5F_t *f); diff --git a/src/H5L.c b/src/H5L.c index 095271b..fe30052 100644 --- a/src/H5L.c +++ b/src/H5L.c @@ -951,7 +951,6 @@ H5Lget_info_by_idx(hid_t loc_id, const char *group_name, if(H5G_traverse(&loc, group_name, H5G_TARGET_SLINK|H5G_TARGET_UDLINK, H5L_get_info_by_idx_cb, &udata, lapl_id, H5AC_ind_dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to get link info") - done: FUNC_LEAVE_API(ret_value) } /* end H5Lget_info_by_idx() */ @@ -1187,23 +1186,6 @@ H5Literate(hid_t id, H5_index_t idx_type, H5_iter_order_t order, /* Check arguments */ id_type = H5I_get_type(id); - -#if 0 - /* get the actual ID from an upper ID level */ - /* MSC - this is a workaround to allow the test suite to pass and - at some point needs to be removed once all high level operations - that needs to go through the VOL actually go through the VOL*/ - if (H5I_FILE_PUBLIC == id_type || H5I_GROUP_PUBLIC == id_type) { - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - grp_id = id_wrapper->obj_id; - id_type = H5I_get_type(grp_id); - } - else { - grp_id = id; - } -#endif - if(!(H5I_GROUP_PUBLIC == id_type || H5I_FILE_PUBLIC == id_type)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument") if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) diff --git a/src/H5VL.c b/src/H5VL.c index f821463..0de74bd 100644 --- a/src/H5VL.c +++ b/src/H5VL.c @@ -540,130 +540,142 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_file_open + * Function: H5VL_attr_create * - * Purpose: Opens a file through the VOL. + * Purpose: Creates an attribute through the VOL * - * Return: Success: User ID of the new file. This ID is of type - * H5I_FILE_PUBLIC which contains the VOL id and the actual file ID + * Return: Success: User ID of the new attr. This ID is of type + * H5I_ATTR_PUBLIC which contains the VOL plugin and the actual attr ID * * Failure: FAIL * * Programmer: Mohamad Chaarawi - * January, 2012 + * April, 2012 * *------------------------------------------------------------------------- */ hid_t -H5VL_file_open(const char *name, unsigned flags, hid_t fapl_id) +H5VL_attr_create(hid_t uid, const char *name, hid_t acpl_id, hid_t aapl_id) { - H5VL_class_t *vol_plugin; /* VOL for file */ - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - H5P_genplist_t *plist; /* Property list pointer */ - hid_t file_id; - hid_t ret_value; /* Return value */ + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the attr will be created */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new created attr*/ + H5I_type_t id_type; + hid_t loc_id; /* actual attr ID */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* get the VOL info from the fapl */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list") - if(H5P_get(plist, H5F_ACS_VOL_NAME, &vol_plugin) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get vol plugin") + id_type = H5I_get_type(uid); + /* Check id */ + if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && + H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* check if the corresponding VOL open callback exists */ - if(NULL == vol_plugin->file_cls.open) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file open' method") - /* call the corresponding VOL open callback */ - if((file_id = (vol_plugin->file_cls.open)(name, flags, fapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + /* get the ID struct */ + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* Create a new id that points to a struct that holds the file id and the VOL plugin */ + /* check if the corresponding VOL create callback exists */ + if(NULL == id_wrapper1->vol_plugin->attr_cls.create) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr create' method") + + /* call the corresponding VOL create callback */ + if((loc_id = (id_wrapper1->vol_plugin->attr_cls.create) + (id_wrapper1->obj_id, name, acpl_id, aapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") + + /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ /* Allocate new id structure */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper->obj_id = file_id; - id_wrapper->vol_plugin = vol_plugin; - vol_plugin->nrefs ++; + id_wrapper2->obj_id = loc_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + if((ret_value = H5I_register(H5I_ATTR_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") - if((ret_value = H5I_register(H5I_FILE_PUBLIC, id_wrapper, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_file_open() */ +} /* end H5VL_attr_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_file_create + * Function: H5VL_attr_open * - * Purpose: Creates a file through the VOL + * Purpose: Opens an attribute through the VOL * - * Return: Success: User ID of the new file. This ID is of type - * H5I_FILE_PUBLIC which contains the VOL id and the actual file ID + * Return: Success: User ID of the new attr. This ID is of type + * H5I_ATTR_PUBLIC which contains the VOL plugin and the actual attr ID * * Failure: FAIL * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ hid_t -H5VL_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id) +H5VL_attr_open(hid_t loc_id, void *location, const char *name, hid_t aapl_id) { - H5VL_class_t *vol_plugin; /* VOL for file */ - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - H5P_genplist_t *plist; /* Property list pointer */ - hid_t file_id; + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the attr will be opend */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend attr*/ + H5I_type_t id_type; + hid_t attr_id; /* actual attr ID */ hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* get the VOL info from the fapl */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list") - if(H5P_get(plist, H5F_ACS_VOL_NAME, &vol_plugin) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get vol plugin ID") + id_type = H5I_get_type(loc_id); + /* Check id */ + if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && + H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && + H5I_ATTR_PUBLIC != id_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* check if the corresponding VOL create callback exists */ - if(NULL == vol_plugin->file_cls.create) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file create' method") - /* call the corresponding VOL create callback */ - if((file_id = (vol_plugin->file_cls.create)(name, flags, fcpl_id, fapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") + /* get the ID struct */ + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* Create a new id that points to a struct that holds the file id and the VOL id */ + /* check if the type specific corresponding VOL open callback exists */ + if(NULL == id_wrapper1->vol_plugin->attr_cls.open) { + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr open' method") + } + + /* call the corresponding VOL open callback */ + if((attr_id = (id_wrapper1->vol_plugin->attr_cls.open) + (id_wrapper1->obj_id, location, name, aapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + + /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ /* Allocate new id structure */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper->obj_id = file_id; - id_wrapper->vol_plugin = vol_plugin; - vol_plugin->nrefs ++; + id_wrapper2->obj_id = attr_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; - if((ret_value = H5I_register(H5I_FILE_PUBLIC, id_wrapper, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") + if((ret_value = H5I_register(H5I_ATTR_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_file_create() */ +} /* end H5VL_attr_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_file_close + * Function: H5VL_attr_read * - * Purpose: Closes a file through the VOL + * Purpose: Reads data from attr through the VOL * * Return: Success: Non Negative * * Failure: Negative * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ -herr_t -H5VL_file_close(hid_t uid) +herr_t H5VL_attr_read(hid_t uid, hid_t mem_type_id, void *buf) { H5VL_id_wrapper_t *id_wrapper; /* user id structure */ herr_t ret_value = SUCCEED; @@ -671,43 +683,39 @@ H5VL_file_close(hid_t uid) FUNC_ENTER_NOAPI(FAIL) /* Check/fix arguments. */ - if(H5I_FILE_PUBLIC != H5I_get_type(uid)) + if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->file_cls.close) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file close' method") - if((ret_value = (id_wrapper->vol_plugin->file_cls.close)(id_wrapper->obj_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEFILE, FAIL, "close failed") - - id_wrapper->vol_plugin->nrefs--; - if(H5I_dec_app_ref(uid) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to decrement ref count on user ID") + if(NULL == id_wrapper->vol_plugin->attr_cls.read) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr read' method") + if((ret_value = (id_wrapper->vol_plugin->attr_cls.read) + (id_wrapper->obj_id, mem_type_id, buf)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "read failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_file_close() */ +} /* end H5VL_attr_read() */ /*------------------------------------------------------------------------- - * Function: H5VL_file_flush + * Function: H5VL_attr_write * - * Purpose: Flushes a file through the VOL + * Purpose: Writes data to attr through the VOL * * Return: Success: Non Negative * * Failure: Negative * * Programmer: Mohamad Chaarawi - * February, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ -herr_t -H5VL_file_flush(hid_t uid, H5F_scope_t scope) +herr_t H5VL_attr_write(hid_t uid, hid_t mem_type_id, const void *buf) { H5VL_id_wrapper_t *id_wrapper; /* user id structure */ herr_t ret_value = SUCCEED; @@ -715,191 +723,160 @@ H5VL_file_flush(hid_t uid, H5F_scope_t scope) FUNC_ENTER_NOAPI(FAIL) /* Check/fix arguments. */ - if(H5I_FILE_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->file_cls.flush) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file flush' method") - if((ret_value = (id_wrapper->vol_plugin->file_cls.flush)(id_wrapper->obj_id, scope)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTFLUSH, FAIL, "flush failed") + if(NULL == id_wrapper->vol_plugin->attr_cls.write) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr write' method") + if((ret_value = (id_wrapper->vol_plugin->attr_cls.write) + (id_wrapper->obj_id, mem_type_id, buf)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "write failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_file_flush() */ +} /* end H5VL_attr_write() */ /*------------------------------------------------------------------------- - * Function: H5VL_file_get + * Function: H5VL_attr_get * - * Purpose: Get specific information about the file through the VOL + * Purpose: Get specific information about the attribute through the VOL * * Return: Success: non negative * * Failure: negative * * Programmer: Mohamad Chaarawi - * February, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ herr_t -H5VL_file_get(hid_t uid, H5VL_file_get_t get_type, ...) +H5VL_attr_get(hid_t uid, H5VL_attr_get_t get_type, ...) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ va_list arguments; /* argument list passed from the API call */ - H5I_type_t id_type; /* Type of ID */ herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) - id_type = H5I_get_type(uid); - /* Check/fix arguments. */ - if (H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && - H5I_DATATYPE_PUBLIC != id_type && H5I_DATASET_PUBLIC != id_type && - H5I_ATTR_PUBLIC != id_type) + /* Check id */ + if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->file_cls.get) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file get' method") + if(NULL == id_wrapper->vol_plugin->attr_cls.get) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr get' method") - va_start(arguments, get_type); - if((ret_value = (id_wrapper->vol_plugin->file_cls.get)(id_wrapper->obj_id, get_type, arguments)) < 0) + va_start (arguments, get_type); + if((ret_value = (id_wrapper->vol_plugin->attr_cls.get)(id_wrapper->obj_id, get_type, + arguments)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") - va_end(arguments); + va_end (arguments); + + /* if the get_type is a named datatype, create a wrapper for it */ + if(H5VL_ATTR_GET_TYPE == get_type) { + H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ + hid_t *ret_id; + + va_start (arguments, get_type); + ret_id = va_arg (arguments, hid_t *); + + if(H5T_committed((H5T_t *)H5I_object_verify(*ret_id, H5I_DATATYPE))) { + /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (temp_id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + temp_id_wrapper->obj_id = *ret_id; + temp_id_wrapper->vol_plugin = id_wrapper->vol_plugin; + if((*ret_id = H5I_register(H5I_DATATYPE_PUBLIC, temp_id_wrapper, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") + } + va_end (arguments); + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_file_get() */ +} /* end H5VL_attr_get() */ /*------------------------------------------------------------------------- - * Function: H5VL_group_create - * - * Purpose: Creates a group through the VOL + * Function: H5VL_attr_generic * - * Return: Success: User ID of the new group. This ID is of type - * H5I_GROUP_PUBLIC which contains the VOL plugin and the actual group ID + * Purpose: perform a plugin specific operation * - * Failure: FAIL + * Return: Success: non negative + * Failure: negative * * Programmer: Mohamad Chaarawi - * March, 2012 + * April, 2012 * *------------------------------------------------------------------------- */ -hid_t -H5VL_group_create(hid_t uid, const char *name, hid_t gcpl_id, hid_t gapl_id) +herr_t +H5VL_attr_generic(hid_t uid, H5VL_attr_generic_t generic_type, ...) { - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the group will be created */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new created group*/ - hid_t group_id; /* actual group ID */ - hid_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* check if the corresponding VOL create callback exists */ - if(NULL == id_wrapper1->vol_plugin->group_cls.create) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `group create' method") - - /* call the corresponding VOL create callback */ - if((group_id = (id_wrapper1->vol_plugin->group_cls.create) - (id_wrapper1->obj_id, name, gcpl_id, gapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") - - /* Create a new id that points to a struct that holds the group id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = group_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; - - if((ret_value = H5I_register(H5I_GROUP_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_group_create() */ - - -/*------------------------------------------------------------------------- - * Function: H5VL_group_open - * - * Purpose: Opens a group through the VOL - * - * Return: Success: User ID of the new group. This ID is of type - * H5I_GROUP_PUBLIC which contains the VOL plugin and the actual group ID - * - * Failure: FAIL - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -hid_t -H5VL_group_open(hid_t loc_id, const char *name, hid_t gapl_id) -{ - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the group will be opend */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend group*/ - hid_t group_id; /* actual group ID */ - hid_t ret_value; /* Return value */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + va_list arguments; /* argument list passed from the API call */ + H5I_type_t id_type; + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + id_type = H5I_get_type(uid); + /* Check id */ + if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && + H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && + H5I_ATTR_PUBLIC != id_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* check if the type specific corresponding VOL open callback exists */ - if(NULL == id_wrapper1->vol_plugin->group_cls.open) { - void *location = NULL; /* a pointer to VOL specific token that indicates - the location of the object */ + if(NULL == id_wrapper->vol_plugin->attr_cls.generic) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr generic' method") - /* Get the token for the Object location through the VOL */ - if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, name, gapl_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") + va_start (arguments, generic_type); + if((ret_value = (id_wrapper->vol_plugin->attr_cls.generic)(id_wrapper->obj_id, generic_type, + arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "generic failed") + va_end (arguments); - /* Open the object through the VOL */ - if((ret_value = H5VL_object_open_by_loc(loc_id, location, gapl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") - } - else { - /* call the corresponding VOL open callback */ - if((group_id = (id_wrapper1->vol_plugin->group_cls.open) - (id_wrapper1->obj_id, name, gapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + if(H5VL_ATTR_OPEN_BY_IDX == generic_type) { + H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ + hid_t *ret_id; - /* Create a new id that points to a struct that holds the group id and the VOL plugin */ + va_start (arguments, generic_type); + ret_id = va_arg (arguments, hid_t *); + + /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + if(NULL == (temp_id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = group_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + temp_id_wrapper->obj_id = *ret_id; + temp_id_wrapper->vol_plugin = id_wrapper->vol_plugin; - if((ret_value = H5I_register(H5I_GROUP_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") + if((*ret_id = H5I_register(H5I_ATTR_PUBLIC, temp_id_wrapper, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") + va_end (arguments); } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_group_open() */ +} /* end H5VL_attr_generic() */ /*------------------------------------------------------------------------- - * Function: H5VL_group_close + * Function: H5VL_attr_close * - * Purpose: Closes a group through the VOL + * Purpose: Closes an attribute through the VOL * * Return: Success: Non Negative * @@ -911,95 +888,103 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_group_close(hid_t uid) +H5VL_attr_close(hid_t uid) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) /* Check/fix arguments. */ - if(H5I_GROUP_PUBLIC != H5I_get_type(uid)) + if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* if the VOL class does not implement a specific group close - callback, try the generic object close */ - if(NULL == id_wrapper->vol_plugin->group_cls.close) { + + /* if the VOL class does not implement a specific attr close + callback, try the generic object close */ + if(NULL == id_wrapper->vol_plugin->attr_cls.close){ if(H5VL_object_close(uid) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close object") } else { - if((ret_value = (id_wrapper->vol_plugin->group_cls.close)(id_wrapper->obj_id)) < 0) + if((ret_value = (id_wrapper->vol_plugin->attr_cls.close)(id_wrapper->obj_id)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") id_wrapper->vol_plugin->nrefs--; - if(H5I_dec_app_ref(uid) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") - } + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_group_close() */ +} /* end H5VL_attr_close() */ /*------------------------------------------------------------------------- - * Function: H5VL_group_get + * Function: H5VL_datatype_commit * - * Purpose: Get specific information about the group through the VOL + * Purpose: Commits a datatype to the file through the VOL * - * Return: Success: non negative + * Return: Success: Positive * - * Failure: negative + * Failure: Negative * * Programmer: Mohamad Chaarawi - * February, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ herr_t -H5VL_group_get(hid_t uid, H5VL_group_get_t get_type, ...) +H5VL_datatype_commit(hid_t uid, const char *name, hid_t type_id, hid_t lcpl_id, + hid_t tcpl_id, hid_t tapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - va_list arguments; /* argument list passed from the API call */ - H5I_type_t id_type; /* Type of ID */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper1; /* wrapper object of the location where the datatype will be commitd */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - id_type = H5I_get_type(uid); - /* Check/fix arguments. */ - if(H5I_GROUP_PUBLIC != id_type && H5I_FILE_PUBLIC != id_type) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->group_cls.get) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `group get' method") + /* check if the corresponding VOL commit callback exists */ + if(NULL == id_wrapper1->vol_plugin->datatype_cls.commit) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `datatype commit' method") - va_start (arguments, get_type); - if((ret_value = (id_wrapper->vol_plugin->group_cls.get) - (id_wrapper->obj_id, get_type, arguments)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") - va_end (arguments); + /* call the corresponding VOL commit callback */ + if((ret_value = (id_wrapper1->vol_plugin->datatype_cls.commit) + (id_wrapper1->obj_id, name, type_id, lcpl_id, tcpl_id, tapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "commit failed") + +#if 0 + /* Create a new id that points to a struct that holds the datatype id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + + if((id_wrapper2->obj_id = H5I_register(H5I_DATATYPE, H5I_object(type_id), TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + H5I_subst(type_id, id_wrapper2); + //H5I_remove_verify(type_id, H5I_DATATYPE); + +#endif done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_group_get() */ +} /* end H5VL_datatype_commit() */ /*------------------------------------------------------------------------- - * Function: H5VL_object_open_by_loc + * Function: H5VL_datatype_open * - * Purpose: Opens a object through the VOL + * Purpose: Opens a named datatype through the VOL * - * Return: Success: User ID of the new object. This ID is of type - * H5I_OBJECT_PUBLIC which contains the VOL plugin and the actual object ID + * Return: Success: User ID of the datatype. This ID is of type + * H5I_DATATYPE_PUBLIC which contains the VOL plugin and the actual datatype ID * * Failure: FAIL * @@ -1009,488 +994,689 @@ done: *------------------------------------------------------------------------- */ hid_t -H5VL_object_open_by_loc(hid_t uid, void *obj_loc, hid_t lapl_id) +H5VL_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id) { - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the object will be opend */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend object*/ - H5I_type_t id_type; - hid_t object_id; /* actual object ID */ + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the datatype will be opend */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend datatype*/ + hid_t datatype_id; /* actual datatype ID */ hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* check if the corresponding VOL open callback exists */ - if(NULL == id_wrapper1->vol_plugin->object_cls.open) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object open' method") + /* check if the type specific corresponding VOL open callback exists */ + if(NULL == id_wrapper1->vol_plugin->datatype_cls.open) { + void *location = NULL; /* a pointer to VOL specific token that indicates + the location of the object */ - /* call the corresponding VOL open callback */ - if((object_id = (id_wrapper1->vol_plugin->object_cls.open) - (id_wrapper1->obj_id, obj_loc, lapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + /* Get the token for the Object location through the VOL */ + if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, name, tapl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") - /* Create a new id that points to a struct that holds the object id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = object_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + /* Open the object through the VOL */ + if((ret_value = H5VL_object_open_by_loc(loc_id, location, tapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") + } + else { + /* call the corresponding VOL open callback */ + if((datatype_id = (id_wrapper1->vol_plugin->datatype_cls.open) + (id_wrapper1->obj_id, name, tapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") - id_type = H5I_get_type(object_id); + /* Create a new id that points to a struct that holds the datatype id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper2->obj_id = datatype_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; - if (H5I_GROUP == id_type) { - if((ret_value = H5I_register(H5I_GROUP_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize object handle") - } - else if (H5I_DATATYPE == id_type) { if((ret_value = H5I_register(H5I_DATATYPE_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize object handle") - } - else if (H5I_DATASET == id_type) { - if((ret_value = H5I_register(H5I_DATASET_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize object handle") + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") } - else { - ret_value = object_id; - } - done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_object_open_by_loc() */ +} /* end H5VL_datatype_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_object_close + * Function: H5VL_dataset_create * - * Purpose: Closes a object through the VOL + * Purpose: Creates a dataset through the VOL * - * Return: Success: Non Negative + * Return: Success: User ID of the new dataset. This ID is of type + * H5I_DATASET_PUBLIC which contains the VOL plugin and the actual dataset ID * - * Failure: Negative + * Failure: FAIL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -herr_t -H5VL_object_close(hid_t uid) +hid_t +H5VL_dataset_create(hid_t uid, const char *name, hid_t dcpl_id, hid_t dapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - H5I_type_t id_type; - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the dataset will be created */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new created dataset*/ + hid_t dataset_id; /* actual dataset ID */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - id_type = H5I_get_type(uid); + /* unwrap the datatype id if it is a named datatype */ + { + H5VL_id_wrapper_t *id_wrapper; + hid_t type_id; + H5P_genplist_t *plist; + /* Get the plist structure */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - /* In case of a named datatype being closed with H5Oopen after an - H5Tcommit, the id is still of type H5I_DATATYPE and not - H5I_DATATYPE_PUBLIC. In that case we just fall back to the - native implementation */ - if(H5I_DATATYPE == id_type) { - if(H5I_object(uid) == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") - if(H5I_dec_app_ref(uid) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") - HGOTO_DONE(ret_value) - } + /* get creation properties */ + if(H5P_get(plist, H5D_CRT_TYPE_ID_NAME, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for datatype id") - /* Check id */ - if(H5I_GROUP_PUBLIC != H5I_get_type(uid) && H5I_DATASET_PUBLIC != H5I_get_type(uid) && - H5I_DATATYPE_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + if(H5I_DATATYPE_PUBLIC == H5I_get_type(type_id)) { + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(type_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + if(H5P_set(plist, H5D_CRT_TYPE_ID_NAME, &(id_wrapper->obj_id)) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") + } + } /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->object_cls.close) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object close' method") - if((ret_value = (id_wrapper->vol_plugin->object_cls.close)(id_wrapper->obj_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") + /* check if the corresponding VOL create callback exists */ + if(NULL == id_wrapper1->vol_plugin->dataset_cls.create) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset create' method") - id_wrapper->vol_plugin->nrefs--; - if(H5I_dec_app_ref(uid) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") + /* call the corresponding VOL create callback */ + if((dataset_id = (id_wrapper1->vol_plugin->dataset_cls.create) + (id_wrapper1->obj_id, name, dcpl_id, dapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") + + /* Create a new id that points to a struct that holds the dataset id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper2->obj_id = dataset_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + if((ret_value = H5I_register(H5I_DATASET_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_object_close() */ +} /* end H5VL_dataset_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_object_lookup + * Function: H5VL_dataset_open * - * Purpose: Lookup the object location in the file + * Purpose: Opens a dataset through the VOL * - * Return: Success: non negative + * Return: Success: User ID of the new dataset. This ID is of type + * H5I_DATASET_PUBLIC which contains the VOL plugin and the actual dataset ID * - * Failure: negative + * Failure: FAIL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -herr_t -H5VL_object_lookup(hid_t uid, H5VL_object_lookup_t lookup_type, ...) +hid_t +H5VL_dataset_open(hid_t loc_id, const char *name, hid_t dapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - va_list arguments; /* argument list passed from the API call */ - H5I_type_t id_type; - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the dataset will be opend */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend dataset*/ + hid_t dataset_id; /* actual dataset ID */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - id_type = H5I_get_type(uid); - /* Check id */ - if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && - H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && - H5I_ATTR_PUBLIC != id_type) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - - /* lookup the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + /* get the ID struct */ + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->object_cls.lookup) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object lookup' method") + /* check if the type specific corresponding VOL open callback exists */ + if(NULL == id_wrapper1->vol_plugin->dataset_cls.open) { + void *location = NULL; /* a pointer to VOL specific token that indicates + the location of the object */ - va_start (arguments, lookup_type); - if((ret_value = (id_wrapper->vol_plugin->object_cls.lookup)(id_wrapper->obj_id, lookup_type, - arguments)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "lookup of object location failed") - va_end (arguments); + /* Get the token for the Object location through the VOL */ + if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, name, dapl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") + + /* Open the object through the VOL */ + if((ret_value = H5VL_object_open_by_loc(loc_id, location, dapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") + } + else { + /* call the corresponding VOL open callback */ + if((dataset_id = (id_wrapper1->vol_plugin->dataset_cls.open) + (id_wrapper1->obj_id, name, dapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + + /* Create a new id that points to a struct that holds the dataset id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper2->obj_id = dataset_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + if((ret_value = H5I_register(H5I_DATASET_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_object_lookup() */ +} /* end H5VL_dataset_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_object_get + * Function: H5VL_dataset_read * - * Purpose: Get specific information about the object through the VOL + * Purpose: Reads data from dataset through the VOL * - * Return: Success: non negative + * Return: Success: Non Negative * - * Failure: negative + * Failure: Negative * * Programmer: Mohamad Chaarawi - * February, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ -herr_t -H5VL_object_get(hid_t uid, H5VL_object_get_t get_type, ...) +herr_t H5VL_dataset_read(hid_t uid, hid_t mem_type_id, hid_t mem_space_id, + hid_t file_space_id, hid_t plist_id, void *buf) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - va_list arguments; /* argument list passed from the API call */ - H5I_type_t id_type; - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) - id_type = H5I_get_type(uid); - /* Check id */ - if(H5I_GROUP_PUBLIC != id_type && H5I_DATASET_PUBLIC != id_type && - H5I_DATATYPE_PUBLIC != id_type && H5I_FILE_PUBLIC != id_type && - H5I_ATTR_PUBLIC != id_type) + /* Check/fix arguments. */ + if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->object_cls.get) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object get' method") + if(NULL == id_wrapper->vol_plugin->dataset_cls.read) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset read' method") + if((ret_value = (id_wrapper->vol_plugin->dataset_cls.read) + (id_wrapper->obj_id, mem_type_id, mem_space_id, file_space_id, plist_id, buf)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "read failed") - va_start (arguments, get_type); - if((ret_value = (id_wrapper->vol_plugin->object_cls.get)(id_wrapper->obj_id, get_type, - arguments)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") - va_end (arguments); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_object_get() */ +} /* end H5VL_dataset_read() */ /*------------------------------------------------------------------------- - * Function: H5VL_datatype_commit + * Function: H5VL_dataset_write * - * Purpose: Commits a datatype to the file through the VOL + * Purpose: Writes data from dataset through the VOL * - * Return: Success: Positive + * Return: Success: Non Negative * - * Failure: Negative + * Failure: Negative * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -herr_t -H5VL_datatype_commit(hid_t uid, const char *name, hid_t type_id, hid_t lcpl_id, - hid_t tcpl_id, hid_t tapl_id) +herr_t H5VL_dataset_write(hid_t uid, hid_t mem_type_id, hid_t mem_space_id, + hid_t file_space_id, hid_t plist_id, const void *buf) { - H5VL_id_wrapper_t *id_wrapper1; /* wrapper object of the location where the datatype will be commitd */ - herr_t ret_value = SUCCEED; /* Return value */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + /* Check/fix arguments. */ + if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* check if the corresponding VOL commit callback exists */ - if(NULL == id_wrapper1->vol_plugin->datatype_cls.commit) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `datatype commit' method") - - /* call the corresponding VOL commit callback */ - if((ret_value = (id_wrapper1->vol_plugin->datatype_cls.commit) - (id_wrapper1->obj_id, name, type_id, lcpl_id, tcpl_id, tapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "commit failed") - -#if 0 - /* Create a new id that points to a struct that holds the datatype id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - - if((id_wrapper2->obj_id = H5I_register(H5I_DATATYPE, H5I_object(type_id), TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; - - H5I_subst(type_id, id_wrapper2); - //H5I_remove_verify(type_id, H5I_DATATYPE); - -#endif + if(NULL == id_wrapper->vol_plugin->dataset_cls.write) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset write' method") + if((ret_value = (id_wrapper->vol_plugin->dataset_cls.write) + (id_wrapper->obj_id, mem_type_id, mem_space_id, file_space_id, plist_id, buf)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "write failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_datatype_commit() */ +} /* end H5VL_dataset_write() */ /*------------------------------------------------------------------------- - * Function: H5VL_datatype_open + * Function: H5VL_dataset_set_extent * - * Purpose: Opens a named datatype through the VOL + * Purpose: Modifies the dimensions of a dataset * - * Return: Success: User ID of the datatype. This ID is of type - * H5I_DATATYPE_PUBLIC which contains the VOL plugin and the actual datatype ID + * Return: Success: Non Negative * - * Failure: FAIL + * Failure: Negative * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -hid_t -H5VL_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id) +herr_t H5VL_dataset_set_extent(hid_t uid, const hsize_t size[]) { - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the datatype will be opend */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend datatype*/ - hid_t datatype_id; /* actual datatype ID */ - hid_t ret_value; /* Return value */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + /* Check/fix arguments. */ + if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset ID") + /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* check if the type specific corresponding VOL open callback exists */ - if(NULL == id_wrapper1->vol_plugin->datatype_cls.open) { - void *location = NULL; /* a pointer to VOL specific token that indicates - the location of the object */ + if(NULL == id_wrapper->vol_plugin->dataset_cls.set_extent) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset set_extent' method") + if((ret_value = (id_wrapper->vol_plugin->dataset_cls.set_extent)(id_wrapper->obj_id, size)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "set_extent failed") - /* Get the token for the Object location through the VOL */ - if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, name, tapl_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_dataset_set_extent() */ - /* Open the object through the VOL */ - if((ret_value = H5VL_object_open_by_loc(loc_id, location, tapl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") + +/*------------------------------------------------------------------------- + * Function: H5VL_dataset_get + * + * Purpose: Get specific information about the dataset through the VOL + * + * Return: Success: non negative + * + * Failure: negative + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_dataset_get(hid_t uid, H5VL_dataset_get_t get_type, ...) +{ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + va_list arguments; /* argument list passed from the API call */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Check id */ + if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + + if(NULL == id_wrapper->vol_plugin->dataset_cls.get) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset get' method") + + va_start (arguments, get_type); + if((ret_value = (id_wrapper->vol_plugin->dataset_cls.get)(id_wrapper->obj_id, get_type, + arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") + va_end (arguments); + + /* if the get_type is a named datatype, create a wrapper for it */ + if(H5VL_DATASET_GET_TYPE == get_type) { + H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ + hid_t *ret_id; + + va_start (arguments, get_type); + ret_id = va_arg (arguments, hid_t *); + + if(H5T_committed((H5T_t *)H5I_object_verify(*ret_id, H5I_DATATYPE))) { + /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (temp_id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + temp_id_wrapper->obj_id = *ret_id; + temp_id_wrapper->vol_plugin = id_wrapper->vol_plugin; + + if((*ret_id = H5I_register(H5I_DATATYPE_PUBLIC, temp_id_wrapper, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") + } + va_end (arguments); } - else { - /* call the corresponding VOL open callback */ - if((datatype_id = (id_wrapper1->vol_plugin->datatype_cls.open) - (id_wrapper1->obj_id, name, tapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") - /* Create a new id that points to a struct that holds the datatype id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = datatype_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_dataset_get() */ - if((ret_value = H5I_register(H5I_DATATYPE_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") + +/*------------------------------------------------------------------------- + * Function: H5VL_dataset_close + * + * Purpose: Closes a dataset through the VOL + * + * Return: Success: Non Negative + * + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_dataset_close(hid_t uid) +{ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Check/fix arguments. */ + if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + + /* if the VOL class does not implement a specific dataset close + callback, try the generic object close */ + if(NULL == id_wrapper->vol_plugin->dataset_cls.close){ + if(H5VL_object_close(uid) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close object") + } + else { + if((ret_value = (id_wrapper->vol_plugin->dataset_cls.close)(id_wrapper->obj_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") + + id_wrapper->vol_plugin->nrefs--; + if(H5I_dec_app_ref(uid) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_datatype_open() */ +} /* end H5VL_dataset_close() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_create + * Function: H5VL_file_open * - * Purpose: Creates a dataset through the VOL + * Purpose: Opens a file through the VOL. * - * Return: Success: User ID of the new dataset. This ID is of type - * H5I_DATASET_PUBLIC which contains the VOL plugin and the actual dataset ID + * Return: Success: User ID of the new file. This ID is of type + * H5I_FILE_PUBLIC which contains the VOL id and the actual file ID * * Failure: FAIL * * Programmer: Mohamad Chaarawi - * March, 2012 + * January, 2012 * *------------------------------------------------------------------------- */ hid_t -H5VL_dataset_create(hid_t uid, const char *name, hid_t dcpl_id, hid_t dapl_id) +H5VL_file_open(const char *name, unsigned flags, hid_t fapl_id) { - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the dataset will be created */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new created dataset*/ - hid_t dataset_id; /* actual dataset ID */ - hid_t ret_value; /* Return value */ + H5VL_class_t *vol_plugin; /* VOL for file */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + H5P_genplist_t *plist; /* Property list pointer */ + hid_t file_id; + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* unwrap the datatype id if it is a named datatype */ - { - H5VL_id_wrapper_t *id_wrapper; - hid_t type_id; - H5P_genplist_t *plist; - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + /* get the VOL info from the fapl */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list") + if(H5P_get(plist, H5F_ACS_VOL_NAME, &vol_plugin) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get vol plugin") - /* get creation properties */ - if(H5P_get(plist, H5D_CRT_TYPE_ID_NAME, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for datatype id") + /* check if the corresponding VOL open callback exists */ + if(NULL == vol_plugin->file_cls.open) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file open' method") + /* call the corresponding VOL open callback */ + if((file_id = (vol_plugin->file_cls.open)(name, flags, fapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") - if(H5I_DATATYPE_PUBLIC == H5I_get_type(type_id)) { - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(type_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + /* Create a new id that points to a struct that holds the file id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper->obj_id = file_id; + id_wrapper->vol_plugin = vol_plugin; + vol_plugin->nrefs ++; - if(H5P_set(plist, H5D_CRT_TYPE_ID_NAME, &(id_wrapper->obj_id)) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") - } - } - /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + if((ret_value = H5I_register(H5I_FILE_PUBLIC, id_wrapper, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_file_open() */ - /* check if the corresponding VOL create callback exists */ - if(NULL == id_wrapper1->vol_plugin->dataset_cls.create) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset create' method") + +/*------------------------------------------------------------------------- + * Function: H5VL_file_create + * + * Purpose: Creates a file through the VOL + * + * Return: Success: User ID of the new file. This ID is of type + * H5I_FILE_PUBLIC which contains the VOL id and the actual file ID + * + * Failure: FAIL + * + * Programmer: Mohamad Chaarawi + * January, 2012 + * + *------------------------------------------------------------------------- + */ +hid_t +H5VL_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id) +{ + H5VL_class_t *vol_plugin; /* VOL for file */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + H5P_genplist_t *plist; /* Property list pointer */ + hid_t file_id; + hid_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* get the VOL info from the fapl */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list") + if(H5P_get(plist, H5F_ACS_VOL_NAME, &vol_plugin) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get vol plugin ID") + /* check if the corresponding VOL create callback exists */ + if(NULL == vol_plugin->file_cls.create) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file create' method") /* call the corresponding VOL create callback */ - if((dataset_id = (id_wrapper1->vol_plugin->dataset_cls.create) - (id_wrapper1->obj_id, name, dcpl_id, dapl_id)) < 0) + if((file_id = (vol_plugin->file_cls.create)(name, flags, fcpl_id, fapl_id)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") - /* Create a new id that points to a struct that holds the dataset id and the VOL plugin */ + /* Create a new id that points to a struct that holds the file id and the VOL id */ /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = dataset_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + id_wrapper->obj_id = file_id; + id_wrapper->vol_plugin = vol_plugin; + vol_plugin->nrefs ++; - if((ret_value = H5I_register(H5I_DATASET_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + if((ret_value = H5I_register(H5I_FILE_PUBLIC, id_wrapper, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_create() */ +} /* end H5VL_file_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_open + * Function: H5VL_file_flush * - * Purpose: Opens a dataset through the VOL + * Purpose: Flushes a file through the VOL + * + * Return: Success: Non Negative + * + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * February, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_file_flush(hid_t uid, H5F_scope_t scope) +{ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Check/fix arguments. */ + if(H5I_FILE_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + + if(NULL == id_wrapper->vol_plugin->file_cls.flush) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file flush' method") + if((ret_value = (id_wrapper->vol_plugin->file_cls.flush)(id_wrapper->obj_id, scope)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTFLUSH, FAIL, "flush failed") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_file_flush() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_file_get + * + * Purpose: Get specific information about the file through the VOL + * + * Return: Success: non negative + * + * Failure: negative + * + * Programmer: Mohamad Chaarawi + * February, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_file_get(hid_t uid, H5VL_file_get_t get_type, ...) +{ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + va_list arguments; /* argument list passed from the API call */ + H5I_type_t id_type; /* Type of ID */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + id_type = H5I_get_type(uid); + /* Check/fix arguments. */ + if (H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && + H5I_DATATYPE_PUBLIC != id_type && H5I_DATASET_PUBLIC != id_type && + H5I_ATTR_PUBLIC != id_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + + if(NULL == id_wrapper->vol_plugin->file_cls.get) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file get' method") + + va_start(arguments, get_type); + if((ret_value = (id_wrapper->vol_plugin->file_cls.get)(id_wrapper->obj_id, get_type, arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") + va_end(arguments); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_file_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_file_generic * - * Return: Success: User ID of the new dataset. This ID is of type - * H5I_DATASET_PUBLIC which contains the VOL plugin and the actual dataset ID + * Purpose: perform a plugin specific operation * - * Failure: FAIL + * Return: Success: non negative + * Failure: negative * * Programmer: Mohamad Chaarawi - * March, 2012 + * April, 2012 * *------------------------------------------------------------------------- */ -hid_t -H5VL_dataset_open(hid_t loc_id, const char *name, hid_t dapl_id) +herr_t +H5VL_file_generic(hid_t uid, H5VL_file_generic_t generic_type, ...) { - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the dataset will be opend */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend dataset*/ - hid_t dataset_id; /* actual dataset ID */ - hid_t ret_value; /* Return value */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + va_list arguments; /* argument list passed from the API call */ + H5I_type_t id_type; + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + id_type = H5I_get_type(uid); + /* Check id */ + if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && + H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && + H5I_FILE_PUBLIC != id_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* check if the type specific corresponding VOL open callback exists */ - if(NULL == id_wrapper1->vol_plugin->dataset_cls.open) { - void *location = NULL; /* a pointer to VOL specific token that indicates - the location of the object */ - - /* Get the token for the Object location through the VOL */ - if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, name, dapl_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") - - /* Open the object through the VOL */ - if((ret_value = H5VL_object_open_by_loc(loc_id, location, dapl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") - } - else { - /* call the corresponding VOL open callback */ - if((dataset_id = (id_wrapper1->vol_plugin->dataset_cls.open) - (id_wrapper1->obj_id, name, dapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + if(NULL == id_wrapper->vol_plugin->file_cls.generic) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file generic' method") - /* Create a new id that points to a struct that holds the dataset id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = dataset_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + va_start (arguments, generic_type); + if((ret_value = (id_wrapper->vol_plugin->file_cls.generic)(id_wrapper->obj_id, generic_type, + arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "generic failed") + va_end (arguments); - if((ret_value = H5I_register(H5I_DATASET_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") - } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_open() */ +} /* end H5VL_file_generic() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_close + * Function: H5VL_file_close * - * Purpose: Closes a dataset through the VOL + * Purpose: Closes a file through the VOL * * Return: Success: Non Negative * * Failure: Negative * * Programmer: Mohamad Chaarawi - * March, 2012 + * January, 2012 * *------------------------------------------------------------------------- */ herr_t -H5VL_dataset_close(hid_t uid) +H5VL_file_close(hid_t uid) { H5VL_id_wrapper_t *id_wrapper; /* user id structure */ herr_t ret_value = SUCCEED; @@ -1498,161 +1684,198 @@ H5VL_dataset_close(hid_t uid) FUNC_ENTER_NOAPI(FAIL) /* Check/fix arguments. */ - if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) + if(H5I_FILE_PUBLIC != H5I_get_type(uid)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* if the VOL class does not implement a specific dataset close - callback, try the generic object close */ - if(NULL == id_wrapper->vol_plugin->dataset_cls.close){ - if(H5VL_object_close(uid) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close object") - } - else { - if((ret_value = (id_wrapper->vol_plugin->dataset_cls.close)(id_wrapper->obj_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") - id_wrapper->vol_plugin->nrefs--; - if(H5I_dec_app_ref(uid) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") - } + if(NULL == id_wrapper->vol_plugin->file_cls.close) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `file close' method") + if((ret_value = (id_wrapper->vol_plugin->file_cls.close)(id_wrapper->obj_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEFILE, FAIL, "close failed") + + id_wrapper->vol_plugin->nrefs--; + if(H5I_dec_app_ref(uid) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to decrement ref count on user ID") + done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_close() */ +} /* end H5VL_file_close() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_read + * Function: H5VL_group_create * - * Purpose: Reads data from dataset through the VOL + * Purpose: Creates a group through the VOL * - * Return: Success: Non Negative + * Return: Success: User ID of the new group. This ID is of type + * H5I_GROUP_PUBLIC which contains the VOL plugin and the actual group ID * - * Failure: Negative + * Failure: FAIL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -herr_t H5VL_dataset_read(hid_t uid, hid_t mem_type_id, hid_t mem_space_id, - hid_t file_space_id, hid_t plist_id, void *buf) +hid_t +H5VL_group_create(hid_t uid, const char *name, hid_t gcpl_id, hid_t gapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the group will be created */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new created group*/ + hid_t group_id; /* actual group ID */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* Check/fix arguments. */ - if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->dataset_cls.read) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset read' method") - if((ret_value = (id_wrapper->vol_plugin->dataset_cls.read) - (id_wrapper->obj_id, mem_type_id, mem_space_id, file_space_id, plist_id, buf)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "read failed") + /* check if the corresponding VOL create callback exists */ + if(NULL == id_wrapper1->vol_plugin->group_cls.create) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `group create' method") + + /* call the corresponding VOL create callback */ + if((group_id = (id_wrapper1->vol_plugin->group_cls.create) + (id_wrapper1->obj_id, name, gcpl_id, gapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") + + /* Create a new id that points to a struct that holds the group id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper2->obj_id = group_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + if((ret_value = H5I_register(H5I_GROUP_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_read() */ +} /* end H5VL_group_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_write + * Function: H5VL_group_open * - * Purpose: Writes data from dataset through the VOL + * Purpose: Opens a group through the VOL * - * Return: Success: Non Negative + * Return: Success: User ID of the new group. This ID is of type + * H5I_GROUP_PUBLIC which contains the VOL plugin and the actual group ID * - * Failure: Negative + * Failure: FAIL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -herr_t H5VL_dataset_write(hid_t uid, hid_t mem_type_id, hid_t mem_space_id, - hid_t file_space_id, hid_t plist_id, const void *buf) +hid_t +H5VL_group_open(hid_t loc_id, const char *name, hid_t gapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the group will be opend */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend group*/ + hid_t group_id; /* actual group ID */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* Check/fix arguments. */ - if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->dataset_cls.write) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset write' method") - if((ret_value = (id_wrapper->vol_plugin->dataset_cls.write) - (id_wrapper->obj_id, mem_type_id, mem_space_id, file_space_id, plist_id, buf)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "write failed") + /* check if the type specific corresponding VOL open callback exists */ + if(NULL == id_wrapper1->vol_plugin->group_cls.open) { + void *location = NULL; /* a pointer to VOL specific token that indicates + the location of the object */ + + /* Get the token for the Object location through the VOL */ + if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, name, gapl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") + + /* Open the object through the VOL */ + if((ret_value = H5VL_object_open_by_loc(loc_id, location, gapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") + } + else { + /* call the corresponding VOL open callback */ + if((group_id = (id_wrapper1->vol_plugin->group_cls.open) + (id_wrapper1->obj_id, name, gapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + /* Create a new id that points to a struct that holds the group id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper2->obj_id = group_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + if((ret_value = H5I_register(H5I_GROUP_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_write() */ +} /* end H5VL_group_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_set_extent + * Function: H5VL_group_get * - * Purpose: Modifies the dimensions of a dataset + * Purpose: Get specific information about the group through the VOL * - * Return: Success: Non Negative + * Return: Success: non negative * - * Failure: Negative + * Failure: negative * * Programmer: Mohamad Chaarawi - * March, 2012 + * February, 2012 * *------------------------------------------------------------------------- */ -herr_t H5VL_dataset_set_extent(hid_t uid, const hsize_t size[]) +herr_t +H5VL_group_get(hid_t uid, H5VL_group_get_t get_type, ...) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + va_list arguments; /* argument list passed from the API call */ + H5I_type_t id_type; /* Type of ID */ + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + id_type = H5I_get_type(uid); /* Check/fix arguments. */ - if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset ID") + if(H5I_GROUP_PUBLIC != id_type && H5I_FILE_PUBLIC != id_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->dataset_cls.set_extent) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset set_extent' method") - if((ret_value = (id_wrapper->vol_plugin->dataset_cls.set_extent)(id_wrapper->obj_id, size)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "set_extent failed") + if(NULL == id_wrapper->vol_plugin->group_cls.get) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `group get' method") + + va_start (arguments, get_type); + if((ret_value = (id_wrapper->vol_plugin->group_cls.get) + (id_wrapper->obj_id, get_type, arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") + va_end (arguments); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_set_extent() */ +} /* end H5VL_group_get() */ /*------------------------------------------------------------------------- - * Function: H5VL_dataset_get + * Function: H5VL_group_close * - * Purpose: Get specific information about the dataset through the VOL + * Purpose: Closes a group through the VOL * - * Return: Success: non negative + * Return: Success: Non Negative * - * Failure: negative + * Failure: Negative * * Programmer: Mohamad Chaarawi * March, 2012 @@ -1660,56 +1883,39 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_dataset_get(hid_t uid, H5VL_dataset_get_t get_type, ...) +H5VL_group_close(hid_t uid) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - va_list arguments; /* argument list passed from the API call */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) - /* Check id */ - if(H5I_DATASET_PUBLIC != H5I_get_type(uid)) + /* Check/fix arguments. */ + if(H5I_GROUP_PUBLIC != H5I_get_type(uid)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->dataset_cls.get) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `dataset get' method") - - va_start (arguments, get_type); - if((ret_value = (id_wrapper->vol_plugin->dataset_cls.get)(id_wrapper->obj_id, get_type, - arguments)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") - va_end (arguments); - - /* if the get_type is a named datatype, create a wrapper for it */ - if(H5VL_DATASET_GET_TYPE == get_type) { - H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ - hid_t *ret_id; - - va_start (arguments, get_type); - ret_id = va_arg (arguments, hid_t *); - - if(H5T_committed((H5T_t *)H5I_object_verify(*ret_id, H5I_DATATYPE))) { - /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (temp_id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - temp_id_wrapper->obj_id = *ret_id; - temp_id_wrapper->vol_plugin = id_wrapper->vol_plugin; - - if((*ret_id = H5I_register(H5I_DATATYPE_PUBLIC, temp_id_wrapper, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") - } - va_end (arguments); + /* if the VOL class does not implement a specific group close + callback, try the generic object close */ + if(NULL == id_wrapper->vol_plugin->group_cls.close) { + if(H5VL_object_close(uid) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close object") } + else { + if((ret_value = (id_wrapper->vol_plugin->group_cls.close)(id_wrapper->obj_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") + + id_wrapper->vol_plugin->nrefs--; + if(H5I_dec_app_ref(uid) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_dataset_get() */ +} /* end H5VL_group_close() */ /*------------------------------------------------------------------------- @@ -1852,300 +2058,118 @@ H5_DLL herr_t H5VL_link_move(hid_t src_loc_id, const char *src_name, hid_t dst_l done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_link_move() */ - - -/*------------------------------------------------------------------------- - * Function: H5VL_link_delete - * - * Purpose: Copy or delete a link from src to dst. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Mohamad Chaarawi - * April, 2012 - * - *------------------------------------------------------------------------- - */ -H5_DLL herr_t H5VL_link_delete(hid_t loc_id, const char *name, hid_t lapl_id) -{ - H5VL_id_wrapper_t *id_wrapper; - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* check if the corresponding VOL delete callback exists */ - if(NULL == id_wrapper->vol_plugin->link_cls.delete) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `link delete' method") - - /* call the corresponding VOL delete callback */ - if((ret_value = (id_wrapper->vol_plugin->link_cls.delete) - (id_wrapper->obj_id, name, lapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "link delete failed") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_link_delete() */ - - -/*------------------------------------------------------------------------- - * Function: H5VL_attr_create - * - * Purpose: Creates an attribute through the VOL - * - * Return: Success: User ID of the new attr. This ID is of type - * H5I_ATTR_PUBLIC which contains the VOL plugin and the actual attr ID - * - * Failure: FAIL - * - * Programmer: Mohamad Chaarawi - * April, 2012 - * - *------------------------------------------------------------------------- - */ -hid_t -H5VL_attr_create(hid_t uid, const char *name, hid_t acpl_id, hid_t aapl_id) -{ - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the attr will be created */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new created attr*/ - H5I_type_t id_type; - hid_t loc_id; /* actual attr ID */ - hid_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - id_type = H5I_get_type(uid); - /* Check id */ - if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && - H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - - /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* check if the corresponding VOL create callback exists */ - if(NULL == id_wrapper1->vol_plugin->attr_cls.create) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr create' method") - - /* call the corresponding VOL create callback */ - if((loc_id = (id_wrapper1->vol_plugin->attr_cls.create) - (id_wrapper1->obj_id, name, acpl_id, aapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "create failed") - - /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = loc_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; - - if((ret_value = H5I_register(H5I_ATTR_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_create() */ - - -/*------------------------------------------------------------------------- - * Function: H5VL_attr_open - * - * Purpose: Opens an attribute through the VOL - * - * Return: Success: User ID of the new attr. This ID is of type - * H5I_ATTR_PUBLIC which contains the VOL plugin and the actual attr ID - * - * Failure: FAIL - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -hid_t -H5VL_attr_open(hid_t loc_id, void *location, const char *name, hid_t aapl_id) -{ - H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the attr will be opend */ - H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend attr*/ - H5I_type_t id_type; - hid_t attr_id; /* actual attr ID */ - hid_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - id_type = H5I_get_type(loc_id); - /* Check id */ - if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && - H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && - H5I_ATTR_PUBLIC != id_type) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - - /* get the ID struct */ - if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* check if the type specific corresponding VOL open callback exists */ - if(NULL == id_wrapper1->vol_plugin->attr_cls.open) { - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr open' method") - } - - /* call the corresponding VOL open callback */ - if((attr_id = (id_wrapper1->vol_plugin->attr_cls.open) - (id_wrapper1->obj_id, location, name, aapl_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") - - /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - id_wrapper2->obj_id = attr_id; - id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; - - if((ret_value = H5I_register(H5I_ATTR_PUBLIC, id_wrapper2, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_open() */ - - -/*------------------------------------------------------------------------- - * Function: H5VL_attr_close - * - * Purpose: Closes an attribute through the VOL - * - * Return: Success: Non Negative - * - * Failure: Negative - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -herr_t -H5VL_attr_close(hid_t uid) -{ - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI(FAIL) - - /* Check/fix arguments. */ - if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* if the VOL class does not implement a specific attr close - callback, try the generic object close */ - if(NULL == id_wrapper->vol_plugin->attr_cls.close){ - if(H5VL_object_close(uid) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close object") - } - else { - if((ret_value = (id_wrapper->vol_plugin->attr_cls.close)(id_wrapper->obj_id)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") - - id_wrapper->vol_plugin->nrefs--; - if(H5I_dec_app_ref(uid) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") - } -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_close() */ +} /* end H5VL_link_move() */ /*------------------------------------------------------------------------- - * Function: H5VL_attr_read - * - * Purpose: Reads data from attr through the VOL + * Function: H5VL_link_delete * - * Return: Success: Non Negative + * Purpose: Copy or delete a link from src to dst. * - * Failure: Negative + * Return: Non-negative on success/Negative on failure * * Programmer: Mohamad Chaarawi - * March, 2012 + * April, 2012 * *------------------------------------------------------------------------- */ -herr_t H5VL_attr_read(hid_t uid, hid_t mem_type_id, void *buf) +H5_DLL herr_t H5VL_link_delete(hid_t loc_id, const char *name, hid_t lapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* Check/fix arguments. */ - if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + /* check if the corresponding VOL delete callback exists */ + if(NULL == id_wrapper->vol_plugin->link_cls.delete) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `link delete' method") - if(NULL == id_wrapper->vol_plugin->attr_cls.read) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr read' method") - if((ret_value = (id_wrapper->vol_plugin->attr_cls.read) - (id_wrapper->obj_id, mem_type_id, buf)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "read failed") + /* call the corresponding VOL delete callback */ + if((ret_value = (id_wrapper->vol_plugin->link_cls.delete) + (id_wrapper->obj_id, name, lapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "link delete failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_read() */ +} /* end H5VL_link_delete() */ /*------------------------------------------------------------------------- - * Function: H5VL_attr_write + * Function: H5VL_object_open_by_loc * - * Purpose: Writes data to attr through the VOL + * Purpose: Opens a object through the VOL * - * Return: Success: Non Negative + * Return: Success: User ID of the new object. This ID is of type + * H5I_OBJECT_PUBLIC which contains the VOL plugin and the actual object ID * - * Failure: Negative + * Failure: FAIL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -herr_t H5VL_attr_write(hid_t uid, hid_t mem_type_id, const void *buf) +hid_t +H5VL_object_open_by_loc(hid_t uid, void *obj_loc, hid_t lapl_id) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ - herr_t ret_value = SUCCEED; + H5VL_id_wrapper_t *id_wrapper1; /* user id structure of the location where the object will be opend */ + H5VL_id_wrapper_t *id_wrapper2; /* user id structure of new opend object*/ + H5I_type_t id_type; + hid_t object_id; /* actual object ID */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - /* Check/fix arguments. */ - if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + if(NULL == (id_wrapper1 = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->attr_cls.write) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr write' method") - if((ret_value = (id_wrapper->vol_plugin->attr_cls.write) - (id_wrapper->obj_id, mem_type_id, buf)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "write failed") + /* check if the corresponding VOL open callback exists */ + if(NULL == id_wrapper1->vol_plugin->object_cls.open) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object open' method") + + /* call the corresponding VOL open callback */ + if((object_id = (id_wrapper1->vol_plugin->object_cls.open) + (id_wrapper1->obj_id, obj_loc, lapl_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "open failed") + + /* Create a new id that points to a struct that holds the object id and the VOL plugin */ + /* Allocate new id structure */ + if(NULL == (id_wrapper2 = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + id_wrapper2->obj_id = object_id; + id_wrapper2->vol_plugin = id_wrapper1->vol_plugin; + + id_type = H5I_get_type(object_id); + + if (H5I_GROUP == id_type) { + if((ret_value = H5I_register(H5I_GROUP_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize object handle") + } + else if (H5I_DATATYPE == id_type) { + if((ret_value = H5I_register(H5I_DATATYPE_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize object handle") + } + else if (H5I_DATASET == id_type) { + if((ret_value = H5I_register(H5I_DATASET_PUBLIC, id_wrapper2, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize object handle") + } + else { + ret_value = object_id; + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_write() */ +} /* end H5VL_object_open_by_loc() */ /*------------------------------------------------------------------------- - * Function: H5VL_attr_get + * Function: H5VL_object_lookup * - * Purpose: Get specific information about the attribute through the VOL + * Purpose: Lookup the object location in the file * * Return: Success: non negative * @@ -2157,74 +2181,57 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL_attr_get(hid_t uid, H5VL_attr_get_t get_type, ...) +H5VL_object_lookup(hid_t uid, H5VL_object_lookup_t lookup_type, ...) { H5VL_id_wrapper_t *id_wrapper; /* user id structure */ va_list arguments; /* argument list passed from the API call */ + H5I_type_t id_type; herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) + id_type = H5I_get_type(uid); /* Check id */ - if(H5I_ATTR_PUBLIC != H5I_get_type(uid)) + if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && + H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && + H5I_ATTR_PUBLIC != id_type) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") - /* get the ID struct */ + /* lookup the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->attr_cls.get) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr get' method") + if(NULL == id_wrapper->vol_plugin->object_cls.lookup) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object lookup' method") - va_start (arguments, get_type); - if((ret_value = (id_wrapper->vol_plugin->attr_cls.get)(id_wrapper->obj_id, get_type, - arguments)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") + va_start (arguments, lookup_type); + if((ret_value = (id_wrapper->vol_plugin->object_cls.lookup)(id_wrapper->obj_id, lookup_type, + arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "lookup of object location failed") va_end (arguments); - - /* if the get_type is a named datatype, create a wrapper for it */ - if(H5VL_ATTR_GET_TYPE == get_type) { - H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ - hid_t *ret_id; - - va_start (arguments, get_type); - ret_id = va_arg (arguments, hid_t *); - - if(H5T_committed((H5T_t *)H5I_object_verify(*ret_id, H5I_DATATYPE))) { - /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (temp_id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - temp_id_wrapper->obj_id = *ret_id; - temp_id_wrapper->vol_plugin = id_wrapper->vol_plugin; - - if((*ret_id = H5I_register(H5I_DATATYPE_PUBLIC, temp_id_wrapper, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") - } - va_end (arguments); - } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_get() */ +} /* end H5VL_object_lookup() */ /*------------------------------------------------------------------------- - * Function: H5VL_attr_generic + * Function: H5VL_object_get * - * Purpose: perform a plugin specific operation + * Purpose: Get specific information about the object through the VOL * * Return: Success: non negative + * * Failure: negative * * Programmer: Mohamad Chaarawi - * April, 2012 + * February, 2012 * *------------------------------------------------------------------------- */ herr_t -H5VL_attr_generic(hid_t uid, H5VL_attr_generic_t generic_type, ...) +H5VL_object_get(hid_t uid, H5VL_object_get_t get_type, ...) { - H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ va_list arguments; /* argument list passed from the API call */ H5I_type_t id_type; herr_t ret_value = SUCCEED; @@ -2233,42 +2240,84 @@ H5VL_attr_generic(hid_t uid, H5VL_attr_generic_t generic_type, ...) id_type = H5I_get_type(uid); /* Check id */ - if(H5I_FILE_PUBLIC != id_type && H5I_GROUP_PUBLIC != id_type && - H5I_DATASET_PUBLIC != id_type && H5I_DATATYPE_PUBLIC != id_type && - H5I_ATTR_PUBLIC != id_type) + if(H5I_GROUP_PUBLIC != id_type && H5I_DATASET_PUBLIC != id_type && + H5I_DATATYPE_PUBLIC != id_type && H5I_FILE_PUBLIC != id_type && + H5I_ATTR_PUBLIC != id_type) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") /* get the ID struct */ if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - if(NULL == id_wrapper->vol_plugin->attr_cls.generic) - HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `attr generic' method") + if(NULL == id_wrapper->vol_plugin->object_cls.get) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object get' method") - va_start (arguments, generic_type); - if((ret_value = (id_wrapper->vol_plugin->attr_cls.generic)(id_wrapper->obj_id, generic_type, - arguments)) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "generic failed") + va_start (arguments, get_type); + if((ret_value = (id_wrapper->vol_plugin->object_cls.get)(id_wrapper->obj_id, get_type, + arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "get failed") va_end (arguments); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_object_get() */ - if(H5VL_ATTR_OPEN_BY_IDX == generic_type) { - H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ - hid_t *ret_id; + +/*------------------------------------------------------------------------- + * Function: H5VL_object_close + * + * Purpose: Closes a object through the VOL + * + * Return: Success: Non Negative + * + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_object_close(hid_t uid) +{ + H5VL_id_wrapper_t *id_wrapper; /* user id structure */ + H5I_type_t id_type; + herr_t ret_value = SUCCEED; - va_start (arguments, generic_type); - ret_id = va_arg (arguments, hid_t *); + FUNC_ENTER_NOAPI(FAIL) - /* Create a new id that points to a struct that holds the attr id and the VOL plugin */ - /* Allocate new id structure */ - if(NULL == (temp_id_wrapper = (H5VL_id_wrapper_t *)H5MM_malloc(sizeof(H5VL_id_wrapper_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - temp_id_wrapper->obj_id = *ret_id; - temp_id_wrapper->vol_plugin = id_wrapper->vol_plugin; + id_type = H5I_get_type(uid); - if((*ret_id = H5I_register(H5I_ATTR_PUBLIC, temp_id_wrapper, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") - va_end (arguments); + /* In case of a named datatype being closed with H5Oopen after an + H5Tcommit, the id is still of type H5I_DATATYPE and not + H5I_DATATYPE_PUBLIC. In that case we just fall back to the + native implementation */ + if(H5I_DATATYPE == id_type) { + if(H5I_object(uid) == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") + if(H5I_dec_app_ref(uid) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") + HGOTO_DONE(ret_value) } + + /* Check id */ + if(H5I_GROUP_PUBLIC != H5I_get_type(uid) && H5I_DATASET_PUBLIC != H5I_get_type(uid) && + H5I_DATATYPE_PUBLIC != H5I_get_type(uid)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a user ID") + + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(uid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + + if(NULL == id_wrapper->vol_plugin->object_cls.close) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `object close' method") + if((ret_value = (id_wrapper->vol_plugin->object_cls.close)(id_wrapper->obj_id)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "close failed") + + id_wrapper->vol_plugin->nrefs--; + if(H5I_dec_app_ref(uid) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on user ID") + done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_generic() */ +} /* end H5VL_object_close() */ + diff --git a/src/H5VLdummy.c b/src/H5VLdummy.c index 8f4131a..45527d0 100644 --- a/src/H5VLdummy.c +++ b/src/H5VLdummy.c @@ -84,12 +84,6 @@ H5VL_class_t H5VL_dummy_g = { NULL, NULL }, - { /* group_cls */ - NULL, - NULL, - NULL, - NULL - }, { /* file_cls */ H5VL_dummy_file_create, /* create */ H5VL_dummy_file_open, /* open */ @@ -97,6 +91,12 @@ H5VL_class_t H5VL_dummy_g = { NULL, H5VL_dummy_file_close /* close */ }, + { /* group_cls */ + NULL, + NULL, + NULL, + NULL + }, { /* link_cls */ NULL, /* create */ NULL, /* delete */ diff --git a/src/H5VLnative.c b/src/H5VLnative.c index a6d21ed7..34a35bb 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -62,12 +62,6 @@ static hid_t H5VL_NATIVE_g = 0; /* Prototypes */ static herr_t H5VL_native_term(void); -static hid_t H5VL_native_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); -static hid_t H5VL_native_file_open(const char *name, unsigned flags, hid_t fapl_id); -static herr_t H5VL_native_file_flush(hid_t fid, H5F_scope_t scope); -static herr_t H5VL_native_file_get(hid_t file_id, H5VL_file_get_t get_type, va_list arguments); -static herr_t H5VL_native_file_close(hid_t fid); - static hid_t H5VL_native_attr_create(hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t aapl_id); static hid_t H5VL_native_attr_open(hid_t loc_id, void *location, const char *attr_name, hid_t aapl_id); static herr_t H5VL_native_attr_read(hid_t attr_id, hid_t dtype_id, void *buf); @@ -76,6 +70,10 @@ static herr_t H5VL_native_attr_get(hid_t id, H5VL_attr_get_t get_type, va_list a static herr_t H5VL_native_attr_generic(hid_t id, H5VL_attr_generic_t generic_type, va_list arguments); static herr_t H5VL_native_attr_close(hid_t attr_id); +static herr_t H5VL_native_datatype_commit(hid_t loc_id, const char *name, hid_t type_id, + hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id); +static hid_t H5VL_native_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id); + static hid_t H5VL_native_dataset_create(hid_t loc_id, const char *name, hid_t dcpl_id, hid_t dapl_id); static hid_t H5VL_native_dataset_open(hid_t loc_id, const char *name, hid_t dapl_id); static herr_t H5VL_native_dataset_read(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, @@ -86,9 +84,12 @@ static herr_t H5VL_native_dataset_set_extent(hid_t dset_id, const hsize_t size[] static herr_t H5VL_native_dataset_get(hid_t id, H5VL_dataset_get_t get_type, va_list arguments); static herr_t H5VL_native_dataset_close(hid_t dataset_id); -static herr_t H5VL_native_datatype_commit(hid_t loc_id, const char *name, hid_t type_id, - hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id); -static hid_t H5VL_native_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id); +static hid_t H5VL_native_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); +static hid_t H5VL_native_file_open(const char *name, unsigned flags, hid_t fapl_id); +static herr_t H5VL_native_file_flush(hid_t fid, H5F_scope_t scope); +static herr_t H5VL_native_file_get(hid_t file_id, H5VL_file_get_t get_type, va_list arguments); +static herr_t H5VL_native_file_generic(hid_t loc_id, H5VL_file_generic_t generic_type, va_list arguments); +static herr_t H5VL_native_file_close(hid_t fid); static hid_t H5VL_native_group_create(hid_t loc_id, const char *name, hid_t gcpl_id, hid_t gapl_id); static hid_t H5VL_native_group_open(hid_t loc_id, const char *name, hid_t gapl_id); @@ -134,19 +135,20 @@ H5VL_class_t H5VL_native_g = { H5VL_native_dataset_get, /* get */ H5VL_native_dataset_close /* close */ }, - { /* group_cls */ - H5VL_native_group_create, /* create */ - H5VL_native_group_open, /* open */ - H5VL_native_group_get, /* get */ - H5VL_native_group_close /* close */ - }, { /* file_cls */ H5VL_native_file_create, /* create */ H5VL_native_file_open, /* open */ H5VL_native_file_flush, /* flush */ H5VL_native_file_get, /* get */ + H5VL_native_file_generic, /* generic */ H5VL_native_file_close /* close */ }, + { /* group_cls */ + H5VL_native_group_create, /* create */ + H5VL_native_group_open, /* open */ + H5VL_native_group_get, /* get */ + H5VL_native_group_close /* close */ + }, { /* link_cls */ H5VL_native_link_create, /* create */ H5VL_native_link_move, /* move */ @@ -273,725 +275,509 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_native_file_open + * Function: H5VL_native_attr_create * - * Purpose: Opens a file as a native HDF5 file. + * Purpose: Creates an attribute on an object. * - * Return: Success: file id. + * Return: Success: attr id. * Failure: NULL * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ static hid_t -H5VL_native_file_open(const char *name, unsigned flags, hid_t fapl_id) +H5VL_native_attr_create(hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t UNUSED aapl_id) { - H5F_t *new_file; /* file struct */ - hid_t ret_value; + H5G_loc_t loc; /* Object location */ + H5P_genplist_t *plist; /* Property list pointer */ + hid_t type_id, space_id; + H5T_t *type; /* Datatype to use for attribute */ + H5S_t *space; /* Dataspace to use for attribute */ + void *location = NULL; + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* Open the file */ - if(NULL == (new_file = H5F_open(name, flags, H5P_FILE_CREATE_DEFAULT, fapl_id, H5AC_dxpl_id))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to open file") + /* Get the plist structure */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(acpl_id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") + /* get creation properties */ + if(H5P_get(plist, H5A_CRT_TYPE_ID_NAME, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for datatype id") + if(H5P_get(plist, H5A_CRT_SPACE_ID_NAME, &space_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for space id") + if(H5P_get(plist, H5A_CRT_LOCATION_NAME, &location) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for lcpl id") - /* store a pointer to the VOL class in the file structure */ - new_file->vol_cls = &H5VL_native_g; + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + if(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file") + if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a type") + if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - /* Keep this ID in file object structure */ - new_file->file_id = ret_value; + if(NULL == location) { /* H5Acreate */ + /* Go do the real work for attaching the attribute to the dataset */ + if((ret_value = H5A_create(&loc, attr_name, type, space, acpl_id, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute") + } + else { /* H5Acreate_by_name */ + H5G_loc_t *obj_loc = (H5G_loc_t *)location; -done: - if(ret_value < 0 && new_file && H5F_try_close(new_file) < 0) - HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "problems closing file") + /* Go do the real work for attaching the attribute to the dataset */ + if((ret_value = H5A_create(obj_loc, attr_name, type, space, acpl_id, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute") + + if(H5G_loc_free(obj_loc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") + } +done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_file_open() */ +} /* end H5VL_native_attr_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_file_create + * Function: H5VL_native_attr_open * - * Purpose: Creates a file as a native HDF5 file. + * Purpose: Opens a attr inside a native h5 file. * - * Return: Success: the file id. + * Return: Success: attr id. * Failure: NULL * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ static hid_t -H5VL_native_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id) +H5VL_native_attr_open(hid_t loc_id, void *location, const char *attr_name, hid_t UNUSED aapl_id) { - H5F_t *new_file; /* file struct */ - hid_t ret_value; + H5G_loc_t loc; /* Object location */ + H5A_t *attr = NULL; /* Attribute opened */ + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* - * Adjust bit flags by turning on the creation bit and making sure that - * the EXCL or TRUNC bit is set. All newly-created files are opened for - * reading and writing. - */ - if (0==(flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC))) - flags |= H5F_ACC_EXCL; /*default*/ - flags |= H5F_ACC_RDWR | H5F_ACC_CREAT; + /* check arguments */ + if(H5I_ATTR == H5I_get_type(loc_id)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute") + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Create the file */ - if(NULL == (new_file = H5F_open(name, flags, fcpl_id, fapl_id, H5AC_dxpl_id))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to create file") + if(NULL != location) { /* H5Aopen_by_name */ + H5G_loc_t *obj_loc = (H5G_loc_t *)location; - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") + /* Read in attribute from object header */ + if(NULL == (attr = H5O_attr_open_by_name(obj_loc->oloc, attr_name, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from object header") - /* store a pointer to the VOL class in the file structure */ - new_file->vol_cls = &H5VL_native_g; + if(H5G_loc_free(obj_loc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") - /* Keep this ID in file object structure */ - new_file->file_id = ret_value; + } + else { /* H5Aopen */ + /* Read in attribute from object header */ + if(NULL == (attr = H5O_attr_open_by_name(loc.oloc, attr_name, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from object header for attribute: '%s'", attr_name) + } + + /* Finish initializing attribute */ + if(H5A_open_common(&loc, attr) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to initialize attribute") + + /* Register the attribute and get an ID for it */ + if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") done: - if(ret_value < 0 && new_file && H5F_try_close(new_file) < 0) - HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "problems closing file") + /* Cleanup on failure */ + if(ret_value < 0) + if(attr && H5A_close(attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_file_create() */ + +} /* end H5VL_native_attr_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_file_close + * Function: H5VL_native_attr_read * - * Purpose: Closes a file. + * Purpose: Reads in data from attribute. * - * Return: Success: 0 - * Failure: -1, file not closed. + * Non-negative on success/Negative on failure * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_file_close(hid_t file_id) +H5VL_native_attr_read(hid_t attr_id, hid_t dtype_id, void *buf) { - int nref; - H5F_t *f; - herr_t ret_value = SUCCEED; /* Return value */ + H5A_t *attr; /* Attribute object for ID */ + H5T_t *mem_type; /* Memory datatype */ + herr_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* Check/fix arguments. */ - if(H5I_FILE != H5I_get_type(file_id)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file ID") - - /* get the file struct */ - if(NULL == (f = (H5F_t *)H5I_object(file_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") - - /* Flush file if this is the last reference to this id and we have write - * intent, unless it will be flushed by the "shared" file being closed. - * This is only necessary to replicate previous behaviour, and could be - * disabled by an option/property to improve performance. */ - if((f->shared->nrefs > 1) && (H5F_INTENT(f) & H5F_ACC_RDWR)) { - if((nref = H5I_get_ref(f->file_id, FALSE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't get ID ref count") - if(nref == 1) - if(H5F_flush(f, H5AC_dxpl_id, FALSE) < 0) - HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush cache") - } /* end if */ + if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + if(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - /* - * Decrement reference count on atom. When it reaches zero the file will - * be closed. - */ - if(H5I_dec_ref(f->file_id) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTCLOSEFILE, FAIL, "decrementing file ID failed") + /* Go write the actual data to the attribute */ + if((ret_value = H5A_read(attr, mem_type, buf, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_READERROR, FAIL, "unable to read attribute") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_file_close() */ +} /* end H5VL_native_attr_read() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_file_flush + * Function: H5VL_native_attr_write * - * Purpose: Flushs a native HDF5 file. + * Purpose: Writes out data to attribute. * - * Return: Success: 0 - * Failure: -1, file not flushed. + * Non-negative on success/Negative on failure * * Programmer: Mohamad Chaarawi - * February, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_file_flush(hid_t object_id, H5F_scope_t scope) +H5VL_native_attr_write(hid_t attr_id, hid_t dtype_id, const void *buf) { - H5F_t *f = NULL; /* File to flush */ - H5O_loc_t *oloc = NULL; /* Object location for ID */ - herr_t ret_value = SUCCEED; /* Return value */ + H5A_t *attr; /* Attribute object for ID */ + H5T_t *mem_type; /* Memory datatype */ + herr_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - switch(H5I_get_type(object_id)) { - case H5I_FILE: - if(NULL == (f = (H5F_t *)H5I_object(object_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") - break; - case H5I_GROUP: - { - H5G_t *grp; + if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + if(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - if(NULL == (grp = (H5G_t *)H5I_object(object_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid group identifier") - oloc = H5G_oloc(grp); - break; - } - case H5I_DATATYPE: - { - H5T_t *type; - - if(NULL == (type = (H5T_t *)H5I_object(object_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid type identifier") - oloc = H5T_oloc(type); - break; - } - case H5I_DATASET: - { - H5D_t *dset; - - if(NULL == (dset = (H5D_t *)H5I_object(object_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier") - oloc = H5D_oloc(dset); - break; - } - - case H5I_ATTR: - { - H5A_t *attr; - - if(NULL == (attr = (H5A_t *)H5I_object(object_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid attribute identifier") - oloc = H5A_oloc(attr); - break; - } - case H5I_UNINIT: - case H5I_BADID: - case H5I_DATASPACE: - case H5I_REFERENCE: - case H5I_VFL: - case H5I_VOL: - case H5I_GENPROP_CLS: - case H5I_GENPROP_LST: - case H5I_ERROR_CLASS: - case H5I_ERROR_MSG: - case H5I_ERROR_STACK: - case H5I_NTYPES: - default: - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - } /* end switch */ - - if(!f) { - if(!oloc) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "object is not assocated with a file") - f = oloc->file; - } /* end if */ - if(!f) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "object is not associated with a file") - - /* Flush the file */ - /* - * Nothing to do if the file is read only. This determination is - * made at the shared open(2) flags level, implying that opening a - * file twice, once for read-only and once for read-write, and then - * calling H5Fflush() with the read-only handle, still causes data - * to be flushed. - */ - if(H5F_ACC_RDWR & H5F_INTENT(f)) { - /* Flush other files, depending on scope */ - if(H5F_SCOPE_GLOBAL == scope) { - /* Call the flush routine for mounted file hierarchies */ - if(H5F_flush_mounts(f, H5AC_dxpl_id) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush mounted file hierarchy") - } /* end if */ - else { - /* Call the flush routine, for this file */ - if(H5F_flush(f, H5AC_dxpl_id, FALSE) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush file's cached information") - } /* end else */ - } /* end if */ + /* Go write the actual data to the attribute */ + if((ret_value = H5A_write(attr, mem_type, buf, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "unable to write attribute") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_file_flush() */ +} /* end H5VL_native_attr_write() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_file_get + * Function: H5VL_native_attr_get * - * Purpose: Gets certain data about a file + * Purpose: Gets certain information about an attribute * * Return: Success: 0 * Failure: -1 * * Programmer: Mohamad Chaarawi - * February, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_file_get(hid_t obj_id, H5VL_file_get_t get_type, va_list arguments) +H5VL_native_attr_get(hid_t attr_id, H5VL_attr_get_t get_type, va_list arguments) { - H5F_t *f = NULL; /* File struct */ + H5A_t *attr; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* Check/fix arguments. */ - if(H5I_get_type(obj_id) == H5I_FILE ) { - if(NULL == (f = (H5F_t *)H5I_object(obj_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file") - } /* end if */ - else { - H5G_loc_t loc; /* Object location */ - /* Get symbol table entry */ - if(H5G_loc(obj_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object ID") - f = loc.oloc->file; - } /* end else */ + /* check arguments */ + if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") switch (get_type) { - /* H5Fget_access_plist */ - case H5VL_FILE_GET_FAPL: + /* H5Aget_space */ + case H5VL_ATTR_GET_SPACE: { - hid_t *plist_id = va_arg (arguments, hid_t *); + hid_t *ret_id = va_arg (arguments, hid_t *); - /* Retrieve the file's access property list */ - if((*plist_id = H5F_get_access_plist(f, TRUE)) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get file access property list") + if((*ret_id = H5A_get_space(attr)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get space ID of attribute") break; } - /* H5Fget_create_plist */ - case H5VL_FILE_GET_FCPL: + /* H5Aget_type */ + case H5VL_ATTR_GET_TYPE: { - H5P_genplist_t *plist; /* Property list */ - hid_t *plist_id = va_arg (arguments, hid_t *); + hid_t *ret_id = va_arg (arguments, hid_t *); - if(NULL == (plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + if((*ret_id = H5A_get_type(attr)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get datatype ID of attribute") + break; + } + /* H5Aget_create_plist */ + case H5VL_ATTR_GET_ACPL: + { + hid_t *ret_id = va_arg (arguments, hid_t *); - /* Create the property list object to return */ - if((*plist_id = H5P_copy_plist(plist, TRUE)) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to copy file creation properties") + if((*ret_id = H5A_get_create_plist(attr)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for attr") break; } - /* H5Fget_filesize */ - case H5VL_FILE_GET_SIZE: + /* H5Aget_name */ + case H5VL_ATTR_GET_NAME: { - haddr_t eof; /* End of file address */ - hsize_t *ret = va_arg (arguments, hsize_t *); + ssize_t *ret_val = va_arg (arguments, ssize_t *); + size_t buf_size = va_arg (arguments, size_t); + char *buf = va_arg (arguments, char *); + + /* Call private function in turn */ + if(0 > (*ret_val = H5A_get_name(attr, buf_size, buf))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get attribute name") - /* Go get the actual file size */ - if(HADDR_UNDEF == (eof = H5FDget_eof(f->shared->lf))) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file size") - *ret = (hsize_t)eof; break; } - /* H5Fget_freespace */ - case H5VL_FILE_GET_FREE_SPACE: + /* H5Aget_info */ + case H5VL_ATTR_GET_INFO: { - hsize_t tot_space; /* Amount of free space in the file */ - hssize_t *ret = va_arg (arguments, hssize_t *); + H5A_info_t *ainfo = va_arg (arguments, H5A_info_t *); + + if(H5A_get_info(attr, ainfo) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get attribute info") - /* Go get the actual amount of free space in the file */ - if(H5MF_get_freespace(f, H5AC_ind_dxpl_id, &tot_space, NULL) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file") - *ret = (hssize_t)tot_space; break; } - case H5VL_FILE_GET_FREE_SECTIONS: + case H5VL_ATTR_GET_STORAGE_SIZE: { - H5F_sect_info_t *sect_info = va_arg (arguments, H5F_sect_info_t *); - ssize_t *ret = va_arg (arguments, ssize_t *); - H5F_mem_t type = va_arg (arguments, H5F_mem_t); - size_t nsects = va_arg (arguments, size_t); + hsize_t *ret = va_arg (arguments, hsize_t *); - /* Go get the free-space section information in the file */ - if((*ret = H5MF_get_free_sections(f, H5AC_ind_dxpl_id, - type, nsects, sect_info)) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file") + /* Set return value */ + *ret = attr->shared->data_size; break; } - /* H5Fget_info2 */ - case H5VL_FILE_GET_INFO: - { - H5F_info2_t *finfo = va_arg (arguments, H5F_info2_t *); + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from attr") + } - /* For file IDs, get the file object directly */ - /* (This prevents the H5G_loc() call from returning the file pointer for - * the top file in a mount hierarchy) - */ - HDassert(f->shared); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_attr_get() */ - /* Reset file info struct */ - HDmemset(finfo, 0, sizeof(*finfo)); + +/*------------------------------------------------------------------------- + * Function: H5VL_native_attr_generic + * + * Purpose: Perform a plugin specific operation for an attribute + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Mohamad Chaarawi + * April, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_attr_generic(hid_t loc_id, H5VL_attr_generic_t generic_type, va_list arguments) +{ + H5A_t *attr = NULL; /* Attribute opened */ + herr_t ret_value = SUCCEED; /* Return value */ - /* Get the size of the superblock and any superblock extensions */ - if(H5F_super_size(f, H5AC_ind_dxpl_id, &finfo->super.super_size, - &finfo->super.super_ext_size) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve superblock sizes") + FUNC_ENTER_NOAPI_NOINIT - /* Get the size of any persistent free space */ - if(H5MF_get_freespace(f, H5AC_ind_dxpl_id, &finfo->free.tot_space, - &finfo->free.meta_size) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve free space information") + switch (generic_type) { + /* H5Aopen_by_idx */ + case H5VL_ATTR_OPEN_BY_IDX: + { + hid_t *ret_id = va_arg (arguments, hid_t *); + char *obj_name = va_arg (arguments, char *); + H5_index_t idx_type = va_arg (arguments, H5_index_t); + H5_iter_order_t order = va_arg (arguments, H5_iter_order_t); + hsize_t n = va_arg (arguments, hsize_t); + hid_t aapl_id = va_arg (arguments, hid_t); + hid_t lapl_id = va_arg (arguments, hid_t); + H5G_loc_t loc; /* Object location */ - /* Check for SOHM info */ - if(H5F_addr_defined(f->shared->sohm_addr)) - if(H5SM_ih_size(f, H5AC_ind_dxpl_id, &finfo->sohm.hdr_size, &finfo->sohm.msgs_info) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve SOHM index & heap storage info") + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Set version # fields */ - finfo->super.version = f->shared->sblock->super_vers; - finfo->sohm.version = f->shared->sohm_vers; - finfo->free.version = HDF5_FREESPACE_VERSION; + /* Open the attribute in the object header */ + if(NULL == (attr = H5A_open_by_idx(&loc, obj_name, idx_type, order, n, lapl_id, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute") + + /* Register the attribute and get an ID for it */ + if((*ret_id = H5I_register(H5I_ATTR, attr, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") break; } - /* H5Fget_intent */ - case H5VL_FILE_GET_INTENT: - { - unsigned *ret = va_arg (arguments, unsigned *); + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't recognize this operation type") + } - /* HDF5 uses some flags internally that users don't know about. - * Simplify things for them so that they only get either H5F_ACC_RDWR - * or H5F_ACC_RDONLY. - */ - if(H5F_INTENT(f) & H5F_ACC_RDWR) - *ret = H5F_ACC_RDWR; - else - *ret = H5F_ACC_RDONLY; - break; - } - /* H5Fget_name */ - case H5VL_FILE_GET_NAME: - { - char *name = va_arg (arguments, char *); - ssize_t *ret = va_arg (arguments, ssize_t *); - size_t size = va_arg (arguments, size_t); - size_t len; - - len = HDstrlen(H5F_OPEN_NAME(f)); - - if(name) { - HDstrncpy(name, H5F_OPEN_NAME(f), MIN(len + 1,size)); - if(len >= size) - name[size-1]='\0'; - } /* end if */ - - /* Set the return value for the API call */ - *ret = (ssize_t)len; - break; - } - /* H5Fget_vfd_handle */ - case H5VL_FILE_GET_VFD_HANDLE: - { - void **file_handle = va_arg (arguments, void **); - hid_t fapl = va_arg (arguments, hid_t); - - /* Retrieve the VFD handle for the file */ - if(H5F_get_vfd_handle(f, fapl, file_handle) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve VFD handle") - break; - } - /* H5Fget_mdc_config */ - case H5VL_FILE_GET_MDC_CONF: - { - H5AC_cache_config_t *config_ptr = va_arg (arguments, H5AC_cache_config_t *); - - /* Go get the resize configuration */ - if(H5AC_get_cache_auto_resize_config(f->shared->cache, config_ptr) < 0) - HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_auto_resize_config() failed.") - break; - } - /* H5Fget_mdc_hit_rate */ - case H5VL_FILE_GET_MDC_HR: - { - double *hit_rate_ptr = va_arg (arguments, double *); - - /* Go get the current hit rate */ - if(H5AC_get_cache_hit_rate(f->shared->cache, hit_rate_ptr) < 0) - HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_hit_rate() failed.") - break; - } - /* H5Fget_mdc_size */ - case H5VL_FILE_GET_MDC_SIZE: - { - size_t *max_size_ptr = va_arg (arguments, size_t *); - size_t *min_clean_size_ptr = va_arg (arguments, size_t *); - size_t *cur_size_ptr = va_arg (arguments, size_t *); - int *cur_num_entries_ptr = va_arg (arguments, int *); - int32_t cur_num_entries; - - /* Go get the size data */ - if(H5AC_get_cache_size(f->shared->cache, max_size_ptr, min_clean_size_ptr, - cur_size_ptr, &cur_num_entries) < 0) - HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_size() failed.") - - if(cur_num_entries_ptr != NULL) - *cur_num_entries_ptr = (int)cur_num_entries; - break; - } - default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information") - } /* end switch */ done: + /* Cleanup on failure */ + if(H5VL_ATTR_OPEN_BY_IDX == generic_type && ret_value < 0) + if(attr && H5A_close(attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_file_get() */ +} /* end H5VL_native_attr_generic() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_group_create + * Function: H5VL_native_attr_close * - * Purpose: Creates a group inside a native h5 file. + * Purpose: Closes an attribute. * - * Return: Success: group id. - * Failure: NULL + * Return: Success: 0 + * Failure: -1, attr not closed. * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ -static hid_t -H5VL_native_group_create(hid_t loc_id, const char *name, hid_t gcpl_id, hid_t gapl_id) +static herr_t +H5VL_native_attr_close(hid_t attr_id) { - H5P_genplist_t *plist; /* Property list pointer */ - H5G_loc_t loc; /* Location to create group */ - H5G_t *grp = NULL; /* New group created */ - hid_t lcpl_id; - hid_t ret_value; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(gcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* get creation properties */ - if(H5P_get(plist, H5G_CRT_LCPL_ID_NAME, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for lcpl id") - - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - - /* if name is NULL then this is from H5Gcreate_anon */ - if (name == NULL) { - H5G_obj_create_t gcrt_info; /* Information for group creation */ - /* Set up group creation info */ - gcrt_info.gcpl_id = gcpl_id; - gcrt_info.cache_type = H5G_NOTHING_CACHED; - HDmemset(&gcrt_info.cache, 0, sizeof(gcrt_info.cache)); - - /* Create the new group & get its ID */ - if(NULL == (grp = H5G__create(loc.oloc->file, &gcrt_info, H5AC_dxpl_id))) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") - } - /* otherwise it's from H5Gcreate */ - else { - /* Create the new group & get its ID */ - if(NULL == (grp = H5G__create_named(&loc, name, lcpl_id, gcpl_id, gapl_id, H5AC_dxpl_id))) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") - } + /* check arguments */ + if(NULL == H5I_object_verify(attr_id, H5I_ATTR)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") + /* Decrement references to that atom (and close it) */ + if(H5I_dec_app_ref(attr_id) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "can't close attribute") done: - if (name == NULL) { - /* Release the group's object header, if it was created */ - if(grp) { - H5O_loc_t *oloc; /* Object location for group */ - - /* Get the new group's object location */ - if(NULL == (oloc = H5G_oloc(grp))) - HDONE_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to get object location of group") - - /* Decrement refcount on group's object header in memory */ - if(H5O_dec_rc_by_loc(oloc, H5AC_dxpl_id) < 0) - HDONE_ERROR(H5E_SYM, H5E_CANTDEC, FAIL, "unable to decrement refcount on newly created object") - } /* end if */ - } - - if(ret_value < 0) - if(grp && H5G_close(grp) < 0) - HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "unable to release group") - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_group_create() */ +} /* end H5VL_native_attr_close() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_group_open + * Function: H5VL_native_datatype_commit * - * Purpose: Opens a group inside a native h5 file. + * Purpose: Commits a datatype inside a native h5 file. * - * Return: Success: group id. + * Return: Success: datatype id. * Failure: NULL * * Programmer: Mohamad Chaarawi - * January, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ -static hid_t -H5VL_native_group_open(hid_t loc_id, const char *name, hid_t gapl_id) +static herr_t +H5VL_native_datatype_commit(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, + hid_t tcpl_id, hid_t tapl_id) { - H5G_loc_t loc; /* Location to open group */ - H5G_t *grp = NULL; /* New group opend */ - hid_t ret_value; + H5G_loc_t loc; /* Location to commit datatype */ + H5T_t *type; /* Datatype for ID */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT if(H5G_loc(loc_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Open the group */ - if((grp = H5G__open_name(&loc, name, gapl_id, H5AC_dxpl_id)) == NULL) - HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") + if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - /* Register an ID for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") + /* Commit the type */ + if(H5T__commit_named(&loc, name, type, lcpl_id, tcpl_id, tapl_id, H5AC_dxpl_id) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype") done: - if(ret_value < 0) - if(grp && H5G_close(grp) < 0) - HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "unable to release group") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_group_open() */ +} /* end H5VL_native_datatype_commit() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_group_close + * Function: H5VL_native_datatype_open * - * Purpose: Closes a group. + * Purpose: Opens a named datatype inside a native h5 file. * - * Return: Success: 0 - * Failure: -1, group not closed. + * Return: Success: datatype id. + * Failure: NULL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -static herr_t -H5VL_native_group_close(hid_t group_id) +static hid_t +H5VL_native_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id) { - herr_t ret_value = SUCCEED; /* Return value */ + H5T_t *type = NULL; /* Datatype opened in file */ + H5G_loc_t loc; /* Group location of object to open */ + H5G_name_t path; /* Datatype group hier. path */ + H5O_loc_t oloc; /* Datatype object location */ + H5O_type_t obj_type; /* Type of object at location */ + H5G_loc_t type_loc; /* Group object for datatype */ + hbool_t obj_found = FALSE; /* Object at 'name' found */ + hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datatype */ + hid_t ret_value = FAIL; FUNC_ENTER_NOAPI_NOINIT - /* Check args */ - if(NULL == H5I_object_verify(group_id,H5I_GROUP)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + + /* Set up datatype location to fill in */ + type_loc.oloc = &oloc; + type_loc.path = &path; + H5G_loc_reset(&type_loc); /* - * Decrement the counter on the group atom. It will be freed if the count - * reaches zero. + * Find the named datatype object header and read the datatype message + * from it. */ - if(H5I_dec_app_ref(group_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close group") + if(H5G_loc_find(&loc, name, &type_loc/*out*/, tapl_id, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "not found") + obj_found = TRUE; -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_group_close() */ + /* Check that the object found is the correct type */ + if(H5O_obj_type(&oloc, &obj_type, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get object type") + if(obj_type != H5O_TYPE_NAMED_DATATYPE) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a named datatype") - -/*------------------------------------------------------------------------- - * Function: H5VL_native_group_get - * - * Purpose: Gets certain data about a file - * - * Return: Success: 0 - * Failure: -1 - * - * Programmer: Mohamad Chaarawi - * February, 2012 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5VL_native_group_get(hid_t obj_id, H5VL_group_get_t get_type, va_list arguments) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT - - switch (get_type) { - /* H5Gget_create_plist */ - case H5VL_GROUP_GET_GCPL: - { - hid_t *new_gcpl_id; - H5G_t *grp = NULL; - - /* Check args */ - if(NULL == (grp = (H5G_t *)H5I_object_verify(obj_id, H5I_GROUP))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") - - new_gcpl_id = va_arg (arguments, hid_t *); - - if((*new_gcpl_id = H5G_get_create_plist(grp)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for group") - break; - } - /* H5Fget_info2 */ - case H5VL_GROUP_GET_INFO: - { - H5G_info_t *grp_info = va_arg (arguments, H5G_info_t *); - H5G_loc_t *obj_loc = va_arg (arguments, H5G_loc_t *); - H5G_loc_t loc; - - if(H5G_loc(obj_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - - if(!H5F_addr_defined(obj_loc->oloc->addr)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") - - /* Retrieve the group's information */ - if(H5G__obj_info(obj_loc->oloc, grp_info, H5AC_ind_dxpl_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve group info") + /* Open it */ + if(NULL == (type = H5T_open(&type_loc, dxpl_id))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to open named datatype") - if(H5G_loc_free(obj_loc) < 0) - HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") - break; - } - default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from group") - } + /* Register the type and return the ID */ + if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register named datatype") done: + if(ret_value < 0) { + if(type != NULL) + H5T_close(type); + else { + if(obj_found && H5F_addr_defined(type_loc.oloc->addr)) + H5G_loc_free(&type_loc); + } /* end else */ + } /* end if */ FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5VL_native_datatype_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_object_open + * Function: H5VL_native_dataset_create * - * Purpose: Opens a object inside a native h5 file. + * Purpose: Creates a dataset inside a native h5 file. * - * Return: Success: object id. + * Return: Success: dataset id. * Failure: NULL * * Programmer: Mohamad Chaarawi @@ -1000,95 +786,157 @@ done: *------------------------------------------------------------------------- */ static hid_t -H5VL_native_object_open(hid_t loc_id, void *location, hid_t lapl_id) +H5VL_native_dataset_create(hid_t loc_id, const char *name, hid_t dcpl_id, hid_t dapl_id) { - H5G_loc_t loc; - H5G_loc_t *obj_loc = (H5G_loc_t *)location; - hid_t ret_value = FAIL; + H5P_genplist_t *plist; /* Property list pointer */ + H5G_loc_t loc; /* Object location to insert dataset into */ + hid_t type_id, space_id, lcpl_id; + H5D_t *dset = NULL; /* New dataset's info */ + const H5S_t *space; /* Dataspace for dataset */ + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* Check args */ + /* Get the plist structure */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + + /* get creation properties */ + if(H5P_get(plist, H5D_CRT_TYPE_ID_NAME, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for datatype id") + if(H5P_get(plist, H5D_CRT_SPACE_ID_NAME, &space_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for space id") + if(H5P_get(plist, H5D_CRT_LCPL_ID_NAME, &lcpl_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for lcpl id") + + /* Check arguments */ if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(!H5F_addr_defined(obj_loc->oloc->addr)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location ID") + if(H5I_DATATYPE != H5I_get_type(type_id)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype ID") + if(NULL == (space = (const H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace ID") - /* Open the object */ - if((ret_value = H5O_open_by_loc(obj_loc, lapl_id, H5AC_dxpl_id, TRUE)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open object") + /* H5Dcreate_anon */ + if (NULL == name) { + /* build and open the new dataset */ + if(NULL == (dset = H5D_create(loc.oloc->file, type_id, space, dcpl_id, dapl_id, H5AC_dxpl_id))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") + /* Register the new dataset to get an ID for it */ + if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register dataset") + } + /* H5Dcreate2 */ + else { + /* Create the new dataset & get its ID */ + if(NULL == (dset = H5D__create_named(&loc, name, type_id, space, lcpl_id, + dcpl_id, dapl_id, H5AC_dxpl_id))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") + if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register dataset") + } done: + if(NULL == name) { + /* Release the dataset's object header, if it was created */ + if(dset) { + H5O_loc_t *oloc; /* Object location for dataset */ + + /* Get the new dataset's object location */ + if(NULL == (oloc = H5D_oloc(dset))) + HDONE_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to get object location of dataset") + + /* Decrement refcount on dataset's object header in memory */ + if(H5O_dec_rc_by_loc(oloc, H5AC_dxpl_id) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "unable to decrement refcount on newly created object") + } /* end if */ + } if(ret_value < 0) - if(H5G_loc_free(obj_loc) < 0) - HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") + if(dset && H5D_close(dset) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_object_open() */ +} /* end H5VL_native_dataset_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_object_close + * Function: H5VL_native_dataset_open * - * Purpose: Closes a object. + * Purpose: Opens a dataset inside a native h5 file. * - * Return: Success: 0 - * Failure: -1, object not closed. + * Return: Success: dataset id. + * Failure: NULL * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -static herr_t -H5VL_native_object_close(hid_t object_id) +static hid_t +H5VL_native_dataset_open(hid_t loc_id, const char *name, hid_t dapl_id) { - herr_t ret_value = SUCCEED; /* Return value */ + H5D_t *dset = NULL; + H5G_loc_t loc; /* Object location of group */ + H5G_loc_t dset_loc; /* Object location of dataset */ + H5G_name_t path; /* Dataset group hier. path */ + H5O_loc_t oloc; /* Dataset object location */ + H5O_type_t obj_type; /* Type of object at location */ + hbool_t loc_found = FALSE; /* Location at 'name' found */ + hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datset */ + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* Get the type of the object and close it in the correct way */ - switch(H5I_get_type(object_id)) { - case H5I_GROUP: - case H5I_DATATYPE: - case H5I_DATASET: - if(H5I_object(object_id) == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") - if(H5I_dec_app_ref(object_id) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") - break; + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - case H5I_UNINIT: - case H5I_BADID: - case H5I_FILE: - case H5I_DATASPACE: - case H5I_ATTR: - case H5I_REFERENCE: - case H5I_VFL: - case H5I_VOL: - case H5I_GENPROP_CLS: - case H5I_GENPROP_LST: - case H5I_ERROR_CLASS: - case H5I_ERROR_MSG: - case H5I_ERROR_STACK: - case H5I_NTYPES: - default: - HGOTO_ERROR(H5E_ARGS, H5E_CANTRELEASE, FAIL, "not a valid file object ID (dataset, group, or datatype)") - break; - } /* end switch */ + /* Set up dataset location to fill in */ + dset_loc.oloc = &oloc; + dset_loc.path = &path; + H5G_loc_reset(&dset_loc); + + /* Find the dataset object */ + if(H5G_loc_find(&loc, name, &dset_loc, dapl_id, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL, "not found") + loc_found = TRUE; + + /* Check that the object found is the correct type */ + if(H5O_obj_type(&oloc, &obj_type, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get object type") + if(obj_type != H5O_TYPE_DATASET) + HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "not a dataset") + + /* Open the dataset */ + if(NULL == (dset = H5D_open(&dset_loc, dapl_id, dxpl_id))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't open dataset") + + /* Register an atom for the dataset */ + if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "can't register dataset atom") done: + if(ret_value < 0) { + if(dset) { + if(H5D_close(dset) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") + } /* end if */ + else { + if(loc_found && H5G_loc_free(&dset_loc) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "can't free location") + } /* end else */ + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_object_close() */ +} /* end H5VL_native_dataset_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_object_get + * Function: H5VL_native_dataset_read * - * Purpose: Gets certain data about a file + * Purpose: Reads raw data from a dataset into a buffer. * * Return: Success: 0 - * Failure: -1 + * Failure: -1, dataset not readd. * * Programmer: Mohamad Chaarawi * March, 2012 @@ -1096,69 +944,65 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5VL_native_object_get(hid_t id, H5VL_object_get_t get_type, va_list arguments) +H5VL_native_dataset_read(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, + hid_t file_space_id, hid_t plist_id, void *buf/*out*/) { - herr_t ret_value = SUCCEED; /* Return value */ - H5G_loc_t loc; /* Location of group */ + H5D_t *dset = NULL; + const H5S_t *mem_space = NULL; + const H5S_t *file_space = NULL; + char fake_char; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - if(H5G_loc(id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - - switch (get_type) { - /* H5Oget_info / H5Oget_info_by_name / H5Oget_info_by_idx */ - case H5VL_OBJECT_GET_INFO: - { - H5O_info_t *obj_info = va_arg (arguments, H5O_info_t *); - H5G_loc_t *obj_loc = va_arg (arguments, H5G_loc_t *); - hbool_t loc_set = FALSE; + /* check arguments */ + if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + if(NULL == dset->oloc.file) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + if(H5S_ALL != mem_space_id) { + if(NULL == (mem_space = (const H5S_t *)H5I_object_verify(mem_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - if(NULL == obj_loc) { - obj_loc = &loc; - } - else { - loc_set = TRUE; - } + /* Check for valid selection */ + if(H5S_SELECT_VALID(mem_space) != TRUE) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") + } /* end if */ + if(H5S_ALL != file_space_id) { + if(NULL == (file_space = (const H5S_t *)H5I_object_verify(file_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - /* Retrieve the object's information */ - if(H5O_get_info(obj_loc->oloc, H5AC_ind_dxpl_id, TRUE, obj_info) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve object info") + /* Check for valid selection */ + if(H5S_SELECT_VALID(file_space) != TRUE) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") + } /* end if */ - if(loc_set && H5G_loc_free(obj_loc) < 0) - HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") - break; - } - /* H5Oget_comment / H5Oget_comment_by_name */ - case H5VL_OBJECT_GET_COMMENT: - { - ssize_t *ret = va_arg (arguments, ssize_t *); - char *comment = va_arg (arguments, char *); - size_t bufsize = va_arg (arguments, size_t); - char *name = va_arg (arguments, char *); - hid_t lapl_id = va_arg (arguments, hid_t); + if(!buf && (NULL == file_space || H5S_GET_SELECT_NPOINTS(file_space) != 0)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") - /* Retrieve the object's comment */ - if((*ret = H5G_loc_get_comment(&loc, name, comment/*out*/, bufsize, - lapl_id, H5AC_ind_dxpl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found") + /* If the buffer is nil, and 0 element is selected, make a fake buffer. + * This is for some MPI package like ChaMPIon on NCSA's tungsten which + * doesn't support this feature. + */ + if(!buf) + buf = &fake_char; + + /* read raw data */ + if(H5D_read(dset, mem_type_id, mem_space, file_space, plist_id, buf/*out*/) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data") - break; - } - default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from object") - } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_object_get() */ +} /* end H5VL_native_dataset_read() */ + /*------------------------------------------------------------------------- - * Function: H5VL_native_object_lookup + * Function: H5VL_native_dataset_write * - * Purpose: Lookup the object location in the file + * Purpose: Writes raw data from a buffer into a dataset. * * Return: Success: 0 - * Failure: -1 + * Failure: -1, dataset not writed. * * Programmer: Mohamad Chaarawi * March, 2012 @@ -1166,711 +1010,993 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_list arguments) +H5VL_native_dataset_write(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, + hid_t file_space_id, hid_t dxpl_id, const void *buf) { - H5G_loc_t loc; - H5G_loc_t *obj_loc; - H5G_name_t obj_path; /* Opened object group hier. path */ - H5G_loc_t **location; - haddr_t obj_addr; - herr_t ret_value = SUCCEED; /* Return value */ + H5D_t *dset = NULL; + const H5S_t *mem_space = NULL; + const H5S_t *file_space = NULL; + char fake_char; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - location = va_arg (arguments, H5G_loc_t **); - *location = (H5G_loc_t *) H5MM_malloc (sizeof (H5G_loc_t)); - - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - - obj_loc = *location; - obj_loc->oloc = (H5O_loc_t *) H5MM_malloc (sizeof (H5O_loc_t));//*location; - obj_loc->path = (H5G_name_t *) H5MM_malloc (sizeof (H5G_name_t));//&obj_path; - H5G_loc_reset(obj_loc); - - switch (lookup_type) { - case H5VL_OBJECT_LOOKUP: - obj_loc->oloc->addr = loc.oloc->addr; - obj_loc->oloc->file = loc.oloc->file; - obj_loc->oloc->holding_file = loc.oloc->holding_file; - obj_loc->path = loc.path; - break; - case H5VL_OBJECT_LOOKUP_BY_NAME: - { - char *name = va_arg (arguments, char *); - hid_t lapl_id = va_arg (arguments, hid_t); - - HDassert(name && *name); - - /* Find the object's location */ - if((ret_value = H5G_loc_find(&loc, name, obj_loc, lapl_id, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found") - break; - } - case H5VL_OBJECT_LOOKUP_BY_IDX: - { - char *group_name = va_arg (arguments, char *); - H5_index_t idx_type = va_arg (arguments, H5_index_t); - H5_iter_order_t order = va_arg (arguments, H5_iter_order_t); - hsize_t n = va_arg (arguments, hsize_t); - hid_t lapl_id = va_arg (arguments, hid_t); - - /* Find the object's location, according to the order in the index */ - if((ret_value = H5G_loc_find_by_idx(&loc, group_name, idx_type, order, n, - obj_loc/*out*/, lapl_id, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "group not found") - break; - } - case H5VL_OBJECT_LOOKUP_BY_ADDR: - { - obj_addr = va_arg (arguments, haddr_t); - obj_loc->oloc->addr = obj_addr; - obj_loc->oloc->file = loc.oloc->file; - obj_loc->oloc->holding_file = loc.oloc->holding_file; - break; - } - case H5VL_OBJECT_LOOKUP_BY_REF: - { - H5R_type_t ref_type = va_arg (arguments, H5R_type_t); - void *_ref = va_arg (arguments, void *); - H5F_t *file = NULL; /* File object */ - - /* Get the file pointer from the entry */ - file = loc.oloc->file; - - HDassert(_ref); - HDassert(ref_type > H5R_BADTYPE || ref_type < H5R_MAXTYPE); - HDassert(file); - - switch(ref_type) { - case H5R_OBJECT: - obj_loc->oloc->addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ - obj_loc->oloc->file = loc.oloc->file; - obj_loc->oloc->holding_file = loc.oloc->holding_file; - break; + /* check arguments */ + if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + if(NULL == dset->oloc.file) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + if(H5S_ALL != mem_space_id) { + if(NULL == (mem_space = (const H5S_t *)H5I_object_verify(mem_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - case H5R_DATASET_REGION: - { - H5HG_t hobjid; /* Heap object ID */ - uint8_t *buf; /* Buffer to store serialized selection in */ - const uint8_t *p; /* Pointer to OID to store */ + /* Check for valid selection */ + if(H5S_SELECT_VALID(mem_space) != TRUE) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") + } /* end if */ + if(H5S_ALL != file_space_id) { + if(NULL == (file_space = (const H5S_t *)H5I_object_verify(file_space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - /* Get the heap ID for the dataset region */ - p = (const uint8_t *)_ref; - H5F_addr_decode(file, &p, &(hobjid.addr)); - INT32DECODE(p, hobjid.idx); + /* Check for valid selection */ + if(H5S_SELECT_VALID(file_space) != TRUE) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") + } /* end if */ - /* Get the dataset region from the heap (allocate inside routine) */ - if(NULL == (buf = (uint8_t *)H5HG_read(file, H5AC_dxpl_id, - &hobjid, NULL, NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL, "Unable to read dataset region information") + if(!buf && (NULL == file_space || H5S_GET_SELECT_NPOINTS(file_space) != 0)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") - /* Get the object oid for the dataset */ - p = buf; - //H5F_addr_decode(file, &p, &(obj_addr)); - H5F_addr_decode(file, &p, &(obj_loc->oloc->addr)); - obj_loc->oloc->file = file; - /* Free the buffer allocated in H5HG_read() */ - H5MM_xfree(buf); - } /* end case */ - break; + /* If the buffer is nil, and 0 element is selected, make a fake buffer. + * This is for some MPI package like ChaMPIon on NCSA's tungsten which + * doesn't support this feature. + */ + if(!buf) + buf = &fake_char; - case H5R_BADTYPE: - case H5R_MAXTYPE: - default: - HDassert("unknown reference type" && 0); - HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") - } /* end switch */ - break; - } - default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't lookup this object") - } /* end switch */ + /* write raw data */ + if(H5D_write(dset, mem_type_id, mem_space, file_space, dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") - //if(H5G_name_free(obj_loc.path) < 0) - //HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to free path") done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_object_lookup() */ +} /* end H5VL_native_dataset_write() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_datatype_commit + * Function: H5VL_native_dataset_set_extent * - * Purpose: Commits a datatype inside a native h5 file. + * Purpose: Set Extent of dataset * - * Return: Success: datatype id. - * Failure: NULL + * Return: Success: 0 + * Failure: -1 * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -static herr_t -H5VL_native_datatype_commit(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, - hid_t tcpl_id, hid_t tapl_id) +static herr_t +H5VL_native_dataset_set_extent(hid_t dset_id, const hsize_t size[]) { - H5G_loc_t loc; /* Location to commit datatype */ - H5T_t *type; /* Datatype for ID */ - herr_t ret_value = SUCCEED; /* Return value */ + H5D_t *dset = NULL; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + /* Check args */ + if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - - /* Commit the type */ - if(H5T__commit_named(&loc, name, type, lcpl_id, tcpl_id, tapl_id, H5AC_dxpl_id) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype") + /* Private function */ + if(H5D_set_extent(dset, size, H5AC_dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to set extend dataset") done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_dataset_set_extent() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_dataset_get + * + * Purpose: Gets certain information about a dataset + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_dataset_get(hid_t id, H5VL_dataset_get_t get_type, va_list arguments) +{ + H5D_t *dset = NULL; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Check args */ + if(NULL == (dset = (H5D_t *)H5I_object_verify(id, H5I_DATASET))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + + switch (get_type) { + /* H5Dget_space */ + case H5VL_DATASET_GET_SPACE: + { + hid_t *ret_id = va_arg (arguments, hid_t *); + + if((*ret_id = H5D_get_space(dset)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get space ID of dataset") + + break; + } + /* H5Dget_space_statuc */ + case H5VL_DATASET_GET_SPACE_STATUS: + { + H5D_space_status_t *allocation = va_arg (arguments, H5D_space_status_t *); + + /* Read data space address and return */ + if(FAIL==(ret_value=H5D_get_space_status(dset, allocation, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to get space status") + + break; + } + /* H5Dget_type */ + case H5VL_DATASET_GET_TYPE: + { + hid_t *ret_id = va_arg (arguments, hid_t *); + + if((*ret_id = H5D_get_type(dset)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get datatype ID of dataset") + + break; + } + /* H5Dget_create_plist */ + case H5VL_DATASET_GET_DCPL: + { + hid_t *ret_id = va_arg (arguments, hid_t *); + + if((*ret_id = H5D_get_create_plist(dset)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for dataset") + + break; + } + /* H5Dget_access_plist */ + case H5VL_DATASET_GET_DAPL: + { + hid_t *ret_id = va_arg (arguments, hid_t *); + + if((*ret_id = H5D_get_access_plist(dset)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get access property list for dataset") + + break; + } + /* H5Dget_storage_size */ + case H5VL_DATASET_GET_STORAGE_SIZE: + { + hsize_t *ret = va_arg (arguments, hsize_t *); + + /* Set return value */ + *ret = H5D_get_storage_size(dset, H5AC_ind_dxpl_id); + break; + } + /* H5Dget_offset */ + case H5VL_DATASET_GET_OFFSET: + { + haddr_t *ret = va_arg (arguments, haddr_t *); + + /* Set return value */ + *ret = H5D_get_offset(dset); + break; + } + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from dataset") + } +done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_datatype_commit() */ +} /* end H5VL_native_dataset_get() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_datatype_open + * Function: H5VL_native_dataset_close * - * Purpose: Opens a named datatype inside a native h5 file. + * Purpose: Closes a dataset. * - * Return: Success: datatype id. - * Failure: NULL + * Return: Success: 0 + * Failure: -1, dataset not closed. * * Programmer: Mohamad Chaarawi * March, 2012 * *------------------------------------------------------------------------- */ -static hid_t -H5VL_native_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id) +static herr_t +H5VL_native_dataset_close(hid_t dset_id) { - H5T_t *type = NULL; /* Datatype opened in file */ - H5G_loc_t loc; /* Group location of object to open */ - H5G_name_t path; /* Datatype group hier. path */ - H5O_loc_t oloc; /* Datatype object location */ - H5O_type_t obj_type; /* Type of object at location */ - H5G_loc_t type_loc; /* Group object for datatype */ - hbool_t obj_found = FALSE; /* Object at 'name' found */ - hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datatype */ - hid_t ret_value = FAIL; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + /* Check args */ + if(NULL == H5I_object_verify(dset_id, H5I_DATASET)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - /* Set up datatype location to fill in */ - type_loc.oloc = &oloc; - type_loc.path = &path; - H5G_loc_reset(&type_loc); + /* + * Decrement the counter on the dataset. It will be freed if the count + * reaches zero. + * + * Pass in TRUE for the 3rd parameter to tell the function to remove + * dataset's ID even though the freeing function might fail. Please + * see the comments in H5I_dec_ref for details. (SLU - 2010/9/7) + */ + if(H5I_dec_app_ref_always_close(dset_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "can't decrement count on dataset ID") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_dataset_close() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_file_create + * + * Purpose: Creates a file as a native HDF5 file. + * + * Return: Success: the file id. + * Failure: NULL + * + * Programmer: Mohamad Chaarawi + * January, 2012 + * + *------------------------------------------------------------------------- + */ +static hid_t +H5VL_native_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id) +{ + H5F_t *new_file; /* file struct */ + hid_t ret_value; + + FUNC_ENTER_NOAPI_NOINIT /* - * Find the named datatype object header and read the datatype message - * from it. + * Adjust bit flags by turning on the creation bit and making sure that + * the EXCL or TRUNC bit is set. All newly-created files are opened for + * reading and writing. */ - if(H5G_loc_find(&loc, name, &type_loc/*out*/, tapl_id, dxpl_id) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "not found") - obj_found = TRUE; + if (0==(flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC))) + flags |= H5F_ACC_EXCL; /*default*/ + flags |= H5F_ACC_RDWR | H5F_ACC_CREAT; - /* Check that the object found is the correct type */ - if(H5O_obj_type(&oloc, &obj_type, dxpl_id) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get object type") - if(obj_type != H5O_TYPE_NAMED_DATATYPE) - HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a named datatype") + /* Create the file */ + if(NULL == (new_file = H5F_open(name, flags, fcpl_id, fapl_id, H5AC_dxpl_id))) + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to create file") - /* Open it */ - if(NULL == (type = H5T_open(&type_loc, dxpl_id))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to open named datatype") + /* Get an atom for the file */ + if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") - /* Register the type and return the ID */ - if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register named datatype") + /* store a pointer to the VOL class in the file structure */ + new_file->vol_cls = &H5VL_native_g; + + /* Keep this ID in file object structure */ + new_file->file_id = ret_value; done: - if(ret_value < 0) { - if(type != NULL) - H5T_close(type); - else { - if(obj_found && H5F_addr_defined(type_loc.oloc->addr)) - H5G_loc_free(&type_loc); - } /* end else */ - } /* end if */ + if(ret_value < 0 && new_file && H5F_try_close(new_file) < 0) + HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "problems closing file") + FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_datatype_open() */ +} /* end H5VL_native_file_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_create + * Function: H5VL_native_file_open * - * Purpose: Creates a dataset inside a native h5 file. + * Purpose: Opens a file as a native HDF5 file. * - * Return: Success: dataset id. + * Return: Success: file id. * Failure: NULL * * Programmer: Mohamad Chaarawi - * March, 2012 + * January, 2012 * *------------------------------------------------------------------------- */ static hid_t -H5VL_native_dataset_create(hid_t loc_id, const char *name, hid_t dcpl_id, hid_t dapl_id) +H5VL_native_file_open(const char *name, unsigned flags, hid_t fapl_id) { - H5P_genplist_t *plist; /* Property list pointer */ - H5G_loc_t loc; /* Object location to insert dataset into */ - hid_t type_id, space_id, lcpl_id; - H5D_t *dset = NULL; /* New dataset's info */ - const H5S_t *space; /* Dataspace for dataset */ - hid_t ret_value; + H5F_t *new_file; /* file struct */ + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + /* Open the file */ + if(NULL == (new_file = H5F_open(name, flags, H5P_FILE_CREATE_DEFAULT, fapl_id, H5AC_dxpl_id))) + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to open file") - /* get creation properties */ - if(H5P_get(plist, H5D_CRT_TYPE_ID_NAME, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for datatype id") - if(H5P_get(plist, H5D_CRT_SPACE_ID_NAME, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for space id") - if(H5P_get(plist, H5D_CRT_LCPL_ID_NAME, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for lcpl id") + /* Get an atom for the file */ + if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") - /* Check arguments */ - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location ID") - if(H5I_DATATYPE != H5I_get_type(type_id)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype ID") - if(NULL == (space = (const H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace ID") + /* store a pointer to the VOL class in the file structure */ + new_file->vol_cls = &H5VL_native_g; - /* H5Dcreate_anon */ - if (NULL == name) { - /* build and open the new dataset */ - if(NULL == (dset = H5D_create(loc.oloc->file, type_id, space, dcpl_id, dapl_id, H5AC_dxpl_id))) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") + /* Keep this ID in file object structure */ + new_file->file_id = ret_value; - /* Register the new dataset to get an ID for it */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register dataset") - } - /* H5Dcreate2 */ - else { - /* Create the new dataset & get its ID */ - if(NULL == (dset = H5D__create_named(&loc, name, type_id, space, lcpl_id, - dcpl_id, dapl_id, H5AC_dxpl_id))) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register dataset") - } done: - if(NULL == name) { - /* Release the dataset's object header, if it was created */ - if(dset) { - H5O_loc_t *oloc; /* Object location for dataset */ + if(ret_value < 0 && new_file && H5F_try_close(new_file) < 0) + HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "problems closing file") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_file_open() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_file_flush + * + * Purpose: Flushs a native HDF5 file. + * + * Return: Success: 0 + * Failure: -1, file not flushed. + * + * Programmer: Mohamad Chaarawi + * February, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_file_flush(hid_t object_id, H5F_scope_t scope) +{ + H5F_t *f = NULL; /* File to flush */ + H5O_loc_t *oloc = NULL; /* Object location for ID */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + switch(H5I_get_type(object_id)) { + case H5I_FILE: + if(NULL == (f = (H5F_t *)H5I_object(object_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + break; + case H5I_GROUP: + { + H5G_t *grp; + + if(NULL == (grp = (H5G_t *)H5I_object(object_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid group identifier") + oloc = H5G_oloc(grp); + break; + } + case H5I_DATATYPE: + { + H5T_t *type; + + if(NULL == (type = (H5T_t *)H5I_object(object_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid type identifier") + oloc = H5T_oloc(type); + break; + } + case H5I_DATASET: + { + H5D_t *dset; + + if(NULL == (dset = (H5D_t *)H5I_object(object_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier") + oloc = H5D_oloc(dset); + break; + } + + case H5I_ATTR: + { + H5A_t *attr; + + if(NULL == (attr = (H5A_t *)H5I_object(object_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid attribute identifier") + oloc = H5A_oloc(attr); + break; + } + case H5I_UNINIT: + case H5I_BADID: + case H5I_DATASPACE: + case H5I_REFERENCE: + case H5I_VFL: + case H5I_VOL: + case H5I_GENPROP_CLS: + case H5I_GENPROP_LST: + case H5I_ERROR_CLASS: + case H5I_ERROR_MSG: + case H5I_ERROR_STACK: + case H5I_NTYPES: + default: + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + } /* end switch */ + + if(!f) { + if(!oloc) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "object is not assocated with a file") + f = oloc->file; + } /* end if */ + if(!f) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "object is not associated with a file") + + /* Flush the file */ + /* + * Nothing to do if the file is read only. This determination is + * made at the shared open(2) flags level, implying that opening a + * file twice, once for read-only and once for read-write, and then + * calling H5Fflush() with the read-only handle, still causes data + * to be flushed. + */ + if(H5F_ACC_RDWR & H5F_INTENT(f)) { + /* Flush other files, depending on scope */ + if(H5F_SCOPE_GLOBAL == scope) { + /* Call the flush routine for mounted file hierarchies */ + if(H5F_flush_mounts(f, H5AC_dxpl_id) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush mounted file hierarchy") + } /* end if */ + else { + /* Call the flush routine, for this file */ + if(H5F_flush(f, H5AC_dxpl_id, FALSE) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush file's cached information") + } /* end else */ + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_file_flush() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_file_get + * + * Purpose: Gets certain data about a file + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Mohamad Chaarawi + * February, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_file_get(hid_t obj_id, H5VL_file_get_t get_type, va_list arguments) +{ + H5F_t *f = NULL; /* File struct */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Check/fix arguments. */ + if(H5I_FILE == H5I_get_type(obj_id)) { + if(NULL == (f = (H5F_t *)H5I_object(obj_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file") + } /* end if */ + else { + H5G_loc_t loc; /* Object location */ + /* Get symbol table entry */ + if(H5G_loc(obj_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object ID") + f = loc.oloc->file; + } /* end else */ + + switch (get_type) { + /* H5Fget_access_plist */ + case H5VL_FILE_GET_FAPL: + { + hid_t *plist_id = va_arg (arguments, hid_t *); + + /* Retrieve the file's access property list */ + if((*plist_id = H5F_get_access_plist(f, TRUE)) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get file access property list") + break; + } + /* H5Fget_create_plist */ + case H5VL_FILE_GET_FCPL: + { + H5P_genplist_t *plist; /* Property list */ + hid_t *plist_id = va_arg (arguments, hid_t *); + + if(NULL == (plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") + + /* Create the property list object to return */ + if((*plist_id = H5P_copy_plist(plist, TRUE)) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to copy file creation properties") + + break; + } + /* H5Fget_filesize */ + case H5VL_FILE_GET_SIZE: + { + haddr_t eof; /* End of file address */ + hsize_t *ret = va_arg (arguments, hsize_t *); + + /* Go get the actual file size */ + if(HADDR_UNDEF == (eof = H5FDget_eof(f->shared->lf))) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file size") + *ret = (hsize_t)eof; + break; + } + /* H5Fget_freespace */ + case H5VL_FILE_GET_FREE_SPACE: + { + hsize_t tot_space; /* Amount of free space in the file */ + hssize_t *ret = va_arg (arguments, hssize_t *); + + /* Go get the actual amount of free space in the file */ + if(H5MF_get_freespace(f, H5AC_ind_dxpl_id, &tot_space, NULL) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file") + *ret = (hssize_t)tot_space; + break; + } + case H5VL_FILE_GET_FREE_SECTIONS: + { + H5F_sect_info_t *sect_info = va_arg (arguments, H5F_sect_info_t *); + ssize_t *ret = va_arg (arguments, ssize_t *); + H5F_mem_t type = va_arg (arguments, H5F_mem_t); + size_t nsects = va_arg (arguments, size_t); + + /* Go get the free-space section information in the file */ + if((*ret = H5MF_get_free_sections(f, H5AC_ind_dxpl_id, + type, nsects, sect_info)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file") + break; + } + /* H5Fget_info2 */ + case H5VL_FILE_GET_INFO: + { + H5F_info2_t *finfo = va_arg (arguments, H5F_info2_t *); + + /* For file IDs, get the file object directly */ + /* (This prevents the H5G_loc() call from returning the file pointer for + * the top file in a mount hierarchy) + */ + HDassert(f->shared); - /* Get the new dataset's object location */ - if(NULL == (oloc = H5D_oloc(dset))) - HDONE_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to get object location of dataset") + /* Reset file info struct */ + HDmemset(finfo, 0, sizeof(*finfo)); - /* Decrement refcount on dataset's object header in memory */ - if(H5O_dec_rc_by_loc(oloc, H5AC_dxpl_id) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "unable to decrement refcount on newly created object") - } /* end if */ - } - if(ret_value < 0) - if(dset && H5D_close(dset) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") + /* Get the size of the superblock and any superblock extensions */ + if(H5F_super_size(f, H5AC_ind_dxpl_id, &finfo->super.super_size, + &finfo->super.super_ext_size) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve superblock sizes") - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_create() */ + /* Get the size of any persistent free space */ + if(H5MF_get_freespace(f, H5AC_ind_dxpl_id, &finfo->free.tot_space, + &finfo->free.meta_size) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve free space information") - -/*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_open - * - * Purpose: Opens a dataset inside a native h5 file. - * - * Return: Success: dataset id. - * Failure: NULL - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -static hid_t -H5VL_native_dataset_open(hid_t loc_id, const char *name, hid_t dapl_id) -{ - H5D_t *dset = NULL; - H5G_loc_t loc; /* Object location of group */ - H5G_loc_t dset_loc; /* Object location of dataset */ - H5G_name_t path; /* Dataset group hier. path */ - H5O_loc_t oloc; /* Dataset object location */ - H5O_type_t obj_type; /* Type of object at location */ - hbool_t loc_found = FALSE; /* Location at 'name' found */ - hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datset */ - hid_t ret_value; + /* Check for SOHM info */ + if(H5F_addr_defined(f->shared->sohm_addr)) + if(H5SM_ih_size(f, H5AC_ind_dxpl_id, &finfo->sohm.hdr_size, &finfo->sohm.msgs_info) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve SOHM index & heap storage info") - FUNC_ENTER_NOAPI_NOINIT + /* Set version # fields */ + finfo->super.version = f->shared->sblock->super_vers; + finfo->sohm.version = f->shared->sohm_vers; + finfo->free.version = HDF5_FREESPACE_VERSION; + break; + } + /* H5Fget_intent */ + case H5VL_FILE_GET_INTENT: + { + unsigned *ret = va_arg (arguments, unsigned *); - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + /* HDF5 uses some flags internally that users don't know about. + * Simplify things for them so that they only get either H5F_ACC_RDWR + * or H5F_ACC_RDONLY. + */ + if(H5F_INTENT(f) & H5F_ACC_RDWR) + *ret = H5F_ACC_RDWR; + else + *ret = H5F_ACC_RDONLY; + break; + } + /* H5Fget_name */ + case H5VL_FILE_GET_NAME: + { + char *name = va_arg (arguments, char *); + ssize_t *ret = va_arg (arguments, ssize_t *); + size_t size = va_arg (arguments, size_t); + size_t len; - /* Set up dataset location to fill in */ - dset_loc.oloc = &oloc; - dset_loc.path = &path; - H5G_loc_reset(&dset_loc); + len = HDstrlen(H5F_OPEN_NAME(f)); - /* Find the dataset object */ - if(H5G_loc_find(&loc, name, &dset_loc, dapl_id, dxpl_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL, "not found") - loc_found = TRUE; + if(name) { + HDstrncpy(name, H5F_OPEN_NAME(f), MIN(len + 1,size)); + if(len >= size) + name[size-1]='\0'; + } /* end if */ - /* Check that the object found is the correct type */ - if(H5O_obj_type(&oloc, &obj_type, dxpl_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get object type") - if(obj_type != H5O_TYPE_DATASET) - HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "not a dataset") + /* Set the return value for the API call */ + *ret = (ssize_t)len; + break; + } + /* H5Fget_mdc_config */ + case H5VL_FILE_GET_MDC_CONF: + { + H5AC_cache_config_t *config_ptr = va_arg (arguments, H5AC_cache_config_t *); - /* Open the dataset */ - if(NULL == (dset = H5D_open(&dset_loc, dapl_id, dxpl_id))) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't open dataset") + /* Go get the resize configuration */ + if(H5AC_get_cache_auto_resize_config(f->shared->cache, config_ptr) < 0) + HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_auto_resize_config() failed.") + break; + } + /* H5Fget_mdc_hit_rate */ + case H5VL_FILE_GET_MDC_HR: + { + double *hit_rate_ptr = va_arg (arguments, double *); - /* Register an atom for the dataset */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "can't register dataset atom") + /* Go get the current hit rate */ + if(H5AC_get_cache_hit_rate(f->shared->cache, hit_rate_ptr) < 0) + HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_hit_rate() failed.") + break; + } + /* H5Fget_mdc_size */ + case H5VL_FILE_GET_MDC_SIZE: + { + size_t *max_size_ptr = va_arg (arguments, size_t *); + size_t *min_clean_size_ptr = va_arg (arguments, size_t *); + size_t *cur_size_ptr = va_arg (arguments, size_t *); + int *cur_num_entries_ptr = va_arg (arguments, int *); + int32_t cur_num_entries; -done: - if(ret_value < 0) { - if(dset) { - if(H5D_close(dset) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") - } /* end if */ - else { - if(loc_found && H5G_loc_free(&dset_loc) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "can't free location") - } /* end else */ - } /* end if */ + /* Go get the size data */ + if(H5AC_get_cache_size(f->shared->cache, max_size_ptr, min_clean_size_ptr, + cur_size_ptr, &cur_num_entries) < 0) + HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_size() failed.") + if(cur_num_entries_ptr != NULL) + *cur_num_entries_ptr = (int)cur_num_entries; + break; + } + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information") + } /* end switch */ +done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_open() */ +} /* end H5VL_native_file_get() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_close + * Function: H5VL_native_file_generic * - * Purpose: Closes a dataset. + * Purpose: Perform a plugin specific operation on a native file * * Return: Success: 0 - * Failure: -1, dataset not closed. + * Failure: -1 * * Programmer: Mohamad Chaarawi - * March, 2012 + * April, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_dataset_close(hid_t dset_id) +H5VL_native_file_generic(hid_t loc_id, H5VL_file_generic_t generic_type, va_list arguments) { - herr_t ret_value = SUCCEED; /* Return value */ + H5F_t *file = NULL; /* File */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* Check args */ - if(NULL == H5I_object_verify(dset_id, H5I_DATASET)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + switch (generic_type) { + /* H5Fget_vfd_handle */ + case H5VL_FILE_GET_VFD_HANDLE: + { + void **file_handle = va_arg (arguments, void **); + hid_t fapl = va_arg (arguments, hid_t); - /* - * Decrement the counter on the dataset. It will be freed if the count - * reaches zero. - * - * Pass in TRUE for the 3rd parameter to tell the function to remove - * dataset's ID even though the freeing function might fail. Please - * see the comments in H5I_dec_ref for details. (SLU - 2010/9/7) - */ - if(H5I_dec_app_ref_always_close(dset_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "can't decrement count on dataset ID") + /* Get the file */ + if(NULL == (file = (H5F_t *)H5I_object_verify(loc_id, H5I_FILE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file id") + + /* Retrieve the VFD handle for the file */ + if(H5F_get_vfd_handle(file, fapl, file_handle) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve VFD handle") + break; + } + /* H5Fis_hdf5 */ + case H5VL_FILE_IS_HDF5: + { + htri_t *ret = va_arg (arguments, htri_t *); + const char *name = va_arg (arguments, const char *); + + if((*ret = H5F_is_hdf5(name)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't determine if file is an HDF5 file") + break; + } + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't recognize this operation type") + } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_close() */ +} /* end H5VL_native_file_generic() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_read + * Function: H5VL_native_file_close * - * Purpose: Reads raw data from a dataset into a buffer. + * Purpose: Closes a file. * * Return: Success: 0 - * Failure: -1, dataset not readd. + * Failure: -1, file not closed. * * Programmer: Mohamad Chaarawi - * March, 2012 + * January, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_dataset_read(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, - hid_t file_space_id, hid_t plist_id, void *buf/*out*/) +H5VL_native_file_close(hid_t file_id) { - H5D_t *dset = NULL; - const H5S_t *mem_space = NULL; - const H5S_t *file_space = NULL; - char fake_char; - herr_t ret_value = SUCCEED; /* Return value */ + int nref; + H5F_t *f; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* check arguments */ - if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if(NULL == dset->oloc.file) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if(H5S_ALL != mem_space_id) { - if(NULL == (mem_space = (const H5S_t *)H5I_object_verify(mem_space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") + /* Check/fix arguments. */ + if(H5I_FILE != H5I_get_type(file_id)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file ID") - /* Check for valid selection */ - if(H5S_SELECT_VALID(mem_space) != TRUE) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") - } /* end if */ - if(H5S_ALL != file_space_id) { - if(NULL == (file_space = (const H5S_t *)H5I_object_verify(file_space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") + /* get the file struct */ + if(NULL == (f = (H5F_t *)H5I_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") - /* Check for valid selection */ - if(H5S_SELECT_VALID(file_space) != TRUE) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") + /* Flush file if this is the last reference to this id and we have write + * intent, unless it will be flushed by the "shared" file being closed. + * This is only necessary to replicate previous behaviour, and could be + * disabled by an option/property to improve performance. */ + if((f->shared->nrefs > 1) && (H5F_INTENT(f) & H5F_ACC_RDWR)) { + if((nref = H5I_get_ref(f->file_id, FALSE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't get ID ref count") + if(nref == 1) + if(H5F_flush(f, H5AC_dxpl_id, FALSE) < 0) + HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush cache") } /* end if */ - if(!buf && (NULL == file_space || H5S_GET_SELECT_NPOINTS(file_space) != 0)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") - - /* If the buffer is nil, and 0 element is selected, make a fake buffer. - * This is for some MPI package like ChaMPIon on NCSA's tungsten which - * doesn't support this feature. + /* + * Decrement reference count on atom. When it reaches zero the file will + * be closed. */ - if(!buf) - buf = &fake_char; - - /* read raw data */ - if(H5D_read(dset, mem_type_id, mem_space, file_space, plist_id, buf/*out*/) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data") + if(H5I_dec_ref(f->file_id) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTCLOSEFILE, FAIL, "decrementing file ID failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_read() */ +} /* end H5VL_native_file_close() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_write + * Function: H5VL_native_group_create * - * Purpose: Writes raw data from a buffer into a dataset. + * Purpose: Creates a group inside a native h5 file. * - * Return: Success: 0 - * Failure: -1, dataset not writed. + * Return: Success: group id. + * Failure: NULL * * Programmer: Mohamad Chaarawi - * March, 2012 + * January, 2012 * *------------------------------------------------------------------------- */ -static herr_t -H5VL_native_dataset_write(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, - hid_t file_space_id, hid_t dxpl_id, const void *buf) +static hid_t +H5VL_native_group_create(hid_t loc_id, const char *name, hid_t gcpl_id, hid_t gapl_id) { - H5D_t *dset = NULL; - const H5S_t *mem_space = NULL; - const H5S_t *file_space = NULL; - char fake_char; - herr_t ret_value = SUCCEED; /* Return value */ + H5P_genplist_t *plist; /* Property list pointer */ + H5G_loc_t loc; /* Location to create group */ + H5G_t *grp = NULL; /* New group created */ + hid_t lcpl_id; + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* check arguments */ - if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if(NULL == dset->oloc.file) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - if(H5S_ALL != mem_space_id) { - if(NULL == (mem_space = (const H5S_t *)H5I_object_verify(mem_space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") + /* Get the plist structure */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(gcpl_id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - /* Check for valid selection */ - if(H5S_SELECT_VALID(mem_space) != TRUE) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") - } /* end if */ - if(H5S_ALL != file_space_id) { - if(NULL == (file_space = (const H5S_t *)H5I_object_verify(file_space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") + /* get creation properties */ + if(H5P_get(plist, H5G_CRT_LCPL_ID_NAME, &lcpl_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for lcpl id") - /* Check for valid selection */ - if(H5S_SELECT_VALID(file_space) != TRUE) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "selection+offset not within extent") - } /* end if */ + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(!buf && (NULL == file_space || H5S_GET_SELECT_NPOINTS(file_space) != 0)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") + /* if name is NULL then this is from H5Gcreate_anon */ + if (name == NULL) { + H5G_obj_create_t gcrt_info; /* Information for group creation */ + /* Set up group creation info */ + gcrt_info.gcpl_id = gcpl_id; + gcrt_info.cache_type = H5G_NOTHING_CACHED; + HDmemset(&gcrt_info.cache, 0, sizeof(gcrt_info.cache)); - /* If the buffer is nil, and 0 element is selected, make a fake buffer. - * This is for some MPI package like ChaMPIon on NCSA's tungsten which - * doesn't support this feature. - */ - if(!buf) - buf = &fake_char; + /* Create the new group & get its ID */ + if(NULL == (grp = H5G__create(loc.oloc->file, &gcrt_info, H5AC_dxpl_id))) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") + } + /* otherwise it's from H5Gcreate */ + else { + /* Create the new group & get its ID */ + if(NULL == (grp = H5G__create_named(&loc, name, lcpl_id, gcpl_id, gapl_id, H5AC_dxpl_id))) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") + } - /* write raw data */ - if(H5D_write(dset, mem_type_id, mem_space, file_space, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") + if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") done: + if (name == NULL) { + /* Release the group's object header, if it was created */ + if(grp) { + H5O_loc_t *oloc; /* Object location for group */ + + /* Get the new group's object location */ + if(NULL == (oloc = H5G_oloc(grp))) + HDONE_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to get object location of group") + + /* Decrement refcount on group's object header in memory */ + if(H5O_dec_rc_by_loc(oloc, H5AC_dxpl_id) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTDEC, FAIL, "unable to decrement refcount on newly created object") + } /* end if */ + } + + if(ret_value < 0) + if(grp && H5G_close(grp) < 0) + HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "unable to release group") + FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_write() */ +} /* end H5VL_native_group_create() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_set_extent + * Function: H5VL_native_group_open * - * Purpose: Set Extent of dataset + * Purpose: Opens a group inside a native h5 file. * - * Return: Success: 0 - * Failure: -1 + * Return: Success: group id. + * Failure: NULL * * Programmer: Mohamad Chaarawi - * March, 2012 + * January, 2012 * *------------------------------------------------------------------------- */ -static herr_t -H5VL_native_dataset_set_extent(hid_t dset_id, const hsize_t size[]) +static hid_t +H5VL_native_group_open(hid_t loc_id, const char *name, hid_t gapl_id) { - H5D_t *dset = NULL; - herr_t ret_value = SUCCEED; /* Return value */ + H5G_loc_t loc; /* Location to open group */ + H5G_t *grp = NULL; /* New group opend */ + hid_t ret_value; FUNC_ENTER_NOAPI_NOINIT - /* Check args */ - if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Private function */ - if(H5D_set_extent(dset, size, H5AC_dxpl_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to set extend dataset") + /* Open the group */ + if((grp = H5G__open_name(&loc, name, gapl_id, H5AC_dxpl_id)) == NULL) + HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") + + /* Register an ID for the group */ + if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") done: + if(ret_value < 0) + if(grp && H5G_close(grp) < 0) + HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "unable to release group") + FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_set_extent() */ +} /* end H5VL_native_group_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_dataset_get + * Function: H5VL_native_group_get * - * Purpose: Gets certain information about a dataset + * Purpose: Gets certain data about a file * * Return: Success: 0 * Failure: -1 * * Programmer: Mohamad Chaarawi - * March, 2012 + * February, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_dataset_get(hid_t id, H5VL_dataset_get_t get_type, va_list arguments) +H5VL_native_group_get(hid_t obj_id, H5VL_group_get_t get_type, va_list arguments) { - H5D_t *dset = NULL; - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* Check args */ - if(NULL == (dset = (H5D_t *)H5I_object_verify(id, H5I_DATASET))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") - switch (get_type) { - /* H5Dget_space */ - case H5VL_DATASET_GET_SPACE: - { - hid_t *ret_id = va_arg (arguments, hid_t *); - - if((*ret_id = H5D_get_space(dset)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get space ID of dataset") - - break; - } - /* H5Dget_space_statuc */ - case H5VL_DATASET_GET_SPACE_STATUS: - { - H5D_space_status_t *allocation = va_arg (arguments, H5D_space_status_t *); - - /* Read data space address and return */ - if(FAIL==(ret_value=H5D_get_space_status(dset, allocation, H5AC_ind_dxpl_id))) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to get space status") - - break; - } - /* H5Dget_type */ - case H5VL_DATASET_GET_TYPE: + /* H5Gget_create_plist */ + case H5VL_GROUP_GET_GCPL: { - hid_t *ret_id = va_arg (arguments, hid_t *); - - if((*ret_id = H5D_get_type(dset)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get datatype ID of dataset") + hid_t *new_gcpl_id; + H5G_t *grp = NULL; - break; - } - /* H5Dget_create_plist */ - case H5VL_DATASET_GET_DCPL: - { - hid_t *ret_id = va_arg (arguments, hid_t *); + /* Check args */ + if(NULL == (grp = (H5G_t *)H5I_object_verify(obj_id, H5I_GROUP))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") - if((*ret_id = H5D_get_create_plist(dset)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for dataset") + new_gcpl_id = va_arg (arguments, hid_t *); + if((*new_gcpl_id = H5G_get_create_plist(grp)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for group") break; } - /* H5Dget_access_plist */ - case H5VL_DATASET_GET_DAPL: + /* H5Fget_info2 */ + case H5VL_GROUP_GET_INFO: { - hid_t *ret_id = va_arg (arguments, hid_t *); - - if((*ret_id = H5D_get_access_plist(dset)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get access property list for dataset") + H5G_info_t *grp_info = va_arg (arguments, H5G_info_t *); + H5G_loc_t *obj_loc = va_arg (arguments, H5G_loc_t *); + H5G_loc_t loc; - break; - } - /* H5Dget_storage_size */ - case H5VL_DATASET_GET_STORAGE_SIZE: - { - hsize_t *ret = va_arg (arguments, hsize_t *); + if(H5G_loc(obj_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Set return value */ - *ret = H5D_get_storage_size(dset, H5AC_ind_dxpl_id); - break; - } - /* H5Dget_offset */ - case H5VL_DATASET_GET_OFFSET: - { - haddr_t *ret = va_arg (arguments, haddr_t *); + if(!H5F_addr_defined(obj_loc->oloc->addr)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") - /* Set return value */ - *ret = H5D_get_offset(dset); + /* Retrieve the group's information */ + if(H5G__obj_info(obj_loc->oloc, grp_info, H5AC_ind_dxpl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve group info") + + if(H5G_loc_free(obj_loc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") break; } default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from dataset") + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from group") } done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_dataset_get() */ +} /* end H5VL_native_group_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_group_close + * + * Purpose: Closes a group. + * + * Return: Success: 0 + * Failure: -1, group not closed. + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_group_close(hid_t group_id) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Check args */ + if(NULL == H5I_object_verify(group_id,H5I_GROUP)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") + + /* + * Decrement the counter on the group atom. It will be freed if the count + * reaches zero. + */ + if(H5I_dec_app_ref(group_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close group") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_group_close() */ /*------------------------------------------------------------------------- @@ -2083,11 +2209,11 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_native_attr_create + * Function: H5VL_native_object_open * - * Purpose: Creates an attribute on an object. + * Purpose: Opens a object inside a native h5 file. * - * Return: Success: attr id. + * Return: Success: object id. * Failure: NULL * * Programmer: Mohamad Chaarawi @@ -2096,135 +2222,40 @@ done: *------------------------------------------------------------------------- */ static hid_t -H5VL_native_attr_create(hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t UNUSED aapl_id) +H5VL_native_object_open(hid_t loc_id, void *location, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5P_genplist_t *plist; /* Property list pointer */ - hid_t type_id, space_id; - H5T_t *type; /* Datatype to use for attribute */ - H5S_t *space; /* Dataspace to use for attribute */ - void *location = NULL; - hid_t ret_value; + H5G_loc_t loc; + H5G_loc_t *obj_loc = (H5G_loc_t *)location; + hid_t ret_value = FAIL; FUNC_ENTER_NOAPI_NOINIT - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(acpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* get creation properties */ - if(H5P_get(plist, H5A_CRT_TYPE_ID_NAME, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for datatype id") - if(H5P_get(plist, H5A_CRT_SPACE_ID_NAME, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for space id") - if(H5P_get(plist, H5A_CRT_LOCATION_NAME, &location) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for lcpl id") - + /* Check args */ if(H5G_loc(loc_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file") - if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a type") - if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - - if(NULL == location) { /* H5Acreate */ - /* Go do the real work for attaching the attribute to the dataset */ - if((ret_value = H5A_create(&loc, attr_name, type, space, acpl_id, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute") - } - else { /* H5Acreate_by_name */ - H5G_name_t obj_path; /* Opened object group hier. path */ - H5G_loc_t *obj_loc = (H5G_loc_t *)location; - /* Set up opened group location to fill in */ - //obj_loc.oloc = oloc;; - //obj_loc.path = &obj_path; - //H5G_name_reset(obj_loc.path); - /* Go do the real work for attaching the attribute to the dataset */ - if((ret_value = H5A_create(obj_loc, attr_name, type, space, acpl_id, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute") + if(!H5F_addr_defined(obj_loc->oloc->addr)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") - if(H5G_loc_free(obj_loc) < 0) - HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") - } + /* Open the object */ + if((ret_value = H5O_open_by_loc(obj_loc, lapl_id, H5AC_dxpl_id, TRUE)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open object") done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_attr_create() */ - - -/*------------------------------------------------------------------------- - * Function: H5VL_native_attr_open - * - * Purpose: Opens a attr inside a native h5 file. - * - * Return: Success: attr id. - * Failure: NULL - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -static hid_t -H5VL_native_attr_open(hid_t loc_id, void *location, const char *attr_name, hid_t UNUSED aapl_id) -{ - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ - hid_t ret_value; - - FUNC_ENTER_NOAPI_NOINIT - - /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute") - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - - if(NULL != location) { /* H5Aopen_by_name */ - H5G_loc_t *obj_loc = (H5G_loc_t *)location; - - /* Read in attribute from object header */ - if(NULL == (attr = H5O_attr_open_by_name(obj_loc->oloc, attr_name, H5AC_ind_dxpl_id))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from object header") - + if(ret_value < 0) if(H5G_loc_free(obj_loc) < 0) HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") - } - else { /* H5Aopen */ - /* Read in attribute from object header */ - if(NULL == (attr = H5O_attr_open_by_name(loc.oloc, attr_name, H5AC_ind_dxpl_id))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from object header for attribute: '%s'", attr_name) - } - - /* Finish initializing attribute */ - if(H5A_open_common(&loc, attr) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to initialize attribute") - - /* Register the attribute and get an ID for it */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") - -done: - /* Cleanup on failure */ - if(ret_value < 0) - if(attr && H5A_close(attr) < 0) - HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") - FUNC_LEAVE_NOAPI(ret_value) - -} /* end H5VL_native_attr_open() */ +} /* end H5VL_native_object_open() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_attr_close + * Function: H5VL_native_object_lookup * - * Purpose: Closes an attribute. + * Purpose: Lookup the object location in the file * * Return: Success: 0 - * Failure: -1, attr not closed. + * Failure: -1 * * Programmer: Mohamad Chaarawi * March, 2012 @@ -2232,99 +2263,135 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5VL_native_attr_close(hid_t attr_id) +H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_list arguments) { - herr_t ret_value = SUCCEED; /* Return value */ + H5G_loc_t loc; + H5G_loc_t *obj_loc; + H5G_loc_t **location; + haddr_t obj_addr; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - /* check arguments */ - if(NULL == H5I_object_verify(attr_id, H5I_ATTR)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + location = va_arg (arguments, H5G_loc_t **); + *location = (H5G_loc_t *) H5MM_malloc (sizeof (H5G_loc_t)); - /* Decrement references to that atom (and close it) */ - if(H5I_dec_app_ref(attr_id) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "can't close attribute") + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_attr_close() */ + obj_loc = *location; + obj_loc->oloc = (H5O_loc_t *) H5MM_malloc (sizeof (H5O_loc_t));//*location; + obj_loc->path = (H5G_name_t *) H5MM_malloc (sizeof (H5G_name_t));//&obj_path; + H5G_loc_reset(obj_loc); - -/*------------------------------------------------------------------------- - * Function: H5VL_native_attr_read - * - * Purpose: Reads in data from attribute. - * - * Non-negative on success/Negative on failure - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5VL_native_attr_read(hid_t attr_id, hid_t dtype_id, void *buf) -{ - H5A_t *attr; /* Attribute object for ID */ - H5T_t *mem_type; /* Memory datatype */ - herr_t ret_value; /* Return value */ + switch (lookup_type) { + case H5VL_OBJECT_LOOKUP: + obj_loc->oloc->addr = loc.oloc->addr; + obj_loc->oloc->file = loc.oloc->file; + obj_loc->oloc->holding_file = loc.oloc->holding_file; + obj_loc->path = loc.path; + break; + case H5VL_OBJECT_LOOKUP_BY_NAME: + { + char *name = va_arg (arguments, char *); + hid_t lapl_id = va_arg (arguments, hid_t); + + HDassert(name && *name); + + /* Find the object's location */ + if((ret_value = H5G_loc_find(&loc, name, obj_loc, lapl_id, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found") + break; + } + case H5VL_OBJECT_LOOKUP_BY_IDX: + { + char *group_name = va_arg (arguments, char *); + H5_index_t idx_type = va_arg (arguments, H5_index_t); + H5_iter_order_t order = va_arg (arguments, H5_iter_order_t); + hsize_t n = va_arg (arguments, hsize_t); + hid_t lapl_id = va_arg (arguments, hid_t); + + /* Find the object's location, according to the order in the index */ + if((ret_value = H5G_loc_find_by_idx(&loc, group_name, idx_type, order, n, + obj_loc/*out*/, lapl_id, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "group not found") + break; + } + case H5VL_OBJECT_LOOKUP_BY_ADDR: + { + obj_addr = va_arg (arguments, haddr_t); + obj_loc->oloc->addr = obj_addr; + obj_loc->oloc->file = loc.oloc->file; + obj_loc->oloc->holding_file = loc.oloc->holding_file; + break; + } + case H5VL_OBJECT_LOOKUP_BY_REF: + { + H5R_type_t ref_type = va_arg (arguments, H5R_type_t); + void *_ref = va_arg (arguments, void *); + H5F_t *file = NULL; /* File object */ - FUNC_ENTER_NOAPI_NOINIT + /* Get the file pointer from the entry */ + file = loc.oloc->file; - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") - if(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + HDassert(_ref); + HDassert(ref_type > H5R_BADTYPE || ref_type < H5R_MAXTYPE); + HDassert(file); - /* Go write the actual data to the attribute */ - if((ret_value = H5A_read(attr, mem_type, buf, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_READERROR, FAIL, "unable to read attribute") + switch(ref_type) { + case H5R_OBJECT: + obj_loc->oloc->addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ + obj_loc->oloc->file = loc.oloc->file; + obj_loc->oloc->holding_file = loc.oloc->holding_file; + break; -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_attr_read() */ + case H5R_DATASET_REGION: + { + H5HG_t hobjid; /* Heap object ID */ + uint8_t *buf; /* Buffer to store serialized selection in */ + const uint8_t *p; /* Pointer to OID to store */ - -/*------------------------------------------------------------------------- - * Function: H5VL_native_attr_write - * - * Purpose: Writes out data to attribute. - * - * Non-negative on success/Negative on failure - * - * Programmer: Mohamad Chaarawi - * March, 2012 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5VL_native_attr_write(hid_t attr_id, hid_t dtype_id, const void *buf) -{ - H5A_t *attr; /* Attribute object for ID */ - H5T_t *mem_type; /* Memory datatype */ - herr_t ret_value; /* Return value */ + /* Get the heap ID for the dataset region */ + p = (const uint8_t *)_ref; + H5F_addr_decode(file, &p, &(hobjid.addr)); + INT32DECODE(p, hobjid.idx); - FUNC_ENTER_NOAPI_NOINIT + /* Get the dataset region from the heap (allocate inside routine) */ + if(NULL == (buf = (uint8_t *)H5HG_read(file, H5AC_dxpl_id, + &hobjid, NULL, NULL))) + HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL, "Unable to read dataset region information") - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") - if(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + /* Get the object oid for the dataset */ + p = buf; + //H5F_addr_decode(file, &p, &(obj_addr)); + H5F_addr_decode(file, &p, &(obj_loc->oloc->addr)); + obj_loc->oloc->file = file; + /* Free the buffer allocated in H5HG_read() */ + H5MM_xfree(buf); + } /* end case */ + break; - /* Go write the actual data to the attribute */ - if((ret_value = H5A_write(attr, mem_type, buf, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "unable to write attribute") + case H5R_BADTYPE: + case H5R_MAXTYPE: + default: + HDassert("unknown reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") + } /* end switch */ + break; + } + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't lookup this object") + } /* end switch */ done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_attr_write() */ +} /* end H5VL_native_object_lookup() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_attr_get + * Function: H5VL_native_object_get * - * Purpose: Gets certain information about an attribute + * Purpose: Gets certain data about a file * * Return: Success: 0 * Failure: -1 @@ -2335,140 +2402,113 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5VL_native_attr_get(hid_t attr_id, H5VL_attr_get_t get_type, va_list arguments) +H5VL_native_object_get(hid_t id, H5VL_object_get_t get_type, va_list arguments) { - H5A_t *attr; herr_t ret_value = SUCCEED; /* Return value */ + H5G_loc_t loc; /* Location of group */ FUNC_ENTER_NOAPI_NOINIT - /* check arguments */ - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + if(H5G_loc(id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") switch (get_type) { - /* H5Aget_space */ - case H5VL_ATTR_GET_SPACE: - { - hid_t *ret_id = va_arg (arguments, hid_t *); - - if((*ret_id = H5A_get_space(attr)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get space ID of attribute") - break; - } - /* H5Aget_type */ - case H5VL_ATTR_GET_TYPE: - { - hid_t *ret_id = va_arg (arguments, hid_t *); - - if((*ret_id = H5A_get_type(attr)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get datatype ID of attribute") - break; - } - /* H5Aget_create_plist */ - case H5VL_ATTR_GET_ACPL: + /* H5Oget_info / H5Oget_info_by_name / H5Oget_info_by_idx */ + case H5VL_OBJECT_GET_INFO: { - hid_t *ret_id = va_arg (arguments, hid_t *); - - if((*ret_id = H5A_get_create_plist(attr)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for attr") + H5O_info_t *obj_info = va_arg (arguments, H5O_info_t *); + H5G_loc_t *obj_loc = va_arg (arguments, H5G_loc_t *); + hbool_t loc_set = FALSE; - break; - } - /* H5Aget_name */ - case H5VL_ATTR_GET_NAME: - { - ssize_t *ret_val = va_arg (arguments, ssize_t *); - size_t buf_size = va_arg (arguments, size_t); - char *buf = va_arg (arguments, char *); + if(NULL == obj_loc) { + obj_loc = &loc; + } + else { + loc_set = TRUE; + } - /* Call private function in turn */ - if(0 > (*ret_val = H5A_get_name(attr, buf_size, buf))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get attribute name") + /* Retrieve the object's information */ + if(H5O_get_info(obj_loc->oloc, H5AC_ind_dxpl_id, TRUE, obj_info) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve object info") + if(loc_set && H5G_loc_free(obj_loc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") break; } - /* H5Aget_info */ - case H5VL_ATTR_GET_INFO: + /* H5Oget_comment / H5Oget_comment_by_name */ + case H5VL_OBJECT_GET_COMMENT: { - H5A_info_t *ainfo = va_arg (arguments, H5A_info_t *); - - if(H5A_get_info(attr, ainfo) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get attribute info") + ssize_t *ret = va_arg (arguments, ssize_t *); + char *comment = va_arg (arguments, char *); + size_t bufsize = va_arg (arguments, size_t); + char *name = va_arg (arguments, char *); + hid_t lapl_id = va_arg (arguments, hid_t); - break; - } - case H5VL_ATTR_GET_STORAGE_SIZE: - { - hsize_t *ret = va_arg (arguments, hsize_t *); + /* Retrieve the object's comment */ + if((*ret = H5G_loc_get_comment(&loc, name, comment/*out*/, bufsize, + lapl_id, H5AC_ind_dxpl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found") - /* Set return value */ - *ret = attr->shared->data_size; break; } default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from attr") + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from object") } - done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_attr_get() */ +} /* end H5VL_native_object_get() */ /*------------------------------------------------------------------------- - * Function: H5VL_native_attr_generic + * Function: H5VL_native_object_close * - * Purpose: Perform a plugin specific operation for an attribute + * Purpose: Closes a object. * * Return: Success: 0 - * Failure: -1 + * Failure: -1, object not closed. * * Programmer: Mohamad Chaarawi - * April, 2012 + * March, 2012 * *------------------------------------------------------------------------- */ static herr_t -H5VL_native_attr_generic(hid_t loc_id, H5VL_attr_generic_t generic_type, va_list arguments) +H5VL_native_object_close(hid_t object_id) { - H5A_t *attr = NULL; /* Attribute opened */ - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - switch (generic_type) { - /* H5Aopen_by_idx */ - case H5VL_ATTR_OPEN_BY_IDX: - { - hid_t *ret_id = va_arg (arguments, hid_t *); - char *obj_name = va_arg (arguments, char *); - H5_index_t idx_type = va_arg (arguments, H5_index_t); - H5_iter_order_t order = va_arg (arguments, H5_iter_order_t); - hsize_t n = va_arg (arguments, hsize_t); - hid_t aapl_id = va_arg (arguments, hid_t); - hid_t lapl_id = va_arg (arguments, hid_t); - H5G_loc_t loc; /* Object location */ - - if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - - /* Open the attribute in the object header */ - if(NULL == (attr = H5A_open_by_idx(&loc, obj_name, idx_type, order, n, lapl_id, H5AC_ind_dxpl_id))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute") + /* Get the type of the object and close it in the correct way */ + switch(H5I_get_type(object_id)) { + case H5I_GROUP: + case H5I_DATATYPE: + case H5I_DATASET: + if(H5I_object(object_id) == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") + if(H5I_dec_app_ref(object_id) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") + break; - /* Register the attribute and get an ID for it */ - if((*ret_id = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") - break; - } + case H5I_UNINIT: + case H5I_BADID: + case H5I_FILE: + case H5I_DATASPACE: + case H5I_ATTR: + case H5I_REFERENCE: + case H5I_VFL: + case H5I_VOL: + case H5I_GENPROP_CLS: + case H5I_GENPROP_LST: + case H5I_ERROR_CLASS: + case H5I_ERROR_MSG: + case H5I_ERROR_STACK: + case H5I_NTYPES: default: - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't recognize this operation type") - } + HGOTO_ERROR(H5E_ARGS, H5E_CANTRELEASE, FAIL, "not a valid file object ID (dataset, group, or datatype)") + break; + } /* end switch */ done: - /* Cleanup on failure */ - if(H5VL_ATTR_OPEN_BY_IDX == generic_type && ret_value < 0) - if(attr && H5A_close(attr) < 0) - HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_native_attr_generic() */ +} /* end H5VL_native_object_close() */ diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index fc5d7d5..f5b7664 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -55,12 +55,6 @@ H5_DLL hid_t H5VL_register(const void *cls, size_t size, hbool_t app_ref); H5_DLL herr_t H5VL_replace_with_uids(hid_t *oid_list, ssize_t num_ids); H5_DLL int H5VL_inc_ref_uid(hid_t fid, hbool_t app_ref); -H5_DLL hid_t H5VL_file_open(const char *name, unsigned flags, hid_t fapl_id); -H5_DLL hid_t H5VL_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); -H5_DLL herr_t H5VL_file_close(hid_t file_id); -H5_DLL herr_t H5VL_file_flush(hid_t file_id, H5F_scope_t scope); -H5_DLL herr_t H5VL_file_get(hid_t uid, H5VL_file_get_t get_type, ...); - H5_DLL hid_t H5VL_attr_create(hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t aapl_id); H5_DLL hid_t H5VL_attr_open(hid_t loc_id, void *location, const char *name, hid_t aapl_id); H5_DLL herr_t H5VL_attr_read(hid_t attr_id, hid_t dtype_id, void *buf); @@ -80,6 +74,13 @@ H5_DLL herr_t H5VL_dataset_get(hid_t uid, H5VL_dataset_get_t get_type, ...); H5_DLL herr_t H5VL_datatype_commit(hid_t loc_id, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id); H5_DLL hid_t H5VL_datatype_open(hid_t loc_id, const char *name, hid_t tapl_id); +H5_DLL hid_t H5VL_file_open(const char *name, unsigned flags, hid_t fapl_id); +H5_DLL hid_t H5VL_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); +H5_DLL herr_t H5VL_file_close(hid_t file_id); +H5_DLL herr_t H5VL_file_flush(hid_t file_id, H5F_scope_t scope); +H5_DLL herr_t H5VL_file_generic(hid_t loc_id, H5VL_file_generic_t generic_type, ...); +H5_DLL herr_t H5VL_file_get(hid_t uid, H5VL_file_get_t get_type, ...); + H5_DLL hid_t H5VL_group_create(hid_t uid, const char *name, hid_t gcpl_id, hid_t gapl_id); H5_DLL hid_t H5VL_group_open(hid_t uid, const char *name, hid_t gapl_id); H5_DLL herr_t H5VL_group_close(hid_t uid); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index f1d56d3..683b7d7 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -35,13 +35,18 @@ typedef enum H5VL_file_get_t { H5VL_FILE_GET_NAME = 6, /*file name */ H5VL_FILE_GET_OBJ_COUNT = 7, /*object count in file */ H5VL_FILE_GET_OBJ_IDS = 8, /*object ids in file */ - H5VL_FILE_GET_VFD_HANDLE = 9, /*file VFD handle */ - H5VL_FILE_GET_MDC_CONF = 10, /*file metadata cache configuration */ - H5VL_FILE_GET_MDC_HR = 11, /*file metadata cache hit rate */ - H5VL_FILE_GET_MDC_SIZE = 12, /*file metadata cache size */ - H5VL_FILE_GET_FREE_SECTIONS = 13 /*file free selections */ + H5VL_FILE_GET_MDC_CONF = 9, /*file metadata cache configuration */ + H5VL_FILE_GET_MDC_HR = 10, /*file metadata cache hit rate */ + H5VL_FILE_GET_MDC_SIZE = 11, /*file metadata cache size */ + H5VL_FILE_GET_FREE_SECTIONS = 12 /*file free selections */ } H5VL_file_get_t; +/* types for all file general operations */ +typedef enum H5VL_file_generic_t { + H5VL_FILE_GET_VFD_HANDLE = 0, /*file VFD handle */ + H5VL_FILE_IS_HDF5 = 1 /* is HDF5? */ +} H5VL_file_generic_t; + /* types for all attr get API routines */ typedef enum H5VL_attr_get_t { H5VL_ATTR_GET_SPACE = 0, /* dataspace */ @@ -105,28 +110,6 @@ typedef enum H5VL_link_create_type_t { #define H5VL_VOL_DEFAULT 0 /* Default VOL plugin value */ -/* H5F routines */ -typedef struct H5VL_file_class_t { - hid_t (*create)(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); - hid_t (*open) (const char *name, unsigned flags, hid_t fapl_id); - herr_t (*flush) (hid_t file_id, H5F_scope_t scope); - herr_t (*get) (hid_t file_id, H5VL_file_get_t get_type, va_list arguments); - herr_t (*close) (hid_t file_id); -} H5VL_file_class_t; - -/* H5D routines */ -typedef struct H5VL_dataset_class_t { - hid_t (*create)(hid_t loc_id, const char *name, hid_t dcpl_id, hid_t dapl_id); - hid_t (*open) (hid_t loc_id, const char *name, hid_t dapl_id); - herr_t (*read) (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, - hid_t xfer_plist_id, void * buf); - herr_t (*write) (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, - hid_t xfer_plist_id, const void * buf ); - herr_t (*set_extent) (hid_t uid, const hsize_t size[]); - herr_t (*get) (hid_t file_id, H5VL_dataset_get_t get_type, va_list arguments); - herr_t (*close) (hid_t dataset_id); -} H5VL_dataset_class_t; - /* H5A routines */ typedef struct H5VL_attr_class_t { hid_t (*create)(hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t aapl_id); @@ -146,6 +129,37 @@ typedef struct H5VL_datatype_class_t { hid_t (*open) (hid_t loc_id, const char * name, hid_t tapl_id); }H5VL_datatype_class_t; +/* H5D routines */ +typedef struct H5VL_dataset_class_t { + hid_t (*create)(hid_t loc_id, const char *name, hid_t dcpl_id, hid_t dapl_id); + hid_t (*open) (hid_t loc_id, const char *name, hid_t dapl_id); + herr_t (*read) (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, + hid_t xfer_plist_id, void * buf); + herr_t (*write) (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, + hid_t xfer_plist_id, const void * buf ); + herr_t (*set_extent) (hid_t uid, const hsize_t size[]); + herr_t (*get) (hid_t file_id, H5VL_dataset_get_t get_type, va_list arguments); + herr_t (*close) (hid_t dataset_id); +} H5VL_dataset_class_t; + +/* H5F routines */ +typedef struct H5VL_file_class_t { + hid_t (*create)(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); + hid_t (*open) (const char *name, unsigned flags, hid_t fapl_id); + herr_t (*flush) (hid_t file_id, H5F_scope_t scope); + herr_t (*get) (hid_t file_id, H5VL_file_get_t get_type, va_list arguments); + herr_t (*generic)(hid_t loc_id, H5VL_file_generic_t generic_type, va_list arguments); + herr_t (*close) (hid_t file_id); +} H5VL_file_class_t; + +/* H5G routines */ +typedef struct H5VL_group_class_t { + hid_t (*create)(hid_t loc_id, const char *name, hid_t gcpl_id, hid_t gapl_id); + hid_t (*open) (hid_t loc_id, const char *name, hid_t gapl_id); + herr_t (*get) (hid_t file_id, H5VL_group_get_t get_type, va_list arguments); + herr_t (*close) (hid_t group_id); +} H5VL_group_class_t; + /* H5L routines */ typedef struct H5VL_link_class_t { herr_t (*create)(H5VL_link_create_type_t create_type, hid_t link_loc_id, const char *link_name, @@ -156,14 +170,6 @@ typedef struct H5VL_link_class_t { herr_t (*delete)(hid_t loc_id, const char *name, hid_t lapl_id); } H5VL_link_class_t; -/* H5G routines */ -typedef struct H5VL_group_class_t { - hid_t (*create)(hid_t loc_id, const char *name, hid_t gcpl_id, hid_t gapl_id); - hid_t (*open) (hid_t loc_id, const char *name, hid_t gapl_id); - herr_t (*get) (hid_t file_id, H5VL_group_get_t get_type, va_list arguments); - herr_t (*close) (hid_t group_id); -} H5VL_group_class_t; - /* H5O routines */ typedef struct H5VL_object_class_t { hid_t (*open) (hid_t loc_id, void *obj_loc, hid_t lapl_id); @@ -181,11 +187,11 @@ typedef struct H5VL_class_t { const char *name; unsigned nrefs; /* Ref count for times struct is pointed to */ herr_t (*terminate)(void); - H5VL_attr_class_t attr_cls; + H5VL_attr_class_t attr_cls; H5VL_datatype_class_t datatype_cls; H5VL_dataset_class_t dataset_cls; - H5VL_group_class_t group_cls; H5VL_file_class_t file_cls; + H5VL_group_class_t group_cls; H5VL_link_class_t link_cls; H5VL_object_class_t object_cls; } H5VL_class_t; -- cgit v0.12