The devfs directory entries are now always sorted.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12803 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-05-25 00:41:32 +00:00
parent c477f77c33
commit 4195ac0c53
+16 -2
View File
@@ -271,8 +271,22 @@ devfs_insert_in_dir(struct devfs_vnode *dir, struct devfs_vnode *vnode)
if (!S_ISDIR(dir->stream.type)) if (!S_ISDIR(dir->stream.type))
return B_BAD_VALUE; return B_BAD_VALUE;
vnode->dir_next = dir->stream.u.dir.dir_head; // make sure the directory stays sorted alphabetically
dir->stream.u.dir.dir_head = vnode;
devfs_vnode *node = dir->stream.u.dir.dir_head, *last = NULL;
while (node && strcmp(node->name, vnode->name) < 0) {
last = node;
node = node->dir_next;
}
if (last == NULL) {
// the new vnode is the first entry in the list
vnode->dir_next = dir->stream.u.dir.dir_head;
dir->stream.u.dir.dir_head = vnode;
} else {
// insert after that node
vnode->dir_next = last->dir_next;
last->dir_next = vnode;
}
vnode->parent = dir; vnode->parent = dir;
dir->modification_time = time(NULL); dir->modification_time = time(NULL);