dev: implement reading from block devices

reading from block devices is done using the block cache (bcache).
This cache stores sectors from a block device in pages of memory
marked as 'cached', which will allow them to be reclaimed when
memory pressure is high (TODO).

while block device drivers implement callbacks allowing reading/writing
at block-granularity, the device subsystem uses the block cache to
implement reading/writing at byte-granularity in a driver-agnostic way.

block drivers can disable the block cache for their devices, but this
will require that any clients communicate with the devices at
block-granularity.

also added an offset parameter to device and object read/write functions/callbacks.
This commit is contained in:
2023-07-09 21:58:40 +01:00
parent 53440653f2
commit 3233169f25
14 changed files with 435 additions and 52 deletions

View File

@@ -132,13 +132,13 @@ struct object *object_header(void *p)
return obj;
}
kern_status_t object_read(struct object *obj, void *p, size_t max,
size_t *nr_read, socks_flags_t flags)
kern_status_t object_read(struct object *obj, void *p, size_t offset,
size_t max, size_t *nr_read, socks_flags_t flags)
{
kern_status_t status = KERN_UNSUPPORTED;
if (obj->ob_type->ob_ops.read) {
status = obj->ob_type->ob_ops.read(obj, p, &max, flags);
status = obj->ob_type->ob_ops.read(obj, p, offset, &max, flags);
} else {
max = 0;
}
@@ -150,13 +150,13 @@ kern_status_t object_read(struct object *obj, void *p, size_t max,
return status;
}
kern_status_t object_write(struct object *obj, const void *p, size_t max,
size_t *nr_written, socks_flags_t flags)
kern_status_t object_write(struct object *obj, const void *p, size_t offset,
size_t max, size_t *nr_written, socks_flags_t flags)
{
kern_status_t status = KERN_UNSUPPORTED;
if (obj->ob_type->ob_ops.write) {
status = obj->ob_type->ob_ops.write(obj, p, &max, flags);
status = obj->ob_type->ob_ops.write(obj, p, offset, &max, flags);
}
return status;