Coverage Report

Created: 2026-12-04 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Dnone.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: Implicit (Non Index) chunked I/O functions.
15
 *
16
 *          This is used when the dataset is:
17
 *            - extendible but with fixed max. dims
18
 *            - with early allocation
19
 *            - without filter
20
 *
21
 *          The chunk coordinate is mapped into the actual disk addresses
22
 *          for the chunk without indexing.
23
 */
24
25
/****************/
26
/* Module Setup */
27
/****************/
28
29
#include "H5Dmodule.h" /* This source code file is part of the H5D module */
30
31
/***********/
32
/* Headers */
33
/***********/
34
#include "H5private.h"   /* Generic Functions                    */
35
#include "H5Dpkg.h"      /* Datasets                             */
36
#include "H5Eprivate.h"  /* Error handling                       */
37
#include "H5MFprivate.h" /* File space management                */
38
#include "H5VMprivate.h" /* Vector functions                     */
39
40
/****************/
41
/* Local Macros */
42
/****************/
43
44
/******************/
45
/* Local Typedefs */
46
/******************/
47
48
/********************/
49
/* Local Prototypes */
50
/********************/
51
52
/* Non Index chunking I/O ops */
53
static herr_t H5D__none_idx_create(const H5D_chk_idx_info_t *idx_info);
54
static herr_t H5D__none_idx_open(const H5D_chk_idx_info_t *idx_info);
55
static herr_t H5D__none_idx_close(const H5D_chk_idx_info_t *idx_info);
56
static herr_t H5D__none_idx_is_open(const H5D_chk_idx_info_t *idx_info, bool *is_open);
57
static bool   H5D__none_idx_is_space_alloc(const H5O_storage_chunk_t *storage);
58
static herr_t H5D__none_idx_get_addr(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udata);
59
static herr_t H5D__none_idx_load_metadata(const H5D_chk_idx_info_t *idx_info);
60
static int    H5D__none_idx_iterate(const H5D_chk_idx_info_t *idx_info, H5D_chunk_cb_func_t chunk_cb,
61
                                    void *chunk_udata);
62
static herr_t H5D__none_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t *udata);
63
static herr_t H5D__none_idx_delete(const H5D_chk_idx_info_t *idx_info);
64
static herr_t H5D__none_idx_copy_setup(const H5D_chk_idx_info_t *idx_info_src,
65
                                       const H5D_chk_idx_info_t *idx_info_dst);
66
static herr_t H5D__none_idx_size(const H5D_chk_idx_info_t *idx_info, hsize_t *size);
67
static herr_t H5D__none_idx_reset(H5O_storage_chunk_t *storage, bool reset_addr);
68
static herr_t H5D__none_idx_dump(const H5O_storage_chunk_t *storage, FILE *stream);
69
70
/*********************/
71
/* Package Variables */
72
/*********************/
73
74
/* Non Index chunk I/O ops */
75
const H5D_chunk_ops_t H5D_COPS_NONE[1] = {{
76
    false,                        /* Non-indexed chunking don't current support SWMR access */
77
    NULL,                         /* init */
78
    H5D__none_idx_create,         /* create */
79
    H5D__none_idx_open,           /* open */
80
    H5D__none_idx_close,          /* close */
81
    H5D__none_idx_is_open,        /* is_open */
82
    H5D__none_idx_is_space_alloc, /* is_space_alloc */
83
    NULL,                         /* insert */
84
    H5D__none_idx_get_addr,       /* get_addr */
85
    H5D__none_idx_load_metadata,  /* load_metadata */
86
    NULL,                         /* resize */
87
    H5D__none_idx_iterate,        /* iterate */
88
    H5D__none_idx_remove,         /* remove */
89
    H5D__none_idx_delete,         /* delete */
90
    H5D__none_idx_copy_setup,     /* copy_setup */
91
    NULL,                         /* copy_shutdown */
92
    H5D__none_idx_size,           /* size */
93
    H5D__none_idx_reset,          /* reset */
94
    H5D__none_idx_dump,           /* dump */
95
    NULL                          /* dest */
96
}};
97
98
/*****************************/
99
/* Library Private Variables */
100
/*****************************/
101
102
/*******************/
103
/* Local Variables */
104
/*******************/
105
106
/*-------------------------------------------------------------------------
107
 * Function:    H5D__none_idx_create
108
 *
109
 * Purpose:     Allocate memory for the maximum # of chunks in the dataset.
110
 *
111
 * Return:      Non-negative on success
112
 *              Negative on failure.
113
 *
114
 *-------------------------------------------------------------------------
115
 */
