hdf5-pure-rust 0.3.5

Pure Rust implementation of the HDF5 file format
Documentation
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
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt;
use std::fs::{self, File, OpenOptions};
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};

use crate::error::{Error, Result};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileDriverKind {
    Sec2,
    Stdio,
    Core,
    Direct,
}

/// Return the canonical integer id assigned to a [`FileDriverKind`].
fn file_driver_kind_id(kind: FileDriverKind) -> u64 {
    match kind {
        FileDriverKind::Sec2 => 0,
        FileDriverKind::Stdio => 1,
        FileDriverKind::Core => 2,
        FileDriverKind::Direct => 3,
    }
}

#[derive(Debug)]
pub struct LocalFileDriver {
    kind: FileDriverKind,
    path: Option<PathBuf>,
    file: Option<File>,
    core_image: Vec<u8>,
    eoa: u64,
    locked: bool,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CoreFileConfig {
    pub increment: usize,
    pub backing_store: bool,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DirectFileConfig {
    pub memory_alignment: u64,
    pub block_size: u64,
    pub copy_buffer_size: usize,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct VfdRegistry {
    by_name: HashMap<String, u64>,
    by_value: HashMap<u64, String>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VfdMemType {
    Default,
    Super,
    BTree,
    RawData,
    GlobalHeap,
    LocalHeap,
    ObjectHeader,
    Draw,
    Garbage,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct VfdIoRequest {
    pub addr: u64,
    pub bytes: Vec<u8>,
}

impl Default for DirectFileConfig {
    fn default() -> Self {
        Self {
            memory_alignment: 4096,
            block_size: 4096,
            copy_buffer_size: 1024 * 1024,
        }
    }
}

impl Default for CoreFileConfig {
    fn default() -> Self {
        Self {
            increment: 64 * 1024,
            backing_store: false,
        }
    }
}

impl LocalFileDriver {
    /// `sec2` VFD: register.
    pub fn sec2_register() -> FileDriverKind {
        FileDriverKind::Sec2
    }

    /// `sec2` VFD: unregister.
    pub fn sec2_unregister() {}

    /// `sec2` VFD: open.
    pub fn sec2_open(path: impl AsRef<Path>, read_write: bool) -> Result<Self> {
        Self::open_file(FileDriverKind::Sec2, path, read_write)
    }

    /// `sec2` VFD: close.
    pub fn sec2_close(self) {}

    /// `sec2` VFD: compare two driver instances.
    pub fn sec2_cmp(&self, other: &Self) -> Ordering {
        self.driver_cmp(other)
    }

    /// `sec2` VFD: query feature flags.
    pub fn sec2_query(&self) -> u64 {
        self.driver_query()
    }

    /// `sec2` VFD: get the end-of-allocation address.
    pub fn sec2_get_eoa(&self) -> u64 {
        self.eoa
    }

    /// `sec2` VFD: set the end-of-allocation address.
    pub fn sec2_set_eoa(&mut self, eoa: u64) {
        self.eoa = eoa;
    }

    /// `sec2` VFD: get the end-of-file address.
    pub fn sec2_get_eof(&mut self) -> Result<u64> {
        self.driver_get_eof()
    }

    /// `sec2` VFD: get the underlying file handle.
    pub fn sec2_get_handle(&self) -> Option<&File> {
        self.file.as_ref()
    }

    /// `sec2` VFD: read bytes from the file.
    pub fn sec2_read(&mut self, addr: u64, buf: &mut [u8]) -> Result<()> {
        self.driver_read(addr, buf)
    }

    /// `sec2` VFD: write bytes to the file.
    pub fn sec2_write(&mut self, addr: u64, data: &[u8]) -> Result<()> {
        self.driver_write(addr, data)
    }

    /// `sec2` VFD: truncate the file to the current EOA.
    pub fn sec2_truncate(&mut self) -> Result<()> {
        self.driver_truncate()
    }

    /// `sec2` VFD: acquire an advisory file lock.
    pub fn sec2_lock(&mut self) {
        self.locked = true;
    }

    /// `sec2` VFD: release an advisory file lock.
    pub fn sec2_unlock(&mut self) {
        self.locked = false;
    }

    /// `sec2` VFD: delete the file.
    pub fn sec2_delete(path: impl AsRef<Path>) -> Result<()> {
        delete_existing(path)
    }

    /// `sec2` VFD: invoke a driver-specific control op.
    pub fn sec2_ctl(&mut self, eoa: Option<u64>) {
        if let Some(eoa) = eoa {
            self.eoa = eoa;
        }
    }

    /// `stdio` VFD: register.
    pub fn stdio_register() -> FileDriverKind {
        FileDriverKind::Stdio
    }

    /// `stdio` VFD: unregister.
    pub fn stdio_unregister() {}

    /// `stdio` VFD: initialize.
    pub fn stdio_init() -> FileDriverKind {
        FileDriverKind::Stdio
    }

    /// `stdio` VFD: open.
    pub fn stdio_open(path: impl AsRef<Path>, read_write: bool) -> Result<Self> {
        Self::open_file(FileDriverKind::Stdio, path, read_write)
    }

    /// `stdio` VFD: close.
    pub fn stdio_close(self) {}

    /// `stdio` VFD: compare two driver instances.
    pub fn stdio_cmp(&self, other: &Self) -> Ordering {
        self.driver_cmp(other)
    }

    /// `stdio` VFD: query feature flags.
    pub fn stdio_query(&self) -> u64 {
        self.driver_query()
    }

    /// `stdio` VFD: allocate space in the file.
    pub fn stdio_alloc(&mut self, size: u64) -> Result<u64> {
        self.driver_alloc(size)
    }

    /// `stdio` VFD: get the end-of-allocation address.
    pub fn stdio_get_eoa(&self) -> u64 {
        self.eoa
    }

    /// `stdio` VFD: set the end-of-allocation address.
    pub fn stdio_set_eoa(&mut self, eoa: u64) {
        self.eoa = eoa;
    }

    /// `stdio` VFD: get the end-of-file address.
    pub fn stdio_get_eof(&mut self) -> Result<u64> {
        self.driver_get_eof()
    }

    /// `stdio` VFD: get the underlying file handle.
    pub fn stdio_get_handle(&self) -> Option<&File> {
        self.file.as_ref()
    }

    /// `stdio` VFD: read bytes from the file.
    pub fn stdio_read(&mut self, addr: u64, buf: &mut [u8]) -> Result<()> {
        self.driver_read(addr, buf)
    }

    /// `stdio` VFD: write bytes to the file.
    pub fn stdio_write(&mut self, addr: u64, data: &[u8]) -> Result<()> {
        self.driver_write(addr, data)
    }

    /// `stdio` VFD: flush buffered writes to disk.
    pub fn stdio_flush(&mut self) -> Result<()> {
        self.driver_flush()
    }

    /// `stdio` VFD: truncate the file to the current EOA.
    pub fn stdio_truncate(&mut self) -> Result<()> {
        self.driver_truncate()
    }

    /// `stdio` VFD: acquire an advisory file lock.
    pub fn stdio_lock(&mut self) {
        self.locked = true;
    }

    /// `stdio` VFD: release an advisory file lock.
    pub fn stdio_unlock(&mut self) {
        self.locked = false;
    }

    /// `stdio` VFD: delete the file.
    pub fn stdio_delete(path: impl AsRef<Path>) -> Result<()> {
        delete_existing(path)
    }

    /// `direct` VFD: register.
    pub fn direct_register() -> FileDriverKind {
        FileDriverKind::Direct
    }

    /// `direct` VFD: unregister.
    pub fn direct_unregister() {}

    /// `direct` VFD: populate the default driver-specific configuration.
    pub fn direct_populate_config() -> DirectFileConfig {
        DirectFileConfig::default()
    }

    /// `direct` VFD: get the driver-specific FAPL configuration.
    pub fn direct_fapl_get(&self) -> Option<DirectFileConfig> {
        (self.kind == FileDriverKind::Direct).then(DirectFileConfig::default)
    }

    /// `direct` VFD: copy the driver-specific FAPL configuration.
    pub fn direct_fapl_copy(config: &DirectFileConfig) -> DirectFileConfig {
        config.clone()
    }

    /// `direct` VFD: open.
    pub fn direct_open(path: impl AsRef<Path>, read_write: bool) -> Result<Self> {
        Self::open_file(FileDriverKind::Direct, path, read_write)
    }

    /// `direct` VFD: check that an I/O request meets alignment requirements.
    pub fn direct_check_alignment_reqs(addr: u64, size: usize, config: &DirectFileConfig) -> bool {
        let Ok(size) = u64::try_from(size) else {
            return false;
        };
        config.memory_alignment != 0
            && config.block_size != 0
            && addr % config.memory_alignment == 0
            && size % config.block_size == 0
    }

    /// `direct` VFD: close.
    pub fn direct_close(self) {}

    /// `direct` VFD: compare two driver instances.
    pub fn direct_cmp(&self, other: &Self) -> Ordering {
        self.driver_cmp(other)
    }

    /// `direct` VFD: query feature flags.
    pub fn direct_query(&self) -> u64 {
        self.driver_query()
    }

    /// `direct` VFD: set the end-of-allocation address.
    pub fn direct_set_eoa(&mut self, eoa: u64) {
        self.eoa = eoa;
    }

    /// `direct` VFD: get the end-of-allocation address.
    pub fn direct_get_eoa(&self) -> u64 {
        self.eoa
    }

    /// `direct` VFD: get the end-of-file address.
    pub fn direct_get_eof(&mut self) -> Result<u64> {
        self.driver_get_eof()
    }

    /// `direct` VFD: get the underlying file handle.
    pub fn direct_get_handle(&self) -> Option<&File> {
        self.file.as_ref()
    }

    /// `direct` VFD: read bytes from the file.
    pub fn direct_read(&mut self, addr: u64, buf: &mut [u8]) -> Result<()> {
        self.driver_read(addr, buf)
    }

    /// `direct` VFD: write bytes to the file.
    pub fn direct_write(&mut self, addr: u64, data: &[u8]) -> Result<()> {
        self.driver_write(addr, data)
    }

    /// `direct` VFD: flush buffered writes to disk.
    pub fn direct_flush(&mut self) -> Result<()> {
        self.driver_flush()
    }

    /// `direct` VFD: truncate the file to the current EOA.
    pub fn direct_truncate(&mut self) -> Result<()> {
        self.driver_truncate()
    }

    /// `direct` VFD: acquire an advisory file lock.
    pub fn direct_lock(&mut self) {
        self.locked = true;
    }

    /// `direct` VFD: release an advisory file lock.
    pub fn direct_unlock(&mut self) {
        self.locked = false;
    }

    /// `direct` VFD: delete the file.
    pub fn direct_delete(path: impl AsRef<Path>) -> Result<()> {
        delete_existing(path)
    }

    /// `core` VFD: return the default driver-specific configuration.
    pub fn core_get_default_config() -> CoreFileConfig {
        CoreFileConfig::default()
    }

    /// `core` VFD: register.
    pub fn core_register() -> FileDriverKind {
        FileDriverKind::Core
    }

    /// `core` VFD: unregister.
    pub fn core_unregister() {}

    /// `core` VFD: get the driver-specific FAPL configuration.
    pub fn core_fapl_get(&self) -> Option<CoreFileConfig> {
        (self.kind == FileDriverKind::Core).then(CoreFileConfig::default)
    }

    /// `core` VFD: compare two driver instances.
    pub fn core_cmp(&self, other: &Self) -> Ordering {
        self.driver_cmp(other)
    }

    /// `core` VFD: query feature flags.
    pub fn core_query(&self) -> u64 {
        self.driver_query()
    }

    /// `core` VFD: get the end-of-allocation address.
    pub fn core_get_eoa(&self) -> u64 {
        self.eoa
    }

    /// `core` VFD: set the end-of-allocation address.
    pub fn core_set_eoa(&mut self, eoa: u64) {
        self.eoa = eoa;
        if let Ok(eoa) = usize::try_from(eoa) {
            if self.core_image.len() < eoa {
                self.core_image.resize(eoa, 0);
            }
        }
    }

    /// `core` VFD: get the end-of-file address.
    pub fn core_get_eof(&self) -> u64 {
        self.core_get_eof_checked().unwrap_or(u64::MAX)
    }

    /// `core` VFD: get the end-of-file address with overflow checking.
    pub fn core_get_eof_checked(&self) -> Result<u64> {
        u64::try_from(self.core_image.len())
            .map_err(|_| Error::InvalidFormat("core VFD EOF exceeds u64".into()))
    }

    /// `core` VFD: get the underlying file handle.
    pub fn core_get_handle(&self) -> Option<&[u8]> {
        (self.kind == FileDriverKind::Core).then_some(self.core_image.as_slice())
    }

    /// `core` VFD: read bytes from the file.
    pub fn core_read(&mut self, addr: u64, buf: &mut [u8]) -> Result<()> {
        self.driver_read(addr, buf)
    }

    /// `core` VFD: write bytes to the file.
    pub fn core_write(&mut self, addr: u64, data: &[u8]) -> Result<()> {
        self.driver_write(addr, data)
    }

    /// `core` VFD: flush buffered writes to disk.
    pub fn core_flush(&mut self) -> Result<()> {
        self.driver_flush()
    }

    /// `core` VFD: truncate the file to the current EOA.
    pub fn core_truncate(&mut self) -> Result<()> {
        self.driver_truncate()
    }

    /// `core` VFD: acquire an advisory file lock.
    pub fn core_lock(&mut self) {
        self.locked = true;
    }

    /// `core` VFD: release an advisory file lock.
    pub fn core_unlock(&mut self) {
        self.locked = false;
    }

    /// `core` VFD: delete the file.
    pub fn core_delete(&mut self) {
        self.core_image.clear();
        self.eoa = 0;
    }

    /// `core` VFD: mark a byte range dirty for later writeback.
    pub fn core_add_dirty_region(&mut self, addr: u64, size: u64) -> Result<()> {
        let end = addr
            .checked_add(size)
            .ok_or_else(|| Error::InvalidFormat("core VFD dirty region overflow".into()))?;
        if end > self.eoa {
            self.core_set_eoa(end);
        }
        Ok(())
    }

    /// `core` VFD: clear the in-memory dirty region list.
    pub fn core_destroy_dirty_list(&mut self) {}

    /// `core` VFD: write a buffer to the backing store.
    pub fn core_write_to_bstore(&mut self, addr: u64, data: &[u8]) -> Result<()> {
        self.core_write(addr, data)
    }

    /// VFD: allocate space in the file.
    pub fn alloc(&mut self, size: u64) -> Result<u64> {
        self.driver_alloc(size)
    }

    /// VFD: free a previously allocated region.
    pub fn free(&mut self, _addr: u64, _size: u64) {}

    /// VFD: try to extend the file by `extra` bytes.
    pub fn try_extend(&mut self, addr: u64, old_size: u64, extra: u64) -> Result<bool> {
        let end = addr
            .checked_add(old_size)
            .and_then(|v| v.checked_add(extra))
            .ok_or_else(|| Error::InvalidFormat("VFD extension overflow".into()))?;
        if end > self.eoa {
            self.eoa = end;
        }
        Ok(true)
    }

    /// Internal helper: open the on-disk file for the given driver kind.
    fn open_file(kind: FileDriverKind, path: impl AsRef<Path>, read_write: bool) -> Result<Self> {
        let mut options = OpenOptions::new();
        options.read(true);
        if read_write {
            options.write(true).create(true);
        }
        let file = options.open(path.as_ref())?;
        let eoa = file.metadata()?.len();
        Ok(Self {
            kind,
            path: Some(path.as_ref().to_path_buf()),
            file: Some(file),
            core_image: Vec::new(),
            eoa,
            locked: false,
        })
    }

    /// Dispatch [`cmp`] to the active driver implementation.
    fn driver_cmp(&self, other: &Self) -> Ordering {
        self.kind
            .cmp(&other.kind)
            .then_with(|| self.path.cmp(&other.path))
    }

    /// Dispatch [`query`] to the active driver implementation.
    fn driver_query(&self) -> u64 {
        match self.kind {
            FileDriverKind::Sec2 | FileDriverKind::Stdio | FileDriverKind::Direct => 0x01,
            FileDriverKind::Core => 0x03,
        }
    }

    /// Dispatch [`alloc`] to the active driver implementation.
    fn driver_alloc(&mut self, size: u64) -> Result<u64> {
        let addr = self.eoa;
        self.eoa = self
            .eoa
            .checked_add(size)
            .ok_or_else(|| Error::InvalidFormat("VFD allocation overflow".into()))?;
        if self.kind == FileDriverKind::Core {
            self.core_set_eoa(self.eoa);
        }
        Ok(addr)
    }

    /// Dispatch [`get_eof`] to the active driver implementation.
    fn driver_get_eof(&mut self) -> Result<u64> {
        if self.kind == FileDriverKind::Core {
            return Ok(self.core_get_eof());
        }
        let file = self
            .file
            .as_ref()
            .ok_or_else(|| Error::InvalidFormat("VFD file handle is closed".into()))?;
        Ok(file.metadata()?.len())
    }

    /// Dispatch [`read`] to the active driver implementation.
    fn driver_read(&mut self, addr: u64, buf: &mut [u8]) -> Result<()> {
        if self.kind == FileDriverKind::Core {
            let start = usize::try_from(addr)
                .map_err(|_| Error::InvalidFormat("core VFD read address too large".into()))?;
            let end = start
                .checked_add(buf.len())
                .ok_or_else(|| Error::InvalidFormat("core VFD read span overflow".into()))?;
            if end > self.core_image.len() {
                return Err(Error::InvalidFormat("core VFD read past EOF".into()));
            }
            buf.copy_from_slice(&self.core_image[start..end]);
            return Ok(());
        }
        let file = self
            .file
            .as_mut()
            .ok_or_else(|| Error::InvalidFormat("VFD file handle is closed".into()))?;
        file.seek(SeekFrom::Start(addr))?;
        file.read_exact(buf)?;
        Ok(())
    }

    /// Dispatch [`write`] to the active driver implementation.
    fn driver_write(&mut self, addr: u64, data: &[u8]) -> Result<()> {
        let data_len = u64::try_from(data.len())
            .map_err(|_| Error::InvalidFormat("VFD write length exceeds u64".into()))?;
        let end = addr
            .checked_add(data_len)
            .ok_or_else(|| Error::InvalidFormat("VFD write span overflow".into()))?;
        if self.kind == FileDriverKind::Core {
            let start = usize::try_from(addr)
                .map_err(|_| Error::InvalidFormat("core VFD write address too large".into()))?;
            let end_usize = usize::try_from(end)
                .map_err(|_| Error::InvalidFormat("core VFD write end too large".into()))?;
            if self.core_image.len() < end_usize {
                self.core_image.resize(end_usize, 0);
            }
            self.core_image[start..end_usize].copy_from_slice(data);
        } else {
            let file = self
                .file
                .as_mut()
                .ok_or_else(|| Error::InvalidFormat("VFD file handle is closed".into()))?;
            file.seek(SeekFrom::Start(addr))?;
            file.write_all(data)?;
        }
        if end > self.eoa {
            self.eoa = end;
        }
        Ok(())
    }

    /// Dispatch [`flush`] to the active driver implementation.
    fn driver_flush(&mut self) -> Result<()> {
        if let Some(file) = self.file.as_mut() {
            file.flush()?;
        }
        Ok(())
    }

    /// Dispatch [`truncate`] to the active driver implementation.
    fn driver_truncate(&mut self) -> Result<()> {
        if self.kind == FileDriverKind::Core {
            let eoa = usize::try_from(self.eoa)
                .map_err(|_| Error::InvalidFormat("core VFD EOA too large".into()))?;
            self.core_image.truncate(eoa);
            return Ok(());
        }
        let file = self
            .file
            .as_mut()
            .ok_or_else(|| Error::InvalidFormat("VFD file handle is closed".into()))?;
        file.set_len(self.eoa)?;
        Ok(())
    }
}

impl Ord for FileDriverKind {
    /// Compare two driver instances by kind then path/state.
    fn cmp(&self, other: &Self) -> Ordering {
        (*self as u8).cmp(&(*other as u8))
    }
}

impl PartialOrd for FileDriverKind {
    /// Total-order partial comparison delegating to [`cmp`].
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

/// Delete the file at `path` if it exists, ignoring not-found errors.
fn delete_existing(path: impl AsRef<Path>) -> Result<()> {
    match fs::remove_file(path.as_ref()) {
        Ok(()) => Ok(()),
        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
        Err(err) => Err(err.into()),
    }
}

/// Render a [`VfdMemType`] as its short name.
#[allow(non_snake_case)]
pub fn H5FD__mem_t_to_str(mem_type: VfdMemType) -> &'static str {
    match mem_type {
        VfdMemType::Default => "H5FD_MEM_DEFAULT",
        VfdMemType::Super => "H5FD_MEM_SUPER",
        VfdMemType::BTree => "H5FD_MEM_BTREE",
        VfdMemType::RawData => "H5FD_MEM_DRAW",
        VfdMemType::GlobalHeap => "H5FD_MEM_GHEAP",
        VfdMemType::LocalHeap => "H5FD_MEM_LHEAP",
        VfdMemType::ObjectHeader => "H5FD_MEM_OHDR",
        VfdMemType::Draw => "H5FD_MEM_DRAW",
        VfdMemType::Garbage => "H5FD_MEM_NTYPES",
    }
}

/// Initialize an empty VFD registry.
#[allow(non_snake_case)]
pub fn H5FD_init() -> VfdRegistry {
    H5FD__init_package()
}

/// Initialize the VFD package and pre-register the built-in drivers.
#[allow(non_snake_case)]
pub fn H5FD__init_package() -> VfdRegistry {
    let mut registry = VfdRegistry::default();
    H5FD_register_driver_by_name(
        &mut registry,
        "sec2",
        file_driver_kind_id(FileDriverKind::Sec2),
    );
    H5FD_register_driver_by_name(
        &mut registry,
        "stdio",
        file_driver_kind_id(FileDriverKind::Stdio),
    );
    H5FD_register_driver_by_name(
        &mut registry,
        "core",
        file_driver_kind_id(FileDriverKind::Core),
    );
    H5FD_register_driver_by_name(
        &mut registry,
        "direct",
        file_driver_kind_id(FileDriverKind::Direct),
    );
    registry
}

/// Tear down the VFD registry, dropping all driver registrations.
#[allow(non_snake_case)]
pub fn H5FD_term_package(registry: &mut VfdRegistry) {
    registry.by_name.clear();
    registry.by_value.clear();
}

/// Free a registered driver class by name.
#[allow(non_snake_case)]
pub fn H5FD__free_cls(registry: &mut VfdRegistry, name: &str) -> Option<u64> {
    H5FDunregister(registry, name)
}

/// Public API: register a VFD driver by name and value.
#[allow(non_snake_case)]
pub fn H5FDregister(registry: &mut VfdRegistry, name: &str, value: u64) -> u64 {
    H5FD_register_driver_by_name(registry, name, value)
}

/// Register a VFD driver by name and value.
#[allow(non_snake_case)]
pub fn H5FD_register(registry: &mut VfdRegistry, name: &str, value: u64) -> u64 {
    H5FDregister(registry, name, value)
}

/// Public API: unregister a VFD driver by name.
#[allow(non_snake_case)]
pub fn H5FDunregister(registry: &mut VfdRegistry, name: &str) -> Option<u64> {
    let value = registry.by_name.remove(name)?;
    registry.by_value.remove(&value);
    Some(value)
}

/// Register a VFD driver by name.
#[allow(non_snake_case)]
pub fn H5FD_register_driver_by_name(registry: &mut VfdRegistry, name: &str, value: u64) -> u64 {
    registry.by_name.insert(name.to_string(), value);
    registry.by_value.insert(value, name.to_string());
    value
}

/// Register a VFD driver by numeric value, providing its name.
#[allow(non_snake_case)]
pub fn H5FD_register_driver_by_value(registry: &mut VfdRegistry, value: u64, name: &str) -> u64 {
    H5FD_register_driver_by_name(registry, name, value)
}

/// Return whether a driver is currently registered under the given name.
#[allow(non_snake_case)]
pub fn H5FD_is_driver_registered_by_name(registry: &VfdRegistry, name: &str) -> bool {
    registry.by_name.contains_key(name)
}

/// Return the value/id of a driver registered under the given name.
#[allow(non_snake_case)]
pub fn H5FD_get_driver_id_by_name(registry: &VfdRegistry, name: &str) -> Option<u64> {
    registry.by_name.get(name).copied()
}

/// Return the value/id of a driver registered under the given name into caller storage.
#[allow(non_snake_case)]
pub fn H5FD_get_driver_id_by_name_into(
    registry: &VfdRegistry,
    name: &str,
    driver_id: &mut u64,
) -> Result<()> {
    *driver_id = H5FD_get_driver_id_by_name(registry, name)
        .ok_or_else(|| Error::InvalidFormat("VFD driver name is not registered".into()))?;
    Ok(())
}

/// Public libhdf5-style lookup of a registered VFD driver id by name.
#[allow(non_snake_case)]
pub fn H5FDget_driver_id(registry: &VfdRegistry, name: &str) -> Option<u64> {
    H5FD_get_driver_id_by_name(registry, name)
}

/// Public libhdf5-style lookup of a registered VFD driver id into caller storage.
#[allow(non_snake_case)]
pub fn H5FDget_driver_id_into(
    registry: &VfdRegistry,
    name: &str,
    driver_id: &mut u64,
) -> Result<()> {
    H5FD_get_driver_id_by_name_into(registry, name, driver_id)
}

/// Look up the name of a driver registered with the given value.
#[allow(non_snake_case)]
pub fn H5FD_get_driver_id_by_value(registry: &VfdRegistry, value: u64) -> Option<&str> {
    registry.by_value.get(&value).map(String::as_str)
}

/// Look up the name of a driver registered with the given value into caller storage.
#[allow(non_snake_case)]
pub fn H5FD_get_driver_id_by_value_into(
    registry: &VfdRegistry,
    value: u64,
    name: &mut String,
) -> Result<()> {
    let found = H5FD_get_driver_id_by_value(registry, value)
        .ok_or_else(|| Error::InvalidFormat("VFD driver value is not registered".into()))?;
    name.clear();
    name.push_str(found);
    Ok(())
}

/// Look up the class name of a driver registered with the given value.
#[allow(non_snake_case)]
pub fn H5FD_get_class(registry: &VfdRegistry, value: u64) -> Option<&str> {
    H5FD_get_driver_id_by_value(registry, value)
}

/// Driver-lookup callback used during package initialization.
#[allow(non_snake_case)]
pub fn H5FD__get_driver_cb(registry: &VfdRegistry, name: &str) -> Option<u64> {
    H5FD_get_driver_id_by_name(registry, name)
}

/// Superblock extension size required for a given driver kind.
#[allow(non_snake_case)]
pub fn H5FD_sb_size(_driver: FileDriverKind) -> usize {
    0
}

/// Return the kind of driver currently in use by the FAPL.
#[allow(non_snake_case)]
pub fn H5FD_fapl_get(driver: &LocalFileDriver) -> FileDriverKind {
    driver.kind
}

/// Public API: open a file using a given driver kind.
#[allow(non_snake_case)]
pub fn H5FDopen(
    path: impl AsRef<Path>,
    kind: FileDriverKind,
    read_write: bool,
) -> Result<LocalFileDriver> {
    H5FD_open(path, kind, read_write)
}

/// Open a file using a given driver kind.
#[allow(non_snake_case)]
pub fn H5FD_open(
    path: impl AsRef<Path>,
    kind: FileDriverKind,
    read_write: bool,
) -> Result<LocalFileDriver> {
    match kind {
        FileDriverKind::Sec2 => LocalFileDriver::sec2_open(path, read_write),
        FileDriverKind::Stdio => LocalFileDriver::stdio_open(path, read_write),
        FileDriverKind::Direct => LocalFileDriver::direct_open(path, read_write),
        FileDriverKind::Core => Err(Error::Unsupported(
            "core VFD open from path is represented by in-memory driver state".into(),
        )),
    }
}

/// Public API: close a driver instance.
#[allow(non_snake_case)]
pub fn H5FDclose(driver: LocalFileDriver) {
    H5FD_close(driver);
}

/// Close a driver instance.
#[allow(non_snake_case)]
pub fn H5FD_close(_driver: LocalFileDriver) {}

/// Public API: compare two driver instances.
#[allow(non_snake_case)]
pub fn H5FDcmp(left: &LocalFileDriver, right: &LocalFileDriver) -> Ordering {
    H5FD_cmp(left, right)
}

/// Compare two driver instances.
#[allow(non_snake_case)]
pub fn H5FD_cmp(left: &LocalFileDriver, right: &LocalFileDriver) -> Ordering {
    left.driver_cmp(right)
}

/// Public API: query the feature flags reported by a driver.
#[allow(non_snake_case)]
pub fn H5FDquery(driver: &LocalFileDriver) -> u64 {
    H5FD_get_feature_flags(driver)
}

/// Public API: query feature flags into a caller-owned output parameter.
#[allow(non_snake_case)]
pub fn H5FDquery_into(driver: &LocalFileDriver, flags: &mut u64) -> Result<()> {
    *flags = H5FD_get_feature_flags(driver);
    Ok(())
}

/// Public API: allocate `size` bytes in the file.
#[allow(non_snake_case)]
pub fn H5FDalloc(driver: &mut LocalFileDriver, size: u64) -> Result<u64> {
    H5FD_alloc(driver, size)
}

/// Internal VFD API: allocate `size` bytes in the file.
#[allow(non_snake_case)]
pub fn H5FD_alloc(driver: &mut LocalFileDriver, size: u64) -> Result<u64> {
    driver.alloc(size)
}

/// Public API: free a region previously allocated in the file.
#[allow(non_snake_case)]
pub fn H5FDfree(driver: &mut LocalFileDriver, addr: u64, size: u64) {
    H5FD_free(driver, addr, size);
}

/// Internal VFD API: free a region previously allocated in the file.
#[allow(non_snake_case)]
pub fn H5FD_free(driver: &mut LocalFileDriver, addr: u64, size: u64) {
    driver.free(addr, size);
}

/// Internal VFD API: attempt to extend an existing allocation.
#[allow(non_snake_case)]
pub fn H5FD_try_extend(
    driver: &mut LocalFileDriver,
    addr: u64,
    old_size: u64,
    extra: u64,
) -> Result<bool> {
    driver.try_extend(addr, old_size, extra)
}

/// Public API: return the current EOA.
#[allow(non_snake_case)]
pub fn H5FDget_eoa(driver: &LocalFileDriver) -> u64 {
    driver.eoa
}

/// Public API: set the current EOA.
#[allow(non_snake_case)]
pub fn H5FDset_eoa(driver: &mut LocalFileDriver, eoa: u64) {
    driver.eoa = eoa;
}

/// Public API: return the current EOF.
#[allow(non_snake_case)]
pub fn H5FDget_eof(driver: &mut LocalFileDriver) -> Result<u64> {
    driver.driver_get_eof()
}

/// Return the maximum addressable file offset for the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_get_maxaddr() -> u64 {
    u64::MAX
}

/// `H5FD_set_base_addr`: VFD base address relocation is not supported by this backend.
#[allow(non_snake_case)]
pub fn H5FD_set_base_addr(_driver: &mut LocalFileDriver, _base_addr: u64) -> Result<()> {
    Err(Error::Unsupported(
        "VFD base address relocation is not implemented in pure-Rust local-only mode".into(),
    ))
}

/// Return the feature flags reported by a driver.
#[allow(non_snake_case)]
pub fn H5FD_get_feature_flags(driver: &LocalFileDriver) -> u64 {
    driver.driver_query()
}

/// Public API: query feature flags for a registered driver id before opening a file.
#[allow(non_snake_case)]
pub fn H5FDdriver_query(registry: &VfdRegistry, driver_id: u64) -> Result<u64> {
    if !registry.by_value.contains_key(&driver_id) {
        return Err(Error::InvalidFormat(format!(
            "VFD driver id {driver_id} is not registered"
        )));
    }
    match driver_id {
        id if id == file_driver_kind_id(FileDriverKind::Sec2) => Ok(0x01),
        id if id == file_driver_kind_id(FileDriverKind::Stdio) => Ok(0x01),
        id if id == file_driver_kind_id(FileDriverKind::Direct) => Ok(0x01),
        id if id == file_driver_kind_id(FileDriverKind::Core) => Ok(0x03),
        _ => Err(unsupported_vfd_driver("custom registered")),
    }
}

/// Public API: query registered driver flags into a caller-owned output parameter.
#[allow(non_snake_case)]
pub fn H5FDdriver_query_into(
    registry: &VfdRegistry,
    driver_id: u64,
    flags: &mut u64,
) -> Result<()> {
    *flags = H5FDdriver_query(registry, driver_id)?;
    Ok(())
}

/// Setting feature flags is a no-op in the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_set_feature_flags(_driver: &mut LocalFileDriver, _flags: u64) {}

/// Public API: read bytes from the file.
#[allow(non_snake_case)]
#[deprecated(note = "use driver-specific read methods")]
pub fn H5FDread(driver: &mut LocalFileDriver, addr: u64, buf: &mut [u8]) -> Result<()> {
    driver.driver_read(addr, buf)
}

/// Public API: write bytes to the file.
#[allow(non_snake_case)]
#[deprecated(note = "use driver-specific write methods")]
pub fn H5FDwrite(driver: &mut LocalFileDriver, addr: u64, data: &[u8]) -> Result<()> {
    driver.driver_write(addr, data)
}

/// Read a list of (addr, buffer) requests sequentially.
#[allow(non_snake_case)]
pub fn H5FDread_vector(driver: &mut LocalFileDriver, requests: &mut [VfdIoRequest]) -> Result<()> {
    H5FD_read_vector_from_selection(driver, requests)
}

/// Write a list of (addr, bytes) requests sequentially.
#[allow(non_snake_case)]
pub fn H5FDwrite_vector(driver: &mut LocalFileDriver, requests: &[VfdIoRequest]) -> Result<()> {
    H5FD_write_vector_from_selection(driver, requests)
}

/// Read a list of selection-based requests sequentially.
#[allow(non_snake_case)]
pub fn H5FDread_selection(
    driver: &mut LocalFileDriver,
    requests: &mut [VfdIoRequest],
) -> Result<()> {
    H5FD_read_from_selection(driver, requests)
}

/// Write a list of selection-based requests sequentially.
#[allow(non_snake_case)]
pub fn H5FDwrite_selection(driver: &mut LocalFileDriver, requests: &[VfdIoRequest]) -> Result<()> {
    H5FD_write_selection(driver, requests)
}

/// Public API: flush buffered writes to disk.
#[allow(non_snake_case)]
pub fn H5FDflush(driver: &mut LocalFileDriver) -> Result<()> {
    driver.driver_flush()
}

/// Public API: truncate the file to the current end-of-allocation address.
#[allow(non_snake_case)]
pub fn H5FDtruncate(driver: &mut LocalFileDriver) -> Result<()> {
    driver.driver_truncate()
}

/// Public API: acquire a VFD lock.
#[allow(non_snake_case)]
pub fn H5FDlock(driver: &mut LocalFileDriver, _read_write: bool) -> Result<()> {
    driver.locked = true;
    Ok(())
}

/// Public API: release a VFD lock.
#[allow(non_snake_case)]
pub fn H5FDunlock(driver: &mut LocalFileDriver) -> Result<()> {
    driver.locked = false;
    Ok(())
}

/// Public API: dispatch a simple VFD control operation.
#[allow(non_snake_case)]
pub fn H5FDctl(driver: &mut LocalFileDriver, new_eoa: Option<u64>) -> Result<()> {
    if let Some(eoa) = new_eoa {
        driver.eoa = eoa;
    }
    Ok(())
}

/// Public API: delete a file using the requested VFD.
#[allow(non_snake_case)]
pub fn H5FDdelete(path: impl AsRef<Path>, kind: FileDriverKind) -> Result<()> {
    match kind {
        FileDriverKind::Sec2 | FileDriverKind::Stdio | FileDriverKind::Direct => {
            delete_existing(path)
        }
        FileDriverKind::Core => Err(Error::Unsupported(
            "core VFD delete is represented by in-memory driver state".into(),
        )),
    }
}

/// Return the file path of the underlying file, if any.
#[allow(non_snake_case)]
pub fn H5FD_get_fileno(driver: &LocalFileDriver) -> Option<&Path> {
    driver.path.as_deref()
}

/// Public API: return the underlying file handle, if any.
#[allow(non_snake_case)]
pub fn H5FDget_vfd_handle(driver: &LocalFileDriver) -> Option<&File> {
    driver.file.as_ref()
}

/// Public API: return the underlying file handle through caller-owned storage.
#[allow(non_snake_case)]
pub fn H5FDget_vfd_handle_into<'a>(
    driver: &'a LocalFileDriver,
    file_handle: &mut Option<&'a File>,
) -> Result<()> {
    let handle = H5FDget_vfd_handle(driver).ok_or_else(|| {
        Error::Unsupported("H5FDget_vfd_handle requires a native file-backed VFD handle".into())
    })?;
    *file_handle = Some(handle);
    Ok(())
}

/// Toggling paged aggregation is a no-op in the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_set_paged_aggr(_driver: &mut LocalFileDriver, _enabled: bool) {}

/// Locate the HDF5 superblock signature within an image buffer.
#[allow(non_snake_case)]
pub fn H5FD_locate_signature(image: &[u8]) -> Option<u64> {
    const SIG: &[u8; 8] = b"\x89HDF\r\n\x1a\n";
    let mut offset = 0usize;
    while offset.checked_add(SIG.len())? <= image.len() {
        if image.get(offset..offset.checked_add(SIG.len())?) == Some(SIG.as_slice()) {
            return u64::try_from(offset).ok();
        }
        offset = if offset == 0 {
            512
        } else {
            offset.checked_mul(2)?
        };
    }
    None
}

/// Translate selection requests into a flat vector form.
#[allow(non_snake_case)]
pub fn H5FD__read_selection_translate_view(requests: &[VfdIoRequest]) -> &[VfdIoRequest] {
    requests
}

/// Translate selection requests into a caller-owned vector.
#[allow(non_snake_case)]
pub fn H5FD__read_selection_translate_into(requests: &[VfdIoRequest], out: &mut Vec<VfdIoRequest>) {
    out.clear();
    out.extend_from_slice(requests);
}

/// Translate selection requests into a flat vector form.
#[allow(non_snake_case)]
#[deprecated(
    note = "use H5FD__read_selection_translate_view or H5FD__read_selection_translate_into"
)]
pub fn H5FD__read_selection_translate(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__read_selection_translate_into(requests, &mut out);
    out
}

/// Translate selection write requests into a flat vector form.
#[allow(non_snake_case)]
pub fn H5FD__write_selection_translate_view(requests: &[VfdIoRequest]) -> &[VfdIoRequest] {
    requests
}

/// Translate selection write requests into a caller-owned vector.
#[allow(non_snake_case)]
pub fn H5FD__write_selection_translate_into(
    requests: &[VfdIoRequest],
    out: &mut Vec<VfdIoRequest>,
) {
    out.clear();
    out.extend_from_slice(requests);
}

/// Translate selection write requests into a flat vector form.
#[allow(non_snake_case)]
#[deprecated(
    note = "use H5FD__write_selection_translate_view or H5FD__write_selection_translate_into"
)]
pub fn H5FD__write_selection_translate(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__write_selection_translate_into(requests, &mut out);
    out
}

