aboutsummaryrefslogtreecommitdiff
path: root/src/fs/devfs
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-07-07 13:22:53 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-11 00:08:15 +0100
commit7861a52adf92a083bb2aed4c35f98d8035dce032 (patch)
tree28cd3c40e4c878f730f5df3c1d93bdf91af490c3 /src/fs/devfs
parent7fc48e9216ff809da5f8055a50b0be17628ef1df (diff)
downloadwnix-7861a52adf92a083bb2aed4c35f98d8035dce032.tar.gz
Setup project skeleton
Diffstat (limited to 'src/fs/devfs')
-rw-r--r--src/fs/devfs/CMakeLists.txt20
-rw-r--r--src/fs/devfs/include/devfs.h24
-rw-r--r--src/fs/devfs/private_include/devfs/ops.h49
-rw-r--r--src/fs/devfs/private_include/devfs/types.h44
-rw-r--r--src/fs/devfs/src/CMakeLists.txt34
-rw-r--r--src/fs/devfs/src/close.c26
-rw-r--r--src/fs/devfs/src/flags.c25
-rw-r--r--src/fs/devfs/src/mkdir.c28
-rw-r--r--src/fs/devfs/src/mknod.c54
-rw-r--r--src/fs/devfs/src/mount.c59
-rw-r--r--src/fs/devfs/src/open.c57
-rw-r--r--src/fs/devfs/src/ops.c32
-rw-r--r--src/fs/devfs/src/read.c98
-rw-r--r--src/fs/devfs/src/read_nb.c41
-rw-r--r--src/fs/devfs/src/register.c44
-rw-r--r--src/fs/devfs/src/search.c29
-rw-r--r--src/fs/devfs/src/stat.c30
-rw-r--r--src/fs/devfs/src/status.c31
-rw-r--r--src/fs/devfs/src/unlink.c26
-rw-r--r--src/fs/devfs/src/update.c27
-rw-r--r--src/fs/devfs/src/write.c95
21 files changed, 873 insertions, 0 deletions
diff --git a/src/fs/devfs/CMakeLists.txt b/src/fs/devfs/CMakeLists.txt
new file mode 100644
index 0000000..c3bbcf8
--- /dev/null
+++ b/src/fs/devfs/CMakeLists.txt
@@ -0,0 +1,20 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+add_library(devfs)
+add_subdirectory(src)
+target_include_directories(devfs PUBLIC include PRIVATE private_include)
+target_link_libraries(devfs PUBLIC state c PRIVATE fs drv ramfs)
diff --git a/src/fs/devfs/include/devfs.h b/src/fs/devfs/include/devfs.h
new file mode 100644
index 0000000..ccc82ac
--- /dev/null
+++ b/src/fs/devfs/include/devfs.h
@@ -0,0 +1,24 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DEVFS_H
+#define DEVFS_H
+
+int devfs_register(void);
+
+#endif
diff --git a/src/fs/devfs/private_include/devfs/ops.h b/src/fs/devfs/private_include/devfs/ops.h
new file mode 100644
index 0000000..0c09776
--- /dev/null
+++ b/src/fs/devfs/private_include/devfs/ops.h
@@ -0,0 +1,49 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DEVFS_OPS_H
+#define DEVFS_OPS_H
+
+#include <fs/fs.h>
+#include <drv/event.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+int devfs_mount(const struct fs_mount *m, struct fs_ret *r);
+int devfs_mkdir(const struct fs_mkdir *m, const struct fs_mp *mp,
+ const union inode_result *i, struct fs_ret *r);
+int devfs_open(const struct fs_open *o, const struct fs_mp *mp,
+ const union inode_result *i, struct fs_ret *r);
+int devfs_read(const struct fs_read *r, struct fs_ret *ret);
+int devfs_read_nb(const struct fs_read *r);
+int devfs_write(const struct fs_write *w, struct fs_ret *r);
+int devfs_stat(const struct fs_stat *s, const struct fs_mp *mp,
+ const union inode_result *i, struct fs_ret *r);
+int devfs_close(struct fs_fd *fd);
+int devfs_search(const char *path, const struct fs_mp *mp,
+ union inode_result *inode, struct fs_ret *r);
+int devfs_status(const char *node, const struct drv_event_ops *const ops,
+ bool available, mode_t mode, void *args);
+int devfs_flags(const union inode_result *i);
+int devfs_update(struct fs_mp_prv *pr);
+int devfs_mknod(const char *path, mode_t mode, dev_t dev,
+ const struct drv_event_ops *const ops, struct fs_mp_prv *mp);
+int devfs_unlink(const char *path, struct fs_mp_prv *mp);
+const struct devfs_ops *devfs_ops(const struct fs_mp_prv *pr, const char *node);
+
+#endif
diff --git a/src/fs/devfs/private_include/devfs/types.h b/src/fs/devfs/private_include/devfs/types.h
new file mode 100644
index 0000000..da6b50b
--- /dev/null
+++ b/src/fs/devfs/private_include/devfs/types.h
@@ -0,0 +1,44 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DEVFS_TYPES_H
+#define DEVFS_TYPES_H
+
+#include <fs/fs.h>
+#include <fs/inode.h>
+#include <drv/drv.h>
+#include <drv/event.h>
+#include <ramfs.h>
+
+struct devfs_ops
+{
+ char *node;
+ struct drv_event_ops ops;
+ struct devfs_ops *prev, *next;
+};
+
+struct fs_mp_prv
+{
+ struct ramfs *rfs;
+ struct drv *drv;
+ struct devfs_ops *head, *tail;
+};
+
+extern const struct fs devfs;
+
+#endif
diff --git a/src/fs/devfs/src/CMakeLists.txt b/src/fs/devfs/src/CMakeLists.txt
new file mode 100644
index 0000000..2a12700
--- /dev/null
+++ b/src/fs/devfs/src/CMakeLists.txt
@@ -0,0 +1,34 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+target_sources(devfs PRIVATE
+ close.c
+ flags.c
+ mount.c
+ mkdir.c
+ mknod.c
+ open.c
+ ops.c
+ stat.c
+ read.c
+ read_nb.c
+ register.c
+ search.c
+ status.c
+ unlink.c
+ update.c
+ write.c
+)
diff --git a/src/fs/devfs/src/close.c b/src/fs/devfs/src/close.c
new file mode 100644
index 0000000..db236d1
--- /dev/null
+++ b/src/fs/devfs/src/close.c
@@ -0,0 +1,26 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <fs/fs.h>
+
+int devfs_close(struct fs_fd *const fd)
+{
+ return -1;
+}
diff --git a/src/fs/devfs/src/flags.c b/src/fs/devfs/src/flags.c
new file mode 100644
index 0000000..082c5ad
--- /dev/null
+++ b/src/fs/devfs/src/flags.c
@@ -0,0 +1,25 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+
+int devfs_flags(const union inode_result *const i)
+{
+ return i->memi->flags;
+}
diff --git a/src/fs/devfs/src/mkdir.c b/src/fs/devfs/src/mkdir.c
new file mode 100644
index 0000000..cc091e0
--- /dev/null
+++ b/src/fs/devfs/src/mkdir.c
@@ -0,0 +1,28 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <fs/fs.h>
+#include <fs/inode.h>
+
+int devfs_mkdir(const struct fs_mkdir *m, const struct fs_mp *const mp,
+ const union inode_result *const i, struct fs_ret *const r)
+{
+ return -1;
+}
diff --git a/src/fs/devfs/src/mknod.c b/src/fs/devfs/src/mknod.c
new file mode 100644
index 0000000..f9a369e
--- /dev/null
+++ b/src/fs/devfs/src/mknod.c
@@ -0,0 +1,54 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <fs/inode.h>
+#include <ramfs.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+int devfs_mknod(const char *const node, const mode_t mode, const dev_t dev,
+ const struct drv_event_ops *const ops, struct fs_mp_prv *const pr)
+{
+ struct devfs_ops *dops = NULL;
+ char *const nodedup = strdup(node);
+
+ if (!nodedup
+ || !(dops = malloc(sizeof *dops))
+ || ramfs_mknod(node, mode, dev, pr->rfs))
+ goto failure;
+
+ *dops = (const struct devfs_ops){.node = nodedup, .ops = *ops};
+
+ if (!pr->head)
+ pr->head = dops;
+ else
+ {
+ dops->prev = pr->tail;
+ pr->tail->next = dops;
+ }
+
+ pr->tail = dops;
+ return 0;
+
+failure:
+ free(dops);
+ return -1;
+}
diff --git a/src/fs/devfs/src/mount.c b/src/fs/devfs/src/mount.c
new file mode 100644
index 0000000..2165971
--- /dev/null
+++ b/src/fs/devfs/src/mount.c
@@ -0,0 +1,59 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <drv/drv.h>
+#include <fs/fs.h>
+#include <ramfs.h>
+#include <stdlib.h>
+
+int devfs_mount(const struct fs_mount *const m, struct fs_ret *const r)
+{
+ struct drv *drv = NULL;
+ struct fs_mp_prv *p = NULL;
+ struct ramfs *const rfs = ramfs_mount(m, r);
+
+ if (!rfs || !(p = malloc(sizeof *p)))
+ goto failure;
+
+ const struct drv_event ev =
+ {
+ .status = devfs_status,
+ .args = p
+ };
+
+ if (!(drv = drv_init(&ev))
+ || fs_mountpoint(m->src, m->tgt, &devfs, devfs_update, p))
+ goto failure;
+
+ *p = (const struct fs_mp_prv)
+ {
+ .drv = drv,
+ .rfs = rfs
+ };
+
+ return 0;
+
+failure:
+ drv_free(drv);
+ free(p);
+ ramfs_free(rfs);
+ return -1;
+}
diff --git a/src/fs/devfs/src/open.c b/src/fs/devfs/src/open.c
new file mode 100644
index 0000000..551061f
--- /dev/null
+++ b/src/fs/devfs/src/open.c
@@ -0,0 +1,57 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/types.h>
+#include <devfs/ops.h>
+#include <fs/fs.h>
+#include <state.h>
+#include <stdlib.h>
+
+struct open
+{
+ struct fs_ret *pr, r;
+};
+
+static enum state done(void *const args)
+{
+ struct open *const op = args;
+
+ *op->pr = op->r;
+ free(op);
+ return STATE_AGAIN;
+}
+
+int devfs_open(const struct fs_open *const o, const struct fs_mp *const mp,
+ const union inode_result *const inode, struct fs_ret *const r)
+{
+ struct open *const op = malloc(sizeof *op);
+
+ if (!op)
+ return -1;
+
+ *op = (const struct open){.pr = r, .r = *r};
+ *o->fd = (const struct fs_fd)
+ {
+ .inode = *inode,
+ .mp = mp
+ };
+
+ *r = (const struct fs_ret){.f = done, .args = op};
+ return 0;
+}
diff --git a/src/fs/devfs/src/ops.c b/src/fs/devfs/src/ops.c
new file mode 100644
index 0000000..c51cfa7
--- /dev/null
+++ b/src/fs/devfs/src/ops.c
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <string.h>
+
+const struct devfs_ops *devfs_ops(const struct fs_mp_prv *const pr,
+ const char *const node)
+{
+ for (struct devfs_ops *o = pr->head; o; o = o->next)
+ if (!strcmp(o->node, node))
+ return o;
+
+ return NULL;
+}
diff --git a/src/fs/devfs/src/read.c b/src/fs/devfs/src/read.c
new file mode 100644
index 0000000..e968eb2
--- /dev/null
+++ b/src/fs/devfs/src/read.c
@@ -0,0 +1,98 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <fs/fs.h>
+#include <state.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+struct read
+{
+ bool done;
+ size_t n;
+ struct fs_fd *fd;
+ struct fs_ret *pr, r;
+};
+
+static int done(const int error, void *const args)
+{
+ struct read *const re = args;
+
+ re->done = true;
+ return 0;
+}
+
+static enum state wait(void *const args)
+{
+ struct read *const re = args;
+
+ if (!re->done)
+ return STATE_AGAIN;
+
+ re->fd->offset += re->n;
+ *re->pr = re->r;
+ free(re);
+ return STATE_AGAIN;
+}
+
+int devfs_read(const struct fs_read *const fr, struct fs_ret *const r)
+{
+ struct read *re = NULL;
+ struct fs_fd *const fd = fr->fd;
+ const struct fs_mp *const mp = fd->mp;
+ const struct inode *const inode = fd->inode.memi;
+ const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name);
+
+ if (!o)
+ {
+ errno = ENOENT;
+ goto failure;
+ }
+ else if (!(re = malloc(sizeof *re)))
+ goto failure;
+
+ *re = (const struct read)
+ {
+ .n = fr->n,
+ .fd = fd,
+ .pr = r,
+ .r = *r
+ };
+
+ const struct drv_event_done d =
+ {
+ .f = done,
+ .args = re
+ };
+
+ const struct drv_event_ops *const ops = &o->ops;
+
+ if (ops->read(fr->buf, fr->n, fd->start + fd->offset, &d, ops->args))
+ goto failure;
+
+ *r = (const struct fs_ret){.f = wait, .args = re};
+ return 0;
+
+failure:
+ free(re);
+ return -1;
+}
diff --git a/src/fs/devfs/src/read_nb.c b/src/fs/devfs/src/read_nb.c
new file mode 100644
index 0000000..2f30d5c
--- /dev/null
+++ b/src/fs/devfs/src/read_nb.c
@@ -0,0 +1,41 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <fs/fs.h>
+#include <errno.h>
+
+int devfs_read_nb(const struct fs_read *const fr)
+{
+ struct fs_fd *const fd = fr->fd;
+ const struct fs_mp *const mp = fd->mp;
+ const struct inode *const inode = fd->inode.memi;
+ const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name);
+
+ if (!o)
+ {
+ errno = ENOENT;
+ return -1;
+ }
+
+ const struct drv_event_ops *const ops = &o->ops;
+
+ return ops->read_nb(fr->buf, fr->n, ops->args);
+}
diff --git a/src/fs/devfs/src/register.c b/src/fs/devfs/src/register.c
new file mode 100644
index 0000000..5ff7b33
--- /dev/null
+++ b/src/fs/devfs/src/register.c
@@ -0,0 +1,44 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <fs/fs.h>
+
+const struct fs devfs =
+{
+ .type = "devfs",
+ .mount = devfs_mount,
+ .stat = devfs_stat,
+ .mkdir = devfs_mkdir,
+ .open = devfs_open,
+ .read = devfs_read,
+ .read_nb = devfs_read_nb,
+ .write = devfs_write,
+ .close = devfs_close,
+ .iops =
+ {
+ .search = devfs_search,
+ .flags = devfs_flags
+ }
+};
+
+int devfs_register(void)
+{
+ return fs_register(&devfs);
+}
diff --git a/src/fs/devfs/src/search.c b/src/fs/devfs/src/search.c
new file mode 100644
index 0000000..4360a9f
--- /dev/null
+++ b/src/fs/devfs/src/search.c
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <fs/fs.h>
+#include <ramfs.h>
+
+int devfs_search(const char *const path, const struct fs_mp *const mp,
+ union inode_result *const inode, struct fs_ret *const r)
+{
+ return ramfs_search(path, mp->prv->rfs, inode, r);
+}
diff --git a/src/fs/devfs/src/stat.c b/src/fs/devfs/src/stat.c
new file mode 100644
index 0000000..50af3ee
--- /dev/null
+++ b/src/fs/devfs/src/stat.c
@@ -0,0 +1,30 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <fs/fs.h>
+#include <fs/inode.h>
+#include <ramfs.h>
+
+int devfs_stat(const struct fs_stat *const s, const struct fs_mp *const mp,
+ const union inode_result *const i, struct fs_ret *const r)
+{
+ return ramfs_stat(s, mp->prv->rfs, i, r);
+}
diff --git a/src/fs/devfs/src/status.c b/src/fs/devfs/src/status.c
new file mode 100644
index 0000000..fb73c94
--- /dev/null
+++ b/src/fs/devfs/src/status.c
@@ -0,0 +1,31 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs/ops.h>
+#include <drv/event.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+int devfs_status(const char *const node, const struct drv_event_ops *const ops,
+ const bool available, const mode_t mode, void *const args)
+{
+ struct fs_mp_prv *const mp = args;
+
+ return available ? devfs_mknod(node, mode, 0, ops, mp)
+ : devfs_unlink(node, mp);
+}
diff --git a/src/fs/devfs/src/unlink.c b/src/fs/devfs/src/unlink.c
new file mode 100644
index 0000000..3cd87b4
--- /dev/null
+++ b/src/fs/devfs/src/unlink.c
@@ -0,0 +1,26 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs/ops.h>
+#include <sys/types.h>
+#include <errno.h>
+
+int devfs_unlink(const char *const node, struct fs_mp_prv *const mp)
+{
+ return -1;
+}
diff --git a/src/fs/devfs/src/update.c b/src/fs/devfs/src/update.c
new file mode 100644
index 0000000..b437044
--- /dev/null
+++ b/src/fs/devfs/src/update.c
@@ -0,0 +1,27 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/types.h>
+#include <devfs/ops.h>
+#include <drv/drv.h>
+
+int devfs_update(struct fs_mp_prv *const pr)
+{
+ return drv_update(pr->drv);
+}
diff --git a/src/fs/devfs/src/write.c b/src/fs/devfs/src/write.c
new file mode 100644
index 0000000..392666c
--- /dev/null
+++ b/src/fs/devfs/src/write.c
@@ -0,0 +1,95 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <devfs.h>
+#include <devfs/ops.h>
+#include <devfs/types.h>
+#include <fs/fs.h>
+#include <state.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+struct write
+{
+ bool done;
+ struct fs_fd *fd;
+ struct fs_ret *pr, r;
+};
+
+static int done(const int error, void *const args)
+{
+ struct write *const w = args;
+
+ w->done = true;
+ return 0;
+}
+
+static enum state wait(void *const args)
+{
+ struct write *const w = args;
+
+ if (!w->done)
+ return STATE_AGAIN;
+
+ *w->pr = w->r;
+ free(w);
+ return STATE_AGAIN;
+}
+
+int devfs_write(const struct fs_write *const fw, struct fs_ret *const r)
+{
+ struct fs_fd *const fd = fw->fd;
+ const struct fs_mp *const mp = fd->mp;
+ const struct inode *const inode = fd->inode.memi;
+ const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name);
+ struct write *const w = malloc(sizeof *w);
+
+ if (!w)
+ goto failure;
+ else if (!o)
+ {
+ errno = ENOENT;
+ goto failure;
+ }
+
+ *w = (const struct write)
+ {
+ .fd = fd,
+ .pr = r,
+ .r = *r
+ };
+
+ const struct drv_event_done d =
+ {
+ .f = done,
+ .args = w
+ };
+
+ const struct drv_event_ops *const ops = &o->ops;
+
+ if (ops->write(fw->buf, fw->n, &d, ops->args))
+ goto failure;
+
+ *r = (const struct fs_ret){.f = wait, .args = w};
+ return 0;
+
+failure:
+ free(w);
+ return -1;
+}