c0ed9896382ef901e0fb676d224187b33a033520
[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
9 #define DEV_MSKIF 0x00000003
10
11 #define DEV_IFVOL 0x0 // volumetric (block) device
12 #define DEV_IFSEQ 0x1 // sequential (character) device
13 #define DEV_IFCAT 0x2 // a device category (as device groupping)
14
15 typedef unsigned int dev_t;
16
17 struct device
18 {
19     struct llist_header siblings;
20     struct device* parent;
21     struct hstr name;
22     dev_t dev_id;
23     int dev_type;
24     char name_val[DEVICE_NAME_SIZE];
25     void* underlay;
26     int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
27     int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
28 };
29
30 struct device*
31 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
32
33 struct device*
34 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...);
35
36 struct device*
37 device_addcat(struct device* parent, char* name_fmt, ...);
38
39 void
40 device_remove(struct device* dev);
41
42 struct device*
43 device_getbyid(struct llist_header* devlist, dev_t id);
44
45 struct device*
46 device_getbyname(struct llist_header* devlist, struct hstr* name);
47
48 struct device*
49 device_getbyoffset(struct llist_header* devlist, int pos);
50
51 #endif /* __LUNAIX_DEVICE_H */