diff options
author | Jerome Soumagne <jsoumagne@hdfgroup.org> | 2019-10-08 20:06:55 (GMT) |
---|---|---|
committer | Jerome Soumagne <jsoumagne@hdfgroup.org> | 2019-10-08 20:06:55 (GMT) |
commit | 4c558700ab33934e7358483c5d20fea4823baf9e (patch) | |
tree | 4ff47fe527c87edaef7b83e564f9dfa1e643d6b1 /src | |
parent | e9f253c7567cf508a3d40b863dce6455f0c93fdb (diff) | |
parent | 9ed9762889fcd05dc230d6652b92fddc5ec880a4 (diff) | |
download | hdf5-4c558700ab33934e7358483c5d20fea4823baf9e.zip hdf5-4c558700ab33934e7358483c5d20fea4823baf9e.tar.gz hdf5-4c558700ab33934e7358483c5d20fea4823baf9e.tar.bz2 |
Merge pull request #1931 in HDFFV/hdf5 from feature/references to develop
* commit '9ed9762889fcd05dc230d6652b92fddc5ec880a4':
Update RELEASE.txt for reference changes
Fix reference type comparison in h5dump
Make wrappers, tests and tools use H5Treclaim() instead of H5Dvlen_reclaim()
Add new H5R API that abstracts object, region and attribute reference types
Remove ability to loc by ref from H5VL layer
Add support for retrieving object name by token
Add H5VL_OBJECT_GET_TYPE to get object type
Add H5VL_MAX_TOKEN_SIZE and H5VL_token_t
Adapt Jerome's "file info" H5VL 'get' query to retrieve container token info.
Fix H5VL_blob_get to return size of blob
Add 'blob' callbacks to VOL, along with a native implementation to store them in the global heap, and changed the VL datatype conversion code to use blobs.
Diffstat (limited to 'src')
57 files changed, 6295 insertions, 1985 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6df8af3..9bb73a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -446,6 +446,7 @@ set (H5O_SOURCES ${HDF5_SRC_DIR}/H5Ochunk.c ${HDF5_SRC_DIR}/H5Ocont.c ${HDF5_SRC_DIR}/H5Ocopy.c + ${HDF5_SRC_DIR}/H5Ocopy_ref.c ${HDF5_SRC_DIR}/H5Odbg.c ${HDF5_SRC_DIR}/H5Odeprec.c ${HDF5_SRC_DIR}/H5Odrvinfo.c @@ -616,6 +617,7 @@ set (H5T_SOURCES ${HDF5_SRC_DIR}/H5Torder.c ${HDF5_SRC_DIR}/H5Tpad.c ${HDF5_SRC_DIR}/H5Tprecis.c + ${HDF5_SRC_DIR}/H5Tref.c ${HDF5_SRC_DIR}/H5Tstrpad.c ${HDF5_SRC_DIR}/H5Tvisit.c ${HDF5_SRC_DIR}/H5Tvlen.c @@ -649,6 +651,7 @@ set (H5VL_SOURCES ${HDF5_SRC_DIR}/H5VLint.c ${HDF5_SRC_DIR}/H5VLnative.c ${HDF5_SRC_DIR}/H5VLnative_attr.c + ${HDF5_SRC_DIR}/H5VLnative_blob.c ${HDF5_SRC_DIR}/H5VLnative_dataset.c ${HDF5_SRC_DIR}/H5VLnative_datatype.c ${HDF5_SRC_DIR}/H5VLnative_file.c diff --git a/src/H5Aint.c b/src/H5Aint.c index c1c0078..2b43a64 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -2270,7 +2270,7 @@ H5A__attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_s H5MM_memcpy(attr_dst->shared->data, buf, attr_dst->shared->data_size); - if(H5D_vlen_reclaim(tid_mem, buf_space, reclaim_buf) < 0) + if(H5T_reclaim(tid_mem, buf_space, reclaim_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADITER, NULL, "unable to reclaim variable-length data") } /* end if */ else { @@ -2401,17 +2401,9 @@ H5A__attr_post_copy_file(const H5O_loc_t *src_oloc, const H5A_t *attr_src, /* Check for expanding references */ if(cpy_info->expand_ref) { - size_t ref_count; - size_t dst_dt_size; /* Destination datatype size */ - - /* Determine size of the destination datatype */ - if(0 == (dst_dt_size = H5T_get_size(attr_dst->shared->dt))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to determine datatype size") - /* Determine # of reference elements to copy */ - ref_count = attr_dst->shared->data_size / dst_dt_size; - /* Copy objects referenced in source buffer to destination file and set destination elements */ - if(H5O_copy_expand_ref(file_src, attr_dst->shared->data, file_dst, attr_dst->shared->data, ref_count, H5T_get_ref_type(attr_dst->shared->dt), cpy_info) < 0) + if(H5O_copy_expand_ref(file_src, H5I_INVALID_HID, attr_src->shared->dt, + attr_src->shared->data, attr_src->shared->data_size, file_dst, attr_dst->shared->data, cpy_info) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, FAIL, "unable to copy reference attribute") } /* end if */ else @@ -706,56 +706,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5Dvlen_reclaim - * - * Purpose: Frees the buffers allocated for storing variable-length data - * in memory. Only frees the VL data in the selection defined in the - * dataspace. The dataset transfer property list is required to find the - * correct allocation/free methods for the VL data in the buffer. - * - * Return: Non-negative on success, negative on failure - * - * Programmer: Quincey Koziol - * Thursday, June 10, 1999 - * - *------------------------------------------------------------------------- - */ -herr_t -H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t dxpl_id, void *buf) -{ - H5S_t *space; /* Dataspace for iteration */ - herr_t ret_value; /* Return value */ - - FUNC_ENTER_API(FAIL) - H5TRACE4("e", "iii*x", type_id, space_id, dxpl_id, buf); - - /* Check args */ - if(H5I_DATATYPE != H5I_get_type(type_id) || buf == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument") - if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace") - if(!(H5S_has_extent(space))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dataspace does not have extent set") - - /* Get the default dataset transfer property list if the user didn't provide one */ - if(H5P_DEFAULT == dxpl_id) - dxpl_id = H5P_DATASET_XFER_DEFAULT; - else - if(TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") - - /* Set DXPL for operation */ - H5CX_set_dxpl(dxpl_id); - - /* Call internal routine */ - ret_value = H5D_vlen_reclaim(type_id, space, buf); - -done: - FUNC_LEAVE_API(ret_value) -} /* end H5Dvlen_reclaim() */ - - -/*------------------------------------------------------------------------- * Function: H5Dvlen_get_buf_size * * Purpose: This routine checks the number of bytes required to store the VL diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index ed82b3b..53ca7d1 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -6088,23 +6088,15 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5_ITER_ERROR, "datatype conversion failed") /* Reclaim space from variable length data */ - if(H5D_vlen_reclaim(tid_mem, buf_space, reclaim_buf) < 0) + if(H5T_reclaim(tid_mem, buf_space, reclaim_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADITER, H5_ITER_ERROR, "unable to reclaim variable-length data") } /* end if */ else if(fix_ref) { /* Check for expanding references */ /* (background buffer has already been zeroed out, if not expanding) */ if(udata->cpy_info->expand_ref) { - size_t ref_count; - size_t dt_size; - - /* Determine # of reference elements to copy */ - if((dt_size = H5T_get_size(udata->dt_src)) == 0) - HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "size must not be 0") - ref_count = nbytes / dt_size; - /* Copy the reference elements */ - if(H5O_copy_expand_ref(udata->file_src, buf, udata->idx_info_dst->f, bkg, ref_count, H5T_get_ref_type(udata->dt_src), udata->cpy_info) < 0) + if(H5O_copy_expand_ref(udata->file_src, udata->tid_src, udata->dt_src, buf, nbytes, udata->idx_info_dst->f, bkg, udata->cpy_info) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy reference attribute") } /* end if */ diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index 29401f8..edad3c5 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -551,26 +551,16 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds H5MM_memcpy(storage_dst->buf, buf, storage_dst->size); - if(H5D_vlen_reclaim(tid_mem, buf_space, reclaim_buf) < 0) + if(H5T_reclaim(tid_mem, buf_space, reclaim_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADITER, FAIL, "unable to reclaim variable-length data") } /* end if */ else if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) { if(f_src != f_dst) { /* Check for expanding references */ if(cpy_info->expand_ref) { - size_t ref_count; - size_t src_dt_size; /* Source datatype size */ - - /* Determine largest datatype size */ - if(0 == (src_dt_size = H5T_get_size(dt_src))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to determine datatype size") - - /* Determine # of reference elements to copy */ - ref_count = storage_src->size / src_dt_size; - /* Copy objects referenced in source buffer to destination file and set destination elements */ - if(H5O_copy_expand_ref(f_src, storage_src->buf, f_dst, - storage_dst->buf, ref_count, H5T_get_ref_type(dt_src), cpy_info) < 0) + if (H5O_copy_expand_ref(f_src, tid_src, dt_src, storage_src->buf, + storage_src->size, f_dst, storage_dst->buf, cpy_info) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "unable to copy reference attribute") } /* end if */ else diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index c9f9fc2..0be7364 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -1543,19 +1543,14 @@ H5D__contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed") /* Reclaim space from variable length data */ - if(H5D_vlen_reclaim(tid_mem, buf_space, reclaim_buf) < 0) + if(H5T_reclaim(tid_mem, buf_space, reclaim_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_BADITER, FAIL, "unable to reclaim variable-length data") } /* end if */ else if(fix_ref) { /* Check for expanding references */ if(cpy_info->expand_ref) { - size_t ref_count; - - /* Determine # of reference elements to copy */ - ref_count = src_nbytes / H5T_get_size(dt_src); - /* Copy the reference elements */ - if(H5O_copy_expand_ref(f_src, buf, f_dst, bkg, ref_count, H5T_get_ref_type(dt_src), cpy_info) < 0) + if(H5O_copy_expand_ref(f_src, tid_src, dt_src, buf, buf_size, f_dst, bkg, cpy_info) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "unable to copy reference attribute") /* After fix ref, copy the new reference elements to the buffer to write out */ diff --git a/src/H5Ddeprec.c b/src/H5Ddeprec.c index 6380bee..f321c82 100644 --- a/src/H5Ddeprec.c +++ b/src/H5Ddeprec.c @@ -303,5 +303,55 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Dextend() */ + +/*------------------------------------------------------------------------- + * Function: H5Dvlen_reclaim + * + * Purpose: Frees the buffers allocated for storing variable-length data + * in memory. Only frees the VL data in the selection defined in the + * dataspace. The dataset transfer property list is required to find the + * correct allocation/free methods for the VL data in the buffer. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Quincey Koziol + * Thursday, June 10, 1999 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t dxpl_id, void *buf) +{ + H5S_t *space; /* Dataspace for iteration */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "iii*x", type_id, space_id, dxpl_id, buf); + + /* Check args */ + if(H5I_DATATYPE != H5I_get_type(type_id) || buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument") + if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace") + if(!(H5S_has_extent(space))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dataspace does not have extent set") + + /* Get the default dataset transfer property list if the user didn't provide one */ + if(H5P_DEFAULT == dxpl_id) + dxpl_id = H5P_DATASET_XFER_DEFAULT; + else + if(TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") + + /* Set DXPL for operation */ + H5CX_set_dxpl(dxpl_id); + + /* Call internal routine */ + ret_value = H5T_reclaim(type_id, space, buf); + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Dvlen_reclaim() */ + #endif /* H5_NO_DEPRECATED_SYMBOLS */ diff --git a/src/H5Dint.c b/src/H5Dint.c index ada542e..772a150 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -547,7 +547,7 @@ H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type) /* To use at least v18 format versions or not */ use_at_least_v18 = (H5F_LOW_BOUND(file) >= H5F_LIBVER_V18); - /* Copy the datatype if it's a custom datatype or if it'll change when it's location is changed */ + /* Copy the datatype if it's a custom datatype or if it'll change when its location is changed */ if(!immutable || relocatable || use_at_least_v18) { /* Copy datatype for dataset */ if((dset->shared->type = H5T_copy(type, H5T_COPY_ALL)) == NULL) @@ -2542,50 +2542,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5D_vlen_reclaim - * - * Purpose: Frees the buffers allocated for storing variable-length data - * in memory. Only frees the VL data in the selection defined in the - * dataspace. - * - * Return: Non-negative on success, negative on failure - *------------------------------------------------------------------------- - */ -herr_t -H5D_vlen_reclaim(hid_t type_id, H5S_t *space, void *buf) -{ - H5T_t *type; /* Datatype */ - H5S_sel_iter_op_t dset_op; /* Operator for iteration */ - H5T_vlen_alloc_info_t vl_alloc_info; /* VL allocation info */ - herr_t ret_value = FAIL; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - /* Check args */ - HDassert(H5I_DATATYPE == H5I_get_type(type_id)); - HDassert(space); - HDassert(buf); - - if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an valid base datatype") - - /* Get the allocation info */ - if(H5CX_get_vlen_alloc_info(&vl_alloc_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") - - /* Call H5S_select_iterate with args, etc. */ - dset_op.op_type = H5S_SEL_ITER_OP_APP; - dset_op.u.app_op.op = H5T_vlen_reclaim; - dset_op.u.app_op.type_id = type_id; - - ret_value = H5S_select_iterate(buf, type, space, &dset_op, &vl_alloc_info); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5D_vlen_reclaim() */ - - -/*------------------------------------------------------------------------- * Function: H5D__vlen_get_buf_size_alloc * * Purpose: This routine makes certain there is enough space in the temporary diff --git a/src/H5Dio.c b/src/H5Dio.c index 1e6e70d..79a856a 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -32,11 +32,6 @@ #include "H5VLnative_private.h" /* Native VOL connector */ -#ifdef H5_HAVE_PARALLEL -/* Remove this if H5R_DATASET_REGION is no longer used in this file */ -#include "H5Rpublic.h" -#endif /*H5_HAVE_PARALLEL*/ - /****************/ /* Local Macros */ @@ -478,33 +473,33 @@ H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "memory dataspace does not have extent set") /* H5S_select_shape_same() has been modified to accept topologically identical - * selections with different rank as having the same shape (if the most - * rapidly changing coordinates match up), but the I/O code still has + * selections with different rank as having the same shape (if the most + * rapidly changing coordinates match up), but the I/O code still has * difficulties with the notion. * - * To solve this, we check to see if H5S_select_shape_same() returns true, - * and if the ranks of the mem and file spaces are different. If the are, - * construct a new mem space that is equivalent to the old mem space, and + * To solve this, we check to see if H5S_select_shape_same() returns true, + * and if the ranks of the mem and file spaces are different. If the are, + * construct a new mem space that is equivalent to the old mem space, and * use that instead. * - * Note that in general, this requires us to touch up the memory buffer as + * Note that in general, this requires us to touch up the memory buffer as * well. */ if(TRUE == H5S_SELECT_SHAPE_SAME(mem_space, file_space) && H5S_GET_EXTENT_NDIMS(mem_space) != H5S_GET_EXTENT_NDIMS(file_space)) { - void *adj_buf = NULL; /* Pointer to the location in buf corresponding */ + const void *adj_buf = NULL; /* Pointer to the location in buf corresponding */ /* to the beginning of the projected mem space. */ /* Attempt to construct projected dataspace for memory dataspace */ if(H5S_select_construct_projection(mem_space, &projected_mem_space, - (unsigned)H5S_GET_EXTENT_NDIMS(file_space), buf, (const void **)&adj_buf, type_info.dst_type_size) < 0) + (unsigned)H5S_GET_EXTENT_NDIMS(file_space), buf, &adj_buf, type_info.dst_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to construct projected memory dataspace") HDassert(projected_mem_space); HDassert(adj_buf); /* Switch to using projected memory dataspace & adjusted buffer */ mem_space = projected_mem_space; - buf = adj_buf; + buf = (void *)adj_buf; /* Casting away 'const' OK -QAK */ } /* end if */ @@ -712,27 +707,27 @@ H5D__write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, if(!(H5S_has_extent(mem_space))) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "memory dataspace does not have extent set") - /* H5S_select_shape_same() has been modified to accept topologically - * identical selections with different rank as having the same shape - * (if the most rapidly changing coordinates match up), but the I/O + /* H5S_select_shape_same() has been modified to accept topologically + * identical selections with different rank as having the same shape + * (if the most rapidly changing coordinates match up), but the I/O * code still has difficulties with the notion. * - * To solve this, we check to see if H5S_select_shape_same() returns - * true, and if the ranks of the mem and file spaces are different. - * If the are, construct a new mem space that is equivalent to the + * To solve this, we check to see if H5S_select_shape_same() returns + * true, and if the ranks of the mem and file spaces are different. + * If the are, construct a new mem space that is equivalent to the * old mem space, and use that instead. * - * Note that in general, this requires us to touch up the memory buffer + * Note that in general, this requires us to touch up the memory buffer * as well. */ if(TRUE == H5S_SELECT_SHAPE_SAME(mem_space, file_space) && H5S_GET_EXTENT_NDIMS(mem_space) != H5S_GET_EXTENT_NDIMS(file_space)) { - void *adj_buf = NULL; /* Pointer to the location in buf corresponding */ + const void *adj_buf = NULL; /* Pointer to the location in buf corresponding */ /* to the beginning of the projected mem space. */ /* Attempt to construct projected dataspace for memory dataspace */ if(H5S_select_construct_projection(mem_space, &projected_mem_space, - (unsigned)H5S_GET_EXTENT_NDIMS(file_space), buf, (const void **)&adj_buf, type_info.src_type_size) < 0) + (unsigned)H5S_GET_EXTENT_NDIMS(file_space), buf, &adj_buf, type_info.src_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to construct projected memory dataspace") HDassert(projected_mem_space); HDassert(adj_buf); diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h index 511e380..9a5277f 100644 --- a/src/H5Dprivate.h +++ b/src/H5Dprivate.h @@ -170,9 +170,6 @@ H5_DLL herr_t H5D_flush_all(H5F_t *f); H5_DLL hid_t H5D_get_create_plist(const H5D_t *dset); H5_DLL hid_t H5D_get_access_plist(const H5D_t *dset); -/* Functions that operate on vlen data */ -H5_DLL herr_t H5D_vlen_reclaim(hid_t type_id, H5S_t *space, void *buf); - /* Functions that operate on chunked storage */ H5_DLL herr_t H5D_chunk_idx_reset(H5O_storage_chunk_t *storage, hbool_t reset_addr); diff --git a/src/H5Dpublic.h b/src/H5Dpublic.h index 7234d16..281da81 100644 --- a/src/H5Dpublic.h +++ b/src/H5Dpublic.h @@ -156,7 +156,6 @@ H5_DLL herr_t H5Dread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *filters, void *buf); H5_DLL herr_t H5Diterate(void *buf, hid_t type_id, hid_t space_id, H5D_operator_t op, void *operator_data); -H5_DLL herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *buf); H5_DLL herr_t H5Dvlen_get_buf_size(hid_t dataset_id, hid_t type_id, hid_t space_id, hsize_t *size); H5_DLL herr_t H5Dfill(const void *fill, hid_t fill_type, void *buf, hid_t buf_type, hid_t space); @@ -203,6 +202,7 @@ H5_DLL hid_t H5Dcreate1(hid_t file_id, const char *name, hid_t type_id, hid_t space_id, hid_t dcpl_id); H5_DLL hid_t H5Dopen1(hid_t file_id, const char *name); H5_DLL herr_t H5Dextend(hid_t dset_id, const hsize_t size[]); +H5_DLL herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *buf); #endif /* H5_NO_DEPRECATED_SYMBOLS */ diff --git a/src/H5Fint.c b/src/H5Fint.c index 5e2cf26..2ebcd94 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -139,18 +139,14 @@ H5F__set_vol_conn(H5F_t *file) /* Sanity check */ HDassert(0 != connector_prop.connector_id); - /* Copy connector info, if it exists */ - if(connector_prop.connector_info) { - H5VL_class_t *connector; /* Pointer to connector */ + /* Retrieve the connector for the ID */ + if(NULL == (file->shared->vol_cls = (H5VL_class_t *)H5I_object(connector_prop.connector_id))) + HGOTO_ERROR(H5E_FILE, H5E_BADTYPE, FAIL, "not a VOL connector ID") - /* Retrieve the connector for the ID */ - if(NULL == (connector = (H5VL_class_t *)H5I_object(connector_prop.connector_id))) - HGOTO_ERROR(H5E_FILE, H5E_BADTYPE, FAIL, "not a VOL connector ID") - - /* Allocate and copy connector info */ - if(H5VL_copy_connector_info(connector, &new_connector_info, connector_prop.connector_info) < 0) + /* Allocate and copy connector info, if it exists */ + if(connector_prop.connector_info) + if(H5VL_copy_connector_info(file->shared->vol_cls, &new_connector_info, connector_prop.connector_info) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "connector info copy failed") - } /* end if */ /* Cache the connector ID & info for the container */ file->shared->vol_id = connector_prop.connector_id; @@ -1377,6 +1373,7 @@ H5F__dest(H5F_t *f, hbool_t flush) if(H5I_dec_ref(f->shared->vol_id) < 0) /* Push error, but keep going*/ HDONE_ERROR(H5E_FILE, H5E_CANTDEC, FAIL, "can't close VOL connector ID") + f->shared->vol_cls = NULL; /* Close the file */ if(H5FD_close(f->shared->lf) < 0) diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h index 6cd2d3c..4b5b788 100644 --- a/src/H5Fpkg.h +++ b/src/H5Fpkg.h @@ -29,9 +29,6 @@ /* Get package's private header */ #include "H5Fprivate.h" -/* Other public headers needed by this file */ -#include "H5VLpublic.h" /* Virtual Object Layer */ - /* Other private headers needed by this file */ #include "H5private.h" /* Generic Functions */ #include "H5ACprivate.h" /* Metadata cache */ @@ -313,6 +310,7 @@ struct H5F_shared_t { /* Cached VOL connector ID & info */ hid_t vol_id; /* ID of VOL connector for the container */ + const H5VL_class_t *vol_cls; /* Pointer to VOL connector class for the container */ void *vol_info; /* Copy of VOL connector info for container */ /* File space allocation information */ @@ -413,6 +411,7 @@ H5_DLL herr_t H5F__close(H5F_t *f); H5_DLL herr_t H5F__set_libver_bounds(H5F_t *f, H5F_libver_t low, H5F_libver_t high); H5_DLL H5F_t *H5F__get_file(void *obj, H5I_type_t type); H5_DLL hid_t H5F__get_file_id(H5F_t *file, hbool_t app_ref); +H5_DLL herr_t H5F__get_cont_info(const H5F_t *f, H5VL_file_cont_info_t *info); /* File mount related routines */ H5_DLL herr_t H5F__mount(H5G_loc_t *loc, const char *name, H5F_t *child, hid_t plist_id); diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 7e87f79..c9a1b25 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -25,14 +25,15 @@ typedef struct H5F_t H5F_t; #include "H5Fpublic.h" /* Public headers needed by this file */ -#include "H5FDpublic.h" /* File drivers */ +#include "H5FDpublic.h" /* File drivers */ +#include "H5VLpublic.h" /* Virtual Object Layer */ /* Private headers needed by this file */ -#include "H5MMprivate.h" /* Memory management */ +#include "H5MMprivate.h" /* Memory management */ #ifdef H5_HAVE_PARALLEL -#include "H5Pprivate.h" /* Property lists */ +#include "H5Pprivate.h" /* Property lists */ #endif /* H5_HAVE_PARALLEL */ -#include "H5VMprivate.h" /* Vectors and arrays */ +#include "H5VMprivate.h" /* Vectors and arrays */ /**************************/ @@ -335,6 +336,7 @@ typedef struct H5F_t H5F_t; #define H5F_NULL_FSM_ADDR(F) ((F)->shared->null_fsm_addr) #define H5F_GET_MIN_DSET_OHDR(F) ((F)->shared->crt_dset_min_ohdr_flag) #define H5F_SET_MIN_DSET_OHDR(F, V) ((F)->shared->crt_dset_min_ohdr_flag = (V)) +#define H5F_VOL_CLS(F) ((F)->shared->vol_cls) #else /* H5F_MODULE */ #define H5F_LOW_BOUND(F) (H5F_get_low_bound(F)) #define H5F_HIGH_BOUND(F) (H5F_get_high_bound(F)) @@ -395,6 +397,7 @@ typedef struct H5F_t H5F_t; #define H5F_NULL_FSM_ADDR(F) (H5F_get_null_fsm_addr(F)) #define H5F_GET_MIN_DSET_OHDR(F) (H5F_get_min_dset_ohdr(F)) #define H5F_SET_MIN_DSET_OHDR(F, V) (H5F_set_min_dset_ohdr((F), (V))) +#define H5F_VOL_CLS(F) (H5F_get_vol_cls(F)) #endif /* H5F_MODULE */ @@ -755,6 +758,7 @@ H5_DLL hbool_t H5F_get_point_of_no_return(const H5F_t *f); H5_DLL hbool_t H5F_get_null_fsm_addr(const H5F_t *f); H5_DLL hbool_t H5F_get_min_dset_ohdr(const H5F_t *f); H5_DLL herr_t H5F_set_min_dset_ohdr(H5F_t *f, hbool_t minimize); +H5_DLL const H5VL_class_t *H5F_get_vol_cls(const H5F_t *f); /* Functions than retrieve values set/cached from the superblock/FCPL */ H5_DLL haddr_t H5F_get_base_addr(const H5F_t *f); diff --git a/src/H5Fquery.c b/src/H5Fquery.c index f36f348..32743c4 100644 --- a/src/H5Fquery.c +++ b/src/H5Fquery.c @@ -1279,3 +1279,66 @@ H5F_get_null_fsm_addr(const H5F_t *f) FUNC_LEAVE_NOAPI(f->shared->null_fsm_addr) } /* end H5F_get_null_fsm_addr() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_get_vol_cls + * + * Purpose: Get the VOL class for the file + * + * Return: VOL class pointer for file, can't fail + * + * Programmer: Quincey Koziol + * Saturday, August 17, 2019 + * + *------------------------------------------------------------------------- + */ +const H5VL_class_t * +H5F_get_vol_cls(const H5F_t *f) +{ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + HDassert(f); + HDassert(f->shared); + + FUNC_LEAVE_NOAPI(f->shared->vol_cls) +} /* end H5F_get_vol_cls */ + + +/*------------------------------------------------------------------------- + * Function: H5F_get_cont_info + * + * Purpose: Get the VOL container info for the file + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * Saturday, August 17, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5F__get_cont_info(const H5F_t *f, H5VL_file_cont_info_t *info) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Sanity checks */ + HDassert(f); + HDassert(f->shared); + + /* Verify structure version */ + if(info->version != H5VL_CONTAINER_INFO_VERSION) + HGOTO_ERROR(H5E_FILE, H5E_VERSION, FAIL, "wrong container info version #") + + /* Set the container info fields */ + info->feature_flags = 0; /* None currently defined */ + info->token_size = H5F_SIZEOF_ADDR(f); + info->blob_id_size = H5HG_HEAP_ID_SIZE(f); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5F_get_cont_info */ + diff --git a/src/H5HGprivate.h b/src/H5HGprivate.h index 1c609e2..4841847 100644 --- a/src/H5HGprivate.h +++ b/src/H5HGprivate.h @@ -49,6 +49,10 @@ typedef struct H5HG_heap_t H5HG_heap_t; #define H5HG_FREE_SIZE(H) (H5HG_get_free_size(H)) #endif /* H5HG_MODULE */ +/* Size of encoded global heap ID */ +/* (size of file address + 32-bit integer) */ +#define H5HG_HEAP_ID_SIZE(F) ((size_t)H5F_SIZEOF_ADDR(F) + H5_SIZEOF_UINT32_T) + /* Main global heap routines */ H5_DLL herr_t H5HG_insert(H5F_t *f, size_t size, void *obj, H5HG_t *hobj/*out*/); @@ -263,8 +263,8 @@ H5Oopen_by_addr(hid_t loc_id, haddr_t addr) FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE2("i", "ia", loc_id, addr); - loc_params.type = H5VL_OBJECT_BY_ADDR; - loc_params.loc_data.loc_by_addr.addr = addr; + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = &addr; loc_params.obj_type = H5I_get_type(loc_id); /* Get the location object */ diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index 9578f95..6e0db25 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -85,8 +85,6 @@ static herr_t H5O__copy_header(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /* hid_t ocpypl_id, hid_t lcpl_id); static herr_t H5O__copy_obj(H5G_loc_t *src_loc, H5G_loc_t *dst_loc, const char *dst_name, hid_t ocpypl_id, hid_t lcpl_id); -static herr_t H5O__copy_obj_by_ref(H5O_loc_t *src_oloc, H5O_loc_t *dst_oloc, - H5G_loc_t *dst_root_loc, H5O_copy_t *cpy_info); static herr_t H5O__copy_free_comm_dt_cb(void *item, void *key, void *op_data); static int H5O__copy_comm_dt_cmp(const void *dt1, const void *dt2); static herr_t H5O__copy_search_comm_dt_cb(hid_t group, const char *name, @@ -110,7 +108,6 @@ H5FL_DEFINE(H5O_copy_search_comm_dt_key_t); /* Declare a free list to manage haddr_t variables */ H5FL_DEFINE(haddr_t); - /*****************************/ /* Library Private Variables */ /*****************************/ @@ -1235,201 +1232,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5O__copy_obj_by_ref - * - * Purpose: Copy the object pointed by _src_ref. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Peter Cao - * Aug 7 2006 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5O__copy_obj_by_ref(H5O_loc_t *src_oloc, H5O_loc_t *dst_oloc, - H5G_loc_t *dst_root_loc, H5O_copy_t *cpy_info) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_STATIC - - HDassert(src_oloc); - HDassert(dst_oloc); - - /* Perform the copy, or look up existing copy */ - if((ret_value = H5O_copy_header_map(src_oloc, dst_oloc, cpy_info, FALSE, NULL, NULL)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") - - /* Check if a new valid object is copied to the destination */ - if(H5F_addr_defined(dst_oloc->addr) && (ret_value > SUCCEED)) { - char tmp_obj_name[80]; - H5G_name_t new_path; - H5O_loc_t new_oloc; - H5G_loc_t new_loc; - - /* Set up group location for new object */ - new_loc.oloc = &new_oloc; - new_loc.path = &new_path; - H5G_loc_reset(&new_loc); - new_oloc.file = dst_oloc->file; - new_oloc.addr = dst_oloc->addr; - - /* Pick a default name for the new object */ - HDsnprintf(tmp_obj_name, sizeof(tmp_obj_name), "~obj_pointed_by_%llu", (unsigned long long)dst_oloc->addr); - - /* Create a link to the newly copied object */ - /* Note: since H5O_copy_header_map actually copied the target object, it - * must exist either in cache or on disk, therefore it is is safe to not - * pass the obj_type and udata fields returned by H5O_copy_header_map. - * This could be changed in the future to slightly improve performance - * --NAF */ - if(H5L_link(dst_root_loc, tmp_obj_name, &new_loc, cpy_info->lcpl_id) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert link") - - H5G_loc_free(&new_loc); - } /* if (H5F_addr_defined(dst_oloc.addr)) */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O__copy_obj_by_ref() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_copy_expand_ref - * - * Purpose: Copy the object pointed by _src_ref. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Peter Cao - * Aug 7 2006 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, H5F_t *file_dst, - void *_dst_ref, size_t ref_count, H5R_type_t ref_type, H5O_copy_t *cpy_info) -{ - H5O_loc_t dst_oloc; /* Copied object object location */ - H5O_loc_t src_oloc; /* Temporary object location for source object */ - H5G_loc_t dst_root_loc; /* The location of root group of the destination file */ - const uint8_t *q; /* Pointer to source OID to store */ - uint8_t *p; /* Pointer to destination OID to store */ - size_t i; /* Local index variable */ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI(FAIL) - - /* Sanity checks */ - HDassert(file_src); - HDassert(_src_ref); - HDassert(file_dst); - HDassert(_dst_ref); - HDassert(ref_count); - HDassert(cpy_info); - - /* Initialize object locations */ - H5O_loc_reset(&src_oloc); - H5O_loc_reset(&dst_oloc); - src_oloc.file = file_src; - dst_oloc.file = file_dst; - - /* Set up the root group in the destination file */ - if(NULL == (dst_root_loc.oloc = H5G_oloc(H5G_rootof(file_dst)))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get object location for root group") - if(NULL == (dst_root_loc.path = H5G_nameof(H5G_rootof(file_dst)))) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get path for root group") - - /* Copy object references */ - if(H5R_OBJECT == ref_type) { - hobj_ref_t *src_ref = (hobj_ref_t *)_src_ref; - hobj_ref_t *dst_ref = (hobj_ref_t *)_dst_ref; - - /* Making equivalent references in the destination file */ - for(i = 0; i < ref_count; i++) { - /* Set up for the object copy for the reference */ - q = (uint8_t *)(&src_ref[i]); - H5F_addr_decode(src_oloc.file, (const uint8_t **)&q, &(src_oloc.addr)); - dst_oloc.addr = HADDR_UNDEF; - - /* Attempt to copy object from source to destination file */ - if(src_oloc.addr != (haddr_t)0) { - if(H5O__copy_obj_by_ref(&src_oloc, &dst_oloc, &dst_root_loc, cpy_info) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") - } /* end if */ - else - /* Set parameters so the reference is written as all 0's */ - HDmemset(&dst_oloc.addr, 0, sizeof(dst_oloc.addr)); - - /* Set the object reference info for the destination file */ - p = (uint8_t *)(&dst_ref[i]); - H5F_addr_encode(dst_oloc.file, &p, dst_oloc.addr); - } /* end for */ - } /* end if */ - /* Copy region references */ - else if(H5R_DATASET_REGION == ref_type) { - hdset_reg_ref_t *src_ref = (hdset_reg_ref_t *)_src_ref; - hdset_reg_ref_t *dst_ref = (hdset_reg_ref_t *)_dst_ref; - uint8_t *buf = NULL; /* Buffer to store serialized selection in */ - H5HG_t hobjid; /* Heap object ID */ - size_t buf_size; /* Length of object in heap */ - - /* Making equivalent references in the destination file */ - for(i = 0; i < ref_count; i++) { - /* Get the heap ID for the dataset region */ - q = (const uint8_t *)(&src_ref[i]); - H5F_addr_decode(src_oloc.file, (const uint8_t **)&q, &(hobjid.addr)); - UINT32DECODE(q, hobjid.idx); - - if(hobjid.addr != (haddr_t)0) { - /* Get the dataset region from the heap (allocate inside routine) */ - if((buf = (uint8_t *)H5HG_read(src_oloc.file, &hobjid, NULL, &buf_size)) == NULL) - HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL, "Unable to read dataset region information") - - /* Get the object oid for the dataset */ - q = (const uint8_t *)buf; - H5F_addr_decode(src_oloc.file, (const uint8_t **)&q, &(src_oloc.addr)); - dst_oloc.addr = HADDR_UNDEF; - - /* copy the object pointed by the ref to the destination */ - if(H5O__copy_obj_by_ref(&src_oloc, &dst_oloc, &dst_root_loc, cpy_info) < 0) { - H5MM_xfree(buf); - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") - } /* end if */ - - /* Serialize object ID */ - p = (uint8_t *)buf; - H5F_addr_encode(dst_oloc.file, &p, dst_oloc.addr); - - /* Save the serialized buffer to the destination */ - if(H5HG_insert(dst_oloc.file, buf_size, buf, &hobjid) < 0) { - H5MM_xfree(buf); - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "Unable to write dataset region information") - } /* end if */ - } /* end if */ - else - /* Set parameters so the reference is written as all 0's */ - HDmemset(&hobjid, 0, sizeof(hobjid)); - - /* Set the dataset region reference info for the destination file */ - p = (uint8_t *)(&dst_ref[i]); - H5F_addr_encode(dst_oloc.file, &p, hobjid.addr); - UINT32ENCODE(p, hobjid.idx); - - /* Free the buffer allocated in H5HG_read() */ - H5MM_xfree(buf); - } /* end for */ - } /* end if */ - else - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_copy_expand_ref() */ - - -/*------------------------------------------------------------------------- * Function: H5O__copy_free_comm_dt_cb * * Purpose: Frees the merge committed dt skip list key and object. diff --git a/src/H5Ocopy_ref.c b/src/H5Ocopy_ref.c new file mode 100644 index 0000000..e8212d6bb --- /dev/null +++ b/src/H5Ocopy_ref.c @@ -0,0 +1,485 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * 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. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*------------------------------------------------------------------------- + * + * Created: H5Ocopy_ref.c + * + * Purpose: Object with references copying routines. + * + *------------------------------------------------------------------------- + */ + +/****************/ +/* Module Setup */ +/****************/ + +#include "H5Omodule.h" /* This source code file is part of the H5O module */ +#define H5F_FRIEND /* Suppress error about including H5Fpkg */ +#define H5R_FRIEND /* Suppress error about including H5Rpkg */ + + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5Fpkg.h" /* File */ +#include "H5Iprivate.h" /* IDs */ +#include "H5Lprivate.h" /* Links */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Opkg.h" /* Object headers */ +#include "H5Rpkg.h" /* References */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + +static herr_t H5O__copy_obj_by_ref(H5O_loc_t *src_oloc, H5O_loc_t *dst_oloc, + H5G_loc_t *dst_root_loc, H5O_copy_t *cpy_info); +static herr_t H5O__copy_expand_ref_object1(H5O_loc_t *src_oloc, + const void *buf_src, H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, + void *buf_dst, size_t ref_count, H5O_copy_t *cpy_info); +static herr_t H5O__copy_expand_ref_region1(H5O_loc_t *src_oloc, + const void *buf_src, H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, + void *buf_dst, size_t ref_count, H5O_copy_t *cpy_info); +static herr_t H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, + H5T_t *dt_src, const void *buf_src, size_t nbytes_src, H5O_loc_t *dst_oloc, + H5G_loc_t *dst_root_loc, void *buf_dst, size_t ref_count, + H5O_copy_t *cpy_info); + +/*********************/ +/* Package Variables */ +/*********************/ + +/* Declare extern the free list to manage blocks of type conversion data */ +H5FL_BLK_EXTERN(type_conv); + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + +/*------------------------------------------------------------------------- + * Function: H5O__copy_obj_by_ref + * + * Purpose: Copy the object pointed to by src_oloc. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O__copy_obj_by_ref(H5O_loc_t *src_oloc, H5O_loc_t *dst_oloc, + H5G_loc_t *dst_root_loc, H5O_copy_t *cpy_info) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_oloc); + HDassert(dst_oloc); + + /* Perform the copy, or look up existing copy */ + if((ret_value = H5O_copy_header_map(src_oloc, dst_oloc, cpy_info, FALSE, NULL, NULL)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") + + /* Check if a new valid object is copied to the destination */ + if(H5F_addr_defined(dst_oloc->addr) && (ret_value > SUCCEED)) { + char tmp_obj_name[80]; + H5G_name_t new_path; + H5O_loc_t new_oloc; + H5G_loc_t new_loc; + + /* Set up group location for new object */ + new_loc.oloc = &new_oloc; + new_loc.path = &new_path; + H5G_loc_reset(&new_loc); + new_oloc.file = dst_oloc->file; + new_oloc.addr = dst_oloc->addr; + + /* Pick a default name for the new object */ + HDsnprintf(tmp_obj_name, sizeof(tmp_obj_name), "~obj_pointed_by_%llu", (unsigned long long)dst_oloc->addr); + + /* Create a link to the newly copied object */ + /* Note: since H5O_copy_header_map actually copied the target object, it + * must exist either in cache or on disk, therefore it is is safe to not + * pass the obj_type and udata fields returned by H5O_copy_header_map. + * This could be changed in the future to slightly improve performance + * --NAF */ + if(H5L_link(dst_root_loc, tmp_obj_name, &new_loc, cpy_info->lcpl_id) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert link") + + H5G_loc_free(&new_loc); + } /* if (H5F_addr_defined(dst_oloc.addr)) */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O__copy_obj_by_ref() */ + + +/*------------------------------------------------------------------------- + * Function: H5O__copy_expand_ref_object1 + * + * Purpose: Copy the object pointed by a deprecated object reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O__copy_expand_ref_object1(H5O_loc_t *src_oloc, const void *buf_src, + H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, void *buf_dst, + size_t ref_count, H5O_copy_t *cpy_info) +{ + const hobj_ref_t *src_ref = (const hobj_ref_t *)buf_src; + hobj_ref_t *dst_ref = (hobj_ref_t *)buf_dst; + const unsigned char zeros[H5R_OBJ_REF_BUF_SIZE] = { 0 }; + size_t buf_size = H5R_OBJ_REF_BUF_SIZE; + size_t i; /* Local index variable */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + /* Making equivalent references in the destination file */ + for(i = 0; i < ref_count; i++) { + const unsigned char *src_buf = (const unsigned char *)&src_ref[i]; + unsigned char *dst_buf = (unsigned char *)&dst_ref[i]; + + /* If data is not initialized, copy zeros and skip */ + if(0 == HDmemcmp(src_buf, zeros, buf_size)) { + HDmemset(dst_buf, 0, buf_size); + continue; + } + + /* Set up for the object copy for the reference */ + if(H5R__decode_addr_obj_compat(src_buf, &buf_size, &src_oloc->addr) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode src object address") + if(!H5F_addr_defined(src_oloc->addr) || src_oloc->addr == 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "undefined reference pointer") + dst_oloc->addr = HADDR_UNDEF; + + /* Attempt to copy object from source to destination file */ + if(H5O__copy_obj_by_ref(src_oloc, dst_oloc, dst_root_loc, cpy_info) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") + + /* Set the object reference info for the destination file */ + if(H5R__encode_addr_obj_compat(dst_oloc->addr, dst_buf, &buf_size) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to encode dst object address") + } /* end for */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O__copy_expand_ref_object1() */ + + +/*------------------------------------------------------------------------- + * Function: H5O__copy_expand_ref_region1 + * + * Purpose: Copy the object pointed by a deprecated region reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O__copy_expand_ref_region1(H5O_loc_t *src_oloc, const void *buf_src, + H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, void *buf_dst, + size_t ref_count, H5O_copy_t *cpy_info) +{ + const hdset_reg_ref_t *src_ref = (const hdset_reg_ref_t *)buf_src; + hdset_reg_ref_t *dst_ref = (hdset_reg_ref_t *)buf_dst; + const unsigned char zeros[H5R_DSET_REG_REF_BUF_SIZE] = { 0 }; + size_t buf_size = H5R_DSET_REG_REF_BUF_SIZE; + size_t i; /* Local index variable */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + /* Making equivalent references in the destination file */ + for(i = 0; i < ref_count; i++) { + const unsigned char *src_buf = (const unsigned char *)&src_ref[i]; + unsigned char *dst_buf = (unsigned char *)&dst_ref[i]; + unsigned char *data = NULL; + size_t data_size; + const uint8_t *p; + uint8_t *q; + + /* If data is not initialized, copy zeros and skip */ + if(0 == HDmemcmp(src_buf, zeros, buf_size)) { + HDmemset(dst_buf, 0, buf_size); + continue; + } + + /* Read from heap */ + if(H5R__decode_heap(src_oloc->file, src_buf, &buf_size, &data, &data_size) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode dataset region information") + + /* Get object address */ + p = (const uint8_t *)data; + H5F_addr_decode(src_oloc->file, &p, &src_oloc->addr); + if(!H5F_addr_defined(src_oloc->addr) || src_oloc->addr == 0) { + H5MM_free(data); + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "undefined reference pointer") + } + dst_oloc->addr = HADDR_UNDEF; + + /* Attempt to copy object from source to destination file */ + if(H5O__copy_obj_by_ref(src_oloc, dst_oloc, dst_root_loc, cpy_info) < 0) { + H5MM_free(data); + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") + } /* end if */ + + /* Serialize object addr */ + q = (uint8_t *)data; + H5F_addr_encode(dst_oloc->file, &q, dst_oloc->addr); + + /* Write to heap */ + if(H5R__encode_heap(dst_oloc->file, dst_buf, &buf_size, data, (size_t)data_size) < 0) { + H5MM_free(data); + HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode dataset region information") + } + + /* Free the buffer allocated in H5R__decode_heap() */ + H5MM_free(data); + } /* end for */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O__copy_expand_ref_region1() */ + + +/*------------------------------------------------------------------------- + * Function: H5O__copy_expand_ref_object2 + * + * Purpose: Copy the object pointed by a reference (object, region, attribute). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, H5T_t *dt_src, + const void *buf_src, size_t nbytes_src, H5O_loc_t *dst_oloc, + H5G_loc_t *dst_root_loc, void *buf_dst, size_t ref_count, + H5O_copy_t *cpy_info) +{ + H5T_t *dt_mem = NULL; /* Memory datatype */ + H5T_t *dt_dst = NULL; /* Destination datatype */ + hid_t tid_mem = H5I_INVALID_HID; /* Datatype ID for memory datatype */ + hid_t tid_dst = H5I_INVALID_HID; /* Datatype ID for memory datatype */ + H5T_path_t *tpath_src_mem = NULL, + *tpath_mem_dst = NULL; /* Datatype conversion paths */ + size_t i; /* Local index variable */ + hbool_t reg_tid_src = (tid_src == H5I_INVALID_HID); + hid_t dst_loc_id = H5I_INVALID_HID; + void *conv_buf = NULL; /* Buffer for converting data */ + size_t conv_buf_size = 0; /* Buffer size */ + void *reclaim_buf = NULL; /* Buffer for reclaiming data */ + H5S_t *buf_space = NULL; /* Dataspace describing buffer */ + hsize_t buf_dim[1] = {ref_count}; /* Dimension for buffer */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + /* Create datatype ID for src datatype. */ + if((tid_src == H5I_INVALID_HID) && (tid_src = H5I_register(H5I_DATATYPE, dt_src, FALSE)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTREGISTER, FAIL, "unable to register source file datatype") + + /* create a memory copy of the reference datatype */ + if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to copy") + if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) { + (void)H5T_close_real(dt_mem); + HGOTO_ERROR(H5E_OHDR, H5E_CANTREGISTER, FAIL, "unable to register memory datatype") + } /* end if */ + + /* create reference datatype at the destinaton file */ + if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to copy") + if(H5T_set_loc(dt_dst, dst_oloc->file, H5T_LOC_DISK) < 0) { + (void)H5T_close_real(dt_dst); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") + } /* end if */ + if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) { + (void)H5T_close_real(dt_dst); + HGOTO_ERROR(H5E_OHDR, H5E_CANTREGISTER, FAIL, "unable to register destination file datatype") + } /* end if */ + + /* Set up the conversion functions */ + if(NULL == (tpath_src_mem = H5T_path_find(dt_src, dt_mem))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to convert between src and mem datatypes") + if(NULL == (tpath_mem_dst = H5T_path_find(dt_mem, dt_dst))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to convert between mem and dst datatypes") + + /* Use extra conversion buffer (TODO we should avoid using an extra buffer once the H5Ocopy code has been reworked) */ + conv_buf_size = MAX(H5T_get_size(dt_src), H5T_get_size(dt_mem)) * ref_count; + if(NULL == (conv_buf = H5FL_BLK_MALLOC(type_conv, conv_buf_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for copy buffer") + H5MM_memcpy(conv_buf, buf_src, nbytes_src); + + /* Convert from source file to memory */ + if(H5T_convert(tpath_src_mem, tid_src, tid_mem, ref_count, (size_t)0, (size_t)0, conv_buf, NULL) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCONVERT, FAIL, "datatype conversion failed") + + /* Retrieve loc ID */ + if((dst_loc_id = H5F__get_file_id(dst_oloc->file, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Making equivalent references in the destination file */ + for(i = 0; i < ref_count; i++) { + H5R_ref_t *ref_ptr = (H5R_ref_t *)conv_buf; + H5R_ref_priv_t *ref = (H5R_ref_priv_t *)&ref_ptr[i]; + size_t token_size = sizeof(src_oloc->addr); + + /* Get src object address */ + if(H5R__get_obj_token(ref, (H5VL_token_t *)&src_oloc->addr, &token_size) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "unable to get object token") + + /* Attempt to copy object from source to destination file */ + if(H5O__copy_obj_by_ref(src_oloc, dst_oloc, dst_root_loc, cpy_info) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object") + + /* Set dst object address */ + if(H5R__set_obj_token(ref, (const H5VL_token_t *)&dst_oloc->addr, token_size) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "unable to set object token") + if(H5R__set_loc_id(ref, dst_loc_id, TRUE) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "unable to set destination loc id") + } /* end for */ + + /* Copy into another buffer, to reclaim memory later */ + if(NULL == (reclaim_buf = H5FL_BLK_MALLOC(type_conv, conv_buf_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for copy buffer") + H5MM_memcpy(reclaim_buf, conv_buf, conv_buf_size); + if(NULL == (buf_space = H5S_create_simple((unsigned)1, buf_dim, NULL))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, FAIL, "can't create simple dataspace") + + /* Convert from memory to destination file */ + if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, ref_count, (size_t)0, (size_t)0, conv_buf, NULL) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCONVERT, FAIL, "datatype conversion failed") + H5MM_memcpy(buf_dst, conv_buf, nbytes_src); + + /* Reclaim space from reference data */ + if(H5T_reclaim(tid_mem, buf_space, reclaim_buf) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "unable to reclaim reference data") + +done: + if(buf_space && (H5S_close(buf_space) < 0)) + HDONE_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "Can't close dataspace") + /* Don't decrement ID, we want to keep underlying datatype */ + if(reg_tid_src && (tid_src > 0) && (NULL == H5I_remove(tid_src))) + HDONE_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") + if((tid_mem > 0) && H5I_dec_ref(tid_mem) < 0) + HDONE_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") + if((tid_dst > 0) && H5I_dec_ref(tid_dst) < 0) + HDONE_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") + if(reclaim_buf) + reclaim_buf = H5FL_BLK_FREE(type_conv, reclaim_buf); + if(conv_buf) + conv_buf = H5FL_BLK_FREE(type_conv, conv_buf); + if((dst_loc_id != H5I_INVALID_HID) && (H5I_dec_ref(dst_loc_id) < 0)) + HDONE_ERROR(H5E_OHDR, H5E_CANTDEC, FAIL, "unable to decrement refcount on location id") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O__copy_expand_ref_object2() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_copy_expand_ref + * + * Purpose: Copy the object pointed by a reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_copy_expand_ref(H5F_t *file_src, hid_t tid_src, H5T_t *dt_src, + void *buf_src, size_t nbytes_src, H5F_t *file_dst, void *buf_dst, + H5O_copy_t *cpy_info) +{ + H5O_loc_t dst_oloc; /* Copied object object location */ + H5O_loc_t src_oloc; /* Temporary object location for source object */ + H5G_loc_t dst_root_loc; /* The location of root group of the destination file */ + size_t ref_count; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity checks */ + HDassert(file_src); + HDassert(buf_src); + HDassert(file_dst); + HDassert(buf_dst); + HDassert(nbytes_src); + HDassert(cpy_info); + + /* Initialize object locations */ + H5O_loc_reset(&src_oloc); + H5O_loc_reset(&dst_oloc); + src_oloc.file = file_src; + dst_oloc.file = file_dst; + + /* Set up the root group in the destination file */ + if(NULL == (dst_root_loc.oloc = H5G_oloc(H5G_rootof(file_dst)))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get object location for root group") + if(NULL == (dst_root_loc.path = H5G_nameof(H5G_rootof(file_dst)))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get path for root group") + + /* Determine # of reference elements to copy */ + ref_count = nbytes_src / H5T_get_size(dt_src); + + /* Copy object references */ + switch(H5T_get_ref_type(dt_src)) { + case H5R_OBJECT1: + if(H5O__copy_expand_ref_object1(&src_oloc, buf_src, &dst_oloc, &dst_root_loc, buf_dst, ref_count, cpy_info) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, FAIL, "unable to expand H5R_OBJECT1 reference") + break; + case H5R_DATASET_REGION1: + if(H5O__copy_expand_ref_region1(&src_oloc, buf_src, &dst_oloc, &dst_root_loc, buf_dst, ref_count, cpy_info) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, FAIL, "unable to expand H5R_DATASET_REGION1 reference") + break; + case H5R_DATASET_REGION2: + case H5R_ATTR: + case H5R_OBJECT2: + if(H5O__copy_expand_ref_object2(&src_oloc, tid_src, dt_src, buf_src, nbytes_src, &dst_oloc, &dst_root_loc, buf_dst, ref_count, cpy_info) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, FAIL, "unable to expand reference") + break; + case H5R_BADTYPE: + case H5R_MAXTYPE: + default: + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") + break; + } /* end switch */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_copy_expand_ref() */ diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 8f301af..805df2b 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -129,7 +129,7 @@ const H5O_msg_class_t H5O_MSG_DTYPE[1] = {{ *------------------------------------------------------------------------- */ static htri_t -H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **pp, H5T_t *dt) +H5O_dtype_decode_helper(unsigned *ioflags/*in,out*/, const uint8_t **pp, H5T_t *dt) { unsigned flags, version; unsigned i; @@ -145,7 +145,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p /* Version, class & flags */ UINT32DECODE(*pp, flags); version = (flags>>4) & 0x0f; - if(version < H5O_DTYPE_VERSION_1 || version > H5O_DTYPE_VERSION_3) + if(version < H5O_DTYPE_VERSION_1 || version > H5O_DTYPE_VERSION_LATEST) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTLOAD, FAIL, "bad version number for datatype message") dt->shared->version = version; dt->shared->type = (H5T_class_t)(flags & 0x0f); @@ -331,7 +331,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Decode the field's datatype information */ - if((can_upgrade = H5O_dtype_decode_helper(f, ioflags, pp, temp_type)) < 0) { + if((can_upgrade = H5O_dtype_decode_helper(ioflags, pp, temp_type)) < 0) { for(j = 0; j <= i; j++) H5MM_xfree(dt->shared->u.compnd.memb[j].name); H5MM_xfree(dt->shared->u.compnd.memb); @@ -438,16 +438,28 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p /* Set reference type */ dt->shared->u.atomic.u.r.rtype = (H5R_type_t)(flags & 0x0f); - - /* Set extra information for object references, so the hobj_ref_t gets swizzled correctly */ - if(dt->shared->u.atomic.u.r.rtype == H5R_OBJECT) { - /* Mark location this type as undefined for now. The caller function should - * decide the location. */ - dt->shared->u.atomic.u.r.loc = H5T_LOC_BADLOC; - - /* This type needs conversion */ - dt->shared->force_conv = TRUE; - } /* end if */ + if(dt->shared->u.atomic.u.r.rtype <= H5R_BADTYPE + || dt->shared->u.atomic.u.r.rtype >= H5R_MAXTYPE) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "invalid reference type"); + + /* Set generic flag */ + if(dt->shared->u.atomic.u.r.rtype == H5R_OBJECT2 + || dt->shared->u.atomic.u.r.rtype == H5R_DATASET_REGION2 + || dt->shared->u.atomic.u.r.rtype == H5R_ATTR) { + dt->shared->u.atomic.u.r.opaque = TRUE; + dt->shared->u.atomic.u.r.version = (unsigned)((flags >> 4) & 0x0f); + if(dt->shared->u.atomic.u.r.version != H5R_ENCODE_VERSION) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "reference version does not match"); + } else + dt->shared->u.atomic.u.r.opaque = FALSE; + + /* This type needs conversion */ + dt->shared->force_conv = TRUE; + + /* Mark location of this type as undefined for now. The caller + * function should decide the location. */ + if(H5T_set_loc(dt, NULL, H5T_LOC_BADLOC) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") break; case H5T_ENUM: @@ -457,7 +469,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p dt->shared->u.enumer.nmembs = dt->shared->u.enumer.nalloc = flags & 0xffff; if(NULL == (dt->shared->parent = H5T__alloc())) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - if(H5O_dtype_decode_helper(f, ioflags, pp, dt->shared->parent) < 0) + if(H5O_dtype_decode_helper(ioflags, pp, dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode parent datatype") /* Check if the parent of this enum has a version greater than the @@ -499,7 +511,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p /* Decode base type of VL information */ if(NULL == (dt->shared->parent = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed") - if(H5O_dtype_decode_helper(f, ioflags, pp, dt->shared->parent) < 0) + if(H5O_dtype_decode_helper(ioflags, pp, dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode VL parent type") /* Check if the parent of this vlen has a version greater than the @@ -511,7 +523,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p /* Mark location this type as undefined for now. The caller function should * decide the location. */ - if(H5T_set_loc(dt, f, H5T_LOC_BADLOC) < 0) + if(H5T_set_loc(dt, NULL, H5T_LOC_BADLOC) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") break; @@ -540,7 +552,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p /* Decode base type of array */ if(NULL == (dt->shared->parent = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "memory allocation failed") - if(H5O_dtype_decode_helper(f, ioflags, pp, dt->shared->parent) < 0) + if(H5O_dtype_decode_helper(ioflags, pp, dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "unable to decode array parent type") /* Check if the parent of this array has a version greater than the @@ -596,7 +608,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) +H5O_dtype_encode_helper(uint8_t **pp, const H5T_t *dt) { unsigned flags = 0; uint8_t *hdr = (uint8_t *)*pp; @@ -956,7 +968,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) } /* end if */ /* Subtype */ - if(H5O_dtype_encode_helper(f, pp, dt->shared->u.compnd.memb[i].type) < 0) + if(H5O_dtype_encode_helper(pp, dt->shared->u.compnd.memb[i].type) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode member type") } /* end for */ } @@ -964,6 +976,8 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) case H5T_REFERENCE: flags |= (dt->shared->u.atomic.u.r.rtype & 0x0f); + if(dt->shared->u.atomic.u.r.opaque) + flags = (unsigned)(flags | (((unsigned)dt->shared->u.atomic.u.r.version & 0x0f) << 4)); break; case H5T_ENUM: @@ -976,7 +990,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) flags = dt->shared->u.enumer.nmembs & 0xffff; /* Parent type */ - if(H5O_dtype_encode_helper(f, pp, dt->shared->parent) < 0) + if(H5O_dtype_encode_helper(pp, dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode parent datatype") /* Names, each a multiple of eight bytes */ @@ -1012,7 +1026,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) } /* end if */ /* Encode base type of VL information */ - if(H5O_dtype_encode_helper(f, pp, dt->shared->parent) < 0) + if(H5O_dtype_encode_helper(pp, dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode VL parent type") break; @@ -1050,7 +1064,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) } /* end if */ /* Encode base type of array's information */ - if(H5O_dtype_encode_helper(f, pp, dt->shared->parent) < 0) + if(H5O_dtype_encode_helper(pp, dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "unable to encode VL parent type") break; @@ -1091,7 +1105,7 @@ done: function using malloc() and is returned to the caller. --------------------------------------------------------------------------*/ static void * -H5O_dtype_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, +H5O_dtype_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSED mesg_flags, unsigned *ioflags/*in,out*/, size_t H5_ATTR_UNUSED p_size, const uint8_t *p) { H5T_t *dt = NULL; @@ -1107,7 +1121,7 @@ H5O_dtype_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSE HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Perform actual decode of message */ - if(H5O_dtype_decode_helper(f, ioflags, &p, dt) < 0) + if(H5O_dtype_decode_helper(ioflags, &p, dt) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode type") /* Set return value */ @@ -1136,7 +1150,7 @@ done: message in the "raw" disk form. --------------------------------------------------------------------------*/ static herr_t -H5O_dtype_encode(H5F_t *f, uint8_t *p, const void *mesg) +H5O_dtype_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p, const void *mesg) { const H5T_t *dt = (const H5T_t *) mesg; herr_t ret_value = SUCCEED; /* Return value */ @@ -1149,7 +1163,7 @@ H5O_dtype_encode(H5F_t *f, uint8_t *p, const void *mesg) HDassert(dt); /* encode */ - if(H5O_dtype_encode_helper(f, &p, dt) < 0) + if(H5O_dtype_encode_helper(&p, dt) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode type") done: diff --git a/src/H5Ofill.c b/src/H5Ofill.c index df39d19..0cc58a6 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -742,7 +742,7 @@ H5O_fill_reset_dyn(H5O_fill_t *fill) HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, FAIL, "can't create scalar dataspace") /* Reclaim any variable length components of the fill value */ - if(H5D_vlen_reclaim(fill_type_id, fill_space, fill->buf) < 0) { + if(H5T_reclaim(fill_type_id, fill_space, fill->buf) < 0) { H5S_close(fill_space); HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "unable to reclaim variable-length fill value data") } /* end if */ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index bcb8299..54e8ec8 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -981,8 +981,8 @@ H5_DLL herr_t H5O_are_mdc_flushes_disabled(H5O_loc_t *oloc, hbool_t *are_disable H5_DLL herr_t H5O_copy_header_map(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, H5O_copy_t *cpy_info, hbool_t inc_depth, H5O_type_t *obj_type, void **udata); -H5_DLL herr_t H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, - H5F_t *file_dst, void *_dst_ref, size_t ref_count, H5R_type_t ref_type, +H5_DLL herr_t H5O_copy_expand_ref(H5F_t *file_src, hid_t tid_src, H5T_t *dt_src, + void *buf_src, size_t nbytes_src, H5F_t *file_dst, void *buf_dst, H5O_copy_t *cpy_info); H5_DLL herr_t H5O_copy(const H5G_loc_t *src_loc, const char *src_name, H5G_loc_t *dst_loc, const char *dst_name, hid_t ocpypl_id, hid_t lcpl_id); diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c index df9cf4e..9baa201 100644 --- a/src/H5Pdxpl.c +++ b/src/H5Pdxpl.c @@ -1519,7 +1519,7 @@ done: * * Purpose: Sets the memory allocate/free pair for VL datatypes. The * allocation routine is called when data is read into a new - * array and the free routine is called when H5Dvlen_reclaim is + * array and the free routine is called when H5Treclaim is * called. The alloc_info and free_info are user parameters * which are passed to the allocation and freeing functions * respectively. To reset the allocate/free functions to the @@ -1563,7 +1563,7 @@ done: * * Purpose: Sets the memory allocate/free pair for VL datatypes. The * allocation routine is called when data is read into a new - * array and the free routine is called when H5Dvlen_reclaim is + * array and the free routine is called when H5Treclaim is * called. The alloc_info and free_info are user parameters * which are passed to the allocation and freeing functions * respectively. To reset the allocate/free functions to the diff --git a/src/H5Pint.c b/src/H5Pint.c index 36367d7..2911eef 100644 --- a/src/H5Pint.c +++ b/src/H5Pint.c @@ -169,6 +169,8 @@ hid_t H5P_CLS_STRING_CREATE_ID_g = H5I_INVALID_HID; H5P_genclass_t *H5P_CLS_STRING_CREATE_g = NULL; hid_t H5P_CLS_VOL_INITIALIZE_ID_g = H5I_INVALID_HID; H5P_genclass_t *H5P_CLS_VOL_INITIALIZE_g = NULL; +hid_t H5P_CLS_REFERENCE_ACCESS_ID_g = H5I_INVALID_HID; +H5P_genclass_t *H5P_CLS_REFERENCE_ACCESS_g = NULL; /* * Predefined property lists for each predefined class. These are initialized @@ -192,6 +194,7 @@ hid_t H5P_LST_OBJECT_COPY_ID_g = H5I_INVALID_HID; hid_t H5P_LST_LINK_CREATE_ID_g = H5I_INVALID_HID; hid_t H5P_LST_LINK_ACCESS_ID_g = H5I_INVALID_HID; hid_t H5P_LST_VOL_INITIALIZE_ID_g = H5I_INVALID_HID; +hid_t H5P_LST_REFERENCE_ACCESS_ID_g = H5I_INVALID_HID; /* Root property list class library initialization object */ const H5P_libclass_t H5P_CLS_ROOT[1] = {{ @@ -312,6 +315,25 @@ const H5P_libclass_t H5P_CLS_VINI[1] = {{ NULL /* Class close callback info */ }}; +/* Reference access property list class library initialization object */ +/* (move to proper source code file when used for real) */ +const H5P_libclass_t H5P_CLS_RACC[1] = {{ + "reference access", /* Class name for debugging */ + H5P_TYPE_REFERENCE_ACCESS, /* Class type */ + + &H5P_CLS_FILE_ACCESS_g, /* Parent class */ + &H5P_CLS_REFERENCE_ACCESS_g, /* Pointer to class */ + &H5P_CLS_REFERENCE_ACCESS_ID_g, /* Pointer to class ID */ + &H5P_LST_REFERENCE_ACCESS_ID_g, /* Pointer to default property list ID */ + NULL, /* Default property registration routine*/ + + NULL, /* Class creation callback */ + NULL, /* Class creation callback info */ + NULL, /* Class copy callback */ + NULL, /* Class copy callback info */ + NULL, /* Class close callback */ + NULL /* Class close callback info */ +}}; /* Library property list classes defined in other code modules */ /* (And not present in src/H5Pprivate.h) */ @@ -364,7 +386,8 @@ static H5P_libclass_t const * const init_class[] = { H5P_CLS_ACRT, /* Attribute creation */ H5P_CLS_AACC, /* Attribute access */ H5P_CLS_LCRT, /* Link creation */ - H5P_CLS_VINI /* VOL initialization */ + H5P_CLS_VINI, /* VOL initialization */ + H5P_CLS_RACC /* Reference access */ }; /* Declare a free list to manage the H5P_genclass_t struct */ @@ -440,7 +463,7 @@ H5P__init_package(void) FUNC_ENTER_PACKAGE /* Sanity check */ - HDcompile_assert(H5P_TYPE_MAP_ACCESS == (H5P_TYPE_MAX_TYPE - 1)); + HDcompile_assert(H5P_TYPE_REFERENCE_ACCESS == (H5P_TYPE_MAX_TYPE - 1)); /* * Initialize the Generic Property class & object groups. @@ -564,6 +587,7 @@ H5P_term_package(void) H5P_LST_LINK_CREATE_ID_g = H5P_LST_LINK_ACCESS_ID_g = H5P_LST_VOL_INITIALIZE_ID_g = + H5P_LST_REFERENCE_ACCESS_ID_g = H5P_LST_FILE_MOUNT_ID_g = H5I_INVALID_HID; } /* end if */ } /* end if */ @@ -594,6 +618,7 @@ H5P_term_package(void) H5P_CLS_LINK_CREATE_g = H5P_CLS_LINK_ACCESS_g = H5P_CLS_VOL_INITIALIZE_g = + H5P_CLS_REFERENCE_ACCESS_g = H5P_CLS_FILE_MOUNT_g = NULL; H5P_CLS_ROOT_ID_g = @@ -616,6 +641,7 @@ H5P_term_package(void) H5P_CLS_LINK_CREATE_ID_g = H5P_CLS_LINK_ACCESS_ID_g = H5P_CLS_VOL_INITIALIZE_ID_g = + H5P_CLS_REFERENCE_ACCESS_ID_g = H5P_CLS_FILE_MOUNT_ID_g = H5I_INVALID_HID; } /* end if */ } /* end if */ @@ -5453,8 +5479,8 @@ H5P__new_plist_of_type(H5P_plist_type_t type) FUNC_ENTER_PACKAGE /* Sanity checks */ - HDcompile_assert(H5P_TYPE_MAP_ACCESS == (H5P_TYPE_MAX_TYPE - 1)); - HDassert(type >= H5P_TYPE_USER && type <= H5P_TYPE_MAP_ACCESS); + HDcompile_assert(H5P_TYPE_REFERENCE_ACCESS == (H5P_TYPE_MAX_TYPE - 1)); + HDassert(type >= H5P_TYPE_USER && type <= H5P_TYPE_REFERENCE_ACCESS); /* Check arguments */ if(type == H5P_TYPE_USER) @@ -5544,6 +5570,10 @@ H5P__new_plist_of_type(H5P_plist_type_t type) class_id = H5P_CLS_VOL_INITIALIZE_ID_g; break; + case H5P_TYPE_REFERENCE_ACCESS: + class_id = H5P_CLS_REFERENCE_ACCESS_ID_g; + break; + case H5P_TYPE_USER: /* shut compiler warnings up */ case H5P_TYPE_ROOT: case H5P_TYPE_MAX_TYPE: diff --git a/src/H5Pprivate.h b/src/H5Pprivate.h index 9fc1acc..f7253a0 100644 --- a/src/H5Pprivate.h +++ b/src/H5Pprivate.h @@ -81,6 +81,7 @@ typedef enum H5P_plist_type_t { H5P_TYPE_VOL_INITIALIZE = 19, H5P_TYPE_MAP_CREATE = 20, H5P_TYPE_MAP_ACCESS = 21, + H5P_TYPE_REFERENCE_ACCESS = 22, H5P_TYPE_MAX_TYPE } H5P_plist_type_t; diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 9f26b8b..bb33561 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -71,6 +71,7 @@ #define H5P_LINK_CREATE (H5OPEN H5P_CLS_LINK_CREATE_ID_g) #define H5P_LINK_ACCESS (H5OPEN H5P_CLS_LINK_ACCESS_ID_g) #define H5P_VOL_INITIALIZE (H5OPEN H5P_CLS_VOL_INITIALIZE_ID_g) +#define H5P_REFERENCE_ACCESS (H5OPEN H5P_CLS_REFERENCE_ACCESS_ID_g) /* * The library's default property lists @@ -93,6 +94,7 @@ #define H5P_LINK_CREATE_DEFAULT (H5OPEN H5P_LST_LINK_CREATE_ID_g) #define H5P_LINK_ACCESS_DEFAULT (H5OPEN H5P_LST_LINK_ACCESS_ID_g) #define H5P_VOL_INITIALIZE_DEFAULT (H5OPEN H5P_LST_VOL_INITIALIZE_ID_g) +#define H5P_REFERENCE_ACCESS_DEFAULT (H5OPEN H5P_LST_REFERENCE_ACCESS_ID_g) /* Common creation order flags (for links in groups and attributes on objects) */ #define H5P_CRT_ORDER_TRACKED 0x0001 @@ -204,6 +206,7 @@ H5_DLLVAR hid_t H5P_CLS_OBJECT_COPY_ID_g; H5_DLLVAR hid_t H5P_CLS_LINK_CREATE_ID_g; H5_DLLVAR hid_t H5P_CLS_LINK_ACCESS_ID_g; H5_DLLVAR hid_t H5P_CLS_VOL_INITIALIZE_ID_g; +H5_DLLVAR hid_t H5P_CLS_REFERENCE_ACCESS_ID_g; /* Default roperty list IDs */ /* (Internal to library, do not use! Use macros above) */ @@ -225,6 +228,7 @@ H5_DLLVAR hid_t H5P_LST_OBJECT_COPY_ID_g; H5_DLLVAR hid_t H5P_LST_LINK_CREATE_ID_g; H5_DLLVAR hid_t H5P_LST_LINK_ACCESS_ID_g; H5_DLLVAR hid_t H5P_LST_VOL_INITIALIZE_ID_g; +H5_DLLVAR hid_t H5P_LST_REFERENCE_ACCESS_ID_g; /*********************/ /* Public Prototypes */ @@ -11,22 +11,24 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* + * Purpose: Reference routines. + */ + /****************/ /* Module Setup */ /****************/ #include "H5Rmodule.h" /* This source code file is part of the H5R module */ - /***********/ /* Headers */ /***********/ #include "H5private.h" /* Generic Functions */ -#include "H5ACprivate.h" /* Metadata cache */ #include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ -#include "H5Gprivate.h" /* Groups */ #include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Rpkg.h" /* References */ #include "H5Sprivate.h" /* Dataspaces */ @@ -61,330 +63,825 @@ /*******************/ -/*-------------------------------------------------------------------------- - NAME - H5Rcreate - PURPOSE - Creates a particular kind of reference for the user - USAGE - herr_t H5Rcreate(ref, loc_id, name, ref_type, space_id) - void *ref; OUT: Reference created - hid_t loc_id; IN: Location ID used to locate object pointed to - const char *name; IN: Name of object at location LOC_ID of object - pointed to - H5R_type_t ref_type; IN: Type of reference to create - hid_t space_id; IN: Dataspace ID with selection, used for Dataset - Region references. - - RETURNS - Non-negative on success/Negative on failure - DESCRIPTION - Creates a particular type of reference specified with REF_TYPE, in the - space pointed to by REF. The LOC_ID and NAME are used to locate the object - pointed to and the SPACE_ID is used to choose the region pointed to (for - Dataset Region references). - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * Function: H5Rcreate_object + * + * Purpose: Creates an object reference. The LOC_ID and NAME are used to locate + * the object pointed to. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ herr_t -H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, hid_t space_id) +H5Rcreate_object(hid_t loc_id, const char *name, H5R_ref_t *ref_ptr) { - H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ - H5VL_loc_params_t loc_params; - herr_t ret_value; /* Return value */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t obj_type; /* Object type of loc_id */ + hid_t file_id = H5I_INVALID_HID;/* File ID */ + H5VL_object_t *vol_obj_file = NULL; /* Object token of file_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0}; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE5("e", "*xi*sRti", ref, loc_id, name, ref_type, space_id); + H5TRACE3("e", "i*s*Rr", loc_id, name, ref_ptr); /* Check args */ - if (ref == NULL) + if(ref_ptr == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") - if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") - if(ref_type != H5R_OBJECT && ref_type != H5R_DATASET_REGION) - HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "reference type not supported") - if(space_id == (-1) && ref_type == H5R_DATASET_REGION) + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get object type */ + if((obj_type = H5I_get_type(loc_id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get the file for the object */ + if((file_id = H5F_get_file_id(loc_id, obj_type, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Retrieve VOL file object */ + if(NULL == (vol_obj_file = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get container info */ + if(H5VL_file_get(vol_obj_file, H5VL_FILE_GET_CONT_INFO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &cont_info) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get container info") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_NAME; + loc_params.loc_data.loc_by_name.name = name; + loc_params.obj_type = obj_type; + + /* Get the object token */ + if(H5VL_object_specific(vol_obj, &loc_params, H5VL_OBJECT_LOOKUP, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, obj_token) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object token") + + /* Create the reference (do not pass filename, since file_id is attached) */ + HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE); + if(H5R__create_object((const H5VL_token_t *)&obj_token, cont_info.token_size, (H5R_ref_priv_t *)ref_ptr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create object reference") + + /* Attach loc_id to reference and hold reference to it */ + if(H5R__set_loc_id((H5R_ref_priv_t *)ref_ptr, file_id, TRUE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference") + +done: + if(file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file") + FUNC_LEAVE_API(ret_value) +} /* end H5Rcreate_object() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rcreate_region + * + * Purpose: Creates a region reference. The LOC_ID and NAME are used to locate + * the object pointed to and the SPACE_ID is used to choose the region pointed + * to. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, + H5R_ref_t *ref_ptr) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t obj_type; /* Object type of loc_id */ + hid_t file_id = H5I_INVALID_HID;/* File ID */ + H5VL_object_t *vol_obj_file = NULL; /* Object token of file_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0}; + struct H5S_t *space = NULL; /* Pointer to dataspace containing region */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "i*si*Rr", loc_id, name, space_id, ref_ptr); + + /* Check args */ + if(ref_ptr == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") + if(!name || !*name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") + if((space_id == H5I_BADID) || (space_id == H5S_ALL)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reference region dataspace id must be valid") + if(NULL == (space = (struct H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get object type */ + if((obj_type = H5I_get_type(loc_id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get the file for the object */ + if((file_id = H5F_get_file_id(loc_id, obj_type, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Retrieve VOL file object */ + if(NULL == (vol_obj_file = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get container info */ + if(H5VL_file_get(vol_obj_file, H5VL_FILE_GET_CONT_INFO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &cont_info) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get container info") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_NAME; + loc_params.loc_data.loc_by_name.name = name; + loc_params.obj_type = obj_type; + + /* Get the object token */ + if(H5VL_object_specific(vol_obj, &loc_params, H5VL_OBJECT_LOOKUP, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, obj_token) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object token") + + /* Create the reference (do not pass filename, since file_id is attached) */ + HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE); + if(H5R__create_region((const H5VL_token_t *)&obj_token, cont_info.token_size, space, (H5R_ref_priv_t *)ref_ptr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create region reference") + + /* Attach loc_id to reference and hold reference to it */ + if(H5R__set_loc_id((H5R_ref_priv_t *)ref_ptr, file_id, TRUE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference") + +done: + if(file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, H5I_INVALID_HID, "unable to decrement refcount on file") + FUNC_LEAVE_API(ret_value) +} /* end H5Rcreate_region() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rcreate_attr + * + * Purpose: Creates an attribute reference. The LOC_ID, NAME and ATTR_NAME are + * used to locate the attribute pointed to. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, + H5R_ref_t *ref_ptr) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t obj_type; /* Object type of loc_id */ + hid_t file_id = H5I_INVALID_HID;/* File ID */ + H5VL_object_t *vol_obj_file = NULL; /* Object token of file_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0}; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "i*s*s*Rr", loc_id, name, attr_name, ref_ptr); + + /* Check args */ + if(ref_ptr == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") + if(!name || !*name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") + if(!attr_name || !*attr_name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name given") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get object type */ + if((obj_type = H5I_get_type(loc_id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* Set up collective metadata if appropriate */ - if(H5CX_set_loc(loc_id) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "can't set access property list info") + /* Get the file for the object */ + if((file_id = H5F_get_file_id(loc_id, obj_type, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Retrieve VOL file object */ + if(NULL == (vol_obj_file = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get container info */ + if(H5VL_file_get(vol_obj_file, H5VL_FILE_GET_CONT_INFO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &cont_info) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get container info") /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(loc_id); + loc_params.type = H5VL_OBJECT_BY_NAME; + loc_params.loc_data.loc_by_name.name = name; + loc_params.obj_type = obj_type; + + /* Get the object token */ + if(H5VL_object_specific(vol_obj, &loc_params, H5VL_OBJECT_LOOKUP, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, obj_token) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object token") + + /* Create the reference (do not pass filename, since file_id is attached) */ + HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE); + if(H5R__create_attr((const H5VL_token_t *)&obj_token, cont_info.token_size, attr_name, (H5R_ref_priv_t *)ref_ptr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create attribute reference") + + /* Attach loc_id to reference and hold reference to it */ + if(H5R__set_loc_id((H5R_ref_priv_t *)ref_ptr, file_id, TRUE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference") + +done: + if(file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, H5I_INVALID_HID, "unable to decrement refcount on file") + FUNC_LEAVE_API(ret_value) +} /* end H5Rcreate_attr() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rdestroy + * + * Purpose: Destroy reference and free resources allocated during H5Rcreate. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Rdestroy(H5R_ref_t *ref_ptr) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "*Rr", ref_ptr); + + /* Check args */ + if(NULL == ref_ptr) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid reference pointer") + + /* Destroy reference */ + if(H5R__destroy((H5R_ref_priv_t *)ref_ptr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTFREE, FAIL, "unable to destroy reference") + + /* Memset back to 0 for safety */ + HDmemset(ref_ptr, 0, H5R_REF_BUF_SIZE); + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rdestroy() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rget_type + * + * Purpose: Given a reference to some object, return the type of that reference. + * + * Return: Reference type/H5R_BADTYPE on failure + * + *------------------------------------------------------------------------- + */ +H5R_type_t +H5Rget_type(const H5R_ref_t *ref_ptr) +{ + H5R_type_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5R_BADTYPE) + H5TRACE1("Rt", "*Rr", ref_ptr); + + /* Check args */ + if(NULL == ref_ptr) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5R_BADTYPE, "invalid reference pointer") + + /* Get reference type */ + ret_value = H5R__get_type((const H5R_ref_priv_t *)ref_ptr); + if((ret_value <= H5R_BADTYPE) || (ret_value >= H5R_MAXTYPE)) + HGOTO_ERROR(H5E_REFERENCE, H5E_BADVALUE, H5R_BADTYPE, "invalid reference type") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rget_type() */ + + +/*------------------------------------------------------------------------- + * Function: H5Requal + * + * Purpose: Compare two references + * + * Return: TRUE if equal, FALSE if unequal, FAIL if error + * + *------------------------------------------------------------------------- + */ +htri_t +H5Requal(const H5R_ref_t *ref1_ptr, const H5R_ref_t *ref2_ptr) +{ + htri_t ret_value; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE2("t", "*Rr*Rr", ref1_ptr, ref2_ptr); + + /* Check args */ + if(!ref1_ptr || !ref2_ptr) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") + + /* Compare references */ + if((ret_value = H5R__equal((const H5R_ref_priv_t *)ref2_ptr, (const H5R_ref_priv_t *)ref2_ptr)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, FAIL, "cannot compare references") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Requal() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rcopy + * + * Purpose: Copy a reference + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Rcopy(const H5R_ref_t *src_ref_ptr, H5R_ref_t *dst_ref_ptr) +{ + herr_t ret_value = SUCCEED; /* Return value */ - /* Get the file object */ - if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + FUNC_ENTER_API(FAIL) + H5TRACE2("e", "*Rr*Rr", src_ref_ptr, dst_ref_ptr); - /* Set up collective metadata if appropriate */ - if(H5CX_set_loc(loc_id) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "can't set access property list info") + /* Check args */ + if(NULL == src_ref_ptr || NULL == dst_ref_ptr) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid reference pointer") - /* Create reference */ - if((ret_value = H5VL_object_specific(vol_obj, &loc_params, H5VL_REF_CREATE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, ref, name, (int)ref_type, space_id)) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create reference") + /* Copy reference */ + if(H5R__copy((const H5R_ref_priv_t *)src_ref_ptr, (H5R_ref_priv_t *)dst_ref_ptr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "cannot copy reference") done: FUNC_LEAVE_API(ret_value) -} /* end H5Rcreate() */ +} /* end H5Rcopy() */ -/*-------------------------------------------------------------------------- - NAME - H5Rdereference2 - PURPOSE - Opens the HDF5 object referenced. - USAGE - hid_t H5Rdereference2(ref) - hid_t id; IN: Dataset reference object is in or location ID of - object that the dataset is located within. - hid_t oapl_id; IN: Property list of the object being referenced. - H5R_type_t ref_type; IN: Type of reference to create - void *ref; IN: Reference to open. - - RETURNS - Valid ID on success, H5I_INVALID_HID on failure - DESCRIPTION - Given a reference to some object, open that object and return an ID for - that object. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG - Raymond Lu - 13 July 2011 - I added the OAPL_ID parameter for the object being referenced. It only - supports dataset access property list currently. ---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * Function: H5Ropen_object + * + * Purpose: Given a reference to some object, open that object and return an + * ID for that object. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ hid_t -H5Rdereference2(hid_t obj_id, hid_t oapl_id, H5R_type_t ref_type, const void *_ref) +H5Ropen_object(const H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) { - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5I_type_t opened_type; - void *opened_obj = NULL; - H5VL_loc_params_t loc_params; - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void *opened_obj = NULL; /* Opened object */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE4("i", "iiRt*x", obj_id, oapl_id, ref_type, _ref); + H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id); /* Check args */ + if(ref_ptr == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + if(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE + || H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") + if(rapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") if(oapl_id < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") - if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") - if(_ref == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + + /* Retrieve loc_id from reference */ + if(H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) { + /* Attempt to re-open file and pass rapl_id as a fapl_id */ + if((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file") + } + + /* Get object token */ + if(H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") /* Verify access property list and set up collective metadata if appropriate */ - if(H5CX_set_apl(&oapl_id, H5P_CLS_DACC, obj_id, FALSE) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "can't set access property list info") + if(H5CX_set_apl(&oapl_id, H5P_CLS_DACC, loc_id, FALSE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") /* Get the VOL object */ - if(NULL == (vol_obj = H5VL_vol_object(obj_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid file identifier") + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_REF; - loc_params.loc_data.loc_by_ref.ref_type = ref_type; - loc_params.loc_data.loc_by_ref._ref = _ref; - loc_params.loc_data.loc_by_ref.lapl_id = oapl_id; - loc_params.obj_type = H5I_get_type(obj_id); + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = obj_token; + loc_params.obj_type = H5I_get_type(loc_id); - /* Dereference */ + /* Open object by token */ if(NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to dereference object") + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token") + /* Register object */ if((ret_value = H5VL_register(opened_type, opened_obj, vol_obj->connector, TRUE)) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") done: FUNC_LEAVE_API(ret_value) -} /* end H5Rdereference2() */ +} /* end H5Ropen_object() */ -/*-------------------------------------------------------------------------- - NAME - H5Rget_region - PURPOSE - Retrieves a dataspace with the region pointed to selected. - USAGE - hid_t H5Rget_region(id, ref_type, ref) - hid_t id; IN: Dataset reference object is in or location ID of - object that the dataset is located within. - H5R_type_t ref_type; IN: Type of reference to get region of - void *ref; IN: Reference to open. - - RETURNS - Valid ID on success, H5I_INVALID_HID on failure - DESCRIPTION - Given a reference to some object, creates a copy of the dataset pointed - to's dataspace and defines a selection in the copy which is the region - pointed to. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * Function: H5Ropen_region + * + * Purpose: Given a reference to some object, creates a copy of the dataset + * pointed to's dataspace and defines a selection in the copy which is the + * region pointed to. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ hid_t -H5Rget_region(hid_t id, H5R_type_t ref_type, const void *ref) +H5Ropen_region(const H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id) { - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5VL_loc_params_t loc_params; - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void *opened_obj = NULL; /* Opened object */ + hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ + H5S_t *space = NULL; /* Dataspace pointer (copy) */ + hid_t space_id = H5I_INVALID_HID; /* Dataspace ID */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE3("i", "iRt*x", id, ref_type, ref); + H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, oapl_id); /* Check args */ - if(ref_type != H5R_DATASET_REGION) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") - if(ref == NULL) + if(ref_ptr == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + if((H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_DATASET_REGION1) + && (H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_DATASET_REGION2)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") + if(rapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") + if(oapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") + + /* Retrieve loc_id from reference */ + if(H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) { + /* Attempt to re-open file and pass rapl_id as a fapl_id */ + if((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file") + } + + /* Get object token */ + if(H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(id); + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = obj_token; + loc_params.obj_type = H5I_get_type(loc_id); - /* get the file object */ - if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid file identifier") + /* Open object by token */ + if(NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token") + + /* Register object */ + if((opened_obj_id = H5VL_register(opened_type, opened_obj, vol_obj->connector, FALSE)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") + + /* Get VOL object object */ + if(NULL == (opened_obj = H5VL_vol_object(opened_obj_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Get dataspace from object */ + if(H5VL_dataset_get(opened_obj, H5VL_DATASET_GET_SPACE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &space_id) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataspace from dataset") + if(NULL == (space = (struct H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a dataspace") /* Get the dataspace with the correct region selected */ - if(H5VL_object_get(vol_obj, &loc_params, H5VL_REF_GET_REGION, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value, (int)ref_type, ref) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to retrieve dataspace") + if(H5R__get_region((const H5R_ref_priv_t *)ref_ptr, space) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get selection on dataspace") + + /* Simply return space_id */ + ret_value = space_id; + +done: + if((opened_obj_id != H5I_INVALID_HID) && (H5I_dec_ref(opened_obj_id) < 0)) + HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close object") + if(H5I_INVALID_HID == ret_value) /* Cleanup on failure */ + if((space_id != H5I_INVALID_HID) && (H5I_dec_ref(space_id) < 0)) + HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close dataspace") + + FUNC_LEAVE_API(ret_value) +} /* end H5Ropen_region() */ + + +/*------------------------------------------------------------------------- + * Function: H5Ropen_attr + * + * Purpose: Given a reference to some attribute, open that attribute and + * return an ID for that attribute. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5Ropen_attr(const H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id) +{ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + H5I_type_t opened_type; /* Opened object type */ + void *opened_obj = NULL; /* Opened object */ + hid_t opened_obj_id = H5I_INVALID_HID; /* Opened object ID */ + void *opened_attr = NULL; /* Opened attribute */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE3("i", "*Rrii", ref_ptr, rapl_id, aapl_id); + + /* Check args */ + if(ref_ptr == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + if(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_ATTR) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") + if(rapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") + if(aapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") + + /* Retrieve loc_id from reference */ + if(H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) { + /* Attempt to re-open file and pass rapl_id as a fapl_id */ + if((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, H5I_INVALID_HID, "cannot re-open referenced file") + } + + /* Get object token */ + if(H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get object token") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = obj_token; + loc_params.obj_type = H5I_get_type(loc_id); + + /* Open object by token */ + if(NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by token") + + /* Register object */ + if((opened_obj_id = H5VL_register(opened_type, opened_obj, vol_obj->connector, FALSE)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") + + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, FALSE) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_SELF; + loc_params.obj_type = opened_type; + + /* Get VOL object object */ + if(NULL == (opened_obj = H5VL_vol_object(opened_obj_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Open the attribute */ + if(NULL == (opened_attr = H5VL_attr_open(opened_obj, &loc_params, H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr), aapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open attribute: '%s'", H5R_REF_ATTRNAME((const H5R_ref_priv_t *)ref_ptr)) + + /* Register the attribute and get an ID for it */ + if((ret_value = H5VL_register(H5I_ATTR, opened_attr, vol_obj->connector, TRUE)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize attribute handle") done: + if((opened_obj_id != H5I_INVALID_HID) && (H5I_dec_ref(opened_obj_id) < 0)) + HDONE_ERROR(H5E_REFERENCE, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close object") + if(H5I_INVALID_HID == ret_value) /* Cleanup on failure */ + if(opened_attr && H5VL_attr_close(vol_obj, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, H5I_INVALID_HID, "can't close attribute") + FUNC_LEAVE_API(ret_value) -} /* end H5Rget_region() */ +} /* end H5Ropen_attr() */ -/*-------------------------------------------------------------------------- - NAME - H5Rget_obj_type2 - PURPOSE - Retrieves the type of object that an object reference points to - USAGE - herr_t H5Rget_obj_type2(id, ref_type, ref, obj_type) - hid_t id; IN: Dataset reference object is in or location ID of - object that the dataset is located within. - H5R_type_t ref_type; IN: Type of reference to query - void *ref; IN: Reference to query. - H5O_type_t *obj_type; OUT: Type of object reference points to - - RETURNS - Non-negative on success/Negative on failure - DESCRIPTION - Given a reference to some object, this function retrieves the type of - object pointed to. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * Function: H5Rget_obj_type3 + * + * Purpose: Given a reference to some object, this function returns the type + * of object pointed to. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ herr_t -H5Rget_obj_type2(hid_t id, H5R_type_t ref_type, const void *ref, - H5O_type_t *obj_type) +H5Rget_obj_type3(const H5R_ref_t *ref_ptr, hid_t rapl_id, H5O_type_t *obj_type) { - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5VL_loc_params_t loc_params; - herr_t ret_value = SUCCEED; /* Return value */ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE4("e", "iRt*x*Ot", id, ref_type, ref, obj_type); + H5TRACE3("e", "*Rri*Ot", ref_ptr, rapl_id, obj_type); /* Check args */ - if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") - if(ref == NULL) + if(ref_ptr == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") + if(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE + || H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") + if(rapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(id); + /* Retrieve loc_id from reference */ + if(H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) { + /* Attempt to re-open file and pass rapl_id as a fapl_id */ + if((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, FAIL, "cannot re-open referenced file") + } + + /* Get object token */ + if(H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to get object token") - /* Get the file object */ - if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = obj_token; + loc_params.obj_type = H5I_get_type(loc_id); - /* Get the object type */ - if(H5VL_object_get(vol_obj, &loc_params, H5VL_REF_GET_TYPE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, obj_type, (int)ref_type, ref) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to determine object type") + /* Retrieve object's type */ + if(H5VL_object_get(vol_obj, &loc_params, H5VL_OBJECT_GET_TYPE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, obj_type) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve object type") done: FUNC_LEAVE_API(ret_value) -} /* end H5Rget_obj_type2() */ +} /* end H5Rget_obj_type3() */ -/*-------------------------------------------------------------------------- - NAME - H5Rget_name - PURPOSE - Determines a name for the object referenced - USAGE - ssize_t H5Rget_name(loc_id, ref_type, ref, name, size) - hid_t loc_id; IN: Dataset reference object is in or location ID of - object that the dataset is located within. - H5R_type_t ref_type; IN: Type of reference - void *ref; IN: Reference to query. - char *name; OUT: Buffer to place name of object referenced. If NULL - then this call will return the size in bytes of name. - size_t size; IN: Size of name buffer (user needs to include NULL terminator - when passing in the size) - - RETURNS - Non-negative length of the path on success, -1 on failure - DESCRIPTION - Given a reference to some object, determine a path to the object - referenced in the file. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - This may not be the only path to that object. - EXAMPLES - REVISION LOG - M. Scot Breitenfeld - 22 January 2014 - Changed the behavior for the returned value of the function when name is NULL. - If name is NULL then size is ignored and the function returns the size - of the name buffer (not including the NULL terminator), it still returns - negative on failure. ---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * Function: H5Rget_file_name + * + * Purpose: Given a reference to some object, determine a file name of the + * object located into. + * + * Return: Non-negative length of the path on success/Negative on failure + * + *------------------------------------------------------------------------- + */ ssize_t -H5Rget_name(hid_t id, H5R_type_t ref_type, const void *_ref, char *name, - size_t size) +H5Rget_file_name(const H5R_ref_t *ref_ptr, char *buf, size_t size) { - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5VL_loc_params_t loc_params; - ssize_t ret_value = -1; /* Return value */ + hid_t loc_id; /* Reference location ID */ + ssize_t ret_value; /* Return value */ FUNC_ENTER_API((-1)) - H5TRACE5("Zs", "iRt*x*sz", id, ref_type, _ref, name, size); + H5TRACE3("Zs", "*Rr*sz", ref_ptr, buf, size); /* Check args */ - if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) + if(ref_ptr == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer") + if(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE + || H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type") - if(_ref == NULL) + + /* Get name */ + if(H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) { + /* Un-opened external references do not have loc_id set but hold a + * copy of the filename */ + if((ret_value = H5R__get_file_name((const H5R_ref_priv_t *)ref_ptr, buf, size)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to retrieve file name") + } else { + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + + /* Retrieve VOL file object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid location identifier") + + if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, H5I_FILE, size, buf, &ret_value) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to get file name") + } + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rget_file_name() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rget_obj_name + * + * Purpose: Given a reference to some object, determine a path to the object + * referenced in the file. + * + * Return: Non-negative length of the path on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +ssize_t +H5Rget_obj_name(const H5R_ref_t *ref_ptr, hid_t rapl_id, char *buf, size_t size) +{ + hid_t loc_id; /* Reference location ID */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + H5VL_token_t obj_token = {0}; /* Object token */ + ssize_t ret_value; /* Return value */ + + FUNC_ENTER_API((-1)) + H5TRACE4("Zs", "*Rri*sz", ref_ptr, rapl_id, buf, size); + + /* Check args */ + if(ref_ptr == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer") + if(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) <= H5R_BADTYPE + || H5R__get_type((const H5R_ref_priv_t *)ref_ptr) >= H5R_MAXTYPE) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type") + if(rapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(id); + /* Retrieve loc_id from reference */ + if(H5I_INVALID_HID == (loc_id = H5R__get_loc_id((const H5R_ref_priv_t *)ref_ptr))) { + /* Attempt to re-open file and pass rapl_id as a fapl_id */ + if((loc_id = H5R__reopen_file((H5R_ref_priv_t *)ref_ptr, rapl_id)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENFILE, (-1), "cannot re-open referenced file") + } - /* Get the file object */ - if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid file identifier") + /* Get object token */ + if((ret_value = H5R__get_obj_token((const H5R_ref_priv_t *)ref_ptr, &obj_token, NULL)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to get object token") - /* Get name */ - if(H5VL_object_get(vol_obj, &loc_params, H5VL_REF_GET_NAME, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value, name, size, (int)ref_type, _ref) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to determine object path") + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid location identifier") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = obj_token; + loc_params.obj_type = H5I_get_type(loc_id); + + /* Retrieve object's name */ + if(H5VL_object_get(vol_obj, &loc_params, H5VL_OBJECT_GET_NAME, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value, buf, size) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, (-1), "can't retrieve object name") done: FUNC_LEAVE_API(ret_value) -} /* end H5Rget_name() */ +} /* end H5Rget_obj_name() */ + +/*------------------------------------------------------------------------- + * Function: H5Rget_attr_name + * + * Purpose: Given a reference to some attribute, determine its name. + * + * Return: Non-negative length of the path on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +ssize_t +H5Rget_attr_name(const H5R_ref_t *ref_ptr, char *buf, size_t size) +{ + ssize_t ret_value; /* Return value */ + + FUNC_ENTER_API((-1)) + H5TRACE3("Zs", "*Rr*sz", ref_ptr, buf, size); + + /* Check args */ + if(ref_ptr == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer") + if(H5R__get_type((const H5R_ref_priv_t *)ref_ptr) != H5R_ATTR) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type") + + /* Get attribute name */ + if((ret_value = H5R__get_attr_name((const H5R_ref_priv_t *)ref_ptr, buf, size)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "unable to determine attribute name") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rget_attr_name() */ diff --git a/src/H5Rdeprec.c b/src/H5Rdeprec.c index ab8d3b4..4743c77 100644 --- a/src/H5Rdeprec.c +++ b/src/H5Rdeprec.c @@ -37,14 +37,15 @@ #include "H5Ppublic.h" /* Property lists */ /* Private headers needed by this file */ -#include "H5private.h" /* Generic Functions */ -#include "H5ACprivate.h" /* Metadata cache */ +#include "H5private.h" /* Generic Functions */ +#include "H5ACprivate.h" /* Metadata cache */ #include "H5CXprivate.h" /* API Contexts */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5Gprivate.h" /* Groups */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Gprivate.h" /* Groups */ #include "H5Iprivate.h" /* IDs */ -#include "H5Oprivate.h" /* Object headers */ +#include "H5Oprivate.h" /* Object headers */ #include "H5Rpkg.h" /* References */ +#include "H5Sprivate.h" /* Dataspaces */ /****************/ @@ -81,53 +82,61 @@ /* Local Variables */ /*******************/ - #ifndef H5_NO_DEPRECATED_SYMBOLS - + /*------------------------------------------------------------------------- * Function: H5Rget_obj_type1 * - * Purpose: Retrieves the type of the object that an object points to. + * Purpose: Retrieves the type of the object that a reference points to. * - * Parameters: - * id IN: Dataset reference object is in or location ID of - * object that the dataset is located within - * ref_type IN: Type of reference to query - * ref IN: Reference to query - * - * Return: Success: An object type (as defined in H5Gpublic.h) - * Failure: H5G_UNKNOWN + * Return: Object type (as defined in H5Gpublic.h) on success + * H5G_UNKNOWN on failure * *------------------------------------------------------------------------- */ H5G_obj_t H5Rget_obj_type1(hid_t id, H5R_type_t ref_type, const void *ref) { - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5VL_loc_params_t loc_params; - H5O_type_t obj_type; /* Object type */ - H5G_obj_t ret_value; /* Return value */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + haddr_t obj_addr; /* Object address */ + H5O_type_t obj_type; /* Object type */ + const unsigned char *buf = (const unsigned char *)ref; /* Reference buffer */ + H5G_obj_t ret_value; /* Return value */ FUNC_ENTER_API(H5G_UNKNOWN) H5TRACE3("Go", "iRt*x", id, ref_type, ref); /* Check args */ - if (ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5G_UNKNOWN, "invalid reference type") - if (ref == NULL) + if(buf == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5G_UNKNOWN, "invalid reference pointer") + if(ref_type != H5R_OBJECT1 && ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5G_UNKNOWN, "invalid reference type") - /* Set location parameters */ - loc_params.type = H5VL_OBJECT_BY_SELF; - loc_params.obj_type = H5I_get_type(id); + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "invalid location identifier") - /* Get the vol object */ - if (NULL == (vol_obj = H5VL_vol_object(id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "invalid file identifier") + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ - /* Get the object information */ - if(H5VL_object_get(vol_obj, &loc_params, H5VL_REF_GET_TYPE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &obj_type, (int)ref_type, ref) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5G_UNKNOWN, "unable to determine object type") + /* Get object type */ + if((vol_obj_type = H5I_get_type(id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "invalid location identifier") + + /* Get object address */ + if(H5R__decode_addr_compat(id, vol_obj_type, ref_type, buf, &obj_addr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, H5G_UNKNOWN, "unable to get object address") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = &obj_addr; + loc_params.obj_type = vol_obj_type; + + /* Retrieve object's type */ + if(H5VL_object_get(vol_obj, &loc_params, H5VL_OBJECT_GET_TYPE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &obj_type) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, H5G_UNKNOWN, "can't retrieve object type") /* Set return value */ ret_value = H5G_map_obj_type(obj_type); @@ -140,54 +149,61 @@ done: /*------------------------------------------------------------------------- * Function: H5Rdereference1 * - * Purpose: Opens the HDF5 object referenced. - * - * Parameters: - * id IN: Dataset reference object is in or location ID of - * object that the dataset is located within - * ref_type IN: Type of reference to create - * ref IN: Reference to open + * Purpose: Given a reference to some object, open that object and return an + * ID for that object. * - * Return: Success: Valid HDF5 ID - * Failure: H5I_INVALID_HID + * Return: Valid ID on success/Negative on failure * *------------------------------------------------------------------------- */ hid_t -H5Rdereference1(hid_t obj_id, H5R_type_t ref_type, const void *_ref) +H5Rdereference1(hid_t obj_id, H5R_type_t ref_type, const void *ref) { - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5I_type_t opened_type; - void *opened_obj = NULL; - H5VL_loc_params_t loc_params; - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + haddr_t obj_addr; /* Object address */ + H5I_type_t opened_type; /* Opened object type */ + void *opened_obj = NULL; /* Opened object */ + const unsigned char *buf = (const unsigned char *)ref; /* Reference buffer */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) - H5TRACE3("i", "iRt*x", obj_id, ref_type, _ref); + H5TRACE3("i", "iRt*x", obj_id, ref_type, ref); /* Check args */ - if (ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") - if (_ref == NULL) + if(buf == NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + if(ref_type != H5R_OBJECT1 && ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") /* Get the VOL object */ - if (NULL == (vol_obj = H5VL_vol_object(obj_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid file identifier") + if(NULL == (vol_obj = H5VL_vol_object(obj_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ - loc_params.type = H5VL_OBJECT_BY_REF; - loc_params.loc_data.loc_by_ref.ref_type = ref_type; - loc_params.loc_data.loc_by_ref._ref = _ref; - loc_params.loc_data.loc_by_ref.lapl_id = H5P_DATASET_ACCESS_DEFAULT; - loc_params.obj_type = H5I_get_type(obj_id); + /* Get object type */ + if((vol_obj_type = H5I_get_type(obj_id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Get object address */ + if(H5R__decode_addr_compat(obj_id, vol_obj_type, ref_type, buf, &obj_addr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, H5I_INVALID_HID, "unable to get object address") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = &obj_addr; + loc_params.obj_type = vol_obj_type; /* Dereference */ if(NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to dereference object") + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by address") - /* Get an atom for the object */ + /* Register object */ if((ret_value = H5VL_register(opened_type, opened_obj, vol_obj->connector, TRUE)) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize object handle") + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") done: FUNC_LEAVE_API(ret_value) @@ -195,3 +211,363 @@ done: #endif /* H5_NO_DEPRECATED_SYMBOLS */ + +/*------------------------------------------------------------------------- + * Function: H5Rcreate + * + * Purpose: Creates a particular type of reference specified with REF_TYPE, + * in the space pointed to by REF. The LOC_ID and NAME are used to locate the + * object pointed to and the SPACE_ID is used to choose the region pointed to + * (for Dataset Region references). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, + hid_t space_id) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + haddr_t obj_addr; /* Object address */ + hid_t file_id = H5I_INVALID_HID; /* File ID for region reference */ + unsigned char *buf = (unsigned char *)ref; /* Return reference pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE5("e", "*xi*sRti", ref, loc_id, name, ref_type, space_id); + + /* Check args */ + if(buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") + if(!name || !*name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") + if(ref_type != H5R_OBJECT1 && ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") + + /* Set up collective metadata if appropriate */ + if(H5CX_set_loc(loc_id) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "can't set access property list info") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ + + /* Get object type */ + if((vol_obj_type = H5I_get_type(loc_id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_NAME; + loc_params.loc_data.loc_by_name.name = name; + loc_params.obj_type = vol_obj_type; + + /* Get the object address */ + if(H5VL_object_specific(vol_obj, &loc_params, H5VL_OBJECT_LOOKUP, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &obj_addr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve object address") + + /* Create reference */ + if(ref_type == H5R_OBJECT1) { + size_t buf_size = H5R_OBJ_REF_BUF_SIZE; + + if((ret_value = H5R__encode_addr_obj_compat(obj_addr, buf, &buf_size)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "unable to encode object reference") + } else { + void *vol_obj_file = NULL; + H5F_t *f = NULL; + H5S_t *space = NULL; /* Pointer to dataspace containing region */ + size_t buf_size = H5R_DSET_REG_REF_BUF_SIZE; + + /* Get the file for the object */ + if((file_id = H5F_get_file_id(loc_id, vol_obj_type, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Retrieve VOL object */ + if(NULL == (vol_obj_file = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Retrieve file from VOL object */ + if(NULL == (f = (H5F_t *)H5VL_object_data(vol_obj_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + + /* Retrieve space */ + if(space_id == H5I_BADID) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reference region dataspace id must be valid") + if(NULL == (space = (struct H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + + /* Encode dataset region */ + if((ret_value = H5R__encode_addr_region_compat(f, obj_addr, space, buf, &buf_size)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "unable to encode region reference") + } + +done: + if(file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file") + FUNC_LEAVE_API(ret_value) +} /* end H5Rcreate() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rget_obj_type2 + * + * Purpose: Given a reference to some object, this function returns the type + * of object pointed to. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5Rget_obj_type2(hid_t id, H5R_type_t ref_type, const void *ref, + H5O_type_t *obj_type) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + haddr_t obj_addr; /* Object address */ + const unsigned char *buf = (const unsigned char *)ref; /* Reference pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "iRt*x*Ot", id, ref_type, ref, obj_type); + + /* Check args */ + if(buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer") + if(ref_type != H5R_OBJECT1 && ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ + + /* Get object type */ + if((vol_obj_type = H5I_get_type(id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get object address */ + if(H5R__decode_addr_compat(id, vol_obj_type, ref_type, buf, &obj_addr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "unable to get object address") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = &obj_addr; + loc_params.obj_type = vol_obj_type; + + /* Retrieve object's type */ + if(H5VL_object_get(vol_obj, &loc_params, H5VL_OBJECT_GET_TYPE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, obj_type) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve object type") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rget_obj_type2() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rdereference2 + * + * Purpose: Given a reference to some object, open that object and return an + * ID for that object. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5Rdereference2(hid_t obj_id, hid_t oapl_id, H5R_type_t ref_type, + const void *ref) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + haddr_t obj_addr; /* Object address */ + H5I_type_t opened_type; /* Opened object type */ + void *opened_obj = NULL; /* Opened object */ + const unsigned char *buf = (const unsigned char *)ref; /* Reference pointer */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE4("i", "iiRt*x", obj_id, oapl_id, ref_type, ref); + + /* Check args */ + if(oapl_id < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a property list") + if(buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + if(ref_type != H5R_OBJECT1 && ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") + + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&oapl_id, H5P_CLS_DACC, obj_id, FALSE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(obj_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid file identifier") + + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ + + /* Get object type */ + if((vol_obj_type = H5I_get_type(obj_id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Get object address */ + if(H5R__decode_addr_compat(obj_id, vol_obj_type, ref_type, buf, &obj_addr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, H5I_INVALID_HID, "unable to get object address") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = &obj_addr; + loc_params.obj_type = vol_obj_type; + + /* Open object by address */ + if(NULL == (opened_obj = H5VL_object_open(vol_obj, &loc_params, &opened_type, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, H5I_INVALID_HID, "unable to open object by address") + + /* Register object */ + if((ret_value = H5VL_register(opened_type, opened_obj, vol_obj->connector, TRUE)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rdereference2() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rget_region + * + * Purpose: Given a reference to some object, creates a copy of the dataset + * pointed to's dataspace and defines a selection in the copy which is the + * region pointed to. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5Rget_region(hid_t id, H5R_type_t ref_type, const void *ref) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + void *vol_obj_file = NULL; /* VOL file */ + H5F_t *f = NULL; /* Native file */ + size_t buf_size = H5R_DSET_REG_REF_BUF_SIZE; /* Reference buffer size */ + H5S_t *space = NULL; /* Dataspace object */ + hid_t file_id = H5I_INVALID_HID; /* File ID for region reference */ + const unsigned char *buf = (const unsigned char *)ref; /* Reference pointer */ + hid_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5I_INVALID_HID) + H5TRACE3("i", "iRt*x", id, ref_type, ref); + + /* Check args */ + if(buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference pointer") + if(ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid reference type") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid file identifier") + + /* Get object type */ + if((vol_obj_type = H5I_get_type(id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ + + /* Get the file for the object */ + if((file_id = H5F_get_file_id(id, vol_obj_type, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a file or file object") + + /* Retrieve VOL object */ + if(NULL == (vol_obj_file = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") + + /* Retrieve file from VOL object */ + if(NULL == (f = (H5F_t *)H5VL_object_data(vol_obj_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid VOL object") + + /* Get the dataspace with the correct region selected */ + if(H5R__decode_addr_region_compat(f, buf, &buf_size, NULL, &space) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataspace") + + /* Atomize */ + if((ret_value = H5I_register(H5I_DATASPACE, space, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register dataspace atom") + +done: + if(file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, H5I_INVALID_HID, "unable to decrement refcount on file") + FUNC_LEAVE_API(ret_value) +} /* end H5Rget_region1() */ + + +/*------------------------------------------------------------------------- + * Function: H5Rget_name + * + * Purpose: Given a reference to some object, determine a path to the object + * referenced in the file. + * + * Return: Non-negative length of the path on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +ssize_t +H5Rget_name(hid_t id, H5R_type_t ref_type, const void *ref, char *name, + size_t size) +{ + H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ + H5I_type_t vol_obj_type = H5I_BADID;/* Object type of loc_id */ + H5VL_loc_params_t loc_params; /* Location parameters */ + haddr_t obj_addr; /* Object address */ + const unsigned char *buf = (const unsigned char *)ref; /* Reference pointer */ + ssize_t ret_value = -1; /* Return value */ + + FUNC_ENTER_API((-1)) + H5TRACE5("Zs", "iRt*x*sz", id, ref_type, ref, name, size); + + /* Check args */ + if(buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference pointer") + if(ref_type != H5R_OBJECT1 && ref_type != H5R_DATASET_REGION1) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, (-1), "invalid reference type") + + /* Get the VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid file identifier") + + /* Currently restrict API usage to native VOL + * TODO check for terminal connector or use capability flag */ + + /* Get object type */ + if((vol_obj_type = H5I_get_type(id)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, (-1), "invalid location identifier") + + /* Get object address */ + if(H5R__decode_addr_compat(id, vol_obj_type, ref_type, buf, &obj_addr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, (-1), "unable to get object address") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_TOKEN; + loc_params.loc_data.loc_by_token.token = &obj_addr; + loc_params.obj_type = vol_obj_type; + + /* Retrieve object's name */ + if(H5VL_object_get(vol_obj, &loc_params, H5VL_OBJECT_GET_NAME, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value, name, size) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, (-1), "can't retrieve object name") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Rget_name() */ diff --git a/src/H5Rint.c b/src/H5Rint.c index 07efae2..e33eecb 100644 --- a/src/H5Rint.c +++ b/src/H5Rint.c @@ -35,11 +35,73 @@ #include "H5Sprivate.h" /* Dataspaces */ #include "H5Tprivate.h" /* Datatypes */ - /****************/ /* Local Macros */ /****************/ +#define H5R_MAX_STRING_LEN (1 << 16) /* Max encoded string length */ + +/* Encode macro */ +#define H5R_ENCODE(func, val, buf, buf_size, actual, m) do {\ + size_t __nalloc = buf_size; \ + if(func(val, buf, &__nalloc) < 0) \ + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, m) \ + if(buf && buf_size >= __nalloc) { \ + buf += __nalloc; \ + buf_size -= __nalloc; \ + } \ + actual += __nalloc; \ +} while(0) + +#define H5R_ENCODE_VAR(func, var, size, buf, buf_size, actual, m) do { \ + size_t __nalloc = buf_size; \ + if(func(var, size, buf, &__nalloc) < 0) \ + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, m) \ + if(buf && buf_size >= __nalloc) { \ + p += __nalloc; \ + buf_size -= __nalloc; \ + } \ + actual += __nalloc; \ +} while(0) + +/* Decode macro */ +#define H5R_DECODE(func, val, buf, buf_size, actual, m) do {\ + size_t __nbytes = buf_size; \ + if(func(buf, &__nbytes, val) < 0) \ + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, m) \ + buf += __nbytes; \ + buf_size -= __nbytes; \ + actual += __nbytes; \ +} while(0) + +#define H5R_DECODE_VAR(func, var, size, buf, buf_size, actual, m) do { \ + size_t __nbytes = buf_size; \ + if(func(buf, &__nbytes, var, size) < 0) \ + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, m) \ + p += __nbytes; \ + buf_size -= __nbytes; \ + actual += __nbytes; \ +} while(0) + +/* Debug */ +//#define H5R_DEBUG +#ifdef H5R_DEBUG +#define H5R_LOG_DEBUG(...) do { \ + HDfprintf(stdout, " # %s(): ", __func__); \ + HDfprintf(stdout, __VA_ARGS__); \ + HDfprintf(stdout, "\n"); \ + HDfflush(stdout); \ + } while (0) +static const char * +H5R__print_token(const H5VL_token_t token) { + static char string[64]; + HDsnprintf(string, 64, "%zu", *(haddr_t *)token); + return string; +} +#else +#define H5R_LOG_DEBUG(...) do { } while (0) +#endif + /******************/ /* Local Typedefs */ /******************/ @@ -48,6 +110,13 @@ /* Local Prototypes */ /********************/ +static herr_t H5R__encode_obj_token(const H5VL_token_t *obj_token, size_t token_size, unsigned char *buf, size_t *nalloc); +static herr_t H5R__decode_obj_token(const unsigned char *buf, size_t *nbytes, H5VL_token_t *obj_token, uint8_t *token_size); +static herr_t H5R__encode_region(H5S_t *space, unsigned char *buf, size_t *nalloc); +static herr_t H5R__decode_region(const unsigned char *buf, size_t *nbytes, H5S_t **space_ptr); +static herr_t H5R__encode_string(const char *string, unsigned char *buf, size_t *nalloc); +static herr_t H5R__decode_string(const unsigned char *buf, size_t *nbytes, char **string_ptr); + /*********************/ /* Package Variables */ /*********************/ @@ -82,14 +151,15 @@ DESCRIPTION herr_t H5R__init_package(void) { - herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT_NOERR /* Mark "top" of interface as initialized */ H5R_top_package_initialize_s = TRUE; - FUNC_LEAVE_NOAPI(ret_value) + /* Sanity check, if assert fails, H5R_REF_BUF_SIZE must be increased */ + HDcompile_assert(sizeof(H5R_ref_priv_t) <= H5R_REF_BUF_SIZE); + + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5R__init_package() */ @@ -167,571 +237,1473 @@ H5R_term_package(void) } /* end H5R_term_package() */ -/*-------------------------------------------------------------------------- - NAME - H5R__create - PURPOSE - Creates a particular kind of reference for the user - USAGE - herr_t H5R__create(ref, loc, name, ref_type, space) - void *ref; OUT: Reference created - H5G_loc_t *loc; IN: File location used to locate object pointed to - const char *name; IN: Name of object at location LOC_ID of object - pointed to - H5R_type_t ref_type; IN: Type of reference to create - H5S_t *space; IN: Dataspace ID with selection, used for Dataset - Region references. +/*------------------------------------------------------------------------- + * Function: H5R__create_object + * + * Purpose: Creates an object reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__create_object(const H5VL_token_t *obj_token, size_t token_size, + H5R_ref_priv_t *ref) +{ + size_t encode_size; + herr_t ret_value = SUCCEED; /* Return value */ - RETURNS - Non-negative on success/Negative on failure - DESCRIPTION - Creates a particular type of reference specified with REF_TYPE, in the - space pointed to by REF. The LOC_ID and NAME are used to locate the object - pointed to and the SPACE_ID is used to choose the region pointed to (for - Dataset Region references). - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ + FUNC_ENTER_PACKAGE + + HDassert(ref); + + /* Create new reference */ + H5MM_memcpy(ref->ref.obj.token, obj_token, token_size); + ref->ref.obj.filename = NULL; + ref->loc_id = H5I_INVALID_HID; + ref->type = (uint8_t)H5R_OBJECT2; + ref->token_size = (uint8_t)token_size; + + /* Cache encoding size (assume no external reference) */ + if(H5R__encode(NULL, ref, NULL, &encode_size, 0) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "unable to determine encoding size") + ref->encode_size = (uint32_t)encode_size; + + H5R_LOG_DEBUG("Created object reference, %d, filename=%s, obj_addr=%s, encode size=%u", + (int)sizeof(H5R_ref_priv_t), ref->ref.obj.filename, H5R__print_token(ref->ref.obj.token), + ref->encode_size); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__create_object() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__create_region + * + * Purpose: Creates a region reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ herr_t -H5R__create(void *_ref, H5G_loc_t *loc, const char *name, H5R_type_t ref_type, H5S_t *space) +H5R__create_region(const H5VL_token_t *obj_token, size_t token_size, + H5S_t *space, H5R_ref_priv_t *ref) { - H5G_loc_t obj_loc; /* Group hier. location of object */ - H5G_name_t path; /* Object group hier. path */ - H5O_loc_t oloc; /* Object object location */ - hbool_t obj_found = FALSE; /* Object location found */ - herr_t ret_value = SUCCEED; /* Return value */ + size_t encode_size; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - HDassert(_ref); - HDassert(loc); - HDassert(name); - HDassert(ref_type > H5R_BADTYPE && ref_type < H5R_MAXTYPE); + HDassert(space); + HDassert(ref); - /* Set up object location to fill in */ - obj_loc.oloc = &oloc; - obj_loc.path = &path; - H5G_loc_reset(&obj_loc); + /* Create new reference */ + H5MM_memcpy(ref->ref.obj.token, obj_token, token_size); + ref->ref.obj.filename = NULL; + if(NULL == (ref->ref.reg.space = H5S_copy(space, FALSE, TRUE))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "unable to copy dataspace") - /* Set the FAPL for the API context */ - H5CX_set_libver_bounds(loc->oloc->file); + ref->loc_id = H5I_INVALID_HID; + ref->type = (uint8_t)H5R_DATASET_REGION2; + ref->token_size = (uint8_t)token_size; - /* Find the object */ - if(H5G_loc_find(loc, name, &obj_loc) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_NOTFOUND, FAIL, "object not found") - obj_found = TRUE; + /* Cache encoding size (assume no external reference) */ + if(H5R__encode(NULL, ref, NULL, &encode_size, 0) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "unable to determine encoding size") + ref->encode_size = (uint32_t)encode_size; - switch (ref_type) { - case H5R_OBJECT: - { - hobj_ref_t *ref = (hobj_ref_t *)_ref; /* Get pointer to correct type of reference struct */ + H5R_LOG_DEBUG("Created region reference, %d, filename=%s, obj_addr=%s, encode size=%u", + (int)sizeof(H5R_ref_priv_t), ref->ref.obj.filename, H5R__print_token(ref->ref.obj.token), + ref->encode_size); - *ref = obj_loc.oloc->addr; - break; +done: + if(ret_value < 0) { + if(ref->ref.reg.space) { + H5S_close(ref->ref.reg.space); + ref->ref.reg.space = NULL; } + } + FUNC_LEAVE_NOAPI(ret_value) +} /* H5R__create_region */ - case H5R_DATASET_REGION: - { - H5HG_t hobjid; /* Heap object ID */ - hdset_reg_ref_t *ref = (hdset_reg_ref_t *)_ref; /* Get pointer to correct type of reference struct */ - hssize_t buf_size; /* Size of buffer needed to serialize selection */ - uint8_t *p; /* Pointer to OID to store */ - uint8_t *buf; /* Buffer to store serialized selection in */ - unsigned heapid_found; /* Flag for non-zero heap ID found */ - unsigned u; /* local index */ - - /* Set up information for dataset region */ - - /* Return any previous heap block to the free list if we are - * garbage collecting - */ - if (H5F_GC_REF(loc->oloc->file)) { - /* Check for an existing heap ID in the reference */ - for (u = 0, heapid_found = 0, p = (uint8_t *)ref; u < H5R_DSET_REG_REF_BUF_SIZE; u++) - if (p[u] != 0) { - heapid_found = 1; - break; - } - - if (heapid_found != 0) { - /* Return heap block to free list */ - } - } - - /* Zero the heap ID out, may leak heap space if user is re-using - * reference and doesn't have garbage collection turned on - */ - HDmemset(ref, 0, H5R_DSET_REG_REF_BUF_SIZE); - - /* Get the amount of space required to serialize the selection */ - if ((buf_size = H5S_SELECT_SERIAL_SIZE(space)) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "Invalid amount of space for serializing selection") - - /* Increase buffer size to allow for the dataset OID */ - buf_size += (hssize_t)sizeof(haddr_t); - - /* Allocate the space to store the serialized information */ - H5_CHECK_OVERFLOW(buf_size, hssize_t, size_t); - if (NULL == (buf = (uint8_t *)H5MM_malloc((size_t)buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - - /* Serialize information for dataset OID into heap buffer */ - p = (uint8_t *)buf; - H5F_addr_encode(loc->oloc->file, &p, obj_loc.oloc->addr); - - /* Serialize the selection into heap buffer */ - if (H5S_SELECT_SERIALIZE(space, &p) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "Unable to serialize selection") - - /* Save the serialized buffer for later */ - H5_CHECK_OVERFLOW(buf_size, hssize_t, size_t); - if(H5HG_insert(loc->oloc->file, (size_t)buf_size, buf, &hobjid) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_WRITEERROR, FAIL, "Unable to serialize selection") - - /* Serialize the heap ID and index for storage in the file */ - p = (uint8_t *)ref; - H5F_addr_encode(loc->oloc->file, &p, hobjid.addr); - UINT32ENCODE(p, hobjid.idx); - - /* Free the buffer we serialized data in */ - H5MM_xfree(buf); - break; - } /* end case H5R_DATASET_REGION */ + +/*------------------------------------------------------------------------- + * Function: H5R__create_attr + * + * Purpose: Creates an attribute reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__create_attr(const H5VL_token_t *obj_token, size_t token_size, + const char *attr_name, H5R_ref_priv_t *ref) +{ + size_t encode_size; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + HDassert(attr_name); + HDassert(ref); + + /* Make sure that attribute name is not longer than supported encode size */ + if(HDstrlen(attr_name) > H5R_MAX_STRING_LEN) + HGOTO_ERROR(H5E_REFERENCE, H5E_ARGS, FAIL, "attribute name too long (%d > %d)", (int)HDstrlen(attr_name), H5R_MAX_STRING_LEN) + + /* Create new reference */ + H5MM_memcpy(ref->ref.obj.token, obj_token, token_size); + ref->ref.obj.filename = NULL; + if(NULL == (ref->ref.attr.name = HDstrdup(attr_name))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "Cannot copy attribute name") + + ref->loc_id = H5I_INVALID_HID; + ref->type = (uint8_t)H5R_ATTR; + ref->token_size = (uint8_t)token_size; + + /* Cache encoding size (assume no external reference) */ + if(H5R__encode(NULL, ref, NULL, &encode_size, 0) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "unable to determine encoding size") + ref->encode_size = (uint32_t)encode_size; + + H5R_LOG_DEBUG("Created attribute reference, %d, filename=%s, obj_addr=%s, attr name=%s, encode size=%u", + (int)sizeof(H5R_ref_priv_t), ref->ref.obj.filename, H5R__print_token(ref->ref.obj.token), + ref->ref.attr.name, ref->encode_size); +done: + if(ret_value < 0) + ref->ref.attr.name = H5MM_xfree(ref->ref.attr.name); + FUNC_LEAVE_NOAPI(ret_value) +} /* H5R__create_attr */ + + +/*------------------------------------------------------------------------- + * Function: H5R__destroy + * + * Purpose: Destroy reference. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__destroy(H5R_ref_priv_t *ref) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + HDassert(ref != NULL); + + ref->ref.obj.filename = H5MM_xfree(ref->ref.obj.filename); + + switch(ref->type) { + case H5R_OBJECT2: + break; + case H5R_DATASET_REGION2: + if(H5S_close(ref->ref.reg.space) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTFREE, FAIL, "Cannot close dataspace") + ref->ref.reg.space = NULL; + break; + case H5R_ATTR: + ref->ref.attr.name = H5MM_xfree(ref->ref.attr.name); + break; + case H5R_OBJECT1: + case H5R_DATASET_REGION1: case H5R_BADTYPE: case H5R_MAXTYPE: + HDassert("invalid reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (invalid reference type)") default: HDassert("unknown reference type" && 0); HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") } /* end switch */ -done: - if (obj_found) - H5G_loc_free(&obj_loc); + /* Decrement refcount of attached loc_id */ + if((ref->loc_id != H5I_INVALID_HID) && (H5I_dec_ref(ref->loc_id) < 0)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "decrementing location ID failed") +done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5R__create() */ +} /* end H5R__destroy() */ -/*-------------------------------------------------------------------------- - NAME - H5R__dereference - PURPOSE - Opens the HDF5 object referenced. - USAGE - hid_t H5R__dereference(ref, oapl_id, ref_type, ref) - H5F_t *file; IN: File the object being dereferenced is within - hid_t oapl_id; IN: Object access property list ID - H5R_type_t ref_type; IN: Type of reference - void *ref; IN: Reference to open. +/*------------------------------------------------------------------------- + * Function: H5R__set_loc_id + * + * Purpose: Attach location ID to reference and increment location refcount. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__set_loc_id(H5R_ref_priv_t *ref, hid_t id, hbool_t inc_ref) +{ + herr_t ret_value = SUCCEED; /* Return value */ - RETURNS - Valid ID on success, Negative on failure - DESCRIPTION - Given a reference to some object, open that object and return an ID for - that object. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - Currently only set up to work with references to datasets - EXAMPLES - REVISION LOG - Raymond Lu - 13 July 2011 - I added the OAPL_ID parameter for the object being referenced. It only - supports dataset access property list currently. - - M. Scot Breitenfeld - 3 March 2015 - Added a check for undefined reference pointer. ---------------------------------------------------------------------------*/ + FUNC_ENTER_PACKAGE + + HDassert(ref != NULL); + HDassert(id != H5I_INVALID_HID); + + /* If a location ID was previously assigned, decrement refcount and assign new one */ + if((ref->loc_id != H5I_INVALID_HID) && (H5I_dec_ref(ref->loc_id) < 0)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "decrementing location ID failed") + ref->loc_id = id; + + /* Prevent location ID from being freed until reference is destroyed */ + if(inc_ref && H5I_inc_ref(ref->loc_id, FALSE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINC, FAIL, "incrementing location ID failed") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__set_loc_id() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__get_loc_id + * + * Purpose: Retrieve location ID attached to existing reference. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ hid_t -H5R__dereference(H5F_t *file, hid_t oapl_id, H5R_type_t ref_type, const void *_ref) +H5R__get_loc_id(const H5R_ref_priv_t *ref) { - H5O_loc_t oloc; /* Object location */ - H5G_name_t path; /* Path of object */ - H5G_loc_t loc; /* Group location */ - unsigned rc; /* Reference count of object */ - H5O_type_t obj_type; /* Type of object */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ + FUNC_ENTER_PACKAGE_NOERR + + HDassert(ref != NULL); + + ret_value = ref->loc_id; + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__get_loc_id() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__reopen_file + * + * Purpose: Re-open referenced file using file access property list. + * + * Return: Valid ID on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +hid_t +H5R__reopen_file(H5R_ref_priv_t *ref, hid_t fapl_id) +{ + void *new_file = NULL; + H5VL_connector_prop_t connector_prop; + unsigned flags = H5F_ACC_RDWR; /* Must open file read-write to allow for object modifications */ + H5P_genplist_t *plist; + hid_t ret_value = H5I_INVALID_HID; + FUNC_ENTER_PACKAGE - HDassert(_ref); - HDassert(ref_type > H5R_BADTYPE && ref_type < H5R_MAXTYPE); - HDassert(file); + /* TODO add search path */ - /* Initialize the object location */ - H5O_loc_reset(&oloc); - oloc.file = file; + /* Verify access property list and set up collective metadata if appropriate */ + if(H5CX_set_apl(&fapl_id, H5P_CLS_FACC, H5I_INVALID_HID, TRUE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - switch (ref_type) { - case H5R_OBJECT: - { - oloc.addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ - if (!H5F_addr_defined(oloc.addr) || oloc.addr == 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "Undefined reference pointer") - break; - } + /* Get the VOL info from the fapl */ + if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "not a file access property list") + if(H5P_peek(plist, H5F_ACS_VOL_CONN_NAME, &connector_prop) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, H5I_INVALID_HID, "can't get VOL connector info") - case H5R_DATASET_REGION: - { - H5HG_t hobjid; /* Heap object ID */ - uint8_t *buf; /* Buffer to store serialized selection in */ - const uint8_t *p; /* Pointer to OID to store */ + /* Stash a copy of the "top-level" connector property, before any pass-through + * connectors modify or unwrap it. + */ + if(H5CX_set_vol_connector_prop(&connector_prop) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTSET, H5I_INVALID_HID, "can't set VOL connector info in API context") - /* Get the heap ID for the dataset region */ - p = (const uint8_t *)_ref; - H5F_addr_decode(oloc.file, &p, &(hobjid.addr)); - UINT32DECODE(p, hobjid.idx); + /* Open the file */ + if(NULL == (new_file = H5VL_file_open(&connector_prop, H5R_REF_FILENAME(ref), flags, fapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, H5I_INVALID_HID, "unable to open file") - if (!H5F_addr_defined(hobjid.addr) || hobjid.addr == 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "Undefined reference pointer") + /* Get an ID for the file */ + if((ret_value = H5VL_register_using_vol_id(H5I_FILE, new_file, connector_prop.connector_id, TRUE)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize file handle") - /* Get the dataset region from the heap (allocate inside routine) */ - if(NULL == (buf = (uint8_t *)H5HG_read(oloc.file, &hobjid, NULL, NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, H5I_INVALID_HID, "Unable to read dataset region information") + /* Attach loc_id to reference */ + if(H5R__set_loc_id((H5R_ref_priv_t *)ref, ret_value, FALSE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, H5I_INVALID_HID, "unable to attach location id to reference") - /* Get the object oid for the dataset */ - p = buf; - H5F_addr_decode(oloc.file, &p, &(oloc.addr)); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__reopen_file() */ - /* Free the buffer allocated in H5HG_read() */ - H5MM_xfree(buf); - break; - } /* end case H5R_DATASET_REGION */ + +/*------------------------------------------------------------------------- + * Function: H5R__get_type + * + * Purpose: Given a reference to some object, return the type of that reference. + * + * Return: Type of the reference + * + *------------------------------------------------------------------------- + */ +H5R_type_t +H5R__get_type(const H5R_ref_priv_t *ref) +{ + H5R_type_t ret_value = H5R_BADTYPE; + + FUNC_ENTER_PACKAGE_NOERR + + HDassert(ref != NULL); + ret_value = ref->type; + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__get_type() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__equal + * + * Purpose: Compare two references + * + * Return: TRUE if equal, FALSE if unequal, FAIL if error + * + *------------------------------------------------------------------------- + */ +htri_t +H5R__equal(const H5R_ref_priv_t *ref1, const H5R_ref_priv_t *ref2) +{ + htri_t ret_value = TRUE; + + FUNC_ENTER_PACKAGE + HDassert(ref1 != NULL); + HDassert(ref2 != NULL); + + /* Compare reference types */ + if(ref1->type != ref2->type) + HGOTO_DONE(FALSE); + + /* Compare object addresses */ + if(ref1->token_size != ref2->token_size) + HGOTO_DONE(FALSE); + if(0 != HDmemcmp(ref1->ref.obj.token, ref2->ref.obj.token, ref1->token_size)) + HGOTO_DONE(FALSE); + + /* Compare filenames */ + if((ref1->ref.obj.filename && (NULL == ref2->ref.obj.filename)) + || ((NULL == ref1->ref.obj.filename) && ref2->ref.obj.filename)) + HGOTO_DONE(FALSE); + if(ref1->ref.obj.filename && ref1->ref.obj.filename + && (0 != HDstrcmp(ref1->ref.obj.filename, ref2->ref.obj.filename))) + HGOTO_DONE(FALSE); + + switch(ref1->type) { + case H5R_OBJECT2: + break; + case H5R_DATASET_REGION2: + if((ret_value = H5S_extent_equal(ref1->ref.reg.space, ref2->ref.reg.space)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, FAIL, "cannot compare dataspace extents") + break; + case H5R_ATTR: + HDassert(ref1->ref.attr.name && ref2->ref.attr.name); + if(0 != HDstrcmp(ref1->ref.attr.name, ref2->ref.attr.name)) + HGOTO_DONE(FALSE); + break; + case H5R_OBJECT1: + case H5R_DATASET_REGION1: case H5R_BADTYPE: case H5R_MAXTYPE: + HDassert("invalid reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (invalid reference type)") default: HDassert("unknown reference type" && 0); - HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, H5I_INVALID_HID, "internal error (unknown reference type)") + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") } /* end switch */ - /* Get the # of links for object, and its type - * (To check to make certain that this object hasn't been deleted - * since the reference was created) - */ - if(H5O_get_rc_and_type(&oloc, &rc, &obj_type) < 0 || 0 == rc) - HGOTO_ERROR(H5E_REFERENCE, H5E_LINKCOUNT, H5I_INVALID_HID, "dereferencing deleted object") +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__equal() */ - /* Construct a group location for opening the object */ - H5G_name_reset(&path); - loc.oloc = &oloc; - loc.path = &path; + +/*------------------------------------------------------------------------- + * Function: H5R__copy + * + * Purpose: Copy a reference + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__copy(const H5R_ref_priv_t *src_ref, H5R_ref_priv_t *dst_ref) +{ + herr_t ret_value = SUCCEED; - /* Open the object */ - switch (obj_type) { - case H5O_TYPE_GROUP: - { - H5G_t *group; /* Pointer to group to open */ + FUNC_ENTER_PACKAGE - if(NULL == (group = H5G_open(&loc))) - HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5I_INVALID_HID, "not found") + HDassert((src_ref != NULL) && (dst_ref != NULL)); - /* Create an atom for the group */ - if((ret_value = H5I_register(H5I_GROUP, group, TRUE)) < 0) { - H5G_close(group); - HGOTO_ERROR(H5E_SYM, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register group") - } + H5MM_memcpy(dst_ref->ref.obj.token, src_ref->ref.obj.token, src_ref->token_size); + dst_ref->encode_size = src_ref->encode_size; + dst_ref->type = src_ref->type; + dst_ref->token_size = src_ref->token_size; + switch(src_ref->type) { + case H5R_OBJECT2: break; - } - - case H5O_TYPE_NAMED_DATATYPE: - { - H5T_t *type; /* Pointer to datatype to open */ - - if(NULL == (type = H5T_open(&loc))) - HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, H5I_INVALID_HID, "not found") + case H5R_DATASET_REGION2: + if(NULL == (dst_ref->ref.reg.space = H5S_copy(src_ref->ref.reg.space, FALSE, TRUE))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "unable to copy dataspace") + break; + case H5R_ATTR: + if(NULL == (dst_ref->ref.attr.name = HDstrdup(src_ref->ref.attr.name))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "Cannot copy attribute name") + break; + case H5R_OBJECT1: + case H5R_DATASET_REGION1: + HDassert("invalid reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (invalid reference type)") + case H5R_BADTYPE: + case H5R_MAXTYPE: + default: + HDassert("unknown reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") + } /* end switch */ - /* Create an atom for the datatype */ - if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) { - H5T_close(type); - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register datatype") - } + /* We only need to keep a copy of the filename if we don't have the loc_id */ + if(src_ref->loc_id == H5I_INVALID_HID) { + HDassert(src_ref->ref.obj.filename); - break; - } + if(NULL == (dst_ref->ref.obj.filename = HDstrdup(src_ref->ref.obj.filename))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "Cannot copy filename") + dst_ref->loc_id = H5I_INVALID_HID; + } else { + dst_ref->ref.obj.filename = NULL; - case H5O_TYPE_DATASET: - { - H5D_t *dset; /* Pointer to dataset to open */ + /* Set location ID and hold reference to it */ + if(H5R__set_loc_id(dst_ref, src_ref->loc_id, TRUE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "cannot set reference location ID") + } - /* Open the dataset */ - if(NULL == (dset = H5D_open(&loc, oapl_id))) - HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, H5I_INVALID_HID, "not found") +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__copy() */ - /* Create an atom for the dataset */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) { - H5D_close(dset); - HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register dataset") - } + +/*------------------------------------------------------------------------- + * Function: H5R__get_obj_token + * + * Purpose: Given a reference to some object, get the encoded object addr. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__get_obj_token(const H5R_ref_priv_t *ref, H5VL_token_t *obj_token, + size_t *token_size) +{ + herr_t ret_value = SUCCEED; /* Return value */ - break; - } + FUNC_ENTER_PACKAGE - case H5O_TYPE_MAP: - HGOTO_ERROR(H5E_REFERENCE, H5E_BADTYPE, H5I_INVALID_HID, "maps not supported in native VOL connector") + HDassert(ref != NULL); + HDassert(ref->token_size <= H5VL_MAX_TOKEN_SIZE); - case H5O_TYPE_UNKNOWN: - case H5O_TYPE_NTYPES: - default: - HGOTO_ERROR(H5E_REFERENCE, H5E_BADTYPE, H5I_INVALID_HID, "can't identify type of object referenced") - } /* end switch */ + if(obj_token) { + if(0 == ref->token_size) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "NULL token size") + H5MM_memcpy(obj_token, ref->ref.obj.token, ref->token_size); + } + if(token_size) + *token_size = ref->token_size; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5R__dereference() */ +} /* end H5R__get_obj_token() */ -/*-------------------------------------------------------------------------- - NAME - H5R__get_region - PURPOSE - Retrieves a dataspace with the region pointed to selected. - USAGE - H5S_t *H5R__get_region(file, ref) - H5F_t *file; IN: File the object being dereferenced is within - void *ref; IN: Reference to open. +/*------------------------------------------------------------------------- + * Function: H5R__set_obj_token + * + * Purpose: Given a reference to some object, set the encoded object addr. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__set_obj_token(H5R_ref_priv_t *ref, const H5VL_token_t *obj_token, + size_t token_size) +{ + herr_t ret_value = SUCCEED; /* Return value */ - RETURNS - Pointer to the dataspace on success, NULL on failure - DESCRIPTION - Given a reference to some object, creates a copy of the dataset pointed - to's dataspace and defines a selection in the copy which is the region - pointed to. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -H5S_t * -H5R__get_region(H5F_t *file, const void *_ref) + FUNC_ENTER_PACKAGE_NOERR + + HDassert(ref != NULL); + HDassert(obj_token); + HDassert(token_size); + HDassert(token_size <= H5VL_MAX_TOKEN_SIZE); + + H5MM_memcpy(ref->ref.obj.token, obj_token, ref->token_size); + ref->token_size = token_size; + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__set_obj_token() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__get_region + * + * Purpose: Given a reference to some object, creates a copy of the dataset + * pointed to's dataspace and defines a selection in the copy which is the + * region pointed to. + * + * Return: Pointer to the dataspace on success/NULL on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__get_region(const H5R_ref_priv_t *ref, H5S_t *space) { - H5O_loc_t oloc; /* Object location */ - const uint8_t *p; /* Pointer to OID to store */ - H5HG_t hobjid; /* Heap object ID */ - uint8_t *buf = NULL; /* Buffer to store serialized selection in */ - H5S_t *ret_value; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE - HDassert(_ref); - HDassert(file); + HDassert(ref != NULL); + HDassert(ref->type == H5R_DATASET_REGION2); + HDassert(space); - /* Initialize the object location */ - H5O_loc_reset(&oloc); - oloc.file = file; + /* Copy reference selection to destination */ + if(H5S_select_copy(space, ref->ref.reg.space, FALSE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "unable to copy selection") - /* Get the heap ID for the dataset region */ - p = (const uint8_t *)_ref; - H5F_addr_decode(oloc.file, &p, &(hobjid.addr)); - UINT32DECODE(p, hobjid.idx); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__get_region() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__get_file_name + * + * Purpose: Given a reference to some object, determine a file name of the + * object located into. + * + * Return: Non-negative length of the path on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +ssize_t +H5R__get_file_name(const H5R_ref_priv_t *ref, char *buf, size_t size) +{ + size_t copy_len; + ssize_t ret_value = -1; /* Return value */ - /* Get the dataset region from the heap (allocate inside routine) */ - if(NULL == (buf = (uint8_t *)H5HG_read(oloc.file, &hobjid, NULL, NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, NULL, "Unable to read dataset region information") + FUNC_ENTER_PACKAGE - /* Get the object oid for the dataset */ - p = buf; - H5F_addr_decode(oloc.file, &p, &(oloc.addr)); + /* Check args */ + HDassert(ref != NULL); - /* Open and copy the dataset's dataspace */ - if(NULL == (ret_value = H5S_read(&oloc))) - HGOTO_ERROR(H5E_DATASPACE, H5E_NOTFOUND, NULL, "not found") + /* Return if that reference has no filename set */ + if(!ref->ref.obj.filename) + HGOTO_ERROR(H5E_REFERENCE, H5E_ARGS, (-1), "no filename available for that reference") - /* Unserialize the selection */ - if(H5S_SELECT_DESERIALIZE(&ret_value, &p) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, NULL, "can't deserialize selection") + /* Get the file name length */ + copy_len = HDstrlen(ref->ref.obj.filename); + HDassert(copy_len <= H5R_MAX_STRING_LEN); -done: - /* Free the buffer allocated in H5HG_read() */ - if(buf) - H5MM_xfree(buf); + /* Copy the file name */ + if(buf) { + copy_len = MIN(copy_len, size - 1); + H5MM_memcpy(buf, ref->ref.obj.filename, copy_len); + buf[copy_len] = '\0'; + } + ret_value = (ssize_t)(copy_len + 1); +done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5R__get_region() */ +} /* end H5R__get_file_name() */ -/*-------------------------------------------------------------------------- - NAME - H5R__get_obj_type - PURPOSE - Retrieves the type of object that an object reference points to - USAGE - H5O_type_t H5R__get_obj_type(file, ref_type, ref) - H5F_t *file; IN: File the object being dereferenced is within - H5R_type_t ref_type; IN: Type of reference to query - void *ref; IN: Reference to query. - H5O_type_t *obj_type; OUT: The type of the object, set on success +/*------------------------------------------------------------------------- + * Function: H5R__get_attr_name + * + * Purpose: Given a reference to some attribute, determine its name. + * + * Return: Non-negative length of the path on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +ssize_t +H5R__get_attr_name(const H5R_ref_priv_t *ref, char *buf, size_t size) +{ + ssize_t ret_value = -1; /* Return value */ + size_t attr_name_len; /* Length of the attribute name */ - RETURNS - Non-negative on success/Negative on failure - DESCRIPTION - Given a reference to some object, this function returns the type of object - pointed to. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ + FUNC_ENTER_PACKAGE_NOERR + + /* Check args */ + HDassert(ref != NULL); + HDassert(ref->type == H5R_ATTR); + + /* Get the attribute name length */ + attr_name_len = HDstrlen(ref->ref.attr.name); + HDassert(attr_name_len <= H5R_MAX_STRING_LEN); + + /* Get the attribute name */ + if(buf) { + size_t copy_len = MIN(attr_name_len, size - 1); + H5MM_memcpy(buf, ref->ref.attr.name, copy_len); + buf[copy_len] = '\0'; + } + + ret_value = (ssize_t)(attr_name_len + 1); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__get_attr_name() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__encode + * + * Purpose: Private function for H5Rencode. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ herr_t -H5R__get_obj_type(H5F_t *file, H5R_type_t ref_type, const void *_ref, - H5O_type_t *obj_type) +H5R__encode(const char *filename, const H5R_ref_priv_t *ref, unsigned char *buf, + size_t *nalloc, unsigned flags) { - H5O_loc_t oloc; /* Object location */ - unsigned rc; /* Reference count of object */ - herr_t ret_value = SUCCEED; /* Return value */ + uint8_t *p = (uint8_t *)buf; + size_t buf_size = 0, encode_size = 0; + herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE - HDassert(file); - HDassert(_ref); + HDassert(ref); + HDassert(nalloc); + + /** + * Encoding format: + * | Reference type (8 bits) | Flags (8 bits) | Token (token size) + * | | + * | |----> H5R_IS_EXTERNAL: File info + * | + * |----> H5R_DATASET_REGION2: Serialized selection + * | + * |----> H5R_ATTR: Attribute name len + name + * + */ + + /* Don't encode if buffer size isn't big enough or buffer is empty */ + if(buf && *nalloc >= H5R_ENCODE_HEADER_SIZE) { + /* Encode the type of the reference */ + *p++ = (uint8_t)ref->type; + + /* Encode the flags */ + *p++ = (uint8_t)flags; - /* Initialize the symbol table entry */ - H5O_loc_reset(&oloc); - oloc.file = file; + buf_size = *nalloc - H5R_ENCODE_HEADER_SIZE; + } + encode_size += H5R_ENCODE_HEADER_SIZE; + + /* Encode object token */ + H5R_ENCODE_VAR(H5R__encode_obj_token, &ref->ref.obj.token, ref->token_size, + p, buf_size, encode_size, "Cannot encode object address"); + + /** + * TODO Encode VOL info + * When we have a better way of storing blobs, we should add + * support for referencing files in external VOLs. + * There are currently multiple limitations: + * - avoid duplicating VOL info on each reference + * - must query terminal VOL connector to avoid passthrough confusion + */ + if(flags & H5R_IS_EXTERNAL) { + /* Encode file name */ + H5R_ENCODE(H5R__encode_string, filename, p, buf_size, encode_size, + "Cannot encode filename"); + } - switch (ref_type) { - case H5R_OBJECT: - { - /* Get the object oid */ - oloc.addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */ + switch(ref->type) { + case H5R_OBJECT2: break; - } + case H5R_DATASET_REGION2: + /* Encode dataspace */ + H5R_ENCODE(H5R__encode_region, ref->ref.reg.space, p, buf_size, + encode_size, "Cannot encode region"); + break; + case H5R_ATTR: + /* Encode attribute name */ + H5R_ENCODE(H5R__encode_string, ref->ref.attr.name, p, buf_size, + encode_size, "Cannot encode attribute name"); + break; + case H5R_OBJECT1: + case H5R_DATASET_REGION1: + case H5R_BADTYPE: + case H5R_MAXTYPE: + HDassert("invalid reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (invalid reference type)") + default: + HDassert("unknown reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") + } /* end switch */ + + *nalloc = encode_size; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__encode() */ - case H5R_DATASET_REGION: - { - H5HG_t hobjid; /* Heap object ID */ - const uint8_t *p; /* Pointer to reference to decode */ - uint8_t *buf; /* Buffer to store serialized selection in */ + +/*------------------------------------------------------------------------- + * Function: H5R__decode + * + * Purpose: Private function for H5Rdecode. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__decode(const unsigned char *buf, size_t *nbytes, H5R_ref_priv_t *ref) +{ + const uint8_t *p = (const uint8_t *)buf; + size_t buf_size = 0, decode_size = 0; + uint8_t flags; + herr_t ret_value = SUCCEED; - /* Get the heap ID for the dataset region */ - p = (const uint8_t *)_ref; - H5F_addr_decode(oloc.file, &p, &(hobjid.addr)); - UINT32DECODE(p, hobjid.idx); + FUNC_ENTER_PACKAGE - /* Get the dataset region from the heap (allocate inside routine) */ - if(NULL == (buf = (uint8_t *)H5HG_read(oloc.file, &hobjid, NULL, NULL))) - HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL, "Unable to read dataset region information") + HDassert(buf); + HDassert(nbytes); + HDassert(ref); + buf_size = *nbytes; - /* Get the object oid for the dataset */ - p = buf; - H5F_addr_decode(oloc.file, &p, &(oloc.addr)); + /* Don't decode if buffer size isn't big enough */ + if(buf_size < H5R_ENCODE_HEADER_SIZE) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") - /* Free the buffer allocated in H5HG_read() */ - H5MM_xfree(buf); + /* Set new reference */ + ref->type = (H5R_type_t)*p++; + if(ref->type <= H5R_BADTYPE || ref->type >= H5R_MAXTYPE) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type") - break; - } + /* Set flags */ + flags = *p++; + + buf_size -= H5R_ENCODE_HEADER_SIZE; + decode_size += H5R_ENCODE_HEADER_SIZE; + /* Decode object token */ + H5R_DECODE_VAR(H5R__decode_obj_token, &ref->ref.obj.token, &ref->token_size, + p, buf_size, decode_size, "Cannot decode object address"); + + /* We do not need to store the filename if the reference is internal */ + if(flags & H5R_IS_EXTERNAL) { + /* Decode file name */ + H5R_DECODE(H5R__decode_string, &ref->ref.obj.filename, p, buf_size, + decode_size, "Cannot decode filename"); + } else + ref->ref.obj.filename = NULL; + + switch(ref->type) { + case H5R_OBJECT2: + break; + case H5R_DATASET_REGION2: + /* Decode dataspace */ + H5R_DECODE(H5R__decode_region, &ref->ref.reg.space, p, buf_size, + decode_size, "Cannot decode region"); + break; + case H5R_ATTR: + /* Decode attribute name */ + H5R_DECODE(H5R__decode_string, &ref->ref.attr.name, p, buf_size, + decode_size, "Cannot decode attribute name"); + break; + case H5R_OBJECT1: + case H5R_DATASET_REGION1: case H5R_BADTYPE: case H5R_MAXTYPE: + HDassert("invalid reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (invalid reference type)") default: HDassert("unknown reference type" && 0); HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") } /* end switch */ - /* Get the # of links for object, and its type */ - /* (To check to make certain that this object hasn't been deleted since the reference was created) */ - if(H5O_get_rc_and_type(&oloc, &rc, obj_type) < 0 || 0 == rc) - HGOTO_ERROR(H5E_REFERENCE, H5E_LINKCOUNT, FAIL, "dereferencing deleted object") + /* Set loc ID to invalid */ + ref->loc_id = H5I_INVALID_HID; + + /* Set encoding size */ + ref->encode_size = decode_size; + + H5R_LOG_DEBUG("Decoded reference, filename=%s, obj_addr=%s, encode size=%u", + ref->ref.obj.filename, H5R__print_token(ref->ref.obj.token), + ref->encode_size); + + *nbytes = decode_size; done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5R__get_obj_type() */ +} /* end H5R__decode() */ -/*-------------------------------------------------------------------------- - NAME - H5R__get_name - PURPOSE - Internal routine to determine a name for the object referenced - USAGE - ssize_t H5R__get_name(f, ref_type, ref, name, size) - H5F_t *f; IN: Pointer to the file that the reference is pointing - into - hid_t lapl_id; IN: LAPL to use for operation - hid_t id; IN: Location ID given for reference - H5R_type_t ref_type; IN: Type of reference - void *_ref; IN: Reference to query. - char *name; OUT: Buffer to place name of object referenced - size_t size; IN: Size of name buffer +/*------------------------------------------------------------------------- + * Function: H5R__encode_obj_token + * + * Purpose: Encode an object address. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5R__encode_obj_token(const H5VL_token_t *obj_token, size_t token_size, + unsigned char *buf, size_t *nalloc) +{ + herr_t ret_value = SUCCEED; - RETURNS - Non-negative length of the path on success, -1 on failure - DESCRIPTION - Given a reference to some object, determine a path to the object - referenced in the file. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - This may not be the only path to that object. - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -ssize_t -H5R__get_name(H5F_t *f, H5R_type_t ref_type, const void *_ref, - char *name, size_t size) + FUNC_ENTER_STATIC_NOERR + + HDassert(nalloc); + + /* Don't encode if buffer size isn't big enough or buffer is empty */ + if(buf && *nalloc >= token_size) { + uint8_t *p = (uint8_t *)buf; + + /* Encode token size */ + *p++ = (uint8_t)(token_size & 0xff); + + /* Encode token */ + H5MM_memcpy(p, obj_token, token_size); + } + *nalloc = token_size + H5_SIZEOF_UINT8_T; + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__encode_obj_token() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__decode_obj_token + * + * Purpose: Decode an object address. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5R__decode_obj_token(const unsigned char *buf, size_t *nbytes, + H5VL_token_t *obj_token, uint8_t *token_size) { - H5O_loc_t oloc; /* Object location describing object for reference */ - ssize_t ret_value = -1; /* Return value */ + const uint8_t *p = (const uint8_t *)buf; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(buf); + HDassert(nbytes); + HDassert(obj_token); + HDassert(token_size); + + /* Don't decode if buffer size isn't big enough */ + if(*nbytes < H5_SIZEOF_UINT8_T) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + + /* Get token size */ + *token_size = *p++; + if(*token_size > sizeof(H5VL_token_t)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Invalid token size (%u)", *token_size) + + /* Decode token */ + H5MM_memcpy(obj_token, p, *token_size); + + *nbytes = *token_size + H5_SIZEOF_UINT8_T; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__decode_obj_token() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__encode_region + * + * Purpose: Encode a selection. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5R__encode_region(H5S_t *space, unsigned char *buf, size_t *nalloc) +{ + uint8_t *p = NULL; /* Pointer to data to store */ + hssize_t buf_size = 0; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(space); + HDassert(nalloc); + + /* Get the amount of space required to serialize the selection */ + if((buf_size = H5S_SELECT_SERIAL_SIZE(space)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "Cannot determine amount of space needed for serializing selection") + + /* Don't encode if buffer size isn't big enough or buffer is empty */ + if(buf && *nalloc >= ((size_t)buf_size + 2 * H5_SIZEOF_UINT32_T)) { + p = (uint8_t *)buf; + int rank; + + /* Encode the size for safety check */ + UINT32ENCODE(p, (uint32_t)buf_size); + + /* Encode the extent rank */ + if((rank = H5S_get_simple_extent_ndims(space)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "can't get extent rank for selection") + UINT32ENCODE(p, (uint32_t)rank); + + /* Serialize the selection */ + if(H5S_SELECT_SERIALIZE(space, (unsigned char **)&p) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "can't serialize selection") + } + *nalloc = (size_t)buf_size + 2 * H5_SIZEOF_UINT32_T; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__encode_region() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__decode_region + * + * Purpose: Decode a selection. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5R__decode_region(const unsigned char *buf, size_t *nbytes, H5S_t **space_ptr) +{ + const uint8_t *p = (const uint8_t *)buf; + size_t buf_size = 0; + unsigned rank; + H5S_t *space; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(buf); + HDassert(nbytes); + HDassert(space_ptr); + + /* Don't decode if buffer size isn't big enough */ + if(*nbytes < (2 * H5_SIZEOF_UINT32_T)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + + /* Decode the selection size */ + UINT32DECODE(p, buf_size); + buf_size += H5_SIZEOF_UINT32_T; + + /* Decode the extent rank */ + UINT32DECODE(p, rank); + buf_size += H5_SIZEOF_UINT32_T; + + /* Don't decode if buffer size isn't big enough */ + if(*nbytes < buf_size) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + + /* Deserialize the selection (dataspaces need the extent rank information) */ + if(NULL == (space = H5S_create(H5S_SIMPLE))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + if(H5S_set_extent_simple(space, rank, NULL, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "can't set extent rank for selection") + if(H5S_SELECT_DESERIALIZE(&space, &p) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "can't deserialize selection") + + *nbytes = buf_size; + *space_ptr = space; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__decode_region() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__encode_string + * + * Purpose: Encode a string. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5R__encode_string(const char *string, unsigned char *buf, size_t *nalloc) +{ + size_t string_len, buf_size; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(string); + HDassert(nalloc); + + /* Get the amount of space required to serialize the string */ + string_len = HDstrlen(string); + if(string_len > H5R_MAX_STRING_LEN) + HGOTO_ERROR(H5E_REFERENCE, H5E_ARGS, FAIL, "string too long") + + /* Compute buffer size, allow for the attribute name length and object address */ + buf_size = string_len + sizeof(uint16_t); + + if(buf && *nalloc >= buf_size) { + uint8_t *p = (uint8_t *)buf; + /* Serialize information for string length into the buffer */ + UINT16ENCODE(p, string_len); + /* Copy the string into the buffer */ + H5MM_memcpy(p, string, string_len); + } + *nalloc = buf_size; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__encode_string() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__decode_string + * + * Purpose: Decode a string. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5R__decode_string(const unsigned char *buf, size_t *nbytes, char **string_ptr) +{ + const uint8_t *p = (const uint8_t *)buf; + size_t string_len; + char *string = NULL; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(buf); + HDassert(nbytes); + HDassert(string_ptr); + + /* Don't decode if buffer size isn't big enough */ + if(*nbytes < sizeof(uint16_t)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + + /* Get the string length */ + UINT16DECODE(p, string_len); + HDassert(string_len <= H5R_MAX_STRING_LEN); + + /* Allocate the string */ + if(NULL == (string = H5MM_malloc(string_len + 1))) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTALLOC, FAIL, "Cannot allocate string") + + /* Copy the string */ + H5MM_memcpy(string, p, string_len); + string[string_len] = '\0'; + + *string_ptr = string; + *nbytes = sizeof(uint16_t) + string_len; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__decode_string() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__encode_heap + * + * Purpose: Encode data and insert into heap (native only). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__encode_heap(H5F_t *f, unsigned char *buf, size_t *nalloc, + const unsigned char *data, size_t data_size) +{ + size_t buf_size; + herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE - /* Check args */ HDassert(f); - HDassert(_ref); + HDassert(nalloc); - /* Initialize the object location */ - H5O_loc_reset(&oloc); - oloc.file = f; + buf_size = H5HG_HEAP_ID_SIZE(f); + if(buf && *nalloc >= buf_size) { + H5HG_t hobjid; + uint8_t *p = (uint8_t *)buf; - /* Get address for reference */ - switch (ref_type) { - case H5R_OBJECT: - { - oloc.addr = *(const hobj_ref_t *)_ref; - break; - } + /* Write the reference information to disk (allocates space also) */ + if(H5HG_insert(f, data_size, (void *)data, &hobjid) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to write reference information") - case H5R_DATASET_REGION: - { - H5HG_t hobjid; /* Heap object ID */ - uint8_t *buf; /* Buffer to store serialized selection in */ - const uint8_t *p; /* Pointer to OID to store */ + /* Encode the heap information */ + H5F_addr_encode(f, &p, hobjid.addr); + UINT32ENCODE(p, hobjid.idx); + } + *nalloc = buf_size; - /* Get the heap ID for the dataset region */ - p = (const uint8_t *)_ref; - H5F_addr_decode(oloc.file, &p, &(hobjid.addr)); - UINT32DECODE(p, hobjid.idx); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__encode_heap() */ - /* Get the dataset region from the heap (allocate inside routine) */ - if((buf = (uint8_t *)H5HG_read(oloc.file, &hobjid, NULL, NULL)) == NULL) - HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, (-1), "Unable to read dataset region information") + +/*------------------------------------------------------------------------- + * Function: H5R__decode_heap + * + * Purpose: Decode data inserted into heap (native only). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__decode_heap(H5F_t *f, const unsigned char *buf, size_t *nbytes, + unsigned char **data_ptr, size_t *data_size) +{ + const uint8_t *p = (const uint8_t *)buf; + H5HG_t hobjid; + size_t buf_size; + herr_t ret_value = SUCCEED; - /* Get the object oid for the dataset */ - p = buf; - H5F_addr_decode(oloc.file, &p, &(oloc.addr)); + FUNC_ENTER_PACKAGE - /* Free the buffer allocated in H5HG_read() */ - H5MM_xfree(buf); + HDassert(f); + HDassert(buf); + HDassert(nbytes); + HDassert(data_ptr); + + buf_size = H5HG_HEAP_ID_SIZE(f); + /* Don't decode if buffer size isn't big enough */ + if(*nbytes < buf_size) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + + /* Get the heap information */ + H5F_addr_decode(f, &p, &(hobjid.addr)); + if(!H5F_addr_defined(hobjid.addr) || hobjid.addr == 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Undefined reference pointer") + UINT32DECODE(p, hobjid.idx); - break; - } + /* Read the information from disk */ + if(NULL == (*data_ptr = (unsigned char *)H5HG_read(f, &hobjid, (void *)*data_ptr, data_size))) + HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "Unable to read reference data") - case H5R_BADTYPE: - case H5R_MAXTYPE: - default: - HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, (-1), "internal error (unknown reference type)") - } /* end switch */ + *nbytes = buf_size; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__decode_heap() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__free_heap + * + * Purpose: Remove data previously inserted into heap (native only). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__free_heap(H5F_t *f, const unsigned char *buf, size_t nbytes) +{ + H5HG_t hobjid; + const uint8_t *p = (const uint8_t *)buf; + size_t buf_size; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + HDassert(f); + HDassert(buf); + + buf_size = H5HG_HEAP_ID_SIZE(f); + /* Don't decode if buffer size isn't big enough */ + if(nbytes < buf_size) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") + + /* Get the heap information */ + H5F_addr_decode(f, &p, &(hobjid.addr)); + if(!H5F_addr_defined(hobjid.addr) || hobjid.addr == 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Undefined reference pointer") + UINT32DECODE(p, hobjid.idx); + + /* Free heap object */ + if(hobjid.addr > 0) { + /* Free heap object */ + if(H5HG_remove(f, &hobjid) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__free_heap() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__decode_addr_compat + * + * Purpose: Decode an object address. (native only) + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__decode_addr_compat(hid_t id, H5I_type_t type, H5R_type_t ref_type, + const unsigned char *buf, haddr_t *addr_ptr) +{ + hid_t file_id = H5I_INVALID_HID; /* File ID for region reference */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + if(ref_type == H5R_OBJECT1) { + size_t buf_size = H5R_OBJ_REF_BUF_SIZE; + + /* Get object address */ + if(H5R__decode_addr_obj_compat(buf, &buf_size, addr_ptr) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "unable to get object address") + } else { + void *vol_obj_file = NULL; + H5F_t *f = NULL; + size_t buf_size = H5R_DSET_REG_REF_BUF_SIZE; + + /* Get the file for the object */ + if((file_id = H5F_get_file_id(id, type, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Retrieve VOL object */ + if(NULL == (vol_obj_file = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Retrieve file from VOL object */ + if(NULL == (f = (H5F_t *)H5VL_object_data(vol_obj_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid VOL object") + + /* Get object address */ + if(H5R__decode_addr_region_compat(f, buf, &buf_size, addr_ptr, NULL) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "unable to get object address") + } + +done: + if(file_id != H5I_INVALID_HID && H5I_dec_ref(file_id) < 0) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file") + FUNC_LEAVE_NOAPI(ret_value) +} + + +/*------------------------------------------------------------------------- + * Function: H5R__encode_addr_obj_compat + * + * Purpose: Encode an object address. (native only) + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__encode_addr_obj_compat(haddr_t addr, unsigned char *buf, size_t *nalloc) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE_NOERR + + HDassert(nalloc); + + /* Don't encode if buffer size isn't big enough or buffer is empty */ + if(buf && *nalloc >= sizeof(addr)) + H5MM_memcpy(buf, &addr, sizeof(addr)); + *nalloc = sizeof(addr); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__encode_addr_obj_compat() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__decode_addr_obj_compat + * + * Purpose: Decode an object address. (native only) + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__decode_addr_obj_compat(const unsigned char *buf, size_t *nbytes, + haddr_t *addr_ptr) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + HDassert(buf); + HDassert(nbytes); + HDassert(addr_ptr); + + /* Don't decode if buffer size isn't big enough */ + if(*nbytes < sizeof(*addr_ptr)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Buffer size is too small") - /* Get name, length, etc. */ - if((ret_value = H5G_get_name_by_addr(f, &oloc, name, size)) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, (-1), "can't determine name") + H5MM_memcpy(addr_ptr, buf, sizeof(*addr_ptr)); + + *nbytes = sizeof(*addr_ptr); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5R__get_name() */ +} /* H5R__decode_addr_obj_compat() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__encode_addr_region_compat + * + * Purpose: Encode dataset selection and insert data into heap (native only). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__encode_addr_region_compat(H5F_t *f, haddr_t obj_addr, H5S_t *space, + unsigned char *buf, size_t *nalloc) +{ + size_t buf_size; + unsigned char *data = NULL; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + HDassert(f); + HDassert(space); + HDassert(nalloc); + + /* Get required buffer size */ + if(H5R__encode_heap(f, NULL, &buf_size, NULL, (size_t)0) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + if(buf && *nalloc >= buf_size) { + ssize_t data_size; + uint8_t *p; + + /* Pass the correct encoding version for the selection depending on the + * file libver bounds, this is later retrieved in H5S hyper encode */ + H5CX_set_libver_bounds(f); + + /* Zero the heap ID out, may leak heap space if user is re-using + * reference and doesn't have garbage collection turned on + */ + HDmemset(buf, 0, buf_size); + + /* Get the amount of space required to serialize the selection */ + if((data_size = H5S_SELECT_SERIAL_SIZE(space)) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "Invalid amount of space for serializing selection") + /* Increase buffer size to allow for the dataset OID */ + data_size += (hssize_t)sizeof(haddr_t); + + /* Allocate the space to store the serialized information */ + H5_CHECK_OVERFLOW(data_size, hssize_t, size_t); + if(NULL == (data = (uint8_t *)H5MM_malloc((size_t)data_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + + /* Serialize information for dataset OID into heap buffer */ + p = (uint8_t *)data; + H5F_addr_encode(f, &p, obj_addr); + + /* Serialize the selection into heap buffer */ + if(H5S_SELECT_SERIALIZE(space, &p) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "Unable to serialize selection") + + /* Write to heap */ + if(H5R__encode_heap(f, buf, nalloc, data, (size_t)data_size) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + } + *nalloc = buf_size; + +done: + H5MM_free(data); + FUNC_LEAVE_NOAPI(ret_value) +} /* H5R__encode_addr_region_compat() */ + + +/*------------------------------------------------------------------------- + * Function: H5R__decode_obj_addr_compat + * + * Purpose: Decode dataset selection from data inserted into heap (native only). + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5R__decode_addr_region_compat(H5F_t *f, const unsigned char *buf, + size_t *nbytes, haddr_t *obj_addr_ptr, H5S_t **space_ptr) +{ + unsigned char *data = NULL; + size_t data_size; + haddr_t obj_addr; + const uint8_t *p; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + HDassert(f); + HDassert(buf); + HDassert(nbytes); + + /* Read from heap */ + if(H5R__decode_heap(f, buf, nbytes, &data, &data_size) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") + + /* Get object address */ + p = (const uint8_t *)data; + H5F_addr_decode(f, &p, &obj_addr); + if(!H5F_addr_defined(obj_addr) || obj_addr == 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Undefined reference pointer") + + if(space_ptr) { + H5O_loc_t oloc; /* Object location */ + H5S_t *space = NULL; + + /* Initialize the object location */ + H5O_loc_reset(&oloc); + oloc.file = f; + oloc.addr = obj_addr; + + /* Open and copy the dataset's dataspace */ + if(NULL == (space = H5S_read(&oloc))) + HGOTO_ERROR(H5E_DATASPACE, H5E_NOTFOUND, FAIL, "not found") + + /* Unserialize the selection */ + if(H5S_SELECT_DESERIALIZE(&space, &p) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "can't deserialize selection") + + *space_ptr = space; + } + if(obj_addr_ptr) + *obj_addr_ptr = obj_addr; + +done: + H5MM_free(data); + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5R__decode_addr_region_compat() */ diff --git a/src/H5Rpkg.h b/src/H5Rpkg.h index 1c1c8eb..1843bcf 100644 --- a/src/H5Rpkg.h +++ b/src/H5Rpkg.h @@ -36,11 +36,51 @@ /* Package Private Macros */ /**************************/ +/* Encode flags */ +#define H5R_IS_EXTERNAL 0x1 /* Set when encoding reference to external file */ + +/* Macros for convenience */ +#define H5R_REF_FILENAME(x) ((x)->ref.obj.filename) +#define H5R_REF_ATTRNAME(x) ((x)->ref.attr.name) + +/* Header size */ +#define H5R_ENCODE_HEADER_SIZE (2 * H5_SIZEOF_UINT8_T) /****************************/ /* Package Private Typedefs */ /****************************/ +/* Object reference */ +typedef struct H5R_ref_priv_obj_t { + H5VL_token_t token; /* Object token */ + char *filename; /* File name */ +} H5R_ref_priv_obj_t; + +/* Region reference */ +typedef struct H5R_ref_priv_reg_t { + H5R_ref_priv_obj_t obj; /* Object reference */ + H5S_t *space; /* Selection */ +} H5R_ref_priv_reg_t; + +/* Attribute reference */ +typedef struct H5R_ref_priv_attr_t { + H5R_ref_priv_obj_t obj; /* Object reference */ + char *name; /* Attribute name */ +} H5R_ref_priv_attr_t; + +/* Generic reference type (keep it cache aligned) */ +typedef struct H5R_ref_priv_t { + union { + H5R_ref_priv_obj_t obj;/* Object reference */ + H5R_ref_priv_reg_t reg;/* Region reference */ + H5R_ref_priv_attr_t attr;/* Attribute Reference */ + } ref; + hid_t loc_id; /* Cached location identifier */ + uint32_t encode_size; /* Cached encoding size */ + int8_t type; /* Reference type */ + uint8_t token_size; /* Cached token size */ + char unused[18]; /* Unused */ +} H5R_ref_priv_t; /*****************************/ /* Package Private Variables */ @@ -50,11 +90,41 @@ /******************************/ /* Package Private Prototypes */ /******************************/ -H5_DLL herr_t H5R__create(void *ref, H5G_loc_t *loc, const char *name, H5R_type_t ref_type, H5S_t *space); -H5_DLL hid_t H5R__dereference(H5F_t *file, hid_t dapl_id, H5R_type_t ref_type, const void *_ref); -H5_DLL H5S_t *H5R__get_region(H5F_t *file, const void *_ref); -H5_DLL herr_t H5R__get_obj_type(H5F_t *file, H5R_type_t ref_type, const void *_ref, H5O_type_t *obj_type); -H5_DLL ssize_t H5R__get_name(H5F_t *file, H5R_type_t ref_type, const void *_ref, char *name, size_t size); +H5_DLL herr_t H5R__create_object(const H5VL_token_t *obj_token, size_t token_size, H5R_ref_priv_t *ref); +H5_DLL herr_t H5R__create_region(const H5VL_token_t *obj_token, size_t token_size, H5S_t *space, H5R_ref_priv_t *ref); +H5_DLL herr_t H5R__create_attr(const H5VL_token_t *obj_token, size_t token_size, const char *attr_name, H5R_ref_priv_t *ref); +H5_DLL herr_t H5R__destroy(H5R_ref_priv_t *ref); + +H5_DLL herr_t H5R__set_loc_id(H5R_ref_priv_t *ref, hid_t id, hbool_t inc_ref); +H5_DLL hid_t H5R__get_loc_id(const H5R_ref_priv_t *ref); +H5_DLL hid_t H5R__reopen_file(H5R_ref_priv_t *ref, hid_t fapl_id); + +H5_DLL H5R_type_t H5R__get_type(const H5R_ref_priv_t *ref); +H5_DLL htri_t H5R__equal(const H5R_ref_priv_t *ref1, const H5R_ref_priv_t *ref2); +H5_DLL herr_t H5R__copy(const H5R_ref_priv_t *src_ref, H5R_ref_priv_t *dst_ref); + +H5_DLL herr_t H5R__get_obj_token(const H5R_ref_priv_t *ref, H5VL_token_t *obj_token, size_t *token_size); +H5_DLL herr_t H5R__set_obj_token(H5R_ref_priv_t *ref, const H5VL_token_t *obj_token, size_t token_size); +H5_DLL herr_t H5R__get_region(const H5R_ref_priv_t *ref, H5S_t *space); + +H5_DLL ssize_t H5R__get_file_name(const H5R_ref_priv_t *ref, char *buf, size_t size); +H5_DLL ssize_t H5R__get_attr_name(const H5R_ref_priv_t *ref, char *buf, size_t size); + +H5_DLL herr_t H5R__encode(const char *filename, const H5R_ref_priv_t *ref, unsigned char *buf, size_t *nalloc, unsigned flags); +H5_DLL herr_t H5R__decode(const unsigned char *buf, size_t *nbytes, H5R_ref_priv_t *ref); + +/* Native HDF5 specific routines */ +H5_DLL herr_t H5R__encode_heap(H5F_t *f, unsigned char *buf, size_t *nalloc, const unsigned char *data, size_t data_size); +H5_DLL herr_t H5R__decode_heap(H5F_t *f, const unsigned char *buf, size_t *nbytes, unsigned char **data_ptr, size_t *data_size); +H5_DLL herr_t H5R__free_heap(H5F_t *f, const unsigned char *buf, size_t nbytes); + +H5_DLL herr_t H5R__decode_addr_compat(hid_t id, H5I_type_t type, H5R_type_t ref_type, const unsigned char *buf, haddr_t *addr_ptr); + +H5_DLL herr_t H5R__encode_addr_obj_compat(haddr_t obj_addr, unsigned char *buf, size_t *nalloc); +H5_DLL herr_t H5R__decode_addr_obj_compat(const unsigned char *buf, size_t *nbytes, haddr_t *obj_addr_ptr); + +H5_DLL herr_t H5R__encode_addr_region_compat(H5F_t *f, haddr_t obj_addr, H5S_t *space, unsigned char *buf, size_t *nalloc); +H5_DLL herr_t H5R__decode_addr_region_compat(H5F_t *f, const unsigned char *buf, size_t *nbytes, haddr_t *obj_addr_ptr, H5S_t **space_ptr); #endif /* _H5Rpkg_H */ diff --git a/src/H5Rprivate.h b/src/H5Rprivate.h index 1bf2e92..6afec47 100644 --- a/src/H5Rprivate.h +++ b/src/H5Rprivate.h @@ -25,6 +25,8 @@ /* Library Private Macros */ /**************************/ +#define H5R_ENCODE_VERSION 0x1 /* Version for encoding references */ + /****************************/ /* Library Private Typedefs */ @@ -41,4 +43,3 @@ /******************************/ #endif /* _H5Rprivate_H */ - diff --git a/src/H5Rpublic.h b/src/H5Rpublic.h index 598bafd..ce54ac4 100644 --- a/src/H5Rpublic.h +++ b/src/H5Rpublic.h @@ -26,47 +26,64 @@ /* Public Macros */ /*****************/ -/* Note! Be careful with the sizes of the references because they should really - * depend on the run-time values in the file. Unfortunately, the arrays need - * to be defined at compile-time, so we have to go with the worst case sizes - * for them. -QAK - */ +/* Deprecated reference buffer sizes that are kept for backward compatibility */ #define H5R_OBJ_REF_BUF_SIZE sizeof(haddr_t) +#define H5R_DSET_REG_REF_BUF_SIZE (sizeof(haddr_t) + 4) -/* 4 is used instead of sizeof(int) to permit portability between the Crays - * and other machines (the heap ID is always encoded as an int32 anyway). +/* Default reference buffer size. + * Note! Be careful with the sizes of the references because they should really + * depend on the run-time values in the file. */ -#define H5R_DSET_REG_REF_BUF_SIZE (sizeof(haddr_t) + 4) +#define H5R_REF_BUF_SIZE (64) /*******************/ /* Public Typedefs */ /*******************/ -/* Reference types */ -typedef enum H5R_type_t { - H5R_BADTYPE = (-1), /* Invalid Reference Type */ - H5R_OBJECT, /* Object reference */ - H5R_DATASET_REGION, /* Dataset Region Reference */ - H5R_MAXTYPE /* Highest type (Invalid as true type) */ +/* + * Reference types allowed. + * DO NOT CHANGE THE ORDER or VALUES as reference type values are encoded into + * the datatype message header. + */ +typedef enum { + H5R_BADTYPE = (-1), /* Invalid reference type */ + H5R_OBJECT1 = 0, /* Backward compatibility (object) */ + H5R_DATASET_REGION1 = 1, /* Backward compatibility (region) */ + H5R_OBJECT2 = 2, /* Object reference */ + H5R_DATASET_REGION2 = 3, /* Region reference */ + H5R_ATTR = 4, /* Attribute Reference */ + H5R_MAXTYPE = 5 /* Highest type (invalid) */ } H5R_type_t; -/* Object reference structure for user's code - * This needs to be large enough to store largest haddr_t on a worst case - * machine (8 bytes currently). +/* Deprecated types are kept for backward compatibility with previous versions */ + +/** + * Deprecated object reference type that is used with deprecated reference APIs. + * Note! This type can only be used with the "native" HDF5 VOL connector. */ typedef haddr_t hobj_ref_t; -/* Dataset Region reference structure for user's code +/** + * Dataset region reference type that is used with deprecated reference APIs. * (Buffer to store heap ID and index) * This needs to be large enough to store largest haddr_t in a worst case - * machine (8 bytes currently) plus an int + * machine (8 bytes currently) plus an int. + * Note! This type can only be used with the "native" HDF5 VOL connector. */ typedef unsigned char hdset_reg_ref_t[H5R_DSET_REG_REF_BUF_SIZE]; +/** + * Opaque reference type. The same reference type is used for object, + * dataset region and attribute references. This is the type that + * should always be used with the current reference API. + */ +typedef unsigned char H5R_ref_t[H5R_REF_BUF_SIZE]; + /********************/ /* Public Variables */ /********************/ + /*********************/ /* Public Prototypes */ /*********************/ @@ -75,30 +92,57 @@ typedef unsigned char hdset_reg_ref_t[H5R_DSET_REG_REF_BUF_SIZE]; extern "C" { #endif -H5_DLL herr_t H5Rcreate(void *ref, hid_t loc_id, const char *name, - H5R_type_t ref_type, hid_t space_id); -H5_DLL hid_t H5Rdereference2(hid_t obj_id, hid_t oapl_id, H5R_type_t ref_type, const void *ref); -H5_DLL hid_t H5Rget_region(hid_t dataset, H5R_type_t ref_type, const void *ref); -H5_DLL herr_t H5Rget_obj_type2(hid_t id, H5R_type_t ref_type, const void *_ref, - H5O_type_t *obj_type); -H5_DLL ssize_t H5Rget_name(hid_t loc_id, H5R_type_t ref_type, const void *ref, - char *name /*out*/, size_t size); +/* Constructors */ +H5_DLL herr_t H5Rcreate_object(hid_t loc_id, const char *name, H5R_ref_t *ref_ptr); +H5_DLL herr_t H5Rcreate_region(hid_t loc_id, const char *name, hid_t space_id, H5R_ref_t *ref_ptr); +H5_DLL herr_t H5Rcreate_attr(hid_t loc_id, const char *name, const char *attr_name, H5R_ref_t *ref_ptr); +H5_DLL herr_t H5Rdestroy(H5R_ref_t *ref_ptr); + +/* Info */ +H5_DLL H5R_type_t H5Rget_type(const H5R_ref_t *ref_ptr); +H5_DLL htri_t H5Requal(const H5R_ref_t *ref1_ptr, const H5R_ref_t *ref2_ptr); +H5_DLL herr_t H5Rcopy(const H5R_ref_t *src_ref_ptr, H5R_ref_t *dst_ref_ptr); + +/* Dereference */ +H5_DLL hid_t H5Ropen_object(const H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id); +H5_DLL hid_t H5Ropen_region(const H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t oapl_id); +H5_DLL hid_t H5Ropen_attr(const H5R_ref_t *ref_ptr, hid_t rapl_id, hid_t aapl_id); + +/* Get type */ +H5_DLL herr_t H5Rget_obj_type3(const H5R_ref_t *ref_ptr, hid_t rapl_id, H5O_type_t *obj_type); + +/* Get name */ +H5_DLL ssize_t H5Rget_file_name(const H5R_ref_t *ref_ptr, char *buf, size_t size); +H5_DLL ssize_t H5Rget_obj_name(const H5R_ref_t *ref_ptr, hid_t rapl_id, char *buf, size_t size); +H5_DLL ssize_t H5Rget_attr_name(const H5R_ref_t *ref_ptr, char *buf, size_t size); /* Symbols defined for compatibility with previous versions of the HDF5 API. * - * Use of these symbols is deprecated. + * Use of these symbols is or will be deprecated. */ -#ifndef H5_NO_DEPRECATED_SYMBOLS + +/* Macros */ + +/* Versions for compatibility */ +#define H5R_OBJECT H5R_OBJECT1 +#define H5R_DATASET_REGION H5R_DATASET_REGION1 /* Function prototypes */ -H5_DLL H5G_obj_t H5Rget_obj_type1(hid_t id, H5R_type_t ref_type, const void *_ref); +#ifndef H5_NO_DEPRECATED_SYMBOLS + +H5_DLL H5G_obj_t H5Rget_obj_type1(hid_t id, H5R_type_t ref_type, const void *ref); H5_DLL hid_t H5Rdereference1(hid_t obj_id, H5R_type_t ref_type, const void *ref); #endif /* H5_NO_DEPRECATED_SYMBOLS */ +H5_DLL herr_t H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, hid_t space_id); +H5_DLL herr_t H5Rget_obj_type2(hid_t id, H5R_type_t ref_type, const void *ref, H5O_type_t *obj_type); +H5_DLL hid_t H5Rdereference2(hid_t obj_id, hid_t oapl_id, H5R_type_t ref_type, const void *ref); +H5_DLL hid_t H5Rget_region(hid_t dataset, H5R_type_t ref_type, const void *ref); +H5_DLL ssize_t H5Rget_name(hid_t loc_id, H5R_type_t ref_type, const void *ref, char *name, size_t size); + #ifdef __cplusplus } #endif #endif /* _H5Rpublic_H */ - @@ -1357,7 +1357,6 @@ H5S_set_extent_simple(H5S_t *space, unsigned rank, const hsize_t *dims, /* Check args */ HDassert(rank <= H5S_MAX_RANK); - HDassert(0 == rank || dims); /* shift out of the previous state to a "simple" dataspace. */ if(H5S__extent_release(&space->extent) < 0) @@ -1378,7 +1377,7 @@ H5S_set_extent_simple(H5S_t *space, unsigned rank, const hsize_t *dims, space->extent.size = (hsize_t *)H5FL_ARR_MALLOC(hsize_t, (size_t)rank); /* Copy the dimensions & compute the number of elements in the extent */ - for(u = 0, nelem = 1; u < space->extent.rank; u++) { + for(u = 0, nelem = 1; dims && (u < space->extent.rank); u++) { space->extent.size[u] = dims[u]; nelem *= dims[u]; } /* end for */ @@ -1390,7 +1389,7 @@ H5S_set_extent_simple(H5S_t *space, unsigned rank, const hsize_t *dims, if(max != NULL) H5MM_memcpy(space->extent.max, max, sizeof(hsize_t) * rank); else - for(u = 0; u < space->extent.rank; u++) + for(u = 0; dims && (u < space->extent.rank); u++) space->extent.max[u] = dims[u]; } /* end else */ @@ -226,18 +226,34 @@ #define H5T_INIT_TYPE_REF_COMMON { \ H5T_INIT_TYPE_ALLOC_COMMON(H5T_REFERENCE) \ H5T_INIT_TYPE_NUM_COMMON(H5T_ORDER_NONE) \ + dt->shared->force_conv = TRUE; \ + dt->shared->u.atomic.u.r.f = NULL; \ + dt->shared->u.atomic.u.r.loc = H5T_LOC_BADLOC; \ + dt->shared->u.atomic.u.r.cls = NULL; \ } #define H5T_INIT_TYPE_OBJREF_CORE { \ H5T_INIT_TYPE_REF_COMMON \ - dt->shared->force_conv = TRUE; \ - dt->shared->u.atomic.u.r.rtype = H5R_OBJECT; \ - dt->shared->u.atomic.u.r.loc = H5T_LOC_MEMORY; \ + dt->shared->u.atomic.u.r.rtype = H5R_OBJECT1; \ + dt->shared->u.atomic.u.r.opaque = FALSE; \ + dt->shared->u.atomic.u.r.version = 0; \ } #define H5T_INIT_TYPE_REGREF_CORE { \ H5T_INIT_TYPE_REF_COMMON \ - dt->shared->u.atomic.u.r.rtype = H5R_DATASET_REGION; \ + dt->shared->u.atomic.u.r.rtype = H5R_DATASET_REGION1; \ + dt->shared->u.atomic.u.r.opaque = FALSE; \ + dt->shared->u.atomic.u.r.version = 0; \ +} + +/* rtype value is only used as a placeholder to differentiate the type from + * other types, any opaque (i.e. "new") reference type could be used. + */ +#define H5T_INIT_TYPE_REF_CORE { \ + H5T_INIT_TYPE_REF_COMMON \ + dt->shared->u.atomic.u.r.rtype = H5R_OBJECT2; \ + dt->shared->u.atomic.u.r.opaque = TRUE; \ + dt->shared->u.atomic.u.r.version = H5R_ENCODE_VERSION; \ } /* Define the code templates for the "SIZE_TMPL" in the H5T_INIT_TYPE macro */ @@ -295,7 +311,7 @@ static htri_t H5T__compiler_conv(H5T_t *src, H5T_t *dst); static herr_t H5T__set_size(H5T_t *dt, size_t size); static herr_t H5T__close_cb(H5T_t *dt); static H5T_path_t *H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_conv_func_t *conv); -static hbool_t H5T__detect_reg_ref(const H5T_t *dt); +static hbool_t H5T__detect_vlen_ref(const H5T_t *dt); /*****************************/ @@ -354,6 +370,7 @@ hid_t H5T_STD_B64BE_g = FAIL; hid_t H5T_STD_B64LE_g = FAIL; hid_t H5T_STD_REF_OBJ_g = FAIL; hid_t H5T_STD_REF_DSETREG_g = FAIL; +hid_t H5T_STD_REF_g = FAIL; hid_t H5T_UNIX_D32BE_g = FAIL; hid_t H5T_UNIX_D32LE_g = FAIL; @@ -444,6 +461,7 @@ size_t H5T_POINTER_COMP_ALIGN_g = 0; size_t H5T_HVL_COMP_ALIGN_g = 0; size_t H5T_HOBJREF_COMP_ALIGN_g = 0; size_t H5T_HDSETREGREF_COMP_ALIGN_g = 0; +size_t H5T_REF_COMP_ALIGN_g = 0; /* * Alignment constraints for native types. These are initialized at run time @@ -737,7 +755,9 @@ H5T__init_package(void) H5T_t *enum_type=NULL; /* Datatype structure for enum objects */ H5T_t *vlen=NULL; /* Datatype structure for vlen objects */ H5T_t *array=NULL; /* Datatype structure for array objects */ - H5T_t *objref=NULL; /* Datatype structure for object reference objects */ + H5T_t *objref=NULL; /* Datatype structure for deprecated reference objects */ + H5T_t *regref=NULL; /* Datatype structure for deprecated region references */ + H5T_t *ref=NULL; /* Datatype structure for opaque references */ hsize_t dim[1]={1}; /* Dimension info for array datatype */ herr_t status; hbool_t copied_dtype = TRUE; /* Flag to indicate whether datatype was copied or allocated (for error cleanup) */ @@ -989,12 +1009,23 @@ H5T__init_package(void) *------------------------------------------------------------ */ - /* Object reference (i.e. object header address in file) */ - H5T_INIT_TYPE(OBJREF, H5T_STD_REF_OBJ_g, ALLOC, -, SET, H5R_OBJ_REF_BUF_SIZE) + /* Deprecated object reference type */ + H5T_INIT_TYPE(OBJREF, H5T_STD_REF_OBJ_g, ALLOC, -, NOSET, -) + if(H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") objref = dt; /* Keep type for later */ - /* Dataset Region reference (i.e. selection inside a dataset) */ - H5T_INIT_TYPE(REGREF, H5T_STD_REF_DSETREG_g, ALLOC, -, SET, H5R_DSET_REG_REF_BUF_SIZE) + /* Deprecated region reference type */ + H5T_INIT_TYPE(REGREF, H5T_STD_REF_DSETREG_g, ALLOC, -, NOSET, -) + if(H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") + regref = dt; /* Keep type for later */ + + /* Opaque reference type */ + H5T_INIT_TYPE(REF, H5T_STD_REF_g, ALLOC, -, NOSET, -) + if(H5T_set_loc(dt, NULL, H5T_LOC_MEMORY) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") + ref = dt; /* Keep type for later */ /* * Register conversion functions beginning with the most general and @@ -1030,6 +1061,10 @@ H5T__init_package(void) status |= H5T__register_int(H5T_PERS_SOFT, "vlen", vlen, vlen, H5T__conv_vlen); status |= H5T__register_int(H5T_PERS_SOFT, "array", array, array, H5T__conv_array); status |= H5T__register_int(H5T_PERS_SOFT, "objref", objref, objref, H5T__conv_order_opt); + status |= H5T__register_int(H5T_PERS_SOFT, "regref", regref, regref, H5T__conv_noop); + status |= H5T__register_int(H5T_PERS_SOFT, "ref", ref, ref, H5T__conv_ref); + status |= H5T__register_int(H5T_PERS_SOFT, "objref_ref", objref, ref, H5T__conv_ref); + status |= H5T__register_int(H5T_PERS_SOFT, "regref_ref", regref, ref, H5T__conv_ref); /* * Native conversions should be listed last since we can use hardware to @@ -1473,6 +1508,7 @@ H5T_top_term_package(void) H5T_STD_B64LE_g = FAIL; H5T_STD_REF_OBJ_g = FAIL; H5T_STD_REF_DSETREG_g = FAIL; + H5T_STD_REF_g = FAIL; H5T_UNIX_D32BE_g = FAIL; H5T_UNIX_D32LE_g = FAIL; @@ -2883,6 +2919,56 @@ done: /*------------------------------------------------------------------------- + * Function: H5Treclaim + * + * Purpose: Frees the buffers allocated for storing variable-length data + * in memory. Only frees the VL data in the selection defined in the + * dataspace. The dataset transfer property list is required to find the + * correct allocation/free methods for the VL data in the buffer. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Quincey Koziol + * Thursday, June 10, 1999 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Treclaim(hid_t type_id, hid_t space_id, hid_t dxpl_id, void *buf) +{ + H5S_t *space; /* Dataspace for iteration */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "iii*x", type_id, space_id, dxpl_id, buf); + + /* Check args */ + if(H5I_DATATYPE != H5I_get_type(type_id) || buf == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument") + if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace") + if(!(H5S_has_extent(space))) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dataspace does not have extent set") + + /* Get the default dataset transfer property list if the user didn't provide one */ + if(H5P_DEFAULT == dxpl_id) + dxpl_id = H5P_DATASET_XFER_DEFAULT; + else + if(TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") + + /* Set DXPL for operation */ + H5CX_set_dxpl(dxpl_id); + + /* Call internal routine */ + ret_value = H5T_reclaim(type_id, space, buf); + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Treclaim() */ + + +/*------------------------------------------------------------------------- * Function: H5Tencode * * Purpose: Given an datatype ID, converts the object description into @@ -4456,28 +4542,10 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset) HGOTO_DONE(-1); if(dt1->shared->u.atomic.u.r.rtype > dt2->shared->u.atomic.u.r.rtype) HGOTO_DONE(1); - - switch(dt1->shared->u.atomic.u.r.rtype) { - case H5R_OBJECT: - if(dt1->shared->u.atomic.u.r.loc < dt2->shared->u.atomic.u.r.loc) - HGOTO_DONE(-1); - if(dt1->shared->u.atomic.u.r.loc > dt2->shared->u.atomic.u.r.loc) - HGOTO_DONE(1); - break; - - case H5R_DATASET_REGION: - /* Does this need more to distinguish it? -QAK 11/30/98 */ - /*void */ - break; - - case H5R_BADTYPE: - case H5R_MAXTYPE: - HDassert("invalid type" && 0); - break; - default: - HDassert("not implemented yet" && 0); - break; - } + if(dt1->shared->u.atomic.u.r.loc < dt2->shared->u.atomic.u.r.loc) + HGOTO_DONE(-1); + if(dt1->shared->u.atomic.u.r.loc > dt2->shared->u.atomic.u.r.loc) + HGOTO_DONE(1); break; case H5T_NO_CLASS: @@ -5330,7 +5398,7 @@ done: htri_t H5T_set_loc(dt,f,loc) H5T_t *dt; IN/OUT: Pointer to the datatype to mark H5F_t *f; IN: Pointer to the file the datatype is in - H5T_vlen_type_t loc IN: location of type + H5T_loc_t loc IN: location of type RETURNS One of two values on success: @@ -5455,17 +5523,9 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc) break; case H5T_REFERENCE: - /* Only need to change location of object references */ - if(dt->shared->u.atomic.u.r.rtype == H5R_OBJECT) { - /* Mark this reference */ - if(loc != dt->shared->u.atomic.u.r.loc) { - /* Set the location */ - dt->shared->u.atomic.u.r.loc = loc; - - /* Indicate that the location changed */ - ret_value = TRUE; - } /* end if */ - } /* end if */ + /* Reference types go through type conversion */ + if((ret_value = H5T__ref_set_loc(dt, f, loc)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "Unable to set reference location"); break; case H5T_NO_CLASS: @@ -5492,7 +5552,7 @@ done: * * Purpose: Check if a datatype will change between disk and memory. * - * Notes: Currently, only variable-length and object references change + * Notes: Currently, only variable-length and references change * between disk & memory (see cases where things are changed in * the H5T_set_loc() code above). * @@ -5527,9 +5587,9 @@ done: /*------------------------------------------------------------------------- - * Function: H5T_detect_reg_ref + * Function: H5T__detect_vlen_ref * - * Purpose: Check whether a datatype contains (or is) a region reference + * Purpose: Check whether a datatype contains (or is) a vlen reference * datatype. * * Return: TRUE (1) or FALSE (0) on success @@ -5541,7 +5601,7 @@ done: *------------------------------------------------------------------------- */ static hbool_t -H5T__detect_reg_ref(const H5T_t *dt) +H5T__detect_vlen_ref(const H5T_t *dt) { unsigned u; /* Local index variable */ hbool_t ret_value = FALSE; /* Return value */ @@ -5551,8 +5611,9 @@ H5T__detect_reg_ref(const H5T_t *dt) /* Sanity checks */ HDassert(dt); - /* Check if this datatype is a region reference */ - if(H5T_REFERENCE == dt->shared->type && H5R_DATASET_REGION == dt->shared->u.atomic.u.r.rtype) + /* Check if this datatype is a vlen reference */ + /* TODO currently H5T_STD_REF is always considered as a vlen type */ + if(H5T_REFERENCE == dt->shared->type && !dt->shared->u.atomic.u.r.opaque) HGOTO_DONE(TRUE); /* Check for types that might have the correct type as a component */ @@ -5561,14 +5622,14 @@ H5T__detect_reg_ref(const H5T_t *dt) /* Iterate over all the compound datatype's fields */ for(u = 0; u < dt->shared->u.compnd.nmembs; u++) /* Recurse on field's datatype */ - if(H5T__detect_reg_ref(dt->shared->u.compnd.memb[u].type)) + if(H5T__detect_vlen_ref(dt->shared->u.compnd.memb[u].type)) HGOTO_DONE(TRUE); break; case H5T_ARRAY: case H5T_VLEN: case H5T_ENUM: - HGOTO_DONE(H5T__detect_reg_ref(dt->shared->parent)); + HGOTO_DONE(H5T__detect_vlen_ref(dt->shared->parent)); break; case H5T_NO_CLASS: @@ -5586,7 +5647,7 @@ H5T__detect_reg_ref(const H5T_t *dt) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T__detect_reg_ref() */ +} /* end H5T__detect_vlen_ref() */ /*------------------------------------------------------------------------- @@ -5622,7 +5683,7 @@ H5T_is_vl_storage(const H5T_t *dt) if(H5T_detect_class(dt, H5T_VLEN, FALSE)) ret_value = TRUE; else if(H5T_detect_class(dt, H5T_REFERENCE, FALSE)) - ret_value = H5T__detect_reg_ref(dt); + ret_value = H5T__detect_vlen_ref(dt); else ret_value = FALSE; diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 48c3282..84642f4 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -30,7 +30,6 @@ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ -#include "H5HGprivate.h" /* Global Heaps */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ @@ -1019,6 +1018,9 @@ H5FL_BLK_DEFINE_STATIC(vlen_seq); /* Declare a free list to manage pieces of array data */ H5FL_BLK_DEFINE_STATIC(array_seq); +/* Declare a free list to manage pieces of reference data */ +H5FL_BLK_DEFINE_STATIC(ref_seq); + /*------------------------------------------------------------------------- * Function: H5T__conv_noop @@ -3020,17 +3022,16 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, hbool_t noop_conv = FALSE; /* Flag to indicate a noop conversion */ hbool_t write_to_file = FALSE; /* Flag to indicate writing to file */ htri_t parent_is_vlen; /* Flag to indicate parent is vlen datatyp */ + size_t bg_seq_len = 0; /* The number of elements in the background sequence */ hid_t tsrc_id = -1, tdst_id = -1;/*temporary type atoms */ H5T_t *src = NULL; /*source datatype */ H5T_t *dst = NULL; /*destination datatype */ - H5HG_t bg_hobjid, parent_hobjid; uint8_t *s = NULL; /*source buffer */ uint8_t *d = NULL; /*destination buffer */ uint8_t *b = NULL; /*background buffer */ ssize_t s_stride, d_stride; /*src and dst strides */ ssize_t b_stride; /*bkg stride */ size_t safe; /*how many elements are safe to process in each pass */ - size_t bg_seq_len = 0; size_t src_base_size, dst_base_size;/*source & destination base size*/ void *conv_buf = NULL; /*temporary conversion buffer */ size_t conv_buf_size = 0; /*size of conversion buffer in bytes */ @@ -3055,13 +3056,13 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype") if(H5T_VLEN != src->shared->type) HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype") - if(H5T_VLEN != dst->shared->type) + if(H5T_VLEN != dst->shared->type) HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype") if(H5T_VLEN_STRING == src->shared->u.vlen.type && H5T_VLEN_STRING == dst->shared->u.vlen.type) { if((H5T_CSET_ASCII == src->shared->u.vlen.cset && H5T_CSET_UTF8 == dst->shared->u.vlen.cset) - || (H5T_CSET_ASCII == dst->shared->u.vlen.cset && H5T_CSET_UTF8 == src->shared->u.vlen.cset)) + || (H5T_CSET_ASCII == dst->shared->u.vlen.cset && H5T_CSET_UTF8 == src->shared->u.vlen.cset)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "The library doesn't convert between strings of ASCII and UTF") - } + } /* end if */ /* Variable-length types don't need a background buffer */ cdata->need_bkg = H5T_BKG_NO; @@ -3179,25 +3180,27 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } /* end else */ for(elmtno = 0; elmtno < safe; elmtno++) { + hbool_t is_nil; /* Whether sequence is "nil" */ + /* Check for "nil" source sequence */ - if((*(src->shared->u.vlen.isnull))(src->shared->u.vlen.f, s)) { + if((*(src->shared->u.vlen.cls->isnull))(src->shared->u.vlen.f, s, &is_nil) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't check if VL data is 'nil'") + else if(is_nil) { /* Write "nil" sequence to destination location */ - if((*(dst->shared->u.vlen.setnull))(dst->shared->u.vlen.f, d, b) < 0) + if((*(dst->shared->u.vlen.cls->setnull))(dst->shared->u.vlen.f, d, b) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't set VL data to 'nil'") - } /* end if */ + } /* end else-if */ else { - ssize_t sseq_len; /* (signed) The number of elements in the current sequence*/ - size_t seq_len; /* The number of elements in the current sequence*/ + size_t seq_len; /* The number of elements in the current sequence */ /* Get length of element sequences */ - if((sseq_len = (*(src->shared->u.vlen.getlen))(s)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "incorrect length") - seq_len = (size_t)sseq_len; + if((*(src->shared->u.vlen.cls->getlen))(src->shared->u.vlen.f, s, &seq_len) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "bad sequence length") /* If we are reading from memory and there is no conversion, just get the pointer to sequence */ if(write_to_file && noop_conv) { /* Get direct pointer to sequence */ - if(NULL == (conv_buf = (*(src->shared->u.vlen.getptr))(s))) + if(NULL == (conv_buf = (*(src->shared->u.vlen.cls->getptr))(s))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid source pointer") } /* end if */ else { @@ -3213,17 +3216,17 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, conv_buf_size = ((1 / H5T_VLEN_MIN_CONF_BUF_SIZE) + 1) * H5T_VLEN_MIN_CONF_BUF_SIZE; if(NULL == (conv_buf = H5FL_BLK_CALLOC(vlen_seq, conv_buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") - } + } /* end if */ else if(conv_buf_size < MAX(src_size, dst_size)) { /* Only allocate conversion buffer in H5T_VLEN_MIN_CONF_BUF_SIZE increments */ conv_buf_size = ((MAX(src_size, dst_size) / H5T_VLEN_MIN_CONF_BUF_SIZE) + 1) * H5T_VLEN_MIN_CONF_BUF_SIZE; if(NULL == (conv_buf = H5FL_BLK_REALLOC(vlen_seq, conv_buf, conv_buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") HDmemset(conv_buf, 0, conv_buf_size); - } /* end if */ + } /* end else-if */ /* Read in VL sequence */ - if((*(src->shared->u.vlen.read))(src->shared->u.vlen.f, s, conv_buf, src_size) < 0) + if((*(src->shared->u.vlen.cls->read))(src->shared->u.vlen.f, s, conv_buf, src_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL data") } /* end else */ @@ -3241,9 +3244,14 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /* If we are writing and there is a nested VL type, read * the sequence into the background buffer */ if(nested) { - const uint8_t *tmp = b; + /* Sanity check */ + HDassert(write_to_file); + + /* Get length of background element sequence */ + if((*(dst->shared->u.vlen.cls->getlen))(dst->shared->u.vlen.f, b, &bg_seq_len) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "bad sequence length") - UINT32DECODE(tmp, bg_seq_len); + /* Read sequence if length > 0 */ if(bg_seq_len > 0) { if(tmp_buf_size < (bg_seq_len * MAX(src_base_size, dst_base_size))) { tmp_buf_size = (bg_seq_len * MAX(src_base_size, dst_base_size)); @@ -3251,10 +3259,10 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") HDmemset(tmp_buf, 0, tmp_buf_size); } /* end if */ - H5F_addr_decode(dst->shared->u.vlen.f, &tmp, &(bg_hobjid.addr)); - UINT32DECODE(tmp, bg_hobjid.idx); - if(NULL == H5HG_read(dst->shared->u.vlen.f, &bg_hobjid, tmp_buf, NULL)) - HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL sequence into background buffer") + + /* Read in background VL sequence */ + if((*(dst->shared->u.vlen.cls->read))(dst->shared->u.vlen.f, b, tmp_buf, bg_seq_len) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL data") } /* end if */ /* If the sequence gets shorter, pad out the original sequence with zeros */ @@ -3268,26 +3276,23 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, } /* end if */ /* Write sequence to destination location */ - if((*(dst->shared->u.vlen.write))(dst->shared->u.vlen.f, &vl_alloc_info, d, conv_buf, b, seq_len, dst_base_size) < 0) + if((*(dst->shared->u.vlen.cls->write))(dst->shared->u.vlen.f, &vl_alloc_info, d, conv_buf, b, seq_len, dst_base_size) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write VL data") if(!noop_conv) { /* For nested VL case, free leftover heap objects from the deeper level if the length of new data elements is shorter than the old data elements.*/ if(nested && seq_len < bg_seq_len) { - size_t parent_seq_len; const uint8_t *tmp; size_t u; - /* TMP_P is reset each time in the loop because DST_BASE_SIZE may include some data in addition to VL info. - SLU */ - for(u = seq_len; u < bg_seq_len; u++) { - tmp = (uint8_t *)tmp_buf + u * dst_base_size; - UINT32DECODE(tmp, parent_seq_len); - if(parent_seq_len > 0) { - H5F_addr_decode(dst->shared->u.vlen.f, &tmp, &(parent_hobjid.addr)); - UINT32DECODE(tmp, parent_hobjid.idx); - if(H5HG_remove(dst->shared->u.vlen.f, &parent_hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") - } /* end if */ + /* Sanity check */ + HDassert(write_to_file); + + tmp = (uint8_t *)tmp_buf + seq_len * dst_base_size; + for(u = seq_len; u < bg_seq_len; u++, tmp += dst_base_size) { + /* Delete sequence in destination location */ + if((*(dst->shared->u.vlen.cls->del))(dst->shared->u.vlen.f, tmp) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove heap object") } /* end for */ } /* end if */ } /* end if */ @@ -3474,6 +3479,195 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__conv_array() */ +/*------------------------------------------------------------------------- + * Function: H5T__conv_ref + * + * Purpose: Converts between reference datatypes in memory and on disk. + * This is a soft conversion function. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5T__conv_ref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, + size_t buf_stride, size_t bkg_stride, void *buf, void *bkg) +{ + H5T_t *src = NULL; /* source datatype */ + H5T_t *dst = NULL; /* destination datatype */ + uint8_t *s = NULL; /* source buffer */ + uint8_t *d = NULL; /* destination buffer */ + uint8_t *b = NULL; /* background buffer */ + ssize_t s_stride, d_stride; /* src and dst strides */ + ssize_t b_stride; /* bkg stride */ + size_t safe; /* how many elements are safe to process in each pass */ + void *conv_buf = NULL; /* temporary conversion buffer */ + size_t conv_buf_size = 0; /* size of conversion buffer in bytes */ + size_t elmtno; /* element number counter */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_PACKAGE + + switch(cdata->command) { + case H5T_CONV_INIT: + /* + * First, determine if this conversion function applies to the + * conversion path SRC_ID-->DST_ID. If not, return failure; + * otherwise initialize the `priv' field of `cdata' with + * information that remains (almost) constant for this + * conversion path. + */ + if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id))) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype") + if(H5T_REFERENCE != src->shared->type) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_REFERENCE datatype") + if(H5T_REFERENCE != dst->shared->type) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_REFERENCE datatype") + /* Only allow for source reference that is not an opaque type, destination must be opaque */ + if(!dst->shared->u.atomic.u.r.opaque) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not an H5T_STD_REF datatype") + + /* Reference types don't need a background buffer */ + cdata->need_bkg = H5T_BKG_NO; + break; + + case H5T_CONV_FREE: + break; + + case H5T_CONV_CONV: + { + /* + * Conversion. + */ + if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + + HDassert(src->shared->u.atomic.u.r.cls); + + /* Initialize source & destination strides */ + if(buf_stride) { + HDassert(buf_stride >= src->shared->size); + HDassert(buf_stride >= dst->shared->size); + H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t); + s_stride = d_stride = (ssize_t)buf_stride; + } /* end if */ + else { + H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t); + H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t); + s_stride = (ssize_t)src->shared->size; + d_stride = (ssize_t)dst->shared->size; + } /* end else */ + if(bkg) { + if(bkg_stride) + b_stride = (ssize_t)bkg_stride; + else + b_stride = d_stride; + } /* end if */ + else + b_stride = 0; + + /* The outer loop of the type conversion macro, controlling which */ + /* direction the buffer is walked */ + while(nelmts > 0) { + /* Check if we need to go backwards through the buffer */ + if(d_stride > s_stride) { + /* Sanity check */ + HDassert(s_stride > 0); + HDassert(d_stride > 0); + HDassert(b_stride >= 0); + + /* Compute the number of "safe" destination elements at */ + /* the end of the buffer (Those which don't overlap with */ + /* any source elements at the beginning of the buffer) */ + safe = nelmts - (((nelmts * (size_t)s_stride) + ((size_t)d_stride - 1)) / (size_t)d_stride); + + /* If we're down to the last few elements, just wrap up */ + /* with a "real" reverse copy */ + if(safe < 2) { + s = (uint8_t *)buf + (nelmts - 1) * (size_t)s_stride; + d = (uint8_t *)buf + (nelmts - 1) * (size_t)d_stride; + b = (uint8_t *)bkg + (nelmts - 1) * (size_t)b_stride; + s_stride = -s_stride; + d_stride = -d_stride; + b_stride = -b_stride; + + safe = nelmts; + } /* end if */ + else { + s = (uint8_t *)buf + (nelmts - safe) * (size_t)s_stride; + d = (uint8_t *)buf + (nelmts - safe) * (size_t)d_stride; + b = (uint8_t *)bkg + (nelmts - safe) * (size_t)b_stride; + } /* end else */ + } /* end if */ + else { + /* Single forward pass over all data */ + s = d = (uint8_t *)buf; + b = (uint8_t *)bkg; + safe = nelmts; + } /* end else */ + + for(elmtno = 0; elmtno < safe; elmtno++) { + size_t buf_size; + hbool_t dst_copy = FALSE; + + /* Get size of references */ + if(0 == (buf_size = src->shared->u.atomic.u.r.cls->getsize( + src->shared->u.atomic.u.r.f, s, src->shared->size, + dst->shared->u.atomic.u.r.f, &dst_copy))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "incorrect size") + + /* Check if conversion buffer is large enough, resize if necessary. */ + if(conv_buf_size < buf_size) { + conv_buf_size = buf_size; + if(NULL == (conv_buf = H5FL_BLK_REALLOC(ref_seq, conv_buf, conv_buf_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") + HDmemset(conv_buf, 0, conv_buf_size); + } /* end if */ + + if(dst_copy && (src->shared->u.atomic.u.r.loc == H5T_LOC_DISK)) { + H5MM_memcpy(conv_buf, s, buf_size); + } else { + /* Read reference */ + if(src->shared->u.atomic.u.r.cls->read( + src->shared->u.atomic.u.r.f, s, src->shared->size, + dst->shared->u.atomic.u.r.f, conv_buf, buf_size) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read reference data") + } + + if(dst_copy && (dst->shared->u.atomic.u.r.loc == H5T_LOC_DISK)) { + H5MM_memcpy(d, conv_buf, buf_size); + } else { + /* Write reference to destination location */ + if(dst->shared->u.atomic.u.r.cls->write( + src->shared->u.atomic.u.r.f, conv_buf, buf_size, src->shared->u.atomic.u.r.rtype, + dst->shared->u.atomic.u.r.f, d, dst->shared->size, b) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write reference data") + } + + /* Advance pointers */ + s += s_stride; + d += d_stride; + b += b_stride; + } /* end for */ + + /* Decrement number of elements left to convert */ + nelmts -= safe; + } /* end while */ + } /* end case */ + break; + + default: /* Some other command we don't know about yet.*/ + HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command") + } /* end switch */ + +done: + /* Release the conversion buffer (always allocated, except on errors) */ + if(conv_buf) + conv_buf = H5FL_BLK_FREE(ref_seq, conv_buf); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__conv_ref() */ + /*------------------------------------------------------------------------- * Function: H5T__conv_i_i @@ -9305,3 +9499,84 @@ H5T_reverse_order(uint8_t *rev, uint8_t *s, size_t size, H5T_order_t order) FUNC_LEAVE_NOAPI(SUCCEED) } + +/*------------------------------------------------------------------------- + * Function: H5T_reclaim + * + * Purpose: Frees the buffers allocated for storing variable-length data + * in memory. Only frees the VL data in the selection defined in the + * dataspace. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_reclaim(hid_t type_id, H5S_t *space, void *buf) +{ + H5T_t *type; /* Datatype */ + H5S_sel_iter_op_t dset_op; /* Operator for iteration */ + H5T_vlen_alloc_info_t vl_alloc_info; /* VL allocation info */ + herr_t ret_value = FAIL; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Check args */ + HDassert(H5I_DATATYPE == H5I_get_type(type_id)); + HDassert(space); + HDassert(buf); + + if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an valid base datatype") + + /* Get the allocation info */ + if(H5CX_get_vlen_alloc_info(&vl_alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") + + /* Call H5S_select_iterate with args, etc. */ + dset_op.op_type = H5S_SEL_ITER_OP_LIB; + dset_op.u.lib_op = H5T_reclaim_cb; + + ret_value = H5S_select_iterate(buf, type, space, &dset_op, &vl_alloc_info); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_reclaim() */ + + +/*------------------------------------------------------------------------- + * Function: H5T_reclaim_cb + * + * Purpose: Iteration callback to reclaim conversion allocated memory for a + * buffer element. + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_reclaim_cb(void *elem, const H5T_t *dt, unsigned H5_ATTR_UNUSED ndim, + const hsize_t H5_ATTR_UNUSED *point, void *op_data) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Sanity check */ + HDassert(elem); + HDassert(dt); + + if(dt->shared->type == H5T_REFERENCE) { + if(H5T_ref_reclaim(elem, dt) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim ref elements") + } else { + HDassert(op_data); + + /* Allow vlen reclaim to recurse into that routine */ + if(H5T_vlen_reclaim(elem, dt, (H5T_vlen_alloc_info_t *)op_data) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_reclaim_cb() */ diff --git a/src/H5Tnative.c b/src/H5Tnative.c index 6daa544..1d203c7 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -126,7 +126,6 @@ static H5T_t * H5T__get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size) { - H5T_t *dt; /* Datatype to make native */ H5T_t *super_type; /* Super type of VL, array and enum datatypes */ H5T_t *nat_super_type; /* Native form of VL, array & enum super datatype */ H5T_t *new_type = NULL; /* New native datatype */ @@ -218,26 +217,36 @@ H5T__get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_ali case H5T_REFERENCE: { + H5T_t *dt; /* Datatype to make native */ size_t align; size_t ref_size; - int not_equal; if(NULL == (ret_value = H5T_copy(dtype, H5T_COPY_TRANSIENT))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot copy reference type") - /* Decide if the data type is object or dataset region reference. */ + /* Decide if the data type is object reference. */ if(NULL == (dt = (H5T_t *)H5I_object(H5T_STD_REF_OBJ_g))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type") - not_equal = H5T_cmp(ret_value, dt, FALSE); /* Update size, offset and compound alignment for parent. */ - if(!not_equal) { + if(0 == H5T_cmp(ret_value, dt, FALSE)) { align = H5T_HOBJREF_COMP_ALIGN_g; ref_size = sizeof(hobj_ref_t); } /* end if */ else { - align = H5T_HDSETREGREF_COMP_ALIGN_g; - ref_size = sizeof(hdset_reg_ref_t); + /* Decide if the data type is dataset region reference. */ + if(NULL == (dt = (H5T_t *)H5I_object(H5T_STD_REF_DSETREG_g))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type") + + if (0 == H5T_cmp(ret_value, dt, FALSE)) { + align = H5T_HDSETREGREF_COMP_ALIGN_g; + ref_size = sizeof(hdset_reg_ref_t); + } /* end if */ + else { + /* Only pointers to underlying opaque reference types */ + align = H5T_REF_COMP_ALIGN_g; + ref_size = sizeof(H5R_ref_t); + } /* end else */ } /* end else */ if(H5T__cmp_offset(comp_size, offset, ref_size, (size_t)1, align, struct_align) < 0) diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index 7798e37..9784abd 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -95,9 +95,14 @@ /* This version also encodes array types more efficiently */ #define H5O_DTYPE_VERSION_3 3 +/* This is the version that adds support for new reference types and prevents + * older versions of the library to attempt reading unknown types. + */ +#define H5O_DTYPE_VERSION_4 4 + /* The latest version of the format. Look through the 'encode helper' routine * and 'size' callback for places to change when updating this. */ -#define H5O_DTYPE_VERSION_LATEST H5O_DTYPE_VERSION_3 +#define H5O_DTYPE_VERSION_LATEST H5O_DTYPE_VERSION_4 /* Flags for visiting datatype */ @@ -175,37 +180,52 @@ struct H5T_path_t { H5T_cdata_t cdata; /*data for this function */ }; +/* Reference function pointers */ +typedef size_t (*H5T_ref_getsizefunc_t)(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); +typedef herr_t (*H5T_ref_readfunc_t)(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); +typedef herr_t (*H5T_ref_writefunc_t)(H5F_t *src_f, const void *src_buf, size_t src_size, H5R_type_t src_type, H5F_t *dst_f, void *dst_buf, size_t dst_size, void *bg_buf); + +typedef struct H5T_ref_class_t { + H5T_ref_getsizefunc_t getsize; /* get reference size (bytes) */ + H5T_ref_readfunc_t read; /* read reference into buffer */ + H5T_ref_writefunc_t write; /* write reference from buffer */ +} H5T_ref_class_t; + typedef struct H5T_atomic_t { - H5T_order_t order; /*byte order */ - size_t prec; /*precision in bits */ - size_t offset; /*bit position of lsb of value */ - H5T_pad_t lsb_pad;/*type of lsb padding */ - H5T_pad_t msb_pad;/*type of msb padding */ + H5T_order_t order; /* byte order */ + size_t prec; /* precision in bits */ + size_t offset; /* bit position of lsb of value */ + H5T_pad_t lsb_pad; /* type of lsb padding */ + H5T_pad_t msb_pad; /* type of msb padding */ union { - struct { - H5T_sign_t sign; /*type of integer sign */ - } i; /*integer; integer types */ - - struct { - size_t sign; /*bit position of sign bit */ - size_t epos; /*position of lsb of exponent */ - size_t esize; /*size of exponent in bits */ - uint64_t ebias; /*exponent bias */ - size_t mpos; /*position of lsb of mantissa */ - size_t msize; /*size of mantissa */ - H5T_norm_t norm; /*normalization */ - H5T_pad_t pad; /*type of padding for internal bits */ - } f; /*floating-point types */ - - struct { - H5T_cset_t cset; /*character set */ - H5T_str_t pad; /*space or null padding of extra bytes */ - } s; /*string types */ - - struct { - H5R_type_t rtype; /*type of reference stored */ - H5T_loc_t loc; /* Location of data in buffer */ - } r; /*reference types */ + struct { + H5T_sign_t sign; /* type of integer sign */ + } i; /* integer; integer types */ + + struct { + size_t sign; /* bit position of sign bit */ + size_t epos; /* position of lsb of exponent */ + size_t esize; /* size of exponent in bits */ + uint64_t ebias; /* exponent bias */ + size_t mpos; /* position of lsb of mantissa */ + size_t msize; /* size of mantissa */ + H5T_norm_t norm; /* normalization */ + H5T_pad_t pad; /* type of padding for internal bits */ + } f; /* floating-point types */ + + struct { + H5T_cset_t cset; /* character set */ + H5T_str_t pad; /* space or null padding of extra bytes */ + } s; /* string types */ + + struct { + H5R_type_t rtype; /* type of reference stored */ + unsigned version; /* version of encoded reference */ + hbool_t opaque; /* opaque reference type */ + H5T_loc_t loc; /* location of data in buffer */ + H5F_t *f; /* file pointer (if data is on disk) */ + const H5T_ref_class_t *cls; /* Pointer to ref class callbacks */ + } r; /* reference types */ } u; } H5T_atomic_t; @@ -243,14 +263,6 @@ typedef struct H5T_enum_t { char **name; /*array of symbol names */ } H5T_enum_t; -/* VL function pointers */ -typedef ssize_t (*H5T_vlen_getlenfunc_t)(const void *vl_addr); -typedef void * (*H5T_vlen_getptrfunc_t)(void *vl_addr); -typedef htri_t (*H5T_vlen_isnullfunc_t)(const H5F_t *f, void *vl_addr); -typedef herr_t (*H5T_vlen_readfunc_t)(H5F_t *f, void *_vl, void *buf, size_t len); -typedef herr_t (*H5T_vlen_writefunc_t)(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size); -typedef herr_t (*H5T_vlen_setnullfunc_t)(H5F_t *f, void *_vl, void *_bg); - /* VL types */ typedef enum { H5T_VLEN_BADTYPE = -1, /* invalid VL Type */ @@ -259,20 +271,35 @@ typedef enum { H5T_VLEN_MAXTYPE /* highest type (Invalid as true type) */ } H5T_vlen_type_t; +/* VL function pointers */ +typedef herr_t (*H5T_vlen_getlen_func_t)(H5F_t *f, const void *vl_addr, size_t *len); +typedef void * (*H5T_vlen_getptr_func_t)(void *vl_addr); +typedef herr_t (*H5T_vlen_isnull_func_t)(const H5F_t *f, void *vl_addr, hbool_t *isnull); +typedef herr_t (*H5T_vlen_setnull_func_t)(H5F_t *f, void *_vl, void *_bg); +typedef herr_t (*H5T_vlen_read_func_t)(H5F_t *f, void *_vl, void *buf, size_t len); +typedef herr_t (*H5T_vlen_write_func_t)(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size); +typedef herr_t (*H5T_vlen_delete_func_t)(H5F_t *f, const void *_vl); + +/* VL datatype callbacks */ +typedef struct H5T_vlen_class_t { + H5T_vlen_getlen_func_t getlen; /* Function to get VL sequence size (in element units, not bytes) */ + H5T_vlen_getptr_func_t getptr; /* Function to get VL sequence pointer */ + H5T_vlen_isnull_func_t isnull; /* Function to check if VL value is NIL */ + H5T_vlen_setnull_func_t setnull;/* Function to set a VL value to NIL */ + H5T_vlen_read_func_t read; /* Function to read VL sequence into buffer */ + H5T_vlen_write_func_t write; /* Function to write VL sequence from buffer */ + H5T_vlen_delete_func_t del; /* Function to delete VL sequence */ +} H5T_vlen_class_t; + /* A VL datatype */ typedef struct H5T_vlen_t { H5T_vlen_type_t type; /* Type of VL data in buffer */ H5T_loc_t loc; /* Location of VL data in buffer */ - H5T_cset_t cset; /* For VL string. character set */ - H5T_str_t pad; /* For VL string. space or null padding of + H5T_cset_t cset; /* For VL string: character set */ + H5T_str_t pad; /* For VL string: space or null padding of * extra bytes */ H5F_t *f; /* File ID (if VL data is on disk) */ - H5T_vlen_getptrfunc_t getptr; /* Function to get VL sequence pointer */ - H5T_vlen_getlenfunc_t getlen; /* Function to get VL sequence size (in element units, not bytes) */ - H5T_vlen_isnullfunc_t isnull; /* Function to check if VL value is NIL */ - H5T_vlen_readfunc_t read; /* Function to read VL sequence into buffer */ - H5T_vlen_writefunc_t write; /* Function to write VL sequence from buffer */ - H5T_vlen_setnullfunc_t setnull; /* Function to set a VL value to NIL */ + const H5T_vlen_class_t *cls; /* Pointer to VL class callbacks */ } H5T_vlen_t; /* An opaque datatype */ @@ -371,6 +398,7 @@ H5_DLLVAR size_t H5T_POINTER_COMP_ALIGN_g; H5_DLLVAR size_t H5T_HVL_COMP_ALIGN_g; H5_DLLVAR size_t H5T_HOBJREF_COMP_ALIGN_g; H5_DLLVAR size_t H5T_HDSETREGREF_COMP_ALIGN_g; +H5_DLLVAR size_t H5T_REF_COMP_ALIGN_g; /* * Alignment information for native types. A value of N indicates that the @@ -483,6 +511,9 @@ H5_DLL herr_t H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, H5_DLL herr_t H5T__conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, size_t bkg_stride, void *buf, void *bkg); +H5_DLL herr_t H5T__conv_ref(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, + size_t nelmts, size_t buf_stride, + size_t bkg_stride, void *buf, void *bkg); H5_DLL herr_t H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, size_t bkg_stride, void *_buf, void *bkg); @@ -1149,6 +1180,9 @@ H5_DLL H5T_t *H5T__array_create(H5T_t *base, unsigned ndims, const hsize_t dim[/ H5_DLL int H5T__get_array_ndims(const H5T_t *dt); H5_DLL int H5T__get_array_dims(const H5T_t *dt, hsize_t dims[]); +/* Reference functions */ +H5_DLL htri_t H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc); + /* Compound functions */ H5_DLL herr_t H5T__insert(H5T_t *parent, const char *name, size_t offset, const H5T_t *member); diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index 3dcbb2c..13a0938 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -52,6 +52,9 @@ typedef struct H5T_t H5T_t; typedef struct H5T_stats_t H5T_stats_t; typedef struct H5T_path_t H5T_path_t; +/* Forward reference of H5S_t */ +struct H5S_t; + /* How to copy a datatype */ typedef enum H5T_copy_t { H5T_COPY_TRANSIENT, @@ -130,7 +133,10 @@ H5_DLL H5T_bkg_t H5T_path_bkg(const H5T_path_t *p); H5_DLL H5T_subset_info_t *H5T_path_compound_subset(const H5T_path_t *p); H5_DLL herr_t H5T_convert(H5T_path_t *tpath, hid_t src_id, hid_t dst_id, size_t nelmts, size_t buf_stride, size_t bkg_stride, void *buf, void *bkg); -H5_DLL herr_t H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned ndim, const hsize_t *point, void *_op_data); +H5_DLL herr_t H5T_reclaim(hid_t type_id, struct H5S_t *space, void *buf); +H5_DLL herr_t H5T_reclaim_cb(void *elem, const H5T_t *dt, unsigned ndim, const hsize_t *point, void *op_data); +H5_DLL herr_t H5T_ref_reclaim(void *elem, const H5T_t *dt); +H5_DLL herr_t H5T_vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info); H5_DLL herr_t H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt); H5_DLL htri_t H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc); H5_DLL htri_t H5T_is_sensible(const H5T_t *dt); diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index fc3e4ee..0ec0c73 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -262,8 +262,9 @@ H5_DLLVAR hid_t H5T_IEEE_F64LE_g; #define H5T_STD_B32LE (H5OPEN H5T_STD_B32LE_g) #define H5T_STD_B64BE (H5OPEN H5T_STD_B64BE_g) #define H5T_STD_B64LE (H5OPEN H5T_STD_B64LE_g) -#define H5T_STD_REF_OBJ (H5OPEN H5T_STD_REF_OBJ_g) +#define H5T_STD_REF_OBJ (H5OPEN H5T_STD_REF_OBJ_g) #define H5T_STD_REF_DSETREG (H5OPEN H5T_STD_REF_DSETREG_g) +#define H5T_STD_REF (H5OPEN H5T_STD_REF_g) H5_DLLVAR hid_t H5T_STD_I8BE_g; H5_DLLVAR hid_t H5T_STD_I8LE_g; H5_DLLVAR hid_t H5T_STD_I16BE_g; @@ -290,6 +291,7 @@ H5_DLLVAR hid_t H5T_STD_B64BE_g; H5_DLLVAR hid_t H5T_STD_B64LE_g; H5_DLLVAR hid_t H5T_STD_REF_OBJ_g; H5_DLLVAR hid_t H5T_STD_REF_DSETREG_g; +H5_DLLVAR hid_t H5T_STD_REF_g; /* * Types which are particular to Unix. @@ -591,6 +593,7 @@ H5_DLL H5T_conv_t H5Tfind(hid_t src_id, hid_t dst_id, H5T_cdata_t **pcdata); H5_DLL htri_t H5Tcompiler_conv(hid_t src_id, hid_t dst_id); H5_DLL herr_t H5Tconvert(hid_t src_id, hid_t dst_id, size_t nelmts, void *buf, void *background, hid_t plist_id); +H5_DLL herr_t H5Treclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *buf); /* Symbols defined for compatibility with previous versions of the HDF5 API. * diff --git a/src/H5Tref.c b/src/H5Tref.c new file mode 100644 index 0000000..6f7bf90 --- /dev/null +++ b/src/H5Tref.c @@ -0,0 +1,761 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * 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. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Module Info: This module contains the functionality for reference + * datatypes in the H5T interface. + */ + +#include "H5Tmodule.h" /* This source code file is part of the H5T module */ +#define H5F_FRIEND /*suppress error about including H5Fpkg */ +#define H5R_FRIEND /*suppress error about including H5Rpkg */ + +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Iprivate.h" /* IDs */ +#include "H5Fpkg.h" /* File */ +#include "H5Rpkg.h" /* References */ +#include "H5Tpkg.h" /* Datatypes */ + +/****************/ +/* Local Macros */ +/****************/ + +#define H5T_REF_MEM_SIZE (H5R_REF_BUF_SIZE) +#define H5T_REF_OBJ_MEM_SIZE (H5R_OBJ_REF_BUF_SIZE) +#define H5T_REF_DSETREG_MEM_SIZE (H5R_DSET_REG_REF_BUF_SIZE) + +#define H5T_REF_OBJ_DISK_SIZE(f) (H5F_SIZEOF_ADDR(f)) +#define H5T_REF_DSETREG_DISK_SIZE(f) (H5HG_HEAP_ID_SIZE(f)) + +/******************/ +/* Local Typedefs */ +/******************/ + +/* For region compatibility support */ +struct H5Tref_dsetreg { + haddr_t obj_addr; /* Object address */ + H5S_t *space; /* Dataspace */ +}; + +/********************/ +/* Local Prototypes */ +/********************/ + +static size_t H5T__ref_mem_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); +static herr_t H5T__ref_mem_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); +static herr_t H5T__ref_mem_write(H5F_t *src_f, const void *src_buf, size_t src_size, H5R_type_t src_type, H5F_t *dst_f, void *dst_buf, size_t dst_size, void *bg_buf); + +static size_t H5T__ref_disk_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); +static herr_t H5T__ref_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); +static herr_t H5T__ref_disk_write(H5F_t *src_f, const void *src_buf, size_t src_size, H5R_type_t src_type, H5F_t *dst_f, void *dst_buf, size_t dst_size, void *bg_buf); + +/* For compatibility */ +static size_t H5T__ref_obj_disk_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); +static herr_t H5T__ref_obj_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); + +static size_t H5T__ref_dsetreg_disk_getsize(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, hbool_t *dst_copy); +static herr_t H5T__ref_dsetreg_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, H5F_t *dst_f, void *dst_buf, size_t dst_size); + +/*******************/ +/* Local Variables */ +/*******************/ + +/* Class for reference in memory */ +static const H5T_ref_class_t H5T_ref_mem_g = { + H5T__ref_mem_getsize, /* 'getsize' */ + H5T__ref_mem_read, /* 'read' */ + H5T__ref_mem_write /* 'write' */ +}; + +static const H5T_ref_class_t H5T_ref_disk_g = { + H5T__ref_disk_getsize, /* 'getsize' */ + H5T__ref_disk_read, /* 'read' */ + H5T__ref_disk_write /* 'write' */ +}; + +static const H5T_ref_class_t H5T_ref_obj_disk_g = { + H5T__ref_obj_disk_getsize, /* 'getsize' */ + H5T__ref_obj_disk_read, /* 'read' */ + NULL /* 'write' */ +}; + +static const H5T_ref_class_t H5T_ref_dsetreg_disk_g = { + H5T__ref_dsetreg_disk_getsize, /* 'getsize' */ + H5T__ref_dsetreg_disk_read, /* 'read' */ + NULL /* 'write' */ +}; + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_set_loc + * + * Purpose: Sets the location of a reference datatype to be either on disk + * or in memory + * + * Return: + * One of two values on success: + * TRUE - If the location of any reference types changed + * FALSE - If the location of any reference types is the same + * Negative value is returned on failure + * + *------------------------------------------------------------------------- + */ +htri_t +H5T__ref_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) +{ + htri_t ret_value = FALSE; /* Indicate success, but no location change */ + + FUNC_ENTER_PACKAGE + + HDassert(dt); + /* f is NULL when loc == H5T_LOC_MEMORY */ + HDassert(loc >= H5T_LOC_BADLOC && loc < H5T_LOC_MAXLOC); + + /* Only change the location if it's different */ + if(loc == dt->shared->u.atomic.u.r.loc && f == dt->shared->u.atomic.u.r.f) + HGOTO_DONE(FALSE) + + switch(loc) { + case H5T_LOC_MEMORY: /* Memory based reference datatype */ + HDassert(NULL == f); + + /* Mark this type as being stored in memory */ + dt->shared->u.atomic.u.r.loc = H5T_LOC_MEMORY; + + /* Reset file ID (since this reference is in memory) */ + dt->shared->u.atomic.u.r.f = f; /* f is NULL */ + + if(dt->shared->u.atomic.u.r.opaque) { + /* Size in memory, disk size is different */ + dt->shared->size = H5T_REF_MEM_SIZE; + dt->shared->u.atomic.prec = 8 * dt->shared->size; + + /* Set up the function pointers to access the reference in memory */ + dt->shared->u.atomic.u.r.cls = &H5T_ref_mem_g; + + } else if(dt->shared->u.atomic.u.r.rtype == H5R_OBJECT1) { + /* Size in memory, disk size is different */ + dt->shared->size = H5T_REF_OBJ_MEM_SIZE; + dt->shared->u.atomic.prec = 8 * dt->shared->size; + + /* Unused for now */ + dt->shared->u.atomic.u.r.cls = NULL; + + } else if(dt->shared->u.atomic.u.r.rtype == H5R_DATASET_REGION1) { + /* Size in memory, disk size is different */ + dt->shared->size = H5T_REF_DSETREG_MEM_SIZE; + dt->shared->u.atomic.prec = 8 * dt->shared->size; + + /* Unused for now */ + dt->shared->u.atomic.u.r.cls = NULL; + + } + break; + + case H5T_LOC_DISK: /* Disk based reference datatype */ + HDassert(f); + + /* Mark this type as being stored on disk */ + dt->shared->u.atomic.u.r.loc = H5T_LOC_DISK; + + /* Set file pointer (since this reference is on disk) */ + dt->shared->u.atomic.u.r.f = f; + + if(dt->shared->u.atomic.u.r.rtype == H5R_OBJECT1) { + /* Size on disk, memory size is different */ + dt->shared->size = H5T_REF_OBJ_DISK_SIZE(f); + dt->shared->u.atomic.prec = 8 * dt->shared->size; + + /* Set up the function pointers to access the reference in memory */ + dt->shared->u.atomic.u.r.cls = &H5T_ref_obj_disk_g; + + } else if(dt->shared->u.atomic.u.r.rtype == H5R_DATASET_REGION1) { + /* Size on disk, memory size is different */ + dt->shared->size = H5T_REF_DSETREG_DISK_SIZE(f); + dt->shared->u.atomic.prec = 8 * dt->shared->size; + + /* Set up the function pointers to access the reference in memory */ + dt->shared->u.atomic.u.r.cls = &H5T_ref_dsetreg_disk_g; + + } else { + H5VL_file_cont_info_t cont_info = {H5VL_CONTAINER_INFO_VERSION, 0, 0, 0}; + size_t ref_encode_size; + H5R_ref_priv_t fixed_ref; + + /* Get container info */ + if(H5F__get_cont_info(f, &cont_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get file container info") + + /* Retrieve min encode size (when references have no vlen part) */ + HDmemset(&fixed_ref, 0, sizeof(fixed_ref)); + fixed_ref.type = (int8_t)H5R_OBJECT2; + fixed_ref.token_size = (uint8_t)cont_info.token_size; + if(H5R__encode(NULL, &fixed_ref, NULL, &ref_encode_size, 0) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "can't get encode size") + + /* Size on disk, memory size is different */ + dt->shared->size = MAX(H5_SIZEOF_UINT32_T + + H5R_ENCODE_HEADER_SIZE + cont_info.blob_id_size, + ref_encode_size); + dt->shared->u.atomic.prec = 8 * dt->shared->size; + + /* Set up the function pointers to access the information on + * disk. Region and attribute references are stored identically + * on disk, so use the same functions. + */ + dt->shared->u.atomic.u.r.cls = &H5T_ref_disk_g; + + } + break; + + case H5T_LOC_BADLOC: + /* Allow undefined location. In H5Odtype.c, H5O_dtype_decode sets undefined + * location for reference type and leaves it for the caller to decide. + */ + dt->shared->u.atomic.u.r.loc = H5T_LOC_BADLOC; + + /* Reset file pointer */ + dt->shared->u.atomic.u.r.f = NULL; + + /* Reset the function pointers */ + dt->shared->u.atomic.u.r.cls = NULL; + + break; + + case H5T_LOC_MAXLOC: + /* MAXLOC is invalid */ + default: + HGOTO_ERROR(H5E_DATATYPE, H5E_BADRANGE, FAIL, "invalid reference datatype location") + } /* end switch */ + + /* Indicate that the location changed */ + ret_value = TRUE; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_set_loc() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_mem_getsize + * + * Purpose: Retrieves the size of a memory based reference. + * + * Return: Non-negative on success/zero on failure + * + *------------------------------------------------------------------------- + */ +static size_t +H5T__ref_mem_getsize(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, + size_t H5_ATTR_UNUSED src_size, H5F_t *dst_f, hbool_t *dst_copy) +{ + void *vol_obj = NULL; + const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf; + unsigned flags = 0; + size_t ret_value = 0; + + FUNC_ENTER_STATIC + + HDassert(src_buf); + HDassert(src_size == H5T_REF_MEM_SIZE); + + /* Retrieve VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier") + + /* Retrieve file from VOL object */ + if(NULL == (src_f = (H5F_t *)H5VL_object_data(vol_obj))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + + /* Set external flag if referenced file is not destination file */ + flags |= (src_f->shared != dst_f->shared) ? H5R_IS_EXTERNAL : 0; + + /* Force re-calculating encoding size if any flags are set */ + if(flags || !src_ref->encode_size) { + /* Pass the correct encoding version for the selection depending on the + * file libver bounds, this is later retrieved in H5S hyper encode */ + if(src_ref->type == (int8_t)H5R_DATASET_REGION2) + H5CX_set_libver_bounds(dst_f); + + /* Determine encoding size */ + if(H5R__encode(H5F_ACTUAL_NAME(src_f), src_ref, NULL, &ret_value, flags) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, 0, "unable to determine encoding size") + } else { + /* Can do a direct copy and skip blob decoding */ + if(src_ref->type == (int8_t)H5R_OBJECT2) + *dst_copy = TRUE; + + /* Get cached encoding size */ + ret_value = src_ref->encode_size; + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_mem_getsize() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_mem_read + * + * Purpose: "Reads" the memory based reference into a buffer + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__ref_mem_read(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, + size_t H5_ATTR_UNUSED src_size, H5F_t *dst_f, void *dst_buf, + size_t dst_size) +{ + void *vol_obj = NULL; + const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf; + unsigned flags = 0; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_buf); + HDassert(src_size == H5T_REF_MEM_SIZE); + HDassert(dst_f); + HDassert(dst_buf); + HDassert(dst_size); + + /* Retrieve VOL object */ + if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier") + + /* Retrieve file from VOL object */ + if(NULL == (src_f = (H5F_t *)H5VL_object_data(vol_obj))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + + /* Set external flag if referenced file is not destination file */ + flags |= (src_f->shared != dst_f->shared) ? H5R_IS_EXTERNAL : 0; + + /* Pass the correct encoding version for the selection depending on the + * file libver bounds, this is later retrieved in H5S hyper encode */ + if(src_ref->type == (int8_t)H5R_DATASET_REGION2) + H5CX_set_libver_bounds(dst_f); + + /* Encode reference */ + if(H5R__encode(H5F_ACTUAL_NAME(src_f), src_ref, dst_buf, &dst_size, flags) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "Cannot encode reference") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_mem_read() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_mem_write + * + * Purpose: "Writes" the memory reference from a buffer + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__ref_mem_write(H5F_t *src_f, const void *src_buf, size_t src_size, + H5R_type_t src_type, H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, + size_t dst_size, void H5_ATTR_UNUSED *bg_buf) +{ + hid_t file_id = H5I_INVALID_HID; + H5R_ref_priv_t *dst_ref = (H5R_ref_priv_t *)dst_buf; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_f); + HDassert(src_buf); + HDassert(src_size); + HDassert(dst_buf); + HDassert(dst_size == H5T_REF_MEM_SIZE); + + /* Make sure reference buffer is correctly initialized */ + HDmemset(dst_buf, 0, dst_size); + + switch(src_type) { + case H5R_OBJECT1: { + if(H5R__create_object((const H5VL_token_t *)src_buf, sizeof(haddr_t), dst_ref) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create object reference") + } + break; + case H5R_DATASET_REGION1: { + const struct H5Tref_dsetreg *src_reg = (const struct H5Tref_dsetreg *)src_buf; + + if(H5R__create_region((const H5VL_token_t *)&src_reg->obj_addr, sizeof(src_reg->obj_addr), src_reg->space, dst_ref) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create region reference") + /* create_region creates its internal copy of the space */ + if(H5S_close(src_reg->space) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTFREE, FAIL, "Cannot close dataspace") + } + break; + case H5R_DATASET_REGION2: + /* Pass the correct encoding version for the selection depending on the + * file libver bounds, this is later retrieved in H5S hyper decode */ + H5CX_set_libver_bounds(src_f); + H5_ATTR_FALLTHROUGH + case H5R_OBJECT2: + case H5R_ATTR: + /* Decode reference */ + if(H5R__decode((const unsigned char *)src_buf, &src_size, dst_ref) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Cannot decode reference") + break; + case H5R_BADTYPE: + case H5R_MAXTYPE: + default: + HDassert("unknown reference type" && 0); + HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)") + } + + /* If no filename set, this is not an external reference */ + if(NULL == H5R_REF_FILENAME(dst_ref)) { + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(src_f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + + /* Attach loc ID to reference and hold reference to it */ + if(H5R__set_loc_id(dst_ref, file_id, TRUE) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTSET, FAIL, "unable to attach location id to reference") + } + +done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_REFERENCE, H5E_CANTDEC, FAIL, "unable to decrement refcount on location id") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_mem_write() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_disk_getsize + * + * Purpose: Retrieves the length of a disk based reference. + * + * Return: Non-negative value (cannot fail) + * + *------------------------------------------------------------------------- + */ +static size_t +H5T__ref_disk_getsize(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, + size_t src_size, H5F_t H5_ATTR_UNUSED *dst_f, hbool_t *dst_copy) +{ + const uint8_t *p = (const uint8_t *)src_buf; + unsigned flags; + H5R_type_t ref_type; + size_t ret_value = 0; + + FUNC_ENTER_STATIC + + HDassert(src_buf); + + /* Set reference type */ + ref_type = (H5R_type_t)*p++; + if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid reference type") + + /* Set flags */ + flags = (unsigned)*p++; + + if(!(flags & H5R_IS_EXTERNAL) && (ref_type == H5R_OBJECT2)) { + /* Can do a direct copy and skip blob decoding */ + *dst_copy = TRUE; + + ret_value = src_size; + } else { + /* Retrieve encoded data size */ + UINT32DECODE(p, ret_value); + + /* Add size of the header */ + ret_value += H5R_ENCODE_HEADER_SIZE; + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_disk_getsize() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_disk_read + * + * Purpose: Reads the disk based reference into a buffer + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__ref_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, + H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, size_t dst_size) +{ + H5VL_object_t *vol_obj = NULL; /* Object info */ + hid_t file_id = H5I_INVALID_HID; + const uint8_t *p = (const uint8_t *)src_buf; + uint8_t *q = (uint8_t *)dst_buf; + size_t buf_size_left = src_size; + size_t expected_size = dst_size; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_f); + HDassert(src_buf); + HDassert(dst_buf); + HDassert(dst_size); + + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(src_f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") + + /* Copy header manually */ + HDmemcpy(q, p, H5R_ENCODE_HEADER_SIZE); + p += H5R_ENCODE_HEADER_SIZE; + q += H5R_ENCODE_HEADER_SIZE; + expected_size -= H5R_ENCODE_HEADER_SIZE; + + /* Skip the length of the sequence */ + p += H5_SIZEOF_UINT32_T; + HDassert(buf_size_left > H5_SIZEOF_UINT32_T); + buf_size_left -= H5_SIZEOF_UINT32_T; + + /* Retrieve blob */ + if(H5VL_blob_get(vol_obj, p, q, &dst_size, NULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get blob") + if(dst_size != expected_size) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "Expected data size does not match") + +done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_disk_read() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_disk_write + * + * Purpose: Writes the disk based reference from a buffer + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__ref_disk_write(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, + size_t src_size, H5R_type_t H5_ATTR_UNUSED src_type, H5F_t *dst_f, + void *dst_buf, size_t dst_size, void *bg_buf) +{ + H5VL_object_t *vol_obj = NULL; /* Object info */ + hid_t file_id = H5I_INVALID_HID; + const uint8_t *p = (const uint8_t *)src_buf; + uint8_t *q = (uint8_t *)dst_buf; + size_t buf_size_left = dst_size; + uint8_t *p_bg = (uint8_t *)bg_buf; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_buf); + HDassert(src_size); + HDassert(dst_f); + HDassert(dst_buf); + + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(dst_f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") + + /* TODO Should get rid of bg stuff */ + if(p_bg) { + size_t p_buf_size_left = dst_size; + + /* Skip the length of the reference */ + p_bg += H5_SIZEOF_UINT32_T; + HDassert(p_buf_size_left > H5_SIZEOF_UINT32_T); + p_buf_size_left -= H5_SIZEOF_UINT32_T; + + /* Remove blob for old data */ + if(H5VL_blob_specific(vol_obj, (void *)p_bg, H5VL_BLOB_DELETE) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to delete blob") + } /* end if */ + + /* Copy header manually so that it does not get encoded into the blob */ + HDmemcpy(q, p, H5R_ENCODE_HEADER_SIZE); + p += H5R_ENCODE_HEADER_SIZE; + q += H5R_ENCODE_HEADER_SIZE; + src_size -= H5R_ENCODE_HEADER_SIZE; + buf_size_left -= H5_SIZEOF_UINT32_T; + + /* Set the size */ + UINT32ENCODE(q, src_size); + HDassert(buf_size_left > H5_SIZEOF_UINT32_T); + buf_size_left -= H5_SIZEOF_UINT32_T; + + /* Store blob */ + if(H5VL_blob_put(vol_obj, p, src_size, q, NULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to put blob") + +done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_disk_write() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_obj_disk_getsize + * + * Purpose: Retrieves the length of a disk based reference. + * + * Return: Non-negative value (cannot fail) + * + *------------------------------------------------------------------------- + */ +static size_t +H5T__ref_obj_disk_getsize(H5F_t H5_ATTR_UNUSED *src_f, + const void H5_ATTR_UNUSED *src_buf, size_t H5_ATTR_UNUSED src_size, + H5F_t H5_ATTR_UNUSED *dst_f, hbool_t H5_ATTR_UNUSED *dst_copy) +{ + size_t ret_value = sizeof(haddr_t); + + FUNC_ENTER_STATIC_NOERR + + HDassert(src_buf); + HDassert(src_size == H5T_REF_OBJ_DISK_SIZE(src_f)); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_obj_disk_getsize() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_obj_disk_read + * + * Purpose: Reads the disk based reference into a buffer + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__ref_obj_disk_read(H5F_t H5_ATTR_UNUSED *src_f, const void *src_buf, + size_t src_size, H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, + size_t H5_ATTR_UNUSED dst_size) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_f); + HDassert(src_buf); + HDassert(src_size == H5T_REF_OBJ_DISK_SIZE(src_f)); + HDassert(dst_buf); + HDassert(dst_size == sizeof(haddr_t)); + + /* Get object address */ + if(H5R__decode_addr_obj_compat((const unsigned char *)src_buf, &src_size, (haddr_t *)dst_buf) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, H5I_INVALID_HID, "unable to get object address") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_obj_disk_read() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_dsetreg_disk_getsize + * + * Purpose: Retrieves the length of a disk based reference. + * + * Return: Non-negative value (cannot fail) + * + *------------------------------------------------------------------------- + */ +static size_t +H5T__ref_dsetreg_disk_getsize(H5F_t H5_ATTR_UNUSED *f, + const void H5_ATTR_UNUSED *buf, size_t H5_ATTR_UNUSED buf_size, + H5F_t H5_ATTR_UNUSED *dst_f, hbool_t H5_ATTR_UNUSED *dst_copy) +{ + size_t ret_value = sizeof(struct H5Tref_dsetreg); + + FUNC_ENTER_STATIC_NOERR + + HDassert(buf); + HDassert(buf_size == H5T_REF_DSETREG_DISK_SIZE(f)); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_dsetreg_disk_getsize() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__ref_dsetreg_disk_read + * + * Purpose: Reads the disk based reference into a buffer + * + * Return: Non-negative on success/Negative on failure + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__ref_dsetreg_disk_read(H5F_t *src_f, const void *src_buf, size_t src_size, + H5F_t H5_ATTR_UNUSED *dst_f, void *dst_buf, size_t H5_ATTR_UNUSED dst_size) +{ + struct H5Tref_dsetreg *dst_reg = (struct H5Tref_dsetreg *)dst_buf; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + + HDassert(src_f); + HDassert(src_buf); + HDassert(src_size == H5T_REF_DSETREG_DISK_SIZE(src_f)); + HDassert(dst_buf); + HDassert(dst_size == sizeof(struct H5Tref_dsetreg)); + + /* Retrieve object address and space */ + if(H5R__decode_addr_region_compat(src_f, (const unsigned char *)src_buf, &src_size, &dst_reg->obj_addr, &dst_reg->space) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTDECODE, FAIL, "unable to get object address") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__ref_dsetreg_disk_read() */ + + +/*------------------------------------------------------------------------- + * Function: H5T_ref_reclaim + * + * Purpose: Internal routine to free reference datatypes + * + * Return: Non-negative on success / Negative on failure + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_ref_reclaim(void *elem, const H5T_t *dt) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity checks */ + HDassert(elem); + HDassert(dt && (dt->shared->type == H5T_REFERENCE)); + + if(dt->shared->u.atomic.u.r.opaque + && (H5R__destroy((H5R_ref_priv_t *)elem) < 0)) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTFREE, FAIL, "cannot free reference") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_ref_reclaim() */ diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index bafb47f..0253b01 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -16,41 +16,119 @@ * datatypes in the H5T interface. */ -#include "H5Tmodule.h" /* This source code file is part of the H5T module */ - +/****************/ +/* Module Setup */ +/****************/ -#include "H5private.h" /* Generic Functions */ -#include "H5CXprivate.h" /* API Contexts */ -#include "H5Dprivate.h" /* Dataset functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5HGprivate.h" /* Global Heaps */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Pprivate.h" /* Property lists */ -#include "H5Tpkg.h" /* Datatypes */ - -/* Local functions */ -static herr_t H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, void *free_info); -static ssize_t H5T_vlen_seq_mem_getlen(const void *_vl); -static void * H5T_vlen_seq_mem_getptr(void *_vl); -static htri_t H5T_vlen_seq_mem_isnull(const H5F_t *f, void *_vl); -static herr_t H5T_vlen_seq_mem_read(H5F_t *f, void *_vl, void *_buf, size_t len); -static herr_t H5T_vlen_seq_mem_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T_vlen_seq_mem_setnull(H5F_t *f, void *_vl, void *_bg); -static ssize_t H5T_vlen_str_mem_getlen(const void *_vl); -static void * H5T_vlen_str_mem_getptr(void *_vl); -static htri_t H5T_vlen_str_mem_isnull(const H5F_t *f, void *_vl); -static herr_t H5T_vlen_str_mem_read(H5F_t *f, void *_vl, void *_buf, size_t len); -static herr_t H5T_vlen_str_mem_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T_vlen_str_mem_setnull(H5F_t *f, void *_vl, void *_bg); -static ssize_t H5T_vlen_disk_getlen(const void *_vl); -static void * H5T_vlen_disk_getptr(void *_vl); -static htri_t H5T_vlen_disk_isnull(const H5F_t *f, void *_vl); -static herr_t H5T_vlen_disk_read(H5F_t *f, void *_vl, void *_buf, size_t len); -static herr_t H5T_vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); -static herr_t H5T_vlen_disk_setnull(H5F_t *f, void *_vl, void *_bg); - -/* Local variables */ +#include "H5Tmodule.h" /* This source code file is part of the H5T module */ +#define H5F_FRIEND /*suppress error about including H5Fpkg */ + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fpkg.h" /* File */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Tpkg.h" /* Datatypes */ + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + +/* Memory-based VL sequence callbacks */ +static herr_t H5T__vlen_mem_seq_getlen(H5F_t *f, const void *_vl, size_t *len); +static void * H5T__vlen_mem_seq_getptr(void *_vl); +static herr_t H5T__vlen_mem_seq_isnull(const H5F_t *f, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_mem_seq_setnull(H5F_t *f, void *_vl, void *_bg); +static herr_t H5T__vlen_mem_seq_read(H5F_t *f, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_mem_seq_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); + +/* Memory-based VL string callbacks */ +static herr_t H5T__vlen_mem_str_getlen(H5F_t *f, const void *_vl, size_t *len); +static void * H5T__vlen_mem_str_getptr(void *_vl); +static herr_t H5T__vlen_mem_str_isnull(const H5F_t *f, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_mem_str_setnull(H5F_t *f, void *_vl, void *_bg); +static herr_t H5T__vlen_mem_str_read(H5F_t *f, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_mem_str_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); + +/* Disk-based VL sequence (and string) callbacks */ +static herr_t H5T__vlen_disk_getlen(H5F_t *f, const void *_vl, size_t *len); +static herr_t H5T__vlen_disk_isnull(const H5F_t *f, void *_vl, hbool_t *isnull); +static herr_t H5T__vlen_disk_setnull(H5F_t *f, void *_vl, void *_bg); +static herr_t H5T__vlen_disk_read(H5F_t *f, void *_vl, void *_buf, size_t len); +static herr_t H5T__vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *_buf, void *_bg, size_t seq_len, size_t base_size); +static herr_t H5T__vlen_disk_delete(H5F_t *f, const void *_vl); + + +/*********************/ +/* Public Variables */ +/*********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + +/* Class for VL sequences in memory */ +static const H5T_vlen_class_t H5T_vlen_mem_seq_g = { + H5T__vlen_mem_seq_getlen, /* 'getlen' */ + H5T__vlen_mem_seq_getptr, /* 'getptr' */ + H5T__vlen_mem_seq_isnull, /* 'isnull' */ + H5T__vlen_mem_seq_setnull, /* 'setnull' */ + H5T__vlen_mem_seq_read, /* 'read' */ + H5T__vlen_mem_seq_write, /* 'write' */ + NULL /* 'delete' */ +}; + +/* Class for VL strings in memory */ +static const H5T_vlen_class_t H5T_vlen_mem_str_g = { + H5T__vlen_mem_str_getlen, /* 'getlen' */ + H5T__vlen_mem_str_getptr, /* 'getptr' */ + H5T__vlen_mem_str_isnull, /* 'isnull' */ + H5T__vlen_mem_str_setnull, /* 'setnull' */ + H5T__vlen_mem_str_read, /* 'read' */ + H5T__vlen_mem_str_write, /* 'write' */ + NULL /* 'delete' */ +}; + +/* Class for both VL strings and sequences in file */ +static const H5T_vlen_class_t H5T_vlen_disk_g = { + H5T__vlen_disk_getlen, /* 'getlen' */ + NULL, /* 'getptr' */ + H5T__vlen_disk_isnull, /* 'isnull' */ + H5T__vlen_disk_setnull, /* 'setnull' */ + H5T__vlen_disk_read, /* 'read' */ + H5T__vlen_disk_write, /* 'write' */ + H5T__vlen_disk_delete /* 'delete' */ +}; @@ -194,32 +272,21 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) dt->shared->u.vlen.loc = H5T_LOC_MEMORY; if(dt->shared->u.vlen.type == H5T_VLEN_SEQUENCE) { - /* size in memory, disk size is different */ + /* Size in memory, disk size is different */ dt->shared->size = sizeof(hvl_t); /* Set up the function pointers to access the VL sequence in memory */ - dt->shared->u.vlen.getlen = H5T_vlen_seq_mem_getlen; - dt->shared->u.vlen.getptr = H5T_vlen_seq_mem_getptr; - dt->shared->u.vlen.isnull = H5T_vlen_seq_mem_isnull; - dt->shared->u.vlen.read = H5T_vlen_seq_mem_read; - dt->shared->u.vlen.write = H5T_vlen_seq_mem_write; - dt->shared->u.vlen.setnull = H5T_vlen_seq_mem_setnull; - } + dt->shared->u.vlen.cls = &H5T_vlen_mem_seq_g; + } /* end if */ else if(dt->shared->u.vlen.type == H5T_VLEN_STRING) { - /* size in memory, disk size is different */ + /* Size in memory, disk size is different */ dt->shared->size = sizeof(char *); /* Set up the function pointers to access the VL string in memory */ - dt->shared->u.vlen.getlen = H5T_vlen_str_mem_getlen; - dt->shared->u.vlen.getptr = H5T_vlen_str_mem_getptr; - dt->shared->u.vlen.isnull = H5T_vlen_str_mem_isnull; - dt->shared->u.vlen.read = H5T_vlen_str_mem_read; - dt->shared->u.vlen.write = H5T_vlen_str_mem_write; - dt->shared->u.vlen.setnull = H5T_vlen_str_mem_setnull; - } - else { + dt->shared->u.vlen.cls = &H5T_vlen_mem_str_g; + } /* end else-if */ + else HDassert(0 && "Invalid VL type"); - } /* Reset file ID (since this VL is in memory) */ dt->shared->u.vlen.f = NULL; @@ -234,18 +301,13 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) /* * Size of element on disk is 4 bytes for the length, plus the size * of an address in this file, plus 4 bytes for the size of a heap - * ID. Memory size is different + * ID. Memory size is different. */ dt->shared->size = 4 + (size_t)H5F_SIZEOF_ADDR(f) + 4; /* Set up the function pointers to access the VL information on disk */ /* VL sequences and VL strings are stored identically on disk, so use the same functions */ - dt->shared->u.vlen.getlen = H5T_vlen_disk_getlen; - dt->shared->u.vlen.getptr = H5T_vlen_disk_getptr; - dt->shared->u.vlen.isnull = H5T_vlen_disk_isnull; - dt->shared->u.vlen.read = H5T_vlen_disk_read; - dt->shared->u.vlen.write = H5T_vlen_disk_write; - dt->shared->u.vlen.setnull = H5T_vlen_disk_setnull; + dt->shared->u.vlen.cls = &H5T_vlen_disk_g; /* Set file ID (since this VL is on disk) */ dt->shared->u.vlen.f = f; @@ -255,6 +317,13 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) /* Allow undefined location. In H5Odtype.c, H5O_dtype_decode sets undefined * location for VL type and leaves it for the caller to decide. */ + dt->shared->u.vlen.loc = H5T_LOC_BADLOC; + + /* Reset the function pointers to access the VL information */ + dt->shared->u.vlen.cls = NULL; + + /* Reset file pointer */ + dt->shared->u.vlen.f = NULL; break; case H5T_LOC_MAXLOC: @@ -269,11 +338,11 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T__vlen_set_loc() */ +} /* end H5T__vlen_set_loc() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_getlen + * Function: H5T__vlen_mem_seq_getlen * * Purpose: Retrieves the length of a memory based VL element. * @@ -284,33 +353,35 @@ done: * *------------------------------------------------------------------------- */ -static ssize_t -H5T_vlen_seq_mem_getlen(const void *_vl) +static herr_t +H5T__vlen_mem_seq_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters, return result */ -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - HDassert(vl); + /* Check parameter */ + HDassert(_vl); + HDassert(len); - FUNC_LEAVE_NOAPI((ssize_t)vl->len) +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + *len = vl->len; #else - HDassert(_vl); H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); - FUNC_LEAVE_NOAPI((ssize_t)vl.len) + *len = vl.len; #endif -} /* end H5T_vlen_seq_mem_getlen() */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_seq_getlen() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_getptr + * Function: H5T__vlen_mem_seq_getptr * * Purpose: Retrieves the pointer for a memory based VL element. * @@ -322,15 +393,15 @@ H5T_vlen_seq_mem_getlen(const void *_vl) *------------------------------------------------------------------------- */ static void * -H5T_vlen_seq_mem_getptr(void *_vl) +H5T__vlen_mem_seq_getptr(void *_vl) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters, return result */ #ifdef H5_NO_ALIGNMENT_RESTRICTIONS @@ -343,48 +414,82 @@ H5T_vlen_seq_mem_getptr(void *_vl) FUNC_LEAVE_NOAPI(vl.p) #endif -} /* end H5T_vlen_seq_mem_getptr() */ +} /* end H5T__vlen_mem_seq_getptr() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_isnull + * Function: H5T__vlen_mem_seq_isnull * * Purpose: Checks if a memory sequence is the "null" sequence * - * Return: TRUE/FALSE on success/Negative on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static htri_t -H5T_vlen_seq_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) +static herr_t +H5T__vlen_mem_seq_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl, hbool_t *isnull) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters, return result */ -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - HDassert(vl); + /* Check parameters */ + HDassert(_vl); - FUNC_LEAVE_NOAPI((vl->len==0 || vl->p==NULL) ? TRUE : FALSE) +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + *isnull = ((vl->len == 0 || vl->p == NULL) ? TRUE : FALSE); #else - HDassert(_vl); H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); - FUNC_LEAVE_NOAPI((vl.len==0 || vl.p==NULL) ? TRUE : FALSE) + *isnull = ((vl.len == 0 || vl.p == NULL) ? TRUE : FALSE); #endif -} /* end H5T_vlen_seq_mem_isnull() */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_seq_isnull() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__vlen_mem_seq_setnull + * + * Purpose: Sets a VL info object in memory to the "nil" value + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Saturday, November 8, 2003 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__vlen_mem_seq_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED *_bg) +{ + hvl_t vl; /* Temporary hvl_t to use during operation */ + + FUNC_ENTER_STATIC_NOERR + + /* check parameters */ + HDassert(_vl); + + /* Set the "nil" hvl_t */ + vl.len = 0; + vl.p = NULL; + + /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ + H5MM_memcpy(_vl, &vl, sizeof(hvl_t)); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_seq_setnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_read + * Function: H5T__vlen_mem_seq_read * * Purpose: "Reads" the memory based VL sequence into a buffer * @@ -396,36 +501,36 @@ H5T_vlen_seq_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_seq_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) +H5T__vlen_mem_seq_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const hvl_t *vl=(const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ + const hvl_t *vl = (const hvl_t *)_vl; /* Pointer to the user's hvl_t information */ #else hvl_t vl; /* User's hvl_t information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters, copy data */ HDassert(buf); #ifdef H5_NO_ALIGNMENT_RESTRICTIONS HDassert(vl && vl->p); - H5MM_memcpy(buf,vl->p,len); + H5MM_memcpy(buf, vl->p, len); #else HDassert(_vl); H5MM_memcpy(&vl, _vl, sizeof(hvl_t)); HDassert(vl.p); - H5MM_memcpy(buf,vl.p,len); + H5MM_memcpy(buf, vl.p, len); #endif FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_vlen_seq_mem_read() */ +} /* end H5T__vlen_mem_seq_read() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_write + * Function: H5T__vlen_mem_seq_write * * Purpose: "Writes" the memory based VL sequence from a buffer * @@ -437,104 +542,104 @@ H5T_vlen_seq_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_seq_mem_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) +H5T__vlen_mem_seq_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) { hvl_t vl; /* Temporary hvl_t to use during operation */ - size_t len; - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* check parameters */ HDassert(_vl); HDassert(buf); - if(seq_len!=0) { - len=seq_len*base_size; + if(seq_len) { + size_t len = seq_len * base_size; /* Sequence size */ /* Use the user's memory allocation routine is one is defined */ - if(vl_alloc_info->alloc_func!=NULL) { - if(NULL==(vl.p=(vl_alloc_info->alloc_func)(len,vl_alloc_info->alloc_info))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") + if(vl_alloc_info->alloc_func != NULL) { + if(NULL == (vl.p = (vl_alloc_info->alloc_func)(len, vl_alloc_info->alloc_info))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "application memory allocation routine failed for VL data") } /* end if */ - else { /* Default to system malloc */ + else /* Default to system malloc */ if(NULL == (vl.p = HDmalloc(len))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") - } /* end else */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed for VL data") /* Copy the data into the newly allocated buffer */ - H5MM_memcpy(vl.p,buf,len); - + H5MM_memcpy(vl.p, buf, len); } /* end if */ else - vl.p=NULL; + vl.p = NULL; /* Set the sequence length */ - vl.len=seq_len; + vl.len = seq_len; /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - H5MM_memcpy(_vl,&vl,sizeof(hvl_t)); + H5MM_memcpy(_vl, &vl, sizeof(hvl_t)); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_seq_mem_write() */ +} /* end H5T__vlen_mem_seq_write() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_seq_mem_setnull + * Function: H5T__vlen_mem_str_getlen * - * Purpose: Sets a VL info object in memory to the "nil" value + * Purpose: Retrieves the length of a memory based VL string. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * Saturday, November 8, 2003 + * Wednesday, June 2, 1999 * *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_seq_mem_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED *_bg) +H5T__vlen_mem_str_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *len) { - hvl_t vl; /* Temporary hvl_t to use during operation */ +#ifdef H5_NO_ALIGNMENT_RESTRICTIONS + const char *s = *(const char * const *)_vl; /* Pointer to the user's string information */ +#else + const char *s = NULL; /* Pointer to the user's string information */ +#endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters */ HDassert(_vl); - /* Set the "nil" hvl_t */ - vl.len=0; - vl.p=NULL; +#ifndef H5_NO_ALIGNMENT_RESTRICTIONS + H5MM_memcpy(&s, _vl, sizeof(char *)); +#endif - /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - H5MM_memcpy(_vl,&vl,sizeof(hvl_t)); + *len = HDstrlen(s); FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_vlen_seq_mem_setnull() */ +} /* end H5T__vlen_mem_str_getlen() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_getlen + * Function: H5T__vlen_mem_str_getptr * - * Purpose: Retrieves the length of a memory based VL string. + * Purpose: Retrieves the pointer for a memory based VL string. * - * Return: Non-negative on success/Negative on failure + * Return: Non-NULL on success/NULL on failure * * Programmer: Quincey Koziol - * Wednesday, June 2, 1999 + * Saturday, June 12, 2004 * *------------------------------------------------------------------------- */ -static ssize_t -H5T_vlen_str_mem_getlen(const void *_vl) +static void * +H5T__vlen_mem_str_getptr(void *_vl) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - const char *s=*(const char * const *)_vl; /* Pointer to the user's string information */ + char *s = *(char **)_vl; /* Pointer to the user's string information */ #else - const char *s = NULL; /* Pointer to the user's string information */ + char *s = NULL; /* Pointer to the user's string information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* check parameters */ #ifdef H5_NO_ALIGNMENT_RESTRICTIONS @@ -544,78 +649,71 @@ H5T_vlen_str_mem_getlen(const void *_vl) H5MM_memcpy(&s, _vl, sizeof(char *)); #endif - FUNC_LEAVE_NOAPI((ssize_t)HDstrlen(s)) -} /* end H5T_vlen_str_mem_getlen() */ + FUNC_LEAVE_NOAPI(s) +} /* end H5T__vlen_mem_str_getptr() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_getptr + * Function: H5T__vlen_mem_str_isnull * - * Purpose: Retrieves the pointer for a memory based VL string. + * Purpose: Checks if a memory string is a NULL pointer * - * Return: Non-NULL on success/NULL on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol - * Saturday, June 12, 2004 + * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static void * -H5T_vlen_str_mem_getptr(void *_vl) +static herr_t +H5T__vlen_mem_str_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl, hbool_t *isnull) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - char *s=*(char **)_vl; /* Pointer to the user's string information */ + char *s = *(char **)_vl; /* Pointer to the user's string information */ #else char *s = NULL; /* Pointer to the user's string information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* check parameters */ -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - HDassert(s); -#else - HDassert(_vl); +#ifndef H5_NO_ALIGNMENT_RESTRICTIONS H5MM_memcpy(&s, _vl, sizeof(char *)); #endif - FUNC_LEAVE_NOAPI(s) -} /* end H5T_vlen_str_mem_getptr() */ + *isnull = (s == NULL ? TRUE : FALSE); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_mem_str_isnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_isnull + * Function: H5T__vlen_mem_str_setnull * - * Purpose: Checks if a memory string is a NULL pointer + * Purpose: Sets a VL info object in memory to the "null" value * - * Return: TRUE/FALSE on success/Negative on failure + * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static htri_t -H5T_vlen_str_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) +static herr_t +H5T__vlen_mem_str_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED *_bg) { -#ifdef H5_NO_ALIGNMENT_RESTRICTIONS - char *s=*(char **)_vl; /* Pointer to the user's string information */ -#else - char *s = NULL; /* Pointer to the user's string information */ -#endif + char *t = NULL; /* Pointer to temporary buffer allocated */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR -#ifndef H5_NO_ALIGNMENT_RESTRICTIONS - H5MM_memcpy(&s, _vl, sizeof(char *)); -#endif + /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ + H5MM_memcpy(_vl, &t, sizeof(char *)); - FUNC_LEAVE_NOAPI(s==NULL ? TRUE : FALSE) -} /* end H5T_vlen_str_mem_isnull() */ + FUNC_LEAVE_NOAPI(SUCCEED) /*lint !e429 The pointer in 't' has been copied */ +} /* end H5T__vlen_mem_str_setnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_read + * Function: H5T__vlen_mem_str_read * * Purpose: "Reads" the memory based VL string into a buffer * @@ -627,17 +725,17 @@ H5T_vlen_str_mem_isnull(const H5F_t H5_ATTR_UNUSED *f, void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_str_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) +H5T__vlen_mem_str_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) { #ifdef H5_NO_ALIGNMENT_RESTRICTIONS - char *s=*(char **)_vl; /* Pointer to the user's string information */ + char *s = *(char **)_vl; /* Pointer to the user's string information */ #else char *s; /* Pointer to the user's string information */ #endif - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - if(len>0) { + if(len > 0) { /* check parameters */ HDassert(buf); #ifdef H5_NO_ALIGNMENT_RESTRICTIONS @@ -647,15 +745,15 @@ H5T_vlen_str_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) H5MM_memcpy(&s, _vl, sizeof(char *)); #endif - H5MM_memcpy(buf,s,len); + H5MM_memcpy(buf, s, len); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5T_vlen_str_mem_read() */ +} /* end H5T__vlen_mem_str_read() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_write + * Function: H5T__vlen_mem_str_write * * Purpose: "Writes" the memory based VL string from a buffer * @@ -667,154 +765,171 @@ H5T_vlen_str_mem_read(H5F_t H5_ATTR_UNUSED *f, void *_vl, void *buf, size_t len) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_str_mem_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_alloc_info, +H5T__vlen_mem_str_write(H5F_t H5_ATTR_UNUSED *f, const H5T_vlen_alloc_info_t *vl_alloc_info, void *_vl, void *buf, void H5_ATTR_UNUSED *_bg, size_t seq_len, size_t base_size) { char *t; /* Pointer to temporary buffer allocated */ size_t len; /* Maximum length of the string to copy */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* check parameters */ HDassert(buf); /* Use the user's memory allocation routine if one is defined */ - if(vl_alloc_info->alloc_func!=NULL) { - if(NULL==(t = (char *)(vl_alloc_info->alloc_func)((seq_len+1)*base_size,vl_alloc_info->alloc_info))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") - } /* end if */ - else { /* Default to system malloc */ + if(vl_alloc_info->alloc_func != NULL) { + if(NULL == (t = (char *)(vl_alloc_info->alloc_func)((seq_len + 1) * base_size, vl_alloc_info->alloc_info))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "application memory allocation routine failed for VL data") + } /* end if */ + else /* Default to system malloc */ if(NULL == (t = (char *)HDmalloc((seq_len + 1) * base_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data") - } /* end else */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed for VL data") - len=(seq_len*base_size); - H5MM_memcpy(t,buf,len); - t[len]='\0'; + /* 'write' the string into the buffer, with memcpy() */ + len = (seq_len * base_size); + H5MM_memcpy(t, buf, len); + t[len] = '\0'; /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - H5MM_memcpy(_vl,&t,sizeof(char *)); + H5MM_memcpy(_vl, &t, sizeof(char *)); done: FUNC_LEAVE_NOAPI(ret_value) /*lint !e429 The pointer in 't' has been copied */ -} /* end H5T_vlen_str_mem_write() */ +} /* end H5T__vlen_mem_str_write() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_str_mem_setnull + * Function: H5T__vlen_disk_getlen * - * Purpose: Sets a VL info object in memory to the "null" value + * Purpose: Retrieves the length of a disk based VL element. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * Saturday, November 8, 2003 + * Wednesday, June 2, 1999 * *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_str_mem_setnull(H5F_t H5_ATTR_UNUSED *f, void *_vl, void H5_ATTR_UNUSED *_bg) +H5T__vlen_disk_getlen(H5F_t H5_ATTR_UNUSED *f, const void *_vl, size_t *seq_len) { - char *t=NULL; /* Pointer to temporary buffer allocated */ + const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR - /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ - H5MM_memcpy(_vl,&t,sizeof(char *)); + /* Check parameters */ + HDassert(vl); + HDassert(seq_len); - FUNC_LEAVE_NOAPI(SUCCEED) /*lint !e429 The pointer in 't' has been copied */ -} /* end H5T_vlen_str_mem_setnull() */ + /* Get length of sequence (different from blob size) */ + UINT32DECODE(vl, *seq_len); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5T__vlen_disk_getlen() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_getlen + * Function: H5T__vlen_disk_isnull * - * Purpose: Retrieves the length of a disk based VL element. + * Purpose: Checks if a disk VL info object is the "nil" object * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol - * Wednesday, June 2, 1999 + * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static ssize_t -H5T_vlen_disk_getlen(const void *_vl) +static herr_t +H5T__vlen_disk_isnull(const H5F_t *f, void *_vl, hbool_t *isnull) { - const uint8_t *vl=(const uint8_t *)_vl; /* Pointer to the disk VL information */ - size_t seq_len = 0; /* Sequence length */ + H5VL_object_t *vol_obj = NULL;/* Object info */ + hid_t file_id = H5I_INVALID_HID; + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC - /* check parameters */ + /* Check parameters */ + HDassert(f); HDassert(vl); + HDassert(isnull); - UINT32DECODE(vl, seq_len); + /* Skip the sequence's length */ + vl += 4; - FUNC_LEAVE_NOAPI((ssize_t)seq_len) -} /* end H5T_vlen_disk_getlen() */ + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id((H5F_t *)f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - -/*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_getptr - * - * Purpose: Retrieves the pointer to a disk based VL element. - * - * Return: Non-NULL on success/NULL on failure - * - * Programmer: Quincey Koziol - * Saturday, June 12, 2004 - * - *------------------------------------------------------------------------- - */ -static void * -H5T_vlen_disk_getptr(void H5_ATTR_UNUSED *vl) -{ - FUNC_ENTER_NOAPI_NOINIT_NOERR + /* Check if blob ID is "nil" */ + if(H5VL_blob_specific(vol_obj, vl, H5VL_BLOB_ISNULL, isnull) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to check if a blob ID is 'nil'") - /* check parameters */ - HDassert(vl); - - FUNC_LEAVE_NOAPI(NULL) -} /* end H5T_vlen_disk_getptr() */ +done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__vlen_disk_isnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_isnull + * Function: H5T__vlen_disk_setnull * - * Purpose: Checks if a disk VL info object is the "nil" object + * Purpose: Sets a VL info object on disk to the "nil" value * - * Return: TRUE/FALSE on success/Negative on failure + * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * Saturday, November 8, 2003 * *------------------------------------------------------------------------- */ -static htri_t -H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) +static herr_t +H5T__vlen_disk_setnull(H5F_t *f, void *_vl, void *bg) { - uint8_t *vl = (uint8_t *)_vl; /* Pointer to the disk VL information */ - haddr_t addr; /* Sequence's heap address */ + H5VL_object_t *vol_obj = NULL;/* Object info */ + hid_t file_id = H5I_INVALID_HID; + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC /* check parameters */ + HDassert(f); HDassert(vl); - /* Skip the sequence's length */ - vl += 4; + /* Free heap object for old data */ + if(bg != NULL) + /* Delete sequence in destination location */ + if(H5T__vlen_disk_delete(f, bg) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove background heap object") - /* Get the heap address */ - H5F_addr_decode(f, (const uint8_t **)&vl, &addr); + /* Set the length of the sequence */ + UINT32ENCODE(vl, 0); + + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - FUNC_LEAVE_NOAPI(addr == 0 ? TRUE : FALSE) -} /* end H5T_vlen_disk_isnull() */ + /* Set blob ID to "nil" */ + if(H5VL_blob_specific(vol_obj, vl, H5VL_BLOB_SETNULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to set a blob ID to 'nil'") + +done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__vlen_disk_setnull() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_read + * Function: H5T__vlen_disk_read * * Purpose: Reads the disk based VL element into a buffer * @@ -826,40 +941,42 @@ H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_disk_read(H5F_t *f, void *_vl, void *buf, size_t H5_ATTR_UNUSED len) +H5T__vlen_disk_read(H5F_t *f, void *_vl, void *buf, size_t H5_ATTR_UNUSED len) { - uint8_t *vl=(uint8_t *)_vl; /* Pointer to the user's hvl_t information */ - H5HG_t hobjid; - herr_t ret_value=SUCCEED; /* Return value */ + H5VL_object_t *vol_obj = NULL;/* Object info */ + hid_t file_id = H5I_INVALID_HID; + const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC - /* check parameters */ + /* Check parameters */ + HDassert(f); HDassert(vl); HDassert(buf); - HDassert(f); /* Skip the length of the sequence */ vl += 4; - /* Get the heap information */ - H5F_addr_decode(f, (const uint8_t **)&vl, &(hobjid.addr)); - UINT32DECODE(vl, hobjid.idx); + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Check if this sequence actually has any data */ - if(hobjid.addr > 0) { - /* Read the VL information from disk */ - if(NULL == H5HG_read(f, &hobjid, buf, NULL)) - HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "Unable to read VL information") - } + /* Retrieve blob */ + if(H5VL_blob_get(vol_obj, vl, buf, NULL, NULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to get blob") done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_disk_read() */ +} /* end H5T__vlen_disk_read() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_write + * Function: H5T__vlen_disk_write * * Purpose: Writes the disk based VL element from a buffer * @@ -871,146 +988,129 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_alloc_info, +H5T__vlen_disk_write(H5F_t *f, const H5T_vlen_alloc_info_t H5_ATTR_UNUSED *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) { - uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ - H5HG_t hobjid; /* New VL sequence's heap ID */ - size_t len; /* Size of new sequence on disk (in bytes) */ - herr_t ret_value = SUCCEED; /* Return value */ + H5VL_object_t *vol_obj = NULL; /* Object info */ + hid_t file_id = H5I_INVALID_HID; + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + const uint8_t *bg = (const uint8_t *)_bg; /* Pointer to the old data hvl_t */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* check parameters */ HDassert(vl); HDassert(seq_len == 0 || buf); HDassert(f); - /* Free heap object for old data. */ - if(bg!=NULL) { - H5HG_t bg_hobjid; /* "Background" VL info sequence's ID info */ - - /* Skip the length of the sequence and heap object ID from background data. */ - bg += 4; - - /* Get heap information */ - H5F_addr_decode(f, (const uint8_t **)&bg, &(bg_hobjid.addr)); - UINT32DECODE(bg, bg_hobjid.idx); - - /* Free heap object for old data */ - if(bg_hobjid.addr > 0) { - /* Free heap object */ - if(H5HG_remove(f, &bg_hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") - } - } /* end if */ + /* Free heap object for old data, if non-NULL */ + if(bg != NULL) + if(H5T__vlen_disk_delete(f, bg) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to remove background heap object") /* Set the length of the sequence */ UINT32ENCODE(vl, seq_len); - /* Write the VL information to disk (allocates space also) */ - len = (seq_len*base_size); - if(H5HG_insert(f, len, buf, &hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to write VL information") + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Encode the heap information */ - H5F_addr_encode(f, &vl, hobjid.addr); - UINT32ENCODE(vl, hobjid.idx); + /* Store blob */ + if(H5VL_blob_put(vol_obj, buf, (seq_len * base_size), vl, NULL) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "unable to put blob") done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_disk_write() */ +} /* end H5T__vlen_disk_write() */ /*------------------------------------------------------------------------- - * Function: H5T_vlen_disk_setnull + * Function: H5T__vlen_disk_delete * - * Purpose: Sets a VL info object on disk to the "nil" value + * Purpose: Deletes a disk-based VL element * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success / Negative on failure * * Programmer: Quincey Koziol - * Saturday, November 8, 2003 + * Friday, August 15, 2019 * *------------------------------------------------------------------------- */ static herr_t -H5T_vlen_disk_setnull(H5F_t *f, void *_vl, void *_bg) +H5T__vlen_disk_delete(H5F_t *f, const void *_vl) { - uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ - uint32_t seq_len = 0; /* Sequence length */ - herr_t ret_value = SUCCEED; /* Return value */ + const uint8_t *vl = (const uint8_t *)_vl; /* Pointer to the user's hvl_t information */ + hid_t file_id = H5I_INVALID_HID; + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC - /* check parameters */ + /* Check parameters */ HDassert(f); - HDassert(vl); - /* Free heap object for old data. */ - if(bg != NULL) { - H5HG_t bg_hobjid; /* "Background" VL info sequence's ID info */ + /* Free heap object for old data */ + if(vl != NULL) { + size_t seq_len; /* VL sequence's length */ - /* Skip the length of the sequence and heap object ID from background data. */ - bg += 4; + /* Get length of sequence */ + UINT32DECODE(vl, seq_len); - /* Get heap information */ - H5F_addr_decode(f, (const uint8_t **)&bg, &(bg_hobjid.addr)); - UINT32DECODE(bg, bg_hobjid.idx); + /* Delete object, if length > 0 */ + if(seq_len > 0) { + H5VL_object_t *vol_obj = NULL; /* Object info */ - /* Free heap object for old data */ - if(bg_hobjid.addr > 0) { - /* Free heap object */ - if(H5HG_remove(f, &bg_hobjid) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") - } /* end if */ - } /* end if */ + /* TODO temporary hack to retrieve file object */ + if((file_id = H5F__get_file_id(f, FALSE)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") + if(NULL == (vol_obj = H5VL_vol_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Set the length of the sequence */ - UINT32ENCODE(vl, seq_len); - - /* Encode the "nil" heap pointer information */ - H5F_addr_encode(f, &vl, (haddr_t)0); - UINT32ENCODE(vl, 0); + if(H5VL_blob_specific(vol_obj, (void *)vl, H5VL_BLOB_DELETE) < 0) /* Casting away 'const' OK -QAK */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREMOVE, FAIL, "unable to delete blob") + } + } /* end if */ done: + if((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0)) + HDONE_ERROR(H5E_DATATYPE, H5E_CANTDEC, FAIL, "unable to decrement refcount on file id") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_disk_setnull() */ +} /* end H5T__vlen_disk_delete() */ -/*-------------------------------------------------------------------------- - NAME - H5T_vlen_reclaim_recurse - PURPOSE - Internal recursive routine to free VL datatypes - USAGE - herr_t H5T_vlen_reclaim_recurse(elem,dt) - void *elem; IN/OUT: Pointer to the dataset element - H5T_t *dt; IN: Datatype of dataset element - - RETURNS - SUCCEED/FAIL - DESCRIPTION - Frees any dynamic memory used by VL datatypes in the current dataset - element. Performs a recursive depth-first traversal of all compound - datatypes to free all VL datatype information allocated by any field. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static herr_t -H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, void *free_info) +/*------------------------------------------------------------------------- + * Function: H5T_vlen_reclaim + * + * Purpose: Internal recursive routine to free VL datatypes + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Quincey Koziol + * Friday, August 15, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info) { unsigned u; /* Local index variable */ + H5MM_free_t free_func; /* Free function */ + void *free_info; /* Free info */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_NOAPI(FAIL) + /* Sanity checks */ HDassert(elem); HDassert(dt); + HDassert(alloc_info); + + free_func = alloc_info->free_func; + free_info = alloc_info->free_info; /* Check the datatype of this element */ switch(dt->shared->type) { @@ -1022,8 +1122,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi /* Calculate the offset member and recurse on it */ for(u = 0; u < dt->shared->u.array.nelem; u++) { off = ((uint8_t *)elem) + u * (dt->shared->parent->shared->size); - if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free array element") + if(H5T_reclaim_cb(off, dt->shared->parent, 0, NULL, alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free array element") } /* end for */ } /* end if */ break; @@ -1037,8 +1137,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi /* Calculate the offset member and recurse on it */ off = ((uint8_t *)elem) + dt->shared->u.compnd.memb[u].offset; - if(H5T_vlen_reclaim_recurse(off, dt->shared->u.compnd.memb[u].type, free_func, free_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free compound field") + if(H5T_reclaim_cb(off, dt->shared->u.compnd.memb[u].type, 0, NULL, alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free compound field") } /* end if */ } /* end for */ break; @@ -1057,8 +1157,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi /* Calculate the offset of each array element and recurse on it */ while(vl->len > 0) { off = ((uint8_t *)vl->p) + (vl->len - 1) * dt->shared->parent->shared->size; - if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free VL element") + if(H5T_reclaim_cb(off, dt->shared->parent, 0, NULL, alloc_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "unable to free VL element") vl->len--; } /* end while */ } /* end if */ @@ -1087,11 +1187,11 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_STRING: case H5T_BITFIELD: case H5T_OPAQUE: - case H5T_REFERENCE: case H5T_ENUM: break; /* Should never have these values */ + case H5T_REFERENCE: case H5T_NO_CLASS: case H5T_NCLASSES: default: @@ -1102,66 +1202,15 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_reclaim_recurse() */ - - -/*-------------------------------------------------------------------------- - NAME - H5T_vlen_reclaim - PURPOSE - Default method to reclaim any VL data for a buffer element - USAGE - herr_t H5T_vlen_reclaim(elem,type_id,ndim,point,op_data) - void *elem; IN/OUT: Pointer to the dataset element - hid_t type_id; IN: Datatype of dataset element - unsigned ndim; IN: Number of dimensions in dataspace - hsize_t *point; IN: Coordinate location of element in dataspace - void *op_data IN: Operator data - - RETURNS - SUCCEED/FAIL - DESCRIPTION - Frees any dynamic memory used by VL datatypes in the current dataset - element. Recursively descends compound datatypes to free all VL datatype - information allocated by any field. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned H5_ATTR_UNUSED ndim, - const hsize_t H5_ATTR_UNUSED *point, void *op_data) -{ - H5T_vlen_alloc_info_t *vl_alloc_info = (H5T_vlen_alloc_info_t *)op_data; /* VL allocation info from iterator */ - H5T_t *dt; - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - HDassert(elem); - HDassert(vl_alloc_info); - HDassert(H5I_DATATYPE == H5I_get_type(type_id)); - - /* Check args */ - if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - - /* Pull the free function and free info pointer out of the op_data and call the recurse datatype free function */ - if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_vlen_reclaim() */ +} /* end H5T_vlen_reclaim() */ /*------------------------------------------------------------------------- * Function: H5T_vlen_reclaim_elmt * * Purpose: Alternative method to reclaim any VL data for a buffer element. - * - * Use this function when the datatype is already available, but + * + * Use this function when the datatype is already available, but * the allocation info is needed from the context before jumping * into recursion. * @@ -1188,10 +1237,9 @@ H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") /* Recurse on buffer to free dynamic fields */ - if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info.free_func, vl_alloc_info.free_info) < 0) + if(H5T_vlen_reclaim(elem, dt, &vl_alloc_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5T_vlen_reclaim_elmt */ - +} /* H5T_vlen_reclaim_elmt() */ diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 0131f0e..5400356 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -177,7 +177,12 @@ static herr_t H5VL__request_specific(void *req, const H5VL_class_t *cls, static herr_t H5VL__request_optional(void *req, const H5VL_class_t *cls, va_list arguments); static herr_t H5VL__request_free(void *req, const H5VL_class_t *cls); - +static herr_t H5VL__blob_put(void *obj, const H5VL_class_t *cls, + const void *buf, size_t size, void *blob_id, void *ctx); +static herr_t H5VL__blob_get(void *obj, const H5VL_class_t *cls, + const void *blob_id, void *buf, size_t *size, void *ctx); +static herr_t H5VL__blob_specific(void *obj, const H5VL_class_t *cls, + void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); /*********************/ /* Package Variables */ @@ -6564,6 +6569,350 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL__blob_put + * + * Purpose: Put a blob through the VOL + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL__blob_put(void *obj, const H5VL_class_t *cls, const void *buf, size_t size, + void *blob_id, void *ctx) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(obj); + HDassert(cls); + HDassert(size == 0 || buf); + HDassert(blob_id); + + /* Check if the corresponding VOL callback exists */ + if(NULL == cls->blob_cls.put) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "VOL connector has no 'blob put' method") + + /* Call the corresponding VOL callback */ + if((cls->blob_cls.put)(obj, buf, size, blob_id, ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "blob put callback failed") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__blob_put() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_blob_put + * + * Purpose: Put a blob through the VOL + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Wednesday, August 21, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_blob_put(const H5VL_object_t *vol_obj, const void *buf, size_t size, + void *blob_id, void *ctx) +{ + hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(vol_obj); + HDassert(size == 0 || buf); + HDassert(blob_id); + + /* Set wrapper info in API context */ + if(H5VL_set_vol_wrapper(vol_obj->data, vol_obj->connector) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info") + vol_wrapper_set = TRUE; + + /* Call the corresponding VOL callback */ + if(H5VL__blob_put(vol_obj->data, vol_obj->connector->cls, buf, size, blob_id, ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "blob put failed") + +done: + /* Reset object wrapping info in API context */ + if(vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_blob_put() */ + + +/*------------------------------------------------------------------------- + * Function: H5VLblob_put + * + * Purpose: Put a blob through the VOL + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VLblob_put(void *obj, hid_t connector_id, const void *buf, size_t size, + void *blob_id, void *ctx) +{ + H5VL_class_t *cls; /* VOL connector's class struct */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API_NOINIT + H5TRACE6("e", "*xi*xz*x*x", obj, connector_id, buf, size, blob_id, ctx); + + /* Get class pointer */ + if(NULL == obj) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid object") + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Call the corresponding VOL callback */ + if(H5VL__blob_put(obj, cls, buf, size, blob_id, ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "blob put failed") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* end H5VLblob_put() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__blob_get + * + * Purpose: Get a blob through the VOL + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL__blob_get(void *obj, const H5VL_class_t *cls, const void *blob_id, + void *buf, size_t *size, void *ctx) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(obj); + HDassert(cls); + HDassert(blob_id); + HDassert(size || buf); + + /* Check if the corresponding VOL callback exists */ + if(NULL == cls->blob_cls.get) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "VOL connector has no 'blob get' method") + + /* Call the corresponding VOL callback */ + if((cls->blob_cls.get)(obj, blob_id, buf, size, ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "blob get callback failed") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__blob_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_blob_get + * + * Purpose: Get a blob through the VOL + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_blob_get(const H5VL_object_t *vol_obj, const void *blob_id, void *buf, + size_t *size, void *ctx) +{ + hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(vol_obj); + HDassert(blob_id); + HDassert(size || buf); + + /* Set wrapper info in API context */ + if(H5VL_set_vol_wrapper(vol_obj->data, vol_obj->connector) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info") + vol_wrapper_set = TRUE; + + /* Call the corresponding VOL callback */ + if(H5VL__blob_get(vol_obj->data, vol_obj->connector->cls, blob_id, buf, size, ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "blob get failed") + +done: + /* Reset object wrapping info in API context */ + if(vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info") + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_blob_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VLblob_get + * + * Purpose: Get a blob through the VOL + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VLblob_get(void *obj, hid_t connector_id, const void *blob_id, void *buf, + size_t *size, void *ctx) +{ + H5VL_class_t *cls; /* VOL connector's class struct */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API_NOINIT + H5TRACE6("e", "*xi*x*x*z*x", obj, connector_id, blob_id, buf, size, ctx); + + /* Get class pointer */ + if(NULL == obj) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid object") + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Call the corresponding VOL callback */ + if(H5VL__blob_get(obj, cls, blob_id, buf, size, ctx) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "blob get failed") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* end H5VLblob_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__blob_specific + * + * Purpose: Specific operation on blobs through the VOL + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Saturday, August 17, 2019 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL__blob_specific(void *obj, const H5VL_class_t *cls, void *blob_id, + H5VL_blob_specific_t specific_type, va_list arguments) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(obj); + HDassert(cls); + HDassert(blob_id); + + /* Check if the corresponding VOL callback exists */ + if(NULL == cls->blob_cls.specific) + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "VOL connector has no 'blob specific' method") + + /* Call the corresponding VOL callback */ + if((cls->blob_cls.specific)(obj, blob_id, specific_type, arguments) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTOPERATE, FAIL, "unable to execute blob specific callback") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__blob_specific() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_blob_specific + * + * Purpose: Specific operation on blobs through the VOL + * + * Return: Success: Non-negative + * Failure: Negative + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_blob_specific(const H5VL_object_t *vol_obj, void *blob_id, + H5VL_blob_specific_t specific_type, ...) +{ + va_list arguments; /* Argument list passed from the API call */ + hbool_t arg_started = FALSE; /* Whether the va_list has been started */ + hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Sanity check */ + HDassert(vol_obj); + HDassert(blob_id); + + /* Set wrapper info in API context */ + if(H5VL_set_vol_wrapper(vol_obj->data, vol_obj->connector) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL wrapper info") + vol_wrapper_set = TRUE; + + /* Call the corresponding internal VOL routine */ + HDva_start(arguments, specific_type); + arg_started = TRUE; + if((ret_value = H5VL__blob_specific(vol_obj->data, vol_obj->connector->cls, blob_id, specific_type, arguments)) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTOPERATE, FAIL, "unable to execute blob specific callback") + +done: + /* End access to the va_list, if we started it */ + if(arg_started) + HDva_end(arguments); + + /* Reset object wrapping info in API context */ + if(vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_blob_specific() */ + + +/*------------------------------------------------------------------------- + * Function: H5VLblob_specific + * + * Purpose: Specific operation on blobs through the VOL + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VLblob_specific(void *obj, hid_t connector_id, void *blob_id, + H5VL_blob_specific_t specific_type, va_list arguments) +{ + H5VL_class_t *cls; /* VOL connector's class struct */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API_NOINIT + H5TRACE5("e", "*xi*xVBx", obj, connector_id, blob_id, specific_type, arguments); + + /* Get class pointer */ + if(NULL == obj) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid object") + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") + + /* Call the corresponding VOL callback */ + if(H5VL__blob_specific(obj, cls, blob_id, specific_type, arguments) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTOPERATE, FAIL, "blob specific operation failed") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* end H5VLblob_specific() */ + + +/*------------------------------------------------------------------------- * Function: H5VL__optional * * Purpose: Optional operation specific to connectors. diff --git a/src/H5VLconnector.h b/src/H5VLconnector.h index 98bc521..3597751 100644 --- a/src/H5VLconnector.h +++ b/src/H5VLconnector.h @@ -37,11 +37,23 @@ #define H5VL_CAP_FLAG_NONE 0 /* No special connector capabilities */ #define H5VL_CAP_FLAG_THREADSAFE 0x01 /* Connector is threadsafe */ +/* Container info version */ +#define H5VL_CONTAINER_INFO_VERSION 0x01 /* Container info struct version */ + +/* The maximum size allowed for blobs */ +#define H5VL_MAX_BLOB_ID_SIZE (16) /* Allow for 128-bits blob IDs */ + +/* The maximum size allowed for tokens */ +#define H5VL_MAX_TOKEN_SIZE (16) /* Allow for 128-bits tokens */ /*******************/ /* Public Typedefs */ /*******************/ +/* type for tokens. Token are unique and permanent identifiers that are + * used to reference HDF5 objects. */ +typedef unsigned char H5VL_token_t[H5VL_MAX_TOKEN_SIZE]; + /* types for attribute GET callback */ typedef enum H5VL_attr_get_t { H5VL_ATTR_GET_ACPL, /* creation property list */ @@ -92,10 +104,11 @@ typedef enum H5VL_datatype_specific_t { /* types for file GET callback */ typedef enum H5VL_file_get_t { + H5VL_FILE_GET_CONT_INFO, /* file get container info */ H5VL_FILE_GET_FAPL, /* file access property list */ H5VL_FILE_GET_FCPL, /* file creation property list */ - H5VL_FILE_GET_INTENT, /* file intent */ H5VL_FILE_GET_FILENO, /* file number */ + H5VL_FILE_GET_INTENT, /* file intent */ H5VL_FILE_GET_NAME, /* file name */ H5VL_FILE_GET_OBJ_COUNT, /* object count in file */ H5VL_FILE_GET_OBJ_IDS /* object ids in file */ @@ -146,18 +159,16 @@ typedef enum H5VL_link_specific_t { /* types for object GET callback */ typedef enum H5VL_object_get_t { - H5VL_REF_GET_NAME, /* object name, for reference */ - H5VL_REF_GET_REGION, /* dataspace of region */ - H5VL_REF_GET_TYPE, /* type of object */ - H5VL_OBJECT_GET_NAME /* object name */ + H5VL_OBJECT_GET_NAME, /* object name */ + H5VL_OBJECT_GET_TYPE /* object type */ } H5VL_object_get_t; /* types for object SPECIFIC callback */ typedef enum H5VL_object_specific_t { H5VL_OBJECT_CHANGE_REF_COUNT, /* H5Oincr/decr_refcount */ H5VL_OBJECT_EXISTS, /* H5Oexists_by_name */ + H5VL_OBJECT_LOOKUP, /* Lookup object */ H5VL_OBJECT_VISIT, /* H5Ovisit(_by_name) */ - H5VL_REF_CREATE, /* H5Rcreate */ H5VL_OBJECT_FLUSH, /* H5{D|G|O|T}flush */ H5VL_OBJECT_REFRESH /* H5{D|G|O|T}refresh */ } H5VL_object_specific_t; @@ -169,56 +180,67 @@ typedef enum H5VL_request_specific_t { H5VL_REQUEST_WAITALL /* Wait until all requests complete */ } H5VL_request_specific_t; -/* types for different ways that objects are located in an HDF5 container */ +/* types for 'blob' SPECIFIC callback */ +typedef enum H5VL_blob_specific_t { + H5VL_BLOB_DELETE, /* Delete a blob (by ID) */ + H5VL_BLOB_GETSIZE, /* Get size of blob */ + H5VL_BLOB_ISNULL, /* Check if a blob ID is "null" */ + H5VL_BLOB_SETNULL /* Set a blob ID to the connector's "null" blob ID value */ +} H5VL_blob_specific_t; + +/* Types for different ways that objects are located in an HDF5 container */ typedef enum H5VL_loc_type_t { H5VL_OBJECT_BY_SELF, H5VL_OBJECT_BY_NAME, H5VL_OBJECT_BY_IDX, - H5VL_OBJECT_BY_ADDR, - H5VL_OBJECT_BY_REF + H5VL_OBJECT_BY_TOKEN } H5VL_loc_type_t; -struct H5VL_loc_by_name { +typedef struct H5VL_loc_by_name { const char *name; hid_t lapl_id; -}; +} H5VL_loc_by_name_t; -struct H5VL_loc_by_idx { +typedef struct H5VL_loc_by_idx { const char *name; H5_index_t idx_type; H5_iter_order_t order; hsize_t n; hid_t lapl_id; -}; +} H5VL_loc_by_idx_t; -struct H5VL_loc_by_addr { - haddr_t addr; -}; +typedef struct H5VL_loc_by_token { + void *token; +} H5VL_loc_by_token_t; -struct H5VL_loc_by_ref { - H5R_type_t ref_type; - const void *_ref; - hid_t lapl_id; -}; - -/* Structure to hold parameters for object locations. - * either: BY_ADDR, BY_ID, BY_NAME, BY_IDX, BY_REF +/* Structure to hold parameters for object locations. + * Either: BY_SELF, BY_NAME, BY_IDX, BY_TOKEN * - * Note: Leave loc_by_addr as the first union member so we + * Note: Leave loc_by_token as the first union member so we * can perform the simplest initialization of the struct * without raising warnings. + * + * Note: BY_SELF requires no union members. */ typedef struct H5VL_loc_params_t { H5I_type_t obj_type; H5VL_loc_type_t type; - union{ - struct H5VL_loc_by_addr loc_by_addr; - struct H5VL_loc_by_name loc_by_name; - struct H5VL_loc_by_idx loc_by_idx; - struct H5VL_loc_by_ref loc_by_ref; + union { + H5VL_loc_by_token_t loc_by_token; + H5VL_loc_by_name_t loc_by_name; + H5VL_loc_by_idx_t loc_by_idx; } loc_data; } H5VL_loc_params_t; +/* Info for H5VL_FILE_GET_CONT_INFO */ +typedef struct H5VL_file_cont_info_t { + unsigned version; /* version information (keep first) */ + uint64_t feature_flags; /* Container feature flags */ + /* (none currently defined) */ + size_t token_size; /* Size of tokens */ + size_t blob_id_size; /* Size of blob IDs */ +} H5VL_file_cont_info_t; + /* VOL connector info fields & callbacks */ typedef struct H5VL_info_class_t { size_t size; /* Size of the VOL info */ @@ -355,6 +377,14 @@ typedef struct H5VL_request_class_t { herr_t (*free)(void *req); } H5VL_request_class_t; +/* 'blob' routines */ +typedef struct H5VL_blob_class_t { + herr_t (*put)(void *obj, const void *buf, size_t size, void *blob_id, void *ctx); + herr_t (*get)(void *obj, const void *blob_id, void *buf, size_t *size, void *ctx); + herr_t (*specific)(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); + herr_t (*optional)(void *obj, void *blob_id, va_list arguments); +} H5VL_blob_class_t; + /* * VOL connector identifiers. Values 0 through 255 are for connectors defined * by the HDF5 library. Values 256 through 511 are available for testing new @@ -386,8 +416,9 @@ typedef struct H5VL_class_t { H5VL_link_class_t link_cls; /* Link (H5L*) class callbacks */ H5VL_object_class_t object_cls; /* Object (H5O*) class callbacks */ - /* Services */ + /* Infrastructure / Services */ H5VL_request_class_t request_cls; /* Asynchronous request class callbacks */ + H5VL_blob_class_t blob_cls; /* 'blob' callbacks */ /* Catch-all */ herr_t (*optional)(void *obj, hid_t dxpl_id, void **req, va_list arguments); /* Optional callback */ @@ -398,6 +429,7 @@ typedef struct H5VL_class_t { /* Public Variables */ /********************/ + /*********************/ /* Public Prototypes */ /*********************/ diff --git a/src/H5VLconnector_passthru.h b/src/H5VLconnector_passthru.h index 9a2bd52..d0d73d2 100644 --- a/src/H5VLconnector_passthru.h +++ b/src/H5VLconnector_passthru.h @@ -13,7 +13,7 @@ /* * This file contains public declarations for authoring VOL connectors * which act as "passthrough" connectors that forward their API calls to - * an underlying connector. + * an underlying connector. * * An example of this might be a logging connector, which creates log messages * and then passes the call on to an underlying VOL connector. @@ -158,6 +158,15 @@ H5_DLL herr_t H5VLrequest_specific(void *req, hid_t connector_id, H5VL_request_s H5_DLL herr_t H5VLrequest_optional(void *req, hid_t connector_id, va_list arguments); H5_DLL herr_t H5VLrequest_free(void *req, hid_t connector_id); +/* Public wrappers for blob callbacks */ +H5_DLL herr_t H5VLblob_put(void *obj, hid_t connector_id, const void *buf, size_t size, void *blob_id, void *ctx); +H5_DLL herr_t H5VLblob_get(void *obj, hid_t connector_id, const void *blob_id, void *buf, size_t *size, void *ctx); +H5_DLL herr_t H5VLblob_specific(void *obj, hid_t connector_id, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); + +/* Public wrappers for generic 'optional' callback */ +H5_DLL herr_t H5VLoptional(void *obj, hid_t connector_id, hid_t dxpl_id, + void **req, va_list arguments); + #ifdef __cplusplus } #endif diff --git a/src/H5VLint.c b/src/H5VLint.c index f9262f4..09acb2a 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -543,6 +543,7 @@ static H5VL_object_t * H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t wrap_obj) { H5VL_object_t *new_vol_obj = NULL; /* Pointer to new VOL object */ + hbool_t conn_rc_incr = FALSE; /* Whether the VOL connector refcount has been incremented */ H5VL_object_t *ret_value = NULL; /* Return value */ FUNC_ENTER_STATIC @@ -569,6 +570,7 @@ H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t /* Bump the reference count on the VOL connector */ H5VL__conn_inc_rc(vol_connector); + conn_rc_incr = TRUE; /* If this is a datatype, we have to hide the VOL object under the H5T_t pointer */ if(H5I_DATATYPE == type) { @@ -579,6 +581,12 @@ H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t ret_value = (H5VL_object_t *)new_vol_obj; done: + /* Cleanup on error */ + if(NULL == ret_value) { + if(conn_rc_incr && H5VL__conn_dec_rc(vol_connector) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTDEC, NULL, "unable to decrement ref count on VOL connector") + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL__new_vol_obj() */ @@ -759,16 +767,17 @@ done: * get the connector information instead of it being passed in. * * Return: Success: A valid HDF5 ID - * Failure: H5I_INVALID_HID + * Failure: H5I_INVALID_HID * *------------------------------------------------------------------------- */ hid_t H5VL_register_using_vol_id(H5I_type_t type, void *obj, hid_t connector_id, hbool_t app_ref) { - H5VL_class_t *cls = NULL; - H5VL_t *connector = NULL; /* VOL connector struct */ - hid_t ret_value = H5I_INVALID_HID; + H5VL_class_t *cls = NULL; /* VOL connector class */ + H5VL_t *connector = NULL; /* VOL connector struct */ + hbool_t conn_id_incr = FALSE; /* Whether the VOL connector ID has been incremented */ + hid_t ret_value = H5I_INVALID_HID;/* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -783,12 +792,24 @@ H5VL_register_using_vol_id(H5I_type_t type, void *obj, hid_t connector_id, hbool connector->id = connector_id; if(H5I_inc_ref(connector->id, FALSE) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector") + conn_id_incr = TRUE; /* Get an ID for the VOL object */ if((ret_value = H5VL_register(type, obj, connector, app_ref)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle") done: + /* Clean up on error */ + if(ret_value < 0) { + /* Decrement VOL connector ID ref count on error */ + if(conn_id_incr && H5I_dec_ref(connector_id) < 0) + HDONE_ERROR(H5E_VOL, H5E_CANTDEC, H5I_INVALID_HID, "unable to decrement ref count on VOL connector") + + /* Free VOL connector struct */ + if(NULL != connector) + connector = H5FL_FREE(H5VL_t, connector); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_register_using_vol_id() */ diff --git a/src/H5VLnative.c b/src/H5VLnative.c index 7848c5d..78eaee4 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -11,8 +11,8 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * Purpose: The native VOL connector where access is to a single HDF5 file - * using HDF5 VFDs. + * Purpose: The native VOL connector where access is to a single HDF5 file + * using HDF5 VFDs. */ #include "H5private.h" /* Generic Functions */ @@ -120,6 +120,12 @@ static H5VL_class_t H5VL_native_cls_g = { NULL, /* optional */ NULL /* free */ }, + { /* blob_cls */ + H5VL__native_blob_put, /* put */ + H5VL__native_blob_get, /* get */ + H5VL__native_blob_specific, /* specific */ + NULL /* optional */ + }, NULL /* optional */ }; diff --git a/src/H5VLnative.h b/src/H5VLnative.h index b2dd13d..5b51e66 100644 --- a/src/H5VLnative.h +++ b/src/H5VLnative.h @@ -17,6 +17,9 @@ #ifndef _H5VLnative_H #define _H5VLnative_H +/* Public headers needed by this file */ +#include "H5VLpublic.h" /* Virtual Object Layer */ + /* Identifier for the native VOL connector */ #define H5VL_NATIVE (H5VL_native_register()) diff --git a/src/H5VLnative_blob.c b/src/H5VLnative_blob.c new file mode 100644 index 0000000..b16b407 --- /dev/null +++ b/src/H5VLnative_blob.c @@ -0,0 +1,237 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * 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. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: Blob callbacks for the native VOL connector + */ + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fprivate.h" /* File access */ +#include "H5HGprivate.h" /* Global Heaps */ +#include "H5VLnative_private.h" /* Native VOL connector */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + + +/*------------------------------------------------------------------------- + * Function: H5VL__native_blob_put + * + * Purpose: Handles the blob 'put' callback + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Friday, August 15, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL__native_blob_put(void *obj, const void *buf, size_t size, void *blob_id, + void H5_ATTR_UNUSED *ctx) +{ + H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ + uint8_t *id = (uint8_t *)blob_id; /* Pointer to blob ID */ + H5HG_t hobjid; /* New VL sequence's heap ID */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Check parameters */ + HDassert(f); + HDassert(size == 0 || buf); + HDassert(id); + + /* Write the VL information to disk (allocates space also) */ + if(H5HG_insert(f, size, (void *)buf, &hobjid) < 0) + HGOTO_ERROR(H5E_VOL, H5E_WRITEERROR, FAIL, "unable to write blob information") + + /* Encode the heap information */ + H5F_addr_encode(f, &id, hobjid.addr); + UINT32ENCODE(id, hobjid.idx); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__native_blob_put() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__native_blob_get + * + * Purpose: Handles the blob 'get' callback + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Friday, August 15, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, + void H5_ATTR_UNUSED *ctx) +{ + H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ + const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the disk blob ID */ + H5HG_t hobjid; /* Global heap ID for sequence */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Sanity check */ + HDassert(f); + HDassert(id); + HDassert(buf); + + /* Get the heap information */ + H5F_addr_decode(f, &id, &hobjid.addr); + UINT32DECODE(id, hobjid.idx); + + /* Check if this sequence actually has any data */ + if(hobjid.addr > 0) + /* Read the VL information from disk */ + if(NULL == H5HG_read(f, &hobjid, buf, size)) + HGOTO_ERROR(H5E_VOL, H5E_READERROR, FAIL, "unable to read VL information") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__native_blob_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL__native_blob_specific + * + * Purpose: Handles the blob 'specific' callback + * + * Return: SUCCEED / FAIL + * + * Programmer: Quincey Koziol + * Friday, August 15, 2019 + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL__native_blob_specific(void *obj, void *blob_id, + H5VL_blob_specific_t specific_type, va_list arguments) +{ + H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Sanity check */ + HDassert(f); + HDassert(blob_id); + + switch(specific_type) { + case H5VL_BLOB_GETSIZE: + { + const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the blob ID */ + size_t *size = HDva_arg(arguments, size_t *); + H5HG_t hobjid; /* blob's heap ID */ + + /* Get heap information */ + H5F_addr_decode(f, &id, &(hobjid.addr)); + UINT32DECODE(id, hobjid.idx); + + /* Free heap object */ + if(hobjid.addr > 0) { + if(H5HG_get_obj_size(f, &hobjid, size) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREMOVE, FAIL, "unable to remove heap object") + } /* end if */ + else + *size = 0; /* Return '0' size for 'nil' blob ID */ + + break; + } + + case H5VL_BLOB_ISNULL: + { + const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the blob ID */ + hbool_t *isnull = HDva_arg(arguments, hbool_t *); + haddr_t addr; /* Sequence's heap address */ + + /* Get the heap address */ + H5F_addr_decode(f, &id, &addr); + + /* Check if heap address is 'nil' */ + *isnull = (addr == 0 ? TRUE : FALSE); + + break; + } + + case H5VL_BLOB_SETNULL: + { + uint8_t *id = (uint8_t *)blob_id; /* Pointer to the blob ID */ + /* Encode the "nil" heap pointer information */ + H5F_addr_encode(f, &id, (haddr_t)0); + UINT32ENCODE(id, 0); + + break; + } + + case H5VL_BLOB_DELETE: + { + const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the blob ID */ + H5HG_t hobjid; /* VL sequence's heap ID */ + + /* Get heap information */ + H5F_addr_decode(f, &id, &hobjid.addr); + UINT32DECODE(id, hobjid.idx); + + /* Free heap object */ + if(hobjid.addr > 0) + if(H5HG_remove(f, &hobjid) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTREMOVE, FAIL, "unable to remove heap object") + + break; + } + + default: + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation") + } /* end switch */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__native_blob_specific() */ diff --git a/src/H5VLnative_file.c b/src/H5VLnative_file.c index 1cb7533..63574c6 100644 --- a/src/H5VLnative_file.c +++ b/src/H5VLnative_file.c @@ -129,6 +129,18 @@ H5VL__native_file_get(void *obj, H5VL_file_get_t get_type, FUNC_ENTER_PACKAGE switch(get_type) { + /* "get container info" */ + case H5VL_FILE_GET_CONT_INFO: + { + H5VL_file_cont_info_t *info = HDva_arg(arguments, H5VL_file_cont_info_t *); + + /* Retrieve the file's container info */ + if(H5F__get_cont_info((H5F_t *)obj, info) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get file container info") + + break; + } + /* H5Fget_access_plist */ case H5VL_FILE_GET_FAPL: { @@ -139,7 +151,7 @@ H5VL__native_file_get(void *obj, H5VL_file_get_t get_type, /* Retrieve the file's access property list */ if((*plist_id = H5F_get_access_plist(f, TRUE)) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get file access property list") + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get file access property list") if(NULL == (new_plist = (H5P_genplist_t *)H5I_object(*plist_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") @@ -163,42 +175,6 @@ H5VL__native_file_get(void *obj, H5VL_file_get_t get_type, break; } - /* H5Fget_obj_count */ - case H5VL_FILE_GET_OBJ_COUNT: - { - unsigned types = HDva_arg(arguments, unsigned); - ssize_t *ret = HDva_arg(arguments, ssize_t *); - size_t obj_count = 0; /* Number of opened objects */ - - f = (H5F_t *)obj; - /* Perform the query */ - if(H5F_get_obj_count(f, types, TRUE, &obj_count) < 0) - HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "H5F_get_obj_count failed") - - /* Set the return value */ - *ret = (ssize_t)obj_count; - break; - } - - /* H5Fget_obj_ids */ - case H5VL_FILE_GET_OBJ_IDS: - { - unsigned types = HDva_arg(arguments, unsigned); - size_t max_objs = HDva_arg(arguments, size_t); - hid_t *oid_list = HDva_arg(arguments, hid_t *); - ssize_t *ret = HDva_arg(arguments, ssize_t *); - size_t obj_count = 0; /* Number of opened objects */ - - f = (H5F_t *)obj; - /* Perform the query */ - if(H5F_get_obj_ids(f, types, max_objs, oid_list, TRUE, &obj_count) < 0) - HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "H5F_get_obj_ids failed") - - /* Set the return value */ - *ret = (ssize_t)obj_count; - break; - } - /* H5Fget_intent */ case H5VL_FILE_GET_INTENT: { @@ -266,6 +242,42 @@ H5VL__native_file_get(void *obj, H5VL_file_get_t get_type, break; } + /* H5Fget_obj_count */ + case H5VL_FILE_GET_OBJ_COUNT: + { + unsigned types = HDva_arg(arguments, unsigned); + ssize_t *ret = HDva_arg(arguments, ssize_t *); + size_t obj_count = 0; /* Number of opened objects */ + + f = (H5F_t *)obj; + /* Perform the query */ + if(H5F_get_obj_count(f, types, TRUE, &obj_count) < 0) + HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "H5F_get_obj_count failed") + + /* Set the return value */ + *ret = (ssize_t)obj_count; + break; + } + + /* H5Fget_obj_ids */ + case H5VL_FILE_GET_OBJ_IDS: + { + unsigned types = HDva_arg(arguments, unsigned); + size_t max_objs = HDva_arg(arguments, size_t); + hid_t *oid_list = HDva_arg(arguments, hid_t *); + ssize_t *ret = HDva_arg(arguments, ssize_t *); + size_t obj_count = 0; /* Number of opened objects */ + + f = (H5F_t *)obj; + /* Perform the query */ + if(H5F_get_obj_ids(f, types, max_objs, oid_list, TRUE, &obj_count) < 0) + HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "H5F_get_obj_ids failed") + + /* Set the return value */ + *ret = (ssize_t)obj_count; + break; + } + default: HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information") } /* end switch */ @@ -397,7 +409,6 @@ H5VL__native_file_specific(void *obj, H5VL_file_specific_t specific_type, break; } - default: HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation") } /* end switch */ diff --git a/src/H5VLnative_object.c b/src/H5VLnative_object.c index 49d4b2c..64d3978 100644 --- a/src/H5VLnative_object.c +++ b/src/H5VLnative_object.c @@ -16,7 +16,6 @@ */ #define H5O_FRIEND /* Suppress error about including H5Opkg */ -#define H5R_FRIEND /* Suppress error about including H5Rpkg */ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ @@ -25,7 +24,6 @@ #include "H5Iprivate.h" /* IDs */ #include "H5Opkg.h" /* Object headers */ #include "H5Pprivate.h" /* Property lists */ -#include "H5Rpkg.h" /* References */ #include "H5VLprivate.h" /* Virtual Object Layer */ #include "H5VLnative_private.h" /* Native VOL connector */ @@ -71,34 +69,14 @@ H5VL__native_object_open(void *obj, const H5VL_loc_params_t *loc_params, H5I_typ break; } - case H5VL_OBJECT_BY_ADDR: + case H5VL_OBJECT_BY_TOKEN: { /* Open the object */ - if(NULL == (ret_value = H5O_open_by_addr(&loc, loc_params->loc_data.loc_by_addr.addr, opened_type))) + if(NULL == (ret_value = H5O_open_by_addr(&loc, *(haddr_t *)loc_params->loc_data.loc_by_token.token, opened_type))) HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENOBJ, NULL, "unable to open object by address") break; } - case H5VL_OBJECT_BY_REF: - { - hid_t temp_id = H5I_INVALID_HID; - H5F_t *file = NULL; - - /* Get the file pointer from the entry */ - file = loc.oloc->file; - - /* Create reference */ - if((temp_id = H5R__dereference(file, loc_params->loc_data.loc_by_ref.lapl_id, - loc_params->loc_data.loc_by_ref.ref_type, - loc_params->loc_data.loc_by_ref._ref)) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTOPENOBJ, NULL, "unable to dereference object") - - *opened_type = H5I_get_type(temp_id); - if(NULL == (ret_value = H5I_remove(temp_id))) - HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to open object") - break; - } - case H5VL_OBJECT_BY_SELF: default: HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, NULL, "unknown open parameters") @@ -166,53 +144,6 @@ H5VL__native_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_obj HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") switch(get_type) { - /* H5Rget_region */ - case H5VL_REF_GET_REGION: - { - hid_t *ret = HDva_arg(arguments, hid_t *); - H5R_type_t H5_ATTR_UNUSED ref_type = (H5R_type_t)HDva_arg(arguments, int); /* enum work-around */ - void *ref = HDva_arg(arguments, void *); - H5S_t *space = NULL; /* Dataspace object */ - - /* Get the dataspace with the correct region selected */ - if((space = H5R__get_region(loc.oloc->file, ref)) == NULL) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to retrieve region") - - /* Atomize */ - if((*ret = H5I_register(H5I_DATASPACE, space, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom") - - break; - } - - /* H5Rget_obj_type1/2 */ - case H5VL_REF_GET_TYPE: - { - H5O_type_t *obj_type = HDva_arg(arguments, H5O_type_t *); - H5R_type_t ref_type = (H5R_type_t)HDva_arg(arguments, int); /* enum work-around */ - void *ref = HDva_arg(arguments, void *); - - /* Get the object information */ - if(H5R__get_obj_type(loc.oloc->file, ref_type, ref, obj_type) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to determine object type") - break; - } - - /* H5Rget_name */ - case H5VL_REF_GET_NAME: - { - ssize_t *ret = HDva_arg(arguments, ssize_t *); - char *name = HDva_arg(arguments, char *); - size_t size = HDva_arg(arguments, size_t); - H5R_type_t ref_type = (H5R_type_t)HDva_arg(arguments, int); /* enum work-around */ - void *ref = HDva_arg(arguments, void *); - - /* Get name */ - if((*ret = H5R__get_name(loc.oloc->file, ref_type, ref, name, size)) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "unable to determine object path") - break; - } - /* Object name */ case H5VL_OBJECT_GET_NAME: { @@ -225,13 +156,13 @@ H5VL__native_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_obj if((*ret = H5G_get_name(&loc, name, size, NULL)) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't retrieve object name") } /* end if */ - else if(loc_params->type == H5VL_OBJECT_BY_ADDR) { + else if(loc_params->type == H5VL_OBJECT_BY_TOKEN) { H5O_loc_t obj_oloc; /* Object location */ /* Initialize the object location */ H5O_loc_reset(&obj_oloc); obj_oloc.file = loc.oloc->file; - obj_oloc.addr = loc_params->loc_data.loc_by_addr.addr; + obj_oloc.addr = *(haddr_t *)loc_params->loc_data.loc_by_token.token; /* Retrieve object's name */ if((*ret = H5G_get_name_by_addr(loc.oloc->file, &obj_oloc, name, size)) < 0) @@ -242,6 +173,29 @@ H5VL__native_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_obj break; } + /* Object type */ + case H5VL_OBJECT_GET_TYPE: + { + H5O_type_t *obj_type = HDva_arg(arguments, H5O_type_t *); + + if(loc_params->type == H5VL_OBJECT_BY_TOKEN) { + H5O_loc_t obj_oloc; /* Object location */ + unsigned rc; /* Reference count of object */ + + /* Initialize the object location */ + H5O_loc_reset(&obj_oloc); + obj_oloc.file = loc.oloc->file; + obj_oloc.addr = *(haddr_t *)loc_params->loc_data.loc_by_token.token; + + /* Get the # of links for object, and its type */ + /* (To check to make certain that this object hasn't been deleted) */ + if(H5O_get_rc_and_type(&obj_oloc, &rc, obj_type) < 0 || 0 == rc) + HGOTO_ERROR(H5E_REFERENCE, H5E_LINKCOUNT, FAIL, "dereferencing deleted object") + } else + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown get_type parameters") + break; + } + default: HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from object") } /* end switch */ @@ -300,6 +254,37 @@ H5VL__native_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5V break; } + /* Lookup object */ + case H5VL_OBJECT_LOOKUP: + { + void *token = va_arg(arguments, void *); + + HDassert(token); + + if(loc_params->type == H5VL_OBJECT_BY_NAME) { + H5G_loc_t obj_loc; /* Group hier. location of object */ + H5G_name_t obj_path; /* Object group hier. path */ + H5O_loc_t obj_oloc; /* Object object location */ + + /* Set up opened group location to fill in */ + obj_loc.oloc = &obj_oloc; + obj_loc.path = &obj_path; + H5G_loc_reset(&obj_loc); + + /* Find the object */ + if(H5G_loc_find(&loc, loc_params->loc_data.loc_by_name.name, &obj_loc) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL, "object not found") + *(haddr_t *)token = obj_loc.oloc->addr; + + /* Release the object location */ + if(H5G_loc_free(&obj_loc) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "can't free location") + } /* end if */ + else + HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown object exists parameters") + break; + } + case H5VL_OBJECT_VISIT: { H5_index_t idx_type = (H5_index_t)HDva_arg(arguments, int); /* enum work-around */ @@ -347,24 +332,6 @@ H5VL__native_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5V break; } - case H5VL_REF_CREATE: - { - void *ref = HDva_arg(arguments, void *); - const char *name = HDva_arg(arguments, char *); - H5R_type_t ref_type = (H5R_type_t)HDva_arg(arguments, int); /* enum work-around */ - hid_t space_id = HDva_arg(arguments, hid_t); - H5S_t *space = NULL; /* Pointer to dataspace containing region */ - - if(space_id != (-1) && (NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE)))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") - - /* Create reference */ - if(H5R__create(ref, &loc, name, ref_type, space) < 0) - HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create reference") - - break; - } - default: HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't recognize this operation type") } /* end switch */ diff --git a/src/H5VLnative_private.h b/src/H5VLnative_private.h index 714b73c..5ed0b1f 100644 --- a/src/H5VLnative_private.h +++ b/src/H5VLnative_private.h @@ -17,13 +17,34 @@ #ifndef _H5VLnative_private_H #define _H5VLnative_private_H +/* Private headers needed by this file */ #include "H5VLnative.h" /* Native VOL connector */ + +/**************************/ +/* Library Private Macros */ +/**************************/ + + +/****************************/ +/* Library Private Typedefs */ +/****************************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/******************************/ +/* Library Private Prototypes */ +/******************************/ + #ifdef __cplusplus extern "C" { #endif -/* Atrribute callbacks */ +/* Attribute callbacks */ H5_DLL void *H5VL__native_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); void *H5VL__native_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_attr_read(void *attr, hid_t dtype_id, void *buf, hid_t dxpl_id, void **req); @@ -80,6 +101,11 @@ H5_DLL herr_t H5VL__native_datatype_get(void *dt, H5VL_datatype_get_t get_type, H5_DLL herr_t H5VL__native_datatype_specific(void *dt, H5VL_datatype_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments); H5_DLL herr_t H5VL__native_datatype_close(void *dt, hid_t dxpl_id, void **req); +/* Blob callbacks */ +H5_DLL herr_t H5VL__native_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void *ctx); +H5_DLL herr_t H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, void *ctx); +H5_DLL herr_t H5VL__native_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); + #ifdef __cplusplus } #endif diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 24070fa..85c2211 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -178,6 +178,12 @@ static herr_t H5VL_pass_through_request_specific(void *req, H5VL_request_specifi static herr_t H5VL_pass_through_request_optional(void *req, va_list arguments); static herr_t H5VL_pass_through_request_free(void *req); +/* Blob callbacks */ +static herr_t H5VL_pass_through_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void *ctx); +static herr_t H5VL_pass_through_blob_get(void *obj, const void *blob_id, void *buf, size_t *size, void *ctx); +static herr_t H5VL_pass_through_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments); + + /*******************/ /* Local variables */ /*******************/ @@ -196,14 +202,14 @@ static const H5VL_class_t H5VL_pass_through_g = { H5VL_pass_through_info_cmp, /* compare */ H5VL_pass_through_info_free, /* free */ H5VL_pass_through_info_to_str, /* to_str */ - H5VL_pass_through_str_to_info, /* from_str */ + H5VL_pass_through_str_to_info /* from_str */ }, { /* wrap_cls */ H5VL_pass_through_get_object, /* get_object */ H5VL_pass_through_get_wrap_ctx, /* get_wrap_ctx */ H5VL_pass_through_wrap_object, /* wrap_object */ H5VL_pass_through_unwrap_object, /* unwrap_object */ - H5VL_pass_through_free_wrap_ctx, /* free_wrap_ctx */ + H5VL_pass_through_free_wrap_ctx /* free_wrap_ctx */ }, { /* attribute_cls */ H5VL_pass_through_attr_create, /* create */ @@ -255,14 +261,14 @@ static const H5VL_class_t H5VL_pass_through_g = { H5VL_pass_through_link_move, /* move */ H5VL_pass_through_link_get, /* get */ H5VL_pass_through_link_specific, /* specific */ - H5VL_pass_through_link_optional, /* optional */ + H5VL_pass_through_link_optional /* optional */ }, { /* object_cls */ H5VL_pass_through_object_open, /* open */ H5VL_pass_through_object_copy, /* copy */ H5VL_pass_through_object_get, /* get */ H5VL_pass_through_object_specific, /* specific */ - H5VL_pass_through_object_optional, /* optional */ + H5VL_pass_through_object_optional /* optional */ }, { /* request_cls */ H5VL_pass_through_request_wait, /* wait */ @@ -272,6 +278,12 @@ static const H5VL_class_t H5VL_pass_through_g = { H5VL_pass_through_request_optional, /* optional */ H5VL_pass_through_request_free /* free */ }, + { /* blob_cls */ + H5VL_pass_through_blob_put, /* put */ + H5VL_pass_through_blob_get, /* get */ + H5VL_pass_through_blob_specific, /* specific */ + NULL /* optional */ + }, NULL /* optional */ }; @@ -2834,3 +2846,83 @@ H5VL_pass_through_request_free(void *obj) return ret_value; } /* end H5VL_pass_through_request_free() */ + +/*------------------------------------------------------------------------- + * Function: H5VL_pass_through_blob_put + * + * Purpose: Handles the blob 'put' callback + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_pass_through_blob_put(void *obj, const void *buf, size_t size, + void *blob_id, void *ctx) +{ + H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + herr_t ret_value; + +#ifdef ENABLE_PASSTHRU_LOGGING + printf("------- PASS THROUGH VOL BLOB Put\n"); +#endif + + ret_value = H5VLblob_put(o->under_object, o->under_vol_id, buf, size, + blob_id, ctx); + + return ret_value; +} /* end H5VL_pass_through_blob_put() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_pass_through_blob_get + * + * Purpose: Handles the blob 'get' callback + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_pass_through_blob_get(void *obj, const void *blob_id, void *buf, + size_t *size, void *ctx) +{ + H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + herr_t ret_value; + +#ifdef ENABLE_PASSTHRU_LOGGING + printf("------- PASS THROUGH VOL BLOB Get\n"); +#endif + + ret_value = H5VLblob_get(o->under_object, o->under_vol_id, blob_id, buf, + size, ctx); + + return ret_value; +} /* end H5VL_pass_through_blob_get() */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_pass_through_blob_specific + * + * Purpose: Handles the blob 'specific' callback + * + * Return: SUCCEED / FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5VL_pass_through_blob_specific(void *obj, void *blob_id, + H5VL_blob_specific_t specific_type, va_list arguments) +{ + H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + herr_t ret_value; + +#ifdef ENABLE_PASSTHRU_LOGGING + printf("------- PASS THROUGH VOL BLOB Specific\n"); +#endif + + ret_value = H5VLblob_specific(o->under_object, o->under_vol_id, blob_id, + specific_type, arguments); + + return ret_value; +} /* end H5VL_pass_through_blob_specific() */ diff --git a/src/H5VLpassthru.h b/src/H5VLpassthru.h index e640636..d145bcd 100644 --- a/src/H5VLpassthru.h +++ b/src/H5VLpassthru.h @@ -17,6 +17,9 @@ #ifndef _H5VLpassthru_H #define _H5VLpassthru_H +/* Public headers needed by this file */ +#include "H5VLpublic.h" /* Virtual Object Layer */ + /* Identifier for the pass-through VOL connector */ #define H5VL_PASSTHRU (H5VL_pass_through_register()) diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 1752b0c..2889524 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -193,6 +193,11 @@ H5_DLL herr_t H5VL_request_specific(const H5VL_object_t *vol_obj, H5VL_request_s H5_DLL herr_t H5VL_request_optional(const H5VL_object_t *vol_obj, ...); H5_DLL herr_t H5VL_request_free(const H5VL_object_t *vol_obj); +/* Blob functions */ +H5_DLL herr_t H5VL_blob_put(const H5VL_object_t *vol_obj, const void *buf, size_t size, void *blob_id, void *ctx); +H5_DLL herr_t H5VL_blob_get(const H5VL_object_t *vol_obj, const void *blob_id, void *buf, size_t *size, void *ctx); +H5_DLL herr_t H5VL_blob_specific(const H5VL_object_t *vol_obj, void *blob_id, H5VL_blob_specific_t specific_type, ...); + /* Generic functions */ H5_DLL herr_t H5VL_optional(const H5VL_object_t *vol_obj, hid_t dxpl_id,void **req, ...); diff --git a/src/H5detect.c b/src/H5detect.c index 32b7d34..d01ee9f 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -107,8 +107,8 @@ typedef struct detected_t { unsigned int comp_align; /* alignment for structure */ } detected_t; -/* This structure holds structure alignment for pointers, hvl_t, hobj_ref_t, - * hdset_reg_ref_t */ +/* This structure holds structure alignment for pointers, vlen and reference + * types. */ typedef struct malign_t { const char *name; unsigned int comp_align; /* alignment for structure */ @@ -383,9 +383,8 @@ precision (detected_t *d) /*------------------------------------------------------------------------- * Function: DETECT_M * - * Purpose: This macro takes only miscellaneous structures or pointer - * (pointer, hvl_t, hobj_ref_t, hdset_reg_ref_t). It - * constructs the names and decides the alignment in structure. + * Purpose: This macro takes only miscellaneous structures or pointer. + * It constructs the names and decides the alignment in structure. * * Return: void *------------------------------------------------------------------------- @@ -761,8 +760,8 @@ H5T__init_native(void)\n\ H5T_native_order_g = H5T_ORDER_%s;\n", "BE"); } - /* Structure alignment for pointers, hvl_t, hobj_ref_t, hdset_reg_ref_t */ - fprintf(rawoutstream, "\n /* Structure alignment for pointers, hvl_t, hobj_ref_t, hdset_reg_ref_t */\n"); + /* Structure alignment for pointers, vlen and reference types */ + fprintf(rawoutstream, "\n /* Structure alignment for pointers, vlen and reference types */\n"); for(j=0; j<na; j++) fprintf(rawoutstream, " H5T_%s_COMP_ALIGN_g = %lu;\n", misc_align[j].name, (unsigned long)(misc_align[j].comp_align)); @@ -1544,11 +1543,12 @@ detect_C99_floats(void) static void HDF_NO_UBSAN detect_alignments(void) { - /* Detect structure alignment for pointers, hvl_t, hobj_ref_t, hdset_reg_ref_t */ + /* Detect structure alignment for pointers, vlen and reference types */ DETECT_M(void *, POINTER, m_g[na_g]); na_g++; DETECT_M(hvl_t, HVL, m_g[na_g]); na_g++; DETECT_M(hobj_ref_t, HOBJREF, m_g[na_g]); na_g++; DETECT_M(hdset_reg_ref_t, HDSETREGREF, m_g[na_g]); na_g++; + DETECT_M(H5R_ref_t, REF, m_g[na_g]); na_g++; } diff --git a/src/H5trace.c b/src/H5trace.c index b1301dd..79dfbc8 100644 --- a/src/H5trace.c +++ b/src/H5trace.c @@ -34,6 +34,7 @@ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5FDprivate.h" /* File drivers */ +#include "H5Rprivate.h" /* References */ #include "H5Ipkg.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5VLprivate.h" /* Virtual Object Layer */ @@ -1856,22 +1857,51 @@ H5_trace(const double *returning, const char *func, const char *type, ...) } /* end else */ break; - case 'r': - if(ptr) { - if(vp) - HDfprintf(out, "0x%lx", (unsigned long)vp); - else - HDfprintf(out, "NULL"); - } /* end if */ - else { - hobj_ref_t ref = HDva_arg(ap, hobj_ref_t); - - HDfprintf(out, "Reference Object=%a", ref); - } /* end else */ - break; - case 'R': switch(type[1]) { + + case 'o': + if(ptr) { + if(vp) + HDfprintf(out, "0x%lx", (unsigned long)vp); + else + HDfprintf(out, "NULL"); + } /* end if */ + else { + hobj_ref_t ref = HDva_arg(ap, hobj_ref_t); + + HDfprintf(out, "Reference Object=%a", ref); + } /* end else */ + break; + + case 'd': + if(ptr) { + if(vp) + HDfprintf(out, "0x%lx", (unsigned long)vp); + else + HDfprintf(out, "NULL"); + } /* end if */ + else { + /* Note! region references are array types */ + HDfprintf(out, "Reference Region"); + goto error; + } /* end else */ + break; + + case 'r': + if(ptr) { + if(vp) + HDfprintf(out, "0x%lx", (unsigned long)vp); + else + HDfprintf(out, "NULL"); + } /* end if */ + else { + /* Note! reference types are opaque types */ + HDfprintf(out, "Reference Opaque"); + goto error; + } /* end else */ + break; + case 't': if(ptr) { if(vp) @@ -1887,12 +1917,24 @@ H5_trace(const double *returning, const char *func, const char *type, ...) HDfprintf(out, "H5R_BADTYPE"); break; - case H5R_OBJECT: - HDfprintf(out, "H5R_OBJECT"); + case H5R_OBJECT1: + HDfprintf(out, "H5R_OBJECT1"); + break; + + case H5R_DATASET_REGION1: + HDfprintf(out, "H5R_DATASET_REGION1"); break; - case H5R_DATASET_REGION: - HDfprintf(out, "H5R_DATASET_REGION"); + case H5R_OBJECT2: + HDfprintf(out, "H5R_OBJECT2"); + break; + + case H5R_DATASET_REGION2: + HDfprintf(out, "H5R_DATASET_REGION2"); + break; + + case H5R_ATTR: + HDfprintf(out, "H5R_ATTR"); break; case H5R_MAXTYPE: @@ -2592,6 +2634,35 @@ H5_trace(const double *returning, const char *func, const char *type, ...) } /* end switch */ } /* end else */ break; + case 'B': + if(ptr) { + if(vp) + HDfprintf (out, "0x%lx", (unsigned long)vp); + else + HDfprintf(out, "NULL"); + } /* end if */ + else { + H5VL_blob_specific_t specific = (H5VL_blob_specific_t)HDva_arg(ap, int); + + switch(specific) { + case H5VL_BLOB_DELETE: + HDfprintf(out, "H5VL_BLOB_DELETE"); + break; + case H5VL_BLOB_GETSIZE: + HDfprintf(out, "H5VL_BLOB_GETSIZE"); + break; + case H5VL_BLOB_ISNULL: + HDfprintf(out, "H5VL_BLOB_ISNULL"); + break; + case H5VL_BLOB_SETNULL: + HDfprintf(out, "H5VL_BLOB_SETNULL"); + break; + default: + HDfprintf(out, "%ld", (long)specific); + break; + } /* end switch */ + } /* end else */ + break; case 'C': if(ptr) { if(vp) @@ -2729,18 +2800,21 @@ H5_trace(const double *returning, const char *func, const char *type, ...) H5VL_file_get_t get = (H5VL_file_get_t)HDva_arg(ap, int); switch(get) { + case H5VL_FILE_GET_CONT_INFO: + HDfprintf(out, "H5VL_FILE_GET_CONT_INFO"); + break; case H5VL_FILE_GET_FAPL: HDfprintf(out, "H5VL_FILE_GET_FAPL"); break; case H5VL_FILE_GET_FCPL: HDfprintf(out, "H5VL_FILE_GET_FCPL"); break; - case H5VL_FILE_GET_INTENT: - HDfprintf(out, "H5VL_FILE_GET_INTENT"); - break; case H5VL_FILE_GET_FILENO: HDfprintf(out, "H5VL_FILE_GET_FILENO"); break; + case H5VL_FILE_GET_INTENT: + HDfprintf(out, "H5VL_FILE_GET_INTENT"); + break; case H5VL_FILE_GET_NAME: HDfprintf(out, "H5VL_FILE_GET_NAME"); break; @@ -2926,18 +3000,12 @@ H5_trace(const double *returning, const char *func, const char *type, ...) H5VL_object_get_t get = (H5VL_object_get_t)HDva_arg(ap, int); switch(get) { - case H5VL_REF_GET_REGION: - HDfprintf(out, "H5VL_REF_GET_REGION"); - break; - case H5VL_REF_GET_TYPE: - HDfprintf(out, "H5VL_REF_GET_TYPE"); - break; - case H5VL_REF_GET_NAME: - HDfprintf(out, "H5VL_REF_GET_NAME"); - break; case H5VL_OBJECT_GET_NAME: HDfprintf(out, "H5VL_OBJECT_GET_NAME"); break; + case H5VL_OBJECT_GET_TYPE: + HDfprintf(out, "H5VL_OBJECT_GET_TYPE"); + break; default: HDfprintf(out, "%ld", (long)get); break; @@ -2961,12 +3029,12 @@ H5_trace(const double *returning, const char *func, const char *type, ...) case H5VL_OBJECT_EXISTS: HDfprintf(out, "H5VL_OBJECT_EXISTS"); break; + case H5VL_OBJECT_LOOKUP: + HDfprintf(out, "H5VL_OBJECT_LOOKUP"); + break; case H5VL_OBJECT_VISIT: HDfprintf(out, "H5VL_OBJECT_VISIT"); break; - case H5VL_REF_CREATE: - HDfprintf(out, "H5VL_REF_CREATE"); - break; case H5VL_OBJECT_FLUSH: HDfprintf(out, "H5VL_OBJECT_FLUSH"); break; diff --git a/src/Makefile.am b/src/Makefile.am index ccee69b..fa412c9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -83,7 +83,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5O.c H5Odeprec.c H5Oainfo.c H5Oalloc.c H5Oattr.c \ H5Oattribute.c H5Obogus.c H5Obtreek.c H5Ocache.c H5Ocache_image.c \ H5Ochunk.c \ - H5Ocont.c H5Ocopy.c H5Odbg.c H5Odrvinfo.c H5Odtype.c H5Oefl.c \ + H5Ocont.c H5Ocopy.c H5Ocopy_ref.c H5Odbg.c H5Odrvinfo.c H5Odtype.c H5Oefl.c \ H5Ofill.c H5Oflush.c H5Ofsinfo.c H5Oginfo.c \ H5Oint.c H5Olayout.c \ H5Olinfo.c H5Olink.c H5Omessage.c H5Omtime.c \ @@ -114,10 +114,12 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5Tfloat.c H5Tinit.c H5Tnative.c H5Toffset.c H5Toh.c \ H5Topaque.c \ H5Torder.c \ + H5Tref.c \ H5Tpad.c H5Tprecis.c H5Tstrpad.c H5Tvisit.c H5Tvlen.c H5TS.c \ H5VL.c H5VLcallback.c H5VLint.c H5VLnative.c \ - H5VLnative_attr.c H5VLnative_dataset.c H5VLnative_datatype.c \ - H5VLnative_file.c H5VLnative_group.c H5VLnative_link.c H5VLnative_object.c \ + H5VLnative_attr.c H5VLnative_blob.c H5VLnative_dataset.c \ + H5VLnative_datatype.c H5VLnative_file.c H5VLnative_group.c \ + H5VLnative_link.c H5VLnative_object.c \ H5VLpassthru.c \ H5VM.c H5WB.c H5Z.c \ H5Zdeflate.c H5Zfletcher32.c H5Znbit.c H5Zshuffle.c \ |