esp_spiffs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief Configuration structure for esp_vfs_spiffs_register
  23. */
  24. typedef struct {
  25. const char* base_path; /*!< File path prefix associated with the filesystem. */
  26. const char* partition_label; /*!< Optional, label of SPIFFS partition to use. If set to NULL, first partition with subtype=spiffs will be used. */
  27. size_t max_files; /*!< Maximum files that could be open at the same time. */
  28. bool format_if_mount_failed; /*!< If true, it will format the file system if it fails to mount. */
  29. } esp_vfs_spiffs_conf_t;
  30. /**
  31. * Register and mount SPIFFS to VFS with given path prefix.
  32. *
  33. * @param conf Pointer to esp_vfs_spiffs_conf_t configuration structure
  34. *
  35. * @return
  36. * - ESP_OK if success
  37. * - ESP_ERR_NO_MEM if objects could not be allocated
  38. * - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted
  39. * - ESP_ERR_NOT_FOUND if partition for SPIFFS was not found
  40. * - ESP_FAIL if mount or format fails
  41. */
  42. esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf);
  43. /**
  44. * Unregister and unmount SPIFFS from VFS
  45. *
  46. * @param partition_label Optional, label of the partition to unregister.
  47. * If not specified, first partition with subtype=spiffs is used.
  48. *
  49. * @return
  50. * - ESP_OK if successful
  51. * - ESP_ERR_INVALID_STATE already unregistered
  52. */
  53. esp_err_t esp_vfs_spiffs_unregister(const char* partition_label);
  54. /**
  55. * Check if SPIFFS is mounted
  56. *
  57. * @param partition_label Optional, label of the partition to check.
  58. * If not specified, first partition with subtype=spiffs is used.
  59. *
  60. * @return
  61. * - true if mounted
  62. * - false if not mounted
  63. */
  64. bool esp_spiffs_mounted(const char* partition_label);
  65. /**
  66. * Format the SPIFFS partition
  67. *
  68. * @param partition_label Optional, label of the partition to format.
  69. * If not specified, first partition with subtype=spiffs is used.
  70. * @return
  71. * - ESP_OK if successful
  72. * - ESP_FAIL on error
  73. */
  74. esp_err_t esp_spiffs_format(const char* partition_label);
  75. /**
  76. * Get information for SPIFFS
  77. *
  78. * @param partition_label Optional, label of the partition to get info for.
  79. * If not specified, first partition with subtype=spiffs is used.
  80. * @param[out] total_bytes Size of the file system
  81. * @param[out] used_bytes Current used bytes in the file system
  82. *
  83. * @return
  84. * - ESP_OK if success
  85. * - ESP_ERR_INVALID_STATE if not mounted
  86. */
  87. esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes);
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* _ESP_SPIFFS_H_ */