ahci: add block operations

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-13 00:02:22 -04:00
commit fc0720b118
5 changed files with 60 additions and 9 deletions

View file

@ -2,6 +2,29 @@
#include <kernel/common.h>
#include <kernel/block.h>
#include <lib/string.h>
#include <fs/devfs.h>
int block_device_register(char *name, size_t lba_start, struct block_ops *ops, struct block_device **out)
{
struct block_device *ret = kzalloc(sizeof(struct block_device), ALLOC_KERN);
if (!ret)
return -ENOMEM;
ret->lba_start = lba_start;
strncpy(ret->name, name, sizeof(ret->name) - 1);
*out = ret;
memcpy(ops, &ret->ops, sizeof(struct block_ops));
dirent_t *dirent;
int res = devfs_insert_device_blk(ret->name, ret, &dirent);
return 0;
}
ssize_t block_read(struct block_device *dev, char *buf, size_t offset, size_t n_blocks)
{
return dev->ops.read(dev, buf, offset, n_blocks);