/// Write a list of selection requests via the active driver.
#[allow(non_snake_case)]
pub fn H5FD_write_selection(driver: &mut LocalFileDriver, requests: &[VfdIoRequest]) -> Result<()> {
    for request in requests {
        driver.driver_write(request.addr, &request.bytes)?;
    }
    Ok(())
}

/// Write a selection request identified by id.
#[allow(non_snake_case)]
pub fn H5FD_write_selection_id(
    driver: &mut LocalFileDriver,
    _selection_id: u64,
    requests: &[VfdIoRequest],
) -> Result<()> {
    H5FD_write_selection(driver, requests)
}

/// Build a vector read request set from a selection.
#[allow(non_snake_case)]
pub fn H5FD_read_vector_from_selection(
    driver: &mut LocalFileDriver,
    requests: &mut [VfdIoRequest],
) -> Result<()> {
    for request in requests {
        driver.driver_read(request.addr, &mut request.bytes)?;
    }
    Ok(())
}

/// Build a vector write request set from a selection.
#[allow(non_snake_case)]
pub fn H5FD_write_vector_from_selection(
    driver: &mut LocalFileDriver,
    requests: &[VfdIoRequest],
) -> Result<()> {
    H5FD_write_selection(driver, requests)
}

/// Read directly from a selection request set.
#[allow(non_snake_case)]
pub fn H5FD_read_from_selection(
    driver: &mut LocalFileDriver,
    requests: &mut [VfdIoRequest],
) -> Result<()> {
    H5FD_read_vector_from_selection(driver, requests)
}

