1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 #ifndef H5TRAV_H__
15 #define H5TRAV_H__
16 
17 #include "hdf5.h"
18 
19 /* Typedefs for visiting objects */
20 typedef herr_t (*h5trav_obj_func_t)(const char *path_name, const H5O_info_t *oinfo,
21         const char *first_seen, void *udata);
22 typedef herr_t (*h5trav_lnk_func_t)(const char *path_name, const H5L_info_t *linfo,
23         void *udata);
24 
25 /*-------------------------------------------------------------------------
26  * public enum to specify type of an object
27  * the TYPE can be:
28  *    H5TRAV_TYPE_UNKNOWN = -1,
29  *    H5TRAV_TYPE_GROUP,            Object is a group
30  *    H5TRAV_TYPE_DATASET,          Object is a dataset
31  *    H5TRAV_TYPE_TYPE,             Object is a named datatype
32  *    H5TRAV_TYPE_LINK,             Object is a symbolic link
33  *    H5TRAV_TYPE_UDLINK,           Object is a user-defined link
34  *-------------------------------------------------------------------------
35  */
36 typedef enum {
37     H5TRAV_TYPE_UNKNOWN = -1,        /* Unknown object type */
38     H5TRAV_TYPE_GROUP,          /* Object is a group */
39     H5TRAV_TYPE_DATASET,        /* Object is a dataset */
40     H5TRAV_TYPE_NAMED_DATATYPE, /* Object is a named datatype */
41     H5TRAV_TYPE_LINK,           /* Object is a symbolic link */
42     H5TRAV_TYPE_UDLINK          /* Object is a user-defined link */
43 } h5trav_type_t;
44 
45 /*-------------------------------------------------------------------------
46  * public struct to store name and type of an object
47  *-------------------------------------------------------------------------
48  */
49 /* Struct to keep track of symbolic link targets visited.
50  * Functions: symlink_visit_add() and symlink_is_visited()
51  */
52 typedef struct symlink_trav_path_t {
53     H5L_type_t  type;
54     char *file;
55     char *path;
56 } symlink_trav_path_t;
57 
58 typedef struct symlink_trav_t {
59     size_t      nalloc;
60     size_t      nused;
61     symlink_trav_path_t *objs;
62     hbool_t dangle_link;
63 } symlink_trav_t;
64 
65 typedef struct trav_path_t {
66     char      *path;
67     h5trav_type_t type;
68     haddr_t     objno;     /* object address */
69     unsigned long 	fileno; /* File number that object is located in */
70 } trav_path_t;
71 
72 typedef struct trav_info_t {
73     size_t      nalloc;
74     size_t      nused;
75     const char *fname;
76     hid_t fid;                          /* File ID */
77     trav_path_t *paths;
78     symlink_trav_t symlink_visited;     /* already visited symbolic links */
79     void * opts;                        /* optional data passing */
80 } trav_info_t;
81 
82 
83 /*-------------------------------------------------------------------------
84  * keep record of hard link information
85  *-------------------------------------------------------------------------
86  */
87 typedef struct trav_link_t {
88     char      *new_name;
89 } trav_link_t;
90 
91 
92 /*-------------------------------------------------------------------------
93  * struct to store basic info needed for the h5trav table traversal algorythm
94  *-------------------------------------------------------------------------
95  */
96 
97 typedef struct trav_obj_t {
98     haddr_t     objno;     /* object address */
99     unsigned    flags[2];  /* h5diff.object is present or not in both files*/
100     hbool_t     is_same_trgobj; /* same target object? no need to compare */
101     char        *name;     /* name */
102     h5trav_type_t type;    /* type of object */
103     trav_link_t *links;    /* array of possible link names */
104     size_t      sizelinks; /* size of links array */
105     size_t      nlinks;    /* number of links */
106 } trav_obj_t;
107 
108 
109 /*-------------------------------------------------------------------------
110  * private struct that stores all objects
111  *-------------------------------------------------------------------------
112  */
113 
114 typedef struct trav_table_t {
115     size_t      size;
116     size_t      nobjs;
117     trav_obj_t *objs;
118 } trav_table_t;
119 
120 
121 /*-------------------------------------------------------------------------
122  * public functions
123  *-------------------------------------------------------------------------
124  */
125 
126 #ifdef __cplusplus
127 extern "C" {
128 #endif
129 
130 /*-------------------------------------------------------------------------
131  * "h5trav general" public functions
132  *-------------------------------------------------------------------------
133  */
134 H5TOOLS_DLL void h5trav_set_index(H5_index_t print_index_by, H5_iter_order_t print_index_order);
135 H5TOOLS_DLL int h5trav_visit(hid_t file_id, const char *grp_name,
136     hbool_t visit_start, hbool_t recurse, h5trav_obj_func_t visit_obj,
137     h5trav_lnk_func_t visit_lnk, void *udata, unsigned fields);
138 H5TOOLS_DLL herr_t symlink_visit_add(symlink_trav_t *visited, H5L_type_t type, const char *file, const char *path);
139 H5TOOLS_DLL hbool_t symlink_is_visited(symlink_trav_t *visited, H5L_type_t type, const char *file, const char *path);
140 
141 /*-------------------------------------------------------------------------
142  * "h5trav info" public functions
143  *-------------------------------------------------------------------------
144  */
145 H5TOOLS_DLL int h5trav_getinfo(hid_t file_id, trav_info_t *info);
146 H5TOOLS_DLL ssize_t h5trav_getindex(const trav_info_t *info, const char *obj);
147 H5TOOLS_DLL int trav_info_visit_obj (const char *path, const H5O_info_t *oinfo, const char *already_visited, void *udata);
148 H5TOOLS_DLL int trav_info_visit_lnk (const char *path, const H5L_info_t *linfo, void *udata);
149 
150 /*-------------------------------------------------------------------------
151  * "h5trav table" public functions
152  *-------------------------------------------------------------------------
153  */
154 
155 H5TOOLS_DLL int  h5trav_gettable(hid_t fid, trav_table_t *travt);
156 H5TOOLS_DLL int  h5trav_getindext(const char *obj, const trav_table_t *travt);
157 
158 /*-------------------------------------------------------------------------
159  * "h5trav print" public functions
160  *-------------------------------------------------------------------------
161  */
162 H5TOOLS_DLL int h5trav_print(hid_t fid);
163 H5TOOLS_DLL void h5trav_set_verbose(int print_verbose);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 /*-------------------------------------------------------------------------
170  * info private functions
171  *-------------------------------------------------------------------------
172  */
173 
174 H5TOOLS_DLL void trav_info_init(const char *filename, hid_t fileid, trav_info_t **info);
175 
176 H5TOOLS_DLL void trav_info_free(trav_info_t *info);
177 
178 H5TOOLS_DLL void trav_info_add(trav_info_t *info, const char *path, h5trav_type_t obj_type);
179 
180 H5TOOLS_DLL void trav_fileinfo_add(trav_info_t *info, hid_t loc_id);
181 
182 /*-------------------------------------------------------------------------
183  * table private functions
184  *-------------------------------------------------------------------------
185  */
186 
187 H5TOOLS_DLL void trav_table_init(trav_table_t **table);
188 
189 H5TOOLS_DLL void trav_table_free(trav_table_t *table);
190 
191 H5TOOLS_DLL void trav_table_addflags(unsigned *flags,
192                          char *objname,
193                          h5trav_type_t type,
194                          trav_table_t *table);
195 
196 #endif  /* H5TRAV_H__ */
197 
198