VSF Documented
vsf_linux_fs.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_LINUX_FS_INTERNAL_H__
19#define __VSF_LINUX_FS_INTERNAL_H__
20
21/*============================ INCLUDES ======================================*/
22
23// avoid to include vsf.h, include necessary headers only
24// #include "vsf.h"
25
27#include "hal/arch/vsf_arch.h"
28#include "kernel/vsf_kernel.h"
29
30#if VSF_USE_LINUX == ENABLED
31
32#if VSF_LINUX_CFG_RELATIVE_PATH == ENABLED
33# include "../../include/termios.h"
35#else
36# include <termios.h>
37# include <sys/stat.h>
38#endif
39
40#if defined(__VSF_LINUX_FS_CLASS_IMPLEMENT)
41# define __VSF_CLASS_IMPLEMENT__
42#elif defined(__VSF_LINUX_FS_CLASS_INHERIT__)
43# define __VSF_CLASS_INHERIT__
44#endif
45
46#include "utilities/ooc_class.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*============================ MACROS ========================================*/
53
54#if VSF_USE_FS != ENABLED
55# error VSF_USE_FS MUST be enabled to use fs in linux
56#endif
57
58/*============================ MACROFIED FUNCTIONS ===========================*/
59/*============================ TYPES =========================================*/
60
65
66enum {
68};
69
70typedef struct vsf_linux_fd_op_t {
73 void (*fn_init)(vsf_linux_fd_t *sfd);
74 void (*fn_fini)(vsf_linux_fd_t *sfd);
75 int (*fn_fcntl)(vsf_linux_fd_t *sfd, int cmd, uintptr_t arg);
76 ssize_t (*fn_read)(vsf_linux_fd_t *sfd, void *buf, size_t count);
77 ssize_t (*fn_write)(vsf_linux_fd_t *sfd, const void *buf, size_t count);
79 int (*fn_eof)(vsf_linux_fd_t *sfd);
81 int (*fn_stat)(vsf_linux_fd_t *sfd, struct stat *buf);
82
83 void * (*fn_mmap)(vsf_linux_fd_t *sfd, off64_t offset, size_t len, uint_fast32_t feature);
84 int (*fn_munmap)(vsf_linux_fd_t *sfd, void *buffer);
85 int (*fn_msync)(vsf_linux_fd_t *sfd, void *buffer);
87
90 void *param;
91 void (*cb)(vsf_linux_fd_priv_t *priv, void *param, short events, vsf_protect_t orig);
93
95 protected_member(
96 // target is used in socket_unix to indicate message for sendmsg/recvmsg,
97 // ofc it can be used in other fd types
98 void *target;
99 int flags;
100
101 short status;
102 short events;
103 // sticky_events will not be cleared
104 // use for eg pipe, pipe_tx is closed, pipe_rx will always POLLIN
105 short sticky_events;
106 short user_data;
107
108 vsf_linux_fd_priv_callback_t events_callback[2];
110 private_member(
111 int ref;
112 )
113};
114
116 protected_member(
117 int fd;
118 int fd_flags;
119 int cur_rdflags;
120 int cur_wrflags;
121 const vsf_linux_fd_op_t *op;
123
124 private_member(
125 vsf_dlist_node_t fd_node;
126 void *mmapped_buffer;
127 )
128
129 protected_member(
130 int unget_buff;
132
133 // used while binding fd to something
134 // eg: in popen, fd is binded with the target pid
135 union {
136 pid_t pid;
137 } binding;
139};
140
141#if defined(__VSF_LINUX_FS_CLASS_IMPLEMENT) || defined(__VSF_LINUX_FS_CLASS_INHERIT__)
142typedef struct vk_file_t vk_file_t;
143typedef struct vsf_linux_fs_priv_t {
144 implement(vsf_linux_fd_priv_t)
145 vk_file_t *file;
146
147 union {
148 struct dirent dir;
149 struct dirent64 dir64;
150 };
151} vsf_linux_fs_priv_t;
152
153vsf_dcl_class(vsf_linux_stream_priv_t)
154typedef void (*vsf_linux_stream_on_evt_t)(vsf_linux_stream_priv_t *priv, vsf_protect_t orig, short event, bool is_ready);
155
156vsf_class(vsf_linux_stream_priv_t) {
157 public_member(
158 implement(vsf_linux_fs_priv_t)
159 )
160 protected_member(
161 vsf_stream_t *stream_rx;
162 vsf_stream_t *stream_tx;
163 vsf_linux_stream_on_evt_t on_evt;
164 bool stream_rx_allocated;
165 bool stream_tx_allocated;
166 )
167};
168
169vsf_class(vsf_linux_pipe_priv_t) {
170 protected_member(
171 implement(vsf_linux_stream_priv_t)
172 vsf_linux_pipe_priv_t *pipe_remote;
173 )
174};
175
176typedef struct vsf_linux_term_priv_t {
177 implement(vsf_linux_pipe_priv_t)
178 const vsf_linux_fd_op_t *subop;
179 struct termios termios;
180 char esc_type;
181 bool line_start;
182 bool subop_inited;
183} vsf_linux_term_priv_t;
184
185typedef struct vsf_linux_key_t vsf_linux_key_t;
186vsf_class(vsf_linux_key_priv_t) {
187 public_member(
188 implement(vsf_linux_fd_priv_t)
189 )
190 protected_member(
191 union {
192 struct {
193 unsigned short *semadj_arr;
194 } sem;
195 } u;
196 vsf_linux_key_t *key;
197 void (*fn_fini)(vsf_linux_fd_t *sfd);
198 int (*fn_close)(vsf_linux_fd_t *sfd);
199 )
200};
201#endif
202
203/*============================ GLOBAL VARIABLES ==============================*/
204
205#if defined(__VSF_LINUX_FS_CLASS_IMPLEMENT) || defined(__VSF_LINUX_FS_CLASS_INHERIT__)
211#endif
212
213/*============================ LOCAL VARIABLES ===============================*/
214/*============================ PROTOTYPES ====================================*/
215
216#if defined(__VSF_LINUX_FS_CLASS_IMPLEMENT) || defined(__VSF_LINUX_FS_CLASS_INHERIT__)
217extern int vsf_linux_fd_bind_target_ex(int fd,
218 void *target, const vsf_linux_fd_op_t *op,
221 uint_fast32_t feature, uint64_t size);
222extern int vsf_linux_fd_bind_target(int fd, void *target,
224 vsf_param_eda_evthandler_t peda_write);
225// compatible with file and directory
226extern int vsf_linux_fd_get_target(int fd, void **target);
227extern int vsf_linux_fs_bind_target(const char *pathname, void *target,
229 vsf_param_eda_evthandler_t peda_write);
230extern int vsf_linux_fs_bind_dir_target(const char *pathname, void *target);
231int vsf_linux_fs_bind_target_ex(const char *pathname,
232 void *target, const vsf_linux_fd_op_t *op,
235 uint_fast32_t feature, uint64_t size);
236extern int vsf_linux_fs_get_target(const char *pathname, void **target);
237typedef struct vk_vfs_file_t vk_vfs_file_t;
238extern int vsf_linux_fs_bind_target_relative(vk_vfs_file_t *dir, const char *pathname,
239 void *target, const vsf_linux_fd_op_t *op,
240 uint_fast32_t feature, uint64_t size);
241extern int vsf_linux_fs_bind_pipe(const char *pathname1, const char *pathname2, bool exclusive);
242extern int vsf_linux_create_pty(int num);
243
244extern int vsf_linux_fd_create(vsf_linux_fd_t **sfd, const vsf_linux_fd_op_t *op);
245extern vsf_linux_fd_t * vsf_linux_fd_get(int fd);
246extern void vsf_linux_fd_delete(int fd);
247extern bool vsf_linux_fd_is_block(vsf_linux_fd_t *sfd);
248
249extern int vsf_linux_fd_get_feature(int fd, uint_fast32_t *feature);
250extern int vsf_linux_fd_set_feature(int fd, uint_fast32_t feature);
251extern int vsf_linux_fd_add_feature(int fd, uint_fast32_t feature);
252
253extern int vsf_linux_fd_set_size(int fd, uint64_t size);
254
255// vsf_linux_fd_xx_trigger/vsf_linux_fd_xx_pend MUST be called scheduler protected
262extern short vsf_linux_fd_get_status(vsf_linux_fd_priv_t *priv, short status);
263
264// stream
265// IMPORTANT: priority of stream MUST be within scheduler priorities
266extern vsf_linux_fd_t * vsf_linux_stream(vsf_stream_t *stream_rx, vsf_stream_t *stream_tx);
269
270// pipe
272extern vsf_linux_fd_t * vsf_linux_tx_pipe(vsf_linux_pipe_priv_t *priv_rx);
273#endif
274
275extern int vsf_linux_fs_bind_buffer(const char *pathname, void *buffer,
276 uint_fast32_t feature, uint64_t size);
277
278#ifdef __cplusplus
279}
280#endif
281
282#undef __VSF_LINUX_FS_CLASS_IMPLEMENT
283#undef __VSF_LINUX_FS_CLASS_INHERIT__
284
285/*============================ INCLUDES ======================================*/
286
287#include "./vfs/vsf_linux_vfs.h"
288
289#endif // VSF_USE_LINUX
290#endif // __VSF_LINUX_FS_INTERNAL_H__
291/* EOF */
Definition vsf_fs.h:114
Definition vsf_linux_fs.h:94
Definition vsf_linux_fs.h:115
Definition vsf_linux.h:278
Definition vsf_linux.h:158
Definition vsf_queue_stream.h:60
Definition vsf_simple_stream.h:254
union @878::@889::@890 u
int pid_t
Definition types.h:85
long long off64_t
Definition types.h:97
int ssize_t
Definition types.h:68
#define vsf_dcl_class
Definition ooc_class.h:46
#define vsf_class(__name)
Definition ooc_class.h:48
uint32_t uintptr_t
Definition stdint.h:38
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned long long uint64_t
Definition stdint.h:11
Definition dirent.h:42
Definition dirent.h:35
Definition stat.h:105
Definition termios.h:205
Definition vsf_list.h:888
Definition vsf_linux_fs.h:70
int(* fn_setsize)(vsf_linux_fd_t *sfd, off64_t size)
Definition vsf_linux_fs.h:80
ssize_t(* fn_write)(vsf_linux_fd_t *sfd, const void *buf, size_t count)
Definition vsf_linux_fs.h:77
int feature
Definition vsf_linux_fs.h:72
int(* fn_msync)(vsf_linux_fd_t *sfd, void *buffer)
Definition vsf_linux_fs.h:85
int priv_size
Definition vsf_linux_fs.h:71
int(* fn_fcntl)(vsf_linux_fd_t *sfd, int cmd, uintptr_t arg)
Definition vsf_linux_fs.h:75
int(* fn_stat)(vsf_linux_fd_t *sfd, struct stat *buf)
Definition vsf_linux_fs.h:81
int(* fn_close)(vsf_linux_fd_t *sfd)
Definition vsf_linux_fs.h:78
int(* fn_eof)(vsf_linux_fd_t *sfd)
Definition vsf_linux_fs.h:79
ssize_t(* fn_read)(vsf_linux_fd_t *sfd, void *buf, size_t count)
Definition vsf_linux_fs.h:76
int(* fn_munmap)(vsf_linux_fd_t *sfd, void *buffer)
Definition vsf_linux_fs.h:84
void(* fn_init)(vsf_linux_fd_t *sfd)
Definition vsf_linux_fs.h:73
void(* fn_fini)(vsf_linux_fd_t *sfd)
Definition vsf_linux_fs.h:74
Definition vsf_linux_fs.h:88
short pendind_events
Definition vsf_linux_fs.h:89
void(* cb)(vsf_linux_fd_priv_t *priv, void *param, short events, vsf_protect_t orig)
Definition vsf_linux_fs.h:91
void * param
Definition vsf_linux_fs.h:90
Definition vsf_linux.h:128
uintalu_t vsf_protect_t
Definition vsf_arch_abstraction.h:53
void(* vsf_param_eda_evthandler_t)(uintptr_t target, vsf_evt_t evt)
Definition vsf_eda.h:658
int vsf_linux_fs_bind_target_relative(vk_vfs_file_t *dir, const char *pathname, void *target, const vsf_linux_fd_op_t *op, uint_fast32_t feature, uint64_t size)
Definition vsf_linux_fs.c:2736
int vsf_linux_fs_get_target(const char *pathname, void **target)
Definition vsf_linux_fs.c:2724
int vsf_linux_fs_bind_dir_target(const char *pathname, void *target)
Definition vsf_linux_fs.c:2789
vsf_linux_fd_t * vsf_linux_tx_pipe(vsf_linux_pipe_priv_t *priv_rx)
Definition vsf_linux_fs.c:3293
int vsf_linux_fd_bind_target_ex(int fd, void *target, const vsf_linux_fd_op_t *op, vsf_param_eda_evthandler_t peda_read, vsf_param_eda_evthandler_t peda_write, uint_fast32_t feature, uint64_t size)
Definition vsf_linux_fs.c:2697
void vsf_linux_fd_set_events(vsf_linux_fd_priv_t *priv, short events, vsf_protect_t orig)
Definition vsf_linux_fs.c:1158
int vsf_linux_fd_set_feature(int fd, uint_fast32_t feature)
Definition vsf_linux_fs.c:885
int vsf_linux_fs_bind_target(const char *pathname, void *target, vsf_param_eda_evthandler_t peda_read, vsf_param_eda_evthandler_t peda_write)
Definition vsf_linux_fs.c:2776
bool vsf_linux_fd_is_block(vsf_linux_fd_t *sfd)
Definition vsf_linux_fs.c:1081
const vsf_linux_fd_op_t __vsf_linux_stream_fdop
Definition vsf_linux_fs.c:231
int vsf_linux_fd_get_feature(int fd, uint_fast32_t *feature)
Definition vsf_linux_fs.c:873
int vsf_linux_create_pty(int num)
Definition vsf_linux_fs.c:3350
vsf_linux_fd_priv_callback_t * vsf_linux_fd_claim_calback(vsf_linux_fd_priv_t *priv)
Definition vsf_linux_fs.c:1106
int vsf_linux_fd_create(vsf_linux_fd_t **sfd, const vsf_linux_fd_op_t *op)
Definition vsf_linux_fs.c:1027
vsf_linux_fd_t * vsf_linux_rx_stream(vsf_stream_t *stream)
Definition vsf_linux_fs.c:3179
int vsf_linux_fs_bind_pipe(const char *pathname1, const char *pathname2, bool exclusive)
Definition vsf_linux_fs.c:3321
vsf_linux_fd_t * vsf_linux_fd_get(int fd)
Definition vsf_linux_fs.c:849
int vsf_linux_fd_bind_target(int fd, void *target, vsf_param_eda_evthandler_t peda_read, vsf_param_eda_evthandler_t peda_write)
Definition vsf_linux_fs.c:2717
const vsf_linux_fd_op_t vsf_linux_term_fdop
Definition vsf_linux_fs.c:252
int vsf_linux_fd_get_target(int fd, void **target)
Definition vsf_linux_fs.c:2684
void vsf_linux_fd_delete(int fd)
Definition vsf_linux_fs.c:1055
const vsf_linux_fd_op_t vsf_linux_pipe_fdop
Definition vsf_linux_fs.c:241
void vsf_linux_fd_clear_status(vsf_linux_fd_priv_t *priv, short status, vsf_protect_t orig)
Definition vsf_linux_fs.c:1184
int vsf_linux_fd_set_size(int fd, uint64_t size)
Definition vsf_linux_fs.c:904
void vsf_linux_fd_release_calback(vsf_linux_fd_priv_t *priv, vsf_linux_fd_priv_callback_t *callback)
Definition vsf_linux_fs.c:1120
int vsf_linux_fs_bind_target_ex(const char *pathname, void *target, const vsf_linux_fd_op_t *op, vsf_param_eda_evthandler_t peda_read, vsf_param_eda_evthandler_t peda_write, uint_fast32_t feature, uint64_t size)
Definition vsf_linux_fs.c:2758
short vsf_linux_fd_get_status(vsf_linux_fd_priv_t *priv, short status)
Definition vsf_linux_fs.c:1191
short vsf_linux_fd_pend_events(vsf_linux_fd_priv_t *priv, short events, vsf_linux_trigger_t *trig, vsf_protect_t orig)
Definition vsf_linux_fs.c:1125
void vsf_linux_fd_set_status(vsf_linux_fd_priv_t *priv, short status, vsf_protect_t orig)
Definition vsf_linux_fs.c:1173
vsf_linux_fd_t * vsf_linux_stream(vsf_stream_t *stream_rx, vsf_stream_t *stream_tx)
Definition vsf_linux_fs.c:3165
const vsf_linux_fd_op_t vsf_linux_key_fdop
Definition vsf_linux_fs.c:263
vsf_linux_fd_t * vsf_linux_rx_pipe(vsf_queue_stream_t *queue_stream)
Definition vsf_linux_fs.c:3264
vsf_linux_fd_t * vsf_linux_tx_stream(vsf_stream_t *stream)
Definition vsf_linux_fs.c:3184
const vsf_linux_fd_op_t __vsf_linux_fs_fdop
Definition vsf_linux_fs.c:200
int vsf_linux_fd_add_feature(int fd, uint_fast32_t feature)
Definition vsf_linux_fs.c:895
@ VSF_LINUX_FDOP_FEATURE_FS
Definition vsf_linux_fs.h:67
int vsf_linux_fs_bind_buffer(const char *pathname, void *buffer, uint_fast32_t feature, uint64_t size)
Definition vsf_linux_fs.c:2855
uint64_t offset
Definition vsf_memfs.h:49
uint32_t size
Definition vsf_memfs.h:50
uint8_t status
Definition vsf_tgui.h:139
struct event_t events[32]
Definition vsf_xboot.c:36