Coverage Report

Created: 2026-11-22 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5FDsplitter.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:     The Splitter VFD implements a file driver which relays all the
15
 *              VFD calls to an underlying VFD, and send all the write calls to
16
 *              another underlying VFD. Maintains two files simultaneously.
17
 */
18
19
#include "H5FDmodule.h" /* This source code file is part of the H5FD module */
20
21
#include "H5private.h"    /* Generic Functions        */
22
#include "H5Eprivate.h"   /* Error handling           */
23
#include "H5Fprivate.h"   /* File access              */
24
#include "H5FDpkg.h"      /* File drivers             */
25
#include "H5FDsplitter.h" /* Splitter file driver     */
26
#include "H5FLprivate.h"  /* Free Lists               */
27
#include "H5Iprivate.h"   /* IDs                      */
28
#include "H5MMprivate.h"  /* Memory management        */
29
#include "H5Pprivate.h"   /* Property lists           */
30
31
/* The driver identification number, initialized at runtime */
32
hid_t H5FD_SPLITTER_id_g = H5I_INVALID_HID;
33
34
/* Driver-specific file access properties */
35
typedef struct H5FD_splitter_fapl_t {
36
    hid_t rw_fapl_id;                                /* fapl for the R/W channel       */
37
    hid_t wo_fapl_id;                                /* fapl for the W/O channel       */
38
    char  wo_path[H5FD_SPLITTER_PATH_MAX + 1];       /* file name for the W/O channel */
39
    char  log_file_path[H5FD_SPLITTER_PATH_MAX + 1]; /* file to record errors reported by the W/O channel */
40
    bool  ignore_wo_errs;                            /* true to ignore errors on the W/O channel */
41
} H5FD_splitter_fapl_t;
42
43
/* The information of this splitter */
44
typedef struct H5FD_splitter_t {
45
    H5FD_t               pub;     /* public stuff, must be first    */
46
    unsigned             version; /* version of the H5FD_splitter_vfd_config_t structure used */
47
    H5FD_splitter_fapl_t fa;      /* driver-specific file access properties */
48
    H5FD_t              *rw_file; /* pointer of R/W channel */
49
    H5FD_t              *wo_file; /* pointer of W/O channel */
50
    FILE                *logfp;   /* Log file pointer */
51
} H5FD_splitter_t;
52
53
/* This macro provides a wrapper for shared fail-log-ignore behavior
54
 * for errors arising in the splitter's W/O channel.
55
 * Logs an error entry in a log file, if the file exists.
56
 * If not set to ignore errors, registers an error with the library.
57
 */
58
#define H5FD_SPLITTER_WO_ERROR(file, funcname, errmajor, errminor, ret, mesg)                                \
59
0
    {                                                                                                        \
60
0
        H5FD__splitter_log_error((file), (funcname), (mesg));                                                \
61
0
        if (false == (file)->fa.ignore_wo_errs)                                                              \
62
0
            HGOTO_ERROR((errmajor), (errminor), (ret), (mesg));                                              \
63
0
    }
64
65
#define H5FD_SPLITTER_DEBUG_OP_CALLS 0 /* debugging print toggle; 0 disables */
66
67
#if H5FD_SPLITTER_DEBUG_OP_CALLS
68
#define H5FD_SPLITTER_LOG_CALL(name)                                                                         \
69
    do {                                                                                                     \
70
        printf("called %s()\n", (name));                                                                     \
71
        fflush(stdout);                                                                                      \
72
    } while (0)
73
#else
74
#define H5FD_SPLITTER_LOG_CALL(name) /* no-op */
75
#endif                               /* H5FD_SPLITTER_DEBUG_OP_CALLS */
76
77
/* Private functions */
78
79
/* Print error messages from W/O channel to log file */
80
static herr_t H5FD__splitter_log_error(const H5FD_splitter_t *file, const char *atfunc, const char *msg);
81
static int    H5FD__copy_plist(hid_t fapl_id, hid_t *id_out_ptr);
82
83
/* Prototypes */
84
static herr_t  H5FD__splitter_populate_config(H5FD_splitter_vfd_config_t *vfd_config,
85
                                              H5FD_splitter_fapl_t       *fapl_out);
86
static herr_t  H5FD__splitter_get_default_wo_path(char *new_path, size_t new_path_len,
87
                                                  const char *base_filename);
88
static hsize_t H5FD__splitter_sb_size(H5FD_t *_file);
89
static herr_t  H5FD__splitter_sb_encode(H5FD_t *_file, char *name /*out*/, unsigned char *buf /*out*/);
90
static herr_t  H5FD__splitter_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf);
91
static void   *H5FD__splitter_fapl_get(H5FD_t *_file);
92
static void   *H5FD__splitter_fapl_copy(const void *_old_fa);
93
static herr_t  H5FD__splitter_fapl_free(void *_fapl);
94
static H5FD_t *H5FD__splitter_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr);
95
static herr_t  H5FD__splitter_close(H5FD_t *_file);
96
static int     H5FD__splitter_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
97
static herr_t  H5FD__splitter_query(const H5FD_t *_file, unsigned long *flags /* out */);
98
static herr_t  H5FD__splitter_get_type_map(const H5FD_t *_file, H5FD_mem_t *type_map);
99
static haddr_t H5FD__splitter_alloc(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size);
100
static herr_t  H5FD__splitter_free(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t size);
101
static haddr_t H5FD__splitter_get_eoa(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type);
102
static herr_t  H5FD__splitter_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr);
103
static haddr_t H5FD__splitter_get_eof(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type);
104
static herr_t  H5FD__splitter_get_handle(H5FD_t *_file, hid_t H5_ATTR_UNUSED fapl, void **file_handle);
105
static herr_t  H5FD__splitter_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
106
                                   void *buf);
107
static herr_t  H5FD__splitter_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
108
                                    const void *buf);
109
static herr_t  H5FD__splitter_flush(H5FD_t *_file, hid_t dxpl_id, bool closing);
110
static herr_t  H5FD__splitter_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing);
111
static herr_t  H5FD__splitter_lock(H5FD_t *_file, bool rw);
112
static herr_t  H5FD__splitter_unlock(H5FD_t *_file);
113
static herr_t  H5FD__splitter_delete(const char *filename, hid_t fapl_id);
114
static herr_t  H5FD__splitter_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void *input,
115
                                  void **output);
116
117
static const H5FD_class_t H5FD_splitter_g = {
118
    H5FD_CLASS_VERSION,           /* struct version       */
119
    H5FD_SPLITTER_VALUE,          /* value                */
120
    "splitter",                   /* name                 */
121
    H5FD_MAXADDR,                 /* maxaddr              */
122
    H5F_CLOSE_WEAK,               /* fc_degree            */
123
    NULL,                         /* terminate            */
124
    H5FD__splitter_sb_size,       /* sb_size              */
125
    H5FD__splitter_sb_encode,     /* sb_encode            */
126
    H5FD__splitter_sb_decode,     /* sb_decode            */
127
    sizeof(H5FD_splitter_fapl_t), /* fapl_size            */
128
    H5FD__splitter_fapl_get,      /* fapl_get             */
129
    H5FD__splitter_fapl_copy,     /* fapl_copy            */
130
    H5FD__splitter_fapl_free,     /* fapl_free            */
131
    0,                            /* dxpl_size            */
132
    NULL,                         /* dxpl_copy            */
133
    NULL,                         /* dxpl_free            */
134
    H5FD__splitter_open,          /* open                 */
135
    H5FD__splitter_close,         /* close                */
136
    H5FD__splitter_cmp,           /* cmp                  */
137
    H5FD__splitter_query,         /* query                */
138
    H5FD__splitter_get_type_map,  /* get_type_map         */
139
    H5FD__splitter_alloc,         /* alloc                */
140
    H5FD__splitter_free,          /* free                 */
141
    H5FD__splitter_get_eoa,       /* get_eoa              */
142
    H5FD__splitter_set_eoa,       /* set_eoa              */
143
    H5FD__splitter_get_eof,       /* get_eof              */
144
    H5FD__splitter_get_handle,    /* get_handle           */
145
    H5FD__splitter_read,          /* read                 */
146
    H5FD__splitter_write,         /* write                */
147
    NULL,                         /* read_vector          */
148
    NULL,                         /* write_vector         */
149
    NULL,                         /* read_selection       */
150
    NULL,                         /* write_selection      */
151
    H5FD__splitter_flush,         /* flush                */
152
    H5FD__splitter_truncate,      /* truncate             */
153
    H5FD__splitter_lock,          /* lock                 */
154
    H5FD__splitter_unlock,        /* unlock               */
155
    H5FD__splitter_delete,        /* del                  */
156
    H5FD__splitter_ctl,           /* ctl                  */
157
    H5FD_FLMAP_DICHOTOMY          /* fl_map               */
158
};
159
160
/* Declare a free list to manage the H5FD_splitter_t struct */
161
H5FL_DEFINE_STATIC(H5FD_splitter_t);
162
163
/* Declare a free list to manage the H5FD_splitter_fapl_t struct */
164
H5FL_DEFINE_STATIC(H5FD_splitter_fapl_t);
165
166
/*-------------------------------------------------------------------------
167
 * Function:    H5FD__splitter_register
168
 *
169
 * Purpose:     Register the driver with the library.
170
 *
171
 * Return:      SUCCEED/FAIL
172
 *
173
 *-------------------------------------------------------------------------
174
 */
