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