From 2eac0fccbc0fa1a38364ab5cb818483379a2668b Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 11 Apr 2019 22:22:21 -0500 Subject: Add H5Fget_fileno() API routine. --- src/H5F.c | 35 +++++++++++++++++++++++++++++++++++ src/H5Fpublic.h | 1 + src/H5VLnative_file.c | 13 +++++++++++++ src/H5VLpublic.h | 1 + test/tfile.c | 24 ++++++++++++++++++++++++ 5 files changed, 74 insertions(+) diff --git a/src/H5F.c b/src/H5F.c index 9df8140..e873652 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -921,6 +921,41 @@ done: /*------------------------------------------------------------------------- + * Function: H5Fget_fileno + * + * Purpose: Public API to retrieve the file's 'file number' that uniquely + * identifies each open file. + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +herr_t +H5Fget_fileno(hid_t file_id, unsigned long *fileno) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_API(FAIL) + + /* If no fileno pointer was passed in, exit quietly */ + if(fileno) { + H5VL_object_t *vol_obj; /* File info */ + + /* Get the internal file structure */ + if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(file_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier") + + /* Get the flags */ + if((ret_value = H5VL_file_get(vol_obj, H5VL_FILE_GET_FILENO, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, fileno)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file's 'file number'") + } /* end if */ + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Fget_fileno() */ + + +/*------------------------------------------------------------------------- * Function: H5Fget_freespace * * Purpose: Retrieves the amount of free space in the file. diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h index 8274654..52f1ee2 100644 --- a/src/H5Fpublic.h +++ b/src/H5Fpublic.h @@ -236,6 +236,7 @@ H5_DLL herr_t H5Fclose(hid_t file_id); H5_DLL hid_t H5Fget_create_plist(hid_t file_id); H5_DLL hid_t H5Fget_access_plist(hid_t file_id); H5_DLL herr_t H5Fget_intent(hid_t file_id, unsigned *intent); +H5_DLL herr_t H5Fget_fileno(hid_t file_id, unsigned long *fileno); H5_DLL ssize_t H5Fget_obj_count(hid_t file_id, unsigned types); H5_DLL ssize_t H5Fget_obj_ids(hid_t file_id, unsigned types, size_t max_objs, hid_t *obj_id_list); H5_DLL herr_t H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void **file_handle); diff --git a/src/H5VLnative_file.c b/src/H5VLnative_file.c index 624cd30..8903911 100644 --- a/src/H5VLnative_file.c +++ b/src/H5VLnative_file.c @@ -228,6 +228,19 @@ H5VL__native_file_get(void *obj, H5VL_file_get_t get_type, break; } + /* H5Fget_fileno */ + case H5VL_FILE_GET_FILENO: + { + unsigned long *fileno = HDva_arg(arguments, unsigned long *); + unsigned long my_fileno = 0; + + f = (H5F_t *)obj; + H5F_GET_FILENO(f, my_fileno); + *fileno = my_fileno; /* sigh */ + + break; + } + /* H5Fget_name */ case H5VL_FILE_GET_NAME: { diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index cf6246b..da31a97 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -114,6 +114,7 @@ typedef enum H5VL_file_get_t { H5VL_FILE_GET_FAPL, /* file access property list */ H5VL_FILE_GET_FCPL, /* file creation property list */ H5VL_FILE_GET_INTENT, /* file intent */ + H5VL_FILE_GET_FILENO, /* file number */ H5VL_FILE_GET_NAME, /* file name */ H5VL_FILE_GET_OBJ_COUNT, /* object count in file */ H5VL_FILE_GET_OBJ_IDS /* object ids in file */ diff --git a/test/tfile.c b/test/tfile.c index 430bc85..acf2bd6 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -1921,6 +1921,7 @@ test_file_open_overlap(void) hid_t sid; ssize_t nobjs; /* # of open objects */ unsigned intent; + unsigned long fileno1, fileno2; /* File number */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ @@ -1939,6 +1940,19 @@ test_file_open_overlap(void) CHECK(ret, FAIL, "H5Fget_intent"); VERIFY(intent, H5F_ACC_RDWR, "H5Fget_intent"); + /* Check the file numbers */ + fileno1 = 0; + ret = H5Fget_fileno(fid1, &fileno1); + CHECK(ret, FAIL, "H5Fget_fileno"); + fileno2 = 0; + ret = H5Fget_fileno(fid2, &fileno2); + CHECK(ret, FAIL, "H5Fget_fileno"); + VERIFY(fileno1, fileno2, "H5Fget_fileno"); + + /* Check that a file number pointer of NULL is ignored */ + ret = H5Fget_fileno(fid1, NULL); + CHECK(ret, FAIL, "H5Fget_fileno"); + /* Create a group in file */ gid = H5Gcreate2(fid1, GROUP1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(gid, FAIL, "H5Gcreate2"); @@ -2652,6 +2666,7 @@ test_userblock_file_size(void) hid_t fcpl2_id; hsize_t dims[2] = {3, 4}; hsize_t filesize1, filesize2, filesize; + unsigned long fileno1, fileno2; /* File number */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ @@ -2669,6 +2684,15 @@ test_userblock_file_size(void) file2_id = H5Fcreate(FILE2, H5F_ACC_TRUNC, fcpl2_id, H5P_DEFAULT); CHECK(file2_id, FAIL, "H5Fcreate"); + /* Check the file numbers */ + fileno1 = 0; + ret = H5Fget_fileno(file1_id, &fileno1); + CHECK(ret, FAIL, "H5Fget_fileno"); + fileno2 = 0; + ret = H5Fget_fileno(file2_id, &fileno2); + CHECK(ret, FAIL, "H5Fget_fileno"); + CHECK(fileno1, fileno2, "H5Fget_fileno"); + /* Create groups */ group1_id = H5Gcreate2(file1_id, GROUP1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(group1_id, FAIL, "H5Gcreate2"); -- cgit v0.12 From 4918d443bb2f8406c3be9882a7945853c84760f6 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 12 Apr 2019 18:21:35 -0500 Subject: Add trace macro. --- src/H5F.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/H5F.c b/src/H5F.c index e873652..779c940 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -936,6 +936,7 @@ H5Fget_fileno(hid_t file_id, unsigned long *fileno) herr_t ret_value = SUCCEED; FUNC_ENTER_API(FAIL) + H5TRACE2("e", "i*Ul", file_id, fileno); /* If no fileno pointer was passed in, exit quietly */ if(fileno) { -- cgit v0.12 From d7e1464058515d07b838741f65a77977224814de Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sat, 13 Apr 2019 22:58:16 -0500 Subject: Add C++, Java, and FORTRAN wrappers and tests for H5Fget_fileno --- c++/src/C2Cppfunction_map.htm | 36 ++++++++++ c++/src/H5File.cpp | 21 ++++++ c++/src/H5File.h | 3 + c++/test/tfile.cpp | 59 +++++++++++++++ fortran/src/H5Ff.c | 34 +++++++++ fortran/src/H5Fff.F90 | 38 ++++++++++ fortran/src/H5f90proto.h | 1 + fortran/test/tH5F.F90 | 29 ++++++++ java/src/hdf/hdf5lib/H5.java | 13 ++++ java/src/jni/h5fImp.c | 20 ++++++ java/src/jni/h5fImp.h | 9 +++ java/test/TestH5F.java | 130 ++++++++++++++++++++++++++++++++++ java/test/testfiles/JUnit-TestH5F.txt | 4 +- 13 files changed, 396 insertions(+), 1 deletion(-) diff --git a/c++/src/C2Cppfunction_map.htm b/c++/src/C2Cppfunction_map.htm index b53ea15..2d779a3 100644 --- a/c++/src/C2Cppfunction_map.htm +++ b/c++/src/C2Cppfunction_map.htm @@ -7666,6 +7666,42 @@ normal'> 

+ + +

H5Fget_fileno

+ + +

unsigned long H5File::getFileNum()

+ + +

 

+ + +

 

+ + +

 

+ + 0) { + try {H5.H5Fclose(H5fid2);} catch (Exception ex) {} + H5fid2 = -1; + } _deleteFile(H5_FILE); + _deleteFile(H5_FILE2); System.out.println(); } @@ -223,6 +235,124 @@ public class TestH5F { } @Test + public void testH5Fget_fileno_same() { + long fileno1 = 0; + long fileno2 = 0; + long fid1 = -1; + long fid2 = -1; + + if (H5fid > 0) { + try {H5.H5Fclose(H5fid);} catch (Exception ex) {} + H5fid = -1; + } + + try { + fid1 = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fid2 = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fileno1 = H5.H5Fget_fileno(fid1); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + try { + fileno2 = H5.H5Fget_fileno(fid2); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + assertEquals(fileno1, fileno2); + + try { + H5.H5Fclose(fid1); + } + catch (Exception ex) { + } + + try { + H5.H5Fclose(fid2); + } + catch (Exception ex) { + } + } + + @Test + public void testH5Fget_fileno_diff() { + long fileno1 = 0; + long fileno2 = 0; + long fid1 = -1; + long fid2 = -1; + + if (H5fid > 0) { + try {H5.H5Fclose(H5fid);} catch (Exception ex) {} + H5fid = -1; + } + if (H5fid2 > 0) { + try {H5.H5Fclose(H5fid2);} catch (Exception ex) {} + H5fid2 = -1; + } + + try { + fid1 = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fid2 = H5.H5Fopen(H5_FILE2, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fileno1 = H5.H5Fget_fileno(fid1); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + try { + fileno2 = H5.H5Fget_fileno(fid2); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + assertNotEquals(fileno1, fileno2); + + try { + H5.H5Fclose(fid1); + } + catch (Exception ex) { + } + + try { + H5.H5Fclose(fid2); + } + catch (Exception ex) { + } + } + + @Test public void testH5Fget_obj_count() { long count = -1; diff --git a/java/test/testfiles/JUnit-TestH5F.txt b/java/test/testfiles/JUnit-TestH5F.txt index 16a423e..791e82d 100644 --- a/java/test/testfiles/JUnit-TestH5F.txt +++ b/java/test/testfiles/JUnit-TestH5F.txt @@ -7,8 +7,10 @@ JUnit version 4.11 .testH5Fget_intent_rdonly .testH5Fget_create_plist .testH5Fget_obj_count +.testH5Fget_fileno_same +.testH5Fget_fileno_diff Time: XXXX -OK (8 tests) +OK (10 tests) -- cgit v0.12