/// Write directly from a selection request set.
#[allow(non_snake_case)]
pub fn H5FD_write_from_selection(
    driver: &mut LocalFileDriver,
    requests: &[VfdIoRequest],
) -> Result<()> {
    H5FD_write_selection(driver, requests)
}

/// Public API wrapper for [`H5FD_read_vector_from_selection`].
#[allow(non_snake_case)]
pub fn H5FDread_vector_from_selection(
    driver: &mut LocalFileDriver,
    requests: &mut [VfdIoRequest],
) -> Result<()> {
    H5FD_read_vector_from_selection(driver, requests)
}

/// Public API wrapper for [`H5FD_write_vector_from_selection`].
#[allow(non_snake_case)]
pub fn H5FDwrite_vector_from_selection(
    driver: &mut LocalFileDriver,
    requests: &[VfdIoRequest],
) -> Result<()> {
    H5FD_write_vector_from_selection(driver, requests)
}

/// Public API wrapper for [`H5FD_read_from_selection`].
#[allow(non_snake_case)]
pub fn H5FDread_from_selection(
    driver: &mut LocalFileDriver,
    requests: &mut [VfdIoRequest],
) -> Result<()> {
    H5FD_read_from_selection(driver, requests)
}

/// Public API wrapper for [`H5FD_write_from_selection`].
#[allow(non_snake_case)]
pub fn H5FDwrite_from_selection(
    driver: &mut LocalFileDriver,
    requests: &[VfdIoRequest],
) -> Result<()> {
    H5FD_write_from_selection(driver, requests)
}

/// Comparator that sorts I/O requests by file address.
#[allow(non_snake_case)]
pub fn H5FD__srt_tmp_cmp(left: &VfdIoRequest, right: &VfdIoRequest) -> Ordering {
    left.addr
        .cmp(&right.addr)
        .then_with(|| left.bytes.len().cmp(&right.bytes.len()))
}

/// Internal helper that sorts a request slice by address.
#[allow(non_snake_case)]
pub fn H5FD__sort_io_req_real(requests: &mut [VfdIoRequest]) {
    requests.sort_by(H5FD__srt_tmp_cmp);
}

/// Sort a vector I/O request set by address.
#[allow(non_snake_case)]
pub fn H5FD_sort_vector_io_req(requests: &mut [VfdIoRequest]) {
    H5FD__sort_io_req_real(requests);
}

/// Sort a selection I/O request set by address.
#[allow(non_snake_case)]
pub fn H5FD_sort_selection_io_req(requests: &mut [VfdIoRequest]) {
    H5FD__sort_io_req_real(requests);
}

/// MPI: getting the rank is not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_mpi_get_rank() -> Result<u32> {
    Err(Error::Unsupported(
        "MPI VFD is intentionally unsupported; use rayon for local parallelism".into(),
    ))
}

/// MPI: getting the communicator is not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_mpi_get_comm() -> Result<()> {
    Err(Error::Unsupported(
        "MPI communicator is unavailable in pure-Rust non-MPI mode".into(),
    ))
}

/// MPI: getting the info object is not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_mpi_get_info() -> Result<()> {
    Err(Error::Unsupported(
        "MPI info is unavailable in pure-Rust non-MPI mode".into(),
    ))
}

/// Convert an `MPI_Offset` to an HDF5 address with sign checks.
#[allow(non_snake_case)]
pub fn H5FD_mpi_MPIOff_to_haddr(offset: i64) -> Option<u64> {
    u64::try_from(offset).ok()
}

/// Convert an HDF5 address to an `MPI_Offset`, rejecting overflow.
#[allow(non_snake_case)]
pub fn H5FD_mpi_haddr_to_MPIOff(addr: u64) -> Option<i64> {
    i64::try_from(addr).ok()
}

/// In the pure-Rust backend file sync is never required.
#[allow(non_snake_case)]
pub fn H5FD_mpi_get_file_sync_required() -> bool {
    false
}

/// MPI: waiting for the left neighbor is not supported.
#[allow(non_snake_case)]
pub fn H5FD_mpio_wait_for_left_neighbor() -> Result<()> {
    Err(Error::Unsupported(
        "MPI synchronization is intentionally unsupported".into(),
    ))
}

/// MPI: signalling the right neighbor is not supported.
#[allow(non_snake_case)]
pub fn H5FD_mpio_signal_right_neighbor() -> Result<()> {
    Err(Error::Unsupported(
        "MPI synchronization is intentionally unsupported".into(),
    ))
}

/// `H5FD__mpio_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_register() -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_unregister() {}

/// `H5FD__mpio_init`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_init() -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD_mpio_init`: public MPIO VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_mpio_init() -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_term`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_term() {}

/// `H5FD_mpio_term`: public MPIO VFD termination; no runtime state is allocated here.
#[allow(non_snake_case)]
pub fn H5FD_mpio_term() {}

/// MPI: setting atomicity is not supported.
#[allow(non_snake_case)]
pub fn H5FD_set_mpio_atomicity(_atomicity: bool) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO atomicity"))
}

/// MPI: getting atomicity is not supported.
#[allow(non_snake_case)]
pub fn H5FD_get_mpio_atomicity() -> Result<bool> {
    Err(unsupported_vfd_driver("MPIO atomicity"))
}

/// `H5FD__mpio_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_open(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_close() {}

/// `H5FD__mpio_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_query() -> u64 {
    0
}

/// `H5FD__mpio_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_get_handle`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_vector_build_types`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_vector_build_types_view(requests: &[VfdIoRequest]) -> &[VfdIoRequest] {
    requests
}

/// `H5FD__mpio_vector_build_types`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_vector_build_types_into(requests: &[VfdIoRequest], out: &mut Vec<VfdIoRequest>) {
    out.clear();
    out.extend_from_slice(requests);
}

/// `H5FD__mpio_vector_build_types`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__mpio_vector_build_types_view or H5FD__mpio_vector_build_types_into")]
pub fn H5FD__mpio_vector_build_types(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__mpio_vector_build_types_into(requests, &mut out);
    out
}

/// VFD: selection build types.
#[allow(non_snake_case)]
pub fn H5FD__selection_build_types_view(requests: &[VfdIoRequest]) -> &[VfdIoRequest] {
    requests
}

/// VFD: selection build types.
#[allow(non_snake_case)]
pub fn H5FD__selection_build_types_into(requests: &[VfdIoRequest], out: &mut Vec<VfdIoRequest>) {
    out.clear();
    out.extend_from_slice(requests);
}

/// VFD: selection build types.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__selection_build_types_view or H5FD__selection_build_types_into")]
pub fn H5FD__selection_build_types(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__selection_build_types_into(requests, &mut out);
    out
}

/// `H5FD__mpio_read_vector`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_read_vector(_requests: &mut [VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_write_vector`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_write_vector(_requests: &[VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_read_selection`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_read_selection(_requests: &mut [VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_write_selection`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_write_selection(_requests: &[VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_flush`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_flush() -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// `H5FD__mpio_ctl`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mpio_ctl(_opcode: u64) -> Result<()> {
    Err(unsupported_vfd_driver("MPIO"))
}

/// Build an [`Error::Unsupported`] for an unimplemented VFD driver.
fn unsupported_vfd_driver(driver: &str) -> Error {
    Error::Unsupported(format!(
        "{driver} VFD is not implemented in pure-Rust local-only mode"
    ))
}

/// Read a little-endian `u32` from `data` at `offset` with bounds checks.
fn read_le_u32_at(data: &[u8], offset: usize, context: &str) -> Result<u32> {
    let end = offset
        .checked_add(4)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} offset overflow")))?;
    let bytes: [u8; 4] = data
        .get(offset..end)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} is truncated")))?
        .try_into()
        .map_err(|_| Error::InvalidFormat(format!("{context} is truncated")))?;
    Ok(u32::from_le_bytes(bytes))
}

/// Read a little-endian `u32` length field as a `usize`.
fn read_le_u32_len_at(data: &[u8], offset: usize, context: &'static str) -> Result<usize> {
    usize::try_from(read_le_u32_at(data, offset, context)?)
        .map_err(|_| Error::InvalidFormat(format!("{context} does not fit in usize")))
}

/// Read a little-endian `u64` from `data` at `offset` with bounds checks.
fn read_le_u64_at(data: &[u8], offset: usize, context: &str) -> Result<u64> {
    let end = offset
        .checked_add(8)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} offset overflow")))?;
    let bytes: [u8; 8] = data
        .get(offset..end)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} is truncated")))?
        .try_into()
        .map_err(|_| Error::InvalidFormat(format!("{context} is truncated")))?;
    Ok(u64::from_le_bytes(bytes))
}

fn validate_config_string(value: &str) -> bool {
    !value.is_empty() && !value.as_bytes().contains(&0)
}

fn validate_optional_config_string(value: Option<&str>) -> bool {
    value.is_none_or(validate_config_string)
}

/// `H5FD__hdfs_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_register() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_unregister() {}

/// `H5FD__hdfs_init`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_init() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD_hdfs_init`: public HDFS VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_hdfs_init() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct HdfsConfig {
    pub namenode_name: String,
    pub namenode_port: u16,
    pub user_name: String,
    pub buffer_size: u32,
}

const HDFS_FAPL_VERSION: u32 = 1;
const HDFS_STRING_SPACE: usize = 128;
const HDFS_STRING_FIELD_SIZE: usize = HDFS_STRING_SPACE + 1;
const HDFS_CONFIG_IMAGE_SIZE: usize =
    4 + HDFS_STRING_FIELD_SIZE + 4 + HDFS_STRING_FIELD_SIZE + HDFS_STRING_FIELD_SIZE + 4;

/// `H5FD__hdfs_validate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_validate_config(config: &HdfsConfig) -> bool {
    validate_config_string(&config.namenode_name)
        && validate_config_string(&config.user_name)
        && hdfs_fixed_string_is_valid(&config.namenode_name)
        && hdfs_fixed_string_is_valid(&config.user_name)
}

/// `H5FD__hdfs_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_sb_size(_config: &HdfsConfig) -> usize {
    HDFS_CONFIG_IMAGE_SIZE
}

/// `H5FD__hdfs_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_sb_encode_into(config: &HdfsConfig, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD__hdfs_validate_config(config) {
        return Err(Error::InvalidFormat("invalid HDFS VFD config".into()));
    }
    out.reserve(H5FD__hdfs_sb_size(config));
    out.extend_from_slice(&HDFS_FAPL_VERSION.to_le_bytes());
    hdfs_encode_fixed_string(&config.namenode_name, out)?;
    out.extend_from_slice(&u32::from(config.namenode_port).to_le_bytes());
    hdfs_encode_fixed_string(&config.user_name, out)?;
    hdfs_encode_fixed_string("", out)?;
    out.extend_from_slice(&config.buffer_size.to_le_bytes());
    Ok(())
}

/// `H5FD__hdfs_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__hdfs_sb_encode_into")]
pub fn H5FD__hdfs_sb_encode(config: &HdfsConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__hdfs_sb_size(config));
    H5FD__hdfs_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__hdfs_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_sb_decode(bytes: &[u8]) -> Result<HdfsConfig> {
    if bytes.len() != HDFS_CONFIG_IMAGE_SIZE {
        return Err(Error::InvalidFormat(
            "HDFS VFD config image has invalid length".into(),
        ));
    }
    let version = read_le_u32_at(bytes, 0, "HDFS VFD config version")?;
    if version != HDFS_FAPL_VERSION {
        return Err(Error::InvalidFormat(
            "unknown HDFS VFD config version".into(),
        ));
    }

    let namenode_start = 4usize;
    let port_offset = namenode_start + HDFS_STRING_FIELD_SIZE;
    let user_start = port_offset + 4;
    let kerberos_start = user_start + HDFS_STRING_FIELD_SIZE;
    let buffer_offset = kerberos_start + HDFS_STRING_FIELD_SIZE;

    let port = read_le_u32_at(bytes, port_offset, "HDFS VFD namenode port")?;
    let namenode_port = u16::try_from(port)
        .map_err(|_| Error::InvalidFormat("HDFS VFD namenode port exceeds u16".into()))?;
    let config = HdfsConfig {
        namenode_name: hdfs_decode_fixed_string(bytes, namenode_start, "HDFS VFD namenode name")?,
        namenode_port,
        user_name: hdfs_decode_fixed_string(bytes, user_start, "HDFS VFD user name")?,
        buffer_size: read_le_u32_at(bytes, buffer_offset, "HDFS VFD stream buffer size")?,
    };
    let kerberos =
        hdfs_decode_fixed_string(bytes, kerberos_start, "HDFS VFD Kerberos ticket cache")?;
    if !kerberos.is_empty() {
        return Err(Error::InvalidFormat(
            "HDFS VFD Kerberos ticket cache is unsupported".into(),
        ));
    }
    if !H5FD__hdfs_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid HDFS VFD config".into()));
    }
    Ok(config)
}

fn hdfs_fixed_string_is_valid(value: &str) -> bool {
    value.len() <= HDFS_STRING_SPACE && !value.as_bytes().contains(&0)
}

fn hdfs_encode_fixed_string(value: &str, out: &mut Vec<u8>) -> Result<()> {
    if !hdfs_fixed_string_is_valid(value) {
        return Err(Error::InvalidFormat("invalid HDFS VFD string field".into()));
    }
    out.extend_from_slice(value.as_bytes());
    out.resize(out.len() + HDFS_STRING_FIELD_SIZE - value.len(), 0);
    Ok(())
}

fn hdfs_decode_fixed_string(bytes: &[u8], offset: usize, context: &str) -> Result<String> {
    let end = offset
        .checked_add(HDFS_STRING_FIELD_SIZE)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} offset overflow")))?;
    let field = bytes
        .get(offset..end)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} is truncated")))?;
    let nul_pos = field
        .iter()
        .position(|&byte| byte == 0)
        .ok_or_else(|| Error::InvalidFormat(format!("{context} is not NUL terminated")))?;
    if field[nul_pos..].iter().any(|&byte| byte != 0) {
        return Err(Error::InvalidFormat(format!(
            "{context} has nonzero bytes after NUL terminator"
        )));
    }
    std::str::from_utf8(&field[..nul_pos])
        .map(str::to_string)
        .map_err(|_| Error::InvalidFormat(format!("{context} is not UTF-8")))
}

/// `H5FD__hdfs_handle_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_handle_open(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_handle_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_handle_close() {}

/// `H5FD__hdfs_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_fapl_get(config: &HdfsConfig) -> HdfsConfig {
    config.clone()
}

/// `H5FD__hdfs_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_fapl_copy(config: &HdfsConfig) -> HdfsConfig {
    config.clone()
}

/// `H5FD__hdfs_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_fapl_free(_config: HdfsConfig) {}

/// `H5FD__hdfs_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_open(_path: &str, _config: &HdfsConfig) -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_close() {}

/// `H5FD__hdfs_cmp`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_cmp() -> Ordering {
    Ordering::Equal
}

/// `H5FD__hdfs_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_query() -> u64 {
    0
}

/// `H5FD__hdfs_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_get_handle`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_lock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_lock() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_unlock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_unlock() -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

/// `H5FD__hdfs_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__hdfs_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("HDFS"))
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct S3ParsedUrl {
    pub scheme: String,
    pub bucket: String,
    pub key: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct S3ParsedUrlRef<'a> {
    pub scheme: &'a str,
    pub bucket: &'a str,
    pub key: &'a str,
}

/// VFD: s3comms init.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_init() -> Result<()> {
    Err(unsupported_vfd_driver("S3/ROS3"))
}

/// VFD: s3comms term func.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_term_func() {}

/// VFD: s3comms term.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_term() {}

/// VFD: s3comms s3r req finish cb.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_req_finish_cb() -> Result<()> {
    Err(unsupported_vfd_driver("S3/ROS3"))
}

/// VFD: s3comms s3r req finish pred.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_req_finish_pred(done: bool) -> bool {
    done
}

/// VFD: s3comms cred provider get creds cb.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_cred_provider_get_creds_cb() -> Result<()> {
    Err(unsupported_vfd_driver("S3/ROS3 credentials"))
}

/// VFD: s3comms cred provider pred.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_cred_provider_pred(has_credentials: bool) -> bool {
    has_credentials
}

/// VFD: s3comms s3r open.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_open(_url: &str) -> Result<()> {
    Err(unsupported_vfd_driver("S3/ROS3"))
}

/// VFD: s3comms s3r close.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_close() {}

/// VFD: s3comms s3r get filesize.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_get_filesize(_url: &str) -> Result<u64> {
    Err(unsupported_vfd_driver("S3/ROS3"))
}

/// VFD: s3comms s3r getsize.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_getsize(_url: &str) -> Result<u64> {
    Err(unsupported_vfd_driver("S3/ROS3"))
}

/// VFD: s3comms s3r getsize headers cb.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_s3r_getsize_headers_cb(_headers: &[(&str, &str)]) -> Option<u64> {
    None
}

/// VFD: s3comms parse url.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_parse_url_ref(url: &str) -> Result<S3ParsedUrlRef<'_>> {
    let (scheme, rest) = url
        .split_once("://")
        .ok_or_else(|| Error::InvalidFormat("S3 URL missing scheme".into()))?;
    let (bucket, key) = rest
        .split_once('/')
        .ok_or_else(|| Error::InvalidFormat("S3 URL missing object key".into()))?;
    if scheme.is_empty() || bucket.is_empty() || key.is_empty() {
        return Err(Error::InvalidFormat("S3 URL has an empty component".into()));
    }
    Ok(S3ParsedUrlRef {
        scheme,
        bucket,
        key,
    })
}

/// VFD: s3comms parse url.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__s3comms_parse_url_ref to borrow URL components")]
pub fn H5FD__s3comms_parse_url(url: &str) -> Result<S3ParsedUrl> {
    let parsed = H5FD__s3comms_parse_url_ref(url)?;
    Ok(S3ParsedUrl {
        scheme: parsed.scheme.to_string(),
        bucket: parsed.bucket.to_string(),
        key: parsed.key.to_string(),
    })
}

/// VFD: s3comms free purl.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_free_purl(_url: S3ParsedUrl) {}

/// VFD: s3comms get aws region.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_get_aws_region_str(endpoint: &str) -> Option<&str> {
    endpoint
        .split('.')
        .find(|part| part.starts_with("us-") || part.starts_with("eu-") || part.starts_with("ap-"))
}

/// VFD: s3comms get aws region.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__s3comms_get_aws_region_str")]
pub fn H5FD__s3comms_get_aws_region(endpoint: &str) -> Option<String> {
    H5FD__s3comms_get_aws_region_str(endpoint).map(str::to_string)
}

/// VFD: s3comms get credentials provider.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_get_credentials_provider() -> Result<()> {
    Err(unsupported_vfd_driver("S3/ROS3 credentials"))
}

/// VFD: s3comms format user agent header.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_format_user_agent_header_to_writer(
    writer: &mut impl fmt::Write,
    product: &str,
    version: &str,
) -> fmt::Result {
    write!(writer, "{product}/{version}")
}

