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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5Gnode.c
* Jun 26 1997
* Robb Matzke <matzke@llnl.gov>
*
* Purpose: Functions for handling symbol table nodes. A
* symbol table node is a small collection of symbol
* table entries. A B-tree usually points to the
* symbol table nodes for any given symbol table.
*
*-------------------------------------------------------------------------
*/
#define H5G_PACKAGE /*suppress error about including H5Gpkg */
#define H5F_PACKAGE /*suppress error about including H5Fpkg */
/* Packages needed by this file... */
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fpkg.h" /* File access */
#include "H5FLprivate.h" /* Free Lists */
#include "H5Gpkg.h" /* Groups */
#include "H5HLprivate.h" /* Local Heaps */
#include "H5MFprivate.h" /* File memory management */
#include "H5MMprivate.h" /* Memory management */
/* Private typedefs */
/*
* Each key field of the B-link tree that points to symbol table
* nodes consists of this structure...
*/
typedef struct H5G_node_key_t {
size_t offset; /*offset into heap for name */
} H5G_node_key_t;
/*
* A symbol table node is a collection of symbol table entries. It can
* be thought of as the lowest level of the B-link tree that points to
* a collection of symbol table entries that belong to a specific symbol
* table or group.
*/
typedef struct H5G_node_t {
H5AC_info_t cache_info; /* Information for H5AC cache functions, _must_ be */
/* first field in structure */
unsigned nsyms; /*number of symbols */
H5G_entry_t *entry; /*array of symbol table entries */
} H5G_node_t;
/* Private macros */
#define H5G_NODE_VERS 1 /*symbol table node version number */
#define H5G_NODE_SIZEOF_HDR(F) (H5G_NODE_SIZEOF_MAGIC + 4)
/* PRIVATE PROTOTYPES */
static herr_t H5G_node_serialize(H5F_t *f, H5G_node_t *sym, size_t size, uint8_t *buf);
static size_t H5G_node_size(const H5F_t *f);
static herr_t H5G_node_shared_free(void *shared);
/* Metadata cache callbacks */
static H5G_node_t *H5G_node_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_udata1,
void *_udata2);
static herr_t H5G_node_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
H5G_node_t *sym, unsigned UNUSED * flags_ptr);
static herr_t H5G_node_dest(H5F_t *f, H5G_node_t *sym);
static herr_t H5G_node_clear(H5F_t *f, H5G_node_t *sym, hbool_t destroy);
static herr_t H5G_compute_size(const H5F_t *f, const H5G_node_t *sym, size_t *size_ptr);
/* B-tree callbacks */
static H5RC_t *H5G_node_get_shared(const H5F_t *f, const void *_udata);
static herr_t H5G_node_create(H5F_t *f, hid_t dxpl_id, H5B_ins_t op, void *_lt_key,
void *_udata, void *_rt_key,
haddr_t *addr_p/*out*/);
static int H5G_node_cmp2(H5F_t *f, hid_t dxpl_id, void *_lt_key, void *_udata,
void *_rt_key);
static int H5G_node_cmp3(H5F_t *f, hid_t dxpl_id, void *_lt_key, void *_udata,
void *_rt_key);
static herr_t H5G_node_found(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_lt_key,
void *_udata);
static H5B_ins_t H5G_node_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_lt_key,
hbool_t *lt_key_changed, void *_md_key,
void *_udata, void *_rt_key,
hbool_t *rt_key_changed,
haddr_t *new_node_p/*out*/);
static H5B_ins_t H5G_node_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *lt_key,
hbool_t *lt_key_changed, void *udata,
void *rt_key, hbool_t *rt_key_changed);
static herr_t H5G_node_decode_key(const H5F_t *f, const H5B_t *bt, const uint8_t *raw,
void *_key);
static herr_t H5G_node_encode_key(const H5F_t *f, const H5B_t *bt, uint8_t *raw,
void *_key);
static herr_t H5G_node_debug_key(FILE *stream, H5F_t *f, hid_t dxpl_id,
int indent, int fwidth, const void *key,
const void *udata);
/* H5G inherits cache-like properties from H5AC */
const H5AC_class_t H5AC_SNODE[1] = {{
H5AC_SNODE_ID,
(H5AC_load_func_t)H5G_node_load,
(H5AC_flush_func_t)H5G_node_flush,
(H5AC_dest_func_t)H5G_node_dest,
(H5AC_clear_func_t)H5G_node_clear,
(H5AC_size_func_t)H5G_compute_size,
}};
/* H5G inherits B-tree like properties from H5B */
H5B_class_t H5B_SNODE[1] = {{
H5B_SNODE_ID, /*id */
sizeof(H5G_node_key_t), /*sizeof_nkey */
H5G_node_get_shared, /*get_shared */
H5G_node_create, /*new */
H5G_node_cmp2, /*cmp2 */
H5G_node_cmp3, /*cmp3 */
H5G_node_found, /*found */
H5G_node_insert, /*insert */
TRUE, /*follow min branch? */
TRUE, /*follow max branch? */
H5G_node_remove, /*remove */
H5G_node_decode_key, /*decode */
H5G_node_encode_key, /*encode */
H5G_node_debug_key, /*debug */
}};
/* Declare a free list to manage the H5G_node_t struct */
H5FL_DEFINE_STATIC(H5G_node_t);
/* Declare a free list to manage sequences of H5G_entry_t's */
H5FL_SEQ_DEFINE_STATIC(H5G_entry_t);
/* Declare a free list to manage blocks of symbol node data */
H5FL_BLK_DEFINE_STATIC(symbol_node);
/* Declare a free list to manage the native key offset sequence information */
H5FL_SEQ_DEFINE_STATIC(size_t);
/* Declare a free list to manage the raw page information */
H5FL_BLK_DEFINE_STATIC(grp_page);
/*-------------------------------------------------------------------------
* Function: H5G_node_get_shared
*
* Purpose: Returns the shared B-tree info for the specified UDATA.
*
* Return: Success: Pointer to the raw B-tree page for this
file's groups
*
* Failure: Can't fail
*
* Programmer: Robb Matzke
* Wednesday, October 8, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static H5RC_t *
H5G_node_get_shared(const H5F_t *f, const void UNUSED *_udata)
{
H5RC_t *rc;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_get_shared);
assert(f);
/* Increment reference count on shared B-tree node */
rc=H5F_GRP_BTREE_SHARED(f);
H5RC_INC(rc);
/* Return the pointer to the ref-count object */
FUNC_LEAVE_NOAPI(rc);
} /* end H5G_node_get_shared() */
/*-------------------------------------------------------------------------
* Function: H5G_node_decode_key
*
* Purpose: Decodes a raw key into a native key.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jul 8 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_decode_key(const H5F_t *f, const H5B_t UNUSED *bt, const uint8_t *raw, void *_key)
{
H5G_node_key_t *key = (H5G_node_key_t *) _key;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_decode_key);
assert(f);
assert(raw);
assert(key);
H5F_DECODE_LENGTH(f, raw, key->offset);
FUNC_LEAVE_NOAPI(SUCCEED);
}
/*-------------------------------------------------------------------------
* Function: H5G_node_encode_key
*
* Purpose: Encodes a native key into a raw key.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jul 8 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_encode_key(const H5F_t *f, const H5B_t UNUSED *bt, uint8_t *raw, void *_key)
{
H5G_node_key_t *key = (H5G_node_key_t *) _key;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_encode_key);
assert(f);
assert(raw);
assert(key);
H5F_ENCODE_LENGTH(f, raw, key->offset);
FUNC_LEAVE_NOAPI(SUCCEED);
}
/*-------------------------------------------------------------------------
* Function: H5G_node_debug_key
*
* Purpose: Prints a key.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Friday, February 28, 2003
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_debug_key(FILE *stream, H5F_t *f, hid_t dxpl_id, int indent, int fwidth,
const void *_key, const void *_udata)
{
const H5G_node_key_t *key = (const H5G_node_key_t *) _key;
const H5G_bt_common_t *udata = (const H5G_bt_common_t *) _udata;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5G_node_debug_key)
HDassert(key);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Heap offset:",
(unsigned)key->offset);
if(udata->heap_addr != 0) {
H5HL_t *heap;
const char *s;
HDfprintf(stream, "%*s%-*s ", indent, "", fwidth, "Name:");
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to protect symbol name")
s = H5HL_offset_into(f, heap, key->offset);
HDfprintf(stream, "%s\n", s);
if(H5HL_unprotect(f, dxpl_id, heap, udata->heap_addr, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to unprotect symbol name")
} /* end if */
else
HDfprintf(stream, "%*s%-*s ", indent, "", fwidth, "Cannot get name; heap address not specified\n");
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_debug_key() */
/*-------------------------------------------------------------------------
* Function: H5G_node_size
*
* Purpose: Returns the total size of a symbol table node.
*
* Return: Success: Total size of the node in bytes.
*
* Failure: Never fails.
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static size_t
H5G_node_size(const H5F_t *f)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_size);
FUNC_LEAVE_NOAPI(H5G_NODE_SIZEOF_HDR(f) +
(2 * H5F_SYM_LEAF_K(f)) * H5G_SIZEOF_ENTRY(f));
}
/*-------------------------------------------------------------------------
* Function: H5G_node_load
*
* Purpose: Loads a symbol table node from the file.
*
* Return: Success: Ptr to the new table.
*
* Failure: NULL
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
* Modifications:
* Robb Matzke, 1999-07-28
* The ADDR argument is passed by value.
*
* Quincey Koziol, 2002-7-180
* Added dxpl parameter to allow more control over I/O from metadata
* cache.
*-------------------------------------------------------------------------
*/
static H5G_node_t *
H5G_node_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *_udata1,
void UNUSED * _udata2)
{
H5G_node_t *sym = NULL;
size_t size = 0;
uint8_t *buf = NULL;
const uint8_t *p = NULL;
H5G_node_t *ret_value; /*for error handling */
FUNC_ENTER_NOAPI_NOINIT(H5G_node_load);
/*
* Check arguments.
*/
assert(f);
assert(H5F_addr_defined(addr));
assert(!_udata1);
assert(NULL == _udata2);
/*
* Initialize variables.
*/
size = H5G_node_size(f);
if ((buf=H5FL_BLK_MALLOC(symbol_node,size))==NULL)
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for symbol table node");
p=buf;
if(NULL == (sym = H5FL_CALLOC(H5G_node_t)) ||
NULL == (sym->entry = H5FL_SEQ_CALLOC(H5G_entry_t, (size_t)(2 * H5F_SYM_LEAF_K(f)))))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
if(H5F_block_read(f, H5FD_MEM_BTREE, addr, size, dxpl_id, buf) < 0)
HGOTO_ERROR(H5E_SYM, H5E_READERROR, NULL, "unable to read symbol table node");
/* magic */
if(HDmemcmp(p, H5G_NODE_MAGIC, (size_t)H5G_NODE_SIZEOF_MAGIC))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "bad symbol table node signature");
p += 4;
/* version */
if(H5G_NODE_VERS != *p++)
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "bad symbol table node version");
/* reserved */
p++;
/* number of symbols */
UINT16DECODE(p, sym->nsyms);
/* entries */
if(H5G_ent_decode_vec(f, &p, sym->entry, sym->nsyms) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "unable to decode symbol table entries");
/* Set return value */
ret_value = sym;
done:
if(buf)
H5FL_BLK_FREE(symbol_node,buf);
if(!ret_value) {
if (sym)
if(H5G_node_dest(f, sym)<0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, NULL, "unable to destroy symbol table node");
}
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5G_node_flush
*
* Purpose: Flush a symbol table node to disk.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
* Modifications:
* rky, 1998-08-28
* Only p0 writes metadata to disk.
*
* Robb Matzke, 1999-07-28
* The ADDR argument is passed by value.
*
* Quincey Koziol, 2002-7-180
* Added dxpl parameter to allow more control over I/O from metadata
* cache.
*
* Pedro Vicente, <pvn@ncsa.uiuc.edu> 18 Sep 2002
* Added `id to name' support.
*
* JRM -- 8/21/06
* Added the flags_ptr parameter. This parameter exists to
* allow the flush routine to report to the cache if the
* entry is resized or renamed as a result of the flush.
* *flags_ptr is set to H5C_CALLBACK__NO_FLAGS_SET on entry.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5G_node_t *sym, unsigned UNUSED * flags_ptr)
{
uint8_t *buf = NULL;
size_t size;
unsigned u;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5G_node_flush);
/*
* Check arguments.
*/
assert(f);
assert(H5F_addr_defined(addr));
assert(sym);
/*
* Look for dirty entries and set the node dirty flag.
*/
for (u = 0; u < sym->nsyms; u++)
if (sym->entry[u].dirty) {
/* Set the node's dirty flag */
sym->cache_info.is_dirty = TRUE;
/* Reset the entry's dirty flag */
sym->entry[u].dirty=FALSE;
} /* end if */
/*
* Write the symbol node to disk.
*/
if (sym->cache_info.is_dirty) {
size = H5G_node_size(f);
/* Allocate temporary buffer */
if ((buf=H5FL_BLK_MALLOC(symbol_node,size))==NULL)
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
if (H5G_node_serialize(f, sym, size, buf) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSERIALIZE, FAIL, "node serialization failed");
if (H5F_block_write(f, H5FD_MEM_BTREE, addr, size, dxpl_id, buf) < 0)
HGOTO_ERROR(H5E_SYM, H5E_WRITEERROR, FAIL, "unable to write symbol table node to the file");
H5FL_BLK_FREE(symbol_node,buf);
/* Reset the node's dirty flag */
sym->cache_info.is_dirty = FALSE;
}
/*
* Destroy the symbol node? This might happen if the node is being
* preempted from the cache.
*/
if (destroy) {
if(H5G_node_dest(f, sym)<0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to destroy symbol table node");
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5G_node_serialize
*
* Purpose: Serialize the symbol table node
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Bill Wendling
* wendling@ncsa.uiuc.edu
* Sept. 16, 2003
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_serialize(H5F_t *f, H5G_node_t *sym, size_t size, uint8_t *buf)
{
uint8_t *p;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT(H5G_node_serialize);
/* check args */
assert(f);
assert(sym);
assert(buf);
p = buf;
/* magic number */
HDmemcpy(p, H5G_NODE_MAGIC, (size_t)H5G_NODE_SIZEOF_MAGIC);
p += 4;
/* version number */
*p++ = H5G_NODE_VERS;
/* reserved */
*p++ = 0;
/* number of symbols */
UINT16ENCODE(p, sym->nsyms);
/* entries */
if (H5G_ent_encode_vec(f, &p, sym->entry, sym->nsyms) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTENCODE, FAIL, "can't serialize")
HDmemset(p, 0, size - (p - buf));
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5G_node_dest
*
* Purpose: Destroy a symbol table node in memory.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Jan 15 2003
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_dest(H5F_t UNUSED *f, H5G_node_t *sym)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_dest);
/*
* Check arguments.
*/
assert(sym);
/* Verify that node is clean */
assert (sym->cache_info.is_dirty==FALSE);
if(sym->entry)
sym->entry = H5FL_SEQ_FREE(H5G_entry_t,sym->entry);
H5FL_FREE(H5G_node_t,sym);
FUNC_LEAVE_NOAPI(SUCCEED);
} /* end H5G_node_dest() */
/*-------------------------------------------------------------------------
* Function: H5G_node_clear
*
* Purpose: Mark a symbol table node in memory as non-dirty.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 20 2003
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_clear(H5F_t *f, H5G_node_t *sym, hbool_t destroy)
{
unsigned u; /* Local index variable */
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT(H5G_node_clear);
/*
* Check arguments.
*/
assert(sym);
/* Look for dirty entries and reset their dirty flag. */
for(u = 0; u < sym->nsyms; u++)
sym->entry[u].dirty=FALSE;
sym->cache_info.is_dirty = FALSE;
/*
* Destroy the symbol node? This might happen if the node is being
* preempted from the cache.
*/
if (destroy)
if (H5G_node_dest(f, sym) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to destroy symbol table node");
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5G_node_clear() */
/*-------------------------------------------------------------------------
* Function: H5G_compute_size
*
* Purpose: Compute the size in bytes of the specified instance of
* H5G_node_t on disk, and return it in *size_ptr. On failure
* the value of size_ptr is undefined.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: John Mainzer
* 5/13/04
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_compute_size(const H5F_t *f, const H5G_node_t UNUSED *sym, size_t *size_ptr)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_compute_size);
/*
* Check arguments.
*/
assert(f);
assert(size_ptr);
*size_ptr = H5G_node_size(f);
FUNC_LEAVE_NOAPI(SUCCEED);
} /* H5G_compute_size() */
/*-------------------------------------------------------------------------
* Function: H5G_node_create
*
* Purpose: Creates a new empty symbol table node. This function is
* called by the B-tree insert function for an empty tree. It
* is also called internally to split a symbol node with LT_KEY
* and RT_KEY null pointers.
*
* Return: Success: Non-negative. The address of symbol table
* node is returned through the ADDR_P argument.
*
* Failure: Negative
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_create(H5F_t *f, hid_t dxpl_id, H5B_ins_t UNUSED op, void *_lt_key,
void UNUSED *_udata, void *_rt_key, haddr_t *addr_p/*out*/)
{
H5G_node_key_t *lt_key = (H5G_node_key_t *) _lt_key;
H5G_node_key_t *rt_key = (H5G_node_key_t *) _rt_key;
H5G_node_t *sym = NULL;
hsize_t size = 0;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5G_node_create);
/*
* Check arguments.
*/
assert(f);
assert(H5B_INS_FIRST == op);
if(NULL == (sym = H5FL_CALLOC(H5G_node_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
size = H5G_node_size(f);
if(HADDR_UNDEF == (*addr_p = H5MF_alloc(f, H5FD_MEM_BTREE, dxpl_id, size)))
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to allocate file space");
sym->entry = H5FL_SEQ_CALLOC(H5G_entry_t, (size_t)(2 * H5F_SYM_LEAF_K(f)));
if(NULL==sym->entry)
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
if(H5AC_set(f, dxpl_id, H5AC_SNODE, *addr_p, sym, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to cache symbol table leaf node");
/*
* The left and right symbols in an empty tree are both the
* empty string stored at offset zero by the H5G functions. This
* allows the comparison functions to work correctly without knowing
* that there are no symbols.
*/
if(lt_key)
lt_key->offset = 0;
if(rt_key)
rt_key->offset = 0;
done:
if(ret_value < 0) {
if(sym != NULL) {
if(sym->entry != NULL)
H5FL_SEQ_FREE(H5G_entry_t, sym->entry);
H5FL_FREE(H5G_node_t, sym);
} /* end if */
} /* end if */
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5G_node_cmp2
*
* Purpose: Compares two keys from a B-tree node (LT_KEY and RT_KEY).
* The UDATA pointer supplies extra data not contained in the
* keys (in this case, the heap address).
*
* Return: Success: negative if LT_KEY is less than RT_KEY.
*
* positive if LT_KEY is greater than RT_KEY.
*
* zero if LT_KEY and RT_KEY are equal.
*
* Failure: FAIL (same as LT_KEY<RT_KEY)
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
H5G_node_cmp2(H5F_t *f, hid_t dxpl_id, void *_lt_key, void *_udata, void *_rt_key)
{
H5G_bt_common_t *udata = (H5G_bt_common_t *) _udata;
H5G_node_key_t *lt_key = (H5G_node_key_t *) _lt_key;
H5G_node_key_t *rt_key = (H5G_node_key_t *) _rt_key;
H5HL_t *heap = NULL;
const char *s1, *s2;
const char *base; /* Base of heap */
int ret_value;
FUNC_ENTER_NOAPI_NOINIT(H5G_node_cmp2)
HDassert(udata);
HDassert(lt_key);
HDassert(rt_key);
/* Get base address of heap */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to protect symbol name")
base = H5HL_offset_into(f, heap, (size_t)0);
/* Get pointers to string names */
s1 = base + lt_key->offset;
s2 = base + rt_key->offset;
/* Set return value */
ret_value = HDstrcmp(s1, s2);
done:
if(heap && H5HL_unprotect(f, dxpl_id, heap, udata->heap_addr, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to unprotect symbol name")
FUNC_LEAVE_NOAPI(ret_value)
} /* H5G_node_cmp2() */
/*-------------------------------------------------------------------------
* Function: H5G_node_cmp3
*
* Purpose: Compares two keys from a B-tree node (LT_KEY and RT_KEY)
* against another key (not necessarily the same type)
* pointed to by UDATA.
*
* Return: Success: negative if the UDATA key is less than
* or equal to the LT_KEY
*
* positive if the UDATA key is greater
* than the RT_KEY.
*
* zero if the UDATA key falls between
* the LT_KEY (exclusive) and the
* RT_KEY (inclusive).
*
* Failure: FAIL (same as UDATA < LT_KEY)
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
H5G_node_cmp3(H5F_t *f, hid_t dxpl_id, void *_lt_key, void *_udata, void *_rt_key)
{
H5G_bt_common_t *udata = (H5G_bt_common_t *) _udata;
H5G_node_key_t *lt_key = (H5G_node_key_t *) _lt_key;
H5G_node_key_t *rt_key = (H5G_node_key_t *) _rt_key;
H5HL_t *heap = NULL;
const char *s;
const char *base; /* Base of heap */
int ret_value=0; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5G_node_cmp3)
/* Get base address of heap */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to protect symbol name")
base = H5HL_offset_into(f, heap, (size_t)0);
/* left side */
s = base + lt_key->offset;
if(HDstrcmp(udata->name, s) <= 0)
HGOTO_DONE(-1);
/* right side */
s = base + rt_key->offset;
if(HDstrcmp(udata->name, s) > 0)
HGOTO_DONE(1);
done:
if(heap && H5HL_unprotect(f, dxpl_id, heap, udata->heap_addr, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to unprotect symbol name")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_cmp3() */
/*-------------------------------------------------------------------------
* Function: H5G_node_found
*
* Purpose: The B-tree search engine has found the symbol table node
* which contains the requested symbol if the symbol exists.
* This function should examine that node for the symbol and
* return information about the symbol through the UDATA
* structure which contains the symbol name on function
* entry.
*
* If the operation flag in UDATA is H5G_OPER_FIND, then
* the entry is copied from the symbol table to the UDATA
* entry field. Otherwise the entry is copied from the
* UDATA entry field to the symbol table.
*
* Return: Success: Non-negative if found and data returned through
* the UDATA pointer.
*
* Failure: Negative if not found.
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 23 1997
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_found(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *_lt_key,
void *_udata)
{
H5G_bt_lkp_t *udata = (H5G_bt_lkp_t *) _udata;
H5G_node_t *sn = NULL;
H5HL_t *heap = NULL;
unsigned lt = 0, idx = 0, rt;
int cmp = 1;
const char *s;
const char *base; /* Base of heap */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5G_node_found)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(udata);
/*
* Load the symbol table node for exclusive access.
*/
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, FAIL, "unable to protect symbol table node")
/* Get base address of heap */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->common.heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to protect symbol name")
base = H5HL_offset_into(f, heap, (size_t)0);
/*
* Binary search.
*/
rt = sn->nsyms;
while(lt < rt && cmp) {
idx = (lt + rt) / 2;
s = base + sn->entry[idx].name_off;
cmp = HDstrcmp(udata->common.name, s);
if (cmp < 0)
rt = idx;
else
lt = idx + 1;
} /* end while */
if(H5HL_unprotect(f, dxpl_id, heap, udata->common.heap_addr, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to unprotect symbol name")
heap = NULL; base = NULL;
if(cmp)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found")
/* Call user's callback operator */
if((udata->op)(&sn->entry[idx], udata->op_data) < 0)
HGOTO_ERROR(H5E_SYM, H5E_BADITER, FAIL, "iterator callback failed")
done:
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to release symbol table node")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_found() */
/*-------------------------------------------------------------------------
* Function: H5G_node_insert
*
* Purpose: The B-tree insertion engine has found the symbol table node
* which should receive the new symbol/address pair. This
* function adds it to that node unless it already existed.
*
* If the node has no room for the symbol then the node is
* split into two nodes. The original node contains the
* low values and the new node contains the high values.
* The new symbol table entry is added to either node as
* appropriate. When a split occurs, this function will
* write the maximum key of the low node to the MID buffer
* and return the address of the new node.
*
* If the new key is larger than RIGHT then update RIGHT
* with the new key.
*
* Return: Success: An insertion command for the caller, one of
* the H5B_INS_* constants. The address of the
* new node, if any, is returned through the
* NEW_NODE_P argument. NEW_NODE_P might not be
* initialized if the return value is
* H5B_INS_NOOP.
*
* Failure: H5B_INS_ERROR, NEW_NODE_P might not be
* initialized.
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 24 1997
*
*-------------------------------------------------------------------------
*/
static H5B_ins_t
H5G_node_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr,
void UNUSED *_lt_key, hbool_t UNUSED *lt_key_changed,
void *_md_key, void *_udata,
void *_rt_key, hbool_t *rt_key_changed,
haddr_t *new_node_p)
{
H5G_node_key_t *md_key = (H5G_node_key_t *) _md_key;
H5G_node_key_t *rt_key = (H5G_node_key_t *) _rt_key;
H5G_bt_ins_t *udata = (H5G_bt_ins_t *) _udata;
H5G_node_t *sn = NULL, *snrt = NULL;
unsigned sn_flags = H5AC__NO_FLAGS_SET, snrt_flags = H5AC__NO_FLAGS_SET;
H5HL_t *heap = NULL;
const char *s;
const char *base; /* Base of heap */
unsigned lt = 0, rt; /* Binary search cntrs */
int cmp = 1, idx = -1;
H5G_node_t *insert_into = NULL; /*node that gets new entry*/
H5G_entry_t ent; /* Entry to insert in node */
H5B_ins_t ret_value = H5B_INS_ERROR;
FUNC_ENTER_NOAPI_NOINIT(H5G_node_insert)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(md_key);
HDassert(rt_key);
HDassert(udata);
HDassert(new_node_p);
/*
* Load the symbol node.
*/
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5B_INS_ERROR, "unable to protect symbol table node")
/* Get base address of heap */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->common.heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5B_INS_ERROR, "unable to protect symbol name")
base = H5HL_offset_into(f, heap, (size_t)0);
/*
* Where does the new symbol get inserted? We use a binary search.
*/
rt = sn->nsyms;
while(lt < rt) {
idx = (lt + rt) / 2;
s = base + sn->entry[idx].name_off;
if(0 == (cmp = HDstrcmp(udata->common.name, s))) /*already present */ {
HCOMMON_ERROR(H5E_SYM, H5E_CANTINSERT, "symbol is already present in symbol table");
if(H5HL_unprotect(f, dxpl_id, heap, udata->common.heap_addr, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, H5B_INS_ERROR, "unable to unprotect symbol name")
heap = NULL; base = NULL;
HGOTO_DONE(H5B_INS_ERROR)
} /* end if */
if (cmp < 0)
rt = idx;
else
lt = idx + 1;
} /* end while */
idx += cmp > 0 ? 1 : 0;
if(H5HL_unprotect(f, dxpl_id, heap, udata->common.heap_addr, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, H5B_INS_ERROR, "unable to unprotect symbol name")
heap = NULL; base = NULL;
/* Convert link information & name to symbol table entry */
if(H5G_ent_convert(f, udata->common.heap_addr, udata->common.name, udata->lnk, &ent, dxpl_id) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTCONVERT, H5B_INS_ERROR, "unable to convert link")
/* Determine where to place entry in node */
if(sn->nsyms >= 2 * H5F_SYM_LEAF_K(f)) {
/*
* The node is full. Split it into a left and right
* node and return the address of the new right node (the
* left node is at the same address as the original node).
*/
ret_value = H5B_INS_RIGHT;
/* The right node */
if(H5G_node_create(f, dxpl_id, H5B_INS_FIRST, NULL, NULL, NULL, new_node_p/*out*/) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, H5B_INS_ERROR, "unable to split symbol table node")
if(NULL == (snrt = H5AC_protect(f, dxpl_id, H5AC_SNODE, *new_node_p, NULL, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5B_INS_ERROR, "unable to split symbol table node")
HDmemcpy(snrt->entry, sn->entry + H5F_SYM_LEAF_K(f),
H5F_SYM_LEAF_K(f) * sizeof(H5G_entry_t));
snrt->nsyms = H5F_SYM_LEAF_K(f);
snrt_flags |= H5AC__DIRTIED_FLAG;
/* The left node */
HDmemset(sn->entry + H5F_SYM_LEAF_K(f), 0,
H5F_SYM_LEAF_K(f) * sizeof(H5G_entry_t));
sn->nsyms = H5F_SYM_LEAF_K(f);
sn_flags |= H5AC__DIRTIED_FLAG;
/* The middle key */
md_key->offset = sn->entry[sn->nsyms - 1].name_off;
/* Where to insert the new entry? */
if(idx <= (int)H5F_SYM_LEAF_K(f)) {
insert_into = sn;
if(idx == (int)H5F_SYM_LEAF_K(f))
md_key->offset = ent.name_off;
} else {
idx -= H5F_SYM_LEAF_K(f);
insert_into = snrt;
if(idx == (int)H5F_SYM_LEAF_K (f)) {
rt_key->offset = ent.name_off;
*rt_key_changed = TRUE;
} /* end if */
} /* end else */
} else {
/* Where to insert the new entry? */
ret_value = H5B_INS_NOOP;
sn_flags |= H5AC__DIRTIED_FLAG;
insert_into = sn;
if(idx == (int)sn->nsyms) {
rt_key->offset = ent.name_off;
*rt_key_changed = TRUE;
} /* end if */
} /* end else */
/* Move entries down to make room for new entry */
HDmemmove(insert_into->entry + idx + 1, insert_into->entry + idx,
(insert_into->nsyms - idx) * sizeof(H5G_entry_t));
/* Copy new entry into table */
H5G_ent_copy(&(insert_into->entry[idx]), &ent, H5_COPY_SHALLOW);
/* Flag entry as dirty */
insert_into->entry[idx].dirty = TRUE;
/* Increment # of symbols in table */
insert_into->nsyms += 1;
done:
if(snrt && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, *new_node_p, snrt, snrt_flags) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5B_INS_ERROR, "unable to release symbol table node")
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, sn_flags) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5B_INS_ERROR, "unable to release symbol table node")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_insert() */
/*-------------------------------------------------------------------------
* Function: H5G_node_remove
*
* Purpose: The B-tree removal engine has found the symbol table node
* which should contain the name which is being removed. This
* function removes the name from the symbol table and
* decrements the link count on the object to which the name
* points.
*
* If the udata->name parameter is set to NULL, then remove
* all entries in this symbol table node. This only occurs
* during the deletion of the entire group, so don't bother
* freeing individual name entries in the local heap, the group's
* symbol table removal code will just free the entire local
* heap eventually. Do reduce the link counts for each object
* however.
*
* Return: Success: If all names are removed from the symbol
* table node then H5B_INS_REMOVE is returned;
* otherwise H5B_INS_NOOP is returned.
*
* Failure: H5B_INS_ERROR
*
* Programmer: Robb Matzke
* Thursday, September 24, 1998
*
*-------------------------------------------------------------------------
*/
static H5B_ins_t
H5G_node_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_lt_key/*in,out*/,
hbool_t UNUSED *lt_key_changed/*out*/,
void *_udata/*in,out*/, void *_rt_key/*in,out*/,
hbool_t *rt_key_changed/*out*/)
{
H5G_node_key_t *lt_key = (H5G_node_key_t *)_lt_key;
H5G_node_key_t *rt_key = (H5G_node_key_t *)_rt_key;
H5G_bt_rm_t *udata = (H5G_bt_rm_t *)_udata;
H5G_node_t *sn = NULL;
unsigned sn_flags = H5AC__NO_FLAGS_SET;
H5HL_t *heap = NULL;
unsigned heap_flags = H5AC__NO_FLAGS_SET;
unsigned lt = 0, rt, idx = 0;
int cmp = 1;
H5B_ins_t ret_value = H5B_INS_ERROR;
FUNC_ENTER_NOAPI_NOINIT(H5G_node_remove)
/* Check arguments */
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(lt_key);
HDassert(rt_key);
HDassert(udata);
/* Load the symbol table */
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5B_INS_ERROR, "unable to protect symbol table node")
/* "Normal" removal of a single entry from the symbol table node */
if(udata->common.name != NULL) {
H5L_type_t lnk_type; /* Type of link being removed */
haddr_t lnk_addr; /* Address of object (for hard link) */
size_t len; /* Length of string in local heap */
const char *base; /* Base of heap */
const char *s; /* Pointer to string in local heap */
/* Lock the heap down */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->common.heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_CANTPROTECT, H5B_INS_ERROR, "unable to protect local heap")
/* Get base address of heap */
base = H5HL_offset_into(f, heap, (size_t)0);
/* Find the name with a binary search */
rt = sn->nsyms;
while(lt < rt && cmp) {
idx = (lt + rt) / 2;
s = base + sn->entry[idx].name_off;
cmp = HDstrcmp(udata->common.name, s);
if(cmp < 0)
rt = idx;
else
lt = idx + 1;
} /* end while */
if(cmp)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5B_INS_ERROR, "name not found")
if(sn->entry[idx].type == H5G_CACHED_SLINK) {
/* Set the type of the link removed */
lnk_type = H5L_TYPE_SOFT;
lnk_addr = HADDR_UNDEF;
/* Remove the soft link's value from the local heap */
s = H5HL_offset_into(f, heap, sn->entry[idx].cache.slink.lval_offset);
if(s) {
len = HDstrlen(s) + 1;
if(H5HL_remove(f, dxpl_id, heap, sn->entry[idx].cache.slink.lval_offset, len, &heap_flags) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, H5B_INS_ERROR, "unable to remove soft link from local heap")
} /* end if */
} /* end if */
else {
/* Set the link information */
lnk_type = H5L_TYPE_HARD;
HDassert(H5F_addr_defined(sn->entry[idx].header));
lnk_addr = sn->entry[idx].header;
} /* end else */
/* Get a pointer to the name of the link */
if(NULL == (s = H5HL_offset_into(f, heap, sn->entry[idx].name_off)))
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to get link name")
/* Get the object's type */
if(H5G_link_name_replace(f, dxpl_id, udata->grp_full_path_r, s, lnk_type, lnk_addr) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to get object type")
/* Decrement the ref. count for hard links, if requested */
if(lnk_type == H5L_TYPE_HARD && udata->adj_link) {
H5O_loc_t tmp_oloc; /* Temporary object location */
/* Build temporary object location */
tmp_oloc.file = f;
tmp_oloc.addr = lnk_addr;
if(H5O_link(&tmp_oloc, -1, dxpl_id) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, H5B_INS_ERROR, "unable to decrement object link count")
} /* end if */
/* Remove the link's name from the local heap */
len = HDstrlen(s) + 1;
if(H5HL_remove(f, dxpl_id, heap, sn->entry[idx].name_off, len, &heap_flags) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, H5B_INS_ERROR, "unable to remove link name from local heap")
/* Remove the entry from the symbol table node */
if(1 == sn->nsyms) {
/*
* We are about to remove the only symbol in this node. Copy the left
* key to the right key and mark the right key as dirty. Free this
* node and indicate that the pointer to this node in the B-tree
* should be removed also.
*/
HDassert(0 == idx);
*rt_key = *lt_key;
*rt_key_changed = TRUE;
sn->nsyms = 0;
if(H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, addr, (hsize_t)H5G_node_size(f)) < 0
|| H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__DIRTIED_FLAG | H5C__DELETED_FLAG) < 0) {
sn = NULL;
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, H5B_INS_ERROR, "unable to free symbol table node")
} /* end if */
sn = NULL;
ret_value = H5B_INS_REMOVE;
} else if(0 == idx) {
/*
* We are about to remove the left-most entry from the symbol table
* node but there are other entries to the right. No key values
* change.
*/
sn->nsyms -= 1;
sn_flags |= H5AC__DIRTIED_FLAG;
HDmemmove(sn->entry + idx, sn->entry + idx + 1,
(sn->nsyms-idx) * sizeof(H5G_entry_t));
ret_value = H5B_INS_NOOP;
} else if (idx + 1 == sn->nsyms) {
/*
* We are about to remove the right-most entry from the symbol table
* node but there are other entries to the left. The right key
* should be changed to reflect the new right-most entry.
*/
sn->nsyms -= 1;
sn_flags |= H5AC__DIRTIED_FLAG;
rt_key->offset = sn->entry[sn->nsyms - 1].name_off;
*rt_key_changed = TRUE;
ret_value = H5B_INS_NOOP;
} else {
/*
* We are about to remove an entry from the middle of a symbol table
* node.
*/
sn->nsyms -= 1;
sn_flags |= H5AC__DIRTIED_FLAG;
HDmemmove(sn->entry + idx, sn->entry + idx + 1,
(sn->nsyms - idx) * sizeof(H5G_entry_t));
ret_value = H5B_INS_NOOP;
} /* end else */
} /* end if */
/* Remove all entries from node, during B-tree deletion */
else {
H5O_loc_t tmp_oloc; /* Temporary object location */
/* Build temporary object location */
tmp_oloc.file = f;
/* Reduce the link count for all entries in this node */
for(idx = 0; idx < sn->nsyms; idx++) {
if(!(H5G_CACHED_SLINK == sn->entry[idx].type)) {
/* Decrement the reference count, if requested */
if(udata->adj_link) {
HDassert(H5F_addr_defined(sn->entry[idx].header));
tmp_oloc.addr = sn->entry[idx].header;
if(H5O_link(&tmp_oloc, -1, dxpl_id) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, H5B_INS_ERROR, "unable to decrement object link count")
} /* end if */
} /* end if */
} /* end for */
/*
* We are about to remove all the symbols in this node. Copy the left
* key to the right key and mark the right key as dirty. Free this
* node and indicate that the pointer to this node in the B-tree
* should be removed also.
*/
*rt_key = *lt_key;
*rt_key_changed = TRUE;
sn->nsyms = 0;
if(H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, addr, (hsize_t)H5G_node_size(f)) < 0
|| H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__DIRTIED_FLAG | H5C__DELETED_FLAG) < 0) {
sn = NULL;
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, H5B_INS_ERROR, "unable to free symbol table node")
} /* end if */
sn = NULL;
ret_value = H5B_INS_REMOVE;
} /* end else */
done:
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, sn_flags) < 0)
HDONE_ERROR(H5E_SYM, H5E_CANTUNPROTECT, H5B_INS_ERROR, "unable to release symbol table node")
if(heap && H5HL_unprotect(f, dxpl_id, heap, udata->common.heap_addr, heap_flags) < 0)
HDONE_ERROR(H5E_SYM, H5E_CANTUNPROTECT, H5B_INS_ERROR, "unable to unprotect local heap")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_remove() */
/*-------------------------------------------------------------------------
* Function: H5G_node_iterate
*
* Purpose: This function gets called during a group iterate operation.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jun 24 1997
*
*-------------------------------------------------------------------------
*/
int
H5G_node_iterate(H5F_t *f, hid_t dxpl_id, const void UNUSED *_lt_key, haddr_t addr,
const void UNUSED *_rt_key, void *_udata)
{
H5G_bt_it_it_t *udata = (H5G_bt_it_it_t *)_udata;
H5G_node_t *sn = NULL;
H5HL_t *heap = NULL;
char buf[1024], *s = buf; /* Buffer for link name & pointer to link name */
size_t buf_size = sizeof(buf); /* Size of link name buffer */
unsigned nsyms; /* # of symbols in node */
H5G_entry_t *ents = NULL; /* Copy of entries in this node */
unsigned u; /* Local index variable */
int ret_value;
FUNC_ENTER_NOAPI(H5G_node_iterate, H5_ITER_ERROR)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(udata);
/*
* Save information about the symbol table node since we can't lock it
* because we're about to call an application function.
*/
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5_ITER_ERROR, "unable to load symbol table node")
nsyms = sn->nsyms;
if(NULL == (ents = H5FL_SEQ_MALLOC(H5G_entry_t, (size_t)nsyms)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed")
HDmemcpy(ents, sn->entry, sizeof(H5G_entry_t) * nsyms);
if(H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) != SUCCEED) {
sn = NULL;
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to release object header")
} /* end if */
sn = NULL; /* Make certain future references will be caught */
/*
* Iterate over the symbol table node entries.
*/
for(u = 0, ret_value = H5_ITER_CONT; u < nsyms && !ret_value; u++) {
if(udata->skip > 0)
--udata->skip;
else {
size_t n; /* Length of link name */
const char *name; /* Pointer to link name in heap */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5_ITER_ERROR, "unable to protect symbol name")
name = H5HL_offset_into(f, heap, ents[u].name_off);
HDassert(name);
n = HDstrlen(name);
/* Allocate space or point to existing buffer */
if((n + 1) > sizeof(buf)) {
if(s != buf)
H5MM_xfree(s);
if(NULL == (s = H5MM_malloc(n + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed")
buf_size = n + 1;
} /* end if */
else
s = buf;
/* Make a copy of the name */
HDstrcpy(s, name);
if(H5HL_unprotect(f, dxpl_id, heap, udata->heap_addr, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to unprotect symbol name")
heap = NULL; name = NULL;
/* Check which type of callback to make */
switch(udata->lnk_op->op_type) {
case H5G_LINK_OP_OLD:
/* Make the old-type application callback */
ret_value = (udata->lnk_op->u.old_op)(udata->group_id, s, udata->op_data);
break;
case H5G_LINK_OP_APP:
{
H5L_info_t info; /* Link info for entry */
/* Make a link info for an entry */
if(H5G_ent_to_info(f, dxpl_id, &info, udata->heap_addr, &ents[u]) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, H5_ITER_ERROR, "unable to get info for symbol table entry")
/* Make the application callback */
ret_value = (udata->lnk_op->u.app_op)(udata->group_id, s, &info, udata->op_data);
}
break;
case H5G_LINK_OP_LIB:
/* Call the library's callback */
{
H5O_link_t lnk; /* Link for entry */
/* Convert the entry to a link */
if(H5G_ent_to_link(f, dxpl_id, &lnk, udata->heap_addr, NULL, &ents[u], s) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTCONVERT, H5_ITER_ERROR, "unable to convert symbol table entry to link")
/* Call the library's callback */
ret_value = (udata->lnk_op->u.lib_op)(&lnk, udata->op_data);
/* Release memory for link object */
if(H5O_msg_reset(H5O_LINK_ID, &lnk) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, H5_ITER_ERROR, "unable to release link message")
}
} /* end switch */
} /* end else */
/* Increment the number of entries passed through */
/* (whether we skipped them or not) */
if(udata->final_ent)
(*udata->final_ent)++;
} /* end for */
if(ret_value < 0)
HERROR(H5E_SYM, H5E_CANTNEXT, "iteration operator failed");
done:
/* Free the memory for the name, if we used a dynamically allocated buffer */
if(s != buf)
H5MM_xfree(s);
if(heap && H5HL_unprotect(f, dxpl_id, heap, udata->heap_addr, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to unprotect symbol name")
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) != SUCCEED)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to release object header")
if(ents)
H5FL_SEQ_FREE(H5G_entry_t, ents);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_iterate() */
/*-------------------------------------------------------------------------
* Function: H5G_node_sumup
*
* Purpose: This function gets called during a group iterate operation
* to return total number of members in the group.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Raymond Lu
* Nov 20, 2002
*
*-------------------------------------------------------------------------
*/
int
H5G_node_sumup(H5F_t *f, hid_t dxpl_id, const void UNUSED *_lt_key, haddr_t addr,
const void UNUSED *_rt_key, void *_udata)
{
hsize_t *num_objs = (hsize_t *)_udata;
H5G_node_t *sn = NULL;
int ret_value = H5_ITER_CONT;
FUNC_ENTER_NOAPI(H5G_node_sumup, H5_ITER_ERROR)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(num_objs);
/* Find the object node and add the number of symbol entries. */
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5_ITER_ERROR, "unable to load symbol table node")
*num_objs += sn->nsyms;
done:
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) != SUCCEED)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to release object header")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_sumup() */
/*-------------------------------------------------------------------------
* Function: H5G_node_name
*
* Purpose: This function gets called during a group iterate operation
* to return object name by giving idx.
*
* Return: 0 if object isn't found in this node; 1 if object is found;
* Negative on failure
*
* Programmer: Raymond Lu
* Nov 20, 2002
*
*-------------------------------------------------------------------------
*/
int
H5G_node_by_idx(H5F_t *f, hid_t dxpl_id, const void UNUSED *_lt_key, haddr_t addr,
const void UNUSED *_rt_key, void *_udata)
{
H5G_bt_it_idx_common_t *udata = (H5G_bt_it_idx_common_t *)_udata;
H5G_node_t *sn = NULL;
int ret_value = H5_ITER_CONT;
FUNC_ENTER_NOAPI(H5G_node_by_idx, H5_ITER_ERROR);
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(udata);
/* Get a pointer to the symbol table node */
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5_ITER_ERROR, "unable to load symbol table node");
/* Find the node, locate the object symbol table entry and retrieve the name */
if(udata->idx >= udata->num_objs && udata->idx < (udata->num_objs + sn->nsyms)) {
hsize_t ent_idx; /* Entry index in this node */
/* Compute index of entry */
ent_idx = udata->idx - udata->num_objs;
/* Call 'by index' callback */
HDassert(udata->op);
if((udata->op)(&sn->entry[ent_idx], udata) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, H5B_INS_ERROR, "'by index' callback failed")
/* Indicate that we found the entry we are interested in */
ret_value = H5_ITER_STOP;
} /* end if */
else
udata->num_objs += sn->nsyms;
done:
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) != SUCCEED)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to release object header")
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5G_node_by_idx() */
/*-------------------------------------------------------------------------
* Function: H5G_node_init
*
* Purpose: This function gets called during a file opening to initialize
* global information about group B-tree nodes for file.
*
* Return: Non-negative on success
* Negative on failure
*
* Programmer: Quincey Koziol
* Jul 5, 2004
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_node_init(H5F_t *f)
{
H5B_shared_t *shared; /* Shared B-tree node info */
size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_node_init, FAIL);
/* Check arguments. */
assert(f);
/* Allocate space for the shared structure */
if(NULL==(shared=H5FL_MALLOC(H5B_shared_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for shared B-tree info")
/* Set up the "global" information for this file's groups */
shared->type= H5B_SNODE;
shared->two_k=2*H5F_KVALUE(f,H5B_SNODE);
shared->sizeof_rkey = H5F_SIZEOF_SIZE(f); /*the name offset */
assert(shared->sizeof_rkey);
shared->sizeof_rnode = H5B_nodesize(f, shared, &shared->sizeof_keys);
assert(shared->sizeof_rnode);
if(NULL==(shared->page=H5FL_BLK_MALLOC(grp_page,shared->sizeof_rnode)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree page")
#ifdef H5_USING_PURIFY
HDmemset(shared->page,0,shared->sizeof_rnode);
#endif /* H5_USING_PURIFY */
if(NULL==(shared->nkey=H5FL_SEQ_MALLOC(size_t,(size_t)(2*H5F_KVALUE(f,H5B_SNODE)+1))))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree page")
/* Initialize the offsets into the native key buffer */
for(u=0; u<(2*H5F_KVALUE(f,H5B_SNODE)+1); u++)
shared->nkey[u]=u*H5B_SNODE->sizeof_nkey;
/* Make shared B-tree info reference counted */
if(NULL==(f->shared->grp_btree_shared=H5RC_create(shared,H5G_node_shared_free)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create ref-count wrapper for shared B-tree info")
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5G_node_init() */
/*-------------------------------------------------------------------------
* Function: H5G_node_close
*
* Purpose: This function gets called during a file close to shutdown
* global information about group B-tree nodes for file.
*
* Return: Non-negative on success
* Negative on failure
*
* Programmer: Quincey Koziol
* Jul 5, 2004
*
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_node_close(const H5F_t *f)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_close)
/* Check arguments. */
assert(f);
/* Free the raw B-tree node buffer */
if (H5F_GRP_BTREE_SHARED(f))
H5RC_DEC(H5F_GRP_BTREE_SHARED(f));
FUNC_LEAVE_NOAPI(SUCCEED);
} /* end H5G_node_close */
/*-------------------------------------------------------------------------
* Function: H5G_node_shared_free
*
* Purpose: Free B-tree shared info
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Thursday, July 8, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5G_node_shared_free (void *_shared)
{
H5B_shared_t *shared = (H5B_shared_t *)_shared;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_node_shared_free)
/* Free the raw B-tree node buffer */
H5FL_BLK_FREE(grp_page,shared->page);
/* Free the B-tree native key offsets buffer */
H5FL_SEQ_FREE(size_t,shared->nkey);
/* Free the shared B-tree info */
H5FL_FREE(H5B_shared_t,shared);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5G_node_shared_free() */
/*-------------------------------------------------------------------------
* Function: H5G_node_copy
*
* Purpose: This function gets called during a group iterate operation
* to copy objects of this node into a new location.
*
* Return: 0(zero) on success/Negative on failure
*
* Programmer: Peter Cao
* Sept 10, 2005
*
*-------------------------------------------------------------------------
*/
int
H5G_node_copy(H5F_t *f, hid_t dxpl_id, const void UNUSED *_lt_key, haddr_t addr,
const void UNUSED *_rt_key, void *_udata)
{
H5G_bt_it_cpy_t *udata = (H5G_bt_it_cpy_t *)_udata;
const H5O_loc_t *src_oloc = udata->src_oloc;
H5O_copy_t *cpy_info = udata->cpy_info;
H5HL_t *heap = NULL;
H5G_node_t *sn = NULL;
unsigned int i; /* Local index variable */
int ret_value = H5_ITER_CONT;
FUNC_ENTER_NOAPI(H5G_node_copy, H5_ITER_ERROR)
/* Check arguments. */
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(udata);
/* load the symbol table into memory from the source file */
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5_ITER_ERROR, "unable to load symbol table node")
/* get the base address of the heap */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->src_heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5_ITER_ERROR, "unable to protect symbol name")
/* copy object in this node one by one */
for(i = 0; i < sn->nsyms; i++) {
H5G_entry_t *src_ent = &(sn->entry[i]); /* Convenience variable to refer to current source group entry */
H5O_link_t lnk; /* Link to insert */
const char *name; /* Name of source object */
H5G_entry_t tmp_src_ent; /* Temperary copy. Change will not affect the cache */
/* expand soft link */
if(H5G_CACHED_SLINK == src_ent->type && cpy_info->expand_soft_link) {
H5O_info_t oinfo; /* Information about object pointed to by soft link */
H5G_loc_t grp_loc; /* Group location holding soft link */
H5G_name_t grp_path; /* Path for group holding soft link */
char *link_name; /* Pointer to value of soft link */
/* Make a temporary copy, so that it will not change the info in the cache */
HDmemcpy(&tmp_src_ent, src_ent, sizeof(H5G_entry_t));
/* Set up group location for soft link to start in */
H5G_name_reset(&grp_path);
grp_loc.path = &grp_path;
grp_loc.oloc = (H5O_loc_t *)src_oloc;
/* Get pointer to link value in local heap */
link_name = (char *)H5HL_offset_into(f, heap, tmp_src_ent.cache.slink.lval_offset);
/* Check if the object pointed by the soft link exists in the source file */
if(H5G_loc_info(&grp_loc, link_name, &oinfo, H5P_DEFAULT, dxpl_id) >= 0) {
tmp_src_ent.header = oinfo.addr;
src_ent = &tmp_src_ent;
} /* end if */
else
H5E_clear_stack(NULL); /* discard any errors from a dangling soft link */
} /* if ((H5G_CACHED_SLINK == src_ent->type)... */
/* Check if object in source group is a hard link */
if(H5F_addr_defined(src_ent->header)) {
H5O_loc_t new_dst_oloc; /* Copied object location in destination */
H5O_loc_t tmp_src_oloc; /* Temporary object location for source object */
/* Set up copied object location to fill in */
H5O_loc_reset(&new_dst_oloc);
new_dst_oloc.file = udata->dst_file;
/* Build temporary object location for source */
H5O_loc_reset(&tmp_src_oloc);
tmp_src_oloc.file = f;
tmp_src_oloc.addr = src_ent->header;
/* Copy the shared object from source to destination */
if(H5O_copy_header_map(&tmp_src_oloc, &new_dst_oloc, dxpl_id, cpy_info, TRUE) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy object")
/* Construct link information for eventual insertion */
lnk.type = H5L_TYPE_HARD;
lnk.u.hard.addr = new_dst_oloc.addr;
} /* ( H5F_addr_defined(src_ent->header)) */
else if(H5G_CACHED_SLINK == src_ent->type) {
/* it is a soft link */
/* Construct link information for eventual insertion */
lnk.type = H5L_TYPE_SOFT;
lnk.u.soft.name = H5HL_offset_into(f, heap, src_ent->cache.slink.lval_offset);
} /* else if */
else
HDassert(0 && "Unknown entry type");
/* Set up common link data */
lnk.cset = H5F_DEFAULT_CSET; /* XXX: Allow user to set this */
lnk.corder = 0; /* Creation order is not tracked for old-style links */
lnk.corder_valid = FALSE; /* Creation order is not valid */
/* lnk.name = name; */ /* This will be set in callback */
/* Determine name of source object */
name = H5HL_offset_into(f, heap, src_ent->name_off);
HDassert(name);
/* Insert the new object in the destination file's group */
/* (Don't increment the link count - that's already done above for hard links) */
if(H5G_stab_insert_real(udata->dst_file, udata->dst_stab, name, &lnk, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5_ITER_ERROR, "unable to insert the name")
} /* end of for (i=0; i<sn->nsyms; i++) */
done:
if (heap && H5HL_unprotect(f, dxpl_id, heap, udata->src_heap_addr, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to unprotect symbol name")
if (sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) != SUCCEED)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to release object header")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_copy() */
/*-------------------------------------------------------------------------
* Function: H5G_node_build_table
*
* Purpose: B-link tree callback for building table of links
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Nov 19 2006
*
*-------------------------------------------------------------------------
*/
int
H5G_node_build_table(H5F_t *f, hid_t dxpl_id, const void UNUSED *_lt_key, haddr_t addr,
const void UNUSED *_rt_key, void *_udata)
{
H5G_bt_it_bt_t *udata = (H5G_bt_it_bt_t *)_udata;
H5G_node_t *sn = NULL; /* Symbol table node */
H5HL_t *heap = NULL; /* Local heap for group */
unsigned u; /* Local index variable */
int ret_value = H5_ITER_CONT;
FUNC_ENTER_NOAPI(H5G_node_build_table, H5_ITER_ERROR)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(udata);
/*
* Save information about the symbol table node since we can't lock it
* because we're about to call an application function.
*/
if(NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5_ITER_ERROR, "unable to load symbol table node")
/* Lock down the heap for this group */
if(NULL == (heap = H5HL_protect(f, dxpl_id, udata->heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5_ITER_ERROR, "unable to protect symbol name")
/* Check if the link table needs to be extended */
if((udata->ltable->nlinks + sn->nsyms) >= udata->alloc_nlinks) {
size_t na = MAX((udata->ltable->nlinks + sn->nsyms), (udata->alloc_nlinks * 2)); /* Double # of links allocated */
H5O_link_t *x; /* Pointer to larger array of links */
/* Re-allocate the link table */
if((x = H5MM_realloc(udata->ltable->lnks, sizeof(H5O_link_t) * na)) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "memory allocation failed")
udata->ltable->lnks = x;
} /* end if */
/* Iterate over the symbol table node entries, adding to link table */
for(u = 0; u < sn->nsyms; u++) {
const char *name; /* Pointer to link name in heap */
unsigned linkno; /* Link allocated */
/* Get pointer to link's name in the heap */
name = H5HL_offset_into(f, heap, sn->entry[u].name_off);
HDassert(name);
/* Determine the link to operate on in the table */
linkno = udata->ltable->nlinks++;
/* Convert the entry to a link */
if(H5G_ent_to_link(f, dxpl_id, &udata->ltable->lnks[linkno], HADDR_UNDEF, heap, &sn->entry[u], name) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTCONVERT, H5_ITER_ERROR, "unable to convert symbol table entry to link")
} /* end for */
done:
/* Release the locked items */
if(heap && H5HL_unprotect(f, dxpl_id, heap, udata->heap_addr, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to unprotect symbol name")
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) != SUCCEED)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5_ITER_ERROR, "unable to release object header")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_build_table() */
/*-------------------------------------------------------------------------
* Function: H5G_node_debug
*
* Purpose: Prints debugging information about a symbol table node
* or a B-tree node for a symbol table B-tree.
*
* Return: 0(zero) on success/Negative on failure
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Aug 4 1997
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_node_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent,
int fwidth, haddr_t heap_addr)
{
H5G_node_t *sn = NULL;
const char *s;
H5HL_t *heap = NULL;
unsigned u;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_node_debug, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
/*
* If we couldn't load the symbol table node, then try loading the
* B-tree node.
*/
if (NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ))) {
H5G_bt_common_t udata; /*data to pass through B-tree */
H5E_clear_stack(NULL); /* discard that error */
udata.heap_addr = heap_addr;
if ( H5B_debug(f, dxpl_id, addr, stream, indent, fwidth, H5B_SNODE, &udata) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, FAIL, "unable to debug B-tree node");
HGOTO_DONE(SUCCEED);
}
fprintf(stream, "%*sSymbol Table Node...\n", indent, "");
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
"Dirty:",
sn->cache_info.is_dirty ? "Yes" : "No");
fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Size of Node (in bytes):", (unsigned)H5G_node_size(f));
fprintf(stream, "%*s%-*s %u of %u\n", indent, "", fwidth,
"Number of Symbols:",
sn->nsyms, (unsigned)(2 * H5F_SYM_LEAF_K(f)));
indent += 3;
fwidth = MAX(0, fwidth - 3);
for(u = 0; u < sn->nsyms; u++) {
fprintf(stream, "%*sSymbol %u:\n", indent - 3, "", u);
if(heap_addr > 0 && H5F_addr_defined(heap_addr)) {
if(NULL == (heap = H5HL_protect(f, dxpl_id, heap_addr)))
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to protect symbol name");
s = H5HL_offset_into(f, heap, sn->entry[u].name_off);
if(s)
fprintf(stream, "%*s%-*s `%s'\n", indent, "", fwidth, "Name:", s);
if(H5HL_unprotect(f, dxpl_id, heap, heap_addr, FALSE) < 0)
HGOTO_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to unprotect symbol name")
heap = NULL; s = NULL;
}
else
fprintf(stream, "%*s%-*s\n", indent, "", fwidth, "Warning: Invalid heap address given, name not displayed!");
H5G_ent_debug(f, dxpl_id, sn->entry + u, stream, indent, fwidth, heap_addr);
} /* end for */
done:
if(sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_SYM, H5E_PROTECT, FAIL, "unable to release symbol table node")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_node_debug() */
|