1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
45
46
47
50
51
52
55
56
57
60
61
62
65
66
67
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
101
105
109
113
117
121
125
129
130
131
132
133
134
138
142
146
150
154
158
162
166
170
174
178
179
183
187
191
192
193
194
195
196
200
204
208
209
210
211
212
213
214
218
222
226
230
234
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
324
325
326
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/* ... */
#ifndef __ESP_VFS_H__
#define __ESP_VFS_H__
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#include <unistd.h>
#include <utime.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "esp_err.h"
#include <sys/types.h>
#include <sys/reent.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/termios.h>
#include <sys/poll.h>14 includes
#ifdef __clang__
#include <sys/dirent.h>
#else
#include <dirent.h>
#endif
#include <string.h>
#include "sdkconfig.h"
#include "esp_vfs_ops.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _SYS_TYPES_FD_SET
#error "VFS should be used with FD_SETSIZE and FD_SET from sys/types.h"
#endif
/* ... */
#define MAX_FDS FD_SETSIZE
/* ... */
#define ESP_VFS_PATH_MAX 15
/* ... */
#define ESP_VFS_FLAG_DEFAULT (1 << 0)
/* ... */
#define ESP_VFS_FLAG_CONTEXT_PTR (1 << 1)
/* ... */
#define ESP_VFS_FLAG_READONLY_FS (1 << 2)
/* ... */
#define ESP_VFS_FLAG_STATIC (1 << 3)6 defines
/* ... */
typedef struct
{
int flags;
union {
ssize_t (*write_p)(void* p, int fd, const void * data, size_t size);
ssize_t (*write)(int fd, const void * data, size_t size);
}{ ... };
union {
off_t (*lseek_p)(void* p, int fd, off_t size, int mode);
off_t (*lseek)(int fd, off_t size, int mode);
}{ ... };
union {
ssize_t (*read_p)(void* ctx, int fd, void * dst, size_t size);
ssize_t (*read)(int fd, void * dst, size_t size);
}{ ... };
union {
ssize_t (*pread_p)(void *ctx, int fd, void * dst, size_t size, off_t offset);
ssize_t (*pread)(int fd, void * dst, size_t size, off_t offset);
}{ ... };
union {
ssize_t (*pwrite_p)(void *ctx, int fd, const void *src, size_t size, off_t offset);
ssize_t (*pwrite)(int fd, const void *src, size_t size, off_t offset);
}{ ... };
union {
int (*open_p)(void* ctx, const char * path, int flags, int mode);
int (*open)(const char * path, int flags, int mode);
}{ ... };
union {
int (*close_p)(void* ctx, int fd);
int (*close)(int fd);
}{ ... };
union {
int (*fstat_p)(void* ctx, int fd, struct stat * st);
int (*fstat)(int fd, struct stat * st);
}{ ... };
#ifdef CONFIG_VFS_SUPPORT_DIR
union {
int (*stat_p)(void* ctx, const char * path, struct stat * st);
int (*stat)(const char * path, struct stat * st);
}{ ... };
union {
int (*link_p)(void* ctx, const char* n1, const char* n2);
int (*link)(const char* n1, const char* n2);
}{ ... };
union {
int (*unlink_p)(void* ctx, const char *path);
int (*unlink)(const char *path);
}{ ... };
union {
int (*rename_p)(void* ctx, const char *src, const char *dst);
int (*rename)(const char *src, const char *dst);
}{ ... };
union {
DIR* (*opendir_p)(void* ctx, const char* name);
DIR* (*opendir)(const char* name);
}{ ... };
union {
struct dirent* (*readdir_p)(void* ctx, DIR* pdir);
struct dirent* (*readdir)(DIR* pdir);
}{ ... };
union {
int (*readdir_r_p)(void* ctx, DIR* pdir, struct dirent* entry, struct dirent** out_dirent);
int (*readdir_r)(DIR* pdir, struct dirent* entry, struct dirent** out_dirent);
}{ ... };
union {
long (*telldir_p)(void* ctx, DIR* pdir);
long (*telldir)(DIR* pdir);
}{ ... };
union {
void (*seekdir_p)(void* ctx, DIR* pdir, long offset);
void (*seekdir)(DIR* pdir, long offset);
}{ ... };
union {
int (*closedir_p)(void* ctx, DIR* pdir);
int (*closedir)(DIR* pdir);
}{ ... };
union {
int (*mkdir_p)(void* ctx, const char* name, mode_t mode);
int (*mkdir)(const char* name, mode_t mode);
}{ ... };
union {
int (*rmdir_p)(void* ctx, const char* name);
int (*rmdir)(const char* name);
}{ ... };
/* ... */#endif
union {
int (*fcntl_p)(void* ctx, int fd, int cmd, int arg);
int (*fcntl)(int fd, int cmd, int arg);
}{ ... };
union {
int (*ioctl_p)(void* ctx, int fd, int cmd, va_list args);
int (*ioctl)(int fd, int cmd, va_list args);
}{ ... };
union {
int (*fsync_p)(void* ctx, int fd);
int (*fsync)(int fd);
}{ ... };
#ifdef CONFIG_VFS_SUPPORT_DIR
union {
int (*access_p)(void* ctx, const char *path, int amode);
int (*access)(const char *path, int amode);
}{ ... };
union {
int (*truncate_p)(void* ctx, const char *path, off_t length);
int (*truncate)(const char *path, off_t length);
}{ ... };
union {
int (*ftruncate_p)(void* ctx, int fd, off_t length);
int (*ftruncate)(int fd, off_t length);
}{ ... };
union {
int (*utime_p)(void* ctx, const char *path, const struct utimbuf *times);
int (*utime)(const char *path, const struct utimbuf *times);
}{ ... };
/* ... */#endif
#ifdef CONFIG_VFS_SUPPORT_TERMIOS
union {
int (*tcsetattr_p)(void *ctx, int fd, int optional_actions, const struct termios *p);
int (*tcsetattr)(int fd, int optional_actions, const struct termios *p);
}{ ... };
union {
int (*tcgetattr_p)(void *ctx, int fd, struct termios *p);
int (*tcgetattr)(int fd, struct termios *p);
}{ ... };
union {
int (*tcdrain_p)(void *ctx, int fd);
int (*tcdrain)(int fd);
}{ ... };
union {
int (*tcflush_p)(void *ctx, int fd, int select);
int (*tcflush)(int fd, int select);
}{ ... };
union {
int (*tcflow_p)(void *ctx, int fd, int action);
int (*tcflow)(int fd, int action);
}{ ... };
union {
pid_t (*tcgetsid_p)(void *ctx, int fd);
pid_t (*tcgetsid)(int fd);
}{ ... };
union {
int (*tcsendbreak_p)(void *ctx, int fd, int duration);
int (*tcsendbreak)(int fd, int duration);
}{ ... };
/* ... */#endif
#if CONFIG_VFS_SUPPORT_SELECT || defined __DOXYGEN__
esp_err_t (*start_select)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, esp_vfs_select_sem_t sem, void **end_select_args);
int (*socket_select)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
void (*stop_socket_select)(void *sem);
void (*stop_socket_select_isr)(void *sem, BaseType_t *woken);
void* (*get_socket_select_semaphore)(void);
esp_err_t (*end_select)(void *end_select_args);/* ... */
#endif
}{ ... } esp_vfs_t;
/* ... */
esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ctx);
/* ... */
esp_err_t esp_vfs_register_fd_range(const esp_vfs_t *vfs, void *ctx, int min_fd, int max_fd);
/* ... */
esp_err_t esp_vfs_register_with_id(const esp_vfs_t *vfs, void *ctx, esp_vfs_id_t *vfs_id);
/* ... */
esp_err_t esp_vfs_unregister(const char* base_path);
/* ... */
esp_err_t esp_vfs_unregister_with_id(esp_vfs_id_t vfs_id);
/* ... */
esp_err_t esp_vfs_register_fd(esp_vfs_id_t vfs_id, int *fd);
/* ... */
esp_err_t esp_vfs_register_fd_with_local_fd(esp_vfs_id_t vfs_id, int local_fd, bool permanent, int *fd);
/* ... */
esp_err_t esp_vfs_unregister_fd(esp_vfs_id_t vfs_id, int fd);
/* ... */
ssize_t esp_vfs_write(struct _reent *r, int fd, const void * data, size_t size);
off_t esp_vfs_lseek(struct _reent *r, int fd, off_t size, int mode);
ssize_t esp_vfs_read(struct _reent *r, int fd, void * dst, size_t size);
int esp_vfs_open(struct _reent *r, const char * path, int flags, int mode);
int esp_vfs_close(struct _reent *r, int fd);
int esp_vfs_fstat(struct _reent *r, int fd, struct stat * st);
int esp_vfs_stat(struct _reent *r, const char * path, struct stat * st);
int esp_vfs_link(struct _reent *r, const char* n1, const char* n2);
int esp_vfs_unlink(struct _reent *r, const char *path);
int esp_vfs_rename(struct _reent *r, const char *src, const char *dst);
int esp_vfs_utime(const char *path, const struct utimbuf *times);
/* ... */
int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
/* ... */
void esp_vfs_select_triggered(esp_vfs_select_sem_t sem);
/* ... */
void esp_vfs_select_triggered_isr(esp_vfs_select_sem_t sem, BaseType_t *woken);
/* ... */
ssize_t esp_vfs_pread(int fd, void *dst, size_t size, off_t offset);
/* ... */
ssize_t esp_vfs_pwrite(int fd, const void *src, size_t size, off_t offset);
/* ... */
void esp_vfs_dump_fds(FILE *fp);
/* ... */
void esp_vfs_dump_registered_paths(FILE *fp);
#ifdef __cplusplus
}{...}
#endif
/* ... */
#endif