]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/tree.h
2fd3386b02f61c02e3abca4c412bca8a4d24b03e
[bacula/bacula] / bacula / src / lib / tree.h
1 /*
2  * Directory tree build/traverse routines
3  * 
4  *    Kern Sibbald, June MMII
5  *
6 */
7 /*
8    Copyright (C) 2002,2003 Kern Sibbald and John Walker
9
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.
14
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.
19
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,
23    MA 02111-1307, USA.
24
25  */
26
27 struct s_mem {
28    struct s_mem *next;                /* next buffer */
29    int rem;                           /* remaining bytes */
30    char *mem;                         /* memory pointer */
31    char first[1];                     /* first byte */
32 };
33
34 struct s_tree_node {
35    char *fname;                       /* file name */
36    int32_t FileIndex;                 /* file index */
37    uint32_t JobId;                    /* JobId */
38    short type;                        /* node type */
39    short extract;                     /* set if extracting */
40    struct s_tree_node *parent;
41    struct s_tree_node *sibling;
42    struct s_tree_node *child;
43    struct s_tree_node *next;          /* next hash of FileIndex */
44 };
45 typedef struct s_tree_node TREE_NODE;
46
47 struct s_tree_root {
48    char *fname;                       /* file name */
49    int32_t FileIndex;                 /* file index */
50    uint32_t JobId;                    /* JobId */
51    short type;                        /* node type */
52    short extract;                     /* set if extracting */
53    struct s_tree_node *parent;
54    struct s_tree_node *sibling;
55    struct s_tree_node *child;
56    struct s_tree_node *next;          /* next hash of FileIndex */
57
58    /* The above ^^^ must be identical to a TREE_NODE structure */
59    struct s_tree_node *first;         /* first entry in the tree */
60    struct s_tree_node *last;          /* last entry in tree */
61    struct s_mem *mem;                 /* tree memory */
62    int cached_path_len;               /* length of cached path */
63    char *cached_path;                 /* cached current path */
64    TREE_NODE *cached_parent;          /* cached parent for above path */
65 };
66 typedef struct s_tree_root TREE_ROOT;
67
68 /* type values */
69 #define TN_ROOT    1                  /* root node */
70 #define TN_NEWDIR  2                  /* created directory to fill path */
71 #define TN_DIR     3                  /* directory entry */
72 #define TN_DIR_NLS 4                  /* directory -- no leading slash -- win32 */
73 #define TN_FILE    5                  /* file entry */
74
75 TREE_ROOT *new_tree(int count);
76 TREE_NODE *new_tree_node(TREE_ROOT *root, int type);
77 TREE_NODE *insert_tree_node(char *fname, TREE_NODE *node, 
78                             TREE_ROOT *root, TREE_NODE *parent);
79 TREE_NODE *make_tree_path(char *path, TREE_ROOT *root);
80 TREE_NODE *first_tree_node(TREE_ROOT *root);
81 TREE_NODE *next_tree_node(TREE_NODE *node);
82 TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node);
83 TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node);
84 void append_tree_node(char *path, TREE_NODE *node, TREE_ROOT *root, TREE_NODE *parent);
85 void print_tree(char *path, TREE_NODE *root);    
86 void free_tree(TREE_ROOT *root);
87 int tree_getpath(TREE_NODE *node, char *buf, int buf_size);