/// VFD: s3comms format user agent header.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_format_user_agent_header_into(product: &str, version: &str, out: &mut String) {
    H5FD__s3comms_format_user_agent_header_to_writer(out, product, version)
        .expect("writing to String should not fail");
}

/// VFD: s3comms format user agent header.
#[allow(non_snake_case)]
#[deprecated(
    note = "use H5FD__s3comms_format_user_agent_header_to_writer or H5FD__s3comms_format_user_agent_header_into"
)]
pub fn H5FD__s3comms_format_user_agent_header(product: &str, version: &str) -> String {
    let mut out = String::with_capacity(product.len() + 1 + version.len());
    H5FD__s3comms_format_user_agent_header_into(product, version, &mut out);
    out
}

/// VFD: s3comms httpcode to str.
#[allow(non_snake_case)]
pub fn H5FD__s3comms_httpcode_to_str(code: u16) -> &'static str {
    match code {
        200 => "OK",
        206 => "Partial Content",
        301 => "Moved Permanently",
        403 => "Forbidden",
        404 => "Not Found",
        416 => "Range Not Satisfiable",
        500 => "Internal Server Error",
        503 => "Service Unavailable",
        _ => "Unknown",
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MirrorXmit {
    Close,
    Lock,
    Open { path: String },
    Reply { status: i32 },
    SetEoa { eoa: u64 },
    Write { addr: u64, data: Vec<u8> },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MirrorXmitRef<'a> {
    Close,
    Lock,
    Open { path: &'a str },
    Reply { status: i32 },
    SetEoa { eoa: u64 },
    Write { addr: u64, data: &'a [u8] },
}

/// `H5FD__mirror_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_register() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD_mirror_init`: public mirror VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_mirror_init() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_unregister() {}

/// `H5FD__mirror_xmit_encode_uint8`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_xmit_encode_uint8_into(value: u8, out: &mut Vec<u8>) {
    out.push(value);
}

/// `H5FD__mirror_xmit_encode_uint8`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__mirror_xmit_encode_uint8_into")]
pub fn H5FD__mirror_xmit_encode_uint8(value: u8) -> Vec<u8> {
    let mut out = Vec::with_capacity(1);
    H5FD__mirror_xmit_encode_uint8_into(value, &mut out);
    out
}

/// `H5FD__mirror_xmit_decode_uint64`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_xmit_decode_uint64(bytes: &[u8]) -> Result<u64> {
    if bytes.len() != 8 {
        return Err(Error::InvalidFormat(
            "mirror transmit uint64 payload has invalid length".into(),
        ));
    }
    read_le_u64_at(bytes, 0, "mirror transmit uint64")
}

/// `mirror` VFD: xmit decode lock.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_decode_lock(bytes: &[u8]) -> Result<MirrorXmit> {
    if !bytes.is_empty() {
        return Err(Error::InvalidFormat(
            "mirror transmit lock payload has invalid length".into(),
        ));
    }
    Ok(MirrorXmit::Lock)
}

/// `mirror` VFD: xmit decode open.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_decode_open_ref(bytes: &[u8]) -> Result<MirrorXmitRef<'_>> {
    let path = std::str::from_utf8(bytes)
        .map_err(|_| Error::InvalidFormat("mirror transmit open path is not UTF-8".into()))?;
    Ok(MirrorXmitRef::Open { path })
}

/// `mirror` VFD: xmit decode open.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_mirror_xmit_decode_open_ref to borrow the path")]
pub fn H5FD_mirror_xmit_decode_open(bytes: &[u8]) -> Result<MirrorXmit> {
    match H5FD_mirror_xmit_decode_open_ref(bytes)? {
        MirrorXmitRef::Open { path } => Ok(MirrorXmit::Open {
            path: path.to_string(),
        }),
        _ => unreachable!("open decoder always returns an open message"),
    }
}

/// `mirror` VFD: xmit decode reply.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_decode_reply(bytes: &[u8]) -> Result<MirrorXmit> {
    if bytes.len() != 4 {
        return Err(Error::InvalidFormat(
            "mirror transmit reply payload has invalid length".into(),
        ));
    }
    let status = i32::from_le_bytes(
        bytes
            .try_into()
            .map_err(|_| Error::InvalidFormat("mirror transmit reply is truncated".into()))?,
    );
    Ok(MirrorXmit::Reply { status })
}

/// `mirror` VFD: xmit decode set eoa.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_decode_set_eoa(bytes: &[u8]) -> Result<MirrorXmit> {
    H5FD__mirror_xmit_decode_uint64(bytes).map(|eoa| MirrorXmit::SetEoa { eoa })
}

/// `mirror` VFD: xmit decode write.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_decode_write_ref(bytes: &[u8]) -> Result<MirrorXmitRef<'_>> {
    if bytes.len() < 8 {
        return Err(Error::InvalidFormat(
            "mirror transmit write payload is truncated".into(),
        ));
    }
    let addr = read_le_u64_at(bytes, 0, "mirror transmit write address")?;
    Ok(MirrorXmitRef::Write {
        addr,
        data: &bytes[8..],
    })
}

/// `mirror` VFD: xmit decode write.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_mirror_xmit_decode_write_ref to borrow the payload")]
pub fn H5FD_mirror_xmit_decode_write(bytes: &[u8]) -> Result<MirrorXmit> {
    match H5FD_mirror_xmit_decode_write_ref(bytes)? {
        MirrorXmitRef::Write { addr, data } => Ok(MirrorXmit::Write {
            addr,
            data: data.to_vec(),
        }),
        _ => unreachable!("write decoder always returns a write message"),
    }
}

/// `mirror` VFD: xmit encode open.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_encode_open_into(path: &str, out: &mut Vec<u8>) -> Result<()> {
    out.extend_from_slice(path.as_bytes());
    Ok(())
}

/// `mirror` VFD: xmit encode open.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_mirror_xmit_encode_open_into")]
pub fn H5FD_mirror_xmit_encode_open(path: &str) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(path.len());
    H5FD_mirror_xmit_encode_open_into(path, &mut out)?;
    Ok(out)
}

/// `mirror` VFD: xmit encode reply.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_encode_reply_into(status: i32, out: &mut Vec<u8>) -> Result<()> {
    out.extend_from_slice(&status.to_le_bytes());
    Ok(())
}

/// `mirror` VFD: xmit encode reply.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_mirror_xmit_encode_reply_into")]
pub fn H5FD_mirror_xmit_encode_reply(status: i32) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(4);
    H5FD_mirror_xmit_encode_reply_into(status, &mut out)?;
    Ok(out)
}

/// `mirror` VFD: xmit encode set eoa.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_encode_set_eoa_into(eoa: u64, out: &mut Vec<u8>) -> Result<()> {
    out.extend_from_slice(&eoa.to_le_bytes());
    Ok(())
}

/// `mirror` VFD: xmit encode set eoa.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_mirror_xmit_encode_set_eoa_into")]
pub fn H5FD_mirror_xmit_encode_set_eoa(eoa: u64) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(8);
    H5FD_mirror_xmit_encode_set_eoa_into(eoa, &mut out)?;
    Ok(out)
}

/// `mirror` VFD: xmit encode write.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_encode_write_into(addr: u64, data: &[u8], out: &mut Vec<u8>) -> Result<()> {
    let image_len = 8usize.checked_add(data.len()).ok_or_else(|| {
        Error::InvalidFormat("mirror transmit write image length overflow".into())
    })?;
    out.reserve(image_len);
    out.extend_from_slice(&addr.to_le_bytes());
    out.extend_from_slice(data);
    Ok(())
}

/// `mirror` VFD: xmit encode write.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_mirror_xmit_encode_write_into")]
pub fn H5FD_mirror_xmit_encode_write(addr: u64, data: &[u8]) -> Result<Vec<u8>> {
    let image_len = 8usize.checked_add(data.len()).ok_or_else(|| {
        Error::InvalidFormat("mirror transmit write image length overflow".into())
    })?;
    let mut out = Vec::with_capacity(image_len);
    H5FD_mirror_xmit_encode_write_into(addr, data, &mut out)?;
    Ok(out)
}

/// `mirror` VFD: xmit is close.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_is_close(message: &MirrorXmit) -> bool {
    matches!(message, MirrorXmit::Close)
}

/// `mirror` VFD: xmit is lock.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_is_lock(message: &MirrorXmit) -> bool {
    matches!(message, MirrorXmit::Lock)
}

/// `mirror` VFD: xmit is set eoa.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_is_set_eoa(message: &MirrorXmit) -> bool {
    matches!(message, MirrorXmit::SetEoa { .. })
}

/// `mirror` VFD: xmit is reply.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_is_reply(message: &MirrorXmit) -> bool {
    matches!(message, MirrorXmit::Reply { .. })
}

/// `mirror` VFD: xmit is write.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_is_write(message: &MirrorXmit) -> bool {
    matches!(message, MirrorXmit::Write { .. })
}

/// `mirror` VFD: xmit is xmit.
#[allow(non_snake_case)]
pub fn H5FD_mirror_xmit_is_xmit(_message: &MirrorXmit) -> bool {
    true
}

/// `H5FD__mirror_verify_reply`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_verify_reply(message: &MirrorXmit) -> bool {
    matches!(message, MirrorXmit::Reply { status: 0 })
}

/// `H5FD__mirror_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_fapl_get() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_fapl_copy() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_fapl_free() {}

/// `H5FD__mirror_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_open(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_close() {}

/// `H5FD__mirror_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_query() -> u64 {
    0
}

/// `H5FD__mirror_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_lock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_lock() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

/// `H5FD__mirror_unlock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__mirror_unlock() -> Result<()> {
    Err(unsupported_vfd_driver("mirror"))
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FamilyFileConfig {
    pub member_size: u64,
    pub printf_filename: String,
}

impl Default for FamilyFileConfig {
    fn default() -> Self {
        Self {
            member_size: 100 * 1024 * 1024,
            printf_filename: "%05d.h5".into(),
        }
    }
}

/// `H5FD__family_get_default_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_get_default_config() -> FamilyFileConfig {
    FamilyFileConfig::default()
}

/// `H5FD__family_get_default_printf_filename`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_get_default_printf_filename() -> &'static str {
    "%05d.h5"
}

/// `H5FD__family_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_register() -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD_family_init`: public family VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_family_init() -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_unregister() {}

/// `H5FD_family_term`: public family VFD termination; no runtime state is allocated here.
#[allow(non_snake_case)]
pub fn H5FD_family_term() {}

/// `H5FD__family_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_fapl_get(config: &FamilyFileConfig) -> FamilyFileConfig {
    config.clone()
}

/// `H5FD__family_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_fapl_copy(config: &FamilyFileConfig) -> FamilyFileConfig {
    config.clone()
}

/// `H5FD__family_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_fapl_free(_config: FamilyFileConfig) {}

/// `H5FD__family_validate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_validate_config(config: &FamilyFileConfig) -> bool {
    !config.printf_filename.is_empty()
}

/// `H5FD__family_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_sb_size(_config: &FamilyFileConfig) -> Result<usize> {
    Ok(8)
}

/// `H5FD__family_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_sb_encode_into(config: &FamilyFileConfig, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD__family_validate_config(config) {
        return Err(Error::InvalidFormat("invalid family VFD config".into()));
    }
    out.reserve(H5FD__family_sb_size(config)?);
    out.extend_from_slice(&config.member_size.to_le_bytes());
    Ok(())
}

/// `H5FD__family_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__family_sb_encode_into")]
pub fn H5FD__family_sb_encode(config: &FamilyFileConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__family_sb_size(config)?);
    H5FD__family_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__family_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_sb_decode(bytes: &[u8]) -> Result<FamilyFileConfig> {
    if bytes.len() != H5FD__family_sb_size(&FamilyFileConfig::default())? {
        return Err(Error::InvalidFormat(
            "family VFD config image has invalid length".into(),
        ));
    }
    let member_size = read_le_u64_at(bytes, 0, "family VFD member size")?;
    let config = FamilyFileConfig {
        member_size,
        printf_filename: FamilyFileConfig::default().printf_filename,
    };
    if !H5FD__family_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid family VFD config".into()));
    }
    Ok(config)
}

/// `H5FD__family_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_open(_pattern: &str, _config: &FamilyFileConfig) -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_close() {}

/// `H5FD__family_cmp`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_cmp(left: &FamilyFileConfig, right: &FamilyFileConfig) -> Ordering {
    left.member_size
        .cmp(&right.member_size)
        .then_with(|| left.printf_filename.cmp(&right.printf_filename))
}

/// `H5FD__family_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_query() -> u64 {
    0
}

/// `H5FD__family_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_flush`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_flush() -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_lock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_lock() -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_unlock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_unlock() -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

/// `H5FD__family_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__family_delete(_pattern: &str) -> Result<()> {
    Err(unsupported_vfd_driver("family"))
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct MultiFileConfig {
    pub memb_map: HashMap<VfdMemType, FileDriverKind>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct MultiFileState {
    pub memb_addr: HashMap<VfdMemType, u64>,
    pub memb_next: HashMap<VfdMemType, u64>,
}

/// `multi` VFD: populate the default driver-specific configuration.
#[allow(non_snake_case)]
pub fn H5FD_multi_populate_config() -> MultiFileConfig {
    let mut config = MultiFileConfig::default();
    config
        .memb_map
        .insert(VfdMemType::Default, FileDriverKind::Sec2);
    config
}

/// `H5FD_multi_init`: public multi VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_multi_init() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `H5FD_multi_term`: public multi VFD termination; no runtime state is allocated here.
#[allow(non_snake_case)]
pub fn H5FD_multi_term() {}

/// VFD: vfd mem type code.
fn vfd_mem_type_code(mem_type: VfdMemType) -> u8 {
    match mem_type {
        VfdMemType::Default => 0,
        VfdMemType::Super => 1,
        VfdMemType::BTree => 2,
        VfdMemType::RawData => 3,
        VfdMemType::GlobalHeap => 4,
        VfdMemType::LocalHeap => 5,
        VfdMemType::ObjectHeader => 6,
        VfdMemType::Draw => 7,
        VfdMemType::Garbage => 8,
    }
}

/// VFD: vfd mem type from code.
fn vfd_mem_type_from_code(code: u8) -> Option<VfdMemType> {
    Some(match code {
        0 => VfdMemType::Default,
        1 => VfdMemType::Super,
        2 => VfdMemType::BTree,
        3 => VfdMemType::RawData,
        4 => VfdMemType::GlobalHeap,
        5 => VfdMemType::LocalHeap,
        6 => VfdMemType::ObjectHeader,
        7 => VfdMemType::Draw,
        8 => VfdMemType::Garbage,
        _ => return None,
    })
}

const VFD_MEM_TYPES_IN_CODE_ORDER: [VfdMemType; 9] = [
    VfdMemType::Default,
    VfdMemType::Super,
    VfdMemType::BTree,
    VfdMemType::RawData,
    VfdMemType::GlobalHeap,
    VfdMemType::LocalHeap,
    VfdMemType::ObjectHeader,
    VfdMemType::Draw,
    VfdMemType::Garbage,
];

/// VFD: file driver kind code.
fn file_driver_kind_code(kind: FileDriverKind) -> u8 {
    match kind {
        FileDriverKind::Sec2 => 0,
        FileDriverKind::Stdio => 1,
        FileDriverKind::Core => 2,
        FileDriverKind::Direct => 3,
    }
}

/// VFD: file driver kind from code.
fn file_driver_kind_from_code(code: u8) -> Option<FileDriverKind> {
    Some(match code {
        0 => FileDriverKind::Sec2,
        1 => FileDriverKind::Stdio,
        2 => FileDriverKind::Core,
        3 => FileDriverKind::Direct,
        _ => return None,
    })
}

/// `multi` VFD: validate config.
#[allow(non_snake_case)]
pub fn H5FD_multi_validate_config(config: &MultiFileConfig) -> bool {
    !config.memb_map.is_empty()
}

/// `multi` VFD: return the superblock extension size for a driver.
#[allow(non_snake_case)]
pub fn H5FD_multi_sb_size(config: &MultiFileConfig) -> Result<usize> {
    config
        .memb_map
        .len()
        .checked_mul(2)
        .and_then(|payload| payload.checked_add(4))
        .ok_or_else(|| Error::InvalidFormat("multi VFD member map length overflow".into()))
}

/// `multi` VFD: sb encode.
#[allow(non_snake_case)]
pub fn H5FD_multi_sb_encode_into(config: &MultiFileConfig, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD_multi_validate_config(config) {
        return Err(Error::InvalidFormat("invalid multi VFD config".into()));
    }
    let count = u32::try_from(config.memb_map.len())
        .map_err(|_| Error::InvalidFormat("multi VFD member count exceeds u32".into()))?;
    out.reserve(H5FD_multi_sb_size(config)?);
    out.extend_from_slice(&count.to_le_bytes());
    for mem_type in VFD_MEM_TYPES_IN_CODE_ORDER {
        if let Some(driver) = config.memb_map.get(&mem_type) {
            out.push(vfd_mem_type_code(mem_type));
            out.push(file_driver_kind_code(*driver));
        }
    }
    Ok(())
}

/// `multi` VFD: sb encode.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD_multi_sb_encode_into")]
pub fn H5FD_multi_sb_encode(config: &MultiFileConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD_multi_sb_size(config)?);
    H5FD_multi_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `multi` VFD: sb decode.
#[allow(non_snake_case)]
pub fn H5FD_multi_sb_decode(bytes: &[u8]) -> Result<MultiFileConfig> {
    let count = read_le_u32_len_at(bytes, 0, "multi VFD member count")?;
    let payload_len = count
        .checked_mul(2)
        .and_then(|len| 4usize.checked_add(len))
        .ok_or_else(|| Error::InvalidFormat("multi VFD member map length overflow".into()))?;
    if bytes.len() != payload_len {
        return Err(Error::InvalidFormat(
            "multi VFD member map has invalid length".into(),
        ));
    }
    let mut memb_map = HashMap::new();
    for entry in bytes[4..].chunks_exact(2) {
        let mem_type = vfd_mem_type_from_code(entry[0])
            .ok_or_else(|| Error::InvalidFormat("invalid multi VFD memory type".into()))?;
        let driver = file_driver_kind_from_code(entry[1])
            .ok_or_else(|| Error::InvalidFormat("invalid multi VFD driver kind".into()))?;
        if memb_map.insert(mem_type, driver).is_some() {
            return Err(Error::InvalidFormat(
                "multi VFD member map contains duplicate memory type".into(),
            ));
        }
    }
    let config = MultiFileConfig { memb_map };
    if !H5FD_multi_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid multi VFD config".into()));
    }
    Ok(config)
}

/// `multi` VFD: get the driver-specific FAPL configuration.
#[allow(non_snake_case)]
pub fn H5FD_multi_fapl_get(config: &MultiFileConfig) -> MultiFileConfig {
    config.clone()
}

/// `multi` VFD: copy the driver-specific FAPL configuration.
#[allow(non_snake_case)]
pub fn H5FD_multi_fapl_copy(config: &MultiFileConfig) -> MultiFileConfig {
    config.clone()
}

/// `multi` VFD: free the driver-specific FAPL configuration.
#[allow(non_snake_case)]
pub fn H5FD_multi_fapl_free(_config: MultiFileConfig) {}

/// `multi` VFD: open.
#[allow(non_snake_case)]
pub fn H5FD_multi_open(_path: &str, _config: &MultiFileConfig) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: close.
#[allow(non_snake_case)]
pub fn H5FD_multi_close() {}

/// `multi` VFD: compare two driver instances.
#[allow(non_snake_case)]
pub fn H5FD_multi_cmp(left: &MultiFileConfig, right: &MultiFileConfig) -> Ordering {
    left.memb_map.len().cmp(&right.memb_map.len())
}

/// `multi` VFD: query feature flags.
#[allow(non_snake_case)]
pub fn H5FD_multi_query() -> u64 {
    0
}

