fat_io_lib finally works, implement virtual partition devices, manage devices via string keys
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m35s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m35s
This commit is contained in:
@@ -1,28 +1,51 @@
|
||||
#include <device/device.h>
|
||||
#include <device/dos.h>
|
||||
#include <device/partdrv.h>
|
||||
#include <device/partitions.h>
|
||||
#include <device/ramdrv.h>
|
||||
#include <device/terminal.h>
|
||||
#include <kb_device.h>
|
||||
#include <devices.h>
|
||||
#include <id/id_alloc.h>
|
||||
#include <libk/align.h>
|
||||
#include <libk/fieldlengthof.h>
|
||||
#include <libk/hash.h>
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <limine/requests.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <ramdisk_device.h>
|
||||
#include <status.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <terminal_device.h>
|
||||
#include <xdrv_device.h>
|
||||
|
||||
#if defined(__x86_64__)
|
||||
#include <device/ps2_kb.h>
|
||||
#endif
|
||||
|
||||
static struct rb_node_link* device_tree = NULL;
|
||||
static spin_lock_t device_tree_lock;
|
||||
struct device_table {
|
||||
struct hash_node_link* device_buckets[1024];
|
||||
spin_lock_t lock;
|
||||
};
|
||||
|
||||
struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
||||
static struct device_table device_table;
|
||||
|
||||
struct device* device_find (const char* key) {
|
||||
struct hash_node_link* found_link = NULL;
|
||||
size_t key_len = strlen_null (key);
|
||||
uint32_t hash = hash_fnv32 (key, key_len);
|
||||
|
||||
spin_lock (&device_table.lock);
|
||||
hash_find (&device_table, key, key_len, hash, lengthof (device_table.device_buckets),
|
||||
device_buckets, struct device, device_table_link, key, found_link);
|
||||
spin_unlock (&device_table.lock);
|
||||
|
||||
if (found_link == NULL)
|
||||
return NULL;
|
||||
|
||||
return hash_entry (found_link, struct device, device_table_link);
|
||||
}
|
||||
|
||||
struct device* device_create (const char* key, device_op_func_t* ops, size_t ops_len,
|
||||
device_init_func_t init, device_fini_func_t fini, void* arg) {
|
||||
if (ops_len >= fieldlengthof (struct device, ops))
|
||||
return NULL;
|
||||
@@ -34,9 +57,9 @@ struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
||||
|
||||
memset (device, 0, sizeof (*device));
|
||||
|
||||
device->id = id;
|
||||
device->init = init;
|
||||
device->fini = fini;
|
||||
memcpy (device->key, key, strlen_null (key));
|
||||
|
||||
if (ops != NULL)
|
||||
memcpy (device->ops, ops, ops_len * sizeof (device_op_func_t));
|
||||
@@ -46,32 +69,16 @@ struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
spin_lock (&device_tree_lock);
|
||||
rbtree_insert (struct device, &device_tree, &device->device_tree_link, device_tree_link, id);
|
||||
spin_unlock (&device_tree_lock);
|
||||
uint32_t device_hash = hash_fnv32 (device->key, strlen_null (device->key));
|
||||
|
||||
return device;
|
||||
}
|
||||
spin_lock (&device_table.lock);
|
||||
|
||||
void device_delete (struct device* device) {
|
||||
spin_lock (&device_tree_lock);
|
||||
spin_lock (&device->lock);
|
||||
hash_insert (&device_table, &device->device_table_link, device_hash,
|
||||
lengthof (device_table.device_buckets), device_buckets);
|
||||
|
||||
rbtree_delete (&device_tree, &device->device_tree_link);
|
||||
spin_unlock (&device_table.lock);
|
||||
|
||||
spin_unlock (&device->lock);
|
||||
spin_unlock (&device_tree_lock);
|
||||
|
||||
device->fini (device);
|
||||
free (device);
|
||||
}
|
||||
|
||||
struct device* device_find (int id) {
|
||||
struct device* device = NULL;
|
||||
|
||||
spin_lock (&device_tree_lock);
|
||||
rbtree_find (struct device, &device_tree, id, device, device_tree_link, id);
|
||||
spin_unlock (&device_tree_lock);
|
||||
DEBUG ("Created device %s\n", device->key);
|
||||
|
||||
return device;
|
||||
}
|
||||
@@ -80,7 +87,7 @@ 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);
|
||||
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL);
|
||||
}
|
||||
|
||||
void ramdisk_device_init (void) {
|
||||
@@ -89,6 +96,7 @@ void ramdisk_device_init (void) {
|
||||
[XDRV_GET_SECTOR_SIZE] = &ramdrv_get_sector_size,
|
||||
[XDRV_GET_DEVICE_TYPE] = &ramdrv_get_device_type,
|
||||
[XDRV_READ] = &ramdrv_read,
|
||||
[XDRV_WRITE] = &ramdrv_write,
|
||||
};
|
||||
|
||||
struct limine_module_response* module = limine_module_request.response;
|
||||
@@ -105,10 +113,43 @@ void ramdisk_device_init (void) {
|
||||
|
||||
struct ramdrv_init init = {
|
||||
.total_size = file->size,
|
||||
.sector_size = 1024,
|
||||
.sector_size = 512,
|
||||
.buffer = file->address,
|
||||
};
|
||||
device_create (RAMDISK_DEVICE, ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
|
||||
device_create ("RD", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
|
||||
}
|
||||
|
||||
void vdisk_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,
|
||||
[XDRV_WRITE] = &ramdrv_write,
|
||||
};
|
||||
|
||||
struct ramdrv_init init = {
|
||||
.total_size = 1024 * 1024 * 50,
|
||||
.sector_size = 512,
|
||||
};
|
||||
|
||||
struct dos_mbr mbr;
|
||||
memset (&mbr, 0, sizeof (mbr));
|
||||
|
||||
mbr.valid_sign[0] = 0x55;
|
||||
mbr.valid_sign[1] = 0xAA;
|
||||
mbr.ptes[0].start_lba = 0;
|
||||
mbr.ptes[0].sector_count = div_align_up (init.total_size, init.sector_size);
|
||||
|
||||
struct device* vdisk =
|
||||
device_create ("VD", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
|
||||
|
||||
size_t sector = 0;
|
||||
size_t sector_count = 1;
|
||||
|
||||
spin_lock (&vdisk->lock);
|
||||
device_op (vdisk, XDRV_WRITE, NULL, NULL, §or, §or_count, &mbr);
|
||||
spin_unlock (&vdisk->lock);
|
||||
}
|
||||
|
||||
#if defined(__x86_64__)
|
||||
@@ -116,13 +157,16 @@ 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);
|
||||
device_create ("KB", ops, lengthof (ops), &ps2kb_init, &ps2kb_fini, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void devices_init (void) {
|
||||
memset (&device_table, 0, sizeof (device_table));
|
||||
|
||||
terminal_device_init ();
|
||||
ramdisk_device_init ();
|
||||
vdisk_device_init ();
|
||||
|
||||
#if defined(__x86_64__)
|
||||
ps2kb_device_init ();
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#ifndef _KERNEL_DEVICE_DEVICE_H
|
||||
#define _KERNEL_DEVICE_DEVICE_H
|
||||
|
||||
#include <libk/hash.h>
|
||||
#include <libk/list.h>
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
#define DEVICES_MAX 1024
|
||||
|
||||
#define device_op1(d, op, proc, rctx, a1, a2, a3, a4, ...) \
|
||||
(d)->ops[(op)]((d), (proc), (rctx), (void*)(a1), (void*)(a2), (void*)(a3), (void*)(a4))
|
||||
|
||||
@@ -24,19 +26,20 @@ typedef bool (*device_init_func_t) (struct device* device, void* arg);
|
||||
typedef void (*device_fini_func_t) (struct device* device);
|
||||
|
||||
struct device {
|
||||
int id;
|
||||
char key[0x100];
|
||||
device_op_func_t ops[32];
|
||||
spin_lock_t lock;
|
||||
struct rb_node_link device_tree_link;
|
||||
struct hash_node_link device_table_link;
|
||||
device_init_func_t init;
|
||||
device_fini_func_t fini;
|
||||
void* udata;
|
||||
};
|
||||
|
||||
struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
||||
struct device* device_create (const char* key, device_op_func_t* ops, size_t ops_len,
|
||||
device_init_func_t init, device_fini_func_t fini, void* arg);
|
||||
struct device* device_find (int id);
|
||||
void device_delete (struct device* device);
|
||||
|
||||
struct device* device_find (const char* key);
|
||||
|
||||
void devices_init (void);
|
||||
|
||||
#endif // _KERNEL_DEVICE_DEVICE_H
|
||||
|
||||
4
kernel/device/dos.h
Normal file
4
kernel/device/dos.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef _KERNEL_DEVICE_DOS_H
|
||||
#define _KERNEL_DEVICE_DOS_H
|
||||
|
||||
#endif // _KERNEL_DEVICE_DOS_H
|
||||
121
kernel/device/partdrv.c
Normal file
121
kernel/device/partdrv.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include <device/device.h>
|
||||
#include <device/partdrv.h>
|
||||
#include <devices.h>
|
||||
#include <libk/std.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
#include <status.h>
|
||||
|
||||
bool partdrv_init (struct device* device, void* arg) {
|
||||
struct partdrv_init* init = arg;
|
||||
|
||||
struct partdrv* partdrv = malloc (sizeof (*partdrv));
|
||||
|
||||
if (partdrv == NULL)
|
||||
return false;
|
||||
|
||||
partdrv->start_sector = init->start_sector;
|
||||
partdrv->super = init->super;
|
||||
partdrv->total_size = init->total_size;
|
||||
|
||||
device->udata = partdrv;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void partdrv_fini (struct device* device) {
|
||||
struct partdrv* partdrv = device->udata;
|
||||
|
||||
free (partdrv);
|
||||
}
|
||||
|
||||
int partdrv_read (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a4;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
struct partdrv* partdrv = device->udata;
|
||||
struct device* super = partdrv->super;
|
||||
|
||||
size_t sector = *(size_t*)a1 + partdrv->start_sector;
|
||||
size_t sector_count = *(size_t*)a2;
|
||||
uint8_t* buffer = a3;
|
||||
|
||||
spin_lock (&super->lock);
|
||||
int ret = device_op (super, XDRV_READ, NULL, NULL, §or, §or_count, buffer);
|
||||
spin_unlock (&super->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int partdrv_write (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a4;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
struct partdrv* partdrv = device->udata;
|
||||
struct device* super = partdrv->super;
|
||||
|
||||
size_t sector = *(size_t*)a1 + partdrv->start_sector;
|
||||
size_t sector_count = *(size_t*)a2;
|
||||
uint8_t* buffer = a3;
|
||||
|
||||
spin_lock (&super->lock);
|
||||
int ret = device_op (super, XDRV_WRITE, NULL, NULL, §or, §or_count, buffer);
|
||||
spin_unlock (&super->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int partdrv_get_device_type (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)device, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
int* device_type = (int*)a1;
|
||||
|
||||
*device_type = XDRV_TYPE_PARTDRV;
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int partdrv_get_sector_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
size_t* secsize = (size_t*)a1;
|
||||
|
||||
struct partdrv* partdrv = device->udata;
|
||||
|
||||
spin_lock (&partdrv->super->lock);
|
||||
device_op (partdrv->super, XDRV_GET_SECTOR_SIZE, NULL, NULL, secsize);
|
||||
spin_unlock (&partdrv->super->lock);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int partdrv_get_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
size_t* size = (size_t*)a1;
|
||||
|
||||
struct partdrv* partdrv = device->udata;
|
||||
|
||||
*size = partdrv->total_size;
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
41
kernel/device/partdrv.h
Normal file
41
kernel/device/partdrv.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _KERNEL_DEVICE_PARTDRV_H
|
||||
#define _KERNEL_DEVICE_PARTDRV_H
|
||||
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
|
||||
struct device;
|
||||
|
||||
struct partdrv_init {
|
||||
struct device* super;
|
||||
size_t start_sector;
|
||||
size_t total_size;
|
||||
};
|
||||
|
||||
struct partdrv {
|
||||
struct device* super;
|
||||
size_t start_sector;
|
||||
size_t total_size;
|
||||
};
|
||||
|
||||
bool partdrv_init (struct device* device, void* arg);
|
||||
|
||||
void partdrv_fini (struct device* device);
|
||||
|
||||
int partdrv_read (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4);
|
||||
|
||||
int partdrv_write (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4);
|
||||
|
||||
int partdrv_get_device_type (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
int partdrv_get_sector_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
int partdrv_get_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
#endif // _KERNEL_DEVICE_PARTDRV_H
|
||||
65
kernel/device/partitions.c
Normal file
65
kernel/device/partitions.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <device/device.h>
|
||||
#include <device/partdrv.h>
|
||||
#include <device/partitions.h>
|
||||
#include <devices.h>
|
||||
#include <libk/fieldsizeof.h>
|
||||
#include <libk/lengthof.h>
|
||||
#include <libk/printf.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <status.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
static int device_probe_partitions_dos (struct device* device) {
|
||||
struct dos_mbr mbr;
|
||||
memset (&mbr, 0, sizeof (mbr));
|
||||
size_t sector = 0;
|
||||
size_t sector_count = 1;
|
||||
size_t sector_size;
|
||||
|
||||
device_op_func_t ops[] = {
|
||||
[XDRV_GET_SIZE] = &partdrv_get_size,
|
||||
[XDRV_GET_SECTOR_SIZE] = &partdrv_get_sector_size,
|
||||
[XDRV_GET_DEVICE_TYPE] = &partdrv_get_device_type,
|
||||
[XDRV_READ] = &partdrv_read,
|
||||
[XDRV_WRITE] = &partdrv_write,
|
||||
};
|
||||
|
||||
spin_lock (&device->lock);
|
||||
|
||||
device_op (device, XDRV_GET_SECTOR_SIZE, NULL, NULL, §or_size);
|
||||
|
||||
int ret = device_op (device, XDRV_READ, NULL, NULL, §or, §or_count, &mbr);
|
||||
|
||||
if (ret < 0) {
|
||||
spin_unlock (&device->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!(mbr.valid_sign[0] == 0x55 && mbr.valid_sign[1] == 0xAA)) {
|
||||
spin_unlock (&device->lock);
|
||||
return -ST_PARTITION_ERROR;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lengthof (mbr.ptes); i++) {
|
||||
struct dos_pte* pte = &mbr.ptes[i];
|
||||
|
||||
struct partdrv_init init = {
|
||||
.start_sector = pte->start_lba,
|
||||
.total_size = pte->sector_count * sector_size,
|
||||
.super = device,
|
||||
};
|
||||
|
||||
char key[fieldsizeof (struct device, key)];
|
||||
memset (key, 0, sizeof (key));
|
||||
snprintf (key, sizeof (key), "%sp%zu", device->key, i);
|
||||
|
||||
device_create (key, ops, lengthof (ops), &partdrv_init, &partdrv_fini, &init);
|
||||
}
|
||||
|
||||
spin_unlock (&device->lock);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int device_probe_partitions (struct device* device) { return device_probe_partitions_dos (device); }
|
||||
27
kernel/device/partitions.h
Normal file
27
kernel/device/partitions.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _KERNEL_DEVICE_PARTITIONS_H
|
||||
#define _KERNEL_DEVICE_PARTITIONS_H
|
||||
|
||||
#include <aux/compiler.h>
|
||||
#include <device/device.h>
|
||||
#include <libk/std.h>
|
||||
|
||||
struct dos_pte {
|
||||
uint8_t drive_attrs;
|
||||
uint8_t chs_start_addr[3];
|
||||
uint8_t part_type;
|
||||
uint8_t chs_last_sect_addr[3];
|
||||
uint32_t start_lba;
|
||||
uint32_t sector_count;
|
||||
} PACKED;
|
||||
|
||||
struct dos_mbr {
|
||||
uint8_t boot_code[440];
|
||||
uint8_t signature[4];
|
||||
uint8_t resv[2];
|
||||
struct dos_pte ptes[4];
|
||||
uint8_t valid_sign[2];
|
||||
} PACKED;
|
||||
|
||||
int device_probe_partitions (struct device* device);
|
||||
|
||||
#endif // _KERNEL_DEVICE_PARTITIONS_H
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <amd64/io.h>
|
||||
#include <device/device.h>
|
||||
#include <device/ps2_kb.h>
|
||||
#include <devices.h>
|
||||
#include <irq/irq.h>
|
||||
#include <kb_device.h>
|
||||
#include <libk/ringbuffer.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/capability.h>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include <device/device.h>
|
||||
#include <device/partitions.h>
|
||||
#include <device/ramdrv.h>
|
||||
#include <devices.h>
|
||||
#include <libk/align.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <status.h>
|
||||
#include <sys/debug.h>
|
||||
#include <xdrv_device.h>
|
||||
|
||||
bool ramdrv_init (struct device* device, void* arg) {
|
||||
struct ramdrv_init* init = arg;
|
||||
@@ -45,7 +46,7 @@ void ramdrv_fini (struct device* device) {
|
||||
|
||||
int ramdrv_get_device_type (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)device, (void)a2, (void)a3, (void)a4;
|
||||
(void)proc, (void)rctx, (void)device, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -59,7 +60,7 @@ int ramdrv_get_device_type (struct device* device, struct proc* proc, struct res
|
||||
|
||||
int ramdrv_get_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)a2, (void)a3, (void)a4;
|
||||
(void)proc, (void)rctx, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -75,7 +76,7 @@ int ramdrv_get_size (struct device* device, struct proc* proc, struct reschedule
|
||||
|
||||
int ramdrv_get_sector_size (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4) {
|
||||
(void)a2, (void)a3, (void)a4;
|
||||
(void)proc, (void)rctx, (void)a2, (void)a3, (void)a4;
|
||||
|
||||
if (a1 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
@@ -108,3 +109,23 @@ int ramdrv_read (struct device* device, struct proc* proc, struct reschedule_ctx
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int ramdrv_write (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4) {
|
||||
(void)proc, (void)rctx, (void)a4;
|
||||
|
||||
if (a1 == NULL || a2 == NULL || a3 == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
size_t sector = *(size_t*)a1;
|
||||
size_t sector_count = *(size_t*)a2;
|
||||
uint8_t* buffer = a3;
|
||||
|
||||
struct ramdrv* ramdrv = device->udata;
|
||||
size_t pos = sector * ramdrv->sector_size;
|
||||
size_t size = sector_count * ramdrv->sector_size;
|
||||
|
||||
memcpy ((void*)(((uintptr_t)ramdrv->buffer) + pos), buffer, size);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <proc/reschedule.h>
|
||||
|
||||
struct device;
|
||||
struct device_op_ctx;
|
||||
|
||||
struct ramdrv_init {
|
||||
size_t total_size;
|
||||
@@ -28,6 +27,9 @@ void ramdrv_fini (struct device* device);
|
||||
int ramdrv_read (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4);
|
||||
|
||||
int ramdrv_write (struct device* device, struct proc* proc, struct reschedule_ctx* rctx, void* a1,
|
||||
void* a2, void* a3, void* a4);
|
||||
|
||||
int ramdrv_get_device_type (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
c += device/device.c \
|
||||
device/terminal.c \
|
||||
device/ramdrv.c
|
||||
device/ramdrv.c \
|
||||
device/partdrv.c \
|
||||
device/partitions.c
|
||||
|
||||
o += device/device.o \
|
||||
device/terminal.o \
|
||||
device/ramdrv.o
|
||||
device/ramdrv.o \
|
||||
device/partdrv.o \
|
||||
device/partitions.o
|
||||
|
||||
ifeq ($(platform),amd64)
|
||||
c += device/ps2_kb.c
|
||||
|
||||
Reference in New Issue
Block a user