summaryrefslogtreecommitdiff
path: root/src/fs/include
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-07-25 14:16:41 +0200
commit14f60e4fd65c42f126eaee7e09cb4251c167c6ed (patch)
tree313b5e16d7d99cf1518c953e2efe5e5fc920dfbf /src/fs/include
parent48a61c16eaa6dcfc75d00dba302537ce1492db98 (diff)
downloadwnix-tty.tar.gz
wiptty
Diffstat (limited to 'src/fs/include')
-rw-r--r--src/fs/include/fs/fs.h159
-rw-r--r--src/fs/include/fs/inode.h79
2 files changed, 238 insertions, 0 deletions
diff --git a/src/fs/include/fs/fs.h b/src/fs/include/fs/fs.h
new file mode 100644
index 0000000..c66ce97
--- /dev/null
+++ b/src/fs/include/fs/fs.h
@@ -0,0 +1,159 @@
+/*
+ * wanix, 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 FS_H
+#define FS_H
+
+#include <fs/inode.h>
+#include <state.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct fs_mountpoint;
+struct fs_mp_prv;
+struct fs_fd_prv;
+
+struct fs_stat
+{
+ const char *path;
+ struct stat *sb;
+ uid_t uid;
+ gid_t gid;
+};
+
+struct fs_mkdir
+{
+ const char *path;
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
+};
+
+struct fs_mount
+{
+ const char *src, *tgt;
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
+};
+
+struct fs_umount
+{
+ const char *tgt;
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
+};
+
+struct fs_open
+{
+ const char *path;
+ struct fs_fd *fd;
+ int flags;
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
+};
+
+struct fs_close
+{
+ struct fs_fd *fd;
+};
+
+struct fs_read
+{
+ struct fs_fd *fd;
+ void *buf;
+ size_t n;
+};
+
+struct fs_write
+{
+ struct fs_fd *fd;
+ const void *buf;
+ size_t n;
+};
+
+struct fs_seek
+{
+ struct fs_fd *fd;
+ long offset;
+};
+
+struct fs_ret
+{
+ enum state (*f)(void *args);
+ void *args;
+};
+
+enum
+{
+ FS_DEV_REQUIRED = 1
+};
+
+struct fs
+{
+ const char *type;
+ int flags;
+ int (*mount)(const struct fs_mount *, struct fs_ret *);
+ int (*umount)(const struct fs_umount *, struct fs_ret *);
+ int (*stat)(const struct fs_stat *, const struct fs_mp *,
+ const union inode_result *, struct fs_ret *);
+ int (*mkdir)(const struct fs_mkdir *, const struct fs_mp *,
+ const union inode_result *, struct fs_ret *);
+ int (*open)(const struct fs_open *, const struct fs_mp *,
+ const union inode_result *, struct fs_ret *);
+ int (*close)(const struct fs_close *, struct fs_ret *);
+ int (*read)(const struct fs_read *, struct fs_ret *);
+ int (*write)(const struct fs_write *, struct fs_ret *);
+ int (*seek)(const struct fs_seek *, struct fs_ret *);
+ struct inode_ops iops;
+};
+
+struct fs_mp
+{
+ const char *src, *tgt;
+ const struct fs *fs;
+ struct fs_mp_prv *prv;
+};
+
+struct fs_fd
+{
+ long offset;
+ int error;
+ const struct fs_mp *mp;
+ union inode_result inode;
+ struct fs_fd_prv *prv;
+};
+
+typedef int (*fs_update_fn)(struct fs_mp_prv *);
+
+int fs_register(const struct fs *fs);
+int fs_update(void);
+int fs_mountpoint(const char *src, const char *tgt, const struct fs *fs,
+ fs_update_fn fn, struct fs_mp_prv *pr);
+const struct fs *fs_from_type(const char *type);
+int fs_mp_from_path(const char *path, struct fs_mp *mp);
+struct fs_mp *fs_mps_from_path(const char *path, size_t *n);
+const char *fs_relpath(const char *path);
+char *fs_parent(const char *path);
+int fs_next(const char *path, char **next, size_t *i);
+
+#endif
diff --git a/src/fs/include/fs/inode.h b/src/fs/include/fs/inode.h
new file mode 100644
index 0000000..914564b
--- /dev/null
+++ b/src/fs/include/fs/inode.h
@@ -0,0 +1,79 @@
+/*
+ * wanix, 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 FS_INODE_H
+#define FS_INODE_H
+
+#include <state.h>
+#include <sys/types.h>
+#include <time.h>
+
+struct fs;
+struct fs_mp;
+struct fs_ret;
+struct inode_prv;
+
+enum
+{
+ INODE_DIR = 1,
+ INODE_REGFILE = 1 << 1,
+ INODE_BLOCKDEV = 1 << 2,
+ INODE_MOUNTPOINT = 1 << 3,
+};
+
+struct inode
+{
+ char *name;
+ int flags;
+ ino_t ino;
+ mode_t mode;
+ uid_t uid;
+ gid_t gid;
+ struct timespec atim, mtim, ctim;
+ struct inode *parent, *child, *left, *right;
+ struct inode_prv *prv;
+};
+
+union inode_result
+{
+ struct inode cachei, *memi;
+};
+
+typedef int (*inode_search_done)(enum state state, const char *relpath,
+ const struct fs_mp *mp, const union inode_result *inode, void *args);
+
+struct inode_search
+{
+ const char *path;
+ inode_search_done done;
+ void *args;
+};
+
+struct inode_ops
+{
+ int (*search)(const char *path, const struct fs_mp *mp,
+ union inode_result *inode, struct fs_ret *r);
+ int (*reserve)(const struct inode *i, void *args, struct fs_ret *r);
+ int (*flags)(const union inode_result *i);
+};
+
+int inode_search(const struct inode_search *s, struct fs_ret *r);
+void inode_search_free(struct inode_search *s);
+void inode_free(struct inode *i);
+
+#endif