Coverage Report

Created: 2026-12-04 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5VLnative_file.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*
14
 * Purpose:     File callbacks for the native VOL connector
15
 *
16
 */
17
18
/****************/
19
/* Module Setup */
20
/****************/
21
22
#define H5F_FRIEND /* Suppress error about including H5Fpkg    */
23
24
/***********/
25
/* Headers */
26
/***********/
27
#include "H5private.h"   /* Generic Functions                        */
28
#include "H5ACprivate.h" /* Metadata cache                           */
29
#include "H5Cprivate.h"  /* Cache                                    */
30
#include "H5Eprivate.h"  /* Error handling                           */
31
#include "H5Fpkg.h"      /* Files                                    */
32
#include "H5FLprivate.h" /* Free Lists                               */
33
#include "H5Iprivate.h"  /* IDs                                      */
34
#include "H5MFprivate.h" /* File memory management                   */
35
#include "H5Pprivate.h"  /* Property lists                           */
36
#include "H5PBprivate.h" /* Page buffering                           */
37
#include "H5VLprivate.h" /* Virtual Object Layer                     */
38
39
#include "H5VLnative_private.h" /* Native VOL connector                     */
40
41
/****************/
42
/* Local Macros */
43
/****************/
44
45
/******************/
46
/* Local Typedefs */
47
/******************/
48
49
/********************/
50
/* Local Prototypes */
51
/********************/
52
53
/*********************/
54
/* Package Variables */
55
/*********************/
56
57
/*****************************/
58
/* Library Private Variables */
59
/*****************************/
60
61
/*******************/
62
/* Local Variables */
63
/*******************/
64
65
/*-------------------------------------------------------------------------
66
 * Function:    H5VL__native_file_create
67
 *
68
 * Purpose:     Handles the file create callback
69
 *
70
 * Return:      Success:    file pointer
71
 *              Failure:    NULL
72
 *
73
 *-------------------------------------------------------------------------
74
 */
75
void *
76
H5VL__native_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id,
77
                         hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
78
0
{
79
0
    H5F_t *new_file  = NULL;
80
0
    void  *ret_value = NULL;
81
82
0
    FUNC_ENTER_PACKAGE
83
84
    /* Adjust bit flags by turning on the creation bit and making sure that
85
     * the EXCL or TRUNC bit is set.  All newly-created files are opened for
86
     * reading and writing.
87
     */
88
0
    if (0 == (flags & (H5F_ACC_EXCL | H5F_ACC_TRUNC)))
89
0
        flags |= H5F_ACC_EXCL; /* default */
90
0
    flags |= H5F_ACC_RDWR | H5F_ACC_CREAT;
91
92
    /* Create the file */
93
0
    if (H5F_open(false, &new_file, name, flags, fcpl_id, fapl_id) < 0)
94
0
        HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to create file");
95
0
    new_file->id_exists = true;
96
97
0
    ret_value = (void *)new_file;
98
99
0
done:
100
0
    if (NULL == ret_value && new_file)
101
0
        if (H5F__close(new_file) < 0)
102
0
            HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, NULL, "problems closing file");
103
104
0
    FUNC_LEAVE_NOAPI(ret_value)
105
0
} /* end H5VL__native_file_create() */
106
107
/*-------------------------------------------------------------------------
108
 * Function:    H5VL__native_file_open
109
 *
110
 * Purpose:     Handles the file open callback
111
 *
112
 * Return:      Success:    file pointer
113
 *              Failure:    NULL
114
 *
115
 *-------------------------------------------------------------------------
116
 */
117
void *
118
H5VL__native_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t H5_ATTR_UNUSED dxpl_id,
119
                       void H5_ATTR_UNUSED **req)
120
2.45k
{
121
2.45k
    H5F_t *new_file  = NULL;
122
2.45k
    void  *ret_value = NULL;
123
124
2.45k
    FUNC_ENTER_PACKAGE
125
126
    /* Open the file */
127
2.45k
    if (H5F_open(false, &new_file, name, flags, H5P_FILE_CREATE_DEFAULT, fapl_id) < 0)
128
603
        HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file");
129
1.84k
    new_file->id_exists = true;
130
131
1.84k
    ret_value = (void *)new_file;
132
133
2.45k
done:
134
2.45k
    if (NULL == ret_value && new_file && H5F_try_close(new_file, NULL) < 0)
135
0
        HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, NULL, "problems closing file");