175
herr_t
176
H5FD__splitter_register(void)
177
1
{
178
1
    herr_t ret_value = SUCCEED; /* Return value */
179
180
1
    FUNC_ENTER_PACKAGE
181
182
1
    H5FD_SPLITTER_LOG_CALL(__func__);
183
184
1
    if (H5I_VFL != H5I_get_type(H5FD_SPLITTER_id_g))
185
1
        if ((H5FD_SPLITTER_id_g = H5FD_register(&H5FD_splitter_g, sizeof(H5FD_class_t), false)) < 0)
186
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register splitter driver");
187
188
1
done:
189
1
    FUNC_LEAVE_NOAPI(ret_value)
190
1
} /* end H5FD__splitter_register() */
191
192
/*---------------------------------------------------------------------------
193
 * Function:    H5FD__splitter_unregister
194
 *
195
 * Purpose:     Reset library driver info.
196
 *
197
 * Returns:     SUCCEED (Can't fail)
198
 *
199
 *---------------------------------------------------------------------------
200
 */
201
herr_t
202
H5FD__splitter_unregister(void)
203
1
{
204
1
    FUNC_ENTER_PACKAGE_NOERR
205
206
1
    H5FD_SPLITTER_LOG_CALL(__func__);
207
208
    /* Reset VFL ID */
209
1
    H5FD_SPLITTER_id_g = H5I_INVALID_HID;
210
211
1
    FUNC_LEAVE_NOAPI(SUCCEED)
212
1
} /* end H5FD__splitter_unregister() */
213
214
/*-------------------------------------------------------------------------
215
 * Function:    H5FD__copy_plist
216
 *
217
 * Purpose:     Sanity-wrapped H5P_copy_plist() for each channel.
218
 *              Utility function for operation in multiple locations.
219
 *
220
 * Return:      0 on success, -1 on error.
221
 *-------------------------------------------------------------------------
222
 */
223
static int
224
H5FD__copy_plist(hid_t fapl_id, hid_t *id_out_ptr)
225
0
{
226
0
    int             ret_value = 0;
227
0
    H5P_genplist_t *plist_ptr = NULL;
228
229
0
    FUNC_ENTER_PACKAGE
230
231
0
    H5FD_SPLITTER_LOG_CALL(__func__);
232
233
0
    assert(id_out_ptr != NULL);
234
235
0
    if (false == H5P_isa_class(fapl_id, H5P_FILE_ACCESS))
236
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, -1, "not a file access property list");
237
238
0
    plist_ptr = (H5P_genplist_t *)H5I_object(fapl_id);
239
0
    if (NULL == plist_ptr)
240
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, -1, "unable to get property list");
241
242
0
    *id_out_ptr = H5P_copy_plist(plist_ptr, false);
243
0
    if (H5I_INVALID_HID == *id_out_ptr)
244
0
        HGOTO_ERROR(H5E_VFL, H5E_BADTYPE, -1, "unable to copy file access property list");
245
246
0
done:
247
0
    FUNC_LEAVE_NOAPI(ret_value)
248
0
} /* end H5FD__copy_plist() */
249
250
/*-------------------------------------------------------------------------
251
 * Function:    H5Pset_fapl_splitter
252
 *
253
 * Purpose:     Sets the file access property list to use the
254
 *              splitter driver.
255
 *
256
 * Return:      SUCCEED/FAIL
257
 *-------------------------------------------------------------------------
258
 */
259
herr_t
260
H5Pset_fapl_splitter(hid_t fapl_id, H5FD_splitter_vfd_config_t *vfd_config)
261
0
{
262
0
    H5FD_splitter_fapl_t *info      = NULL;
263
0
    H5P_genplist_t       *plist_ptr = NULL;
264
0
    herr_t                ret_value = SUCCEED;
265
266
0
    FUNC_ENTER_API(FAIL)
267
268
0
    H5FD_SPLITTER_LOG_CALL(__func__);
269
270
0
    if (H5FD_SPLITTER_MAGIC != vfd_config->magic)
271
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid configuration (magic number mismatch)");
272
0
    if (H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION != vfd_config->version)
273
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid config (version number mismatch)");
274
0
    if (NULL == (plist_ptr = (H5P_genplist_t *)H5I_object(fapl_id)))
275
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a valid property list");
276
277
0
    info = H5FL_CALLOC(H5FD_splitter_fapl_t);
278
0
    if (NULL == info)
279
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate file access property list struct");
280
281
0
    if (H5FD__splitter_populate_config(vfd_config, info) < 0)
282
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't setup driver configuration");
283
284
0
    ret_value = H5P_set_driver(plist_ptr, H5FD_SPLITTER, info, NULL);
285
286
0
done:
287
0
    if (info)
288
0
        info = H5FL_FREE(H5FD_splitter_fapl_t, info);
289
290
0
    FUNC_LEAVE_API(ret_value)
291
0
} /* end H5Pset_fapl_splitter() */
292
293
/*-------------------------------------------------------------------------
294
 * Function:    H5Pget_fapl_splitter
295
 *
296
 * Purpose:     Returns information about the splitter file access property
297
 *              list through the structure config.
298
 *
299
 *              Will fail if config is received without pre-set valid
300
 *              magic and version information.
301
 *
302
 * Return:      SUCCEED/FAIL
303
 *-------------------------------------------------------------------------
304
 */
305
herr_t
306
H5Pget_fapl_splitter(hid_t fapl_id, H5FD_splitter_vfd_config_t *config /*out*/)
307
0
{
308
0
    const H5FD_splitter_fapl_t *fapl_ptr     = NULL;
309
0
    H5FD_splitter_fapl_t       *default_fapl = NULL;
310
0
    H5P_genplist_t             *plist_ptr    = NULL;
311
0
    herr_t                      ret_value    = SUCCEED;
312
313
0
    FUNC_ENTER_API(FAIL)
314
315
0
    H5FD_SPLITTER_LOG_CALL(__func__);
316
317
    /* Check arguments */
318
0
    if (true != H5P_isa_class(fapl_id, H5P_FILE_ACCESS))
319
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
320
0
    if (config == NULL)
321
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "config pointer is null");
322
0
    if (H5FD_SPLITTER_MAGIC != config->magic)
323
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "info-out pointer invalid (magic number mismatch)");
324
0
    if (H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION != config->version)
325
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "info-out pointer invalid (version unsafe)");
326
327
    /* Pre-set out FAPL IDs with intent to replace these values */
328
0
    config->rw_fapl_id = H5I_INVALID_HID;
329
0
    config->wo_fapl_id = H5I_INVALID_HID;
330
331
    /* Check and get the splitter fapl */
332
0
    if (NULL == (plist_ptr = H5P_object_verify(fapl_id, H5P_FILE_ACCESS, true)))
333
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
334
0
    if (H5FD_SPLITTER != H5P_peek_driver(plist_ptr))
335
0
        HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "incorrect VFL driver");
336
0
    fapl_ptr = (const H5FD_splitter_fapl_t *)H5P_peek_driver_info(plist_ptr);
337
0
    if (NULL == fapl_ptr) {
338
0
        if (NULL == (default_fapl = H5FL_CALLOC(H5FD_splitter_fapl_t)))
339
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate file access property list struct");
340
0
        if (H5FD__splitter_populate_config(NULL, default_fapl) < 0)
341
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't initialize driver configuration info");
342
0
        fapl_ptr = default_fapl;
343
0
    }
344
345
0
    strncpy(config->wo_path, fapl_ptr->wo_path, H5FD_SPLITTER_PATH_MAX + 1);
346
0
    strncpy(config->log_file_path, fapl_ptr->log_file_path, H5FD_SPLITTER_PATH_MAX + 1);
347
0
    config->ignore_wo_errs = fapl_ptr->ignore_wo_errs;
348
349
    /* Copy R/W and W/O FAPLs */
350
0
    if (H5FD__copy_plist(fapl_ptr->rw_fapl_id, &(config->rw_fapl_id)) < 0)
351
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "can't copy R/W FAPL");
352
0
    if (H5FD__copy_plist(fapl_ptr->wo_fapl_id, &(config->wo_fapl_id)) < 0)
353
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "can't copy W/O FAPL");
354
355
0
done:
356
0
    if (default_fapl)
357
0
        H5FL_FREE(H5FD_splitter_fapl_t, default_fapl);
