aboutsummaryrefslogtreecommitdiff
path: root/src/drv/null
diff options
context:
space:
mode:
Diffstat (limited to 'src/drv/null')
-rw-r--r--src/drv/null/CMakeLists.txt20
-rw-r--r--src/drv/null/include/drv/null.h28
-rw-r--r--src/drv/null/private_include/drv/null/ops.h31
-rw-r--r--src/drv/null/private_include/drv/null/types.h32
-rw-r--r--src/drv/null/src/CMakeLists.txt23
-rw-r--r--src/drv/null/src/free.c32
-rw-r--r--src/drv/null/src/init.c35
-rw-r--r--src/drv/null/src/read.c30
-rw-r--r--src/drv/null/src/update.c48
-rw-r--r--src/drv/null/src/write.c29
10 files changed, 308 insertions, 0 deletions
diff --git a/src/drv/null/CMakeLists.txt b/src/drv/null/CMakeLists.txt
new file mode 100644
index 0000000..ab09fc2
--- /dev/null
+++ b/src/drv/null/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(drv_null)
+add_subdirectory(src)
+target_include_directories(drv_null PUBLIC include PRIVATE private_include)
+target_link_libraries(drv_null PUBLIC c PRIVATE drv_event)
diff --git a/src/drv/null/include/drv/null.h b/src/drv/null/include/drv/null.h
new file mode 100644
index 0000000..52ff26f
--- /dev/null
+++ b/src/drv/null/include/drv/null.h
@@ -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/>.
+ */
+
+#ifndef DRV_NULL_H
+#define DRV_NULL_H
+
+#include <drv/event.h>
+
+struct drv_port *drv_null_init(const struct drv_event *ev);
+int drv_null_update(struct drv_port *p);
+void drv_null_free(struct drv_port *p);
+
+#endif
diff --git a/src/drv/null/private_include/drv/null/ops.h b/src/drv/null/private_include/drv/null/ops.h
new file mode 100644
index 0000000..cf9d8f2
--- /dev/null
+++ b/src/drv/null/private_include/drv/null/ops.h
@@ -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/>.
+ */
+
+#ifndef DRV_NULL_OPS_H
+#define DRV_NULL_OPS_H
+
+#include <drv/event.h>
+#include <drv/null/types.h>
+#include <stddef.h>
+
+int drv_null_read(struct drv_port *p, void *buf, size_t n, off_t offset,
+ const struct drv_event_done *done);
+int drv_null_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
+
+#endif
diff --git a/src/drv/null/private_include/drv/null/types.h b/src/drv/null/private_include/drv/null/types.h
new file mode 100644
index 0000000..1c9266d
--- /dev/null
+++ b/src/drv/null/private_include/drv/null/types.h
@@ -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/>.
+ */
+
+#ifndef DRV_NULL_TYPES_H
+#define DRV_NULL_TYPES_H
+
+#include <drv/event.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct drv_port
+{
+ bool init;
+ struct drv_event ev;
+};
+
+#endif
diff --git a/src/drv/null/src/CMakeLists.txt b/src/drv/null/src/CMakeLists.txt
new file mode 100644
index 0000000..899cada
--- /dev/null
+++ b/src/drv/null/src/CMakeLists.txt
@@ -0,0 +1,23 @@
+# 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(drv_null PRIVATE
+ free.c
+ init.c
+ read.c
+ update.c
+ write.c
+)
diff --git a/src/drv/null/src/free.c b/src/drv/null/src/free.c
new file mode 100644
index 0000000..1251580
--- /dev/null
+++ b/src/drv/null/src/free.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 <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/ops.h>
+#include <drv/null/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void drv_null_free(struct drv_port *const p)
+{
+ if (!p)
+ return;
+
+ free(p);
+}
diff --git a/src/drv/null/src/init.c b/src/drv/null/src/init.c
new file mode 100644
index 0000000..4ed6c39
--- /dev/null
+++ b/src/drv/null/src/init.c
@@ -0,0 +1,35 @@
+/*
+ * 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 <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/ops.h>
+#include <drv/null/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct drv_port *drv_null_init(const struct drv_event *const ev)
+{
+ struct drv_port *ret = NULL;
+
+ if (!(ret = malloc(sizeof *ret)))
+ return NULL;
+
+ *ret = (const struct drv_port){.ev = *ev};
+ return ret;
+}
diff --git a/src/drv/null/src/read.c b/src/drv/null/src/read.c
new file mode 100644
index 0000000..7dd9820
--- /dev/null
+++ b/src/drv/null/src/read.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 <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/types.h>
+#include <drv/null/ops.h>
+#include <stddef.h>
+
+int drv_null_read(struct drv_port *const p, void *const buf, const size_t n,
+ const off_t offset, const struct drv_event_done *const d)
+{
+ /* TODO: how to set EOF? */
+ return 0;
+}
diff --git a/src/drv/null/src/update.c b/src/drv/null/src/update.c
new file mode 100644
index 0000000..cc0b456
--- /dev/null
+++ b/src/drv/null/src/update.c
@@ -0,0 +1,48 @@
+/*
+ * 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 <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/ops.h>
+#include <drv/null/types.h>
+#include <stdbool.h>
+
+static int init(struct drv_port *const p)
+{
+ if (p->init)
+ return 0;
+
+ const struct drv_event *const ev = &p->ev;
+ const struct drv_event_ops ops =
+ {
+ .read = drv_null_read,
+ .write = drv_null_write,
+ .p = p
+ };
+
+ if (ev->status("null", &ops, true, 0666, ev->args))
+ return -1;
+
+ p->init = true;
+ return 0;
+}
+
+int drv_null_update(struct drv_port *const p)
+{
+ return init(p);
+}
diff --git a/src/drv/null/src/write.c b/src/drv/null/src/write.c
new file mode 100644
index 0000000..9ca8b53
--- /dev/null
+++ b/src/drv/null/src/write.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 <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/types.h>
+#include <drv/null/ops.h>
+#include <stddef.h>
+
+int drv_null_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const d)
+{
+ return n;
+}