VFS mountpoint backing device system
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m24s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m24s
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#include <device/device.h>
|
||||
#include <device/ramdrv.h>
|
||||
#include <device/terminal.h>
|
||||
#include <libk/fieldlengthof.h>
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <limine/requests.h>
|
||||
#include <m/kb_device.h>
|
||||
#include <m/ramdisk_device.h>
|
||||
#include <m/terminal_device.h>
|
||||
#include <m/xdrv_device.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
@@ -18,7 +22,7 @@ static struct rb_node_link* device_tree = NULL;
|
||||
static spin_lock_t device_tree_lock;
|
||||
|
||||
struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
||||
bool (*init) (void* arg), void (*fini) (void), void* arg) {
|
||||
device_init_func_t init, device_fini_func_t fini, void* arg) {
|
||||
if (ops_len >= fieldlengthof (struct device, ops))
|
||||
return NULL;
|
||||
|
||||
@@ -36,7 +40,7 @@ struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
||||
if (ops != NULL)
|
||||
memcpy (device->ops, ops, ops_len * sizeof (device_op_func_t));
|
||||
|
||||
if (!device->init (arg)) {
|
||||
if (!device->init (device, arg)) {
|
||||
free (device);
|
||||
return NULL;
|
||||
}
|
||||
@@ -57,7 +61,8 @@ void device_delete (struct device* device) {
|
||||
spin_unlock (&device->lock);
|
||||
spin_unlock (&device_tree_lock);
|
||||
|
||||
device->fini ();
|
||||
device->fini (device);
|
||||
free (device);
|
||||
}
|
||||
|
||||
struct device* device_find (int id) {
|
||||
@@ -70,19 +75,55 @@ struct device* device_find (int id) {
|
||||
return device;
|
||||
}
|
||||
|
||||
void devices_init (void) {
|
||||
{
|
||||
device_op_func_t ops[] = {
|
||||
[TERMINAL_PUTSTR] = &terminal_putstr,
|
||||
};
|
||||
device_create (TERMINAL_DEVICE, ops, lengthof (ops), &terminal_init, &terminal_fini, NULL);
|
||||
void terminal_device_init (void) {
|
||||
device_op_func_t ops[] = {
|
||||
[TERMINAL_PUTSTR] = &terminal_putstr,
|
||||
};
|
||||
device_create (TERMINAL_DEVICE, ops, lengthof (ops), &terminal_init, &terminal_fini, NULL);
|
||||
}
|
||||
|
||||
void ramdisk_device_init (void) {
|
||||
device_op_func_t ops[] = {
|
||||
[XDRV_GET_SIZE] = &ramdrv_get_size,
|
||||
[XDRV_GET_SECTOR_SIZE] = &ramdrv_get_sector_size,
|
||||
[XDRV_GET_DEVICE_TYPE] = &ramdrv_get_device_type,
|
||||
[XDRV_READ] = &ramdrv_read,
|
||||
};
|
||||
|
||||
struct limine_module_response* module = limine_module_request.response;
|
||||
|
||||
const char* ramdisk_path = "/boot/mop3dist.tar";
|
||||
struct limine_file* file = NULL;
|
||||
|
||||
for (size_t i = 0; i < module->module_count; i++) {
|
||||
file = module->modules[i];
|
||||
|
||||
if (strncmp (file->path, ramdisk_path, strlen (ramdisk_path)) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
struct ramdrv_init init = {
|
||||
.total_size = file->size,
|
||||
.sector_size = 1024,
|
||||
.buffer = file->address,
|
||||
};
|
||||
device_create (RAMDISK_DEVICE, ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
|
||||
}
|
||||
|
||||
#if defined(__x86_64__)
|
||||
{
|
||||
device_op_func_t ops[] = {
|
||||
[KB_READ_KEY] = &ps2kb_read_key,
|
||||
};
|
||||
device_create (KB_DEVICE, ops, lengthof (ops), &ps2kb_init, &ps2kb_fini, NULL);
|
||||
}
|
||||
void ps2kb_device_init (void) {
|
||||
device_op_func_t ops[] = {
|
||||
[KB_READ_KEY] = &ps2kb_read_key,
|
||||
};
|
||||
device_create (KB_DEVICE, ops, lengthof (ops), &ps2kb_init, &ps2kb_fini, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void devices_init (void) {
|
||||
terminal_device_init ();
|
||||
ramdisk_device_init ();
|
||||
|
||||
#if defined(__x86_64__)
|
||||
ps2kb_device_init ();
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user