diff options
author | Jonathan Kim <jkm@hdfgroup.org> | 2010-04-22 18:43:19 (GMT) |
---|---|---|
committer | Jonathan Kim <jkm@hdfgroup.org> | 2010-04-22 18:43:19 (GMT) |
commit | cacfe71beb159fc44df256f641d4faac594c802e (patch) | |
tree | e550a119d88414f2188a5af68edc08bf44b642b8 /tools/lib | |
parent | 8881ff748cc1cc6055f9e89f4a27c2c7883a5dfa (diff) | |
download | hdf5-cacfe71beb159fc44df256f641d4faac594c802e.zip hdf5-cacfe71beb159fc44df256f641d4faac594c802e.tar.gz hdf5-cacfe71beb159fc44df256f641d4faac594c802e.tar.bz2 |
[svn-r18615] Purpose:
Fix for bug 1817 : h5copy fail to copy dangling link by specifying
link path directly
Description:
Merged from hdf5 trunk r18614.
Tested:
jam, amani
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5diff.c | 145 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 132 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.h | 31 |
3 files changed, 163 insertions, 145 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 9e753fe..5f18ab3 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -20,28 +20,6 @@ #include "h5tools.h" #include "h5tools_utils.h" -/* This code is layout for common code among tools */ -typedef enum toolname_t { - TOOL_H5DIFF, TOOL_H5LS, TOOL__H5DUMP /* add as necessary */ -} h5tool_toolname_t; -/* this struct can be used to differntiate among tools if necessary */ -typedef struct { - h5tool_toolname_t toolname; - int msg_mode; -} h5tool_opt_t; - -/* To return link info - * Functions: - * H5tools_get_link_info() - * Note: this may be move to h5tools code if used by other tools - */ -typedef struct { - H5O_type_t trg_type; /* OUT: target type */ - const char *trg_path; /* OUT: target obj path. This must be freed - * when used with H5tools_get_link_info() */ - H5L_info_t linfo; /* OUT: link info */ - h5tool_opt_t opt; /* IN: options */ -} h5tool_link_info_t; /* * Debug printf macros. The prefix allows output filtering by test scripts. */ @@ -254,129 +232,6 @@ out: } -/*------------------------------------------------------------------------- - * Function: H5tools_get_link_info - * - * Purpose: Get link (soft, external) info and its target object type - (dataset, group, named datatype) and path, if exist - * - * Patameters: - * - [IN] fileid : link file id - * - [IN] linkpath : link path - * - [OUT] h5li : link's info (H5L_info_t) - * - [OUT] link_info: returning target object info (h5tool_link_info_t) - * - * Return: - * 1 : Succed to get link info. - * 0 : Detected as a dangling link - * -1 : H5 API failed. - * - * NOTE: - * link_info->trg_path must be freed out of this function - * - * Programmer: Jonathan Kim - * - * Date: Feb 8, 2010 - *-------------------------------------------------------------------------*/ -static int H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info) -{ - int Ret = -1; /* init to fail */ - htri_t l_ret; - H5O_info_t trg_oinfo; - hid_t fapl; - hid_t lapl = H5P_DEFAULT; - - /* init */ - link_info->trg_type = H5O_TYPE_UNKNOWN; - - /* check if link itself exist */ - if((H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0)) - { - if(link_info->opt.msg_mode==1) - parallel_print("Warning: link <%s> doesn't exist \n",linkpath); - goto out; - } - - /* get info from link */ - if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0) - { - if(link_info->opt.msg_mode==1) - parallel_print("Warning: unable to get link info from <%s>\n",linkpath); - goto out; - } - - /* trg_path must be freed out of this function when finished using */ - link_info->trg_path = (char*)HDcalloc(link_info->linfo.u.val_size, sizeof(char)); - HDassert(link_info->trg_path); - - /* get link value */ - if(H5Lget_val(file_id, linkpath, link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) - { - if(link_info->opt.msg_mode==1) - parallel_print("Warning: unable to get link value from <%s>\n",linkpath); - goto out; - } - - /*----------------------------------------------------- - * if link type is external link use different lapl to - * follow object in other file - */ - if (link_info->linfo.type == H5L_TYPE_EXTERNAL) - { - fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_sec2(fapl); - lapl = H5Pcreate(H5P_LINK_ACCESS); - H5Pset_elink_fapl(lapl, fapl); - } - - /*-------------------------------------------------------------- - * if link's target object exist, get type - */ - /* check if target object exist */ - l_ret = H5Oexists_by_name(file_id, linkpath, lapl); - - /* detect dangling link */ - if(l_ret == FALSE) - { - Ret = 0; - goto out; - } - /* function failed */ - else if (l_ret < 0) - { - goto out; - } - - /* get target object info */ - if(H5Oget_info_by_name(file_id, linkpath, &trg_oinfo, lapl) < 0) - { - if(link_info->opt.msg_mode==1) - parallel_print("Warning: unable to get object information for <%s>\n", linkpath); - goto out; - } - - /* check unknown type */ - if (trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES) - { - if(link_info->opt.msg_mode==1) - parallel_print("Warning: target object of <%s> is unknown type\n", linkpath); - goto out; - } - - /* set target obj type to return */ - link_info->trg_type = trg_oinfo.type; - - /* succeed */ - Ret = 1; -out: - if (link_info->linfo.type == H5L_TYPE_EXTERNAL) - { - H5Pclose(fapl); - H5Pclose(lapl); - } - - return Ret; -} /*------------------------------------------------------------------------- * Function: h5diff diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index c5bc761..a51a286 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -626,3 +626,135 @@ tmpfile(void) } #endif + +/*------------------------------------------------------------------------- + * Function: H5tools_get_link_info + * + * Purpose: Get link (soft, external) info and its target object type + (dataset, group, named datatype) and path, if exist + * + * Patameters: + * - [IN] fileid : link file id + * - [IN] linkpath : link path + * - [OUT] h5li : link's info (H5L_info_t) + * - [OUT] link_info: returning target object info (h5tool_link_info_t) + * + * Return: + * 2 : given pathname is object + * 1 : Succed to get link info. + * 0 : Detected as a dangling link + * -1 : H5 API failed. + * + * NOTE: + * link_info->trg_path must be freed out of this function + * + * Programmer: Jonathan Kim + * + * Date: Feb 8, 2010 + *-------------------------------------------------------------------------*/ +int H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info) +{ + int Ret = -1; /* init to fail */ + htri_t l_ret; + H5O_info_t trg_oinfo; + hid_t fapl; + hid_t lapl = H5P_DEFAULT; + + /* init */ + link_info->trg_type = H5O_TYPE_UNKNOWN; + + /* check if link itself exist */ + if((H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0)) + { + if(link_info->opt.msg_mode==1) + parallel_print("Warning: link <%s> doesn't exist \n",linkpath); + goto out; + } + + /* get info from link */ + if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0) + { + if(link_info->opt.msg_mode==1) + parallel_print("Warning: unable to get link info from <%s>\n",linkpath); + goto out; + } + + /* given path is hard link (object) */ + if (link_info->linfo.type == H5L_TYPE_HARD) + { + Ret = 2; + goto out; + } + + /* trg_path must be freed out of this function when finished using */ + link_info->trg_path = (char*)HDcalloc(link_info->linfo.u.val_size, sizeof(char)); + HDassert(link_info->trg_path); + + /* get link value */ + if(H5Lget_val(file_id, linkpath, link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) + { + if(link_info->opt.msg_mode==1) + parallel_print("Warning: unable to get link value from <%s>\n",linkpath); + goto out; + } + + /*----------------------------------------------------- + * if link type is external link use different lapl to + * follow object in other file + */ + if (link_info->linfo.type == H5L_TYPE_EXTERNAL) + { + fapl = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_sec2(fapl); + lapl = H5Pcreate(H5P_LINK_ACCESS); + H5Pset_elink_fapl(lapl, fapl); + } + + /*-------------------------------------------------------------- + * if link's target object exist, get type + */ + /* check if target object exist */ + l_ret = H5Oexists_by_name(file_id, linkpath, lapl); + + /* detect dangling link */ + if(l_ret == FALSE) + { + Ret = 0; + goto out; + } + /* function failed */ + else if (l_ret < 0) + { + goto out; + } + + /* get target object info */ + if(H5Oget_info_by_name(file_id, linkpath, &trg_oinfo, lapl) < 0) + { + if(link_info->opt.msg_mode==1) + parallel_print("Warning: unable to get object information for <%s>\n", linkpath); + goto out; + } + + /* check unknown type */ + if (trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES) + { + if(link_info->opt.msg_mode==1) + parallel_print("Warning: target object of <%s> is unknown type\n", linkpath); + goto out; + } + + /* set target obj type to return */ + link_info->trg_type = trg_oinfo.type; + + /* succeed */ + Ret = 1; +out: + if (link_info->linfo.type == H5L_TYPE_EXTERNAL) + { + H5Pclose(fapl); + H5Pclose(lapl); + } + + return Ret; +} diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index e7b175c..dcd8f2b 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -119,4 +119,35 @@ extern obj_t *search_obj(table_t *temp, haddr_t objno); extern FILE * tmpfile(void); #endif + +/************************************************************* + * + * candidate functions to be public + * + *************************************************************/ + +/* This code is layout for common code among tools */ +typedef enum toolname_t { + TOOL_H5DIFF, TOOL_H5LS, TOOL__H5DUMP /* add as necessary */ +} h5tool_toolname_t; + +/* this struct can be used to differntiate among tools */ +typedef struct { + h5tool_toolname_t toolname; + int msg_mode; +} h5tool_opt_t; + +/* obtain link info from H5tools_get_link_info() */ +typedef struct { + H5O_type_t trg_type; /* OUT: target type */ + const char *trg_path; /* OUT: target obj path. This must be freed + * when used with H5tools_get_link_info() */ + H5L_info_t linfo; /* OUT: link info */ + h5tool_opt_t opt; /* IN: options */ +} h5tool_link_info_t; + + +/* Definitions of routines */ +extern int H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info); + #endif /* H5TOOLS_UTILS_H__ */ |