VSF Documented
esp_vfs.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 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/*
19 * esp_vfs.h -- ESP-IDF VFS compatibility header (clean-room).
20 *
21 * Scope
22 * -----
23 * The ESP-IDF VFS layer has two faces:
24 *
25 * (1) POSIX filesystem API surface (open/close/read/write/lseek/stat/
26 * opendir/readdir/mkdir/unlink/rename/...). In ESP-IDF these are
27 * implemented inside newlib + esp_vfs_*; in this sub-system they are
28 * provided natively by VSF's linux shell (shell/sys/linux) which
29 * already wraps component/fs (vk_file_* / vk_fs_mount) as synchronous
30 * POSIX calls. Users therefore include the usual <stdio.h> /
31 * <unistd.h> / <fcntl.h> / <sys/stat.h> / <dirent.h> / <sys/mount.h>
32 * headers and get matching behaviour for free. This header forwards
33 * to them so that source files written with #include "esp_vfs.h"
34 * compile unchanged.
35 *
36 * (2) Runtime VFS driver registration (esp_vfs_register /
37 * esp_vfs_register_fd_range). ESP-IDF lets callers splice a custom
38 * driver under a path prefix such as "/dev/foo". VSF's native
39 * equivalents are vk_fs_mount + devfs nodes, whose semantics are
40 * not 1:1 compatible with the esp_vfs_t function-pointer table
41 * (async peda sub-calls vs. bare C callbacks). We deliberately
42 * publish the shape of esp_vfs_t and esp_vfs_register() so that
43 * ESP-IDF code compiles, but the register path returns
44 * ESP_ERR_NOT_SUPPORTED. Concrete filesystems (FAT/LittleFS) bypass
45 * this and mount directly via the matching esp_vfs_fat.h /
46 * esp_littlefs.h entry points, which are fully functional on top
47 * of component/fs.
48 */
49
50#ifndef __VSF_ESPIDF_ESP_VFS_H__
51#define __VSF_ESPIDF_ESP_VFS_H__
52
53/*============================ INCLUDES ======================================*/
54
55#include "esp_err.h"
56
57#include <stdint.h>
58#include <stddef.h>
59#include <stdbool.h>
60
61// POSIX surface (open/read/write/lseek/stat/opendir/readdir/mkdir/unlink
62// /rename/...). VSF linux shell exposes the whole set already.
63#include <sys/types.h>
64#include <sys/stat.h>
65#include <fcntl.h>
66#include <unistd.h>
67#include <dirent.h>
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73/*============================ MACROS ========================================*/
74
75// Matches ESP-IDF's CONFIG_VFS_SUPPORT_IO constants so existing code that
76// checks them compiles. Path length cap is informational: VSF places no
77// hard limit of its own beyond the linux shell FD cap.
78#ifndef ESP_VFS_PATH_MAX
79# define ESP_VFS_PATH_MAX 15
80#endif
81
82#define ESP_VFS_FLAG_DEFAULT 0
83#define ESP_VFS_FLAG_CONTEXT_PTR (1 << 0)
84#define ESP_VFS_FLAG_READONLY_FS (1 << 1)
85
86/*============================ TYPES =========================================*/
87
88// ESP-IDF's esp_vfs_t is a large table of POSIX-shaped function pointers.
89// The fields used by nearly all callers are preserved here so that struct
90// initialisers written against ESP-IDF compile; unused tail fields are
91// deliberately omitted to keep this shim small. Register_* paths do not
92// invoke these function pointers (see file header).
93struct esp_vfs_t {
94 int flags;
95 union {
96 ssize_t (*write) (int fd, const void *data, size_t size);
97 ssize_t (*write_p) (void *ctx, int fd, const void *data, size_t size);
98 };
99 union {
100 off_t (*lseek) (int fd, off_t size, int mode);
101 off_t (*lseek_p) (void *ctx, int fd, off_t size, int mode);
102 };
103 union {
104 ssize_t (*read) (int fd, void *dst, size_t size);
105 ssize_t (*read_p) (void *ctx, int fd, void *dst, size_t size);
106 };
107 union {
108 int (*open) (const char *path, int flags, int mode);
109 int (*open_p) (void *ctx, const char *path, int flags, int mode);
110 };
111 union {
112 int (*close) (int fd);
113 int (*close_p) (void *ctx, int fd);
114 };
115 union {
116 int (*fstat) (int fd, struct stat *st);
117 int (*fstat_p) (void *ctx, int fd, struct stat *st);
118 };
119 union {
120 int (*stat) (const char *path, struct stat *st);
121 int (*stat_p) (void *ctx, const char *path, struct stat *st);
122 };
123 union {
124 int (*unlink) (const char *path);
125 int (*unlink_p)(void *ctx, const char *path);
126 };
127 union {
128 int (*rename) (const char *src, const char *dst);
129 int (*rename_p)(void *ctx, const char *src, const char *dst);
130 };
131};
132
133typedef struct esp_vfs_t esp_vfs_t;
134
135/*============================ PROTOTYPES ====================================*/
136
137// Register / unregister a custom VFS driver under a path prefix.
138//
139// Status in this sub-system: NOT IMPLEMENTED. The VSF native VFS is reached
140// through vk_fs_mount / devfs, not through a function-pointer table.
141// These entry points exist so that code written against ESP-IDF links;
142// callers receive ESP_ERR_NOT_SUPPORTED and are expected to migrate to
143// vk_fs_mount or the higher-level helpers in esp_vfs_fat.h / esp_littlefs.h.
144extern esp_err_t esp_vfs_register(const char *base_path,
145 const esp_vfs_t *vfs,
146 void *ctx);
147extern esp_err_t esp_vfs_unregister(const char *base_path);
148extern esp_err_t esp_vfs_register_fd_range(const esp_vfs_t *vfs, void *ctx,
149 int min_fd, int max_fd);
150
151#ifdef __cplusplus
152}
153#endif
154
155#endif // __VSF_ESPIDF_ESP_VFS_H__
int esp_err_t
Definition esp_err.h:41
esp_err_t esp_vfs_unregister(const char *base_path)
Definition esp_vfs_port.c:47
esp_err_t esp_vfs_register_fd_range(const esp_vfs_t *vfs, void *ctx, int min_fd, int max_fd)
Definition esp_vfs_port.c:53
esp_err_t esp_vfs_register(const char *base_path, const esp_vfs_t *vfs, void *ctx)
Definition esp_vfs_port.c:41
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
int ssize_t
Definition types.h:91
long off_t
Definition types.h:123
Definition esp_vfs.h:93
int(* open_p)(void *ctx, const char *path, int flags, int mode)
Definition esp_vfs.h:109
int flags
Definition esp_vfs.h:94
off_t(* lseek)(int fd, off_t size, int mode)
Definition esp_vfs.h:100
int(* unlink_p)(void *ctx, const char *path)
Definition esp_vfs.h:125
int(* unlink)(const char *path)
Definition esp_vfs.h:124
int(* close)(int fd)
Definition esp_vfs.h:112
int(* fstat_p)(void *ctx, int fd, struct stat *st)
Definition esp_vfs.h:117
ssize_t(* read)(int fd, void *dst, size_t size)
Definition esp_vfs.h:104
int(* rename_p)(void *ctx, const char *src, const char *dst)
Definition esp_vfs.h:129
int(* stat_p)(void *ctx, const char *path, struct stat *st)
Definition esp_vfs.h:121
ssize_t(* read_p)(void *ctx, int fd, void *dst, size_t size)
Definition esp_vfs.h:105
int(* rename)(const char *src, const char *dst)
Definition esp_vfs.h:128
ssize_t(* write_p)(void *ctx, int fd, const void *data, size_t size)
Definition esp_vfs.h:97
int(* fstat)(int fd, struct stat *st)
Definition esp_vfs.h:116
off_t(* lseek_p)(void *ctx, int fd, off_t size, int mode)
Definition esp_vfs.h:101
int(* close_p)(void *ctx, int fd)
Definition esp_vfs.h:113
ssize_t(* write)(int fd, const void *data, size_t size)
Definition esp_vfs.h:96
int(* open)(const char *path, int flags, int mode)
Definition esp_vfs.h:108
Definition stat.h:107
uint32_t size
Definition vsf_memfs.h:50
Generated from commit: vsfteam/vsf@015f4d1