358
359
0
    FUNC_LEAVE_API(ret_value)
360
0
} /* end H5Pget_fapl_splitter() */
361
362
/*-------------------------------------------------------------------------
363
 * Function:    H5FD__splitter_populate_config
364
 *
365
 * Purpose:    Populates a H5FD_splitter_fapl_t structure with the provided
366
 *             values, supplying defaults where values are not provided.
367
 *
368
 * Return:    Non-negative on success/Negative on failure
369
 *
370
 *-------------------------------------------------------------------------
371
 */
372
static herr_t
373
H5FD__splitter_populate_config(H5FD_splitter_vfd_config_t *vfd_config, H5FD_splitter_fapl_t *fapl_out)
374
0
{
375
0
    H5P_genplist_t *def_plist;
376
0
    H5P_genplist_t *plist;
377
0
    bool            free_config = false;
378
0
    herr_t          ret_value   = SUCCEED;
379
380
0
    FUNC_ENTER_PACKAGE
381
382
0
    assert(fapl_out);
383
384
0
    memset(fapl_out, 0, sizeof(H5FD_splitter_fapl_t));
385
386
0
    if (!vfd_config) {
387
0
        vfd_config = H5MM_calloc(sizeof(H5FD_splitter_vfd_config_t));
388
0
        if (NULL == vfd_config)
389
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate file access property list struct");
390
391
0
        vfd_config->magic      = H5FD_SPLITTER_MAGIC;
392
0
        vfd_config->version    = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION;
393
0
        vfd_config->rw_fapl_id = H5P_DEFAULT;
394
0
        vfd_config->wo_fapl_id = H5P_DEFAULT;
395
396
0
        free_config = true;
397
0
    }
398
399
    /* Make sure that the W/O channel supports write-only capability.
400
     * Some drivers (e.g. family or multi) do revision of the superblock
401
     * in-memory, causing problems in that channel.
402
     * Uses the feature flag H5FD_FEAT_DEFAULT_VFD_COMPATIBLE as the
403
     * determining attribute.
404
     */
405
0
    if (H5P_DEFAULT != vfd_config->wo_fapl_id) {
406
0
        H5FD_class_t      *wo_driver = NULL;
407
0
        H5FD_driver_prop_t wo_driver_prop;
408
0
        H5P_genplist_t    *wo_plist_ptr    = NULL;
409
0
        unsigned long      wo_driver_flags = 0;
410
411
0
        wo_plist_ptr = (H5P_genplist_t *)H5I_object(vfd_config->wo_fapl_id);
412
0
        if (NULL == wo_plist_ptr)
413
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
414
0
        if (H5P_peek(wo_plist_ptr, H5F_ACS_FILE_DRV_NAME, &wo_driver_prop) < 0)
415
0
            HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get driver ID & info");
416
0
        wo_driver = (H5FD_class_t *)H5I_object(wo_driver_prop.driver_id);
417
0
        if (NULL == wo_driver)
418
0
            HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "invalid driver ID in file access property list");
419
0
        if (H5FD_driver_query(wo_driver, &wo_driver_flags) < 0)
420
0
            HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "can't query VFD flags");
421
0
        if (0 == (H5FD_FEAT_DEFAULT_VFD_COMPATIBLE & wo_driver_flags))
422
0
            HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "unsuitable W/O driver");
423
0
    } /* end if W/O VFD is non-default */
424
425
0
    fapl_out->ignore_wo_errs = vfd_config->ignore_wo_errs;
426
0
    strncpy(fapl_out->wo_path, vfd_config->wo_path, H5FD_SPLITTER_PATH_MAX + 1);
427
0
    fapl_out->wo_path[H5FD_SPLITTER_PATH_MAX] = '\0';
428
0
    strncpy(fapl_out->log_file_path, vfd_config->log_file_path, H5FD_SPLITTER_PATH_MAX + 1);
429
0
    fapl_out->log_file_path[H5FD_SPLITTER_PATH_MAX] = '\0';
430
0
    fapl_out->rw_fapl_id                            = H5P_FILE_ACCESS_DEFAULT; /* pre-set value */
431
0
    fapl_out->wo_fapl_id                            = H5P_FILE_ACCESS_DEFAULT; /* pre-set value */
432
433
0
    if (NULL == (def_plist = (H5P_genplist_t *)H5I_object(H5P_FILE_ACCESS_DEFAULT)))
434
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
435
436
    /* Set non-default channel FAPL IDs in splitter configuration info */
437
0
    if (H5P_DEFAULT != vfd_config->rw_fapl_id) {
438
0
        if (false == H5P_isa_class(vfd_config->rw_fapl_id, H5P_FILE_ACCESS))
439
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access list");
440
0
        fapl_out->rw_fapl_id = vfd_config->rw_fapl_id;
441
0
    }
442
0
    else {
443
        /* Use copy of default file access property list for R/W channel FAPL ID.
444
         * The Sec2 driver is explicitly set on the FAPL ID, as the default
445
         * driver might have been replaced with the Splitter VFD, which
446
         * would cause recursion badness.
447
         */
448
0
        if ((fapl_out->rw_fapl_id = H5P_copy_plist(def_plist, false)) < 0)
449
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTCOPY, FAIL, "can't copy property list");
450
0
        if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_out->rw_fapl_id)))
451
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
452
0
        if (H5P_set_driver_by_value(plist, H5_VFD_SEC2, NULL, true) < 0)
453
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't set default driver on R/W channel FAPL");
454
0
    }
455
0
    if (H5P_DEFAULT != vfd_config->wo_fapl_id) {
456
0
        if (false == H5P_isa_class(vfd_config->wo_fapl_id, H5P_FILE_ACCESS))
457
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access list");
458
0
        fapl_out->wo_fapl_id = vfd_config->wo_fapl_id;
459
0
    }
460
0
    else {
461
        /* Use copy of default file access property list for W/O channel FAPL ID.
462
         * The Sec2 driver is explicitly set on the FAPL ID, as the default
463
         * driver might have been replaced with the Splitter VFD, which
464
         * would cause recursion badness.
465
         */
466
0
        if ((fapl_out->wo_fapl_id = H5P_copy_plist(def_plist, false)) < 0)
467
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTCOPY, FAIL, "can't copy property list");
468
0
        if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_out->wo_fapl_id)))
469
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
470
0
        if (H5P_set_driver_by_value(plist, H5_VFD_SEC2, NULL, true) < 0)
471
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't set default driver on R/W channel FAPL");
472
0
    }
473
474
0
done:
475
0
    if (free_config && vfd_config)
476
0
        H5MM_free(vfd_config);
477
478
0
    FUNC_LEAVE_NOAPI(ret_value)
479
0
} /* end H5FD__splitter_populate_config() */
480
481
/*-------------------------------------------------------------------------
482
 * Function:    H5FD__splitter_get_default_wo_path
483
 *
484
 * Purpose:     Given a base filename, returns a default filename for the
485
 *              W/O channel file by appending '_wo' to the base file name.
486
 *
487
 * Return:      Non-negative on Success/Negative on Failure
488
 *
489
 *-------------------------------------------------------------------------
490
 */
491
static herr_t
492
H5FD__splitter_get_default_wo_path(char *new_path, size_t new_path_len, const char *base_filename)
493
0
{
494
0
    const char *suffix           = "_wo";
495
0
    size_t      old_filename_len = 0;
496
0
    char       *file_extension   = NULL;
497
0
    herr_t      ret_value        = SUCCEED;
498
499
0
    FUNC_ENTER_PACKAGE
500
501
0
    assert(new_path);
502
0
    assert(base_filename);
503
504
    /* Check that output buffer can hold base filename + `_wo` suffix */
505
0
    old_filename_len = strlen(base_filename);
506
0
    if (old_filename_len > H5FD_SPLITTER_PATH_MAX - strlen(suffix) - 1)
507
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "filename exceeds max length");
508
509
    /* Determine if filename contains a ".h5" extension. */
510
0
    file_extension = strstr(base_filename, ".h5");
511
0
    if (file_extension) {
512
        /* Insert the suffix between the filename and ".h5" extension. */
513
0
        intptr_t beginningLength = file_extension - base_filename;
514
0
        snprintf(new_path, new_path_len, "%.*s%s%s", (int)beginningLength, base_filename, suffix, ".h5");
515
0
    }
516
0
    else {
517
        /* If the filename doesn't contain a ".h5" extension, but contains
518
         * AN extension, just insert the suffix before that extension.
519
         */
520
0
        file_extension = strrchr(base_filename, '.');
521
0
        if (file_extension) {
522
0
            intptr_t beginningLength = file_extension - base_filename;
523
0
            snprintf(new_path, new_path_len, "%.*s%s%s", (int)beginningLength, base_filename, suffix,
524
0
                     file_extension);
525
0
        }
526
0
        else {
527
            /* If the filename doesn't contain an extension at all, just insert
528
             * the suffix at the end of the filename.
529
             */
530
0
            snprintf(new_path, new_path_len, "%s%s", base_filename, suffix);
531
0
        }
532
0
    }
