+/* parent is locked at least shared */
+static struct dentry *next_positive(struct dentry *parent,
+ struct list_head *from,
+ int count)
+{
+ struct dentry *res = NULL;
+ struct list_head *p;
+
+ spin_lock(&parent->d_lock);
+ for (p = from->next; p != &parent->d_subdirs; p = p->next) {
+ struct dentry *d = list_entry(p, struct dentry, d_child);
+ if (simple_positive(d) && !--count) {
+ res = d;
+ break;
+ }
+ }
+ spin_unlock(&parent->d_lock);
+ return res;
+}
+
+static void move_cursor(struct dentry *cursor, struct list_head *after)
+{
+ struct dentry *parent = cursor->d_parent;
+
+ spin_lock(&parent->d_lock);
+ __list_del(cursor->d_child.prev, cursor->d_child.next);
+ if (after)
+ list_add(&cursor->d_child, after);
+ else
+ list_add_tail(&cursor->d_child, &parent->d_subdirs);
+ spin_unlock(&parent->d_lock);
+}
+