summaryrefslogtreecommitdiffstats
path: root/src/H5B2cache.c
blob: 9e01c03ca18e1ead1c308a5fbb49bac662090717 (plain)
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*-------------------------------------------------------------------------
 *
 * Created:     H5B2cache.c
 *              Jan 31 2005
 *              Quincey Koziol <koziol@hdfgroup.org>
 *
 * Purpose:     Implement v2 B-tree metadata cache methods.
 *
 *-------------------------------------------------------------------------
 */

/****************/
/* Module Setup */
/****************/

#define H5B2_PACKAGE		/*suppress error about including H5B2pkg  */


/***********/
/* Headers */
/***********/
#include "H5private.h"		/* Generic Functions			*/
#include "H5B2pkg.h"		/* v2 B-trees				*/
#include "H5Eprivate.h"		/* Error handling		  	*/
#include "H5MFprivate.h"	/* File memory management		*/
#include "H5WBprivate.h"        /* Wrapped Buffers                      */


/****************/
/* Local Macros */
/****************/

/* B-tree format version #'s */
#define H5B2_HDR_VERSION 0              /* Header */
#define H5B2_INT_VERSION 0              /* Internal node */
#define H5B2_LEAF_VERSION 0             /* Leaf node */

/* Size of stack buffer for serialized headers */
#define H5B2_HDR_BUF_SIZE               128


/******************/
/* Local Typedefs */
/******************/


/********************/
/* Package Typedefs */
/********************/


/********************/
/* Local Prototypes */
/********************/

/* Metadata cache callbacks */
static H5B2_hdr_t *H5B2__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata);
static herr_t H5B2__cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_hdr_t *hdr, unsigned UNUSED * flags_ptr);
static herr_t H5B2__cache_hdr_dest(H5F_t *f, H5B2_hdr_t *hdr);
static herr_t H5B2__cache_hdr_clear(H5F_t *f, H5B2_hdr_t *hdr, hbool_t destroy);
static herr_t H5B2__cache_hdr_size(const H5F_t *f, const H5B2_hdr_t *hdr, size_t *size_ptr);
static H5B2_internal_t *H5B2__cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata);
static herr_t H5B2__cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_internal_t *i, unsigned UNUSED * flags_ptr);
static herr_t H5B2__cache_internal_dest(H5F_t *f, H5B2_internal_t *internal);
static herr_t H5B2__cache_internal_clear(H5F_t *f, H5B2_internal_t *i, hbool_t destroy);
static herr_t H5B2__cache_internal_size(const H5F_t *f, const H5B2_internal_t *i, size_t *size_ptr);
static H5B2_leaf_t *H5B2__cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata);
static herr_t H5B2__cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_leaf_t *l, unsigned UNUSED * flags_ptr);
static herr_t H5B2__cache_leaf_dest(H5F_t *f, H5B2_leaf_t *leaf);
static herr_t H5B2__cache_leaf_clear(H5F_t *f, H5B2_leaf_t *l, hbool_t destroy);
static herr_t H5B2__cache_leaf_size(const H5F_t *f, const H5B2_leaf_t *l, size_t *size_ptr);


/*********************/
/* Package Variables */
/*********************/

/* H5B2 inherits cache-like properties from H5AC */
const H5AC_class_t H5AC_BT2_HDR[1] = {{
    H5AC_BT2_HDR_ID,
    (H5AC_load_func_t)H5B2__cache_hdr_load,
    (H5AC_flush_func_t)H5B2__cache_hdr_flush,
    (H5AC_dest_func_t)H5B2__cache_hdr_dest,
    (H5AC_clear_func_t)H5B2__cache_hdr_clear,
    (H5AC_notify_func_t)NULL,
    (H5AC_size_func_t)H5B2__cache_hdr_size,
}};

/* H5B2 inherits cache-like properties from H5AC */
const H5AC_class_t H5AC_BT2_INT[1] = {{
    H5AC_BT2_INT_ID,
    (H5AC_load_func_t)H5B2__cache_internal_load,
    (H5AC_flush_func_t)H5B2__cache_internal_flush,
    (H5AC_dest_func_t)H5B2__cache_internal_dest,
    (H5AC_clear_func_t)H5B2__cache_internal_clear,
    (H5AC_notify_func_t)NULL,
    (H5AC_size_func_t)H5B2__cache_internal_size,
}};

/* H5B2 inherits cache-like properties from H5AC */
const H5AC_class_t H5AC_BT2_LEAF[1] = {{
    H5AC_BT2_LEAF_ID,
    (H5AC_load_func_t)H5B2__cache_leaf_load,
    (H5AC_flush_func_t)H5B2__cache_leaf_flush,
    (H5AC_dest_func_t)H5B2__cache_leaf_dest,
    (H5AC_clear_func_t)H5B2__cache_leaf_clear,
    (H5AC_notify_func_t)NULL,
    (H5AC_size_func_t)H5B2__cache_leaf_size,
}};


/*****************************/
/* Library Private Variables */
/*****************************/


/*******************/
/* Local Variables */
/*******************/



/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_hdr_load
 *
 * Purpose:	Loads a B-tree header from the disk.
 *
 * Return:	Success:	Pointer to a new B-tree.
 *		Failure:	NULL
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 1 2005
 *
 *-------------------------------------------------------------------------
 */
static H5B2_hdr_t *
H5B2__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)
{
    H5B2_hdr_t		*hdr = NULL;    /* B-tree header */
    H5B2_hdr_cache_ud_t *udata = (H5B2_hdr_cache_ud_t *)_udata;
    H5B2_create_t       cparam;         /* B-tree creation parameters */
    H5B2_subid_t        id;		/* ID of B-tree class, as found in file */
    uint16_t            depth;          /* Depth of B-tree */
    uint32_t            stored_chksum;  /* Stored metadata checksum value */
    uint32_t            computed_chksum; /* Computed metadata checksum value */
    H5WB_t              *wb = NULL;     /* Wrapped buffer for header data */
    uint8_t             hdr_buf[H5B2_HDR_BUF_SIZE]; /* Buffer for header */
    uint8_t		*buf;           /* Pointer to header buffer */
    const uint8_t	*p;             /* Pointer into raw data buffer */
    H5B2_hdr_t		*ret_value;     /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(H5F_addr_defined(addr));
    HDassert(udata);

    /* Allocate new B-tree header and reset cache info */
    if(NULL == (hdr = H5B2__hdr_alloc(udata->f)))
        HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "allocation failed for B-tree header")

    /* Wrap the local buffer for serialized header info */
    if(NULL == (wb = H5WB_wrap(hdr_buf, sizeof(hdr_buf))))
        HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, NULL, "can't wrap buffer")

    /* Get a pointer to a buffer that's large enough for header */
    if(NULL == (buf = (uint8_t *)H5WB_actual(wb, hdr->hdr_size)))
        HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "can't get actual buffer")

    /* Read header from disk */
    if(H5F_block_read(f, H5FD_MEM_BTREE, addr, hdr->hdr_size, dxpl_id, buf) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree header")

    /* Get temporary pointer to serialized header */
    p = buf;

    /* Magic number */
    if(HDmemcmp(p, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC))
	HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "wrong B-tree header signature")
    p += H5_SIZEOF_MAGIC;

    /* Version */
    if(*p++ != H5B2_HDR_VERSION)
	HGOTO_ERROR(H5E_BTREE, H5E_BADRANGE, NULL, "wrong B-tree header version")

    /* B-tree class */
    id = (H5B2_subid_t)*p++;
    if(id >= H5B2_NUM_BTREE_ID)
        HGOTO_ERROR(H5E_BTREE, H5E_BADTYPE, NULL, "incorrect B-tree type")

    /* Node size (in bytes) */
    UINT32DECODE(p, cparam.node_size);

    /* Raw key size (in bytes) */
    UINT16DECODE(p, cparam.rrec_size);

    /* Depth of tree */
    UINT16DECODE(p, depth);

    /* Split & merge %s */
    cparam.split_percent = *p++;
    cparam.merge_percent = *p++;

    /* Root node pointer */
    H5F_addr_decode(udata->f, (const uint8_t **)&p, &(hdr->root.addr));
    UINT16DECODE(p, hdr->root.node_nrec);
    H5F_DECODE_LENGTH(udata->f, p, hdr->root.all_nrec);

    /* Metadata checksum */
    UINT32DECODE(p, stored_chksum);

    /* Sanity check */
    HDassert((size_t)(p - (const uint8_t *)buf) == hdr->hdr_size);

    /* Compute checksum on entire header */
    computed_chksum = H5_checksum_metadata(buf, (hdr->hdr_size - H5B2_SIZEOF_CHKSUM), 0);

    /* Verify checksum */
    if(stored_chksum != computed_chksum)
        HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 B-tree header")

    /* Initialize B-tree header info */
    cparam.cls = H5B2_client_class_g[id];
    if(H5B2__hdr_init(hdr, &cparam, udata->ctx_udata, depth) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, NULL, "can't initialize B-tree header info")

    /* Set the B-tree header's address */
    hdr->addr = addr;

    /* Set return value */
    ret_value = hdr;

