fix: memory leakage in file descriptor allocation
[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     char bdev_id[DEV_ID_SIZE];
15     char name[PARTITION_NAME_SIZE];
16     struct blkio_context* blkio;
17     struct device* dev;
18     void* driver;
19     u64_t end_lba;
20     u32_t blk_size;
21 };
22
23 struct lpt_entry
24 {
25     char part_name[PARTITION_NAME_SIZE];
26     u64_t base_lba;
27     u64_t end_lba;
28 } __attribute__((packed));
29
30 // Lunaix Partition Table
31 struct lpt_header
32 {
33     u32_t signature;
34     u32_t crc;
35     u32_t pt_start_lba;
36     u32_t pt_end_lba;
37     u32_t table_len;
38 } __attribute__((packed));
39
40 typedef u64_t partition_t;
41 typedef uint32_t bdev_t;
42 typedef void (*devfs_exporter)(struct block_dev* bdev, void* fsnode);
43
44 void
45 block_init();
46
47 struct block_dev*
48 block_alloc_dev(const char* blk_id, void* driver, req_handler ioreq_handler);
49
50 int
51 block_mount(struct block_dev* bdev, devfs_exporter export);
52
53 void
54 blk_mapping_init();
55
56 void
57 blk_set_blkmapping(struct block_dev* bdev, void* fsnode);
58
59 #endif /* __LUNAIX_BLOCK_H */