From 7bff4eb559d3f28f27ab29ced0d1e46ada1df620 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Wed, 28 Aug 2002 13:34:12 -0500 Subject: [svn-r5904] Purpose: Added 'ID to name' support Description: There is a new API function H5Iget_name Most of the changes are on H5G.c , regarding the symbol table entry struct H5G_entry_t which has 2 new fields 'name' and 'old_name' A new private function was introduced H5G_ent_copy, that does a deep copy between 2 symbol table entries The test file is getname.c Platforms tested: windows 2000, Linux, Solaris --- src/H5A.c | 19 +- src/H5D.c | 9 +- src/H5F.c | 24 +- src/H5G.c | 664 ++++++++++++++++++++++- src/H5Gent.c | 46 ++ src/H5Gprivate.h | 30 +- src/H5Gstab.c | 41 +- src/H5I.c | 385 +++++++++++-- src/H5Ipublic.h | 4 + src/H5O.c | 10 + src/H5Odtype.c | 12 +- src/H5T.c | 10 +- test/Makefile.in | 10 +- test/getname.c | 1573 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 14 files changed, 2766 insertions(+), 71 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index 678f37e..6703a6f 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -201,6 +201,10 @@ done: * April 2, 1998 * * Modifications: + * + * Pedro Vicente, 22 Aug 2002 + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ static hid_t @@ -240,8 +244,9 @@ H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type, /* Mark it initially set to initialized */ attr->initialized = TRUE; /*for now, set to false later*/ - /* Copy the symbol table entry */ - attr->ent=*ent; + /* Deep copy of the symbol table entry */ + if (H5G_ent_copy(ent,&(attr->ent))<0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry"); /* Compute the internal sizes */ attr->dt_size=(H5O_DTYPE[0].raw_size)(attr->ent.file,type); @@ -472,6 +477,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ static hid_t @@ -490,9 +498,10 @@ H5A_open(H5G_entry_t *ent, unsigned idx) if (NULL==(attr=H5O_read(ent, H5O_ATTR, (int)idx, attr))) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from dataset header"); attr->initialized=1; - - /* Copy the symbol table entry */ - attr->ent=*ent; + + /* Deep copy of the symbol table entry */ + if (H5G_ent_copy(ent,&(attr->ent))<0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry"); /* Hold the symbol table entry (and file) open */ if (H5O_open(&(attr->ent)) < 0) { diff --git a/src/H5D.c b/src/H5D.c index 577e25f..a15f00d 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -1958,6 +1958,9 @@ done: * Feb 26, 2002 * A new fill value message and two new properties are added. * + * Pedro Vicente, 22 Aug 2002 + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ H5D_t * @@ -1982,8 +1985,10 @@ H5D_open_oid(H5G_entry_t *ent) if(NULL==(dataset = H5D_new(H5P_DEFAULT))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - /* Copy over the symbol table information if it's provided */ - HDmemcpy(&(dataset->ent),ent,sizeof(H5G_entry_t)); + /* Deep copy of the symbol table entry */ + if (H5G_ent_copy(ent,&(dataset->ent))<0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, NULL, "unable to copy entry"); + /* Find the dataset object */ if (H5O_open(&(dataset->ent)) < 0) diff --git a/src/H5F.c b/src/H5F.c index 564fefc..13421a1 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -2912,9 +2912,12 @@ done: * * Modifications: * - * Robb Matzke, 1998-10-14 + * Robb Matzke, 1998-10-14 * The ref count for the child is decremented by calling H5F_close(). * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ static herr_t @@ -2954,6 +2957,11 @@ H5F_unmount(H5G_entry_t *loc, const char *name) parent = child->mtab.parent; for (i=0; imtab.nmounts; i++) { if (parent->mtab.child[i].file==child) { + + /* Search the symbol table entry list and replace names through group IDs */ + if (H5G_replace_name( H5G_UNKNOWN, loc, name, NULL, OP_UNMOUNT )<0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name "); + /* Unmount the child */ parent->mtab.nmounts -= 1; H5G_close(parent->mtab.child[i].group); @@ -3022,6 +3030,9 @@ done: * Tuesday, October 6, 1998 * * Modifications: + * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. * *------------------------------------------------------------------------- */ @@ -3032,6 +3043,7 @@ H5F_mountpoint(H5G_entry_t *find/*in,out*/) int lt, rt, md=(-1), cmp; H5G_entry_t *ent = NULL; herr_t ret_value=SUCCEED; /* Return value */ + char *tmp; FUNC_ENTER_NOAPI(H5F_mountpoint, FAIL); @@ -3063,7 +3075,9 @@ H5F_mountpoint(H5G_entry_t *find/*in,out*/) /* Copy root info over to ENT */ if (0==cmp) { ent = H5G_entof(parent->mtab.child[md].file->shared->root_grp); + tmp = find->name; *find = *ent; + find->name = tmp; parent = ent->file; } } while (!cmp); @@ -3086,6 +3100,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ herr_t @@ -3114,6 +3131,11 @@ H5Fmount(hid_t loc_id, const char *name, hid_t child_id, hid_t plist_id) if (H5F_mount(loc, name, child, plist_id)<0) HGOTO_ERROR(H5E_FILE, H5E_MOUNT, FAIL, "unable to mount file"); + /* Search the symbol table entry list and replace names through group IDs */ + /* We pass H5G_UNKNOWN as object type; search all IDs */ + if (H5G_replace_name( H5G_UNKNOWN, loc, name, NULL, OP_MOUNT )<0) + HRETURN_ERROR(H5E_FILE, H5E_MOUNT, FAIL, "unable to replace name "); + done: FUNC_LEAVE(ret_value); } diff --git a/src/H5G.c b/src/H5G.c index d12f5e3..2141389 100644 --- a/src/H5G.c +++ b/src/H5G.c @@ -69,6 +69,9 @@ * Robb Matzke, 30 Aug 1997 * Added `Errors:' field to function prologues. * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ @@ -107,6 +110,10 @@ static size_t H5G_comp_alloc_g = 0; /*sizeof component buffer */ /* Declare a free list to manage the H5G_t struct */ H5FL_DEFINE(H5G_t); +/* Private prototypes */ +static herr_t H5G_replace_ent(void *obj_ptr, hid_t obj_id, void *key); + + /*------------------------------------------------------------------------- * Function: H5Gcreate @@ -489,6 +496,9 @@ done: * Monday, April 6, 1998 * * Modifications: + * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. * *------------------------------------------------------------------------- */ @@ -497,6 +507,7 @@ H5Gunlink(hid_t loc_id, const char *name) { H5G_entry_t *loc = NULL; herr_t ret_value=SUCCEED; /* Return value */ + H5G_stat_t statbuf; FUNC_ENTER_API(H5Gunlink, FAIL); H5TRACE2("e","is",loc_id,name); @@ -507,10 +518,19 @@ H5Gunlink(hid_t loc_id, const char *name) if (!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name"); + /* Get object type before unlink */ + if (H5G_get_objinfo(loc, name, FALSE, &statbuf)<0) { + HRETURN_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found"); + } + /* Unlink */ if (H5G_unlink(loc, name)<0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to unlink object"); + /* Search the symbol table entry list and replace names through group IDs */ + if (H5G_replace_name( statbuf.type, loc, name, NULL, OP_UNLINK )<0) + HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name "); + done: FUNC_LEAVE (ret_value); } @@ -1025,6 +1045,10 @@ H5G_basename(const char *name, size_t *size_p) * called. * (2) We need to be able to free it from H5G_term_interface() * when the library terminates. + * + * Pedro Vicente, 22 Aug 2002 + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ static herr_t @@ -1038,6 +1062,8 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/, int _nlinks = H5G_NLINKS; const char *s = NULL; herr_t ret_value=SUCCEED; /* Return value */ + + H5G_t *tmp_grp; FUNC_ENTER_NOINIT(H5G_namei); @@ -1055,10 +1081,18 @@ H5G_namei(H5G_entry_t *loc_ent, const char *name, const char **rest/*out*/, } else if (!loc_ent) { HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no current working group"); } else if ('/' == *name) { - *obj_ent = H5G_rootof(loc_ent->file)->ent; + tmp_grp=H5G_rootof(loc_ent->file); + + /* Deep copy of the symbol table entry */ + if (H5G_ent_copy( &(tmp_grp->ent), obj_ent )<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry"); + } else { - *obj_ent = *loc_ent; + /* Deep copy of the symbol table entry */ + if (H5G_ent_copy( loc_ent, obj_ent )<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry"); } + HDmemset(grp_ent, 0, sizeof(H5G_entry_t)); grp_ent->header = HADDR_UNDEF; @@ -1156,6 +1190,9 @@ done: * Friday, April 10, 1998 * * Modifications: + * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. * *------------------------------------------------------------------------- */ @@ -1168,6 +1205,9 @@ H5G_traverse_slink (H5G_entry_t *grp_ent/*in,out*/, const char *clv = NULL; /*cached link value */ char *linkval = NULL; /*the copied link value */ herr_t ret_value=SUCCEED; /* Return value */ + + /*Store old name */ + char* old_name=obj_ent->name; FUNC_ENTER_NOAPI(H5G_traverse_slink, FAIL); @@ -1183,6 +1223,8 @@ H5G_traverse_slink (H5G_entry_t *grp_ent/*in,out*/, if (H5G_namei (grp_ent, linkval, NULL, grp_ent, obj_ent, H5G_TARGET_NORMAL, nlinks)) HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "unable to follow symbolic link"); + obj_ent->name = old_name; + done: H5MM_xfree (linkval); FUNC_LEAVE (ret_value); @@ -1207,6 +1249,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ herr_t @@ -1246,6 +1291,11 @@ H5G_mkroot (H5F_t *f, H5G_entry_t *ent) H5O_reset (H5O_STAB, &stab); } + /*create the "/" name */ + ent->name = HDstrdup( "/" ); + ent->old_name = NULL; + + /* * Create the group pointer. Also decrement the open object count so we * don't count the root group as an open object. The root group will @@ -1453,6 +1503,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ H5G_t * @@ -1471,8 +1524,9 @@ H5G_open_oid(H5G_entry_t *ent) if (NULL==(grp = H5FL_ALLOC(H5G_t,1))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - /* Copy over the symbol table information if it's provided */ - HDmemcpy(&(grp->ent),ent,sizeof(H5G_entry_t)); + /*deep copy of the symbol table entry*/ + if (H5G_ent_copy(ent,&(grp->ent))<0) + HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to copy entry"); /* Grab the object header */ if (H5O_open(&(grp->ent)) < 0) @@ -2314,8 +2368,11 @@ done: * * Modifications: * - * Raymond Lu - * Thursday, April 18, 2002 + * Raymond Lu + * Thursday, April 18, 2002 + * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. * *------------------------------------------------------------------------- */ @@ -2366,6 +2423,14 @@ H5G_move(H5G_entry_t *src_loc, const char *src_name, H5G_entry_t *dst_loc, if (H5G_unlink(src_loc, src_name)<0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to deregister old object name"); + /* + Search the symbol table entry list and replace names through group IDs + This has to be done here because H5G_link and H5G_unlink have + internal object entries , and do not modify the entries list + */ + if (H5G_replace_name( sb.type, src_loc, src_name, dst_name, OP_MOVE )<0) + HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name "); + done: FUNC_LEAVE(ret_value); } @@ -2422,3 +2487,590 @@ H5G_insertion_file(H5G_entry_t *loc, const char *name) done: FUNC_LEAVE(ret_value); } + + + +/*------------------------------------------------------------------------- + * Function: H5G_insert_name + * + * Purpose: Insert a name into the symbol entry OBJ, located at LOC + * + * Return: Success: 0, Failure: -1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: August 22, 2002 + * + * Comments: The allocated memory (H5MM_malloc) is freed in H5O_close + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +herr_t +H5G_insert_name(H5G_entry_t *loc, H5G_entry_t *obj, const char *name) +{ + + size_t len1, len2; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(H5G_insert_name, FAIL); + + if ( loc->name ) { + + len1 = HDstrlen(loc->name); + len2 = HDstrlen(name); + assert(len2>0&&len1>0); + /* this is the root group */ + if ('/'==loc->name[len1-1]) + { + + if (NULL==(obj->name = H5MM_malloc (len1+len2+1))) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); + HDstrcpy(obj->name, loc->name); + HDstrcpy(obj->name+len1, name); + + } + /* this is a subgroup */ + else + { + if (NULL==(obj->name = H5MM_malloc (len1+1+len2+1))) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); + HDstrcpy(obj->name, loc->name); + HDstrcpy(obj->name+len1, "/"); + HDstrcpy(obj->name+len1+1, name); + } + } + +done: + FUNC_LEAVE(ret_value); + +} + + + +/*------------------------------------------------------------------------- + * Function: H5G_replace_name + * + * Purpose: Search the symbol table entry list and replace names through group IDs + * + * Return: Success: 0, Failure: -1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: June 11, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +herr_t H5G_replace_name( int type, H5G_entry_t *loc, const char *src_name, + const char *dst_name, int op ) +{ + + H5G_names_t names; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(H5G_replace_name, FAIL); + + names.src_name=src_name; + names.dst_name=dst_name; + names.loc=loc; + names.op=op; + + switch ( type ) + { + + /* Object is a group */ + case H5G_GROUP: + + /* Search and replace names through group IDs */ + names.obj_type = H5I_GROUP; + H5I_search(H5I_GROUP, (H5I_search_func_t)H5G_replace_ent, &names ); + + break; + + /* Object is a dataset */ + case H5G_DATASET: + + /* Search and replace names through dataset IDs */ + names.obj_type = H5I_DATASET; + H5I_search(H5I_DATASET, (H5I_search_func_t)H5G_replace_ent, &names ); + + break; + + /* Object is a named data type */ + case H5G_TYPE: + + /* Search and replace names through datatype IDs */ + names.obj_type = H5I_DATATYPE; + H5I_search(H5I_DATATYPE, (H5I_search_func_t)H5G_replace_ent, &names ); + + break; + + /* We pass H5G_UNKNOWN as object type for the H5Fmount case; search all IDs */ + case H5G_UNKNOWN: + + /* Search through group IDs */ + if ( H5I_nmembers(H5I_GROUP) ) { + names.obj_type = H5I_GROUP; + H5I_search(H5I_GROUP, (H5I_search_func_t)H5G_replace_ent, &names ); + } + /* Search through dataset IDs */ + if ( H5I_nmembers(H5I_DATASET) ) { + names.obj_type = H5I_DATASET; + H5I_search(H5I_DATASET, (H5I_search_func_t)H5G_replace_ent, &names ); + } + /* Search through datatype IDs */ + if ( H5I_nmembers(H5I_DATATYPE) ) { + names.obj_type = H5I_DATATYPE; + H5I_search(H5I_DATATYPE, (H5I_search_func_t)H5G_replace_ent, &names ); + } + + break; + + /* Object is a symbolic link */ + + case H5G_LINK: + + /* Search through group IDs */ + if ( H5I_nmembers(H5I_GROUP) ) { + names.obj_type = H5I_GROUP; + H5I_search(H5I_GROUP, (H5I_search_func_t)H5G_replace_ent, &names ); + } + /* Search through dataset IDs */ + if ( H5I_nmembers(H5I_DATASET) ) { + names.obj_type = H5I_DATASET; + H5I_search(H5I_DATASET, (H5I_search_func_t)H5G_replace_ent, &names ); + } + /* Search through datatype IDs */ + if ( H5I_nmembers(H5I_DATATYPE) ) { + names.obj_type = H5I_DATATYPE; + H5I_search(H5I_DATATYPE, (H5I_search_func_t)H5G_replace_ent, &names ); + } + + break; + + default: + HRETURN_ERROR (H5E_DATATYPE, H5E_BADTYPE, FAIL, + "not valid object type"); + + }; + +done: + FUNC_LEAVE( SUCCEED ); +} + + + +/*------------------------------------------------------------------------- + * Function: H5G_rest + * + * Purpose: Get the last component of the name + * + * Return: SUCCEED + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: July 5, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + + static herr_t + H5G_rest( const char *name, const char **rest/*out*/ ) + { + + size_t nchars; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(H5G_rest, FAIL); + + /* traverse the name */ + while ((name = H5G_component(name, &nchars)) && *name) + { + if (rest) *rest = name; + + /* next component */ + name += nchars; + } + + +done: + FUNC_LEAVE(SUCCEED); + + } + +/*------------------------------------------------------------------------- + * Function: H5G_replace_ent + * + * Purpose: H5I_search callback function to replace group entry names + * + * Return: Success: 0, Failure: -1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: June 5, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + static herr_t + H5G_replace_ent(void *obj_ptr, hid_t obj_id, void *key) + { + H5G_names_t *names = key; + H5G_entry_t *ent = NULL; + size_t len1, len2; + char *tmp_buf; + H5F_t *parent_file; + H5F_t *child_file; + H5F_mount_t *child_mnt; + H5G_entry_t *child_grp_ent; + unsigned i; + size_t len; + const char *rest = NULL; /*the base name */ + int cmp; + char *new_src_name; + char *new_dst_name; + herr_t ret_value = FAIL; + + FUNC_ENTER_NOAPI(H5G_replace_ent, FAIL); + + assert(obj_ptr); + + /* avoid no named datatypes */ + if( names->obj_type==H5I_DATATYPE && H5T_is_immutable((H5T_t*)obj_ptr)) + { + /* Do not exit loop */ + ret_value = SUCCEED; + goto done; + } + + /* Get the symbol table entry */ + switch(names->obj_type) { + case H5I_GROUP: + ent = H5G_entof((H5G_t*)obj_ptr); + break; + case H5I_DATASET: + ent = H5D_entof((H5D_t*)obj_ptr); + break; + case H5I_DATATYPE: + ent = H5T_entof((H5T_t*)obj_ptr); + break; + default: + ret_value = FAIL; + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "unknown data object"); + } + + + /* Check if is a mounted file */ + if(ent->file->mtab.parent) { + + if(ent->file->mtab.parent->shared != names->loc->file->shared ) + { + /* Do not exit loop */ + ret_value = SUCCEED; + goto done; + } + + + if ( names->op==OP_UNLINK || names->op==OP_MOVE ) { + parent_file = ent->file->mtab.parent; + for ( i = 0; i < parent_file->mtab.nmounts; i++ ) + { + child_mnt = &parent_file->mtab.child[i]; + child_file = child_mnt->file; + + /* we found the right file */ + if( ent->file->shared == child_file->shared ) + { + child_grp_ent = &child_mnt->group->ent; + len = HDstrlen( child_grp_ent->name ); + + /* Find the prefix of the name */ + cmp = HDstrncmp( child_grp_ent->name, names->src_name, len); + if ( cmp == 0 ) + { + new_src_name=H5MM_strdup(names->src_name+len); + + if (names->op==OP_UNLINK) + new_dst_name=H5MM_strdup(names->dst_name); + else if (names->op==OP_MOVE) + new_dst_name=H5MM_strdup(names->dst_name+len); + + /* Search the symbol table entry list and replace names through group IDs */ + if (H5G_replace_name( H5G_UNKNOWN, + child_grp_ent, + new_src_name, + new_dst_name, + names->op )<0) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to replace name "); + + H5MM_xfree(new_dst_name); + + + }/*if */ + + }/*if */ + + + } /*for */ + }/*if */ + + + } /*if */ + + /* Verify if file IDs refer to the same file */ + else { + if( ent->file->shared != names->loc->file->shared ) + { + /* Do not exit loop */ + ret_value = SUCCEED; + goto done; + } + } + + /* Get the type of call we are doing */ + switch(names->op) { + + /*------------------------------------------------------------------------- + * OP_MOUNT + *------------------------------------------------------------------------- + */ + + case OP_MOUNT: + + /* Find entries that might contain part of this name */ + if ( HDstrstr( ent->name, names->src_name )) + { + + /* Store the old name for unmount case */ + /*ent->old_name = ent->name;*/ + ent->old_name = HDstrdup(ent->name); + + if (names->dst_name) { + len1 = HDstrlen( names->dst_name ); + ent->name = H5MM_malloc( len1+1 ); + HDstrcpy( ent->name, names->dst_name ); + } + else + HDstrcpy( ent->name, "" ); + + } + + /* Do not exit loop */ + ret_value = 0; + goto done; + break; + + /*------------------------------------------------------------------------- + * OP_UNMOUNT + *------------------------------------------------------------------------- + */ + + case OP_UNMOUNT: + + if(ent->name){ + /* Find entries that might contain part of this name */ + if ( HDstrstr( ent->name, names->src_name )) + { + + /* Delete the old name */ + ent->name=H5MM_xfree(ent->name); + + if (names->dst_name){ + len1 = HDstrlen( names->dst_name ); + ent->name = H5MM_malloc( len1+1 ); + HDstrcpy( ent->name, names->dst_name ); + } + } + }/*if*/ + + + /* See if the entry old name matches */ + if ( ent->old_name ) { + if ( HDstrstr( ent->old_name, names->src_name )) + { + + /* Delete the old name */ + if (ent->name ) + H5MM_xfree(ent->name); + + /* Copy the old name to the entry */ + ent->name = ent->old_name; + ent->old_name = NULL; + } + } + + + /* Do not exit loop */ + ret_value = 0; + + + goto done; + break; + + /*------------------------------------------------------------------------- + * OP_UNLINK + *------------------------------------------------------------------------- + */ + + case OP_UNLINK: + + /* H5Gunlink case */ + + if (ent->name ){ + cmp = HDstrcmp( ent->name, names->src_name ); + + /* Found the correct entry, just replace the name */ + if ( cmp==0 ) + { + ent->name=H5MM_xfree(ent->name); + + if (names->dst_name){ + len1 = HDstrlen( names->dst_name ); + ent->name = H5MM_malloc( len1+1 ); + HDstrcpy( ent->name, names->dst_name ); + } + + } + + /* Find other entries that might contain part of this name */ + else if ( cmp>0 ) + { + + if ( HDstrstr( ent->name, names->src_name )) + { + /* Delete the old name and clear the entry */ + H5MM_xfree(ent->name); + ent->name=NULL; + } + + } + }/*if*/ + + + /* Do not exit loop */ + ret_value = 0; + goto done; + break; + + /*------------------------------------------------------------------------- + * OP_MOVE + *------------------------------------------------------------------------- + */ + + case OP_MOVE: + + /* H5Gmove case, check for relative names case */ + + /* Verify if we have the wanted entry */ + if ( HDstrcmp( ent->name, names->src_name )!=0 ) + { + + /* Do not exit loop */ + ret_value = SUCCEED; + + /* Get the last component of the name */ + H5G_rest( ent->name, &rest ); + + /* Relative names case, build the full pathname */ + if ( rest && HDstrcmp( rest, names->src_name )==0 ) + { + + len1 = HDstrlen(ent->name); + len2 = HDstrlen(rest); + ent->name[len1-len2-1] = '\0'; + + tmp_buf = HDstrdup(ent->name); + + len1 = HDstrlen(ent->name); + len2 = HDstrlen(names->dst_name); + assert(len1>0 && len2>0); + + H5MM_xfree(ent->name); + ent->name = H5MM_malloc(len1+1+len2+1); + HDstrcpy(ent->name, tmp_buf); + HDstrcpy(ent->name+len1, "/"); + HDstrcpy(ent->name+len1+1, names->dst_name); + + HDfree(tmp_buf); + + /* Found entry, exit loop */ + ret_value = 1; + + } /* Relative names case */ + + goto done; + + } /* wanted entry */ + + + break; + + /*------------------------------------------------------------------------- + * OP_LINK + *------------------------------------------------------------------------- + */ + + case OP_LINK: + + /* H5Glink case */ + cmp = HDstrcmp( ent->name, names->src_name ); + + /* Found the correct entry, just replace the name */ + if ( cmp==0 ) + { + + if (ent->name ) + H5MM_xfree(ent->name); + + len1 = HDstrlen( names->dst_name ); + ent->name = H5MM_malloc( len1+1 ); + HDstrcpy( ent->name, names->dst_name ); + } + + + /* Do not exit loop */ + ret_value = 0; + goto done; + break; + + + + default: + ret_value = FAIL; + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "invalid call"); + } + + + + /* Delete the old name */ + if (ent->name ) + H5MM_xfree(ent->name); + + /* Add the new name */ + len1 = HDstrlen( names->dst_name ); + ent->name = H5MM_malloc( len1+1 ); + HDstrcpy( ent->name, names->dst_name ); + + /* Found entry, exit loop */ + ret_value = 1; + +done: + FUNC_LEAVE(ret_value); +} + diff --git a/src/H5Gent.c b/src/H5Gent.c index bcc40d8..30c082e 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -337,6 +337,52 @@ done: FUNC_LEAVE(ret_value); } + + +/*------------------------------------------------------------------------- + * Function: H5G_ent_copy + * + * Purpose: Do a deep copy of symbol table entries + * + * Return: Success: 0, Failure: -1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: August 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +herr_t +H5G_ent_copy( const H5G_entry_t *src, H5G_entry_t *dst ) +{ + + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5G_ent_copy, FAIL); + + assert( src ); + assert( dst ); + + HDmemcpy(dst,src,sizeof(H5G_entry_t)); + + if (src->name){ + dst->name=H5MM_strdup(src->name); + } + if (src->old_name){ + dst->old_name=H5MM_strdup(src->old_name); + } + + +done: + FUNC_LEAVE(SUCCEED); +} + + /*------------------------------------------------------------------------- * Function: H5G_ent_debug diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h index 1d9df9d..7a92c08 100644 --- a/src/H5Gprivate.h +++ b/src/H5Gprivate.h @@ -10,7 +10,10 @@ * * Purpose: Library-visible declarations. * - * Modifications: + * Modifications: Aug 22, 2002 + * Pedro Vicente + * Added 'names' field to H5G_entry_t + * Added H5G_replace_name * *------------------------------------------------------------------------- */ @@ -92,6 +95,8 @@ typedef struct H5G_entry_t { H5G_type_t type; /*type of information cached */ H5G_cache_t cache; /*cached data from object header */ H5F_t *file; /*file to which this obj hdr belongs */ + char *name; /*name associated with atom */ + char *old_name; /*old name hidden by a file mount */ } H5G_entry_t; typedef struct H5G_t H5G_t; @@ -107,6 +112,25 @@ typedef struct H5G_typeinfo_t { char *desc; /*description of object type */ } H5G_typeinfo_t; + + typedef enum H5G_names_op_t { + OP_MOVE = 0, /* H5*move call */ + OP_LINK = 1, /* H5Glink call */ + OP_UNLINK = 2, /* H5Gunlink call */ + OP_MOUNT = 3, /* H5Fmount call */ + OP_UNMOUNT= 4 /* H5Funmount call */ + }H5G_names_op_t; + +/* Struct only used by change name callback function */ +typedef struct H5G_names_t { + H5I_type_t obj_type; + const char *src_name; + const char *dst_name; + H5G_entry_t *loc; + H5G_names_op_t op; +} H5G_names_t; + + /* * Library prototypes... These are the ones that other packages routinely * call. @@ -168,4 +192,8 @@ __DLL__ H5G_cache_t *H5G_ent_cache(H5G_entry_t *ent, H5G_type_t *cache_type); __DLL__ herr_t H5G_ent_modified(H5G_entry_t *ent, H5G_type_t cache_type); __DLL__ herr_t H5G_ent_debug(H5F_t *f, const H5G_entry_t *ent, FILE * stream, int indent, int fwidth, haddr_t heap); +__DLL__ herr_t H5G_replace_name( int type, H5G_entry_t *loc, const char *src_name, + const char *dst_name, int op ); +__DLL__ herr_t H5G_insert_name( H5G_entry_t *loc, H5G_entry_t *obj, const char *name); +__DLL__ herr_t H5G_ent_copy( const H5G_entry_t *src, H5G_entry_t *dst ); #endif diff --git a/src/H5Gstab.c b/src/H5Gstab.c index 9c4311c..72c0d25 100644 --- a/src/H5Gstab.c +++ b/src/H5Gstab.c @@ -121,6 +121,10 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ herr_t @@ -131,6 +135,8 @@ H5G_stab_find(H5G_entry_t *grp_ent, const char *name, H5O_stab_t stab; /*symbol table message */ herr_t ret_value=SUCCEED; /* Return value */ + obj_ent->name=NULL; + FUNC_ENTER_NOAPI(H5G_stab_find, FAIL); /* Check arguments */ @@ -146,10 +152,28 @@ H5G_stab_find(H5G_entry_t *grp_ent, const char *name, udata.heap_addr = stab.heap_addr; /* search the B-tree */ - if (H5B_find(grp_ent->file, H5B_SNODE, stab.btree_addr, &udata) < 0) - HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found"); - if (obj_ent) - *obj_ent = udata.ent; + if (H5B_find(grp_ent->file, H5B_SNODE, stab.btree_addr, &udata) < 0) { + HRETURN_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "not found"); + } + + /* change OBJ_ENT only if found */ + else + { + if (obj_ent) { + + /* do a deep copy */ + if (H5G_ent_copy( &(udata.ent), obj_ent )<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy entry"); + + /* insert the name into the symbol entry OBJ_ENT */ + if (H5G_insert_name( grp_ent, obj_ent, name ) < 0) { + HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, + "cannot insert name"); + } + + } + } + done: FUNC_LEAVE(ret_value); @@ -173,6 +197,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ herr_t @@ -207,6 +234,12 @@ H5G_stab_insert(H5G_entry_t *grp_ent, const char *name, H5G_entry_t *obj_ent) /* update the name offset in the entry */ obj_ent->name_off = udata.ent.name_off; + /* insert the name into the symbol entry OBJ_ENT */ + if (H5G_insert_name( grp_ent, obj_ent, name ) < 0) { + HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, + "cannot insert name"); + } + done: FUNC_LEAVE(ret_value); } diff --git a/src/H5I.c b/src/H5I.c index 01d2e20..e86ce66 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -37,6 +37,16 @@ #include "H5FLprivate.h" /*Free Lists */ #include "H5MMprivate.h" +#define H5G_PACKAGE /*suppress error message about including H5Gpkg.h */ +#define H5I_DEBUG_OUTPUT + + +#include "H5Gprivate.h" /*symbol tables */ +#include "H5Gpkg.h" +#include "H5Dprivate.h" /*datasets */ +#include "H5Tprivate.h" /*data types */ +#include "H5Aprivate.h" /*attributes */ + /* Interface initialialization? */ #define PABLO_MASK H5I_mask static int interface_initialize_g = 0; @@ -1107,69 +1117,354 @@ done: FUNC_LEAVE(ret_value); } - + + + /*------------------------------------------------------------------------- - * Function: H5I_debug + * Function: H5Iget_name * - * Purpose: Dump the contents of a group to stderr for debugging. + * Purpose: Gets a name of an object from its ID. * - * Return: Success: Non-negative + * Return: Success: 0, Failure: -1 * - * Failure: Negative + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * - * Programmer: Robb Matzke - * Friday, February 19, 1999 + * Date: July 26, 2002 + * + * Comments: Public function + * If `name' is non-NULL then write up to `size' bytes into that + * buffer and always return the length of the entry name. + * Otherwise `size' is ignored and the function does not store the name, + * just returning the number of characters required to store the name. + * If an error occurs then the buffer pointed to by `name' (NULL or non-NULL) + * is unchanged and the function returns a negative value. + * If a zero is returned for the name's length, then there is no name + * associated with the ID. * * Modifications: * *------------------------------------------------------------------------- */ + +ssize_t H5Iget_name(hid_t id, char *name/*out*/, size_t size) +{ + H5G_entry_t *ent; /*symbol table entry */ + size_t len=0; + size_t count; + ssize_t ret_value; + + FUNC_ENTER_API (H5Iget_name, FAIL); + + /* get symbol table entry */ + if ( NULL== ( ent = H5G_loc( id ))) + goto done; + + if ( ent->name != NULL ) { + + len = HDstrlen(ent->name); + count = MIN(len+1,size); + + if ( name ) { + HDstrncpy( name, ent->name, count ); + if ( len >= size ) { + name[size-1]='\0'; + } + } + } + else + { + len = 0; + } + +done: + ret_value = len; + FUNC_LEAVE( ret_value ); +} + + + +/*------------------------------------------------------------------------- + * Function: H5I_debug + * + * Purpose: Dump the contents of a group to stderr for debugging. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Friday, February 19, 1999 + * + * Modifications: + * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * + *------------------------------------------------------------------------- + */ #ifdef H5I_DEBUG_OUTPUT static herr_t H5I_debug(H5I_type_t grp) { - H5I_id_group_t *grp_ptr; - H5I_id_info_t *cur; - int is, js; - unsigned int iu; - - FUNC_ENTER_NOAPI(H5I_debug, FAIL); + H5I_id_group_t *grp_ptr; + H5I_id_info_t *cur; + int is, js; + unsigned int iu; + herr_t ret_value; /* Return value */ + + + H5G_entry_t *ent = NULL; + + FUNC_ENTER_API(H5I_debug, FAIL); + + fprintf(stderr, "Dumping group %d\n", (int)grp); + grp_ptr = H5I_id_group_list_g[grp]; + + /* Header */ + fprintf(stderr, " count = %u\n", grp_ptr->count); + fprintf(stderr, " reserved = %u\n", grp_ptr->reserved); + fprintf(stderr, " wrapped = %u\n", grp_ptr->wrapped); + fprintf(stderr, " hash_size = %lu\n", + (unsigned long)grp_ptr->hash_size); + fprintf(stderr, " ids = %u\n", grp_ptr->ids); + fprintf(stderr, " nextid = %u\n", grp_ptr->nextid); + + /* Cache */ + fprintf(stderr, " Cache:\n"); + for (is=0; isid)==grp) { + fprintf(stderr, " Entry-%d, ID=%lu\n", + is, (unsigned long)(H5I_cache_g[is]->id)); + } + } + + /* List */ + fprintf(stderr, " List:\n"); + for (iu=0; iuhash_size; iu++) { + for (js=0, cur=grp_ptr->id_list[iu]; cur; cur=cur->next, js++) { + fprintf(stderr, " #%u.%d\n", iu, js); + fprintf(stderr, " id = %lu\n", + (unsigned long)(cur->id)); + fprintf(stderr, " count = %u\n", cur->count); + fprintf(stderr, " obj = 0x%08lx\n", + (unsigned long)(cur->obj_ptr)); + + + switch(grp) { - fprintf(stderr, "Dumping group %d\n", (int)grp); - grp_ptr = H5I_id_group_list_g[grp]; + case H5I_GROUP: + ent = H5G_entof((H5G_t*)cur->obj_ptr); + break; + case H5I_DATASET: + ent = H5D_entof((H5D_t*)cur->obj_ptr); + break; + case H5I_DATATYPE: + ent = H5T_entof((H5T_t*)cur->obj_ptr); + break; + default: + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "unknown data object"); + }/* switch*/ + + fprintf(stderr, "name = %s\n",ent->name); + + + + } + } + +done: + FUNC_LEAVE(SUCCEED); +} +#endif /* H5I_DEBUG_OUTPUT */ - /* Header */ - fprintf(stderr, " count = %u\n", grp_ptr->count); - fprintf(stderr, " reserved = %u\n", grp_ptr->reserved); - fprintf(stderr, " wrapped = %u\n", grp_ptr->wrapped); - fprintf(stderr, " hash_size = %lu\n", - (unsigned long)grp_ptr->hash_size); - fprintf(stderr, " ids = %u\n", grp_ptr->ids); - fprintf(stderr, " nextid = %u\n", grp_ptr->nextid); - - /* Cache */ - fprintf(stderr, " Cache:\n"); - for (is=0; isid)==grp) { - fprintf(stderr, " Entry-%d, ID=%lu\n", - is, (unsigned long)(H5I_cache_g[is]->id)); - } - } - /* List */ - fprintf(stderr, " List:\n"); - for (iu=0; iuhash_size; iu++) { - for (js=0, cur=grp_ptr->id_list[iu]; cur; cur=cur->next, js++) { - fprintf(stderr, " #%u.%d\n", iu, js); - fprintf(stderr, " id = %lu\n", - (unsigned long)(cur->id)); - fprintf(stderr, " count = %u\n", cur->count); - fprintf(stderr, " obj = 0x%08lx\n", - (unsigned long)(cur->obj_ptr)); - } - } +/*------------------------------------------------------------------------- + * Function: H5I_debug_grp + * + * Purpose: Dump the contents of a group to stderr for debugging + * + * Return: Success: 0, Failure: -1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: July 26, 2002 + * + * Comments: Public function + * + * Modifications: + * + *------------------------------------------------------------------------- + */ - FUNC_LEAVE(SUCCEED); +#ifdef H5I_DEBUG_OUTPUT +herr_t H5Idebug_grp(H5I_type_t grp) +{ + H5I_id_group_t *grp_ptr; + H5I_id_info_t *cur; + int is, js; + unsigned int iu; + herr_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5Idebug_grp, FAIL); + + fprintf(stderr, "Dumping group %d\n", (int)grp); + grp_ptr = H5I_id_group_list_g[grp]; + + /* Header */ + fprintf(stderr, " count = %u\n", grp_ptr->count); + fprintf(stderr, " reserved = %u\n", grp_ptr->reserved); + fprintf(stderr, " wrapped = %u\n", grp_ptr->wrapped); + fprintf(stderr, " hash_size = %lu\n", + (unsigned long)grp_ptr->hash_size); + fprintf(stderr, " ids = %u\n", grp_ptr->ids); + fprintf(stderr, " nextid = %u\n", grp_ptr->nextid); + + /* Cache */ + fprintf(stderr, " Cache:\n"); + for (is=0; isid)==grp) { + fprintf(stderr, " Entry-%d, ID=%lu\n", + is, (unsigned long)(H5I_cache_g[is]->id)); + } + } + + /* List */ + fprintf(stderr, " List:\n"); + for (iu=0; iuhash_size; iu++) { + for (js=0, cur=grp_ptr->id_list[iu]; cur; cur=cur->next, js++) { + + /* avoid no named datatypes */ + if( grp==H5I_DATATYPE && H5T_is_immutable((H5T_t*)cur->obj_ptr)) + break; + + + fprintf(stderr, " #%u.%d\n", iu, js); + fprintf(stderr, " id = %lu\n", + (unsigned long)(cur->id)); + fprintf(stderr, " count = %u\n", cur->count); + fprintf(stderr, " obj = 0x%08lx\n", + (unsigned long)(cur->obj_ptr)); + } + } + +done: + FUNC_LEAVE(SUCCEED); } #endif /* H5I_DEBUG_OUTPUT */ + + + +/*------------------------------------------------------------------------- + * Function: H5Idebug_name + * + * Purpose: Dump the contents of a group to stderr for debugging + * + * Return: Success: 0, Failure: -1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: July 26, 2002 + * + * Comments: Public function + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +#ifdef H5I_DEBUG_OUTPUT +herr_t H5Idebug_name(hid_t id) +{ + + H5I_type_t grp_type; /* group type */ + H5I_id_group_t *grp_ptr; /* ptr to the atomic group */ + H5I_id_info_t *cur=NULL; /* Current node being worked with */ + H5I_id_info_t *next=NULL; /* Next node in list */ + unsigned i; + + H5G_entry_t *ent = NULL; + H5G_t *group=NULL; + H5T_t *dt=NULL; + H5D_t *dset=NULL; + herr_t ret_value; /* Return value */ + + FUNC_ENTER_API (H5Idebug_name, FAIL); + + grp_type = H5I_get_type(id); + + /* Check it */ + if (grp_type <= H5I_BADID || grp_type >= H5I_NGROUPS) { + HRETURN(FAIL); + } + + grp_ptr = H5I_id_group_list_g[grp_type]; + if (grp_ptr == NULL || grp_ptr->count <= 0) { + HRETURN(FAIL); + } + + /* Cache */ + fprintf(stderr, "\n"); + fprintf(stderr, "Cache:\n"); + for (i=0; iid)==grp_type) { + + cur = H5I_cache_g[i]; + fprintf(stderr, " Entry-%d, ID=%lu\n", i, cur->id); + + switch(grp_type) { + case H5I_GROUP: + ent = H5G_entof((H5G_t*)cur->obj_ptr); + break; + case H5I_DATASET: + ent = H5D_entof((H5D_t*)cur->obj_ptr); + break; + case H5I_DATATYPE: + ent = H5T_entof((H5T_t*)cur->obj_ptr); + break; + default: + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "unknown data object"); + }/* switch*/ + + fprintf(stderr, "name = %s\n",ent->name); + + } + } + + /* List */ + fprintf(stderr, "List:\n"); + for (i=0; ihash_size; i++) { + for (cur=grp_ptr->id_list[i]; cur; cur=next) { + + switch(grp_type) { + + case H5I_GROUP: + ent = H5G_entof((H5G_t*)cur->obj_ptr); + break; + case H5I_DATASET: + ent = H5D_entof((H5D_t*)cur->obj_ptr); + break; + case H5I_DATATYPE: + ent = H5T_entof((H5T_t*)cur->obj_ptr); + break; + default: + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "unknown data object"); + }/* switch*/ + + /* can be NULL in case of named datatypes */ + if (ent) + { + fprintf(stderr, "id = %lu\n",(unsigned long)(cur->id)); + fprintf(stderr, "name = %s\n",ent->name); + } + + } + } + +done: + FUNC_LEAVE(SUCCEED); +} +#endif /* H5I_DEBUG_OUTPUT */ \ No newline at end of file diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h index 85db6fd..2773f66 100644 --- a/src/H5Ipublic.h +++ b/src/H5Ipublic.h @@ -52,6 +52,10 @@ extern "C" { #endif __DLL__ H5I_type_t H5Iget_type(hid_t id); +__DLL__ ssize_t H5Iget_name(hid_t object_id, char *name/*out*/, size_t size); +__DLL__ herr_t H5Idebug_name(hid_t id); +__DLL__ herr_t H5Idebug_grp(H5I_type_t grp); + #ifdef __cplusplus diff --git a/src/H5O.c b/src/H5O.c index 900cd8c..0ce00e4 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -269,6 +269,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ herr_t @@ -306,6 +309,13 @@ H5O_close(H5G_entry_t *obj_ent) if (0==obj_ent->file->nopen_objs && obj_ent->file->closing) H5I_dec_ref(obj_ent->file->closing); + + /* Free the ID to name buffers */ + if ( obj_ent->name ) + obj_ent->name = H5MM_xfree(obj_ent->name); + if ( obj_ent->old_name ) + obj_ent->old_name = H5MM_xfree(obj_ent->old_name); + done: FUNC_LEAVE(ret_value); } diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 772cac7..81ea37b 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1108,6 +1108,9 @@ done: * * Modifications: * + * Pedro Vicente, 22 Aug 2002 + * Added `id to name' support. + * *------------------------------------------------------------------------- */ static herr_t @@ -1123,8 +1126,13 @@ H5O_dtype_set_share (H5F_t UNUSED *f, void *_mesg/*in,out*/, assert (sh); assert (!sh->in_gh); - dt->ent = sh->u.ent; - dt->state = H5T_STATE_NAMED; + dt->ent = sh->u.ent; + + dt->ent.name = NULL; + dt->ent.old_name = NULL; + + dt->state = H5T_STATE_NAMED; + done: FUNC_LEAVE (ret_value); diff --git a/src/H5T.c b/src/H5T.c index bc54b58..08f10f0 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -5406,6 +5406,9 @@ done: * Robb Matzke, 20 May 1999 * Now able to copy opaque types. * + * Pedro Vicente, 22 Aug 2002 + * Added a deep copy of the symbol table entry + * *------------------------------------------------------------------------- */ H5T_t * @@ -5425,9 +5428,14 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) if (NULL==(new_dt = H5FL_ALLOC(H5T_t,0))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - /* Copy actual information */ + /* Copy actual information */ *new_dt = *old_dt; + /* Deep copy of the symbol table entry */ + if (H5G_ent_copy(&(old_dt->ent),&(new_dt->ent))<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to copy entry"); + + /* Copy parent information */ if (new_dt->parent) new_dt->parent = H5T_copy(new_dt->parent, method); diff --git a/test/Makefile.in b/test/Makefile.in index 5ee046b..8292529 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -19,7 +19,7 @@ CPPFLAGS=-I. -I$(srcdir) -I../src -I$(top_srcdir)/src @CPPFLAGS@ 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 + srb_write srb_append srb_read ttsafe stream_test getname TIMINGS=testmeta @@ -49,7 +49,7 @@ MOSTLYCLEAN=cmpd_dset.h5 compact_dataset.h5 dataset.h5 extend.h5 istore.h5 \ tvlstr.h5 flush.h5 enum1.h5 titerate.h5 ttsafe.h5 tarray1.h5 \ tgenprop.h5 tmisc.h5 tmisc2a.h5 tmisc2b.h5 tmisc3.h5 tmisc4a.h5 \ tmisc4b.h5 tmisc5.h5 tmisc6.h5 tmisc7.h5 tmisc8.h5 \ - set_extent_read.h5 set_extent_create.h5 + set_extent_read.h5 set_extent_create.h5 getname.h5 CLEAN=$(TIMINGS) ## Source and object files for programs... The TEST_SRC list contains all the @@ -65,7 +65,7 @@ TEST_SRC=big.c bittests.c cmpd_dset.c dsets.c dtypes.c extend.c \ tvlstr.c tmisc.c unlink.c enum.c ttsafe.c ttsafe_dcreate.c \ ttsafe_error.c ttsafe_cancel.c ttsafe_acreate.c gass_write.c \ gass_read.c gass_append.c srb_read.c srb_write.c srb_append.c \ - stream_test.c set_extent.c + stream_test.c set_extent.c getname.c TEST_OBJ=$(TEST_SRC:.c=.lo) @@ -188,5 +188,9 @@ stream_test: stream_test.lo testmeta: testmeta.lo @$(LT_LINK_EXE) $(CFLAGS) -o $@ testmeta.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS) +getname: getname.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ getname.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS) + + @CONCLUDE@ diff --git a/test/getname.c b/test/getname.c index c8b493d..d17c4fb 100644 --- a/test/getname.c +++ b/test/getname.c @@ -1,22 +1,1593 @@ #include "hdf5.h" #include "h5test.h" + + + +/* Compound datatype */ +typedef struct s1_t { + unsigned int a; + unsigned int b; + float c; +} s1_t; + +#define FILE0 "getname.h5" +#define FILE1 "getname1.h5" +#define FILE2 "getname2.h5" +#define FILE3 "getname3.h5" + + + +#define RANK 2 +#define NX 4 +#define NY 5 + +int check_name( char *name, const char* check ) +{ + + int ret = HDstrcmp( name, check ); + HDstrcpy( name, "" ); + return ret; + +} + int main( void ) { + hid_t file_id, file1_id, file2_id, file3_id; + hid_t group_id, group2_id, group3_id, group4_id, group5_id, group6_id; + hid_t dataset_id, dataset2_id; + hid_t space_id; + hid_t type_id; + hsize_t dims[1] = { 5 }; + + /*buffer to hold name and its size */ + char name[20]; + size_t size=20; + + /*small buffer to hold name and its size */ + char name2[2]; + size_t size2=2; + + /*dynamic buffer to hold name and its size */ + char *name3 = NULL; + size_t name_len; + + + /* Create a new file_id using default properties. */ + if ((file_id = H5Fcreate( FILE0, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gcreate + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gcreate"); + + /* Create group "g1" in the root group using absolute name */ + if ((group_id = H5Gcreate( file_id, "/g1", 0 ))<0) goto out; + + /* Create group "g2" in group "g1" using absolute name */ + if ((group2_id = H5Gcreate( file_id, "/g1/g2", 0 ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gopen + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gopen"); + + /* Reopen the group */ + if ((group_id = H5Gopen( file_id, "/g1" ))<0) goto out; + + /* Reopen the group */ + if ((group2_id = H5Gopen( file_id, "/g1/g2" ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Dcreate + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Dcreate"); + + /* Create the data space */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + + /* Create a new dataset */ + if ((dataset_id = H5Dcreate( file_id , "d1", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/d1" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + + /* Reopen the group */ + if ((group_id = H5Gopen( file_id, "g1" ))<0) goto out; + + /* Create a new dataset inside "g1" */ + if ((dataset_id = H5Dcreate( group_id , "d1", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/d1" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Dclose( dataset_id ); + H5Sclose( space_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Dopen + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Dopen"); + + /* Reopen the dataset */ + if ((dataset_id = H5Dopen( file_id, "d1"))<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/d1" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + + + /* Reopen the group */ + if ((group_id = H5Gopen( file_id, "g1" ))<0) goto out; + + /* Reopen the dataset */ + if ((dataset_id = H5Dopen( group_id, "d1"))<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/d1" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Gclose( group_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with a long path + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with a long path"); + + /* Create group "g2/bar/baz" */ + if ((group_id = H5Gcreate( file_id, "g2", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "g2/bar", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "g2/bar/baz", 0 ))<0) goto out; + + /* Create a dataset */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + if ((dataset_id = H5Dcreate( group3_id , "d1", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Sclose( space_id ); + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + /* Reopen the dataset */ + if ((dataset_id = H5Dopen( file_id, "/g2/bar/baz/d1"))<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "/g2/bar/baz/d1" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Tcommit + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Tcommit"); + + /* Create a datatype */ + if ((type_id = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)))<0) goto out; + + /* Insert fields */ + if (H5Tinsert (type_id, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT)<0) goto out; + if (H5Tinsert (type_id, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT)<0) goto out; + if (H5Tinsert (type_id, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT)<0) goto out; + + /* Save datatype for later */ + if (H5Tcommit (file_id, "t1", type_id)<0) goto out; + + /* Get name */ + if (H5Iget_name( type_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/t1" )!=0) + goto out; + + /* Close datatype */ + H5Tclose(type_id); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Topen + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Topen"); + + /* Open the named datatype */ + if((type_id=H5Topen(file_id, "t1"))<0) goto out; + + /* Get name */ + if (H5Iget_name( type_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/t1" )!=0) + goto out; + + + /* Close datatype */ + H5Tclose(type_id); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gmove and H5Gopen + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gmove and H5Gopen"); + + /* Reopen the group */ + if ((group_id = H5Gopen( file_id, "/g1" ))<0) goto out; + + + /* Rename group */ + if (H5Gmove( file_id, "/g1", "/g1a" )<0) goto out; + + + /* Get name */ + if (H5Iget_name( group_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1a" )!=0) + goto out; + + + /* Close */ + H5Gclose( group_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gmove and H5Dopen + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gmove and H5Dopen"); + + /* Reopen the dataset */ + if ((dataset_id = H5Dopen( file_id, "/d1"))<0) goto out; + + /* Rename dataset */ + if (H5Gmove( file_id, "/d1", "/d1a" )<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/d1a" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gmove and H5Topen + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gmove and H5Topen"); + + /* Open the named datatype */ + if((type_id=H5Topen(file_id, "/t1"))<0) goto out; + + /* Rename datatype */ + if (H5Gmove( file_id, "/t1", "/t1a" )<0) goto out; + + /* Get name */ + if (H5Iget_name( type_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/t1a" )!=0) + goto out; + + + /* Close datatype */ + H5Tclose(type_id); + + PASSED(); + + /*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gmove and relative names + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gmove and relative names"); + + /* Create group "/g3" */ + if ((group_id = H5Gcreate( file_id, "/g3", 0 ))<0) goto out; + + /* Create group "/g3/foo" using absolute name */ + if ((group2_id = H5Gcreate( file_id, "/g3/foo1", 0 ))<0) goto out; + + /* Rename group */ + if (H5Gmove( group_id, "foo1", "foo2" )<0) goto out; + + + /* Get name */ + if (H5Iget_name( group_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g3" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g3/foo2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gmove and a long path + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gmove and H5Gopen"); + + /* Create group "g4/A/B" */ + if ((group_id = H5Gcreate( file_id, "g4", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "g4/A", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "g4/A/B", 0 ))<0) goto out; + + /* Create group "g5/C" */ + if ((group4_id = H5Gcreate( file_id, "g5", 0 ))<0) goto out; + if ((group5_id = H5Gcreate( file_id, "g5/C", 0 ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g4/A/B" )!=0) + goto out; + + /* Move group "B" to "D"*/ + if (H5Gmove( file_id, "/g4/A/B", "/g5/C/D" )<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g5/C/D" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + H5Gclose( group4_id ); + H5Gclose( group5_id ); + + PASSED(); + + + /*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gmove and a long path + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gmove and H5Gopen"); + + /* Create group "g6/A/B" and "g7" */ + if ((group_id = H5Gcreate( file_id, "g6", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "g6/A", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "g6/A/B", 0 ))<0) goto out; + if ((group4_id = H5Gcreate( file_id, "g7", 0 ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g6/A/B" )!=0) + goto out; + + /* Move group "A" to "C"*/ + if (H5Gmove( file_id, "/g6/A", "/g7/C" )<0) goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + /* Verify */ + if (check_name( name, "/g7/C" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + H5Gclose( group4_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gunlink + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gunlink"); + + /* Create a new group. */ + if ((group_id = H5Gcreate( file_id, "/g8", 0 ))<0) goto out; + + /* Delete */ + if (H5Gunlink( file_id, "/g8")<0) + goto out; - TESTING("get name"); + /* Get name */ + if (H5Iget_name( group_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gunlink and a long path + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gunlink and a long path"); + + /* Create group "g9/a/b" */ + if ((group_id = H5Gcreate( file_id, "g9", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "g9/a", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "g9/a/b", 0 ))<0) goto out; + + /* Delete */ + if (H5Gunlink( file_id, "/g9/a")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + /* Create group "g10/a/b" */ + if ((group_id = H5Gcreate( file_id, "g10", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "g10/a", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "g10/a/b", 0 ))<0) goto out; + + /* Delete */ + if (H5Gunlink( file_id, "/g10/a/b")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Gunlink, same names + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Gunlink, same names"); + + + /* Create group "g11/g" */ + if ((group_id = H5Gcreate( file_id, "g11", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "g11/g", 0 ))<0) goto out; + + /* Create two datasets "g11/d" and "g11/g/d"*/ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + if ((dataset_id = H5Dcreate( group_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + if ((dataset2_id = H5Dcreate( group2_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Delete */ + if (H5Gunlink( file_id, "/g11/d")<0) + goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( dataset2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g11/g/d" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Dclose( dataset2_id ); + H5Sclose( space_id ); + H5Gclose( group_id ); + H5Gclose( group2_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Fmount; with IDs on the list + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Fmount; with IDs on the list"); + + /* Create a group "g12" in the first file */ + if ((group_id = H5Gcreate( file_id, "/g12", 0 ))<0) goto out; + /* Close */ + H5Gclose( group_id ); + + /* Create second file and dataset "d" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* Create a data space */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + /* Create the dataset */ + if ((dataset_id = H5Dcreate( file1_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Close */ + H5Dclose( dataset_id ); + + /* Mount second file under "g12" in the first file */ + if (H5Fmount(file_id, "/g12", file1_id, H5P_DEFAULT)<0) goto out; + + /* Access dataset D in the first file under "/G/D" name */ + if ((dataset_id = H5Dopen( file_id, "/g12/d"))<0) goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "/g12/d" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Fclose( file1_id ); + H5Sclose( space_id ); + + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Fmount; long name + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Fmount; long name"); + + /* Create a group "g13/g1/g2" in the first file */ + if ((group_id = H5Gcreate( file_id, "/g13", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g13/g1", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "/g13/g1/g2", 0 ))<0) goto out; + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + /* Create second file and group "g" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + if ((group_id = H5Gcreate( file1_id, "/g14", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file1_id, "/g14/g3", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file1_id, "/g14/g3/g4", 0 ))<0) goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + /* Mount second file under "/g13/g1" in the first file */ + if (H5Fmount(file_id, "/g13/g1", file1_id, H5P_DEFAULT)<0) goto out; + + /* Access group in the first file */ + if ((group_id = H5Gopen( file_id, "/g13/g1/g14/g3/g4"))<0) goto out; + + /* Get name */ + if (H5Iget_name( group_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "/g13/g1/g14/g3/g4" )!=0) + goto out; + + if (H5Funmount(file_id, "/g13/g1")<0) goto out; + + + /* Get name */ + if (H5Iget_name( group_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Fclose( file1_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Funmount + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Funmount"); + + /* Create a group "g15/g1/g2" in the first file */ + if ((group_id = H5Gcreate( file_id, "/g15", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g15/g1", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file_id, "/g15/g1/g2", 0 ))<0) goto out; + if ((group4_id = H5Gcreate( file_id, "/g15/g1/g2/g3", 0 ))<0) goto out; + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + H5Gclose( group4_id ); + /* Create second file and group "g" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + if ((group_id = H5Gcreate( file1_id, "/g16", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file1_id, "/g16/g4", 0 ))<0) goto out; + if ((group3_id = H5Gcreate( file1_id, "/g16/g4/g5", 0 ))<0) goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + /* Access group in the first file */ + if ((group_id = H5Gopen( file_id, "/g15/g1/g2/g3"))<0) goto out; + /* Mount second file under "/g13/g1" in the first file */ + if (H5Fmount(file_id, "/g15/g1", file1_id, H5P_DEFAULT)<0) goto out; + + /* Get name */ + if (H5Iget_name( group_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + if (H5Funmount(file_id, "/g15/g1")<0) goto out; + + /* Get name */ + if (H5Iget_name( group_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "/g15/g1/g2/g3" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Fclose( file1_id ); + + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with a defined type dataset + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with a defined type dataset"); + + /* Create a datatype */ + if ((type_id = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)))<0) goto out; + + /* Insert fields */ + if (H5Tinsert (type_id, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT)<0) goto out; + if (H5Tinsert (type_id, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT)<0) goto out; + if (H5Tinsert (type_id, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT)<0) goto out; + + /* Create group "g17" */ + if ((group_id = H5Gcreate( file_id, "g17", 0 ))<0) goto out; + + /* Save datatype for later */ + if (H5Tcommit (group_id, "t", type_id)<0) goto out; + + /* Create a data space */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + + /* Create a new dataset */ + if ((dataset_id = H5Dcreate( group_id , "d", type_id, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Tclose( type_id ); + H5Sclose( space_id ); + H5Gclose( group_id ); + + /* Open the named datatype */ + if((type_id=H5Topen(file_id, "/g17/t"))<0) goto out; + + /* Get name */ + if (H5Iget_name( type_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g17/t" )!=0) + goto out; + + /* Close datatype */ + H5Tclose(type_id); + + /* Reopen the dataset */ + if ((dataset_id = H5Dopen( file_id, "/g17/d"))<0) goto out; + + /* Get datatype*/ + if((type_id=H5Dget_type(dataset_id))<0) goto out; + + + /* Get name */ + if (H5Iget_name( type_id, name, size )< 0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Tclose( type_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with different files, test1 + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with different files"); + + /* Create a new file using default properties. */ + if ((file2_id = H5Fcreate( FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + +/* Create a new file using default properties. */ + if ((file3_id = H5Fcreate( FILE3, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + + /* Create the data space */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + + /* Create a new dataset */ + if ((dataset_id = H5Dcreate( file2_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Create a new dataset */ + if ((dataset2_id = H5Dcreate( file3_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Delete */ + if (H5Gunlink( file2_id, "/d")<0) + goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( dataset2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/d" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Dclose( dataset2_id ); + H5Sclose( space_id ); + H5Fclose( file2_id ); + H5Fclose( file3_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with different files, test2 + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with different files"); + + /* Create a new file using default properties. */ + if ((file2_id = H5Fcreate( FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + +/* Create a new file using default properties. */ + if ((file3_id = H5Fcreate( FILE3, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + + /* Create the data space */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + + /* Create a new dataset */ + if ((dataset_id = H5Dcreate( file2_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Create a new dataset */ + if ((dataset2_id = H5Dcreate( file3_id , "d", H5T_NATIVE_INT, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Delete */ + if (H5Gunlink( file3_id, "/d")<0) + goto out; + + /* Get name */ + if (H5Iget_name( dataset_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/d" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( dataset2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Dclose( dataset2_id ); + H5Sclose( space_id ); + H5Fclose( file2_id ); + H5Fclose( file3_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with a small buffer for name + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with a small buffer for name"); + + /* Reopen the group */ + if ((group_id = H5Gopen( file_id, "/g15" ))<0) goto out; + + /* Get name */ + name_len=H5Iget_name( group_id, name2, size2 ); + + if ( name_len > size2 ) + /* Get name with a larger buffer */ + name_len=H5Iget_name( group_id, name, size ); + + /* Verify */ + if (check_name( name, "/g15" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + + PASSED(); + + + /*------------------------------------------------------------------------- + * Test H5Iget_name with a dynamic buffer for name + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with a dynamic buffer for name"); + + /* Reopen the group */ + if ((group_id = H5Gopen( file_id, "/g15" ))<0) goto out; + + /* Get name */ + name_len=H5Iget_name( group_id, NULL, size ); + + /* Include the extra null character */ + name3 = malloc(name_len+1); + + /* Get name */ + if (H5Iget_name( group_id, name3, name_len+1 )<0) goto out; + + /* Verify */ + if (check_name( name3, "/g15" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group_id, name3, 3 )<0) goto out; + + /* Verify */ + if (check_name( name3, "/g" )!=0) + goto out; + + if ( name3 ) + free(name3); + + + /* Close */ + H5Gclose( group_id ); + + PASSED(); + + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with invalid IDs + *------------------------------------------------------------------------- + */ + + + TESTING("H5Iget_name with invalid IDs"); + + /* Create a data space */ + if ((space_id = H5Screate_simple( 1, dims, NULL ))<0) goto out; + + /* Define a datatype */ + if ((type_id = H5Tcopy(H5T_NATIVE_INT))<0) goto out; + + /* Create a new dataset */ + if ((dataset_id = H5Dcreate( file_id , "d2", type_id, space_id, + H5P_DEFAULT ))<0) goto out; + + /* Get name for non commited datatype, it should fail */ + if (H5Iget_name( type_id, name, size ) >0) goto out; + + /* Get name for data space, it should fail */ + if (H5Iget_name( space_id, name, size ) >0) goto out; + + /* Close */ + H5Dclose( dataset_id ); + H5Sclose( space_id ); + H5Tclose( type_id ); + + PASSED(); + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with added names with mounting + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with added names with mounting"); + + /* Create a group "g18/g2" in the first file */ + if ((group_id = H5Gcreate( file_id, "/g18", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g18/g2", 0 ))<0) goto out; + + /* Create second file and group "/g3/g4/g5" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if ((group3_id = H5Gcreate( file1_id, "/g3", 0 ))<0) goto out; + if ((group4_id = H5Gcreate( file1_id, "/g3/g4", 0 ))<0) goto out; + if ((group5_id = H5Gcreate( file1_id, "/g3/g4/g5", 0 ))<0) goto out; + + /* Mount first file at "g3/g4" in the second file */ + if (H5Fmount(file1_id, "/g3/g4", file_id, H5P_DEFAULT)<0) goto out; + + /* Get name for the ID of the first file, should be "/g19/g2" still */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g18/g2" )!=0) + goto out; + + /* Open the mounted group */ + if ((group6_id = H5Gopen( file_id, "/g3/g4/g18/g2" ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group6_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g3/g4/g18/g2" )!=0) + goto out; + + /* Unmount */ + if (H5Funmount(file1_id, "/g3/g4")<0) goto out; + + /* Get name for the ID of the first file, should be "/g18/g2" still */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g18/g2" )!=0) + goto out; + + /* Get name for the ID of the secondt file, should be "" */ + if (H5Iget_name( group6_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + H5Gclose( group4_id ); + H5Gclose( group5_id ); + H5Gclose( group6_id ); + H5Fclose( file1_id ); + + PASSED(); + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Fclose + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Fclose"); + + /* Create a file and group "/g1/g2" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if ((group_id = H5Gcreate( file1_id, "/g1", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file1_id, "/g1/g2", 0 ))<0) goto out; + + /* Get name for the ID */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/g2" )!=0) + goto out; + + /* Close file */ + H5Fclose( file1_id ); + + /* Get name for the ID */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + + PASSED(); + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Fmount and H5Gunlink + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Fmount and H5Gunlink"); + + /* Create a file and group "/g1/g2" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if ((group_id = H5Gcreate( file1_id, "/g1", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file1_id, "/g1/g2", 0 ))<0) goto out; + + /* Create a new file and group "/g3/g4" in it */ + if ((file2_id = H5Fcreate( FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + if ((group3_id = H5Gcreate( file2_id, "/g3", 0 ))<0) goto out; + if ((group4_id = H5Gcreate( file2_id, "/g3/g4", 0 ))<0) goto out; + + /* Mount first file at "g3/g4" in the second file */ + if(H5Fmount(file2_id, "/g3/g4", file1_id, H5P_DEFAULT)<0) goto out; + + /* Open the mounted group */ + if ((group5_id = H5Gopen( file2_id, "/g3/g4/g1/g2" ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group5_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g3/g4/g1/g2" )!=0) + goto out; + + /* Delete */ + if (H5Gunlink( file1_id, "/g3/g4/g1/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + H5Gclose( group4_id ); + H5Gclose( group5_id ); + H5Fclose( file1_id ); + H5Fclose( file2_id ); + + PASSED(); + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Fmount and H5Gmove + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Fmount and H5Gmove"); + + /* Create a file and group "/g1/g2" in it */ + file1_id = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if ((group_id = H5Gcreate( file1_id, "/g1", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file1_id, "/g1/g2", 0 ))<0) goto out; + + /* Create a new file and group "/g3/g4" in it */ + if ((file2_id = H5Fcreate( FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT ))<0) goto out; + if ((group3_id = H5Gcreate( file2_id, "/g3", 0 ))<0) goto out; + if ((group4_id = H5Gcreate( file2_id, "/g3/g4", 0 ))<0) goto out; + + + /* Mount first file at "g3/g4" in the second file */ + if(H5Fmount(file2_id, "/g3/g4", file1_id, H5P_DEFAULT)<0) goto out; + + /* Open the mounted group */ + if ((group5_id = H5Gopen( file2_id, "/g3/g4/g1/g2" ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group5_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g3/g4/g1/g2" )!=0) + goto out; + + /* Rename group */ + if (H5Gmove( file2_id, "/g3/g4/g1/g2", "/g3/g4/g1/g5" )<0) goto out; + + /* Get name */ + if (H5Iget_name( group5_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g3/g4/g1/g5" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g1/g5" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + H5Gclose( group4_id ); + H5Gclose( group5_id ); + H5Fclose( file1_id ); + H5Fclose( file2_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Glink hard + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Glink hard"); + + /* Create group "g19/g1" */ + if ((group_id = H5Gcreate( file_id, "/g19", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g19/g1", 0 ))<0) goto out; + + /* Create hard link to "g19/g1/ group */ + if (H5Glink(file_id, H5G_LINK_HARD, "/g19/g1", "/g19/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g19/g1" )!=0) + goto out; + + /* Open the group */ + if ((group3_id = H5Gopen( file_id, "/g19/g2" ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g19/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Glink symbolic + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Glink symbolic"); + + /* Create group "g20/g1" */ + if ((group_id = H5Gcreate( file_id, "/g20", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g20/g1", 0 ))<0) goto out; + + /* Create symbolic link to "g20/g1/ group */ + if (H5Glink(file_id, H5G_LINK_SOFT, "/g20/g1", "/g20/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g20/g1" )!=0) + goto out; + + /* Open the group */ + if ((group3_id = H5Gopen( file_id, "/g20/g2" ))<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g20/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Glink symbolic and move target + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Glink symbolic and move target"); + + /* Create group "g21/g1" */ + if ((group_id = H5Gcreate( file_id, "/g21", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g21/g1", 0 ))<0) goto out; + + /* Create symbolic link to "g21/g1/ group */ + if (H5Glink(file_id, H5G_LINK_SOFT, "/g21/g1", "/g21/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g21/g1" )!=0) + goto out; + + /* Open the group */ + if ((group3_id = H5Gopen( file_id, "/g21/g2" ))<0) goto out; + + /* Rename group */ + if (H5Gmove( file_id, "/g21/g1", "/g21/g3" )<0) goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g21/g3" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g21/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Glink symbolic and move source + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Glink symbolic and move source"); + + /* Create group "g22/g1" */ + if ((group_id = H5Gcreate( file_id, "/g22", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g22/g1", 0 ))<0) goto out; + + /* Create symbolic link to "g22/g1/ group */ + if (H5Glink(file_id, H5G_LINK_SOFT, "/g22/g1", "/g22/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g22/g1" )!=0) + goto out; + + /* Open the group */ + if ((group3_id = H5Gopen( file_id, "/g22/g2" ))<0) goto out; + + /* Rename group */ + if (H5Gmove( file_id, "/g22/g2", "/g22/g3" )<0) goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g22/g1" )!=0) + goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g22/g3" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + + + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Glink symbolic and unlink target + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Glink symbolic and unlink target"); + + /* Create group "g23/g1" */ + if ((group_id = H5Gcreate( file_id, "/g23", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g23/g1", 0 ))<0) goto out; + + /* Create symbolic link to "g23/g1/ group */ + if (H5Glink(file_id, H5G_LINK_SOFT, "/g23/g1", "/g23/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g23/g1" )!=0) + goto out; + + /* Open the group */ + if ((group3_id = H5Gopen( file_id, "/g23/g2" ))<0) goto out; + + /* Delete group */ + if (H5Gunlink( file_id, "/g23/g1")<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g23/g2" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + +/*------------------------------------------------------------------------- + * Test H5Iget_name with H5Glink symbolic and unlink source + *------------------------------------------------------------------------- + */ + + TESTING("H5Iget_name with H5Glink symbolic and unlink source"); + + /* Create group "g24/g1" */ + if ((group_id = H5Gcreate( file_id, "/g24", 0 ))<0) goto out; + if ((group2_id = H5Gcreate( file_id, "/g24/g1", 0 ))<0) goto out; + + /* Create symbolic link to "g24/g1/ group */ + if (H5Glink(file_id, H5G_LINK_SOFT, "/g24/g1", "/g24/g2")<0) + goto out; + + /* Get name */ + if (H5Iget_name( group2_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "/g24/g1" )!=0) + goto out; + + /* Open the group */ + if ((group3_id = H5Gopen( file_id, "/g24/g2" ))<0) goto out; + + /* Delete group */ + if (H5Gunlink( file_id, "/g24/g2")<0) goto out; + + /* Get name */ + if (H5Iget_name( group3_id, name, size )<0) goto out; + + /* Verify */ + if (check_name( name, "" )!=0) + goto out; + + /* Close */ + H5Gclose( group_id ); + H5Gclose( group2_id ); + H5Gclose( group3_id ); + + PASSED(); + + +/*------------------------------------------------------------------------- + * end tests + *------------------------------------------------------------------------- + */ + + + + /* Close file */ + H5Fclose( file_id ); + return 0; + +out: + H5Fclose( file_id ); + H5_FAILED(); + return 1; } -- cgit v0.12