From a64865a93fdb22dee230d57a0a3c684668545acd Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 1 Jul 2025 04:01:01 -0400 Subject: 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 --- sys/fs/tmpfs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sys/fs/tmpfs.c') 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); @@ -268,6 +269,14 @@ tmpfs_write(struct vnode *vp, struct sio_txn *sio) np->len += TMPFS_BSIZE; } + /* + * 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 @@ -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); -- cgit v1.2.3