From 7d7842302b1dcf0da0067b30c49da59b8f766cb3 Mon Sep 17 00:00:00 2001 From: Mohamad Chaarawi Date: Sun, 8 Apr 2012 17:22:37 -0500 Subject: [svn-r22258] links and attributes VOL routines change native location token to be of type H5O_loc_t several bug fixes and issues resolved --- src/H5A.c | 502 ++++++++++++++++++++++++++------------------------ src/H5Adeprec.c | 79 +++----- src/H5Apkg.h | 6 + src/H5Aprivate.h | 5 +- src/H5D.c | 4 +- src/H5Ddeprec.c | 5 +- src/H5L.c | 4 +- src/H5O.c | 81 +++++++-- src/H5Pacpl.c | 50 ++++- src/H5VL.c | 377 ++++++++++++++++++++++++++++++++++++-- src/H5VLnative.c | 536 +++++++++++++++++++++++++++++++++++++++++++++--------- src/H5VLprivate.h | 8 + src/H5VLpublic.h | 33 +++- test/tattr.c | 22 +++ test/th5o.c | 1 + 15 files changed, 1293 insertions(+), 420 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index 725d89a..09e838f 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -36,6 +36,7 @@ #include "H5Opkg.h" /* Object headers */ #include "H5Sprivate.h" /* Dataspace functions */ #include "H5SMprivate.h" /* Shared Object Header Messages */ +#include "H5VLprivate.h" /* VOL plugins */ /****************/ /* Local Macros */ @@ -66,10 +67,6 @@ typedef struct H5A_iter_cb1 { /* Local Prototypes */ /********************/ -static herr_t H5A_open_common(const H5G_loc_t *loc, H5A_t *attr); -static herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id); -static herr_t H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id); - /*********************/ /* Package Variables */ @@ -220,47 +217,39 @@ hid_t H5Acreate2(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t UNUSED aapl_id) { - H5G_loc_t loc; /* Object location */ - H5T_t *type; /* Datatype to use for attribute */ - H5S_t *space; /* Dataspace to use for attribute */ + H5P_genplist_t *plist; /* Property list pointer */ + void *location = NULL; hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE6("i", "i*siiii", loc_id, attr_name, type_id, space_id, acpl_id, aapl_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file") if(!attr_name || !*attr_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name") - 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") - - /* 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") -#if 0 - hid_t ret_value; /* Return value */ - FUNC_ENTER_API(FAIL) - H5TRACE6("i", "i*siiii", loc_id, attr_name, type_id, space_id, acpl_id, aapl_id); + /* Get correct property list */ + if(H5P_DEFAULT == acpl_id) + acpl_id = H5P_ATTRIBUTE_CREATE_DEFAULT; - /* check arguments */ - if(H5I_ATTR_PUBLIC == H5I_get_type(loc_id)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute") - if(!attr_name || !*attr_name) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name") + /* 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") + + /* set creation properties */ + if(H5P_set(plist, H5A_CRT_TYPE_ID_NAME, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") + if(H5P_set(plist, H5A_CRT_SPACE_ID_NAME, &space_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for space id") + if(H5P_set(plist, H5A_CRT_LOCATION_NAME, &location) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for location") /* Create the attribute through the VOL */ - if((ret_value = H5VL_attr_create(loc_id, attr_name, type_id, space_id, acpl_id, aapl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") -#endif + if((ret_value = H5VL_attr_create(loc_id, attr_name, acpl_id, aapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") + done: FUNC_LEAVE_API(ret_value) } /* H5Acreate2() */ @@ -302,13 +291,9 @@ H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t UNUSED aapl_id, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5G_loc_t obj_loc; /* Location used to open group */ - H5G_name_t obj_path; /* Opened object group hier. path */ - H5O_loc_t obj_oloc; /* Opened object object location */ - hbool_t loc_found = FALSE; /* Entry at 'obj_name' found */ - H5T_t *type; /* Datatype to use for attribute */ - H5S_t *space; /* Dataspace to use for attribute */ + H5P_genplist_t *plist; /* Property list pointer */ + void *location = NULL; /* a pointer to VOL specific token that indicates + the location of the object */ hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) @@ -316,50 +301,48 @@ H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, acpl_id, aapl_id, lapl_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file") if(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name") if(!attr_name || !*attr_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name") - 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") - /* Set up opened group location to fill in */ - obj_loc.oloc = &obj_oloc; - obj_loc.path = &obj_path; - H5G_loc_reset(&obj_loc); - /* Find the object's location */ - if(H5G_loc_find(&loc, obj_name, &obj_loc/*out*/, lapl_id, H5AC_ind_dxpl_id) < 0) + /* Find the object's location + if(H5G_loc_find(&loc, obj_name, &obj_loc, lapl_id, H5AC_ind_dxpl_id) < 0) HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "object not found") - loc_found = TRUE; - - /* 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 0 /* Get the token for the Object location through the VOL */ - if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, obj_name, lapl_id) < 0) + if(H5VL_object_lookup(loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, obj_name, lapl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") + /* Get correct property list */ + if(H5P_DEFAULT == acpl_id) + acpl_id = H5P_ATTRIBUTE_CREATE_DEFAULT; + + /* 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") + + /* set creation properties */ + if(H5P_set(plist, H5A_CRT_TYPE_ID_NAME, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") + if(H5P_set(plist, H5A_CRT_SPACE_ID_NAME, &space_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for space id") + if(H5P_set(plist, H5A_CRT_LOCATION_NAME, &location) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for location") + /* Create the attribute through the VOL */ - if((ret_value = H5VL_attr_create(loc_id, attr_name, type_id, space_id, acpl_id, aapl_id)) < 0) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") -#endif + if((ret_value = H5VL_attr_create(loc_id, attr_name, acpl_id, aapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") done: - /* Release resources */ - if(loc_found && H5G_loc_free(&obj_loc) < 0) - HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't free location") - + if (NULL != location) { + free (location); + location = NULL; + } FUNC_LEAVE_API(ret_value) } /* H5Acreate_by_name() */ @@ -553,41 +536,24 @@ done: H5Aclose or resource leaks will develop. --------------------------------------------------------------------------*/ hid_t -H5Aopen(hid_t loc_id, const char *attr_name, hid_t UNUSED aapl_id) +H5Aopen(hid_t loc_id, const char *attr_name, hid_t aapl_id) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ hid_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE3("i", "i*si", loc_id, attr_name, aapl_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!attr_name || !*attr_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name") - /* 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") + /* Open the attribute through the VOL */ + if((ret_value = H5VL_attr_open(loc_id, NULL, attr_name, aapl_id)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to open attribute") 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_API(ret_value) } /* H5Aopen() */ @@ -617,18 +583,16 @@ hid_t H5Aopen_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, hid_t UNUSED aapl_id, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ + void *location = NULL; /* a pointer to VOL specific token that indicates + the location of the object */ hid_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE5("i", "i*s*sii", loc_id, obj_name, attr_name, aapl_id, lapl_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name") if(!attr_name || !*attr_name) @@ -639,20 +603,19 @@ H5Aopen_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") - /* Open the attribute on the object header */ - if(NULL == (attr = H5A_open_by_name(&loc, obj_name, attr_name, lapl_id, H5AC_ind_dxpl_id))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute") + /* Get the token for the Object location through the VOL */ + if(H5VL_object_lookup(loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, obj_name, lapl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") - /* 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") + /* Open the attribute through the VOL */ + if((ret_value = H5VL_attr_open(loc_id, location, attr_name, aapl_id)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to open attribute") 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") - + if (NULL != location) { + free (location); + location = NULL; + } FUNC_LEAVE_API(ret_value) } /* H5Aopen_by_name() */ @@ -685,8 +648,6 @@ hid_t H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t UNUSED aapl_id, hid_t lapl_id) { - H5A_t *attr = NULL; /* Attribute opened */ - H5G_loc_t loc; /* Object location */ hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) @@ -694,10 +655,8 @@ H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, lapl_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name") if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) @@ -710,20 +669,11 @@ H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") - /* 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_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") + if(H5VL_attr_generic(loc_id, H5VL_ATTR_OPEN_BY_IDX, &ret_value, + obj_name, idx_type, order, n, aapl_id, lapl_id) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to open attribute") 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_API(ret_value) } /* H5Aopen_by_idx() */ @@ -746,7 +696,7 @@ done: * *------------------------------------------------------------------------- */ -static herr_t +herr_t H5A_open_common(const H5G_loc_t *loc, H5A_t *attr) { herr_t ret_value = SUCCEED; /* Return value */ @@ -933,24 +883,18 @@ done: herr_t H5Awrite(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 */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "ii*x", attr_id, dtype_id, buf); /* 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(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") if(NULL == buf) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null attribute buffer") - /* 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") + /* write the data through the VOL */ + if((ret_value = H5VL_attr_write(attr_id, dtype_id, buf)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_READERROR, FAIL, "can't read data") done: FUNC_LEAVE_API(ret_value) @@ -973,7 +917,7 @@ done: DESCRIPTION This function writes a complete attribute to disk. --------------------------------------------------------------------------*/ -static herr_t +herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id) { uint8_t *tconv_buf = NULL; /* datatype conv buffer */ @@ -1090,24 +1034,18 @@ done: herr_t H5Aread(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 */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "ii*x", attr_id, dtype_id, buf); /* 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(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") if(NULL == buf) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null attribute buffer") - /* 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") + /* Read the data through the VOL */ + if((ret_value = H5VL_attr_read(attr_id, dtype_id, buf)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_READERROR, FAIL, "can't read data") done: FUNC_LEAVE_API(ret_value) @@ -1130,7 +1068,7 @@ done: DESCRIPTION This function reads a complete attribute from disk. --------------------------------------------------------------------------*/ -static herr_t +herr_t H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id) { uint8_t *tconv_buf = NULL; /* datatype conv buffer*/ @@ -1236,31 +1174,58 @@ done: hid_t H5Aget_space(hid_t attr_id) { - H5A_t *attr; /* Attribute object for ID */ - H5S_t *ds = NULL; /* Copy of dataspace for attribute */ hid_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE1("i", "i", attr_id); - /* check arguments */ - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + /* get the dataspace through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_SPACE, &ret_value) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get data space") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Aget_space() */ + + +/*------------------------------------------------------------------------- + * Function: H5A_get_space + * + * Purpose: Returns and ID for the dataspace of the attribute. + * + * Return: Success: ID for dataspace + * + * Failure: FAIL + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +hid_t +H5A_get_space(H5A_t *attr) +{ + H5S_t *ds = NULL; + hid_t ret_value = FAIL; + + FUNC_ENTER_NOAPI_NOINIT /* Copy the attribute's dataspace */ if(NULL == (ds = H5S_copy(attr->shared->ds, FALSE, TRUE))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to copy dataspace") + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to copy dataspace") /* Atomize */ if((ret_value = H5I_register(H5I_DATASPACE, ds, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom") done: - if(ret_value < 0 && ds) - (void)H5S_close(ds); + if(ret_value < 0 && ds) { + if(H5S_close(ds) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataspace") + } /* end if */ - FUNC_LEAVE_API(ret_value) -} /* H5Aget_space() */ + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5A_get_space() */ /*-------------------------------------------------------------------------- @@ -1282,16 +1247,41 @@ done: hid_t H5Aget_type(hid_t attr_id) { - H5A_t *attr; /* Attribute object for ID */ - H5T_t *dt = NULL; /* Copy of attribute's datatype */ hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE1("i", "i", attr_id); - /* check arguments */ - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + /* get the datatype through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_TYPE, &ret_value) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get type") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Aget_type() */ + + +/*------------------------------------------------------------------------- + * Function: H5A_get_type + * + * Purpose: Returns and ID for the datatype of the dataset. + * + * Return: Success: ID for datatype + * + * Failure: FAIL + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +hid_t +H5A_get_type(H5A_t *attr) +{ + H5T_t *dt = NULL; + hid_t ret_value = FAIL; + + FUNC_ENTER_NOAPI_NOINIT /* Patch the datatype's "top level" file pointer */ if(H5T_patch_file(attr->shared->dt, attr->oloc.file) < 0) @@ -1303,7 +1293,7 @@ H5Aget_type(hid_t attr_id) * read-only. */ if(NULL == (dt = H5T_copy(attr->shared->dt, H5T_COPY_REOPEN))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to copy datatype") + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to copy datatype") /* Mark any datatypes as being in memory now */ if(H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0) @@ -1311,7 +1301,7 @@ H5Aget_type(hid_t attr_id) /* Lock copied type */ if(H5T_lock(dt, FALSE) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to lock transient datatype") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to lock transient datatype") /* Atomize */ if((ret_value = H5I_register(H5I_DATATYPE, dt, TRUE)) < 0) @@ -1320,11 +1310,11 @@ H5Aget_type(hid_t attr_id) done: if(ret_value < 0) { if(dt && H5T_close(dt) < 0) - HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to release datatype") + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release datatype") } /* end if */ - FUNC_LEAVE_API(ret_value) -} /* H5Aget_type() */ + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5A_get_type() */ /*-------------------------------------------------------------------------- @@ -1349,10 +1339,6 @@ done: hid_t H5Aget_create_plist(hid_t attr_id) { - H5A_t *attr; /* Attribute object for ID */ - H5P_genplist_t *plist; /* Default property list */ - hid_t new_plist_id; /* ID of ACPL to return */ - H5P_genplist_t *new_plist; /* ACPL to return */ hid_t ret_value; FUNC_ENTER_API(FAIL) @@ -1360,9 +1346,40 @@ H5Aget_create_plist(hid_t attr_id) HDassert(H5P_LST_ATTRIBUTE_CREATE_g != -1); - /* Get attribute and default attribute creation property list*/ - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") + /* get the acpl through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_ACPL, &ret_value) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get acpl") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Aget_create_plist() */ + + +/*-------------------------------------------------------------------------- + NAME + H5A_get_create_plist + PURPOSE + private version of H5Aget_create_plist + RETURNS + This function returns the ID of a copy of the attribute's creation + property list, or negative on failure. + + ERRORS + + DESCRIPTION + This function returns a copy of the creation property list for + an attribute. The resulting ID must be closed with H5Pclose() or + resource leaks will occur. +--------------------------------------------------------------------------*/ +hid_t +H5A_get_create_plist(H5A_t* attr) +{ + H5P_genplist_t *plist; /* Default property list */ + hid_t new_plist_id; /* ID of ACPL to return */ + H5P_genplist_t *new_plist; /* ACPL to return */ + hid_t ret_value; + FUNC_ENTER_NOAPI_NOINIT + if(NULL == (plist = (H5P_genplist_t *)H5I_object(H5P_LST_ATTRIBUTE_CREATE_g))) HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "can't get default ACPL") @@ -1379,7 +1396,7 @@ H5Aget_create_plist(hid_t attr_id) ret_value = new_plist_id; done: - FUNC_LEAVE_API(ret_value) + FUNC_LEAVE_NOAPI(ret_value) } /* end H5Aget_create_plist() */ @@ -1407,21 +1424,18 @@ done: ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, char *buf) { - H5A_t *my_attr; /* Attribute object for ID */ ssize_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE3("Zs", "iz*s", attr_id, buf_size, buf); /* check arguments */ - if(NULL == (my_attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") if(!buf && buf_size) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid buffer") - /* Call private function in turn */ - if(0 > (ret_value = H5A_get_name(my_attr, buf_size, buf))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get attribute name") + /* get the name through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_NAME, &ret_value, buf_size, buf) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get name") done: FUNC_LEAVE_API(ret_value) @@ -1497,8 +1511,7 @@ H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, char *name /*out*/, size_t size, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute object for name */ + hid_t attr_id = -1; ssize_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) @@ -1506,10 +1519,8 @@ H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, lapl_id); /* Check args */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) @@ -1522,6 +1533,15 @@ H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") + if(H5VL_attr_generic(loc_id, H5VL_ATTR_OPEN_BY_IDX, &attr_id, + obj_name, idx_type, order, n, H5P_DEFAULT, lapl_id) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to open attribute") + + /* get the name through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_NAME, &ret_value, size, name) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get name") + +#if 0 /* Open the attribute on 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, "can't open attribute") @@ -1535,10 +1555,11 @@ H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, if((size_t)ret_value >= size) name[size - 1]='\0'; } /* end if */ +#endif done: /* Release resources */ - if(attr && H5A_close(attr) < 0) + if(attr_id > 0 && H5VL_attr_close(attr_id) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") FUNC_LEAVE_API(ret_value) @@ -1565,18 +1586,14 @@ done: hsize_t H5Aget_storage_size(hid_t attr_id) { - H5A_t *attr; /* Attribute object for ID */ hsize_t ret_value; /* Return value */ FUNC_ENTER_API(0) H5TRACE1("h", "i", attr_id); - /* Check args */ - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not an attribute") - - /* Set return value */ - ret_value = attr->shared->data_size; + /* get the storage size through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_STORAGE_SIZE, &ret_value) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, 0, "unable to get acpl") done: FUNC_LEAVE_API(ret_value) @@ -1599,19 +1616,14 @@ done: herr_t H5Aget_info(hid_t attr_id, H5A_info_t *ainfo) { - H5A_t *attr; /* Attribute object for name */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "i*x", attr_id, ainfo); - /* Check args */ - if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") - - /* Get the attribute information */ - if(H5A_get_info(attr, ainfo) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info") + /* get the attribute info through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_INFO, ainfo) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get attribute info") done: FUNC_LEAVE_API(ret_value) @@ -1635,18 +1647,17 @@ herr_t H5Aget_info_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, H5A_info_t *ainfo, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute object for name */ + hid_t attr_id = -1; + void *location = NULL; /* a pointer to VOL specific token that indicates + the location of the object */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE5("e", "i*s*s*xi", loc_id, obj_name, attr_name, ainfo, lapl_id); /* Check args */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name") if(!attr_name || !*attr_name) @@ -1658,7 +1669,7 @@ H5Aget_info_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, else if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") - +#if 0 /* Open the attribute on the object header */ if(NULL == (attr = H5A_open_by_name(&loc, obj_name, attr_name, lapl_id, H5AC_ind_dxpl_id))) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute") @@ -1666,12 +1677,28 @@ H5Aget_info_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, /* Get the attribute information */ if(H5A_get_info(attr, ainfo) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info") +#endif + + /* Get the token for the Object location through the VOL */ + if(H5VL_object_lookup(loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, obj_name, lapl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") + /* Open the attribute through the VOL */ + if((attr_id = H5VL_attr_open(loc_id, location, attr_name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to open attribute") + + /* get the attribute info through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_INFO, ainfo) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get attribute info") done: - /* Cleanup on failure */ - if(attr && H5A_close(attr) < 0) + /* release resources */ + if(attr_id > 0 && H5VL_attr_close(attr_id) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") + if (NULL != location) { + free (location); + location = NULL; + } FUNC_LEAVE_API(ret_value) } /* end H5Aget_info_by_name() */ @@ -1694,8 +1721,7 @@ herr_t H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute object for name */ + hid_t attr_id = FAIL; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -1703,10 +1729,8 @@ H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, lapl_id); /* Check args */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) @@ -1721,6 +1745,7 @@ H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") +#if 0 /* Open the attribute on 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, "can't open attribute") @@ -1728,10 +1753,20 @@ H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, /* Get the attribute information */ if(H5A_get_info(attr, ainfo) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info") +#endif + + /* open the attribute through the VOL */ + if(H5VL_attr_generic(loc_id, H5VL_ATTR_OPEN_BY_IDX, &attr_id, + obj_name, idx_type, order, n, H5P_DEFAULT, lapl_id) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to open attribute") + + /* get the attribute info through the VOL */ + if(H5VL_attr_get(attr_id, H5VL_ATTR_GET_INFO, ainfo) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get attribute info") done: /* Release resources */ - if(attr && H5A_close(attr) < 0) + if(attr_id && H5VL_attr_close(attr_id) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") FUNC_LEAVE_API(ret_value) @@ -2018,11 +2053,8 @@ H5Aiterate_by_name(hid_t loc_id, const char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t *idx, H5A_operator2_t op, void *op_data, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ - H5G_loc_t obj_loc; /* Location used to open group */ - H5G_name_t obj_path; /* Opened object group hier. path */ - H5O_loc_t obj_oloc; /* Opened object object location */ - hbool_t loc_found = FALSE; /* Entry at 'obj_name' found */ + void *location = NULL; + hid_t obj_loc_id = (-1); /* ID for object located */ H5A_attr_iter_op_t attr_op; /* Attribute operator */ hsize_t start_idx; /* Index of attribute to start iterating at */ @@ -2034,10 +2066,8 @@ H5Aiterate_by_name(hid_t loc_id, const char *obj_name, H5_index_t idx_type, op_data, lapl_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!obj_name || !*obj_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name") if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N) @@ -2050,19 +2080,13 @@ H5Aiterate_by_name(hid_t loc_id, const char *obj_name, H5_index_t idx_type, if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") - /* Set up opened group location to fill in */ - obj_loc.oloc = &obj_oloc; - obj_loc.path = &obj_path; - H5G_loc_reset(&obj_loc); - - /* Find the object's location */ - if(H5G_loc_find(&loc, obj_name, &obj_loc/*out*/, lapl_id, H5AC_ind_dxpl_id) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "object not found") - loc_found = TRUE; + /* Get the token for the Object location through the VOL */ + if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP_BY_NAME, &location, obj_name, lapl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") - /* Open the object */ - if((obj_loc_id = H5O_open_by_loc(&obj_loc, lapl_id, H5AC_ind_dxpl_id, TRUE)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open object") + /* Open the object through the VOL */ + if((obj_loc_id = H5VL_object_open_by_loc(loc_id, location, lapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") /* Build attribute operator info */ attr_op.op_type = H5A_ATTR_OP_APP2; @@ -2083,8 +2107,6 @@ done: if(H5I_dec_app_ref(obj_loc_id) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "unable to close temporary object") } /* end if */ - else if(loc_found && H5G_loc_free(&obj_loc) < 0) - HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't free location") FUNC_LEAVE_API(ret_value) } /* H5Aiterate_by_name() */ @@ -2299,13 +2321,9 @@ H5Aclose(hid_t attr_id) FUNC_ENTER_API(FAIL) H5TRACE1("e", "i", attr_id); - /* check arguments */ - if(NULL == H5I_object_verify(attr_id, H5I_ATTR)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute") - - /* 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") + /* Close the attribute through the VOL */ + if((ret_value = H5VL_attr_close(attr_id)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "unable to close attribute") done: FUNC_LEAVE_API(ret_value) diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index 806b721..96c03e8 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -139,31 +139,38 @@ hid_t H5Acreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t plist_id) { - H5G_loc_t loc; /* Object location */ - H5T_t *type; /* Datatype to use for attribute */ - H5S_t *space; /* Dataspace to use for attribute */ + void *location = NULL; + H5P_genplist_t *plist; /* Property list pointer */ hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE5("i", "i*siii", loc_id, name, type_id, space_id, plist_id); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file") if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") - 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") - /* Go do the real work for attaching the attribute to the dataset */ - if((ret_value = H5A_create(&loc, name, type, space, plist_id, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute") + /* Get correct property list */ + if(H5P_DEFAULT == plist_id) + plist_id = H5P_ATTRIBUTE_CREATE_DEFAULT; + + /* Get the plist structure */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(plist_id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + + /* set creation properties */ + if(H5P_set(plist, H5A_CRT_TYPE_ID_NAME, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") + if(H5P_set(plist, H5A_CRT_SPACE_ID_NAME, &space_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for space id") + if(H5P_set(plist, H5A_CRT_LOCATION_NAME, &location) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for location") + + /* Create the attribute through the VOL */ + if((ret_value = H5VL_attr_create(loc_id, name, plist_id, H5P_DEFAULT)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") done: FUNC_LEAVE_API(ret_value) @@ -195,35 +202,22 @@ done: hid_t H5Aopen_name(hid_t loc_id, const char *name) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ hid_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE2("i", "i*s", loc_id, name); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") - /* Open the attribute on the object header */ - if(NULL == (attr = H5A_open_by_name(&loc, ".", name, H5P_LINK_ACCESS_DEFAULT, H5AC_ind_dxpl_id))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute: '%s'", name) - - /* 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") + /* Open the attribute through the VOL */ + if((ret_value = H5VL_attr_open(loc_id, NULL, name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to open attribute") 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_API(ret_value) } /* H5Aopen_name() */ @@ -253,33 +247,20 @@ done: hid_t H5Aopen_idx(hid_t loc_id, unsigned idx) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ hid_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE2("i", "iIu", loc_id, idx); /* check arguments */ - if(H5I_ATTR == H5I_get_type(loc_id)) + if(H5I_ATTR_PUBLIC == 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") - /* Open the attribute in the object header */ - if(NULL == (attr = H5A_open_by_idx(&loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)idx, H5P_LINK_ACCESS_DEFAULT, 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_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") + if(H5VL_attr_generic(loc_id, H5VL_ATTR_OPEN_BY_IDX, &ret_value, ".", H5_INDEX_CRT_ORDER, + H5_ITER_INC, (hsize_t)idx, H5P_DEFAULT, H5P_LINK_ACCESS_DEFAULT) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get dataset access properties") 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_API(ret_value) } /* H5Aopen_idx() */ diff --git a/src/H5Apkg.h b/src/H5Apkg.h index 20aa5b9..e7732e2 100644 --- a/src/H5Apkg.h +++ b/src/H5Apkg.h @@ -217,10 +217,16 @@ H5_DLL H5A_t *H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name, H5_DLL ssize_t H5A_get_name(H5A_t *attr, size_t buf_size, char *buf); H5_DLL H5A_t *H5A_copy(H5A_t *new_attr, const H5A_t *old_attr); H5_DLL herr_t H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo); +H5_DLL hid_t H5A_get_type(H5A_t *attr); +H5_DLL hid_t H5A_get_space(H5A_t *attr); +H5_DLL hid_t H5A_get_create_plist(H5A_t* attr); H5_DLL herr_t H5A_free(H5A_t *attr); H5_DLL herr_t H5A_close(H5A_t *attr); H5_DLL htri_t H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5O_ainfo_t *ainfo); H5_DLL herr_t H5A_set_version(const H5F_t *f, H5A_t *attr); +H5_DLL herr_t H5A_open_common(const H5G_loc_t *loc, H5A_t *attr); +H5_DLL herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id); +H5_DLL herr_t H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id); /* Attribute "dense" storage routines */ H5_DLL herr_t H5A_dense_create(H5F_t *f, hid_t dxpl_id, H5O_ainfo_t *ainfo); diff --git a/src/H5Aprivate.h b/src/H5Aprivate.h index 0c0e519..18219e6 100644 --- a/src/H5Aprivate.h +++ b/src/H5Aprivate.h @@ -29,7 +29,10 @@ /**************************/ /* Library Private Macros */ /**************************/ - +/* ======== Attribute creation property names ======== */ +#define H5A_CRT_TYPE_ID_NAME "attr_type_id" +#define H5A_CRT_SPACE_ID_NAME "attr_space_id" +#define H5A_CRT_LOCATION_NAME "attr_location" /****************************/ /* Library Private Typedefs */ diff --git a/src/H5D.c b/src/H5D.c index 3dae982..acb300f 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -535,7 +535,7 @@ H5Dget_storage_size(hid_t dset_id) /* get storage size through the VOL */ if(H5VL_dataset_get(dset_id, H5VL_DATASET_GET_STORAGE_SIZE, &ret_value) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get storage size") + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, 0, "unable to get storage size") done: FUNC_LEAVE_API(ret_value) @@ -566,7 +566,7 @@ H5Dget_offset(hid_t dset_id) /* get offset through the VOL */ if(H5VL_dataset_get(dset_id, H5VL_DATASET_GET_OFFSET, &ret_value) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get offset") + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, HADDR_UNDEF, "unable to get offset") done: FUNC_LEAVE_API(ret_value) diff --git a/src/H5Ddeprec.c b/src/H5Ddeprec.c index e41e059..a2de87f 100644 --- a/src/H5Ddeprec.c +++ b/src/H5Ddeprec.c @@ -44,7 +44,7 @@ #include "H5Dpkg.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ - +#include "H5VLprivate.h" /* VOL plugins */ /****************/ /* Local Macros */ @@ -142,6 +142,7 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t dcpl_id) { H5P_genplist_t *plist; /* Property list pointer */ + hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) @@ -162,6 +163,8 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") if(H5P_set(plist, H5D_CRT_SPACE_ID_NAME, &space_id) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for space id") + if(H5P_set(plist, H5D_CRT_LCPL_ID_NAME, &lcpl_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for lcpl id") /* Create the dataset through the VOL */ if((ret_value = H5VL_dataset_create(loc_id, name, dcpl_id, H5P_DATASET_ACCESS_DEFAULT)) < 0) diff --git a/src/H5L.c b/src/H5L.c index 35dbaa9..3705144 100644 --- a/src/H5L.c +++ b/src/H5L.c @@ -491,9 +491,9 @@ H5Lcreate_hard(hid_t cur_loc_id, const char *cur_name, /* set creation properties */ if(H5P_set(plist, H5L_CRT_TARGET_ID_NAME, &cur_loc_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for current location id") + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target id") if(H5P_set(plist, H5L_CRT_TARGET_NAME_NAME, &cur_name) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for target name") + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target name") /* Create the link through the VOL */ if((ret_value = H5VL_link_create(H5VL_CREATE_HARD_LINK, new_loc_id, new_name, diff --git a/src/H5O.c b/src/H5O.c index 8230de2..7e1f6ba 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -408,20 +408,15 @@ herr_t H5Olink(hid_t obj_id, hid_t new_loc_id, const char *new_name, hid_t lcpl_id, hid_t lapl_id) { - H5G_loc_t new_loc; - H5G_loc_t obj_loc; + H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE5("e", "ii*sii", obj_id, new_loc_id, new_name, lcpl_id, lapl_id); /* Check arguments */ - if(H5G_loc(obj_id, &obj_loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") if(new_loc_id == H5L_SAME_LOC) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot use H5L_SAME_LOC when only one location is specified") - if(H5G_loc(new_loc_id, &new_loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") if(!new_name || !*new_name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name specified") /* Avoid compiler warning on 32-bit machines */ @@ -432,9 +427,22 @@ H5Olink(hid_t obj_id, hid_t new_loc_id, const char *new_name, hid_t lcpl_id, if(lcpl_id != H5P_DEFAULT && (TRUE != H5P_isa_class(lcpl_id, H5P_LINK_CREATE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a link creation property list") - /* Link to the object */ - if(H5L_link(&new_loc, new_name, &obj_loc, lcpl_id, lapl_id, H5AC_dxpl_id) < 0) - HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") + /* Check the group access property list */ + if(H5P_DEFAULT == lcpl_id) + lcpl_id = H5P_LINK_CREATE_DEFAULT; + + /* Get the plist structure */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + + /* set creation properties */ + if(H5P_set(plist, H5L_CRT_TARGET_ID_NAME, &obj_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target id") + + /* Create the link through the VOL */ + if((ret_value = H5VL_link_create(H5VL_CREATE_HARD_LINK, new_loc_id, new_name, + lcpl_id, lapl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create link") done: FUNC_LEAVE_API(ret_value) @@ -592,11 +600,12 @@ H5Oget_info(hid_t loc_id, H5O_info_t *oinfo) if(!oinfo) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no info struct") - /* Get the token for the Object location through the VOL */ + /* Get the token for the Object location through the VOL if(H5VL_object_lookup (loc_id, H5VL_OBJECT_LOOKUP, &location) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to locate object") + */ /* Get the group info through the VOL using the location token */ - if((ret_value = H5VL_object_get(loc_id, H5VL_OBJECT_GET_INFO, oinfo, location)) < 0) + if((ret_value = H5VL_object_get(loc_id, H5VL_OBJECT_GET_INFO, oinfo, NULL)) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get group info") done: @@ -624,6 +633,7 @@ done: herr_t H5Oget_info_by_name(hid_t loc_id, const char *name, H5O_info_t *oinfo, hid_t lapl_id) { +#if 1 void *location = NULL; /* a pointer to VOL specific token that indicates the location of the object */ herr_t ret_value = SUCCEED; /* Return value */ @@ -656,6 +666,55 @@ done: location = NULL; } FUNC_LEAVE_API(ret_value) +#endif +#if 0 + H5G_loc_t loc; /* Location of group */ + H5G_loc_t obj_loc; /* Location used to open group */ + H5G_name_t obj_path; /* Opened object group hier. path */ + H5O_loc_t obj_oloc; /* Opened object object location */ + hbool_t loc_found = FALSE; /* Entry at 'name' found */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "i*s*xi", loc_id, name, oinfo, lapl_id); + + /* Check args */ + if(H5G_loc(loc_id, &loc) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + if(!name || !*name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name") + if(!oinfo) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no info struct") + if(H5P_DEFAULT == lapl_id) + lapl_id = H5P_LINK_ACCESS_DEFAULT; + else + if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID") + + + obj_loc.oloc = &obj_oloc; + obj_loc.path = &obj_path; + H5G_loc_reset(&obj_loc); + + /* 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") + loc_found = TRUE; + /* Retrieve the object's information */ + if(H5O_get_info(obj_loc.oloc, H5AC_ind_dxpl_id, TRUE, oinfo) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve object info") + + /* Retrieve the object's information + if(H5G_loc_info(&loc, name, TRUE, oinfo, lapl_id, H5AC_ind_dxpl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found") + */ +done: + /* Release the object location */ + if(loc_found && H5G_loc_free(&obj_loc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") + + FUNC_LEAVE_API(ret_value) +#endif } /* end H5Oget_info_by_name() */ diff --git a/src/H5Pacpl.c b/src/H5Pacpl.c index 41a4f96..bd4a758 100644 --- a/src/H5Pacpl.c +++ b/src/H5Pacpl.c @@ -33,7 +33,9 @@ /* Headers */ /***********/ #include "H5private.h" /* Generic Functions */ +#include "H5Aprivate.h" /* Attributes */ #include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ #include "H5Ppkg.h" /* Property lists */ @@ -41,6 +43,9 @@ /* Local Macros */ /****************/ +/* Definitions for UDATA */ +#define H5A_CRT_LOCATION_SIZE sizeof(void *) +#define H5A_CRT_LOCATION_DEF NULL /******************/ /* Local Typedefs */ @@ -55,7 +60,8 @@ /********************/ /* Local Prototypes */ /********************/ - +/* Property class callbacks */ +static herr_t H5P_acrt_reg_prop(H5P_genclass_t *pclass); /*********************/ /* Package Variables */ @@ -67,7 +73,7 @@ const H5P_libclass_t H5P_CLS_ACRT[1] = {{ &H5P_CLS_STRING_CREATE_g, /* Parent class ID */ &H5P_CLS_ATTRIBUTE_CREATE_g, /* Pointer to class ID */ &H5P_LST_ATTRIBUTE_CREATE_g, /* Pointer to default property list ID */ - NULL, /* Default property registration routine */ + H5P_acrt_reg_prop, /* Default property registration routine */ NULL, /* Class creation callback */ NULL, /* Class creation callback info */ NULL, /* Class copy callback */ @@ -82,3 +88,43 @@ const H5P_libclass_t H5P_CLS_ACRT[1] = {{ /*****************************/ + +/*------------------------------------------------------------------------- + * Function: H5P_acrt_reg_prop + * + * Purpose: Register the attribute creation property list class's properties + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Mohamad Chaarawi + * April 5, 2012 + *------------------------------------------------------------------------- + */ +static herr_t +H5P_acrt_reg_prop(H5P_genclass_t *pclass) +{ + hid_t type_id = FAIL; + hid_t space_id = FAIL; + void *location = H5A_CRT_LOCATION_DEF; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Register the type ID property*/ + if(H5P_register_real(pclass, H5A_CRT_TYPE_ID_NAME, sizeof(hid_t), &type_id, + NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + + /* Register the space ID property */ + if(H5P_register_real(pclass, H5A_CRT_SPACE_ID_NAME, sizeof(hid_t), &space_id, + NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + + /* Register the lcpl ID property */ + if(H5P_register_real(pclass, H5A_CRT_LOCATION_NAME, H5A_CRT_LOCATION_SIZE, &location, + NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5P_acrt_reg_prop() */ diff --git a/src/H5VL.c b/src/H5VL.c index 4dde009..7a78ef8 100644 --- a/src/H5VL.c +++ b/src/H5VL.c @@ -1690,25 +1690,7 @@ H5VL_link_create(H5VL_link_create_type_t create_type, hid_t loc_id, const char * FUNC_ENTER_NOAPI(FAIL) - /* unwrap the higher level user ids. */ - if(H5L_SAME_LOC != loc_id) { - H5VL_id_wrapper_t *id_wrapper; - - /* get the ID struct */ - if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") - - /* set the vol plugin sturcture if it hasn't been done yet */ - if (NULL == vol_plugin) - vol_plugin = id_wrapper->vol_plugin; - - new_id = id_wrapper->obj_id; - } - else { - new_id = loc_id; - } - - /* unwrap the high level ID if the creation call is H5Lcreate_hard */ + /* unwrap the target high level ID if the creation call is H5Lcreate_hard */ if(H5VL_CREATE_HARD_LINK == create_type) { H5P_genplist_t *plist; /* Property list pointer */ hid_t cur_id; @@ -1723,7 +1705,7 @@ H5VL_link_create(H5VL_link_create_type_t create_type, hid_t loc_id, const char * /* Only one of the IDs can be H5L_SAME_LOC, and the other one must be of the wrapper type. Get the VOL plugin struct in case the link id is H5L_SAME_LOC*/ - if (H5L_SAME_LOC != cur_id) { + if (H5L_SAME_LOC != cur_id && H5I_DATATYPE != H5I_get_type(cur_id)) { H5VL_id_wrapper_t *id_wrapper; /* get the ID struct */ @@ -1736,6 +1718,24 @@ H5VL_link_create(H5VL_link_create_type_t create_type, hid_t loc_id, const char * } } + /* unwrap the higher level user ids. */ + if(H5L_SAME_LOC != loc_id && H5I_DATATYPE != H5I_get_type(loc_id)) { + H5VL_id_wrapper_t *id_wrapper; + + /* get the ID struct */ + if(NULL == (id_wrapper = (H5VL_id_wrapper_t *)H5I_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid user identifier") + + /* set the vol plugin sturcture if it hasn't been done yet */ + if (NULL == vol_plugin) + vol_plugin = id_wrapper->vol_plugin; + + new_id = id_wrapper->obj_id; + } + else { + new_id = loc_id; + } + /* check if the corresponding VOL create callback exists */ if(NULL == vol_plugin->link_cls.create) HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "vol plugin has no `link create' method") @@ -1809,3 +1809,340 @@ 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_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*/ + hid_t loc_id; /* actual attr 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->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*/ + hid_t attr_id; /* actual attr 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(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() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_attr_read + * + * Purpose: Reads data from attr through the VOL + * + * Return: Success: Non Negative + * + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +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; + + 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(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_attr_read() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_attr_write + * + * Purpose: Writes data to attr through the VOL + * + * Return: Success: Non Negative + * + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +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; + + 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(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_attr_write() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_attr_get + * + * Purpose: Get specific information about the attribute through the VOL + * + * Return: Success: non negative + * + * Failure: negative + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_attr_get(hid_t uid, H5VL_attr_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_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->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->attr_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_attr_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_attr_generic + * + * Purpose: perform a plugin specific operation + * + * Return: Success: non negative + * Failure: negative + * + * Programmer: Mohamad Chaarawi + * April, 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_attr_generic(hid_t uid, H5VL_attr_generic_t generic_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) + + /* 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") + + 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); + + if(H5VL_ATTR_OPEN_BY_IDX == generic_type) { + H5VL_id_wrapper_t *temp_id_wrapper; /* user id structure */ + hid_t *ret_id; + + 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 == (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_ATTR_PUBLIC, temp_id_wrapper, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attr handle") + } +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_attr_generic() */ diff --git a/src/H5VLnative.c b/src/H5VLnative.c index 808bc4d..dd76f48 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -21,6 +21,7 @@ * using HDF5 VFDs. */ +#define H5A_PACKAGE /*suppress error about including H5Apkg */ #define H5D_PACKAGE /*suppress error about including H5Dpkg */ #define H5F_PACKAGE /*suppress error about including H5Fpkg */ #define H5G_PACKAGE /*suppress error about including H5Gpkg */ @@ -33,6 +34,7 @@ #include "H5private.h" /* Generic Functions */ +#include "H5Apkg.h" /* Attribute pkg */ #include "H5Aprivate.h" /* Attributes */ #include "H5Dpkg.h" /* Dataset pkg */ #include "H5Dprivate.h" /* Datasets */ @@ -66,6 +68,14 @@ 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); +static herr_t H5VL_native_attr_write(hid_t attr_id, hid_t dtype_id, const void *buf); +static herr_t H5VL_native_attr_get(hid_t id, H5VL_attr_get_t get_type, va_list arguments); +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 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, @@ -100,12 +110,14 @@ H5VL_class_t H5VL_native_g = { 0, /* nrefs */ H5VL_native_term, /*terminate */ { /* attribute_cls */ - NULL, /* create */ - NULL, /* open */ - NULL, /* read */ - NULL, /* write */ + H5VL_native_attr_create, /* create */ + H5VL_native_attr_open, /* open */ + H5VL_native_attr_read, /* read */ + H5VL_native_attr_write, /* write */ NULL, /* delete */ - NULL /* close */ + H5VL_native_attr_get, /* get */ + H5VL_native_attr_generic, /* generic */ + H5VL_native_attr_close /* close */ }, { /* datatype_cls */ H5VL_native_datatype_commit, /* commit */ @@ -940,22 +952,21 @@ H5VL_native_group_get(hid_t obj_id, H5VL_group_get_t get_type, va_list arguments case H5VL_GROUP_GET_INFO: { H5G_info_t *grp_info = va_arg (arguments, H5G_info_t *); - haddr_t *addr = va_arg (arguments, haddr_t *); + H5O_loc_t *oloc = va_arg (arguments, H5O_loc_t *); H5G_loc_t loc; - H5O_loc_t oloc; /* Opened object object location */ if(H5G_loc(obj_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(!H5F_addr_defined(*addr)) + if(!H5F_addr_defined(oloc->addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") - oloc.addr = *addr; - oloc.file = loc.oloc->file; - /* Retrieve the group's information */ - if(H5G__obj_info(&oloc, grp_info/*out*/, H5AC_ind_dxpl_id) < 0) + if(H5G__obj_info(oloc, grp_info, H5AC_ind_dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve group info") + + if(H5O_loc_free(oloc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") break; } default: @@ -986,8 +997,7 @@ H5VL_native_object_open(hid_t loc_id, void *location, hid_t lapl_id) H5G_loc_t loc; H5G_loc_t obj_loc; /* Location used to open group */ H5G_name_t obj_path; /* Opened object group hier. path */ - H5O_loc_t obj_oloc; /* Opened object object location */ - haddr_t addr = *((haddr_t *)location); + H5O_loc_t *oloc = (H5O_loc_t *)location; hid_t ret_value = FAIL; FUNC_ENTER_NOAPI_NOINIT @@ -995,22 +1005,22 @@ H5VL_native_object_open(hid_t loc_id, void *location, hid_t lapl_id) /* Check args */ if(H5G_loc(loc_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(!H5F_addr_defined(addr)) + if(!H5F_addr_defined(oloc->addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") /* Set up opened group location to fill in */ - obj_loc.oloc = &obj_oloc; + obj_loc.oloc = oloc; obj_loc.path = &obj_path; - H5G_loc_reset(&obj_loc); - obj_loc.oloc->addr = addr; - obj_loc.oloc->file = loc.oloc->file; - H5G_name_reset(obj_loc.path); /* objects opened through this routine don't have a path name */ + H5G_name_reset(obj_loc.path); /* 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: + if(H5G_loc_free(&obj_loc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_native_object_open() */ @@ -1099,18 +1109,22 @@ H5VL_native_object_get(hid_t id, H5VL_object_get_t get_type, va_list arguments) case H5VL_OBJECT_GET_INFO: { H5O_info_t *obj_info = va_arg (arguments, H5O_info_t *); - haddr_t *addr = va_arg (arguments, haddr_t *); - H5O_loc_t oloc; /* Opened object object location */ - - if(!H5F_addr_defined(*addr)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no address supplied") + H5O_loc_t *oloc = va_arg (arguments, H5O_loc_t *); + hbool_t loc_set = FALSE; - oloc.addr = *addr; - oloc.file = loc.oloc->file; + if(NULL == oloc) { + oloc = loc.oloc; + } + else { + loc_set = TRUE; + } /* Retrieve the object's information */ - if(H5O_get_info(&oloc, H5AC_ind_dxpl_id, TRUE, obj_info) < 0) + if(H5O_get_info(oloc, H5AC_ind_dxpl_id, TRUE, obj_info) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve object info") + + if(loc_set && H5O_loc_free(oloc) < 0) + HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") break; } /* H5Oget_comment / H5Oget_comment_by_name */ @@ -1155,28 +1169,27 @@ H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_lis H5G_loc_t loc; H5G_loc_t obj_loc; H5G_name_t obj_path; /* Opened object group hier. path */ - H5O_loc_t obj_oloc; /* Opened object object location */ - haddr_t **location; + H5O_loc_t **location; haddr_t obj_addr; - hbool_t loc_found = FALSE; /* Entry at 'name' found */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT - location = va_arg (arguments, haddr_t **); - *location = (haddr_t *) malloc (sizeof (haddr_t)); + location = va_arg (arguments, H5O_loc_t **); + *location = (H5O_loc_t *) H5MM_malloc (sizeof (H5O_loc_t)); if(H5G_loc(loc_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Set up opened group location to fill in */ + obj_loc.oloc = *location; obj_loc.path = &obj_path; - obj_loc.oloc = &obj_oloc; H5G_loc_reset(&obj_loc); switch (lookup_type) { case H5VL_OBJECT_LOOKUP: - obj_addr = loc.oloc->addr; + (*location)->addr = loc.oloc->addr; + (*location)->file = loc.oloc->file; + (*location)->holding_file = loc.oloc->holding_file; break; case H5VL_OBJECT_LOOKUP_BY_NAME: { @@ -1186,10 +1199,8 @@ H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_lis HDassert(name && *name); /* Find the object's location */ - if((ret_value = H5G_loc_find(&loc, name, &obj_loc/*out*/, lapl_id, H5AC_dxpl_id)) < 0) + 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") - loc_found = TRUE; - obj_addr = (haddr_t)obj_loc.oloc->addr; break; } case H5VL_OBJECT_LOOKUP_BY_IDX: @@ -1204,13 +1215,14 @@ H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_lis 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") - loc_found = TRUE; - obj_addr = (haddr_t)obj_loc.oloc->addr; break; } case H5VL_OBJECT_LOOKUP_BY_ADDR: { obj_addr = va_arg (arguments, haddr_t); + (*location)->addr = obj_addr; + (*location)->file = loc.oloc->file; + (*location)->holding_file = loc.oloc->holding_file; break; } case H5VL_OBJECT_LOOKUP_BY_REF: @@ -1228,7 +1240,9 @@ H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_lis switch(ref_type) { case H5R_OBJECT: - obj_addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ + (*location)->addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ + (*location)->file = loc.oloc->file; + (*location)->holding_file = loc.oloc->holding_file; break; case H5R_DATASET_REGION: @@ -1249,8 +1263,9 @@ H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_lis /* Get the object oid for the dataset */ p = buf; - H5F_addr_decode(file, &p, &(obj_addr)); - + //H5F_addr_decode(file, &p, &(obj_addr)); + H5F_addr_decode(file, &p, &((*location)->addr)); + (*location)->file = file; /* Free the buffer allocated in H5HG_read() */ H5MM_xfree(buf); } /* end case */ @@ -1268,12 +1283,9 @@ H5VL_native_object_lookup(hid_t loc_id, H5VL_object_lookup_t lookup_type, va_lis HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't lookup this object") } /* end switch */ - *location[0] = obj_addr; + if(H5G_name_free(obj_loc.path) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to free path") done: - /* Release the object location if we failed after copying it */ - if(loc_found) - if(H5G_loc_free(&obj_loc) < 0) - HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location") FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_native_object_lookup() */ @@ -1820,7 +1832,7 @@ H5VL_native_dataset_get(hid_t id, H5VL_dataset_get_t get_type, va_list arguments break; } - /* H5Dget_type */ + /* H5Dget_access_plist */ case H5VL_DATASET_GET_DAPL: { hid_t *ret_id = va_arg (arguments, hid_t *); @@ -1830,7 +1842,7 @@ H5VL_native_dataset_get(hid_t id, H5VL_dataset_get_t get_type, va_list arguments break; } - /* H5Dget_type */ + /* H5Dget_storage_size */ case H5VL_DATASET_GET_STORAGE_SIZE: { hsize_t *ret = va_arg (arguments, hsize_t *); @@ -1839,7 +1851,7 @@ H5VL_native_dataset_get(hid_t id, H5VL_dataset_get_t get_type, va_list arguments *ret = H5D_get_storage_size(dset, H5AC_ind_dxpl_id); break; } - /* H5Dget_type */ + /* H5Dget_offset */ case H5VL_DATASET_GET_OFFSET: { haddr_t *ret = va_arg (arguments, haddr_t *); @@ -1860,7 +1872,7 @@ done: /*------------------------------------------------------------------------- * Function: H5VL_native_link_create * - * Purpose: Creates an hard link from NEW_NAME to CUR_NAME. + * Purpose: Creates an hard/soft/UD/external links. * * Return: Non-negative on success/Negative on failure * @@ -1886,10 +1898,10 @@ H5VL_native_link_create(H5VL_link_create_type_t create_type, hid_t loc_id, const switch (create_type) { case H5VL_CREATE_HARD_LINK: { - H5G_loc_t cur_loc, *cur_loc_p; - H5G_loc_t new_loc, *new_loc_p; + H5G_loc_t cur_loc; + H5G_loc_t link_loc; hid_t cur_loc_id; - char *cur_name; + char *cur_name = NULL; if(H5P_get(plist, H5L_CRT_TARGET_ID_NAME, &cur_loc_id) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for current location id") @@ -1898,23 +1910,33 @@ H5VL_native_link_create(H5VL_link_create_type_t create_type, hid_t loc_id, const if(cur_loc_id != H5L_SAME_LOC && H5G_loc(cur_loc_id, &cur_loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - if(loc_id != H5L_SAME_LOC && H5G_loc(loc_id, &new_loc) < 0) + if(loc_id != H5L_SAME_LOC && H5G_loc(loc_id, &link_loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") - /* Set up current & new location pointers */ - cur_loc_p = &cur_loc; - new_loc_p = &new_loc; - if(cur_loc_id == H5L_SAME_LOC) - cur_loc_p = new_loc_p; - else if(loc_id == H5L_SAME_LOC) - new_loc_p = cur_loc_p; - else if(cur_loc_p->oloc->file != new_loc_p->oloc->file) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "source and destination should be in the same file.") - - /* Create the link */ - if((ret_value = H5L_create_hard(cur_loc_p, cur_name, new_loc_p, link_name, - lcpl_id, lapl_id, H5AC_dxpl_id)) < 0) - HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") + /* H5Lcreate_hard */ + if (NULL != cur_name) { + H5G_loc_t *cur_loc_p, *link_loc_p; + + /* Set up current & new location pointers */ + cur_loc_p = &cur_loc; + link_loc_p = &link_loc; + if(cur_loc_id == H5L_SAME_LOC) + cur_loc_p = link_loc_p; + else if(loc_id == H5L_SAME_LOC) + link_loc_p = cur_loc_p; + else if(cur_loc_p->oloc->file != link_loc_p->oloc->file) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "source and destination should be in the same file.") + + /* Create the link */ + if((ret_value = H5L_create_hard(cur_loc_p, cur_name, link_loc_p, link_name, + lcpl_id, lapl_id, H5AC_dxpl_id)) < 0) + HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") + } + else { /* H5Olink */ + /* Link to the object */ + if(H5L_link(&link_loc, link_name, &cur_loc, lcpl_id, lapl_id, H5AC_dxpl_id) < 0) + HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") + } break; } case H5VL_CREATE_SOFT_LINK: @@ -2013,7 +2035,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_native_link_move() */ -#if 0 /*------------------------------------------------------------------------- * Function: H5VL_native_attr_create @@ -2029,18 +2050,32 @@ done: *------------------------------------------------------------------------- */ static hid_t -H5VL_native_attr_create(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id, - hid_t acpl_id, hid_t UNUSED aapl_id) +H5VL_native_attr_create(hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t UNUSED aapl_id) { - H5G_loc_t loc; /* Object location */ - H5T_t *type; /* Datatype to use for attribute */ - H5S_t *space; /* Dataspace to use for attribute */ + 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 + /* 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") + if(H5G_loc(loc_id, &loc) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") + 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))) @@ -2048,12 +2083,349 @@ H5VL_native_attr_create(hid_t loc_id, const char *attr_name, hid_t type_id, hid_ if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space") - /* 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") + 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; /* Object location */ + H5G_name_t obj_path; /* Opened object group hier. path */ + H5O_loc_t *oloc = (H5O_loc_t *)location; + + /* Set up opened group location to fill in */ + obj_loc.oloc = oloc;//&obj_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(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_attr_create() */ -#endif + +/*------------------------------------------------------------------------- + * 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 */ + H5O_loc_t *oloc = (H5O_loc_t *)location; + + /* Read in attribute from object header */ + if(NULL == (attr = H5O_attr_open_by_name(oloc, attr_name, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from object header") + + if(H5O_loc_free(oloc) < 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() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_attr_close + * + * Purpose: Closes an attribute. + * + * Return: Success: 0 + * Failure: -1, attr not closed. + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_attr_close(hid_t attr_id) +{ + 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") + + /* 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: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_attr_close() */ + + +/*------------------------------------------------------------------------- + * 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 */ + + FUNC_ENTER_NOAPI_NOINIT + + 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") + + /* 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_attr_read() */ + + +/*------------------------------------------------------------------------- + * 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 */ + + FUNC_ENTER_NOAPI_NOINIT + + 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") + + /* 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_attr_write() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_native_attr_get + * + * Purpose: Gets certain information about an attribute + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Mohamad Chaarawi + * March, 2012 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_native_attr_get(hid_t attr_id, H5VL_attr_get_t get_type, va_list arguments) +{ + H5A_t *attr; + herr_t ret_value = SUCCEED; /* Return value */ + + 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") + + 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: + { + 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") + + 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 *); + + /* 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") + + break; + } + /* H5Aget_info */ + case H5VL_ATTR_GET_INFO: + { + 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") + + break; + } + case H5VL_ATTR_GET_STORAGE_SIZE: + { + hsize_t *ret = va_arg (arguments, hsize_t *); + + /* 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") + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_native_attr_get() */ + + +/*------------------------------------------------------------------------- + * 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 */ + + 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") + + /* 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; + } + default: + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't recognize this operation type") + } + +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() */ diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index f9e3145..e509b6c 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -61,6 +61,14 @@ 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); +H5_DLL herr_t H5VL_attr_write(hid_t attr_id, hid_t dtype_id, const void *buf); +H5_DLL herr_t H5VL_attr_get(hid_t id, H5VL_attr_get_t get_type, ...); +H5_DLL herr_t H5VL_attr_generic(hid_t id, H5VL_attr_generic_t generic_type, ...); +H5_DLL herr_t H5VL_attr_close(hid_t attr_id); + H5_DLL hid_t H5VL_dataset_create(hid_t uid, const char *name, hid_t dcpl_id, hid_t dapl_id); H5_DLL hid_t H5VL_dataset_open(hid_t uid, const char *name, hid_t dapl_id); H5_DLL herr_t H5VL_dataset_close(hid_t uid); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index 11e8344..f1d56d3 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -42,6 +42,21 @@ typedef enum H5VL_file_get_t { H5VL_FILE_GET_FREE_SECTIONS = 13 /*file free selections */ } H5VL_file_get_t; +/* types for all attr get API routines */ +typedef enum H5VL_attr_get_t { + H5VL_ATTR_GET_SPACE = 0, /* dataspace */ + H5VL_ATTR_GET_TYPE = 1, /* datatype */ + H5VL_ATTR_GET_ACPL = 2, /* creation property list */ + H5VL_ATTR_GET_NAME = 3, /* access property list */ + H5VL_ATTR_GET_STORAGE_SIZE = 4, /* storage size */ + H5VL_ATTR_GET_INFO = 5 /* offset */ +} H5VL_attr_get_t; + +/* types for all attr general operations */ +typedef enum H5VL_attr_generic_t { + H5VL_ATTR_OPEN_BY_IDX = 0 /* H5Aopen_by_idx */ +} H5VL_attr_generic_t; + /* types for all dataset get API routines */ typedef enum H5VL_dataset_get_t { H5VL_DATASET_GET_SPACE = 0, /* dataspace */ @@ -113,14 +128,16 @@ typedef struct H5VL_dataset_class_t { } H5VL_dataset_class_t; /* H5A routines */ -typedef struct H5VL_attribute_class_t { - hid_t (*create)( hid_t loc_id, const char *attr_name, hid_t acpl_id, hid_t aapl_id); - hid_t (*open) (hid_t obj_id, const char *attr_name, hid_t aapl_id); - herr_t (*read) (hid_t attr_id, hid_t mem_type_id, void *buf ); - herr_t (*write) (hid_t attr_id, hid_t mem_type_id, const void *buf ); - herr_t (*delete)(hid_t loc_id, const char *attr_name ); +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); + hid_t (*open) (hid_t loc_id, void *location, const char *attr_name, hid_t aapl_id); + herr_t (*read) (hid_t attr_id, hid_t mem_type_id, void *buf); + herr_t (*write) (hid_t attr_id, hid_t mem_type_id, const void *buf); + herr_t (*delete)(hid_t loc_id, const char *attr_name); + herr_t (*get) (hid_t file_id, H5VL_attr_get_t get_type, va_list arguments); + herr_t (*generic)(hid_t id, H5VL_attr_generic_t generic_type, va_list arguments); herr_t (*close) (hid_t attr_id); -} H5VL_attribute_class_t; +} H5VL_attr_class_t; /* H5T routines*/ typedef struct H5VL_datatype_class_t { @@ -164,7 +181,7 @@ typedef struct H5VL_class_t { const char *name; unsigned nrefs; /* Ref count for times struct is pointed to */ herr_t (*terminate)(void); - H5VL_attribute_class_t attribute_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; diff --git a/test/tattr.c b/test/tattr.c index 1285f0e..ee6707f 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -9832,6 +9832,12 @@ test_attr_bug3(hid_t fcpl, hid_t fapl) did = H5Dcreate2(fid, "dset", tid2, sid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(did, FAIL, "H5Dcreate2"); + /* MSC - workaround committed datatypes */ + ret = H5Tclose(tid1); + CHECK(ret, FAIL, "H5Tclose"); + tid1 = H5Topen2(fid, "dtype", H5P_DEFAULT); + CHECK(tid1, FAIL, "H5Topen2"); + /* Create attribute on datatype, using that datatype as its datatype */ aid1 = H5Acreate2(tid1, "attr", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid1, FAIL, "H5Acreate2"); @@ -9973,6 +9979,12 @@ test_attr_bug4(hid_t fcpl, hid_t fapl) aid2 = H5Acreate2(did, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid2, FAIL, "H5Acreate2"); + /* MSC - workaround committed datatypes */ + ret = H5Tclose(tid); + CHECK(ret, FAIL, "H5Tclose"); + tid = H5Topen2(fid, "dtype", H5P_DEFAULT); + CHECK(tid, FAIL, "H5Topen2"); + /* Create attribute on datatype (this is the main test) */ aid3 = H5Acreate2(tid, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid3, FAIL, "H5Acreate2"); @@ -10057,6 +10069,11 @@ test_attr_bug5(hid_t fcpl, hid_t fapl) aidd1 = H5Acreate2(did1, BUG3_ATTR_NAME, tid1, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aidd1, FAIL, "H5Acreate2"); + /* MSC - workaround committed datatypes */ + ret = H5Tclose(tid1); + CHECK(ret, FAIL, "H5Tclose"); + tid1 = H5Topen2(fid1, BUG3_DT_NAME, H5P_DEFAULT); + CHECK(tid1, FAIL, "H5Topen2"); /* Create attribute on datatype */ aidt1 = H5Acreate2(tid1, BUG3_ATTR_NAME, tid1, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aidt1, FAIL, "H5Acreate2"); @@ -10261,6 +10278,11 @@ test_attr_bug7(hid_t fcpl, hid_t fapl) */ sid = H5Screate_simple(1, &dims_s, NULL); CHECK(sid, FAIL, "H5Screate_simple"); + /* MSC - workaround committed datatypes */ + ret = H5Tclose(tid); + CHECK(ret, FAIL, "H5Tclose"); + tid = H5Topen2(fid, TYPE1_NAME, H5P_DEFAULT); + CHECK(tid, FAIL, "H5Topen2"); aid = H5Acreate2(tid, ATTR1_NAME, H5T_STD_I8LE, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid, FAIL, "H5Acreate2"); diff --git a/test/th5o.c b/test/th5o.c index c878b34..c695474 100644 --- a/test/th5o.c +++ b/test/th5o.c @@ -636,6 +636,7 @@ test_h5o_plist(void) /* Commit the type inside the group anonymously and link it in */ dtype = H5Tcopy(H5T_NATIVE_INT); CHECK(dtype, FAIL, "H5Tcopy"); + ret = H5Tcommit_anon(fid, dtype, tcpl, H5P_DEFAULT); CHECK(ret, FAIL, "H5Tcommit_anon"); ret = H5Olink(dtype, fid, "datatype", H5P_DEFAULT, H5P_DEFAULT); -- cgit v0.12