diff options
Diffstat (limited to 'src/H5Adeprec.c')
-rw-r--r-- | src/H5Adeprec.c | 206 |
1 files changed, 115 insertions, 91 deletions
diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index 7202edf..2cc3b80 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -47,6 +47,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ #include "H5Opkg.h" /* Object headers */ +#include "H5VLprivate.h" /* Virtual Object Layer */ /****************/ @@ -138,9 +139,11 @@ 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 *attr = NULL; /* attr token from VOL plugin */ + void *obj = NULL; /* object token of loc_id */ + H5VL_t *vol_plugin; /* VOL plugin information */ + H5VL_loc_params_t loc_params; + H5P_genplist_t *plist; /* Property list pointer */ hid_t ret_value; /* Return value */ FUNC_ENTER_API(FAIL) @@ -149,22 +152,46 @@ H5Acreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, /* 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(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, H5VL_ATTR_TYPE_ID, &type_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for datatype id") + if(H5P_set(plist, H5VL_ATTR_SPACE_ID, &space_id) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for space id") + + loc_params.type = H5VL_OBJECT_BY_SELF; + loc_params.obj_type = H5I_get_type(loc_id); + + /* get the file object */ + if(NULL == (obj = (void *)H5VL_get_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + + /* get the plugin pointer */ + if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") + + /* Create the attribute through the VOL */ + if(NULL == (attr = H5VL_attr_create(obj, loc_params, vol_plugin, name, plist_id, H5P_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") + + /* Get an atom for the attribute */ + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") done: + if (ret_value < 0 && attr) + if(H5VL_attr_close (attr, vol_plugin, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") FUNC_LEAVE_API(ret_value) } /* H5Acreate1() */ @@ -194,8 +221,10 @@ done: hid_t H5Aopen_name(hid_t loc_id, const char *name) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ + void *attr = NULL; /* attr token from VOL plugin */ + void *obj = NULL; /* object token of loc_id */ + H5VL_t *vol_plugin; /* VOL plugin information */ + H5VL_loc_params_t loc_params; hid_t ret_value; FUNC_ENTER_API(FAIL) @@ -204,25 +233,32 @@ H5Aopen_name(hid_t loc_id, const char *name) /* 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(!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) + loc_params.type = H5VL_OBJECT_BY_SELF; + loc_params.obj_type = H5I_get_type(loc_id); - /* 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") + /* get the file object */ + if(NULL == (obj = (void *)H5VL_get_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") -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") + /* get the plugin pointer */ + if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") + + /* Create the attribute through the VOL */ + if(NULL == (attr = H5VL_attr_open(obj, loc_params, vol_plugin, name, H5P_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") + /* Get an atom for the attribute */ + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + +done: + if (ret_value < 0 && attr) + if(H5VL_attr_close (attr, vol_plugin, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") FUNC_LEAVE_API(ret_value) } /* H5Aopen_name() */ @@ -252,8 +288,10 @@ done: hid_t H5Aopen_idx(hid_t loc_id, unsigned idx) { - H5G_loc_t loc; /* Object location */ - H5A_t *attr = NULL; /* Attribute opened */ + void *attr = NULL; /* attr token from VOL plugin */ + void *obj = NULL; /* object token of loc_id */ + H5VL_t *vol_plugin; /* VOL plugin information */ + H5VL_loc_params_t loc_params; hid_t ret_value; FUNC_ENTER_API(FAIL) @@ -262,23 +300,34 @@ H5Aopen_idx(hid_t loc_id, unsigned idx) /* 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") - - /* 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") + loc_params.type = H5VL_OBJECT_BY_IDX; + loc_params.loc_data.loc_by_idx.name = "."; + loc_params.loc_data.loc_by_idx.idx_type = H5_INDEX_CRT_ORDER; + loc_params.loc_data.loc_by_idx.order = H5_ITER_INC; + loc_params.loc_data.loc_by_idx.n = (hsize_t)idx; + loc_params.loc_data.loc_by_idx.plist_id = H5P_LINK_ACCESS_DEFAULT; + loc_params.obj_type = H5I_get_type(loc_id); + + /* get the file object */ + if(NULL == (obj = (void *)H5VL_get_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + /* get the plugin pointer */ + if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") + + /* Create the attribute through the VOL */ + if(NULL == (attr = H5VL_attr_open(obj, loc_params, vol_plugin, NULL, H5P_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") + + /* Get an atom for the attribute */ + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") 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 (ret_value < 0 && attr) + if(H5VL_attr_close (attr, vol_plugin, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") FUNC_LEAVE_API(ret_value) } /* H5Aopen_idx() */ @@ -304,56 +353,31 @@ done: int H5Aget_num_attrs(hid_t loc_id) { - H5O_loc_t *loc; /* Object location for attribute */ - void *obj; - int ret_value; + H5VL_t *vol_plugin; + void *obj; + H5VL_loc_params_t loc_params; + H5O_info_t oinfo; + int ret_value; FUNC_ENTER_API(FAIL) H5TRACE1("Is", "i", loc_id); - /* check arguments */ - if(H5I_BADID == H5I_get_type(loc_id)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad location ID") - if(H5I_FILE == H5I_get_type(loc_id) || H5I_ATTR == H5I_get_type(loc_id)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute") - if(NULL == (obj = H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADATOM, FAIL, "illegal object atom") - switch(H5I_get_type (loc_id)) { - case H5I_DATASET: - if(NULL == (loc = H5D_oloc((H5D_t*)obj))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get location for object") - break; - - case H5I_DATATYPE: - if(NULL == (loc = H5T_oloc((H5T_t*)obj))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "target datatype is not committed") - break; - - case H5I_GROUP: - if(NULL == (loc = H5G_oloc((H5G_t*)obj))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get location for object") - break; - - case H5I_UNINIT: - case H5I_BADID: - case H5I_FILE: - case H5I_DATASPACE: - case H5I_ATTR: - case H5I_REFERENCE: - case H5I_VFL: - case H5I_GENPROP_CLS: - case H5I_GENPROP_LST: - case H5I_ERROR_CLASS: - case H5I_ERROR_MSG: - case H5I_ERROR_STACK: - case H5I_NTYPES: - default: - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "inappropriate attribute target") - } /*lint !e788 All appropriate cases are covered */ - - /* Look up the # of attributes for the object */ - if((ret_value = H5O_attr_count(loc, H5AC_ind_dxpl_id)) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, FAIL, "can't get attribute count for object") + loc_params.type = H5VL_OBJECT_BY_SELF; + loc_params.obj_type = H5I_get_type(loc_id); + + /* get the file object */ + if(NULL == (obj = (void *)H5VL_get_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + /* get the plugin pointer */ + if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") + + /* Get the group info through the VOL using the location token */ + if(H5VL_object_get(obj, loc_params, vol_plugin, H5VL_OBJECT_GET_INFO, + H5_REQUEST_NULL, &oinfo) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get group info") + + ret_value = oinfo.num_attrs; done: FUNC_LEAVE_API(ret_value) |