summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c++/test/tfile.cpp59
-rw-r--r--release_docs/RELEASE.txt2
-rw-r--r--src/H5F.c39
-rw-r--r--src/H5Fpublic.h1
-rw-r--r--test/file_handle.c84
-rw-r--r--test/titerate.c4
6 files changed, 187 insertions, 2 deletions
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index 82d7338..47d06f7 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -59,6 +59,9 @@ using namespace H5;
#define F3_SYM_INTERN_K F2_SYM_INTERN_K
#define FILE3 "tfile3.h5"
+#define KB 1024
+#define FILE4 "tfile4.h5"
+
/*-------------------------------------------------------------------------
* Function: test_file_create
@@ -311,6 +314,61 @@ test_file_open(void)
/*-------------------------------------------------------------------------
+ * Function: test_file_size
+ *
+ * Purpose: Test file size.
+ *
+ * Return: None
+ *
+ * Programmer: Raymond Lu
+ * June, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+test_file_size(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing File Size\n"));
+
+ hid_t fapl_id;
+ fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template
+
+ try {
+ // Use the file access template id to create a file access prop.
+ // list object to pass in H5File::H5File
+ FileAccPropList fapl(fapl_id);
+
+ // Set to sec2 driver. Do we want to test other file drivers?
+ // They're not tested in C++.
+ // File drivers seem not implemented.
+ //fapl.setSec2();
+
+ // Create a file
+ H5File fid( FILE4, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl);
+
+ // Get file size
+ haddr_t file_size = fid.getFileSize();
+ CHECK(file_size, FAIL, "H5File::getFileSize");
+
+ // Check if file size is reasonable. It's supposed to be 2KB now.
+ if(file_size<1*KB || file_size>4*KB)
+ CHECK(FAIL, FAIL, "H5File::getFileSize");
+ } // end of try block
+
+ catch( Exception E ) {
+ CHECK(FAIL, FAIL, E.getCFuncName());
+ }
+
+ // use C test utility routine to close property list.
+ H5Pclose(fapl_id);
+
+} /* test_file_size() */
+
+
+/*-------------------------------------------------------------------------
* Function: test_file
*
* Purpose: Main program
@@ -332,6 +390,7 @@ test_file(void)
test_file_create(); /* Test file creation (also creation templates) */
test_file_open(); /* Test file opening */
+ test_file_size(); /* Test file size */
} /* test_file() */
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index 13a4dfc..7f1afcc 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -41,6 +41,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
- Added option that if $HDF5_DISABLE_VERSION_CHECK is set to 2,
will suppress all library version mismatch warning messages.
AKC - 2004/4/14
diff --git a/src/H5F.c b/src/H5F.c
index 6b46ddf..478aa6d 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -4667,3 +4667,42 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_mpi_get_comm() */
#endif /* H5_HAVE_PARALLEL */
+
+/*-------------------------------------------------------------------------
+ * 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/file_handle.c b/test/file_handle.c
index cf255e8..1616bb0 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,17 @@ 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. Currently, this file size
+ * is 976.
+ */
+ if(file_size<KB/2 || file_size>1*KB)
+ goto error;
+
if(H5Fclose(file)<0)
goto error;
h5_cleanup(FILENAME, fapl);
@@ -177,6 +209,10 @@ error:
*
* Modifications:
*
+ * Raymond Lu
+ * Wednesday, June 23, 2004
+ * Added test for H5Fget_filesize.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -190,6 +226,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 +239,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 +286,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 +332,10 @@ error:
*
* Modifications:
*
+ * Raymond Lu
+ * Wednesday, June 23, 2004
+ * Added test for H5Fget_filesize.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -288,6 +345,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 +399,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 +435,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)
diff --git a/test/titerate.c b/test/titerate.c
index 4cb3f0c..aea951e 100644
--- a/test/titerate.c
+++ b/test/titerate.c
@@ -859,7 +859,11 @@ static void test_links(void)
herr_t ret; /* Generic return value */
hid_t gid, gid1;
int i;
+#ifdef H5_WANT_H5_V1_4_COMPAT
+ int obj_type; /* Type of object */
+#else /*H5_WANT_H5_V1_4_COMPAT*/
H5G_obj_t obj_type; /* Type of object */
+#endif /*H5_WANT_H5_V1_4_COMPAT*/
hsize_t nobjs; /* Number of objects */
/* Output message about test being performed */