116
static herr_t
117
H5D__none_idx_create(const H5D_chk_idx_info_t *idx_info)
118
0
{
119
0
    hsize_t nbytes;              /* Total size of dataset chunks */
120
0
    haddr_t addr;                /* The address of dataset chunks */
121
0
    herr_t  ret_value = SUCCEED; /* Return value */
122
123
0
    FUNC_ENTER_PACKAGE
124
125
    /* Check args */
126
0
    assert(idx_info);
127
0
    assert(idx_info->f);
128
0
    assert(idx_info->pline);
129
0
    assert(idx_info->pline->nused == 0); /* Shouldn't have filter defined on entering here */
130
0
    assert(idx_info->layout);
131
0
    assert(idx_info->layout->u.chunk.max_nchunks);
132
0
    assert(!H5_addr_defined(
133
0
        idx_info->layout->storage.u.chunk.idx_addr)); /* address of data shouldn't be defined */
134
135
    /* Calculate size of max dataset chunks */
136
0
    nbytes = idx_info->layout->u.chunk.max_nchunks * idx_info->layout->u.chunk.size;
137
138
    /* Allocate space for max dataset chunks */
139
0
    addr = H5MF_alloc(idx_info->f, H5FD_MEM_DRAW, nbytes);
140
0
    if (!H5_addr_defined(addr))
141
0
        HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "file allocation failed");
142
143
    /* This is the address of the dataset chunks */
144
0
    idx_info->layout->storage.u.chunk.idx_addr = addr;
145
146
0
done:
147
0
    FUNC_LEAVE_NOAPI(ret_value)
148
0
} /* end H5D__none_idx_create() */
149
150
/*-------------------------------------------------------------------------
151
 * Function:    H5D__none_idx_open
152
 *
153
 * Purpose:     Opens an existing "none" index. Currently a no-op.
154
 *
155
 * Return:      SUCCEED (can't fail)
156
 *
157
 *-------------------------------------------------------------------------
158
 */
159
static herr_t
160
H5D__none_idx_open(const H5D_chk_idx_info_t H5_ATTR_UNUSED *idx_info)
161
0
{
162
0
    FUNC_ENTER_PACKAGE_NOERR
163
164
    /* NO OP */
165
166
0
    FUNC_LEAVE_NOAPI(SUCCEED)
167
0
} /* end H5D__none_idx_open() */
168
169
/*-------------------------------------------------------------------------
170
 * Function:    H5D__none_idx_close
171
 *
172
 * Purpose:     Closes an existing "none" index. Currently a no-op.
173
 *
174
 * Return:      SUCCEED (can't fail)
175
 *
176
 *-------------------------------------------------------------------------
177
 */
178
static herr_t
179
H5D__none_idx_close(const H5D_chk_idx_info_t H5_ATTR_UNUSED *idx_info)
180
0
{
181
0
    FUNC_ENTER_PACKAGE_NOERR
182
183
    /* NO OP */
184
185
0
    FUNC_LEAVE_NOAPI(SUCCEED)
186
0
} /* end H5D__none_idx_close() */
187
188
/*-------------------------------------------------------------------------
189
 * Function:    H5D__none_idx_is_open
190
 *
191
 * Purpose:     Query if the index is opened or not
192
 *
193
 * Return:      SUCCEED (can't fail)
194
 *
195
 *-------------------------------------------------------------------------
196
 */
197
static herr_t
198
H5D__none_idx_is_open(const H5D_chk_idx_info_t H5_ATTR_NDEBUG_UNUSED *idx_info, bool *is_open)
199
0
{
200
0
    FUNC_ENTER_PACKAGE_NOERR
201
202
0
    assert(idx_info);
203
0
    assert(idx_info->layout);
204
0
    assert(H5D_CHUNK_IDX_NONE == idx_info->layout->storage.u.chunk.idx_type);
205
0
    assert(is_open);
206
207
0
    *is_open = true;
208
209
0
    FUNC_LEAVE_NOAPI(SUCCEED)
210
0
} /* end H5D__none_idx_is_open() */
211
212
/*-------------------------------------------------------------------------
213
 * Function:    H5D__none_idx_is_space_alloc
214
 *
215
 * Purpose:     Query if space for the dataset chunks is allocated
216
 *
217
 * Return:      true/false
218
 *
219
 *-------------------------------------------------------------------------
220
 */
