diff --git a/dev/console.c b/dev/console.c index 354f503..b08eb0a 100644 --- a/dev/console.c +++ b/dev/console.c @@ -26,9 +26,10 @@ static struct { size_t l_resize_cols; } console; -static struct devfs_dev_ops console_dev_ops = { - .read = (devfs_dev_ops_read)console_read_dev, - .write = (devfs_dev_ops_write)console_write_dev, +static struct devfs_dev_info console_dev_ops = { + .dev = NULL, + .read = console_read_dev, + .write = console_write_dev, }; static bool is_printable(char c) @@ -174,7 +175,7 @@ ssize_t console_write_dev(void *dev, void *buf, size_t offset, size_t count) return console_write(buf, count); } -size_t console_read_dev(void *dev, void *buf, size_t offset, size_t count) +ssize_t console_read_dev(void *dev, void *buf, size_t offset, size_t count) { return console_read(buf, count); } diff --git a/fs/devfs.c b/fs/devfs.c index 9e3ecbb..b9c2ddd 100644 --- a/fs/devfs.c +++ b/fs/devfs.c @@ -6,16 +6,12 @@ #include static struct fs *devfs; -static struct devfs_dev_ops block_dev_ops = { - .read = (devfs_dev_ops_read)block_read, - .write = (devfs_dev_ops_write)block_write, -}; static int devfs_read(struct vnode *vnode, void *buf, size_t offset, size_t size) { if (!vnode->priv_data) return -EINVAL; - struct devfs_dev_ops *ops = vnode->priv_data; + struct devfs_dev_info *ops = vnode->priv_data; return ops->read(vnode->priv_data, buf, offset, size); } @@ -23,7 +19,7 @@ static int devfs_write(struct vnode *vnode, void *buf, size_t offset, size_t siz { if (!vnode->priv_data) return -EINVAL; - struct devfs_dev_ops *ops = vnode->priv_data; + struct devfs_dev_info *ops = vnode->priv_data; return ops->write(vnode->priv_data, buf, offset, size); } @@ -49,7 +45,7 @@ static int devfs_open_dir(struct fs *fs, struct vnode *out) return -EINVAL; } -int devfs_insert(struct vnode *dir, const char *name, uint32_t flags, struct devfs_dev_ops *ops) +int devfs_insert(struct vnode *dir, const char *name, uint32_t flags, struct devfs_dev_info *ops) { if (!name || !ops) return -EINVAL; @@ -114,7 +110,15 @@ struct fs *devfs_init() if (n > 0) { for (int i = 0; i < n; i++) { - devfs_insert(devfs->root, bdevs[i]->name, VFS_VNO_BLKDEV, &block_dev_ops); + struct devfs_dev_info *block_dev_info = kmalloc(sizeof(struct devfs_dev_info), ALLOC_KERN); + if (!block_dev_info) + goto out; + + block_dev_info->dev = &bdevs[i]; + block_dev_info->read = (void *)block_read; + block_dev_info->write = (void *)block_write; + + devfs_insert(devfs->root, bdevs[i]->name, VFS_VNO_BLKDEV, block_dev_info); } } diff --git a/include/fs/devfs.h b/include/fs/devfs.h index 2ebbcac..93db5fe 100644 --- a/include/fs/devfs.h +++ b/include/fs/devfs.h @@ -4,16 +4,14 @@ #include -typedef ssize_t (*devfs_dev_ops_write)(void *dev, void *buf, size_t offset, size_t size); -typedef ssize_t (*devfs_dev_ops_read)(void *dev, void *buf, size_t offset, size_t size); - struct vnode; -struct devfs_dev_ops { - devfs_dev_ops_write write; - devfs_dev_ops_read read; +struct devfs_dev_info { + void *dev; + ssize_t (*read)(void *dev, void *buf, size_t offset, size_t size); + ssize_t (*write)(void *dev, void *buf, size_t offset, size_t size); }; struct fs *devfs_init(); -int devfs_insert(struct vnode *dir, const char *name, uint32_t flags, struct devfs_dev_ops *ops); +int devfs_insert(struct vnode *dir, const char *name, uint32_t flags, struct devfs_dev_info *ops); #endif /* _DEVFS_H_ */