feat: reformatted driver code and linkage. Some optimizations
This commit is contained in:
@@ -12,34 +12,28 @@
|
||||
#include "blockdev.h"
|
||||
|
||||
#define MAX_BLOCK_DEVS 64
|
||||
#define MAX_BLOCK_DRIVERS 64
|
||||
|
||||
int last_block_dev = 0;
|
||||
block_device block_devices[MAX_BLOCK_DEVS];
|
||||
int last_block_driver = 0;
|
||||
block_dev_driver block_dev_drivers[MAX_BLOCK_DRIVERS];
|
||||
block_device block_devices[MAX_BLOCK_DEVS] = {0};
|
||||
|
||||
extern struct block_dev_driver __start_block_dev_driver[];
|
||||
extern struct block_dev_driver __stop_block_dev_driver[];
|
||||
#define NUM_DRIVERS ((size_t)(__stop_block_dev_driver - __start_block_dev_driver))
|
||||
#define DRIVER(i) ((__start_block_dev_driver) + (i))
|
||||
|
||||
semaphore_t *block_semaphore;
|
||||
bool blockdev_task_running = false;
|
||||
|
||||
uint8_t block_dev_register_driver(block_dev_driver *driver) {
|
||||
if (last_block_dev >= MAX_BLOCK_DEVS - 1) {
|
||||
return BLOCK_DEV_REGISTER_DRIVER_FULL;
|
||||
}
|
||||
|
||||
memcpy((uint8_t *) &block_dev_drivers[last_block_driver++], (const uint8_t *) driver, sizeof(block_dev_driver));
|
||||
return BLOCK_DEV_REGISTER_DRIVER_OK;
|
||||
}
|
||||
|
||||
uint8_t block_dev_register(block_device *device) {
|
||||
if (last_block_dev >= MAX_BLOCK_DEVS - 1) {
|
||||
return BLOCK_DEV_REGISTER_FULL;
|
||||
}
|
||||
|
||||
memcpy((uint8_t *) &block_devices[last_block_dev++], (const uint8_t *) device, sizeof(block_device));
|
||||
|
||||
if (blockdev_task_running) {
|
||||
semaphore_signal(block_semaphore);
|
||||
}
|
||||
|
||||
memcpy((uint8_t *) &block_devices[last_block_dev++], (const uint8_t *) device, sizeof(block_device));
|
||||
return BLOCK_DEV_REGISTER_OK;
|
||||
}
|
||||
|
||||
@@ -66,15 +60,15 @@ void block_dev_scan() {
|
||||
block_devices[i].flags.unreadable = 1;
|
||||
goto _block_dev_scan_free;
|
||||
}
|
||||
for (int j = 0; j < last_block_driver; ++j) {
|
||||
for (size_t j = 0; j < NUM_DRIVERS; ++j) {
|
||||
// validate if driver is appropriate at all
|
||||
// don't use a root device driver (i.e. mbr) for a non-root device
|
||||
if (block_dev_drivers[j].flags.root_only && !block_devices[i].flags.root_device) continue;
|
||||
if (DRIVER(j)->flags.root_only && !block_devices[i].flags.root_device) continue;
|
||||
|
||||
// let the driver test the disk
|
||||
uint8_t driver_result = block_dev_drivers[j].check_device(&block_devices[i], lba0);
|
||||
uint8_t driver_result = DRIVER(j)->check_device(&block_devices[i], lba0);
|
||||
if (driver_result == BLOCK_DEV_DRIVER_CHECK_OK) {
|
||||
block_devices[i].driver = &block_dev_drivers[j];
|
||||
block_devices[i].driver = DRIVER(j);
|
||||
block_devices[i].flags.driver_installed = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user