esp_spiffs.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /**
  78. * Check integrity of SPIFFS
  79. *
  80. * @param partition_label Same label as passed to esp_vfs_spiffs_register
  81. * @return
  82. * - ESP_OK if successful
  83. * - ESP_ERR_INVALID_STATE if not mounted
  84. * - ESP_FAIL on error
  85. */
  86. esp_err_t esp_spiffs_check(const char* partition_label);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* _ESP_SPIFFS_H_ */