esp_spiffs.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 Same label as passed to esp_vfs_spiffs_register.
  47. *
  48. * @return
  49. * - ESP_OK if successful
  50. * - ESP_ERR_INVALID_STATE already unregistered
  51. */
  52. esp_err_t esp_vfs_spiffs_unregister(const char* partition_label);
  53. /**
  54. * Check if SPIFFS is mounted
  55. *
  56. * @param partition_label Optional, label of the partition to check.
  57. * If not specified, first partition with subtype=spiffs is used.
  58. *
  59. * @return
  60. * - true if mounted
  61. * - false if not mounted
  62. */
  63. bool esp_spiffs_mounted(const char* partition_label);
  64. /**
  65. * Format the SPIFFS partition
  66. *
  67. * @param partition_label Same label as passed to esp_vfs_spiffs_register.
  68. * @return
  69. * - ESP_OK if successful
  70. * - ESP_FAIL on error
  71. */
  72. esp_err_t esp_spiffs_format(const char* partition_label);
  73. /**
  74. * Get information for SPIFFS
  75. *
  76. * @param partition_label Same label as passed to esp_vfs_spiffs_register
  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. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* _ESP_SPIFFS_H_ */