feat: rank drivers at compile time
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <tasks/task.h>
|
||||
#include <tasks/locking.h>
|
||||
#include <attributes.h>
|
||||
#include <libc/sort.h>
|
||||
#include "blockdev.h"
|
||||
|
||||
#define MAX_BLOCK_DEVS 64
|
||||
@@ -80,21 +79,6 @@ void block_dev_scan() {
|
||||
}
|
||||
}
|
||||
|
||||
int block_dev_driver_comp(const void *a, const void *b) {
|
||||
int rank_a = ((struct block_dev_driver *) a)->rank;
|
||||
int rank_b = ((struct block_dev_driver *) b)->rank;
|
||||
if (rank_a > rank_b) {
|
||||
return 1;
|
||||
} else if (rank_a < rank_b) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void block_dev_pre_init() {
|
||||
qsort(DRIVER(0), NUM_DRIVERS, sizeof(struct block_dev_driver), block_dev_driver_comp);
|
||||
}
|
||||
|
||||
void noreturn block_dev_task(void *data) {
|
||||
while (true) {
|
||||
semaphore_wait(block_semaphore);
|
||||
|
||||
@@ -34,7 +34,6 @@ typedef uint8_t (*block_device_access)(const block_device *device, uint8_t direc
|
||||
|
||||
struct block_dev_driver {
|
||||
char name[16];
|
||||
uint16_t rank;
|
||||
struct {
|
||||
uint8_t root_only: 1;
|
||||
} flags;
|
||||
@@ -42,7 +41,7 @@ struct block_dev_driver {
|
||||
block_device_driver_free free_device;
|
||||
} __attribute__((__aligned__(STRUCT_ALIGNMENT)));
|
||||
|
||||
#define BLOCK_DEV_DRIVER(data...) GENERIC_DRIVER(block_dev_driver, data)
|
||||
#define BLOCK_DEV_DRIVER(order) GENERIC_DRIVER(block_dev_driver, order)
|
||||
|
||||
typedef struct block_device {
|
||||
struct {
|
||||
@@ -65,8 +64,6 @@ uint8_t block_dev_register(block_device *device);
|
||||
|
||||
void block_dev_free(block_device *device);
|
||||
|
||||
void block_dev_pre_init();
|
||||
|
||||
void block_dev_start_task();
|
||||
|
||||
void block_dev_print_info();
|
||||
|
||||
@@ -193,11 +193,10 @@ get_fat_table_value(uint8_t fat_type, const uint8_t *fat_table, uint32_t active_
|
||||
return result;
|
||||
}
|
||||
|
||||
BLOCK_DEV_DRIVER(
|
||||
BLOCK_DEV_DRIVER(900) = {
|
||||
.name = "fat",
|
||||
.rank = 10000,
|
||||
.check_device = fat_check_device,
|
||||
.free_device = NULL, // todo
|
||||
);
|
||||
};
|
||||
|
||||
// steal validation code from here https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/fs/fat/inode.c#L1456
|
||||
@@ -100,10 +100,9 @@ void mbr_read_from_ide(uint8_t ide_drive) {
|
||||
free(mbr_data);
|
||||
}
|
||||
|
||||
BLOCK_DEV_DRIVER(
|
||||
BLOCK_DEV_DRIVER(200) = {
|
||||
.name = "mbr",
|
||||
.rank = 100,
|
||||
.flags.root_only = 1,
|
||||
.check_device = mbr_check_device,
|
||||
.free_device = NULL, // todo
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user