diff --git a/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c b/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c index 63477d6ce5..81b7ebf44e 100644 --- a/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c +++ b/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c @@ -1252,19 +1252,15 @@ static void btc_l2cap_vfs_register(void) break; } - esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT, + static const esp_vfs_fs_ops_t vfs = { .write = l2cap_vfs_write, - .open = NULL, - .fstat = NULL, .close = l2cap_vfs_close, .read = l2cap_vfs_read, - .fcntl = NULL }; // No FD range is registered here: l2cap_vfs_id is used to register/unregister // file descriptors - if (esp_vfs_register_with_id(&vfs, NULL, &l2cap_local_param.l2cap_vfs_id) != ESP_OK) { + if (esp_vfs_register_fs_with_id(&vfs, ESP_VFS_FLAG_STATIC, NULL, &l2cap_local_param.l2cap_vfs_id) != ESP_OK) { ret = ESP_BT_L2CAP_FAILURE; break; } diff --git a/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c b/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c index 8607e42191..33e5a59070 100644 --- a/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c +++ b/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c @@ -1659,19 +1659,15 @@ static void btc_spp_vfs_register(void) break; } - esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT, + static const esp_vfs_fs_ops_t vfs = { .write = spp_vfs_write, - .open = NULL, - .fstat = NULL, .close = spp_vfs_close, .read = spp_vfs_read, - .fcntl = NULL }; // No FD range is registered here: spp_vfs_id is used to register/unregister // file descriptors - if (esp_vfs_register_with_id(&vfs, NULL, &spp_local_param.spp_vfs_id) != ESP_OK) { + if (esp_vfs_register_fs_with_id(&vfs, ESP_VFS_FLAG_STATIC, NULL, &spp_local_param.spp_vfs_id) != ESP_OK) { ret = ESP_SPP_FAILURE; break; } diff --git a/components/esp_driver_uart/include/driver/esp_private/uart_vfs.h b/components/esp_driver_uart/include/driver/esp_private/uart_vfs.h index b74996ae6f..ced7196835 100644 --- a/components/esp_driver_uart/include/driver/esp_private/uart_vfs.h +++ b/components/esp_driver_uart/include/driver/esp_private/uart_vfs.h @@ -18,7 +18,7 @@ extern "C" { * This function is called in vfs_console in order to get the vfs implementation * of uart. * - * @return pointer to structure esp_vfs_t + * @return pointer to structure esp_vfs_fs_ops_t */ const esp_vfs_fs_ops_t *esp_vfs_uart_get_vfs(void); diff --git a/components/esp_driver_usb_serial_jtag/include/driver/esp_private/usb_serial_jtag_vfs.h b/components/esp_driver_usb_serial_jtag/include/driver/esp_private/usb_serial_jtag_vfs.h index 4415447613..3c4c0f9ecd 100644 --- a/components/esp_driver_usb_serial_jtag/include/driver/esp_private/usb_serial_jtag_vfs.h +++ b/components/esp_driver_usb_serial_jtag/include/driver/esp_private/usb_serial_jtag_vfs.h @@ -18,7 +18,7 @@ extern "C" { * This function is called in vfs_console in order to get the vfs implementation * of usb_serial_jtag. * - * @return pointer to structure esp_vfs_t + * @return pointer to structure esp_vfs_fs_ops_t */ const esp_vfs_fs_ops_t *esp_vfs_usb_serial_jtag_get_vfs(void); diff --git a/components/esp_libc/test_apps/newlib/main/test_file.c b/components/esp_libc/test_apps/newlib/main/test_file.c index a7f5cab625..7d2530564c 100644 --- a/components/esp_libc/test_apps/newlib/main/test_file.c +++ b/components/esp_libc/test_apps/newlib/main/test_file.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -47,14 +47,12 @@ TEST_CASE("file - blksize", "[newlib_file]") FILE* f; blksize_test_ctx_t ctx = {}; const char c = 42; - const esp_vfs_t desc = { - .flags = ESP_VFS_FLAG_CONTEXT_PTR, + static const esp_vfs_fs_ops_t desc = { .open_p = blksize_test_open, .fstat_p = blksize_test_fstat, .write_p = blksize_test_write, }; - - TEST_ESP_OK(esp_vfs_register("/test", &desc, &ctx)); + TEST_ESP_OK(esp_vfs_register_fs("/test", &desc, ESP_VFS_FLAG_CONTEXT_PTR | ESP_VFS_FLAG_STATIC, &ctx)); /* test with zero st_blksize (=not set) */ ctx.blksize = 0; diff --git a/components/esp_libc/test_apps/newlib/main/test_misc.c b/components/esp_libc/test_apps/newlib/main/test_misc.c index bc4e6656c8..dd825c775d 100644 --- a/components/esp_libc/test_apps/newlib/main/test_misc.c +++ b/components/esp_libc/test_apps/newlib/main/test_misc.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -153,14 +153,17 @@ TEST_CASE("file - scandir", "[newlib_misc]") scandir_test_dir_context_t scandir_test_dir_ctx = { .filenames = test_filenames, .num_files = num_test_files }; - const esp_vfs_t scandir_test_vfs = { - .flags = ESP_VFS_FLAG_CONTEXT_PTR, + static const esp_vfs_dir_ops_t dir_ops = { .opendir_p = scandir_test_opendir, .readdir_p = scandir_test_readdir, .closedir_p = scandir_test_closedir }; - TEST_ESP_OK(esp_vfs_register("/data", &scandir_test_vfs, &scandir_test_dir_ctx)); + static const esp_vfs_fs_ops_t fs_ops = { + .dir = &dir_ops, + }; + + TEST_ESP_OK(esp_vfs_register_fs("/data", &fs_ops, ESP_VFS_FLAG_CONTEXT_PTR | ESP_VFS_FLAG_STATIC, &scandir_test_dir_ctx)); struct dirent **namelist; s_select_calls = 0; diff --git a/components/esp_usb_cdc_rom_console/include/esp_private/esp_vfs_cdcacm.h b/components/esp_usb_cdc_rom_console/include/esp_private/esp_vfs_cdcacm.h index d03b06b3fc..8c1f911a50 100644 --- a/components/esp_usb_cdc_rom_console/include/esp_private/esp_vfs_cdcacm.h +++ b/components/esp_usb_cdc_rom_console/include/esp_private/esp_vfs_cdcacm.h @@ -18,7 +18,7 @@ extern "C" { * This function is called in vfs_console in order to get the vfs implementation * of cdcacm. * - * @return pointer to structure esp_vfs_t + * @return pointer to structure esp_vfs_fs_ops_t */ const esp_vfs_fs_ops_t *esp_vfs_cdcacm_get_vfs(void); diff --git a/components/fatfs/vfs/vfs_fat_spiflash.c b/components/fatfs/vfs/vfs_fat_spiflash.c index 0ee00e25d7..a5f88a2519 100644 --- a/components/fatfs/vfs/vfs_fat_spiflash.c +++ b/components/fatfs/vfs/vfs_fat_spiflash.c @@ -23,7 +23,7 @@ static const char* TAG = "vfs_fat_spiflash"; static vfs_fat_spiflash_ctx_t *s_ctx[FF_VOLUMES] = {}; -extern esp_err_t esp_vfs_set_readonly_flag(const char* base_path); // from vfs/vfs.c to set readonly flag in esp_vfs_t struct externally +extern esp_err_t esp_vfs_set_readonly_flag(const char* base_path); // from vfs/vfs.c to set readonly flag externally static bool s_get_context_id_by_label(const char *label, uint32_t *out_id) { diff --git a/components/lwip/port/esp32xx/vfs_lwip.c b/components/lwip/port/esp32xx/vfs_lwip.c index 8c42cddc52..d59922d594 100644 --- a/components/lwip/port/esp32xx/vfs_lwip.c +++ b/components/lwip/port/esp32xx/vfs_lwip.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -88,26 +88,39 @@ static int lwip_fstat(int fd, struct stat * st) void esp_vfs_lwip_sockets_register(void) { - esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT, - .write = &lwip_write, - .open = NULL, - .fstat = &lwip_fstat, - .close = &lwip_close, - .read = &lwip_read, - .fcntl = &lwip_fcntl_r_wrapper, - .ioctl = &lwip_ioctl_r_wrapper, + #ifdef CONFIG_VFS_SUPPORT_SELECT + + static const esp_vfs_select_ops_t s_lwip_select_ops = { .socket_select = &lwip_select, - .get_socket_select_semaphore = &lwip_get_socket_select_semaphore, .stop_socket_select = &lwip_stop_socket_select, .stop_socket_select_isr = &lwip_stop_socket_select_isr, -#endif // CONFIG_VFS_SUPPORT_SELECT + .get_socket_select_semaphore = &lwip_get_socket_select_semaphore, }; - /* Non-LWIP file descriptors are from 0 to (LWIP_SOCKET_OFFSET-1). LWIP - * file descriptors are registered from LWIP_SOCKET_OFFSET to - * MAX_FDS-1. - */ - ESP_ERROR_CHECK(esp_vfs_register_fd_range(&vfs, NULL, LWIP_SOCKET_OFFSET, MAX_FDS)); +#endif + + static const esp_vfs_fs_ops_t s_lwip_vfs = { + .write = &lwip_write, + .read = &lwip_read, + .close = &lwip_close, + .fstat = &lwip_fstat, + .fcntl = &lwip_fcntl_r_wrapper, + .ioctl = &lwip_ioctl_r_wrapper, +#ifdef CONFIG_VFS_SUPPORT_SELECT + .select = &s_lwip_select_ops, +#endif + }; + + /* Non-LWIP file descriptors are from 0 to (LWIP_SOCKET_OFFSET-1). + * LWIP file descriptors are registered from LWIP_SOCKET_OFFSET to MAX_FDS-1. + * + * Use ESP_VFS_FLAG_STATIC since s_lwip_vfs and subcomponents are static. + * No context pointer needed -> flags have no ESP_VFS_FLAG_CONTEXT_PTR. + */ + ESP_ERROR_CHECK(esp_vfs_register_fd_range(&s_lwip_vfs, + ESP_VFS_FLAG_STATIC, + NULL /* ctx */, + LWIP_SOCKET_OFFSET, + MAX_FDS)); } diff --git a/components/vfs/include/esp_vfs.h b/components/vfs/include/esp_vfs.h index 4f515eb488..c8f6d9ccdb 100644 --- a/components/vfs/include/esp_vfs.h +++ b/components/vfs/include/esp_vfs.h @@ -292,7 +292,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct * registered, ESP_ERR_INVALID_ARG if the file descriptor boundaries * are incorrect. */ -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_fd_range(const esp_vfs_fs_ops_t *vfs, int flags, void *ctx, int min_fd, int max_fd); /** * Special case function for registering a VFS that uses a method other than diff --git a/components/vfs/test_apps/main/test_vfs_fd.c b/components/vfs/test_apps/main/test_vfs_fd.c index 353701cdca..904e864032 100644 --- a/components/vfs/test_apps/main/test_vfs_fd.c +++ b/components/vfs/test_apps/main/test_vfs_fd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -60,13 +60,12 @@ TEST_CASE("FDs from different VFSs don't collide", "[vfs]") .fd = 1, }; - esp_vfs_t desc = { - .flags = ESP_VFS_FLAG_CONTEXT_PTR, + esp_vfs_fs_ops_t desc = { .open_p = collision_test_vfs_open, .close_p = collision_test_vfs_close, }; - TEST_ESP_OK( esp_vfs_register(VFS_PREF1, &desc, ¶m) ); - TEST_ESP_OK( esp_vfs_register(VFS_PREF2, &desc, ¶m) ); + TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF1, &desc, ESP_VFS_FLAG_CONTEXT_PTR, ¶m) ); + TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF2, &desc, ESP_VFS_FLAG_CONTEXT_PTR, ¶m) ); const int fd1 = open(VFS_PREF1 FILE1, 0, 0); const int fd2 = open(VFS_PREF2 FILE1, 0, 0); @@ -155,13 +154,12 @@ static void concurrent_task(void *param) TEST_CASE("VFS can handle concurrent open/close requests", "[vfs]") { - esp_vfs_t desc = { - .flags = ESP_VFS_FLAG_DEFAULT, + esp_vfs_fs_ops_t desc = { .open = concurrent_test_vfs_open, .close = concurrent_test_vfs_close, }; - TEST_ESP_OK( esp_vfs_register(VFS_PREF1, &desc, NULL) ); + TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF1, &desc, ESP_VFS_FLAG_DEFAULT, NULL) ); concurrent_test_task_param_t param1 = { .path = VFS_PREF1 FILE1, .done = xSemaphoreCreateBinary() }; concurrent_test_task_param_t param2 = { .path = VFS_PREF1 FILE1, .done = xSemaphoreCreateBinary() }; @@ -233,14 +231,13 @@ static int time_test_vfs_write(int fd, const void *data, size_t size) TEST_CASE("Open & write & close through VFS passes performance test", "[vfs]") { - esp_vfs_t desc = { - .flags = ESP_VFS_FLAG_DEFAULT, + esp_vfs_fs_ops_t desc = { .open = time_test_vfs_open, .close = time_test_vfs_close, .write = time_test_vfs_write, }; - TEST_ESP_OK( esp_vfs_register(VFS_PREF1, &desc, NULL) ); + TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF1, &desc, ESP_VFS_FLAG_DEFAULT, NULL) ); ccomp_timer_start(); const int iter_count = 5000; @@ -278,17 +275,16 @@ static int vfs_overlap_test_close(int fd) TEST_CASE("esp_vfs_register_fd_range checks for overlap", "[vfs]") { - esp_vfs_t vfs1 = { + esp_vfs_fs_ops_t vfs1 = { .open = vfs_overlap_test_open, .close = vfs_overlap_test_close }; - - TEST_ESP_OK(esp_vfs_register("/test", &vfs1, NULL)); + TEST_ESP_OK(esp_vfs_register_fs("/test", &vfs1, ESP_VFS_FLAG_DEFAULT, NULL)); int fd = open("/test/1", 0, 0); TEST_ASSERT_NOT_EQUAL(-1, fd); - esp_vfs_t vfs2 = { }; - esp_err_t err = esp_vfs_register_fd_range(&vfs2, NULL, fd, fd + 1); + esp_vfs_fs_ops_t vfs2 = { }; + esp_err_t err = esp_vfs_register_fd_range(&vfs2, ESP_VFS_FLAG_DEFAULT, NULL, fd, fd + 1); close(fd); TEST_ESP_OK(esp_vfs_unregister("/test")); diff --git a/components/vfs/test_apps/main/test_vfs_open.c b/components/vfs/test_apps/main/test_vfs_open.c index 7b888d83b4..fc9815fe96 100644 --- a/components/vfs/test_apps/main/test_vfs_open.c +++ b/components/vfs/test_apps/main/test_vfs_open.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,7 @@ #include #include #include "esp_vfs.h" +#include "esp_vfs_ops.h" #include "unity.h" static int open_errno_test_open(const char * path, int flags, int mode) @@ -19,10 +20,10 @@ static int open_errno_test_open(const char * path, int flags, int mode) TEST_CASE("esp_vfs_open sets correct errno", "[vfs]") { - esp_vfs_t desc = { + const esp_vfs_fs_ops_t desc = { .open = open_errno_test_open }; - TEST_ESP_OK(esp_vfs_register("/test", &desc, NULL)); + TEST_ESP_OK(esp_vfs_register_fs("/test", &desc, ESP_VFS_FLAG_DEFAULT, NULL)); int fd = open("/test/path", 0, 0); int e = errno; diff --git a/components/vfs/test_apps/main/test_vfs_paths.c b/components/vfs/test_apps/main/test_vfs_paths.c index f7b9234bd8..65fc624fcd 100644 --- a/components/vfs/test_apps/main/test_vfs_paths.c +++ b/components/vfs/test_apps/main/test_vfs_paths.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +12,7 @@ #include #include #include "esp_vfs.h" +#include "esp_vfs_ops.h" #include "unity.h" #include "esp_log.h" @@ -68,13 +69,16 @@ static int dummy_closedir(void* ctx, DIR* pdir) /* Initializer for this dummy VFS implementation */ -#define DUMMY_VFS() { \ - .flags = ESP_VFS_FLAG_CONTEXT_PTR, \ - .open_p = dummy_open, \ - .close_p = dummy_close, \ - .opendir_p = dummy_opendir, \ - .closedir_p = dummy_closedir \ - } +static const esp_vfs_dir_ops_t s_dummy_vfs_dir = { + .opendir_p = dummy_opendir, + .closedir_p = dummy_closedir, +}; + +static const esp_vfs_fs_ops_t s_dummy_vfs = { + .open_p = dummy_open, + .close_p = dummy_close, + .dir = &s_dummy_vfs_dir, +}; /* Helper functions to test VFS behavior */ @@ -136,15 +140,13 @@ TEST_CASE("vfs parses paths correctly", "[vfs]") .match_path = "", .called = false }; - esp_vfs_t desc_foo = DUMMY_VFS(); - TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo) ); dummy_vfs_t inst_foo1 = { .match_path = "", .called = false }; - esp_vfs_t desc_foo1 = DUMMY_VFS(); - TEST_ESP_OK( esp_vfs_register("/foo1", &desc_foo1, &inst_foo1) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo1", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo1) ); inst_foo.match_path = "/file"; test_opened(&inst_foo, "/foo/file"); @@ -171,15 +173,13 @@ TEST_CASE("vfs parses paths correctly", "[vfs]") .match_path = "", .called = false }; - esp_vfs_t desc_foobar = DUMMY_VFS(); - TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo/bar", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foobar) ); dummy_vfs_t inst_toplevel = { .match_path = "", .called = false }; - esp_vfs_t desc_toplevel = DUMMY_VFS(); - TEST_ESP_OK( esp_vfs_register("", &desc_toplevel, &inst_toplevel) ); + TEST_ESP_OK( esp_vfs_register_fs("", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_toplevel) ); inst_foo.match_path = "/bar/file"; inst_foobar.match_path = "/file"; @@ -204,15 +204,13 @@ TEST_CASE("vfs unregisters correct nested mount point", "[vfs]") .match_path = "/file", .called = false }; - esp_vfs_t desc_foobar = DUMMY_VFS(); - TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo/bar", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foobar) ); dummy_vfs_t inst_foo = { .match_path = "/bar/file", .called = false }; - esp_vfs_t desc_foo = DUMMY_VFS(); - TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo) ); /* basic operation */ test_opened(&inst_foobar, "/foo/bar/file"); @@ -228,8 +226,8 @@ TEST_CASE("vfs unregisters correct nested mount point", "[vfs]") /* repeat the above, with the reverse order of registration */ TEST_ESP_OK( esp_vfs_unregister("/foo/bar") ); - TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) ); - TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo) ); + TEST_ESP_OK( esp_vfs_register_fs("/foo/bar", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foobar) ); test_opened(&inst_foobar, "/foo/bar/file"); test_not_called(&inst_foo, "/foo/bar/file"); TEST_ESP_OK( esp_vfs_unregister("/foo") ); @@ -242,13 +240,12 @@ TEST_CASE("vfs unregisters correct nested mount point", "[vfs]") void test_vfs_register(const char* prefix, bool expect_success, int line) { dummy_vfs_t inst; - esp_vfs_t desc = DUMMY_VFS(); - esp_err_t err = esp_vfs_register(prefix, &desc, &inst); + esp_err_t err = esp_vfs_register_fs(prefix, &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst); if (expect_success) { - UNITY_TEST_ASSERT_EQUAL_INT(ESP_OK, err, line, "esp_vfs_register should succeed"); + UNITY_TEST_ASSERT_EQUAL_INT(ESP_OK, err, line, "esp_vfs_register_fs should succeed"); } else { UNITY_TEST_ASSERT_EQUAL_INT(ESP_ERR_INVALID_ARG, - err, line, "esp_vfs_register should fail"); + err, line, "esp_vfs_register_fs should fail"); } if (err == ESP_OK) { TEST_ESP_OK( esp_vfs_unregister(prefix) ); diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index 71b2ef4bf2..ebf41b80a9 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -520,7 +520,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct return esp_vfs_register_common(base_path, strlen(base_path), vfs, ctx, NULL); } -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_fd_range(const esp_vfs_fs_ops_t *vfs, int flags, void *ctx, int min_fd, int max_fd) { if (min_fd < 0 || max_fd < 0 || min_fd > MAX_FDS || max_fd > MAX_FDS || min_fd > max_fd) { ESP_LOGD(TAG, "Invalid arguments: esp_vfs_register_fd_range(0x%p, 0x%p, %d, %d)", vfs, ctx, min_fd, max_fd); diff --git a/components/vfs/vfs_eventfd.c b/components/vfs/vfs_eventfd.c index a8ae79d1b9..bae6ecff9e 100644 --- a/components/vfs/vfs_eventfd.c +++ b/components/vfs/vfs_eventfd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -351,6 +351,22 @@ static int event_close(int fd) return ret; } +#ifdef CONFIG_VFS_SUPPORT_SELECT +static const esp_vfs_select_ops_t s_vfs_eventfd_select = { + .start_select = &event_start_select, + .end_select = &event_end_select, +}; +#endif + +static const esp_vfs_fs_ops_t s_vfs_eventfd = { + .write = &event_write, + .read = &event_read, + .close = &event_close, +#ifdef CONFIG_VFS_SUPPORT_SELECT + .select = &s_vfs_eventfd_select, +#endif +}; + esp_err_t esp_vfs_eventfd_register(const esp_vfs_eventfd_config_t *config) { if (config == NULL || config->max_fds >= MAX_FDS) { @@ -367,17 +383,7 @@ esp_err_t esp_vfs_eventfd_register(const esp_vfs_eventfd_config_t *config) s_events[i].fd = FD_INVALID; } - esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT, - .write = &event_write, - .close = &event_close, - .read = &event_read, -#ifdef CONFIG_VFS_SUPPORT_SELECT - .start_select = &event_start_select, - .end_select = &event_end_select, -#endif - }; - return esp_vfs_register_with_id(&vfs, NULL, &s_eventfd_vfs_id); + return esp_vfs_register_fs_with_id(&s_vfs_eventfd, ESP_VFS_FLAG_STATIC | ESP_VFS_FLAG_STATIC, NULL, &s_eventfd_vfs_id); } esp_err_t esp_vfs_eventfd_unregister(void) diff --git a/docs/en/api-reference/storage/vfs.rst b/docs/en/api-reference/storage/vfs.rst index f9e0d87ddc..98cd97fd7c 100644 --- a/docs/en/api-reference/storage/vfs.rst +++ b/docs/en/api-reference/storage/vfs.rst @@ -17,10 +17,6 @@ For example, one can mount a FAT filesystem driver at the ``/fat`` prefix and ca FS Registration --------------- -.. note:: - - For previous version of the API (using :cpp:type:`esp_vfs_t`), see documentation for previous release. - To register an FS driver, an application needs to define an instance of the :cpp:type:`esp_vfs_fs_ops_t` structure and populate it with function pointers to FS APIs: .. highlight:: c @@ -79,7 +75,7 @@ In some cases, it might be beneficial or even necessary to pass some context to ssize_t myfs_write(myfs_t* fs, int fd, const void * data, size_t size); - // In definition of esp_vfs_t: + // In definition of esp_vfs_fs_ops_t: .write_p = &myfs_write, // ... other members initialized diff --git a/docs/zh_CN/api-reference/storage/vfs.rst b/docs/zh_CN/api-reference/storage/vfs.rst index 74e19ba49d..523ab264f2 100644 --- a/docs/zh_CN/api-reference/storage/vfs.rst +++ b/docs/zh_CN/api-reference/storage/vfs.rst @@ -17,10 +17,6 @@ VFS 组件支持 C 库函数(如 fopen 和 fprintf 等)与文件系统 (FS) 注册 FS 驱动程序 --------------------- -.. note:: - - 有关先前版本 API(使用 :cpp:type:`esp_vfs_t`)的内容,可以查阅之前发布的文档。 - 如需注册 FS 驱动程序,应用程序首先要定义一个 :cpp:type:`esp_vfs_fs_ops_t` 结构体实例,并用指向 FS API 的函数指针填充它。 .. highlight:: c @@ -79,7 +75,7 @@ VFS 组件支持 C 库函数(如 fopen 和 fprintf 等)与文件系统 (FS) ssize_t myfs_write(myfs_t* fs, int fd, const void * data, size_t size); - // 在 esp_vfs_t 的定义中: + // 在 esp_vfs_fs_ops_t 的定义中: .write_p = &myfs_write, // ... 初始化其他成员 diff --git a/examples/peripherals/usb/device/tusb_composite_msc_serialdevice/main/idf_component.yml b/examples/peripherals/usb/device/tusb_composite_msc_serialdevice/main/idf_component.yml index 03340b8fe0..e1a93a262e 100644 --- a/examples/peripherals/usb/device/tusb_composite_msc_serialdevice/main/idf_component.yml +++ b/examples/peripherals/usb/device/tusb_composite_msc_serialdevice/main/idf_component.yml @@ -1,4 +1,4 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_tinyusb: - version: "^2.0.0" + version: "^2.0.1~1" diff --git a/examples/peripherals/usb/device/tusb_console/main/idf_component.yml b/examples/peripherals/usb/device/tusb_console/main/idf_component.yml index 03340b8fe0..e1a93a262e 100644 --- a/examples/peripherals/usb/device/tusb_console/main/idf_component.yml +++ b/examples/peripherals/usb/device/tusb_console/main/idf_component.yml @@ -1,4 +1,4 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_tinyusb: - version: "^2.0.0" + version: "^2.0.1~1" diff --git a/examples/peripherals/usb/device/tusb_serial_device/main/idf_component.yml b/examples/peripherals/usb/device/tusb_serial_device/main/idf_component.yml index 03340b8fe0..e1a93a262e 100644 --- a/examples/peripherals/usb/device/tusb_serial_device/main/idf_component.yml +++ b/examples/peripherals/usb/device/tusb_serial_device/main/idf_component.yml @@ -1,4 +1,4 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_tinyusb: - version: "^2.0.0" + version: "^2.0.1~1" diff --git a/tools/test_apps/storage/std_filesystem/main/test_status.cpp b/tools/test_apps/storage/std_filesystem/main/test_status.cpp index 7eeb0ce8f7..74d3c45e73 100644 --- a/tools/test_apps/storage/std_filesystem/main/test_status.cpp +++ b/tools/test_apps/storage/std_filesystem/main/test_status.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -81,15 +81,48 @@ static int test_vfs_closedir(void* ctx, DIR* pdir) TEST_CASE("std::filesystem status functions") { test_vfs_ctx_t test_ctx = {}; - esp_vfs_t desc = {}; - desc.flags = ESP_VFS_FLAG_CONTEXT_PTR; - desc.open_p = test_vfs_open; - desc.stat_p = test_vfs_stat; - desc.opendir_p = test_vfs_opendir; - desc.readdir_p = test_vfs_readdir; - desc.closedir_p = test_vfs_closedir; + esp_vfs_dir_ops_t dir_desc = { + .stat_p = test_vfs_stat, + .link_p = nullptr, + .unlink_p = nullptr, + .rename_p = nullptr, + .opendir_p = test_vfs_opendir, + .readdir_p = test_vfs_readdir, + .readdir_r_p = nullptr, + .telldir_p = nullptr, + .seekdir_p = nullptr, + .closedir_p = test_vfs_closedir, + .mkdir_p = nullptr, + .rmdir_p = nullptr, + .access_p = nullptr, + .truncate_p = nullptr, + .ftruncate_p = nullptr, + .utime_p = nullptr, + }; - REQUIRE(esp_vfs_register("/test", &desc, &test_ctx) == ESP_OK); + esp_vfs_fs_ops_t desc = { + .write_p = nullptr, + .lseek_p = nullptr, + .read_p = nullptr, + .pread_p = nullptr, + .pwrite_p = nullptr, + .open_p = test_vfs_open, + .close_p = nullptr, + .fstat_p = nullptr, + .fcntl_p = nullptr, + .ioctl_p = nullptr, + .fsync_p = nullptr, + .dir = &dir_desc, +#ifdef CONFIG_VFS_SUPPORT_TERMIOS + .termios = nullptr, +#endif + +#if CONFIG_VFS_SUPPORT_SELECT || defined __DOXYGEN__ + .select = nullptr, +#endif + }; + + REQUIRE(esp_vfs_register_fs("/test", &desc, ESP_VFS_FLAG_CONTEXT_PTR, &test_ctx) == ESP_OK); SECTION("Test file exists") { test_ctx.cmp_path = "/file.txt";