136
137
2.45k
    FUNC_LEAVE_NOAPI(ret_value)
138
2.45k
} /* end H5VL__native_file_open() */
139
140
/*-------------------------------------------------------------------------
141
 * Function:    H5VL__native_file_get
142
 *
143
 * Purpose:     Handles the file get callback
144
 *
145
 * Return:      SUCCEED/FAIL
146
 *
147
 *-------------------------------------------------------------------------
148
 */
149
herr_t
150
H5VL__native_file_get(void *obj, H5VL_file_get_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id,
151
                      void H5_ATTR_UNUSED **req)
152
15
{
153
15
    H5F_t *f         = NULL;    /* File struct */
154
15
    herr_t ret_value = SUCCEED; /* Return value */
155
156
15
    FUNC_ENTER_PACKAGE
157
158
15
    switch (args->op_type) {
159
        /* "get container info" */
160
15
        case H5VL_FILE_GET_CONT_INFO: {
161
15
            if (H5F__get_cont_info((H5F_t *)obj, args->args.get_cont_info.info) < 0)
162
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get file container info");
163
164
15
            break;
165
15
        }
166
167
        /* H5Fget_access_plist */
168
15
        case H5VL_FILE_GET_FAPL: {
169
0
            if ((args->args.get_fapl.fapl_id = H5F_get_access_plist((H5F_t *)obj, true)) < 0)
170
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get file access property list");
171
172
0
            break;
173
0
        }
174
175
        /* H5Fget_create_plist */
176
0
        case H5VL_FILE_GET_FCPL: {
177
0
            H5P_genplist_t *plist; /* Property list */
178
179
0
            f = (H5F_t *)obj;
180
0
            if (NULL == (plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id)))
181
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list");
182
183
            /* Create the property list object to return */
184
0
            if ((args->args.get_fcpl.fcpl_id = H5P_copy_plist(plist, true)) < 0)
185
0
                HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "unable to copy file creation properties");
186
187
0
            break;
188
0
        }
189
190
        /* H5Fget_intent */
191
0
        case H5VL_FILE_GET_INTENT: {
192
0
            f = (H5F_t *)obj;
193
194
            /* HDF5 uses some flags internally that users don't know about.
195
             * Simplify things for them so that they only get either H5F_ACC_RDWR
196
             * or H5F_ACC_RDONLY and any SWMR flags.
197
             */
198
0
            if (H5F_INTENT(f) & H5F_ACC_RDWR) {
199
0
                *args->args.get_intent.flags = H5F_ACC_RDWR;
200
201
                /* Check for SWMR write access on the file */
202
0
                if (H5F_INTENT(f) & H5F_ACC_SWMR_WRITE)
203
0
                    *args->args.get_intent.flags |= H5F_ACC_SWMR_WRITE;
204
0
            } /* end if */
205
0
            else {
206
0
                *args->args.get_intent.flags = H5F_ACC_RDONLY;
207
208
                /* Check for SWMR read access on the file */
209
0
                if (H5F_INTENT(f) & H5F_ACC_SWMR_READ)
210
0
                    *args->args.get_intent.flags |= H5F_ACC_SWMR_READ;
211
0
            } /* end else */
212
213
0
            break;
214
0
        }
215
216
        /* H5Fget_fileno */
217
0
        case H5VL_FILE_GET_FILENO: {
218
0
            unsigned long fileno = 0;
219
220
0
            H5F_GET_FILENO((H5F_t *)obj, fileno);
221
0
            *args->args.get_fileno.fileno = fileno;
222
223
0
            break;
224
0
        }
225
226
        /* H5Fget_name */