533
534
0
done:
535
0
    FUNC_LEAVE_NOAPI(ret_value)
536
0
} /* end H5FD__splitter_get_default_wo_path() */
537
538
/*-------------------------------------------------------------------------
539
 * Function:    H5FD__splitter_flush
540
 *
541
 * Purpose:     Flushes all data to disk for both channels.
542
 *
543
 * Return:      SUCCEED/FAIL
544
 *-------------------------------------------------------------------------
545
 */
546
static herr_t
547
H5FD__splitter_flush(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, bool closing)
548
0
{
549
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
550
0
    herr_t           ret_value = SUCCEED; /* Return value */
551
552
0
    FUNC_ENTER_PACKAGE
553
554
0
    H5FD_SPLITTER_LOG_CALL(__func__);
555
556
    /* Public API for dxpl "context" */
557
0
    if (H5FDflush(file->rw_file, dxpl_id, closing) < 0)
558
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTFLUSH, FAIL, "unable to flush R/W file");
559
0
    if (H5FDflush(file->wo_file, dxpl_id, closing) < 0)
560
0
        H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTFLUSH, FAIL, "unable to flush W/O file")
561
562
0
done:
563
0
    FUNC_LEAVE_NOAPI(ret_value)
564
0
} /* end H5FD__splitter_flush() */
565
566
/*-------------------------------------------------------------------------
567
 * Function:    H5FD__splitter_read
568
 *
569
 * Purpose:     Reads SIZE bytes of data from the R/W channel, beginning at
570
 *              address ADDR into buffer BUF according to data transfer
571
 *              properties in DXPL_ID.
572
 *
573
 * Return:      Success:    SUCCEED
574
 *                          The read result is written into the BUF buffer
575
 *                          which should be allocated by the caller.
576
 *              Failure:    FAIL
577
 *                          The contents of BUF are undefined.
578
 *-------------------------------------------------------------------------
579
 */
580
static herr_t
581
H5FD__splitter_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUSED dxpl_id, haddr_t addr,
582
                    size_t size, void *buf)
583
0
{
584
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
585
0
    herr_t           ret_value = SUCCEED;
586
587
0
    FUNC_ENTER_PACKAGE
588
589
0
    H5FD_SPLITTER_LOG_CALL(__func__);
590
591
0
    assert(file && file->pub.cls);
592
0
    assert(buf);
593
594
    /* Check for overflow conditions */
595
0
    if (!H5_addr_defined(addr))
596
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr);
597
0
    if (H5FD_REGION_OVERFLOW(addr, size))
598
0
        HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr);
599
600
    /* Only read from R/W channel */
601
    /* Public API for dxpl "context" */
602
0
    if (H5FDread(file->rw_file, type, dxpl_id, addr, size, buf) < 0)
603
0
        HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "Reading from R/W channel failed");
604
605
0
done:
606
0
    FUNC_LEAVE_NOAPI(ret_value)
607
0
} /* end H5FD__splitter_read() */
608
609
/*-------------------------------------------------------------------------
610
 * Function:    H5FD__splitter_write
611
 *
612
 * Purpose:     Writes SIZE bytes of data to R/W and W/O channels, beginning
613
 *              at address ADDR from buffer BUF according to data transfer
614
 *              properties in DXPL_ID.
615
 *
616
 * Return:      SUCCEED/FAIL
617
 *-------------------------------------------------------------------------
618
 */
619
static herr_t
620
H5FD__splitter_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
621
                     const void *buf)
622
0
{
623
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
624
0
    H5P_genplist_t  *plist_ptr = NULL;
625
0
    herr_t           ret_value = SUCCEED;
626
627
0
    FUNC_ENTER_PACKAGE
628
629
0
    H5FD_SPLITTER_LOG_CALL(__func__);
630
631
0
    if (NULL == (plist_ptr = (H5P_genplist_t *)H5I_object(dxpl_id)))
632
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list");
633
634
    /* Write to each file */
635
    /* Public API for dxpl "context" */
636
0
    if (H5FDwrite(file->rw_file, type, dxpl_id, addr, size, buf) < 0)
637
0
        HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "R/W file write failed");
638
0
    if (H5FDwrite(file->wo_file, type, dxpl_id, addr, size, buf) < 0)
639
0
        H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_WRITEERROR, FAIL, "unable to write W/O file")
640
641
0
done:
642
0
    FUNC_LEAVE_NOAPI(ret_value)
643
0
} /* end H5FD__splitter_write() */
644
645
/*-------------------------------------------------------------------------
646
 * Function:    H5FD__splitter_fapl_get
647
 *
648
 * Purpose:     Returns a file access property list which indicates how the
649
 *              specified file is being accessed. The return list could be
650
 *              used to access another file the same way.
651
 *
652
 * Return:      Success:    Ptr to new file access property list with all
653
 *                          members copied from the file struct.
654
 *              Failure:    NULL
655
 *-------------------------------------------------------------------------
656
 */
657
static void *
658
H5FD__splitter_fapl_get(H5FD_t *_file)
659
0
{
660
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
661
0
    void            *ret_value = NULL;
662
663
0
    FUNC_ENTER_PACKAGE_NOERR
664
665
0
    H5FD_SPLITTER_LOG_CALL(__func__);
666
667
0
    ret_value = H5FD__splitter_fapl_copy(&(file->fa));
668
669
0
    FUNC_LEAVE_NOAPI(ret_value)
670
0
} /* end H5FD__splitter_fapl_get() */
671
672
/*-------------------------------------------------------------------------
673
 * Function:    H5FD__splitter_fapl_copy
674
 *
675
 * Purpose:     Copies the file access properties.
676
 *
677
 * Return:      Success:    Pointer to a new property list info structure.
678
 *              Failure:    NULL
679
 *-------------------------------------------------------------------------
680
 */
681
static void *
682
H5FD__splitter_fapl_copy(const void *_old_fa)
683
0
{
684
0
    const H5FD_splitter_fapl_t *old_fa_ptr = (const H5FD_splitter_fapl_t *)_old_fa;
685
0
    H5FD_splitter_fapl_t       *new_fa_ptr = NULL;
686
0
    void                       *ret_value  = NULL;
687
688
0
    FUNC_ENTER_PACKAGE
689
690
0
    H5FD_SPLITTER_LOG_CALL(__func__);
691
692
0
    assert(old_fa_ptr);
693
694
0
    new_fa_ptr = H5FL_CALLOC(H5FD_splitter_fapl_t);
695
0
    if (NULL == new_fa_ptr)
696
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL");
697
698
0
    H5MM_memcpy(new_fa_ptr, old_fa_ptr, sizeof(H5FD_splitter_fapl_t));
699
0
    strncpy(new_fa_ptr->wo_path, old_fa_ptr->wo_path, H5FD_SPLITTER_PATH_MAX + 1);
700
0
    strncpy(new_fa_ptr->log_file_path, old_fa_ptr->log_file_path, H5FD_SPLITTER_PATH_MAX + 1);
701
702
    /* Copy R/W and W/O FAPLs */
703
0
    if (H5FD__copy_plist(old_fa_ptr->rw_fapl_id, &(new_fa_ptr->rw_fapl_id)) < 0)
704
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy R/W FAPL");
705
0
    if (H5FD__copy_plist(old_fa_ptr->wo_fapl_id, &(new_fa_ptr->wo_fapl_id)) < 0)
706
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy W/O FAPL");
707
708
0
    ret_value = (void *)new_fa_ptr;
709
710
0
done:
711
0
    if (NULL == ret_value)
712
0
        if (new_fa_ptr)
713
0
            new_fa_ptr = H5FL_FREE(H5FD_splitter_fapl_t, new_fa_ptr);
714
715
0
    FUNC_LEAVE_NOAPI(ret_value)
716
0
} /* end H5FD__splitter_fapl_copy() */
717
718
/*--------------------------------------------------------------------------
719
 * Function:    H5FD__splitter_fapl_free
720
 *
721
 * Purpose:     Releases the file access lists
722
 *
723
 * Return:      SUCCEED/FAIL
724
 *--------------------------------------------------------------------------
725
 */
726
static herr_t
727
H5FD__splitter_fapl_free(void *_fapl)
728
0
{
729
0
    H5FD_splitter_fapl_t *fapl      = (H5FD_splitter_fapl_t *)_fapl;
730
0
    herr_t                ret_value = SUCCEED;
731
732
0
    FUNC_ENTER_PACKAGE
733
734
0
    H5FD_SPLITTER_LOG_CALL(__func__);
735
736
    /* Check arguments */
737
0
    assert(fapl);
738
739
0
    if (H5I_dec_ref(fapl->rw_fapl_id) < 0)
740
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "can't close R/W FAPL ID");
741
0
    if (H5I_dec_ref(fapl->wo_fapl_id) < 0)