/// `multi` VFD: get type map.
#[allow(non_snake_case)]
pub fn H5FD_multi_get_type_map(config: &MultiFileConfig) -> &HashMap<VfdMemType, FileDriverKind> {
    &config.memb_map
}

/// VFD: compute next.
pub fn compute_next(file: &mut MultiFileState) {
    file.memb_next.clear();
    for (mt1, addr1) in &file.memb_addr {
        let next = file
            .memb_addr
            .iter()
            .filter_map(|(_, addr2)| (*addr2 > *addr1).then_some(*addr2))
            .min()
            .unwrap_or(u64::MAX);
        file.memb_next.insert(*mt1, next);
    }
}

/// `multi` VFD: get the end-of-allocation address.
#[allow(non_snake_case)]
pub fn H5FD_multi_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: set the end-of-allocation address.
#[allow(non_snake_case)]
pub fn H5FD_multi_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: get the end-of-file address.
#[allow(non_snake_case)]
pub fn H5FD_multi_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: get the underlying file handle.
#[allow(non_snake_case)]
pub fn H5FD_multi_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: allocate space in the file.
#[allow(non_snake_case)]
pub fn H5FD_multi_alloc(_size: u64) -> Result<u64> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: free a previously allocated region.
#[allow(non_snake_case)]
pub fn H5FD_multi_free(_addr: u64, _size: u64) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: read bytes from the file.
#[allow(non_snake_case)]
pub fn H5FD_multi_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: write bytes to the file.
#[allow(non_snake_case)]
pub fn H5FD_multi_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: flush buffered writes to disk.
#[allow(non_snake_case)]
pub fn H5FD_multi_flush() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: truncate the file to the current EOA.
#[allow(non_snake_case)]
pub fn H5FD_multi_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: acquire an advisory file lock.
#[allow(non_snake_case)]
pub fn H5FD_multi_lock() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: release an advisory file lock.
#[allow(non_snake_case)]
pub fn H5FD_multi_unlock() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: delete the file.
#[allow(non_snake_case)]
pub fn H5FD_multi_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `multi` VFD: invoke a driver-specific control op.
#[allow(non_snake_case)]
pub fn H5FD_multi_ctl(_opcode: u64) -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SplitterFileConfig {
    pub write_only_path: Option<PathBuf>,
    pub ignore_wo_errors: bool,
}

/// `H5FD__splitter_populate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_populate_config(write_only_path: Option<PathBuf>) -> SplitterFileConfig {
    SplitterFileConfig {
        write_only_path,
        ignore_wo_errors: false,
    }
}

/// `H5FD__splitter_get_default_wo_path`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_get_default_wo_path() -> &'static str {
    "%s.splitter"
}

/// VFD: split populate config.
#[allow(non_snake_case)]
pub fn H5FD_split_populate_config(write_only_path: Option<PathBuf>) -> SplitterFileConfig {
    H5FD__splitter_populate_config(write_only_path)
}

/// `H5FD__splitter_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_register() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD_splitter_init`: public splitter VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_splitter_init() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_unregister() {}

/// `H5FD__splitter_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_fapl_get(config: &SplitterFileConfig) -> SplitterFileConfig {
    config.clone()
}

/// `H5FD__splitter_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_fapl_copy(config: &SplitterFileConfig) -> SplitterFileConfig {
    config.clone()
}

/// `H5FD__splitter_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_fapl_free(_config: SplitterFileConfig) {}

/// `H5FD__splitter_validate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_validate_config(config: &SplitterFileConfig) -> bool {
    config
        .write_only_path
        .as_ref()
        .is_none_or(|path| !path.as_os_str().is_empty())
}

/// `H5FD__splitter_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_open(_path: &str, _config: &SplitterFileConfig) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_close() {}

/// `H5FD__splitter_flush`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_flush() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_sb_size(config: &SplitterFileConfig) -> Result<usize> {
    5usize
        .checked_add(
            config
                .write_only_path
                .as_ref()
                .map(|path| path.as_os_str().as_encoded_bytes().len())
                .unwrap_or(0),
        )
        .ok_or_else(|| Error::InvalidFormat("splitter VFD config image length overflow".into()))
}

/// `H5FD__splitter_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_sb_encode_into(config: &SplitterFileConfig, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD__splitter_validate_config(config) {
        return Err(Error::InvalidFormat("invalid splitter VFD config".into()));
    }
    let path = config
        .write_only_path
        .as_ref()
        .map(|path| path.as_os_str().as_encoded_bytes())
        .unwrap_or(&[]);
    let path_len = u32::try_from(path.len())
        .map_err(|_| Error::InvalidFormat("splitter VFD path length exceeds u32".into()))?;
    out.reserve(H5FD__splitter_sb_size(config)?);
    out.push(u8::from(config.ignore_wo_errors));
    out.extend_from_slice(&path_len.to_le_bytes());
    out.extend_from_slice(path);
    Ok(())
}

/// `H5FD__splitter_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__splitter_sb_encode_into")]
pub fn H5FD__splitter_sb_encode(config: &SplitterFileConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__splitter_sb_size(config)?);
    H5FD__splitter_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__splitter_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_sb_decode(bytes: &[u8]) -> Result<SplitterFileConfig> {
    let ignore_wo_errors = *bytes
        .first()
        .ok_or_else(|| Error::InvalidFormat("splitter VFD flags are truncated".into()))?
        != 0;
    if bytes[0] > 1 {
        return Err(Error::InvalidFormat(
            "splitter VFD ignore-errors flag is invalid".into(),
        ));
    }
    let path_len = read_le_u32_len_at(bytes, 1, "splitter VFD path length")?;
    let path_end = 5usize
        .checked_add(path_len)
        .ok_or_else(|| Error::InvalidFormat("splitter VFD path length overflow".into()))?;
    let path_bytes = bytes
        .get(5..path_end)
        .ok_or_else(|| Error::InvalidFormat("splitter VFD path is truncated".into()))?;
    if bytes.len() != path_end {
        return Err(Error::InvalidFormat(
            "splitter VFD config has trailing bytes".into(),
        ));
    }
    let write_only_path = if path_bytes.is_empty() {
        None
    } else {
        Some(PathBuf::from(std::str::from_utf8(path_bytes).map_err(
            |_| Error::InvalidFormat("splitter VFD path is not UTF-8".into()),
        )?))
    };
    let config = SplitterFileConfig {
        write_only_path,
        ignore_wo_errors,
    };
    if !H5FD__splitter_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid splitter VFD config".into()));
    }
    Ok(config)
}

/// `H5FD__splitter_cmp`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_cmp(left: &SplitterFileConfig, right: &SplitterFileConfig) -> Ordering {
    left.write_only_path
        .cmp(&right.write_only_path)
        .then_with(|| left.ignore_wo_errors.cmp(&right.ignore_wo_errors))
}

/// `H5FD__splitter_get_handle`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_lock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_lock() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_unlock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_unlock() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_ctl`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_ctl(_opcode: u64) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_query() -> u64 {
    0
}

/// `H5FD__splitter_alloc`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_alloc(_size: u64) -> Result<u64> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_get_type_map`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_get_type_map() -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_free(_addr: u64, _size: u64) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("splitter"))
}

/// `H5FD__splitter_log_error`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_log_error_str(message: &str) -> &str {
    message
}

/// `H5FD__splitter_log_error`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__splitter_log_error_to_writer(
    writer: &mut impl fmt::Write,
    message: &str,
) -> fmt::Result {
    fmt::Write::write_str(writer, message)
}

/// `H5FD__splitter_log_error`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__splitter_log_error_str or H5FD__splitter_log_error_to_writer")]
pub fn H5FD__splitter_log_error(message: &str) -> String {
    H5FD__splitter_log_error_str(message).to_string()
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct LogFileConfig {
    pub log_path: Option<PathBuf>,
    pub flags: u64,
    pub buffer_size: usize,
}

/// `H5FD__log_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_register() -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD_log_init`: public log VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_log_init() -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_unregister() {}

/// `H5FD_log_term`: public log VFD termination; no runtime state is allocated here.
#[allow(non_snake_case)]
pub fn H5FD_log_term() {}

/// `H5FD__log_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_fapl_get(config: &LogFileConfig) -> LogFileConfig {
    config.clone()
}

/// `H5FD__log_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_fapl_copy(config: &LogFileConfig) -> LogFileConfig {
    config.clone()
}

/// `H5FD__log_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_fapl_free(_config: LogFileConfig) {}

/// `H5FD__log_validate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_validate_config(config: &LogFileConfig) -> bool {
    config
        .log_path
        .as_ref()
        .is_none_or(|path| !path.as_os_str().is_empty())
}

/// `H5FD__log_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_sb_size(config: &LogFileConfig) -> Result<usize> {
    20usize
        .checked_add(
            config
                .log_path
                .as_ref()
                .map(|path| path.as_os_str().as_encoded_bytes().len())
                .unwrap_or(0),
        )
        .ok_or_else(|| Error::InvalidFormat("log VFD config image length overflow".into()))
}

/// `H5FD__log_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_sb_encode_into(config: &LogFileConfig, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD__log_validate_config(config) {
        return Err(Error::InvalidFormat("invalid log VFD config".into()));
    }
    let path = config
        .log_path
        .as_ref()
        .map(|path| path.as_os_str().as_encoded_bytes())
        .unwrap_or(&[]);
    let buffer_size = u64::try_from(config.buffer_size)
        .map_err(|_| Error::InvalidFormat("log VFD buffer size exceeds u64".into()))?;
    let path_len = u32::try_from(path.len())
        .map_err(|_| Error::InvalidFormat("log VFD path length exceeds u32".into()))?;
    out.reserve(H5FD__log_sb_size(config)?);
    out.extend_from_slice(&config.flags.to_le_bytes());
    out.extend_from_slice(&buffer_size.to_le_bytes());
    out.extend_from_slice(&path_len.to_le_bytes());
    out.extend_from_slice(path);
    Ok(())
}

/// `H5FD__log_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__log_sb_encode_into")]
pub fn H5FD__log_sb_encode(config: &LogFileConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__log_sb_size(config)?);
    H5FD__log_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__log_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_sb_decode(bytes: &[u8]) -> Result<LogFileConfig> {
    let flags = read_le_u64_at(bytes, 0, "log VFD flags")?;
    let buffer_size = usize::try_from(read_le_u64_at(bytes, 8, "log VFD buffer size")?)
        .map_err(|_| Error::InvalidFormat("log VFD buffer size does not fit usize".into()))?;
    let path_len = read_le_u32_len_at(bytes, 16, "log VFD path length")?;
    let path_end = 20usize
        .checked_add(path_len)
        .ok_or_else(|| Error::InvalidFormat("log VFD path length overflow".into()))?;
    let path_bytes = bytes
        .get(20..path_end)
        .ok_or_else(|| Error::InvalidFormat("log VFD path is truncated".into()))?;
    if bytes.len() != path_end {
        return Err(Error::InvalidFormat(
            "log VFD config has trailing bytes".into(),
        ));
    }
    let log_path = if path_bytes.is_empty() {
        None
    } else {
        Some(PathBuf::from(std::str::from_utf8(path_bytes).map_err(
            |_| Error::InvalidFormat("log VFD path is not UTF-8".into()),
        )?))
    };
    let config = LogFileConfig {
        log_path,
        flags,
        buffer_size,
    };
    if !H5FD__log_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid log VFD config".into()));
    }
    Ok(config)
}

/// `H5FD__log_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_open(_path: &str, _config: &LogFileConfig) -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_close() {}

/// `H5FD__log_cmp`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_cmp(left: &LogFileConfig, right: &LogFileConfig) -> Ordering {
    left.log_path
        .cmp(&right.log_path)
        .then_with(|| left.flags.cmp(&right.flags))
        .then_with(|| left.buffer_size.cmp(&right.buffer_size))
}

/// `H5FD__log_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_query() -> u64 {
    0
}

/// `H5FD__log_alloc`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_alloc(_size: u64) -> Result<u64> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_free(_addr: u64, _size: u64) -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_get_handle`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_lock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_lock() -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_unlock`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_unlock() -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

/// `H5FD__log_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__log_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("log"))
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Ros3Config {
    pub endpoint: Option<String>,
    pub region: Option<String>,
    pub token: Option<String>,
}

/// `H5FD__ros3_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_register() -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_unregister() {}

/// `H5FD__ros3_init`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_init() -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD_ros3_init`: public ROS3 VFD init; unsupported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD_ros3_init() -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_term`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_term() {}

/// `H5FD__ros3_validate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_validate_config(config: &Ros3Config) -> bool {
    validate_optional_config_string(config.endpoint.as_deref())
        && validate_optional_config_string(config.region.as_deref())
        && validate_optional_config_string(config.token.as_deref())
}

/// `H5FD__ros3_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_fapl_get(config: &Ros3Config) -> Ros3Config {
    config.clone()
}

/// `H5FD__ros3_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_fapl_copy(config: &Ros3Config) -> Ros3Config {
    config.clone()
}

/// `H5FD__ros3_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_fapl_free(_config: Ros3Config) {}

/// `H5FD__ros3_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_sb_size(config: &Ros3Config) -> Result<usize> {
    12usize
        .checked_add(config.endpoint.as_ref().map(String::len).unwrap_or(0))
        .and_then(|len| len.checked_add(config.region.as_ref().map(String::len).unwrap_or(0)))
        .and_then(|len| len.checked_add(config.token.as_ref().map(String::len).unwrap_or(0)))
        .ok_or_else(|| Error::InvalidFormat("ROS3 VFD config image length overflow".into()))
}

/// `H5FD__ros3_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_sb_encode_into(config: &Ros3Config, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD__ros3_validate_config(config) {
        return Err(Error::InvalidFormat("invalid ROS3 VFD config".into()));
    }
    let endpoint = config.endpoint.as_deref().unwrap_or("").as_bytes();
    let region = config.region.as_deref().unwrap_or("").as_bytes();
    let token = config.token.as_deref().unwrap_or("").as_bytes();
    let endpoint_len = u32::try_from(endpoint.len())
        .map_err(|_| Error::InvalidFormat("ROS3 VFD endpoint length exceeds u32".into()))?;
    let region_len = u32::try_from(region.len())
        .map_err(|_| Error::InvalidFormat("ROS3 VFD region length exceeds u32".into()))?;
    let token_len = u32::try_from(token.len())
        .map_err(|_| Error::InvalidFormat("ROS3 VFD token length exceeds u32".into()))?;
    out.reserve(H5FD__ros3_sb_size(config)?);
    out.extend_from_slice(&endpoint_len.to_le_bytes());
    out.extend_from_slice(&region_len.to_le_bytes());
    out.extend_from_slice(&token_len.to_le_bytes());
    out.extend_from_slice(endpoint);
    out.extend_from_slice(region);
    out.extend_from_slice(token);
    Ok(())
}

/// `H5FD__ros3_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__ros3_sb_encode_into")]
pub fn H5FD__ros3_sb_encode(config: &Ros3Config) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__ros3_sb_size(config)?);
    H5FD__ros3_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__ros3_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_sb_decode(bytes: &[u8]) -> Result<Ros3Config> {
    let endpoint_len = read_le_u32_len_at(bytes, 0, "ROS3 VFD endpoint length")?;
    let region_len = read_le_u32_len_at(bytes, 4, "ROS3 VFD region length")?;
    let token_len = read_le_u32_len_at(bytes, 8, "ROS3 VFD token length")?;
    let endpoint_start = 12usize;
    let region_start = endpoint_start
        .checked_add(endpoint_len)
        .ok_or_else(|| Error::InvalidFormat("ROS3 VFD endpoint length overflow".into()))?;
    let token_start = region_start
        .checked_add(region_len)
        .ok_or_else(|| Error::InvalidFormat("ROS3 VFD region length overflow".into()))?;
    let end = token_start
        .checked_add(token_len)
        .ok_or_else(|| Error::InvalidFormat("ROS3 VFD token length overflow".into()))?;
    if bytes.len() != end {
        return Err(Error::InvalidFormat(
            "ROS3 VFD config has invalid length".into(),
        ));
    }
    let decode_string = |range: std::ops::Range<usize>, context: &str| -> Result<Option<String>> {
        let raw = bytes
            .get(range)
            .ok_or_else(|| Error::InvalidFormat(format!("{context} is truncated")))?;
        if raw.is_empty() {
            Ok(None)
        } else {
            Ok(Some(
                std::str::from_utf8(raw)
                    .map_err(|_| Error::InvalidFormat(format!("{context} is not UTF-8")))?
                    .to_string(),
            ))
        }
    };
    let config = Ros3Config {
        endpoint: decode_string(endpoint_start..region_start, "ROS3 VFD endpoint")?,
        region: decode_string(region_start..token_start, "ROS3 VFD region")?,
        token: decode_string(token_start..end, "ROS3 VFD token")?,
    };
    if !H5FD__ros3_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid ROS3 VFD config".into()));
    }
    Ok(config)
}

/// `H5FD__ros3_str_token_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_str_token_close(token: &mut Option<String>) {
    *token = None;
}

/// `H5FD__ros3_str_token_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_str_token_delete(token: &mut Option<String>) {
    *token = None;
}

/// `H5FD__ros3_str_endpoint_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_str_endpoint_close(endpoint: &mut Option<String>) {
    *endpoint = None;
}

/// `H5FD__ros3_str_endpoint_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_str_endpoint_delete(endpoint: &mut Option<String>) {
    *endpoint = None;
}

/// `H5FD__ros3_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_query() -> u64 {
    0
}

/// `H5FD__ros3_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_get_handle`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("ROS3"))
}

/// `H5FD__ros3_reset_stats`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_reset_stats() {}

/// `H5FD__ros3_print_stats`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ros3_print_stats_str() -> &'static str {
    "ros3 statistics unavailable: ROS3 VFD unsupported"
}

/// `H5FD__ros3_print_stats`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__ros3_print_stats_str to borrow the static status text")]
pub fn H5FD__ros3_print_stats() -> String {
    H5FD__ros3_print_stats_str().to_string()
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct OnionRevisionRecord {
    pub revision: u64,
    pub address: u64,
    pub size: u64,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct OnionRevisionIndex {
    pub records: Vec<OnionRevisionRecord>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct OnionHeader {
    pub version: u8,
    pub flags: u8,
    pub revision_count: u64,
}

/// `H5FD__onion_ingest_revision_record`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_ingest_revision_record(
    index: &mut OnionRevisionIndex,
    record: OnionRevisionRecord,
) {
    H5FD__onion_revision_index_insert(index, record);
}

/// `H5FD__onion_archival_index_is_valid`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_archival_index_is_valid(index: &OnionRevisionIndex) -> bool {
    index
        .records
        .windows(2)
        .all(|pair| pair[0].revision <= pair[1].revision)
}

/// `H5FD__onion_revision_index_destroy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_revision_index_destroy(index: &mut OnionRevisionIndex) {
    index.records.clear();
}

/// `H5FD__onion_revision_index_init`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_revision_index_init() -> OnionRevisionIndex {
    OnionRevisionIndex::default()
}

/// `H5FD__onion_revision_index_resize`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_revision_index_resize(index: &mut OnionRevisionIndex, capacity: usize) {
    if index.records.capacity() < capacity {
        index.records.reserve(capacity - index.records.capacity());
    }
}

/// `H5FD__onion_revision_index_insert`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_revision_index_insert(
    index: &mut OnionRevisionIndex,
    record: OnionRevisionRecord,
) {
    index.records.push(record);
    index
        .records
        .sort_by(H5FD__onion_archival_index_list_sort_cmp);
}

/// `H5FD__onion_revision_record_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_revision_record_decode(bytes: &[u8]) -> Result<OnionRevisionRecord> {
    if bytes.len() != 24 {
        return Err(Error::InvalidFormat(
            "onion revision record image has invalid length".into(),
        ));
    }
    let revision = read_le_u64_at(bytes, 0, "onion revision record revision")?;
    let address = read_le_u64_at(bytes, 8, "onion revision record address")?;
    let size = read_le_u64_at(bytes, 16, "onion revision record size")?;
    Ok(OnionRevisionRecord {
        revision,
        address,
        size,
    })
}