227
0
        case H5VL_FILE_GET_NAME: {
228
0
            H5VL_file_get_name_args_t *file_args = &args->args.get_name;
229
230
0
            if (H5VL_native_get_file_struct(obj, file_args->type, &f) < 0)
231
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object");
232
233
            /* Get length of file name */
234
0
            *file_args->file_name_len = strlen(H5F_OPEN_NAME(f));
235
236
            /* Populate buffer with name, if given */
237
0
            if (file_args->buf) {
238
0
                strncpy(file_args->buf, H5F_OPEN_NAME(f),
239
0
                        MIN(*file_args->file_name_len + 1, file_args->buf_size));
240
0
                if (*file_args->file_name_len >= file_args->buf_size)
241
0
                    file_args->buf[file_args->buf_size - 1] = '\0';
242
0
            } /* end if */
243
244
0
            break;
245
0
        }
246
247
        /* H5Fget_obj_count */
248
0
        case H5VL_FILE_GET_OBJ_COUNT: {
249
0
            if (H5F_get_obj_count((H5F_t *)obj, args->args.get_obj_count.types, true,
250
0
                                  args->args.get_obj_count.count) < 0)
251
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve object count");
252
253
0
            break;
254
0
        }
255
256
        /* H5Fget_obj_ids */
257
0
        case H5VL_FILE_GET_OBJ_IDS: {
258
0
            H5VL_file_get_obj_ids_args_t *file_args = &args->args.get_obj_ids;
259
260
0
            if (H5F_get_obj_ids((H5F_t *)obj, file_args->types, file_args->max_objs, file_args->oid_list,
261
0
                                true, file_args->count) < 0)
262
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve object IDs");
263
264
0
            break;
265
0
        }
266
267
0
        default:
268
0
            HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information");
269
15
    } /* end switch */
270
271
15
done:
272
15
    FUNC_LEAVE_NOAPI(ret_value)
273
15
} /* end H5VL__native_file_get() */
274
275
/*-------------------------------------------------------------------------
276
 * Function:    H5VL__native_file_specific
277
 *
278
 * Purpose:     Handles the file specific callback
279
 *
280
 * Return:      SUCCEED/FAIL
281
 *
282
 *-------------------------------------------------------------------------
283
 */
284
herr_t
285
H5VL__native_file_specific(void *obj, H5VL_file_specific_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id,
286
                           void H5_ATTR_UNUSED **req)
287
0
{
288
0
    herr_t ret_value = SUCCEED; /* Return value */
289
290
0
    FUNC_ENTER_PACKAGE
291
292
0
    switch (args->op_type) {
293
        /* H5Fflush */
294
0
        case H5VL_FILE_FLUSH: {
295
0
            H5F_t *f = NULL; /* File to flush */
296
297
            /* Get the file for the object */
298
0
            if (H5VL_native_get_file_struct(obj, args->args.flush.obj_type, &f) < 0)
299
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object");
300
301
            /* Nothing to do if the file is read only. This determination is
302
             * made at the shared open(2) flags level, implying that opening a
303
             * file twice, once for read-only and once for read-write, and then
304
             * calling H5Fflush() with the read-only handle, still causes data
305
             * to be flushed.
306
             */
307
0
            if (H5F_ACC_RDWR & H5F_INTENT(f)) {
308
                /* Flush other files, depending on scope */
309
0
                if (H5F_SCOPE_GLOBAL == args->args.flush.scope) {
310
                    /* Call the flush routine for mounted file hierarchies */
311
0
                    if (H5F_flush_mounts(f) < 0)
312
0
                        HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush mounted file hierarchy");
313
0
                } /* end if */
314
0
                else {
315
                    /* Call the flush routine, for this file */
316
0
                    if (H5F__flush(f) < 0)
317
0
                        HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL,
318
0
                                    "unable to flush file's cached information");
319
0
                } /* end else */
320
0
            }     /* end if */
321
322
0
            break;
323
0
        }
324
325
        /* H5Freopen */
326
0
        case H5VL_FILE_REOPEN: {
327
0
            H5F_t *new_file;
328
329
            /* Reopen the file through the VOL connector */
330
0
            if (NULL == (new_file = H5F__reopen((H5F_t *)obj)))
331
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to reopen file");
332
0
            new_file->id_exists = true;
333
334
            /* Set 'out' value */
335
0
            *args->args.reopen.file = new_file;
336
337
0
            break;
338
0
        }
339
340
        /* H5Fis_accessible */
341
0
        case H5VL_FILE_IS_ACCESSIBLE: {
342
0
            if (H5F__is_hdf5(args->args.is_accessible.filename, args->args.is_accessible.fapl_id,
343
0
                             args->args.is_accessible.accessible) < 0)
344
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "error in HDF5 file check");
345
346
0
            break;
347
0
        }
