summaryrefslogtreecommitdiffstats
path: root/src/H5FDstdio.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2008-10-07 04:17:35 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2008-10-07 04:17:35 (GMT)
commit9f60f016ab71cf8ce39c859fd9eb61c6fca35d63 (patch)
tree0ddbcb2f8707b578af22c62748420b9e3c19177b /src/H5FDstdio.c
parent504c67846e6a4cc5706403bf21a9ae4f07aae7b4 (diff)
downloadhdf5-9f60f016ab71cf8ce39c859fd9eb61c6fca35d63.zip
hdf5-9f60f016ab71cf8ce39c859fd9eb61c6fca35d63.tar.gz
hdf5-9f60f016ab71cf8ce39c859fd9eb61c6fca35d63.tar.bz2
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which includes a fair bit of code cleanup & rearrangement along with a couple of bug fixes also. Tested on: Mac OS X/32 10.5.5 (amazon) in debug mode Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'src/H5FDstdio.c')
-rw-r--r--src/H5FDstdio.c88
1 files changed, 65 insertions, 23 deletions
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index 46c8e81..59056c9 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -166,6 +166,7 @@ static herr_t H5FD_stdio_read(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_
static herr_t H5FD_stdio_write(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr,
size_t size, const void *buf);
static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
+static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
static const H5FD_class_t H5FD_stdio_g = {
"stdio", /*name */
@@ -194,6 +195,7 @@ static const H5FD_class_t H5FD_stdio_g = {
H5FD_stdio_read, /*read */
H5FD_stdio_write, /*write */
H5FD_stdio_flush, /*flush */
+ H5FD_stdio_truncate, /*truncate */
NULL, /*lock */
NULL, /*unlock */
H5FD_FLMAP_SINGLE /*fl_map */
@@ -943,19 +945,63 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
* Programmer: Robb Matzke
* Wednesday, October 22, 1997
*
- * Modifications:
- * Ported to VFL/H5FD layer - QAK, 10/18/99
- *
*-------------------------------------------------------------------------
*/
static herr_t
H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
{
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func="H5FD_stdio_flush"; /* Function Name for error reporting */
+ static const char *func = "H5FD_stdio_flush"; /* Function Name for error reporting */
/* Shut compiler up */
- dxpl_id=dxpl_id;
+ dxpl_id = dxpl_id;
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ /* Only try to flush the file if we have write access */
+ if(file->write_access) {
+ /* Flush */
+ if(!closing) {
+ if(fflush(file->fp) < 0)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
+
+ /* Reset last file I/O information */
+ file->pos = HADDR_UNDEF;
+ file->op = H5FD_STDIO_OP_UNKNOWN;
+ } /* end if */
+ } /* end if */
+
+ return(0);
+} /* end H5FD_stdio_flush() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_stdio_truncate
+ *
+ * Purpose: Makes sure that the true file size is the same (or larger)
+ * than the end-of-address.
+ *
+ * Errors:
+ * IO SEEKERROR fseek failed.
+ * IO WRITEERROR fflush or fwrite failed.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, January 31, 2008
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing)
+{
+ H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
+ static const char *func = "H5FD_stdio_truncate"; /* Function Name for error reporting */
+
+ /* Shut compiler up */
+ dxpl_id = dxpl_id;
+ closing = closing;
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
@@ -963,9 +1009,10 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
/* Only try to flush the file if we have write access */
if(file->write_access) {
/* Makes sure that the true file size is the same as the end-of-address. */
- if (file->eoa!=file->eof) {
+ if(file->eoa != file->eof) {
+ int fd = fileno(file->fp); /* File descriptor for HDF5 file */
+
#ifdef _WIN32
- int fd=_fileno(file->fp); /* File descriptor for HDF5 file */
HFILE filehandle; /* Windows file handle */
LARGE_INTEGER li; /* 64-bit integer for SetFilePointer() call */
@@ -975,14 +1022,16 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
/* Translate 64-bit integers into form Windows wants */
/* [This algorithm is from the Windows documentation for SetFilePointer()] */
li.QuadPart = (LONGLONG)file->eoa;
- (void)SetFilePointer((HANDLE)filehandle,li.LowPart,&li.HighPart,FILE_BEGIN);
- if(SetEndOfFile((HANDLE)filehandle)==0)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to extend file properly", -1)
+ (void)SetFilePointer((HANDLE)filehandle, li.LowPart, &li.HighPart, FILE_BEGIN);
+ if(SetEndOfFile((HANDLE)filehandle) == 0)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1)
#else /* _WIN32 */
- int fd=fileno(file->fp); /* File descriptor for HDF5 file */
+ /* Reset seek offset to beginning of file, so that file isn't re-extended later */
+ rewind(file->fp);
- if (-1==file_truncate(fd, (file_offset_t)file->eoa))
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to extend file properly", -1)
+ /* Truncate file to proper length */
+ if(-1 == file_truncate(fd, (file_offset_t)file->eoa))
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1)
#endif /* _WIN32 */
/* Update the eof value */
@@ -992,23 +1041,15 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
file->pos = HADDR_UNDEF;
file->op = H5FD_STDIO_OP_UNKNOWN;
} /* end if */
-
- /*
- * Flush
- */
- if(!closing) {
- if (fflush(file->fp) < 0)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
- } /* end if */
} /* end if */
else {
/* Double-check for problems */
- if (file->eoa>file->eof)
+ if(file->eoa > file->eof)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_TRUNCATED, "eoa>eof!", -1)
} /* end else */
return(0);
-}
+} /* end H5FD_stdio_truncate() */
#ifdef _H5private_H
@@ -1019,3 +1060,4 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
*/
#error "Do not use HDF5 private definitions"
#endif
+