/// `H5FD__onion_revision_record_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_revision_record_encode_into(
    record: &OnionRevisionRecord,
    out: &mut Vec<u8>,
) -> Result<()> {
    out.reserve(24);
    out.extend_from_slice(&record.revision.to_le_bytes());
    out.extend_from_slice(&record.address.to_le_bytes());
    out.extend_from_slice(&record.size.to_le_bytes());
    Ok(())
}

/// `H5FD__onion_revision_record_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_revision_record_encode_into")]
pub fn H5FD__onion_revision_record_encode(record: &OnionRevisionRecord) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(24);
    H5FD__onion_revision_record_encode_into(record, &mut out)?;
    Ok(out)
}

/// `H5FD__onion_archival_index_list_sort_cmp`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_archival_index_list_sort_cmp(
    left: &OnionRevisionRecord,
    right: &OnionRevisionRecord,
) -> Ordering {
    left.revision
        .cmp(&right.revision)
        .then_with(|| left.address.cmp(&right.address))
        .then_with(|| left.size.cmp(&right.size))
}

/// `H5FD__onion_merge_revision_index_into_archival_index`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_merge_revision_index_into_archival_index(
    archival: &mut OnionRevisionIndex,
    mut revision: OnionRevisionIndex,
) {
    archival.records.append(&mut revision.records);
    archival
        .records
        .sort_by(H5FD__onion_archival_index_list_sort_cmp);
}

/// `H5FD__onion_ingest_header`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_ingest_header(bytes: &[u8]) -> Result<OnionHeader> {
    H5FD__onion_sb_decode(bytes)
}

/// `H5FD__onion_write_header`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_write_header_into(header: &OnionHeader, out: &mut Vec<u8>) -> Result<()> {
    H5FD__onion_header_encode_into(header, out)
}

/// `H5FD__onion_write_header`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_write_header_into")]
pub fn H5FD__onion_write_header(header: &OnionHeader) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__onion_sb_size(header));
    H5FD__onion_write_header_into(header, &mut out)?;
    Ok(out)
}

/// `H5FD__onion_header_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_header_encode_into(header: &OnionHeader, out: &mut Vec<u8>) -> Result<()> {
    H5FD__onion_sb_encode_into(header, out)
}

/// `H5FD__onion_header_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_header_encode_into")]
pub fn H5FD__onion_header_encode(header: &OnionHeader) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__onion_sb_size(header));
    H5FD__onion_header_encode_into(header, &mut out)?;
    Ok(out)
}

/// `H5FD__onion_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_register() -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_unregister() {}

/// `H5FD__onion_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_sb_size(_header: &OnionHeader) -> usize {
    10
}

/// `H5FD__onion_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_sb_encode_into(header: &OnionHeader, out: &mut Vec<u8>) -> Result<()> {
    out.reserve(H5FD__onion_sb_size(header));
    out.push(header.version);
    out.push(header.flags);
    out.extend_from_slice(&header.revision_count.to_le_bytes());
    Ok(())
}

/// `H5FD__onion_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_sb_encode_into")]
pub fn H5FD__onion_sb_encode(header: &OnionHeader) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__onion_sb_size(header));
    H5FD__onion_sb_encode_into(header, &mut out)?;
    Ok(out)
}

/// `H5FD__onion_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_sb_decode(bytes: &[u8]) -> Result<OnionHeader> {
    if bytes.len() != H5FD__onion_sb_size(&OnionHeader::default()) {
        return Err(Error::InvalidFormat(
            "onion VFD header image has invalid length".into(),
        ));
    }
    Ok(OnionHeader {
        version: *bytes
            .first()
            .ok_or_else(|| Error::InvalidFormat("onion VFD version is truncated".into()))?,
        flags: *bytes
            .get(1)
            .ok_or_else(|| Error::InvalidFormat("onion VFD flags are truncated".into()))?,
        revision_count: read_le_u64_at(bytes, 2, "onion VFD revision count")?,
    })
}

/// `H5FD__onion_commit_new_revision_record`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_commit_new_revision_record(
    index: &mut OnionRevisionIndex,
    address: u64,
    size: u64,
) -> OnionRevisionRecord {
    let revision = index.records.last().map_or(0, |record| record.revision + 1);
    let record = OnionRevisionRecord {
        revision,
        address,
        size,
    };
    H5FD__onion_revision_index_insert(index, record.clone());
    record
}

/// `H5FD__onion_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_close() {}

/// `H5FD__onion_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_get_legit_fapl_id`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_get_legit_fapl_id() -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_create_truncate_onion`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_create_truncate_onion(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_remove_unused_symbols`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_remove_unused_symbols(symbols: &mut Vec<String>) {
    symbols.retain(|symbol| !symbol.is_empty());
}

/// `H5FD__onion_parse_config_str`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_parse_config_str(config: &str) -> HashMap<String, String> {
    config
        .split(',')
        .filter_map(|entry| entry.split_once('='))
        .map(|(key, value)| (key.trim().to_string(), value.trim().to_string()))
        .collect()
}

/// `H5FD__onion_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_open(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_open_rw`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_open_rw(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// `H5FD__onion_ctl`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_ctl(_opcode: u64) -> Result<()> {
    Err(unsupported_vfd_driver("onion"))
}

/// VFD: H5FDonion get revision count.
#[allow(non_snake_case)]
pub fn H5FDonion_get_revision_count(header: &OnionHeader) -> u64 {
    header.revision_count
}

/// VFD: get onion revision count.
#[allow(non_snake_case)]
pub fn H5FD__get_onion_revision_count(header: &OnionHeader) -> u64 {
    H5FDonion_get_revision_count(header)
}

/// `H5FD__onion_write_final_history`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_write_final_history_into(
    index: &OnionRevisionIndex,
    out: &mut Vec<u8>,
) -> Result<()> {
    H5FD__onion_history_encode_into(index, out)
}

/// `H5FD__onion_write_final_history`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_write_final_history_into")]
pub fn H5FD__onion_write_final_history(index: &OnionRevisionIndex) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__onion_history_size(index)?);
    H5FD__onion_write_final_history_into(index, &mut out)?;
    Ok(out)
}

/// `H5FD__onion_ingest_history`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_ingest_history(bytes: &[u8]) -> Result<OnionRevisionIndex> {
    if bytes.len() % 24 != 0 {
        return Err(Error::InvalidFormat(
            "onion revision history has a partial trailing record".into(),
        ));
    }
    let mut index = OnionRevisionIndex::default();
    for chunk in bytes.chunks_exact(24) {
        let record = H5FD__onion_revision_record_decode(chunk)?;
        H5FD__onion_revision_index_insert(&mut index, record);
    }
    Ok(index)
}

/// `H5FD__onion_write_history`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_write_history_into(index: &OnionRevisionIndex, out: &mut Vec<u8>) -> Result<()> {
    H5FD__onion_history_encode_into(index, out)
}

/// `H5FD__onion_write_history`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_write_history_into")]
pub fn H5FD__onion_write_history(index: &OnionRevisionIndex) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__onion_history_size(index)?);
    H5FD__onion_write_history_into(index, &mut out)?;
    Ok(out)
}

/// `H5FD__onion_history_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_history_size(index: &OnionRevisionIndex) -> Result<usize> {
    index
        .records
        .len()
        .checked_mul(24)
        .ok_or_else(|| Error::InvalidFormat("onion revision history length overflow".into()))
}

/// `H5FD__onion_history_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__onion_history_encode_into(
    index: &OnionRevisionIndex,
    out: &mut Vec<u8>,
) -> Result<()> {
    out.reserve(H5FD__onion_history_size(index)?);
    for record in &index.records {
        H5FD__onion_revision_record_encode_into(record, out)?;
    }
    Ok(())
}

/// `H5FD__onion_history_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__onion_history_encode_into")]
pub fn H5FD__onion_history_encode(index: &OnionRevisionIndex) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__onion_history_size(index)?);
    H5FD__onion_history_encode_into(index, &mut out)?;
    Ok(out)
}

/// VFD: supports swmr test.
#[allow(non_snake_case)]
pub fn H5FD__supports_swmr_test(driver: FileDriverKind) -> bool {
    matches!(driver, FileDriverKind::Sec2 | FileDriverKind::Stdio)
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubfilingConfig {
    pub ioc_count: u32,
    pub stripe_size: u64,
    pub stripe_count: u32,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct IocConfig {
    pub thread_pool_size: usize,
    pub queue_depth: usize,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubfilingObject {
    pub id: u64,
    pub path: PathBuf,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct IocQueueEntry {
    pub request: VfdIoRequest,
    pub complete: bool,
}

/// `H5FD__multi_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__multi_register() -> Result<()> {
    Err(unsupported_vfd_driver("multi"))
}

/// `H5FD__multi_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__multi_unregister() {}

/// `H5FD__ioc_calculate_target_ioc`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_calculate_target_ioc(addr: u64, config: &SubfilingConfig) -> u32 {
    let count = config.ioc_count.max(1);
    let stripe = config.stripe_size.max(1);
    u32::try_from((addr / stripe) % u64::from(count)).unwrap_or(0)
}

/// `H5FD__ioc_write_independent_async`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_write_independent_async(_request: &VfdIoRequest) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC async"))
}

/// `H5FD__ioc_read_independent_async`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_read_independent_async(_request: &mut VfdIoRequest) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC async"))
}

/// `H5FD__ioc_async_completion`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_async_completion(entry: &mut IocQueueEntry) {
    entry.complete = true;
}

/// `H5FD__subfiling_new_object_id`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_new_object_id(previous: u64) -> u64 {
    H5FD__subfiling_new_object_id_checked(previous).unwrap_or(u64::MAX)
}

/// `H5FD__subfiling_new_object_id_checked`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_new_object_id_checked(previous: u64) -> Result<u64> {
    previous
        .checked_add(1)
        .ok_or_else(|| Error::InvalidFormat("subfiling object id overflow".into()))
}

/// `H5FD__subfiling_get_object`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_object(
    objects: &[SubfilingObject],
    id: u64,
) -> Option<&SubfilingObject> {
    objects.iter().find(|object| object.id == id)
}

/// `H5FD__subfiling_free_object`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_free_object(_object: SubfilingObject) {}

/// `H5FD__subfiling_free_context`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_free_context(_config: SubfilingConfig) {}

/// `H5FD__subfiling_free_topology`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_free_topology(_objects: Vec<SubfilingObject>) {}

/// `H5FD__subfiling_open_stub_file`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_open_stub_file(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_open_subfiles`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_open_subfiles(_path: &str, _config: &SubfilingConfig) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_setup_context`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_setup_context(config: &SubfilingConfig) -> SubfilingConfig {
    config.clone()
}

/// `H5FD__subfiling_init_app_topology`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_init_app_topology_into(config: &SubfilingConfig, out: &mut Vec<u32>) {
    out.clear();
    out.extend(0..config.ioc_count);
}

/// `H5FD__subfiling_init_app_topology`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_init_app_topology_into")]
pub fn H5FD__subfiling_init_app_topology(config: &SubfilingConfig) -> Vec<u32> {
    let mut out = Vec::with_capacity(config.ioc_count as usize);
    H5FD__subfiling_init_app_topology_into(config, &mut out);
    out
}

/// `H5FD__subfiling_get_ioc_selection_criteria_from_env`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_ioc_selection_criteria_from_env() -> Option<String> {
    std::env::var("HDF5_SUBFILING_IOC_SELECTION").ok()
}

/// `H5FD__subfiling_find_cached_topology_info`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_find_cached_topology_info_view() -> Option<&'static [u32]> {
    None
}

/// `H5FD__subfiling_find_cached_topology_info`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_find_cached_topology_info_view")]
pub fn H5FD__subfiling_find_cached_topology_info() -> Option<Vec<u32>> {
    H5FD__subfiling_find_cached_topology_info_view().map(<[u32]>::to_vec)
}

/// `H5FD__subfiling_init_app_layout`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_init_app_layout(config: &SubfilingConfig) -> SubfilingConfig {
    config.clone()
}

/// `H5FD__subfiling_gather_topology_info`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_gather_topology_info_into(config: &SubfilingConfig, out: &mut Vec<u32>) {
    H5FD__subfiling_init_app_topology_into(config, out);
}

/// `H5FD__subfiling_gather_topology_info`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_gather_topology_info_into")]
pub fn H5FD__subfiling_gather_topology_info(config: &SubfilingConfig) -> Vec<u32> {
    let mut out = Vec::with_capacity(config.ioc_count as usize);
    H5FD__subfiling_gather_topology_info_into(config, &mut out);
    out
}

/// `H5FD__subfiling_compare_layout_nodelocal`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_compare_layout_nodelocal(
    left: &SubfilingConfig,
    right: &SubfilingConfig,
) -> Ordering {
    left.ioc_count
        .cmp(&right.ioc_count)
        .then_with(|| left.stripe_size.cmp(&right.stripe_size))
        .then_with(|| left.stripe_count.cmp(&right.stripe_count))
}

/// `H5FD__subfiling_identify_ioc_ranks`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_identify_ioc_ranks_into(config: &SubfilingConfig, out: &mut Vec<u32>) {
    H5FD__subfiling_init_app_topology_into(config, out);
}

/// `H5FD__subfiling_identify_ioc_ranks`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_identify_ioc_ranks_into")]
pub fn H5FD__subfiling_identify_ioc_ranks(config: &SubfilingConfig) -> Vec<u32> {
    let mut out = Vec::with_capacity(config.ioc_count as usize);
    H5FD__subfiling_identify_ioc_ranks_into(config, &mut out);
    out
}

/// `H5FD__subfiling_init_context`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_init_context() -> SubfilingConfig {
    H5FD__subfiling_get_default_config()
}

/// `H5FD__subfiling_record_fid_map_entry`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_record_fid_map_entry(_fid: u64, _object: &SubfilingObject) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_get_default_ioc_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_default_ioc_config() -> IocConfig {
    IocConfig {
        thread_pool_size: 1,
        queue_depth: 64,
    }
}

/// `H5FD__subfiling_ioc_open_files`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_ioc_open_files(_config: &SubfilingConfig) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__subfiling_create_config_file`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_create_config_file(_path: &str, _config: &SubfilingConfig) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling config file"))
}

/// `H5FD__subfiling_open_config_file`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_open_config_file(_path: &str) -> Result<SubfilingConfig> {
    Err(unsupported_vfd_driver("subfiling config file"))
}

/// `H5FD__subfiling_get_config_from_file`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_config_from_file(_path: &str) -> Result<SubfilingConfig> {
    Err(unsupported_vfd_driver("subfiling config file"))
}

/// `H5FD__subfiling_resolve_pathname`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_resolve_pathname(path: &str) -> PathBuf {
    PathBuf::from(path)
}

/// `H5FD__subfiling_close_subfiles`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_close_subfiles() {}

/// `H5FD__subfiling_set_config_prop`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_set_config_prop(config: &mut SubfilingConfig, stripe_size: u64) {
    config.stripe_size = stripe_size;
}

/// `H5FD__subfiling_log`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_log_to_writer(writer: &mut impl fmt::Write, message: &str) -> fmt::Result {
    writeln!(writer, "{message}")
}

/// `H5FD__subfiling_log`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_log_to_writer")]
pub fn H5FD__subfiling_log(message: &str) -> String {
    let mut out = String::new();
    H5FD__subfiling_log_to_writer(&mut out, message).expect("writing to String should not fail");
    out
}

/// `H5FD__subfiling_log_nonewline`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_log_nonewline_str(message: &str) -> &str {
    message
}

/// `H5FD__subfiling_log_nonewline`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_log_nonewline_to_writer(
    writer: &mut impl fmt::Write,
    message: &str,
) -> fmt::Result {
    fmt::Write::write_str(writer, message)
}

/// `H5FD__subfiling_log_nonewline`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(
    note = "use H5FD__subfiling_log_nonewline_str or H5FD__subfiling_log_nonewline_to_writer"
)]
pub fn H5FD__subfiling_log_nonewline(message: &str) -> String {
    H5FD__subfiling_log_nonewline_str(message).to_string()
}

/// `H5FD__ioc_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_register() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_unregister() {}

/// `H5FD__ioc_init`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_init() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_term`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_term() {}

/// `H5FD__ioc_validate_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_validate_config(config: &IocConfig) -> bool {
    config.thread_pool_size > 0 && config.queue_depth > 0
}

/// `H5FD__ioc_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_sb_size(_config: &IocConfig) -> usize {
    16
}

/// `H5FD__ioc_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_sb_encode_into(config: &IocConfig, out: &mut Vec<u8>) -> Result<()> {
    if !H5FD__ioc_validate_config(config) {
        return Err(Error::InvalidFormat("invalid subfiling IOC config".into()));
    }
    let thread_pool_size = u64::try_from(config.thread_pool_size)
        .map_err(|_| Error::InvalidFormat("subfiling IOC thread pool size exceeds u64".into()))?;
    let queue_depth = u64::try_from(config.queue_depth)
        .map_err(|_| Error::InvalidFormat("subfiling IOC queue depth exceeds u64".into()))?;
    out.reserve(H5FD__ioc_sb_size(config));
    out.extend_from_slice(&thread_pool_size.to_le_bytes());
    out.extend_from_slice(&queue_depth.to_le_bytes());
    Ok(())
}

/// `H5FD__ioc_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__ioc_sb_encode_into")]
pub fn H5FD__ioc_sb_encode(config: &IocConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__ioc_sb_size(config));
    H5FD__ioc_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__ioc_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_sb_decode(bytes: &[u8]) -> Result<IocConfig> {
    if bytes.len() != H5FD__ioc_sb_size(&IocConfig::default()) {
        return Err(Error::InvalidFormat(
            "subfiling IOC config image has invalid length".into(),
        ));
    }
    let thread_pool_size =
        usize::try_from(read_le_u64_at(bytes, 0, "subfiling IOC thread pool size")?).map_err(
            |_| Error::InvalidFormat("subfiling IOC thread pool size does not fit usize".into()),
        )?;
    let queue_depth = usize::try_from(read_le_u64_at(bytes, 8, "subfiling IOC queue depth")?)
        .map_err(|_| Error::InvalidFormat("subfiling IOC queue depth does not fit usize".into()))?;
    let config = IocConfig {
        thread_pool_size,
        queue_depth,
    };
    if !H5FD__ioc_validate_config(&config) {
        return Err(Error::InvalidFormat("invalid subfiling IOC config".into()));
    }
    Ok(config)
}

/// `H5FD__ioc_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_fapl_get(config: &IocConfig) -> IocConfig {
    config.clone()
}

/// `H5FD__ioc_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_fapl_copy(config: &IocConfig) -> IocConfig {
    config.clone()
}

/// `H5FD__ioc_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_fapl_free(_config: IocConfig) {}

/// `H5FD__ioc_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_open(_path: &str, _config: &IocConfig) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_close_int`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_close_int() {}

/// `H5FD__ioc_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_close() {}

/// `H5FD__ioc_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_query() -> u64 {
    0
}

/// `H5FD__ioc_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_read`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_read(_addr: u64, _buf: &mut [u8]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_write`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_write(_addr: u64, _data: &[u8]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_write_vector`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_write_vector(_requests: &[VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_write_vector_internal`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_write_vector_internal(_requests: &[VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_read_vector_internal`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_read_vector_internal(_requests: &mut [VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__subfiling__truncate_sub_files`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling__truncate_sub_files(_config: &SubfilingConfig) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling__get_real_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling__get_real_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__ioc_init_threads`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_init_threads() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC threads"))
}

/// `H5FD__ioc_finalize_threads`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_finalize_threads() {}

/// `H5FD__ioc_thread_main`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_thread_main() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC threads"))
}

/// VFD: translate opcode.
pub fn translate_opcode(op: u64) -> &'static str {
    match op {
        0 => "READ_OP",
        1 => "WRITE_OP",
        2 => "OPEN_OP",
        3 => "CLOSE_OP",
        4 => "TRUNC_OP",
        5 => "GET_EOF_OP",
        6 => "FINI_OP",
        7 => "LOGGING_OP",
        _ => "unknown",
    }
}