348
349
        /* H5Fdelete */
350
0
        case H5VL_FILE_DELETE: {
351
0
            if (H5F__delete(args->args.del.filename, args->args.del.fapl_id) < 0)
352
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTDELETEFILE, FAIL, "error in HDF5 file deletion");
353
354
0
            break;
355
0
        }
356
357
        /* Check if two files are the same */
358
0
        case H5VL_FILE_IS_EQUAL: {
359
0
            if (!obj || !args->args.is_equal.obj2)
360
0
                *args->args.is_equal.same_file = false;
361
0
            else
362
0
                *args->args.is_equal.same_file =
363
0
                    (((H5F_t *)obj)->shared == ((H5F_t *)args->args.is_equal.obj2)->shared);
364
365
0
            break;
366
0
        }
367
368
0
        default:
369
0
            HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation");
370
0
    } /* end switch */
371
372
0
done:
373
0
    FUNC_LEAVE_NOAPI(ret_value)
374
0
} /* end H5VL__native_file_specific() */
375
376
/*-------------------------------------------------------------------------
377
 * Function:    H5VL__native_file_optional
378
 *
379
 * Purpose:     Handles the file optional callback
380
 *
381
 * Return:      SUCCEED/FAIL
382
 *
383
 *-------------------------------------------------------------------------
384
 */
385
herr_t
386
H5VL__native_file_optional(void *obj, H5VL_optional_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id,
387
                           void H5_ATTR_UNUSED **req)
388
1.84k
{
389
1.84k
    H5F_t                            *f         = (H5F_t *)obj; /* File */
390
1.84k
    H5VL_native_file_optional_args_t *opt_args  = args->args;   /* Pointer to native operation's arguments */
391
1.84k
    herr_t                            ret_value = SUCCEED;      /* Return value */
392
393
1.84k
    FUNC_ENTER_PACKAGE
394
395
1.84k
    switch (args->op_type) {
396
        /* H5Fget_filesize */
397
0
        case H5VL_NATIVE_FILE_GET_SIZE: {
398
0
            haddr_t max_eof_eoa; /* Maximum of the EOA & EOF */
399
0
            haddr_t base_addr;   /* Base address for the file */
400
401
            /* Get the actual file size & base address */
402
0
            if (H5F__get_max_eof_eoa(f, &max_eof_eoa) < 0)
403
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "file can't get max eof/eoa ");
404
0
            base_addr = H5FD_get_base_addr(f->shared->lf);
405
406
            /* Convert relative base address for file to absolute address */
407
0
            *opt_args->get_size.size = (hsize_t)(max_eof_eoa + base_addr);
408
409
0
            break;
410
0
        }
411
412
        /* H5Fget_file_image */
413
0
        case H5VL_NATIVE_FILE_GET_FILE_IMAGE: {
414
0
            H5VL_native_file_get_file_image_t *gfi_args = &opt_args->get_file_image;
415
416
            /* Get file image */
417
0
            if (H5F__get_file_image(f, gfi_args->buf, gfi_args->buf_size, gfi_args->image_len) < 0)
418
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "get file image failed");
419
420
0
            break;
421
0
        }
422
423
        /* H5Fget_freespace */
424
0
        case H5VL_NATIVE_FILE_GET_FREE_SPACE: {
425
0
            H5VL_native_file_get_freespace_t *gfs_args = &opt_args->get_freespace;
426
427
            /* Get the actual amount of free space in the file */
428
0
            if (H5MF_get_freespace(f, gfs_args->size, NULL) < 0)
429
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file");
430
431
0
            break;
432
0
        }
