INIT_LIST_HEAD(&main_stack);
INIT_LIST_HEAD(&sibling_stack);
- list_add(&main_dentry->tmp_list, &main_stack);
+ list_add(&root->tmp_list, &main_stack);
+ node = root->d_inode->children.rb_node;
while (1) {
// Prepare for non-recursive in-order traversal of the red-black
// tree of this dentry's children
- node = main_dentry->d_inode->children.rb_node;
while (node) {
// Push this node to the sibling stack and examine the
// left neighbor, if any
list_add(&rbnode_dentry(node)->tmp_list, &sibling_stack);
- push_left_siblings:
node = node->rb_left;
}
-
- pop_sibling:
-
next_sibling = sibling_stack.next;
if (next_sibling == sibling_stack_bottom) {
// Done with all siblings. Pop the main dentry to move
tmp_list);
list_del(&main_dentry->tmp_list);
- if (main_dentry == root) {
- ret = 0;
+ if (main_dentry == root)
goto out;
- }
// Restore sibling stack bottom from the previous level
sibling_stack_bottom = (void*)main_dentry->parent;
// in the in-order traversal of the red-black tree, is
// the one to the right.
node = main_dentry->rb_node.rb_right;
- if (node) {
- list_add(&rbnode_dentry(node)->tmp_list,
- &sibling_stack);
- goto push_left_siblings;
- } else {
- goto pop_sibling;
- }
} else {
// The sibling stack is not empty, so there are more to
// go!
// sibling stack to be its current height, and set
// main_dentry to the sibling so it becomes the parent
// dentry in the next iteration through the outer loop.
- list_add(&dentry->tmp_list, &main_stack);
- dentry->parent = (void*)sibling_stack_bottom;
- sibling_stack_bottom = sibling_stack.next;
-
- main_dentry = dentry;
+ if (inode_has_children(dentry->d_inode)) {
+ list_add(&dentry->tmp_list, &main_stack);
+ dentry->parent = (void*)sibling_stack_bottom;
+ sibling_stack_bottom = sibling_stack.next;
+
+ main_dentry = dentry;
+ node = main_dentry->d_inode->children.rb_node;
+ } else {
+ node = dentry->rb_node.rb_right;
+ }
}
}
out: