/** * Register the VFS at the specified mount point. * The callback functions are registered to handle the * different functions that may be requested against the * VFS. */ void registerTestVFS(char *mountPoint) { esp_vfs_t vfs; esp_err_t err; vfs.fd_offset = 0; vfs.flags = ESP_VFS_FLAG_DEFAULT; vfs.close = vfs_close; vfs.closedir = vfs_closedir; vfs.fstat = vfs_fstat; vfs.link = vfs_link; vfs.lseek = vfs_lseek; vfs.mkdir = vfs_mkdir; vfs.open = vfs_open; vfs.opendir = vfs_opendir; vfs.read = vfs_read; vfs.readdir = vfs_readdir; vfs.rename = vfs_rename; vfs.rmdir = vfs_rmdir; vfs.seekdir = vfs_seekdir; vfs.stat = vfs_stat; vfs.telldir = vfs_telldir; vfs.unlink = vfs_unlink; vfs.write = vfs_write; err = esp_vfs_register(mountPoint, &vfs, NULL); if (err != ESP_OK) { ESP_LOGE(tag, "esp_vfs_register: err=%d", err); } } // End of registerTestVFS
esp_err_t esp_vfs_semihost_register(const char* base_path, const char* host_path) { const esp_vfs_t vfs = { .flags = ESP_VFS_FLAG_CONTEXT_PTR, .write_p = &vfs_semihost_write, .open_p = &vfs_semihost_open, .close_p = &vfs_semihost_close, .read_p = &vfs_semihost_read, .lseek_p = &vfs_semihost_lseek, }; ESP_LOGD(TAG, "Register semihosting driver '%s' -> '%s'", base_path, host_path ? host_path : "null"); if (!esp_cpu_in_ocd_debug_mode()) { ESP_LOGE(TAG, "OpenOCD is not connected!"); return ESP_ERR_NOT_SUPPORTED; } int i = 0; for (i = 0; i < CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS; i++) { if (ctx_is_unused(&s_semhost_ctx[i])) { break; } if (strcmp(base_path, s_semhost_ctx[i].base_path) == 0) { return ESP_ERR_INVALID_STATE; } } if (i == CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS) { return ESP_ERR_NO_MEM; } strlcpy(s_semhost_ctx[i].base_path, base_path, sizeof(s_semhost_ctx[i].base_path) - 1); if (host_path) { strlcpy(s_semhost_ctx[i].host_path, host_path, sizeof(s_semhost_ctx[i].host_path) - 1); } ESP_LOGD(TAG, "Register semihosting driver %d %p", i, &s_semhost_ctx[i]); return esp_vfs_register(base_path, &vfs, &s_semhost_ctx[i]); }
#define test_not_called(instance, path) test_open(instance, path, false, false, __LINE__) #define test_dir_opened(instance, path) test_opendir(instance, path, true, true, __LINE__) #define test_dir_not_opened(instance, path) test_opendir(instance, path, true, false, __LINE__) #define test_dir_not_called(instance, path) test_opendir(instance, path, false, false, __LINE__) TEST_CASE("vfs parses paths correctly", "[vfs]") { dummy_vfs_t inst_foo = { .match_path = "", .called = false }; esp_vfs_t desc_foo = DUMMY_VFS(); TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &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) ); inst_foo.match_path = "/file"; test_opened(&inst_foo, "/foo/file"); test_not_opened(&inst_foo, "/foo/file1"); test_not_called(&inst_foo, "/foo1/file"); test_not_called(&inst_foo, "/foo1"); test_not_opened(&inst_foo, "/foo"); inst_foo.match_path = "/junk";
{ assert(fd >=0 && fd < 3); st->st_mode = S_IFCHR; return 0; } static int IRAM_ATTR uart_close(int fd) { assert(fd >=0 && fd < 3); return 0; } void esp_vfs_dev_uart_register() { esp_vfs_t vfs = { .fd_offset = 0, .flags = ESP_VFS_FLAG_DEFAULT, .write = &uart_write, .open = &uart_open, .fstat = &uart_fstat, .close = &uart_close, .read = &uart_read, .lseek = NULL, .stat = NULL, .link = NULL, .unlink = NULL, .rename = NULL }; ESP_ERROR_CHECK(esp_vfs_register("/dev/uart", &vfs, NULL)); }