433
434
        /* H5Fget_free_sections */
435
0
        case H5VL_NATIVE_FILE_GET_FREE_SECTIONS: {
436
0
            H5VL_native_file_get_free_sections_t *gfs_args = &opt_args->get_free_sections;
437
438
            /* Go get the free-space section information in the file */
439
0
            if (H5MF_get_free_sections(f, gfs_args->type, gfs_args->nsects, gfs_args->sect_info,
440
0
                                       gfs_args->sect_count) < 0)
441
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to check free space for file");
442
443
0
            break;
444
0
        }
445
446
        /* H5Fget_info1/2 */
447
0
        case H5VL_NATIVE_FILE_GET_INFO: {
448
0
            H5VL_native_file_get_info_t *gfi_args = &opt_args->get_info;
449
450
            /* Get the file struct. This call is careful to not return the file pointer
451
             * for the top file in a mount hierarchy.
452
             */
453
0
            if (H5VL_native_get_file_struct(obj, gfi_args->type, &f) < 0)
454
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "could not get a file struct");
455
456
            /* Get the file info */
457
0
            if (H5F__get_info(f, gfi_args->finfo) < 0)
458
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to retrieve file info");
459
460
0
            break;
461
0
        }
462
463
        /* H5Fget_mdc_config */
464
0
        case H5VL_NATIVE_FILE_GET_MDC_CONF: {
465
            /* Get the metadata cache configuration */
466
0
            if (H5AC_get_cache_auto_resize_config(f->shared->cache, opt_args->get_mdc_config.config) < 0)
467
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get metadata cache configuration");
468
469
0
            break;
470
0
        }
471
472
        /* H5Fget_mdc_hit_rate */
473
0
        case H5VL_NATIVE_FILE_GET_MDC_HR: {
474
            /* Get the current hit rate */
475
0
            if (H5AC_get_cache_hit_rate(f->shared->cache, opt_args->get_mdc_hit_rate.hit_rate) < 0)
476
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get metadata cache hit rate");
477
478
0
            break;
479
0
        }
480
481
        /* H5Fget_mdc_size */
482
0
        case H5VL_NATIVE_FILE_GET_MDC_SIZE: {
483
0
            H5VL_native_file_get_mdc_size_t *gms_args = &opt_args->get_mdc_size;
484
485
            /* Get the size data */
486
0
            if (H5AC_get_cache_size(f->shared->cache, gms_args->max_size, gms_args->min_clean_size,
487
0
                                    gms_args->cur_size, gms_args->cur_num_entries) < 0)
488
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get metadata cache size");
489
490
0
            break;
491
0
        }
492
493
        /* H5Fget_vfd_handle */
494
0
        case H5VL_NATIVE_FILE_GET_VFD_HANDLE: {
495
0
            H5VL_native_file_get_vfd_handle_t *gvh_args = &opt_args->get_vfd_handle;
496
497
            /* Retrieve the VFD handle for the file */
498
0
            if (H5F_get_vfd_handle(f, gvh_args->fapl_id, gvh_args->file_handle) < 0)
499
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve VFD handle");
500
501
0
            break;
502
0
        }
503
504
        /* H5Fclear_elink_file_cache */
505
0
        case H5VL_NATIVE_FILE_CLEAR_ELINK_CACHE: {
506
            /* Release the EFC */
507
0
            if (f->shared->efc)
508
0
                if (H5F__efc_release(f->shared->efc) < 0)
509
0
                    HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "can't release external file cache");
510
511
0
            break;
512
0
        }
513
514
        /* H5Freset_mdc_hit_rate_stats */
515
0
        case H5VL_NATIVE_FILE_RESET_MDC_HIT_RATE: {
516
            /* Reset the hit rate statistic */
517
0
            if (H5AC_reset_cache_hit_rate_stats(f->shared->cache) < 0)
518
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't reset cache hit rate");
519
520
0
            break;
521
0
        }
