Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
Loading...
Searching...
No Matches
spiffs_config.h
1
/*
2
* SPDX-FileCopyrightText: 2013-2016 Peter Andersson (pelleplutt1976<at>gmail.com)
3
* SPDX-License-Identifier: MIT
4
*/
5
6
#pragma once
7
8
/*
9
* spiffs_config.h
10
*
11
* Created on: Jul 3, 2013
12
* Author: petera
13
*/
14
15
#ifdef __cplusplus
16
extern
"C"
{
17
#endif
18
19
#include "board.h"
20
21
// ----------- 8< ------------
22
// Following includes are for the linux test build of spiffs
23
// These may/should/must be removed/altered/replaced in your target
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <string.h>
27
#include <stddef.h>
28
#include <unistd.h>
29
#include <stdint.h>
30
31
// ----------- >8 ------------
32
33
// compile time switches
34
35
// Set generic spiffs debug output call.
36
#ifndef SPIFFS_DBG
37
#define SPIFFS_DBG(...)
//printf(_f, ## __VA_ARGS__)
38
#endif
39
// Set spiffs debug output call for garbage collecting.
40
#ifndef SPIFFS_GC_DBG
41
#define SPIFFS_GC_DBG(...)
//printf(_f, ## __VA_ARGS__)
42
#endif
43
// Set spiffs debug output call for caching.
44
#ifndef SPIFFS_CACHE_DBG
45
#define SPIFFS_CACHE_DBG(...)
//printf(_f, ## __VA_ARGS__)
46
#endif
47
// Set spiffs debug output call for system consistency checks.
48
#ifndef SPIFFS_CHECK_DBG
49
#define SPIFFS_CHECK_DBG(...)
//printf(_f, ## __VA_ARGS__)
50
#endif
51
// Set spiffs debug output call for all api invocations.
52
#ifndef SPIFFS_API_DBG
53
#define SPIFFS_API_DBG(...)
//printf(_f, ## __VA_ARGS__)
54
#endif
55
56
// Defines spiffs debug print formatters
57
// some general signed number
58
#ifndef _SPIPRIi
59
#define _SPIPRIi "%d"
60
#endif
61
// address
62
#ifndef _SPIPRIad
63
#define _SPIPRIad "%08x"
64
#endif
65
// block
66
#ifndef _SPIPRIbl
67
#define _SPIPRIbl "%04x"
68
#endif
69
// page
70
#ifndef _SPIPRIpg
71
#define _SPIPRIpg "%04x"
72
#endif
73
// span index
74
#ifndef _SPIPRIsp
75
#define _SPIPRIsp "%04x"
76
#endif
77
// file descriptor
78
#ifndef _SPIPRIfd
79
#define _SPIPRIfd "%d"
80
#endif
81
// file object id
82
#ifndef _SPIPRIid
83
#define _SPIPRIid "%04x"
84
#endif
85
// file flags
86
#ifndef _SPIPRIfl
87
#define _SPIPRIfl "%02x"
88
#endif
89
90
// Enable/disable API functions to determine exact number of bytes
91
// for filedescriptor and cache buffers. Once decided for a configuration,
92
// this can be disabled to reduce flash.
93
#ifndef SPIFFS_BUFFER_HELP
94
#define SPIFFS_BUFFER_HELP 0
95
#endif
96
97
// Enables/disable memory read caching of nucleus file system operations.
98
// If enabled, memory area must be provided for cache in SPIFFS_mount.
99
#ifndef SPIFFS_CACHE
100
#define SPIFFS_CACHE 1
101
#endif
102
#if SPIFFS_CACHE
103
// Enables memory write caching for file descriptors in hydrogen
104
#ifndef SPIFFS_CACHE_WR
105
#define SPIFFS_CACHE_WR 1
106
#endif
107
108
// Enable/disable statistics on caching. Debug/test purpose only.
109
#ifndef SPIFFS_CACHE_STATS
110
#define SPIFFS_CACHE_STATS 1
111
#endif
112
#endif
113
114
// Always check header of each accessed page to ensure consistent state.
115
// If enabled it will increase number of reads, will increase flash.
116
#ifndef SPIFFS_PAGE_CHECK
117
#define SPIFFS_PAGE_CHECK 1
118
#endif
119
120
// Define maximum number of gc runs to perform to reach desired free pages.
121
#ifndef SPIFFS_GC_MAX_RUNS
122
#define SPIFFS_GC_MAX_RUNS 5
123
#endif
124
125
// Enable/disable statistics on gc. Debug/test purpose only.
126
#ifndef SPIFFS_GC_STATS
127
#define SPIFFS_GC_STATS 1
128
#endif
129
130
// Garbage collecting examines all pages in a block which and sums up
131
// to a block score. Deleted pages normally gives positive score and
132
// used pages normally gives a negative score (as these must be moved).
133
// To have a fair wear-leveling, the erase age is also included in score,
134
// whose factor normally is the most positive.
135
// The larger the score, the more likely it is that the block will
136
// picked for garbage collection.
137
138
// Garbage collecting heuristics - weight used for deleted pages.
139
#ifndef SPIFFS_GC_HEUR_W_DELET
140
#define SPIFFS_GC_HEUR_W_DELET (5)
141
#endif
142
// Garbage collecting heuristics - weight used for used pages.
143
#ifndef SPIFFS_GC_HEUR_W_USED
144
#define SPIFFS_GC_HEUR_W_USED (-1)
145
#endif
146
// Garbage collecting heuristics - weight used for time between
147
// last erased and erase of this block.
148
#ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
149
#define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
150
#endif
151
152
// Object name maximum length. Note that this length include the
153
// zero-termination character, meaning maximum string of characters
154
// can at most be SPIFFS_OBJ_NAME_LEN - 1.
155
#ifndef SPIFFS_OBJ_NAME_LEN
156
#define SPIFFS_OBJ_NAME_LEN (32)
157
#endif
158
159
// Maximum length of the metadata associated with an object.
160
// Setting to non-zero value enables metadata-related API but also
161
// changes the on-disk format, so the change is not backward-compatible.
162
//
163
// Do note: the meta length must never exceed
164
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
165
//
166
// This is derived from following:
167
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
168
// spiffs_object_ix_header fields + at least some LUT entries)
169
#ifndef SPIFFS_OBJ_META_LEN
170
#define SPIFFS_OBJ_META_LEN (0)
171
#endif
172
173
// Size of buffer allocated on stack used when copying data.
174
// Lower value generates more read/writes. No meaning having it bigger
175
// than logical page size.
176
#ifndef SPIFFS_COPY_BUFFER_STACK
177
#define SPIFFS_COPY_BUFFER_STACK (64)
178
#endif
179
180
// Enable this to have an identifiable spiffs filesystem. This will look for
181
// a magic in all sectors to determine if this is a valid spiffs system or
182
// not on mount point. If not, SPIFFS_format must be called prior to mounting
183
// again.
184
#ifndef SPIFFS_USE_MAGIC
185
#define SPIFFS_USE_MAGIC (1)
186
#endif
187
188
#if SPIFFS_USE_MAGIC
189
// Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
190
// enabled, the magic will also be dependent on the length of the filesystem.
191
// For example, a filesystem configured and formatted for 4 megabytes will not
192
// be accepted for mounting with a configuration defining the filesystem as 2
193
// megabytes.
194
#ifndef SPIFFS_USE_MAGIC_LENGTH
195
#define SPIFFS_USE_MAGIC_LENGTH (0)
196
#endif
197
#endif
198
199
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
200
// These should be defined on a multithreaded system
201
202
struct
spiffs_t;
203
void
spiffs_lock(
struct
spiffs_t *fs);
204
void
spiffs_unlock(
struct
spiffs_t *fs);
205
206
// define this to enter a mutex if you're running on a multithreaded system
207
#ifndef SPIFFS_LOCK
208
#define SPIFFS_LOCK(fs) spiffs_lock(fs)
209
#endif
210
// define this to exit a mutex if you're running on a multithreaded system
211
#ifndef SPIFFS_UNLOCK
212
#define SPIFFS_UNLOCK(fs) spiffs_unlock(fs)
213
#endif
214
215
// Enable if only one spiffs instance with constant configuration will exist
216
// on the target. This will reduce calculations, flash and memory accesses.
217
// Parts of configuration must be defined below instead of at time of mount.
218
#ifndef SPIFFS_SINGLETON
219
#define SPIFFS_SINGLETON 0
220
#endif
221
222
#if SPIFFS_SINGLETON
223
// Instead of giving parameters in config struct, singleton build must
224
// give parameters in defines below.
225
#ifndef SPIFFS_CFG_PHYS_SZ
226
#define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
227
#endif
228
#ifndef SPIFFS_CFG_PHYS_ERASE_SZ
229
#define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
230
#endif
231
#ifndef SPIFFS_CFG_PHYS_ADDR
232
#define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
233
#endif
234
#ifndef SPIFFS_CFG_LOG_PAGE_SZ
235
#define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
236
#endif
237
#ifndef SPIFFS_CFG_LOG_BLOCK_SZ
238
#define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
239
#endif
240
#endif
241
242
// Enable this if your target needs aligned data for index tables
243
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
244
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
245
#endif
246
247
// Enable this if you want the HAL callbacks to be called with the spiffs struct
248
#ifndef SPIFFS_HAL_CALLBACK_EXTRA
249
#define SPIFFS_HAL_CALLBACK_EXTRA 1
250
#endif
251
252
// Enable this if you want to add an integer offset to all file handles
253
// (spiffs_file). This is useful if running multiple instances of spiffs on
254
// same target, in order to recognise to what spiffs instance a file handle
255
// belongs.
256
// NB: This adds config field fh_ix_offset in the configuration struct when
257
// mounting, which must be defined.
258
#ifndef SPIFFS_FILEHDL_OFFSET
259
#define SPIFFS_FILEHDL_OFFSET 0
260
#endif
261
262
// Enable this to compile a read only version of spiffs.
263
// This will reduce binary size of spiffs. All code comprising modification
264
// of the file system will not be compiled. Some config will be ignored.
265
// HAL functions for erasing and writing to spi-flash may be null. Cache
266
// can be disabled for even further binary size reduction (and ram savings).
267
// Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
268
// If the file system cannot be mounted due to aborted erase operation and
269
// SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
270
// returned.
271
// Might be useful for e.g. bootloaders and such.
272
#ifndef SPIFFS_READ_ONLY
273
#define SPIFFS_READ_ONLY 0
274
#endif
275
276
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
277
// in the api. This function will visualize all filesystem using given printf
278
// function.
279
#ifndef SPIFFS_TEST_VISUALISATION
280
#define SPIFFS_TEST_VISUALISATION 0
281
#endif
282
#if SPIFFS_TEST_VISUALISATION
283
#ifndef spiffs_printf
284
#define spiffs_printf(...) DEBUG(__VA_ARGS__)
285
#endif
286
// spiffs_printf argument for a free page
287
#ifndef SPIFFS_TEST_VIS_FREE_STR
288
#define SPIFFS_TEST_VIS_FREE_STR "_"
289
#endif
290
// spiffs_printf argument for a deleted page
291
#ifndef SPIFFS_TEST_VIS_DELE_STR
292
#define SPIFFS_TEST_VIS_DELE_STR "/"
293
#endif
294
// spiffs_printf argument for an index page for given object id
295
#ifndef SPIFFS_TEST_VIS_INDX_STR
296
#define SPIFFS_TEST_VIS_INDX_STR(id) "i"
297
#endif
298
// spiffs_printf argument for a data page for given object id
299
#ifndef SPIFFS_TEST_VIS_DATA_STR
300
#define SPIFFS_TEST_VIS_DATA_STR(id) "d"
301
#endif
302
#endif
303
304
// Types depending on configuration such as the amount of flash bytes
305
// given to spiffs file system in total (spiffs_file_system_size),
306
// the logical block size (log_block_size), and the logical page size
307
// (log_page_size)
308
309
// Block index type. Make sure the size of this type can hold
310
// the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
311
typedef
uint16_t spiffs_block_ix;
312
// Page index type. Make sure the size of this type can hold
313
// the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
314
typedef
uint16_t spiffs_page_ix;
315
// Object id type - most significant bit is reserved for index flag. Make sure the
316
// size of this type can hold the highest object id on a full system,
317
// i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
318
typedef
uint16_t spiffs_obj_id;
319
// Object span index type. Make sure the size of this type can
320
// hold the largest possible span index on the system -
321
// i.e. (spiffs_file_system_size / log_page_size) - 1
322
typedef
uint16_t spiffs_span_ix;
323
324
typedef
uint8_t u8_t;
325
typedef
uint32_t u32_t;
326
typedef
int32_t s32_t;
327
typedef
uint16_t u16_t;
328
typedef
int16_t s16_t;
329
330
#ifdef __cplusplus
331
}
332
#endif
Generated on Sat Oct 3 2026 14:10:59 by
1.13.2