diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2003-10-29 17:04:58 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2003-10-29 17:04:58 (GMT) |
commit | d1f7c81a466c0bf041c380abee0f0c21ca30c86f (patch) | |
tree | 960def503380ca7737e93ae841bc2d4148b9d271 | |
parent | 219f713c6fdea98da7c1fdbb0eafa60a5f0bbe99 (diff) | |
download | hdf5-d1f7c81a466c0bf041c380abee0f0c21ca30c86f.zip hdf5-d1f7c81a466c0bf041c380abee0f0c21ca30c86f.tar.gz hdf5-d1f7c81a466c0bf041c380abee0f0c21ca30c86f.tar.bz2 |
[svn-r7784] *** empty log message ***
-rw-r--r-- | src/H5F.c | 33 | ||||
-rw-r--r-- | src/H5Fpkg.h | 1 | ||||
-rw-r--r-- | src/H5Fprivate.h | 1 | ||||
-rw-r--r-- | src/H5Gprivate.h | 1 | ||||
-rw-r--r-- | src/H5I.c | 88 | ||||
-rw-r--r-- | src/H5Iprivate.h | 1 | ||||
-rw-r--r-- | src/H5Ipublic.h | 1 | ||||
-rw-r--r-- | test/tfile.c | 105 |
8 files changed, 231 insertions, 0 deletions
@@ -2137,6 +2137,9 @@ H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id) if ((ret_value = H5I_register(H5I_FILE, new_file))<0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file") + /* Keep this ID in file object structure */ + new_file->file_id = ret_value; + done: if (ret_value<0 && new_file) if(H5F_close(new_file)<0) @@ -4164,6 +4167,36 @@ done: /*------------------------------------------------------------------------- + * Function: H5F_get_id + * + * Purpose: Quick and dirty routine to retrieve the file's 'file id' + * (Mainly added to stop non-file routines from poking about + * in the H5F_t data structure) + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Raymond Lu + * Oct 29, 2003 + * + * Modifications: + *------------------------------------------------------------------------- + */ +hid_t +H5F_get_id(H5F_t *file) +{ + hid_t ret_value; + + FUNC_ENTER_NOINIT(H5F_get_id) + + assert(file); + ret_value = file->file_id; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5F_get_id() */ + + +/*------------------------------------------------------------------------- * Function: H5F_get_base_addr * * Purpose: Quick and dirty routine to retrieve the file's 'base_addr' value diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h index 8ba9806..ea11040 100644 --- a/src/H5Fpkg.h +++ b/src/H5Fpkg.h @@ -181,6 +181,7 @@ struct H5F_t { char *name; /* Name used to open file */ H5F_file_t *shared; /* The shared file info */ unsigned nopen_objs; /* Number of open object headers*/ + hid_t file_id; /* ID of this file */ hid_t closing; /* H5I_FILE_CLOSING ID or zero */ H5F_mtab_t mtab; /* File mount table */ }; diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 4f97e9a..800d14e 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -385,6 +385,7 @@ H5_DLL herr_t H5F_init(void); H5_DLL hid_t H5F_get_driver_id(const H5F_t *f); H5_DLL unsigned H5F_get_intent(const H5F_t *f); H5_DLL herr_t H5F_get_fileno(const H5F_t *f, unsigned long *filenum); +H5_DLL hid_t H5F_get_id(H5F_t *file); H5_DLL int H5F_get_obj_count(const H5F_t *f, unsigned types); H5_DLL int H5F_get_obj_ids(const H5F_t *f, unsigned types, int max_objs, hid_t *obj_id_list); H5_DLL haddr_t H5F_get_base_addr(const H5F_t *f); diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h index 2bf2c3f..b2bff6c 100644 --- a/src/H5Gprivate.h +++ b/src/H5Gprivate.h @@ -38,6 +38,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Bprivate.h" /* B-trees */ #include "H5Fprivate.h" /* File access */ +#include "H5Gprivate.h" /* Group */ #include "H5RSprivate.h" /* Reference-counted strings */ /* @@ -793,6 +793,94 @@ done: /*------------------------------------------------------------------------- + * Function: H5Iget_file_id + * + * Purpose: The public version of H5I_get_file_id(), obtains the file + * ID given an object ID. User has to close this ID. + * + * Return: Success: file ID + * + * Failure: a negative value + * + * Programmer: Raymond Lu + * Oct 27, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Iget_file_id(hid_t obj_id) +{ + hid_t ret_value = FAIL; + + FUNC_ENTER_API(H5Iget_file_id, FAIL); + H5TRACE1("i","i",obj_id); + + ret_value = H5I_get_file_id(obj_id); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5I_get_file_id + * + * Purpose: The private version of H5Iget_file_id(), obtains the file + * ID given an object ID. + * + * Return: Success: file ID + * + * Failure: a negative value + * + * Programmer: Raymond Lu + * Oct 27, 2003 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5I_get_file_id(hid_t obj_id) +{ + hid_t ret_value = FAIL; + H5I_type_t obj_type = H5I_BADID; + H5G_entry_t *ent; + + FUNC_ENTER_NOAPI(H5I_get_file_id, FAIL); + + /* Get object type */ + obj_type = H5I_GRP(obj_id); + + switch(obj_type) { + case H5I_FILE: + ret_value = obj_id; + /* Increment reference count on atom. */ + if (H5I_inc_ref(ret_value)<0) + HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "incrementing file ID failed"); + + break; + case H5I_GROUP: + case H5I_DATASET: + case H5I_ATTR: + ent = H5G_loc(obj_id); + ret_value = H5F_get_id(ent->file); + /* Increment reference count on atom. */ + if (H5I_inc_ref(ret_value)<0) + HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "incrementing file ID failed"); + + break; + default: + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object ID"); + } + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- * Function: H5I_remove * * Purpose: Removes the specified ID from its group. diff --git a/src/H5Iprivate.h b/src/H5Iprivate.h index 79819a5..42369e3 100644 --- a/src/H5Iprivate.h +++ b/src/H5Iprivate.h @@ -67,6 +67,7 @@ H5_DLL hid_t H5I_register(H5I_type_t grp, void *object); H5_DLL void *H5I_object(hid_t id); H5_DLL void *H5I_object_verify(hid_t id, H5I_type_t id_type); H5_DLL H5I_type_t H5I_get_type(hid_t id); +H5_DLL hid_t H5I_get_file_id(hid_t obj_id); H5_DLL void *H5I_remove(hid_t id); H5_DLL void *H5I_search(H5I_type_t grp, H5I_search_func_t func, void *key); H5_DLL int H5I_inc_ref(hid_t id); diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h index 1f4b845..eb97994 100644 --- a/src/H5Ipublic.h +++ b/src/H5Ipublic.h @@ -59,6 +59,7 @@ extern "C" { /* Public API functions */ H5_DLL H5I_type_t H5Iget_type(hid_t id); +H5_DLL hid_t H5Iget_file_id(hid_t obj_id); H5_DLL ssize_t H5Iget_name(hid_t object_id, char *name/*out*/, size_t size); #ifdef __cplusplus diff --git a/test/tfile.c b/test/tfile.c index b829133..91ecf18 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -53,6 +53,9 @@ #define F3_SYM_INTERN_K F2_SYM_INTERN_K #define FILE3 "tfile3.h5" +#define ATTR_NAME "attr" +#define FILE4 "tfile4.h5" + #define OBJ_ID_COUNT_0 0 #define OBJ_ID_COUNT_1 1 #define OBJ_ID_COUNT_2 2 @@ -817,6 +820,107 @@ create_objects(hid_t fid1, hid_t fid2, hid_t *ret_did, hid_t *ret_gid1, /**************************************************************** ** +** test_get_file_id(): Test H5Iget_file_id() +** +*****************************************************************/ +static void +test_get_file_id(void) +{ + hid_t fid1, fid2; + hid_t dataset_id, dataspace_id, group_id, attr_id; + hid_t plist; + hsize_t dims[F2_RANK]; + herr_t ret; + + /* Create a file */ + fid1 = H5Fcreate(FILE4, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Return a duplicated file ID even not expecting user to do it. + * And close this duplicated ID + */ + fid2 = H5Iget_file_id(fid1); + CHECK(fid2, FAIL, "H5Iget_file_id"); + VERIFY(fid2, fid1, "H5Iget_file_id"); + + ret = H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + /* Create a group in the file. Make a duplicated file ID from the group. + * And close this duplicated ID + */ + group_id = H5Gcreate(fid1, "/group", 0); + CHECK(group_id, FAIL, "H5Gcreate"); + + fid2 = H5Iget_file_id(group_id); + CHECK(fid2, FAIL, "H5Iget_file_id"); + VERIFY(fid2, fid1, "H5Iget_file_id"); + + ret = H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + /* Create a dataset in the group. Make a duplicated file ID from the + * dataset. And close this duplicated ID. + */ + dims[0] = F2_DIM0; + dims[1] = F2_DIM1; + dataspace_id = H5Screate_simple(F2_RANK, dims, NULL); + CHECK(dataspace_id, FAIL, "H5Screate_simple"); + + dataset_id = H5Dcreate(group_id, "/dset", H5T_NATIVE_INT, dataspace_id, + H5P_DEFAULT); + CHECK(dataset_id, FAIL, "H5Dcreate"); + + fid2 = H5Iget_file_id(dataset_id); + CHECK(fid2, FAIL, "H5Iget_file_id"); + VERIFY(fid2, fid1, "H5Iget_file_id"); + + ret = H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + /* Create an attribute for the dataset. Make a duplicated file ID from + * this attribute. And close it. + */ + attr_id=H5Acreate(dataset_id,ATTR_NAME,H5T_NATIVE_INT,dataspace_id,H5P_DEFAULT); + CHECK(ret, FAIL, "H5Acreate"); + + fid2 = H5Iget_file_id(attr_id); + CHECK(fid2, FAIL, "H5Iget_file_id"); + VERIFY(fid2, fid1, "H5Iget_file_id"); + + ret = H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + /* Create a property list and try to get file ID from it. + * Supposed to fail. + */ + plist = H5Pcreate(H5P_FILE_ACCESS); + CHECK(plist, FAIL, "H5Pcreate"); + + H5E_BEGIN_TRY { + fid2 = H5Iget_file_id(plist); + } H5E_END_TRY; + VERIFY(fid2, FAIL, "H5Iget_file_id"); + + /* Close objects */ + ret = H5Aclose(attr_id); + CHECK(ret, FAIL, "H5Aclose"); + + ret = H5Sclose(dataspace_id); + CHECK(ret, FAIL, "H5Sclose"); + + ret = H5Dclose(dataset_id); + CHECK(ret, FAIL, "H5Dclose"); + + ret = H5Gclose(group_id); + CHECK(ret, FAIL, "H5Gclose"); + + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); +} + +/**************************************************************** +** ** test_obj_count_and_id(): test object count and ID list functions. ** ****************************************************************/ @@ -1070,6 +1174,7 @@ test_file(void) #ifndef H5_NO_SHARED_WRITING test_file_close(); /* Test file close behavior */ #endif /* H5_NO_SHARED_WRITING */ + test_get_file_id(); /* Test H5Iget_file_id */ test_file_perm(); /* Test file access permissions */ test_file_freespace(); /* Test file free space information */ } /* test_file() */ |