Seregon/zftpd

Zero-copy FTP/HTTP Daemon compatible with all POSIX systems

C/11.0 KB/No license
include/pal_filesystem.h
zftpd / include / pal_filesystem.h
1/*
2MIT License
3 
4Copyright (c) 2026 Seregon
5 
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12 
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15 
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
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 
34typedef enum {
35 VFS_CAP_SENDFILE = 1U << 0,
36 VFS_CAP_STREAM_ONLY = 1U << 1
37} vfs_capability_t;
38 
39typedef struct {
40 uint32_t mode;
41 uint64_t size;
42 int64_t mtime;
43} vfs_stat_t;
44 
45typedef 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 
65ftp_error_t vfs_stat(const char *path, vfs_stat_t *out);
66ftp_error_t vfs_open(vfs_node_t *node, const char *path);
67void vfs_close(vfs_node_t *node);
68void vfs_set_offset(vfs_node_t *node, uint64_t offset);
69ssize_t vfs_read(vfs_node_t *node, void *buffer, size_t length);
70 
71static inline vfs_capability_t vfs_get_caps(const vfs_node_t *node)
72{
73 return (node != NULL) ? node->caps : 0;
74}
75 
76static inline uint64_t vfs_get_size(const vfs_node_t *node)
77{
78 return (node != NULL) ? node->size : 0U;
79}
80 
81#endif
82