1 #include <klibc/stdio.h>
2 #include <lunaix/device.h>
3 #include <lunaix/fs/twifs.h>
4 #include <lunaix/mm/valloc.h>
5 #include <lunaix/spike.h>
7 static DEFINE_LLIST(root_list);
9 static volatile dev_t devid = 0;
12 __device_add(struct device* parent,
18 struct device* dev = vzalloc(sizeof(struct device));
21 assert((parent->dev_type & DEV_MSKIF) == DEV_IFCAT);
25 __sprintf_internal(dev->name_val, name_fmt, DEVICE_NAME_SIZE, args);
27 dev->dev_id = devid++;
28 dev->name = HSTR(dev->name_val, strlen);
30 dev->underlay = underlay;
33 hstr_rehash(&dev->name, HSTR_FULL_HASH);
34 llist_append(&root_list, &dev->siblings);
40 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...)
43 va_start(args, name_fmt);
46 __device_add(parent, underlay, name_fmt, DEV_IFSEQ, args);
53 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...)
56 va_start(args, name_fmt);
59 __device_add(parent, underlay, name_fmt, DEV_IFVOL, args);
66 device_addcat(struct device* parent, char* name_fmt, ...)
69 va_start(args, name_fmt);
71 struct device* dev = __device_add(parent, NULL, name_fmt, DEV_IFCAT, args);
78 device_getbyid(struct llist_header* devlist, dev_t id)
80 devlist = devlist ? devlist : &root_list;
81 struct device *pos, *n;
82 llist_for_each(pos, n, devlist, siblings)
84 if (pos->dev_id == id) {
93 device_getbyname(struct llist_header* devlist, struct hstr* name)
95 devlist = devlist ? devlist : &root_list;
96 struct device *pos, *n;
97 llist_for_each(pos, n, devlist, siblings)
99 if (HSTR_EQ(&pos->name, name)) {
108 device_remove(struct device* dev)
110 llist_delete(&dev->siblings);
115 device_getbyoffset(struct llist_header* devlist, int offset)
117 devlist = devlist ? devlist : &root_list;
118 struct device *pos, *n;
120 llist_for_each(pos, n, devlist, siblings)
122 if (off++ >= offset) {