esp_spiffs.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _ESP_SPIFFS_H_
  15. #define _ESP_SPIFFS_H_
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. /**
  19. * @brief Configuration structure for esp_vfs_spiffs_register
  20. */
  21. typedef struct {
  22. const char* base_path; /*!< File path prefix associated with the filesystem. */
  23. const char* partition_label; /*!< Optional, label of SPIFFS partition to use. If set to NULL, first partition with subtype=spiffs will be used. */
  24. size_t max_files; /*!< Maximum files that could be open at the same time. */
  25. bool format_if_mount_failed; /*!< If true, it will format the file system if it fails to mount. */
  26. } esp_vfs_spiffs_conf_t;
  27. /**
  28. * Register and mount SPIFFS to VFS with given path prefix.
  29. *
  30. * @param conf Pointer to esp_vfs_spiffs_conf_t configuration structure
  31. *
  32. * @return
  33. * - ESP_OK if success
  34. * - ESP_ERR_NO_MEM if objects could not be allocated
  35. * - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted
  36. * - ESP_ERR_NOT_FOUND if partition for SPIFFS was not found
  37. * - ESP_FAIL if mount or format fails
  38. */
  39. esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf);
  40. /**
  41. * Unregister and unmount SPIFFS from VFS
  42. *
  43. * @param partition_label Optional, label of the partition to unregister.
  44. * If not specified, first partition with subtype=spiffs is used.
  45. *
  46. * @return
  47. * - ESP_OK if successful
  48. * - ESP_ERR_INVALID_STATE already unregistered
  49. */
  50. esp_err_t esp_vfs_spiffs_unregister(const char* partition_label);
  51. /**
  52. * Check if SPIFFS is mounted
  53. *
  54. * @param partition_label Optional, label of the partition to check.
  55. * If not specified, first partition with subtype=spiffs is used.
  56. *
  57. * @return
  58. * - true if mounted
  59. * - false if not mounted
  60. */
  61. bool esp_spiffs_mounted(const char* partition_label);
  62. /**
  63. * Format the SPIFFS partition
  64. *
  65. * @param partition_label Optional, label of the partition to format.
  66. * If not specified, first partition with subtype=spiffs is used.
  67. * @return
  68. * - ESP_OK if successful
  69. * - ESP_FAIL on error
  70. */
  71. esp_err_t esp_spiffs_format(const char* partition_label);
  72. /**
  73. * Get information for SPIFFS
  74. *
  75. * @param partition_label Optional, label of the partition to get info for.
  76. * If not specified, first partition with subtype=spiffs is used.
  77. * @param[out] total_bytes Size of the file system
  78. * @param[out] used_bytes Current used bytes in the file system
  79. *
  80. * @return
  81. * - ESP_OK if success
  82. * - ESP_ERR_INVALID_STATE if not mounted
  83. */
  84. esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes);
  85. #endif /* _ESP_SPIFFS_H_ */