221
static bool
222
H5D__none_idx_is_space_alloc(const H5O_storage_chunk_t *storage)
223
0
{
224
0
    FUNC_ENTER_PACKAGE_NOERR
225
226
    /* Check args */
227
0
    assert(storage);
228
229
0
    FUNC_LEAVE_NOAPI((bool)H5_addr_defined(storage->idx_addr))
230
0
} /* end H5D__none_idx_is_space_alloc() */
231
232
/*-------------------------------------------------------------------------
233
 * Function:    H5D__none_idx_get_addr
234
 *
235
 * Purpose:     Get the file address of a chunk.
236
 *              Save the retrieved information in the udata supplied.
237
 *
238
 * Return:      Non-negative on success/Negative on failure
239
 *
240
 *-------------------------------------------------------------------------
241
 */
242
static herr_t
243
H5D__none_idx_get_addr(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udata)
244
0
{
245
0
    FUNC_ENTER_PACKAGE_NOERR
246
247
    /* Sanity checks */
248
0
    assert(idx_info);
249
0
    assert(idx_info->f);
250
0
    assert(idx_info->pline);
251
0
    assert(idx_info->pline->nused == 0);
252
0
    assert(idx_info->layout);
253
0
    assert(udata);
254
0
    assert(H5_addr_defined(idx_info->layout->storage.u.chunk.idx_addr));
255
256
    /* Calculate the index of this chunk */
257
0
    udata->chunk_idx = H5VM_array_offset_pre((idx_info->layout->u.chunk.ndims - 1),
258
0
                                             idx_info->layout->u.chunk.max_down_chunks, udata->common.scaled);
259
260
    /* Calculate the address of the chunk */
261
0
    udata->chunk_block.offset =
262
0
        idx_info->layout->storage.u.chunk.idx_addr + udata->chunk_idx * idx_info->layout->u.chunk.size;
263
264
    /* Update the other (constant) information for the chunk */
265
0
    udata->chunk_block.length = idx_info->layout->u.chunk.size;
266
0
    udata->filter_mask        = 0;
267
268
0
    FUNC_LEAVE_NOAPI(SUCCEED)
269
0
} /* H5D__none_idx_get_addr() */
270
271
/*-------------------------------------------------------------------------
272
 * Function:    H5D__none_idx_load_metadata
273
 *
274
 * Purpose:     Load additional chunk index metadata beyond the chunk index
275
 *              itself. Currently a no-op.
276
 *
277
 * Return:      Non-negative on success/Negative on failure
278
 *
279
 *-------------------------------------------------------------------------
280
 */
281
static herr_t
282
H5D__none_idx_load_metadata(const H5D_chk_idx_info_t H5_ATTR_UNUSED *idx_info)
283
0
{
284
0
    FUNC_ENTER_PACKAGE_NOERR
285
286
    /* NO OP */
287
288
0
    FUNC_LEAVE_NOAPI(SUCCEED)
289
0
} /* H5D__none_idx_load_metadata() */
290
291
/*-------------------------------------------------------------------------
292
 * Function:    H5D__none_idx_iterate
293
 *
294
 * Purpose:     Iterate over the chunks in an index, making a callback
295
 *              for each one.
296
 *
297
 * Return:      Non-negative on success/Negative on failure
298
 *
299
 *-------------------------------------------------------------------------
300
 */