742
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "can't close W/O FAPL ID");
743
744
    /* Free the property list */
745
0
    fapl = H5FL_FREE(H5FD_splitter_fapl_t, fapl);
746
747
0
done:
748
0
    FUNC_LEAVE_NOAPI(ret_value)
749
0
} /* end H5FD__splitter_fapl_free() */
750
751
/*-------------------------------------------------------------------------
752
 * Function:    H5FD__splitter_open
753
 *
754
 * Purpose:     Create and/or opens a file as an HDF5 file.
755
 *
756
 * Return:      Success:    A pointer to a new file data structure. The
757
 *                          public fields will be initialized by the
758
 *                          caller, which is always H5FD_open().
759
 *              Failure:    NULL
760
 *-------------------------------------------------------------------------
761
 */
762
static H5FD_t *
763
H5FD__splitter_open(const char *name, unsigned flags, hid_t splitter_fapl_id, haddr_t maxaddr)
764
0
{
765
0
    H5FD_splitter_t            *file_ptr     = NULL; /* Splitter VFD info */
766
0
    const H5FD_splitter_fapl_t *fapl_ptr     = NULL; /* Driver-specific property list */
767
0
    H5FD_splitter_fapl_t       *default_fapl = NULL;
768
0
    H5P_genplist_t             *plist_ptr    = NULL;
769
0
    H5FD_t                     *ret_value    = NULL;
770
771
0
    FUNC_ENTER_PACKAGE
772
773
0
    H5FD_SPLITTER_LOG_CALL(__func__);
774
775
    /* Check arguments */
776
0
    if (!name || !*name)
777
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name");
778
0
    if (0 == maxaddr || HADDR_UNDEF == maxaddr)
779
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr");
780
0
    if (H5FD_ADDR_OVERFLOW(maxaddr))
781
0
        HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr");
782
0
    if (H5FD_SPLITTER != H5Pget_driver(splitter_fapl_id))
783
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "driver is not splitter");
784
785
0
    file_ptr = (H5FD_splitter_t *)H5FL_CALLOC(H5FD_splitter_t);
786
0
    if (NULL == file_ptr)
787
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate file struct");
788
0
    file_ptr->fa.rw_fapl_id = H5I_INVALID_HID;
789
0
    file_ptr->fa.wo_fapl_id = H5I_INVALID_HID;
790
791
    /* Get the driver-specific file access properties */
792
0
    plist_ptr = (H5P_genplist_t *)H5I_object(splitter_fapl_id);
793
0
    if (NULL == plist_ptr)
794
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list");
795
0
    fapl_ptr = (const H5FD_splitter_fapl_t *)H5P_peek_driver_info(plist_ptr);
796
0
    if (NULL == fapl_ptr) {
797
0
        if (NULL == (default_fapl = H5FL_CALLOC(H5FD_splitter_fapl_t)))
798
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate file access property list struct");
799
0
        if (H5FD__splitter_populate_config(NULL, default_fapl) < 0)
800
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTSET, NULL, "can't initialize driver configuration info");
801
802
        /* If W/O path is not set, use base filename with '_wo' suffix */
803
0
        if (*default_fapl->wo_path == '\0')
804
0
            if (H5FD__splitter_get_default_wo_path(default_fapl->wo_path, H5FD_SPLITTER_PATH_MAX + 1, name) <
805
0
                0)
806
0
                HGOTO_ERROR(H5E_VFL, H5E_CANTSET, NULL, "can't generate default filename for W/O channel");
807
808
0
        fapl_ptr = default_fapl;
809
0
    }
810
811
    /* Copy simpler info */
812
0
    strncpy(file_ptr->fa.wo_path, fapl_ptr->wo_path, H5FD_SPLITTER_PATH_MAX + 1);
813
0
    strncpy(file_ptr->fa.log_file_path, fapl_ptr->log_file_path, H5FD_SPLITTER_PATH_MAX + 1);
814
0
    file_ptr->fa.ignore_wo_errs = fapl_ptr->ignore_wo_errs;
815
816
    /* Copy R/W and W/O channel FAPLs. */
817
0
    if (H5FD__copy_plist(fapl_ptr->rw_fapl_id, &(file_ptr->fa.rw_fapl_id)) < 0)
818
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy R/W FAPL");
819
0
    if (H5FD__copy_plist(fapl_ptr->wo_fapl_id, &(file_ptr->fa.wo_fapl_id)) < 0)
820
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy W/O FAPL");
821
822
    /* Prepare log file if necessary.
823
     * If application wants to ignore the errors from W/O channel and
824
     * provided a name for the log file, then open it
825
     */
826
0
    if (!file_ptr->logfp) {
827
0
        if (file_ptr->fa.log_file_path[0] != '\0') {
828
0
            int log_file_fd = -1;
829
830
0
            if ((log_file_fd = HDopen(file_ptr->fa.log_file_path, O_WRONLY | O_CREAT | O_TRUNC,
831
0
                                      H5_POSIX_CREATE_MODE_URWGROR)) < 0)
832
0
                HSYS_GOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open log file");
833
834
0
            if (NULL == (file_ptr->logfp = HDfdopen(log_file_fd, "w"))) {
835
0
                HDclose(log_file_fd);
836
0
                HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open log file");
837
0
            }
838
0
        } /* end if logfile path given */
839
0
    }     /* end if logfile pointer/handle does not exist */
840
841
0
    if (H5FD_open(false, &file_ptr->rw_file, name, flags, fapl_ptr->rw_fapl_id, HADDR_UNDEF) < 0)
842
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open R/W file");
843
0
    if (H5FD_open(false, &file_ptr->wo_file, fapl_ptr->wo_path, flags, fapl_ptr->wo_fapl_id, HADDR_UNDEF) < 0)
844
0
        H5FD_SPLITTER_WO_ERROR(file_ptr, __func__, H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open W/O file")
845
846
0
    ret_value = (H5FD_t *)file_ptr;
847
848
0
done:
849
0
    if (default_fapl)
850
0
        H5FL_FREE(H5FD_splitter_fapl_t, default_fapl);
851
852
0
    if (NULL == ret_value) {
853
0
        if (file_ptr) {
854
0
            if (H5I_INVALID_HID != file_ptr->fa.rw_fapl_id)
855
0
                H5I_dec_ref(file_ptr->fa.rw_fapl_id);
856
0
            if (H5I_INVALID_HID != file_ptr->fa.wo_fapl_id)
857
0
                H5I_dec_ref(file_ptr->fa.wo_fapl_id);
858
0
            if (file_ptr->rw_file)
859
0
                H5FD_close(file_ptr->rw_file);
860
0
            if (file_ptr->wo_file)
861
0
                H5FD_close(file_ptr->wo_file);
862
0
            if (file_ptr->logfp)
863
0
                fclose(file_ptr->logfp);
864
0
            H5FL_FREE(H5FD_splitter_t, file_ptr);
865
0
        }
866
0
    } /* end if error */
867
868
0
    FUNC_LEAVE_NOAPI(ret_value)
869
0
} /* end H5FD__splitter_open() */
870
871
/*-------------------------------------------------------------------------
872
 * Function:    H5FD__splitter_close
873
 *
874
 * Purpose:     Closes files on both read-write and write-only channels.
875
 *
876
 * Return:      Success:    SUCCEED
877
 *              Failure:    FAIL, file not closed.
878
 *-------------------------------------------------------------------------
879
 */
880
static herr_t
881
H5FD__splitter_close(H5FD_t *_file)
882
0
{
883
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
884
0
    herr_t           ret_value = SUCCEED;
885
886
0
    FUNC_ENTER_PACKAGE
887
888
0
    H5FD_SPLITTER_LOG_CALL(__func__);
889
890
    /* Sanity check */
891
0
    assert(file);
892
893
0
    if (H5I_dec_ref(file->fa.rw_fapl_id) < 0)
894
0
        HGOTO_ERROR(H5E_VFL, H5E_ARGS, FAIL, "can't close R/W FAPL");
895
0
    if (H5I_dec_ref(file->fa.wo_fapl_id) < 0)
896
0
        HGOTO_ERROR(H5E_VFL, H5E_ARGS, FAIL, "can't close W/O FAPL");
897
898
0
    if (file->rw_file)
899
0
        if (H5FD_close(file->rw_file) == FAIL)
900
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to close R/W file");
901
0
    if (file->wo_file)
902
0
        if (H5FD_close(file->wo_file) == FAIL)
903
0
            H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
904
0
                                   "unable to close W/O file")
905
906
0
    if (file->logfp) {
907
0
        fclose(file->logfp);
908
0
        file->logfp = NULL;
909
0
    }
910
911
    /* Release the file info */
912
0
    file = H5FL_FREE(H5FD_splitter_t, file);
