esp_vfs_private.h 3.3 KB

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