/// `H5FD__ioc_handle_work_request`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_handle_work_request(_entry: &mut IocQueueEntry) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_send_ack_to_client`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_send_ack_to_client(entry: &mut IocQueueEntry) {
    entry.complete = true;
}

/// `H5FD__ioc_send_nack_to_client`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_send_nack_to_client(entry: &mut IocQueueEntry) {
    entry.complete = false;
}

/// `H5FD__ioc_file_queue_write_indep`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_file_queue_write_indep(request: VfdIoRequest) -> IocQueueEntry {
    IocQueueEntry {
        request,
        complete: false,
    }
}

/// `H5FD__ioc_file_queue_read_indep`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_file_queue_read_indep(request: VfdIoRequest) -> IocQueueEntry {
    IocQueueEntry {
        request,
        complete: false,
    }
}

/// `H5FD__ioc_file_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_file_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_file_report_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_file_report_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("subfiling IOC"))
}

/// `H5FD__ioc_io_queue_alloc_entry`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_io_queue_alloc_entry(request: VfdIoRequest) -> IocQueueEntry {
    IocQueueEntry {
        request,
        complete: false,
    }
}

/// `H5FD__ioc_io_queue_add_entry`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_io_queue_add_entry(queue: &mut Vec<IocQueueEntry>, entry: IocQueueEntry) {
    queue.push(entry);
}

/// `H5FD__ioc_io_queue_dispatch_eligible_entries`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_io_queue_dispatch_eligible_entries(queue: &mut [IocQueueEntry]) {
    for entry in queue {
        entry.complete = true;
    }
}

/// `H5FD__ioc_io_queue_complete_entry`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__ioc_io_queue_complete_entry(entry: &mut IocQueueEntry) {
    entry.complete = true;
}

/// `H5FD__subfiling_register`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_register() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_unregister`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_unregister() {}

/// `H5FD__subfiling_init`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_init() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_term`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_term() {}

/// VFD: H5FDsubfiling get file mapping.
#[allow(non_snake_case)]
pub fn H5FDsubfiling_get_file_mapping_into(config: &SubfilingConfig, out: &mut Vec<u32>) {
    H5FD__subfiling_identify_ioc_ranks_into(config, out);
}

/// VFD: H5FDsubfiling get file mapping.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FDsubfiling_get_file_mapping_into")]
pub fn H5FDsubfiling_get_file_mapping(config: &SubfilingConfig) -> Vec<u32> {
    let mut out = Vec::with_capacity(config.ioc_count as usize);
    H5FDsubfiling_get_file_mapping_into(config, &mut out);
    out
}

/// `H5FD__subfiling_get_default_config`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_default_config() -> SubfilingConfig {
    SubfilingConfig {
        ioc_count: 1,
        stripe_size: 64 * 1024 * 1024,
        stripe_count: 1,
    }
}

/// `H5FD__subfiling_sb_size`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_sb_size(_config: &SubfilingConfig) -> usize {
    16
}

/// `H5FD__subfiling_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_sb_encode_into(config: &SubfilingConfig, out: &mut Vec<u8>) -> Result<()> {
    if config.stripe_size == 0 || config.ioc_count == 0 || config.stripe_count == 0 {
        return Err(Error::InvalidFormat("invalid subfiling VFD config".into()));
    }
    out.reserve(H5FD__subfiling_sb_size(config));
    out.extend_from_slice(&config.stripe_size.to_le_bytes());
    out.extend_from_slice(&config.ioc_count.to_le_bytes());
    out.extend_from_slice(&config.stripe_count.to_le_bytes());
    Ok(())
}

/// `H5FD__subfiling_sb_encode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_sb_encode_into")]
pub fn H5FD__subfiling_sb_encode(config: &SubfilingConfig) -> Result<Vec<u8>> {
    let mut out = Vec::with_capacity(H5FD__subfiling_sb_size(config));
    H5FD__subfiling_sb_encode_into(config, &mut out)?;
    Ok(out)
}

/// `H5FD__subfiling_sb_decode`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_sb_decode(bytes: &[u8]) -> Result<SubfilingConfig> {
    if bytes.len() != H5FD__subfiling_sb_size(&SubfilingConfig::default()) {
        return Err(Error::InvalidFormat(
            "subfiling VFD config image has invalid length".into(),
        ));
    }
    let config = SubfilingConfig {
        stripe_size: read_le_u64_at(bytes, 0, "subfiling VFD stripe size")?,
        ioc_count: read_le_u32_at(bytes, 8, "subfiling VFD IOC count")?,
        stripe_count: read_le_u32_at(bytes, 12, "subfiling VFD stripe count")?,
    };
    if config.stripe_size == 0 || config.ioc_count == 0 || config.stripe_count == 0 {
        return Err(Error::InvalidFormat("invalid subfiling VFD config".into()));
    }
    Ok(config)
}

/// `H5FD__subfiling_fapl_get`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_fapl_get(config: &SubfilingConfig) -> SubfilingConfig {
    config.clone()
}

/// VFD: copy plist.
#[allow(non_snake_case)]
pub fn H5FD__copy_plist<T: Clone>(value: &T) -> T {
    value.clone()
}

/// `H5FD__subfiling_fapl_copy`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_fapl_copy(config: &SubfilingConfig) -> SubfilingConfig {
    config.clone()
}

/// `H5FD__subfiling_fapl_free`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_fapl_free(_config: SubfilingConfig) {}

/// `H5FD__subfiling_open`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_open(_path: &str, _config: &SubfilingConfig) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_close_int`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_close_int() {}

/// `H5FD__subfiling_close`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_close() {}

/// `H5FD__subfiling_cmp`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_cmp(left: &SubfilingConfig, right: &SubfilingConfig) -> Ordering {
    H5FD__subfiling_compare_layout_nodelocal(left, right)
}

/// `H5FD__subfiling_query`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_query() -> u64 {
    0
}

/// `H5FD__subfiling_get_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_eoa() -> Result<u64> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_set_eoa`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_set_eoa(_eoa: u64) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_get_eof`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_eof() -> Result<u64> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_get_handle`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_handle() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_write_vector`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_write_vector(_requests: &[VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_truncate`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_truncate() -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_delete`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_delete(_path: &str) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_ctl`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_ctl(_opcode: u64) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_io_helper`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_io_helper(_requests: &[VfdIoRequest]) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_mirror_writes_to_stub`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_mirror_writes_to_stub(_enabled: bool) -> Result<()> {
    Err(unsupported_vfd_driver("subfiling"))
}

/// `H5FD__subfiling_generate_io_vectors`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_generate_io_vectors_view(requests: &[VfdIoRequest]) -> &[VfdIoRequest] {
    requests
}

/// `H5FD__subfiling_generate_io_vectors`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_generate_io_vectors_into(
    requests: &[VfdIoRequest],
    out: &mut Vec<VfdIoRequest>,
) {
    out.clear();
    out.extend_from_slice(requests);
}

/// `H5FD__subfiling_generate_io_vectors`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(
    note = "use H5FD__subfiling_generate_io_vectors_view or H5FD__subfiling_generate_io_vectors_into"
)]
pub fn H5FD__subfiling_generate_io_vectors(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__subfiling_generate_io_vectors_into(requests, &mut out);
    out
}

/// `H5FD__subfiling_get_iovec_sizes`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_iovec_sizes_iter(
    requests: &[VfdIoRequest],
) -> impl Iterator<Item = usize> + '_ {
    requests.iter().map(|request| request.bytes.len())
}

/// `H5FD__subfiling_get_iovec_sizes`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_get_iovec_sizes_into(requests: &[VfdIoRequest], out: &mut Vec<usize>) {
    out.clear();
    out.extend(H5FD__subfiling_iovec_sizes_iter(requests));
}

/// `H5FD__subfiling_get_iovec_sizes`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_get_iovec_sizes_into")]
pub fn H5FD__subfiling_get_iovec_sizes(requests: &[VfdIoRequest]) -> Vec<usize> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__subfiling_get_iovec_sizes_into(requests, &mut out);
    out
}

/// `H5FD__subfiling_translate_io_req_to_iovec`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_translate_io_req_to_iovec_ref(request: &VfdIoRequest) -> &VfdIoRequest {
    request
}

/// `H5FD__subfiling_translate_io_req_to_iovec`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_translate_io_req_to_iovec_ref")]
pub fn H5FD__subfiling_translate_io_req_to_iovec(request: &VfdIoRequest) -> VfdIoRequest {
    H5FD__subfiling_translate_io_req_to_iovec_ref(request).clone()
}

/// `H5FD__subfiling_iovec_fill_first`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_iovec_fill_first_ref(requests: &[VfdIoRequest]) -> Option<&VfdIoRequest> {
    requests.first()
}

/// `H5FD__subfiling_iovec_fill_first`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_iovec_fill_first_ref")]
pub fn H5FD__subfiling_iovec_fill_first(requests: &[VfdIoRequest]) -> Option<VfdIoRequest> {
    H5FD__subfiling_iovec_fill_first_ref(requests).cloned()
}

/// `H5FD__subfiling_iovec_fill_last`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_iovec_fill_last_ref(requests: &[VfdIoRequest]) -> Option<&VfdIoRequest> {
    requests.last()
}

/// `H5FD__subfiling_iovec_fill_last`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_iovec_fill_last_ref")]
pub fn H5FD__subfiling_iovec_fill_last(requests: &[VfdIoRequest]) -> Option<VfdIoRequest> {
    H5FD__subfiling_iovec_fill_last_ref(requests).cloned()
}

/// `H5FD__subfiling_iovec_fill_first_last`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_iovec_fill_first_last_into(
    requests: &[VfdIoRequest],
    out: &mut Vec<VfdIoRequest>,
) {
    out.clear();
    if let Some(first) = H5FD__subfiling_iovec_fill_first_ref(requests) {
        out.push(first.clone());
    }
    if requests.len() > 1 {
        if let Some(last) = H5FD__subfiling_iovec_fill_last_ref(requests) {
            out.push(last.clone());
        }
    }
}

/// `H5FD__subfiling_iovec_fill_first_last`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(note = "use H5FD__subfiling_iovec_fill_first_last_into")]
pub fn H5FD__subfiling_iovec_fill_first_last(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len().min(2));
    H5FD__subfiling_iovec_fill_first_last_into(requests, &mut out);
    out
}

/// `H5FD__subfiling_iovec_fill_uniform`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_iovec_fill_uniform_view(requests: &[VfdIoRequest]) -> &[VfdIoRequest] {
    requests
}

/// `H5FD__subfiling_iovec_fill_uniform`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_iovec_fill_uniform_into(
    requests: &[VfdIoRequest],
    out: &mut Vec<VfdIoRequest>,
) {
    out.clear();
    out.extend_from_slice(requests);
}

/// `H5FD__subfiling_iovec_fill_uniform`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
#[deprecated(
    note = "use H5FD__subfiling_iovec_fill_uniform_view or H5FD__subfiling_iovec_fill_uniform_into"
)]
pub fn H5FD__subfiling_iovec_fill_uniform(requests: &[VfdIoRequest]) -> Vec<VfdIoRequest> {
    let mut out = Vec::with_capacity(requests.len());
    H5FD__subfiling_iovec_fill_uniform_into(requests, &mut out);
    out
}

/// `H5FD__subfiling_cast_to_void`: distributed/cloud driver, not supported by the pure-Rust backend.
#[allow(non_snake_case)]
pub fn H5FD__subfiling_cast_to_void<T>(value: T) -> T {
    value
}

#[cfg(test)]
mod tests {
    use std::path::PathBuf;

    use super::{
        Error, FamilyFileConfig, FileDriverKind, HdfsConfig, IocConfig, LocalFileDriver,
        LogFileConfig, MirrorXmit, MirrorXmitRef, MultiFileConfig, OnionHeader, OnionRevisionIndex,
        OnionRevisionRecord, Ros3Config, SplitterFileConfig, SubfilingConfig, VfdMemType,
    };

    #[test]
    fn core_vfd_reads_writes_and_allocates() {
        let mut driver = LocalFileDriver {
            kind: super::FileDriverKind::Core,
            path: None,
            file: None,
            core_image: Vec::new(),
            eoa: 0,
            locked: false,
        };
        let addr = driver.alloc(4).unwrap();
        assert_eq!(addr, 0);
        driver.core_write(addr, b"abcd").unwrap();
        let mut out = [0; 4];
        driver.core_read(0, &mut out).unwrap();
        assert_eq!(&out, b"abcd");
        assert_eq!(driver.core_get_eof_checked().unwrap(), 4);
    }

    #[test]
    fn direct_vfd_get_eoa_and_flush_mirror_driver_state() {
        let path = std::env::temp_dir().join(format!(
            "hdf5_pure_rust_direct_vfd_{}_{}.h5",
            std::process::id(),
            "get_eoa_flush"
        ));
        LocalFileDriver::direct_delete(&path).unwrap();

        let mut driver = LocalFileDriver::direct_open(&path, true).unwrap();
        assert_eq!(driver.direct_get_eoa(), 0);
        assert_eq!(driver.direct_get_eof().unwrap(), 0);

        driver.direct_set_eoa(8);
        assert_eq!(driver.direct_get_eoa(), 8);
        driver.direct_write(0, b"abcd").unwrap();
        driver.direct_flush().unwrap();
        assert_eq!(driver.direct_get_eoa(), 8);
        assert_eq!(driver.direct_get_eof().unwrap(), 4);

        driver.direct_truncate().unwrap();
        assert_eq!(driver.direct_get_eof().unwrap(), 8);
        drop(driver);
        LocalFileDriver::direct_delete(&path).unwrap();
    }

