2 * Directory tree build/traverse routines
4 * Kern Sibbald, June MMII
8 Bacula® - The Network Backup Solution
10 Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
12 The main author of Bacula is Kern Sibbald, with contributions from
13 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark ofJohn Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
32 Switzerland, email:ftf@fsfeurope.org.
36 struct s_mem *next; /* next buffer */
37 int rem; /* remaining bytes */
38 char *mem; /* memory pointer */
39 char first[1]; /* first byte */
44 #define foreach_child(var, list) \
45 for((var)=NULL; (*((TREE_NODE **)&(var))=(TREE_NODE*)(list->child.next(var))); )
47 #define tree_node_has_child(node) \
48 ((node)->child.size() > 0)
50 #define first_child(node) \
51 ((TREE_NODE *)(node->child.first())
55 * Keep this node as small as possible because
56 * there is one for each file.
59 /* KEEP sibling as the first member to avoid having to
60 * do initialization of child */
63 char *fname; /* file name */
64 int32_t FileIndex; /* file index */
65 uint32_t JobId; /* JobId */
66 uint16_t fname_len; /* filename length */
67 int type: 8; /* node type */
68 unsigned int extract: 1; /* extract item */
69 unsigned int extract_dir: 1; /* extract dir entry only */
70 unsigned int hard_link: 1; /* set if have hard link */
71 unsigned int soft_link: 1; /* set if is soft link */
72 unsigned int inserted: 1; /* set when node newly inserted */
73 unsigned int loaded: 1; /* set when the dir is in the tree */
74 struct s_tree_node *parent;
75 struct s_tree_node *next; /* next hash of FileIndex */
77 typedef struct s_tree_node TREE_NODE;
80 /* KEEP sibling as the first member to avoid having to
81 * do initialization of child */
84 const char *fname; /* file name */
85 int32_t FileIndex; /* file index */
86 uint32_t JobId; /* JobId */
87 uint16_t fname_len; /* filename length */
88 unsigned int type: 8; /* node type */
89 unsigned int extract: 1; /* extract item */
90 unsigned int extract_dir: 1; /* extract dir entry only */
91 unsigned int have_link: 1; /* set if have hard link */
92 unsigned int inserted: 1; /* set when newly inserted */
93 unsigned int loaded: 1; /* set when the dir is in the tree */
94 struct s_tree_node *parent;
95 struct s_tree_node *next; /* next hash of FileIndex */
97 /* The above ^^^ must be identical to a TREE_NODE structure */
98 struct s_tree_node *first; /* first entry in the tree */
99 struct s_tree_node *last; /* last entry in tree */
100 struct s_mem *mem; /* tree memory */
101 uint32_t total_size; /* total bytes allocated */
102 uint32_t blocks; /* total mallocs */
103 int cached_path_len; /* length of cached path */
104 char *cached_path; /* cached current path */
105 TREE_NODE *cached_parent; /* cached parent for above path */
107 typedef struct s_tree_root TREE_ROOT;
111 #define TN_ROOT 1 /* root node */
112 #define TN_NEWDIR 2 /* created directory to fill path */
113 #define TN_DIR 3 /* directory entry */
114 #define TN_DIR_NLS 4 /* directory -- no leading slash -- win32 */
115 #define TN_FILE 5 /* file entry */
117 /* External interface */
118 TREE_ROOT *new_tree(int count);
119 TREE_NODE *insert_tree_node(char *path, char *fname, int type,
120 TREE_ROOT *root, TREE_NODE *parent);
121 TREE_NODE *make_tree_path(char *path, TREE_ROOT *root);
122 TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node);
123 TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node);
124 void free_tree(TREE_ROOT *root);
125 int tree_getpath(TREE_NODE *node, char *buf, int buf_size);
128 * Use the following for traversing the whole tree. It will be
129 * traversed in the order the entries were inserted into the
132 #define first_tree_node(r) (r)->first
133 #define next_tree_node(n) (n)->next