sweep through entire page table to free up intermediate tables
[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 static inline struct block_dev*
52 block_dev(struct device* dev) 
53 {
54     return (struct block_dev*)dev->underlay;
55 }
56
57 void
58 block_init();
59
60 struct block_dev*
61 block_alloc_dev(const char* blk_id, void* driver, req_handler ioreq_handler);
62
63 int
64 block_mount(struct block_dev* bdev, devfs_exporter export);
65
66 void
67 blk_mapping_init();
68
69 void
70 blk_set_blkmapping(struct block_dev* bdev, void* fsnode);
71
72 struct block_dev*
73 blk_mount_part(struct block_dev* bdev,
74                const char* name,
75                size_t index,
76                u64_t start_lba,
77                u64_t end_lba);
78
79 #endif /* __LUNAIX_BLOCK_H */