+/*
+ * This routine can be called to release the
+ * previously allocated tree node.
+ */
+static void free_tree_node(TREE_ROOT *root)
+{
+ int asize = BALIGN(sizeof(TREE_NODE));
+ root->mem->rem += asize;
+ root->mem->mem -= asize;
+}
+
+
+
+/*
+ * Allocate bytes for filename in tree structure.
+ * Keep the pointers properly aligned by allocating
+ * sizes that are aligned.
+ */
+static char *tree_alloc(TREE_ROOT *root, int size)
+{
+ char *buf;
+ int asize = BALIGN(size);
+
+ if (root->mem->rem < asize) {
+ uint32_t mb_size;
+ if (root->total_size >= 1000000) {
+ mb_size = 1000000;
+ } else {
+ mb_size = 100000;
+ }
+ malloc_buf(root, mb_size);
+ }
+ root->mem->rem -= asize;
+ buf = root->mem->mem;
+ root->mem->mem += asize;
+ return buf;
+}
+
+
+/* This routine frees the whole tree */
+void free_tree(TREE_ROOT *root)
+{
+ struct s_mem *mem, *rel;
+
+ for (mem=root->mem; mem; ) {
+ rel = mem;
+ mem = mem->next;
+ free(rel);
+ }
+ if (root->cached_path) {
+ free_pool_memory(root->cached_path);
+ root->cached_path = NULL;
+ }
+ Dmsg2(400, "Total size=%u blocks=%d\n", root->total_size, root->blocks);
+ free(root);
+ return;
+}
+
+
+/*
+ * Insert a node in the tree. This is the main subroutine
+ * called when building a tree.
+ *
+ */
+TREE_NODE *insert_tree_node(char *path, char *fname, int type,
+ TREE_ROOT *root, TREE_NODE *parent)