1 /*
2  * Copyright (c) 2014 Dave Vasilevsky <dave@vasilevsky.ca>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #ifndef SQFS_TRAVERSE_H
26 #define SQFS_TRAVERSE_H
27 
28 #include "common.h"
29 
30 #include "dir.h"
31 #include "stack.h"
32 
33 typedef struct {
34 	bool dir_end;
35 	sqfs_dir_entry entry;
36 	char *path;
37 
38 
39 	/* private */
40 	int state;
41 	sqfs *fs;
42 	sqfs_name namebuf;
43 	sqfs_stack stack;
44 
45 	size_t path_size, path_cap;
46 	size_t path_last_size;
47 } sqfs_traverse;
48 
49 /* Begin a recursive traversal of a filesystem tree.
50    Every sub-item of the given inode will be traversed in-order, but not
51    this inode itself. */
52 sqfs_err sqfs_traverse_open(sqfs_traverse *trv, sqfs *fs, sqfs_inode_id iid);
53 sqfs_err sqfs_traverse_open_inode(sqfs_traverse *trv, sqfs *fs,
54 	sqfs_inode *inode);
55 
56 /* Clean up at any point during or after a traversal */
57 void sqfs_traverse_close(sqfs_traverse *trv);
58 
59 /* Get the next item in the traversal. An item may be:
60    - A directory entry, in which case trv->entry will be filled
61 	 - A marker that a directory is finished, in which case trv->dir_end will
62      be true.
63    Returns false if there are no more items. */
64 bool sqfs_traverse_next(sqfs_traverse *trv, sqfs_err *err);
65 
66 /* Don't recurse into the directory just returned. */
67 sqfs_err sqfs_traverse_prune(sqfs_traverse *trv);
68 
69 #endif
70