diff options
Diffstat (limited to 'src/H5FDcore.c')
-rw-r--r-- | src/H5FDcore.c | 558 |
1 files changed, 263 insertions, 295 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 9b4aadc..b51ea8c 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -17,57 +17,40 @@ * Programmer: Robb Matzke <matzke@llnl.gov> * Tuesday, August 10, 1999 * - * Purpose: A driver which stores the HDF5 data in main memory using - * only the HDF5 public API. This driver is useful for fast - * access to small, temporary hdf5 files. + * Purpose: A driver which stores the HDF5 data in main memory using + * only the HDF5 public API. This driver is useful for fast + * access to small, temporary hdf5 files. */ /* Interface initialization */ #define H5_INTERFACE_INIT_FUNC H5FD_core_init_interface -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5FDcore.h" /* Core file driver */ -#include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5Pprivate.h" /* Property lists */ +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fprivate.h" /* File access */ +#include "H5FDprivate.h" /* File drivers */ +#include "H5FDcore.h" /* Core file driver */ +#include "H5Iprivate.h" /* IDs */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5Pprivate.h" /* Property lists */ /* The driver identification number, initialized at runtime */ static hid_t H5FD_CORE_g = 0; -/* Since Windows doesn't follow the rest of the world when it comes - * to POSIX I/O types, some typedefs and constants are needed to avoid - * making the code messy with #ifdefs. - * NOTE: These are only used when writing data to the backing store on - * file close. - */ -#ifdef H5_HAVE_WIN32_API -typedef unsigned int h5_core_io_t; -typedef int h5_core_io_ret_t; -static int H5_CORE_MAX_IO_BYTES_g = INT_MAX; -#else -/* Unix, everyone else */ -typedef size_t h5_core_io_t; -typedef ssize_t h5_core_io_ret_t; -static size_t H5_CORE_MAX_IO_BYTES_g = SSIZET_MAX; -#endif /* H5_HAVE_WIN32_API */ - -/* The description of a file belonging to this driver. The `eoa' and `eof' +/* The description of a file belonging to this driver. The 'eoa' and 'eof' * determine the amount of hdf5 address space in use and the high-water mark * of the file (the current size of the underlying memory). */ typedef struct H5FD_core_t { - H5FD_t pub; /*public stuff, must be first */ - char *name; /*for equivalence testing */ - unsigned char *mem; /*the underlying memory */ - haddr_t eoa; /*end of allocated region */ - haddr_t eof; /*current allocated size */ - size_t increment; /*multiples for mem allocation */ - hbool_t backing_store; /*write to file name on flush */ - int fd; /*backing store file descriptor */ + H5FD_t pub; /* public stuff, must be first */ + char *name; /* for equivalence testing */ + unsigned char *mem; /* the underlying memory */ + haddr_t eoa; /* end of allocated region */ + haddr_t eof; /* current allocated size */ + size_t increment; /* multiples for mem allocation */ + hbool_t backing_store; /* write to file name on flush */ + int fd; /* backing store file descriptor */ /* Information for determining uniqueness of a file with a backing store */ #ifndef H5_HAVE_WIN32_API /* On most systems the combination of device and i-node number uniquely @@ -100,8 +83,8 @@ typedef struct H5FD_core_t { HANDLE hFile; /* Native windows file handle */ #endif /* H5_HAVE_WIN32_API */ - hbool_t dirty; /*changes not saved? */ - H5FD_file_image_callbacks_t fi_callbacks; /* file image callbacks */ + hbool_t dirty; /* changes not saved? */ + H5FD_file_image_callbacks_t fi_callbacks; /* file image callbacks */ /* Information from file open flags, for SWMR access */ hbool_t swmr_read; /* Whether the file is open for SWMR read access */ @@ -109,38 +92,38 @@ typedef struct H5FD_core_t { /* Driver-specific file access properties */ typedef struct H5FD_core_fapl_t { - size_t increment; /*how much to grow memory */ - hbool_t backing_store; /*write to file name on flush */ + size_t increment; /* how much to grow memory */ + hbool_t backing_store; /* write to file name on flush */ } H5FD_core_fapl_t; /* Allocate memory in multiples of this size by default */ -#define H5FD_CORE_INCREMENT 8192 +#define H5FD_CORE_INCREMENT 8192 /* These macros check for overflow of various quantities. These macros * assume that file_offset_t is signed and haddr_t and size_t are unsigned. * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. + * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' + * is too large to be represented by the second argument + * of the file seek function. * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. + * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too + * large to be represented by the `size_t' type. * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely in memory. + * REGION_OVERFLOW: Checks whether an address and size pair describe data + * which can be addressed entirely in memory. */ -#define MAXADDR ((haddr_t)((~(size_t)0)-1)) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || (A) > (haddr_t)MAXADDR) -#define SIZE_OVERFLOW(Z) ((Z) > (hsize_t)MAXADDR) -#define REGION_OVERFLOW(A,Z) (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || \ - HADDR_UNDEF==(A)+(Z) || \ - (size_t)((A)+(Z))<(size_t)(A)) +#define MAXADDR ((haddr_t)((~(size_t)0)-1)) +#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || (A) > (haddr_t)MAXADDR) +#define SIZE_OVERFLOW(Z) ((Z) > (hsize_t)MAXADDR) +#define REGION_OVERFLOW(A,Z) (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || \ + HADDR_UNDEF==(A)+(Z) || \ + (size_t)((A)+(Z))<(size_t)(A)) /* Prototypes */ static herr_t H5FD_core_term(void); static void *H5FD_core_fapl_get(H5FD_t *_file); static H5FD_t *H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, - haddr_t maxaddr); + haddr_t maxaddr); static herr_t H5FD_core_close(H5FD_t *_file); static int H5FD_core_cmp(const H5FD_t *_f1, const H5FD_t *_f2); static herr_t H5FD_core_query(const H5FD_t *_f1, unsigned long *flags); @@ -149,61 +132,58 @@ static herr_t H5FD_core_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr); static haddr_t H5FD_core_get_eof(const H5FD_t *_file); static herr_t H5FD_core_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle); static herr_t H5FD_core_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, - size_t size, void *buf); + size_t size, void *buf); static herr_t H5FD_core_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, - size_t size, const void *buf); + size_t size, const void *buf); static herr_t H5FD_core_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); static herr_t H5FD_core_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static const H5FD_class_t H5FD_core_g = { - "core", /*name */ - MAXADDR, /*maxaddr */ - H5F_CLOSE_WEAK, /*fc_degree */ - H5FD_core_term, /*terminate */ - NULL, /*sb_size */ - NULL, /*sb_encode */ - NULL, /*sb_decode */ - sizeof(H5FD_core_fapl_t), /*fapl_size */ - H5FD_core_fapl_get, /*fapl_get */ - NULL, /*fapl_copy */ - NULL, /*fapl_free */ - 0, /*dxpl_size */ - NULL, /*dxpl_copy */ - NULL, /*dxpl_free */ - H5FD_core_open, /*open */ - H5FD_core_close, /*close */ - H5FD_core_cmp, /*cmp */ - H5FD_core_query, /*query */ - NULL, /*get_type_map */ - NULL, /*alloc */ - NULL, /*free */ - H5FD_core_get_eoa, /*get_eoa */ - H5FD_core_set_eoa, /*set_eoa */ - H5FD_core_get_eof, /*get_eof */ - H5FD_core_get_handle, /*get_handle */ - H5FD_core_read, /*read */ - H5FD_core_write, /*write */ - H5FD_core_flush, /*flush */ - H5FD_core_truncate, /*truncate */ - NULL, /*lock */ - NULL, /*unlock */ - H5FD_FLMAP_DICHOTOMY /*fl_map */ + "core", /* name */ + MAXADDR, /* maxaddr */ + H5F_CLOSE_WEAK, /* fc_degree */ + H5FD_core_term, /* terminate */ + NULL, /* sb_size */ + NULL, /* sb_encode */ + NULL, /* sb_decode */ + sizeof(H5FD_core_fapl_t), /* fapl_size */ + H5FD_core_fapl_get, /* fapl_get */ + NULL, /* fapl_copy */ + NULL, /* fapl_free */ + 0, /* dxpl_size */ + NULL, /* dxpl_copy */ + NULL, /* dxpl_free */ + H5FD_core_open, /* open */ + H5FD_core_close, /* close */ + H5FD_core_cmp, /* cmp */ + H5FD_core_query, /* query */ + NULL, /* get_type_map */ + NULL, /* alloc */ + NULL, /* free */ + H5FD_core_get_eoa, /* get_eoa */ + H5FD_core_set_eoa, /* set_eoa */ + H5FD_core_get_eof, /* get_eof */ + H5FD_core_get_handle, /* get_handle */ + H5FD_core_read, /* read */ + H5FD_core_write, /* write */ + H5FD_core_flush, /* flush */ + H5FD_core_truncate, /* truncate */ + NULL, /* lock */ + NULL, /* unlock */ + H5FD_FLMAP_DICHOTOMY /* fl_map */ }; -/*-------------------------------------------------------------------------- -NAME - H5FD_core_init_interface -- Initialize interface-specific information -USAGE - herr_t H5FD_core_init_interface() - -RETURNS - Non-negative on success/Negative on failure -DESCRIPTION - Initializes any interface-specific data or routines. (Just calls - H5FD_core_init currently). - ---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * Function: H5FD_core_init_interface + * + * Purpose: Initializes any interface-specific data or routines. + * + * Return: Success: The driver ID for the core driver. + * Failure: Negative. + * + *------------------------------------------------------------------------- + */ static herr_t H5FD_core_init_interface(void) { @@ -214,16 +194,15 @@ H5FD_core_init_interface(void) /*------------------------------------------------------------------------- - * Function: H5FD_core_init + * Function: H5FD_core_init * - * Purpose: Initialize this driver by registering the driver with the - * library. + * Purpose: Initialize this driver by registering the driver with the + * library. * - * Return: Success: The driver ID for the core driver. + * Return: Success: The driver ID for the core driver. + * Failure: Negative. * - * Failure: Negative. - * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- @@ -231,15 +210,15 @@ H5FD_core_init_interface(void) hid_t H5FD_core_init(void) { - hid_t ret_value=H5FD_CORE_g; /* Return value */ + hid_t ret_value = H5FD_CORE_g; /* Return value */ FUNC_ENTER_NOAPI(FAIL) - if (H5I_VFL!=H5Iget_type(H5FD_CORE_g)) + if(H5I_VFL != H5Iget_type(H5FD_CORE_g)) H5FD_CORE_g = H5FD_register(&H5FD_core_g,sizeof(H5FD_class_t),FALSE); /* Set return value */ - ret_value=H5FD_CORE_g; + ret_value = H5FD_CORE_g; done: FUNC_LEAVE_NOAPI(ret_value) @@ -247,11 +226,11 @@ done: /*--------------------------------------------------------------------------- - * Function: H5FD_core_term + * Function: H5FD_core_term * - * Purpose: Shut down the VFD + * Purpose: Shut down the VFD * - * Returns: Non-negative on success or negative on failure + * Returns: SUCCEED (Can't fail) * * Programmer: Quincey Koziol * Friday, Jan 30, 2004 @@ -264,32 +243,32 @@ H5FD_core_term(void) FUNC_ENTER_NOAPI_NOINIT_NOERR /* Reset VFL ID */ - H5FD_CORE_g=0; + H5FD_CORE_g = 0; FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD_core_term() */ /*------------------------------------------------------------------------- - * Function: H5Pset_fapl_core + * Function: H5Pset_fapl_core * - * Purpose: Modify the file access property list to use the H5FD_CORE - * driver defined in this source file. The INCREMENT specifies - * how much to grow the memory each time we need more. + * Purpose: Modify the file access property list to use the H5FD_CORE + * driver defined in this source file. The INCREMENT specifies + * how much to grow the memory each time we need more. * - * Return: Non-negative on success/Negative on failure + * Return: SUCCEED/FAIL * - * Programmer: Robb Matzke - * Thursday, February 19, 1998 + * Programmer: Robb Matzke + * Thursday, February 19, 1998 * *------------------------------------------------------------------------- */ herr_t H5Pset_fapl_core(hid_t fapl_id, size_t increment, hbool_t backing_store) { - H5FD_core_fapl_t fa; - H5P_genplist_t *plist; /* Property list pointer */ - herr_t ret_value; + H5FD_core_fapl_t fa; + H5P_genplist_t *plist; /* Property list pointer */ + herr_t ret_value; FUNC_ENTER_API(FAIL) H5TRACE3("e", "izb", fapl_id, increment, backing_store); @@ -309,26 +288,23 @@ done: /*------------------------------------------------------------------------- - * Function: H5Pget_fapl_core - * - * Purpose: Queries properties set by the H5Pset_fapl_core() function. + * Function: H5Pget_fapl_core * - * Return: Success: Non-negative + * Purpose: Queries properties set by the H5Pset_fapl_core() function. * - * Failure: Negative + * Return: SUCCEED/FAIL * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Tuesday, August 10, 1999 * *------------------------------------------------------------------------- */ herr_t -H5Pget_fapl_core(hid_t fapl_id, size_t *increment/*out*/, - hbool_t *backing_store/*out*/) +H5Pget_fapl_core(hid_t fapl_id, size_t *increment /*out*/, hbool_t *backing_store /*out*/) { - H5FD_core_fapl_t *fa; - H5P_genplist_t *plist; /* Property list pointer */ - herr_t ret_value=SUCCEED; /* Return value */ + H5FD_core_fapl_t *fa; + H5P_genplist_t *plist; /* Property list pointer */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE3("e", "ixx", fapl_id, increment, backing_store); @@ -351,15 +327,15 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_fapl_get + * Function: H5FD_core_fapl_get * - * Purpose: Returns a copy of the file access properties. + * Purpose: Returns a copy of the file access properties. * - * Return: Success: Ptr to new file access properties. + * Return: Success: Ptr to new file access properties. * - * Failure: NULL + * Failure: NULL * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Friday, August 13, 1999 * *------------------------------------------------------------------------- @@ -367,9 +343,9 @@ done: static void * H5FD_core_fapl_get(H5FD_t *_file) { - H5FD_core_t *file = (H5FD_core_t*)_file; - H5FD_core_fapl_t *fa; - void *ret_value; /* Return value */ + H5FD_core_t *file = (H5FD_core_t*)_file; + H5FD_core_fapl_t *fa; + void *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -380,7 +356,7 @@ H5FD_core_fapl_get(H5FD_t *_file) fa->backing_store = (hbool_t)(file->fd >= 0); /* Set return value */ - ret_value=fa; + ret_value = fa; done: FUNC_LEAVE_NOAPI(ret_value) @@ -388,36 +364,35 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_open + * Function: H5FD_core_open * - * Purpose: Create memory as an HDF5 file. + * Purpose: Create memory as an HDF5 file. * - * Return: Success: A pointer to a new file data structure. The - * public fields will be initialized by the - * caller, which is always H5FD_open(). + * Return: Success: A pointer to a new file data structure. The + * public fields will be initialized by the + * caller, which is always H5FD_open(). * - * Failure: NULL + * Failure: NULL * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- */ static H5FD_t * -H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, - haddr_t maxaddr) +H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) { - int o_flags; - H5FD_core_t *file=NULL; - H5FD_core_fapl_t *fa=NULL; - H5P_genplist_t *plist; /* Property list pointer */ + int o_flags; + H5FD_core_t *file = NULL; + H5FD_core_fapl_t *fa = NULL; + H5P_genplist_t *plist; /* Property list pointer */ #ifdef H5_HAVE_WIN32_API struct _BY_HANDLE_FILE_INFORMATION fileinfo; #endif - h5_stat_t sb; - int fd=-1; - H5FD_file_image_info_t file_image_info; - H5FD_t *ret_value; + h5_stat_t sb; + int fd = -1; + H5FD_file_image_info_t file_image_info; + H5FD_t *ret_value; FUNC_ENTER_NOAPI_NOINIT @@ -557,20 +532,23 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, /* Read in existing data, being careful of interrupted system calls, * partial results, and the end of the file. */ + + uint8_t *mem = file->mem; /* memory pointer for writes */ + while(size > 0) { - h5_core_io_t bytes_in = 0; /* # of bytes to read */ - h5_core_io_ret_t bytes_read = -1; /* # of bytes actually read */ + h5_posix_io_t bytes_in = 0; /* # of bytes to read */ + h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */ /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. */ - if(size > H5_CORE_MAX_IO_BYTES_g) - bytes_in = H5_CORE_MAX_IO_BYTES_g; + if(size > H5_POSIX_MAX_IO_BYTES) + bytes_in = H5_POSIX_MAX_IO_BYTES; else - bytes_in = (h5_core_io_t)size; + bytes_in = (h5_posix_io_t)size; do { - bytes_read = HDread(file->fd, file->mem, bytes_in); + bytes_read = HDread(file->fd, mem, bytes_in); } while(-1 == bytes_read && EINTR == errno); if(-1 == bytes_read) { /* error */ @@ -578,12 +556,13 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, time_t mytime = HDtime(NULL); HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - HGOTO_ERROR(H5E_IO, H5E_READERROR, NULL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', file->mem = %p, size = %lu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), file->mem, (unsigned long)size, (unsigned long long)myoffset); + HGOTO_ERROR(H5E_IO, H5E_READERROR, NULL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', file->mem = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), file->mem, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)myoffset); } /* end if */ HDassert(bytes_read >= 0); HDassert((size_t)bytes_read <= size); + mem += bytes_read; size -= (size_t)bytes_read; } /* end while */ } /* end else */ @@ -598,20 +577,26 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, ret_value = (H5FD_t *)file; done: + if(!ret_value && file) { + if(file->fd >= 0) + HDclose(file->fd); + H5MM_xfree(file->name); + H5MM_xfree(file->mem); + H5MM_xfree(file); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_core_open() */ /*------------------------------------------------------------------------- - * Function: H5FD_core_close + * Function: H5FD_core_close * - * Purpose: Closes the file. + * Purpose: Closes the file. * - * Return: Success: 0 + * Return: SUCCEED/FAIL * - * Failure: -1 - * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- @@ -619,8 +604,8 @@ done: static herr_t H5FD_core_close(H5FD_t *_file) { - H5FD_core_t *file = (H5FD_core_t*)_file; - herr_t ret_value = SUCCEED; /* Return value */ + H5FD_core_t *file = (H5FD_core_t*)_file; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -651,19 +636,19 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_cmp + * Function: H5FD_core_cmp * - * Purpose: Compares two files belonging to this driver by name. If one - * file doesn't have a name then it is less than the other file. - * If neither file has a name then the comparison is by file - * address. + * Purpose: Compares two files belonging to this driver by name. If one + * file doesn't have a name then it is less than the other file. + * If neither file has a name then the comparison is by file + * address. * - * Return: Success: A value like strcmp() + * Return: Success: A value like strcmp() * - * Failure: never fails (arguments were checked by the - * caller). + * Failure: never fails (arguments were checked by the + * caller). * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- @@ -671,9 +656,9 @@ done: static int H5FD_core_cmp(const H5FD_t *_f1, const H5FD_t *_f2) { - const H5FD_core_t *f1 = (const H5FD_core_t*)_f1; - const H5FD_core_t *f2 = (const H5FD_core_t*)_f2; - int ret_value = 0; + const H5FD_core_t *f1 = (const H5FD_core_t*)_f1; + const H5FD_core_t *f2 = (const H5FD_core_t*)_f2; + int ret_value = 0; FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -735,15 +720,14 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_query + * Function: H5FD_core_query * - * Purpose: Set the flags that this VFL driver is capable of supporting. + * Purpose: Set the flags that this VFL driver is capable of supporting. * (listed in H5FDpublic.h) * - * Return: Success: non-negative - * Failure: negative + * Return: SUCCEED (Can't fail) * - * Programmer: Quincey Koziol + * Programmer: Quincey Koziol * Tuesday, October 7, 2008 * *------------------------------------------------------------------------- @@ -751,7 +735,7 @@ done: static herr_t H5FD_core_query(const H5FD_t * _file, unsigned long *flags /* out */) { - const H5FD_core_t *file = (const H5FD_core_t*)_file; + const H5FD_core_t *file = (const H5FD_core_t*)_file; FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -775,17 +759,15 @@ H5FD_core_query(const H5FD_t * _file, unsigned long *flags /* out */) /*------------------------------------------------------------------------- - * Function: H5FD_core_get_eoa - * - * Purpose: Gets the end-of-address marker for the file. The EOA marker - * is the first address past the last byte allocated in the - * format address space. + * Function: H5FD_core_get_eoa * - * Return: Success: The end-of-address marker. + * Purpose: Gets the end-of-address marker for the file. The EOA marker + * is the first address past the last byte allocated in the + * format address space. * - * Failure: HADDR_UNDEF + * Return: The end-of-address marker. (Can't fail) * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Monday, August 2, 1999 * *------------------------------------------------------------------------- @@ -793,7 +775,7 @@ H5FD_core_query(const H5FD_t * _file, unsigned long *flags /* out */) static haddr_t H5FD_core_get_eoa(const H5FD_t *_file, H5FD_mem_t UNUSED type) { - const H5FD_core_t *file = (const H5FD_core_t*)_file; + const H5FD_core_t *file = (const H5FD_core_t*)_file; FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -802,17 +784,15 @@ H5FD_core_get_eoa(const H5FD_t *_file, H5FD_mem_t UNUSED type) /*------------------------------------------------------------------------- - * Function: H5FD_core_set_eoa + * Function: H5FD_core_set_eoa * - * Purpose: Set the end-of-address marker for the file. This function is - * called shortly after an existing HDF5 file is opened in order - * to tell the driver where the end of the HDF5 data is located. + * Purpose: Set the end-of-address marker for the file. This function is + * called shortly after an existing HDF5 file is opened in order + * to tell the driver where the end of the HDF5 data is located. * - * Return: Success: 0 + * Return: SUCCEED/FAIL * - * Failure: -1 - * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- @@ -820,8 +800,8 @@ H5FD_core_get_eoa(const H5FD_t *_file, H5FD_mem_t UNUSED type) static herr_t H5FD_core_set_eoa(H5FD_t *_file, H5FD_mem_t UNUSED type, haddr_t addr) { - H5FD_core_t *file = (H5FD_core_t*)_file; - herr_t ret_value = SUCCEED; /* Return value */ + H5FD_core_t *file = (H5FD_core_t*)_file; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -836,19 +816,17 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_get_eof - * - * Purpose: Returns the end-of-file marker, which is the greater of - * either the size of the underlying memory or the HDF5 - * end-of-address markers. + * Function: H5FD_core_get_eof * - * Return: Success: End of file address, the first address past - * the end of the "file", either the memory - * or the HDF5 file. + * Purpose: Returns the end-of-file marker, which is the greater of + * either the size of the underlying memory or the HDF5 + * end-of-address markers. * - * Failure: HADDR_UNDEF + * Return: End of file address, the first address past + * the end of the "file", either the memory + * or the HDF5 file. (Can't fail) * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- @@ -856,7 +834,7 @@ done: static haddr_t H5FD_core_get_eof(const H5FD_t *_file) { - const H5FD_core_t *file = (const H5FD_core_t*)_file; + const H5FD_core_t *file = (const H5FD_core_t*)_file; FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -867,9 +845,9 @@ H5FD_core_get_eof(const H5FD_t *_file) /*------------------------------------------------------------------------- * Function: H5FD_core_get_handle * - * Purpose: Returns the file handle of CORE file driver. + * Purpose: Gets the file handle of CORE file driver. * - * Returns: Non-negative if succeed or negative if fails. + * Returns: SUCCEED/FAIL * * Programmer: Raymond Lu * Sept. 16, 2002 @@ -880,7 +858,7 @@ static herr_t H5FD_core_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle) { H5FD_core_t *file = (H5FD_core_t *)_file; /* core VFD info */ - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -925,26 +903,25 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_read + * Function: H5FD_core_read * - * Purpose: Reads SIZE bytes of data from FILE beginning at address ADDR - * into buffer BUF according to data transfer properties in - * DXPL_ID. + * Purpose: Reads SIZE bytes of data from FILE beginning at address ADDR + * into buffer BUF according to data transfer properties in + * DXPL_ID. * - * Return: Success: Zero. Result is stored in caller-supplied - * buffer BUF. + * Return: Success: SUCCEED. Result is stored in caller-supplied + * buffer BUF. * - * Failure: -1, Contents of buffer BUF are undefined. + * Failure: FAIL, Contents of buffer BUF are undefined. * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t H5FD_core_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, haddr_t addr, - size_t size, void *buf/*out*/) + size_t size, void *buf/*out*/) { H5FD_core_t *file = (H5FD_core_t*)_file; herr_t ret_value=SUCCEED; /* Return value */ @@ -997,28 +974,25 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_write - * - * Purpose: Writes SIZE bytes of data to FILE beginning at address ADDR - * from buffer BUF according to data transfer properties in - * DXPL_ID. + * Function: H5FD_core_write * - * Return: Success: Zero + * Purpose: Writes SIZE bytes of data to FILE beginning at address ADDR + * from buffer BUF according to data transfer properties in + * DXPL_ID. * - * Failure: -1 + * Return: SUCCEED/FAIL * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Thursday, July 29, 1999 * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t H5FD_core_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, haddr_t addr, - size_t size, const void *buf) + size_t size, const void *buf) { H5FD_core_t *file = (H5FD_core_t*)_file; - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -1057,7 +1031,7 @@ H5FD_core_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had } /* end else */ #ifdef H5_CLEAR_MEMORY -HDmemset(x + file->eof, 0, (size_t)(new_eof - file->eof)); + HDmemset(x + file->eof, 0, (size_t)(new_eof - file->eof)); #endif /* H5_CLEAR_MEMORY */ file->mem = x; @@ -1076,49 +1050,46 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_flush + * Function: H5FD_core_flush * - * Purpose: Flushes the file to backing store if there is any and if the - * dirty flag is set. + * Purpose: Flushes the file to backing store if there is any and if the + * dirty flag is set. * - * Return: Success: 0 + * Return: SUCCEED/FAIL * - * Failure: -1 - * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Friday, October 15, 1999 * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t H5FD_core_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) { - H5FD_core_t *file = (H5FD_core_t*)_file; - herr_t ret_value=SUCCEED; /* Return value */ + H5FD_core_t *file = (H5FD_core_t*)_file; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* Write to backing store */ - if (file->dirty && file->fd>=0 && file->backing_store) { + if (file->dirty && file->fd >= 0 && file->backing_store) { haddr_t size = file->eof; unsigned char *ptr = file->mem; - if (0!=HDlseek(file->fd, (off_t)0, SEEK_SET)) + if(0 != HDlseek(file->fd, (off_t)0, SEEK_SET)) HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "error seeking in backing store") while (size > 0) { - h5_core_io_t bytes_in = 0; /* # of bytes to write */ - h5_core_io_ret_t bytes_wrote = -1; /* # of bytes written */ + h5_posix_io_t bytes_in = 0; /* # of bytes to write */ + h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. */ - if(size > H5_CORE_MAX_IO_BYTES_g) - bytes_in = H5_CORE_MAX_IO_BYTES_g; + if(size > H5_POSIX_MAX_IO_BYTES) + bytes_in = H5_POSIX_MAX_IO_BYTES; else - bytes_in = (h5_core_io_t)size; + bytes_in = (h5_posix_io_t)size; do { bytes_wrote = HDwrite(file->fd, ptr, bytes_in); @@ -1129,7 +1100,7 @@ H5FD_core_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) time_t mytime = HDtime(NULL); HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write to backing store failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', ptr = %p, size = %lu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), ptr, (unsigned long)size, (unsigned long long)myoffset); + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write to backing store failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', ptr = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), ptr, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)myoffset); } /* end if */ HDassert(bytes_wrote > 0); @@ -1149,42 +1120,40 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_core_truncate + * Function: H5FD_core_truncate * - * Purpose: Makes sure that the true file size is the same (or larger) - * than the end-of-address. + * Purpose: Makes sure that the true file size is the same (or larger) + * than the end-of-address. * - * Addendum -- 12/2/11 - * For file images opened with the core file driver, it is - * necessary that we avoid reallocating the core file driver's - * buffer uneccessarily. + * Addendum -- 12/2/11 + * For file images opened with the core file driver, it is + * necessary that we avoid reallocating the core file driver's + * buffer uneccessarily. * - * To this end, I have made the following functional changes - * to this function. + * To this end, I have made the following functional changes + * to this function. * - * If we are closing, and there is no backing store, this - * function becomes a no-op. + * If we are closing, and there is no backing store, this + * function becomes a no-op. * - * If we are closing, and there is backing store, we set the - * eof to equal the eoa, and truncate the backing store to - * the new eof + * If we are closing, and there is backing store, we set the + * eof to equal the eoa, and truncate the backing store to + * the new eof * - * If we are not closing, we realloc the buffer to size equal - * to the smallest multiple of the allocation increment that - * equals or exceeds the eoa and set the eof accordingly. - * Note that we no longer truncate the backing store to the - * new eof if applicable. - * -- JRM + * If we are not closing, we realloc the buffer to size equal + * to the smallest multiple of the allocation increment that + * equals or exceeds the eoa and set the eof accordingly. + * Note that we no longer truncate the backing store to the + * new eof if applicable. + * -- JRM * - * Return: Success: Non-negative - * Failure: Negative + * Return: SUCCEED/FAIL * - * Programmer: Quincey Koziol + * Programmer: Quincey Koziol * Tuesday, October 7, 2008 * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t H5FD_core_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t closing) { @@ -1275,4 +1244,3 @@ H5FD_core_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t closing) done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_core_truncate() */ - |