summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-02-22 02:21:21 -0500
committerIan Moffett <ian@osmora.org>2025-02-22 02:21:21 -0500
commit34e8460892c06ebff138f23e42536f8cf9d13e78 (patch)
treee9089debefee1cbb218e6510eaf78bb9140ce5e5
parentd68537c1ca22d58f1c219d970d5aa462df9e0c6b (diff)
kernel: devfs: Add support for write()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/fs/devfs.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c
index 0589bbe..024239d 100644
--- a/sys/fs/devfs.c
+++ b/sys/fs/devfs.c
@@ -63,6 +63,22 @@ bdevsw_read(void *devsw, dev_t dev, struct sio_txn *sio)
return bdevsw->read(dev, sio, 0);
}
+static inline int
+cdevsw_write(void *devsw, dev_t dev, struct sio_txn *sio)
+{
+ struct cdevsw *cdevsw = devsw;
+
+ return cdevsw->write(dev, sio, 0);
+}
+
+static inline int
+bdevsw_write(void *devsw, dev_t dev, struct sio_txn *sio)
+{
+ struct bdevsw *bdevsw = devsw;
+
+ return bdevsw->write(dev, sio, 0);
+}
+
/*
* Get a devfs node by name.
*
@@ -174,6 +190,25 @@ devfs_read(struct vnode *vp, struct sio_txn *sio)
}
static int
+devfs_write(struct vnode *vp, struct sio_txn *sio)
+{
+ struct devfs_node *dnp;
+ void *devsw;
+
+ if ((dnp = vp->data) == NULL)
+ return -EIO;
+
+ devsw = dev_get(dnp->major, dnp->dev);
+
+ if (!dnp->is_block) {
+ return cdevsw_write(devsw, dnp->dev, sio);
+ }
+
+ /* Block device */
+ return bdevsw_write(devsw, dnp->dev, sio);
+}
+
+static int
devfs_init(struct fs_info *fip)
{
struct vnode *vp;
@@ -232,6 +267,7 @@ const struct vops g_devfs_vops = {
.lookup = devfs_lookup,
.reclaim = devfs_reclaim,
.read = devfs_read,
+ .write = devfs_write,
.getattr = devfs_getattr
};