Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | /* |
| 2 | MIT License |
| 3 | |
| 4 | Copyright (c) 2026 Seregon |
| 5 | |
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | of this software and associated documentation files (the "Software"), to deal |
| 8 | in the Software without restriction, including without limitation the rights |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | copies of the Software, and to permit persons to whom the Software is |
| 11 | furnished to do so, subject to the following conditions: |
| 12 | |
| 13 | The above copyright notice and this permission notice shall be included in all |
| 14 | copies or substantial portions of the Software. |
| 15 | |
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef PAL_FILESYSTEM_H |
| 26 | #define PAL_FILESYSTEM_H |
| 27 | |
| 28 | #include "ftp_types.h" |
| 29 | #include <stddef.h> |
| 30 | #include <stdint.h> |
| 31 | #include <time.h> |
| 32 | #include <sys/types.h> |
| 33 | |
| 34 | typedef enum { |
| 35 | VFS_CAP_SENDFILE = 1U << 0, |
| 36 | VFS_CAP_STREAM_ONLY = 1U << 1 |
| 37 | } vfs_capability_t; |
| 38 | |
| 39 | typedef struct { |
| 40 | uint32_t mode; |
| 41 | uint64_t size; |
| 42 | int64_t mtime; |
| 43 | } vfs_stat_t; |
| 44 | |
| 45 | typedef struct vfs_node { |
| 46 | vfs_capability_t caps; |
| 47 | void *private_ctx; |
| 48 | int fd; |
| 49 | uint64_t size; |
| 50 | uint64_t offset; |
| 51 | |
| 52 | #if defined(PLATFORM_PS4) || defined(PLATFORM_PS5) |
| 53 | struct { |
| 54 | int self_fd; |
| 55 | uint64_t elf_off; |
| 56 | uint16_t num_entries; |
| 57 | uint16_t phnum; |
| 58 | uint64_t phoff; |
| 59 | uint64_t file_size; |
| 60 | uint32_t magic; |
| 61 | } psx; |
| 62 | #endif |
| 63 | } vfs_node_t; |
| 64 | |
| 65 | ftp_error_t vfs_stat(const char *path, vfs_stat_t *out); |
| 66 | ftp_error_t vfs_open(vfs_node_t *node, const char *path); |
| 67 | void vfs_close(vfs_node_t *node); |
| 68 | void vfs_set_offset(vfs_node_t *node, uint64_t offset); |
| 69 | ssize_t vfs_read(vfs_node_t *node, void *buffer, size_t length); |
| 70 | |
| 71 | static inline vfs_capability_t vfs_get_caps(const vfs_node_t *node) |
| 72 | { |
| 73 | return (node != NULL) ? node->caps : 0; |
| 74 | } |
| 75 | |
| 76 | static inline uint64_t vfs_get_size(const vfs_node_t *node) |
| 77 | { |
| 78 | return (node != NULL) ? node->size : 0U; |
| 79 | } |
| 80 | |
| 81 | #endif |
| 82 |