summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--release_docs/RELEASE.txt2
-rw-r--r--src/H5F.c39
-rw-r--r--src/H5Fpublic.h1
-rw-r--r--test/Makefile.in13
-rw-r--r--test/file_handle.c83
5 files changed, 133 insertions, 5 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index a7f5362..3be733e 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -44,6 +44,8 @@ New Features
Library:
--------
+ - A new API function H5Fget_filesize was added. It returns the
+ actual file size of the opened file. SLU - 2004/06/24
- New Feature of Data transformation is added. AKC - 2004/05/03.
- New exception handler for datatype conversion is put in to
replace the old overflow callback function. This exception
diff --git a/src/H5F.c b/src/H5F.c
index fca616d..a8f3f43 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -4704,3 +4704,42 @@ done:
FUNC_LEAVE_API(ret_value)
} /* end H5Fget_freespace() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5Fget_filesize
+ *
+ * Purpose: Retrieves the file size of the HDF5 file. This function
+ * is called after an existing file is opened in order
+ * to learn the true size of the underlying file.
+ *
+ * Return: Success: File size
+ * Failure: Negative
+ *
+ * Programmer: David Pitt
+ * david.pitt@bigpond.com
+ * Apr 27, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+haddr_t
+H5Fget_filesize(hid_t file_id)
+{
+ H5F_t *file=NULL; /* File object for file ID */
+ haddr_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(H5Fget_filesize, FAIL)
+ H5TRACE1("a","i",file_id);
+
+ /* Check args */
+ if(NULL==(file=H5I_object_verify(file_id, H5I_FILE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file ID")
+
+ /* Go get the actual file size */
+ if((ret_value = H5FDget_eof(file->shared->lf))<0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file size")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Fget_filesize() */
diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h
index 431f9bc..911bdff 100644
--- a/src/H5Fpublic.h
+++ b/src/H5Fpublic.h
@@ -113,6 +113,7 @@ H5_DLL herr_t H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void** file_handle);
H5_DLL herr_t H5Fmount(hid_t loc, const char *name, hid_t child, hid_t plist);
H5_DLL herr_t H5Funmount(hid_t loc, const char *name);
H5_DLL hssize_t H5Fget_freespace(hid_t file_id);
+H5_DLL haddr_t H5Fget_filesize(hid_t file_id);
#ifdef __cplusplus
}
diff --git a/test/Makefile.in b/test/Makefile.in
index bdc5446..78e25d1 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -31,7 +31,14 @@ TEST_PROGS=testhdf5 lheap ohdr stab gheap hyperslab istore bittests dtypes
dsets cmpd_dset extend external links unlink big mtime fillval mount \
flush1 flush2 enum gass_write gass_read gass_append set_extent \
srb_write srb_append srb_read ttsafe stream_test getname file_handle \
- ntypes dangle error_test err_compat dtransform
+ ntypes dangle dtransform
+
+## Test programs for Error API. Only compile them but let testerror.sh run
+## them to compare the output error messages with standard ones. 'make check'
+## doesn't run them directly.
+ERR_PROGS=error_test err_compat
+
+PROGS=$(ERR_PROGS) $(TEST_PROGS)
TIMINGS=testmeta
@@ -101,10 +108,10 @@ timings _timings: $(TIMINGS)
## Programs have to be built before they can be tested!
##
-check test _test: $(TEST_PROGS)
+check test _test: $(PROGS)
## How to build the tests... They all depend on the test and hdf5 libraries.
-$(TEST_PROGS): $(LIB) $(LIBHDF5)
+$(PROGS): $(LIB) $(LIBHDF5)
TESTHDF5_OBJ=testhdf5.lo tarray.lo tattr.lo tconfig.lo tfile.lo \
tgenprop.lo th5s.lo theap.lo titerate.lo tmeta.lo ttime.lo trefer.lo \
diff --git a/test/file_handle.c b/test/file_handle.c
index cf255e8..8df8409 100644
--- a/test/file_handle.c
+++ b/test/file_handle.c
@@ -21,6 +21,7 @@
#include "h5test.h"
+#define KB 1024
#define FAMILY_NUMBER 4
#define FAMILY_SIZE 128
#define MULTI_SIZE 128
@@ -49,6 +50,10 @@ const char *FILENAME[] = {
*
* Modifications:
*
+ * Raymond Lu
+ * Wednesday, June 23, 2004
+ * Added test for H5Fget_filesize.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -57,7 +62,8 @@ test_sec2(void)
hid_t file=(-1), fapl, access_fapl = -1;
char filename[1024];
int *fhandle=NULL;
-
+ haddr_t file_size;
+
TESTING("SEC2 file driver");
/* Set property list and file name for SEC2 driver. */
@@ -83,6 +89,16 @@ test_sec2(void)
if(*fhandle<0)
goto error;
+ /* Check file size API */
+ if((file_size = H5Fget_filesize(file)) <= 0)
+ goto error;
+
+ /* There is no garantee the size of metadata in file is constant.
+ * Just try to check if it's reasonable. It's 2KB right now.
+ */
+ if(file_size<1*KB || file_size>4*KB)
+ goto error;
+
if(H5Fclose(file)<0)
goto error;
h5_cleanup(FILENAME, fapl);
@@ -111,6 +127,10 @@ error:
* Tuesday, Sept 24, 2002
*
* Modifications:
+ *
+ * Raymond Lu
+ * Wednesday, June 23, 2004
+ * Added test for H5Fget_filesize.
*
*-------------------------------------------------------------------------
*/
@@ -120,6 +140,7 @@ test_core(void)
hid_t file=(-1), fapl, access_fapl = -1;
char filename[1024];
void *fhandle=NULL;
+ haddr_t file_size;
TESTING("CORE file driver");
@@ -148,6 +169,16 @@ test_core(void)
goto error;
}
+ /* Check file size API */
+ if((file_size = H5Fget_filesize(file)) <= 0)
+ goto error;
+
+ /* There is no garantee the size of metadata in file is constant.
+ * Just try to check if it's reasonable. Why is this 4KB?
+ */
+ if(file_size<2*KB || file_size>6*KB)
+ goto error;
+
if(H5Fclose(file)<0)
goto error;
h5_cleanup(FILENAME, fapl);
@@ -177,6 +208,10 @@ error:
*
* Modifications:
*
+ * Raymond Lu
+ * Wednesday, June 23, 2004
+ * Added test for H5Fget_filesize.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -190,6 +225,7 @@ test_family(void)
int *fhandle=NULL, *fhandle2=NULL;
int buf[FAMILY_NUMBER][FAMILY_SIZE];
hsize_t dims[2]={FAMILY_NUMBER, FAMILY_SIZE};
+ haddr_t file_size;
TESTING("FAMILY file driver");
@@ -202,6 +238,14 @@ test_family(void)
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
goto error;
+ /* Check file size API */
+ if((file_size = H5Fget_filesize(file)) <= 0)
+ goto error;
+
+ /* The file size is supposed to be 2KB right now. */
+ if(file_size<1*KB || file_size>4*KB)
+ goto error;
+
/* Create and write dataset */
if((space=H5Screate_simple(2, dims, NULL))<0)
goto error;
@@ -241,6 +285,14 @@ test_family(void)
if(*fhandle2<0)
goto error;
+ /* Check file size API */
+ if((file_size = H5Fget_filesize(file)) <= 0)
+ goto error;
+
+ /* Some data has been written. The file size should be bigger(4KB) now. */
+ if(file_size<2*KB || file_size>6*KB)
+ goto error;
+
if(H5Sclose(space)<0)
goto error;
if(H5Dclose(dset)<0)
@@ -279,6 +331,10 @@ error:
*
* Modifications:
*
+ * Raymond Lu
+ * Wednesday, June 23, 2004
+ * Added test for H5Fget_filesize.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -288,6 +344,7 @@ test_multi(void)
hid_t access_fapl = -1;
char filename[1024];
int *fhandle2=NULL, *fhandle=NULL;
+ haddr_t file_size;
H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES];
hid_t memb_fapl[H5FD_MEM_NTYPES];
haddr_t memb_addr[H5FD_MEM_NTYPES];
@@ -341,9 +398,20 @@ test_multi(void)
if (H5Pclose(access_fapl) < 0)
goto error;
+ /* Check file size API */
+ if((file_size = H5Fget_filesize(file)) <= 0)
+ goto error;
+
+ /* Before any data is written, the raw data file is empty. So
+ * the file size is only the size of metadata file. It's supposed
+ * to be 2KB.
+ */
+ if(file_size<1*KB || file_size>4*KB)
+ goto error;
+
if((dset=H5Dcreate(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT))<0)
goto error;
-
+
for(i=0; i<MULTI_SIZE; i++)
for(j=0; j<MULTI_SIZE; j++)
buf[i][j] = i*10000+j;
@@ -366,6 +434,17 @@ test_multi(void)
if(*fhandle2<0)
goto error;
+ /* Check file size API */
+ if((file_size = H5Fget_filesize(file)) <= 0)
+ goto error;
+
+ /* After the data is written, the file size is huge because the
+ * beginning of raw data file is set at HADDR_MAX/2. It's supposed
+ * to be (HADDR_MAX/2 + 128*128*4)
+ */
+ if(file_size < HADDR_MAX/2 || file_size > HADDR_MAX)
+ goto error;
+
if(H5Sclose(space)<0)
goto error;
if(H5Dclose(dset)<0)