summaryrefslogtreecommitdiffstats
path: root/perform/pio_engine.c
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2002-05-13 19:55:33 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2002-05-13 19:55:33 (GMT)
commitd07e0dd9a3d98981ba49c1a39998faf7cb522075 (patch)
treef9d03b17c9c1b722c8145cd3b7cdbc8f2cb4386b /perform/pio_engine.c
parent4793f81ae10d65a681ce440ce072b510b1ec8d92 (diff)
downloadhdf5-d07e0dd9a3d98981ba49c1a39998faf7cb522075.zip
hdf5-d07e0dd9a3d98981ba49c1a39998faf7cb522075.tar.gz
hdf5-d07e0dd9a3d98981ba49c1a39998faf7cb522075.tar.bz2
[svn-r5407] Purpose:
Bug fix Description: Was not able to handle data size (file size) larger than 32bits. Was using long, which is only 4 bytes big in SP, thus overflowing into negative when trying to address 2GB or larger. Solution: Changed those variables involved in file size/offset calculation to type off_t. (If a certain system/compiler has off_t defined as 4 bytes, it can't write to file size larger than 2GB anyway.) Note that the lseek of SP with -D_LARGE_FILE still fails for offset larger than 2GB (works for 2GB). That has to be fixed soon. Platforms tested: burrwhite (linux 2.4) and modi4 parallel.
Diffstat (limited to 'perform/pio_engine.c')
-rw-r--r--perform/pio_engine.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/perform/pio_engine.c b/perform/pio_engine.c
index e48129a..abc0668 100644
--- a/perform/pio_engine.c
+++ b/perform/pio_engine.c
@@ -129,9 +129,9 @@ typedef union _file_descr {
static char *pio_create_filename(iotype iot, const char *base_name,
char *fullname, size_t size);
static herr_t do_write(file_descr *fd, iotype iot, long ndsets,
- long nelmts, long buf_size, void *buffer);
+ long nelmts, size_t buf_size, void *buffer);
static herr_t do_read(file_descr *fd, iotype iot, long ndsets,
- long nelmts, long buf_size, void *buffer /*out*/);
+ long nelmts, size_t buf_size, void *buffer /*out*/);
static herr_t do_fopen(iotype iot, char *fname, file_descr *fd /*out*/,
int flags);
static herr_t do_fclose(iotype iot, file_descr *fd);
@@ -157,9 +157,10 @@ do_pio(parameters param)
char fname[FILENAME_MAX];
int maxprocs;
int nfiles, nf;
- long ndsets, nelmts;
+ long ndsets;
+ long nelmts;
char *buffer = NULL; /*data buffer pointer */
- long buf_size; /*data buffer size in bytes */
+ size_t buf_size; /*data buffer size in bytes */
/* HDF5 variables */
herr_t hrc; /*HDF5 return code */
@@ -244,7 +245,7 @@ buf_size=MIN(1024*1024, buf_size);
#endif
/* allocate data buffer */
- buffer = malloc((size_t)buf_size);
+ buffer = malloc(buf_size);
if (buffer == NULL){
fprintf(stderr, "malloc for data buffer size (%ld) failed\n",
@@ -468,7 +469,7 @@ pio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
*/
static herr_t
do_write(file_descr *fd, iotype iot, long ndsets,
- long nelmts, long buf_size, void *buffer)
+ long nelmts, size_t buf_size, void *buffer)
{
int ret_code = SUCCESS;
int rc; /*routine return code */
@@ -480,7 +481,7 @@ do_write(file_descr *fd, iotype iot, long ndsets,
char dname[64];
off_t dset_offset; /*dataset offset in a file */
off_t file_offset; /*file offset of the next transfer */
- long dset_size; /*one dataset size in bytes */
+ off_t dset_size; /*one dataset size in bytes */
long nelmts_in_buf;
long elmts_begin; /*first elmt this process transfer */
long elmts_count; /*number of elmts this process transfer */
@@ -587,7 +588,9 @@ fprintf(stderr, "proc %d: elmts_begin=%ld, elmts_count=%ld\n",
/* Calculate offset of write within a dataset/file */
switch (iot) {
case RAWIO:
- file_offset = dset_offset + (elmts_begin + nelmts_written)*ELMT_SIZE;
+ /* need to (off_t) the elmnts_begin expression because they */
+ /* may be of smaller sized integer types */
+ file_offset = dset_offset + (off_t)(elmts_begin + nelmts_written)*ELMT_SIZE;
#if AKCDEBUG
fprintf(stderr, "proc %d: writes %ld bytes at file-offset %ld\n",
@@ -692,7 +695,7 @@ done:
*/
static herr_t
do_read(file_descr *fd, iotype iot, long ndsets,
- long nelmts, long buf_size, void *buffer /*out*/)
+ long nelmts, size_t buf_size, void *buffer /*out*/)
{
int ret_code = SUCCESS;
int rc; /*routine return code */
@@ -704,7 +707,7 @@ do_read(file_descr *fd, iotype iot, long ndsets,
char dname[64];
off_t dset_offset; /*dataset offset in a file */
off_t file_offset; /*file offset of the next transfer */
- long dset_size; /*one dataset size in bytes */
+ off_t dset_size; /*one dataset size in bytes */
long nelmts_in_buf;
long elmts_begin; /*first elmt this process transfer */
long elmts_count; /*number of elmts this process transfer */
@@ -797,7 +800,9 @@ fprintf(stderr, "proc %d: elmts_begin=%ld, elmts_count=%ld\n",
/* Calculate offset of read within a dataset/file */
switch (iot){
case RAWIO:
- file_offset = dset_offset + (elmts_begin + nelmts_read)*ELMT_SIZE;
+ /* need to (off_t) the elmnts_begin expression because they */
+ /* may be of smaller sized integer types */
+ file_offset = dset_offset + (off_t)(elmts_begin + nelmts_read)*ELMT_SIZE;
#if AKCDEBUG
fprintf(stderr, "proc %d: read %ld bytes at file-offset %ld\n",