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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* 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: Reference routines.
*/
/****************/
/* Module Setup */
/****************/
#include "H5Rmodule.h" /* This source code file is part of the H5R module */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5ESprivate.h" /* Event Sets */
#include "H5Iprivate.h" /* IDs */
#include "H5MMprivate.h" /* Memory management */
#include "H5Rpkg.h" /* References */
#include "H5Sprivate.h" /* Dataspaces */
#include "H5VLprivate.h" /* Virtual Object Layer */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Local Prototypes */
/********************/
/* Helper routines for sync/async API calls */
static hid_t H5R__open_object_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr,
H5VL_object_t **_vol_obj_ptr);
static hid_t H5R__open_region_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr,
H5VL_object_t **_vol_obj_ptr);
static hid_t H5R__open_attr_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id, void **token_ptr,
H5VL_object_t **_vol_obj_ptr);
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5Rcreate_object
*
* Purpose: Creates an object reference. The LOC_ID and NAME are used
* to locate the object pointed to.
*
* Return: Non-negative on success / Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5Rcreate_object(hid_t loc_id, const char *name, hid_t oapl_id, H5R_ref_t *ref_ptr)
{
H5VL_object_t * vol_obj = NULL; /* Object of loc_id */
H5I_type_t obj_type; /* Object type of loc_id */
hid_t file_id = H5I_INVALID_HID; /* File ID */
H5VL_object_t * vol_obj_file = NULL; /* Object of file_id */
H5VL_object_specific_args_t obj_spec_vol_cb_args; /* Arguments to VOL callback */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0};
H5VL_file_get_args_t file_get_vol_cb_args; /* Arguments to VOL callback */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE4("e", "i*si*Rr", loc_id, name, oapl_id, ref_ptr);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
if (!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given")
if (oapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list")
/* Get object access property list */
if (H5P_DEFAULT == oapl_id)
oapl_id = H5P_LINK_ACCESS_DEFAULT;
else if (TRUE != H5P_isa_class(oapl_id, H5P_LINK_ACCESS))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "oapl_id is not a link access property list ID")
/* Get the VOL object */
if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Get object type */
if ((obj_type = H5I_get_type(loc_id)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Get the file for the object */
if ((file_id = H5F_get_file_id(vol_obj, obj_type, FALSE)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Retrieve VOL file object */
if (NULL == (vol_obj_file = H5VL_vol_object(file_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Set up VOL callback arguments */
file_get_vol_cb_args.op_type = H5VL_FILE_GET_CONT_INFO;
file_get_vol_cb_args.args.get_cont_info.info = &cont_info;
/* Get container info */
if (H5VL_file_get(vol_obj_file, &file_get_vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get container info")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_NAME;
loc_params.loc_data.loc_by_name.name = name;
loc_params.loc_data.loc_by_name.lapl_id = oapl_id;
loc_params.obj_type = obj_type;
/* Set up VOL callback arguments */
obj_spec_vol_cb_args.op_type = H5VL_OBJECT_LOOKUP;
obj_spec_vol_cb_args.args.lookup.token_ptr = &obj_token;
/* Get the object token */
if (H5VL_object_specific(vol_obj, &loc_params, &obj_spec_vol_cb_args, H5P_DATASET_XFER_DEFAULT,
H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object token")
/* Create the reference (do not pass filename, since file_id is attached) */
HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE);
if (H5R__create_object(&obj_token, cont_info.token_size, (H5R_ref_priv_t *)ref_ptr) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create object reference")
/* Attach loc_id to reference and hold reference to it */
if (H5R__set_loc_id((H5R_ref_priv_t *)ref_ptr, file_id, TRUE, TRUE) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference")
done:
if (file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0)
HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file")
FUNC_LEAVE_API(ret_value)
} /* end H5Rcreate_object() */
/*-------------------------------------------------------------------------
* Function: H5Rcreate_region
*
* Purpose: Creates a region reference. The LOC_ID and NAME are used to
* locate the object pointed to and the SPACE_ID is used to
* choose the region pointed to.
*
* Return: Non-negative on success / Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, hid_t oapl_id, H5R_ref_t *ref_ptr)
{
H5VL_object_t * vol_obj = NULL; /* Object of loc_id */
H5I_type_t obj_type; /* Object type of loc_id */
hid_t file_id = H5I_INVALID_HID; /* File ID */
H5VL_object_t * vol_obj_file = NULL; /* Object of file_id */
H5VL_object_specific_args_t obj_spec_vol_cb_args; /* Arguments to VOL callback */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0};
H5VL_file_get_args_t file_get_vol_cb_args; /* Arguments to VOL callback */
struct H5S_t * space = NULL; /* Pointer to dataspace containing region */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE5("e", "i*sii*Rr", loc_id, name, space_id, oapl_id, ref_ptr);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
if (!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given")
if ((space_id == H5I_INVALID_HID) || (space_id == H5S_ALL) || (space_id == H5S_BLOCK))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reference region dataspace id must be valid")
if (NULL == (space = (struct H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
if (oapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list")
/* Get object access property list */
if (H5P_DEFAULT == oapl_id)
oapl_id = H5P_LINK_ACCESS_DEFAULT;
else if (TRUE != H5P_isa_class(oapl_id, H5P_LINK_ACCESS))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "oapl_id is not a link access property list ID")
/* Get the VOL object */
if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Get object type */
if ((obj_type = H5I_get_type(loc_id)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Get the file for the object */
if ((file_id = H5F_get_file_id(vol_obj, obj_type, FALSE)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Retrieve VOL file object */
if (NULL == (vol_obj_file = H5VL_vol_object(file_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Set up VOL callback arguments */
file_get_vol_cb_args.op_type = H5VL_FILE_GET_CONT_INFO;
file_get_vol_cb_args.args.get_cont_info.info = &cont_info;
/* Get container info */
if (H5VL_file_get(vol_obj_file, &file_get_vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get container info")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_NAME;
loc_params.loc_data.loc_by_name.name = name;
loc_params.loc_data.loc_by_name.lapl_id = oapl_id;
loc_params.obj_type = obj_type;
/* Set up VOL callback arguments */
obj_spec_vol_cb_args.op_type = H5VL_OBJECT_LOOKUP;
obj_spec_vol_cb_args.args.lookup.token_ptr = &obj_token;
/* Get the object token */
if (H5VL_object_specific(vol_obj, &loc_params, &obj_spec_vol_cb_args, H5P_DATASET_XFER_DEFAULT,
H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object token")
/* Create the reference (do not pass filename, since file_id is attached) */
HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE);
if (H5R__create_region((const H5O_token_t *)&obj_token, cont_info.token_size, space,
(H5R_ref_priv_t *)ref_ptr) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create region reference")
/* Attach loc_id to reference and hold reference to it */
if (H5R__set_loc_id((H5R_ref_priv_t *)ref_ptr, file_id, TRUE, TRUE) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference")
done:
if (file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0)
HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file")
FUNC_LEAVE_API(ret_value)
} /* end H5Rcreate_region() */
/*-------------------------------------------------------------------------
* Function: H5Rcreate_attr
*
* Purpose: Creates an attribute reference. The LOC_ID, NAME and
* ATTR_NAME are used to locate the attribute pointed to.
*
* Return: Non-negative on success / Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, hid_t oapl_id, H5R_ref_t *ref_ptr)
{
H5VL_object_t * vol_obj = NULL; /* Object of loc_id */
H5I_type_t obj_type; /* Object type of loc_id */
hid_t file_id = H5I_INVALID_HID; /* File ID */
H5VL_object_t * vol_obj_file = NULL; /* Object of file_id */
H5VL_object_specific_args_t obj_spec_vol_cb_args; /* Arguments to VOL callback */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0};
H5VL_file_get_args_t file_get_vol_cb_args; /* Arguments to VOL callback */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE5("e", "i*s*si*Rr", loc_id, name, attr_name, oapl_id, ref_ptr);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
if (!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given")
if (!attr_name || !*attr_name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name given")
if (oapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list")
/* Get object access property list */
if (H5P_DEFAULT == oapl_id)
oapl_id = H5P_LINK_ACCESS_DEFAULT;
else if (TRUE != H5P_isa_class(oapl_id, H5P_LINK_ACCESS))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "oapl_id is not a link access property list ID")
/* Get the VOL object */
if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Get object type */
if ((obj_type = H5I_get_type(loc_id)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Get the file for the object */
if ((file_id = H5F_get_file_id(vol_obj, obj_type, FALSE)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
/* Retrieve VOL file object */
if (NULL == (vol_obj_file = H5VL_vol_object(file_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Set up VOL callback arguments */
file_get_vol_cb_args.op_type = H5VL_FILE_GET_CONT_INFO;
file_get_vol_cb_args.args.get_cont_info.info = &cont_info;
/* Get container info */
if (H5VL_file_get(vol_obj_file, &file_get_vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get container info")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_NAME;
loc_params.loc_data.loc_by_name.name = name;
loc_params.loc_data.loc_by_name.lapl_id = oapl_id;
loc_params.obj_type = obj_type;
/* Set up VOL callback arguments */
obj_spec_vol_cb_args.op_type = H5VL_OBJECT_LOOKUP;
obj_spec_vol_cb_args.args.lookup.token_ptr = &obj_token;
/* Get the object token */
if (H5VL_object_specific(vol_obj, &loc_params, &obj_spec_vol_cb_args, H5P_DATASET_XFER_DEFAULT,
H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object token")
/* Create the reference (do not pass filename, since file_id is attached) */
HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE);
if (H5R__create_attr((const H5O_token_t *)&obj_token, cont_info.token_size, attr_name,
(H5R_ref_priv_t *)ref_ptr) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create attribute reference")
/* Attach loc_id to reference and hold reference to it */
if (H5R__set_loc_id((H5R_ref_priv_t *)ref_ptr, file_id, TRUE, TRUE) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference")
done:
if (file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0)
HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file")
FUNC_LEAVE_API(ret_value)
} /* end H5Rcreate_attr() */
/*-------------------------------------------------------------------------
* Function: H5Rdestroy
*
* Purpose: Destroy reference and free resources allocated during
* H5Rcreate.
*
* Return: Non-negative on success / Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5Rdestroy(H5R_ref_t *ref_ptr)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("e", "*Rr", ref_ptr);
/* Check args */
if (NULL == ref_ptr)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid reference pointer")
/* Destroy reference */
if (H5R__destroy((H5R_ref_priv_t *)ref_ptr) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTFREE, FAIL, "unable to destroy reference")
/* Memset back to 0 for safety */
HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE);
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rdestroy() */
/*-------------------------------------------------------------------------
* Function: H5Rget_type
*
* Purpose: Given a reference to some object, return the type of that
* reference.
*
* Return: Reference type / H5R_BADTYPE on failure
*
*-------------------------------------------------------------------------
*/
H5R_type_t
H5Rget_type(const H5R_ref_t *ref_ptr)
{
H5R_type_t ret_value; /* Return value */
FUNC_ENTER_API(H5R_BADTYPE)
H5TRACE1("Rt", "*Rr", ref_ptr);
/* Check args */
if (NULL == ref_ptr)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5R_BADTYPE, "invalid reference pointer")
/* Get reference type */
ret_value = H5R__get_type((const H5R_ref_priv_t *)ref_ptr);
if ((ret_value <= H5R_BADTYPE) || (ret_value >= H5R_MAXTYPE))
HGOTO_ERROR(H5E_REFERENCE, H5E_BADVALUE, H5R_BADTYPE, "invalid reference type")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rget_type() */
/*-------------------------------------------------------------------------
* Function: H5Requal
*
* Purpose: Compare two references
*
* Return: TRUE if equal, FALSE if unequal, FAIL if error
*
*-------------------------------------------------------------------------
*/
htri_t
H5Requal(const H5R_ref_t *ref1_ptr, const H5R_ref_t *ref2_ptr)
{
htri_t ret_value; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE2("t", "*Rr*Rr", ref1_ptr, ref2_ptr);
/* Check args */
if (!ref1_ptr || !ref2_ptr)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
/* Compare references */
if ((ret_value = H5R__equal((const H5R_ref_priv_t *)ref2_ptr, (const H5R_ref_priv_t *)ref2_ptr)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, FAIL, "cannot compare references")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Requal() */
/*-------------------------------------------------------------------------
* Function: H5Rcopy
*
* Purpose: Copy a reference
*
* Return: Non-negative on success / Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5Rcopy(const H5R_ref_t *src_ref_ptr, H5R_ref_t *dst_ref_ptr)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE2("e", "*Rr*Rr", src_ref_ptr, dst_ref_ptr);
/* Check args */
if (NULL == src_ref_ptr || NULL == dst_ref_ptr)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid reference pointer")
/* Copy reference */
if (H5R__copy((const H5R_ref_priv_t *)src_ref_ptr, (H5R_ref_priv_t *)dst_ref_ptr) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "cannot copy reference")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rcopy() */
/*-------------------------------------------------------------------------
* Function: H5R__open_object_api_common
*
* Purpose: This is the common function for opening an object via a reference.
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
static hid_t
H5R__open_object_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr,
H5VL_object_t **_vol_obj_ptr)
{
hid_t loc_id; /* Reference location ID */
H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */
H5VL_object_t **vol_obj_ptr =
(_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
H5I_type_t opened_type; /* Opened object type */
void * opened_obj = NULL; /* Opened object */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_STATIC
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer")
if (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE ||
H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type")
if (rapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list")
if (oapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list")
/* Retrieve loc_id from reference */
if (H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) {
/* Attempt to re-open file and pass rapl_id as a fapl_id */
if ((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file")
}
/* Verify access property list and set up collective metadata if appropriate */
if (H5CX_set_apl(&oapl_id, H5P_CLS_DACC, loc_id, FALSE) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")
/* Get object token */
if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token")
/* Set up arguments for object access by token */
if (H5VL_setup_token_args(loc_id, &obj_token, vol_obj_ptr, &loc_params) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments")
/* Open object by token */
if (NULL == (opened_obj = H5VL_object_open(*vol_obj_ptr, &loc_params, &opened_type,
H5P_DATASET_XFER_DEFAULT, token_ptr)))
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token")
/* Register object */
if ((ret_value = H5VL_register(opened_type, opened_obj, (*vol_obj_ptr)->connector, TRUE)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5R__open_object_api_common() */
/*-------------------------------------------------------------------------
* Function: H5Ropen_object
*
* Purpose: Given a reference to some object, open that object and
* return an ID for that object.
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
hid_t
H5Ropen_object(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id)
{
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_API(H5I_INVALID_HID)
H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id);
/* Open the dataset synchronously */
if ((ret_value = H5R__open_object_api_common(ref_ptr, rapl_id, oapl_id, NULL, NULL)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object synchronously")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Ropen_object() */
/*-------------------------------------------------------------------------
* Function: H5Ropen_object_async
*
* Purpose: Asynchronous version of H5Ropen_object
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
hid_t
H5Ropen_object_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr,
hid_t rapl_id, hid_t oapl_id, hid_t es_id)
{
H5VL_object_t *vol_obj = NULL; /* Object of loc_id */
void * token = NULL; /* Request token for async operation */
void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_API(H5I_INVALID_HID)
H5TRACE7("i", "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id);
/* Set up request token pointer for asynchronous operation */
if (H5ES_NONE != es_id)
token_ptr = &token; /* Point at token for VOL connector to set up */
/* Open the object asynchronously */
if ((ret_value = H5R__open_object_api_common(ref_ptr, rapl_id, oapl_id, token_ptr, &vol_obj)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object asynchronously")
/* If a token was created, add the token to the event set */
if (NULL != token)
/* clang-format off */
if (H5ES_insert(es_id, vol_obj->connector, token,
H5ARG_TRACE7(FUNC, "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id)) < 0) {
/* clang-format on */
if (H5I_dec_app_ref_always_close(ret_value) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDEC, H5I_INVALID_HID, "can't decrement count on object ID")
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set")
} /* end if */
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Ropen_object_async() */
/*-------------------------------------------------------------------------
* Function: H5R__open_region_api_common
*
* Purpose: This is the common function for opening a region.
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
static hid_t
H5R__open_region_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id, void **token_ptr,
H5VL_object_t **_vol_obj_ptr)
{
hid_t loc_id; /* Reference location ID */
H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */
H5VL_object_t **vol_obj_ptr =
(_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */
H5VL_loc_params_t loc_params; /* Location parameters */
H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */
H5O_token_t obj_token = {0}; /* Object token */
H5I_type_t opened_type; /* Opened object type */
void * opened_obj = NULL; /* Opened object */
hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */
H5S_t * space = NULL; /* Dataspace pointer (copy) */
hid_t space_id = H5I_INVALID_HID; /* Dataspace ID */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_STATIC
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer")
if ((H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_DATASET_REGION1) &&
(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_DATASET_REGION2))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type")
if (rapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list")
if (oapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list")
/* Retrieve loc_id from reference */
if (H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) {
/* Attempt to re-open file and pass rapl_id as a fapl_id */
if ((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file")
}
/* Get object token */
if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token")
/* Set up arguments for object access by token */
if (H5VL_setup_token_args(loc_id, &obj_token, vol_obj_ptr, &loc_params) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set object access arguments")
/* Open object by token */
if (NULL == (opened_obj = H5VL_object_open(*vol_obj_ptr, &loc_params, &opened_type,
H5P_DATASET_XFER_DEFAULT, token_ptr)))
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token")
/* Register object */
if ((opened_obj_id = H5VL_register(opened_type, opened_obj, (*vol_obj_ptr)->connector, FALSE)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle")
/* Get VOL object object */
if (NULL == (opened_obj = H5VL_vol_object(opened_obj_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier")
/* Set up VOL callback arguments */
vol_cb_args.op_type = H5VL_DATASET_GET_SPACE;
vol_cb_args.args.get_space.space_id = H5I_INVALID_HID;
/* Get dataspace from object */
if (H5VL_dataset_get(opened_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataspace from dataset")
space_id = vol_cb_args.args.get_space.space_id;
if (NULL == (space = (struct H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a dataspace")
/* Get the dataspace with the correct region selected */
if (H5R__get_region((const H5R_ref_priv_t *)ref_ptr, space) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get selection on dataspace")
/* Simply return space_id */
ret_value = space_id;
done:
if ((opened_obj_id != H5I_INVALID_HID) && (H5I_dec_ref(opened_obj_id) < 0))
HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close object")
if (H5I_INVALID_HID == ret_value) /* Cleanup on failure */
if ((space_id != H5I_INVALID_HID) && (H5I_dec_ref(space_id) < 0))
HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close dataspace")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5R__open_region_api_common() */
/*-------------------------------------------------------------------------
* Function: H5Ropen_region
*
* Purpose: Given a reference to some object, creates a copy of the dataset
* pointed to's dataspace and defines a selection in the copy
* which is the region pointed to.
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
hid_t
H5Ropen_region(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id)
{
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_API(H5I_INVALID_HID)
H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id);
/* Open the region synchronously */
if ((ret_value = H5R__open_region_api_common(ref_ptr, rapl_id, oapl_id, NULL, NULL)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open region synchronously")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Ropen_region() */
/*-------------------------------------------------------------------------
* Function: H5Ropen_region_async
*
* Purpose: Asynchronous version of H5Ropen_region
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
hid_t
H5Ropen_region_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr,
hid_t rapl_id, hid_t oapl_id, hid_t es_id)
{
H5VL_object_t *vol_obj = NULL; /* Object of loc_id */
void * token = NULL; /* Request token for async operation */
void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_API(H5I_INVALID_HID)
H5TRACE7("i", "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id);
/* Set up request token pointer for asynchronous operation */
if (H5ES_NONE != es_id)
token_ptr = &token; /* Point at token for VOL connector to set up */
/* Open the region asynchronously */
if ((ret_value = H5R__open_region_api_common(ref_ptr, rapl_id, oapl_id, token_ptr, &vol_obj)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open region asynchronously")
/* If a token was created, add the token to the event set */
if (NULL != token)
/* clang-format off */
if (H5ES_insert(es_id, vol_obj->connector, token,
H5ARG_TRACE7(FUNC, "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, oapl_id, es_id)) < 0) {
/* clang-format on */
if (H5I_dec_app_ref_always_close(ret_value) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDEC, H5I_INVALID_HID, "can't decrement count on region ID")
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set")
} /* end if */
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Ropen_region_async() */
/*-------------------------------------------------------------------------
* Function: H5R__open_attr_api_common
*
* Purpose: This is the common function for opening an attribute via a reference.
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
static hid_t
H5R__open_attr_api_common(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id, void **token_ptr,
H5VL_object_t **_vol_obj_ptr)
{
hid_t loc_id; /* Reference location ID */
H5VL_object_t * tmp_vol_obj = NULL; /* Object for loc_id */
H5VL_object_t **vol_obj_ptr =
(_vol_obj_ptr ? _vol_obj_ptr : &tmp_vol_obj); /* Ptr to object ptr for loc_id */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
H5I_type_t opened_type; /* Opened object type */
void * opened_obj = NULL; /* Opened object */
hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */
void * opened_attr = NULL; /* Opened attribute */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_STATIC
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer")
if (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_ATTR)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type")
if (rapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list")
if (aapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list")
/* Retrieve loc_id from reference */
if (H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) {
/* Attempt to re-open file and pass rapl_id as a fapl_id */
if ((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file")
}
/* Get object token */
if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token")
/* Get the VOL object */
if (NULL == (*vol_obj_ptr = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_TOKEN;
loc_params.loc_data.loc_by_token.token = &obj_token;
loc_params.obj_type = H5I_get_type(loc_id);
/* Open object by token */
if (NULL == (opened_obj = H5VL_object_open(*vol_obj_ptr, &loc_params, &opened_type,
H5P_DATASET_XFER_DEFAULT, token_ptr)))
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token")
/* Register object */
if ((opened_obj_id = H5VL_register(opened_type, opened_obj, (*vol_obj_ptr)->connector, FALSE)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle")
/* Verify access property list and set up collective metadata if appropriate */
if (H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, FALSE) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_SELF;
loc_params.obj_type = opened_type;
/* Get VOL object object */
if (NULL == (opened_obj = H5VL_vol_object(opened_obj_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier")
/* Open the attribute */
if (NULL == (opened_attr = H5VL_attr_open(opened_obj, &loc_params,
H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr), aapl_id,
H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL)))
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open attribute: '%s'",
H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr))
/* Register the attribute and get an ID for it */
if ((ret_value = H5VL_register(H5I_ATTR, opened_attr, (*vol_obj_ptr)->connector, TRUE)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register attribute handle")
done:
if ((opened_obj_id != H5I_INVALID_HID) && (H5I_dec_ref(opened_obj_id) < 0))
HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close object")
if (H5I_INVALID_HID == ret_value) /* Cleanup on failure */
if (opened_attr && H5VL_attr_close(*vol_obj_ptr, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close attribute")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5R__open_attr_api_common() */
/*-------------------------------------------------------------------------
* Function: H5Ropen_attr
*
* Purpose: Given a reference to some attribute, open that attribute and
* return an ID for that attribute.
*
* Return: Valid ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
hid_t
H5Ropen_attr(H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id)
{
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_API(H5I_INVALID_HID)
H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, aapl_id);
/* Open the attribute synchronously */
if ((ret_value = H5R__open_attr_api_common(ref_ptr, rapl_id, aapl_id, NULL, NULL)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_OPENERROR, H5I_INVALID_HID, "unable to open attribute synchronously")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Ropen_attr() */
/*--------------------------------------------------------------------------
* Function: H5Ropen_attr_async
*
* Purpose: Asynchronous version of H5Ropen_attr
*
* Return: An attribute ID on success / H5I_INVALID_HID on failure
*
*-------------------------------------------------------------------------
*/
hid_t
H5Ropen_attr_async(const char *app_file, const char *app_func, unsigned app_line, H5R_ref_t *ref_ptr,
hid_t rapl_id, hid_t aapl_id, hid_t es_id)
{
H5VL_object_t *vol_obj = NULL; /* Object for loc_id */
void * token = NULL; /* Request token for async operation */
void ** token_ptr = H5_REQUEST_NULL; /* Pointer to request token for async operation */
hid_t ret_value; /* Return value */
FUNC_ENTER_API(H5I_INVALID_HID)
H5TRACE7("i", "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, aapl_id, es_id);
/* Set up request token pointer for asynchronous operation */
if (H5ES_NONE != es_id)
token_ptr = &token; /* Point at token for VOL connector to set up */
/* Open the attribute asynchronously */
if ((ret_value = H5R__open_attr_api_common(ref_ptr, rapl_id, aapl_id, token_ptr, &vol_obj)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_OPENERROR, H5I_INVALID_HID, "unable to open attribute asynchronously")
/* If a token was created, add the token to the event set */
if (NULL != token)
/* clang-format off */
if (H5ES_insert(es_id, vol_obj->connector, token,
H5ARG_TRACE7(FUNC, "*s*sIu*Rriii", app_file, app_func, app_line, ref_ptr, rapl_id, aapl_id, es_id)) < 0) {
/* clang-format on */
if (H5I_dec_app_ref_always_close(ret_value) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDEC, H5I_INVALID_HID,
"can't decrement count on attribute ID")
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINSERT, H5I_INVALID_HID, "can't insert token into event set")
} /* end if */
done:
FUNC_LEAVE_API(ret_value)
} /* H5Ropen_attr_async() */
/*-------------------------------------------------------------------------
* Function: H5Rget_obj_type3
*
* Purpose: Given a reference to some object, this function returns the
* type of object pointed to.
*
* Return: Non-negative on success / Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5Rget_obj_type3(H5R_ref_t *ref_ptr, hid_t rapl_id, H5O_type_t *obj_type /*out*/)
{
hid_t loc_id; /* Reference location ID */
H5VL_object_t * vol_obj = NULL; /* Object of loc_id */
H5VL_object_get_args_t vol_cb_args; /* Arguments to VOL callback */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "*Rrix", ref_ptr, rapl_id, obj_type);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
if (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE ||
H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type")
if (rapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list")
/* Retrieve loc_id from reference */
if (H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr)))
/* Attempt to re-open file and pass rapl_id as a fapl_id */
if ((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, FAIL, "cannot re-open referenced file")
/* Get object token */
if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get object token")
/* Get the VOL object */
if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_TOKEN;
loc_params.loc_data.loc_by_token.token = &obj_token;
loc_params.obj_type = H5I_get_type(loc_id);
/* Set up VOL callback arguments */
vol_cb_args.op_type = H5VL_OBJECT_GET_TYPE;
vol_cb_args.args.get_type.obj_type = obj_type;
/* Retrieve object's type */
if (H5VL_object_get(vol_obj, &loc_params, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "can't retrieve object type")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rget_obj_type3() */
/*-------------------------------------------------------------------------
* Function: H5Rget_file_name
*
* Purpose: Given a reference to some object, determine a file name of the
* object located into.
*
* Return: Non-negative length of the path on success / -1 on failure
*
*-------------------------------------------------------------------------
*/
ssize_t
H5Rget_file_name(const H5R_ref_t *ref_ptr, char *buf /*out*/, size_t size)
{
hid_t loc_id; /* Reference location ID */
ssize_t ret_value; /* Return value */
FUNC_ENTER_API((-1))
H5TRACE3("Zs", "*Rrxz", ref_ptr, buf, size);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer")
if (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE ||
H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type")
/* Get name */
if (H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) {
/* Un-opened external references do not have loc_id set but hold a
* copy of the filename */
if ((ret_value = H5R__get_file_name((const H5R_ref_priv_t *)ref_ptr, buf, size)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to retrieve file name")
}
else {
H5VL_object_t * vol_obj; /* Object of loc_id */
H5VL_file_get_args_t vol_cb_args; /* Arguments to VOL callback */
size_t file_name_len = 0; /* Length of file name */
/* Retrieve VOL file object */
if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid location identifier")
/* Set up VOL callback arguments */
vol_cb_args.op_type = H5VL_FILE_GET_NAME;
vol_cb_args.args.get_name.type = H5I_FILE;
vol_cb_args.args.get_name.buf_size = size;
vol_cb_args.args.get_name.buf = buf;
vol_cb_args.args.get_name.file_name_len = &file_name_len;
/* Get file name */
if (H5VL_file_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to get file name")
/* Set return value */
ret_value = (ssize_t)file_name_len;
}
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rget_file_name() */
/*-------------------------------------------------------------------------
* Function: H5Rget_obj_name
*
* Purpose: Given a reference to some object, determine a path to the
* object referenced in the file.
*
* Return: Non-negative length of the path on success / -1 on failure
*
*-------------------------------------------------------------------------
*/
ssize_t
H5Rget_obj_name(H5R_ref_t *ref_ptr, hid_t rapl_id, char *buf /*out*/, size_t size)
{
hid_t loc_id; /* Reference location ID */
H5VL_object_t * vol_obj = NULL; /* Object of loc_id */
H5VL_object_get_args_t vol_cb_args; /* Arguments to VOL callback */
H5VL_loc_params_t loc_params; /* Location parameters */
H5O_token_t obj_token = {0}; /* Object token */
size_t obj_name_len = 0; /* Length of object's name */
ssize_t ret_value = 0; /* Return value */
FUNC_ENTER_API((-1))
H5TRACE4("Zs", "*Rrixz", ref_ptr, rapl_id, buf, size);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer")
if (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE ||
H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type")
if (rapl_id < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "not a property list")
/* Retrieve loc_id from reference */
if (H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr)))
/* Attempt to re-open file and pass rapl_id as a fapl_id */
if ((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, (-1), "cannot re-open referenced file")
/* Get object token */
if (H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to get object token")
/* Get the VOL object */
if (NULL == (vol_obj = H5VL_vol_object(loc_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid location identifier")
/* Set location parameters */
loc_params.type = H5VL_OBJECT_BY_TOKEN;
loc_params.loc_data.loc_by_token.token = &obj_token;
loc_params.obj_type = H5I_get_type(loc_id);
/* Set up VOL callback arguments */
vol_cb_args.op_type = H5VL_OBJECT_GET_NAME;
vol_cb_args.args.get_name.buf_size = size;
vol_cb_args.args.get_name.buf = buf;
vol_cb_args.args.get_name.name_len = &obj_name_len;
/* Retrieve object's name */
if (H5VL_object_get(vol_obj, &loc_params, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "can't retrieve object name")
/* Set return value */
ret_value = (ssize_t)obj_name_len;
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rget_obj_name() */
/*-------------------------------------------------------------------------
* Function: H5Rget_attr_name
*
* Purpose: Given a reference to some attribute, determine its name.
*
* Return: Non-negative length of the path on success / -1 on failure
*
*-------------------------------------------------------------------------
*/
ssize_t
H5Rget_attr_name(const H5R_ref_t *ref_ptr, char *buf /*out*/, size_t size)
{
ssize_t ret_value; /* Return value */
FUNC_ENTER_API((-1))
H5TRACE3("Zs", "*Rrxz", ref_ptr, buf, size);
/* Check args */
if (ref_ptr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer")
if (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_ATTR)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type")
/* Get attribute name */
if ((ret_value = H5R__get_attr_name((const H5R_ref_priv_t *)ref_ptr, buf, size)) < 0)
HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to determine attribute name")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rget_attr_name() */
|