1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /* Programmer: Quincey Koziol <koziol@hdfgroup.org>
15 * Monday, March 6, 2006
16 *
17 * Purpose: v2 B-tree metadata statistics functions.
18 *
19 */
20
21 /****************/
22 /* Module Setup */
23 /****************/
24
25 #include "H5B2module.h" /* This source code file is part of the H5B2 module */
26
27
28 /***********/
29 /* Headers */
30 /***********/
31 #include "H5private.h" /* Generic Functions */
32 #include "H5B2pkg.h" /* v2 B-trees */
33 #include "H5Eprivate.h" /* Error handling */
34
35
36 /****************/
37 /* Local Macros */
38 /****************/
39
40
41 /******************/
42 /* Local Typedefs */
43 /******************/
44
45
46 /********************/
47 /* Package Typedefs */
48 /********************/
49
50
51 /********************/
52 /* Local Prototypes */
53 /********************/
54
55
56 /*********************/
57 /* Package Variables */
58 /*********************/
59
60
61 /*****************************/
62 /* Library Private Variables */
63 /*****************************/
64
65
66 /*******************/
67 /* Local Variables */
68 /*******************/
69
70
71 /*-------------------------------------------------------------------------
72 * Function: H5B2_stat_info
73 *
74 * Purpose: Retrieve metadata statistics for a v2 B-tree
75 *
76 * Return: SUCCEED (Can't fail)
77 *
78 * Programmer: Quincey Koziol
79 * Monday, March 6, 2006
80 *
81 *-------------------------------------------------------------------------
82 */
83 herr_t
H5B2_stat_info(H5B2_t * bt2,H5B2_stat_t * info)84 H5B2_stat_info(H5B2_t *bt2, H5B2_stat_t *info)
85 {
86 FUNC_ENTER_NOAPI_NOINIT_NOERR
87
88 /* Check arguments. */
89 HDassert(info);
90
91 /* Get information about the B-tree */
92 info->depth = bt2->hdr->depth;
93 info->nrecords = bt2->hdr->root.all_nrec;
94
95 FUNC_LEAVE_NOAPI(SUCCEED)
96 } /* H5B2_stat_info() */
97
98
99 /*-------------------------------------------------------------------------
100 * Function: H5B2_size
101 *
102 * Purpose: Iterate over all the records in the B-tree, collecting
103 * storage info.
104 *
105 * Return: SUCCEED/FAIL
106 *
107 * Programmer: Vailin Choi
108 * June 19 2007
109 *
110 *-------------------------------------------------------------------------
111 */
112 herr_t
H5B2_size(H5B2_t * bt2,hsize_t * btree_size)113 H5B2_size(H5B2_t *bt2, hsize_t *btree_size)
114 {
115 H5B2_hdr_t *hdr; /* Pointer to the B-tree header */
116 herr_t ret_value = SUCCEED; /* Return value */
117
118 FUNC_ENTER_NOAPI(FAIL)
119
120 /* Check arguments. */
121 HDassert(bt2);
122 HDassert(btree_size);
123
124 /* Set the shared v2 B-tree header's file context for this operation */
125 bt2->hdr->f = bt2->f;
126
127 /* Get the v2 B-tree header */
128 hdr = bt2->hdr;
129
130 /* Add size of header to B-tree metadata total */
131 *btree_size += hdr->hdr_size;
132
133 /* Iterate through records */
134 if(hdr->root.node_nrec > 0) {
135 /* Check for root node being a leaf */
136 if(hdr->depth == 0)
137 *btree_size += hdr->node_size;
138 else
139 /* Iterate through nodes */
140 if(H5B2__node_size(hdr, hdr->depth, &hdr->root, hdr, btree_size) < 0)
141 HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "node iteration failed")
142 } /* end if */
143
144 done:
145 FUNC_LEAVE_NOAPI(ret_value)
146 } /* H5B2_size() */
147
148