1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Purpose: Link callbacks for the native VOL connector
*
*/
#define H5L_FRIEND /* Suppress error about including H5Lpkg */
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Gprivate.h" /* Groups */
#include "H5Iprivate.h" /* IDs */
#include "H5Lpkg.h" /* Links */
#include "H5Pprivate.h" /* Property lists */
#include "H5VLprivate.h" /* Virtual Object Layer */
#include "H5VLnative_private.h" /* Native VOL connector */
/*-------------------------------------------------------------------------
* Function: H5VL__native_link_create
*
* Purpose: Handles the link create callback
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params,
hid_t lcpl_id, hid_t H5_ATTR_UNUSED lapl_id, hid_t H5_ATTR_UNUSED dxpl_id,
void H5_ATTR_UNUSED **req, va_list arguments)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
switch (create_type) {
case H5VL_LINK_CREATE_HARD: {
H5G_loc_t cur_loc;
H5G_loc_t link_loc;
void * cur_obj = HDva_arg(arguments, void *);
H5VL_loc_params_t *cur_params = HDva_arg(arguments, H5VL_loc_params_t *);
if (NULL != cur_obj && H5G_loc_real(cur_obj, cur_params->obj_type, &cur_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
if (NULL != obj && H5G_loc_real(obj, loc_params->obj_type, &link_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* H5Lcreate_hard */
if (H5VL_OBJECT_BY_NAME == cur_params->type) {
H5G_loc_t *cur_loc_p, *link_loc_p;
/* Set up current & new location pointers */
cur_loc_p = &cur_loc;
link_loc_p = &link_loc;
if (NULL == cur_obj)
cur_loc_p = link_loc_p;
else if (NULL == obj)
link_loc_p = cur_loc_p;
else if (cur_loc_p->oloc->file != link_loc_p->oloc->file)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
"source and destination should be in the same file.")
/* Create the link */
if ((ret_value =
H5L__create_hard(cur_loc_p, cur_params->loc_data.loc_by_name.name, link_loc_p,
loc_params->loc_data.loc_by_name.name, lcpl_id)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link")
} /* end if */
else { /* H5Olink */
/* Link to the object */
if (H5L_link(&link_loc, loc_params->loc_data.loc_by_name.name, &cur_loc, lcpl_id) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to create link")
} /* end else */
break;
}
case H5VL_LINK_CREATE_SOFT: {
char * target_name = HDva_arg(arguments, char *);
H5G_loc_t link_loc; /* Group location for new link */
if (H5G_loc_real(obj, loc_params->obj_type, &link_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Create the link */
if ((ret_value = H5L__create_soft(target_name, &link_loc, loc_params->loc_data.loc_by_name.name,
lcpl_id)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link")
break;
}
case H5VL_LINK_CREATE_UD: {
H5G_loc_t link_loc; /* Group location for new link */
H5L_type_t link_type = (H5L_type_t)HDva_arg(arguments, int);
void * udata = HDva_arg(arguments, void *);
size_t udata_size = HDva_arg(arguments, size_t);
if (H5G_loc_real(obj, loc_params->obj_type, &link_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Create link */
if (H5L__create_ud(&link_loc, loc_params->loc_data.loc_by_name.name, udata, udata_size, link_type,
lcpl_id) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link")
break;
}
default:
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "invalid link creation call")
} /* end switch */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__native_link_create() */
/*-------------------------------------------------------------------------
* Function: H5VL__native_link_copy
*
* Purpose: Handles the link copy callback
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__native_link_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj,
const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t H5_ATTR_UNUSED lapl_id,
hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
{
H5G_loc_t src_loc, *src_loc_p;
H5G_loc_t dst_loc, *dst_loc_p;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
if (NULL != src_obj && H5G_loc_real(src_obj, loc_params1->obj_type, &src_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
if (NULL != dst_obj && H5G_loc_real(dst_obj, loc_params2->obj_type, &dst_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Set up src & dst location pointers */
src_loc_p = &src_loc;
dst_loc_p = &dst_loc;
if (NULL == src_obj)
src_loc_p = dst_loc_p;
else if (NULL == dst_obj)
dst_loc_p = src_loc_p;
/* Copy the link */
if (H5L__move(src_loc_p, loc_params1->loc_data.loc_by_name.name, dst_loc_p,
loc_params2->loc_data.loc_by_name.name, TRUE, lcpl_id) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTCOPY, FAIL, "unable to copy link")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__native_link_copy() */
/*-------------------------------------------------------------------------
* Function: H5VL__native_link_move
*
* Purpose: Handles the link move callback
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__native_link_move(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj,
const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t H5_ATTR_UNUSED lapl_id,
hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
{
H5G_loc_t src_loc, *src_loc_p;
H5G_loc_t dst_loc, *dst_loc_p;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
if (NULL != src_obj && H5G_loc_real(src_obj, loc_params1->obj_type, &src_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
if (NULL != dst_obj && H5G_loc_real(dst_obj, loc_params2->obj_type, &dst_loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Set up src & dst location pointers */
src_loc_p = &src_loc;
dst_loc_p = &dst_loc;
if (NULL == src_obj)
src_loc_p = dst_loc_p;
else if (NULL == dst_obj)
dst_loc_p = src_loc_p;
/* Move the link */
if (H5L__move(src_loc_p, loc_params1->loc_data.loc_by_name.name, dst_loc_p,
loc_params2->loc_data.loc_by_name.name, FALSE, lcpl_id) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTMOVE, FAIL, "unable to move link")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__native_link_move() */
/*-------------------------------------------------------------------------
* Function: H5VL__native_link_get
*
* Purpose: Handles the link get callback
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__native_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_t get_type,
hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, va_list arguments)
{
H5G_loc_t loc;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
switch (get_type) {
/* H5Lget_info/H5Lget_info_by_idx */
case H5VL_LINK_GET_INFO: {
H5L_info2_t *linfo2 = HDva_arg(arguments, H5L_info2_t *);
/* Get the link information */
if (loc_params->type == H5VL_OBJECT_BY_NAME) { /* H5Lget_info */
if (H5L_get_info(&loc, loc_params->loc_data.loc_by_name.name, linfo2) < 0)
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link info")
} /* end if */
else if (loc_params->type == H5VL_OBJECT_BY_IDX) { /* H5Lget_info_by_idx */
if (H5L__get_info_by_idx(
&loc, loc_params->loc_data.loc_by_idx.name, loc_params->loc_data.loc_by_idx.idx_type,
loc_params->loc_data.loc_by_idx.order, loc_params->loc_data.loc_by_idx.n, linfo2) < 0)
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link info")
} /* end else-if */
else
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link info")
break;
}
/* H5Lget_name_by_idx */
case H5VL_LINK_GET_NAME: {
char * name = HDva_arg(arguments, char *);
size_t size = HDva_arg(arguments, size_t);
ssize_t *ret = HDva_arg(arguments, ssize_t *);
/* Get the link name */
if ((*ret = H5L__get_name_by_idx(&loc, loc_params->loc_data.loc_by_idx.name,
loc_params->loc_data.loc_by_idx.idx_type,
loc_params->loc_data.loc_by_idx.order,
loc_params->loc_data.loc_by_idx.n, name, size)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link info")
break;
}
/* H5Lget_val/H5Lget_val_by_idx */
case H5VL_LINK_GET_VAL: {
void * buf = HDva_arg(arguments, void *);
size_t size = HDva_arg(arguments, size_t);
/* Get the link information */
if (loc_params->type == H5VL_OBJECT_BY_NAME) { /* H5Lget_val */
if (H5L__get_val(&loc, loc_params->loc_data.loc_by_name.name, buf, size) < 0)
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link value")
}
else if (loc_params->type == H5VL_OBJECT_BY_IDX) { /* H5Lget_val_by_idx */
if (H5L__get_val_by_idx(&loc, loc_params->loc_data.loc_by_idx.name,
loc_params->loc_data.loc_by_idx.idx_type,
loc_params->loc_data.loc_by_idx.order,
loc_params->loc_data.loc_by_idx.n, buf, size) < 0)
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link val")
}
else
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to get link val")
break;
}
default:
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from link")
} /* end switch */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__native_link_get() */
/*-------------------------------------------------------------------------
* Function: H5VL__native_link_specific
*
* Purpose: Handles the link specific callback
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__native_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_specific_t specific_type,
hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, va_list arguments)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
switch (specific_type) {
case H5VL_LINK_EXISTS: {
htri_t * ret = HDva_arg(arguments, htri_t *);
H5G_loc_t loc;
if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Check for the existence of the link */
if ((*ret = H5L__exists(&loc, loc_params->loc_data.loc_by_name.name)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_NOTFOUND, FAIL, "unable to specific link info")
break;
}
case H5VL_LINK_ITER: {
H5G_loc_t loc;
hbool_t recursive = (hbool_t)HDva_arg(arguments, unsigned);
H5_index_t idx_type = (H5_index_t)HDva_arg(arguments, int); /* enum work-around */
H5_iter_order_t order = (H5_iter_order_t)HDva_arg(arguments, int); /* enum work-around */
hsize_t * idx_p = HDva_arg(arguments, hsize_t *);
H5L_iterate2_t op = HDva_arg(arguments, H5L_iterate2_t);
void * op_data = HDva_arg(arguments, void *);
/* Get the location */
if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
/* Visit or iterate over the links */
if (loc_params->type == H5VL_OBJECT_BY_SELF) {
if (recursive) {
/* H5Lvisit */
if ((ret_value = H5G_visit(&loc, ".", idx_type, order, op, op_data)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_BADITER, FAIL, "link visitation failed")
} /* end if */
else {
/* H5Literate */
if ((ret_value = H5L_iterate(&loc, ".", idx_type, order, idx_p, op, op_data)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_BADITER, FAIL, "error iterating over links")
} /* end else */
} /* end if */
else if (loc_params->type == H5VL_OBJECT_BY_NAME) {
if (recursive) {
/* H5Lvisit_by_name */
if ((ret_value = H5G_visit(&loc, loc_params->loc_data.loc_by_name.name, idx_type, order,
op, op_data)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_BADITER, FAIL, "link visitation failed")
} /* end if */
else {
/* H5Literate_by_name */
if ((ret_value = H5L_iterate(&loc, loc_params->loc_data.loc_by_name.name, idx_type, order,
idx_p, op, op_data)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_BADITER, FAIL, "error iterating over links")
} /* end else */
} /* end else-if */
else
HGOTO_ERROR(H5E_LINK, H5E_UNSUPPORTED, FAIL, "unknown link iterate params")
break;
}
case H5VL_LINK_DELETE: {
H5G_loc_t loc;
if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Unlink */
if (loc_params->type == H5VL_OBJECT_BY_NAME) { /* H5Ldelete */
if (H5L__delete(&loc, loc_params->loc_data.loc_by_name.name) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTDELETE, FAIL, "unable to delete link")
} /* end if */
else if (loc_params->type == H5VL_OBJECT_BY_IDX) { /* H5Ldelete_by_idx */
if (H5L__delete_by_idx(
&loc, loc_params->loc_data.loc_by_idx.name, loc_params->loc_data.loc_by_idx.idx_type,
loc_params->loc_data.loc_by_idx.order, loc_params->loc_data.loc_by_idx.n) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CANTDELETE, FAIL, "unable to delete link")
} /* end else-if */
else
HGOTO_ERROR(H5E_LINK, H5E_CANTDELETE, FAIL, "unable to delete link")
break;
}
default:
HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation")
} /* end switch */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__native_link_specific() */
|