522
523
        /* H5Fset_mdc_config */
524
0
        case H5VL_NATIVE_FILE_SET_MDC_CONFIG: {
525
            /* Set the metadata cache configuration  */
526
0
            if (H5AC_set_cache_auto_resize_config(f->shared->cache, opt_args->set_mdc_config.config) < 0)
527
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set metadata cache configuration");
528
529
0
            break;
530
0
        }
531
532
        /* H5Fget_metadata_read_retry_info */
533
0
        case H5VL_NATIVE_FILE_GET_METADATA_READ_RETRY_INFO: {
534
0
            if (H5F_get_metadata_read_retry_info(f, opt_args->get_metadata_read_retry_info.info) < 0)
535
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get metadata read retry info");
536
537
0
            break;
538
0
        }
539
540
        /* H5Fstart_swmr_write */
541
0
        case H5VL_NATIVE_FILE_START_SWMR_WRITE: {
542
0
            if (H5F__start_swmr_write(f) < 0)
543
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't start SWMR write");
544
545
0
            break;
546
0
        }
547
548
        /* H5Fstart_mdc_logging */
549
0
        case H5VL_NATIVE_FILE_START_MDC_LOGGING: {
550
            /* Call mdc logging function */
551
0
            if (H5C_start_logging(f->shared->cache) < 0)
552
0
                HGOTO_ERROR(H5E_FILE, H5E_LOGGING, FAIL, "unable to start mdc logging");
553
554
0
            break;
555
0
        }
556
557
        /* H5Fstop_mdc_logging */
558
0
        case H5VL_NATIVE_FILE_STOP_MDC_LOGGING: {
559
            /* Call mdc logging function */
560
0
            if (H5C_stop_logging(f->shared->cache) < 0)
561
0
                HGOTO_ERROR(H5E_FILE, H5E_LOGGING, FAIL, "unable to stop mdc logging");
562
563
0
            break;
564
0
        }
565
566
        /* H5Fget_mdc_logging_status */
567
0
        case H5VL_NATIVE_FILE_GET_MDC_LOGGING_STATUS: {
568
0
            H5VL_native_file_get_mdc_logging_status_t *gmls_args = &opt_args->get_mdc_logging_status;
569
570
            /* Call mdc logging function */
571
0
            if (H5C_get_logging_status(f->shared->cache, gmls_args->is_enabled,
572
0
                                       gmls_args->is_currently_logging) < 0)
573
0
                HGOTO_ERROR(H5E_FILE, H5E_LOGGING, FAIL, "unable to get logging status");
574
575
0
            break;
576
0
        }
577
578
        /* H5Fformat_convert */
579
0
        case H5VL_NATIVE_FILE_FORMAT_CONVERT: {
580
            /* Convert the format */
581
0
            if (H5F__format_convert(f) < 0)
582
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTCONVERT, FAIL, "can't convert file format");
583
584
0
            break;
585
0
        }
586
587
        /* H5Freset_page_buffering_stats */
588
0
        case H5VL_NATIVE_FILE_RESET_PAGE_BUFFERING_STATS: {
589
            /* Sanity check */
590
0
            if (NULL == f->shared->page_buf)
591
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "page buffering not enabled on file");
592
593
            /* Reset the statistics */
594
0
            if (H5PB_reset_stats(f->shared->page_buf) < 0)
595
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't reset stats for page buffering");
596
597
0
            break;
598
0
        }
599
600
        /* H5Fget_page_buffering_stats */
601
0
        case H5VL_NATIVE_FILE_GET_PAGE_BUFFERING_STATS: {
602
0
            H5VL_native_file_get_page_buffering_stats_t *gpbs_args = &opt_args->get_page_buffering_stats;
603
604
            /* Sanity check */
605
0
            if (NULL == f->shared->page_buf)
606
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "page buffering not enabled on file");
607
608
            /* Get the statistics */
609
0
            if (H5PB_get_stats(f->shared->page_buf, gpbs_args->accesses, gpbs_args->hits, gpbs_args->misses,
610
0
                               gpbs_args->evictions, gpbs_args->bypasses) < 0)
