summaryrefslogtreecommitdiff
path: root/src/sys/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/fs')
-rw-r--r--src/sys/fs/tmpfs.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/sys/fs/tmpfs.c b/src/sys/fs/tmpfs.c
index c49dc93..9046002 100644
--- a/src/sys/fs/tmpfs.c
+++ b/src/sys/fs/tmpfs.c
@@ -47,7 +47,9 @@ struct tmpfs_node {
char name[TMPFS_NAMEMAX];
char *data;
size_t len;
+ size_t real_len;
int ref;
+ vtype_t vtype; /* vnode vtype mapping */
TAILQ_ENTRY(tmpfs_node) link;
};
@@ -61,13 +63,14 @@ static struct vop tmpfs_vops;
* Create a new tmpfs node
*
* @name: Name of node to create
+ * @type: Type of vnode file should be associated with
* @np_res: Result pointer is written here
*
* Returns zero on success, otherwise a less than
* zero value on failure
*/
static int
-tmpfs_new(const char *name, struct tmpfs_node **np_res)
+tmpfs_new(const char *name, vtype_t type, struct tmpfs_node **np_res)
{
struct tmpfs_node *np;
size_t name_len;
@@ -93,8 +96,10 @@ tmpfs_new(const char *name, struct tmpfs_node **np_res)
return -ENOMEM;
}
+ np->real_len = 0;
np->len = TMPFS_INIT_SIZE;
np->ref = 1;
+ np->vtype = type;
memset(np->data, 0, TMPFS_INIT_SIZE);
memcpy(np->name, name, name_len);
@@ -160,7 +165,7 @@ tmpfs_lookup(struct vop_lookup_args *args)
return error;
}
- error = vfs_valloc(&vp, VTYPE_FILE, 0);
+ error = vfs_valloc(&vp, np->vtype, 0);
if (error < 0) {
return error;
}
@@ -195,7 +200,15 @@ tmpfs_create(struct vop_create_args *args)
return -EEXIST;
}
- return tmpfs_new(ndp->path, NULL);
+ /* Only accept the types we support */
+ switch (args->vtype) {
+ case VTYPE_FILE:
+ break;
+ default:
+ return -ENOTSUP;
+ }
+
+ return tmpfs_new(ndp->path, args->vtype, NULL);
}
/*
@@ -276,6 +289,7 @@ tmpfs_write(struct vop_rw_data *data)
}
}
+ np->real_len += len;
node_len = np->len;
dest = np->data + data->off;
memcpy(dest, data->data, len);
@@ -304,7 +318,7 @@ tmpfs_read(struct vop_rw_data *data)
/* Return EOF if the offset is too far */
len = data->len;
- if (data->off >= np->len) {
+ if (data->off >= np->real_len) {
return 0; /* EOF */
}
@@ -323,6 +337,23 @@ tmpfs_read(struct vop_rw_data *data)
}
static int
+tmpfs_getattr(struct vnode *vp, struct vattr *res)
+{
+ struct tmpfs_node *np;
+
+ if (vp == NULL || res == NULL) {
+ return -EINVAL;
+ }
+
+ if ((np = vp->data) == NULL) {
+ return -EIO;
+ }
+
+ res->size = np->real_len;
+ return 0;
+}
+
+static int
tmpfs_reclaim(struct vnode *vp, int flags)
{
return 0;
@@ -333,7 +364,8 @@ static struct vop tmpfs_vops = {
.create = tmpfs_create,
.reclaim = tmpfs_reclaim,
.write = tmpfs_write,
- .read = tmpfs_read
+ .read = tmpfs_read,
+ .getattr = tmpfs_getattr
};
struct vfsops g_tmpfs_vfsops = {