done:
    /* Release resources */
    if(wb && H5WB_unwrap(wb) < 0)
        HDONE_ERROR(H5E_BTREE, H5E_CLOSEERROR, NULL, "can't close wrapped buffer")
    if(!ret_value && hdr)
        if(H5B2__hdr_free(hdr) < 0)
            HDONE_ERROR(H5E_BTREE, H5E_CANTRELEASE, NULL, "can't release v2 B-tree header")

    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_hdr_load() */ /*lint !e818 Can't make udata a pointer to const */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_hdr_flush
 *
 * Purpose:	Flushes a dirty B-tree header to disk.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 1 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
    H5B2_hdr_t *hdr, unsigned UNUSED * flags_ptr)
{
    H5WB_t      *wb = NULL;             /* Wrapped buffer for header data */
    uint8_t     hdr_buf[H5B2_HDR_BUF_SIZE]; /* Buffer for header */
    herr_t      ret_value = SUCCEED;    /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(H5F_addr_defined(addr));
    HDassert(hdr);

    if(hdr->cache_info.is_dirty) {
        uint8_t	*buf;           /* Pointer to header buffer */
        uint8_t *p;             /* Pointer into raw data buffer */
        uint32_t metadata_chksum; /* Computed metadata checksum value */

        /* Set the B-tree header's file context for this operation */
        hdr->f = f;

        /* Wrap the local buffer for serialized header info */
        if(NULL == (wb = H5WB_wrap(hdr_buf, sizeof(hdr_buf))))
            HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't wrap buffer")

        /* Get a pointer to a buffer that's large enough for header */
        if(NULL == (buf = (uint8_t *)H5WB_actual(wb, hdr->hdr_size)))
            HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, FAIL, "can't get actual buffer")

        /* Get temporary pointer to serialized header */
        p = buf;

        /* Magic number */
        HDmemcpy(p, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC);
        p += H5_SIZEOF_MAGIC;

        /* Version # */
        *p++ = H5B2_HDR_VERSION;

        /* B-tree type */
        *p++ = hdr->cls->id;

        /* Node size (in bytes) */
        UINT32ENCODE(p, hdr->node_size);

        /* Raw key size (in bytes) */
        UINT16ENCODE(p, hdr->rrec_size);

        /* Depth of tree */
        UINT16ENCODE(p, hdr->depth);

        /* Split & merge %s */
        H5_CHECK_OVERFLOW(hdr->split_percent, /* From: */ unsigned, /* To: */ uint8_t);
        *p++ = (uint8_t)hdr->split_percent;
        H5_CHECK_OVERFLOW(hdr->merge_percent, /* From: */ unsigned, /* To: */ uint8_t);
        *p++ = (uint8_t)hdr->merge_percent;

        /* Root node pointer */
        H5F_addr_encode(f, &p, hdr->root.addr);
        UINT16ENCODE(p, hdr->root.node_nrec);
        H5F_ENCODE_LENGTH(f, p, hdr->root.all_nrec);

        /* Compute metadata checksum */
        metadata_chksum = H5_checksum_metadata(buf, (hdr->hdr_size - H5B2_SIZEOF_CHKSUM), 0);

        /* Metadata checksum */
        UINT32ENCODE(p, metadata_chksum);

        /* Write the B-tree header. */
        HDassert((size_t)(p - buf) == hdr->hdr_size);
        if(H5F_block_write(f, H5FD_MEM_BTREE, addr, hdr->hdr_size, dxpl_id, buf) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree header to disk")

        hdr->cache_info.is_dirty = FALSE;
    } /* end if */

    if(destroy)
        if(H5B2__cache_hdr_dest(f, hdr) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree header")

done:
    /* Release resources */
    if(wb && H5WB_unwrap(wb) < 0)
        HDONE_ERROR(H5E_BTREE, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer")

    FUNC_LEAVE_NOAPI(ret_value)
} /* H5B2__cache_hdr_flush() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_hdr_dest
 *
 * Purpose:	Destroys a B-tree header in memory.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 1 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_hdr_dest(H5F_t *f, H5B2_hdr_t *hdr)
{
    herr_t ret_value = SUCCEED;     /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(hdr);
    HDassert(hdr->rc == 0);

    /* If we're going to free the space on disk, the address must be valid */
    HDassert(!hdr->cache_info.free_file_space_on_destroy || H5F_addr_defined(hdr->cache_info.addr));

    /* Check for freeing file space for B-tree header */
    if(hdr->cache_info.free_file_space_on_destroy) {
        /* Release the space on disk */
        /* (XXX: Nasty usage of internal DXPL value! -QAK) */
        if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, hdr->cache_info.addr, (hsize_t)hdr->hdr_size) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree header")
    } /* end if */

    /* Release B-tree header info */
    if(H5B2__hdr_free(hdr) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree header info")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_hdr_dest() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_hdr_clear
 *
 * Purpose:	Mark a B-tree header in memory as non-dirty.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb  1 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_hdr_clear(H5F_t *f, H5B2_hdr_t *hdr, hbool_t destroy)
{
    herr_t ret_value = SUCCEED;         /* Return value */

    FUNC_ENTER_STATIC

    /*
     * Check arguments.
     */
    HDassert(hdr);

    /* Reset the dirty flag.  */
    hdr->cache_info.is_dirty = FALSE;

    if(destroy)
        if(H5B2__cache_hdr_dest(f, hdr) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree header")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_hdr_clear() */


/*-------------------------------------------------------------------------
 * Function:    H5B2__cache_hdr_size
 *
 * Purpose:     Compute the size in bytes of a B-tree header
 *              on disk, and return it in *size_ptr.  On failure,
 *              the value of *size_ptr is undefined.
 *
 * Return:      SUCCEED (Can't fail)
 *
 * Programmer:  Quincey Koziol
 *              koziol@hdfgroup.org
 *              Feb 1 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_hdr_size(const H5F_t UNUSED *f, const H5B2_hdr_t *hdr, size_t *size_ptr)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check arguments */
    HDassert(f);
    HDassert(hdr);
    HDassert(size_ptr);

    /* Set size value */
    *size_ptr = hdr->hdr_size;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5B2__cache_hdr_size() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_internal_load
 *
 * Purpose:	Loads a B-tree internal node from the disk.
 *
 * Return:	Success:	Pointer to a new B-tree internal node.
 *              Failure:        NULL
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static H5B2_internal_t *
H5B2__cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)
{
    H5B2_internal_cache_ud_t *udata = (H5B2_internal_cache_ud_t *)_udata;     /* Pointer to user data */
    H5B2_internal_t	*internal = NULL;       /* Internal node read */
    const uint8_t	*p;             /* Pointer into raw data buffer */
    uint8_t		*native;        /* Pointer to native record info */
    H5B2_node_ptr_t	*int_node_ptr;  /* Pointer to node pointer info */
    uint32_t            stored_chksum;  /* Stored metadata checksum value */
    uint32_t            computed_chksum; /* Computed metadata checksum value */
    unsigned		u;              /* Local index variable */
    H5B2_internal_t	*ret_value;     /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(H5F_addr_defined(addr));
    HDassert(udata);

    /* Allocate new internal node and reset cache info */
    if(NULL == (internal = H5FL_MALLOC(H5B2_internal_t)))
	HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
    HDmemset(&internal->cache_info, 0, sizeof(H5AC_info_t));

    /* Set the B-tree header's file context for this operation */
    udata->hdr->f = f;

    /* Increment ref. count on B-tree header */
    if(H5B2__hdr_incr(udata->hdr) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_CANTINC, NULL, "can't increment ref. count on B-tree header")

    /* Share B-tree information */
    internal->hdr = udata->hdr;

    /* Read header from disk */
    if(H5F_block_read(f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, dxpl_id, udata->hdr->page) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree internal node")

    p = udata->hdr->page;

    /* Magic number */
    if(HDmemcmp(p, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC))
        HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "wrong B-tree internal node signature")
    p += H5_SIZEOF_MAGIC;

    /* Version */
    if(*p++ != H5B2_INT_VERSION)
	HGOTO_ERROR(H5E_BTREE, H5E_BADRANGE, NULL, "wrong B-tree internal node version")

    /* B-tree type */
    if(*p++ != (uint8_t)udata->hdr->cls->id)
        HGOTO_ERROR(H5E_BTREE, H5E_BADTYPE, NULL, "incorrect B-tree type")

    /* Allocate space for the native keys in memory */
    if(NULL == (internal->int_native = (uint8_t *)H5FL_FAC_MALLOC(udata->hdr->node_info[udata->depth].nat_rec_fac)))
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree internal native keys")

    /* Allocate space for the node pointers in memory */
    if(NULL == (internal->node_ptrs = (H5B2_node_ptr_t *)H5FL_FAC_MALLOC(udata->hdr->node_info[udata->depth].node_ptr_fac)))
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree internal node pointers")

    /* Set the number of records in the leaf & it's depth */
    internal->nrec = udata->nrec;
    internal->depth = udata->depth;

    /* Deserialize records for internal node */
    native = internal->int_native;
    for(u = 0; u < internal->nrec; u++) {
        /* Decode record */
        if((udata->hdr->cls->decode)(p, native, udata->hdr->cb_ctx) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, NULL, "unable to decode B-tree record")

        /* Move to next record */
        p += udata->hdr->rrec_size;
        native += udata->hdr->cls->nrec_size;
    } /* end for */

    /* Deserialize node pointers for internal node */
    int_node_ptr = internal->node_ptrs;
    for(u = 0; u < (unsigned)(internal->nrec + 1); u++) {
        /* Decode node pointer */
        H5F_addr_decode(udata->f, (const uint8_t **)&p, &(int_node_ptr->addr));
        UINT64DECODE_VAR(p, int_node_ptr->node_nrec, udata->hdr->max_nrec_size);
        if(udata->depth > 1)
            UINT64DECODE_VAR(p, int_node_ptr->all_nrec, udata->hdr->node_info[udata->depth - 1].cum_max_nrec_size)
        else
            int_node_ptr->all_nrec = int_node_ptr->node_nrec;

        /* Move to next node pointer */
        int_node_ptr++;
    } /* end for */

    /* Compute checksum on internal node */
    computed_chksum = H5_checksum_metadata(udata->hdr->page, (size_t)(p - (const uint8_t *)udata->hdr->page), 0);

    /* Metadata checksum */
    UINT32DECODE(p, stored_chksum);

    /* Sanity check parsing */
    HDassert((size_t)(p - (const uint8_t *)udata->hdr->page) <= udata->hdr->node_size);

    /* Verify checksum */
    if(stored_chksum != computed_chksum)
        HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 internal node")

    /* Set return value */
    ret_value = internal;

done:
    if(!ret_value && internal)
        if(H5B2__internal_free(internal) < 0)
            HDONE_ERROR(H5E_BTREE, H5E_CANTFREE, NULL, "unable to destroy B-tree internal node")

    FUNC_LEAVE_NOAPI(ret_value)
} /* H5B2__cache_internal_load() */ /*lint !e818 Can't make udata a pointer to const */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_internal_flush
 *
 * Purpose:	Flushes a dirty B-tree internal node to disk.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 3 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_internal_t *internal, unsigned UNUSED * flags_ptr)
{
    herr_t      ret_value = SUCCEED;    /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(H5F_addr_defined(addr));
    HDassert(internal);
    HDassert(internal->hdr);

    if(internal->cache_info.is_dirty) {
        uint8_t *p;             /* Pointer into raw data buffer */
        uint8_t *native;        /* Pointer to native record info */
        H5B2_node_ptr_t *int_node_ptr;      /* Pointer to node pointer info */
        uint32_t metadata_chksum; /* Computed metadata checksum value */
        unsigned u;             /* Local index variable */

        /* Set the B-tree header's file context for this operation */
        internal->hdr->f = f;

        p = internal->hdr->page;

        /* Magic number */
        HDmemcpy(p, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC);
        p += H5_SIZEOF_MAGIC;

        /* Version # */
        *p++ = H5B2_INT_VERSION;

        /* B-tree type */
        *p++ = internal->hdr->cls->id;
        HDassert((size_t)(p - internal->hdr->page) == (H5B2_INT_PREFIX_SIZE - H5B2_SIZEOF_CHKSUM));

        /* Serialize records for internal node */
        native = internal->int_native;
        for(u = 0; u < internal->nrec; u++) {
            /* Encode record */
            if((internal->hdr->cls->encode)(p, native, internal->hdr->cb_ctx) < 0)
                HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record")

            /* Move to next record */
            p += internal->hdr->rrec_size;
            native += internal->hdr->cls->nrec_size;
        } /* end for */

        /* Serialize node pointers for internal node */
        int_node_ptr = internal->node_ptrs;
        for(u = 0; u < (unsigned)(internal->nrec + 1); u++) {
            /* Encode node pointer */
            H5F_addr_encode(f, &p, int_node_ptr->addr);
            UINT64ENCODE_VAR(p, int_node_ptr->node_nrec, internal->hdr->max_nrec_size);
            if(internal->depth > 1)
                UINT64ENCODE_VAR(p, int_node_ptr->all_nrec, internal->hdr->node_info[internal->depth - 1].cum_max_nrec_size);

            /* Move to next node pointer */
            int_node_ptr++;
        } /* end for */

        /* Compute metadata checksum */
        metadata_chksum = H5_checksum_metadata(internal->hdr->page, (size_t)(p - internal->hdr->page), 0);

        /* Metadata checksum */
        UINT32ENCODE(p, metadata_chksum);

	/* Write the B-tree internal node */
        HDassert((size_t)(p - internal->hdr->page) <= internal->hdr->node_size);
	if(H5F_block_write(f, H5FD_MEM_BTREE, addr, internal->hdr->node_size, dxpl_id, internal->hdr->page) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree internal node to disk")

	internal->cache_info.is_dirty = FALSE;
    } /* end if */

    if(destroy)
        if(H5B2__cache_internal_dest(f, internal) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree internal node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* H5B2__cache_internal_flush() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_internal_dest
 *
 * Purpose:	Destroys a B-tree internal node in memory.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_internal_dest(H5F_t *f, H5B2_internal_t *internal)
{
    herr_t ret_value = SUCCEED;     /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(internal);
    HDassert(internal->hdr);

    /* If we're going to free the space on disk, the address must be valid */
    HDassert(!internal->cache_info.free_file_space_on_destroy || H5F_addr_defined(internal->cache_info.addr));

    /* Check for freeing file space for B-tree internal node */
    if(internal->cache_info.free_file_space_on_destroy) {
        /* Release the space on disk */
        /* (XXX: Nasty usage of internal DXPL value! -QAK) */
        if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, internal->cache_info.addr, (hsize_t)internal->hdr->node_size) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree internal node")
    } /* end if */

    /* Release v2 b-tree internal node */
    if(H5B2__internal_free(internal) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to release v2 B-tree internal node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_internal_dest() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_internal_clear
 *
 * Purpose:	Mark a B-tree internal node in memory as non-dirty.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb  2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_internal_clear(H5F_t *f, H5B2_internal_t *internal, hbool_t destroy)
{
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_STATIC

    /*
     * Check arguments.
     */
    HDassert(internal);

    /* Reset the dirty flag.  */
    internal->cache_info.is_dirty = FALSE;

    if(destroy)
        if(H5B2__cache_internal_dest(f, internal) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree internal node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_internal_clear() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_internal_size
 *
 * Purpose:	Compute the size in bytes of a B-tree internal node
 *		on disk, and return it in *size_ptr.  On failure,
 *		the value of *size_ptr is undefined.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_internal_size(const H5F_t UNUSED *f, const H5B2_internal_t *internal, size_t *size_ptr)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check arguments */
    HDassert(internal);
    HDassert(internal->hdr);
    HDassert(size_ptr);

    /* Set size value */
    *size_ptr = internal->hdr->node_size;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5B2__cache_internal_size() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_leaf_load
 *
 * Purpose:	Loads a B-tree leaf from the disk.
 *
 * Return:	Success:	Pointer to a new B-tree leaf node.
 *		Failure:	NULL
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static H5B2_leaf_t *
H5B2__cache_leaf_load(H5F_t UNUSED *f, hid_t dxpl_id, haddr_t addr, void *_udata)
{
    H5B2_leaf_cache_ud_t *udata = (H5B2_leaf_cache_ud_t *)_udata;
    H5B2_leaf_t		*leaf = NULL;   /* Pointer to lead node loaded */
    const uint8_t	*p;             /* Pointer into raw data buffer */
    uint8_t		*native;        /* Pointer to native keys */
    uint32_t            stored_chksum;  /* Stored metadata checksum value */
    uint32_t            computed_chksum; /* Computed metadata checksum value */
    unsigned		u;              /* Local index variable */
    H5B2_leaf_t		*ret_value;     /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(H5F_addr_defined(addr));
    HDassert(udata);

    /* Allocate new leaf node and reset cache info */
    if(NULL == (leaf = H5FL_MALLOC(H5B2_leaf_t)))
	HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed")
    HDmemset(&leaf->cache_info, 0, sizeof(H5AC_info_t));

    /* Set the B-tree header's file context for this operation */
    udata->hdr->f = udata->f;

    /* Increment ref. count on B-tree header */
    if(H5B2__hdr_incr(udata->hdr) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_CANTINC, NULL, "can't increment ref. count on B-tree header")

    /* Share B-tree header information */
    leaf->hdr = udata->hdr;

    /* Read header from disk */
    if(H5F_block_read(udata->f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, dxpl_id, udata->hdr->page) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree leaf node")

    p = udata->hdr->page;

    /* Magic number */
    if(HDmemcmp(p, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC))
	HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "wrong B-tree leaf node signature")
    p += H5_SIZEOF_MAGIC;

    /* Version */
    if(*p++ != H5B2_LEAF_VERSION)
	HGOTO_ERROR(H5E_BTREE, H5E_BADRANGE, NULL, "wrong B-tree leaf node version")

    /* B-tree type */
    if(*p++ != (uint8_t)udata->hdr->cls->id)
        HGOTO_ERROR(H5E_BTREE, H5E_BADTYPE, NULL, "incorrect B-tree type")

    /* Allocate space for the native keys in memory */
    if(NULL == (leaf->leaf_native = (uint8_t *)H5FL_FAC_MALLOC(udata->hdr->node_info[0].nat_rec_fac)))
	HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree leaf native keys")

    /* Set the number of records in the leaf */
    leaf->nrec = udata->nrec;

    /* Deserialize records for leaf node */
    native = leaf->leaf_native;
    for(u = 0; u < leaf->nrec; u++) {
        /* Decode record */
        if((udata->hdr->cls->decode)(p, native, udata->hdr->cb_ctx) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, NULL, "unable to decode B-tree record")

        /* Move to next record */
        p += udata->hdr->rrec_size;
        native += udata->hdr->cls->nrec_size;
    } /* end for */

    /* Compute checksum on leaf node */
    computed_chksum = H5_checksum_metadata(udata->hdr->page, (size_t)(p - (const uint8_t *)udata->hdr->page), 0);

    /* Metadata checksum */
    UINT32DECODE(p, stored_chksum);

    /* Sanity check parsing */
    HDassert((size_t)(p - (const uint8_t *)udata->hdr->page) <= udata->hdr->node_size);

    /* Verify checksum */
    if(stored_chksum != computed_chksum)
	HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 leaf node")

    /* Set return value */
    ret_value = leaf;

done:
    if(!ret_value && leaf)
        if(H5B2__leaf_free(leaf) < 0)
            HDONE_ERROR(H5E_BTREE, H5E_CANTFREE, NULL, "unable to destroy B-tree leaf node")

    FUNC_LEAVE_NOAPI(ret_value)
} /* H5B2__cache_leaf_load() */ /*lint !e818 Can't make udata a pointer to const */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_leaf_flush
 *
 * Purpose:	Flushes a dirty B-tree leaf node to disk.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B2_leaf_t *leaf, unsigned UNUSED * flags_ptr)
{
    herr_t      ret_value = SUCCEED;    /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(H5F_addr_defined(addr));
    HDassert(leaf);
    HDassert(leaf->hdr);

    if(leaf->cache_info.is_dirty) {
        uint8_t *p;             /* Pointer into raw data buffer */
        uint8_t *native;        /* Pointer to native keys */
        uint32_t metadata_chksum; /* Computed metadata checksum value */
        unsigned u;             /* Local index variable */

        /* Set the B-tree header's file context for this operation */
        leaf->hdr->f = f;

        p = leaf->hdr->page;

        /* magic number */
        HDmemcpy(p, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC);
        p += H5_SIZEOF_MAGIC;

        /* version # */
        *p++ = H5B2_LEAF_VERSION;

        /* b-tree type */
        *p++ = leaf->hdr->cls->id;
        HDassert((size_t)(p - leaf->hdr->page) == (H5B2_LEAF_PREFIX_SIZE - H5B2_SIZEOF_CHKSUM));

        /* Serialize records for leaf node */
        native = leaf->leaf_native;
        for(u = 0; u < leaf->nrec; u++) {
            /* Encode record */
            if((leaf->hdr->cls->encode)(p, native, leaf->hdr->cb_ctx) < 0)
                HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record")

            /* Move to next record */
            p += leaf->hdr->rrec_size;
            native += leaf->hdr->cls->nrec_size;
        } /* end for */

        /* Compute metadata checksum */
        metadata_chksum = H5_checksum_metadata(leaf->hdr->page, (size_t)(p - leaf->hdr->page), 0);

        /* Metadata checksum */
        UINT32ENCODE(p, metadata_chksum);

	/* Write the B-tree leaf node */
        HDassert((size_t)(p - leaf->hdr->page) <= leaf->hdr->node_size);
	if(H5F_block_write(f, H5FD_MEM_BTREE, addr, leaf->hdr->node_size, dxpl_id, leaf->hdr->page) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree leaf node to disk")

	leaf->cache_info.is_dirty = FALSE;
    } /* end if */

    if(destroy)
        if(H5B2__cache_leaf_dest(f, leaf) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree leaf node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* H5B2__cache_leaf_flush() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_leaf_dest
 *
 * Purpose:	Destroys a B-tree leaf node in memory.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_leaf_dest(H5F_t *f, H5B2_leaf_t *leaf)
{
    herr_t ret_value = SUCCEED;     /* Return value */

    FUNC_ENTER_STATIC

    /* Check arguments */
    HDassert(f);
    HDassert(leaf);
    HDassert(leaf->hdr);

    /* If we're going to free the space on disk, the address must be valid */
    HDassert(!leaf->cache_info.free_file_space_on_destroy || H5F_addr_defined(leaf->cache_info.addr));

    /* Check for freeing file space for B-tree leaf node */
    if(leaf->cache_info.free_file_space_on_destroy) {
        /* Release the space on disk */
        /* (XXX: Nasty usage of internal DXPL value! -QAK) */
        if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, leaf->cache_info.addr, (hsize_t)leaf->hdr->node_size) < 0)
            HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free v2 B-tree leaf node")
    } /* end if */

    /* Destroy v2 b-tree leaf node */
    if(H5B2__leaf_free(leaf) < 0)
        HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree leaf node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_leaf_dest() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_leaf_clear
 *
 * Purpose:	Mark a B-tree leaf node in memory as non-dirty.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb  2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_leaf_clear(H5F_t *f, H5B2_leaf_t *leaf, hbool_t destroy)
{
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_STATIC

    /*
     * Check arguments.
     */
    HDassert(leaf);

    /* Reset the dirty flag.  */
    leaf->cache_info.is_dirty = FALSE;

    if(destroy)
        if(H5B2__cache_leaf_dest(f, leaf) < 0)
	    HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree leaf node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B2__cache_leaf_clear() */


/*-------------------------------------------------------------------------
 * Function:	H5B2__cache_leaf_size
 *
 * Purpose:	Compute the size in bytes of a B-tree leaf node
 *		on disk, and return it in *size_ptr.  On failure,
 *		the value of *size_ptr is undefined.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *		koziol@ncsa.uiuc.edu
 *		Feb 2 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5B2__cache_leaf_size(const H5F_t UNUSED *f, const H5B2_leaf_t *leaf, size_t *size_ptr)
{
    FUNC_ENTER_STATIC_NOERR

    /* check arguments */
    HDassert(leaf);
    HDassert(leaf->hdr);
    HDassert(size_ptr);

    /* Set size value */
    *size_ptr = leaf->hdr->node_size;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5B2__cache_leaf_size() */

opt">); if(NULL != *pp) { /* Encode alloc and fill time */ *(*pp)++ = (uint8_t)fill->alloc_time; *(*pp)++ = (uint8_t)fill->fill_time; /* Encode size of fill value */ INT64ENCODE(*pp, fill->size) /* Encode the fill value & datatype */ if(fill->size > 0) { /* Encode the fill value itself */ HDmemcpy(*pp, (uint8_t *)fill->buf, (size_t)fill->size); *pp += fill->size; /* Encode fill value datatype */ HDassert(fill->type); if(H5T_encode(fill->type, NULL, &dt_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype") /* Encode the size of a size_t */ enc_value = (uint64_t)dt_size; enc_size = H5VM_limit_enc_size(enc_value); HDassert(enc_size < 256); /* Encode the size */ *(*pp)++ = (uint8_t)enc_size; /* Encode the size of the encoded datatype */ UINT64ENCODE_VAR(*pp, enc_value, enc_size); if(H5T_encode(fill->type, *pp, &dt_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype") *pp += dt_size; } /* end if */ } /* end if */ /* Calculate size needed for encoding */ *size += 2; *size += sizeof(int64_t); if(fill->size > 0) { /* The size of the fill value buffer */ *size += (size_t)fill->size; /* calculate those if they were not calculated earlier */ if(NULL == *pp) { /* Get the size of the encoded datatype */ HDassert(fill->type); if(H5T_encode(fill->type, NULL, &dt_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype") enc_value = (uint64_t)dt_size; enc_size = H5VM_limit_enc_size(enc_value); } *size += (1 + enc_size); *size += dt_size; } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__fill_value_enc() */ /*------------------------------------------------------------------------- * Function: H5P__fill_value_dec * * Purpose: Callback routine which is called whenever the fill value * property in the dataset creation property list is * decoded. * * Return: Success: Non-negative * Failure: Negative * * Programmer: Mohamad Chaarawi * Monday, October 10, 2011 * *------------------------------------------------------------------------- */ static herr_t H5P__fill_value_dec(const void **_pp, void *_value) { H5O_fill_t *fill = (H5O_fill_t *)_value; /* Fill value */ const uint8_t **pp = (const uint8_t **)_pp; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC HDcompile_assert(sizeof(size_t) <= sizeof(uint64_t)); HDcompile_assert(sizeof(ssize_t) <= sizeof(int64_t)); /* Set property to default value */ *fill = H5D_def_fill_g; /* Decode alloc and fill time */ fill->alloc_time = (H5D_alloc_time_t)*(*pp)++; fill->fill_time = (H5D_fill_time_t)*(*pp)++; /* Decode fill size */ INT64DECODE(*pp, fill->size) /* Check if there's a fill value */ if(fill->size > 0) { size_t dt_size = 0; uint64_t enc_value; unsigned enc_size; /* Allocate fill buffer and copy the contents in it */ if(NULL == (fill->buf = H5MM_malloc((size_t)fill->size))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for fill value buffer") HDmemcpy((uint8_t *)fill->buf, *pp, (size_t)fill->size); *pp += fill->size; enc_size = *(*pp)++; HDassert(enc_size < 256); /* Decode the size of encoded datatype */ UINT64DECODE_VAR(*pp, enc_value, enc_size); dt_size = (size_t)enc_value; /* Decode type */ if(NULL == (fill->type = H5T_decode(*pp))) HGOTO_ERROR(H5E_PLIST, H5E_CANTDECODE, FAIL, "can't decode fill value datatype") *pp += dt_size; } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__fill_value_dec() */ /*------------------------------------------------------------------------- * Function: H5P_fill_value_cmp * * Purpose: Callback routine which is called whenever the fill value * property in the dataset creation property list is compared. * * Return: positive if VALUE1 is greater than VALUE2, negative if * VALUE2 is greater than VALUE1 and zero if VALUE1 and * VALUE2 are equal. * * Programmer: Quincey Koziol * Wednesday, January 7, 2004 * *------------------------------------------------------------------------- */ int H5P_fill_value_cmp(const void *_fill1, const void *_fill2, size_t H5_ATTR_UNUSED size) { const H5O_fill_t *fill1 = (const H5O_fill_t *)_fill1, /* Create local aliases for values */ *fill2 = (const H5O_fill_t *)_fill2; int cmp_value; /* Value from comparison */ herr_t ret_value = 0; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR /* Sanity check */ HDassert(fill1); HDassert(fill2); HDassert(size == sizeof(H5O_fill_t)); /* Check the size of fill values */ if(fill1->size < fill2->size) HGOTO_DONE(-1); if(fill1->size > fill2->size) HGOTO_DONE(1); /* Check the types of the fill values */ if(fill1->type == NULL && fill2->type != NULL) HGOTO_DONE(-1); if(fill1->type != NULL && fill2->type == NULL) HGOTO_DONE(1); if(fill1->type != NULL) if((cmp_value = H5T_cmp(fill1->type, fill2->type, FALSE)) != 0) HGOTO_DONE(cmp_value); /* Check the fill values in the buffers */ if(fill1->buf == NULL && fill2->buf != NULL) HGOTO_DONE(-1); if(fill1->buf != NULL && fill2->buf == NULL) HGOTO_DONE(1); if(fill1->buf != NULL) if((cmp_value = HDmemcmp(fill1->buf, fill2->buf, (size_t)fill1->size)) != 0) HGOTO_DONE(cmp_value); /* Check the allocation time for the fill values */ if(fill1->alloc_time < fill2->alloc_time) HGOTO_DONE(-1); if(fill1->alloc_time > fill2->alloc_time) HGOTO_DONE(1); /* Check the fill time for the fill values */ if(fill1->fill_time < fill2->fill_time) HGOTO_DONE(-1); if(fill1->fill_time > fill2->fill_time) HGOTO_DONE(1); done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_fill_value_cmp() */ /*------------------------------------------------------------------------- * Function: H5P__dcrt_ext_file_list_enc * * Purpose: Callback routine which is called whenever the efl * property in the dataset creation property list is * encoded. * * Return: Success: Non-negative * Failure: Negative * * Programmer: Mohamad Chaarawi * Monday, October 10, 2011 * *------------------------------------------------------------------------- */ static herr_t H5P__dcrt_ext_file_list_enc(const void *value, void **_pp, size_t *size) { const H5O_efl_t *efl = (const H5O_efl_t *)value; /* Create local aliases for values */ size_t len = 0; /* String length of slot name */ size_t u; /* Local index variable */ uint8_t **pp = (uint8_t **)_pp; unsigned enc_size; uint64_t enc_value; FUNC_ENTER_STATIC_NOERR /* Sanity check */ HDassert(efl); HDcompile_assert(sizeof(size_t) <= sizeof(uint64_t)); HDcompile_assert(sizeof(off_t) <= sizeof(uint64_t)); HDcompile_assert(sizeof(hsize_t) <= sizeof(uint64_t)); HDassert(size); if(NULL != *pp) { /* Encode number of slots used */ enc_value = (uint64_t)efl->nused; enc_size = H5VM_limit_enc_size(enc_value); HDassert(enc_size < 256); *(*pp)++ = (uint8_t)enc_size; UINT64ENCODE_VAR(*pp, enc_value, enc_size); /* Encode file list */ for(u = 0; u < efl->nused; u++) { /* Calculate length of slot name and encode it */ len = HDstrlen(efl->slot[u].name) + 1; enc_value = (uint64_t)len; enc_size = H5VM_limit_enc_size(enc_value); HDassert(enc_size < 256); *(*pp)++ = (uint8_t)enc_size; UINT64ENCODE_VAR(*pp, enc_value, enc_size); /* Encode name */ HDmemcpy(*pp, (uint8_t *)(efl->slot[u].name), len); *pp += len; /* Encode offset */ enc_value = (uint64_t)efl->slot[u].offset; enc_size = H5VM_limit_enc_size(enc_value); HDassert(enc_size < 256); *(*pp)++ = (uint8_t)enc_size; UINT64ENCODE_VAR(*pp, enc_value, enc_size); /* encode size */ enc_value = (uint64_t)efl->slot[u].size; enc_size = H5VM_limit_enc_size(enc_value); HDassert(enc_size < 256); *(*pp)++ = (uint8_t)enc_size; UINT64ENCODE_VAR(*pp, enc_value, enc_size); } /* end for */ } /* end if */ /* Calculate size needed for encoding */ *size += (1 + H5VM_limit_enc_size((uint64_t)efl->nused)); for(u = 0; u < efl->nused; u++) { len = HDstrlen(efl->slot[u].name) + 1; *size += (1 + H5VM_limit_enc_size((uint64_t)len)); *size += len; *size += (1 + H5VM_limit_enc_size((uint64_t)efl->slot[u].offset)); *size += (1 + H5VM_limit_enc_size((uint64_t)efl->slot[u].size)); } /* end for */ FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__dcrt_ext_file_list_enc() */ /*------------------------------------------------------------------------- * Function: H5P__dcrt_ext_file_list_dec * * Purpose: Callback routine which is called whenever the efl * property in the dataset creation property list is * decoded. * * Return: Success: Non-negative * Failure: Negative * * Programmer: Mohamad Chaarawi * Monday, October 10, 2011 * *------------------------------------------------------------------------- */ static herr_t H5P__dcrt_ext_file_list_dec(const void **_pp, void *_value) { H5O_efl_t *efl = (H5O_efl_t *)_value; /* External file list */ const uint8_t **pp = (const uint8_t **)_pp; size_t u, nused; unsigned enc_size; uint64_t enc_value; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* Sanity check */ HDassert(pp); HDassert(*pp); HDassert(efl); HDcompile_assert(sizeof(size_t) <= sizeof(uint64_t)); HDcompile_assert(sizeof(off_t) <= sizeof(uint64_t)); HDcompile_assert(sizeof(hsize_t) <= sizeof(uint64_t)); /* Set property to default value */ *efl = H5D_def_efl_g; /* Decode number of slots used */ enc_size = *(*pp)++; HDassert(enc_size < 256); UINT64DECODE_VAR(*pp, enc_value, enc_size); nused = (size_t)enc_value; /* Decode information for each slot */ for(u = 0; u < nused; u++) { size_t len; if(efl->nused >= efl->nalloc) { size_t na = efl->nalloc + H5O_EFL_ALLOC; H5O_efl_entry_t *x = (H5O_efl_entry_t *)H5MM_realloc(efl->slot, na * sizeof(H5O_efl_entry_t)); if(!x) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "memory allocation failed") efl->nalloc = na; efl->slot = x; } /* end if */ /* Decode length of slot name */ enc_size = *(*pp)++; HDassert(enc_size < 256); UINT64DECODE_VAR(*pp, enc_value, enc_size); len = (size_t)enc_value; /* Allocate name buffer and decode the name into it */ efl->slot[u].name = H5MM_xstrdup((const char *)(*pp)); *pp += len; /* decode offset */ enc_size = *(*pp)++; HDassert(enc_size < 256); UINT64DECODE_VAR(*pp, enc_value, enc_size); efl->slot[u].offset = (off_t)enc_value; /* decode size */ enc_size = *(*pp)++; HDassert(enc_size < 256); UINT64DECODE_VAR(*pp, enc_value, enc_size); efl->slot[u].size = (hsize_t)enc_value; efl->slot[u].name_offset = 0; /*not entered into heap yet*/ efl->nused++; } /* end for */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__dcrt_ext_file_list_dec() */ /*------------------------------------------------------------------------- * Function: H5P__dcrt_ext_file_list_cmp * * Purpose: Callback routine which is called whenever the external file * list property in the dataset creation property list is * compared. * * Return: positive if VALUE1 is greater than VALUE2, negative if * VALUE2 is greater than VALUE1 and zero if VALUE1 and * VALUE2 are equal. * * Programmer: Quincey Koziol * Wednesday, January 7, 2004 * *------------------------------------------------------------------------- */ static int H5P__dcrt_ext_file_list_cmp(const void *_efl1, const void *_efl2, size_t H5_ATTR_UNUSED size) { const H5O_efl_t *efl1 = (const H5O_efl_t *)_efl1, /* Create local aliases for values */ *efl2 = (const H5O_efl_t *)_efl2; int cmp_value; /* Value from comparison */ herr_t ret_value = 0; /* Return value */ FUNC_ENTER_STATIC_NOERR /* Sanity check */ HDassert(efl1); HDassert(efl2); HDassert(size == sizeof(H5O_efl_t)); /* Check the heap address of external file lists */ if(H5F_addr_defined(efl1->heap_addr) || H5F_addr_defined(efl2->heap_addr)) { if(!H5F_addr_defined(efl1->heap_addr) && H5F_addr_defined(efl2->heap_addr)) HGOTO_DONE(-1); if(H5F_addr_defined(efl1->heap_addr) && !H5F_addr_defined(efl2->heap_addr)) HGOTO_DONE(1); if((cmp_value = H5F_addr_cmp(efl1->heap_addr, efl2->heap_addr)) != 0) HGOTO_DONE(cmp_value); } /* end if */ /* Check the number of allocated efl entries */ if(efl1->nalloc < efl2->nalloc) HGOTO_DONE(-1); if(efl1->nalloc > efl2->nalloc) HGOTO_DONE(1); /* Check the number of used efl entries */ if(efl1->nused < efl2->nused) HGOTO_DONE(-1); if(efl1->nused > efl2->nused) HGOTO_DONE(1); /* Check the efl entry information */ if(efl1->slot == NULL && efl2->slot != NULL) HGOTO_DONE(-1); if(efl1->slot != NULL && efl2->slot == NULL) HGOTO_DONE(1); if(efl1->slot != NULL && efl1->nused > 0) { size_t u; /* Local index variable */ /* Loop through all entries, comparing them */ for(u = 0; u < efl1->nused; u++) { /* Check the name offset of the efl entry */ if(efl1->slot[u].name_offset < efl2->slot[u].name_offset) HGOTO_DONE(-1); if(efl1->slot[u].name_offset > efl2->slot[u].name_offset) HGOTO_DONE(1); /* Check the name of the efl entry */ if(efl1->slot[u].name == NULL && efl2->slot[u].name != NULL) HGOTO_DONE(-1); if(efl1->slot[u].name != NULL && efl2->slot[u].name == NULL) HGOTO_DONE(1); if(efl1->slot[u].name != NULL) if((cmp_value = HDstrcmp(efl1->slot[u].name, efl2->slot[u].name)) != 0) HGOTO_DONE(cmp_value); /* Check the file offset of the efl entry */ if(efl1->slot[u].offset < efl2->slot[u].offset) HGOTO_DONE(-1); if(efl1->slot[u].offset > efl2->slot[u].offset) HGOTO_DONE(1); /* Check the file size of the efl entry */ if(efl1->slot[u].size < efl2->slot[u].size) HGOTO_DONE(-1); if(efl1->slot[u].size > efl2->slot[u].size) HGOTO_DONE(1); } /* end for */ } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__dcrt_ext_file_list_cmp() */ /*------------------------------------------------------------------------- * Function: H5P__set_layout * * Purpose: Sets the layout of raw data in the file. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Tuesday, November 23, 2004 * *------------------------------------------------------------------------- */ static herr_t H5P__set_layout(H5P_genplist_t *plist, const H5O_layout_t *layout) { unsigned alloc_time_state; /* State of allocation time property */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_STATIC /* Get the allocation time state */ if(H5P_get(plist, H5D_CRT_ALLOC_TIME_STATE_NAME, &alloc_time_state) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get space allocation time state") /* If we still have the "default" allocation time, change it according to the new layout */ if(alloc_time_state) { H5O_fill_t fill; /* Fill value */ /* Get current fill value info */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Set the default based on layout */ switch(layout->type) { case H5D_COMPACT: fill.alloc_time = H5D_ALLOC_TIME_EARLY; break; case H5D_CONTIGUOUS: fill.alloc_time = H5D_ALLOC_TIME_LATE; break; case H5D_CHUNKED: fill.alloc_time = H5D_ALLOC_TIME_INCR; break; case H5D_LAYOUT_ERROR: case H5D_NLAYOUTS: default: HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown layout type") } /* end switch */ /* Set updated fill value info */ if(H5P_set(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set space allocation time") } /* end if */ /* Set layout value */ if(H5P_set(plist, H5D_CRT_LAYOUT_NAME, layout) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "can't set layout") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__set_layout() */ #ifndef H5_HAVE_C99_DESIGNATED_INITIALIZER /*------------------------------------------------------------------------- * Function: H5P__init_def_layout * * Purpose: Set the default layout information for the various types of * dataset layouts * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Tuesday, January 13, 2009 * *------------------------------------------------------------------------- */ static herr_t H5P__init_def_layout(void) { const H5O_layout_chunk_t def_layout_chunk = H5D_DEF_LAYOUT_CHUNK_INIT; const H5O_storage_compact_t def_store_compact = H5D_DEF_STORAGE_COMPACT_INIT; const H5O_storage_chunk_t def_store_chunk = H5D_DEF_STORAGE_CHUNK_INIT; FUNC_ENTER_STATIC_NOERR /* Initialize the default layout info for non-contigous layouts */ H5D_def_layout_compact_g.storage.u.compact = def_store_compact; H5D_def_layout_chunk_g.u.chunk = def_layout_chunk; H5D_def_layout_chunk_g.storage.u.chunk = def_store_chunk; /* Note that we've initialized the default values */ H5P_dcrt_def_layout_init_g = TRUE; FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__init_def_layout() */ #endif /* H5_HAVE_C99_DESIGNATED_INITIALIZER */ /*------------------------------------------------------------------------- * Function: H5Pset_layout * * Purpose: Sets the layout of raw data in the file. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Tuesday, January 6, 1998 * * Modifications: * * Raymond Lu * Tuesday, October 2, 2001 * Changed the way to check parameter and set property for * generic property list. * *------------------------------------------------------------------------- */ herr_t H5Pset_layout(hid_t plist_id, H5D_layout_t layout_type) { H5P_genplist_t *plist; /* Property list pointer */ const H5O_layout_t *layout; /* Pointer to default layout information for type specified */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "iDl", plist_id, layout_type); /* Check arguments */ if(layout_type < 0 || layout_type >= H5D_NLAYOUTS) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "raw data layout method is not valid") /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") #ifndef H5_HAVE_C99_DESIGNATED_INITIALIZER /* If the compiler doesn't support C99 designated initializers, check if * the default layout structs have been initialized yet or not. *ick* -QAK */ if(!H5P_dcrt_def_layout_init_g) if(H5P__init_def_layout() < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "can't initialize default layout info") #endif /* H5_HAVE_C99_DESIGNATED_INITIALIZER */ /* Get pointer to correct default layout */ switch(layout_type) { case H5D_COMPACT: layout = &H5D_def_layout_compact_g; break; case H5D_CONTIGUOUS: layout = &H5D_def_layout_contig_g; break; case H5D_CHUNKED: layout = &H5D_def_layout_chunk_g; break; case H5D_LAYOUT_ERROR: case H5D_NLAYOUTS: default: HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown layout type") } /* end switch */ /* Set value */ if(H5P__set_layout(plist, layout) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "can't set layout") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_layout() */ /*------------------------------------------------------------------------- * Function: H5Pget_layout * * Purpose: Retrieves layout type of a dataset creation property list. * * Return: Success: The layout type * * Failure: H5D_LAYOUT_ERROR (negative) * * Programmer: Robb Matzke * Wednesday, January 7, 1998 * * Modifications: * * Raymond Lu * Tuesday, October 2, 2001 * Changed the way to check parameter and get property for * generic property list. * *------------------------------------------------------------------------- */ H5D_layout_t H5Pget_layout(hid_t plist_id) { H5P_genplist_t *plist; /* Property list pointer */ H5O_layout_t layout; /* Layout property */ H5D_layout_t ret_value; /* Return value */ FUNC_ENTER_API(H5D_LAYOUT_ERROR) H5TRACE1("Dl", "i", plist_id); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5D_LAYOUT_ERROR, "can't find object for ID") /* Get layout property */ if(H5P_get(plist, H5D_CRT_LAYOUT_NAME, &layout) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5D_LAYOUT_ERROR, "can't get layout") /* Set return value */ ret_value = layout.type; done: FUNC_LEAVE_API(ret_value) } /* ed H5Pget_layout() */ /*------------------------------------------------------------------------- * Function: H5Pset_chunk * * Purpose: Sets the number of dimensions and the size of each chunk to * the values specified. The dimensionality of the chunk should * match the dimensionality of the dataspace. * * As a side effect, the layout method is changed to * H5D_CHUNKED. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Tuesday, January 6, 1998 * * Modifications: * * Raymond Lu * Tuesday, October 2, 2001 * Changed the way to check parameter and set property for * generic property list. * *------------------------------------------------------------------------- */ herr_t H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[/*ndims*/]) { H5P_genplist_t *plist; /* Property list pointer */ H5O_layout_t chunk_layout; /* Layout information for setting chunk info */ uint64_t chunk_nelmts; /* Number of elements in chunk */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "iIs*[a1]h", plist_id, ndims, dim); /* Check arguments */ if(ndims <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "chunk dimensionality must be positive") if(ndims > H5S_MAX_RANK) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "chunk dimensionality is too large") if(!dim) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no chunk dimensions specified") #ifndef H5_HAVE_C99_DESIGNATED_INITIALIZER /* If the compiler doesn't support C99 designated initializers, check if * the default layout structs have been initialized yet or not. *ick* -QAK */ if(!H5P_dcrt_def_layout_init_g) if(H5P__init_def_layout() < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "can't initialize default layout info") #endif /* H5_HAVE_C99_DESIGNATED_INITIALIZER */ /* Verify & initialize property's chunk dims */ HDmemcpy(&chunk_layout, &H5D_def_layout_chunk_g, sizeof(H5D_def_layout_chunk_g)); HDmemset(&chunk_layout.u.chunk.dim, 0, sizeof(chunk_layout.u.chunk.dim)); chunk_nelmts = 1; for(u = 0; u < (unsigned)ndims; u++) { if(dim[u] == 0) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "all chunk dimensions must be positive") if(dim[u] != (dim[u] & 0xffffffff)) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "all chunk dimensions must be less than 2^32") chunk_nelmts *= dim[u]; if(chunk_nelmts > (uint64_t)0xffffffff) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "number of elements in chunk must be < 4GB") chunk_layout.u.chunk.dim[u] = (uint32_t)dim[u]; /* Store user's chunk dimensions */ } /* end for */ /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Set chunk information in property list */ chunk_layout.u.chunk.ndims = (unsigned)ndims; if(H5P__set_layout(plist, &chunk_layout) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set layout") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_chunk() */ /*------------------------------------------------------------------------- * Function: H5Pget_chunk * * Purpose: Retrieves the chunk size of chunked layout. The chunk * dimensionality is returned and the chunk size in each * dimension is returned through the DIM argument. At most * MAX_NDIMS elements of DIM will be initialized. * * Return: Success: Positive Chunk dimensionality. * * Failure: Negative * * Programmer: Robb Matzke * Wednesday, January 7, 1998 * * Modifications: * * Raymond Lu * Tuesday, October 2, 2001 * Changed the way to check parameter and set property for * generic property list. * *------------------------------------------------------------------------- */ int H5Pget_chunk(hid_t plist_id, int max_ndims, hsize_t dim[]/*out*/) { H5P_genplist_t *plist; /* Property list pointer */ H5O_layout_t layout; /* Layout information */ int ret_value; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("Is", "iIsx", plist_id, max_ndims, dim); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Retrieve the layout property */ if(H5P_get(plist, H5D_CRT_LAYOUT_NAME, &layout) < 0) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't get layout") if(H5D_CHUNKED != layout.type) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a chunked storage layout") if(dim) { unsigned u; /* Local index variable */ /* Get the dimension sizes */ for(u = 0; u < layout.u.chunk.ndims && u < (unsigned)max_ndims; u++) dim[u] = layout.u.chunk.dim[u]; } /* end if */ /* Set the return value */ ret_value = (int)layout.u.chunk.ndims; done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_chunk() */ /*------------------------------------------------------------------------- * Function: H5Pset_external * * Purpose: Adds an external file to the list of external files. PLIST_ID * should be an object ID for a dataset creation property list. * NAME is the name of an external file, OFFSET is the location * where the data starts in that file, and SIZE is the number of * bytes reserved in the file for the data. * * If a dataset is split across multiple files then the files * should be defined in order. The total size of the dataset is * the sum of the SIZE arguments for all the external files. If * the total size is larger than the size of a dataset then the * dataset can be extended (provided the dataspace also allows * the extending). * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Tuesday, March 3, 1998 * *------------------------------------------------------------------------- */ herr_t H5Pset_external(hid_t plist_id, const char *name, off_t offset, hsize_t size) { size_t idx; hsize_t total, tmp; H5O_efl_t efl; H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE4("e", "i*soh", plist_id, name, offset, size); /* Check arguments */ if(!name || !*name) HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") if(offset < 0) HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "negative external file offset") /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") if(H5P_get(plist, H5D_CRT_EXT_FILE_LIST_NAME, &efl) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external file list") if(efl.nused > 0 && H5O_EFL_UNLIMITED == efl.slot[efl.nused - 1].size) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "previous file size is unlimited") if(H5O_EFL_UNLIMITED != size) { for(idx = 0, total = size; idx < efl.nused; idx++, total = tmp) { tmp = total + efl.slot[idx].size; if(tmp <= total) HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "total external data size overflowed") } /* end for */ } /* end if */ /* Add to the list */ if(efl.nused >= efl.nalloc) { size_t na = efl.nalloc + H5O_EFL_ALLOC; H5O_efl_entry_t *x = (H5O_efl_entry_t *)H5MM_realloc(efl.slot, na * sizeof(H5O_efl_entry_t)); if(!x) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "memory allocation failed") efl.nalloc = na; efl.slot = x; } /* end if */ idx = efl.nused; efl.slot[idx].name_offset = 0; /*not entered into heap yet*/ efl.slot[idx].name = H5MM_xstrdup(name); efl.slot[idx].offset = offset; efl.slot[idx].size = size; efl.nused++; if(H5P_set(plist, H5D_CRT_EXT_FILE_LIST_NAME, &efl) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set external file list") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_external() */ /*------------------------------------------------------------------------- * Function: H5Pget_external_count * * Purpose: Returns the number of external files for this dataset. * * Return: Success: Number of external files * * Failure: Negative * * Programmer: Robb Matzke * Tuesday, March 3, 1998 * * Modifications: * * Raymond Lu * Tuesday, October 2, 2001 * Changed the way to check parameter and set property for * generic property list. * *------------------------------------------------------------------------- */ int H5Pget_external_count(hid_t plist_id) { H5O_efl_t efl; H5P_genplist_t *plist; /* Property list pointer */ int ret_value; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE1("Is", "i", plist_id); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get value */ if(H5P_get(plist, H5D_CRT_EXT_FILE_LIST_NAME, &efl) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external file list") /* Set return value */ ret_value = (int)efl.nused; done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_external_count() */ /*------------------------------------------------------------------------- * Function: H5Pget_external * * Purpose: Returns information about an external file. External files * are numbered from zero to N-1 where N is the value returned * by H5Pget_external_count(). At most NAME_SIZE characters are * copied into the NAME array. If the external file name is * longer than NAME_SIZE with the null terminator, then the * return value is not null terminated (similar to strncpy()). * * If NAME_SIZE is zero or NAME is the null pointer then the * external file name is not returned. If OFFSET or SIZE are * null pointers then the corresponding information is not * returned. * * See Also: H5Pset_external() * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Tuesday, March 3, 1998 * * Modifications: * * Raymond Lu * Tuesday, October 2, 2001 * Changed the way to check parameter and get property for * generic property list. * *------------------------------------------------------------------------- */ herr_t H5Pget_external(hid_t plist_id, unsigned idx, size_t name_size, char *name/*out*/, off_t *offset/*out*/, hsize_t *size/*out*/) { H5O_efl_t efl; H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE6("e", "iIuzxxx", plist_id, idx, name_size, name, offset, size); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get value */ if(H5P_get(plist, H5D_CRT_EXT_FILE_LIST_NAME, &efl) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external file list") if(idx >= efl.nused) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "external file index is out of range") /* Return values */ if(name_size>0 && name) HDstrncpy(name, efl.slot[idx].name, name_size); if(offset) *offset = efl.slot[idx].offset; if(size) *size = efl.slot[idx].size; done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_external() */ /*------------------------------------------------------------------------- * Function: H5Pset_szip * * Purpose: Sets the compression method for a permanent or transient * filter pipeline (depending on whether PLIST_ID is a dataset * creation or transfer property list) to H5Z_FILTER_SZIP * Szip is a special compression package that is said to be good * for scientific data. * * Return: Non-negative on success/Negative on failure * * Programmer: Kent Yang * Tuesday, April 1, 2003 * *------------------------------------------------------------------------- */ herr_t H5Pset_szip(hid_t plist_id, unsigned options_mask, unsigned pixels_per_block) { H5O_pline_t pline; H5P_genplist_t *plist; /* Property list pointer */ unsigned cd_values[2]; /* Filter parameters */ unsigned int config_flags; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "iIuIu", plist_id, options_mask, pixels_per_block); if(H5Z_get_filter_info(H5Z_FILTER_SZIP, &config_flags) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't get filter info") if(!(config_flags & H5Z_FILTER_CONFIG_ENCODE_ENABLED)) HGOTO_ERROR(H5E_PLINE, H5E_NOENCODER, FAIL, "Filter present but encoding is disabled.") /* Check arguments */ if((pixels_per_block % 2) == 1) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "pixels_per_block is not even") if(pixels_per_block > H5_SZIP_MAX_PIXELS_PER_BLOCK) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "pixels_per_block is too large") /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Always set K13 compression (and un-set CHIP compression) */ options_mask &= (unsigned)(~H5_SZIP_CHIP_OPTION_MASK); options_mask |= H5_SZIP_ALLOW_K13_OPTION_MASK; /* Always set "raw" (no szip header) flag for data */ options_mask |= H5_SZIP_RAW_OPTION_MASK; /* Mask off the LSB and MSB options, if they were given */ /* (The HDF5 library sets them internally, as needed) */ options_mask &= (unsigned)(~(H5_SZIP_LSB_OPTION_MASK | H5_SZIP_MSB_OPTION_MASK)); /* Set the parameters for the filter */ cd_values[0]=options_mask; cd_values[1]=pixels_per_block; /* Add the filter */ if(H5P_get(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline") if(H5Z_append(&pline, H5Z_FILTER_SZIP, H5Z_FLAG_OPTIONAL, (size_t)2, cd_values) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to add szip filter to pipeline") if(H5P_set(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to set pipeline") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_szip() */ /*------------------------------------------------------------------------- * Function: H5Pset_shuffle * * Purpose: Sets the shuffling method for a permanent * filter to H5Z_FILTER_SHUFFLE * and bytes of the datatype of the array to be shuffled * * Return: Non-negative on success/Negative on failure * * Programmer: Kent Yang * Wednesday, November 13, 2002 * * Modifications: * *------------------------------------------------------------------------- */ herr_t H5Pset_shuffle(hid_t plist_id) { H5O_pline_t pline; H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value=SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE1("e", "i", plist_id); /* Check arguments */ if(TRUE != H5P_isa_class(plist_id, H5P_DATASET_CREATE)) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset creation property list") /* Get the plist structure */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(plist_id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Add the filter */ if(H5P_get(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline") if(H5Z_append(&pline, H5Z_FILTER_SHUFFLE, H5Z_FLAG_OPTIONAL, (size_t)0, NULL) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to shuffle the data") if(H5P_set(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to set pipeline") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_shuffle() */ /*------------------------------------------------------------------------- * Function: H5Pset_nbit * * Purpose: Sets nbit filter for a dataset creation property list * * Return: Non-negative on success/Negative on failure * * Programmer: Xiaowen Wu * Wednesday, December 22, 2004 * * Modifications: * * *------------------------------------------------------------------------- */ herr_t H5Pset_nbit(hid_t plist_id) { H5O_pline_t pline; H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value=SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE1("e", "i", plist_id); /* Check arguments */ if(TRUE != H5P_isa_class(plist_id, H5P_DATASET_CREATE)) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset creation property list") /* Get the plist structure */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(plist_id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Add the nbit filter */ if(H5P_get(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline") if(H5Z_append(&pline, H5Z_FILTER_NBIT, H5Z_FLAG_OPTIONAL, (size_t)0, NULL) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to add nbit filter to pipeline") if(H5P_set(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to set pipeline") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_nbit() */ /*------------------------------------------------------------------------- * Function: H5Pset_scaleoffset * * Purpose: Sets scaleoffset filter for a dataset creation property list * and user-supplied parameters * * Parameters: scale_factor: for integer datatype, this parameter will be minimum-bits, if this value is set to 0, scaleoffset filter will calculate the minimum-bits. For floating-point datatype, For variable-minimum-bits method, this will be the decimal precision of the filter, For fixed-minimum-bits method, this will be the minimum-bit of the filter. scale_type: 0 for floating-point variable-minimum-bits, 1 for floating-point fixed-minimum-bits, other values, for integer datatype * Return: Non-negative on success/Negative on failure * * Programmer: Xiaowen Wu * Thursday, April 14, 2005 * * Modifications: * * *------------------------------------------------------------------------- */ herr_t H5Pset_scaleoffset(hid_t plist_id, H5Z_SO_scale_type_t scale_type, int scale_factor) { H5O_pline_t pline; H5P_genplist_t *plist; /* Property list pointer */ unsigned cd_values[2]; /* Filter parameters */ herr_t ret_value=SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "iZaIs", plist_id, scale_type, scale_factor); /* Check arguments */ if(TRUE != H5P_isa_class(plist_id, H5P_DATASET_CREATE)) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset creation property list") if(scale_factor < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "scale factor must be >= 0") if(scale_type!=H5Z_SO_FLOAT_DSCALE && scale_type!=H5Z_SO_FLOAT_ESCALE && scale_type!=H5Z_SO_INT) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid scale type") /* Get the plist structure */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(plist_id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Set parameters for the filter * scale_type = 0: floating-point type, filter uses variable-minimum-bits method, * scale_factor is decimal scale factor * scale_type = 1: floating-point type, filter uses fixed-minimum-bits method, * scale_factor is the fixed minimum number of bits * scale type = other: integer type, scale_factor is minimum number of bits * if scale_factor = 0, then filter calculates minimum number of bits */ cd_values[0] = scale_type; cd_values[1] = (unsigned)scale_factor; /* Add the scaleoffset filter */ if(H5P_get(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline") if(H5Z_append(&pline, H5Z_FILTER_SCALEOFFSET, H5Z_FLAG_OPTIONAL, (size_t)2, cd_values) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to add scaleoffset filter to pipeline") if(H5P_set(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to set pipeline") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_scaleoffset() */ /*------------------------------------------------------------------------- * Function: H5Pset_fill_value * * Purpose: Set the fill value for a dataset creation property list. The * VALUE is interpreted as being of type TYPE, which need not * be the same type as the dataset but the library must be able * to convert VALUE to the dataset type when the dataset is * created. If VALUE is NULL, it will be interpreted as * undefining fill value. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Thursday, October 1, 1998 * *------------------------------------------------------------------------- */ herr_t H5Pset_fill_value(hid_t plist_id, hid_t type_id, const void *value) { H5P_genplist_t *plist; /* Property list pointer */ H5O_fill_t fill; /* Fill value to modify */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "ii*x", plist_id, type_id, value); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get the current fill value */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Release the dynamic fill value components */ H5O_fill_reset_dyn(&fill); if(value) { H5T_t *type; /* Datatype for fill value */ H5T_path_t *tpath; /* Conversion information */ /* Retrieve pointer to datatype */ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Set the fill value */ if(NULL == (fill.type = H5T_copy(type, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy datatype") fill.size = (ssize_t)H5T_get_size(type); if(NULL == (fill.buf = H5MM_malloc((size_t)fill.size))) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "memory allocation failed for fill value") HDmemcpy(fill.buf, value, (size_t)fill.size); /* Set up type conversion function */ if(NULL == (tpath = H5T_path_find(type, type, NULL, NULL, H5AC_ind_dxpl_id, FALSE))) HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types") /* If necessary, convert fill value datatypes (which copies VL components, etc.) */ if(!H5T_path_noop(tpath)) { uint8_t *bkg_buf = NULL; /* Background conversion buffer */ /* Allocate a background buffer */ if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (size_t)fill.size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Convert the fill value */ if(H5T_convert(tpath, type_id, type_id, (size_t)1, (size_t)0, (size_t)0, fill.buf, bkg_buf, H5AC_ind_dxpl_id) < 0) { if(bkg_buf) bkg_buf = H5FL_BLK_FREE(type_conv, bkg_buf); HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "datatype conversion failed") } /* end if */ /* Release the background buffer */ if(bkg_buf) bkg_buf = H5FL_BLK_FREE(type_conv, bkg_buf); } /* end if */ } /* end if */ else fill.size = (-1); /* Update fill value in property list */ if(H5P_set(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set fill value") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_fill_value() */ /*------------------------------------------------------------------------- * Function: H5P_get_fill_value * * Purpose: Queries the fill value property of a dataset creation * property list. The fill value is returned through the VALUE * pointer and the memory is allocated by the caller. The fill * value will be converted from its current datatype to the * specified TYPE. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Wednesday, October 17, 2007 * *------------------------------------------------------------------------- */ herr_t H5P_get_fill_value(H5P_genplist_t *plist, const H5T_t *type, void *value/*out*/, hid_t dxpl_id) { H5O_fill_t fill; /* Fill value to retrieve */ H5T_path_t *tpath; /*type conversion info */ void *buf = NULL; /*conversion buffer */ void *bkg = NULL; /*conversion buffer */ hid_t src_id = -1; /*source datatype id */ hid_t dst_id = -1; /*destination datatype id */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* * If no fill value is defined then return an error. We can't even * return zero because we don't know the datatype of the dataset and * datatype conversion might not have resulted in zero. If fill value * is undefined, also return error. */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") if(fill.size == -1) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "fill value is undefined") /* Check for "default" fill value */ if(fill.size == 0) { HDmemset(value, 0, H5T_get_size(type)); HGOTO_DONE(SUCCEED); } /* end if */ /* * Can we convert between the source and destination datatypes? */ if(NULL == (tpath = H5T_path_find(fill.type, type, NULL, NULL, dxpl_id, FALSE))) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "unable to convert between src and dst datatypes") if((src_id = H5I_register(H5I_DATATYPE, H5T_copy(fill.type, H5T_COPY_TRANSIENT), FALSE)) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "unable to copy/register datatype") /* * Data type conversions are always done in place, so we need a buffer * other than the fill value buffer that is large enough for both source * and destination. The app-supplied buffer might do okay. */ if(H5T_get_size(type) >= H5T_get_size(fill.type)) { buf = value; if(H5T_path_bkg(tpath) && NULL == (bkg = H5MM_malloc(H5T_get_size(type)))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for type conversion") } /* end if */ else { if(NULL == (buf = H5MM_malloc(H5T_get_size(fill.type)))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for type conversion") if(H5T_path_bkg(tpath) && NULL == (bkg = H5MM_malloc(H5T_get_size(fill.type)))) HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL, "memory allocation failed for type conversion") } /* end else */ HDmemcpy(buf, fill.buf, H5T_get_size(fill.type)); /* Do the conversion */ if((dst_id = H5I_register(H5I_DATATYPE, H5T_copy(type, H5T_COPY_TRANSIENT), FALSE)) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "unable to copy/register datatype") if(H5T_convert(tpath, src_id, dst_id, (size_t)1, (size_t)0, (size_t)0, buf, bkg, dxpl_id) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "datatype conversion failed") if(buf != value) HDmemcpy(value, buf, H5T_get_size(type)); done: if(buf != value) H5MM_xfree(buf); if(bkg != value) H5MM_xfree(bkg); if(src_id >= 0 && H5I_dec_ref(src_id) < 0) HDONE_ERROR(H5E_PLIST, H5E_CANTDEC, FAIL, "can't decrement ref count of temp ID") if(dst_id >= 0 && H5I_dec_ref(dst_id) < 0) HDONE_ERROR(H5E_PLIST, H5E_CANTDEC, FAIL, "can't decrement ref count of temp ID") FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_get_fill_value() */ /*------------------------------------------------------------------------- * Function: H5Pget_fill_value * * Purpose: Queries the fill value property of a dataset creation * property list. The fill value is returned through the VALUE * pointer and the memory is allocated by the caller. The fill * value will be converted from its current datatype to the * specified TYPE. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Thursday, October 1, 1998 * *------------------------------------------------------------------------- */ herr_t H5Pget_fill_value(hid_t plist_id, hid_t type_id, void *value/*out*/) { H5P_genplist_t *plist; /* Property list pointer */ H5T_t *type; /* Datatype */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "iix", plist_id, type_id, value); /* Check arguments */ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") if(!value) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,"no fill value output buffer") /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get the fill value */ if(H5P_get_fill_value(plist, type, value, H5AC_ind_dxpl_id) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_fill_value() */ /*------------------------------------------------------------------------- * Function: H5P_is_fill_value_defined * * Purpose: Check if fill value is defined. Internal version of function * * Return: Non-negative on success/Negative on failure * * Programmer: Raymond Lu * Wednesday, January 16, 2002 * *------------------------------------------------------------------------- */ herr_t H5P_is_fill_value_defined(const H5O_fill_t *fill, H5D_fill_value_t *status) { herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) HDassert(fill); HDassert(status); /* Check if the fill value was "unset" */ if(fill->size == -1 && !fill->buf) *status = H5D_FILL_VALUE_UNDEFINED; /* Check if the fill value was set to the default fill value by the library */ else if(fill->size == 0 && !fill->buf) *status = H5D_FILL_VALUE_DEFAULT; /* Check if the fill value was set by the application */ else if(fill->size > 0 && fill->buf) *status = H5D_FILL_VALUE_USER_DEFINED; else { *status = H5D_FILL_VALUE_ERROR; HGOTO_ERROR(H5E_PLIST, H5E_BADRANGE, FAIL, "invalid combination of fill-value info") } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_is_fill_value_defined() */ /*------------------------------------------------------------------------- * Function: H5P_fill_value_defined * * Purpose: Check if fill value is defined. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Wednesday, October 17, 2007 * *------------------------------------------------------------------------- */ herr_t H5P_fill_value_defined(H5P_genplist_t *plist, H5D_fill_value_t *status) { H5O_fill_t fill; /* Fill value to query */ herr_t ret_value = SUCCEED; FUNC_ENTER_NOAPI(FAIL) HDassert(status); /* Get the fill value struct */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Get the fill-value status */ if(H5P_is_fill_value_defined(&fill, status) < 0) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't check fill value status") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_fill_value_defined() */ /*------------------------------------------------------------------------- * Function: H5Pfill_value_defined * * Purpose: Check if fill value is defined. * * Return: Non-negative on success/Negative on failure * * Programmer: Raymond Lu * Wednesday, January 16, 2002 * *------------------------------------------------------------------------- */ herr_t H5Pfill_value_defined(hid_t plist_id, H5D_fill_value_t *status) { H5P_genplist_t *plist; /* Property list to query */ herr_t ret_value = SUCCEED; FUNC_ENTER_API(FAIL) H5TRACE2("e", "i*DF", plist_id, status); HDassert(status); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Get the fill-value status */ if(H5P_fill_value_defined(plist, status) < 0) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't check fill value status") done: FUNC_LEAVE_API(ret_value) } /* end H5Pfill_value_defined() */ /*------------------------------------------------------------------------- * Function: H5Pset_alloc_time * * Purpose: Set space allocation time for dataset during creation. * Valid values are H5D_ALLOC_TIME_DEFAULT, H5D_ALLOC_TIME_EARLY, * H5D_ALLOC_TIME_LATE, H5D_ALLOC_TIME_INCR * * Return: Non-negative on success/Negative on failure * * Programmer: Raymond Lu * Wednesday, January 16, 2002 * * Modifications: * * *------------------------------------------------------------------------- */ herr_t H5Pset_alloc_time(hid_t plist_id, H5D_alloc_time_t alloc_time) { H5P_genplist_t *plist; /* Property list pointer */ H5O_fill_t fill; /* Fill value property to modify */ unsigned alloc_time_state; /* State of allocation time property */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "iDa", plist_id, alloc_time); /* Check arguments */ if(alloc_time < H5D_ALLOC_TIME_DEFAULT || alloc_time > H5D_ALLOC_TIME_INCR) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid allocation time setting") /* Get the property list structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Check for resetting to default for layout type */ if(alloc_time == H5D_ALLOC_TIME_DEFAULT) { H5O_layout_t layout; /* Type of storage layout */ /* Retrieve the storage layout */ if(H5P_get(plist, H5D_CRT_LAYOUT_NAME, &layout) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get layout") /* Set the default based on layout */ switch(layout.type) { case H5D_COMPACT: alloc_time = H5D_ALLOC_TIME_EARLY; break; case H5D_CONTIGUOUS: alloc_time = H5D_ALLOC_TIME_LATE; break; case H5D_CHUNKED: alloc_time = H5D_ALLOC_TIME_INCR; break; case H5D_LAYOUT_ERROR: case H5D_NLAYOUTS: default: HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown layout type") } /* end switch */ /* Reset the "state" of the allocation time property back to the "default" */ alloc_time_state = 1; } /* end if */ else /* Set the "state" of the allocation time property to indicate the user modified it */ alloc_time_state = 0; /* Retrieve previous fill value settings */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Update property value */ fill.alloc_time = alloc_time; /* Set values */ if(H5P_set(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set fill value") if(H5P_set(plist, H5D_CRT_ALLOC_TIME_STATE_NAME, &alloc_time_state) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set space allocation time") done: FUNC_LEAVE_API(ret_value) } /* H5Pset_alloc_time() */ /*------------------------------------------------------------------------- * Function: H5Pget_alloc_time * * Purpose: Get space allocation time for dataset creation. * Valid values are H5D_ALLOC_TIME_DEFAULT, H5D_ALLOC_TIME_EARLY, * H5D_ALLOC_TIME_LATE, H5D_ALLOC_TIME_INCR * * Return: Non-negative on success/Negative on failure * * Programmer: Raymond Lu * Wednesday, January 16, 2002 * *------------------------------------------------------------------------- */ herr_t H5Pget_alloc_time(hid_t plist_id, H5D_alloc_time_t *alloc_time/*out*/) { herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "ix", plist_id, alloc_time); /* Get values */ if(alloc_time) { H5P_genplist_t *plist; /* Property list pointer */ H5O_fill_t fill; /* Fill value property to query */ /* Get the property list structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Retrieve fill value settings */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Set user's value */ *alloc_time = fill.alloc_time; } /* end if */ done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_alloc_time() */ /*------------------------------------------------------------------------- * Function: H5Pset_fill_time * * Purpose: Set fill value writing time for dataset. Valid values are * H5D_FILL_TIME_ALLOC and H5D_FILL_TIME_NEVER. * * Return: Non-negative on success/Negative on failure * * Programmer: Raymond Lu * Wednesday, January 16, 2002 * *------------------------------------------------------------------------- */ herr_t H5Pset_fill_time(hid_t plist_id, H5D_fill_time_t fill_time) { H5P_genplist_t *plist; /* Property list pointer */ H5O_fill_t fill; /* Fill value property to modify */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "iDf", plist_id, fill_time); /* Check arguments */ if(fill_time < H5D_FILL_TIME_ALLOC || fill_time > H5D_FILL_TIME_IFSET) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid fill time setting") /* Get the property list structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Retrieve previous fill value settings */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Update property value */ fill.fill_time = fill_time; /* Set values */ if(H5P_set(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set fill value") done: FUNC_LEAVE_API(ret_value) } /* end H5Pset_fill_time() */ /*------------------------------------------------------------------------- * Function: H5Pget_fill_time * * Purpose: Get fill value writing time. Valid values are H5D_NEVER * and H5D_ALLOC. * * Return: Non-negative on success/Negative on failure * * Programmer: Raymond Lu * Wednesday, January 16, 2002 * * Modifications: * * *------------------------------------------------------------------------- */ herr_t H5Pget_fill_time(hid_t plist_id, H5D_fill_time_t *fill_time/*out*/) { herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "ix", plist_id, fill_time); /* Set values */ if(fill_time) { H5P_genplist_t *plist; /* Property list pointer */ H5O_fill_t fill; /* Fill value property to query */ /* Get the property list structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") /* Retrieve fill value settings */ if(H5P_get(plist, H5D_CRT_FILL_VALUE_NAME, &fill) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get fill value") /* Set user's value */ *fill_time = fill.fill_time; } /* end if */ done: FUNC_LEAVE_API(ret_value) } /* end H5Pget_fill_time() */