747e05f315693c560f6c78e23a2a5dbf301b81c2
[lunaix-os.git] / lunaix-os / hal / char / devnull.c
1 #include <lunaix/device.h>
2 #include <lunaix/mm/page.h>
3
4 static int
5 __null_wr_pg(struct device* dev, void* buf, size_t offset)
6 {
7     // do nothing
8     return PG_SIZE;
9 }
10
11 static int
12 __null_wr(struct device* dev, void* buf, size_t offset, size_t len)
13 {
14     // do nothing
15     return len;
16 }
17
18 static int
19 __null_rd_pg(struct device* dev, void* buf, size_t offset)
20 {
21     // do nothing
22     return 0;
23 }
24
25 static int
26 __null_rd(struct device* dev, void* buf, size_t offset, size_t len)
27 {
28     // do nothing
29     return 0;
30 }
31
32 static int
33 pdev_nulldev_init(struct device_def* def)
34 {
35     struct device* devnull = device_allocseq(NULL, NULL);
36     devnull->ops.write_page = __null_wr_pg;
37     devnull->ops.write = __null_wr;
38     devnull->ops.read_page = __null_rd_pg;
39     devnull->ops.read = __null_rd;
40
41     device_register(devnull, &def->class, "null");
42
43     return 0;
44 }
45
46 static struct device_def devnull_def = {
47     .name = "null",
48     .class = DEVCLASSV(DEVIF_NON, DEVFN_PSEUDO, DEV_NULL, DEV_BUILTIN_NULL),
49     .init = pdev_nulldev_init};
50 EXPORT_DEVICE(nulldev, &devnull_def, load_onboot);