obj: add read() and write() object callbacks

This commit is contained in:
2023-05-14 21:11:32 +01:00
parent 0238008986
commit d02d05d922
10 changed files with 91 additions and 28 deletions

View File

@@ -9,13 +9,18 @@ static struct object *dev_folder = NULL;
static struct device *__root_device = NULL;
static struct device *__misc_device = NULL;
static kern_status_t device_object_destroy(struct object *);
static kern_status_t device_object_read(struct object *obj, void *, size_t *, socks_flags_t);
static kern_status_t device_object_write(struct object *obj, const void *, size_t *, socks_flags_t);
static kern_status_t device_object_query_name(struct object *, char out[OBJECT_NAME_MAX]);
static kern_status_t device_object_get_child_at(struct object *, size_t, struct object **);
static kern_status_t device_object_get_child_named(struct object *, const char *, struct object **);
static struct object_type device_type = {
.ob_name = "device",
.ob_size = sizeof(struct device),
.ob_ops = {
.read = device_object_read,
.write = device_object_write,
.destroy = device_object_destroy,
.query_name = device_object_query_name,
.get_at = device_object_get_child_at,
@@ -91,17 +96,17 @@ struct device *device_alloc(void)
return DEVICE_CAST(dev_object);
}
kern_status_t device_read(struct device *dev, void *buf, size_t size, size_t *bytes_read)
kern_status_t device_read(struct device *dev, void *buf, size_t size, size_t *bytes_read, socks_flags_t flags)
{
switch (dev->dev_type) {
case DEV_TYPE_INPUT:
return input_device_read(dev, buf, size, bytes_read);
return input_device_read(dev, buf, size, bytes_read, flags);
default:
return KERN_UNSUPPORTED;
}
}
kern_status_t device_write(struct device *dev, const void *buf, size_t size, size_t *bytes_written)
kern_status_t device_write(struct device *dev, const void *buf, size_t size, size_t *bytes_written, socks_flags_t flags)
{
return KERN_UNSUPPORTED;
}
@@ -111,6 +116,18 @@ struct device *cast_to_device(struct object *obj)
return DEVICE_CAST(obj);
}
static kern_status_t device_object_read(struct object *obj, void *p, size_t *count, socks_flags_t flags)
{
struct device *dev = DEVICE_CAST(obj);
return device_read(dev, p, *count, count, flags);
}
static kern_status_t device_object_write(struct object *obj, const void *p, size_t *count, socks_flags_t flags)
{
struct device *dev = DEVICE_CAST(obj);
return device_write(dev, p, *count, count, flags);
}
static kern_status_t device_object_destroy(struct object *obj)
{
return KERN_OK;