301
static int
302
H5D__none_idx_iterate(const H5D_chk_idx_info_t *idx_info, H5D_chunk_cb_func_t chunk_cb, void *chunk_udata)
303
0
{
304
0
    H5D_chunk_rec_t chunk_rec;                /* generic chunk record  */
305
0
    unsigned        ndims;                    /* Rank of chunk */
306
0
    unsigned        u;                        /* Local index variable */
307
0
    int             curr_dim;                 /* Current rank */
308
0
    hsize_t         idx;                      /* Array index of chunk */
309
0
    int             ret_value = H5_ITER_CONT; /* Return value */
310
311
0
    FUNC_ENTER_PACKAGE
312
313
    /* Sanity checks */
314
0
    assert(idx_info);
315
0
    assert(idx_info->f);
316
0
    assert(idx_info->pline);
317
0
    assert(!idx_info->pline->nused);
318
0
    assert(idx_info->layout);
319
0
    assert(chunk_cb);
320
0
    assert(chunk_udata);
321
0
    assert(H5_addr_defined(idx_info->layout->storage.u.chunk.idx_addr));
322
323
    /* Initialize generic chunk record */
324
0
    memset(&chunk_rec, 0, sizeof(chunk_rec));
325
0
    chunk_rec.nbytes      = idx_info->layout->u.chunk.size;
326
0
    chunk_rec.filter_mask = 0;
327
328
0
    ndims = idx_info->layout->u.chunk.ndims - 1;
329
0
    assert(ndims > 0);
330
331
    /* Iterate over all the chunks in the dataset's dataspace */
332
0
    for (u = 0; u < idx_info->layout->u.chunk.nchunks && ret_value == H5_ITER_CONT; u++) {
333
        /* Calculate the index of this chunk */
334
0
        idx = H5VM_array_offset_pre(ndims, idx_info->layout->u.chunk.max_down_chunks, chunk_rec.scaled);
335
336
        /* Calculate the address of the chunk */
337
0
        chunk_rec.chunk_addr =
338
0
            idx_info->layout->storage.u.chunk.idx_addr + idx * idx_info->layout->u.chunk.size;
339
340
        /* Make "generic chunk" callback */
341
0
        if ((ret_value = (*chunk_cb)(&chunk_rec, chunk_udata)) < 0)
342
0
            HGOTO_ERROR(H5E_DATASET, H5E_CALLBACK, H5_ITER_ERROR,
343
0
                        "failure in generic chunk iterator callback");
344
345
        /* Update coordinates of chunk in dataset */
346
0
        curr_dim = (int)(ndims - 1);
347
0
        while (curr_dim >= 0) {
348
            /* Increment coordinate in current dimension */
349
0
            chunk_rec.scaled[curr_dim]++;
350
351
            /* Check if we went off the end of the current dimension */
352
0
            if (chunk_rec.scaled[curr_dim] >= idx_info->layout->u.chunk.chunks[curr_dim]) {
353
                /* Reset coordinate & move to next faster dimension */
354
0
                chunk_rec.scaled[curr_dim] = 0;
355
0
                curr_dim--;
356
0
            } /* end if */
357
0
            else
358
0
                break;
359
0
        } /* end while */
360
0
    }     /* end for */
361
362
0
done:
363
0
    FUNC_LEAVE_NOAPI(ret_value)
364
0
} /* end H5D__none_idx_iterate() */
365
366
/*-------------------------------------------------------------------------
367
 * Function:    H5D__none_idx_remove
368
 *
369
 * Purpose:     Remove chunk from index.
370
 *
371
 * Note:        Chunks can't be removed (or added) to datasets with this
372
 *              form of index - all the space for all the chunks is always
373
 *              allocated in the file.
374
 *
375
 * Return:  Non-negative on success/Negative on failure
376
 *
377
 *-------------------------------------------------------------------------
378
 */
379
static herr_t
380
H5D__none_idx_remove(const H5D_chk_idx_info_t H5_ATTR_UNUSED *idx_info,
381
                     H5D_chunk_common_ud_t H5_ATTR_UNUSED    *udata)
382
0
{
383
0
    FUNC_ENTER_PACKAGE_NOERR
384
385
    /* NO OP */
386
387
0
    FUNC_LEAVE_NOAPI(SUCCEED)
388
0
} /* H5D__none_idx_remove() */
389
390
/*-------------------------------------------------------------------------
391
 * Function:    H5D__none_idx_delete
392
 *
393
 * Purpose:     Delete raw data storage for entire dataset (i.e. all chunks)
394
 *
395
 * Return:      Success:    Non-negative
396
 *              Failure:    negative
397
 *
398
 *-------------------------------------------------------------------------
399
 */
400
static herr_t
401
H5D__none_idx_delete(const H5D_chk_idx_info_t *idx_info)
402
0
{
403
0
    hsize_t nbytes;              /* Size of all chunks */
404
0
    herr_t  ret_value = SUCCEED; /* Return value */
405
406
0
    FUNC_ENTER_PACKAGE
407
408
    /* Sanity checks */
409
0
    assert(idx_info);
410
0
    assert(idx_info->f);
411
0
    assert(idx_info->pline);
412
0
    assert(!idx_info->pline->nused); /* Shouldn't have filter defined on entering here */
413
0
    assert(idx_info->layout);
414
0
    assert(H5_addr_defined(idx_info->layout->storage.u.chunk.idx_addr)); /* should be defined */
415
416
    /* chunk size * max # of chunks */
417
0
    nbytes = idx_info->layout->u.chunk.max_nchunks * idx_info->layout->u.chunk.size;
418
0
    if (H5MF_xfree(idx_info->f, H5FD_MEM_DRAW, idx_info->layout->storage.u.chunk.idx_addr, nbytes) < 0)
419
0
        HGOTO_ERROR(H5E_DATASET, H5E_CANTFREE, H5_ITER_ERROR, "unable to free dataset chunks");
420
421
0
    idx_info->layout->storage.u.chunk.idx_addr = HADDR_UNDEF;
422
423
0
done:
424
0
    FUNC_LEAVE_NOAPI(ret_value)
425
0
} /* end H5D__none_idx_delete() */
426
427
/*-------------------------------------------------------------------------
428
 * Function:    H5D__none_idx_copy_setup
429
 *
430
 * Purpose:     Set up any necessary information for copying chunks
431
 *
432
 * Return:      Non-negative on success/Negative on failure
433
 *
434
 *-------------------------------------------------------------------------
435
 */
