#include "config.h"
#include "list.h"
#include "sha1.h"
+#include "rbtree.h"
#include <string.h>
struct stat;
/* The parent of this directory entry. */
struct dentry *parent;
- /* Linked list of sibling directory entries. */
- struct dentry *next;
- struct dentry *prev;
+ struct rb_node rb_node;
/*
* Size of directory entry on disk, in bytes. Typical size is around
};
};
+#define rbnode_dentry(node) container_of(node, struct dentry, rb_node)
+
/*
* WIM inode.
*
struct hlist_node hlist;
char *extracted_file;
- /* If non-NULL, the children of this inode (implies the inode is a
- * directory) */
- struct dentry *children;
+ /* Root of a red-black tree storing the children of this inode (if
+ * non-empty, implies the inode is a directory, although that is also
+ * noted in the @attributes field.) */
+ struct rb_root children;
#ifdef WITH_FUSE
/* wimfs file descriptors table for the inode */
int (*visitor)(struct dentry*, void*),
void *args);
+extern int for_dentry_in_rbtree(struct rb_node *node,
+ int (*visitor)(struct dentry *, void *),
+ void *arg);
+
extern int for_dentry_in_tree_depth(struct dentry *root,
int (*visitor)(struct dentry*, void*),
void *args);
extern int increment_dentry_refcnt(struct dentry *dentry, void *ignore);
extern void unlink_dentry(struct dentry *dentry);
-extern void link_dentry(struct dentry *dentry, struct dentry *parent);
+extern bool dentry_add_child(struct dentry * restrict parent,
+ struct dentry * restrict child);
+
+// XXX
+#define link_dentry(child, parent) dentry_add_child(parent, child)
extern int verify_dentry(struct dentry *dentry, void *wim);
return dentry->parent == dentry;
}
-static inline bool dentry_is_first_sibling(const struct dentry *dentry)
-{
- return dentry_is_root(dentry) || dentry->parent->d_inode->children == dentry;
-}
-
-static inline bool dentry_is_only_child(const struct dentry *dentry)
-{
- return dentry->next == dentry;
-}
-
static inline bool inode_is_directory(const struct inode *inode)
{
return (inode->attributes & FILE_ATTRIBUTE_DIRECTORY)
return inode_is_regular_file(dentry->d_inode);
}
+static inline bool inode_has_children(const struct inode *inode)
+{
+ return inode->children.rb_node != NULL;
+}
+
static inline bool dentry_is_empty_directory(const struct dentry *dentry)
{
- return dentry_is_directory(dentry) && dentry->d_inode->children == NULL;
+ const struct inode *inode = dentry->d_inode;
+ return inode_is_directory(inode) && !inode_has_children(inode);
}
#endif