summaryrefslogtreecommitdiffstats
path: root/src/H5Olayout.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Olayout.c')
-rw-r--r--src/H5Olayout.c199
1 files changed, 65 insertions, 134 deletions
diff --git a/src/H5Olayout.c b/src/H5Olayout.c
index b7a2584..d8f05f0 100644
--- a/src/H5Olayout.c
+++ b/src/H5Olayout.c
@@ -5,12 +5,10 @@
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Programmer: Robb Matzke <matzke@llnl.gov>
@@ -35,25 +33,23 @@
/* Local macros */
-/* Version # of encoded virtual dataset global heap blocks */
-#define H5O_LAYOUT_VDS_GH_ENC_VERS 0
-
/* PRIVATE PROTOTYPES */
-static void *H5O__layout_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
- unsigned mesg_flags, unsigned *ioflags, const uint8_t *p);
+static void *H5O__layout_decode(H5F_t *f, H5O_t *open_oh, unsigned mesg_flags,
+ unsigned *ioflags, size_t p_size, const uint8_t *p);
static herr_t H5O__layout_encode(H5F_t *f, hbool_t disable_shared, uint8_t *p, const void *_mesg);
static void *H5O__layout_copy(const void *_mesg, void *_dest);
static size_t H5O__layout_size(const H5F_t *f, hbool_t disable_shared, const void *_mesg);
static herr_t H5O__layout_reset(void *_mesg);
static herr_t H5O__layout_free(void *_mesg);
-static herr_t H5O__layout_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
- void *_mesg);
+static herr_t H5O__layout_delete(H5F_t *f, H5O_t *open_oh, void *_mesg);
+static herr_t H5O__layout_pre_copy_file(H5F_t *file_src, const void *mesg_src,
+ hbool_t *deleted, const H5O_copy_t *cpy_info, void *udata);
static void *H5O__layout_copy_file(H5F_t *file_src, void *mesg_src,
H5F_t *file_dst, hbool_t *recompute_size, unsigned *mesg_flags,
- H5O_copy_t *cpy_info, void *udata, hid_t dxpl_id);
-static herr_t H5O__layout_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg,
- FILE * stream, int indent, int fwidth);
+ H5O_copy_t *cpy_info, void *udata);
+static herr_t H5O__layout_debug(H5F_t *f, const void *_mesg, FILE *stream,
+ int indent, int fwidth);
/* This message derives from H5O message class */
const H5O_msg_class_t H5O_MSG_LAYOUT[1] = {{
@@ -71,7 +67,7 @@ const H5O_msg_class_t H5O_MSG_LAYOUT[1] = {{
NULL, /* link method */
NULL, /* set share method */
NULL, /* can share method */
- NULL, /* pre copy native value to file */
+ H5O__layout_pre_copy_file, /* pre copy native value to file */
H5O__layout_copy_file, /* copy native value to file */
NULL, /* post copy native value to file */
NULL, /* get creation index */
@@ -100,8 +96,9 @@ H5FL_DEFINE(H5O_layout_t);
*-------------------------------------------------------------------------
*/
static void *
-H5O__layout_decode(H5F_t *f, hid_t H5_ATTR_UNUSED dxpl_id, H5O_t H5_ATTR_UNUSED *open_oh,
- unsigned H5_ATTR_UNUSED mesg_flags, unsigned H5_ATTR_UNUSED *ioflags, const uint8_t *p)
+H5O__layout_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh,
+ unsigned H5_ATTR_UNUSED mesg_flags, unsigned H5_ATTR_UNUSED *ioflags,
+ size_t H5_ATTR_UNUSED p_size, const uint8_t *p)
{
H5O_layout_t *mesg = NULL;
uint8_t *heap_block = NULL;
@@ -397,7 +394,7 @@ H5O__layout_decode(H5F_t *f, hid_t H5_ATTR_UNUSED dxpl_id, H5O_t H5_ATTR_UNUSED
size_t i;
/* Read heap */
- if(NULL == (heap_block = (uint8_t *)H5HG_read(f, dxpl_id, &(mesg->storage.u.virt.serial_list_hobjid), NULL, &block_size)))
+ if(NULL == (heap_block = (uint8_t *)H5HG_read(f, &(mesg->storage.u.virt.serial_list_hobjid), NULL, &block_size)))
HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "Unable to read global heap block")
heap_block_p = (const uint8_t *)heap_block;
@@ -552,8 +549,6 @@ static herr_t
H5O__layout_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, const void *_mesg)
{
const H5O_layout_t *mesg = (const H5O_layout_t *) _mesg;
- uint8_t *heap_block = NULL;
- size_t *str_size = NULL;
unsigned u;
herr_t ret_value = SUCCEED; /* Return value */
@@ -678,106 +673,9 @@ H5O__layout_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p,
break;
case H5D_VIRTUAL:
- /* Create heap block if it has not been created yet */
- /* Note that we assume here that the contents of the heap block
- * cannot change! If this ever stops being the case we must change
- * this code to allow overwrites of the heap block. -NAF */
- if((mesg->storage.u.virt.serial_list_hobjid.addr == HADDR_UNDEF)
- && (mesg->storage.u.virt.list_nused > 0)) {
- uint8_t *heap_block_p;
- size_t block_size;
- hssize_t select_serial_size;
- hsize_t tmp_hsize;
- uint32_t chksum;
- size_t i;
-
- /* Allocate array for caching results of strlen */
- if(NULL == (str_size = (size_t *)H5MM_malloc(2 * mesg->storage.u.virt.list_nused *sizeof(size_t))))
- HGOTO_ERROR(H5E_OHDR, H5E_RESOURCE, FAIL, "unable to allocate string length array")
-
- /*
- * Calculate heap block size
- */
- /* Version and number of entries */
- block_size = (size_t)1 + H5F_SIZEOF_SIZE(f);
-
- /* Calculate size of each entry */
- for(i = 0; i < mesg->storage.u.virt.list_nused; i++) {
- HDassert(mesg->storage.u.virt.list[i].source_file_name);
- HDassert(mesg->storage.u.virt.list[i].source_dset_name);
- HDassert(mesg->storage.u.virt.list[i].source_select);
- HDassert(mesg->storage.u.virt.list[i].source_dset.virtual_select);
-
- /* Source file name */
- str_size[2 * i] = HDstrlen(mesg->storage.u.virt.list[i].source_file_name) + (size_t)1;
- block_size += str_size[2 * i];
-
- /* Source dset name */
- str_size[(2 * i) + 1] = HDstrlen(mesg->storage.u.virt.list[i].source_dset_name) + (size_t)1;
- block_size += str_size[(2 * i) + 1];
-
- /* Source selection */
- if((select_serial_size = H5S_SELECT_SERIAL_SIZE(mesg->storage.u.virt.list[i].source_select)) < 0)
- HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to check dataspace selection size")
- block_size += (size_t)select_serial_size;
-
- /* Virtual dataset selection */
- if((select_serial_size = H5S_SELECT_SERIAL_SIZE(mesg->storage.u.virt.list[i].source_dset.virtual_select)) < 0)
- HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to check dataspace selection size")
- block_size += (size_t)select_serial_size;
- } /* end for */
-
- /* Checksum */
- block_size += 4;
-
- /* Allocate heap block */
- if(NULL == (heap_block = (uint8_t *)H5MM_malloc(block_size)))
- HGOTO_ERROR(H5E_OHDR, H5E_RESOURCE, FAIL, "unable to allocate heap block")
-
- /*
- * Encode heap block
- */
- heap_block_p = heap_block;
-
- /* Encode heap block encoding version */
- *heap_block_p++ = (uint8_t)H5O_LAYOUT_VDS_GH_ENC_VERS;
-
- /* Number of entries */
- tmp_hsize = (hsize_t)mesg->storage.u.virt.list_nused;
- H5F_ENCODE_LENGTH(f, heap_block_p, tmp_hsize)
-
- /* Encode each entry */
- for(i = 0; i < mesg->storage.u.virt.list_nused; i++) {
- /* Source file name */
- (void)HDmemcpy((char *)heap_block_p, mesg->storage.u.virt.list[i].source_file_name, str_size[2 * i]);
- heap_block_p += str_size[2 * i];
-
- /* Source dataset name */
- (void)HDmemcpy((char *)heap_block_p, mesg->storage.u.virt.list[i].source_dset_name, str_size[(2 * i) + 1]);
- heap_block_p += str_size[(2 * i) + 1];
-
- /* Source selection */
- if(H5S_SELECT_SERIALIZE(mesg->storage.u.virt.list[i].source_select, &heap_block_p) < 0)
- HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to serialize source selection")
-
- /* Virtual selection */
- if(H5S_SELECT_SERIALIZE(mesg->storage.u.virt.list[i].source_dset.virtual_select, &heap_block_p) < 0)
- HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to serialize virtual selection")
- } /* end for */
-
- /* Checksum */
- chksum = H5_checksum_metadata(heap_block, block_size - (size_t)4, 0);
- UINT32ENCODE(heap_block_p, chksum)
-
- /* Insert block into global heap */
- if(H5HG_insert(f, H5AC_ind_read_dxpl_id, block_size, heap_block, &((H5O_layout_t *)mesg)->storage.u.virt.serial_list_hobjid) < 0) /* Casting away const OK --NAF */
- HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "unable to insert virtual dataset heap block")
- } /* end if */
-
- /* Heap information */
+ /* Encode heap ID for VDS info */
H5F_addr_encode(f, &p, mesg->storage.u.virt.serial_list_hobjid.addr);
UINT32ENCODE(p, mesg->storage.u.virt.serial_list_hobjid.idx);
-
break;
case H5D_LAYOUT_ERROR:
@@ -787,9 +685,6 @@ H5O__layout_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p,
} /* end switch */
done:
- heap_block = (uint8_t *)H5MM_xfree(heap_block);
- str_size = (size_t *)H5MM_xfree(str_size);
-
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O__layout_encode() */
@@ -999,7 +894,7 @@ H5O__layout_free(void *_mesg)
*-------------------------------------------------------------------------
*/
static herr_t
-H5O__layout_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, void *_mesg)
+H5O__layout_delete(H5F_t *f, H5O_t *open_oh, void *_mesg)
{
H5O_layout_t *mesg = (H5O_layout_t *) _mesg;
herr_t ret_value = SUCCEED; /* Return value */
@@ -1019,19 +914,19 @@ H5O__layout_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, void *_mesg)
case H5D_CONTIGUOUS: /* Contiguous block on disk */
/* Free the file space for the raw data */
- if(H5D__contig_delete(f, dxpl_id, &mesg->storage) < 0)
+ if(H5D__contig_delete(f, &mesg->storage) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to free raw data")
break;
case H5D_CHUNKED: /* Chunked blocks on disk */
/* Free the file space for the index & chunk raw data */
- if(H5D__chunk_delete(f, dxpl_id, open_oh, &mesg->storage) < 0)
+ if(H5D__chunk_delete(f, open_oh, &mesg->storage) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to free raw data")
break;
case H5D_VIRTUAL: /* Virtual dataset */
/* Free the file space virtual dataset */
- if(H5D__virtual_delete(f, dxpl_id, &mesg->storage) < 0)
+ if(H5D__virtual_delete(f, &mesg->storage) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to free raw data")
break;
@@ -1047,6 +942,42 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5O__layout_pre_copy_file
+ *
+ * Purpose: Perform any necessary actions before copying message between
+ * files.
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Vailin Choi; Dec 2017
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5O__layout_pre_copy_file(H5F_t H5_ATTR_UNUSED *file_src, const void *mesg_src,
+ hbool_t H5_ATTR_UNUSED *deleted, const H5O_copy_t *cpy_info, void H5_ATTR_UNUSED *udata)
+{
+ const H5O_layout_t *layout_src = (const H5O_layout_t *)mesg_src; /* Source layout */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* check args */
+ HDassert(cpy_info);
+ HDassert(cpy_info->file_dst);
+
+ /* Check to ensure that the version of the message to be copied does not exceed
+ the message version allowed by the destination file's high bound */
+ if(layout_src->version > H5O_layout_ver_bounds[H5F_HIGH_BOUND(cpy_info->file_dst)])
+ HGOTO_ERROR(H5E_OHDR, H5E_BADRANGE, FAIL, "layout message version out of bounds")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5O__layout_pre_copy_file() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5O__layout_copy_file
*
* Purpose: Copies a message from _MESG to _DEST in file
@@ -1063,7 +994,7 @@ done:
static void *
H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst,
hbool_t H5_ATTR_UNUSED *recompute_size, unsigned H5_ATTR_UNUSED *mesg_flags,
- H5O_copy_t *cpy_info, void *_udata, hid_t dxpl_id)
+ H5O_copy_t *cpy_info, void *_udata)
{
H5D_copy_file_ud_t *udata = (H5D_copy_file_ud_t *)_udata; /* Dataset copying user data */
H5O_layout_t *layout_src = (H5O_layout_t *) mesg_src;
@@ -1087,7 +1018,7 @@ H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst,
case H5D_COMPACT:
if(layout_src->storage.u.compact.buf) {
/* copy compact raw data */
- if(H5D__compact_copy(file_src, &layout_src->storage.u.compact, file_dst, &layout_dst->storage.u.compact, udata->src_dtype, cpy_info, dxpl_id) < 0)
+ if(H5D__compact_copy(file_src, &layout_src->storage.u.compact, file_dst, &layout_dst->storage.u.compact, udata->src_dtype, cpy_info) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage")
copied = TRUE;
} /* end if */
@@ -1104,7 +1035,7 @@ H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst,
if(H5D__contig_is_space_alloc(&layout_src->storage)) {
/* copy contiguous raw data */
- if(H5D__contig_copy(file_src, &layout_src->storage.u.contig, file_dst, &layout_dst->storage.u.contig, udata->src_dtype, cpy_info, dxpl_id) < 0)
+ if(H5D__contig_copy(file_src, &layout_src->storage.u.contig, file_dst, &layout_dst->storage.u.contig, udata->src_dtype, cpy_info) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy contiguous storage")
copied = TRUE;
} /* end if */
@@ -1113,7 +1044,7 @@ H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst,
case H5D_CHUNKED:
if(H5D__chunk_is_space_alloc(&layout_src->storage)) {
/* Create chunked layout */
- if(H5D__chunk_copy(file_src, &layout_src->storage.u.chunk, &layout_src->u.chunk, file_dst, &layout_dst->storage.u.chunk, udata->src_space_extent, udata->src_dtype, udata->common.src_pline, cpy_info, dxpl_id) < 0)
+ if(H5D__chunk_copy(file_src, &layout_src->storage.u.chunk, &layout_src->u.chunk, file_dst, &layout_dst->storage.u.chunk, udata->src_space_extent, udata->src_dtype, udata->common.src_pline, cpy_info) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage")
copied = TRUE;
} /* end if */
@@ -1122,7 +1053,7 @@ H5O__layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst,
case H5D_VIRTUAL:
/* Copy virtual layout. Always copy so the memory fields get copied
* properly. */
- if(H5D__virtual_copy(file_dst, layout_dst, dxpl_id) < 0)
+ if(H5D__virtual_copy(file_dst, layout_dst) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy virtual storage")
break;
@@ -1161,8 +1092,8 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5O__layout_debug(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, const void *_mesg,
- FILE * stream, int indent, int fwidth)
+H5O__layout_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream,
+ int indent, int fwidth)
{
const H5O_layout_t *mesg = (const H5O_layout_t *) _mesg;
size_t u;