summaryrefslogtreecommitdiffstats
path: root/src/H5R.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-11-11 05:23:53 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-11-11 05:23:53 (GMT)
commite53f3daf610359bc61b8da499c66495b0476b68d (patch)
tree975e4e306b34e4d4a707947068bac14b612f28c3 /src/H5R.c
parentf5eebb7d17a356fb0eaca4fce91f710155f89f8c (diff)
downloadhdf5-e53f3daf610359bc61b8da499c66495b0476b68d.zip
hdf5-e53f3daf610359bc61b8da499c66495b0476b68d.tar.gz
hdf5-e53f3daf610359bc61b8da499c66495b0476b68d.tar.bz2
[svn-r12892] Description:
Add H5Rget_name routine and tests... Tested on: FreeBSD/32 4.11 (sleipnir) Linux/32 2.4 (heping) Linux/64 2.4 (mir)
Diffstat (limited to 'src/H5R.c')
-rw-r--r--src/H5R.c152
1 files changed, 151 insertions, 1 deletions
diff --git a/src/H5R.c b/src/H5R.c
index 7068cbd..a8e2d32 100644
--- a/src/H5R.c
+++ b/src/H5R.c
@@ -38,6 +38,8 @@ static herr_t H5R_create(void *ref, H5G_loc_t *loc, const char *name,
static hid_t H5R_dereference(H5F_t *file, hid_t dxpl_id, H5R_type_t ref_type, const void *_ref);
static H5S_t * H5R_get_region(H5F_t *file, hid_t dxpl_id, const void *_ref);
static H5G_obj_t H5R_get_obj_type(H5F_t *file, hid_t dxpl_id, H5R_type_t ref_type, const void *_ref);
+static ssize_t H5R_get_name(H5F_t *file, hid_t dxpl_id, hid_t id,
+ H5R_type_t ref_type, const void *_ref, char *name, size_t size);
/*--------------------------------------------------------------------------
@@ -338,7 +340,6 @@ H5R_dereference(H5F_t *file, hid_t dxpl_id, H5R_type_t ref_type, const void *_re
H5O_loc_t oloc; /* Object location */
H5G_name_t path; /* Path of object */
H5G_loc_t loc; /* Group location */
- const uint8_t *p; /* Pointer to OID to store */
int oid_type; /* type of object being dereferenced */
hid_t ret_value;
@@ -362,6 +363,7 @@ H5R_dereference(H5F_t *file, hid_t dxpl_id, H5R_type_t ref_type, const void *_re
const hdset_reg_ref_t *ref = (const hdset_reg_ref_t *)_ref; /* Get pointer to correct type of reference struct */
H5HG_t hobjid; /* Heap object ID */
uint8_t *buf; /* Buffer to store serialized selection in */
+ const uint8_t *p; /* Pointer to OID to store */
/* Get the heap ID for the dataset region */
p = (const uint8_t *)ref;
@@ -772,3 +774,151 @@ done:
FUNC_LEAVE_API(ret_value)
} /* end H5Rget_obj_type() */
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5R_get_name
+ PURPOSE
+ Internal routine to determine a name for the object referenced
+ USAGE
+ ssize_t H5R_get_name(f, dxpl_id, ref_type, ref, name, size)
+ H5F_t *f; IN: Pointer to the file that the reference is pointing
+ into
+ hid_t dxpl_id; IN: DXPL to use for operation
+ hid_t id; IN: Location ID given for reference
+ H5R_type_t ref_type; IN: Type of reference
+ void *ref; IN: Reference to query.
+ char *name; OUT: Buffer to place name of object referenced
+ size_t size; IN: Size of name buffer
+
+ RETURNS
+ Non-negative length of the path on success, Negative on failure
+ DESCRIPTION
+ Given a reference to some object, determine a path to the object
+ referenced in the file.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ This may not be the only path to that object.
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+ssize_t
+H5R_get_name(H5F_t *f, hid_t dxpl_id, hid_t id, H5R_type_t ref_type,
+ const void *_ref, char *name, size_t size)
+{
+ hid_t file_id = (-1); /* ID for file that the reference is in */
+ H5O_loc_t oloc; /* Object location describing object for reference */
+ const uint8_t *p; /* Pointer to reference to decode */
+ ssize_t ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5R_get_name)
+
+ /* Check args */
+ HDassert(f);
+ HDassert(_ref);
+ HDassert(name);
+
+ /* Initialize the object location */
+ H5O_loc_reset(&oloc);
+ oloc.file = f;
+
+ /* Get address for reference */
+ p = (const uint8_t *)_ref;
+ switch(ref_type) {
+ case H5R_OBJECT:
+ H5F_addr_decode(oloc.file, &p, &oloc.addr);
+ break;
+
+ case H5R_DATASET_REGION:
+ {
+ /* Skip over the heap ID for the dataset region */
+ p += H5F_SIZEOF_ADDR(f);
+ p += 4;
+
+ /* Get the object oid for the dataset */
+ H5F_addr_decode(oloc.file, &p, &oloc.addr);
+ } /* end case */
+ break;
+
+ case H5R_INTERNAL:
+ HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "Internal references are not yet supported")
+
+ case H5R_BADTYPE:
+ case H5R_MAXTYPE:
+ default:
+ HDassert("unknown reference type" && 0);
+ HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL, "internal error (unknown reference type)")
+ } /* end switch */
+
+ /* Retrieve file ID for name search */
+ if((file_id = H5I_get_file_id(id)) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "can't retrieve file ID")
+
+ /* Get name, length, etc. */
+ if((ret_value = H5G_get_refobj_name(file_id, dxpl_id, &oloc, name, size)) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, FAIL, "can't determine name")
+
+done:
+ /* Close file ID used for search */
+ if(file_id > 0)
+ if(H5I_dec_ref(file_id) < 0)
+ HDONE_ERROR(H5E_REFERENCE, H5E_CANTCLOSEFILE, FAIL, "can't determine name")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5R_get_name() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5Rget_name
+ PURPOSE
+ Determines a name for the object referenced
+ USAGE
+ ssize_t H5Rget_name(loc_id, ref_type, ref, name, size)
+ hid_t loc_id; IN: Dataset reference object is in or location ID of
+ object that the dataset is located within.
+ H5R_type_t ref_type; IN: Type of reference
+ void *ref; IN: Reference to query.
+ char *name; OUT: Buffer to place name of object referenced
+ size_t size; IN: Size of name buffer
+
+ RETURNS
+ Non-negative length of the path on success, Negative on failure
+ DESCRIPTION
+ Given a reference to some object, determine a path to the object
+ referenced in the file.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ This may not be the only path to that object.
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+ssize_t
+H5Rget_name(hid_t id, H5R_type_t ref_type, const void *_ref, char *name,
+ size_t size)
+{
+ H5G_loc_t loc; /* Group location */
+ H5F_t *file; /* File object */
+ ssize_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(H5Rget_name, FAIL)
+
+ /* Check args */
+ if(H5G_loc(id, &loc) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+ if(ref_type <= H5R_BADTYPE || ref_type >= H5R_MAXTYPE)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type")
+ if(_ref == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer")
+
+ /* Get the file pointer from the entry */
+ file = loc.oloc->file;
+
+ /* Get name */
+ if((ret_value = H5R_get_name(file, H5AC_dxpl_id, id, ref_type, _ref, name, size)) < 0)
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to determine object path")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Rget_name() */
+