From 002bdd193d3454147fe4b7e8dfd4eecfa08d05bc Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 14 May 2024 00:07:14 -0400 Subject: kernel: devfs: Add cdev_read() Signed-off-by: Ian Moffett --- sys/fs/devfs.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'sys/fs') diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c index 6e8efc9..79606eb 100644 --- a/sys/fs/devfs.c +++ b/sys/fs/devfs.c @@ -63,6 +63,17 @@ node_from_name(const char *name) return NULL; } +static int +cdev_read(struct device *dev, struct device_node *node, struct sio_txn *sio) +{ + size_t n_bytes; + + spinlock_acquire(&node->lock); + n_bytes = dev->read(dev, sio); + spinlock_release(&node->lock); + return n_bytes; +} + static int blkdev_read(struct device *dev, struct device_node *node, struct sio_txn *sio) { @@ -139,7 +150,11 @@ vop_read(struct vnode *vp, struct sio_txn *sio) node = vp->data; dev = device_fetch(node->major, node->minor); - return blkdev_read(dev, node, sio); + + if (dev->blocksize > 1) + return blkdev_read(dev, node, sio); + + return cdev_read(dev, node, sio); } static int -- cgit v1.2.3