summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-15 12:57:09 -0400
committerIan Moffett <ian@osmora.org>2025-10-15 12:57:09 -0400
commit6074369de8b4406f4c3dec2e136cb5282d628810 (patch)
tree848e5b6f0894d4c861edde6200bc68d0b89be92c
parentd1181bb2e8dc918fcfedad55d3af558034df4a80 (diff)
kern: vfs: Add vnode operation for reads
Introduces a read callback wrapper implementation for vnodes to simplify file reading Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--src/sys/include/os/vnode.h13
-rw-r--r--src/sys/os/vfs_subr.c29
2 files changed, 42 insertions, 0 deletions
diff --git a/src/sys/include/os/vnode.h b/src/sys/include/os/vnode.h
index 77459a1..868e137 100644
--- a/src/sys/include/os/vnode.h
+++ b/src/sys/include/os/vnode.h
@@ -87,6 +87,7 @@ struct vop_rw_data {
struct vop {
int(*lookup)(struct vop_lookup_args *args);
ssize_t(*write)(struct vop_rw_data *data);
+ ssize_t(*read)(struct vop_rw_data *data);
};
/*
@@ -147,4 +148,16 @@ int vfs_vrel(struct vnode *vp, int flags);
*/
ssize_t vop_write(struct vnode *vp, char *data, size_t len);
+/*
+ * Wrapper for the read write callback
+ *
+ * @vp: Vnode to read from
+ * @data: Read data written here
+ * @len: Length of bytes to read
+ *
+ * Returns the number of bytes read on success, otherwise
+ * a less than zero value on failure.
+ */
+ssize_t vop_read(struct vnode *vp, char *data, size_t len);
+
#endif /* !_OS_VNODE_H_ */
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);
+}