2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
9 * Copyright (c) 2007, The Storage Networking Industry Association.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * - Neither the name of The Storage Networking Industry Association (SNIA)
23 * nor the names of its contributors may be used to endorse or promote
24 * products derived from this software without specific prior written
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * This file defines macros and constants related to traversing file
42 * system hieratchy in post-order, pre-order and level-order ways.
53 * Library functions for traversing file system hierarchy in
54 * post-order, pre-order and level-order.
56 * This example will be used in the following descriptions.
57 * All alphabetical entries are directory and all the numerical
58 * entries are non-directory entries.
80 * Each traversing function gets an argument of 'struct fs_traverse *'
81 * type. The fields of this structure are explained below.
83 * For each entry while traversing, the callback function is
84 * called and three arguments are passed to it. The argument
85 * specified in the struct fs_traverse, a struct fst_node for the
86 * path and a struct fst_node for the entry.
88 * For the root of the traversing, the fields of struct fst_node
89 * of the entry are all NULL.
91 * If the path to be traversed is not a directory, the callback
92 * function is called on it. The fields of the 'struct fst_node'
93 * argument for entry are all NULL.
97 * Post-order means that the directory is processed after all
98 * its children are processed. Post-order traversing of the above
99 * hierarchy will be like this:
121 * In post-order the callback function returns 0 on success
122 * or non-zero to stop further traversing the hierarchy.
124 * One of the applications of post-order traversing of a
125 * hierarchy can be deleting the hierarchy from the file system.
129 * Pre-order means that the directory is processed before
130 * any of its children are processed. Pre-order traversing of
131 * the above hierarchy will be like this:
153 * In pre-order, the callback function can return 3 values:
154 * 0: means that the traversing should continue.
156 * < 0: means that the traversing should be stopped immediately.
158 * FST_SKIP: means that no further entries of this directory
159 * should be processed. Traversing continues with the
160 * next directory of the same level. For example, if
161 * callback returns FST_SKIP on AAA/BBB, the callback
162 * will not be called on 1, 2, 3 and traversing will
163 * continue with AAA/CCC.
167 * This is a special case of pre-order. In this method,
168 * all the non-directory entries of a directory are processed
169 * and then come the directory entries. Level-order traversing
170 * of the above hierarchy will be like this:
192 * The rules of pre-order for the return value of callback
193 * function applies for level-order.
196 #include <sys/types.h>
197 #include <sys/stat.h>
201 * To prune a directory when traversing it, this return
202 * value should be returned by the callback function in
203 * level-order and pre-order traversing.
205 * In level-order processing, this return value stops
206 * reading the rest of the directory and calling the callback
207 * function for them. Traversing will continue with the next
208 * directory of the same level. The children of the current
209 * directory will be pruned too. For example on this ,
219 * Directives for traversing file system.
221 * FST_STOP_ONERR: Stop travergins when stat fails on an entry.
222 * FST_STOP_ONLONG: Stop on detecting long path.
223 * FST_VERBOSE: Verbose running.
225 #define FST_STOP_ONERR 0x00000001
226 #define FST_STOP_ONLONG 0x00000002
227 #define FST_VERBOSE 0x80000000
230 typedef void (*ft_log_t
)();
234 * The arguments of traversing file system contains:
235 * path: The physical path to be traversed.
237 * lpath The logical path to be passed to the callback
239 * If this is set to NULL, the default value will be
242 * For example, traversing '/v1.chkpnt/backup/home' as
243 * physical path can have a logical path of '/v1/home'.
245 * flags Show how the traversing should be done.
246 * Values of this field are of FST_ constants.
248 * callbk The callback function pointer. The callback
249 * function is called like this:
252 * struct fst_node *path,
253 * struct fst_node *entry)
255 * arg The 'void *' argument to be passed to the call
258 * logfp The log function pointer. This function
259 * is called to log the messages.
262 typedef struct fs_traverse
{
265 unsigned int ft_flags
;
272 * Traversing Nodes. For each path and node upon entry this
273 * structure is passed to the callback function.
275 typedef struct fst_node
{
278 struct stat64
*tn_st
;
281 extern int traverse_post(fs_traverse_t
*);
282 extern int traverse_pre(fs_traverse_t
*);
283 extern int traverse_level(fs_traverse_t
*);
285 extern int getdents(int, struct dirent
*, size_t);
290 #endif /* _TRAVERSE_H_ */