esp_spiffs.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ESP_SPIFFS_H_
  7. #define _ESP_SPIFFS_H_
  8. #include <stdbool.h>
  9. #include "esp_err.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief Configuration structure for esp_vfs_spiffs_register
  15. */
  16. typedef struct {
  17. const char* base_path; /*!< File path prefix associated with the filesystem. */
  18. const char* partition_label; /*!< Optional, label of SPIFFS partition to use. If set to NULL, first partition with subtype=spiffs will be used. */
  19. size_t max_files; /*!< Maximum files that could be open at the same time. */
  20. bool format_if_mount_failed; /*!< If true, it will format the file system if it fails to mount. */
  21. } esp_vfs_spiffs_conf_t;
  22. /**
  23. * Register and mount SPIFFS to VFS with given path prefix.
  24. *
  25. * @param conf Pointer to esp_vfs_spiffs_conf_t configuration structure
  26. *
  27. * @return
  28. * - ESP_OK if success
  29. * - ESP_ERR_NO_MEM if objects could not be allocated
  30. * - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted
  31. * - ESP_ERR_NOT_FOUND if partition for SPIFFS was not found
  32. * - ESP_FAIL if mount or format fails
  33. */
  34. esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf);
  35. /**
  36. * Unregister and unmount SPIFFS from VFS
  37. *
  38. * @param partition_label Same label as passed to esp_vfs_spiffs_register.
  39. *
  40. * @return
  41. * - ESP_OK if successful
  42. * - ESP_ERR_INVALID_STATE already unregistered
  43. */
  44. esp_err_t esp_vfs_spiffs_unregister(const char* partition_label);
  45. /**
  46. * Check if SPIFFS is mounted
  47. *
  48. * @param partition_label Optional, label of the partition to check.
  49. * If not specified, first partition with subtype=spiffs is used.
  50. *
  51. * @return
  52. * - true if mounted
  53. * - false if not mounted
  54. */
  55. bool esp_spiffs_mounted(const char* partition_label);
  56. /**
  57. * Format the SPIFFS partition
  58. *
  59. * @param partition_label Same label as passed to esp_vfs_spiffs_register.
  60. * @return
  61. * - ESP_OK if successful
  62. * - ESP_FAIL on error
  63. */
  64. esp_err_t esp_spiffs_format(const char* partition_label);
  65. /**
  66. * Get information for SPIFFS
  67. *
  68. * @param partition_label Same label as passed to esp_vfs_spiffs_register
  69. * @param[out] total_bytes Size of the file system
  70. * @param[out] used_bytes Current used bytes in the file system
  71. *
  72. * @return
  73. * - ESP_OK if success
  74. * - ESP_ERR_INVALID_STATE if not mounted
  75. */
  76. esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* _ESP_SPIFFS_H_ */