From 93ffb11b4728c1dfe5415d9805f1acf3bce7bb94 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 17 Oct 2025 16:03:43 -0400 Subject: kern: tmpfs: Add tmpfs write callback Signed-off-by: Ian Moffett --- src/sys/fs/tmpfs.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'src/sys') diff --git a/src/sys/fs/tmpfs.c b/src/sys/fs/tmpfs.c index 4a5c607..afc29b0 100644 --- a/src/sys/fs/tmpfs.c +++ b/src/sys/fs/tmpfs.c @@ -232,6 +232,56 @@ tmpfs_mount(struct fs_info *fip, struct mount_args *margs) return 0; } +/* + * Write to the filesystem + */ +static ssize_t +tmpfs_write(struct vop_rw_data *data) +{ + struct vnode *vp; + struct tmpfs_node *np; + char *dest; + void *p; + size_t node_len, len; + size_t overflow_window; + + if (data == NULL) { + return -EINVAL; + } + + if ((vp = data->vp) == NULL) { + return -EIO; + } + + /* We need the vnode for lengths */ + if ((np = vp->data) == NULL) { + return -EIO; + } + + /* + * Check if there is going to be any overflows + * and if so, get the overflow window and expand + * the buffer by it. + */ + len = data->len; + if ((len + data->off) > np->len) { + overflow_window = (len + data->off) - np->len; + np->len += overflow_window + 1; + + p = np->data; + np->data = krealloc(np->data, np->len); + if (np->data == NULL) { + np->data = p; + return -ENOMEM; + } + } + + node_len = np->len; + dest = np->data + data->off; + memcpy(dest, data->data, len); + return len; +} + static int tmpfs_reclaim(struct vnode *vp, int flags) { @@ -241,7 +291,8 @@ tmpfs_reclaim(struct vnode *vp, int flags) static struct vop tmpfs_vops = { .lookup = tmpfs_lookup, .create = tmpfs_create, - .reclaim = tmpfs_reclaim + .reclaim = tmpfs_reclaim, + .write = tmpfs_write }; struct vfsops g_tmpfs_vfsops = { -- cgit v1.2.3