VSF Documented
vsf_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_FS_H__
19#define __VSF_FS_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "./vsf_fs_cfg.h"
24
25#if VSF_USE_FS == ENABLED
26
27#include "kernel/vsf_kernel.h"
28
29#if defined(__VSF_FS_CLASS_IMPLEMENT)
30# define __VSF_CLASS_IMPLEMENT__
31#elif defined(__VSF_FS_CLASS_INHERIT__)
32# define __VSF_CLASS_INHERIT__
33#endif
34
35#include "utilities/ooc_class.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*============================ MACROS ========================================*/
42
43#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL != ENABLED
44# error VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL is needed to use fs
45#endif
46
47/*============================ MACROFIED FUNCTIONS ===========================*/
48/*============================ TYPES =========================================*/
49
50vsf_dcl_class(vk_fs_t)
52vsf_dcl_class(vk_vfs_file_t)
53#if VSF_USE_SIMPLE_STREAM == ENABLED
55#endif
56
60
62 protected_member(
63 uint8_t close_local_size;
64 uint8_t read_local_size;
65 uint8_t write_local_size;
66 uint8_t setsize_local_size;
67 uint8_t setpos_local_size;
68 vsf_peda_evthandler_t fn_close;
70 vsf_peda_evthandler_t fn_write;
71 vsf_peda_evthandler_t fn_setsize;
72 vsf_peda_evthandler_t fn_setpos;
73
74 void * (*fn_direct_access)(vk_file_t *file);
75 )
76};
77
79 protected_member(
80 uint8_t lookup_local_size;
81 uint8_t create_local_size;
82 uint8_t unlink_local_size;
83 uint8_t chmod_local_size;
84 vsf_peda_evthandler_t fn_lookup;
85 vsf_peda_evthandler_t fn_create;
86 vsf_peda_evthandler_t fn_unlink;
87 vsf_peda_evthandler_t fn_chmod;
88 )
89};
90
91// TODO: remove fop and dop, put everything here for optimization
93 protected_member(
94 // if succeed, VSF_VFS_FILE_ATTR_MOUNTED should be set in file->attr
95 uint8_t mount_local_size;
96 uint8_t unmount_local_size;
97#if VSF_FS_CFG_USE_CACHE == ENABLED
98 uint8_t sync_local_size;
99#endif
100 uint8_t rename_local_size;
101 vsf_err_t (*fn_probe)(uint8_t *sector0_buf, uint_fast32_t sector_size);
102 vsf_peda_evthandler_t fn_mount;
103 vsf_peda_evthandler_t fn_unmount;
104 vsf_peda_evthandler_t fn_rename;
105#if VSF_FS_CFG_USE_CACHE == ENABLED
107#endif
108 vk_fs_fop_t fop;
109 vk_fs_dop_t dop;
111};
112
115 public_member(
116 vk_file_attr_t attr;
117 char *name;
119
120#if VSF_FS_CFG_TIME == ENABLED
121 struct {
122 uint64_t create;
124 uint64_t modify;
125 } time;
126#endif
128
129 protected_member(
130 const vk_fs_op_t *fsop;
131 vk_fs_info_t *fsinfo;
132
133 vk_file_t *parent;
134 uint64_t pos;
136
137 private_member(
138 uint32_t ref;
139 )
140};
141
144};
145
146#if defined(__VSF_FS_CLASS_INHERIT__) || defined(__VSF_FS_CLASS_IMPLEMENT)
147typedef enum vk_vfs_file_attr_t {
148 VSF_VFS_FILE_ATTR_MOUNTED = VSF_FILE_ATTR_EXT,
149} vk_vfs_file_attr_t;
150
151vsf_class(vk_vfs_file_t) {
152 implement(vk_file_t)
153 implement(vsf_dlist_node_t)
154
155 protected_member(
156 bool is_to_unlink;
157 union {
158 struct {
159 void *param;
160 struct {
161 void (*fn_read)(uintptr_t target, vsf_evt_t evt);
162 void (*fn_write)(uintptr_t target, vsf_evt_t evt);
163 } callback;
164# if VSF_FS_CFG_VFS_FILE_HAS_OP == ENABLED
165 void *op;
166# endif
167 } f;
168 struct {
169 void *param;
170 vsf_dlist_t child_list;
171 } d;
172 struct {
173 const vk_fs_op_t *op;
174 void *data;
175 vk_file_t *root;
176 } subfs;
177 };
178 )
179};
180#endif
181
182#if VSF_USE_SIMPLE_STREAM == ENABLED
184 public_member(
185 vk_file_t *file;
187 private_member(
189 uint32_t rw_size;
190 vsf_stream_t *stream;
191 uint32_t cur_size;
192 uint8_t *cur_buff;
193 vsf_eda_t *cur_eda;
194 )
195};
196#endif
197
198#if defined(__VSF_FS_CLASS_INHERIT__) || defined(__VSF_FS_CLASS_IMPLEMENT)
202
204 const char *name;
205 vk_file_attr_t attr;
206)
208 const char *name;
209)
210__vsf_component_peda_ifs(vk_file_lookup,
211 const char *name;
212 vk_file_t **result;
213)
216)
218 vk_file_t *olddir;
219 const char *oldname;
220 vk_file_t *newdir;
221 const char *newname;
222)
224 uint8_t *buff;
226)
228 uint8_t *buff;
230)
231__vsf_component_peda_ifs(vk_file_setpos,
233 uint64_t *result;
234)
237#endif
238
239/*============================ GLOBAL VARIABLES ==============================*/
240
241extern vk_fs_op_t vk_vfs_op;
242
243/*============================ PROTOTYPES ====================================*/
244
245extern void vk_fs_init(void);
246
247extern vsf_err_t vk_fs_mount(vk_file_t *dir, const vk_fs_op_t *fsop, void *fsdata);
249#if VSF_FS_CFG_USE_CACHE == ENABLED
250extern vsf_err_t vk_fs_sync(vk_file_t *dir);
251#endif
252
253extern vsf_err_t vk_file_open(vk_file_t *dir, const char *name, vk_file_t **file);
254extern vsf_err_t vk_file_create(vk_file_t *dir, const char *name, vk_file_attr_t attr);
255extern vsf_err_t vk_file_unlink(vk_file_t *dir, const char *name);
256extern vsf_err_t vk_file_rename(vk_file_t *olddir, const char *oldname, vk_file_t *newdir, const char *newname);
257
259extern vsf_err_t vk_file_close(vk_file_t *file);
260extern uint64_t vk_file_tell(vk_file_t *file);
265#if VSF_FS_CFG_USE_CACHE == ENABLED
266extern vsf_err_t vk_file_sync(vk_file_t *file);
267#endif
268
269extern char * vk_file_getfileext(char *fname);
270extern char * vk_file_getfilename(char *path);
272
273#if defined(__VSF_FS_CLASS_INHERIT__) || defined(__VSF_FS_CLASS_IMPLEMENT)
274extern bool vk_file_is_match(char *path, char *name);
275extern bool vk_file_is_div(char ch);
276
278extern void vk_file_free(vk_file_t *file);
279extern void * vk_file_direct_access(vk_file_t *file);
280
281extern void vk_fs_return(vk_file_t *file, vsf_err_t err);
282
283dcl_vsf_peda_methods(extern, vk_fsop_succeed)
284dcl_vsf_peda_methods(extern, vk_fsop_not_support)
285#endif
286
287#if VSF_USE_SIMPLE_STREAM == ENABLED
290#endif
291
292#ifdef __cplusplus
293}
294#endif
295
296/*============================ INCLUDES ======================================*/
297
298#ifndef __VSF_HEADER_ONLY_SHOW_FS_INFO__
299# if VSF_FS_USE_FATFS == ENABLED
301# endif
302# if VSF_FS_USE_MEMFS == ENABLED
304# endif
305# if VSF_FS_USE_WINFS == ENABLED
307# endif
308# if VSF_FS_USE_LITTLEFS == ENABLED
310# endif
311# if VSF_FS_USE_LINFS == ENABLED
313# endif
314# if VSF_FS_USE_ROMFS == ENABLED
316# endif
317#endif
318
319#undef __VSF_FS_CLASS_IMPLEMENT
320#undef __VSF_FS_CLASS_INHERIT__
321
322#endif // VSF_USE_FS
323#endif // __VSF_FS_H__
vsf_err_t
Definition __type.h:42
Definition vsf_fs.h:183
Definition vsf_fs.h:114
Definition vsf_fs.h:78
Definition vsf_fs.h:61
Definition vsf_fs.h:92
Definition vsf_eda.h:766
Definition vsf_simple_stream.h:254
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
#define vsf_dcl_class
Definition ooc_class.h:46
#define vsf_class(__name)
Definition ooc_class.h:48
time_t time(time_t *t)
Definition vsf_linux_glibc_time.c:89
uint32_t uintptr_t
Definition stdint.h:38
unsigned int uint_fast32_t
Definition stdint.h:27
long long int64_t
Definition stdint.h:10
unsigned long long uint64_t
Definition stdint.h:11
unsigned short uint_fast16_t
Definition stdint.h:25
Definition vsf_fs.h:142
vk_file_t root
Definition vsf_fs.h:143
Definition vsf_list.h:888
Definition vsf_list.h:883
#define access
Definition unistd.h:115
void sync(void)
Definition vsf_linux_fs.c:2137
#define __vsf_component_peda_ifs(__peda_name,...)
Definition vsf_component_cfg.h:62
#define vsf_peda_evthandler_t
Definition vsf_component_cfg.h:37
int16_t vsf_evt_t
Definition vsf_eda.h:654
#define dcl_vsf_peda_methods(__decoration,...)
Definition vsf_eda.h:372
bool vk_file_is_match(char *path, char *name)
Definition vsf_fs.c:268
void vk_file_free(vk_file_t *file)
Definition vsf_fs.c:222
void * vk_file_direct_access(vk_file_t *file)
Definition vsf_fs.c:233
vk_file_t * vk_file_alloc(uint_fast16_t size)
Definition vsf_fs.c:203
bool vk_file_is_div(char ch)
Definition vsf_fs.c:263
vsf_err_t vk_file_rename(vk_file_t *olddir, const char *oldname, vk_file_t *newdir, const char *newname)
Definition vsf_fs.c:839
vsf_err_t vk_file_sync(vk_file_t *file)
Definition vsf_fs.c:872
vk_file_t * vk_file_get_parent(vk_file_t *file)
Definition vsf_fs.c:279
vsf_err_t vk_file_write(vk_file_t *file, uint8_t *buff, uint_fast32_t size)
Definition vsf_fs.c:740
void vk_fs_init(void)
Definition vsf_fs.c:292
char * vk_file_getfilename(char *path)
Definition vsf_fs.c:250
vsf_err_t vk_file_unlink(vk_file_t *dir, const char *name)
Definition vsf_fs.c:821
vsf_err_t vk_file_close(vk_file_t *file)
Definition vsf_fs.c:713
vsf_err_t vk_fs_sync(vk_file_t *dir)
Definition vsf_fs.c:674
vsf_err_t vk_file_open(vk_file_t *dir, const char *name, vk_file_t **file)
Definition vsf_fs.c:686
char * vk_file_getfileext(char *fname)
Definition vsf_fs.c:241
vsf_err_t vk_file_create(vk_file_t *dir, const char *name, vk_file_attr_t attr)
Definition vsf_fs.c:802
uint64_t vk_file_tell(vk_file_t *file)
Definition vsf_fs.c:771
uint32_t vk_file_get_ref(vk_file_t *file)
Definition vsf_fs.c:198
vsf_err_t vk_file_read(vk_file_t *file, uint8_t *buff, uint_fast32_t size)
Definition vsf_fs.c:724
vk_fs_op_t vk_vfs_op
vsf_err_t vk_file_seek(vk_file_t *file, int64_t offset, vk_file_whence_t whence)
Definition vsf_fs.c:777
vsf_err_t vk_fs_mount(vk_file_t *dir, const vk_fs_op_t *fsop, void *fsdata)
Definition vsf_fs.c:645
vsf_err_t vk_file_setsize(vk_file_t *file, uint64_t size)
Definition vsf_fs.c:756
vsf_err_t vk_file_write_stream(vk_file_stream_t *pthis, vsf_stream_t *stream, uint_fast32_t size)
Definition vsf_fs.c:1555
vsf_err_t vk_fs_unmount(vk_file_t *dir)
Definition vsf_fs.c:661
vsf_err_t vk_file_read_stream(vk_file_stream_t *pthis, vsf_stream_t *stream, uint_fast32_t size)
Definition vsf_fs.c:1544
vk_file_attr_t
Definition vsf_fs_cfg.h:99
@ VSF_FILE_ATTR_EXT
Definition vsf_fs_cfg.h:108
vk_file_whence_t
Definition vsf_fs_cfg.h:114
const vk_fs_op_t * fsop
Definition vsf_malfs.c:135
uint64_t offset
Definition vsf_memfs.h:49
uint8_t * buff
Definition vsf_memfs.h:51
uint32_t size
Definition vsf_memfs.h:50