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://www.hdfgroup.org/licenses. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /*-------------------------------------------------------------------------
15 *
16 * Created: H5Ftest.c
17 * Jan 3 2007
18 * Quincey Koziol
19 *
20 * Purpose: File testing routines.
21 *
22 *-------------------------------------------------------------------------
23 */
24
25 /****************/
26 /* Module Setup */
27 /****************/
28
29 #include "H5Fmodule.h" /* This source code file is part of the H5F module */
30 #define H5F_TESTING /* Suppress warning about H5F testing funcs */
31 #define H5G_FRIEND /* Suppress error about including H5Gpkg.h */
32 #define H5G_TESTING /* Suppress warning about H5G testing funcs */
33 #define H5SM_FRIEND /* Suppress error about including H5SMpkg.h */
34 #define H5SM_TESTING /* Suppress warning about H5SM testing funcs */
35
36 /***********/
37 /* Headers */
38 /***********/
39 #include "H5private.h" /* Generic Functions */
40 #include "H5CXprivate.h" /* API Contexts */
41 #include "H5Eprivate.h" /* Error handling */
42 #include "H5Fpkg.h" /* File access */
43 #include "H5Gpkg.h" /* Groups */
44 #include "H5Iprivate.h" /* IDs */
45 #include "H5SMpkg.h" /* Shared object header messages */
46 #include "H5VLprivate.h" /* Virtual Object Layer */
47
48 /****************/
49 /* Local Macros */
50 /****************/
51
52 /******************/
53 /* Local Typedefs */
54 /******************/
55
56 /********************/
57 /* Package Typedefs */
58 /********************/
59
60 /********************/
61 /* Local Prototypes */
62 /********************/
63
64 /*********************/
65 /* Package Variables */
66 /*********************/
67
68 /*****************************/
69 /* Library Private Variables */
70 /*****************************/
71
72 /*******************/
73 /* Local Variables */
74 /*******************/
75
76 /*-------------------------------------------------------------------------
77 * Function: H5F__get_sohm_mesg_count_test
78 *
79 * Purpose: Retrieve the number of shared messages of a given type in a file
80 *
81 * Return: SUCCEED/FAIL
82 *
83 * Programmer: Quincey Koziol
84 * Jan 3, 2007
85 *
86 *-------------------------------------------------------------------------
87 */
88 herr_t
H5F__get_sohm_mesg_count_test(hid_t file_id,unsigned type_id,size_t * mesg_count)89 H5F__get_sohm_mesg_count_test(hid_t file_id, unsigned type_id, size_t *mesg_count)
90 {
91 H5F_t * file; /* File info */
92 hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */
93 herr_t ret_value = SUCCEED; /* Return value */
94
95 FUNC_ENTER_PACKAGE
96
97 /* Check arguments */
98 if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
99 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
100
101 /* Push API context */
102 if (H5CX_push() < 0)
103 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set API context")
104 api_ctx_pushed = TRUE;
105
106 /* Retrieve count for message type */
107 if (H5SM__get_mesg_count_test(file, type_id, mesg_count) < 0)
108 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve shared message count")
109
110 done:
111 if (api_ctx_pushed && H5CX_pop() < 0)
112 HDONE_ERROR(H5E_FILE, H5E_CANTRESET, FAIL, "can't reset API context")
113
114 FUNC_LEAVE_NOAPI(ret_value)
115 } /* end H5F__get_sohm_mesg_count_test() */
116
117 /*-------------------------------------------------------------------------
118 * Function: H5F__check_cached_stab_test
119 *
120 * Purpose: Check that a file's superblock contains a cached symbol
121 * table entry, that the entry matches that in the root
122 * group's object header, and check that the addresses are
123 * valid.
124 *
125 * Return: SUCCEED/FAIL
126 *
127 * Programmer: Neil Fortner
128 * Mar 31, 2009
129 *
130 *-------------------------------------------------------------------------
131 */
132 herr_t
H5F__check_cached_stab_test(hid_t file_id)133 H5F__check_cached_stab_test(hid_t file_id)
134 {
135 H5F_t * file; /* File info */
136 hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */
137 herr_t ret_value = SUCCEED; /* Return value */
138
139 FUNC_ENTER_PACKAGE
140
141 /* Check arguments */
142 if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
143 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
144
145 /* Push API context */
146 if (H5CX_push() < 0)
147 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set API context")
148 api_ctx_pushed = TRUE;
149
150 /* Verify the cached stab info */
151 if (H5G__verify_cached_stab_test(H5G_oloc(file->shared->root_grp), file->shared->sblock->root_ent) < 0)
152 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to verify cached symbol table info")
153
154 done:
155 if (api_ctx_pushed && H5CX_pop() < 0)
156 HDONE_ERROR(H5E_FILE, H5E_CANTRESET, FAIL, "can't reset API context")
157
158 FUNC_LEAVE_NOAPI(ret_value)
159 } /* end H5F__check_cached_stab_test() */
160
161 /*-------------------------------------------------------------------------
162 * Function: H5F__get_maxaddr_test
163 *
164 * Purpose: Retrieve the maximum address for a file
165 *
166 * Return: SUCCEED/FAIL
167 *
168 * Programmer: Quincey Koziol
169 * Jun 10, 2009
170 *
171 *-------------------------------------------------------------------------
172 */
173 herr_t
H5F__get_maxaddr_test(hid_t file_id,haddr_t * maxaddr)174 H5F__get_maxaddr_test(hid_t file_id, haddr_t *maxaddr)
175 {
176 H5F_t *file; /* File info */
177 herr_t ret_value = SUCCEED; /* Return value */
178
179 FUNC_ENTER_PACKAGE
180
181 /* Check arguments */
182 if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
183 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
184
185 /* Retrieve maxaddr for file */
186 *maxaddr = file->shared->maxaddr;
187
188 done:
189 FUNC_LEAVE_NOAPI(ret_value)
190 } /* end H5F__get_maxaddr_test() */
191
192 /*-------------------------------------------------------------------------
193 * Function: H5F__get_sbe_addr_test
194 *
195 * Purpose: Retrieve the address of a superblock extension's object header
196 * for a file
197 *
198 * Return: SUCCEED/FAIL
199 *
200 * Programmer: Quincey Koziol
201 * Jul 10, 2016
202 *
203 *-------------------------------------------------------------------------
204 */
205 herr_t
H5F__get_sbe_addr_test(hid_t file_id,haddr_t * sbe_addr)206 H5F__get_sbe_addr_test(hid_t file_id, haddr_t *sbe_addr)
207 {
208 H5F_t *file; /* File info */
209 herr_t ret_value = SUCCEED; /* Return value */
210
211 FUNC_ENTER_PACKAGE
212
213 /* Check arguments */
214 if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
215 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
216
217 /* Retrieve maxaddr for file */
218 *sbe_addr = file->shared->sblock->ext_addr;
219
220 done:
221 FUNC_LEAVE_NOAPI(ret_value)
222 } /* end H5F__get_sbe_addr_test() */
223
224 /*-------------------------------------------------------------------------
225 * Function: H5F__same_file_test
226 *
227 * Purpose: Check if two file IDs refer to the same underlying file.
228 *
229 * Return: SUCCEED/FAIL
230 *
231 * Programmer: Quincey Koziol
232 * Oct 13, 2018
233 *
234 *-------------------------------------------------------------------------
235 */
236 htri_t
H5F__same_file_test(hid_t file_id1,hid_t file_id2)237 H5F__same_file_test(hid_t file_id1, hid_t file_id2)
238 {
239 H5F_t *file1, *file2; /* File info */
240 htri_t ret_value = FAIL; /* Return value */
241
242 FUNC_ENTER_PACKAGE
243
244 /* Check arguments */
245 if (NULL == (file1 = (H5F_t *)H5VL_object_verify(file_id1, H5I_FILE)))
246 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
247 if (NULL == (file2 = (H5F_t *)H5VL_object_verify(file_id2, H5I_FILE)))
248 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
249
250 /* If they are using the same underlying "shared" file struct, they are the same file */
251 ret_value = (file1->shared == file2->shared);
252
253 done:
254 FUNC_LEAVE_NOAPI(ret_value)
255 } /* end H5F__same_file_test() */
256
257 /*-------------------------------------------------------------------------
258 * Function: H5F__reparse_file_lock_variable_test
259 *
260 * Purpose: Re-parse the file locking environment variable.
261 *
262 * Since getenv(3) is fairly expensive, we only parse it once,
263 * when the library opens. This test function is used to
264 * re-parse the environment variable after we've changed it
265 * with setnev(3).
266 *
267 * Return: SUCCEED/FAIL
268 *
269 * Programmer: Dana Robinson
270 * Summer 2020
271 *
272 *-------------------------------------------------------------------------
273 */
274 herr_t
H5F__reparse_file_lock_variable_test(void)275 H5F__reparse_file_lock_variable_test(void)
276 {
277 herr_t ret_value = SUCCEED;
278
279 FUNC_ENTER_PACKAGE
280
281 /* Check the file locking environment variable */
282 if (H5F__parse_file_lock_env_var(&use_locks_env_g) < 0)
283 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to parse file locking environment variable")
284
285 done:
286 FUNC_LEAVE_NOAPI(ret_value)
287 } /* end H5F__reparse_file_lock_variable_test() */
288