81716002bbc166be8881a590f7078f3bf1c9bbb3
[lunaix-os.git] / lunaix-os / includes / lunaix / device.h
1 #ifndef __LUNAIX_DEVICE_H
2 #define __LUNAIX_DEVICE_H
3
4 #define DEVICE_NAME_SIZE 32
5
6 #include <lunaix/ds/hstr.h>
7 #include <lunaix/ds/llist.h>
8 #include <lunaix/types.h>
9
10 #define DEV_MSKIF 0x00000003
11
12 #define DEV_IFVOL 0x0 // volumetric (block) device
13 #define DEV_IFSEQ 0x1 // sequential (character) device
14 #define DEV_IFCAT 0x2 // a device category (as device groupping)
15
16 typedef unsigned int dev_t;
17
18 struct device
19 {
20     struct llist_header siblings;
21     struct llist_header children;
22     struct device* parent;
23     struct hstr name;
24     dev_t dev_id;
25     int dev_type;
26     char name_val[DEVICE_NAME_SIZE];
27     void* underlay;
28     int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
29     int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
30 };
31
32 struct device*
33 device_add(struct device* parent,
34            void* underlay,
35            char* name_fmt,
36            uint32_t type,
37            va_list args);
38
39 struct device*
40 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
41
42 struct device*
43 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...);
44
45 struct device*
46 device_addcat(struct device* parent, char* name_fmt, ...);
47
48 void
49 device_remove(struct device* dev);
50
51 struct device*
52 device_getbyid(struct llist_header* devlist, dev_t id);
53
54 struct device*
55 device_getbyhname(struct llist_header* devlist, struct hstr* name);
56
57 struct device*
58 device_getbyname(struct llist_header* devlist, const char* name, size_t len);
59
60 struct device*
61 device_getbyoffset(struct llist_header* devlist, int pos);
62
63 #endif /* __LUNAIX_DEVICE_H */