From 6074369de8b4406f4c3dec2e136cb5282d628810 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 15 Oct 2025 12:57:09 -0400 Subject: kern: vfs: Add vnode operation for reads Introduces a read callback wrapper implementation for vnodes to simplify file reading Signed-off-by: Ian Moffett --- src/sys/os/vfs_subr.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/sys/os/vfs_subr.c') diff --git a/src/sys/os/vfs_subr.c b/src/sys/os/vfs_subr.c index 8d5b032..47ed468 100644 --- a/src/sys/os/vfs_subr.c +++ b/src/sys/os/vfs_subr.c @@ -172,3 +172,32 @@ vop_write(struct vnode *vp, char *data, size_t len) rwdata.vp = vp; return vops->write(&rwdata); } + +ssize_t +vop_read(struct vnode *vp, char *data, size_t len) +{ + struct vop_rw_data rwdata; + struct vop *vops; + + if (vp == NULL || data == NULL) { + return -EINVAL; + } + + if (len == 0) { + return -EINVAL; + } + + /* Grab the virtual operations */ + if ((vops = vp->vops) == NULL) { + return -EIO; + } + + if (vops->read == NULL) { + return -ENOTSUP; + } + + rwdata.data = data; + rwdata.len = len; + rwdata.vp = vp; + return vops->read(&rwdata); +} -- cgit v1.2.3