436
static herr_t
437
H5D__none_idx_copy_setup(const H5D_chk_idx_info_t H5_ATTR_NDEBUG_UNUSED *idx_info_src,
438
                         const H5D_chk_idx_info_t                       *idx_info_dst)
439
0
{
440
0
    herr_t ret_value = SUCCEED; /* Return value */
441
442
0
    FUNC_ENTER_PACKAGE
443
444
    /* Check args */
445
0
    assert(idx_info_src);
446
0
    assert(idx_info_src->f);
447
0
    assert(idx_info_src->pline);
448
0
    assert(!idx_info_src->pline->nused);
449
0
    assert(idx_info_src->layout);
450
0
    assert(H5_addr_defined(idx_info_src->layout->storage.u.chunk.idx_addr));
451
452
0
    assert(idx_info_dst);
453
0
    assert(idx_info_dst->f);
454
0
    assert(idx_info_dst->pline);
455
0
    assert(!idx_info_dst->pline->nused);
456
0
    assert(idx_info_dst->layout);
457
458
    /* Set copied metadata tag */
459
0
    H5_BEGIN_TAG(H5AC__COPIED_TAG)
460
461
    /* Allocate dataset chunks in the dest. file */
462
0
    if (H5D__none_idx_create(idx_info_dst) < 0)
463
0
        HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize chunked storage");
464
465
    /* Reset metadata tag */
466
0
    H5_END_TAG
467
468
0
done:
469
0
    FUNC_LEAVE_NOAPI(ret_value)
470
0
} /* end H5D__none_idx_copy_setup() */
471
472
/*-------------------------------------------------------------------------
473
 * Function:    H5D__none_idx_size
474
 *
475
 * Purpose:     Retrieve the amount of index storage for chunked dataset
476
 *
477
 * Return:      Success:        Non-negative
478
 *              Failure:        negative
479
 *
480
 *-------------------------------------------------------------------------
481
 */
482
static herr_t
483
H5D__none_idx_size(const H5D_chk_idx_info_t H5_ATTR_UNUSED *idx_info, hsize_t *index_size)
484
0
{
485
0
    FUNC_ENTER_PACKAGE_NOERR
486
487
    /* Check args */
488
0
    assert(index_size);
489
490
0
    *index_size = 0;
491
492
0
    FUNC_LEAVE_NOAPI(SUCCEED)
493
0
} /* end H5D__none_idx_size() */
494
495
/*-------------------------------------------------------------------------
496
 * Function:    H5D__none_idx_reset
497
 *
498
 * Purpose:     Reset indexing information.
499
 *
500
 * Return:      Non-negative on success/Negative on failure
501
 *
502
 *-------------------------------------------------------------------------
503
 */
504
static herr_t
505
H5D__none_idx_reset(H5O_storage_chunk_t *storage, bool reset_addr)
506
0
{
507
0
    FUNC_ENTER_PACKAGE_NOERR
508
509
    /* Check args */
510
0
    assert(storage);
511
512
    /* Reset index info */
513
0
    if (reset_addr)
514
0
        storage->idx_addr = HADDR_UNDEF;
515
516
0
    FUNC_LEAVE_NOAPI(SUCCEED)
517
0
} /* end H5D__none_idx_reset() */
518
519
/*-------------------------------------------------------------------------
520
 * Function:    H5D__none_idx_dump
521
 *
522
 * Purpose:     Dump
523
 *
524
 * Return:      Non-negative on success/Negative on failure
525
 *
526
 *-------------------------------------------------------------------------
527
 */
528
static herr_t
529
H5D__none_idx_dump(const H5O_storage_chunk_t *storage, FILE *stream)
530
0
{
531
0
    FUNC_ENTER_PACKAGE_NOERR
532
533
    /* Check args */
534
0
    assert(storage);
535
0
    assert(stream);
536
537
0
    fprintf(stream, "    Address: %" PRIuHADDR "\n", storage->idx_addr);
538
539
0
    FUNC_LEAVE_NOAPI(SUCCEED)
540
0
} /* end H5D__none_idx_dump() */