summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-17 16:03:43 -0400
committerIan Moffett <ian@osmora.org>2025-10-17 16:08:06 -0400
commit93ffb11b4728c1dfe5415d9805f1acf3bce7bb94 (patch)
tree09c85657f6b0ff0797930538263c342198162e0d /src
parent6502aae76e88e552281fa9c920dcc22cd4a836f5 (diff)
kern: tmpfs: Add tmpfs write callback
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r--src/sys/fs/tmpfs.c53
1 files changed, 52 insertions, 1 deletions
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 = {