913
0
    file = NULL;
914
915
0
done:
916
0
    FUNC_LEAVE_NOAPI(ret_value)
917
0
} /* end H5FD__splitter_close() */
918
919
/*-------------------------------------------------------------------------
920
 * Function:    H5FD__splitter_get_eoa
921
 *
922
 * Purpose:     Returns the end-of-address marker for the file. The EOA
923
 *              marker is the first address past the last byte allocated in
924
 *              the format address space.
925
 *
926
 * Return:      Success:    The end-of-address-marker
927
 *
928
 *              Failure:    HADDR_UNDEF
929
 *-------------------------------------------------------------------------
930
 */
931
static haddr_t
932
H5FD__splitter_get_eoa(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
933
0
{
934
0
    const H5FD_splitter_t *file      = (const H5FD_splitter_t *)_file;
935
0
    haddr_t                ret_value = HADDR_UNDEF;
936
937
0
    FUNC_ENTER_PACKAGE
938
939
0
    H5FD_SPLITTER_LOG_CALL(__func__);
940
941
    /* Sanity check */
942
0
    assert(file);
943
0
    assert(file->rw_file);
944
945
0
    if ((ret_value = H5FD_get_eoa(file->rw_file, type)) == HADDR_UNDEF)
946
0
        HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, HADDR_UNDEF, "unable to get eoa");
947
948
0
done:
949
0
    FUNC_LEAVE_NOAPI(ret_value)
950
0
} /* end H5FD__splitter_get_eoa */
951
952
/*-------------------------------------------------------------------------
953
 * Function:    H5FD__splitter_set_eoa
954
 *
955
 * Purpose:     Set the end-of-address marker for the file. This function is
956
 *              called shortly after an existing HDF5 file is opened in order
957
 *              to tell the driver where the end of the HDF5 data is located.
958
 *
959
 * Return:      SUCCEED/FAIL
960
 *-------------------------------------------------------------------------
961
 */
962
static herr_t
963
H5FD__splitter_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr)
964
0
{
965
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
966
0
    herr_t           ret_value = SUCCEED; /* Return value */
967
968
0
    FUNC_ENTER_PACKAGE
969
970
0
    H5FD_SPLITTER_LOG_CALL(__func__)
971
972
    /* Sanity check */
973
0
    assert(file);
974
0
    assert(file->rw_file);
975
0
    assert(file->wo_file);
976
977
0
    if (H5FD_set_eoa(file->rw_file, type, addr) < 0)
978
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "H5FDset_eoa failed for R/W file");
979
980
0
    if (H5FD_set_eoa(file->wo_file, type, addr) < 0)
981
0
        H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTSET, FAIL, "unable to set EOA for W/O file")
982
983
0
done:
984
0
    FUNC_LEAVE_NOAPI(ret_value)
985
0
} /* end H5FD__splitter_set_eoa() */
986
987
/*-------------------------------------------------------------------------
988
 * Function:    H5FD__splitter_get_eof
989
 *
990
 * Purpose:     Returns the end-of-address marker for the file. The EOA
991
 *              marker is the first address past the last byte allocated in
992
 *              the format address space.
993
 *
994
 * Return:      Success:    The end-of-address-marker
995
 *
996
 *              Failure:    HADDR_UNDEF
997
 *-------------------------------------------------------------------------
998
 */
999
static haddr_t
1000
H5FD__splitter_get_eof(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
1001
0
{
1002
0
    const H5FD_splitter_t *file      = (const H5FD_splitter_t *)_file;
1003
0
    haddr_t                ret_value = HADDR_UNDEF; /* Return value */
1004
1005
0
    FUNC_ENTER_PACKAGE
1006
1007
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1008
1009
    /* Sanity check */
1010
0
    assert(file);
1011
0
    assert(file->rw_file);
1012
1013
0
    if (HADDR_UNDEF == (ret_value = H5FD_get_eof(file->rw_file, type)))
1014
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTGET, HADDR_UNDEF, "unable to get eof");
1015
1016
0
done:
1017
0
    FUNC_LEAVE_NOAPI(ret_value)
1018
0
} /* end H5FD__splitter_get_eof */
1019
1020
/*-------------------------------------------------------------------------
1021
 * Function:    H5FD__splitter_truncate
1022
 *
1023
 * Purpose:     Notify driver to truncate the file back to the allocated size.
1024
 *
1025
 * Return:      SUCCEED/FAIL
1026
 *-------------------------------------------------------------------------
1027
 */
1028
static herr_t
1029
H5FD__splitter_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing)
1030
0
{
1031
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
1032
0
    herr_t           ret_value = SUCCEED; /* Return value */
1033
1034
0
    FUNC_ENTER_PACKAGE
1035
1036
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1037
1038
0
    assert(file);
1039
0
    assert(file->rw_file);
1040
0
    assert(file->wo_file);
1041
1042
0
    if (H5FDtruncate(file->rw_file, dxpl_id, closing) < 0)
1043
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTUPDATE, FAIL, "unable to truncate R/W file");
1044
1045
0
    if (H5FDtruncate(file->wo_file, dxpl_id, closing) < 0)
1046
0
        H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTUPDATE, FAIL, "unable to truncate W/O file")
1047
1048
0
done:
1049
0
    FUNC_LEAVE_NOAPI(ret_value)
1050
0
} /* end H5FD__splitter_truncate */
1051
1052
/*-------------------------------------------------------------------------
1053
 * Function:    H5FD__splitter_sb_size
1054
 *
1055
 * Purpose:     Obtains the number of bytes required to store the driver file
1056
 *              access data in the HDF5 superblock.
1057
 *
1058
 * Return:      Success:    Number of bytes required.
1059
 *
1060
 *              Failure:    0 if an error occurs or if the driver has no
1061
 *                          data to store in the superblock.
1062
 *
1063
 * NOTE: no public API for H5FD_sb_size, it needs to be added
1064
 *-------------------------------------------------------------------------
1065
 */
1066
static hsize_t
1067
H5FD__splitter_sb_size(H5FD_t *_file)
1068
0
{
1069
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
1070
0
    hsize_t          ret_value = 0;
1071
1072
0
    FUNC_ENTER_PACKAGE_NOERR
1073
1074
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1075
1076
    /* Sanity check */
1077
0
    assert(file);
1078
0
    assert(file->rw_file);
1079
1080
0
    if (file->rw_file)
1081
0
        ret_value = H5FD_sb_size(file->rw_file);
1082
1083
0
    FUNC_LEAVE_NOAPI(ret_value)
1084
0
} /* end H5FD__splitter_sb_size */
1085
1086
/*-------------------------------------------------------------------------
1087
 * Function:    H5FD__splitter_sb_encode
1088
 *
1089
 * Purpose:     Encode driver-specific data into the output arguments.
1090
 *
1091
 * Return:      SUCCEED/FAIL
1092
 *-------------------------------------------------------------------------
1093
 */
1094
static herr_t
1095
H5FD__splitter_sb_encode(H5FD_t *_file, char *name /*out*/, unsigned char *buf /*out*/)
1096
0
{
1097
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
1098
0
    herr_t           ret_value = SUCCEED; /* Return value */
1099
1100
0
    FUNC_ENTER_PACKAGE
1101
1102
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1103
1104
    /* Sanity check */
1105
0
    assert(file);
1106
0
    assert(file->rw_file);
1107
1108
0
    if (file->rw_file && H5FD_sb_encode(file->rw_file, name, buf) < 0)
1109
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTENCODE, FAIL, "unable to encode the superblock in R/W file");
1110
1111
0
done:
1112
0
    FUNC_LEAVE_NOAPI(ret_value)
1113
0
} /* end H5FD__splitter_sb_encode */
1114
1115
/*-------------------------------------------------------------------------
1116
 * Function:    H5FD__splitter_sb_decode
1117
 *
1118
 * Purpose:     Decodes the driver information block.
1119
 *
1120
 * Return:      SUCCEED/FAIL
1121
 *
1122
 * NOTE: no public API for H5FD_sb_size, need to add
1123
 *-------------------------------------------------------------------------
1124
 */
1125
static herr_t
1126
H5FD__splitter_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf)
1127
0
{
1128
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
1129
0
    herr_t           ret_value = SUCCEED; /* Return value */
1130
1131
0
    FUNC_ENTER_PACKAGE
1132
1133
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1134
1135
    /* Sanity check */
1136
0
    assert(file);
1137
0
    assert(file->rw_file);
1138
1139
0
    if (H5FD_sb_load(file->rw_file, name, buf) < 0)
1140
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, FAIL, "unable to decode the superblock in R/W file");
1141
1142
0
done:
1143
0
    FUNC_LEAVE_NOAPI(ret_value)