611
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve stats for page buffering");
612
613
0
            break;
614
0
        }
615
616
        /* H5Fget_mdc_image_info */
617
0
        case H5VL_NATIVE_FILE_GET_MDC_IMAGE_INFO: {
618
0
            H5VL_native_file_get_mdc_image_info_t *gmii_args = &opt_args->get_mdc_image_info;
619
620
            /* Go get the address and size of the cache image */
621
0
            if (H5AC_get_mdc_image_info(f->shared->cache, gmii_args->addr, gmii_args->len) < 0)
622
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve cache image info");
623
624
0
            break;
625
0
        }
626
627
        /* H5Fget_eoa */
628
0
        case H5VL_NATIVE_FILE_GET_EOA: {
629
0
            haddr_t rel_eoa; /* Relative address of EOA */
630
631
            /* This routine will work only for drivers with this feature enabled.*/
632
            /* We might introduce a new feature flag in the future */
633
0
            if (!H5F_HAS_FEATURE(f, H5FD_FEAT_SUPPORTS_SWMR_IO))
634
0
                HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
635
0
                            "must use a SWMR-compatible VFD for this public routine");
636
637
            /* The real work */
638
0
            if (HADDR_UNDEF == (rel_eoa = H5F_get_eoa(f, H5FD_MEM_DEFAULT)))
639
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "get_eoa request failed");
640
641
            /* Set return value */
642
            /* (Note compensating for base address subtraction in internal routine) */
643
0
            *opt_args->get_eoa.eoa = rel_eoa + H5F_get_base_addr(f);
644
645
0
            break;
646
0
        }
647
648
        /* H5Fincrement_filesize */
649
0
        case H5VL_NATIVE_FILE_INCR_FILESIZE: {
650
0
            haddr_t max_eof_eoa; /* Maximum of the relative EOA & EOF */
651
652
            /* This public routine will work only for drivers with this feature enabled.*/
653
            /* We might introduce a new feature flag in the future */
654
0
            if (!H5F_HAS_FEATURE(f, H5FD_FEAT_SUPPORTS_SWMR_IO))
655
0
                HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
656
0
                            "must use a SWMR-compatible VFD for this public routine");
657
658
            /* Get the maximum of EOA and EOF */
659
0
            if (H5F__get_max_eof_eoa(f, &max_eof_eoa) < 0)
660
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "file can't get max eof/eoa ");
661
662
            /* Set EOA to the maximum value + increment */
663
0
            if (H5F__set_eoa(f, H5FD_MEM_DEFAULT, max_eof_eoa + opt_args->increment_filesize.increment) < 0)
664
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "driver set_eoa request failed");
665
666
0
            break;
667
0
        }
668
669
        /* H5Fset_latest_format, H5Fset_libver_bounds */
670
0
        case H5VL_NATIVE_FILE_SET_LIBVER_BOUNDS: {
671
0
            H5VL_native_file_set_libver_bounds_t *slb_args = &opt_args->set_libver_bounds;
672
673
            /* Call internal set_libver_bounds function */
674
0
            if (H5F__set_libver_bounds(f, slb_args->low, slb_args->high) < 0)
675
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "cannot set low/high bounds");
676
677
0
            break;
678
0
        }
679
680
        /* H5Fget_dset_no_attrs_hint */
681
0
        case H5VL_NATIVE_FILE_GET_MIN_DSET_OHDR_FLAG: {
682
0
            *opt_args->get_min_dset_ohdr_flag.minimize = H5F_GET_MIN_DSET_OHDR(f);
683
684
0
            break;
685
0
        }
686
687
        /* H5Fset_dset_no_attrs_hint */
688
0
        case H5VL_NATIVE_FILE_SET_MIN_DSET_OHDR_FLAG: {
689
0
            if (H5F_set_min_dset_ohdr(f, opt_args->set_min_dset_ohdr_flag.minimize) < 0)
690
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL,
691
0
                            "cannot set file's dataset object header minimization flag");
