]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/tree.h
Tweak version date
[bacula/bacula] / bacula / src / lib / tree.h
index dd81675648993ea7f0c5de956e235038ae882cfb..3464cb1965d889203ff5261adce04c4634f8a049 100644 (file)
@@ -1,28 +1,36 @@
 /*
- * Directory tree build/traverse routines
- * 
- *    Kern Sibbald, June MMII
- *
-*/
-/*
-   Copyright (C) 2002-2004 Kern Sibbald and John Walker
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2002-2009 Free Software Foundation Europe e.V.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
- */
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
+/*
+ * Directory tree build/traverse routines
+ *
+ *    Kern Sibbald, June MMII
+ *
+*/
 
 struct s_mem {
    struct s_mem *next;                /* next buffer */
@@ -31,52 +39,69 @@ struct s_mem {
    char first[1];                     /* first byte */
 };
 
-#define foreach_child(cld, node) \
-        for(cld=(node)->child_; cld; cld=cld->sibling_)
+#define USE_DLIST
+
+#define foreach_child(var, list) \
+    for((var)=NULL; (*((TREE_NODE **)&(var))=(TREE_NODE*)(list->child.next(var))); )
 
 #define tree_node_has_child(node) \
-        ((node)->child_ != NULL)
+        ((node)->child.size() > 0)
 
 #define first_child(node) \
-        ((node)->child_)
+        ((TREE_NODE *)(node->child.first())
 
+struct delta_list {
+   struct delta_list *next;
+   JobId_t JobId;
+   int32_t FileIndex;
+};
 
 /*
  * Keep this node as small as possible because
  *   there is one for each file.
  */
 struct s_tree_node {
+   /* KEEP sibling as the first member to avoid having to
+    *  do initialization of child */
+   rblink sibling;
+   rblist child;
    char *fname;                       /* file name */
    int32_t FileIndex;                 /* file index */
    uint32_t JobId;                    /* JobId */
+   int32_t delta_seq;                 /* current delta sequence */
    uint16_t fname_len;                /* filename length */
    int type: 8;                       /* node type */
    unsigned int extract: 1;           /* extract item */
    unsigned int extract_dir: 1;       /* extract dir entry only */
    unsigned int hard_link: 1;         /* set if have hard link */
-   unsigned int soft_link: 1;         /* set if is soft link */  
-   unsigned int inserted: 1;          /* set when newly inserted */
+   unsigned int soft_link: 1;         /* set if is soft link */
+   unsigned int inserted: 1;          /* set when node newly inserted */
+   unsigned int loaded: 1;            /* set when the dir is in the tree */
    struct s_tree_node *parent;
-   struct s_tree_node *sibling_;
    struct s_tree_node *next;          /* next hash of FileIndex */
-   struct s_tree_node *child_;
+   struct delta_list *delta_list;     /* delta parts for this node */
 };
 typedef struct s_tree_node TREE_NODE;
 
 struct s_tree_root {
-   char *fname;                       /* file name */
+   /* KEEP sibling as the first member to avoid having to
+    *  do initialization of child */
+   rblink sibling;
+   rblist child;
+   const char *fname;                 /* file name */
    int32_t FileIndex;                 /* file index */
    uint32_t JobId;                    /* JobId */
+   int32_t delta_seq;                 /* current delta sequence */
    uint16_t fname_len;                /* filename length */
    unsigned int type: 8;              /* node type */
    unsigned int extract: 1;           /* extract item */
    unsigned int extract_dir: 1;       /* extract dir entry only */
    unsigned int have_link: 1;         /* set if have hard link */
    unsigned int inserted: 1;          /* set when newly inserted */
+   unsigned int loaded: 1;            /* set when the dir is in the tree */
    struct s_tree_node *parent;
-   struct s_tree_node *sibling_;
    struct s_tree_node *next;          /* next hash of FileIndex */
-   struct s_tree_node *child_;
+   struct delta_list *delta_list;     /* delta parts for this node */
 
    /* The above ^^^ must be identical to a TREE_NODE structure */
    struct s_tree_node *first;         /* first entry in the tree */
@@ -90,6 +115,7 @@ struct s_tree_root {
 };
 typedef struct s_tree_root TREE_ROOT;
 
+
 /* type values */
 #define TN_ROOT    1                  /* root node */
 #define TN_NEWDIR  2                  /* created directory to fill path */
@@ -99,18 +125,21 @@ typedef struct s_tree_root TREE_ROOT;
 
 /* External interface */
 TREE_ROOT *new_tree(int count);
-TREE_NODE *insert_tree_node(char *path, char *fname, TREE_NODE *node, 
+TREE_NODE *insert_tree_node(char *path, char *fname, int type,
                             TREE_ROOT *root, TREE_NODE *parent);
 TREE_NODE *make_tree_path(char *path, TREE_ROOT *root);
 TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node);
 TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node);
+void tree_add_delta_part(TREE_ROOT *root, TREE_NODE *node, 
+                         JobId_t JobId, int32_t FileIndex);
 void free_tree(TREE_ROOT *root);
 int tree_getpath(TREE_NODE *node, char *buf, int buf_size);
+void tree_remove_node(TREE_ROOT *root, TREE_NODE *node);
 
-#ifdef SLOW_WAY
-TREE_NODE *first_tree_node(TREE_ROOT *root);
-TREE_NODE *next_tree_node(TREE_NODE *node);
-#else
-  #define first_tree_node(r) (r)->first
-  #define next_tree_node(n)  (n)->next
-#endif
+/*
+ * Use the following for traversing the whole tree. It will be
+ *   traversed in the order the entries were inserted into the
+ *   tree.
+ */
+#define first_tree_node(r) (r)->first
+#define next_tree_node(n)  (n)->next