/src/hdf5/src/H5VLnative_attr.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the COPYING file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /* |
14 | | * Purpose: Attribute callbacks for the native VOL connector |
15 | | * |
16 | | */ |
17 | | |
18 | | /****************/ |
19 | | /* Module Setup */ |
20 | | /****************/ |
21 | | |
22 | | #define H5A_FRIEND /* Suppress error about including H5Apkg */ |
23 | | |
24 | | /***********/ |
25 | | /* Headers */ |
26 | | /***********/ |
27 | | #include "H5private.h" /* Generic Functions */ |
28 | | #include "H5Apkg.h" /* Attributes */ |
29 | | #include "H5CXprivate.h" /* API Contexts */ |
30 | | #include "H5Eprivate.h" /* Error handling */ |
31 | | #include "H5Fprivate.h" /* Files */ |
32 | | #include "H5Gprivate.h" /* Groups */ |
33 | | #include "H5Iprivate.h" /* IDs */ |
34 | | #include "H5Pprivate.h" /* Property lists */ |
35 | | #include "H5Sprivate.h" /* Dataspaces */ |
36 | | #include "H5Tprivate.h" /* Datatypes */ |
37 | | #include "H5VLprivate.h" /* Virtual Object Layer */ |
38 | | |
39 | | #include "H5VLnative_private.h" /* Native VOL connector */ |
40 | | |
41 | | /****************/ |
42 | | /* Local Macros */ |
43 | | /****************/ |
44 | | |
45 | | /******************/ |
46 | | /* Local Typedefs */ |
47 | | /******************/ |
48 | | |
49 | | /********************/ |
50 | | /* Local Prototypes */ |
51 | | /********************/ |
52 | | |
53 | | /*********************/ |
54 | | /* Package Variables */ |
55 | | /*********************/ |
56 | | |
57 | | /*****************************/ |
58 | | /* Library Private Variables */ |
59 | | /*****************************/ |
60 | | |
61 | | /*******************/ |
62 | | /* Local Variables */ |
63 | | /*******************/ |
64 | | |
65 | | /*------------------------------------------------------------------------- |
66 | | * Function: H5VL__native_attr_create |
67 | | * |
68 | | * Purpose: Handles the attribute create callback |
69 | | * |
70 | | * Return: Success: attribute pointer |
71 | | * Failure: NULL |
72 | | * |
73 | | *------------------------------------------------------------------------- |
74 | | */ |
75 | | void * |
76 | | H5VL__native_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t type_id, |
77 | | hid_t space_id, hid_t acpl_id, hid_t H5_ATTR_UNUSED aapl_id, |
78 | | hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
79 | 0 | { |
80 | 0 | H5P_genplist_t *plist; |
81 | 0 | H5G_loc_t loc; /* Object location */ |
82 | 0 | H5G_loc_t obj_loc; /* Location used to open group */ |
83 | 0 | bool loc_found = false; |
84 | 0 | H5T_t *type, *dt; /* Datatype to use for attribute */ |
85 | 0 | H5S_t *space; /* Dataspace to use for attribute */ |
86 | 0 | H5A_t *attr = NULL; |
87 | 0 | void *ret_value = NULL; |
88 | |
|
89 | 0 | FUNC_ENTER_PACKAGE |
90 | |
|
91 | 0 | if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) |
92 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object"); |
93 | 0 | if (0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) |
94 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, NULL, "no write intent on file"); |
95 | | |
96 | 0 | if (NULL == (plist = H5P_object_verify(aapl_id, H5P_ATTRIBUTE_ACCESS))) |
97 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "AAPL is not an attribute access property list"); |
98 | | |
99 | 0 | if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) |
100 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a datatype"); |
101 | | /* If this is a named datatype, get the connector's pointer to the datatype */ |
102 | 0 | type = H5T_get_actual_type(dt); |
103 | |
|
104 | 0 | if (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) |
105 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data space"); |
106 | | |
107 | 0 | if (loc_params->type == H5VL_OBJECT_BY_SELF) { |
108 | | /* H5Acreate */ |
109 | | /* Go do the real work for attaching the attribute to the dataset */ |
110 | 0 | if (NULL == (attr = H5A__create(&loc, attr_name, type, space, acpl_id))) |
111 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "unable to create attribute"); |
112 | 0 | } /* end if */ |
113 | 0 | else if (loc_params->type == H5VL_OBJECT_BY_NAME) { |
114 | | /* H5Acreate_by_name */ |
115 | 0 | if (NULL == (attr = H5A__create_by_name(&loc, loc_params->loc_data.loc_by_name.name, attr_name, type, |
116 | 0 | space, acpl_id))) |
117 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "unable to create attribute"); |
118 | 0 | } /* end else-if */ |
119 | 0 | else |
120 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, NULL, "unknown attribute create parameters"); |
121 | | |
122 | 0 | ret_value = (void *)attr; |
123 | |
|
124 | 0 | done: |
125 | | /* Release resources */ |
126 | 0 | if (loc_found && H5G_loc_free(&obj_loc) < 0) |
127 | 0 | HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, NULL, "can't free location"); |
128 | |
|
129 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
130 | 0 | } /* end H5VL__native_attr_create() */ |
131 | | |
132 | | /*------------------------------------------------------------------------- |
133 | | * Function: H5VL__native_attr_open |
134 | | * |
135 | | * Purpose: Handles the attribute open callback |
136 | | * |
137 | | * Return: Success: attribute pointer |
138 | | * Failure: NULL |
139 | | * |
140 | | *------------------------------------------------------------------------- |
141 | | */ |
142 | | void * |
143 | | H5VL__native_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t aapl_id, |
144 | | hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
145 | 78 | { |
146 | 78 | H5P_genplist_t *plist; |
147 | 78 | H5G_loc_t loc; /* Object location */ |
148 | 78 | H5A_t *attr = NULL; /* Attribute opened */ |
149 | 78 | void *ret_value; |
150 | | |
151 | 78 | FUNC_ENTER_PACKAGE |
152 | | |
153 | | /* check arguments */ |
154 | 78 | if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) |
155 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object"); |
156 | | |
157 | 78 | if (NULL == (plist = H5P_object_verify(aapl_id, H5P_ATTRIBUTE_ACCESS))) |
158 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "AAPL is not an attribute access property list"); |
159 | | |
160 | 78 | if (loc_params->type == H5VL_OBJECT_BY_SELF) { |
161 | | /* H5Aopen */ |
162 | | /* Open the attribute */ |
163 | 0 | if (NULL == (attr = H5A__open(&loc, attr_name))) |
164 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to open attribute: '%s'", attr_name); |
165 | 0 | } /* end if */ |
166 | 78 | else if (loc_params->type == H5VL_OBJECT_BY_NAME) { |
167 | | /* H5Aopen_by_name */ |
168 | | /* Open the attribute on the object header */ |
169 | 78 | if (NULL == (attr = H5A__open_by_name(&loc, loc_params->loc_data.loc_by_name.name, attr_name))) |
170 | 14 | HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "can't open attribute"); |
171 | 78 | } /* end else-if */ |
172 | 0 | else if (loc_params->type == H5VL_OBJECT_BY_IDX) { |
173 | | /* H5Aopen_by_idx */ |
174 | | /* Open the attribute in the object header */ |
175 | 0 | if (NULL == (attr = H5A__open_by_idx( |
176 | 0 | &loc, loc_params->loc_data.loc_by_idx.name, loc_params->loc_data.loc_by_idx.idx_type, |
177 | 0 | loc_params->loc_data.loc_by_idx.order, loc_params->loc_data.loc_by_idx.n))) |
178 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to open attribute"); |
179 | 0 | } /* end else-if */ |
180 | 0 | else |
181 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, NULL, "unknown attribute open parameters"); |
182 | | |
183 | 64 | ret_value = (void *)attr; |
184 | | |
185 | 78 | done: |
186 | 78 | FUNC_LEAVE_NOAPI(ret_value) |
187 | 64 | } /* end H5VL__native_attr_open() */ |
188 | | |
189 | | /*------------------------------------------------------------------------- |
190 | | * Function: H5VL__native_attr_read |
191 | | * |
192 | | * Purpose: Handles the attribute read callback |
193 | | * |
194 | | * Return: SUCCEED/FAIL |
195 | | * |
196 | | *------------------------------------------------------------------------- |
197 | | */ |
198 | | herr_t |
199 | | H5VL__native_attr_read(void *attr, hid_t dtype_id, void *buf, hid_t dxpl_id, void H5_ATTR_UNUSED **req) |
200 | 64 | { |
201 | 64 | H5T_t *mem_type; /* Memory datatype */ |
202 | 64 | herr_t ret_value; /* Return value */ |
203 | | |
204 | 64 | FUNC_ENTER_PACKAGE |
205 | | |
206 | 64 | if (NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) |
207 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype"); |
208 | | |
209 | | /* Set DXPL for operation */ |
210 | 64 | H5CX_set_dxpl(dxpl_id); |
211 | | |
212 | | /* Go write the actual data to the attribute */ |
213 | 64 | if ((ret_value = H5A__read((H5A_t *)attr, mem_type, buf)) < 0) |
214 | 3 | HGOTO_ERROR(H5E_ATTR, H5E_READERROR, FAIL, "unable to read attribute"); |
215 | | |
216 | 64 | done: |
217 | 64 | FUNC_LEAVE_NOAPI(ret_value) |
218 | 64 | } /* end H5VL__native_attr_read() */ |
219 | | |
220 | | /*------------------------------------------------------------------------- |
221 | | * Function: H5VL__native_attr_write |
222 | | * |
223 | | * Purpose: Handles the attribute write callback |
224 | | * |
225 | | * Return: SUCCEED/FAIL |
226 | | * |
227 | | *------------------------------------------------------------------------- |
228 | | */ |
229 | | herr_t |
230 | | H5VL__native_attr_write(void *attr, hid_t dtype_id, const void *buf, hid_t dxpl_id, void H5_ATTR_UNUSED **req) |
231 | 0 | { |
232 | 0 | H5T_t *mem_type; /* Memory datatype */ |
233 | 0 | herr_t ret_value; /* Return value */ |
234 | |
|
235 | 0 | FUNC_ENTER_PACKAGE |
236 | |
|
237 | 0 | if (NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE))) |
238 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype"); |
239 | | |
240 | | /* Set DXPL for operation */ |
241 | 0 | H5CX_set_dxpl(dxpl_id); |
242 | | |
243 | | /* Go write the actual data to the attribute */ |
244 | 0 | if ((ret_value = H5A__write((H5A_t *)attr, mem_type, buf)) < 0) |
245 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "unable to write attribute"); |
246 | | |
247 | 0 | done: |
248 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
249 | 0 | } /* end H5VL__native_attr_write() */ |
250 | | |
251 | | /*------------------------------------------------------------------------- |
252 | | * Function: H5VL__native_attr_get |
253 | | * |
254 | | * Purpose: Handles the attribute get callback |
255 | | * |
256 | | * Return: SUCCEED/FAIL |
257 | | * |
258 | | *------------------------------------------------------------------------- |
259 | | */ |
260 | | herr_t |
261 | | H5VL__native_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id, |
262 | | void H5_ATTR_UNUSED **req) |
263 | 61 | { |
264 | 61 | herr_t ret_value = SUCCEED; /* Return value */ |
265 | | |
266 | 61 | FUNC_ENTER_PACKAGE |
267 | | |
268 | 61 | switch (args->op_type) { |
269 | | /* H5Aget_space */ |
270 | 3 | case H5VL_ATTR_GET_SPACE: { |
271 | 3 | H5A_t *attr = (H5A_t *)obj; |
272 | | |
273 | 3 | if ((args->args.get_space.space_id = H5A_get_space(attr)) < 0) |
274 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get space ID of attribute"); |
275 | 3 | break; |
276 | 3 | } |
277 | | |
278 | | /* H5Aget_type */ |
279 | 58 | case H5VL_ATTR_GET_TYPE: { |
280 | 58 | H5A_t *attr = (H5A_t *)obj; |
281 | | |
282 | 58 | if ((args->args.get_type.type_id = H5A__get_type(attr)) < 0) |
283 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get datatype ID of attribute"); |
284 | 58 | break; |
285 | 58 | } |
286 | | |
287 | | /* H5Aget_create_plist */ |
288 | 58 | case H5VL_ATTR_GET_ACPL: { |
289 | 0 | H5A_t *attr = (H5A_t *)obj; |
290 | |
|
291 | 0 | if ((args->args.get_acpl.acpl_id = H5A__get_create_plist(attr)) < 0) |
292 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for attr"); |
293 | | |
294 | 0 | break; |
295 | 0 | } |
296 | | |
297 | | /* H5Aget_name */ |
298 | 0 | case H5VL_ATTR_GET_NAME: { |
299 | 0 | H5VL_attr_get_name_args_t *get_name_args = &args->args.get_name; |
300 | |
|
301 | 0 | if (H5VL_OBJECT_BY_SELF == get_name_args->loc_params.type) { |
302 | 0 | if (H5A__get_name((H5A_t *)obj, get_name_args->buf_size, get_name_args->buf, |
303 | 0 | get_name_args->attr_name_len) < 0) |
304 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get attribute name"); |
305 | 0 | } |
306 | 0 | else if (H5VL_OBJECT_BY_IDX == get_name_args->loc_params.type) { |
307 | 0 | H5G_loc_t loc; |
308 | 0 | H5A_t *attr; |
309 | | |
310 | | /* check arguments */ |
311 | 0 | if (H5G_loc_real(obj, get_name_args->loc_params.obj_type, &loc) < 0) |
312 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object"); |
313 | | |
314 | | /* Open the attribute on the object header */ |
315 | 0 | if (NULL == (attr = H5A__open_by_idx(&loc, get_name_args->loc_params.loc_data.loc_by_idx.name, |
316 | 0 | get_name_args->loc_params.loc_data.loc_by_idx.idx_type, |
317 | 0 | get_name_args->loc_params.loc_data.loc_by_idx.order, |
318 | 0 | get_name_args->loc_params.loc_data.loc_by_idx.n))) |
319 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute"); |
320 | | |
321 | | /* Get the length of the name */ |
322 | 0 | *get_name_args->attr_name_len = strlen(attr->shared->name); |
323 | | |
324 | | /* Copy the name into the user's buffer, if given */ |
325 | 0 | if (get_name_args->buf) { |
326 | 0 | strncpy(get_name_args->buf, attr->shared->name, |
327 | 0 | MIN((*get_name_args->attr_name_len + 1), get_name_args->buf_size)); |
328 | 0 | if (*get_name_args->attr_name_len >= get_name_args->buf_size) |
329 | 0 | get_name_args->buf[get_name_args->buf_size - 1] = '\0'; |
330 | 0 | } /* end if */ |
331 | | |
332 | | /* Release resources */ |
333 | 0 | if (attr && H5A__close(attr) < 0) |
334 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute"); |
335 | 0 | } |
336 | 0 | else |
337 | 0 | HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't get name of attr"); |
338 | | |
339 | 0 | break; |
340 | 0 | } |
341 | | |
342 | | /* H5Aget_info */ |
343 | 0 | case H5VL_ATTR_GET_INFO: { |
344 | 0 | H5VL_attr_get_info_args_t *get_info_args = &args->args.get_info; |
345 | 0 | H5A_t *attr = NULL; |
346 | |
|
347 | 0 | if (H5VL_OBJECT_BY_SELF == get_info_args->loc_params.type) { |
348 | 0 | attr = (H5A_t *)obj; |
349 | 0 | if (H5A__get_info(attr, get_info_args->ainfo) < 0) |
350 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get attribute info"); |
351 | 0 | } |
352 | 0 | else if (H5VL_OBJECT_BY_NAME == get_info_args->loc_params.type) { |
353 | 0 | H5G_loc_t loc; |
354 | | |
355 | | /* check arguments */ |
356 | 0 | if (H5G_loc_real(obj, get_info_args->loc_params.obj_type, &loc) < 0) |
357 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object"); |
358 | | |
359 | | /* Open the attribute on the object header */ |
360 | 0 | if (NULL == |
361 | 0 | (attr = H5A__open_by_name(&loc, get_info_args->loc_params.loc_data.loc_by_name.name, |
362 | 0 | get_info_args->attr_name))) |
363 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute"); |
364 | | |
365 | | /* Get the attribute information */ |
366 | 0 | if (H5A__get_info(attr, get_info_args->ainfo) < 0) |
367 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info"); |
368 | | |
369 | | /* Release resources */ |
370 | 0 | if (attr && H5A__close(attr) < 0) |
371 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute"); |
372 | 0 | } |
373 | 0 | else if (H5VL_OBJECT_BY_IDX == get_info_args->loc_params.type) { |
374 | 0 | H5G_loc_t loc; |
375 | | |
376 | | /* check arguments */ |
377 | 0 | if (H5G_loc_real(obj, get_info_args->loc_params.obj_type, &loc) < 0) |
378 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object"); |
379 | | |
380 | | /* Open the attribute on the object header */ |
381 | 0 | if (NULL == (attr = H5A__open_by_idx(&loc, get_info_args->loc_params.loc_data.loc_by_idx.name, |
382 | 0 | get_info_args->loc_params.loc_data.loc_by_idx.idx_type, |
383 | 0 | get_info_args->loc_params.loc_data.loc_by_idx.order, |
384 | 0 | get_info_args->loc_params.loc_data.loc_by_idx.n))) |
385 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute"); |
386 | | |
387 | | /* Get the attribute information */ |
388 | 0 | if (H5A__get_info(attr, get_info_args->ainfo) < 0) |
389 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info"); |
390 | | |
391 | | /* Release resources */ |
392 | 0 | if (attr && H5A__close(attr) < 0) |
393 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute"); |
394 | 0 | } |
395 | 0 | else |
396 | 0 | HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't get name of attr"); |
397 | | |
398 | 0 | break; |
399 | 0 | } |
400 | | |
401 | 0 | case H5VL_ATTR_GET_STORAGE_SIZE: { |
402 | 0 | H5A_t *attr = (H5A_t *)obj; |
403 | | |
404 | | /* Set storage size */ |
405 | 0 | *args->args.get_storage_size.data_size = attr->shared->data_size; |
406 | 0 | break; |
407 | 0 | } |
408 | | |
409 | 0 | default: |
410 | 0 | HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from attr"); |
411 | 61 | } /* end switch */ |
412 | | |
413 | 61 | done: |
414 | 61 | FUNC_LEAVE_NOAPI(ret_value) |
415 | 61 | } /* end H5VL__native_attr_get() */ |
416 | | |
417 | | /*------------------------------------------------------------------------- |
418 | | * Function: H5VL__native_attr_specific |
419 | | * |
420 | | * Purpose: Handles the attribute specific callback |
421 | | * |
422 | | * Return: SUCCEED/FAIL |
423 | | * |
424 | | *------------------------------------------------------------------------- |
425 | | */ |
426 | | herr_t |
427 | | H5VL__native_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_specific_args_t *args, |
428 | | hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
429 | 107 | { |
430 | 107 | H5G_loc_t loc; |
431 | 107 | herr_t ret_value = SUCCEED; /* Return value */ |
432 | | |
433 | 107 | FUNC_ENTER_PACKAGE |
434 | | |
435 | | /* Get location for passed-in object */ |
436 | 107 | if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) |
437 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object"); |
438 | | |
439 | 107 | switch (args->op_type) { |
440 | | /* H5Adelete/delete_by_name */ |
441 | 0 | case H5VL_ATTR_DELETE: { |
442 | 0 | if (H5VL_OBJECT_BY_SELF == loc_params->type) { |
443 | | /* Delete the attribute from the location */ |
444 | 0 | if (H5O__attr_remove(loc.oloc, args->args.del.name) < 0) |
445 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute"); |
446 | 0 | } /* end if */ |
447 | 0 | else if (H5VL_OBJECT_BY_NAME == loc_params->type) { |
448 | | /* Delete the attribute */ |
449 | 0 | if (H5A__delete_by_name(&loc, loc_params->loc_data.loc_by_name.name, args->args.del.name) < 0) |
450 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute"); |
451 | 0 | } /* end else-if */ |
452 | 0 | else |
453 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown attribute delete location"); |
454 | 0 | break; |
455 | 0 | } |
456 | | |
457 | | /* H5Adelete_by_idx */ |
458 | 0 | case H5VL_ATTR_DELETE_BY_IDX: { |
459 | 0 | H5VL_attr_delete_by_idx_args_t *del_by_idx_args = |
460 | 0 | &args->args.delete_by_idx; /* Arguments to delete_by_idx operation */ |
461 | |
|
462 | 0 | if (H5VL_OBJECT_BY_NAME == loc_params->type) { |
463 | | /* Delete the attribute from the location */ |
464 | 0 | if (H5A__delete_by_idx(&loc, loc_params->loc_data.loc_by_name.name, del_by_idx_args->idx_type, |
465 | 0 | del_by_idx_args->order, del_by_idx_args->n) < 0) |
466 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute"); |
467 | 0 | } /* end if */ |
468 | 0 | else |
469 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown attribute delete_by_idx location"); |
470 | 0 | break; |
471 | 0 | } |
472 | | |
473 | | /* H5Aexists/exists_by_name */ |
474 | 107 | case H5VL_ATTR_EXISTS: { |
475 | 107 | if (loc_params->type == H5VL_OBJECT_BY_SELF) { |
476 | | /* Check if the attribute exists */ |
477 | 0 | if (H5O__attr_exists(loc.oloc, args->args.exists.name, args->args.exists.exists) < 0) |
478 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to determine if attribute exists"); |
479 | 0 | } /* end if */ |
480 | 107 | else if (loc_params->type == H5VL_OBJECT_BY_NAME) { |
481 | | /* Check if the attribute exists */ |
482 | 107 | if (H5A__exists_by_name(loc, loc_params->loc_data.loc_by_name.name, args->args.exists.name, |
483 | 107 | args->args.exists.exists) < 0) |
484 | 12 | HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to determine if attribute exists"); |
485 | 107 | } /* end else-if */ |
486 | 0 | else |
487 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown parameters"); |
488 | 95 | break; |
489 | 107 | } |
490 | | |
491 | | /* H5Aiterate/iterate_by_name */ |
492 | 95 | case H5VL_ATTR_ITER: { |
493 | 0 | H5VL_attr_iterate_args_t *iter_args = &args->args.iterate; /* Arguments to iterate operation */ |
494 | 0 | static const char *self_name = "."; /* Name for 'self' location */ |
495 | 0 | const char *loc_name; /* Location name */ |
496 | | |
497 | | /* Set correct name, for type of location */ |
498 | 0 | if (loc_params->type == H5VL_OBJECT_BY_SELF) /* H5Aiterate2 */ |
499 | 0 | loc_name = self_name; |
500 | 0 | else if (loc_params->type == H5VL_OBJECT_BY_NAME) /* H5Aiterate_by_name */ |
501 | 0 | loc_name = loc_params->loc_data.loc_by_name.name; |
502 | 0 | else |
503 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unsupported location type"); |
504 | | |
505 | | /* Iterate over attributes */ |
506 | 0 | if ((ret_value = H5A__iterate(&loc, loc_name, iter_args->idx_type, iter_args->order, |
507 | 0 | iter_args->idx, iter_args->op, iter_args->op_data)) < 0) |
508 | 0 | HERROR(H5E_ATTR, H5E_BADITER, "attribute iteration failed"); |
509 | 0 | break; |
510 | 0 | } |
511 | | |
512 | | /* H5Arename/rename_by_name */ |
513 | 0 | case H5VL_ATTR_RENAME: { |
514 | 0 | if (loc_params->type == H5VL_OBJECT_BY_SELF) { /* H5Arename */ |
515 | | /* Call attribute rename routine */ |
516 | 0 | if (H5O__attr_rename(loc.oloc, args->args.rename.old_name, args->args.rename.new_name) < 0) |
517 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute"); |
518 | 0 | } /* end if */ |
519 | 0 | else if (loc_params->type == H5VL_OBJECT_BY_NAME) { /* H5Arename_by_name */ |
520 | | /* Call attribute rename routine */ |
521 | 0 | if (H5A__rename_by_name(loc, loc_params->loc_data.loc_by_name.name, |
522 | 0 | args->args.rename.old_name, args->args.rename.new_name) < 0) |
523 | 0 | HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute"); |
524 | 0 | } /* end else-if */ |
525 | 0 | else |
526 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown attribute rename parameters"); |
527 | 0 | break; |
528 | 0 | } |
529 | | |
530 | 0 | default: |
531 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation"); |
532 | 107 | } /* end switch */ |
533 | | |
534 | 107 | done: |
535 | 107 | FUNC_LEAVE_NOAPI(ret_value) |
536 | 107 | } /* end H5VL__native_attr_specific() */ |
537 | | |
538 | | /*------------------------------------------------------------------------- |
539 | | * Function: H5VL__native_attr_optional |
540 | | * |
541 | | * Purpose: Handles the attribute optional callback |
542 | | * |
543 | | * Return: SUCCEED/FAIL |
544 | | * |
545 | | *------------------------------------------------------------------------- |
546 | | */ |
547 | | herr_t |
548 | | H5VL__native_attr_optional(void H5_ATTR_UNUSED *obj, H5VL_optional_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id, |
549 | | void H5_ATTR_UNUSED **req) |
550 | 0 | { |
551 | | #ifndef H5_NO_DEPRECATED_SYMBOLS |
552 | | H5VL_native_attr_optional_args_t *opt_args = args->args; /* Pointer to native operation's arguments */ |
553 | | #endif /* H5_NO_DEPRECATED_SYMBOLS */ |
554 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
555 | |
|
556 | 0 | FUNC_ENTER_PACKAGE |
557 | |
|
558 | 0 | switch (args->op_type) { |
559 | | #ifndef H5_NO_DEPRECATED_SYMBOLS |
560 | | case H5VL_NATIVE_ATTR_ITERATE_OLD: { |
561 | | H5VL_native_attr_iterate_old_t *iter_args = &opt_args->iterate_old; |
562 | | |
563 | | /* Call the actual iteration routine */ |
564 | | if ((ret_value = H5A__iterate_old(iter_args->loc_id, iter_args->attr_num, iter_args->op, |
565 | | iter_args->op_data)) < 0) |
566 | | HERROR(H5E_VOL, H5E_BADITER, "error iterating over attributes"); |
567 | | |
568 | | break; |
569 | | } |
570 | | #endif /* H5_NO_DEPRECATED_SYMBOLS */ |
571 | | |
572 | 0 | default: |
573 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid optional operation"); |
574 | 0 | } /* end switch */ |
575 | | |
576 | 0 | done: |
577 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
578 | 0 | } /* end H5VL__native_attr_optional() */ |
579 | | |
580 | | /*------------------------------------------------------------------------- |
581 | | * Function: H5VL__native_attr_close |
582 | | * |
583 | | * Purpose: Handles the attribute close callback |
584 | | * |
585 | | * Return: Success: SUCCEED |
586 | | * Failure: FAIL (attribute will not be closed) |
587 | | * |
588 | | *------------------------------------------------------------------------- |
589 | | */ |
590 | | herr_t |
591 | | H5VL__native_attr_close(void *attr, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
592 | 64 | { |
593 | 64 | herr_t ret_value = SUCCEED; /* Return value */ |
594 | | |
595 | 64 | FUNC_ENTER_PACKAGE |
596 | | |
597 | 64 | if (H5A__close((H5A_t *)attr) < 0) |
598 | 0 | HGOTO_ERROR(H5E_SYM, H5E_CANTDEC, FAIL, "can't close attribute"); |
599 | | |
600 | 64 | done: |
601 | 64 | FUNC_LEAVE_NOAPI(ret_value) |
602 | 64 | } /* end H5VL__native_attr_close() */ |