From 732d6c11f39cb3d9646f8077a1df2b453659ddaa Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 7 Oct 2025 15:35:53 -0400 Subject: kern: vfs: Add write vop to vnodes Signed-off-by: Ian Moffett --- src/sys/include/os/vnode.h | 27 +++++++++++++++++++++++++++ src/sys/os/vfs_subr.c | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'src') diff --git a/src/sys/include/os/vnode.h b/src/sys/include/os/vnode.h index 354c73c..77459a1 100644 --- a/src/sys/include/os/vnode.h +++ b/src/sys/include/os/vnode.h @@ -66,12 +66,27 @@ struct vop_lookup_args { struct vnode **vpp; }; +/* + * Represents VOP data that can be used to read + * or write a file, etc + * + * @data: Buffer containing I/O data + * @len: Length of buffer + * @vp: Current vnode + */ +struct vop_rw_data { + void *data; + size_t len; + struct vnode *vp; +}; + /* * Represents operations that can be performed on * a specific vnode. These are implemented as callbacks */ struct vop { int(*lookup)(struct vop_lookup_args *args); + ssize_t(*write)(struct vop_rw_data *data); }; /* @@ -120,4 +135,16 @@ int vfs_valloc(struct vnode **resp, vtype_t type, int flags); */ int vfs_vrel(struct vnode *vp, int flags); +/* + * Wrapper for the vnode write callback + * + * @vp: Vnode to write to + * @data: Data to write + * @len: Length of bytes to write + * + * Returns the number of bytes written on success, otherwise + * a less than zero value on failure. + */ +ssize_t vop_write(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 64c7492..b82b683 100644 --- a/src/sys/os/vfs_subr.c +++ b/src/sys/os/vfs_subr.c @@ -143,3 +143,28 @@ vfs_cmp_cnt(const char *path) return cnt + 1; } + +ssize_t +vop_write(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; + } + + rwdata.data = data; + rwdata.len = len; + rwdata.vp = vp; + return vops->write(&rwdata); +} -- cgit v1.2.3