summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-17 12:37:49 -0400
committerIan Moffett <ian@osmora.org>2025-10-17 12:37:49 -0400
commit93c729aefb2596c14bbe135b0126d964342ab77b (patch)
tree82ae69ba41a5a26e9681f8834c35fc4c54d762cb /src
parent98205eb9fd88826b6d906cc74f635ef76718355a (diff)
kern: vfs: Add 'create' virtual file operation
The create VOP allows the caller to create a node within the parent directory of a filesystem represented by a vnode. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r--src/sys/include/os/vnode.h24
-rw-r--r--src/sys/os/vfs_subr.c22
2 files changed, 46 insertions, 0 deletions
diff --git a/src/sys/include/os/vnode.h b/src/sys/include/os/vnode.h
index 1bef1e2..628ba68 100644
--- a/src/sys/include/os/vnode.h
+++ b/src/sys/include/os/vnode.h
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/atomic.h>
+#include <sys/namei.h>
/* Forward declarations */
struct vnode;
@@ -83,12 +84,23 @@ struct vop_rw_data {
};
/*
+ * Arguments to create an entry within a
+ * filesystem
+ *
+ * @ndp: Path component to create
+ */
+struct vop_create_args {
+ struct nameidata *ndp;
+};
+
+/*
* Represents operations that can be performed on
* a specific vnode. These are implemented as callbacks
*/
struct vop {
int(*lookup)(struct vop_lookup_args *args);
int(*reclaim)(struct vnode *vp, int flags);
+ int(*create)(struct vop_create_args *args);
ssize_t(*write)(struct vop_rw_data *data);
ssize_t(*read)(struct vop_rw_data *data);
};
@@ -176,4 +188,16 @@ ssize_t vop_read(struct vnode *vp, char *data, off_t off, size_t len);
*/
int vop_reclaim(struct vnode *vp, int flags);
+/*
+ * Create a node within a specific filesystem or
+ * directory
+ *
+ * @vp: Vnode of parent directory
+ * @ndp: Namei descriptor of path component
+ *
+ * Returns zero on success, otherwise a less than zero
+ * value on failure.
+ */
+int vop_create(struct vnode *vp, struct nameidata *ndp);
+
#endif /* !_OS_VNODE_H_ */
diff --git a/src/sys/os/vfs_subr.c b/src/sys/os/vfs_subr.c
index 6cb7767..adfcffb 100644
--- a/src/sys/os/vfs_subr.c
+++ b/src/sys/os/vfs_subr.c
@@ -224,3 +224,25 @@ vop_reclaim(struct vnode *vp, int flags)
return vops->reclaim(vp, flags);
}
+
+int
+vop_create(struct vnode *vp, struct nameidata *ndp)
+{
+ struct vop *vops;
+ struct vop_create_args args;
+
+ if (vp == NULL || ndp == NULL) {
+ return -EINVAL;
+ }
+
+ if ((vops = vp->vops) == NULL) {
+ return -EIO;
+ }
+
+ if (vops->create == NULL) {
+ return -EIO;
+ }
+
+ args.ndp = ndp;
+ return vops->create(&args);
+}