summaryrefslogtreecommitdiff
path: root/sys/fs/tmpfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/fs/tmpfs.c')
-rw-r--r--sys/fs/tmpfs.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/sys/fs/tmpfs.c b/sys/fs/tmpfs.c
index 9dce89a..a6e40e1 100644
--- a/sys/fs/tmpfs.c
+++ b/sys/fs/tmpfs.c
@@ -211,6 +211,8 @@ tmpfs_create(struct vop_create_args *args)
root_np = TAILQ_FIRST(&root);
np->dirvp = dirvp;
np->type = TMPFS_REG;
+ np->real_size = 0;
+ np->mode = 0700;
memcpy(np->rpath, pcp, strlen(pcp) + 1);
TAILQ_INSERT_TAIL(&root_np->dirents, np, link);
@@ -269,6 +271,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
@@ -287,7 +297,6 @@ tmpfs_write(struct vnode *vp, struct sio_txn *sio)
buf = np->data;
memcpy(&buf[sio->offset], sio->buf, sio->len);
spinlock_release(&np->lock);
- kprintf("%d\n", sio->len);
return sio->len;
}
@@ -316,12 +325,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);
@@ -329,6 +335,30 @@ tmpfs_read(struct vnode *vp, struct sio_txn *sio)
return sio->len;
}
+/*
+ * TMPFS get attribute callback for VFS
+ */
+static int
+tmpfs_getattr(struct vop_getattr_args *args)
+{
+ struct vnode *vp;
+ struct tmpfs_node *np;
+ struct vattr attr;
+
+ if ((vp = args->vp) == NULL) {
+ return -EIO;
+ }
+ if ((np = vp->data) == NULL) {
+ return -EIO;
+ }
+
+ memset(&attr, VNOVAL, sizeof(attr));
+ attr.size = np->real_size;
+ attr.mode = np->mode;
+ *args->res = attr;
+ return 0;
+}
+
static int
tmpfs_reclaim(struct vnode *vp)
{
@@ -378,7 +408,7 @@ tmpfs_init(struct fs_info *fip)
const struct vops g_tmpfs_vops = {
.lookup = tmpfs_lookup,
- .getattr = NULL,
+ .getattr = tmpfs_getattr,
.read = tmpfs_read,
.write = tmpfs_write,
.reclaim = tmpfs_reclaim,