7-ps2_keyboard.md and 8-multitasking.md (#29)
[lunaix-os.git] / lunaix-os / includes / lunaix / block.h
1 #ifndef __LUNAIX_BLOCK_H
2 #define __LUNAIX_BLOCK_H
3
4 #include <hal/ahci/hba.h>
5 #include <lunaix/blkio.h>
6 #include <lunaix/device.h>
7
8 #define LPT_SIG 0x414e554c
9 #define PARTITION_NAME_SIZE 48
10 #define DEV_ID_SIZE 32
11
12 struct block_dev;
13
14 struct block_dev_ops
15 {
16     int (*block_read)(struct block_dev*, void*, u64_t, size_t);
17     int (*block_write)(struct block_dev*, void*, u64_t, size_t);
18     void* (*block_alloc)(struct block_dev*);
19     void (*block_free)(struct block_dev*, void*);
20 };
21
22 struct block_dev
23 {
24     struct llist_header parts;
25     struct blkio_context* blkio;
26     struct device* dev;
27     char bdev_id[DEV_ID_SIZE];
28     char name[PARTITION_NAME_SIZE];
29     void* driver;
30     u64_t start_lba;
31     u64_t end_lba;
32     u32_t blk_size;
33     struct block_dev_ops ops;
34     struct devclass* class;
35 };
36
37 // Lunaix Partition Table
38 struct lpt_header
39 {
40     u32_t signature;
41     u32_t crc;
42     u32_t pt_start_lba;
43     u32_t pt_end_lba;
44     u32_t table_len;
45 } __attribute__((packed));
46
47 typedef u64_t partition_t;
48 typedef u32_t bdev_t;
49 typedef void (*devfs_exporter)(struct block_dev* bdev, void* fsnode);
50
51 void
52 block_init();
53
54 struct block_dev*
55 block_alloc_dev(const char* blk_id, void* driver, req_handler ioreq_handler);
56
57 int
58 block_mount(struct block_dev* bdev, devfs_exporter export);
59
60 void
61 blk_mapping_init();
62
63 void
64 blk_set_blkmapping(struct block_dev* bdev, void* fsnode);
65
66 struct block_dev*
67 blk_mount_part(struct block_dev* bdev,
68                const char* name,
69                size_t index,
70                u64_t start_lba,
71                u64_t end_lba);
72
73 #endif /* __LUNAIX_BLOCK_H */