diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2003-12-18 16:18:09 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2003-12-18 16:18:09 (GMT) |
commit | 8f65e4252d4f8eea059fcdbe5efc14546175c864 (patch) | |
tree | ade9d7df10060156d25aa6a5d0e5c6581eaf8cbc /tools/lib | |
parent | 1f0ca5b200c1e20050265d40d26f9bc29333fb74 (diff) | |
download | hdf5-8f65e4252d4f8eea059fcdbe5efc14546175c864.zip hdf5-8f65e4252d4f8eea059fcdbe5efc14546175c864.tar.gz hdf5-8f65e4252d4f8eea059fcdbe5efc14546175c864.tar.bz2 |
[svn-r7969] Purpose:
h5repack new features
Description:
addded the copy routines for hard links
changed the traversal structure to store information about the hard links
added tests
Solution:
Platforms tested:
linux
solaris
IRIX
Misc. update:
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5diff.c | 6 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 133 | ||||
-rw-r--r-- | tools/lib/h5trav.h | 29 | ||||
-rw-r--r-- | tools/lib/h5trav_table.c | 76 |
4 files changed, 195 insertions, 49 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 3b59b0e..eeabd8c 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -239,7 +239,7 @@ int diff_match( hid_t file1_id, { c1 = (table->objs[i].flags[0]) ? 'x' : ' '; c2 = (table->objs[i].flags[1]) ? 'x' : ' '; - printf("%5c %6c %-15s\n", c1, c2, table->objs[i].objname); + printf("%5c %6c %-15s\n", c1, c2, table->objs[i].name); } printf("\n"); } @@ -254,9 +254,9 @@ int diff_match( hid_t file1_id, { if ( table->objs[i].flags[0] && table->objs[i].flags[1] ) nfound+=diff( file1_id, - table->objs[i].objname, + table->objs[i].name, file2_id, - table->objs[i].objname, + table->objs[i].name, options, table->objs[i].type ); } diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index fc64fc7..e065e28 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -25,7 +25,7 @@ int traverse( hid_t loc_id, trav_info_t *info, int *idx ); -herr_t get_nobjects( hid_t loc_id, +herr_t get_nnames( hid_t loc_id, const char *group_name ); herr_t get_name_type( hid_t loc_id, @@ -40,7 +40,7 @@ herr_t get_name_type( hid_t loc_id, * Purpose: get an array of "trav_info_t" , containing the name and type of * objects in the file * - * Return: number of objects in file + * Return: number of object names in file * * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * @@ -53,19 +53,46 @@ int h5trav_getinfo( hid_t file_id, trav_info_t *info ) { trav_table_t *table=NULL; - int nobjects=0; + int nnames=0; /* init table */ trav_table_init( &table ); /* iterate starting on the root group */ - if (( nobjects = traverse( file_id, "/", table, info, &nobjects )) < 0 ) + if (( nnames = traverse( file_id, "/", table, info, &nnames )) < 0 ) return -1; /* free table */ trav_table_free( table ); - return nobjects; + return nnames; + +} + + +/*------------------------------------------------------------------------- + * Function: h5trav_gettable + * + * Purpose: get the trav_table_t struct + * + * Return: 0, -1 on error + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: December 17, 2003 + * + *------------------------------------------------------------------------- + */ + +int h5trav_gettable(hid_t fid, trav_table_t *travt) +{ + int nnames=0; + + /* iterate starting on the root group */ + if (( nnames = traverse(fid,"/",travt,NULL,&nnames))<0) + return -1; + + return 0; } @@ -131,7 +158,7 @@ void h5trav_freeinfo( trav_info_t *info, int nobjs ) /*------------------------------------------------------------------------- - * Function: count_objects + * Function: count_names * * Purpose: operator function * @@ -146,7 +173,7 @@ void h5trav_freeinfo( trav_info_t *info, int nobjs ) *------------------------------------------------------------------------- */ -static herr_t count_objects( hid_t loc_id, const char *name, void *op_data) +static herr_t count_names( hid_t loc_id, const char *name, void *op_data) { H5G_stat_t statbuf; @@ -161,9 +188,9 @@ static herr_t count_objects( hid_t loc_id, const char *name, void *op_data) } /*------------------------------------------------------------------------- - * Function: get_nobjects + * Function: get_nnames * - * Purpose: Counts the number of objects in the group GROUP_NAME + * Purpose: Counts the number of names in the group GROUP_NAME * * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * @@ -181,12 +208,12 @@ static herr_t count_objects( hid_t loc_id, const char *name, void *op_data) *------------------------------------------------------------------------- */ -herr_t get_nobjects( hid_t loc_id, const char *group_name ) +herr_t get_nnames( hid_t loc_id, const char *group_name ) { int nobjs = 0; - if ( H5Giterate( loc_id, group_name, NULL, count_objects, (void *)&nobjs ) < 0 ) + if ( H5Giterate( loc_id, group_name, NULL, count_names, (void *)&nobjs ) < 0 ) return -1; return nobjs; @@ -287,17 +314,18 @@ int traverse( hid_t loc_id, char *name=NULL; H5G_obj_t type; - int nobjs; - int i; + int n_names; char *path=NULL; H5G_stat_t statbuf; int inserted_objs=0; - int j; + int i, j; + - if (( nobjs = get_nobjects( loc_id, group_name )) < 0 ) + /* get the number of names */ + if (( n_names = get_nnames( loc_id, group_name )) < 0 ) return -1; - for ( i = 0; i < nobjs; i++) + for ( i = 0; i < n_names; i++) { if (get_name_type( loc_id, group_name, i, &name, &type ) < 0 ) @@ -365,8 +393,9 @@ int traverse( hid_t loc_id, else { #if defined (H5_TRAV_DEBUG) - printf("%s %s\n", "HARDLINK", table->objs[j].objname); + printf("<%s> HARDLINK to <%s>\n", path, table->objs[j].name); #endif + trav_table_addlink(table,j,path); } } @@ -404,11 +433,11 @@ int traverse( hid_t loc_id, else { #if defined (H5_TRAV_DEBUG) - printf("%s %s\n", "HARDLINK", table->objs[j].objname); + printf("<%s> HARDLINK to <%s>\n", path, table->objs[j].name); #endif - } - - } + trav_table_addlink(table,j,path); + } /* displayed==1 */ + } /* nlink>1 */ break; @@ -442,7 +471,10 @@ int traverse( hid_t loc_id, /* increment */ inserted_objs++; - + + /* add object to table */ + trav_table_add(statbuf.objno, path, H5G_LINK, table ); + break; @@ -471,9 +503,9 @@ int traverse( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: diff_list + * Function: h5trav_printinfo * - * Purpose: print list of objects in file + * Purpose: print list of names in file * * Return: void * @@ -481,10 +513,6 @@ int traverse( hid_t loc_id, * * Date: May 9, 2003 * - * Comments: - * - * Modifications: - * *------------------------------------------------------------------------- */ void h5trav_printinfo(int nobjs, trav_info_t *travi) @@ -515,3 +543,52 @@ void h5trav_printinfo(int nobjs, trav_info_t *travi) +/*------------------------------------------------------------------------- + * Function: h5trav_printtable + * + * Purpose: print list of objects in file + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +void h5trav_printtable(trav_table_t *table) +{ + int i, j; + + for ( i = 0; i < table->nobjs; i++) + { + switch ( table->objs[i].type ) + { + case H5G_GROUP: + printf(" %-10s %s\n", "group", table->objs[i].name ); + break; + case H5G_DATASET: + printf(" %-10s %s\n", "dataset", table->objs[i].name ); + break; + case H5G_TYPE: + printf(" %-10s %s\n", "datatype", table->objs[i].name ); + break; + case H5G_LINK: + printf(" %-10s %s\n", "link", table->objs[i].name ); + break; + default: + printf(" %-10s %s\n", "User defined object", table->objs[i].name ); + break; + } + + if (table->objs[i].nlinks) + { + for ( j=0; j<table->objs[i].nlinks; j++) + { + printf(" %-10s %s\n", " hardlink", table->objs[i].links[j] ); + } + } + + } +} + diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h index 1f826bb..cedbc54 100644 --- a/tools/lib/h5trav.h +++ b/tools/lib/h5trav.h @@ -40,16 +40,28 @@ typedef struct trav_info_t { /*------------------------------------------------------------------------- + * keep record of hard link information + *------------------------------------------------------------------------- + */ +typedef struct trav_link_t { + char *new_name; +} trav_link_t; + + +/*------------------------------------------------------------------------- * struct to store basic info needed for the h5trav table traversal algorythm *------------------------------------------------------------------------- */ typedef struct trav_obj_t { - haddr_t objno; - unsigned flags[2]; - char *objname; - int displayed; - H5G_obj_t type; + haddr_t objno; /* object number from H5Gget_objinfo */ + unsigned flags[2]; /* h5diff.object is present or not in both files*/ + char *name; /* name */ + int displayed; /* hard link already traversed once */ + H5G_obj_t type; /* type of object */ + trav_link_t *links; /* array of possible link names */ + int sizelinks; /* size of links array */ + int nlinks; /* number of links */ } trav_obj_t; @@ -78,7 +90,7 @@ int h5trav_getinfo( hid_t file_id, trav_info_t *info ); int h5trav_getindex( const char *obj, int nobjs, trav_info_t *info ); void h5trav_freeinfo( trav_info_t *info, int nobjs ); void h5trav_printinfo(int nobjs, trav_info_t *info); - +int h5trav_gettable(hid_t fid, trav_table_t *travt); #ifdef __cplusplus @@ -107,6 +119,11 @@ void trav_table_addflags(unsigned *flags, H5G_obj_t type, trav_table_t *table); +void h5trav_printtable(trav_table_t *table); + +void trav_table_addlink(trav_table_t *table, + int j /* the object index */, + char *path ); #endif /* H5TRAV_H__ */ diff --git a/tools/lib/h5trav_table.c b/tools/lib/h5trav_table.c index bbbe2d6..0071559 100644 --- a/tools/lib/h5trav_table.c +++ b/tools/lib/h5trav_table.c @@ -57,7 +57,7 @@ int trav_table_search(haddr_t objno, trav_table_t *table ) */ void trav_table_add(haddr_t objno, - char *objname, + char *name, H5G_obj_t type, trav_table_t *table) { @@ -73,16 +73,21 @@ void trav_table_add(haddr_t objno, table->objs[i].flags[0] = table->objs[i].flags[1] = 0; table->objs[i].displayed = 0; table->objs[i].type = H5G_UNKNOWN; - table->objs[i].objname = NULL; + table->objs[i].name = NULL; + table->objs[i].links = NULL; + table->objs[i].nlinks = 0; + table->objs[i].sizelinks = 0; } } i = table->nobjs++; table->objs[i].objno = objno; table->objs[i].flags[0] = table->objs[i].flags[1] = 0; - HDfree(table->objs[i].objname); - table->objs[i].objname = (char *)HDstrdup(objname); + HDfree(table->objs[i].name); + table->objs[i].name = (char *)HDstrdup(name); table->objs[i].type = type; + table->objs[i].links = NULL; + table->objs[i].nlinks = 0; } @@ -101,7 +106,7 @@ void trav_table_add(haddr_t objno, */ void trav_table_addflags(unsigned *flags, - char *objname, + char *name, H5G_obj_t type, trav_table_t *table) { @@ -117,7 +122,10 @@ void trav_table_addflags(unsigned *flags, table->objs[i].flags[0] = table->objs[i].flags[1] = 0; table->objs[i].displayed = 0; table->objs[i].type = H5G_UNKNOWN; - table->objs[i].objname = NULL; + table->objs[i].name = NULL; + table->objs[i].links = NULL; + table->objs[i].nlinks = 0; + table->objs[i].sizelinks = 0; } } @@ -125,9 +133,11 @@ void trav_table_addflags(unsigned *flags, table->objs[i].objno = 0; table->objs[i].flags[0] = flags[0]; table->objs[i].flags[1] = flags[1]; - HDfree(table->objs[i].objname); - table->objs[i].objname = (char *)HDstrdup(objname); + HDfree(table->objs[i].name); + table->objs[i].name = (char *)HDstrdup(name); table->objs[i].type = type; + table->objs[i].links = NULL; + table->objs[i].nlinks = 0; } @@ -160,7 +170,10 @@ void trav_table_init( trav_table_t **tbl ) table->objs[i].flags[0] = table->objs[i].flags[1] = 0; table->objs[i].displayed = 0; table->objs[i].type = H5G_UNKNOWN; - table->objs[i].objname = NULL; + table->objs[i].name = NULL; + table->objs[i].links = NULL; + table->objs[i].nlinks = 0; + table->objs[i].sizelinks = 0; } *tbl = table; @@ -184,14 +197,53 @@ void trav_table_init( trav_table_t **tbl ) void trav_table_free( trav_table_t *table ) { - int i; + int i, j; for ( i = 0; i < table->nobjs; i++) - HDfree( table->objs[i].objname ); - + { + HDfree( table->objs[i].name ); + if (table->objs[i].nlinks) + { + for ( j=0; j<table->objs[i].nlinks; j++) + HDfree( table->objs[i].links[j].new_name ); + + HDfree(table->objs[i].links); + } + } HDfree(table->objs); HDfree(table); } +/*------------------------------------------------------------------------- + * Function: trav_table_addlink + * + * Purpose: Add a hardlink name to the object + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: December 17, 2003 + * + *------------------------------------------------------------------------- + */ + +void trav_table_addlink(trav_table_t *table, + int j /* the object index */, + char *path ) +{ + int k; + /* store the link information */ + if (table->objs[j].nlinks == table->objs[j].sizelinks) { + table->objs[j].sizelinks += 2; + table->objs[j].links = + (trav_link_t*)HDrealloc(table->objs[j].links, + table->objs[j].sizelinks * sizeof(trav_link_t)); + } + k = table->objs[j].nlinks++; + table->objs[j].links[k].new_name = (char*)HDstrdup(path); +} + + |