1144
0
} /* end H5FD__splitter_sb_decode */
1145
1146
/*-------------------------------------------------------------------------
1147
 * Function:    H5FD__splitter_cmp
1148
 *
1149
 * Purpose:     Compare the keys of two files.
1150
 *
1151
 * Return:      Success:    A value like strcmp()
1152
 *              Failure:    Must never fail
1153
 *-------------------------------------------------------------------------
1154
 */
1155
static int
1156
H5FD__splitter_cmp(const H5FD_t *_f1, const H5FD_t *_f2)
1157
0
{
1158
0
    const H5FD_splitter_t *f1        = (const H5FD_splitter_t *)_f1;
1159
0
    const H5FD_splitter_t *f2        = (const H5FD_splitter_t *)_f2;
1160
0
    herr_t                 ret_value = 0; /* Return value */
1161
1162
0
    FUNC_ENTER_PACKAGE_NOERR
1163
1164
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1165
1166
0
    assert(f1);
1167
0
    assert(f2);
1168
1169
0
    ret_value = H5FD_cmp(f1->rw_file, f2->rw_file);
1170
1171
0
    FUNC_LEAVE_NOAPI(ret_value)
1172
0
} /* end H5FD__splitter_cmp */
1173
1174
/*--------------------------------------------------------------------------
1175
 * Function:    H5FD__splitter_get_handle
1176
 *
1177
 * Purpose:     Returns a pointer to the file handle of low-level virtual
1178
 *              file driver.
1179
 *
1180
 * Return:      SUCCEED/FAIL
1181
 *--------------------------------------------------------------------------
1182
 */
1183
static herr_t
1184
H5FD__splitter_get_handle(H5FD_t *_file, hid_t H5_ATTR_UNUSED fapl, void **file_handle)
1185
0
{
1186
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
1187
0
    herr_t           ret_value = SUCCEED; /* Return value */
1188
1189
0
    FUNC_ENTER_PACKAGE
1190
1191
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1192
1193
    /* Check arguments */
1194
0
    assert(file);
1195
0
    assert(file->rw_file);
1196
0
    assert(file_handle);
1197
1198
    /* Only do for R/W channel */
1199
0
    if (H5FD_get_vfd_handle(file->rw_file, file->fa.rw_fapl_id, file_handle) < 0)
1200
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "unable to get handle of R/W file");
1201
1202
0
done:
1203
0
    FUNC_LEAVE_NOAPI(ret_value)
1204
0
} /* end H5FD__splitter_get_handle */
1205
1206
/*--------------------------------------------------------------------------
1207
 * Function:    H5FD__splitter_lock
1208
 *
1209
 * Purpose:     Sets a file lock.
1210
 *
1211
 * Return:      SUCCEED/FAIL
1212
 *--------------------------------------------------------------------------
1213
 */
1214
static herr_t
1215
H5FD__splitter_lock(H5FD_t *_file, bool rw)
1216
0
{
1217
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file; /* VFD file struct */
1218
0
    herr_t           ret_value = SUCCEED;                  /* Return value */
1219
1220
0
    FUNC_ENTER_PACKAGE
1221
1222
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1223
1224
0
    assert(file);
1225
0
    assert(file->rw_file);
1226
1227
    /* Place the lock on each file */
1228
0
    if (H5FD_lock(file->rw_file, rw) < 0)
1229
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTLOCKFILE, FAIL, "unable to lock R/W file");
1230
1231
0
    if (file->wo_file != NULL)
1232
0
        if (H5FD_lock(file->wo_file, rw) < 0)
1233
0
            H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTLOCKFILE, FAIL, "unable to lock W/O file")
1234
1235
0
done:
1236
0
    FUNC_LEAVE_NOAPI(ret_value)
1237
0
} /* end H5FD__splitter_lock */
1238
1239
/*--------------------------------------------------------------------------
1240
 * Function:    H5FD__splitter_unlock
1241
 *
1242
 * Purpose:     Removes a file lock.
1243
 *
1244
 * Return:      SUCCEED/FAIL
1245
 *--------------------------------------------------------------------------
1246
 */
1247
static herr_t
1248
H5FD__splitter_unlock(H5FD_t *_file)
1249
0
{
1250
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file; /* VFD file struct */
1251
0
    herr_t           ret_value = SUCCEED;                  /* Return value */
1252
1253
0
    FUNC_ENTER_PACKAGE
1254
1255
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1256
1257
    /* Check arguments */
1258
0
    assert(file);
1259
0
    assert(file->rw_file);
1260
1261
    /* Remove the lock on each file */
1262
0
    if (H5FD_unlock(file->rw_file) < 0)
1263
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTUNLOCKFILE, FAIL, "unable to unlock R/W file");
1264
1265
0
    if (file->wo_file != NULL)
1266
0
        if (H5FD_unlock(file->wo_file) < 0)
1267
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTUNLOCKFILE, FAIL, "unable to unlock W/O file");
1268
1269
0
done:
1270
0
    FUNC_LEAVE_NOAPI(ret_value)
1271
0
} /* end H5FD__splitter_unlock */
1272
1273
/*-------------------------------------------------------------------------
1274
 * Function:    H5FD__splitter_ctl
1275
 *
1276
 * Purpose:     Splitter VFD version of the ctl callback.
1277
 *
1278
 *              The desired operation is specified by the op_code
1279
 *              parameter.
1280
 *
1281
 *              The flags parameter controls management of op_codes that
1282
 *              are unknown to the callback
1283
 *
1284
 *              The input and output parameters allow op_code specific
1285
 *              input and output
1286
 *
1287
 *              At present, this VFD supports no op codes of its own and
1288
 *              simply passes ctl calls on to the R/W channel VFD.
1289
 *
1290
 * Return:      Non-negative on success/Negative on failure
1291
 *
1292
 *-------------------------------------------------------------------------
1293
 */
1294
static herr_t
1295
H5FD__splitter_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void *input, void **output)
1296
0
{
1297
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file;
1298
0
    herr_t           ret_value = SUCCEED;
1299
1300
0
    FUNC_ENTER_PACKAGE
1301
1302
    /* Sanity checks */
1303
0
    assert(file);
1304
1305
0
    switch (op_code) {
1306
        /* Unknown op code */
1307
0
        default:
1308
0
            if (flags & H5FD_CTL_ROUTE_TO_TERMINAL_VFD_FLAG) {
1309
                /* Pass ctl call down to R/W channel VFD */
1310
0
                if (H5FDctl(file->rw_file, op_code, flags, input, output) < 0)
1311
0
                    HGOTO_ERROR(H5E_VFL, H5E_FCNTL, FAIL, "VFD ctl request failed");
1312
0
            }
1313
0
            else {
1314
                /* If no valid VFD routing flag is specified, fail for unknown op code
1315
                 * if H5FD_CTL_FAIL_IF_UNKNOWN_FLAG flag is set.
1316
                 */
1317
0
                if (flags & H5FD_CTL_FAIL_IF_UNKNOWN_FLAG)
1318
0
                    HGOTO_ERROR(H5E_VFL, H5E_FCNTL, FAIL,
1319
0
                                "VFD ctl request failed (unknown op code and fail if unknown flag is set)");
1320
0
            }
1321
1322
0
            break;
1323
0
    }
1324
1325
0
done:
1326
0
    FUNC_LEAVE_NOAPI(ret_value)
1327
0
} /* end H5FD__splitter_ctl() */
1328
1329
/*-------------------------------------------------------------------------
1330
 * Function:    H5FD__splitter_query
1331
 *
1332
 * Purpose:     Set the flags that this VFL driver is capable of supporting.
1333
 *              (listed in H5FDpublic.h)
1334
 *
1335
 * Return:      SUCCEED/FAIL
1336
 *-------------------------------------------------------------------------
1337
 */
1338
static herr_t
1339
H5FD__splitter_query(const H5FD_t *_file, unsigned long *flags /* out */)
1340
0
{
1341
0
    const H5FD_splitter_t *file      = (const H5FD_splitter_t *)_file;
1342
0
    herr_t                 ret_value = SUCCEED;
1343
1344
0
    FUNC_ENTER_PACKAGE
1345
1346
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1347
1348
0
    if (file) {
1349
0
        assert(file);
1350
0
        assert(file->rw_file);
1351
1352
0
        if (H5FDquery(file->rw_file, flags) < 0)
1353
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTLOCK, FAIL, "unable to query R/W file");
1354
0
    }
1355
0
    else {
1356
        /* There is no file. Because this is a pure passthrough VFD,
1357
         * it has no features of its own.
1358
         */
1359
0
        if (flags)
1360
0
            *flags = 0;
1361
0
    }
1362
1363
0
done:
1364
0
    FUNC_LEAVE_NOAPI(ret_value)
1365
0
} /* end H5FD__splitter_query() */
1366
1367
/*-------------------------------------------------------------------------
1368
 * Function:    H5FD__splitter_alloc
1369
 *
1370
 * Purpose:     Allocate file memory.
1371
 *
1372
 * Return:      Address of allocated space (HADDR_UNDEF if error).
1373
 *-------------------------------------------------------------------------
1374
 */
