summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-01 04:01:01 -0400
committerIan Moffett <ian@osmora.org>2025-07-01 04:04:17 -0400
commita64865a93fdb22dee230d57a0a3c684668545acd (patch)
treed84e80a98ddcc763d82b5ff99bbe2e428d6cd748
parentba76ec6d4eb0bac8af9a3a6c0e9f53e53eb8d3f3 (diff)
kernel: tmpfs: Store the *real* size in a node
The 'len' field within the tmpfs node stores the buffer length which is relative to the tmpfs block size. Introduce a real size which returns the amount of data actually present within those buffers. Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/fs/tmpfs.c14
-rw-r--r--sys/include/fs/tmpfs.h2
2 files changed, 12 insertions, 4 deletions
diff --git a/sys/fs/tmpfs.c b/sys/fs/tmpfs.c
index 50f2d74..5f8e531 100644
--- a/sys/fs/tmpfs.c
+++ b/sys/fs/tmpfs.c
@@ -211,6 +211,7 @@ tmpfs_create(struct vop_create_args *args)
root_np = TAILQ_FIRST(&root);
np->dirvp = dirvp;
np->type = TMPFS_REG;
+ np->real_size = 0;
memcpy(np->rpath, pcp, strlen(pcp) + 1);
TAILQ_INSERT_TAIL(&root_np->dirents, np, link);
@@ -269,6 +270,14 @@ tmpfs_write(struct vnode *vp, struct sio_txn *sio)
}
/*
+ * Bring up the real size if we are writing
+ * more bytes.
+ */
+ if (sio->offset >= np->real_size) {
+ np->real_size = sio->offset;
+ }
+
+ /*
* If the length to be written exceeds the residual byte
* count. We will try to expand the buffer by the page
* size. However, if this fails, we will split the write
@@ -315,12 +324,9 @@ tmpfs_read(struct vnode *vp, struct sio_txn *sio)
spinlock_acquire(&np->lock);
- if (sio->offset > np->len - 1) {
+ if (sio->offset > np->real_size) {
return -EINVAL;
}
- if ((sio->offset + sio->len) > np->len) {
- sio->len = np->len;
- }
buf = np->data;
memcpy(sio->buf, &buf[sio->offset], sio->len);
diff --git a/sys/include/fs/tmpfs.h b/sys/include/fs/tmpfs.h
index b2a5bbe..ca24060 100644
--- a/sys/include/fs/tmpfs.h
+++ b/sys/include/fs/tmpfs.h
@@ -53,6 +53,7 @@ struct tmpfs_node;
* @rpath: /tmp/ relative path (for lookups)
* @type: The tmpfs node type [one-to-one to vtype]
* @len: Length of buffer
+ * @real_size: Actual size of file
* @data: The backing file data
* @dirvp: Vnode of the parent node
* @vp: Vnode of the current node
@@ -62,6 +63,7 @@ struct tmpfs_node {
char rpath[PATH_MAX];
uint8_t type;
size_t len;
+ size_t real_size;
void *data;
struct vnode *dirvp;
struct vnode *vp;