feat: implemented errno, strtol. Started ustar. Reformatted headers and

code. Added some self-tests. Started prepwork for vfs.
This commit is contained in:
2021-03-14 21:14:22 +01:00
parent 586b8191b4
commit 77c8dca72a
39 changed files with 504 additions and 60 deletions

View File

@@ -15,7 +15,7 @@
#define MAX_BLOCK_DEVS 64
int last_block_dev = 0;
block_device block_devices[MAX_BLOCK_DEVS] = {0};
block_device_t block_devices[MAX_BLOCK_DEVS] = {0};
extern struct block_dev_driver __start_block_dev_driver[];
extern struct block_dev_driver __stop_block_dev_driver[];
@@ -25,12 +25,12 @@ extern struct block_dev_driver __stop_block_dev_driver[];
semaphore_t *block_semaphore;
bool blockdev_task_running = false;
uint8_t block_dev_register(block_device *device) {
uint8_t block_dev_register(block_device_t *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));
memcpy((uint8_t *) &block_devices[last_block_dev++], (const uint8_t *) device, sizeof(block_device_t));
if (blockdev_task_running) {
semaphore_signal(block_semaphore);
@@ -38,7 +38,7 @@ uint8_t block_dev_register(block_device *device) {
return BLOCK_DEV_REGISTER_OK;
}
void block_dev_free(block_device *device) {
void block_dev_free(block_device_t *device) {
//todo
k_panics("block dev free not supported");
}
@@ -51,6 +51,43 @@ int block_dev_num_not_scanned() {
return not_scanned;
}
bool block_dev_mount(char *identifier, char *driver_name) {
bool result = true;
block_device_t *device = NULL;
for (int i = 0; i < last_block_dev; ++i) {
if (strncmp(block_devices[i].identifier, identifier, 16) == 0) {
device = &block_devices[i];
}
}
if (identifier == NULL) {
result = false;
goto _end;
}
struct block_dev_driver *driver = NULL;
for (size_t j = 0; j < NUM_DRIVERS; ++j) {
if (strncmp(DRIVER(j)->name, driver_name, 16) == 0) {
driver = DRIVER(j);
}
}
if (driver == NULL) {
result = false;
goto _end;
}
uint8_t *lba0 = malloc(device->block_size);
uint8_t read_result = device->access(device, BLOCK_DEV_DIRECTION_READ, 0, 1, lba0);
if (read_result != BLOCK_DEV_ACCESS_OK) {
result = false;
goto _access_fail;
}
if (driver->check_device(device, lba0) != BLOCK_DEV_DRIVER_CHECK_OK) {
result = false;
}
_access_fail:
free(lba0);
_end:
return result;
}
void block_dev_scan() {
int c_last_block_dev = last_block_dev;
for (int i = 0; i < c_last_block_dev; ++i) {
@@ -62,9 +99,14 @@ void block_dev_scan() {
goto _block_dev_scan_free;
}
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 (DRIVER(j)->flags.root_only && !block_devices[i].flags.root_device) continue;
// only partitioning drivers are automatically assigned
if (!DRIVER(i)->flags.partitioning) {
continue;
}
// only root devices have partitions
if (!block_devices[i].flags.root_device) {
continue;
}
// let the driver test the disk
uint8_t driver_result = DRIVER(j)->check_device(&block_devices[i], lba0);