diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-07 13:22:53 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-25 14:16:41 +0200 |
| commit | 14f60e4fd65c42f126eaee7e09cb4251c167c6ed (patch) | |
| tree | 313b5e16d7d99cf1518c953e2efe5e5fc920dfbf /src/fs/iso9660 | |
| parent | 48a61c16eaa6dcfc75d00dba302537ce1492db98 (diff) | |
| download | wnix-tty.tar.gz | |
wiptty
Diffstat (limited to 'src/fs/iso9660')
| -rw-r--r-- | src/fs/iso9660/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | src/fs/iso9660/include/iso9660.h | 24 | ||||
| -rw-r--r-- | src/fs/iso9660/private_include/iso9660/ops.h | 39 | ||||
| -rw-r--r-- | src/fs/iso9660/private_include/iso9660/types.h | 34 | ||||
| -rw-r--r-- | src/fs/iso9660/src/CMakeLists.txt | 28 | ||||
| -rw-r--r-- | src/fs/iso9660/src/close.c | 26 | ||||
| -rw-r--r-- | src/fs/iso9660/src/mkdir.c | 28 | ||||
| -rw-r--r-- | src/fs/iso9660/src/mount.c | 196 | ||||
| -rw-r--r-- | src/fs/iso9660/src/open.c | 27 | ||||
| -rw-r--r-- | src/fs/iso9660/src/read.c | 27 | ||||
| -rw-r--r-- | src/fs/iso9660/src/register.c | 44 | ||||
| -rw-r--r-- | src/fs/iso9660/src/search.c | 27 | ||||
| -rw-r--r-- | src/fs/iso9660/src/seek.c | 27 | ||||
| -rw-r--r-- | src/fs/iso9660/src/stat.c | 28 | ||||
| -rw-r--r-- | src/fs/iso9660/src/write.c | 28 |
15 files changed, 603 insertions, 0 deletions
diff --git a/src/fs/iso9660/CMakeLists.txt b/src/fs/iso9660/CMakeLists.txt new file mode 100644 index 0000000..67b56cf --- /dev/null +++ b/src/fs/iso9660/CMakeLists.txt @@ -0,0 +1,20 @@ +# 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/>. + +add_library(iso9660) +add_subdirectory(src) +target_include_directories(iso9660 PUBLIC include PRIVATE private_include) +target_link_libraries(iso9660 PUBLIC c PRIVATE fs kprintf state) diff --git a/src/fs/iso9660/include/iso9660.h b/src/fs/iso9660/include/iso9660.h new file mode 100644 index 0000000..f5ee681 --- /dev/null +++ b/src/fs/iso9660/include/iso9660.h @@ -0,0 +1,24 @@ +/* + * 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 ISO9660_H +#define ISO9660_H + +int iso9660_register(void); + +#endif diff --git a/src/fs/iso9660/private_include/iso9660/ops.h b/src/fs/iso9660/private_include/iso9660/ops.h new file mode 100644 index 0000000..64cd798 --- /dev/null +++ b/src/fs/iso9660/private_include/iso9660/ops.h @@ -0,0 +1,39 @@ +/* + * 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 ISO9660_OPS_H +#define ISO9660_OPS_H + +#include <fs/fs.h> +#include <fs/inode.h> + +int iso9660_mount(const struct fs_mount *m, struct fs_ret *r); +int iso9660_mkdir(const struct fs_mkdir *m, const struct fs_mp *mp, + const union inode_result *i, struct fs_ret *r); +int iso9660_open(const struct fs_open *o, const struct fs_mp *mp, + const union inode_result *i, struct fs_ret *r); +int iso9660_read(const struct fs_read *r, struct fs_ret *ret); +int iso9660_write(const struct fs_write *w, struct fs_ret *r); +int iso9660_stat(const struct fs_stat *s, const struct fs_mp *mp, + const union inode_result *inode, struct fs_ret *r); +int iso9660_seek(const struct fs_seek *s, struct fs_ret *r); +int iso9660_close(const struct fs_close *c, struct fs_ret *r); +int iso9660_search(const char *path, const struct fs_mp *prv, + union inode_result *inode, struct fs_ret *r); + +#endif diff --git a/src/fs/iso9660/private_include/iso9660/types.h b/src/fs/iso9660/private_include/iso9660/types.h new file mode 100644 index 0000000..89cd1d3 --- /dev/null +++ b/src/fs/iso9660/private_include/iso9660/types.h @@ -0,0 +1,34 @@ +/* + * 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 ISO9660_TYPES_H +#define ISO9660_TYPES_H + +#include <fs/fs.h> +#include <fs/inode.h> + +struct fs_mp_prv +{ + int dummy; +}; + +enum {ISO9660_SECTOR_SZ = 2048}; + +extern const struct fs iso9660; + +#endif diff --git a/src/fs/iso9660/src/CMakeLists.txt b/src/fs/iso9660/src/CMakeLists.txt new file mode 100644 index 0000000..97dd80b --- /dev/null +++ b/src/fs/iso9660/src/CMakeLists.txt @@ -0,0 +1,28 @@ +# 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/>. + +target_sources(iso9660 PRIVATE + close.c + mount.c + mkdir.c + open.c + stat.c + read.c + register.c + search.c + seek.c + write.c +) diff --git a/src/fs/iso9660/src/close.c b/src/fs/iso9660/src/close.c new file mode 100644 index 0000000..dc80117 --- /dev/null +++ b/src/fs/iso9660/src/close.c @@ -0,0 +1,26 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> + +int iso9660_close(const struct fs_close *const c, struct fs_ret *const r) +{ + return -1; +} diff --git a/src/fs/iso9660/src/mkdir.c b/src/fs/iso9660/src/mkdir.c new file mode 100644 index 0000000..e3d91ce --- /dev/null +++ b/src/fs/iso9660/src/mkdir.c @@ -0,0 +1,28 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> +#include <fs/inode.h> + +int iso9660_mkdir(const struct fs_mkdir *const m, const struct fs_mp *const mp, + const union inode_result *const inode, struct fs_ret *const r) +{ + return -1; +} diff --git a/src/fs/iso9660/src/mount.c b/src/fs/iso9660/src/mount.c new file mode 100644 index 0000000..aeddcc5 --- /dev/null +++ b/src/fs/iso9660/src/mount.c @@ -0,0 +1,196 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <iso9660/types.h> +#include <fs/fs.h> +#include <kprintf.h> +#include <state.h> +#include <errno.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> + +struct mount +{ + char *path, header[sizeof "CD001"]; + struct fs_fd fd; + struct fs_ret *r; + struct fs_mount mount; + const struct fs_mp *mp; +}; + +static void free_mount(struct mount *const m) +{ + if (!m) + return; + + const struct fs_close c = {.fd = &m->fd}; + + m->mp->fs->close(&c, m->r); + free(m->path); + free(m); +} + +static enum state check_header(void *const args) +{ + struct mount *const m = args; + static const char header[] = {1, 'C', 'D', '0', '0', '1'}; + + if (memcmp(m->header, header, sizeof header)) + { + kprintf("invalid header"); + free_mount(m); + return STATE_FATAL; + } + + free_mount(m); + return STATE_OK; +} + +static enum state read_header(void *const args) +{ + struct mount *const m = args; + struct fs_fd *const fd = &m->fd; + const struct fs_read r = + { + .buf = m->header, + .n = sizeof m->header, + .fd = fd + }; + + if (fd->error) + { + errno = fd->error; + goto failure; + } + + *m->r = (const struct fs_ret) + { + .f = check_header, + .args = m + }; + + if (m->mp->fs->read(&r, m->r)) + goto failure; + + return STATE_AGAIN; + +failure: + free_mount(m); + return STATE_FATAL; +} + +static enum state seek_header(void *const args) +{ + struct mount *const m = args; + const struct fs_mp *const mp = m->mp; + const struct fs_seek s = + { + .fd = &m->fd, + .offset = 16 * ISO9660_SECTOR_SZ + }; + + *m->r = (const struct fs_ret) + { + .args = m, + .f = read_header + }; + + if (mp->fs->seek(&s, m->r)) + goto failure; + + return STATE_AGAIN; + +failure: + free_mount(m); + return STATE_FATAL; +} + +static int search_done(const enum state state, const char *const relpath, + const struct fs_mp *const mp, const union inode_result *const inode, + void *const args) +{ + struct mount *const m = args; + const struct fs_mount *const fm = &m->mount; + + if (!inode) + { + errno = ENOENT; + goto failure; + } + + const struct fs_open o = + { + .fd = &m->fd, + .gid = fm->gid, + .uid = fm->uid, + .mode = fm->mode, + .path = relpath + }; + + *m->r = (const struct fs_ret) + { + .args = m, + .f = seek_header + }; + + if (mp->fs->open(&o, mp, inode, m->r)) + goto failure; + + m->mp = mp; + return 0; + +failure: + free_mount(m); + return -1; +} + +int iso9660_mount(const struct fs_mount *const fm, struct fs_ret *const r) +{ + char *tgtdup = NULL; + struct mount *const m = malloc(sizeof *m); + + if (!m || !(tgtdup = strdup(fm->tgt))) + goto failure; + + *m = (const struct mount) + { + .path = tgtdup, + .mount = *fm, + .r = r + }; + + const struct inode_search s = + { + .args = m, + .path = fm->src, + .done = search_done + }; + + if (inode_search(&s, r)) + goto failure; + + return 0; + +failure: + free(tgtdup); + free(m); + return -1; +} diff --git a/src/fs/iso9660/src/open.c b/src/fs/iso9660/src/open.c new file mode 100644 index 0000000..b7c78ef --- /dev/null +++ b/src/fs/iso9660/src/open.c @@ -0,0 +1,27 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> + +int iso9660_open(const struct fs_open *const o, const struct fs_mp *const mp, + const union inode_result *const inode, struct fs_ret *const r) +{ + return -1; +} diff --git a/src/fs/iso9660/src/read.c b/src/fs/iso9660/src/read.c new file mode 100644 index 0000000..7a8569f --- /dev/null +++ b/src/fs/iso9660/src/read.c @@ -0,0 +1,27 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> +#include <stddef.h> + +int iso9660_read(const struct fs_read *const r, struct fs_ret *const ret) +{ + return -1; +} diff --git a/src/fs/iso9660/src/register.c b/src/fs/iso9660/src/register.c new file mode 100644 index 0000000..2b69651 --- /dev/null +++ b/src/fs/iso9660/src/register.c @@ -0,0 +1,44 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> + +const struct fs iso9660 = +{ + .type = "iso9660", + .flags = FS_DEV_REQUIRED, + .mount = iso9660_mount, + .stat = iso9660_stat, + .mkdir = iso9660_mkdir, + .open = iso9660_open, + .read = iso9660_read, + .write = iso9660_write, + .close = iso9660_close, + .seek = iso9660_seek, + .iops = + { + .search = iso9660_search + } +}; + +int iso9660_register(void) +{ + return fs_register(&iso9660); +} diff --git a/src/fs/iso9660/src/search.c b/src/fs/iso9660/src/search.c new file mode 100644 index 0000000..c6d1208 --- /dev/null +++ b/src/fs/iso9660/src/search.c @@ -0,0 +1,27 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> + +int iso9660_search(const char *const path, const struct fs_mp *const mp, + union inode_result *const inode, struct fs_ret *const r) +{ + return -1; +} diff --git a/src/fs/iso9660/src/seek.c b/src/fs/iso9660/src/seek.c new file mode 100644 index 0000000..c78bb52 --- /dev/null +++ b/src/fs/iso9660/src/seek.c @@ -0,0 +1,27 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <iso9660/types.h> +#include <fs/fs.h> + +int iso9660_seek(const struct fs_seek *const s, struct fs_ret *const r) +{ + return -1; +} diff --git a/src/fs/iso9660/src/stat.c b/src/fs/iso9660/src/stat.c new file mode 100644 index 0000000..e5905e4 --- /dev/null +++ b/src/fs/iso9660/src/stat.c @@ -0,0 +1,28 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> +#include <sys/stat.h> + +int iso9660_stat(const struct fs_stat *const s, const struct fs_mp *const mp, + const union inode_result *const inode, struct fs_ret *const r) +{ + return -1; +} diff --git a/src/fs/iso9660/src/write.c b/src/fs/iso9660/src/write.c new file mode 100644 index 0000000..b7baa93 --- /dev/null +++ b/src/fs/iso9660/src/write.c @@ -0,0 +1,28 @@ +/* + * 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/>. + */ + +#include <iso9660.h> +#include <iso9660/ops.h> +#include <fs/fs.h> +#include <errno.h> + +int iso9660_write(const struct fs_write *const w, struct fs_ret *const r) +{ + errno = EROFS; + return -1; +} |
