device: add devfs
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
4b17525d33
commit
df3a785e43
2 changed files with 30 additions and 1 deletions
|
|
@ -1,2 +1,3 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
obj-y += device.o
|
||||
obj-y += block.o
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <drivers/tty.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/block.h>
|
||||
#include <kernel/device.h>
|
||||
#include <kernel/atomic.h>
|
||||
|
||||
#include <fs/devfs.h>
|
||||
|
||||
#include <lib/rbtree.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/math.h>
|
||||
|
|
@ -16,9 +22,11 @@ static mem_cache_t *dev_info_cache = NULL;
|
|||
|
||||
static rbtree_t device_tree = {0};
|
||||
|
||||
static u64 device_ticker = 0;
|
||||
|
||||
dev_t device_create(void *private, dev_class_t class, const char *name)
|
||||
{
|
||||
dev_t key = rbt_next_key(&device_tree);
|
||||
dev_t key = atomic_xadd(&device_ticker, 1);
|
||||
rbnode_t *node = rbt_insert(&device_tree, key);
|
||||
|
||||
size_t name_len = strlen(name);
|
||||
|
|
@ -31,6 +39,26 @@ dev_t device_create(void *private, dev_class_t class, const char *name)
|
|||
|
||||
node->value = (vaddr_t)info;
|
||||
|
||||
dirent_t *devfile = NULL;
|
||||
|
||||
if (class == DEV_CLASS_BLK) {
|
||||
int res = devfs_insert_device_blk(name, private, &devfile);
|
||||
|
||||
if (res < 0) {
|
||||
kerr("failed to insert blk device node: %s\n", strerror(-res));
|
||||
return res;
|
||||
}
|
||||
} else if (class == DEV_CLASS_TTY) {
|
||||
int res = devfs_insert_device_chr(name, private, &devfile);
|
||||
|
||||
if (res < 0) {
|
||||
kerr("failed to insert chr device node: %s\n", strerror(-res));
|
||||
return res;
|
||||
} else {
|
||||
krdy("inserted chrdev node %s: value %d\n", name, res);
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue