regression: mmap for fd
[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 };
35
36 // Lunaix Partition Table
37 struct lpt_header
38 {
39     u32_t signature;
40     u32_t crc;
41     u32_t pt_start_lba;
42     u32_t pt_end_lba;
43     u32_t table_len;
44 } __attribute__((packed));
45
46 typedef u64_t partition_t;
47 typedef u32_t bdev_t;
48 typedef void (*devfs_exporter)(struct block_dev* bdev, void* fsnode);
49
50 void
51 block_init();
52
53 struct block_dev*
54 block_alloc_dev(const char* blk_id, void* driver, req_handler ioreq_handler);
55
56 int
57 block_mount(struct block_dev* bdev, devfs_exporter export);
58
59 void
60 blk_mapping_init();
61
62 void
63 blk_set_blkmapping(struct block_dev* bdev, void* fsnode);
64
65 struct block_dev*
66 blk_mount_part(struct block_dev* bdev,
67                const char* name,
68                size_t index,
69                u64_t start_lba,
70                u64_t end_lba);
71
72 #endif /* __LUNAIX_BLOCK_H */