    #[test]
    fn public_h5fd_runtime_wrappers_and_driver_query_are_explicit() {
        let mut registry = super::H5FD_init();
        assert_eq!(
            super::H5FDget_driver_id(&registry, "sec2"),
            Some(super::file_driver_kind_id(FileDriverKind::Sec2))
        );
        let mut driver_id = u64::MAX;
        super::H5FDget_driver_id_into(&registry, "sec2", &mut driver_id).unwrap();
        assert_eq!(driver_id, super::file_driver_kind_id(FileDriverKind::Sec2));
        assert_eq!(
            super::H5FD_get_driver_id_by_value(
                &registry,
                super::file_driver_kind_id(FileDriverKind::Sec2)
            ),
            Some("sec2")
        );
        let mut driver_name = String::from("stale");
        super::H5FD_get_driver_id_by_value_into(
            &registry,
            super::file_driver_kind_id(FileDriverKind::Sec2),
            &mut driver_name,
        )
        .unwrap();
        assert_eq!(driver_name, "sec2");
        assert_eq!(super::H5FDget_driver_id(&registry, "missing"), None);
        driver_id = 0xfeed;
        assert!(matches!(
            super::H5FDget_driver_id_into(&registry, "missing", &mut driver_id).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert_eq!(driver_id, 0xfeed);
        driver_name = String::from("stale");
        assert!(matches!(
            super::H5FD_get_driver_id_by_value_into(&registry, 99, &mut driver_name).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert_eq!(driver_name, "stale");
        assert_eq!(
            super::H5FDdriver_query(&registry, super::file_driver_kind_id(FileDriverKind::Sec2))
                .unwrap(),
            0x01
        );
        let mut flags = 0;
        super::H5FDdriver_query_into(
            &registry,
            super::file_driver_kind_id(FileDriverKind::Sec2),
            &mut flags,
        )
        .unwrap();
        assert_eq!(flags, 0x01);
        assert_eq!(
            super::H5FDdriver_query(&registry, super::file_driver_kind_id(FileDriverKind::Core))
                .unwrap(),
            0x03
        );
        assert!(matches!(
            super::H5FDdriver_query(&registry, 99).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        super::H5FDregister(&mut registry, "custom", 99);
        assert!(matches!(
            super::H5FDdriver_query(&registry, 99).unwrap_err(),
            Error::Unsupported(_)
        ));
        flags = 0xfeed;
        assert!(matches!(
            super::H5FDdriver_query_into(&registry, 99, &mut flags).unwrap_err(),
            Error::Unsupported(_)
        ));
        assert_eq!(flags, 0xfeed);

        let mut driver = LocalFileDriver {
            kind: super::FileDriverKind::Core,
            path: None,
            file: None,
            core_image: Vec::new(),
            eoa: 0,
            locked: false,
        };
        assert_eq!(super::H5FD_alloc(&mut driver, 2).unwrap(), 0);
        assert_eq!(super::H5FDget_eoa(&driver), 2);
        assert!(super::H5FD_try_extend(&mut driver, 0, 2, 4).unwrap());
        assert_eq!(super::H5FDget_eoa(&driver), 6);
        super::H5FD_free(&mut driver, 0, 6);
        assert_eq!(super::H5FDget_eoa(&driver), 6);
        super::H5FDquery_into(&driver, &mut flags).unwrap();
        assert_eq!(flags, 0x03);

        driver.core_write(0, b"abcdef").unwrap();
        super::H5FDset_eoa(&mut driver, 3);
        super::H5FDtruncate(&mut driver).unwrap();
        assert_eq!(driver.core_get_handle().unwrap(), b"abc");
        assert!(matches!(
            super::H5FD_set_base_addr(&mut driver, 512).unwrap_err(),
            Error::Unsupported(_)
        ));

        super::H5FDlock(&mut driver, true).unwrap();
        assert!(driver.locked);
        super::H5FDunlock(&mut driver).unwrap();
        assert!(!driver.locked);

        super::H5FDctl(&mut driver, Some(11)).unwrap();
        assert_eq!(super::H5FDget_eoa(&driver), 11);
        super::H5FDctl(&mut driver, None).unwrap();
        assert_eq!(super::H5FDget_eoa(&driver), 11);

        let handle_path = std::env::temp_dir().join(format!(
            "hdf5_pure_rust_h5fd_handle_{}_{}.h5",
            std::process::id(),
            "public"
        ));
        LocalFileDriver::sec2_delete(&handle_path).unwrap();
        let handle_driver = LocalFileDriver::sec2_open(&handle_path, true).unwrap();
        let mut file_handle = None;
        super::H5FDget_vfd_handle_into(&handle_driver, &mut file_handle).unwrap();
        let stale_handle = file_handle.map(|handle| handle as *const std::fs::File);
        assert!(stale_handle.is_some());
        let err = super::H5FDget_vfd_handle_into(&driver, &mut file_handle).unwrap_err();
        assert_eq!(
            err.to_string(),
            "Unsupported: H5FDget_vfd_handle requires a native file-backed VFD handle"
        );
        assert_eq!(
            file_handle.map(|handle| handle as *const std::fs::File),
            stale_handle
        );
        drop(handle_driver);
        LocalFileDriver::sec2_delete(&handle_path).unwrap();

        let path = std::env::temp_dir().join(format!(
            "hdf5_pure_rust_h5fddelete_{}_{}.h5",
            std::process::id(),
            "public"
        ));
        std::fs::write(&path, b"delete me").unwrap();
        assert!(path.exists());
        super::H5FDdelete(&path, FileDriverKind::Sec2).unwrap();
        assert!(!path.exists());
        super::H5FDdelete(&path, FileDriverKind::Sec2).unwrap();
        assert!(matches!(
            super::H5FDdelete(&path, FileDriverKind::Core).unwrap_err(),
            Error::Unsupported(_)
        ));
    }

    #[test]
    fn vfd_caller_owned_output_helpers_replace_stale_storage() {
        let requests = [
            super::VfdIoRequest {
                addr: 16,
                bytes: b"abc".to_vec(),
            },
            super::VfdIoRequest {
                addr: 32,
                bytes: b"def".to_vec(),
            },
        ];
        let stale_request = super::VfdIoRequest {
            addr: 999,
            bytes: b"stale".to_vec(),
        };

        let mut translated = vec![stale_request.clone()];
        super::H5FD__read_selection_translate_into(&requests, &mut translated);
        assert_eq!(translated, requests);

        super::H5FD__read_selection_translate_into(&[], &mut translated);
        assert!(translated.is_empty());

        let mut write_translated = vec![stale_request.clone()];
        super::H5FD__write_selection_translate_into(&requests, &mut write_translated);
        assert_eq!(write_translated, requests);

        let mut generated = vec![stale_request];
        super::H5FD__subfiling_generate_io_vectors_into(&requests, &mut generated);
        assert_eq!(generated, requests);

        let mut mpio_types = vec![super::VfdIoRequest {
            addr: 999,
            bytes: b"stale".to_vec(),
        }];
        super::H5FD__mpio_vector_build_types_into(&requests, &mut mpio_types);
        assert_eq!(mpio_types, requests);

        let mut selection_types = vec![super::VfdIoRequest {
            addr: 999,
            bytes: b"stale".to_vec(),
        }];
        super::H5FD__selection_build_types_into(&requests, &mut selection_types);
        assert_eq!(selection_types, requests);

        let mut iovec_sizes = vec![999, 1000];
        super::H5FD__subfiling_get_iovec_sizes_into(&requests, &mut iovec_sizes);
        assert_eq!(iovec_sizes, vec![3, 3]);

        super::H5FD__subfiling_get_iovec_sizes_into(&[], &mut iovec_sizes);
        assert!(iovec_sizes.is_empty());

        let mut first_last = vec![super::VfdIoRequest {
            addr: 999,
            bytes: b"stale".to_vec(),
        }];
        super::H5FD__subfiling_iovec_fill_first_last_into(&requests, &mut first_last);
        assert_eq!(first_last, requests);

        super::H5FD__subfiling_iovec_fill_first_last_into(&[], &mut first_last);
        assert!(first_last.is_empty());

        let mut uniform = vec![super::VfdIoRequest {
            addr: 999,
            bytes: b"stale".to_vec(),
        }];
        super::H5FD__subfiling_iovec_fill_uniform_into(&requests, &mut uniform);
        assert_eq!(uniform, requests);

        let config = SubfilingConfig {
            ioc_count: 3,
            stripe_size: 1024,
            stripe_count: 1,
        };
        let mut topology = vec![99, 100];
        super::H5FD__subfiling_init_app_topology_into(&config, &mut topology);
        assert_eq!(topology, vec![0, 1, 2]);

        let mut gathered = vec![99, 100];
        super::H5FD__subfiling_gather_topology_info_into(&config, &mut gathered);
        assert_eq!(gathered, vec![0, 1, 2]);

        let mut ranks = vec![99, 100];
        super::H5FD__subfiling_identify_ioc_ranks_into(&config, &mut ranks);
        assert_eq!(ranks, vec![0, 1, 2]);

        let mut mapping = vec![99, 100];
        super::H5FDsubfiling_get_file_mapping_into(&config, &mut mapping);
        assert_eq!(mapping, vec![0, 1, 2]);
    }

    #[test]
    fn family_multi_splitter_and_log_configs_round_trip() {
        let family = FamilyFileConfig {
            member_size: 4096,
            printf_filename: "member-%03d.h5".into(),
        };
        let mut family_bytes = Vec::new();
        super::H5FD__family_sb_encode_into(&family, &mut family_bytes).unwrap();
        assert_eq!(
            super::H5FD__family_sb_size(&family).unwrap(),
            family_bytes.len()
        );
        assert_eq!(
            super::H5FD__family_sb_decode(&family_bytes).unwrap(),
            FamilyFileConfig {
                member_size: family.member_size,
                printf_filename: FamilyFileConfig::default().printf_filename,
            }
        );
        assert_eq!(family_bytes, 4096u64.to_le_bytes());
        let family_default_size = FamilyFileConfig {
            member_size: 0,
            printf_filename: "member-%03d.h5".into(),
        };
        let mut family_default_size_bytes = Vec::new();
        super::H5FD__family_sb_encode_into(&family_default_size, &mut family_default_size_bytes)
            .unwrap();
        assert_eq!(family_default_size_bytes, 0u64.to_le_bytes());
        let mut invalid_family_bytes = Vec::new();
        assert!(super::H5FD__family_sb_encode_into(
            &FamilyFileConfig {
                member_size: 4096,
                printf_filename: String::new(),
            },
            &mut invalid_family_bytes
        )
        .is_err());

        let mut multi = MultiFileConfig::default();
        multi
            .memb_map
            .insert(VfdMemType::Default, FileDriverKind::Sec2);
        multi
            .memb_map
            .insert(VfdMemType::RawData, FileDriverKind::Core);
        let mut multi_bytes = Vec::new();
        super::H5FD_multi_sb_encode_into(&multi, &mut multi_bytes).unwrap();
        assert_eq!(
            super::H5FD_multi_sb_size(&multi).unwrap(),
            multi_bytes.len()
        );
        assert_eq!(super::H5FD_multi_sb_decode(&multi_bytes).unwrap(), multi);
        let mut invalid_multi_bytes = Vec::new();
        assert!(super::H5FD_multi_sb_encode_into(
            &MultiFileConfig::default(),
            &mut invalid_multi_bytes
        )
        .is_err());

        let splitter = SplitterFileConfig {
            write_only_path: Some(PathBuf::from("mirror.h5")),
            ignore_wo_errors: true,
        };
        let mut splitter_bytes = Vec::new();
        super::H5FD__splitter_sb_encode_into(&splitter, &mut splitter_bytes).unwrap();
        assert_eq!(
            super::H5FD__splitter_sb_size(&splitter).unwrap(),
            splitter_bytes.len()
        );
        assert_eq!(
            super::H5FD__splitter_sb_decode(&splitter_bytes).unwrap(),
            splitter
        );
        let mut invalid_splitter_bytes = Vec::new();
        assert!(super::H5FD__splitter_sb_encode_into(
            &SplitterFileConfig {
                write_only_path: Some(PathBuf::from("")),
                ignore_wo_errors: true,
            },
            &mut invalid_splitter_bytes
        )
        .is_err());

        let log = LogFileConfig {
            log_path: Some(PathBuf::from("driver.log")),
            flags: 0x55,
            buffer_size: 8192,
        };
        let mut log_bytes = Vec::new();
        super::H5FD__log_sb_encode_into(&log, &mut log_bytes).unwrap();
        assert_eq!(super::H5FD__log_sb_size(&log).unwrap(), log_bytes.len());
        assert_eq!(super::H5FD__log_sb_decode(&log_bytes).unwrap(), log);
        let mut invalid_log_bytes = Vec::new();
        assert!(super::H5FD__log_sb_encode_into(
            &LogFileConfig {
                log_path: Some(PathBuf::from("")),
                flags: 0,
                buffer_size: 0,
            },
            &mut invalid_log_bytes
        )
        .is_err());

        let ros3 = Ros3Config {
            endpoint: Some("s3.us-east-1.amazonaws.com".into()),
            region: Some("us-east-1".into()),
            token: Some("session-token".into()),
        };
        let mut ros3_bytes = Vec::new();
        super::H5FD__ros3_sb_encode_into(&ros3, &mut ros3_bytes).unwrap();
        assert_eq!(super::H5FD__ros3_sb_size(&ros3).unwrap(), ros3_bytes.len());
        assert_eq!(super::H5FD__ros3_sb_decode(&ros3_bytes).unwrap(), ros3);
        let mut invalid_ros3_bytes = Vec::new();
        assert!(super::H5FD__ros3_sb_encode_into(
            &Ros3Config {
                endpoint: Some(String::new()),
                region: None,
                token: None,
            },
            &mut invalid_ros3_bytes,
        )
        .is_err());

        assert!(matches!(
            super::H5FD_hdfs_init(),
            Err(Error::Unsupported(_))
        ));
        assert!(matches!(
            super::H5FD_family_init(),
            Err(Error::Unsupported(_))
        ));
        super::H5FD_family_term();
        assert!(matches!(
            super::H5FD_multi_init(),
            Err(Error::Unsupported(_))
        ));
        super::H5FD_multi_term();
        assert!(matches!(
            super::H5FD_splitter_init(),
            Err(Error::Unsupported(_))
        ));
        assert!(matches!(super::H5FD_log_init(), Err(Error::Unsupported(_))));
        super::H5FD_log_term();
        assert!(matches!(
            super::H5FD_ros3_init(),
            Err(Error::Unsupported(_))
        ));
        assert!(matches!(
            super::H5FD_mpio_init(),
            Err(Error::Unsupported(_))
        ));
        super::H5FD_mpio_term();
        assert!(matches!(
            super::H5FD_mirror_init(),
            Err(Error::Unsupported(_))
        ));

        assert_eq!(
            super::H5FD_mirror_xmit_decode_lock(&[]).unwrap(),
            MirrorXmit::Lock
        );
        let mut uint8_bytes = Vec::new();
        super::H5FD__mirror_xmit_encode_uint8_into(0xab, &mut uint8_bytes);
        assert_eq!(uint8_bytes, vec![0xab]);
        let mut open_bytes = Vec::new();
        super::H5FD_mirror_xmit_encode_open_into("mirror.h5", &mut open_bytes).unwrap();
        assert_eq!(
            super::H5FD_mirror_xmit_decode_open_ref(&open_bytes).unwrap(),
            MirrorXmitRef::Open { path: "mirror.h5" }
        );
        let mut reply_bytes = Vec::new();
        super::H5FD_mirror_xmit_encode_reply_into(0, &mut reply_bytes).unwrap();
        assert_eq!(
            super::H5FD_mirror_xmit_decode_reply(&reply_bytes).unwrap(),
            MirrorXmit::Reply { status: 0 }
        );
        let mut set_eoa_bytes = Vec::new();
        super::H5FD_mirror_xmit_encode_set_eoa_into(4096, &mut set_eoa_bytes).unwrap();
        assert_eq!(
            super::H5FD_mirror_xmit_decode_set_eoa(&set_eoa_bytes).unwrap(),
            MirrorXmit::SetEoa { eoa: 4096 }
        );
        let mut write_bytes = Vec::new();
        super::H5FD_mirror_xmit_encode_write_into(8192, b"abc", &mut write_bytes).unwrap();
        assert_eq!(
            super::H5FD_mirror_xmit_decode_write_ref(&write_bytes).unwrap(),
            MirrorXmitRef::Write {
                addr: 8192,
                data: b"abc"
            }
        );

        let onion = OnionHeader {
            version: 1,
            flags: 0x2,
            revision_count: 3,
        };
        let mut onion_bytes = Vec::new();
        super::H5FD__onion_sb_encode_into(&onion, &mut onion_bytes).unwrap();
        assert_eq!(super::H5FD__onion_sb_size(&onion), onion_bytes.len());
        assert_eq!(super::H5FD__onion_sb_decode(&onion_bytes).unwrap(), onion);
        assert_eq!(
            {
                let mut bytes = Vec::new();
                super::H5FD__onion_write_header_into(&onion, &mut bytes).unwrap();
                bytes
            },
            onion_bytes
        );
        assert_eq!(
            {
                let mut bytes = Vec::new();
                super::H5FD__onion_header_encode_into(&onion, &mut bytes).unwrap();
                bytes
            },
            onion_bytes
        );

        let ioc = IocConfig {
            thread_pool_size: 4,
            queue_depth: 16,
        };
        let mut ioc_bytes = Vec::new();
        super::H5FD__ioc_sb_encode_into(&ioc, &mut ioc_bytes).unwrap();
        assert_eq!(super::H5FD__ioc_sb_size(&ioc), ioc_bytes.len());
        assert_eq!(super::H5FD__ioc_sb_decode(&ioc_bytes).unwrap(), ioc);
        let mut invalid_ioc_bytes = Vec::new();
        assert!(super::H5FD__ioc_sb_encode_into(
            &IocConfig {
                thread_pool_size: 0,
                queue_depth: 16,
            },
            &mut invalid_ioc_bytes
        )
        .is_err());

        let subfiling = SubfilingConfig {
            ioc_count: 2,
            stripe_size: 1024,
            stripe_count: 8,
        };
        let mut subfiling_bytes = Vec::new();
        super::H5FD__subfiling_sb_encode_into(&subfiling, &mut subfiling_bytes).unwrap();
        assert_eq!(
            super::H5FD__subfiling_sb_size(&subfiling),
            subfiling_bytes.len()
        );
        assert_eq!(
            super::H5FD__subfiling_sb_decode(&subfiling_bytes).unwrap(),
            subfiling
        );
        let mut invalid_subfiling_bytes = Vec::new();
        assert!(super::H5FD__subfiling_sb_encode_into(
            &SubfilingConfig {
                ioc_count: 0,
                stripe_size: 1024,
                stripe_count: 8,
            },
            &mut invalid_subfiling_bytes
        )
        .is_err());
        assert_eq!(
            super::H5FD__subfiling_new_object_id_checked(41).unwrap(),
            42
        );
        assert!(super::H5FD__subfiling_new_object_id_checked(u64::MAX).is_err());
        assert_eq!(super::H5FD__subfiling_new_object_id(u64::MAX), u64::MAX);

        let history = OnionRevisionIndex {
            records: vec![
                OnionRevisionRecord {
                    revision: 1,
                    address: 64,
                    size: 8,
                },
                OnionRevisionRecord {
                    revision: 2,
                    address: 128,
                    size: 16,
                },
            ],
        };
        let mut history_bytes = Vec::new();
        super::H5FD__onion_history_encode_into(&history, &mut history_bytes).unwrap();
        assert_eq!(
            super::H5FD__onion_ingest_history(&history_bytes).unwrap(),
            history
        );
        assert_eq!(history_bytes.len(), 48);
        let mut record_bytes = Vec::new();
        super::H5FD__onion_revision_record_encode_into(&history.records[0], &mut record_bytes)
            .unwrap();
        assert_eq!(record_bytes.len(), 24);
        assert_eq!(
            super::H5FD__onion_revision_record_decode(&record_bytes).unwrap(),
            history.records[0]
        );
    }

    #[test]
    fn vfd_config_decoders_reject_truncated_or_invalid_payloads() {
        assert!(matches!(
            super::H5FD__family_sb_decode(&[0; 4]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__family_sb_decode(&[0; 9]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_multi_sb_decode(&[1, 0, 0, 0, 99, 0]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_multi_sb_decode(&[2, 0, 0, 0, 0, 0, 0, 1]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__splitter_sb_decode(&[0, 4, 0, 0, 0, b'a']).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__splitter_sb_decode(&[2, 0, 0, 0, 0]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__log_sb_decode(&[0; 7]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_mirror_xmit_decode_lock(&[0]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_mirror_xmit_decode_open_ref(&[0xff]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_mirror_xmit_decode_reply(&[0; 3]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_mirror_xmit_decode_set_eoa(&[0; 7]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD_mirror_xmit_decode_write_ref(&[0; 7]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__onion_sb_decode(&[0; 9]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__onion_revision_record_decode(&[0; 23]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__onion_ingest_history(&[0; 25]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__ioc_sb_decode(&[0; 15]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__ioc_sb_decode(&[0; 16]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__subfiling_sb_decode(&[0; 15]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__subfiling_sb_decode(&[0; 16]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__hdfs_sb_decode(&[0; 16]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        let mut hdfs_bad_version = vec![0; super::H5FD__hdfs_sb_size(&HdfsConfig::default())];
        hdfs_bad_version[0..4].copy_from_slice(&2u32.to_le_bytes());
        assert!(matches!(
            super::H5FD__hdfs_sb_decode(&hdfs_bad_version).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        let mut hdfs_bad_port = vec![0; super::H5FD__hdfs_sb_size(&HdfsConfig::default())];
        hdfs_bad_port[0..4].copy_from_slice(&1u32.to_le_bytes());
        hdfs_bad_port[4..7].copy_from_slice(b"nn\0");
        hdfs_bad_port[133..137].copy_from_slice(&65536u32.to_le_bytes());
        hdfs_bad_port[137..142].copy_from_slice(b"user\0");
        assert!(matches!(
            super::H5FD__hdfs_sb_decode(&hdfs_bad_port).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        let mut hdfs_bad_string = vec![0; super::H5FD__hdfs_sb_size(&HdfsConfig::default())];
        hdfs_bad_string[0..4].copy_from_slice(&1u32.to_le_bytes());
        hdfs_bad_string[4..].fill(b'a');
        assert!(matches!(
            super::H5FD__hdfs_sb_decode(&hdfs_bad_string).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        let mut hdfs_bad_trailing = vec![0; super::H5FD__hdfs_sb_size(&HdfsConfig::default())];
        hdfs_bad_trailing[0..4].copy_from_slice(&1u32.to_le_bytes());
        hdfs_bad_trailing[4..7].copy_from_slice(b"nn\0");
        hdfs_bad_trailing[8] = b'x';
        hdfs_bad_trailing[137..142].copy_from_slice(b"user\0");
        assert!(matches!(
            super::H5FD__hdfs_sb_decode(&hdfs_bad_trailing).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__ros3_sb_decode(&[1, 0, 0, 0, 0, 0, 0, 0]).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        let mut ros3_truncated = Vec::new();
        ros3_truncated.extend_from_slice(&4u32.to_le_bytes());
        ros3_truncated.extend_from_slice(&0u32.to_le_bytes());
        ros3_truncated.extend_from_slice(&0u32.to_le_bytes());
        ros3_truncated.extend_from_slice(b"s3");
        assert!(matches!(
            super::H5FD__ros3_sb_decode(&ros3_truncated).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        let mut ros3_nul = Vec::new();
        ros3_nul.extend_from_slice(&4u32.to_le_bytes());
        ros3_nul.extend_from_slice(&0u32.to_le_bytes());
        ros3_nul.extend_from_slice(&0u32.to_le_bytes());
        ros3_nul.extend_from_slice(b"s3\0x");
        assert!(matches!(
            super::H5FD__ros3_sb_decode(&ros3_nul).unwrap_err(),
            Error::InvalidFormat(_)
        ));
        assert!(matches!(
            super::H5FD__s3comms_parse_url_ref("s3://bucket/").unwrap_err(),
            Error::InvalidFormat(_)
        ));
    }

    #[test]
    fn hdfs_vfd_config_helpers_round_trip_copy_and_runtime_ops_are_unsupported() {
        let config = HdfsConfig {
            namenode_name: "nn.example.org".into(),
            namenode_port: 8020,
            user_name: "hdf5".into(),
            buffer_size: 65536,
        };
        assert!(super::H5FD__hdfs_validate_config(&config));
        let mut bytes = Vec::new();
        super::H5FD__hdfs_sb_encode_into(&config, &mut bytes).unwrap();
        assert_eq!(bytes.len(), super::H5FD__hdfs_sb_size(&config));
        assert_eq!(super::H5FD__hdfs_sb_decode(&bytes).unwrap(), config);
        assert_eq!(super::H5FD__hdfs_fapl_get(&config), config);
        assert_eq!(super::H5FD__hdfs_fapl_copy(&config), config);
        super::H5FD__hdfs_fapl_free(config.clone());

        let invalid = HdfsConfig {
            namenode_name: String::new(),
            ..config.clone()
        };
        assert!(!super::H5FD__hdfs_validate_config(&invalid));
        assert!(super::H5FD__hdfs_sb_encode_into(&invalid, &mut Vec::new()).is_err());

        let mut buf = *b"keep";
        assert!(matches!(
            super::H5FD__hdfs_open("hdfs://nn.example.org/data.h5", &config).unwrap_err(),
            Error::Unsupported(_)
        ));
        assert!(matches!(
            super::H5FD__hdfs_read(0, &mut buf).unwrap_err(),
            Error::Unsupported(_)
        ));
        assert_eq!(&buf, b"keep");
        assert!(matches!(
            super::H5FD__hdfs_write(0, &buf).unwrap_err(),
            Error::Unsupported(_)
        ));
        assert!(matches!(
            super::H5FD__hdfs_delete("hdfs://nn.example.org/data.h5").unwrap_err(),
            Error::Unsupported(_)
        ));
        assert!(matches!(
            super::H5FD__hdfs_lock().unwrap_err(),
            Error::Unsupported(_)
        ));
        assert!(matches!(
            super::H5FD__hdfs_unlock().unwrap_err(),
            Error::Unsupported(_)
        ));
    }
}