vbos/kernel/block.c
Michael Shaw fc0720b118 ahci: add block operations
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-13 00:03:13 -04:00

36 lines
913 B
C

/* SPDX-License-Identifier: GPL-2.0-only */
#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);
}
ssize_t block_write(struct block_device *dev, char *buf, size_t offset, size_t n_blocks)
{
return dev->ops.write(dev, buf, offset, n_blocks);
}