summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5Dchunk.c104
-rw-r--r--src/H5Dio.c84
-rw-r--r--src/H5Dprivate.h3
-rw-r--r--src/H5Dpublic.h2
-rw-r--r--src/H5F.c6
-rw-r--r--src/H5FDsec2.c2
-rw-r--r--src/H5Fpkg.h3
-rw-r--r--src/H5Fprivate.h1
-rw-r--r--src/H5Fpublic.h1
9 files changed, 202 insertions, 4 deletions
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c
index 7a06477..da7d809 100644
--- a/src/H5Dchunk.c
+++ b/src/H5Dchunk.c
@@ -281,6 +281,110 @@ H5FL_DEFINE(H5D_chunk_info_t);
/* Declare a free list to manage the chunk sequence information */
H5FL_BLK_DEFINE_STATIC(chunk);
+
+/*-------------------------------------------------------------------------
+ * Function: H5D__direct_write
+ *
+ * Purpose: Internal routine for H5PSIdirect_write to write a chunk
+ * directly into the file.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Raymond Lu
+ * 30 July 2012
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5D__chunk_direct_write(const H5D_t *dset, hid_t dxpl_id, unsigned filters, hsize_t *offset,
+ size_t data_size, const void *buf)
+{
+ const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */
+ H5D_chunk_ud_t udata; /* User data for querying chunk info */
+ hsize_t chunk_idx;
+ H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */
+ H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */
+ const H5D_rdcc_t *rdcc = &(dset->shared->cache.chunk); /*raw data chunk cache */
+ int space_ndims; /* Dataset's space rank */
+ hsize_t space_dim[H5O_LAYOUT_NDIMS]; /* Dataset's dataspace dimensions */
+ H5FD_t *lf;
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ /*FUNC_ENTER_PACKAGE*/
+ FUNC_ENTER_STATIC_TAG(dxpl_id, dset->oloc.addr, FAIL)
+
+ /* Allocate data space and initialize it if it hasn't been. */
+ if(!(*dset->shared->layout.ops->is_space_alloc)(&dset->shared->layout.storage)) {
+ /* Allocate storage */
+ if(H5D__alloc_storage(dset, dxpl_id, H5D_ALLOC_WRITE, FALSE, NULL) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage")
+ } /* end if */
+
+
+ /* Retrieve the dataset dimensions */
+ if((space_ndims = H5S_get_simple_extent_dims(dset->shared->space, space_dim, NULL)) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to get simple dataspace info")
+
+ /* Calculate the index of this chunk */
+ if(H5V_chunk_index((unsigned)space_ndims, offset,
+ layout->u.chunk.dim, layout->u.chunk.down_chunks, &chunk_idx) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't get chunk index")
+
+ /* Find out the file address of the chunk */
+ if(H5D__chunk_lookup(dset, dxpl_id, offset, chunk_idx,
+ &udata) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address")
+
+ udata.filter_mask = filters;
+
+ /* Check if the chunk needs to be 'inserted' (could exist already and
+ * the 'insert' operation could resize it)
+ */
+ {
+ H5D_chk_idx_info_t idx_info; /* Chunked index info */
+
+ /* Compose chunked index info struct */
+ idx_info.f = dset->oloc.file;
+ idx_info.dxpl_id = dxpl_id;
+ idx_info.pline = &(dset->shared->dcpl_cache.pline);
+ idx_info.layout = &(dset->shared->layout.u.chunk);
+ idx_info.storage = &(dset->shared->layout.storage.u.chunk);
+
+ /* Set up the size of chunk for user data */
+ udata.nbytes = data_size;
+
+ /* Create the chunk it if it doesn't exist, or reallocate the chunk
+ * if its size changed.
+ */
+ if((dset->shared->layout.storage.u.chunk.ops->insert)(&idx_info, &udata) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert/resize chunk")
+
+ /* Make sure the address of the chunk is returned. */
+ if(!H5F_addr_defined(udata.addr))
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "chunk address isn't defined")
+ } /* end if */
+
+ /* Fill the DXPL cache values for later use */
+ if(H5D__get_dxpl_cache(dxpl_id, &dxpl_cache) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't fill dxpl cache")
+
+ /* Evict the entry from the cache if present, but do not flush
+ * it to disk */
+ if(UINT_MAX != udata.idx_hint) {
+ if(H5D__chunk_cache_evict(dset, dxpl_id, dxpl_cache,
+ rdcc->slot[udata.idx_hint], FALSE) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTREMOVE, FAIL, "unable to evict chunk")
+ } /* end if */
+
+ /* Write the data to the file */
+ if(H5F_block_write(dset->oloc.file, H5FD_MEM_DRAW, udata.addr, data_size, dxpl_id, buf) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to write raw data to file")
+
+
+done:
+ /*FUNC_LEAVE_NOAPI(ret_value)*/
+ FUNC_LEAVE_NOAPI_TAG(ret_value, FAIL)
+}
/*-------------------------------------------------------------------------
diff --git a/src/H5Dio.c b/src/H5Dio.c
index 1bd6dae..7852b3e 100644
--- a/src/H5Dio.c
+++ b/src/H5Dio.c
@@ -28,6 +28,8 @@
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free Lists */
#include "H5Iprivate.h" /* IDs */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5Sprivate.h" /* Dataspace */
#ifdef H5_HAVE_PARALLEL
/* Remove this if H5R_DATASET_REGION is no longer used in this file */
@@ -271,6 +273,88 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5PSIdirect_write
+ *
+ * Purpose: Temporary name for the DECTRIS project. It writes an entire
+ * chunk to the file directly.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Raymond Lu
+ * 30 July 2012
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, unsigned filters, hsize_t *offset,
+ size_t data_size, const void *buf)
+{
+ H5D_t *dset = NULL;
+ int ndims;
+ hsize_t *dims = NULL;
+ hsize_t *internal_offset = NULL;
+ int i;
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+
+ /* check arguments */
+ if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
+ if(NULL == dset->oloc.file)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
+
+ if(H5D_CHUNKED != dset->shared->layout.type)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset")
+
+ /* 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")
+
+ if(!buf)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer")
+
+ ndims = (int)H5S_GET_EXTENT_NDIMS(dset->shared->space);
+ if(NULL == (dims = (hsize_t *)H5MM_malloc(ndims*sizeof(hsize_t))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for dimensions")
+
+ if(NULL == (internal_offset = (hsize_t *)H5MM_malloc((ndims+1)*sizeof(hsize_t))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for offset")
+
+ if(H5S_get_simple_extent_dims(dset->shared->space, dims, NULL) < 0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't retrieve dataspace extent dims")
+
+ for(i=0; i<ndims; i++) {
+ /* Make sure the offset doesn't exceed the dataset's dimensions */
+ if(offset[i] > dims[i])
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "offset exceeds dimensions of dataset")
+
+ /* Make sure the offset fall right on a chunk's boundary */
+ if(offset[i] % dset->shared->layout.u.chunk.dim[i])
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "offset doesn't fall on chunks's boundary")
+
+ internal_offset[i] = offset[i];
+ }
+
+ /* The library's chunking code requires the offset terminates with a zero */
+ internal_offset[ndims] = 0;
+
+ /* write raw data */
+ if(H5D__chunk_direct_write(dset, dxpl_id, filters, internal_offset, data_size, buf) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data")
+
+done:
+ if(dims)
+ H5MM_free(dims);
+
+ FUNC_LEAVE_API(ret_value)
+} /* end H5PSIdirect_write() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5D__read
*
* Purpose: Reads (part of) a DATASET into application memory BUF. See
diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h
index 85051c3..48c6ddd 100644
--- a/src/H5Dprivate.h
+++ b/src/H5Dprivate.h
@@ -178,5 +178,8 @@ H5_DLL herr_t H5D_chunk_idx_reset(H5O_storage_chunk_t *storage, hbool_t reset_ad
H5_DLL herr_t H5D_btree_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream,
int indent, int fwidth, unsigned ndims);
+H5_DLL herr_t H5D__chunk_direct_write(const H5D_t *dset, hid_t dxpl_id, unsigned filters,
+ hsize_t *offset, size_t data_size, const void *buf);
+
#endif /* _H5Dprivate_H */
diff --git a/src/H5Dpublic.h b/src/H5Dpublic.h
index c878d4a..58c2a2b 100644
--- a/src/H5Dpublic.h
+++ b/src/H5Dpublic.h
@@ -118,6 +118,8 @@ H5_DLL herr_t H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t plist_id, void *buf/*out*/);
H5_DLL herr_t H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t plist_id, const void *buf);
+H5_DLL herr_t H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, unsigned filters, hsize_t *offset,
+ size_t data_size, const 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);
diff --git a/src/H5F.c b/src/H5F.c
index 12c25cd..d864e88 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -1261,7 +1261,7 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id,
* way for us to detect it here anyway).
*/
if(drvr->cmp)
- tent_flags = flags & ~(H5F_ACC_CREAT|H5F_ACC_TRUNC|H5F_ACC_EXCL);
+ tent_flags = flags & ~(H5F_ACC_CREAT|H5F_ACC_TRUNC|H5F_ACC_EXCL|H5F_ACC_SYNC);
else
tent_flags = flags;
@@ -1464,9 +1464,9 @@ H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
if(!filename || !*filename)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file name")
/* In this routine, we only accept the following flags:
- * H5F_ACC_EXCL, H5F_ACC_TRUNC and H5F_ACC_DEBUG
+ * H5F_ACC_SYNC, H5F_ACC_EXCL, H5F_ACC_TRUNC and H5F_ACC_DEBUG
*/
- if(flags & ~(H5F_ACC_EXCL | H5F_ACC_TRUNC | H5F_ACC_DEBUG))
+ if(flags & ~(H5F_ACC_SYNC | H5F_ACC_EXCL | H5F_ACC_TRUNC | H5F_ACC_DEBUG))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid flags")
/* The H5F_ACC_EXCL and H5F_ACC_TRUNC flags are mutually exclusive */
if((flags & H5F_ACC_EXCL) && (flags & H5F_ACC_TRUNC))
diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c
index 241609d..b65fee9 100644
--- a/src/H5FDsec2.c
+++ b/src/H5FDsec2.c
@@ -357,6 +357,8 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
o_flags |= O_CREAT;
if(H5F_ACC_EXCL & flags)
o_flags |= O_EXCL;
+ if(H5F_ACC_SYNC & flags)
+ o_flags |= O_SYNC;
/* Open the file */
if((fd = HDopen(name, o_flags, 0666)) < 0) {
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index 334879c..2d4678b 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -63,7 +63,8 @@
#define H5F_SUPER_ALL_FLAGS (H5F_SUPER_WRITE_ACCESS | H5F_SUPER_FILE_OK)
/* Mask for removing private file access flags */
-#define H5F_ACC_PUBLIC_FLAGS 0x001fu
+/* #define H5F_ACC_PUBLIC_FLAGS 0x001fu */
+#define H5F_ACC_PUBLIC_FLAGS 0x003fu
/* Free space section+aggregator merge flags */
#define H5F_FS_MERGE_METADATA 0x01 /* Section can merge with metadata aggregator */
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 7c6fae8..1ef40b0 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -547,6 +547,7 @@ H5_DLL hbool_t H5F_use_tmp_space(const H5F_t *f);
H5_DLL hbool_t H5F_is_tmp_addr(const H5F_t *f, haddr_t addr);
/* Functions that retrieve values from VFD layer */
+H5_DLL H5FD_t* H5F_get_driver(const H5F_t *f);
H5_DLL hid_t H5F_get_driver_id(const H5F_t *f);
H5_DLL herr_t H5F_get_fileno(const H5F_t *f, unsigned long *filenum);
H5_DLL hbool_t H5F_has_feature(const H5F_t *f, unsigned feature);
diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h
index f32b3e0..7b7acb4 100644
--- a/src/H5Fpublic.h
+++ b/src/H5Fpublic.h
@@ -48,6 +48,7 @@
#define H5F_ACC_EXCL (H5CHECK 0x0004u) /*fail if file already exists*/
#define H5F_ACC_DEBUG (H5CHECK 0x0008u) /*print debug info */
#define H5F_ACC_CREAT (H5CHECK 0x0010u) /*create non-existing files */
+#define H5F_ACC_SYNC (H5CHECK 0x0020u) /*no filesystem caching */
/* Value passed to H5Pset_elink_acc_flags to cause flags to be taken from the
* parent file. */