1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "esp_vfs.h" 8 #include "esp_vfs_common.h" 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 typedef struct vfs_entry_ { 15 esp_vfs_t vfs; // contains pointers to VFS functions 16 char path_prefix[ESP_VFS_PATH_MAX]; // path prefix mapped to this VFS 17 size_t path_prefix_len; // micro-optimization to avoid doing extra strlen 18 void* ctx; // optional pointer which can be passed to VFS 19 int offset; // index of this structure in s_vfs array 20 } vfs_entry_t; 21 22 23 /** 24 * @brief get pointer of uart vfs. 25 * 26 * This function is called in vfs_console in order to get the vfs implementation 27 * of uart. 28 * 29 * @return pointer to structure esp_vfs_t 30 */ 31 const esp_vfs_t *esp_vfs_uart_get_vfs(void); 32 33 /** 34 * @brief get pointer of cdcacm vfs. 35 * 36 * This function is called in vfs_console in order to get the vfs implementation 37 * of cdcacm. 38 * 39 * @return pointer to structure esp_vfs_t 40 */ 41 const esp_vfs_t *esp_vfs_cdcacm_get_vfs(void); 42 43 /** 44 * @brief get pointer of usb_serial_jtag vfs. 45 * 46 * This function is called in vfs_console in order to get the vfs implementation 47 * of usb_serial_jtag. 48 * 49 * @return pointer to structure esp_vfs_nonblocking_console_t 50 */ 51 const esp_vfs_t *esp_vfs_usb_serial_jtag_get_vfs(void); 52 53 /** 54 * Register a virtual filesystem. 55 * 56 * @param base_path file path prefix associated with the filesystem. 57 * Must be a zero-terminated C string, may be empty. 58 * If not empty, must be up to ESP_VFS_PATH_MAX 59 * characters long, and at least 2 characters long. 60 * Name must start with a "/" and must not end with "/". 61 * For example, "/data" or "/dev/spi" are valid. 62 * These VFSes would then be called to handle file paths such as 63 * "/data/myfile.txt" or "/dev/spi/0". 64 * In the special case of an empty base_path, a "fallback" 65 * VFS is registered. Such VFS will handle paths which are not 66 * matched by any other registered VFS. 67 * @param len Length of the base_path. 68 * @param vfs Pointer to esp_vfs_t, a structure which maps syscalls to 69 * the filesystem driver functions. VFS component doesn't 70 * assume ownership of this pointer. 71 * @param ctx If vfs->flags has ESP_VFS_FLAG_CONTEXT_PTR set, a pointer 72 * which should be passed to VFS functions. Otherwise, NULL. 73 * @param vfs_index Index for getting the vfs content. 74 * 75 * @return ESP_OK if successful. 76 * ESP_ERR_NO_MEM if too many VFSes are registered. 77 * ESP_ERR_INVALID_ARG if given an invalid parameter. 78 */ 79 esp_err_t esp_vfs_register_common(const char *base_path, size_t len, const esp_vfs_t* vfs, void* ctx, int *vfs_index); 80 81 /** 82 * Get vfs fd with given path. 83 * 84 * @param path file path prefix associated with the filesystem. 85 * 86 * @return Pointer to the `vfs_entry_t` corresponding to the given path, which cannot be NULL. 87 */ 88 const vfs_entry_t *get_vfs_for_path(const char *path); 89 90 /** 91 * Get vfs fd with given vfs index. 92 * 93 * @param index VFS index. 94 * 95 * @return Pointer to the `vfs_entry_t` corresponding to the given path, which cannot be NULL. 96 */ 97 const vfs_entry_t *get_vfs_for_index(int index); 98 99 #ifdef __cplusplus 100 } 101 #endif 102