1375
static haddr_t
1376
H5FD__splitter_alloc(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size)
1377
0
{
1378
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file; /* VFD file struct */
1379
0
    haddr_t          ret_value = HADDR_UNDEF;              /* Return value */
1380
1381
0
    FUNC_ENTER_PACKAGE
1382
1383
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1384
1385
    /* Check arguments */
1386
0
    assert(file);
1387
0
    assert(file->rw_file);
1388
1389
    /* Allocate memory for each file, only return the return value for R/W file. */
1390
0
    if ((ret_value = H5FDalloc(file->rw_file, type, dxpl_id, size)) == HADDR_UNDEF)
1391
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, HADDR_UNDEF, "unable to allocate for R/W file");
1392
1393
0
    if (H5FDalloc(file->wo_file, type, dxpl_id, size) == HADDR_UNDEF)
1394
0
        H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTINIT, HADDR_UNDEF,
1395
0
                               "unable to alloc for W/O file")
1396
1397
0
done:
1398
0
    FUNC_LEAVE_NOAPI(ret_value)
1399
0
} /* end H5FD__splitter_alloc() */
1400
1401
/*-------------------------------------------------------------------------
1402
 * Function:    H5FD__splitter_get_type_map
1403
 *
1404
 * Purpose:     Retrieve the memory type mapping for this file
1405
 *
1406
 * Return:      SUCCEED/FAIL
1407
 *-------------------------------------------------------------------------
1408
 */
1409
static herr_t
1410
H5FD__splitter_get_type_map(const H5FD_t *_file, H5FD_mem_t *type_map)
1411
0
{
1412
0
    const H5FD_splitter_t *file      = (const H5FD_splitter_t *)_file;
1413
0
    herr_t                 ret_value = SUCCEED;
1414
1415
0
    FUNC_ENTER_PACKAGE
1416
1417
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1418
1419
    /* Check arguments */
1420
0
    assert(file);
1421
0
    assert(file->rw_file);
1422
1423
    /* Retrieve memory type mapping for R/W channel only */
1424
0
    if (H5FD_get_fs_type_map(file->rw_file, type_map) < 0)
1425
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "unable to allocate for R/W file");
1426
1427
0
done:
1428
0
    FUNC_LEAVE_NOAPI(ret_value)
1429
0
} /* end H5FD__splitter_get_type_map() */
1430
1431
/*-------------------------------------------------------------------------
1432
 * Function:    H5FD__splitter_free
1433
 *
1434
 * Purpose:     Free the resources for the splitter VFD.
1435
 *
1436
 * Return:      SUCCEED/FAIL
1437
 *-------------------------------------------------------------------------
1438
 */
1439
static herr_t
1440
H5FD__splitter_free(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t size)
1441
0
{
1442
0
    H5FD_splitter_t *file      = (H5FD_splitter_t *)_file; /* VFD file struct */
1443
0
    herr_t           ret_value = SUCCEED;                  /* Return value */
1444
1445
0
    FUNC_ENTER_PACKAGE
1446
1447
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1448
1449
    /* Check arguments */
1450
0
    assert(file);
1451
0
    assert(file->rw_file);
1452
1453
0
    if (H5FDfree(file->rw_file, type, dxpl_id, addr, size) < 0)
1454
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "unable to free for R/W file");
1455
1456
0
    if (H5FDfree(file->wo_file, type, dxpl_id, addr, size) < 0)
1457
0
        H5FD_SPLITTER_WO_ERROR(file, __func__, H5E_VFL, H5E_CANTINIT, FAIL, "unable to free for W/O file")
1458
1459
0
done:
1460
0
    FUNC_LEAVE_NOAPI(ret_value)
1461
0
} /* end H5FD__splitter_free() */
1462
1463
/*-------------------------------------------------------------------------
1464
 * Function:    H5FD__splitter_delete
1465
 *
1466
 * Purpose:     Delete a file
1467
 *
1468
 * Return:      SUCCEED/FAIL
1469
 *
1470
 *-------------------------------------------------------------------------
1471
 */
1472
static herr_t
1473
H5FD__splitter_delete(const char *filename, hid_t fapl_id)
1474
0
{
1475
0
    const H5FD_splitter_fapl_t *fapl_ptr     = NULL;
1476
0
    H5FD_splitter_fapl_t       *default_fapl = NULL;
1477
0
    H5P_genplist_t             *plist;
1478
0
    herr_t                      ret_value = SUCCEED;
1479
1480
0
    FUNC_ENTER_PACKAGE
1481
1482
0
    assert(filename);
1483
1484
    /* Get the driver info */
1485
0
    if (H5P_FILE_ACCESS_DEFAULT == fapl_id) {
1486
0
        if (NULL == (default_fapl = H5FL_CALLOC(H5FD_splitter_fapl_t)))
1487
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate file access property list struct");
1488
0
        if (H5FD__splitter_populate_config(NULL, default_fapl) < 0)
1489
0
            HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't initialize driver configuration info");
1490
1491
        /* If W/O path is not set, use base filename with '_wo' suffix */
1492
0
        if (*default_fapl->wo_path == '\0')
1493
0
            if (H5FD__splitter_get_default_wo_path(default_fapl->wo_path, H5FD_SPLITTER_PATH_MAX + 1,
1494
0
                                                   filename) < 0)
1495
0
                HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't generate default filename for W/O channel");
1496
1497
0
        fapl_ptr = default_fapl;
1498
0
    }
1499
0
    else {
1500
0
        if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
1501
0
            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list");
1502
0
        if (NULL == (fapl_ptr = (const H5FD_splitter_fapl_t *)H5P_peek_driver_info(plist))) {
1503
0
            if (NULL == (default_fapl = H5FL_CALLOC(H5FD_splitter_fapl_t)))
1504
0
                HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL,
1505
0
                            "unable to allocate file access property list struct");
1506
0
            if (H5FD__splitter_populate_config(NULL, default_fapl) < 0)
1507
0
                HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't initialize driver configuration info");
1508
1509
            /* If W/O path is not set, use base filename with '_wo' suffix */
1510
0
            if (*default_fapl->wo_path == '\0')
1511
0
                if (H5FD__splitter_get_default_wo_path(default_fapl->wo_path, H5FD_SPLITTER_PATH_MAX + 1,
1512
0
                                                       filename) < 0)
1513
0
                    HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL,
1514
0
                                "can't generate default filename for W/O channel");
1515
1516
0
            fapl_ptr = default_fapl;
1517
0
        }
1518
0
    }
1519
1520
0
    if (H5FDdelete(filename, fapl_ptr->rw_fapl_id) < 0)
1521
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "unable to delete file");
1522
0
    if (H5FDdelete(fapl_ptr->wo_path, fapl_ptr->wo_fapl_id) < 0)
1523
0
        HGOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "unable to delete W/O channel file");
1524
1525
0
done:
1526
0
    if (default_fapl)
1527
0
        H5FL_FREE(H5FD_splitter_fapl_t, default_fapl);
1528
1529
0
    FUNC_LEAVE_NOAPI(ret_value)
1530
0
}
1531
1532
/*-------------------------------------------------------------------------
1533
 * Function:    H5FD__splitter_log_error
1534
 *
1535
 * Purpose:     Log an error from the W/O channel appropriately.
1536
 *
1537
 * Return:      SUCCEED/FAIL
1538
 *-------------------------------------------------------------------------
1539
 */
1540
static herr_t
1541
H5FD__splitter_log_error(const H5FD_splitter_t *file, const char *atfunc, const char *msg)
1542
0
{
1543
0
    herr_t ret_value = SUCCEED;
1544
1545
0
    FUNC_ENTER_PACKAGE_NOERR
1546
1547
0
    H5FD_SPLITTER_LOG_CALL(__func__);
1548
1549
    /* Check arguments */
1550
0
    assert(file);
1551
0
    assert(atfunc && *atfunc);
1552
0
    assert(msg && *msg);
1553
1554
0
    if (file->logfp != NULL) {
1555
0
        size_t size;
1556
0
        char  *s;
1557
1558
0
        size = strlen(atfunc) + strlen(msg) + 3; /* ':', ' ', '\n' */
1559
0
        s    = (char *)H5MM_malloc(sizeof(char) * (size + 1));
1560
0
        if (NULL == s)
1561
0
            ret_value = FAIL;
1562
0
        else if (size < (size_t)snprintf(s, size + 1, "%s: %s\n", atfunc, msg))
1563
0
            ret_value = FAIL;
1564
0
        else if (size != fwrite(s, 1, size, file->logfp))
1565
0
            ret_value = FAIL;
1566
0
        H5MM_free(s);
1567
0
    }
1568
1569
0
    FUNC_LEAVE_NOAPI(ret_value)
1570
0
} /* end H5FD__splitter_log_error() */