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 LICENSE 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 | | /* Module Setup */ |
15 | | /****************/ |
16 | | |
17 | | #include "H5Dmodule.h" /* This source code file is part of the H5D module */ |
18 | | |
19 | | /***********/ |
20 | | /* Headers */ |
21 | | /***********/ |
22 | | #include "H5private.h" /* Generic Functions */ |
23 | | #include "H5CXprivate.h" /* API Contexts */ |
24 | | #include "H5Dpkg.h" /* Datasets */ |
25 | | #include "H5Eprivate.h" /* Error handling */ |
26 | | #include "H5ESprivate.h" /* Event Sets */ |
27 | | #include "H5FLprivate.h" /* Free lists */ |
28 | | #include "H5Iprivate.h" /* IDs */ |
29 | | #include "H5MMprivate.h" /* Memory management */ |
30 | | #include "H5VLprivate.h" /* Virtual Object Layer */ |
31 | | |
32 | | #include "H5VLnative_private.h" /* Native VOL connector */ |
33 | | |
34 | | /****************/ |
35 | | /* Local Macros */ |
36 | | /****************/ |
37 | | |
38 | | /******************/ |
39 | | /* Local Typedefs */ |
40 | | /******************/ |
41 | | |
42 | | /********************/ |
43 | | /* Local Prototypes */ |
44 | | /********************/ |
45 | | |
46 | | /* Helper routines for sync/async API calls */ |
47 | | static hid_t H5D__create_api_common(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, |
48 | | hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id, void **token_ptr, |
49 | | H5VL_object_t **_vol_obj_ptr); |
50 | | static hid_t H5D__open_api_common(hid_t loc_id, const char *name, hid_t dapl_id, void **token_ptr, |
51 | | H5VL_object_t **_vol_obj_ptr); |
52 | | static hid_t H5D__get_space_api_common(hid_t dset_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr); |
53 | | static herr_t H5D__read_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], |
54 | | hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **token_ptr, |
55 | | H5VL_object_t **_vol_obj_ptr); |
56 | | static herr_t H5D__write_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], |
57 | | hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **token_ptr, |
58 | | H5VL_object_t **_vol_obj_ptr); |
59 | | static herr_t H5D__set_extent_api_common(hid_t dset_id, const hsize_t size[], void **token_ptr, |
60 | | H5VL_object_t **_vol_obj_ptr); |
61 | | |
62 | | /*********************/ |
63 | | /* Package Variables */ |
64 | | /*********************/ |
65 | | |
66 | | /* Package initialization variable */ |
67 | | bool H5_PKG_INIT_VAR = false; |
68 | | |
69 | | /*****************************/ |
70 | | /* Library Private Variables */ |
71 | | /*****************************/ |
72 | | |
73 | | /* Declare extern free list to manage the H5S_sel_iter_t struct */ |
74 | | H5FL_EXTERN(H5S_sel_iter_t); |
75 | | |
76 | | /* Declare extern the free list to manage blocks of type conversion data */ |
77 | | H5FL_BLK_EXTERN(type_conv); |
78 | | |
79 | | /*******************/ |
80 | | /* Local Variables */ |
81 | | /*******************/ |
82 | | |
83 | | /*------------------------------------------------------------------------- |
84 | | * Function: H5D__create_api_common |
85 | | * |
86 | | * Purpose: This is the common function for creating HDF5 datasets. |
87 | | * |
88 | | * Return: Success: A dataset ID |
89 | | * Failure: H5I_INVALID_HID |
90 | | * |
91 | | *------------------------------------------------------------------------- |
92 | | */ |
93 | | static hid_t |
94 | | H5D__create_api_common(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t lcpl_id, |
95 | | hid_t dcpl_id, hid_t dapl_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) |
96 | 0 | { |
97 | 0 | void *dset = NULL; /* New dataset's info */ |
98 | 0 | H5VL_object_t *tmp_vol_obj = NULL; /* Object for loc_id */ |
99 | 0 | H5VL_object_t **vol_obj_ptr = |
100 | 0 | (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ |
101 | 0 | H5VL_loc_params_t loc_params; /* Location parameters for object access */ |
102 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
103 | |
|
104 | 0 | FUNC_ENTER_PACKAGE |
105 | | |
106 | | /* Check arguments */ |
107 | 0 | if (!name) |
108 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be NULL"); |
109 | 0 | if (!*name) |
110 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be an empty string"); |
111 | | |
112 | | /* Set up object access arguments */ |
113 | 0 | if (H5VL_setup_acc_args(loc_id, H5P_CLS_DACC, true, &dapl_id, vol_obj_ptr, &loc_params) < 0) |
114 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments"); |
115 | | |
116 | | /* Get link creation property list */ |
117 | 0 | if (H5P_DEFAULT == lcpl_id) |
118 | 0 | lcpl_id = H5P_LINK_CREATE_DEFAULT; |
119 | 0 | else if (true != H5P_isa_class(lcpl_id, H5P_LINK_CREATE)) |
120 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "lcpl_id is not a link creation property list"); |
121 | | |
122 | | /* Get dataset creation property list */ |
123 | 0 | if (H5P_DEFAULT == dcpl_id) |
124 | 0 | dcpl_id = H5P_DATASET_CREATE_DEFAULT; |
125 | 0 | else if (true != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE)) |
126 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, |
127 | 0 | "dcpl_id is not a dataset create property list ID"); |
128 | | |
129 | | /* Set the DCPL for the API context */ |
130 | 0 | H5CX_set_dcpl(dcpl_id); |
131 | | |
132 | | /* Set the LCPL for the API context */ |
133 | 0 | H5CX_set_lcpl(lcpl_id); |
134 | | |
135 | | /* Create the dataset */ |
136 | 0 | if (NULL == (dset = H5VL_dataset_create(*vol_obj_ptr, &loc_params, name, lcpl_id, type_id, space_id, |
137 | 0 | dcpl_id, dapl_id, H5P_DATASET_XFER_DEFAULT, token_ptr))) |
138 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, H5I_INVALID_HID, "unable to create dataset"); |
139 | | |
140 | | /* Get an ID for the dataset */ |
141 | 0 | if ((ret_value = H5VL_register(H5I_DATASET, dset, H5VL_OBJ_CONNECTOR(*vol_obj_ptr), true)) < 0) |
142 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register dataset"); |
143 | | |
144 | 0 | done: |
145 | 0 | if (H5I_INVALID_HID == ret_value) |
146 | 0 | if (dset && H5VL_dataset_close(*vol_obj_ptr, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
147 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release dataset"); |
148 | |
|
149 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
150 | 0 | } /* end H5D__create_api_common() */ |
151 | | |
152 | | /*------------------------------------------------------------------------- |
153 | | * Function: H5Dcreate2 |
154 | | * |
155 | | * Purpose: Creates a new dataset named NAME at LOC_ID, opens the |
156 | | * dataset for access, and associates with that dataset constant |
157 | | * and initial persistent properties including the type of each |
158 | | * datapoint as stored in the file (TYPE_ID), the size of the |
159 | | * dataset (SPACE_ID), and other initial miscellaneous |
160 | | * properties (DCPL_ID). |
161 | | * |
162 | | * All arguments are copied into the dataset, so the caller is |
163 | | * allowed to derive new types, dataspaces, and creation |
164 | | * parameters from the old ones and reuse them in calls to |
165 | | * create other datasets. |
166 | | * |
167 | | * Return: Success: The object ID of the new dataset. At this |
168 | | * point, the dataset is ready to receive its |
169 | | * raw data. Attempting to read raw data from |
170 | | * the dataset will probably return the fill |
171 | | * value. The dataset should be closed when the |
172 | | * caller is no longer interested in it. |
173 | | * |
174 | | * Failure: H5I_INVALID_HID |
175 | | * |
176 | | *------------------------------------------------------------------------- |
177 | | */ |
178 | | hid_t |
179 | | H5Dcreate2(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, |
180 | | hid_t dapl_id) |
181 | 0 | { |
182 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
183 | |
|
184 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
185 | | |
186 | | /* Create the dataset synchronously */ |
187 | 0 | if ((ret_value = H5D__create_api_common(loc_id, name, type_id, space_id, lcpl_id, dcpl_id, dapl_id, NULL, |
188 | 0 | NULL)) < 0) |
189 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, H5I_INVALID_HID, "unable to synchronously create dataset"); |
190 | | |
191 | 0 | done: |
192 | 0 | FUNC_LEAVE_API(ret_value) |
193 | 0 | } /* end H5Dcreate2() */ |
194 | | |
195 | | /*------------------------------------------------------------------------- |
196 | | * Function: H5Dcreate_async |
197 | | * |
198 | | * Purpose: Asynchronous version of H5Dcreate |
199 | | * |
200 | | * Return: Success: A dataset ID |
201 | | * Failure: H5I_INVALID_HID |
202 | | * |
203 | | *------------------------------------------------------------------------- |
204 | | */ |
205 | | hid_t |
206 | | H5Dcreate_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, |
207 | | hid_t type_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id, hid_t es_id) |
208 | 0 | { |
209 | 0 | H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ |
210 | 0 | void *token = NULL; /* Request token for async operation */ |
211 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
212 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
213 | |
|
214 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
215 | | |
216 | | /* Set up request token pointer for asynchronous operation */ |
217 | 0 | if (H5ES_NONE != es_id) |
218 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
219 | | |
220 | | /* Create the dataset asynchronously */ |
221 | 0 | if ((ret_value = H5D__create_api_common(loc_id, name, type_id, space_id, lcpl_id, dcpl_id, dapl_id, |
222 | 0 | token_ptr, &vol_obj)) < 0) |
223 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, H5I_INVALID_HID, "unable to asynchronously create dataset"); |
224 | | |
225 | | /* If a token was created, add the token to the event set */ |
226 | 0 | if (NULL != token) |
227 | | /* clang-format off */ |
228 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
229 | 0 | H5ARG_TRACE11(__func__, "*s*sIui*siiiiii", app_file, app_func, app_line, loc_id, name, type_id, space_id, lcpl_id, dcpl_id, dapl_id, es_id)) < 0) { |
230 | | /* clang-format on */ |
231 | 0 | if (H5I_dec_app_ref_always_close(ret_value) < 0) |
232 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, H5I_INVALID_HID, "can't decrement count on dataset ID"); |
233 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set"); |
234 | 0 | } /* end if */ |
235 | | |
236 | 0 | done: |
237 | 0 | FUNC_LEAVE_API(ret_value) |
238 | 0 | } /* end H5Dcreate_async() */ |
239 | | |
240 | | /*------------------------------------------------------------------------- |
241 | | * Function: H5Dcreate_anon |
242 | | * |
243 | | * Purpose: Creates a new dataset named NAME at LOC_ID, opens the |
244 | | * dataset for access, and associates with that dataset constant |
245 | | * and initial persistent properties including the type of each |
246 | | * datapoint as stored in the file (TYPE_ID), the size of the |
247 | | * dataset (SPACE_ID), and other initial miscellaneous |
248 | | * properties (DCPL_ID). |
249 | | * |
250 | | * All arguments are copied into the dataset, so the caller is |
251 | | * allowed to derive new types, dataspaces, and creation |
252 | | * parameters from the old ones and reuse them in calls to |
253 | | * create other datasets. |
254 | | * |
255 | | * The resulting ID should be linked into the file with |
256 | | * H5Olink or it will be deleted when closed. |
257 | | * |
258 | | * Return: Success: The object ID of the new dataset. At this |
259 | | * point, the dataset is ready to receive its |
260 | | * raw data. Attempting to read raw data from |
261 | | * the dataset will probably return the fill |
262 | | * value. The dataset should be linked into |
263 | | * the group hierarchy before being closed or |
264 | | * it will be deleted. The dataset should be |
265 | | * closed when the caller is no longer interested |
266 | | * in it. |
267 | | * |
268 | | * Failure: H5I_INVALID_HID |
269 | | * |
270 | | *------------------------------------------------------------------------- |
271 | | */ |
272 | | hid_t |
273 | | H5Dcreate_anon(hid_t loc_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id) |
274 | 0 | { |
275 | 0 | void *dset = NULL; /* dset object from VOL connector */ |
276 | 0 | H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ |
277 | 0 | H5VL_loc_params_t loc_params; /* Location parameters for object access */ |
278 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
279 | |
|
280 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
281 | | |
282 | | /* Check arguments */ |
283 | 0 | if (H5P_DEFAULT == dcpl_id) |
284 | 0 | dcpl_id = H5P_DATASET_CREATE_DEFAULT; |
285 | 0 | else if (true != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE)) |
286 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not dataset create property list ID"); |
287 | | |
288 | 0 | if (H5P_DEFAULT == dapl_id) |
289 | 0 | dapl_id = H5P_DATASET_ACCESS_DEFAULT; |
290 | 0 | else if (true != H5P_isa_class(dapl_id, H5P_DATASET_ACCESS)) |
291 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not dataset access property list ID"); |
292 | | |
293 | | /* Set the DCPL for the API context */ |
294 | 0 | H5CX_set_dcpl(dcpl_id); |
295 | | |
296 | | /* Verify access property list and set up collective metadata if appropriate */ |
297 | 0 | if (H5CX_set_apl(&dapl_id, H5P_CLS_DACC, loc_id, true) < 0) |
298 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info"); |
299 | | |
300 | | /* get the location object */ |
301 | 0 | if (NULL == (vol_obj = H5VL_vol_object(loc_id))) |
302 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier"); |
303 | | |
304 | | /* Set location parameters */ |
305 | 0 | loc_params.type = H5VL_OBJECT_BY_SELF; |
306 | 0 | loc_params.obj_type = H5I_get_type(loc_id); |
307 | | |
308 | | /* Create the dataset */ |
309 | 0 | if (NULL == |
310 | 0 | (dset = H5VL_dataset_create(vol_obj, &loc_params, NULL, H5P_LINK_CREATE_DEFAULT, type_id, space_id, |
311 | 0 | dcpl_id, dapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) |
312 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, H5I_INVALID_HID, "unable to create dataset"); |
313 | | |
314 | | /* Get an ID for the dataset */ |
315 | 0 | if ((ret_value = H5VL_register(H5I_DATASET, dset, H5VL_OBJ_CONNECTOR(vol_obj), true)) < 0) |
316 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register dataset"); |
317 | | |
318 | 0 | done: |
319 | | /* Cleanup on failure */ |
320 | 0 | if (H5I_INVALID_HID == ret_value) |
321 | 0 | if (dset && H5VL_dataset_close(vol_obj, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
322 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release dataset"); |
323 | |
|
324 | 0 | FUNC_LEAVE_API(ret_value) |
325 | 0 | } /* end H5Dcreate_anon() */ |
326 | | |
327 | | /*------------------------------------------------------------------------- |
328 | | * Function: H5D__open_api_common |
329 | | * |
330 | | * Purpose: This is the common function for opening a dataset |
331 | | * |
332 | | * Return: Success: Object ID of the dataset |
333 | | * Failure: H5I_INVALID_HID |
334 | | * |
335 | | *------------------------------------------------------------------------- |
336 | | */ |
337 | | static hid_t |
338 | | H5D__open_api_common(hid_t loc_id, const char *name, hid_t dapl_id, void **token_ptr, |
339 | | H5VL_object_t **_vol_obj_ptr) |
340 | 0 | { |
341 | 0 | void *dset = NULL; /* dset object from VOL connector */ |
342 | 0 | H5VL_object_t *tmp_vol_obj = NULL; /* Object for loc_id */ |
343 | 0 | H5VL_object_t **vol_obj_ptr = |
344 | 0 | (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ |
345 | 0 | H5VL_loc_params_t loc_params; /* Location parameters for object access */ |
346 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
347 | |
|
348 | 0 | FUNC_ENTER_PACKAGE |
349 | | |
350 | | /* Check args */ |
351 | 0 | if (!name) |
352 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be NULL"); |
353 | 0 | if (!*name) |
354 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "name parameter cannot be an empty string"); |
355 | | |
356 | | /* Set up object access arguments */ |
357 | 0 | if (H5VL_setup_acc_args(loc_id, H5P_CLS_DACC, false, &dapl_id, vol_obj_ptr, &loc_params) < 0) |
358 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments"); |
359 | | |
360 | | /* Open the dataset */ |
361 | 0 | if (NULL == (dset = H5VL_dataset_open(*vol_obj_ptr, &loc_params, name, dapl_id, H5P_DATASET_XFER_DEFAULT, |
362 | 0 | token_ptr))) |
363 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open dataset"); |
364 | | |
365 | | /* Register an atom for the dataset */ |
366 | 0 | if ((ret_value = H5VL_register(H5I_DATASET, dset, H5VL_OBJ_CONNECTOR(*vol_obj_ptr), true)) < 0) |
367 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register dataset ID"); |
368 | | |
369 | 0 | done: |
370 | 0 | if (H5I_INVALID_HID == ret_value) |
371 | 0 | if (dset && H5VL_dataset_close(*vol_obj_ptr, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
372 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, H5I_INVALID_HID, "unable to release dataset"); |
373 | |
|
374 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
375 | 0 | } /* H5D__open_api_common() */ |
376 | | |
377 | | /*------------------------------------------------------------------------- |
378 | | * Function: H5Dopen2 |
379 | | * |
380 | | * Purpose: Finds a dataset named NAME at LOC_ID, opens it, and returns |
381 | | * its ID. The dataset should be close when the caller is no |
382 | | * longer interested in it. |
383 | | * |
384 | | * Takes a dataset access property list |
385 | | * |
386 | | * Return: Success: Object ID of the dataset |
387 | | * |
388 | | * Failure: H5I_INVALID_HID |
389 | | * |
390 | | *------------------------------------------------------------------------- |
391 | | */ |
392 | | hid_t |
393 | | H5Dopen2(hid_t loc_id, const char *name, hid_t dapl_id) |
394 | 0 | { |
395 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
396 | |
|
397 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
398 | | |
399 | | /* Open the dataset synchronously */ |
400 | 0 | if ((ret_value = H5D__open_api_common(loc_id, name, dapl_id, NULL, NULL)) < 0) |
401 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to synchronously open dataset"); |
402 | | |
403 | 0 | done: |
404 | 0 | FUNC_LEAVE_API(ret_value) |
405 | 0 | } /* end H5Dopen2() */ |
406 | | |
407 | | /*------------------------------------------------------------------------- |
408 | | * Function: H5Dopen_async |
409 | | * |
410 | | * Purpose: Asynchronous version of H5Dopen2 |
411 | | * |
412 | | * Return: Success: A group ID |
413 | | * Failure: H5I_INVALID_HID |
414 | | * |
415 | | *------------------------------------------------------------------------- |
416 | | */ |
417 | | hid_t |
418 | | H5Dopen_async(const char *app_file, const char *app_func, unsigned app_line, hid_t loc_id, const char *name, |
419 | | hid_t dapl_id, hid_t es_id) |
420 | 0 | { |
421 | 0 | H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ |
422 | 0 | void *token = NULL; /* Request token for async operation */ |
423 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
424 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
425 | |
|
426 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
427 | | |
428 | | /* Set up request token pointer for asynchronous operation */ |
429 | 0 | if (H5ES_NONE != es_id) |
430 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
431 | | |
432 | | /* Open the dataset asynchronously */ |
433 | 0 | if ((ret_value = H5D__open_api_common(loc_id, name, dapl_id, token_ptr, &vol_obj)) < 0) |
434 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to asynchronously open dataset"); |
435 | | |
436 | | /* If a token was created, add the token to the event set */ |
437 | 0 | if (NULL != token) |
438 | | /* clang-format off */ |
439 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
440 | 0 | H5ARG_TRACE7(__func__, "*s*sIui*sii", app_file, app_func, app_line, loc_id, name, dapl_id, es_id)) < 0) { |
441 | | /* clang-format on */ |
442 | 0 | if (H5I_dec_app_ref_always_close(ret_value) < 0) |
443 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, H5I_INVALID_HID, "can't decrement count on dataset ID"); |
444 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set"); |
445 | 0 | } /* end if */ |
446 | | |
447 | 0 | done: |
448 | 0 | FUNC_LEAVE_API(ret_value) |
449 | 0 | } /* end H5Dopen_async() */ |
450 | | |
451 | | /*------------------------------------------------------------------------- |
452 | | * Function: H5Dclose |
453 | | * |
454 | | * Purpose: Closes access to a dataset and releases resources used by |
455 | | * it. It is illegal to subsequently use that same dataset |
456 | | * ID in calls to other dataset functions. |
457 | | * |
458 | | * Return: Non-negative on success/Negative on failure |
459 | | * |
460 | | *------------------------------------------------------------------------- |
461 | | */ |
462 | | herr_t |
463 | | H5Dclose(hid_t dset_id) |
464 | 0 | { |
465 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
466 | |
|
467 | 0 | FUNC_ENTER_API(FAIL) |
468 | | |
469 | | /* Check args */ |
470 | 0 | if (H5I_DATASET != H5I_get_type(dset_id)) |
471 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset ID"); |
472 | | |
473 | | /* Decrement the counter on the dataset. It will be freed if the count |
474 | | * reaches zero. |
475 | | */ |
476 | 0 | if (H5I_dec_app_ref_always_close(dset_id) < 0) |
477 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "can't decrement count on dataset ID"); |
478 | | |
479 | 0 | done: |
480 | 0 | FUNC_LEAVE_API(ret_value) |
481 | 0 | } /* end H5Dclose() */ |
482 | | |
483 | | /*------------------------------------------------------------------------- |
484 | | * Function: H5Dclose_async |
485 | | * |
486 | | * Purpose: Asynchronous version of H5Dclose |
487 | | * |
488 | | * Return: Non-negative on success/Negative on failure |
489 | | * |
490 | | *------------------------------------------------------------------------- |
491 | | */ |
492 | | herr_t |
493 | | H5Dclose_async(const char *app_file, const char *app_func, unsigned app_line, hid_t dset_id, hid_t es_id) |
494 | 0 | { |
495 | 0 | void *token = NULL; /* Request token for async operation */ |
496 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
497 | 0 | H5VL_object_t *vol_obj = NULL; /* VOL object of dset_id */ |
498 | 0 | H5VL_connector_t *connector = NULL; /* VOL connector */ |
499 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
500 | |
|
501 | 0 | FUNC_ENTER_API(FAIL) |
502 | | |
503 | | /* Check args */ |
504 | 0 | if (H5I_DATASET != H5I_get_type(dset_id)) |
505 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset ID"); |
506 | | |
507 | | /* Get dataset object's connector */ |
508 | 0 | if (NULL == (vol_obj = H5VL_vol_object(dset_id))) |
509 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get VOL object for dataset"); |
510 | | |
511 | | /* Prepare for possible asynchronous operation */ |
512 | 0 | if (H5ES_NONE != es_id) { |
513 | | /* Increase connector's refcount, so it doesn't get closed if closing |
514 | | * the dataset closes the file */ |
515 | 0 | connector = H5VL_OBJ_CONNECTOR(vol_obj); |
516 | 0 | H5VL_conn_inc_rc(connector); |
517 | | |
518 | | /* Point at token for operation to set up */ |
519 | 0 | token_ptr = &token; |
520 | 0 | } /* end if */ |
521 | | |
522 | | /* Decrement the counter on the dataset. It will be freed if the count |
523 | | * reaches zero. |
524 | | */ |
525 | 0 | if (H5I_dec_app_ref_always_close_async(dset_id, token_ptr) < 0) |
526 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "can't decrement count on dataset ID"); |
527 | | |
528 | | /* If a token was created, add the token to the event set */ |
529 | 0 | if (NULL != token) |
530 | | /* clang-format off */ |
531 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
532 | 0 | H5ARG_TRACE5(__func__, "*s*sIuii", app_file, app_func, app_line, dset_id, es_id)) < 0) |
533 | | /* clang-format on */ |
534 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set"); |
535 | | |
536 | 0 | done: |
537 | 0 | if (connector && H5VL_conn_dec_rc(connector) < 0) |
538 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "can't decrement ref count on connector"); |
539 | |
|
540 | 0 | FUNC_LEAVE_API(ret_value) |
541 | 0 | } /* end H5Dclose_async() */ |
542 | | |
543 | | /*------------------------------------------------------------------------- |
544 | | * Function: H5D__get_space_api_common |
545 | | * |
546 | | * Purpose: This is the common function for getting a dataset's dataspace |
547 | | * |
548 | | * Return: Success: ID for a copy of the dataspace. |
549 | | * Failure: H5I_INVALID_HID |
550 | | * |
551 | | *------------------------------------------------------------------------- |
552 | | */ |
553 | | static hid_t |
554 | | H5D__get_space_api_common(hid_t dset_id, void **token_ptr, H5VL_object_t **_vol_obj_ptr) |
555 | 0 | { |
556 | 0 | H5VL_object_t *tmp_vol_obj = NULL; /* Object for loc_id */ |
557 | 0 | H5VL_object_t **vol_obj_ptr = |
558 | 0 | (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ |
559 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
560 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
561 | |
|
562 | 0 | FUNC_ENTER_PACKAGE |
563 | | |
564 | | /* Check args */ |
565 | 0 | if (NULL == (*vol_obj_ptr = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
566 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid dataset identifier"); |
567 | | |
568 | | /* Set up VOL callback arguments */ |
569 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_SPACE; |
570 | 0 | vol_cb_args.args.get_space.space_id = H5I_INVALID_HID; |
571 | | |
572 | | /* Get the dataspace */ |
573 | 0 | if (H5VL_dataset_get(*vol_obj_ptr, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, token_ptr) < 0) |
574 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataspace"); |
575 | | |
576 | | /* Set return value */ |
577 | 0 | ret_value = vol_cb_args.args.get_space.space_id; |
578 | |
|
579 | 0 | done: |
580 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
581 | 0 | } /* H5D__get_space_api_common() */ |
582 | | |
583 | | /*------------------------------------------------------------------------- |
584 | | * Function: H5Dget_space |
585 | | * |
586 | | * Purpose: Returns a copy of the file dataspace for a dataset. |
587 | | * |
588 | | * Return: Success: ID for a copy of the dataspace. The data |
589 | | * space should be released by calling |
590 | | * H5Sclose(). |
591 | | * |
592 | | * Failure: H5I_INVALID_HID |
593 | | * |
594 | | *------------------------------------------------------------------------- |
595 | | */ |
596 | | hid_t |
597 | | H5Dget_space(hid_t dset_id) |
598 | 0 | { |
599 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
600 | |
|
601 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
602 | | |
603 | | /* Get the dataset's dataspace synchronously */ |
604 | 0 | if ((ret_value = H5D__get_space_api_common(dset_id, NULL, NULL)) < 0) |
605 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to synchronously get dataspace"); |
606 | | |
607 | 0 | done: |
608 | 0 | FUNC_LEAVE_API(ret_value) |
609 | 0 | } /* end H5Dget_space() */ |
610 | | |
611 | | /*------------------------------------------------------------------------- |
612 | | * Function: H5Dget_space_async |
613 | | * |
614 | | * Purpose: Asynchronous version of H5Dget_space |
615 | | * |
616 | | * Return: Success: ID for a copy of the dataspace. The data |
617 | | * space should be released by calling |
618 | | * H5Sclose(). |
619 | | * |
620 | | * Failure: H5I_INVALID_HID |
621 | | * |
622 | | *------------------------------------------------------------------------- |
623 | | */ |
624 | | hid_t |
625 | | H5Dget_space_async(const char *app_file, const char *app_func, unsigned app_line, hid_t dset_id, hid_t es_id) |
626 | 0 | { |
627 | 0 | H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ |
628 | 0 | void *token = NULL; /* Request token for async operation */ |
629 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
630 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
631 | |
|
632 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
633 | | |
634 | | /* Set up request token pointer for asynchronous operation */ |
635 | 0 | if (H5ES_NONE != es_id) |
636 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
637 | | |
638 | | /* Get the dataset's dataspace asynchronously */ |
639 | 0 | if ((ret_value = H5D__get_space_api_common(dset_id, token_ptr, &vol_obj)) < 0) |
640 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to asynchronously get dataspace"); |
641 | | |
642 | | /* If a token was created, add the token to the event set */ |
643 | 0 | if (NULL != token) |
644 | | /* clang-format off */ |
645 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
646 | 0 | H5ARG_TRACE5(__func__, "*s*sIuii", app_file, app_func, app_line, dset_id, es_id)) < 0) { |
647 | | /* clang-format on */ |
648 | 0 | if (H5I_dec_app_ref(ret_value) < 0) |
649 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, H5I_INVALID_HID, |
650 | 0 | "can't decrement count on dataspace ID"); |
651 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set"); |
652 | 0 | } /* end if */ |
653 | | |
654 | 0 | done: |
655 | 0 | FUNC_LEAVE_API(ret_value) |
656 | 0 | } /* end H5Dget_space_async() */ |
657 | | |
658 | | /*------------------------------------------------------------------------- |
659 | | * Function: H5Dget_space_status |
660 | | * |
661 | | * Purpose: Returns the status of dataspace allocation. |
662 | | * |
663 | | * Return: Non-negative on success/Negative on failure |
664 | | * |
665 | | *------------------------------------------------------------------------- |
666 | | */ |
667 | | herr_t |
668 | | H5Dget_space_status(hid_t dset_id, H5D_space_status_t *allocation /*out*/) |
669 | 0 | { |
670 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
671 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
672 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
673 | |
|
674 | 0 | FUNC_ENTER_API(FAIL) |
675 | | |
676 | | /* Check args */ |
677 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
678 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
679 | | |
680 | | /* Set up VOL callback arguments */ |
681 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_SPACE_STATUS; |
682 | 0 | vol_cb_args.args.get_space_status.status = allocation; |
683 | | |
684 | | /* Get dataspace status */ |
685 | 0 | if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
686 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to get space status"); |
687 | | |
688 | 0 | done: |
689 | 0 | FUNC_LEAVE_API(ret_value) |
690 | 0 | } /* H5Dget_space_status() */ |
691 | | |
692 | | /*------------------------------------------------------------------------- |
693 | | * Function: H5Dget_type |
694 | | * |
695 | | * Purpose: Returns a copy of the file datatype for a dataset. |
696 | | * |
697 | | * Return: Success: ID for a copy of the datatype. The data |
698 | | * type should be released by calling |
699 | | * H5Tclose(). |
700 | | * |
701 | | * Failure: H5I_INVALID_HID |
702 | | * |
703 | | *------------------------------------------------------------------------- |
704 | | */ |
705 | | hid_t |
706 | | H5Dget_type(hid_t dset_id) |
707 | 0 | { |
708 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
709 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
710 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
711 | |
|
712 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
713 | | |
714 | | /* Check args */ |
715 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
716 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid dataset identifier"); |
717 | | |
718 | | /* Set up VOL callback arguments */ |
719 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_TYPE; |
720 | 0 | vol_cb_args.args.get_type.type_id = H5I_INVALID_HID; |
721 | | |
722 | | /* Get the datatype */ |
723 | 0 | if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
724 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to get datatype"); |
725 | | |
726 | | /* Set return value */ |
727 | 0 | ret_value = vol_cb_args.args.get_type.type_id; |
728 | |
|
729 | 0 | done: |
730 | 0 | FUNC_LEAVE_API(ret_value) |
731 | 0 | } /* end H5Dget_type() */ |
732 | | |
733 | | /*------------------------------------------------------------------------- |
734 | | * Function: H5Dget_create_plist |
735 | | * |
736 | | * Purpose: Returns a copy of the dataset creation property list. |
737 | | * |
738 | | * Return: Success: ID for a copy of the dataset creation |
739 | | * property list. The template should be |
740 | | * released by calling H5P_close(). |
741 | | * |
742 | | * Failure: H5I_INVALID_HID |
743 | | * |
744 | | *------------------------------------------------------------------------- |
745 | | */ |
746 | | hid_t |
747 | | H5Dget_create_plist(hid_t dset_id) |
748 | 0 | { |
749 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
750 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
751 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
752 | |
|
753 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
754 | | |
755 | | /* Check args */ |
756 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
757 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid dataset identifier"); |
758 | | |
759 | | /* Set up VOL callback arguments */ |
760 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_DCPL; |
761 | 0 | vol_cb_args.args.get_dcpl.dcpl_id = H5I_INVALID_HID; |
762 | | |
763 | | /* Get the dataset creation property list */ |
764 | 0 | if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
765 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataset creation properties"); |
766 | | |
767 | | /* Set return value */ |
768 | 0 | ret_value = vol_cb_args.args.get_dcpl.dcpl_id; |
769 | |
|
770 | 0 | done: |
771 | 0 | FUNC_LEAVE_API(ret_value) |
772 | 0 | } /* end H5Dget_create_plist() */ |
773 | | |
774 | | /*------------------------------------------------------------------------- |
775 | | * Function: H5Dget_access_plist |
776 | | * |
777 | | * Purpose: Returns a copy of the dataset access property list. |
778 | | * |
779 | | * Description: H5Dget_access_plist returns the dataset access property |
780 | | * list identifier of the specified dataset. |
781 | | * |
782 | | * The chunk cache parameters in the returned property lists will be |
783 | | * those used by the dataset. If the properties in the file access |
784 | | * property list were used to determine the dataset's chunk cache |
785 | | * configuration, then those properties will be present in the |
786 | | * returned dataset access property list. If the dataset does not |
787 | | * use a chunked layout, then the chunk cache properties will be set |
788 | | * to the default. The chunk cache properties in the returned list |
789 | | * are considered to be “set”, and any use of this list will override |
790 | | * the corresponding properties in the file's file access property |
791 | | * list. |
792 | | * |
793 | | * All link access properties in the returned list will be set to the |
794 | | * default values. |
795 | | * |
796 | | * Return: Success: ID for a copy of the dataset access |
797 | | * property list. The template should be |
798 | | * released by calling H5Pclose(). |
799 | | * |
800 | | * Failure: H5I_INVALID_HID |
801 | | * |
802 | | *------------------------------------------------------------------------- |
803 | | */ |
804 | | hid_t |
805 | | H5Dget_access_plist(hid_t dset_id) |
806 | 0 | { |
807 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
808 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
809 | 0 | hid_t ret_value = H5I_INVALID_HID; /* Return value */ |
810 | |
|
811 | 0 | FUNC_ENTER_API(H5I_INVALID_HID) |
812 | | |
813 | | /* Check args */ |
814 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
815 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid dataset identifier"); |
816 | | |
817 | | /* Set up VOL callback arguments */ |
818 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_DAPL; |
819 | 0 | vol_cb_args.args.get_dapl.dapl_id = H5I_INVALID_HID; |
820 | | |
821 | | /* Get the dataset access property list */ |
822 | 0 | if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
823 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataset access properties"); |
824 | | |
825 | | /* Set return value */ |
826 | 0 | ret_value = vol_cb_args.args.get_dapl.dapl_id; |
827 | |
|
828 | 0 | done: |
829 | 0 | FUNC_LEAVE_API(ret_value) |
830 | 0 | } /* end H5Dget_access_plist() */ |
831 | | |
832 | | /*------------------------------------------------------------------------- |
833 | | * Function: H5Dget_storage_size |
834 | | * |
835 | | * Purpose: Returns the amount of storage that is required for the |
836 | | * dataset. For chunked datasets this is the number of allocated |
837 | | * chunks times the chunk size. |
838 | | * |
839 | | * Return: Success: The amount of storage space allocated for the |
840 | | * dataset, not counting meta data. The return |
841 | | * value may be zero if no data has been stored. |
842 | | * |
843 | | * Failure: Zero |
844 | | * |
845 | | *------------------------------------------------------------------------- |
846 | | */ |
847 | | hsize_t |
848 | | H5Dget_storage_size(hid_t dset_id) |
849 | 0 | { |
850 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
851 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
852 | 0 | hsize_t storage_size = 0; /* Storage size of dataset */ |
853 | 0 | hsize_t ret_value = 0; /* Return value */ |
854 | |
|
855 | 0 | FUNC_ENTER_API(0) |
856 | | |
857 | | /* Check args */ |
858 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
859 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid dataset identifier"); |
860 | | |
861 | | /* Set up VOL callback arguments */ |
862 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_STORAGE_SIZE; |
863 | 0 | vol_cb_args.args.get_storage_size.storage_size = &storage_size; |
864 | | |
865 | | /* Get the storage size */ |
866 | 0 | if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
867 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, 0, "unable to get storage size"); |
868 | | |
869 | | /* Set return value */ |
870 | 0 | ret_value = storage_size; |
871 | |
|
872 | 0 | done: |
873 | 0 | FUNC_LEAVE_API(ret_value) |
874 | 0 | } /* end H5Dget_storage_size() */ |
875 | | |
876 | | /*------------------------------------------------------------------------- |
877 | | * Function: H5Dget_offset |
878 | | * |
879 | | * Purpose: Returns the address of dataset in file. |
880 | | * |
881 | | * Return: Success: The address of dataset |
882 | | * |
883 | | * Failure: HADDR_UNDEF (can also be a valid return value!) |
884 | | * |
885 | | *------------------------------------------------------------------------- |
886 | | */ |
887 | | haddr_t |
888 | | H5Dget_offset(hid_t dset_id) |
889 | 0 | { |
890 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
891 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
892 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
893 | 0 | haddr_t dset_offset = HADDR_UNDEF; /* Dataset's offset */ |
894 | 0 | haddr_t ret_value = HADDR_UNDEF; /* Return value */ |
895 | |
|
896 | 0 | FUNC_ENTER_API(HADDR_UNDEF) |
897 | | |
898 | | /* Check args */ |
899 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
900 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, HADDR_UNDEF, "invalid dataset identifier"); |
901 | | |
902 | | /* Set up VOL callback arguments */ |
903 | 0 | dset_opt_args.get_offset.offset = &dset_offset; |
904 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_OFFSET; |
905 | 0 | vol_cb_args.args = &dset_opt_args; |
906 | | |
907 | | /* Get the offset */ |
908 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
909 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, HADDR_UNDEF, "unable to get offset"); |
910 | | |
911 | | /* Set return value */ |
912 | 0 | ret_value = dset_offset; |
913 | |
|
914 | 0 | done: |
915 | 0 | FUNC_LEAVE_API(ret_value) |
916 | 0 | } /* end H5Dget_offset() */ |
917 | | |
918 | | /*------------------------------------------------------------------------- |
919 | | * Function: H5D__read_api_common |
920 | | * |
921 | | * Purpose: Common helper routine for sync/async dataset read operations. |
922 | | * |
923 | | * Return: SUCCEED/FAIL |
924 | | * |
925 | | *------------------------------------------------------------------------- |
926 | | */ |
927 | | static herr_t |
928 | | H5D__read_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], |
929 | | hid_t file_space_id[], hid_t dxpl_id, void *buf[], void **token_ptr, |
930 | | H5VL_object_t **_vol_obj_ptr) |
931 | 0 | { |
932 | 0 | H5VL_object_t *tmp_vol_obj = NULL; /* Object for loc_id */ |
933 | 0 | H5VL_object_t **vol_obj_ptr = |
934 | 0 | (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ |
935 | 0 | void *obj_local; /* Local buffer for obj */ |
936 | 0 | void **obj = &obj_local; /* Array of object pointers */ |
937 | 0 | H5VL_connector_t *connector; /* VOL connector pointer */ |
938 | 0 | size_t i; /* Local index variable */ |
939 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
940 | |
|
941 | 0 | FUNC_ENTER_PACKAGE |
942 | | |
943 | | /* Check arguments */ |
944 | 0 | if (count == 0) |
945 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "count must be greater than 0"); |
946 | 0 | if (!dset_id) |
947 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dset_id array not provided"); |
948 | 0 | if (!mem_type_id) |
949 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "mem_type_id array not provided"); |
950 | 0 | if (!mem_space_id) |
951 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "mem_space_id array not provided"); |
952 | 0 | if (!file_space_id) |
953 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file_space_id array not provided"); |
954 | 0 | if (!buf) |
955 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buf array not provided"); |
956 | | |
957 | | /* Allocate obj array if necessary */ |
958 | 0 | if (count > 1) |
959 | 0 | if (NULL == (obj = (void **)H5MM_malloc(count * sizeof(void *)))) |
960 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate space for object array"); |
961 | | |
962 | | /* Get vol_obj_ptr (return just the first dataset to caller if requested) */ |
963 | 0 | if (NULL == (*vol_obj_ptr = H5VL_vol_object_verify(dset_id[0], H5I_DATASET))) |
964 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id is not a dataset ID"); |
965 | | |
966 | | /* Save the connector of the first dataset. Unpack the connector and call |
967 | | * the "direct" read function here to avoid allocating an array of count |
968 | | * H5VL_object_ts. */ |
969 | 0 | connector = H5VL_OBJ_CONNECTOR(*vol_obj_ptr); |
970 | | |
971 | | /* Build obj array */ |
972 | 0 | obj[0] = H5VL_OBJ_DATA(*vol_obj_ptr); |
973 | 0 | for (i = 1; i < count; i++) { |
974 | 0 | htri_t cls_cmp; |
975 | | |
976 | | /* Get the object */ |
977 | 0 | if (NULL == (tmp_vol_obj = H5VL_vol_object_verify(dset_id[i], H5I_DATASET))) |
978 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id is not a dataset ID"); |
979 | 0 | obj[i] = H5VL_OBJ_DATA(tmp_vol_obj); |
980 | | |
981 | | /* Make sure the class matches */ |
982 | 0 | if ((cls_cmp = H5VL_conn_same_class(H5VL_OBJ_CONNECTOR(tmp_vol_obj), connector)) < 0) |
983 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOMPARE, FAIL, "can't compare VOL connectors"); |
984 | 0 | if (!cls_cmp) |
985 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, |
986 | 0 | "datasets are accessed through different VOL connectors and can't be used in the " |
987 | 0 | "same I/O call"); |
988 | 0 | } |
989 | | |
990 | | /* Get the default dataset transfer property list if the user didn't provide one */ |
991 | 0 | if (H5P_DEFAULT == dxpl_id) |
992 | 0 | dxpl_id = H5P_DATASET_XFER_DEFAULT; |
993 | 0 | else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) |
994 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms"); |
995 | | |
996 | | /* Read the data */ |
997 | 0 | if (H5VL_dataset_read(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, |
998 | 0 | token_ptr) < 0) |
999 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data"); |
1000 | | |
1001 | 0 | done: |
1002 | | /* Free memory */ |
1003 | 0 | if (obj != &obj_local) |
1004 | 0 | H5MM_free(obj); |
1005 | |
|
1006 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1007 | 0 | } /* end H5D__read_api_common() */ |
1008 | | |
1009 | | /*------------------------------------------------------------------------- |
1010 | | * Function: H5Dread |
1011 | | * |
1012 | | * Purpose: Reads (part of) a DSET from the file into application |
1013 | | * memory BUF. The part of the dataset to read is defined with |
1014 | | * MEM_SPACE_ID and FILE_SPACE_ID. The data points are |
1015 | | * converted from their file type to the MEM_TYPE_ID specified. |
1016 | | * Additional miscellaneous data transfer properties can be |
1017 | | * passed to this function with the PLIST_ID argument. |
1018 | | * |
1019 | | * The FILE_SPACE_ID can be the constant H5S_ALL which indicates |
1020 | | * that the entire file dataspace is to be referenced. |
1021 | | * |
1022 | | * The MEM_SPACE_ID can be the constant H5S_ALL in which case |
1023 | | * the memory dataspace is the same as the file dataspace |
1024 | | * defined when the dataset was created. The MEM_SPACE_ID can |
1025 | | * also be the constant H5S_BLOCK, which indicates that the |
1026 | | * buffer provided is a single contiguous block of memory, with |
1027 | | * the same # of elements as specified in the FILE_SPACE_ID |
1028 | | * selection. |
1029 | | * |
1030 | | * The number of elements in the memory dataspace must match |
1031 | | * the number of elements in the file dataspace. |
1032 | | * |
1033 | | * The PLIST_ID can be the constant H5P_DEFAULT in which |
1034 | | * case the default data transfer properties are used. |
1035 | | * |
1036 | | * Return: Non-negative on success/Negative on failure |
1037 | | * |
1038 | | *------------------------------------------------------------------------- |
1039 | | */ |
1040 | | herr_t |
1041 | | H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t dxpl_id, |
1042 | | void *buf /*out*/) |
1043 | 0 | { |
1044 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1045 | |
|
1046 | 0 | FUNC_ENTER_API(FAIL) |
1047 | | |
1048 | | /* Read the data */ |
1049 | 0 | if (H5D__read_api_common(1, &dset_id, &mem_type_id, &mem_space_id, &file_space_id, dxpl_id, &buf, NULL, |
1050 | 0 | NULL) < 0) |
1051 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't synchronously read data"); |
1052 | | |
1053 | 0 | done: |
1054 | 0 | FUNC_LEAVE_API(ret_value) |
1055 | 0 | } /* end H5Dread() */ |
1056 | | |
1057 | | /*------------------------------------------------------------------------- |
1058 | | * Function: H5Dread_async |
1059 | | * |
1060 | | * Purpose: Asynchronously read dataset elements. |
1061 | | * |
1062 | | * Return: Non-negative on success/Negative on failure |
1063 | | * |
1064 | | *------------------------------------------------------------------------- |
1065 | | */ |
1066 | | herr_t |
1067 | | H5Dread_async(const char *app_file, const char *app_func, unsigned app_line, hid_t dset_id, hid_t mem_type_id, |
1068 | | hid_t mem_space_id, hid_t file_space_id, hid_t dxpl_id, void *buf /*out*/, hid_t es_id) |
1069 | 0 | { |
1070 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset VOL object */ |
1071 | 0 | void *token = NULL; /* Request token for async operation */ |
1072 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
1073 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1074 | |
|
1075 | 0 | FUNC_ENTER_API(FAIL) |
1076 | | |
1077 | | /* Set up request token pointer for asynchronous operation */ |
1078 | 0 | if (H5ES_NONE != es_id) |
1079 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
1080 | | |
1081 | | /* Read the data */ |
1082 | 0 | if (H5D__read_api_common(1, &dset_id, &mem_type_id, &mem_space_id, &file_space_id, dxpl_id, &buf, |
1083 | 0 | token_ptr, &vol_obj) < 0) |
1084 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't asynchronously read data"); |
1085 | | |
1086 | | /* If a token was created, add the token to the event set */ |
1087 | 0 | if (NULL != token) |
1088 | | /* clang-format off */ |
1089 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
1090 | 0 | H5ARG_TRACE10(__func__, "*s*sIuiiiii*xi", app_file, app_func, app_line, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, es_id)) < 0) |
1091 | | /* clang-format on */ |
1092 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set"); |
1093 | | |
1094 | 0 | done: |
1095 | 0 | FUNC_LEAVE_API(ret_value) |
1096 | 0 | } /* end H5Dread_async() */ |
1097 | | |
1098 | | /*------------------------------------------------------------------------- |
1099 | | * Function: H5Dread_multi |
1100 | | * |
1101 | | * Purpose: Multi-version of H5Dread(), which reads selections from |
1102 | | * multiple datasets from a file into application memory BUFS. |
1103 | | * |
1104 | | * Return: Non-negative on success/Negative on failure |
1105 | | * |
1106 | | *------------------------------------------------------------------------- |
1107 | | */ |
1108 | | herr_t |
1109 | | H5Dread_multi(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], hid_t file_space_id[], |
1110 | | hid_t dxpl_id, void *buf[] /*out*/) |
1111 | 0 | { |
1112 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1113 | |
|
1114 | 0 | FUNC_ENTER_API(FAIL) |
1115 | |
|
1116 | 0 | if (count == 0) |
1117 | 0 | HGOTO_DONE(SUCCEED); |
1118 | | |
1119 | | /* Read the data */ |
1120 | 0 | if (H5D__read_api_common(count, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, NULL, |
1121 | 0 | NULL) < 0) |
1122 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't synchronously read data"); |
1123 | | |
1124 | 0 | done: |
1125 | 0 | FUNC_LEAVE_API(ret_value) |
1126 | 0 | } /* end H5Dread_multi() */ |
1127 | | |
1128 | | /*------------------------------------------------------------------------- |
1129 | | * Function: H5Dread_multi_async |
1130 | | * |
1131 | | * Purpose: Asynchronously read dataset elements from multiple |
1132 | | * datasets. |
1133 | | * |
1134 | | * Return: Non-negative on success/Negative on failure |
1135 | | * |
1136 | | *------------------------------------------------------------------------- |
1137 | | */ |
1138 | | herr_t |
1139 | | H5Dread_multi_async(const char *app_file, const char *app_func, unsigned app_line, size_t count, |
1140 | | hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], hid_t file_space_id[], |
1141 | | hid_t dxpl_id, void *buf[] /*out*/, hid_t es_id) |
1142 | 0 | { |
1143 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset VOL object */ |
1144 | 0 | void *token = NULL; /* Request token for async operation */ |
1145 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
1146 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1147 | |
|
1148 | 0 | FUNC_ENTER_API(FAIL) |
1149 | | |
1150 | | /* Set up request token pointer for asynchronous operation */ |
1151 | 0 | if (H5ES_NONE != es_id) |
1152 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
1153 | | |
1154 | | /* Read the data */ |
1155 | 0 | if (H5D__read_api_common(count, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, |
1156 | 0 | token_ptr, &vol_obj) < 0) |
1157 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't asynchronously read data"); |
1158 | | |
1159 | | /* If a token was created, add the token to the event set */ |
1160 | 0 | if (NULL != token) |
1161 | | /* clang-format off */ |
1162 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
1163 | 0 | H5ARG_TRACE11(__func__, "*s*sIuz*i*i*i*ii**xi", app_file, app_func, app_line, count, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, es_id)) < 0) |
1164 | | /* clang-format on */ |
1165 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set"); |
1166 | | |
1167 | 0 | done: |
1168 | 0 | FUNC_LEAVE_API(ret_value) |
1169 | 0 | } /* end H5Dread_multi_async() */ |
1170 | | |
1171 | | /*------------------------------------------------------------------------- |
1172 | | * Function: H5Dread_chunk2 |
1173 | | * |
1174 | | * Purpose: Reads an entire chunk from the file directly. |
1175 | | * |
1176 | | * Return: Non-negative on success/Negative on failure |
1177 | | * |
1178 | | *--------------------------------------------------------------------------- |
1179 | | */ |
1180 | | herr_t |
1181 | | H5Dread_chunk2(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *filters /*out*/, |
1182 | | void *buf /*out*/, size_t *buf_size) |
1183 | 0 | { |
1184 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
1185 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
1186 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
1187 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1188 | |
|
1189 | 0 | FUNC_ENTER_API(FAIL) |
1190 | | |
1191 | | /* Check arguments */ |
1192 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
1193 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id is not a dataset ID"); |
1194 | 0 | if (!offset) |
1195 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset cannot be NULL"); |
1196 | 0 | if (!filters) |
1197 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "filters cannot be NULL"); |
1198 | 0 | if (!buf_size) |
1199 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buf_size cannot be NULL"); |
1200 | | |
1201 | | /* Get the default dataset transfer property list if the user didn't provide one */ |
1202 | 0 | if (H5P_DEFAULT == dxpl_id) |
1203 | 0 | dxpl_id = H5P_DATASET_XFER_DEFAULT; |
1204 | 0 | else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) |
1205 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dxpl_id is not a dataset transfer property list ID"); |
1206 | | |
1207 | | /* Set up VOL callback arguments */ |
1208 | 0 | dset_opt_args.chunk_read.offset = offset; |
1209 | 0 | dset_opt_args.chunk_read.filters = 0; |
1210 | 0 | dset_opt_args.chunk_read.buf = buf; |
1211 | 0 | dset_opt_args.chunk_read.buf_size = buf_size; |
1212 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_CHUNK_READ; |
1213 | 0 | vol_cb_args.args = &dset_opt_args; |
1214 | | |
1215 | | /* Read the raw chunk */ |
1216 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, dxpl_id, H5_REQUEST_NULL) < 0) |
1217 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read unprocessed chunk data"); |
1218 | | |
1219 | | /* Set return value */ |
1220 | 0 | *filters = dset_opt_args.chunk_read.filters; |
1221 | |
|
1222 | 0 | done: |
1223 | 0 | FUNC_LEAVE_API(ret_value) |
1224 | 0 | } /* end H5Dread_chunk2() */ |
1225 | | |
1226 | | /*------------------------------------------------------------------------- |
1227 | | * Function: H5D__write_api_common |
1228 | | * |
1229 | | * Purpose: Common helper routine for sync/async dataset write operations. |
1230 | | * |
1231 | | * Return: SUCCEED/FAIL |
1232 | | * |
1233 | | *------------------------------------------------------------------------- |
1234 | | */ |
1235 | | static herr_t |
1236 | | H5D__write_api_common(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], |
1237 | | hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void **token_ptr, |
1238 | | H5VL_object_t **_vol_obj_ptr) |
1239 | 0 | { |
1240 | 0 | H5VL_object_t *tmp_vol_obj = NULL; /* Object for loc_id */ |
1241 | 0 | H5VL_object_t **vol_obj_ptr = |
1242 | 0 | (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ |
1243 | 0 | void *obj_local; /* Local buffer for obj */ |
1244 | 0 | void **obj = &obj_local; /* Array of object pointers */ |
1245 | 0 | H5VL_connector_t *connector; /* VOL connector pointer */ |
1246 | 0 | size_t i; /* Local index variable */ |
1247 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1248 | |
|
1249 | 0 | FUNC_ENTER_PACKAGE |
1250 | | |
1251 | | /* Check arguments */ |
1252 | 0 | if (count == 0) |
1253 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "count must be greater than 0"); |
1254 | 0 | if (!dset_id) |
1255 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dset_id array not provided"); |
1256 | 0 | if (!mem_type_id) |
1257 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "mem_type_id array not provided"); |
1258 | 0 | if (!mem_space_id) |
1259 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "mem_space_id array not provided"); |
1260 | 0 | if (!file_space_id) |
1261 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file_space_id array not provided"); |
1262 | 0 | if (!buf) |
1263 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buf array not provided"); |
1264 | | |
1265 | | /* Allocate obj array if necessary */ |
1266 | 0 | if (count > 1) |
1267 | 0 | if (NULL == (obj = (void **)H5MM_malloc(count * sizeof(void *)))) |
1268 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate space for object array"); |
1269 | | |
1270 | | /* Get vol_obj_ptr (return just the first dataset to caller if requested) */ |
1271 | 0 | if (NULL == (*vol_obj_ptr = (H5VL_object_t *)H5I_object_verify(dset_id[0], H5I_DATASET))) |
1272 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id is not a dataset ID"); |
1273 | | |
1274 | | /* Save the connector of the first dataset. Unpack the connector and call |
1275 | | * the "direct" write function here to avoid allocating an array of count |
1276 | | * H5VL_object_ts. */ |
1277 | 0 | connector = H5VL_OBJ_CONNECTOR(*vol_obj_ptr); |
1278 | | |
1279 | | /* Build obj array */ |
1280 | 0 | obj[0] = H5VL_OBJ_DATA(*vol_obj_ptr); |
1281 | 0 | for (i = 1; i < count; i++) { |
1282 | 0 | htri_t cls_cmp; |
1283 | | |
1284 | | /* Get the object */ |
1285 | 0 | if (NULL == (tmp_vol_obj = (H5VL_object_t *)H5I_object_verify(dset_id[i], H5I_DATASET))) |
1286 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id is not a dataset ID"); |
1287 | 0 | obj[i] = H5VL_OBJ_DATA(tmp_vol_obj); |
1288 | | |
1289 | | /* Make sure the class matches */ |
1290 | 0 | if ((cls_cmp = H5VL_conn_same_class(H5VL_OBJ_CONNECTOR(tmp_vol_obj), connector)) < 0) |
1291 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOMPARE, FAIL, "can't compare VOL connectors"); |
1292 | 0 | if (!cls_cmp) |
1293 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, |
1294 | 0 | "datasets are accessed through different VOL connectors and can't be used in the " |
1295 | 0 | "same I/O call"); |
1296 | 0 | } |
1297 | | |
1298 | | /* Get the default dataset transfer property list if the user didn't provide one */ |
1299 | 0 | if (H5P_DEFAULT == dxpl_id) |
1300 | 0 | dxpl_id = H5P_DATASET_XFER_DEFAULT; |
1301 | 0 | else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) |
1302 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms"); |
1303 | | |
1304 | | /* Write the data */ |
1305 | 0 | if (H5VL_dataset_write(count, obj, connector, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, |
1306 | 0 | token_ptr) < 0) |
1307 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data"); |
1308 | | |
1309 | 0 | done: |
1310 | | /* Free memory */ |
1311 | 0 | if (obj != &obj_local) |
1312 | 0 | H5MM_free(obj); |
1313 | |
|
1314 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1315 | 0 | } /* end H5D__write_api_common() */ |
1316 | | |
1317 | | /*------------------------------------------------------------------------- |
1318 | | * Function: H5Dwrite |
1319 | | * |
1320 | | * Purpose: Writes (part of) a DSET from application memory BUF to the |
1321 | | * file. The part of the dataset to write is defined with the |
1322 | | * MEM_SPACE_ID and FILE_SPACE_ID arguments. The data points |
1323 | | * are converted from their current type (MEM_TYPE_ID) to their |
1324 | | * file datatype. Additional miscellaneous data transfer |
1325 | | * properties can be passed to this function with the |
1326 | | * PLIST_ID argument. |
1327 | | * |
1328 | | * The FILE_SPACE_ID can be the constant H5S_ALL which indicates |
1329 | | * that the entire file dataspace is to be referenced. |
1330 | | * |
1331 | | * The MEM_SPACE_ID can be the constant H5S_ALL in which case |
1332 | | * the memory dataspace is the same as the file dataspace |
1333 | | * defined when the dataset was created. The MEM_SPACE_ID can |
1334 | | * also be the constant H5S_BLOCK, which indicates that the |
1335 | | * buffer provided is a single contiguous block of memory, with |
1336 | | * the same # of elements as specified in the FILE_SPACE_ID |
1337 | | * selection. |
1338 | | * |
1339 | | * The number of elements in the memory dataspace must match |
1340 | | * the number of elements in the file dataspace. |
1341 | | * |
1342 | | * The PLIST_ID can be the constant H5P_DEFAULT in which |
1343 | | * case the default data transfer properties are used. |
1344 | | * |
1345 | | * Return: Non-negative on success/Negative on failure |
1346 | | * |
1347 | | *------------------------------------------------------------------------- |
1348 | | */ |
1349 | | herr_t |
1350 | | H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t dxpl_id, |
1351 | | const void *buf) |
1352 | 0 | { |
1353 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1354 | |
|
1355 | 0 | FUNC_ENTER_API(FAIL) |
1356 | | |
1357 | | /* Write the data */ |
1358 | 0 | if (H5D__write_api_common(1, &dset_id, &mem_type_id, &mem_space_id, &file_space_id, dxpl_id, &buf, NULL, |
1359 | 0 | NULL) < 0) |
1360 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't synchronously write data"); |
1361 | | |
1362 | 0 | done: |
1363 | 0 | FUNC_LEAVE_API(ret_value) |
1364 | 0 | } /* end H5Dwrite() */ |
1365 | | |
1366 | | /*------------------------------------------------------------------------- |
1367 | | * Function: H5Dwrite_async |
1368 | | * |
1369 | | * Purpose: For asynchronous VOL with request token |
1370 | | * |
1371 | | * Return: Non-negative on success/Negative on failure |
1372 | | * |
1373 | | *------------------------------------------------------------------------- |
1374 | | */ |
1375 | | herr_t |
1376 | | H5Dwrite_async(const char *app_file, const char *app_func, unsigned app_line, hid_t dset_id, |
1377 | | hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t dxpl_id, const void *buf, |
1378 | | hid_t es_id) |
1379 | 0 | { |
1380 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset VOL object */ |
1381 | 0 | void *token = NULL; /* Request token for async operation */ |
1382 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
1383 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1384 | |
|
1385 | 0 | FUNC_ENTER_API(FAIL) |
1386 | | |
1387 | | /* Set up request token pointer for asynchronous operation */ |
1388 | 0 | if (H5ES_NONE != es_id) |
1389 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
1390 | | |
1391 | | /* Write the data */ |
1392 | 0 | if (H5D__write_api_common(1, &dset_id, &mem_type_id, &mem_space_id, &file_space_id, dxpl_id, &buf, |
1393 | 0 | token_ptr, &vol_obj) < 0) |
1394 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't asynchronously write data"); |
1395 | | |
1396 | | /* If a token was created, add the token to the event set */ |
1397 | 0 | if (NULL != token) |
1398 | | /* clang-format off */ |
1399 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
1400 | 0 | H5ARG_TRACE10(__func__, "*s*sIuiiiii*xi", app_file, app_func, app_line, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, es_id)) < 0) |
1401 | | /* clang-format on */ |
1402 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set"); |
1403 | | |
1404 | 0 | done: |
1405 | 0 | FUNC_LEAVE_API(ret_value) |
1406 | 0 | } /* end H5Dwrite_async() */ |
1407 | | |
1408 | | /*------------------------------------------------------------------------- |
1409 | | * Function: H5Dwrite_multi |
1410 | | * |
1411 | | * Purpose: Multi-version of H5Dwrite(), which writes selections from |
1412 | | * application memory BUFs into multiple datasets in a file. |
1413 | | * |
1414 | | * Return: Non-negative on success/Negative on failure |
1415 | | * |
1416 | | *------------------------------------------------------------------------- |
1417 | | */ |
1418 | | herr_t |
1419 | | H5Dwrite_multi(size_t count, hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], |
1420 | | hid_t file_space_id[], hid_t dxpl_id, const void *buf[]) |
1421 | 0 | { |
1422 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1423 | |
|
1424 | 0 | FUNC_ENTER_API(FAIL) |
1425 | |
|
1426 | 0 | if (count == 0) |
1427 | 0 | HGOTO_DONE(SUCCEED); |
1428 | | |
1429 | | /* Write the data */ |
1430 | 0 | if (H5D__write_api_common(count, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, NULL, |
1431 | 0 | NULL) < 0) |
1432 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't synchronously write data"); |
1433 | | |
1434 | 0 | done: |
1435 | 0 | FUNC_LEAVE_API(ret_value) |
1436 | 0 | } /* end H5Dwrite_multi() */ |
1437 | | |
1438 | | /*------------------------------------------------------------------------- |
1439 | | * Function: H5Dwrite_multi_async |
1440 | | * |
1441 | | * Purpose: Asynchronously write dataset elements to multiple |
1442 | | * datasets. |
1443 | | * |
1444 | | * Return: Non-negative on success/Negative on failure |
1445 | | * |
1446 | | *------------------------------------------------------------------------- |
1447 | | */ |
1448 | | herr_t |
1449 | | H5Dwrite_multi_async(const char *app_file, const char *app_func, unsigned app_line, size_t count, |
1450 | | hid_t dset_id[], hid_t mem_type_id[], hid_t mem_space_id[], hid_t file_space_id[], |
1451 | | hid_t dxpl_id, const void *buf[], hid_t es_id) |
1452 | 0 | { |
1453 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset VOL object */ |
1454 | 0 | void *token = NULL; /* Request token for async operation */ |
1455 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
1456 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1457 | |
|
1458 | 0 | FUNC_ENTER_API(FAIL) |
1459 | | |
1460 | | /* Set up request token pointer for asynchronous operation */ |
1461 | 0 | if (H5ES_NONE != es_id) |
1462 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
1463 | | |
1464 | | /* Write the data */ |
1465 | 0 | if (H5D__write_api_common(count, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, |
1466 | 0 | token_ptr, &vol_obj) < 0) |
1467 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't asynchronously write data"); |
1468 | | |
1469 | | /* If a token was created, add the token to the event set */ |
1470 | 0 | if (NULL != token) |
1471 | | /* clang-format off */ |
1472 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
1473 | 0 | H5ARG_TRACE11(__func__, "*s*sIuz*i*i*i*ii**xi", app_file, app_func, app_line, count, dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf, es_id)) < 0) |
1474 | | /* clang-format on */ |
1475 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set"); |
1476 | | |
1477 | 0 | done: |
1478 | 0 | FUNC_LEAVE_API(ret_value) |
1479 | 0 | } /* end H5Dwrite_multi_async() */ |
1480 | | |
1481 | | /*------------------------------------------------------------------------- |
1482 | | * Function: H5Dwrite_chunk |
1483 | | * |
1484 | | * Purpose: Writes an entire chunk to the file directly. |
1485 | | * |
1486 | | * Return: Non-negative on success/Negative on failure |
1487 | | * |
1488 | | *------------------------------------------------------------------------- |
1489 | | */ |
1490 | | herr_t |
1491 | | H5Dwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters, const hsize_t *offset, size_t data_size, |
1492 | | const void *buf) |
1493 | 0 | { |
1494 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
1495 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
1496 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
1497 | 0 | uint32_t data_size_32; /* Chunk data size (limited to 32-bits currently) */ |
1498 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1499 | |
|
1500 | 0 | FUNC_ENTER_API(FAIL) |
1501 | | |
1502 | | /* Check arguments */ |
1503 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
1504 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset ID"); |
1505 | 0 | if (!buf) |
1506 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buf cannot be NULL"); |
1507 | 0 | if (!offset) |
1508 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset cannot be NULL"); |
1509 | 0 | if (0 == data_size) |
1510 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "data_size cannot be zero"); |
1511 | | |
1512 | | /* Make sure data size is less than 4 GiB */ |
1513 | 0 | data_size_32 = (uint32_t)data_size; |
1514 | 0 | if (data_size != (size_t)data_size_32) |
1515 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid data_size - chunks cannot be > 4 GiB"); |
1516 | | |
1517 | | /* Get the default dataset transfer property list if the user didn't provide one */ |
1518 | 0 | if (H5P_DEFAULT == dxpl_id) |
1519 | 0 | dxpl_id = H5P_DATASET_XFER_DEFAULT; |
1520 | 0 | else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) |
1521 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dxpl_id is not a dataset transfer property list ID"); |
1522 | | |
1523 | | /* Set up VOL callback arguments */ |
1524 | 0 | dset_opt_args.chunk_write.offset = offset; |
1525 | 0 | dset_opt_args.chunk_write.filters = filters; |
1526 | 0 | dset_opt_args.chunk_write.size = data_size_32; |
1527 | 0 | dset_opt_args.chunk_write.buf = buf; |
1528 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_CHUNK_WRITE; |
1529 | 0 | vol_cb_args.args = &dset_opt_args; |
1530 | | |
1531 | | /* Write chunk */ |
1532 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, dxpl_id, H5_REQUEST_NULL) < 0) |
1533 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write unprocessed chunk data"); |
1534 | | |
1535 | 0 | done: |
1536 | 0 | FUNC_LEAVE_API(ret_value) |
1537 | 0 | } /* end H5Dwrite_chunk() */ |
1538 | | |
1539 | | /*------------------------------------------------------------------------- |
1540 | | * Function: H5Dscatter |
1541 | | * |
1542 | | * Purpose: Scatters data provided by the callback op to the |
1543 | | * destination buffer dst_buf, where the dimensions of |
1544 | | * dst_buf and the selection to be scattered to are specified |
1545 | | * by the dataspace dst_space_id. The type of the data to be |
1546 | | * scattered is specified by type_id. |
1547 | | * |
1548 | | * Return: Non-negative on success/Negative on failure |
1549 | | * |
1550 | | *------------------------------------------------------------------------- |
1551 | | */ |
1552 | | herr_t |
1553 | | H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, hid_t dst_space_id, void *dst_buf /*out*/) |
1554 | 0 | { |
1555 | 0 | H5T_t *type; /* Datatype */ |
1556 | 0 | H5S_t *dst_space; /* Dataspace */ |
1557 | 0 | H5S_sel_iter_t *iter = NULL; /* Selection iteration info*/ |
1558 | 0 | bool iter_init = false; /* Selection iteration info has been initialized */ |
1559 | 0 | const void *src_buf = NULL; /* Source (contiguous) data buffer */ |
1560 | 0 | size_t src_buf_nbytes = 0; /* Size of src_buf */ |
1561 | 0 | size_t type_size; /* Datatype element size */ |
1562 | 0 | hssize_t nelmts; /* Number of remaining elements in selection */ |
1563 | 0 | size_t nelmts_scatter = 0; /* Number of elements to scatter to dst_buf */ |
1564 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1565 | |
|
1566 | 0 | FUNC_ENTER_API(FAIL) |
1567 | | |
1568 | | /* Check args */ |
1569 | 0 | if (op == NULL) |
1570 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid callback function pointer"); |
1571 | 0 | if (NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) |
1572 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype"); |
1573 | 0 | if (NULL == (dst_space = (H5S_t *)H5I_object_verify(dst_space_id, H5I_DATASPACE))) |
1574 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace"); |
1575 | 0 | if (dst_buf == NULL) |
1576 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no destination buffer provided"); |
1577 | | |
1578 | | /* Get datatype element size */ |
1579 | 0 | if (0 == (type_size = H5T_GET_SIZE(type))) |
1580 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get datatype size"); |
1581 | | |
1582 | | /* Get number of elements in dataspace */ |
1583 | 0 | if ((nelmts = (hssize_t)H5S_GET_SELECT_NPOINTS(dst_space)) < 0) |
1584 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "unable to get number of elements in selection"); |
1585 | | |
1586 | | /* Allocate the selection iterator */ |
1587 | 0 | if (NULL == (iter = H5FL_MALLOC(H5S_sel_iter_t))) |
1588 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate selection iterator"); |
1589 | | |
1590 | | /* Initialize selection iterator */ |
1591 | 0 | if (H5S_select_iter_init(iter, dst_space, type_size, 0) < 0) |
1592 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize selection iterator information"); |
1593 | 0 | iter_init = true; |
1594 | | |
1595 | | /* Loop until all data has been scattered */ |
1596 | 0 | while (nelmts > 0) { |
1597 | | /* Prepare & restore library for user callback */ |
1598 | 0 | H5_BEFORE_USER_CB(FAIL) |
1599 | 0 | { |
1600 | | /* Make callback to retrieve data */ |
1601 | 0 | ret_value = op(&src_buf, &src_buf_nbytes, op_data); |
1602 | 0 | } |
1603 | 0 | H5_AFTER_USER_CB(FAIL) |
1604 | 0 | if (ret_value < 0) |
1605 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CALLBACK, FAIL, "callback operator returned failure"); |
1606 | | |
1607 | | /* Calculate number of elements */ |
1608 | 0 | nelmts_scatter = src_buf_nbytes / type_size; |
1609 | | |
1610 | | /* Check callback results */ |
1611 | 0 | if (!src_buf) |
1612 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "callback did not return a buffer"); |
1613 | 0 | if (src_buf_nbytes == 0) |
1614 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "callback returned a buffer size of 0"); |
1615 | 0 | if (src_buf_nbytes % type_size) |
1616 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buffer size is not a multiple of datatype size"); |
1617 | 0 | if (nelmts_scatter > (size_t)nelmts) |
1618 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "callback returned more elements than in selection"); |
1619 | | |
1620 | | /* Scatter data */ |
1621 | 0 | if (H5D__scatter_mem(src_buf, iter, nelmts_scatter, dst_buf) < 0) |
1622 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "scatter failed"); |
1623 | | |
1624 | 0 | nelmts -= (hssize_t)nelmts_scatter; |
1625 | 0 | } /* end while */ |
1626 | | |
1627 | 0 | done: |
1628 | | /* Release selection iterator */ |
1629 | 0 | if (iter_init && H5S_SELECT_ITER_RELEASE(iter) < 0) |
1630 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't release selection iterator"); |
1631 | 0 | if (iter) |
1632 | 0 | iter = H5FL_FREE(H5S_sel_iter_t, iter); |
1633 | |
|
1634 | 0 | FUNC_LEAVE_API(ret_value) |
1635 | 0 | } /* H5Dscatter() */ |
1636 | | |
1637 | | /*------------------------------------------------------------------------- |
1638 | | * Function: H5Dgather |
1639 | | * |
1640 | | * Purpose: Gathers data provided from the source buffer src_buf to |
1641 | | * contiguous buffer dst_buf, then calls the callback op. |
1642 | | * The dimensions of src_buf and the selection to be gathered |
1643 | | * are specified by the dataspace src_space_id. The type of |
1644 | | * the data to be gathered is specified by type_id. |
1645 | | * |
1646 | | * Return: Non-negative on success/Negative on failure |
1647 | | * |
1648 | | *------------------------------------------------------------------------- |
1649 | | */ |
1650 | | herr_t |
1651 | | H5Dgather(hid_t src_space_id, const void *src_buf, hid_t type_id, size_t dst_buf_size, void *dst_buf /*out*/, |
1652 | | H5D_gather_func_t op, void *op_data) |
1653 | 0 | { |
1654 | 0 | H5T_t *type; /* Datatype */ |
1655 | 0 | H5S_t *src_space; /* Dataspace */ |
1656 | 0 | H5S_sel_iter_t *iter = NULL; /* Selection iteration info*/ |
1657 | 0 | bool iter_init = false; /* Selection iteration info has been initialized */ |
1658 | 0 | size_t type_size; /* Datatype element size */ |
1659 | 0 | hssize_t nelmts; /* Number of remaining elements in selection */ |
1660 | 0 | size_t dst_buf_nelmts; /* Number of elements that can fit in dst_buf */ |
1661 | 0 | size_t nelmts_gathered; /* Number of elements gathered from src_buf */ |
1662 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1663 | |
|
1664 | 0 | FUNC_ENTER_API(FAIL) |
1665 | | |
1666 | | /* Check args */ |
1667 | 0 | if (NULL == (src_space = (H5S_t *)H5I_object_verify(src_space_id, H5I_DATASPACE))) |
1668 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace"); |
1669 | 0 | if (src_buf == NULL) |
1670 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no source buffer provided"); |
1671 | 0 | if (NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) |
1672 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype"); |
1673 | 0 | if (dst_buf_size == 0) |
1674 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination buffer size is 0"); |
1675 | 0 | if (dst_buf == NULL) |
1676 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no destination buffer provided"); |
1677 | | |
1678 | | /* Get datatype element size */ |
1679 | 0 | if (0 == (type_size = H5T_GET_SIZE(type))) |
1680 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get datatype size"); |
1681 | | |
1682 | | /* Get number of elements in dst_buf_size */ |
1683 | 0 | dst_buf_nelmts = dst_buf_size / type_size; |
1684 | 0 | if (dst_buf_nelmts == 0) |
1685 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, |
1686 | 0 | "destination buffer is not large enough to hold one element"); |
1687 | | |
1688 | | /* Get number of elements in dataspace */ |
1689 | 0 | if ((nelmts = (hssize_t)H5S_GET_SELECT_NPOINTS(src_space)) < 0) |
1690 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "unable to get number of elements in selection"); |
1691 | | |
1692 | | /* If dst_buf is not large enough to hold all the elements, make sure there |
1693 | | * is a callback */ |
1694 | 0 | if (((size_t)nelmts > dst_buf_nelmts) && (op == NULL)) |
1695 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no callback supplied and destination buffer too small"); |
1696 | | |
1697 | | /* Allocate the selection iterator */ |
1698 | 0 | if (NULL == (iter = H5FL_MALLOC(H5S_sel_iter_t))) |
1699 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate selection iterator"); |
1700 | | |
1701 | | /* Initialize selection iterator */ |
1702 | 0 | if (H5S_select_iter_init(iter, src_space, type_size, 0) < 0) |
1703 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize selection iterator information"); |
1704 | 0 | iter_init = true; |
1705 | | |
1706 | | /* Loop until all data has been scattered */ |
1707 | 0 | while (nelmts > 0) { |
1708 | | /* Gather data */ |
1709 | 0 | if (0 == |
1710 | 0 | (nelmts_gathered = H5D__gather_mem(src_buf, iter, MIN(dst_buf_nelmts, (size_t)nelmts), dst_buf))) |
1711 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "gather failed"); |
1712 | 0 | assert(nelmts_gathered == MIN(dst_buf_nelmts, (size_t)nelmts)); |
1713 | | |
1714 | | /* Make callback to process dst_buf */ |
1715 | 0 | if (op) { |
1716 | | /* Prepare & restore library for user callback */ |
1717 | 0 | H5_BEFORE_USER_CB(FAIL) |
1718 | 0 | { |
1719 | 0 | ret_value = op(dst_buf, nelmts_gathered * type_size, op_data); |
1720 | 0 | } |
1721 | 0 | H5_AFTER_USER_CB(FAIL) |
1722 | 0 | if (ret_value < 0) |
1723 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CALLBACK, FAIL, "callback operator returned failure"); |
1724 | 0 | } |
1725 | | |
1726 | 0 | nelmts -= (hssize_t)nelmts_gathered; |
1727 | 0 | assert(op || (nelmts == 0)); |
1728 | 0 | } /* end while */ |
1729 | | |
1730 | 0 | done: |
1731 | | /* Release selection iterator */ |
1732 | 0 | if (iter_init && H5S_SELECT_ITER_RELEASE(iter) < 0) |
1733 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't release selection iterator"); |
1734 | 0 | if (iter) |
1735 | 0 | iter = H5FL_FREE(H5S_sel_iter_t, iter); |
1736 | |
|
1737 | 0 | FUNC_LEAVE_API(ret_value) |
1738 | 0 | } /* H5Dgather() */ |
1739 | | |
1740 | | /*-------------------------------------------------------------------------- |
1741 | | NAME |
1742 | | H5Dfill |
1743 | | PURPOSE |
1744 | | Fill a selection in memory with a value |
1745 | | USAGE |
1746 | | herr_t H5Dfill(fill, fill_type, space, buf, buf_type) |
1747 | | const void *fill; IN: Pointer to fill value to use |
1748 | | hid_t fill_type_id; IN: Datatype of the fill value |
1749 | | void *buf; IN/OUT: Memory buffer to fill selection within |
1750 | | hid_t buf_type_id; IN: Datatype of the elements in buffer |
1751 | | hid_t space_id; IN: Dataspace describing memory buffer & |
1752 | | containing selection to use. |
1753 | | RETURNS |
1754 | | Non-negative on success/Negative on failure. |
1755 | | DESCRIPTION |
1756 | | Use the selection in the dataspace to fill elements in a memory buffer. |
1757 | | GLOBAL VARIABLES |
1758 | | COMMENTS, BUGS, ASSUMPTIONS |
1759 | | If "fill" parameter is NULL, use all zeros as fill value |
1760 | | EXAMPLES |
1761 | | REVISION LOG |
1762 | | --------------------------------------------------------------------------*/ |
1763 | | herr_t |
1764 | | H5Dfill(const void *fill, hid_t fill_type_id, void *buf, hid_t buf_type_id, hid_t space_id) |
1765 | 0 | { |
1766 | 0 | H5S_t *space; /* Dataspace */ |
1767 | 0 | H5T_t *fill_type; /* Fill-value datatype */ |
1768 | 0 | H5T_t *buf_type; /* Buffer datatype */ |
1769 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1770 | |
|
1771 | 0 | FUNC_ENTER_API(FAIL) |
1772 | | |
1773 | | /* Check args */ |
1774 | 0 | if (buf == NULL) |
1775 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid buffer"); |
1776 | 0 | if (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) |
1777 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a dataspace"); |
1778 | 0 | if (NULL == (fill_type = (H5T_t *)H5I_object_verify(fill_type_id, H5I_DATATYPE))) |
1779 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a datatype"); |
1780 | 0 | if (NULL == (buf_type = (H5T_t *)H5I_object_verify(buf_type_id, H5I_DATATYPE))) |
1781 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a datatype"); |
1782 | | |
1783 | | /* Fill the selection in the memory buffer */ |
1784 | 0 | if (H5D__fill(fill, fill_type, buf, buf_type, space) < 0) |
1785 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTENCODE, FAIL, "filling selection failed"); |
1786 | | |
1787 | 0 | done: |
1788 | 0 | FUNC_LEAVE_API(ret_value) |
1789 | 0 | } /* H5Dfill() */ |
1790 | | |
1791 | | /*------------------------------------------------------------------------- |
1792 | | * Function: H5Diterate |
1793 | | * |
1794 | | * Purpose: This routine iterates over all the elements selected in a memory |
1795 | | * buffer. The callback function is called once for each element selected |
1796 | | * in the dataspace. The selection in the dataspace is modified so |
1797 | | * that any elements already iterated over are removed from the selection |
1798 | | * if the iteration is interrupted (by the H5D_operator_t function |
1799 | | * returning non-zero) in the "middle" of the iteration and may be |
1800 | | * re-started by the user where it left off. |
1801 | | * |
1802 | | * NOTE: Until "subtracting" elements from a selection is implemented, |
1803 | | * the selection is not modified. |
1804 | | * |
1805 | | * Parameters: |
1806 | | * void *buf; IN/OUT: Pointer to the buffer in memory containing |
1807 | | * the elements to iterate over. |
1808 | | * hid_t type_id; IN: Datatype ID for the elements stored in BUF. |
1809 | | * hid_t space_id; IN: Dataspace ID for BUF, also contains the |
1810 | | * selection to iterate over. |
1811 | | * H5D_operator_t op; IN: Function pointer to the routine to be |
1812 | | * called for each element in BUF iterated over. |
1813 | | * void *operator_data; IN/OUT: Pointer to any user-defined data |
1814 | | * associated with the operation. |
1815 | | * |
1816 | | * Operation information: |
1817 | | * H5D_operator_t is defined as: |
1818 | | * typedef herr_t (*H5D_operator_t)(void *elem, hid_t type_id, |
1819 | | * unsigned ndim, const hsize_t *point, void *operator_data); |
1820 | | * |
1821 | | * H5D_operator_t parameters: |
1822 | | * void *elem; IN/OUT: Pointer to the element in memory containing |
1823 | | * the current point. |
1824 | | * hid_t type_id; IN: Datatype ID for the elements stored in ELEM. |
1825 | | * unsigned ndim; IN: Number of dimensions for POINT array |
1826 | | * const hsize_t *point; IN: Array containing the location of the element |
1827 | | * within the original dataspace. |
1828 | | * void *operator_data; IN/OUT: Pointer to any user-defined data |
1829 | | * associated with the operation. |
1830 | | * |
1831 | | * The return values from an operator are: |
1832 | | * Zero causes the iterator to continue, returning zero when all |
1833 | | * elements have been processed. |
1834 | | * Positive causes the iterator to immediately return that positive |
1835 | | * value, indicating short-circuit success. The iterator can be |
1836 | | * restarted at the next element. |
1837 | | * Negative causes the iterator to immediately return that value, |
1838 | | * indicating failure. The iterator can be restarted at the next |
1839 | | * element. |
1840 | | * |
1841 | | * Return: Returns the return value of the last operator if it was non-zero, |
1842 | | * or zero if all elements were processed. Otherwise returns a |
1843 | | * negative value. |
1844 | | * |
1845 | | *------------------------------------------------------------------------- |
1846 | | */ |
1847 | | herr_t |
1848 | | H5Diterate(void *buf, hid_t type_id, hid_t space_id, H5D_operator_t op, void *operator_data) |
1849 | 0 | { |
1850 | 0 | const H5T_t *type; /* Datatype */ |
1851 | 0 | H5S_t *space; /* Dataspace for iteration */ |
1852 | 0 | H5S_sel_iter_op_t dset_op; /* Operator for iteration */ |
1853 | 0 | herr_t ret_value; /* Return value */ |
1854 | |
|
1855 | 0 | FUNC_ENTER_API(FAIL) |
1856 | | |
1857 | | /* Check args */ |
1858 | 0 | if (NULL == op) |
1859 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid operator"); |
1860 | 0 | if (NULL == buf) |
1861 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid buffer"); |
1862 | 0 | if (H5I_DATATYPE != H5I_get_type(type_id)) |
1863 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid datatype"); |
1864 | 0 | if (NULL == (type = (const H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) |
1865 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an valid base datatype"); |
1866 | 0 | if (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) |
1867 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace"); |
1868 | 0 | if (!(H5S_has_extent(space))) |
1869 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dataspace does not have extent set"); |
1870 | | |
1871 | 0 | dset_op.op_type = H5S_SEL_ITER_OP_APP; |
1872 | 0 | dset_op.u.app_op.op = op; |
1873 | 0 | dset_op.u.app_op.type_id = type_id; |
1874 | |
|
1875 | 0 | ret_value = H5S_select_iterate(buf, type, space, &dset_op, operator_data); |
1876 | |
|
1877 | 0 | done: |
1878 | 0 | FUNC_LEAVE_API(ret_value) |
1879 | 0 | } /* end H5Diterate() */ |
1880 | | |
1881 | | /*------------------------------------------------------------------------- |
1882 | | * Function: H5Dvlen_get_buf_size |
1883 | | * |
1884 | | * Purpose: This routine checks the number of bytes required to store the VL |
1885 | | * data from the dataset, using the space_id for the selection in the |
1886 | | * dataset on disk and the type_id for the memory representation of the |
1887 | | * VL data, in memory. The *size value is modified according to how many |
1888 | | * bytes are required to store the VL data in memory. |
1889 | | * |
1890 | | * Return: Non-negative on success, negative on failure |
1891 | | * |
1892 | | *------------------------------------------------------------------------- |
1893 | | */ |
1894 | | herr_t |
1895 | | H5Dvlen_get_buf_size(hid_t dataset_id, hid_t type_id, hid_t space_id, hsize_t *size /*out*/) |
1896 | 0 | { |
1897 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
1898 | 0 | uint64_t supported; /* Whether 'get vlen buf size' operation is supported by VOL connector */ |
1899 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1900 | |
|
1901 | 0 | FUNC_ENTER_API(FAIL) |
1902 | | |
1903 | | /* Check args */ |
1904 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dataset_id, H5I_DATASET))) |
1905 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
1906 | 0 | if (H5I_DATATYPE != H5I_get_type(type_id)) |
1907 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid datatype identifier"); |
1908 | 0 | if (H5I_DATASPACE != H5I_get_type(space_id)) |
1909 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace identifier"); |
1910 | 0 | if (size == NULL) |
1911 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid 'size' pointer"); |
1912 | | |
1913 | | /* Check if the 'get_vlen_buf_size' callback is supported */ |
1914 | 0 | supported = 0; |
1915 | 0 | if (H5VL_introspect_opt_query(vol_obj, H5VL_SUBCLS_DATASET, H5VL_NATIVE_DATASET_GET_VLEN_BUF_SIZE, |
1916 | 0 | &supported) < 0) |
1917 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't check for 'get vlen buf size' operation"); |
1918 | 0 | if (supported & H5VL_OPT_QUERY_SUPPORTED) { |
1919 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
1920 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
1921 | | |
1922 | | /* Set up VOL callback arguments */ |
1923 | 0 | dset_opt_args.get_vlen_buf_size.type_id = type_id; |
1924 | 0 | dset_opt_args.get_vlen_buf_size.space_id = space_id; |
1925 | 0 | dset_opt_args.get_vlen_buf_size.size = size; |
1926 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_VLEN_BUF_SIZE; |
1927 | 0 | vol_cb_args.args = &dset_opt_args; |
1928 | | |
1929 | | /* Make the 'get_vlen_buf_size' callback */ |
1930 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
1931 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to get vlen buf size"); |
1932 | 0 | } /* end if */ |
1933 | 0 | else { |
1934 | | /* Perform a generic operation that will work with all VOL connectors */ |
1935 | 0 | if (H5D__vlen_get_buf_size_gen(vol_obj, type_id, space_id, size) < 0) |
1936 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to get vlen buf size"); |
1937 | 0 | } /* end else */ |
1938 | | |
1939 | 0 | done: |
1940 | 0 | FUNC_LEAVE_API(ret_value) |
1941 | 0 | } /* end H5Dvlen_get_buf_size() */ |
1942 | | |
1943 | | /*------------------------------------------------------------------------- |
1944 | | * Function: H5D__set_extent_api_common |
1945 | | * |
1946 | | * Purpose: This is the common function for changing a dataset's dimensions |
1947 | | * |
1948 | | * Return: Non-negative on success, negative on failure |
1949 | | * |
1950 | | *------------------------------------------------------------------------- |
1951 | | */ |
1952 | | static herr_t |
1953 | | H5D__set_extent_api_common(hid_t dset_id, const hsize_t size[], void **token_ptr, |
1954 | | H5VL_object_t **_vol_obj_ptr) |
1955 | 0 | { |
1956 | 0 | H5VL_object_t *tmp_vol_obj = NULL; /* Object for loc_id */ |
1957 | 0 | H5VL_object_t **vol_obj_ptr = |
1958 | 0 | (_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */ |
1959 | 0 | H5VL_dataset_specific_args_t vol_cb_args; /* Arguments to VOL callback */ |
1960 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1961 | |
|
1962 | 0 | FUNC_ENTER_PACKAGE |
1963 | | |
1964 | | /* Check args */ |
1965 | 0 | if (NULL == (*vol_obj_ptr = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
1966 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
1967 | 0 | if (!size) |
1968 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size array cannot be NULL"); |
1969 | | |
1970 | | /* Set up collective metadata if appropriate */ |
1971 | 0 | if (H5CX_set_loc(dset_id) < 0) |
1972 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set collective metadata read info"); |
1973 | | |
1974 | | /* Set up VOL callback arguments */ |
1975 | 0 | vol_cb_args.op_type = H5VL_DATASET_SET_EXTENT; |
1976 | 0 | vol_cb_args.args.set_extent.size = size; |
1977 | | |
1978 | | /* Set the extent */ |
1979 | 0 | if (H5VL_dataset_specific(*vol_obj_ptr, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, token_ptr) < 0) |
1980 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to set dataset extent"); |
1981 | | |
1982 | 0 | done: |
1983 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1984 | 0 | } /* H5D__set_extent_api_common() */ |
1985 | | |
1986 | | /*------------------------------------------------------------------------- |
1987 | | * Function: H5Dset_extent |
1988 | | * |
1989 | | * Purpose: Modifies the dimensions of a dataset. |
1990 | | * Can change to a smaller dimension. |
1991 | | * |
1992 | | * Return: Non-negative on success, negative on failure |
1993 | | * |
1994 | | *------------------------------------------------------------------------- |
1995 | | */ |
1996 | | herr_t |
1997 | | H5Dset_extent(hid_t dset_id, const hsize_t size[]) |
1998 | 0 | { |
1999 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2000 | |
|
2001 | 0 | FUNC_ENTER_API(FAIL) |
2002 | | |
2003 | | /* Change a datset's dimensions synchronously */ |
2004 | 0 | if ((ret_value = H5D__set_extent_api_common(dset_id, size, NULL, NULL)) < 0) |
2005 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to synchronously change a dataset's dimensions"); |
2006 | | |
2007 | 0 | done: |
2008 | 0 | FUNC_LEAVE_API(ret_value) |
2009 | 0 | } /* end H5Dset_extent() */ |
2010 | | |
2011 | | /*------------------------------------------------------------------------- |
2012 | | * Function: H5Dset_extent_async |
2013 | | * |
2014 | | * Purpose: Asynchronous version of H5Dset_extent |
2015 | | * |
2016 | | * Return: Non-negative on success, negative on failure |
2017 | | * |
2018 | | *------------------------------------------------------------------------- |
2019 | | */ |
2020 | | herr_t |
2021 | | H5Dset_extent_async(const char *app_file, const char *app_func, unsigned app_line, hid_t dset_id, |
2022 | | const hsize_t size[], hid_t es_id) |
2023 | 0 | { |
2024 | 0 | H5VL_object_t *vol_obj = NULL; /* Object for loc_id */ |
2025 | 0 | void *token = NULL; /* Request token for async operation */ |
2026 | 0 | void **token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */ |
2027 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2028 | |
|
2029 | 0 | FUNC_ENTER_API(FAIL) |
2030 | | |
2031 | | /* Set up request token pointer for asynchronous operation */ |
2032 | 0 | if (H5ES_NONE != es_id) |
2033 | 0 | token_ptr = &token; /* Point at token for VOL connector to set up */ |
2034 | | |
2035 | | /* Change a datset's dimensions asynchronously */ |
2036 | 0 | if (H5D__set_extent_api_common(dset_id, size, token_ptr, &vol_obj) < 0) |
2037 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to asynchronously change a dataset's dimensions"); |
2038 | | |
2039 | | /* If a token was created, add the token to the event set */ |
2040 | 0 | if (NULL != token) |
2041 | | /* clang-format off */ |
2042 | 0 | if (H5ES_insert(es_id, H5VL_OBJ_CONNECTOR(vol_obj), token, |
2043 | 0 | H5ARG_TRACE6(__func__, "*s*sIui*hi", app_file, app_func, app_line, dset_id, size, es_id)) < 0) |
2044 | | /* clang-format on */ |
2045 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert token into event set"); |
2046 | | |
2047 | 0 | done: |
2048 | 0 | FUNC_LEAVE_API(ret_value) |
2049 | 0 | } /* H5Dset_extent_async() */ |
2050 | | |
2051 | | /*------------------------------------------------------------------------- |
2052 | | * Function: H5Dflush |
2053 | | * |
2054 | | * Purpose: Flushes all buffers associated with a dataset. |
2055 | | * |
2056 | | * Return: Non-negative on success, negative on failure |
2057 | | * |
2058 | | *------------------------------------------------------------------------- |
2059 | | */ |
2060 | | herr_t |
2061 | | H5Dflush(hid_t dset_id) |
2062 | 0 | { |
2063 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
2064 | 0 | H5VL_dataset_specific_args_t vol_cb_args; /* Arguments to VOL callback */ |
2065 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2066 | |
|
2067 | 0 | FUNC_ENTER_API(FAIL) |
2068 | | |
2069 | | /* Check args */ |
2070 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2071 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id parameter is not a valid dataset identifier"); |
2072 | | |
2073 | | /* Set up collective metadata if appropriate */ |
2074 | 0 | if (H5CX_set_loc(dset_id) < 0) |
2075 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set collective metadata read info"); |
2076 | | |
2077 | | /* Set up VOL callback arguments */ |
2078 | 0 | vol_cb_args.op_type = H5VL_DATASET_FLUSH; |
2079 | 0 | vol_cb_args.args.flush.dset_id = dset_id; |
2080 | | |
2081 | | /* Flush dataset information cached in memory |
2082 | | * XXX: Note that we need to pass the ID to the VOL since the H5F_flush_cb_t |
2083 | | * callback needs it and that's in the public API. |
2084 | | */ |
2085 | 0 | if (H5VL_dataset_specific(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2086 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTFLUSH, FAIL, "unable to flush dataset"); |
2087 | | |
2088 | 0 | done: |
2089 | 0 | FUNC_LEAVE_API(ret_value) |
2090 | 0 | } /* H5Dflush */ |
2091 | | |
2092 | | /*------------------------------------------------------------------------- |
2093 | | * Function: H5Drefresh |
2094 | | * |
2095 | | * Purpose: Refreshes all buffers associated with a dataset. |
2096 | | * |
2097 | | * Return: Non-negative on success, negative on failure |
2098 | | * |
2099 | | *------------------------------------------------------------------------- |
2100 | | */ |
2101 | | herr_t |
2102 | | H5Drefresh(hid_t dset_id) |
2103 | 0 | { |
2104 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
2105 | 0 | H5VL_dataset_specific_args_t vol_cb_args; /* Arguments to VOL callback */ |
2106 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2107 | |
|
2108 | 0 | FUNC_ENTER_API(FAIL) |
2109 | | |
2110 | | /* Check args */ |
2111 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2112 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id parameter is not a valid dataset identifier"); |
2113 | | |
2114 | | /* Set up collective metadata if appropriate */ |
2115 | 0 | if (H5CX_set_loc(dset_id) < 0) |
2116 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set collective metadata read info"); |
2117 | | |
2118 | | /* Set up VOL callback arguments */ |
2119 | 0 | vol_cb_args.op_type = H5VL_DATASET_REFRESH; |
2120 | 0 | vol_cb_args.args.refresh.dset_id = dset_id; |
2121 | | |
2122 | | /* Refresh the dataset object */ |
2123 | 0 | if (H5VL_dataset_specific(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2124 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTLOAD, FAIL, "unable to refresh dataset"); |
2125 | | |
2126 | 0 | done: |
2127 | 0 | FUNC_LEAVE_API(ret_value) |
2128 | 0 | } /* end H5Drefresh() */ |
2129 | | |
2130 | | /*------------------------------------------------------------------------- |
2131 | | * Function: H5Dformat_convert (Internal) |
2132 | | * |
2133 | | * Purpose: For chunked: |
2134 | | * Convert the chunk indexing type to version 1 B-tree if not |
2135 | | * For compact/contiguous: |
2136 | | * Downgrade layout version to 3 if greater than 3 |
2137 | | * For virtual: |
2138 | | * No conversion |
2139 | | * |
2140 | | * Return: Non-negative on success, negative on failure |
2141 | | * |
2142 | | *------------------------------------------------------------------------- |
2143 | | */ |
2144 | | herr_t |
2145 | | H5Dformat_convert(hid_t dset_id) |
2146 | 0 | { |
2147 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
2148 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2149 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2150 | |
|
2151 | 0 | FUNC_ENTER_API(FAIL) |
2152 | | |
2153 | | /* Check args */ |
2154 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2155 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id parameter is not a valid dataset identifier"); |
2156 | | |
2157 | | /* Set up collective metadata if appropriate */ |
2158 | 0 | if (H5CX_set_loc(dset_id) < 0) |
2159 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set collective metadata read info"); |
2160 | | |
2161 | | /* Set up VOL callback arguments */ |
2162 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_FORMAT_CONVERT; |
2163 | 0 | vol_cb_args.args = NULL; |
2164 | | |
2165 | | /* Convert the dataset */ |
2166 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2167 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTUPDATE, FAIL, "can't convert dataset format"); |
2168 | | |
2169 | 0 | done: |
2170 | 0 | FUNC_LEAVE_API(ret_value) |
2171 | 0 | } /* H5Dformat_convert */ |
2172 | | |
2173 | | /*------------------------------------------------------------------------- |
2174 | | * Function: H5Dget_chunk_index_type (Internal) |
2175 | | * |
2176 | | * Purpose: Retrieve a dataset's chunk indexing type |
2177 | | * |
2178 | | * Return: Non-negative on success, negative on failure |
2179 | | * |
2180 | | *------------------------------------------------------------------------- |
2181 | | */ |
2182 | | herr_t |
2183 | | H5Dget_chunk_index_type(hid_t dset_id, H5D_chunk_index_t *idx_type /*out*/) |
2184 | 0 | { |
2185 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
2186 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2187 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
2188 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2189 | |
|
2190 | 0 | FUNC_ENTER_API(FAIL) |
2191 | | |
2192 | | /* Check args */ |
2193 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2194 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id parameter is not a valid dataset identifier"); |
2195 | 0 | if (NULL == idx_type) |
2196 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "idx_type parameter cannot be NULL"); |
2197 | | |
2198 | | /* Set up VOL callback arguments */ |
2199 | 0 | dset_opt_args.get_chunk_idx_type.idx_type = idx_type; |
2200 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_CHUNK_INDEX_TYPE; |
2201 | 0 | vol_cb_args.args = &dset_opt_args; |
2202 | | |
2203 | | /* Get the chunk indexing type */ |
2204 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2205 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk index type"); |
2206 | | |
2207 | 0 | done: |
2208 | 0 | FUNC_LEAVE_API(ret_value) |
2209 | 0 | } /* H5Dget_chunk_index_type() */ |
2210 | | |
2211 | | /*------------------------------------------------------------------------- |
2212 | | * Function: H5Dget_chunk_storage_size |
2213 | | * |
2214 | | * Purpose: Returns the size of an allocated chunk. |
2215 | | * |
2216 | | * Intended for use with the H5D(O)read_chunk API call so |
2217 | | * the caller can construct an appropriate buffer. |
2218 | | * |
2219 | | * Return: Non-negative on success, negative on failure |
2220 | | * |
2221 | | *------------------------------------------------------------------------- |
2222 | | */ |
2223 | | herr_t |
2224 | | H5Dget_chunk_storage_size(hid_t dset_id, const hsize_t *offset, hsize_t *chunk_nbytes /*out*/) |
2225 | 0 | { |
2226 | 0 | H5VL_object_t *vol_obj; /* Dataset for this operation */ |
2227 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2228 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
2229 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2230 | |
|
2231 | 0 | FUNC_ENTER_API(FAIL) |
2232 | | |
2233 | | /* Check arguments */ |
2234 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2235 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dset_id parameter is not a valid dataset identifier"); |
2236 | 0 | if (NULL == offset) |
2237 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset parameter cannot be NULL"); |
2238 | 0 | if (NULL == chunk_nbytes) |
2239 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "chunk_nbytes parameter cannot be NULL"); |
2240 | | |
2241 | | /* Set up VOL callback arguments */ |
2242 | 0 | dset_opt_args.get_chunk_storage_size.offset = offset; |
2243 | 0 | dset_opt_args.get_chunk_storage_size.size = chunk_nbytes; |
2244 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_CHUNK_STORAGE_SIZE; |
2245 | 0 | vol_cb_args.args = &dset_opt_args; |
2246 | | |
2247 | | /* Get the dataset creation property list */ |
2248 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2249 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get storage size of chunk"); |
2250 | | |
2251 | 0 | done: |
2252 | 0 | FUNC_LEAVE_API(ret_value) |
2253 | 0 | } /* H5Dget_chunk_storage_size() */ |
2254 | | |
2255 | | /*------------------------------------------------------------------------- |
2256 | | * Function: H5Dget_num_chunks |
2257 | | * |
2258 | | * Purpose: Retrieves the number of chunks that have non-empty intersection |
2259 | | * with a specified selection. |
2260 | | * |
2261 | | * Note: Currently, this function only gets the number of all written |
2262 | | * chunks, regardless the dataspace. |
2263 | | * |
2264 | | * Parameters: |
2265 | | * hid_t dset_id; IN: Chunked dataset ID |
2266 | | * hid_t fspace_id; IN: File dataspace ID |
2267 | | * hsize_t *nchunks; OUT: Number of non-empty chunks |
2268 | | * |
2269 | | * Return: Non-negative on success, negative on failure |
2270 | | * |
2271 | | *------------------------------------------------------------------------- |
2272 | | */ |
2273 | | herr_t |
2274 | | H5Dget_num_chunks(hid_t dset_id, hid_t fspace_id, hsize_t *nchunks /*out*/) |
2275 | 0 | { |
2276 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset for this operation */ |
2277 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2278 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
2279 | 0 | herr_t ret_value = SUCCEED; |
2280 | |
|
2281 | 0 | FUNC_ENTER_API(FAIL) |
2282 | | |
2283 | | /* Check arguments */ |
2284 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2285 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
2286 | 0 | if (NULL == nchunks) |
2287 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument (null)"); |
2288 | | |
2289 | | /* Set up VOL callback arguments */ |
2290 | 0 | dset_opt_args.get_num_chunks.space_id = fspace_id; |
2291 | 0 | dset_opt_args.get_num_chunks.nchunks = nchunks; |
2292 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_NUM_CHUNKS; |
2293 | 0 | vol_cb_args.args = &dset_opt_args; |
2294 | | |
2295 | | /* Get the number of written chunks */ |
2296 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2297 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get number of chunks"); |
2298 | | |
2299 | 0 | done: |
2300 | 0 | FUNC_LEAVE_API(ret_value) |
2301 | 0 | } /* H5Dget_num_chunks() */ |
2302 | | |
2303 | | /*------------------------------------------------------------------------- |
2304 | | * Function: H5Dget_chunk_info |
2305 | | * |
2306 | | * Purpose: Retrieves information about a chunk specified by its index. |
2307 | | * |
2308 | | * Parameters: |
2309 | | * hid_t dset_id; IN: Chunked dataset ID |
2310 | | * hid_t fspace_id; IN: File dataspace ID |
2311 | | * hsize_t index; IN: Index of written chunk |
2312 | | * hsize_t *offset OUT: Logical position of the chunk's |
2313 | | * first element in the dataspace |
2314 | | * unsigned *filter_mask OUT: Mask for identifying the filters in use |
2315 | | * haddr_t *addr OUT: Address of the chunk |
2316 | | * hsize_t *size OUT: Size of the chunk |
2317 | | * |
2318 | | * Return: Non-negative on success, negative on failure |
2319 | | * |
2320 | | *------------------------------------------------------------------------- |
2321 | | */ |
2322 | | herr_t |
2323 | | H5Dget_chunk_info(hid_t dset_id, hid_t fspace_id, hsize_t chk_index, hsize_t *offset /*out*/, |
2324 | | unsigned *filter_mask /*out*/, haddr_t *addr /*out*/, hsize_t *size /*out*/) |
2325 | 0 | { |
2326 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset for this operation */ |
2327 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2328 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
2329 | 0 | hsize_t nchunks = 0; /* Number of chunks */ |
2330 | 0 | herr_t ret_value = SUCCEED; |
2331 | |
|
2332 | 0 | FUNC_ENTER_API(FAIL) |
2333 | | |
2334 | | /* Check arguments */ |
2335 | 0 | if (NULL == offset && NULL == filter_mask && NULL == addr && NULL == size) |
2336 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, |
2337 | 0 | "invalid arguments, must have at least one non-null output argument"); |
2338 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2339 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
2340 | | |
2341 | | /* Set up VOL callback arguments */ |
2342 | 0 | dset_opt_args.get_num_chunks.space_id = fspace_id; |
2343 | 0 | dset_opt_args.get_num_chunks.nchunks = &nchunks; |
2344 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_NUM_CHUNKS; |
2345 | 0 | vol_cb_args.args = &dset_opt_args; |
2346 | | |
2347 | | /* Get the number of written chunks to check range */ |
2348 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2349 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get number of chunks"); |
2350 | | |
2351 | | /* Check range for chunk index */ |
2352 | 0 | if (chk_index >= nchunks) |
2353 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_BADRANGE, FAIL, "chunk index is out of range"); |
2354 | | |
2355 | | /* Set up VOL callback arguments */ |
2356 | 0 | dset_opt_args.get_chunk_info_by_idx.space_id = fspace_id; |
2357 | 0 | dset_opt_args.get_chunk_info_by_idx.chk_index = chk_index; |
2358 | 0 | dset_opt_args.get_chunk_info_by_idx.offset = offset; |
2359 | 0 | dset_opt_args.get_chunk_info_by_idx.filter_mask = filter_mask; |
2360 | 0 | dset_opt_args.get_chunk_info_by_idx.addr = addr; |
2361 | 0 | dset_opt_args.get_chunk_info_by_idx.size = size; |
2362 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_CHUNK_INFO_BY_IDX; |
2363 | 0 | vol_cb_args.args = &dset_opt_args; |
2364 | | |
2365 | | /* Call private function to get the chunk info given the chunk's index */ |
2366 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2367 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk info by index"); |
2368 | | |
2369 | 0 | done: |
2370 | 0 | FUNC_LEAVE_API(ret_value) |
2371 | 0 | } /* H5Dget_chunk_info() */ |
2372 | | |
2373 | | /*------------------------------------------------------------------------- |
2374 | | * Function: H5Dget_chunk_info_by_coord |
2375 | | * |
2376 | | * Purpose: Retrieves information about a chunk specified by its logical |
2377 | | * coordinates. |
2378 | | * |
2379 | | * Parameters: |
2380 | | * hid_t dset_id; IN: Chunked dataset ID |
2381 | | * hsize_t *offset IN: Logical position of the chunk's |
2382 | | * first element in the dataspace |
2383 | | * unsigned *filter_mask OUT: Mask for identifying the filters in use |
2384 | | * haddr_t *addr OUT: Address of the chunk |
2385 | | * hsize_t *size OUT: Size of the chunk |
2386 | | * |
2387 | | * Return: Non-negative on success, negative on failure |
2388 | | * |
2389 | | *------------------------------------------------------------------------- |
2390 | | */ |
2391 | | herr_t |
2392 | | H5Dget_chunk_info_by_coord(hid_t dset_id, const hsize_t *offset, unsigned *filter_mask /*out*/, |
2393 | | haddr_t *addr /*out*/, hsize_t *size /*out*/) |
2394 | 0 | { |
2395 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset for this operation */ |
2396 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2397 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
2398 | 0 | herr_t ret_value = SUCCEED; |
2399 | |
|
2400 | 0 | FUNC_ENTER_API(FAIL) |
2401 | | |
2402 | | /* Check arguments */ |
2403 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2404 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
2405 | 0 | if (NULL == filter_mask && NULL == addr && NULL == size) |
2406 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, |
2407 | 0 | "invalid arguments, must have at least one non-null output argument"); |
2408 | 0 | if (NULL == offset) |
2409 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument (null)"); |
2410 | | |
2411 | | /* Set up VOL callback arguments */ |
2412 | 0 | dset_opt_args.get_chunk_info_by_coord.offset = offset; |
2413 | 0 | dset_opt_args.get_chunk_info_by_coord.filter_mask = filter_mask; |
2414 | 0 | dset_opt_args.get_chunk_info_by_coord.addr = addr; |
2415 | 0 | dset_opt_args.get_chunk_info_by_coord.size = size; |
2416 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_GET_CHUNK_INFO_BY_COORD; |
2417 | 0 | vol_cb_args.args = &dset_opt_args; |
2418 | | |
2419 | | /* Call private function to get the chunk info given the chunk's index */ |
2420 | 0 | if (H5VL_dataset_optional(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
2421 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk info by its logical coordinates"); |
2422 | | |
2423 | 0 | done: |
2424 | 0 | FUNC_LEAVE_API(ret_value) |
2425 | 0 | } /* end H5Dget_chunk_info_by_coord() */ |
2426 | | |
2427 | | /*------------------------------------------------------------------------- |
2428 | | * Function: H5Dchunk_iter |
2429 | | * |
2430 | | * Purpose: Iterates over all chunks in dataset with given callback and user data. |
2431 | | * |
2432 | | * Parameters: |
2433 | | * hid_t dset_id; IN: Chunked dataset ID |
2434 | | * hid_t dxpl_id; IN: Dataset transfer property list ID |
2435 | | * H5D_chunk_iter_op_t cb IN: User callback function, called for every chunk. |
2436 | | * void *op_data IN/OUT: Optional user data passed on to user callback. |
2437 | | * |
2438 | | * Return: Non-negative on success, negative on failure |
2439 | | * |
2440 | | *------------------------------------------------------------------------- |
2441 | | */ |
2442 | | herr_t |
2443 | | H5Dchunk_iter(hid_t dset_id, hid_t dxpl_id, H5D_chunk_iter_op_t op, void *op_data) |
2444 | 0 | { |
2445 | 0 | H5VL_object_t *vol_obj = NULL; /* Dataset for this operation */ |
2446 | 0 | H5VL_optional_args_t vol_cb_args; /* Arguments to VOL callback */ |
2447 | 0 | H5VL_native_dataset_optional_args_t dset_opt_args; /* Arguments for optional operation */ |
2448 | 0 | herr_t ret_value = SUCCEED; |
2449 | |
|
2450 | 0 | FUNC_ENTER_API(FAIL) |
2451 | | |
2452 | | /* Check arguments */ |
2453 | 0 | if (NULL == (vol_obj = H5VL_vol_object_verify(dset_id, H5I_DATASET))) |
2454 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier"); |
2455 | 0 | if (NULL == op) |
2456 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid callback to chunk iteration"); |
2457 | | |
2458 | | /* Get the default dataset transfer property list if the user didn't provide one */ |
2459 | 0 | if (H5P_DEFAULT == dxpl_id) |
2460 | 0 | dxpl_id = H5P_DATASET_XFER_DEFAULT; |
2461 | 0 | else if (true != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) |
2462 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dxpl_id is not a dataset transfer property list ID"); |
2463 | | |
2464 | | /* Set up VOL callback arguments */ |
2465 | 0 | dset_opt_args.chunk_iter.op = op; |
2466 | 0 | dset_opt_args.chunk_iter.op_data = op_data; |
2467 | 0 | vol_cb_args.op_type = H5VL_NATIVE_DATASET_CHUNK_ITER; |
2468 | 0 | vol_cb_args.args = &dset_opt_args; |
2469 | | |
2470 | | /* Iterate over the chunks */ |
2471 | 0 | if ((ret_value = H5VL_dataset_optional(vol_obj, &vol_cb_args, dxpl_id, H5_REQUEST_NULL)) < 0) |
2472 | 0 | HERROR(H5E_DATASET, H5E_BADITER, "error iterating over dataset chunks"); |
2473 | |
|
2474 | 0 | done: |
2475 | 0 | FUNC_LEAVE_API(ret_value) |
2476 | 0 | } /* end H5Dchunk_iter() */ |