devfs: alloc devfs_dev_info struct for each dev
This commit is contained in:
parent
3b247ad5e9
commit
6d67d7fbfe
3 changed files with 22 additions and 19 deletions
|
|
@ -26,9 +26,10 @@ static struct {
|
||||||
size_t l_resize_cols;
|
size_t l_resize_cols;
|
||||||
} console;
|
} console;
|
||||||
|
|
||||||
static struct devfs_dev_ops console_dev_ops = {
|
static struct devfs_dev_info console_dev_ops = {
|
||||||
.read = (devfs_dev_ops_read)console_read_dev,
|
.dev = NULL,
|
||||||
.write = (devfs_dev_ops_write)console_write_dev,
|
.read = console_read_dev,
|
||||||
|
.write = console_write_dev,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool is_printable(char c)
|
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);
|
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);
|
return console_read(buf, count);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
fs/devfs.c
20
fs/devfs.c
|
|
@ -6,16 +6,12 @@
|
||||||
#include <fs/devfs.h>
|
#include <fs/devfs.h>
|
||||||
|
|
||||||
static struct fs *devfs;
|
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)
|
static int devfs_read(struct vnode *vnode, void *buf, size_t offset, size_t size)
|
||||||
{
|
{
|
||||||
if (!vnode->priv_data)
|
if (!vnode->priv_data)
|
||||||
return -EINVAL;
|
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);
|
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)
|
if (!vnode->priv_data)
|
||||||
return -EINVAL;
|
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);
|
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;
|
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)
|
if (!name || !ops)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -114,7 +110,15 @@ struct fs *devfs_init()
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
for (int i = 0; i < n; i++) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,14 @@
|
||||||
|
|
||||||
#include <kernel/common.h>
|
#include <kernel/common.h>
|
||||||
|
|
||||||
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 vnode;
|
||||||
struct devfs_dev_ops {
|
struct devfs_dev_info {
|
||||||
devfs_dev_ops_write write;
|
void *dev;
|
||||||
devfs_dev_ops_read read;
|
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();
|
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_ */
|
#endif /* _DEVFS_H_ */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue