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 /****************/
15 /* Module Setup */
16 /****************/
17
18 #include "H5Fmodule.h" /* This source code file is part of the H5F module */
19
20
21 /***********/
22 /* Headers */
23 /***********/
24 #include "H5private.h" /* Generic Functions */
25 #include "H5Aprivate.h" /* Attributes */
26 #include "H5ACprivate.h" /* Metadata cache */
27 #include "H5Dprivate.h" /* Datasets */
28 #include "H5Eprivate.h" /* Error handling */
29 #include "H5Fpkg.h" /* File access */
30 #include "H5FDprivate.h" /* File drivers */
31 #include "H5Gprivate.h" /* Groups */
32 #include "H5Iprivate.h" /* IDs */
33 #include "H5MFprivate.h" /* File memory management */
34 #include "H5MMprivate.h" /* Memory management */
35 #include "H5Pprivate.h" /* Property lists */
36 #include "H5SMprivate.h" /* Shared Object Header Messages */
37 #include "H5Tprivate.h" /* Datatypes */
38
39
40 /****************/
41 /* Local Macros */
42 /****************/
43
44 /******************/
45 /* Local Typedefs */
46 /******************/
47
48
49 /********************/
50 /* Package Typedefs */
51 /********************/
52
53
54 /********************/
55 /* Local Prototypes */
56 /********************/
57
58
59 /*********************/
60 /* Package Variables */
61 /*********************/
62
63 /* Package initialization variable */
64 hbool_t H5_PKG_INIT_VAR = FALSE;
65
66
67 /*****************************/
68 /* Library Private Variables */
69 /*****************************/
70
71
72 /*******************/
73 /* Local Variables */
74 /*******************/
75
76
77 /* File ID class */
78 static const H5I_class_t H5I_FILE_CLS[1] = {{
79 H5I_FILE, /* ID class value */
80 0, /* Class flags */
81 0, /* # of reserved IDs for class */
82 (H5I_free_t)H5F_close /* Callback routine for closing objects of this class */
83 }};
84
85
86 /*--------------------------------------------------------------------------
87 NAME
88 H5F__init_package -- Initialize interface-specific information
89 USAGE
90 herr_t H5F__init_package()
91 RETURNS
92 Non-negative on success/Negative on failure
93 DESCRIPTION
94 Initializes any interface-specific data or routines.
95
96 --------------------------------------------------------------------------*/
97 herr_t
H5F__init_package(void)98 H5F__init_package(void)
99 {
100 herr_t ret_value = SUCCEED; /* Return value */
101
102 FUNC_ENTER_PACKAGE
103
104 /*
105 * Initialize the atom group for the file IDs.
106 */
107 if(H5I_register_type(H5I_FILE_CLS) < 0)
108 HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to initialize interface")
109
110 done:
111 FUNC_LEAVE_NOAPI(ret_value)
112 } /* H5F__init_package() */
113
114
115 /*-------------------------------------------------------------------------
116 * Function: H5F_term_package
117 *
118 * Purpose: Terminate this interface: free all memory and reset global
119 * variables to their initial values. Release all ID groups
120 * associated with this interface.
121 *
122 * Return: Success: Positive if anything was done that might
123 * have affected other interfaces; zero
124 * otherwise.
125 *
126 * Failure: Never fails.
127 *
128 * Programmer: Robb Matzke
129 * Friday, February 19, 1999
130 *
131 *-------------------------------------------------------------------------
132 */
133 int
H5F_term_package(void)134 H5F_term_package(void)
135 {
136 int n = 0;
137
138 FUNC_ENTER_NOAPI_NOINIT_NOERR
139
140 if(H5_PKG_INIT_VAR) {
141 if(H5I_nmembers(H5I_FILE) > 0) {
142 (void)H5I_clear_type(H5I_FILE, FALSE, FALSE);
143 n++; /*H5I*/
144 } /* end if */
145 else {
146 /* Make certain we've cleaned up all the shared file objects */
147 H5F_sfile_assert_num(0);
148
149 /* Destroy the file object id group */
150 n += (H5I_dec_type_ref(H5I_FILE) > 0);
151
152 /* Mark closed */
153 if(0 == n)
154 H5_PKG_INIT_VAR = FALSE;
155 } /* end else */
156 } /* end if */
157
158 FUNC_LEAVE_NOAPI(n)
159 } /* end H5F_term_package() */
160
161
162 /*-------------------------------------------------------------------------
163 * Function: H5Fget_create_plist
164 *
165 * Purpose: Get an atom for a copy of the file-creation property list for
166 * this file. This function returns an atom with a copy of the
167 * properties used to create a file.
168 *
169 * Return: Success: template ID
170 *
171 * Failure: FAIL
172 *
173 * Programmer: Unknown
174 *
175 *-------------------------------------------------------------------------
176 */
177 hid_t
H5Fget_create_plist(hid_t file_id)178 H5Fget_create_plist(hid_t file_id)
179 {
180 H5F_t *file; /* File info */
181 H5P_genplist_t *plist; /* Property list */
182 hid_t ret_value; /* Return value */
183
184 FUNC_ENTER_API(FAIL)
185 H5TRACE1("i", "i", file_id);
186
187 /* check args */
188 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
189 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
190 if(NULL == (plist = (H5P_genplist_t *)H5I_object(file->shared->fcpl_id)))
191 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list")
192
193 /* Create the property list object to return */
194 if((ret_value = H5P_copy_plist(plist, TRUE)) < 0)
195 HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to copy file creation properties")
196
197 done:
198 FUNC_LEAVE_API(ret_value)
199 } /* end H5Fget_create_plist() */
200
201
202 /*-------------------------------------------------------------------------
203 * Function: H5Fget_access_plist
204 *
205 * Purpose: Returns a copy of the file access property list of the
206 * specified file.
207 *
208 * NOTE: Make sure that, if you are going to overwrite
209 * information in the copied property list that was
210 * previously opened and assigned to the property list, then
211 * you must close it before overwriting the values.
212 *
213 * Return: Success: Object ID for a copy of the file access
214 * property list.
215 *
216 * Failure: FAIL
217 *
218 * Programmer: Robb Matzke
219 * Wednesday, February 18, 1998
220 *
221 *-------------------------------------------------------------------------
222 */
223 hid_t
H5Fget_access_plist(hid_t file_id)224 H5Fget_access_plist(hid_t file_id)
225 {
226 H5F_t *f; /* File info */
227 hid_t ret_value; /* Return value */
228
229 FUNC_ENTER_API(FAIL)
230 H5TRACE1("i", "i", file_id);
231
232 /* Check args */
233 if(NULL == (f = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
234 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
235
236 /* Retrieve the file's access property list */
237 if((ret_value = H5F_get_access_plist(f, TRUE)) < 0)
238 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get file access property list")
239
240 done:
241 FUNC_LEAVE_API(ret_value)
242 } /* end H5Fget_access_plist() */
243
244
245 /*-------------------------------------------------------------------------
246 * Function: H5Fget_obj_count
247 *
248 * Purpose: Public function returning the number of opened object IDs
249 * (files, datasets, groups and datatypes) in the same file.
250 *
251 * Return: Non-negative on success; negative on failure.
252 *
253 * Programmer: Raymond Lu
254 * Wednesday, Dec 5, 2001
255 *
256 *-------------------------------------------------------------------------
257 */
258 ssize_t
H5Fget_obj_count(hid_t file_id,unsigned types)259 H5Fget_obj_count(hid_t file_id, unsigned types)
260 {
261 H5F_t *f = NULL; /* File to query */
262 size_t obj_count = 0; /* Number of opened objects */
263 ssize_t ret_value; /* Return value */
264
265 FUNC_ENTER_API(FAIL)
266 H5TRACE2("Zs", "iIu", file_id, types);
267
268 /* Check arguments */
269 if(file_id != (hid_t)H5F_OBJ_ALL && (NULL == (f = (H5F_t *)H5I_object_verify(file_id, H5I_FILE))))
270 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file id")
271 if(0 == (types & H5F_OBJ_ALL))
272 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not an object type")
273
274 /* Perform the query */
275 if(H5F_get_obj_count(f, types, TRUE, &obj_count) < 0)
276 HGOTO_ERROR(H5E_INTERNAL, H5E_BADITER, FAIL, "H5F_get_obj_count failed")
277
278 /* Set the return value */
279 ret_value = (ssize_t)obj_count;
280
281 done:
282 FUNC_LEAVE_API(ret_value)
283 } /* end H5Fget_obj_count() */
284
285
286 /*-------------------------------------------------------------------------
287 * Function: H5Fget_object_ids
288 *
289 * Purpose: Public function to return a list of opened object IDs.
290 *
291 * Return: Non-negative on success; negative on failure.
292 *
293 * Programmer: Raymond Lu
294 * Wednesday, Dec 5, 2001
295 *
296 * Modification:
297 * Raymond Lu
298 * 24 September 2008
299 * Changed the return value to ssize_t and MAX_OBJTS to size_t to
300 * accommadate potential large number of objects.
301 *
302 *-------------------------------------------------------------------------
303 */
304 ssize_t
H5Fget_obj_ids(hid_t file_id,unsigned types,size_t max_objs,hid_t * oid_list)305 H5Fget_obj_ids(hid_t file_id, unsigned types, size_t max_objs, hid_t *oid_list)
306 {
307 H5F_t *f = NULL; /* File to query */
308 size_t obj_id_count = 0; /* Number of open objects */
309 ssize_t ret_value; /* Return value */
310
311 FUNC_ENTER_API(FAIL)
312 H5TRACE4("Zs", "iIuz*i", file_id, types, max_objs, oid_list);
313
314 /* Check arguments */
315 if(file_id != (hid_t)H5F_OBJ_ALL && (NULL == (f = (H5F_t *)H5I_object_verify(file_id, H5I_FILE))))
316 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file id")
317 if(0 == (types & H5F_OBJ_ALL))
318 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not an object type")
319 if(!oid_list)
320 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "object ID list is NULL")
321
322 /* Perform the query */
323 if(H5F_get_obj_ids(f, types, max_objs, oid_list, TRUE, &obj_id_count) < 0)
324 HGOTO_ERROR(H5E_INTERNAL, H5E_BADITER, FAIL, "H5F_get_obj_ids failed")
325
326 /* Set the return value */
327 ret_value = (ssize_t)obj_id_count;
328
329 done:
330 FUNC_LEAVE_API(ret_value)
331 } /* end H5Fget_obj_ids() */
332
333
334 /*-------------------------------------------------------------------------
335 * Function: H5Fget_vfd_handle
336 *
337 * Purpose: Returns a pointer to the file handle of the low-level file
338 * driver.
339 *
340 * Return: Success: non-negative value.
341 * Failure: negative.
342 *
343 * Programmer: Raymond Lu
344 * Sep. 16, 2002
345 *
346 *-------------------------------------------------------------------------
347 */
348 herr_t
H5Fget_vfd_handle(hid_t file_id,hid_t fapl,void ** file_handle)349 H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle)
350 {
351 H5F_t *file; /* File to query */
352 herr_t ret_value = SUCCEED; /* Return value */
353
354 FUNC_ENTER_API(FAIL)
355 H5TRACE3("e", "ii**x", file_id, fapl, file_handle);
356
357 /* Check args */
358 if(!file_handle)
359 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file handle pointer")
360
361 /* Get the file */
362 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
363 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file id")
364
365 /* Retrieve the VFD handle for the file */
366 if(H5F_get_vfd_handle(file, fapl, file_handle) < 0)
367 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve VFD handle")
368
369 done:
370 FUNC_LEAVE_API(ret_value)
371 } /* end H5Fget_vfd_handle() */
372
373
374 /*-------------------------------------------------------------------------
375 * Function: H5Fis_hdf5
376 *
377 * Purpose: Check the file signature to detect an HDF5 file.
378 *
379 * Bugs: This function is not robust: it only uses the default file
380 * driver when attempting to open the file when in fact it
381 * should use all known file drivers.
382 *
383 * Return: Success: TRUE/FALSE
384 *
385 * Failure: Negative
386 *
387 * Programmer: Unknown
388 *
389 * Modifications:
390 * Robb Matzke, 1999-08-02
391 * Rewritten to use the virtual file layer.
392 *-------------------------------------------------------------------------
393 */
394 htri_t
H5Fis_hdf5(const char * name)395 H5Fis_hdf5(const char *name)
396 {
397 htri_t ret_value; /* Return value */
398
399 FUNC_ENTER_API(FAIL)
400 H5TRACE1("t", "*s", name);
401
402 /* Check args and all the boring stuff. */
403 if(!name || !*name)
404 HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "no file name specified")
405
406 /* call the private is_HDF5 function */
407 if((ret_value = H5F__is_hdf5(name, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id)) < 0)
408 HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable open file")
409
410 done:
411
412 FUNC_LEAVE_API(ret_value)
413 } /* end H5Fis_hdf5() */
414
415
416 /*-------------------------------------------------------------------------
417 * Function: H5Fcreate
418 *
419 * Purpose: This is the primary function for creating HDF5 files . The
420 * flags parameter determines whether an existing file will be
421 * overwritten or not. All newly created files are opened for
422 * both reading and writing. All flags may be combined with the
423 * bit-wise OR operator (`|') to change the behavior of the file
424 * create call.
425 *
426 * The more complex behaviors of a file's creation and access
427 * are controlled through the file-creation and file-access
428 * property lists. The value of H5P_DEFAULT for a template
429 * value indicates that the library should use the default
430 * values for the appropriate template.
431 *
432 * See also: H5Fpublic.h for the list of supported flags. H5Ppublic.h for
433 * the list of file creation and file access properties.
434 *
435 * Return: Success: A file ID
436 *
437 * Failure: FAIL
438 *
439 * Programmer: Unknown
440 *
441 *-------------------------------------------------------------------------
442 */
443 hid_t
H5Fcreate(const char * filename,unsigned flags,hid_t fcpl_id,hid_t fapl_id)444 H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
445 {
446 hbool_t ci_load = FALSE; /* whether MDC ci load requested */
447 hbool_t ci_write = FALSE; /* whether MDC CI write requested */
448 H5F_t *new_file = NULL; /*file struct for new file */
449 hid_t dxpl_id = H5AC_ind_read_dxpl_id; /*dxpl used by library */
450 hid_t ret_value; /*return value */
451
452 FUNC_ENTER_API(FAIL)
453 H5TRACE4("i", "*sIuii", filename, flags, fcpl_id, fapl_id);
454
455 /* Check/fix arguments */
456 if(!filename || !*filename)
457 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file name")
458 /* In this routine, we only accept the following flags:
459 * H5F_ACC_EXCL, H5F_ACC_TRUNC and H5F_ACC_SWMR_WRITE
460 */
461 if(flags & ~(H5F_ACC_EXCL | H5F_ACC_TRUNC | H5F_ACC_SWMR_WRITE))
462 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid flags")
463 /* The H5F_ACC_EXCL and H5F_ACC_TRUNC flags are mutually exclusive */
464 if((flags & H5F_ACC_EXCL) && (flags & H5F_ACC_TRUNC))
465 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "mutually exclusive flags for file creation")
466
467 /* Check file creation property list */
468 if(H5P_DEFAULT == fcpl_id)
469 fcpl_id = H5P_FILE_CREATE_DEFAULT;
470 else
471 if(TRUE != H5P_isa_class(fcpl_id, H5P_FILE_CREATE))
472 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not file create property list")
473
474 /* Verify access property list and get correct dxpl */
475 if(H5P_verify_apl_and_dxpl(&fapl_id, H5P_CLS_FACC, &dxpl_id, H5I_INVALID_HID, TRUE) < 0)
476 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set access and transfer property lists")
477
478 /*
479 * Adjust bit flags by turning on the creation bit and making sure that
480 * the EXCL or TRUNC bit is set. All newly-created files are opened for
481 * reading and writing.
482 */
483 if (0==(flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC)))
484 flags |= H5F_ACC_EXCL; /*default*/
485 flags |= H5F_ACC_RDWR | H5F_ACC_CREAT;
486
487 /*
488 * Create a new file or truncate an existing file.
489 */
490 if(NULL == (new_file = H5F_open(filename, flags, fcpl_id, fapl_id, dxpl_id)))
491 HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to create file")
492
493 /* Check to see if both SWMR and cache image are requested. Fail if so */
494 if(H5C_cache_image_status(new_file, &ci_load, &ci_write) < 0)
495 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get MDC cache image status")
496 if((ci_load || ci_write) && (flags & (H5F_ACC_SWMR_READ | H5F_ACC_SWMR_WRITE)))
497 HGOTO_ERROR(H5E_FILE, H5E_UNSUPPORTED, FAIL, "can't have both SWMR and cache image")
498
499 /* Get an atom for the file */
500 if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0)
501 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file")
502
503 /* Keep this ID in file object structure */
504 new_file->file_id = ret_value;
505
506 done:
507 if(ret_value < 0 && new_file && H5F_try_close(new_file, NULL) < 0)
508 HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "problems closing file")
509
510 FUNC_LEAVE_API(ret_value)
511 } /* end H5Fcreate() */
512
513
514 /*-------------------------------------------------------------------------
515 * Function: H5Fopen
516 *
517 * Purpose: This is the primary function for accessing existing HDF5
518 * files. The FLAGS argument determines whether writing to an
519 * existing file will be allowed or not. All flags may be
520 * combined with the bit-wise OR operator (`|') to change the
521 * behavior of the file open call. The more complex behaviors
522 * of a file's access are controlled through the file-access
523 * property list.
524 *
525 * See Also: H5Fpublic.h for a list of possible values for FLAGS.
526 *
527 * Return: Success: A file ID
528 *
529 * Failure: FAIL
530 *
531 * Programmer: Unknown
532 *
533 * Modifications:
534 * Robb Matzke, 1997-07-18
535 * File struct creation and destruction is through H5F_new() and
536 * H5F__dest(). Reading the root symbol table entry is done with
537 * H5G_decode().
538 *
539 * Robb Matzke, 1997-09-23
540 * Most of the work is now done by H5F_open() since H5Fcreate()
541 * and H5Fopen() originally contained almost identical code.
542 *
543 * Robb Matzke, 1998-02-18
544 * Added better error checking for the flags and the file access
545 * property list. It used to be possible to make the library
546 * dump core by passing an object ID that was not a file access
547 * property list.
548 *
549 * Robb Matzke, 1999-08-02
550 * The file access property list is passed to the H5F_open() as
551 * object IDs.
552 *-------------------------------------------------------------------------
553 */
554 hid_t
H5Fopen(const char * filename,unsigned flags,hid_t fapl_id)555 H5Fopen(const char *filename, unsigned flags, hid_t fapl_id)
556 {
557 hbool_t ci_load = FALSE; /* whether MDC ci load requested */
558 hbool_t ci_write = FALSE; /* whether MDC CI write requested */
559 H5F_t *new_file = NULL; /*file struct for new file */
560 hid_t dxpl_id = H5AC_ind_read_dxpl_id; /*dxpl used by library */
561 hid_t ret_value; /*return value */
562
563 FUNC_ENTER_API(FAIL)
564 H5TRACE3("i", "*sIui", filename, flags, fapl_id);
565
566 /* Check/fix arguments. */
567 if(!filename || !*filename)
568 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file name")
569 /* Reject undefined flags (~H5F_ACC_PUBLIC_FLAGS) and the H5F_ACC_TRUNC & H5F_ACC_EXCL flags */
570 if((flags & ~H5F_ACC_PUBLIC_FLAGS) ||
571 (flags & H5F_ACC_TRUNC) || (flags & H5F_ACC_EXCL))
572 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file open flags")
573 /* Asking for SWMR write access on a read-only file is invalid */
574 if((flags & H5F_ACC_SWMR_WRITE) && 0 == (flags & H5F_ACC_RDWR))
575 HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "SWMR write access on a file open for read-only access is not allowed")
576 /* Asking for SWMR read access on a non-read-only file is invalid */
577 if((flags & H5F_ACC_SWMR_READ) && (flags & H5F_ACC_RDWR))
578 HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "SWMR read access on a file open for read-write access is not allowed")
579
580 /* Verify access property list and get correct dxpl */
581 if(H5P_verify_apl_and_dxpl(&fapl_id, H5P_CLS_FACC, &dxpl_id, H5I_INVALID_HID, TRUE) < 0)
582 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set access and transfer property lists")
583
584 /* Open the file */
585 if(NULL == (new_file = H5F_open(filename, flags, H5P_FILE_CREATE_DEFAULT, fapl_id, dxpl_id)))
586 HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to open file")
587
588 /* Check to see if both SWMR and cache image are requested. Fail if so */
589 if(H5C_cache_image_status(new_file, &ci_load, &ci_write) < 0)
590 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get MDC cache image status")
591 if((ci_load || ci_write) && (flags & (H5F_ACC_SWMR_READ | H5F_ACC_SWMR_WRITE)))
592 HGOTO_ERROR(H5E_FILE, H5E_UNSUPPORTED, FAIL, "can't have both SWMR and cache image")
593
594 /* Get an atom for the file */
595 if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0)
596 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle")
597
598 /* Keep this ID in file object structure */
599 new_file->file_id = ret_value;
600
601 done:
602 if(ret_value < 0 && new_file && H5F_try_close(new_file, NULL) < 0)
603 HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "problems closing file")
604
605 FUNC_LEAVE_API(ret_value)
606 } /* end H5Fopen() */
607
608
609 /*-------------------------------------------------------------------------
610 * Function: H5Fflush
611 *
612 * Purpose: Flushes all outstanding buffers of a file to disk but does
613 * not remove them from the cache. The OBJECT_ID can be a file,
614 * dataset, group, attribute, or named data type.
615 *
616 * Return: Non-negative on success/Negative on failure
617 *
618 * Programmer: Robb Matzke
619 * Thursday, August 6, 1998
620 *
621 *-------------------------------------------------------------------------
622 */
623 herr_t
H5Fflush(hid_t object_id,H5F_scope_t scope)624 H5Fflush(hid_t object_id, H5F_scope_t scope)
625 {
626 H5F_t *f = NULL; /* File to flush */
627 H5O_loc_t *oloc = NULL; /* Object location for ID */
628 herr_t ret_value = SUCCEED; /* Return value */
629
630 FUNC_ENTER_API(FAIL)
631 H5TRACE2("e", "iFs", object_id, scope);
632
633 switch(H5I_get_type(object_id)) {
634 case H5I_FILE:
635 if(NULL == (f = (H5F_t *)H5I_object(object_id)))
636 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier")
637 break;
638
639 case H5I_GROUP:
640 {
641 H5G_t *grp;
642
643 if(NULL == (grp = (H5G_t *)H5I_object(object_id)))
644 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid group identifier")
645 oloc = H5G_oloc(grp);
646 }
647 break;
648
649 case H5I_DATATYPE:
650 {
651 H5T_t *type;
652
653 if(NULL == (type = (H5T_t *)H5I_object(object_id)))
654 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid type identifier")
655 oloc = H5T_oloc(type);
656 }
657 break;
658
659 case H5I_DATASET:
660 {
661 H5D_t *dset;
662
663 if(NULL == (dset = (H5D_t *)H5I_object(object_id)))
664 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset identifier")
665 oloc = H5D_oloc(dset);
666 }
667 break;
668
669 case H5I_ATTR:
670 {
671 H5A_t *attr;
672
673 if(NULL == (attr = (H5A_t *)H5I_object(object_id)))
674 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid attribute identifier")
675 oloc = H5A_oloc(attr);
676 }
677 break;
678
679 case H5I_UNINIT:
680 case H5I_BADID:
681 case H5I_DATASPACE:
682 case H5I_REFERENCE:
683 case H5I_VFL:
684 case H5I_GENPROP_CLS:
685 case H5I_GENPROP_LST:
686 case H5I_ERROR_CLASS:
687 case H5I_ERROR_MSG:
688 case H5I_ERROR_STACK:
689 case H5I_NTYPES:
690 default:
691 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
692 } /* end switch */
693
694 if(!f) {
695 if(!oloc)
696 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "object is not assocated with a file")
697 f = oloc->file;
698 } /* end if */
699 if(!f)
700 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "object is not associated with a file")
701
702 /* Flush the file */
703 /*
704 * Nothing to do if the file is read only. This determination is
705 * made at the shared open(2) flags level, implying that opening a
706 * file twice, once for read-only and once for read-write, and then
707 * calling H5Fflush() with the read-only handle, still causes data
708 * to be flushed.
709 */
710 if(H5F_ACC_RDWR & H5F_INTENT(f)) {
711 /* Flush other files, depending on scope */
712 if(H5F_SCOPE_GLOBAL == scope) {
713 /* Call the flush routine for mounted file hierarchies */
714 if(H5F_flush_mounts(f, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id) < 0)
715 HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush mounted file hierarchy")
716 } /* end if */
717 else {
718 /* Call the flush routine, for this file */
719 if(H5F__flush(f, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id, FALSE) < 0)
720 HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush file's cached information")
721 } /* end else */
722 } /* end if */
723
724 done:
725 FUNC_LEAVE_API(ret_value)
726 } /* end H5Fflush() */
727
728
729 /*-------------------------------------------------------------------------
730 * Function: H5Fclose
731 *
732 * Purpose: This function closes the file specified by FILE_ID by
733 * flushing all data to storage, and terminating access to the
734 * file through FILE_ID. If objects (e.g., datasets, groups,
735 * etc.) are open in the file then the underlying storage is not
736 * closed until those objects are closed; however, all data for
737 * the file and the open objects is flushed.
738 *
739 * Return: Success: Non-negative
740 *
741 * Failure: Negative
742 *
743 * Programmer: Robb Matzke
744 * Saturday, February 20, 1999
745 *
746 * Modifications:
747 *
748 *-------------------------------------------------------------------------
749 */
750 herr_t
H5Fclose(hid_t file_id)751 H5Fclose(hid_t file_id)
752 {
753 H5F_t *f = NULL;
754 int nref;
755 herr_t ret_value = SUCCEED;
756
757 FUNC_ENTER_API(FAIL)
758 H5TRACE1("e", "i", file_id);
759
760 /* Check/fix arguments. */
761 if(H5I_FILE != H5I_get_type(file_id))
762 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file ID")
763
764 /* Flush file if this is the last reference to this id and we have write
765 * intent, unless it will be flushed by the "shared" file being closed.
766 * This is only necessary to replicate previous behaviour, and could be
767 * disabled by an option/property to improve performance. */
768 if(NULL == (f = (H5F_t *)H5I_object(file_id)))
769 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier")
770 if((f->shared->nrefs > 1) && (H5F_INTENT(f) & H5F_ACC_RDWR)) {
771 if((nref = H5I_get_ref(file_id, FALSE)) < 0)
772 HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't get ID ref count")
773 if(nref == 1)
774 if(H5F__flush(f, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id, FALSE) < 0)
775 HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush cache")
776 } /* end if */
777
778 /*
779 * Decrement reference count on atom. When it reaches zero the file will
780 * be closed.
781 */
782 if(H5I_dec_app_ref(file_id) < 0)
783 HGOTO_ERROR(H5E_ATOM, H5E_CANTCLOSEFILE, FAIL, "decrementing file ID failed")
784
785 done:
786 FUNC_LEAVE_API(ret_value)
787 } /* end H5Fclose() */
788
789
790 /*-------------------------------------------------------------------------
791 * Function: H5Freopen
792 *
793 * Purpose: Reopen a file. The new file handle which is returned points
794 * to the same file as the specified file handle. Both handles
795 * share caches and other information. The only difference
796 * between the handles is that the new handle is not mounted
797 * anywhere and no files are mounted on it.
798 *
799 * Return: Success: New file ID
800 *
801 * Failure: FAIL
802 *
803 * Programmer: Robb Matzke
804 * Friday, October 16, 1998
805 *
806 *-------------------------------------------------------------------------
807 */
808 hid_t
H5Freopen(hid_t file_id)809 H5Freopen(hid_t file_id)
810 {
811 H5F_t *old_file = NULL;
812 H5F_t *new_file = NULL;
813 hid_t ret_value;
814
815 FUNC_ENTER_API(FAIL)
816 H5TRACE1("i", "i", file_id);
817
818 /* Check arguments */
819 if(NULL == (old_file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
820 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
821
822 /* Get a new "top level" file struct, sharing the same "low level" file struct */
823 if(NULL == (new_file = H5F_new(old_file->shared, 0, H5P_FILE_CREATE_DEFAULT, H5P_FILE_ACCESS_DEFAULT, NULL)))
824 HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to reopen file")
825
826 /* Duplicate old file's names */
827 new_file->open_name = H5MM_xstrdup(old_file->open_name);
828 new_file->actual_name = H5MM_xstrdup(old_file->actual_name);
829 new_file->extpath = H5MM_xstrdup(old_file->extpath);
830
831 if((ret_value = H5I_register(H5I_FILE, new_file, TRUE)) < 0)
832 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle")
833
834 /* Keep this ID in file object structure */
835 new_file->file_id = ret_value;
836
837 done:
838 if(ret_value < 0 && new_file)
839 if(H5F__dest(new_file, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id, FALSE) < 0)
840 HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file")
841
842 FUNC_LEAVE_API(ret_value)
843 } /* end H5Freopen() */
844
845
846 /*-------------------------------------------------------------------------
847 * Function: H5Fget_intent
848 *
849 * Purpose: Public API to retrieve the file's 'intent' flags passed
850 * during H5Fopen()
851 *
852 * Return: Non-negative on success/negative on failure
853 *
854 * Programmer: James Laird
855 * August 23, 2006
856 *
857 *-------------------------------------------------------------------------
858 */
859 herr_t
H5Fget_intent(hid_t file_id,unsigned * intent_flags)860 H5Fget_intent(hid_t file_id, unsigned *intent_flags)
861 {
862 herr_t ret_value = SUCCEED;
863
864 FUNC_ENTER_API(FAIL)
865 H5TRACE2("e", "i*Iu", file_id, intent_flags);
866
867 /* If no intent flags were passed in, exit quietly */
868 if(intent_flags) {
869 H5F_t * file; /* Pointer to file structure */
870
871 /* Get the internal file structure */
872 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
873 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
874
875 /* HDF5 uses some flags internally that users don't know about.
876 * Simplify things for them so that they only get either H5F_ACC_RDWR
877 * or H5F_ACC_RDONLY.
878 */
879 if(H5F_INTENT(file) & H5F_ACC_RDWR) {
880 *intent_flags = H5F_ACC_RDWR;
881
882 /* Check for SWMR write access on the file */
883 if(H5F_INTENT(file) & H5F_ACC_SWMR_WRITE)
884 *intent_flags |= H5F_ACC_SWMR_WRITE;
885 } /* end if */
886 else {
887 *intent_flags = H5F_ACC_RDONLY;
888
889 /* Check for SWMR read access on the file */
890 if(H5F_INTENT(file) & H5F_ACC_SWMR_READ)
891 *intent_flags |= H5F_ACC_SWMR_READ;
892 } /* end else */
893 } /* end if */
894
895 done:
896 FUNC_LEAVE_API(ret_value)
897 } /* end H5Fget_intent() */
898
899
900 /*-------------------------------------------------------------------------
901 * Function: H5Fget_freespace
902 *
903 * Purpose: Retrieves the amount of free space in the file.
904 *
905 * Return: Success: Amount of free space for type
906 * Failure: Negative
907 *
908 * Programmer: Quincey Koziol
909 * koziol@ncsa.uiuc.edu
910 * Oct 6, 2003
911 *
912 *-------------------------------------------------------------------------
913 */
914 hssize_t
H5Fget_freespace(hid_t file_id)915 H5Fget_freespace(hid_t file_id)
916 {
917 H5F_t *file; /* File object for file ID */
918 hsize_t tot_space; /* Amount of free space in the file */
919 hssize_t ret_value; /* Return value */
920
921 FUNC_ENTER_API(FAIL)
922 H5TRACE1("Hs", "i", file_id);
923
924 /* Check args */
925 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
926 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
927
928 /* Go get the actual amount of free space in the file */
929 if(H5MF_get_freespace(file, H5AC_ind_read_dxpl_id, &tot_space, NULL) < 0)
930 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file")
931
932 ret_value = (hssize_t)tot_space;
933
934 done:
935 FUNC_LEAVE_API(ret_value)
936 } /* end H5Fget_freespace() */
937
938
939 /*-------------------------------------------------------------------------
940 * Function: H5Fget_filesize
941 *
942 * Purpose: Retrieves the file size of the HDF5 file. This function
943 * is called after an existing file is opened in order
944 * to learn the true size of the underlying file.
945 *
946 * Return: Success: Non-negative
947 * Failure: Negative
948 *
949 * Programmer: David Pitt
950 * david.pitt@bigpond.com
951 * Apr 27, 2004
952 *
953 *-------------------------------------------------------------------------
954 */
955 herr_t
H5Fget_filesize(hid_t file_id,hsize_t * size)956 H5Fget_filesize(hid_t file_id, hsize_t *size)
957 {
958 H5F_t *file; /* File object for file ID */
959 haddr_t eof; /* End of file address */
960 haddr_t eoa; /* End of allocation address */
961 haddr_t max_eof_eoa; /* Maximum of the EOA & EOF */
962 haddr_t base_addr; /* Base address for the file */
963 herr_t ret_value = SUCCEED; /* Return value */
964
965 FUNC_ENTER_API(FAIL)
966 H5TRACE2("e", "i*h", file_id, size);
967
968 /* Check args */
969 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
970 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
971
972 /* Go get the actual file size */
973 eof = H5FD_get_eof(file->shared->lf, H5FD_MEM_DEFAULT);
974 eoa = H5FD_get_eoa(file->shared->lf, H5FD_MEM_DEFAULT);
975 max_eof_eoa = MAX(eof, eoa);
976 if(HADDR_UNDEF == max_eof_eoa)
977 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "file get eof/eoa requests failed")
978 base_addr = H5FD_get_base_addr(file->shared->lf);
979
980 if(size)
981 *size = (hsize_t)(max_eof_eoa + base_addr); /* Convert relative base address for file to absolute address */
982
983 done:
984 FUNC_LEAVE_API(ret_value)
985 } /* end H5Fget_filesize() */
986
987
988 /*-------------------------------------------------------------------------
989 * Function: H5Fget_file_image
990 *
991 * Purpose: If a buffer is provided (via the buf_ptr argument) and is
992 * big enough (size in buf_len argument), load *buf_ptr with
993 * an image of the open file whose ID is provided in the
994 * file_id parameter, and return the number of bytes copied
995 * to the buffer.
996 *
997 * If the buffer exists, but is too small to contain an image
998 * of the indicated file, return a negative number.
999 *
1000 * Finally, if no buffer is provided, return the size of the
1001 * buffer needed. This value is simply the eoa of the target
1002 * file.
1003 *
1004 * Note that any user block is skipped.
1005 *
1006 * Also note that the function may not be used on files
1007 * opened with either the split/multi file driver or the
1008 * family file driver.
1009 *
1010 * In the former case, the sparse address space makes the
1011 * get file image operation impractical, due to the size of
1012 * the image typically required.
1013 *
1014 * In the case of the family file driver, the problem is
1015 * the driver message in the super block, which will prevent
1016 * the image being opened with any driver other than the
1017 * family file driver -- which negates the purpose of the
1018 * operation. This can be fixed, but no resources for
1019 * this now.
1020 *
1021 * Return: Success: Bytes copied / number of bytes needed.
1022 * Failure: negative value
1023 *
1024 * Programmer: John Mainzer
1025 * 11/15/11
1026 *
1027 *-------------------------------------------------------------------------
1028 */
1029 ssize_t
H5Fget_file_image(hid_t file_id,void * buf_ptr,size_t buf_len)1030 H5Fget_file_image(hid_t file_id, void *buf_ptr, size_t buf_len)
1031 {
1032 H5F_t *file; /* File object for file ID */
1033 ssize_t ret_value; /* Return value */
1034
1035 FUNC_ENTER_API(FAIL)
1036 H5TRACE3("Zs", "i*xz", file_id, buf_ptr, buf_len);
1037
1038 /* Check args */
1039 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1040 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1041
1042 /* call private get_file_image function */
1043 if((ret_value = H5F_get_file_image(file, buf_ptr, buf_len, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id)) < 0)
1044 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file image")
1045
1046 done:
1047 FUNC_LEAVE_API(ret_value)
1048 } /* H5Fget_file_image() */
1049
1050
1051 /*-------------------------------------------------------------------------
1052 * Function: H5Fget_mdc_config
1053 *
1054 * Purpose: Retrieves the current automatic cache resize configuration
1055 * from the metadata cache, and return it in *config_ptr.
1056 *
1057 * Note that the version field of *config_Ptr must be correctly
1058 * filled in by the caller. This allows us to adapt for
1059 * obsolete versions of the structure.
1060 *
1061 * Return: Success: SUCCEED
1062 * Failure: FAIL
1063 *
1064 * Programmer: John Mainzer
1065 * 3/24/05
1066 *
1067 *-------------------------------------------------------------------------
1068 */
1069 herr_t
H5Fget_mdc_config(hid_t file_id,H5AC_cache_config_t * config_ptr)1070 H5Fget_mdc_config(hid_t file_id, H5AC_cache_config_t *config_ptr)
1071 {
1072 H5F_t *file; /* File object for file ID */
1073 herr_t ret_value = SUCCEED; /* Return value */
1074
1075 FUNC_ENTER_API(FAIL)
1076 H5TRACE2("e", "i*x", file_id, config_ptr);
1077
1078 /* Check args */
1079 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1080 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1081 if((NULL == config_ptr) || (config_ptr->version != H5AC__CURR_CACHE_CONFIG_VERSION))
1082 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Bad config_ptr")
1083
1084 /* Go get the resize configuration */
1085 if(H5AC_get_cache_auto_resize_config(file->shared->cache, config_ptr) < 0)
1086 HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_auto_resize_config() failed.")
1087
1088 done:
1089 FUNC_LEAVE_API(ret_value)
1090 } /* H5Fget_mdc_config() */
1091
1092
1093 /*-------------------------------------------------------------------------
1094 * Function: H5Fset_mdc_config
1095 *
1096 * Purpose: Sets the current metadata cache automatic resize
1097 * configuration, using the contents of the instance of
1098 * H5AC_cache_config_t pointed to by config_ptr.
1099 *
1100 * Return: Success: SUCCEED
1101 * Failure: FAIL
1102 *
1103 * Programmer: John Mainzer
1104 * 3/24/05
1105 *
1106 *-------------------------------------------------------------------------
1107 */
1108 herr_t
H5Fset_mdc_config(hid_t file_id,H5AC_cache_config_t * config_ptr)1109 H5Fset_mdc_config(hid_t file_id, H5AC_cache_config_t *config_ptr)
1110 {
1111 H5F_t *file; /* File object for file ID */
1112 herr_t ret_value = SUCCEED; /* Return value */
1113
1114 FUNC_ENTER_API(FAIL)
1115 H5TRACE2("e", "i*x", file_id, config_ptr);
1116
1117 /* Check args */
1118 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1119 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1120
1121 /* set the resize configuration */
1122 if(H5AC_set_cache_auto_resize_config(file->shared->cache, config_ptr) < 0)
1123 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "H5AC_set_cache_auto_resize_config() failed.")
1124
1125 done:
1126 FUNC_LEAVE_API(ret_value)
1127 } /* H5Fset_mdc_config() */
1128
1129
1130 /*-------------------------------------------------------------------------
1131 * Function: H5Fget_mdc_hit_rate
1132 *
1133 * Purpose: Retrieves the current hit rate from the metadata cache.
1134 * This rate is the overall hit rate since the last time
1135 * the hit rate statistics were reset either manually or
1136 * automatically.
1137 *
1138 * Return: Success: SUCCEED
1139 * Failure: FAIL
1140 *
1141 * Programmer: John Mainzer
1142 * 3/24/05
1143 *
1144 *-------------------------------------------------------------------------
1145 */
1146 herr_t
H5Fget_mdc_hit_rate(hid_t file_id,double * hit_rate_ptr)1147 H5Fget_mdc_hit_rate(hid_t file_id, double *hit_rate_ptr)
1148 {
1149 H5F_t *file; /* File object for file ID */
1150 herr_t ret_value = SUCCEED; /* Return value */
1151
1152 FUNC_ENTER_API(FAIL)
1153 H5TRACE2("e", "i*d", file_id, hit_rate_ptr);
1154
1155 /* Check args */
1156 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1157 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1158
1159 if(NULL == hit_rate_ptr)
1160 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "NULL hit rate pointer")
1161
1162 /* Go get the current hit rate */
1163 if(H5AC_get_cache_hit_rate(file->shared->cache, hit_rate_ptr) < 0)
1164 HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_hit_rate() failed.")
1165
1166 done:
1167 FUNC_LEAVE_API(ret_value)
1168 } /* H5Fget_mdc_hit_rate() */
1169
1170
1171 /*-------------------------------------------------------------------------
1172 * Function: H5Fget_mdc_size
1173 *
1174 * Purpose: Retrieves the maximum size, minimum clean size, current
1175 * size, and current number of entries from the metadata
1176 * cache associated with the specified file. If any of
1177 * the ptr parameters are NULL, the associated datum is
1178 * not returned.
1179 *
1180 * Return: Success: SUCCEED
1181 * Failure: FAIL
1182 *
1183 * Programmer: John Mainzer
1184 * 3/24/05
1185 *
1186 *-------------------------------------------------------------------------
1187 */
1188 herr_t
H5Fget_mdc_size(hid_t file_id,size_t * max_size_ptr,size_t * min_clean_size_ptr,size_t * cur_size_ptr,int * cur_num_entries_ptr)1189 H5Fget_mdc_size(hid_t file_id, size_t *max_size_ptr, size_t *min_clean_size_ptr,
1190 size_t *cur_size_ptr, int *cur_num_entries_ptr)
1191 {
1192 H5F_t *file; /* File object for file ID */
1193 uint32_t cur_num_entries;
1194 herr_t ret_value = SUCCEED; /* Return value */
1195
1196 FUNC_ENTER_API(FAIL)
1197 H5TRACE5("e", "i*z*z*z*Is", file_id, max_size_ptr, min_clean_size_ptr,
1198 cur_size_ptr, cur_num_entries_ptr);
1199
1200 /* Check args */
1201 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1202 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1203
1204 /* Go get the size data */
1205 if(H5AC_get_cache_size(file->shared->cache, max_size_ptr,
1206 min_clean_size_ptr, cur_size_ptr, &cur_num_entries) < 0)
1207 HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC_get_cache_size() failed.")
1208
1209 if(cur_num_entries_ptr != NULL)
1210 *cur_num_entries_ptr = (int)cur_num_entries;
1211
1212 done:
1213 FUNC_LEAVE_API(ret_value)
1214 } /* H5Fget_mdc_size() */
1215
1216
1217 /*-------------------------------------------------------------------------
1218 * Function: H5Freset_mdc_hit_rate_stats
1219 *
1220 * Purpose: Reset the hit rate statistic whose current value can
1221 * be obtained via the H5Fget_mdc_hit_rate() call. Note
1222 * that this statistic will also be reset once per epoch
1223 * by the automatic cache resize code if it is enabled.
1224 *
1225 * It is probably a bad idea to call this function unless
1226 * you are controlling cache size from your program instead
1227 * of using our cache size control code.
1228 *
1229 * Return: Success: SUCCEED
1230 * Failure: FAIL
1231 *
1232 * Programmer: John Mainzer
1233 * 3/24/05
1234 *
1235 *-------------------------------------------------------------------------
1236 */
1237 herr_t
H5Freset_mdc_hit_rate_stats(hid_t file_id)1238 H5Freset_mdc_hit_rate_stats(hid_t file_id)
1239 {
1240 H5F_t *file; /* File object for file ID */
1241 herr_t ret_value = SUCCEED; /* Return value */
1242
1243 FUNC_ENTER_API(FAIL)
1244 H5TRACE1("e", "i", file_id);
1245
1246 /* Check args */
1247 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1248 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1249
1250 /* Reset the hit rate statistic */
1251 if(H5AC_reset_cache_hit_rate_stats(file->shared->cache) < 0)
1252 HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't reset cache hit rate")
1253
1254 done:
1255 FUNC_LEAVE_API(ret_value)
1256 } /* H5Freset_mdc_hit_rate_stats() */
1257
1258
1259 /*-------------------------------------------------------------------------
1260 * Function: H5Fget_name
1261 *
1262 * Purpose: Gets the name of the file to which object OBJ_ID belongs.
1263 * If `name' is non-NULL then write up to `size' bytes into that
1264 * buffer and always return the length of the entry name.
1265 * Otherwise `size' is ignored and the function does not store the name,
1266 * just returning the number of characters required to store the name.
1267 * If an error occurs then the buffer pointed to by `name' (NULL or non-NULL)
1268 * is unchanged and the function returns a negative value.
1269 *
1270 * Note: This routine returns the name that was used to open the file,
1271 * not the actual name after resolving symlinks, etc.
1272 *
1273 * Return: Success: The length of the file name
1274 * Failure: Negative
1275 *
1276 * Programmer: Raymond Lu
1277 * June 29, 2004
1278 *
1279 *-------------------------------------------------------------------------
1280 */
1281 ssize_t
H5Fget_name(hid_t obj_id,char * name,size_t size)1282 H5Fget_name(hid_t obj_id, char *name/*out*/, size_t size)
1283 {
1284 H5F_t *f; /* Top file in mount hierarchy */
1285 size_t len;
1286 ssize_t ret_value;
1287
1288 FUNC_ENTER_API(FAIL)
1289 H5TRACE3("Zs", "ixz", obj_id, name, size);
1290
1291 /* For file IDs, get the file object directly */
1292 /* (This prevents the H5G_loc() call from returning the file pointer for
1293 * the top file in a mount hierarchy)
1294 */
1295 if(H5I_get_type(obj_id) == H5I_FILE ) {
1296 if(NULL == (f = (H5F_t *)H5I_object(obj_id)))
1297 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
1298 } /* end if */
1299 else {
1300 H5G_loc_t loc; /* Object location */
1301
1302 /* Get symbol table entry */
1303 if(H5G_loc(obj_id, &loc) < 0)
1304 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object ID")
1305 f = loc.oloc->file;
1306 } /* end else */
1307
1308 len = HDstrlen(H5F_OPEN_NAME(f));
1309
1310 if(name) {
1311 HDstrncpy(name, H5F_OPEN_NAME(f), MIN(len + 1,size));
1312 if(len >= size)
1313 name[size-1]='\0';
1314 } /* end if */
1315
1316 /* Set return value */
1317 ret_value = (ssize_t)len;
1318
1319 done:
1320 FUNC_LEAVE_API(ret_value)
1321 } /* end H5Fget_name() */
1322
1323
1324 /*-------------------------------------------------------------------------
1325 * Function: H5Fget_info2
1326 *
1327 * Purpose: Gets general information about the file, including:
1328 * 1. Get storage size for superblock extension if there is one.
1329 * 2. Get the amount of btree and heap storage for entries
1330 * in the SOHM table if there is one.
1331 * 3. The amount of free space tracked in the file.
1332 *
1333 * Return: Success: non-negative on success
1334 * Failure: Negative
1335 *
1336 * Programmer: Vailin Choi
1337 * July 11, 2007
1338 *
1339 *-------------------------------------------------------------------------
1340 */
1341 herr_t
H5Fget_info2(hid_t obj_id,H5F_info2_t * finfo)1342 H5Fget_info2(hid_t obj_id, H5F_info2_t *finfo)
1343 {
1344 H5F_t *f; /* Top file in mount hierarchy */
1345 herr_t ret_value = SUCCEED; /* Return value */
1346
1347 FUNC_ENTER_API(FAIL)
1348 H5TRACE2("e", "i*x", obj_id, finfo);
1349
1350 /* Check args */
1351 if(!finfo)
1352 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no info struct")
1353
1354 /* For file IDs, get the file object directly */
1355 /* (This prevents the H5G_loc() call from returning the file pointer for
1356 * the top file in a mount hierarchy)
1357 */
1358 if(H5I_get_type(obj_id) == H5I_FILE ) {
1359 if(NULL == (f = (H5F_t *)H5I_object(obj_id)))
1360 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
1361 } /* end if */
1362 else {
1363 H5G_loc_t loc; /* Object location */
1364
1365 /* Get symbol table entry */
1366 if(H5G_loc(obj_id, &loc) < 0)
1367 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object ID")
1368 f = loc.oloc->file;
1369 } /* end else */
1370 HDassert(f->shared);
1371
1372 /* Reset file info struct */
1373 HDmemset(finfo, 0, sizeof(*finfo));
1374
1375 /* Get the size of the superblock and any superblock extensions */
1376 if(H5F__super_size(f, H5AC_ind_read_dxpl_id, &finfo->super.super_size, &finfo->super.super_ext_size) < 0)
1377 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve superblock sizes")
1378
1379 /* Get the size of any persistent free space */
1380 if(H5MF_get_freespace(f, H5AC_ind_read_dxpl_id, &finfo->free.tot_space, &finfo->free.meta_size) < 0)
1381 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve free space information")
1382
1383 /* Check for SOHM info */
1384 if(H5F_addr_defined(f->shared->sohm_addr))
1385 if(H5SM_ih_size(f, H5AC_ind_read_dxpl_id, &finfo->sohm.hdr_size, &finfo->sohm.msgs_info) < 0)
1386 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "Unable to retrieve SOHM index & heap storage info")
1387
1388 /* Set version # fields */
1389 finfo->super.version = f->shared->sblock->super_vers;
1390 finfo->sohm.version = f->shared->sohm_vers;
1391 finfo->free.version = HDF5_FREESPACE_VERSION;
1392
1393 done:
1394 FUNC_LEAVE_API(ret_value)
1395 } /* end H5Fget_info2() */
1396
1397
1398 /*-------------------------------------------------------------------------
1399 * Function: H5Fget_metadata_read_retry_info
1400 *
1401 * Purpose: To retrieve the collection of read retries for metadata items with checksum.
1402 *
1403 * Return: Success: non-negative on success
1404 * Failure: Negative
1405 *
1406 * Programmer: Vailin Choi; October 2013
1407 *
1408 *-------------------------------------------------------------------------
1409 */
1410 herr_t
H5Fget_metadata_read_retry_info(hid_t file_id,H5F_retry_info_t * info)1411 H5Fget_metadata_read_retry_info(hid_t file_id, H5F_retry_info_t *info)
1412 {
1413 H5F_t *file; /* File object for file ID */
1414 unsigned i, j; /* Local index variable */
1415 size_t tot_size; /* Size of each retries[i] */
1416 herr_t ret_value = SUCCEED; /* Return value */
1417
1418 FUNC_ENTER_API(FAIL)
1419 H5TRACE2("e", "i*x", file_id, info);
1420
1421 /* Check args */
1422 if(!info)
1423 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no info struct")
1424
1425 /* Get the file pointer */
1426 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1427 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1428
1429 /* Copy the # of bins for "retries" array */
1430 info->nbins = file->shared->retries_nbins;
1431
1432 /* Initialize the array of "retries" */
1433 HDmemset(info->retries, 0, sizeof(info->retries));
1434
1435 /* Return if there are no bins -- no retries */
1436 if(!info->nbins)
1437 HGOTO_DONE(SUCCEED);
1438
1439 /* Calculate size for each retries[i] */
1440 tot_size = info->nbins * sizeof(uint32_t);
1441
1442 /* Map and copy information to info's retries for metadata items with tracking for read retries */
1443 j = 0;
1444 for(i = 0; i < H5AC_NTYPES; i++) {
1445 switch(i) {
1446 case H5AC_OHDR_ID:
1447 case H5AC_OHDR_CHK_ID:
1448 case H5AC_BT2_HDR_ID:
1449 case H5AC_BT2_INT_ID:
1450 case H5AC_BT2_LEAF_ID:
1451 case H5AC_FHEAP_HDR_ID:
1452 case H5AC_FHEAP_DBLOCK_ID:
1453 case H5AC_FHEAP_IBLOCK_ID:
1454 case H5AC_FSPACE_HDR_ID:
1455 case H5AC_FSPACE_SINFO_ID:
1456 case H5AC_SOHM_TABLE_ID:
1457 case H5AC_SOHM_LIST_ID:
1458 case H5AC_EARRAY_HDR_ID:
1459 case H5AC_EARRAY_IBLOCK_ID:
1460 case H5AC_EARRAY_SBLOCK_ID:
1461 case H5AC_EARRAY_DBLOCK_ID:
1462 case H5AC_EARRAY_DBLK_PAGE_ID:
1463 case H5AC_FARRAY_HDR_ID:
1464 case H5AC_FARRAY_DBLOCK_ID:
1465 case H5AC_FARRAY_DBLK_PAGE_ID:
1466 case H5AC_SUPERBLOCK_ID:
1467 HDassert(j < H5F_NUM_METADATA_READ_RETRY_TYPES);
1468 if(file->shared->retries[i] != NULL) {
1469 /* Allocate memory for retries[i]
1470 *
1471 * This memory should be released by the user with
1472 * the H5free_memory() call.
1473 */
1474 if(NULL == (info->retries[j] = (uint32_t *)H5MM_malloc(tot_size)))
1475 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
1476
1477 /* Copy the information */
1478 HDmemcpy(info->retries[j], file->shared->retries[i], tot_size);
1479 } /* end if */
1480
1481 /* Increment location in info->retries[] array */
1482 j++;
1483 break;
1484
1485 default:
1486 break;
1487 } /* end switch */
1488 } /* end for */
1489
1490 done:
1491 FUNC_LEAVE_API(ret_value)
1492 } /* end H5Fget_metadata_read_retry_info() */
1493
1494
1495 /*-------------------------------------------------------------------------
1496 * Function: H5Fget_free_sections
1497 *
1498 * Purpose: To get free-space section information for free-space manager with
1499 * TYPE that is associated with file FILE_ID.
1500 * If SECT_INFO is null, this routine returns the total # of free-space
1501 * sections.
1502 *
1503 * Return: Success: non-negative, the total # of free space sections
1504 * Failure: negative
1505 *
1506 * Programmer: Vailin Choi; July 1st, 2009
1507 *
1508 *-------------------------------------------------------------------------
1509 */
1510 ssize_t
H5Fget_free_sections(hid_t file_id,H5F_mem_t type,size_t nsects,H5F_sect_info_t * sect_info)1511 H5Fget_free_sections(hid_t file_id, H5F_mem_t type, size_t nsects,
1512 H5F_sect_info_t *sect_info/*out*/)
1513 {
1514 H5F_t *file; /* Top file in mount hierarchy */
1515 ssize_t ret_value; /* Return value */
1516
1517 FUNC_ENTER_API(FAIL)
1518 H5TRACE4("Zs", "iFmzx", file_id, type, nsects, sect_info);
1519
1520 /* Check args */
1521 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1522 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1523 if(sect_info && nsects == 0)
1524 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "nsects must be > 0")
1525
1526 /* Go get the free-space section information in the file */
1527 if((ret_value = H5MF_get_free_sections(file, H5AC_ind_read_dxpl_id, type, nsects, sect_info)) < 0)
1528 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file")
1529
1530 done:
1531 FUNC_LEAVE_API(ret_value)
1532 } /* end H5Fget_free_sections() */
1533
1534
1535 /*-------------------------------------------------------------------------
1536 * Function: H5Fclear_elink_file_cache
1537 *
1538 * Purpose: Releases the external file cache associated with the
1539 * provided file, potentially closing any cached files
1540 * unless they are held open from somewhere\ else.
1541 *
1542 * Return: Success: non-negative
1543 * Failure: negative
1544 *
1545 * Programmer: Neil Fortner; December 30, 2010
1546 *
1547 *-------------------------------------------------------------------------
1548 */
1549 herr_t
H5Fclear_elink_file_cache(hid_t file_id)1550 H5Fclear_elink_file_cache(hid_t file_id)
1551 {
1552 H5F_t *file; /* File */
1553 herr_t ret_value = SUCCEED; /* Return value */
1554
1555 FUNC_ENTER_API(FAIL)
1556 H5TRACE1("e", "i", file_id);
1557
1558 /* Check args */
1559 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1560 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
1561
1562 /* Release the EFC */
1563 if(file->shared->efc)
1564 if(H5F_efc_release(file->shared->efc) < 0)
1565 HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "can't release external file cache")
1566
1567 done:
1568 FUNC_LEAVE_API(ret_value)
1569 } /* end H5Fclear_elink_file_cache() */
1570
1571
1572 /*-------------------------------------------------------------------------
1573 * Function: H5Fstart_swmr_write
1574 *
1575 * Purpose: To enable SWMR writing mode for the file
1576 * 1) Refresh opened objects: part 1
1577 * 2) Flush & reset accumulator
1578 * 3) Mark the file in SWMR writing mode
1579 * 4) Set metadata read attempts and retries info
1580 * 5) Disable accumulator
1581 * 6) Evict all cache entries except the superblock
1582 * 7) Refresh opened objects (part 2)
1583 * 8) Unlock the file
1584 *
1585 * Pre-conditions:
1586 * 1) The file being opened has v3 superblock
1587 * 2) The file is opened with H5F_ACC_RDWR
1588 * 3) The file is not already marked for SWMR writing
1589 * 4) Current implementaion for opened objects:
1590 * --only allow datasets and groups without attributes
1591 * --disallow named datatype with/without attributes
1592 * --disallow opened attributes attached to objects
1593 * NOTE: Currently, only opened groups and datasets are allowed
1594 * when enabling SWMR via H5Fstart_swmr_write().
1595 * Will later implement a different approach--
1596 * set up flush dependency/proxy even for file opened without
1597 * SWMR to resolve issues with opened objects.
1598 *
1599 * Return: Non-negative on success/negative on failure
1600 *
1601 * Programmer:
1602 * Vailin Choi; Feb 2014
1603 *
1604 *-------------------------------------------------------------------------
1605 */
1606 herr_t
H5Fstart_swmr_write(hid_t file_id)1607 H5Fstart_swmr_write(hid_t file_id)
1608 {
1609 hbool_t ci_load = FALSE; /* whether MDC ci load requested */
1610 hbool_t ci_write = FALSE; /* whether MDC CI write requested */
1611 H5F_t *file = NULL; /* File info */
1612 size_t grp_dset_count=0; /* # of open objects: groups & datasets */
1613 size_t nt_attr_count=0; /* # of opened named datatypes + opened attributes */
1614 hid_t *obj_ids=NULL; /* List of ids */
1615 H5G_loc_t *obj_glocs=NULL; /* Group location of the object */
1616 H5O_loc_t *obj_olocs=NULL; /* Object location */
1617 H5G_name_t *obj_paths=NULL; /* Group hierarchy path */
1618 size_t u; /* Local index variable */
1619 hbool_t setup = FALSE; /* Boolean flag to indicate whether SWMR setting is enabled */
1620 H5F_io_info2_t fio_info; /* I/O info for operation */
1621 herr_t ret_value = SUCCEED; /* Return value */
1622
1623 FUNC_ENTER_API(FAIL)
1624 H5TRACE1("e", "i", file_id);
1625
1626 /* check args */
1627 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1628 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
1629
1630 /* Should have write permission */
1631 if((H5F_INTENT(file) & H5F_ACC_RDWR) == 0)
1632 HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "no write intent on file")
1633
1634 if(file->shared->sblock->super_vers < HDF5_SUPERBLOCK_VERSION_3)
1635 HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "file superblock version should be at least 3")
1636 HDassert(file->shared->latest_flags == H5F_LATEST_ALL_FLAGS);
1637
1638 /* Should not be marked for SWMR writing mode already */
1639 if(file->shared->sblock->status_flags & H5F_SUPER_SWMR_WRITE_ACCESS)
1640 HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "file already in SWMR writing mode")
1641
1642 HDassert(file->shared->sblock->status_flags & H5F_SUPER_WRITE_ACCESS);
1643
1644 /* Check to see if cache image is enabled. Fail if so */
1645 if(H5C_cache_image_status(file, &ci_load, &ci_write) < 0)
1646 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get MDC cache image status")
1647 if(ci_load || ci_write )
1648 HGOTO_ERROR(H5E_FILE, H5E_UNSUPPORTED, FAIL, "can't have both SWMR and MDC cache image")
1649
1650 /* Flush data buffers */
1651 if(H5F__flush(file, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id, FALSE) < 0)
1652 HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush file's cached information")
1653
1654 /* Get the # of opened named datatypes and attributes */
1655 if(H5F_get_obj_count(file, H5F_OBJ_DATATYPE|H5F_OBJ_ATTR, FALSE, &nt_attr_count) < 0)
1656 HGOTO_ERROR(H5E_INTERNAL, H5E_BADITER, FAIL, "H5F_get_obj_count failed")
1657 if(nt_attr_count)
1658 HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "named datatypes and/or attributes opened in the file")
1659
1660 /* Get the # of opened datasets and groups */
1661 if(H5F_get_obj_count(file, H5F_OBJ_GROUP|H5F_OBJ_DATASET, FALSE, &grp_dset_count) < 0)
1662 HGOTO_ERROR(H5E_INTERNAL, H5E_BADITER, FAIL, "H5F_get_obj_count failed")
1663
1664 if(grp_dset_count) {
1665 /* Allocate space for group and object locations */
1666 if((obj_ids = (hid_t *) H5MM_malloc(grp_dset_count * sizeof(hid_t))) == NULL)
1667 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, FAIL, "can't allocate buffer for hid_t")
1668 if((obj_glocs = (H5G_loc_t *) H5MM_malloc(grp_dset_count * sizeof(H5G_loc_t))) == NULL)
1669 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, FAIL, "can't allocate buffer for H5G_loc_t")
1670 if((obj_olocs = (H5O_loc_t *) H5MM_malloc(grp_dset_count * sizeof(H5O_loc_t))) == NULL)
1671 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, FAIL, "can't allocate buffer for H5O_loc_t")
1672 if((obj_paths = (H5G_name_t *) H5MM_malloc(grp_dset_count * sizeof(H5G_name_t))) == NULL)
1673 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, FAIL, "can't allocate buffer for H5G_name_t")
1674
1675 /* Get the list of opened object ids (groups & datasets) */
1676 if(H5F_get_obj_ids(file, H5F_OBJ_GROUP|H5F_OBJ_DATASET, grp_dset_count, obj_ids, FALSE, &grp_dset_count) < 0)
1677 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "H5F_get_obj_ids failed")
1678
1679 /* Refresh opened objects (groups, datasets) in the file */
1680 for(u = 0; u < grp_dset_count; u++) {
1681 H5O_loc_t *oloc; /* object location */
1682 H5G_loc_t tmp_loc;
1683
1684 /* Set up the id's group location */
1685 obj_glocs[u].oloc = &obj_olocs[u];
1686 obj_glocs[u].path = &obj_paths[u];
1687 H5G_loc_reset(&obj_glocs[u]);
1688
1689 /* get the id's object location */
1690 if((oloc = H5O_get_loc(obj_ids[u])) == NULL)
1691 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an object")
1692
1693 /* Make deep local copy of object's location information */
1694 H5G_loc(obj_ids[u], &tmp_loc);
1695 H5G_loc_copy(&obj_glocs[u], &tmp_loc, H5_COPY_DEEP);
1696
1697 /* Close the object */
1698 if(H5I_dec_ref(obj_ids[u]) < 0)
1699 HGOTO_ERROR(H5E_ATOM, H5E_CANTCLOSEOBJ, FAIL, "decrementing object ID failed")
1700 } /* end for */
1701 } /* end if */
1702
1703 /* Set up I/O info for operation */
1704 fio_info.f = file;
1705 if(NULL == (fio_info.meta_dxpl = (H5P_genplist_t *)H5I_object(H5AC_ind_read_dxpl_id)))
1706 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get property list")
1707 if(NULL == (fio_info.raw_dxpl = (H5P_genplist_t *)H5I_object(H5AC_rawdata_dxpl_id)))
1708 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get property list")
1709
1710 /* Flush and reset the accumulator */
1711 if(H5F__accum_reset(&fio_info, TRUE) < 0)
1712 HGOTO_ERROR(H5E_IO, H5E_CANTRESET, FAIL, "can't reset accumulator")
1713
1714 /* Turn on SWMR write in shared file open flags */
1715 file->shared->flags |= H5F_ACC_SWMR_WRITE;
1716
1717 /* Mark the file in SWMR writing mode */
1718 file->shared->sblock->status_flags |= H5F_SUPER_SWMR_WRITE_ACCESS;
1719
1720 /* Set up metadata read attempts */
1721 file->shared->read_attempts = H5F_SWMR_METADATA_READ_ATTEMPTS;
1722
1723 /* Initialize "retries" and "retries_nbins" */
1724 if(H5F_set_retries(file) < 0)
1725 HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "can't set retries and retries_nbins")
1726
1727 /* Turn off usage of accumulator */
1728 file->shared->feature_flags &= ~(unsigned)H5FD_FEAT_ACCUMULATE_METADATA;
1729 if(H5FD_set_feature_flags(file->shared->lf, file->shared->feature_flags) < 0)
1730 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set feature_flags in VFD")
1731
1732 setup = TRUE;
1733
1734 /* Mark superblock as dirty */
1735 if(H5F_super_dirty(file) < 0)
1736 HGOTO_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
1737
1738 /* Flush the superblock */
1739 if(H5F_flush_tagged_metadata(file, H5AC__SUPERBLOCK_TAG, H5AC_ind_read_dxpl_id) < 0)
1740 HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush superblock")
1741
1742 /* Evict all flushed entries in the cache except the pinned superblock */
1743 if(H5F__evict_cache_entries(file, H5AC_ind_read_dxpl_id) < 0)
1744 HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to evict file's cached information")
1745
1746 /* Refresh (reopen) the objects (groups & datasets) in the file */
1747 for(u = 0; u < grp_dset_count; u++)
1748 if(H5O_refresh_metadata_reopen(obj_ids[u], &obj_glocs[u], H5AC_ind_read_dxpl_id, TRUE) < 0)
1749 HGOTO_ERROR(H5E_ATOM, H5E_CLOSEERROR, FAIL, "can't refresh-close object")
1750
1751 /* Unlock the file */
1752 if(H5FD_unlock(file->shared->lf) < 0)
1753 HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to unlock the file")
1754
1755 done:
1756 if(ret_value < 0 && setup) {
1757 HDassert(file);
1758
1759 /* Re-enable accumulator */
1760 file->shared->feature_flags |= (unsigned)H5FD_FEAT_ACCUMULATE_METADATA;
1761 if(H5FD_set_feature_flags(file->shared->lf, file->shared->feature_flags) < 0)
1762 HDONE_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set feature_flags in VFD")
1763
1764 /* Reset the # of read attempts */
1765 file->shared->read_attempts = H5F_METADATA_READ_ATTEMPTS;
1766 if(H5F_set_retries(file) < 0)
1767 HDONE_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "can't set retries and retries_nbins")
1768
1769 /* Un-set H5F_ACC_SWMR_WRITE in shared open flags */
1770 file->shared->flags &= ~H5F_ACC_SWMR_WRITE;
1771
1772 /* Unmark the file: not in SWMR writing mode */
1773 file->shared->sblock->status_flags &= (uint8_t)(~H5F_SUPER_SWMR_WRITE_ACCESS);
1774
1775 /* Mark superblock as dirty */
1776 if(H5F_super_dirty(file) < 0)
1777 HDONE_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
1778
1779 /* Flush the superblock */
1780 if(H5F_flush_tagged_metadata(file, H5AC__SUPERBLOCK_TAG, H5AC_ind_read_dxpl_id) < 0)
1781 HDONE_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush superblock")
1782 } /* end if */
1783
1784 /* Free memory */
1785 if(obj_ids)
1786 H5MM_xfree(obj_ids);
1787 if(obj_glocs)
1788 H5MM_xfree(obj_glocs);
1789 if(obj_olocs)
1790 H5MM_xfree(obj_olocs);
1791 if(obj_paths)
1792 H5MM_xfree(obj_paths);
1793
1794 FUNC_LEAVE_API(ret_value)
1795 } /* end H5Fstart_swmr_write() */
1796
1797
1798 /*-------------------------------------------------------------------------
1799 * Function: H5Fstart_mdc_logging
1800 *
1801 * Purpose: Start metadata cache logging operations for a file.
1802 * - Logging must have been set up via the fapl.
1803 *
1804 * Return: Non-negative on success/Negative on errors
1805 *
1806 *-------------------------------------------------------------------------
1807 */
1808 herr_t
H5Fstart_mdc_logging(hid_t file_id)1809 H5Fstart_mdc_logging(hid_t file_id)
1810 {
1811 H5F_t *file; /* File info */
1812 herr_t ret_value = SUCCEED; /* Return value */
1813
1814 FUNC_ENTER_API(FAIL)
1815 H5TRACE1("e", "i", file_id);
1816
1817 /* Sanity check */
1818 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1819 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "hid_t identifier is not a file ID")
1820
1821 /* Call mdc logging function */
1822 if(H5C_start_logging(file->shared->cache) < 0)
1823 HGOTO_ERROR(H5E_FILE, H5E_LOGFAIL, FAIL, "unable to start mdc logging")
1824
1825 done:
1826 FUNC_LEAVE_API(ret_value)
1827 } /* H5Fstart_mdc_logging() */
1828
1829
1830 /*-------------------------------------------------------------------------
1831 * Function: H5Fstop_mdc_logging
1832 *
1833 * Purpose: Stop metadata cache logging operations for a file.
1834 * - Does not close the log file.
1835 * - Logging must have been set up via the fapl.
1836 *
1837 * Return: Non-negative on success/Negative on errors
1838 *
1839 *-------------------------------------------------------------------------
1840 */
1841 herr_t
H5Fstop_mdc_logging(hid_t file_id)1842 H5Fstop_mdc_logging(hid_t file_id)
1843 {
1844 H5F_t *file; /* File info */
1845 herr_t ret_value = SUCCEED; /* Return value */
1846
1847 FUNC_ENTER_API(FAIL)
1848 H5TRACE1("e", "i", file_id);
1849
1850 /* Sanity check */
1851 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1852 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "hid_t identifier is not a file ID")
1853
1854 /* Call mdc logging function */
1855 if(H5C_stop_logging(file->shared->cache) < 0)
1856 HGOTO_ERROR(H5E_FILE, H5E_LOGFAIL, FAIL, "unable to stop mdc logging")
1857
1858 done:
1859 FUNC_LEAVE_API(ret_value)
1860 } /* H5Fstop_mdc_logging() */
1861
1862
1863 /*-------------------------------------------------------------------------
1864 * Function: H5Fget_mdc_logging_status
1865 *
1866 * Purpose: Get the logging flags. is_enabled determines if logging was
1867 * set up via the fapl. is_currently_logging determines if
1868 * log messages are being recorded at this time.
1869 *
1870 * Return: Non-negative on success/Negative on errors
1871 *
1872 *-------------------------------------------------------------------------
1873 */
1874 herr_t
H5Fget_mdc_logging_status(hid_t file_id,hbool_t * is_enabled,hbool_t * is_currently_logging)1875 H5Fget_mdc_logging_status(hid_t file_id, hbool_t *is_enabled,
1876 hbool_t *is_currently_logging)
1877 {
1878 H5F_t *file; /* File info */
1879 herr_t ret_value = SUCCEED; /* Return value */
1880
1881 FUNC_ENTER_API(FAIL)
1882 H5TRACE3("e", "i*b*b", file_id, is_enabled, is_currently_logging);
1883
1884 /* Sanity check */
1885 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1886 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "hid_t identifier is not a file ID")
1887
1888 /* Call mdc logging function */
1889 if(H5C_get_logging_status(file->shared->cache, is_enabled, is_currently_logging) < 0)
1890 HGOTO_ERROR(H5E_FILE, H5E_LOGFAIL, FAIL, "unable to get logging status")
1891
1892 done:
1893 FUNC_LEAVE_API(ret_value)
1894 } /* H5Fget_mdc_logging_status() */
1895
1896
1897 /*-------------------------------------------------------------------------
1898 * Function: H5Fset_latest_format
1899 *
1900 * Purpose: Enable switching the "latest format" flag while a file is open.
1901 *
1902 * Return: Non-negative on success/Negative on failure
1903 *
1904 * Programmer: Quincey Koziol
1905 * Monday, September 21, 2015
1906 *-------------------------------------------------------------------------
1907 */
1908 herr_t
H5Fset_latest_format(hid_t file_id,hbool_t latest_format)1909 H5Fset_latest_format(hid_t file_id, hbool_t latest_format)
1910 {
1911 H5F_t *f; /* File */
1912 unsigned latest_flags; /* Latest format flags for file */
1913 herr_t ret_value = SUCCEED; /* Return value */
1914
1915 FUNC_ENTER_API(FAIL)
1916 H5TRACE2("e", "ib", file_id, latest_format);
1917
1918 /* Check args */
1919 if(NULL == (f = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
1920 HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "not a file ID")
1921
1922 /* Check if the value is changing */
1923 latest_flags = H5F_USE_LATEST_FLAGS(f, H5F_LATEST_ALL_FLAGS);
1924 if(latest_format != (H5F_LATEST_ALL_FLAGS == latest_flags)) {
1925 /* Call the flush routine, for this file */
1926 if(H5F__flush(f, H5AC_ind_read_dxpl_id, H5AC_rawdata_dxpl_id, FALSE) < 0)
1927 HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush file's cached information")
1928
1929 /* Toggle the 'latest format' flag */
1930 H5F_SET_LATEST_FLAGS(f, latest_format ? H5F_LATEST_ALL_FLAGS : 0);
1931 } /* end if */
1932
1933 done:
1934 FUNC_LEAVE_API(ret_value)
1935 } /* end H5Fset_latest_format() */
1936
1937
1938 /*-------------------------------------------------------------------------
1939 * Function: H5Fformat_convert_super (Internal)
1940 *
1941 * Purpose: Downgrade the superblock version to v2 and
1942 * downgrade persistent file space to non-persistent
1943 * for 1.8 library.
1944 *
1945 * Return: Non-negative on success/Negative on failure
1946 *
1947 * Programmer: Vailin Choi
1948 * Jan 2016
1949 *
1950 *-------------------------------------------------------------------------
1951 */
1952 herr_t
H5Fformat_convert(hid_t fid)1953 H5Fformat_convert(hid_t fid)
1954 {
1955 herr_t ret_value = SUCCEED; /* Return value */
1956
1957 FUNC_ENTER_API(FAIL)
1958 H5TRACE1("e", "i", fid);
1959
1960 if(H5I_FILE == H5I_get_type(fid)) {
1961 H5F_t *f; /* File to flush */
1962 hbool_t mark_dirty = FALSE;
1963
1964 /* Get file object */
1965 if(NULL == (f = (H5F_t *)H5I_object(fid)))
1966 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier")
1967
1968 /* Check if the superblock should be downgraded */
1969 if(f->shared->sblock->super_vers > HDF5_SUPERBLOCK_VERSION_V18_LATEST) {
1970 f->shared->sblock->super_vers = HDF5_SUPERBLOCK_VERSION_V18_LATEST;
1971 mark_dirty = TRUE;
1972 } /* end if */
1973
1974 /* Check for persistent freespace manager, which needs to be downgraded */
1975 if(!(f->shared->fs_strategy == H5F_FILE_SPACE_STRATEGY_DEF &&
1976 f->shared->fs_persist == H5F_FREE_SPACE_PERSIST_DEF &&
1977 f->shared->fs_threshold == H5F_FREE_SPACE_THRESHOLD_DEF &&
1978 f->shared->fs_page_size == H5F_FILE_SPACE_PAGE_SIZE_DEF)) {
1979 /* Check to remove free-space manager info message from superblock extension */
1980 if(H5F_addr_defined(f->shared->sblock->ext_addr))
1981 if(H5F_super_ext_remove_msg(f, H5AC_ind_read_dxpl_id, H5O_FSINFO_ID) < 0)
1982 HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "error in removing message from superblock extension")
1983
1984 /* Close freespace manager */
1985 if(H5MF_try_close(f, H5AC_ind_read_dxpl_id) < 0)
1986 HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "unable to free free-space address")
1987
1988 /* Set non-persistent freespace manager */
1989 f->shared->fs_strategy = H5F_FILE_SPACE_STRATEGY_DEF;
1990 f->shared->fs_persist = H5F_FREE_SPACE_PERSIST_DEF;
1991 f->shared->fs_threshold = H5F_FREE_SPACE_THRESHOLD_DEF;
1992 f->shared->fs_page_size = H5F_FILE_SPACE_PAGE_SIZE_DEF;
1993
1994 /* Indicate that the superblock should be marked dirty */
1995 mark_dirty = TRUE;
1996 } /* end if */
1997
1998 /* Check if we should mark the superblock dirty */
1999 if(mark_dirty)
2000 /* Mark superblock as dirty */
2001 if(H5F_super_dirty(f) < 0)
2002 HGOTO_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
2003 } /* end if */
2004 else
2005 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object")
2006
2007 done:
2008 FUNC_LEAVE_API(ret_value)
2009 } /* end H5Fformat_convert() */
2010
2011
2012 /*-------------------------------------------------------------------------
2013 * Function: H5Freset_page_buffering_stats
2014 *
2015 * Purpose: Resets statistics for the page buffer layer.
2016 *
2017 * Return: Success: SUCCEED
2018 * Failure: FAIL
2019 *
2020 * Programmer: Mohamad Chaarawi
2021 *
2022 *-------------------------------------------------------------------------
2023 */
2024 herr_t
H5Freset_page_buffering_stats(hid_t file_id)2025 H5Freset_page_buffering_stats(hid_t file_id)
2026 {
2027 H5F_t *file; /* File to reset stats on */
2028 herr_t ret_value = SUCCEED; /* Return value */
2029
2030 FUNC_ENTER_API(FAIL)
2031 H5TRACE1("e", "i", file_id);
2032
2033 /* Check args */
2034 if(NULL == (file = (H5F_t *)H5I_object(file_id)))
2035 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier")
2036 if(NULL == file->shared->page_buf)
2037 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "page buffering not enabled on file")
2038
2039 /* Reset the statistics */
2040 if(H5PB_reset_stats(file->shared->page_buf) < 0)
2041 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't reset stats for page buffering")
2042
2043 done:
2044 FUNC_LEAVE_API(ret_value)
2045 } /* H5Freset_page_buffering_stats() */
2046
2047
2048 /*-------------------------------------------------------------------------
2049 * Function: H5Fget_page_buffering_stats
2050 *
2051 * Purpose: Retrieves statistics for the page buffer layer.
2052 *
2053 * Return: Success: SUCCEED
2054 * Failure: FAIL
2055 *
2056 * Programmer: Mohamad Chaarawi
2057 *
2058 *-------------------------------------------------------------------------
2059 */
2060 herr_t
H5Fget_page_buffering_stats(hid_t file_id,unsigned accesses[2],unsigned hits[2],unsigned misses[2],unsigned evictions[2],unsigned bypasses[2])2061 H5Fget_page_buffering_stats(hid_t file_id, unsigned accesses[2], unsigned hits[2],
2062 unsigned misses[2], unsigned evictions[2], unsigned bypasses[2])
2063 {
2064 H5F_t *file; /* File object for file ID */
2065 herr_t ret_value = SUCCEED; /* Return value */
2066
2067 FUNC_ENTER_API(FAIL)
2068 H5TRACE6("e", "i*Iu*Iu*Iu*Iu*Iu", file_id, accesses, hits, misses, evictions,
2069 bypasses);
2070
2071 /* Check args */
2072 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
2073 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
2074 if(NULL == file->shared->page_buf)
2075 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "page buffering not enabled on file")
2076 if(NULL == accesses || NULL == hits || NULL == misses || NULL == evictions || NULL == bypasses)
2077 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "NULL input parameters for stats")
2078
2079 /* Get the statistics */
2080 if(H5PB_get_stats(file->shared->page_buf, accesses, hits, misses, evictions, bypasses) < 0)
2081 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve stats for page buffering")
2082
2083 done:
2084 FUNC_LEAVE_API(ret_value)
2085 } /* H5Fget_page_buffering_stats() */
2086
2087
2088 /*-------------------------------------------------------------------------
2089 * Function: H5Fget_mdc_image_info
2090 *
2091 * Purpose: Retrieves the image_addr and image_len for the cache image in the file.
2092 * image_addr: --base address of the on disk metadata cache image
2093 * --HADDR_UNDEF if no cache image
2094 * image_len: --size of the on disk metadata cache image
2095 * --zero if no cache image
2096 *
2097 * Return: Success: SUCCEED
2098 * Failure: FAIL
2099 *
2100 * Programmer: Vailin Choi; March 2017
2101 *
2102 *-------------------------------------------------------------------------
2103 */
2104 herr_t
H5Fget_mdc_image_info(hid_t file_id,haddr_t * image_addr,hsize_t * image_len)2105 H5Fget_mdc_image_info(hid_t file_id, haddr_t *image_addr, hsize_t *image_len)
2106 {
2107 H5F_t *file; /* File object for file ID */
2108 herr_t ret_value = SUCCEED; /* Return value */
2109
2110 FUNC_ENTER_API(FAIL)
2111 H5TRACE3("e", "i*a*h", file_id, image_addr, image_len);
2112
2113 /* Check args */
2114 if(NULL == (file = (H5F_t *)H5I_object_verify(file_id, H5I_FILE)))
2115 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
2116 if(NULL == image_addr || NULL == image_len)
2117 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "NULL image addr or image len")
2118
2119 /* Go get the address and size of the cache image */
2120 if(H5AC_get_mdc_image_info(file->shared->cache, image_addr, image_len) < 0)
2121 HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "can't retrieve cache image info")
2122
2123 done:
2124 FUNC_LEAVE_API(ret_value)
2125 } /* H5Fget_mdc_image_info() */
2126
2127