-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesp_littlefs.h
205 lines (182 loc) · 5.87 KB
/
esp_littlefs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef ESP_LITTLEFS_H__
#define ESP_LITTLEFS_H__
#include "esp_err.h"
#include "esp_idf_version.h"
#include <stdbool.h>
#include "esp_partition.h"
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
#include <sdmmc_cmd.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define ESP_LITTLEFS_VERSION_NUMBER "1.14.8"
#define ESP_LITTLEFS_VERSION_MAJOR 1
#define ESP_LITTLEFS_VERSION_MINOR 14
#define ESP_LITTLEFS_VERSION_PATCH 8
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 2) && CONFIG_VFS_SUPPORT_DIR
#define ESP_LITTLEFS_ENABLE_FTRUNCATE
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 2)
/**
*Configuration structure for esp_vfs_littlefs_register.
*/
typedef struct {
const char *base_path; /**< Mounting point. */
const char *partition_label; /**< Label of partition to use. */
const esp_partition_t* partition; /**< partition to use if partition_label is NULL */
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
sdmmc_card_t *sdcard; /**< SD card handle to use if both esp_partition handle & partition label is NULL */
#endif
uint8_t format_if_mount_failed:1; /**< Format the file system if it fails to mount. */
uint8_t read_only : 1; /**< Mount the partition as read-only. */
uint8_t dont_mount:1; /**< Don't attempt to mount.*/
uint8_t grow_on_mount:1; /**< Grow filesystem to match partition size on mount.*/
} esp_vfs_littlefs_conf_t;
/**
* Register and mount (if configured to) littlefs to VFS with given path prefix.
*
* @param conf Pointer to esp_vfs_littlefs_conf_t configuration structure
*
* @return
* - ESP_OK if success
* - ESP_ERR_NO_MEM if objects could not be allocated
* - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted
* - ESP_ERR_NOT_FOUND if partition for littlefs was not found
* - ESP_FAIL if mount or format fails
*/
esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t * conf);
/**
* Unregister and unmount littlefs from VFS
*
* @param partition_label Label of the partition to unregister.
*
* @return
* - ESP_OK if successful
* - ESP_ERR_INVALID_STATE already unregistered
*/
esp_err_t esp_vfs_littlefs_unregister(const char* partition_label);
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Unregister and unmount LittleFS from VFS for SD card
*
* @param sdcard SD card to unregister.
*
* @return
* - ESP_OK if successful
* - ESP_ERR_INVALID_STATE already unregistered
*/
esp_err_t esp_vfs_littlefs_unregister_sdmmc(sdmmc_card_t *sdcard);
#endif
/**
* Unregister and unmount littlefs from VFS
*
* @param partition partition to unregister.
*
* @return
* - ESP_OK if successful
* - ESP_ERR_INVALID_STATE already unregistered
*/
esp_err_t esp_vfs_littlefs_unregister_partition(const esp_partition_t* partition);
/**
* Check if littlefs is mounted
*
* @param partition_label Label of the partition to check.
*
* @return
* - true if mounted
* - false if not mounted
*/
bool esp_littlefs_mounted(const char* partition_label);
/**
* Check if littlefs is mounted
*
* @param partition partition to check.
*
* @return
* - true if mounted
* - false if not mounted
*/
bool esp_littlefs_partition_mounted(const esp_partition_t* partition);
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Check if littlefs is mounted
*
* @param sdcard SD card to check.
*
* @return
* - true if mounted
* - false if not mounted
*/
bool esp_littlefs_sdmmc_mounted(sdmmc_card_t *sdcard);
#endif
/**
* Format the littlefs partition
*
* @param partition_label Label of the partition to format.
* @return
* - ESP_OK if successful
* - ESP_FAIL on error
*/
esp_err_t esp_littlefs_format(const char* partition_label);
/**
* Format the littlefs partition
*
* @param partition partition to format.
* @return
* - ESP_OK if successful
* - ESP_FAIL on error
*/
esp_err_t esp_littlefs_format_partition(const esp_partition_t* partition);
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Format the LittleFS on a SD card
*
* @param sdcard SD card to format
* @return
* - ESP_OK if successful
* - ESP_FAIL on error
*/
esp_err_t esp_littlefs_format_sdmmc(sdmmc_card_t *sdcard);
#endif
/**
* Get information for littlefs
*
* @param partition_label Optional, label of the partition to get info for.
* @param[out] total_bytes Size of the file system
* @param[out] used_bytes Current used bytes in the file system
*
* @return
* - ESP_OK if success
* - ESP_ERR_INVALID_STATE if not mounted
*/
esp_err_t esp_littlefs_info(const char* partition_label, size_t* total_bytes, size_t* used_bytes);
/**
* Get information for littlefs
*
* @param parition the partition to get info for.
* @param[out] total_bytes Size of the file system
* @param[out] used_bytes Current used bytes in the file system
*
* @return
* - ESP_OK if success
* - ESP_ERR_INVALID_STATE if not mounted
*/
esp_err_t esp_littlefs_partition_info(const esp_partition_t* partition, size_t *total_bytes, size_t *used_bytes);
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Get information for littlefs on SD card
*
* @param[in] sdcard the SD card to get info for.
* @param[out] total_bytes Size of the file system
* @param[out] used_bytes Current used bytes in the file system
*
* @return
* - ESP_OK if success
* - ESP_ERR_INVALID_STATE if not mounted
*/
esp_err_t esp_littlefs_sdmmc_info(sdmmc_card_t *sdcard, size_t *total_bytes, size_t *used_bytes);
#endif
#ifdef __cplusplus
} // extern "C"
#endif
#endif