esp_littlefs.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef ESP_LITTLEFS_H__
  2. #define ESP_LITTLEFS_H__
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #include <stdarg.h>
  6. #include <unistd.h>
  7. #include <utime.h>
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/semphr.h"
  10. #include "esp_err.h"
  11. #include <sys/types.h>
  12. #include <sys/reent.h>
  13. #include <sys/stat.h>
  14. #include <sys/time.h>
  15. #include <sys/termios.h>
  16. #include <sys/poll.h>
  17. #include <dirent.h>
  18. #include <string.h>
  19. #include "sdkconfig.h"
  20. #include "lfs.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. enum {
  25. LITTLEFS_ATTR_MTIME, /**< Last Modified - time (seconds) */
  26. LITTLEFS_ATTR_MAX
  27. };
  28. /**
  29. *Configuration structure for esp_vfs_littlefs_register.
  30. */
  31. typedef struct {
  32. const char *base_path; /**< Mounting point. */
  33. const char *partition_label; /**< Label of partition to use. */
  34. uint8_t format_if_mount_failed:1; /**< Format the file system if it fails to mount. */
  35. uint8_t dont_mount:1; /**< Don't attempt to mount or format. Overrides format_if_mount_failed */
  36. } esp_vfs_littlefs_conf_t;
  37. /**
  38. * Register and mount littlefs to VFS with given path prefix.
  39. *
  40. * @param conf Pointer to esp_vfs_littlefs_conf_t configuration structure
  41. *
  42. * @return
  43. * - ESP_OK if success
  44. * - ESP_ERR_NO_MEM if objects could not be allocated
  45. * - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted
  46. * - ESP_ERR_NOT_FOUND if partition for littlefs was not found
  47. * - ESP_FAIL if mount or format fails
  48. */
  49. esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t * conf);
  50. /**
  51. * Unregister and unmount littlefs from VFS
  52. *
  53. * @param partition_label Label of the partition to unregister.
  54. *
  55. * @return
  56. * - ESP_OK if successful
  57. * - ESP_ERR_INVALID_STATE already unregistered
  58. */
  59. esp_err_t esp_vfs_littlefs_unregister(const char* partition_label);
  60. /**
  61. * Check if littlefs is mounted
  62. *
  63. * @param partition_label Label of the partition to check.
  64. *
  65. * @return
  66. * - true if mounted
  67. * - false if not mounted
  68. */
  69. bool esp_littlefs_mounted(const char* partition_label);
  70. /**
  71. * Format the littlefs partition
  72. *
  73. * @param partition_label Label of the partition to format.
  74. * @return
  75. * - ESP_OK if successful
  76. * - ESP_FAIL on error
  77. */
  78. esp_err_t esp_littlefs_format(const char* partition_label);
  79. /**
  80. * Get information for littlefs
  81. *
  82. * @param partition_label Optional, label of the partition to get info for.
  83. * @param[out] total_bytes Size of the file system
  84. * @param[out] used_bytes Current used bytes in the file system
  85. *
  86. * @return
  87. * - ESP_OK if success
  88. * - ESP_ERR_INVALID_STATE if not mounted
  89. */
  90. esp_err_t esp_littlefs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes);
  91. #if CONFIG_LITTLEFS_HUMAN_READABLE
  92. /**
  93. * @brief converts an enumerated lfs error into a string.
  94. * @param lfs_errno The enumerated littlefs error.
  95. */
  96. const char * esp_littlefs_errno(enum lfs_error lfs_errno);
  97. #endif
  98. #ifdef __cplusplus
  99. } // extern "C"
  100. #endif
  101. #endif