2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Directory tree build/traverse routines
22 * Kern Sibbald, June MMII
29 struct s_mem *next; /* next buffer */
30 int rem; /* remaining bytes */
31 char *mem; /* memory pointer */
32 char first[1]; /* first byte */
37 #define foreach_child(var, list) \
38 for((var)=NULL; (*((TREE_NODE **)&(var))=(TREE_NODE*)(list->child.next(var))); )
40 #define tree_node_has_child(node) \
41 ((node)->child.size() > 0)
43 #define first_child(node) \
44 ((TREE_NODE *)(node->child.first())
47 struct delta_list *next;
53 * Keep this node as small as possible because
54 * there is one for each file.
57 /* KEEP sibling as the first member to avoid having to
58 * do initialization of child */
61 char *fname; /* file name */
62 int32_t FileIndex; /* file index */
63 uint32_t JobId; /* JobId */
64 int32_t delta_seq; /* current delta sequence */
65 uint16_t fname_len; /* filename length */
66 int type: 8; /* node type */
67 unsigned int extract: 1; /* extract item */
68 unsigned int extract_dir: 1; /* extract dir entry only */
69 unsigned int hard_link: 1; /* set if have hard link */
70 unsigned int soft_link: 1; /* set if is soft link */
71 unsigned int inserted: 1; /* set when node newly inserted */
72 unsigned int loaded: 1; /* set when the dir is in the tree */
73 unsigned int can_access: 1; /* Can access to this node */
74 struct s_tree_node *parent;
75 struct s_tree_node *next; /* next hash of FileIndex */
76 struct delta_list *delta_list; /* delta parts for this node */
78 typedef struct s_tree_node TREE_NODE;
81 /* KEEP sibling as the first member to avoid having to
82 * do initialization of child */
85 const char *fname; /* file name */
86 int32_t FileIndex; /* file index */
87 uint32_t JobId; /* JobId */
88 int32_t delta_seq; /* current delta sequence */
89 uint16_t fname_len; /* filename length */
90 unsigned int type: 8; /* node type */
91 unsigned int extract: 1; /* extract item */
92 unsigned int extract_dir: 1; /* extract dir entry only */
93 unsigned int have_link: 1; /* set if have hard link */
94 unsigned int inserted: 1; /* set when newly inserted */
95 unsigned int loaded: 1; /* set when the dir is in the tree */
96 struct s_tree_node *parent;
97 struct s_tree_node *next; /* next hash of FileIndex */
98 struct delta_list *delta_list; /* delta parts for this node */
100 /* The above ^^^ must be identical to a TREE_NODE structure */
101 struct s_tree_node *first; /* first entry in the tree */
102 struct s_tree_node *last; /* last entry in tree */
103 struct s_mem *mem; /* tree memory */
104 uint32_t total_size; /* total bytes allocated */
105 uint32_t blocks; /* total mallocs */
106 int cached_path_len; /* length of cached path */
107 char *cached_path; /* cached current path */
108 TREE_NODE *cached_parent; /* cached parent for above path */
109 htable hardlinks; /* references to first occurrence of hardlinks */
111 typedef struct s_tree_root TREE_ROOT;
113 /* hardlink hashtable entry */
119 typedef struct s_hl_entry HL_ENTRY;
122 #define TN_ROOT 1 /* root node */
123 #define TN_NEWDIR 2 /* created directory to fill path */
124 #define TN_DIR 3 /* directory entry */
125 #define TN_DIR_NLS 4 /* directory -- no leading slash -- win32 */
126 #define TN_FILE 5 /* file entry */
128 /* External interface */
129 TREE_ROOT *new_tree(int count);
130 TREE_NODE *insert_tree_node(char *path, char *fname, int type,
131 TREE_ROOT *root, TREE_NODE *parent);
132 TREE_NODE *make_tree_path(char *path, TREE_ROOT *root);
133 TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node);
134 TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node);
135 void tree_add_delta_part(TREE_ROOT *root, TREE_NODE *node,
136 JobId_t JobId, int32_t FileIndex);
137 void free_tree(TREE_ROOT *root);
138 int tree_getpath(TREE_NODE *node, char *buf, int buf_size);
139 void tree_remove_node(TREE_ROOT *root, TREE_NODE *node);
142 * Use the following for traversing the whole tree. It will be
143 * traversed in the order the entries were inserted into the
146 #define first_tree_node(r) (r)->first
147 #define next_tree_node(n) (n)->next