// // Created by rick on 06-02-21. // #ifndef NEW_KERNEL_BLOCKDEV_H #define NEW_KERNEL_BLOCKDEV_H #include #include #include #define BLOCK_DEV_LBA_SIZE 512 #define BLOCK_DEV_ACCESS_OK 0 #define BLOCK_DEV_ACCESS_ERR 1 #define BLOCK_DEV_DIRECTION_READ 0 #define BLOCK_DEV_DIRECTION_WRITE 1 #define BLOCK_DEV_DRIVER_CHECK_OK 0 #define BLOCK_DEV_DRIVER_CHECK_NO_MATCH 1 #define BLOCK_DEV_REGISTER_DRIVER_OK 0 #define BLOCK_DEV_REGISTER_DRIVER_FULL 1 #define BLOCK_DEV_REGISTER_OK 0 #define BLOCK_DEV_REGISTER_FULL 1 typedef struct block_device block_device_t; typedef uint8_t (*block_device_driver_check_device)(block_device_t *device); typedef uint8_t (*block_device_driver_free)(block_device_t *device); typedef uint8_t (*block_device_access)(const block_device_t *device, uint8_t direction, uint32_t lba, uint8_t sectors, void *target); typedef struct block_dev_driver { char name[16]; struct { uint8_t partitioning: 1; } flags; block_device_driver_check_device check_device; block_device_driver_free free_device; } __attribute__((__aligned__(STRUCT_ALIGNMENT))) block_dev_driver_t; #define BLOCK_DEV_DRIVER(order) GENERIC_DRIVER(block_dev_driver, order) struct block_device { struct { uint8_t present: 1; uint8_t scanned: 1; uint8_t unreadable: 1; uint8_t root_device: 1; uint8_t driver_installed: 1; } flags; char identifier[16]; uint32_t num_lba; uint16_t block_size; block_device_access access; struct block_dev_driver *driver; void *device_info; // pointer to driver defined structure void *driver_info; // pointer to driver defined structure // todo device info }; uint8_t block_dev_register(block_device_t *device); void block_dev_free(block_device_t *device); void *block_dev_mount(const char *device, const char *driver_name); void block_dev_print_info(); #endif //NEW_KERNEL_BLOCKDEV_H