692
693
0
            break;
694
0
        }
695
696
#ifdef H5_HAVE_PARALLEL
697
        /* H5Fget_mpi_atomicity */
698
        case H5VL_NATIVE_FILE_GET_MPI_ATOMICITY: {
699
            if (H5F__get_mpi_atomicity(f, opt_args->get_mpi_atomicity.flag) < 0)
700
                HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "cannot get MPI atomicity");
701
702
            break;
703
        }
704
705
        /* H5Fset_mpi_atomicity */
706
        case H5VL_NATIVE_FILE_SET_MPI_ATOMICITY: {
707
            if (H5F__set_mpi_atomicity(f, opt_args->set_mpi_atomicity.flag) < 0)
708
                HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "cannot set MPI atomicity");
709
710
            break;
711
        }
712
#endif /* H5_HAVE_PARALLEL */
713
714
        /* Finalize H5Fopen */
715
1.84k
        case H5VL_NATIVE_FILE_POST_OPEN: {
716
            /* Call package routine */
717
1.84k
            if (H5F__post_open(f) < 0)
718
0
                HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "can't finish opening file");
719
1.84k
            break;
720
1.84k
        }
721
722
1.84k
        default:
723
0
            HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid optional operation");
724
1.84k
    } /* end switch */
725
726
1.84k
done:
727
1.84k
    FUNC_LEAVE_NOAPI(ret_value)
728
1.84k
} /* end H5VL__native_file_optional() */
729
730
/*-------------------------------------------------------------------------
731
 * Function:    H5VL__native_file_close
732
 *
733
 * Purpose:     Handles the file close callback
734
 *
735
 * Return:      Success:    SUCCEED
736
 *              Failure:    FAIL (file will not be closed)
737
 *
738
 *-------------------------------------------------------------------------
739
 */
740
herr_t
741
H5VL__native_file_close(void *file, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
742
2.26k
{
743
2.26k
    int    nref;
744
2.26k
    H5F_t *f         = (H5F_t *)file;
745
2.26k
    hid_t  file_id   = H5I_INVALID_HID;
746
2.26k
    herr_t ret_value = SUCCEED; /* Return value */
747
748
2.26k
    FUNC_ENTER_PACKAGE
749
750
    /* This routine should only be called when a file ID's ref count drops to zero */
751
2.26k
    assert(f->shared == NULL || H5F_ID_EXISTS(f));
752
753
2.26k
    if (f->shared == NULL)
754
414
        f = H5FL_FREE(H5F_t, f);
755
756
1.84k
    else {
757
758
        /* Flush file if this is the last reference to this id and we have write
759
         * intent, unless it will be flushed by the "shared" file being closed.
760
         * This is only necessary to replicate previous behaviour, and could be
761
         * disabled by an option/property to improve performance.
762
         */
763
1.84k
        if ((H5F_NREFS(f) > 1) && (H5F_INTENT(f) & H5F_ACC_RDWR)) {
764
            /* Get the file ID corresponding to the H5F_t struct */
765
0
            if (H5I_find_id(f, H5I_FILE, &file_id) < 0 || H5I_INVALID_HID == file_id)
766
0
                HGOTO_ERROR(H5E_ID, H5E_CANTGET, FAIL, "invalid ID");
767
768
            /* Get the number of references outstanding for this file ID */
769
0
            if ((nref = H5I_get_ref(file_id, false)) < 0)
770
0
                HGOTO_ERROR(H5E_ID, H5E_CANTGET, FAIL, "can't get ID ref count");
771
0
            if (nref == 1)
772
0
                if (H5F__flush(f) < 0)
773
0
                    HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush cache");
774
0
        } /* end if */
775
776
        /* Close the file */
777
1.84k
        if (H5F__close(f) < 0)
778
414
            HGOTO_ERROR(H5E_FILE, H5E_CANTDEC, FAIL, "can't close file");
779
1.84k
    }
780
781
2.26k
done:
782
2.26k
    FUNC_LEAVE_NOAPI(ret_value)
783
2.26k
} /* end H5VL__native_file_close() */