2 * Directory tree build/traverse routines
4 * Kern Sibbald, June MMII
8 Copyright (C) 2002-2004 Kern Sibbald and John Walker
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public
21 License along with this program; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 struct s_mem *next; /* next buffer */
29 int rem; /* remaining bytes */
30 char *mem; /* memory pointer */
31 char first[1]; /* first byte */
34 #define foreach_child(cld, node) \
35 for(cld=(node)->child_; cld; cld=cld->sibling_)
37 #define tree_node_has_child(node) \
38 ((node)->child_ != NULL)
40 #define first_child(node) \
45 * Keep this node as small as possible because
46 * there is one for each file.
49 char *fname; /* file name */
50 int32_t FileIndex; /* file index */
51 uint32_t JobId; /* JobId */
52 uint16_t fname_len; /* filename length */
53 int type: 8; /* node type */
54 unsigned int extract: 1; /* extract item */
55 unsigned int extract_dir: 1; /* extract dir entry only */
56 unsigned int hard_link: 1; /* set if have hard link */
57 unsigned int soft_link: 1; /* set if is soft link */
58 unsigned int inserted: 1; /* set when newly inserted */
59 struct s_tree_node *parent;
60 struct s_tree_node *sibling_;
61 struct s_tree_node *next; /* next hash of FileIndex */
62 struct s_tree_node *child_;
64 typedef struct s_tree_node TREE_NODE;
67 char *fname; /* file name */
68 int32_t FileIndex; /* file index */
69 uint32_t JobId; /* JobId */
70 uint16_t fname_len; /* filename length */
71 unsigned int type: 8; /* node type */
72 unsigned int extract: 1; /* extract item */
73 unsigned int extract_dir: 1; /* extract dir entry only */
74 unsigned int have_link: 1; /* set if have hard link */
75 unsigned int inserted: 1; /* set when newly inserted */
76 struct s_tree_node *parent;
77 struct s_tree_node *sibling_;
78 struct s_tree_node *next; /* next hash of FileIndex */
79 struct s_tree_node *child_;
81 /* The above ^^^ must be identical to a TREE_NODE structure */
82 struct s_tree_node *first; /* first entry in the tree */
83 struct s_tree_node *last; /* last entry in tree */
84 struct s_mem *mem; /* tree memory */
85 uint32_t total_size; /* total bytes allocated */
86 uint32_t blocks; /* total mallocs */
87 int cached_path_len; /* length of cached path */
88 char *cached_path; /* cached current path */
89 TREE_NODE *cached_parent; /* cached parent for above path */
91 typedef struct s_tree_root TREE_ROOT;
94 #define TN_ROOT 1 /* root node */
95 #define TN_NEWDIR 2 /* created directory to fill path */
96 #define TN_DIR 3 /* directory entry */
97 #define TN_DIR_NLS 4 /* directory -- no leading slash -- win32 */
98 #define TN_FILE 5 /* file entry */
100 /* External interface */
101 TREE_ROOT *new_tree(int count);
102 TREE_NODE *insert_tree_node(char *path, char *fname, TREE_NODE *node,
103 TREE_ROOT *root, TREE_NODE *parent);
104 TREE_NODE *make_tree_path(char *path, TREE_ROOT *root);
105 TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node);
106 TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node);
107 void free_tree(TREE_ROOT *root);
108 int tree_getpath(TREE_NODE *node, char *buf, int buf_size);
111 TREE_NODE *first_tree_node(TREE_ROOT *root);
112 TREE_NODE *next_tree_node(TREE_NODE *node);
114 #define first_tree_node(r) (r)->first
115 #define next_tree_node(n) (n)->next