88#ifndef SPIFFS_CONFIG_H_
99#define SPIFFS_CONFIG_H_
1010
11+ // ----------- 8< ------------
12+ // Following includes are for the linux test build of spiffs
13+ // These may/should/must be removed/altered/replaced in your target
14+ #include <stdio.h>
15+ #include <stdlib.h>
16+ #include <string.h>
1117#include <stddef.h>
1218#include <stdint.h>
1319#include <stdbool.h>
14- #include <string.h>
15- #include <stdio.h>
16-
17- typedef int16_t file_t ;
18- typedef int32_t s32_t ;
19- typedef uint32_t u32_t ;
20- typedef int16_t s16_t ;
21- typedef uint16_t u16_t ;
22- typedef int8_t s8_t ;
23- typedef uint8_t u8_t ;
24-
25- #ifndef SEEK_SET
26- #define SEEK_SET 0 /* set file offset to offset */
27- #endif
28-
29- #ifndef SEEK_CUR
30- #define SEEK_CUR 1 /* set file offset to current plus offset */
31- #endif
32-
33- #ifndef SEEK_END
34- #define SEEK_END 2 /* set file offset to EOF plus offset */
35- #endif
36-
37- #ifndef EOF
38- #define EOF (-1)
39- #endif
40-
41- // compile time switches
20+ #include <unistd.h>
4221
4322// Set generic spiffs debug output call.
4423#ifndef SPIFFS_DBG
45- #define SPIFFS_DBG (...) //printf(__VA_ARGS__)
24+ #define SPIFFS_DBG (_f , ...) //printf(_f, ## __VA_ARGS__)
4625#endif
4726// Set spiffs debug output call for garbage collecting.
4827#ifndef SPIFFS_GC_DBG
49- #define SPIFFS_GC_DBG (...) //printf(__VA_ARGS__)
28+ #define SPIFFS_GC_DBG (_f , ...) //printf(_f, ## __VA_ARGS__)
5029#endif
5130// Set spiffs debug output call for caching.
5231#ifndef SPIFFS_CACHE_DBG
53- #define SPIFFS_CACHE_DBG (...) //printf(__VA_ARGS__)
32+ #define SPIFFS_CACHE_DBG (_f , ...) //printf(_f, ## __VA_ARGS__)
5433#endif
5534// Set spiffs debug output call for system consistency checks.
5635#ifndef SPIFFS_CHECK_DBG
57- #define SPIFFS_CHECK_DBG (...) //printf(__VA_ARGS__)
36+ #define SPIFFS_CHECK_DBG (_f , ...) //printf(_f, ## __VA_ARGS__)
5837#endif
59-
6038// Set spiffs debug output call for all api invocations.
6139#ifndef SPIFFS_API_DBG
62- #define SPIFFS_API_DBG (...) //printf(__VA_ARGS__)
40+ #define SPIFFS_API_DBG (_f , ...) //printf(_f, ## __VA_ARGS__)
6341#endif
6442
43+ // needed types
44+ typedef int16_t file_t ;
45+ typedef int32_t s32_t ;
46+ typedef uint32_t u32_t ;
47+ typedef int16_t s16_t ;
48+ typedef uint16_t u16_t ;
49+ typedef int8_t s8_t ;
50+ typedef uint8_t u8_t ;
51+
6552// Defines spiffs debug print formatters
6653// some general signed number
67- #ifndef _SPIPRIi
6854#define _SPIPRIi "%d"
69- #endif
7055// address
71- #ifndef _SPIPRIad
7256#define _SPIPRIad "%08x"
73- #endif
7457// block
75- #ifndef _SPIPRIbl
7658#define _SPIPRIbl "%04x"
77- #endif
7859// page
79- #ifndef _SPIPRIpg
8060#define _SPIPRIpg "%04x"
81- #endif
8261// span index
83- #ifndef _SPIPRIsp
8462#define _SPIPRIsp "%04x"
85- #endif
8663// file descriptor
87- #ifndef _SPIPRIfd
8864#define _SPIPRIfd "%d"
89- #endif
9065// file object id
91- #ifndef _SPIPRIid
9266#define _SPIPRIid "%04x"
93- #endif
9467// file flags
95- #ifndef _SPIPRIfl
9668#define _SPIPRIfl "%02x"
97- #endif
69+
9870
9971// Enable/disable API functions to determine exact number of bytes
10072// for filedescriptor and cache buffers. Once decided for a configuration,
@@ -127,9 +99,7 @@ typedef uint8_t u8_t;
12799#endif
128100
129101// Define maximum number of gc runs to perform to reach desired free pages.
130- #ifndef SPIFFS_GC_MAX_RUNS
131- #define SPIFFS_GC_MAX_RUNS 5
132- #endif
102+ #define SPIFFS_GC_MAX_RUNS 10
133103
134104// Enable/disable statistics on gc. Debug/test purpose only.
135105#ifndef SPIFFS_GC_STATS
@@ -145,23 +115,17 @@ typedef uint8_t u8_t;
145115// picked for garbage collection.
146116
147117// Garbage collecting heuristics - weight used for deleted pages.
148- #ifndef SPIFFS_GC_HEUR_W_DELET
149118#define SPIFFS_GC_HEUR_W_DELET (5)
150- #endif
151119// Garbage collecting heuristics - weight used for used pages.
152- #ifndef SPIFFS_GC_HEUR_W_USED
153120#define SPIFFS_GC_HEUR_W_USED (-1)
154- #endif
155121// Garbage collecting heuristics - weight used for time between
156122// last erased and erase of this block.
157- #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
158123#define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
159- #endif
160124
161- // Object name maximum length.
162- #ifndef SPIFFS_OBJ_NAME_LEN
125+ // Object name maximum length. Note that this length include the
126+ // zero-termination character, meaning maximum string of characters
127+ // can at most be SPIFFS_OBJ_NAME_LEN - 1.
163128#define SPIFFS_OBJ_NAME_LEN (32)
164- #endif
165129
166130// Maximum length of the metadata associated with an object.
167131// Setting to non-zero value enables metadata-related API but also
@@ -173,15 +137,13 @@ typedef uint8_t u8_t;
173137// This is derived from following:
174138// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
175139// spiffs_object_ix_header fields + at least some LUT entries)
176- #ifndef SPIFFS_OBJ_META_LEN
177140#define SPIFFS_OBJ_META_LEN (0)
178- #endif
179141
180142// Size of buffer allocated on stack used when copying data.
181143// Lower value generates more read/writes. No meaning having it bigger
182144// than logical page size.
183145#ifndef SPIFFS_COPY_BUFFER_STACK
184- #define SPIFFS_COPY_BUFFER_STACK (64 )
146+ #define SPIFFS_COPY_BUFFER_STACK (256 )
185147#endif
186148
187149// Enable this to have an identifiable spiffs filesystem. This will look for
@@ -207,50 +169,23 @@ typedef uint8_t u8_t;
207169// These should be defined on a multithreaded system
208170
209171// define this to enter a mutex if you're running on a multithreaded system
210- #ifndef SPIFFS_LOCK
211172#define SPIFFS_LOCK (fs )
212- #endif
213173// define this to exit a mutex if you're running on a multithreaded system
214- #ifndef SPIFFS_UNLOCK
215174#define SPIFFS_UNLOCK (fs )
216- #endif
217-
218175
219176// Enable if only one spiffs instance with constant configuration will exist
220177// on the target. This will reduce calculations, flash and memory accesses.
221178// Parts of configuration must be defined below instead of at time of mount.
222- #ifndef SPIFFS_SINGLETON
223179#define SPIFFS_SINGLETON 0
224- #endif
225-
226- #if SPIFFS_SINGLETON
227- // Instead of giving parameters in config struct, singleton build must
228- // give parameters in defines below.
229- #ifndef SPIFFS_CFG_PHYS_SZ
230- #define SPIFFS_CFG_PHYS_SZ (ignore ) (1024*1024*2)
231- #endif
232- #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
233- #define SPIFFS_CFG_PHYS_ERASE_SZ (ignore ) (65536)
234- #endif
235- #ifndef SPIFFS_CFG_PHYS_ADDR
236- #define SPIFFS_CFG_PHYS_ADDR (ignore ) (0)
237- #endif
238- #ifndef SPIFFS_CFG_LOG_PAGE_SZ
239- #define SPIFFS_CFG_LOG_PAGE_SZ (ignore ) (256)
240- #endif
241- #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
242- #define SPIFFS_CFG_LOG_BLOCK_SZ (ignore ) (65536)
243- #endif
244- #endif
245180
246181// Enable this if your target needs aligned data for index tables
247182#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
248- #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
183+ #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
249184#endif
250185
251186// Enable this if you want the HAL callbacks to be called with the spiffs struct
252187#ifndef SPIFFS_HAL_CALLBACK_EXTRA
253- #define SPIFFS_HAL_CALLBACK_EXTRA 0
188+ #define SPIFFS_HAL_CALLBACK_EXTRA 0
254189#endif
255190
256191// Enable this if you want to add an integer offset to all file handles
@@ -260,7 +195,7 @@ typedef uint8_t u8_t;
260195// NB: This adds config field fh_ix_offset in the configuration struct when
261196// mounting, which must be defined.
262197#ifndef SPIFFS_FILEHDL_OFFSET
263- #define SPIFFS_FILEHDL_OFFSET 0
198+ #define SPIFFS_FILEHDL_OFFSET 0
264199#endif
265200
266201// Enable this to compile a read only version of spiffs.
@@ -274,7 +209,7 @@ typedef uint8_t u8_t;
274209// returned.
275210// Might be useful for e.g. bootloaders and such.
276211#ifndef SPIFFS_READ_ONLY
277- #define SPIFFS_READ_ONLY 0
212+ #define SPIFFS_READ_ONLY 0
278213#endif
279214
280215// Enable this to add a temporal file cache using the fd buffer.
@@ -296,7 +231,7 @@ typedef uint8_t u8_t;
296231// directly. If all available descriptors become opened, all cache memory is
297232// lost.
298233#ifndef SPIFFS_TEMPORAL_FD_CACHE
299- #define SPIFFS_TEMPORAL_FD_CACHE 1
234+ #define SPIFFS_TEMPORAL_FD_CACHE 1
300235#endif
301236
302237// Temporal file cache hit score. Each time a file is opened, all cached files
@@ -305,7 +240,7 @@ typedef uint8_t u8_t;
305240// value for the specific access patterns of the application. However, it must
306241// be between 1 (no gain for hitting a cached entry often) and 255.
307242#ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
308- #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
243+ #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
309244#endif
310245
311246// Enable to be able to map object indices to memory.
@@ -321,12 +256,12 @@ typedef uint8_t u8_t;
321256// file is modified in some way. The index buffer is tied to the file
322257// descriptor.
323258#ifndef SPIFFS_IX_MAP
324- #define SPIFFS_IX_MAP 1
259+ #define SPIFFS_IX_MAP 1
325260#endif
326261
327262// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
328263// in the api. This function will visualize all filesystem using given printf
329- // function.
264+ // function..
330265#ifndef SPIFFS_TEST_VISUALISATION
331266#define SPIFFS_TEST_VISUALISATION 1
332267#endif
@@ -335,22 +270,14 @@ typedef uint8_t u8_t;
335270#define spiffs_printf (...) printf(__VA_ARGS__)
336271#endif
337272// spiffs_printf argument for a free page
338- #ifndef SPIFFS_TEST_VIS_FREE_STR
339273#define SPIFFS_TEST_VIS_FREE_STR "_"
340- #endif
341274// spiffs_printf argument for a deleted page
342- #ifndef SPIFFS_TEST_VIS_DELE_STR
343275#define SPIFFS_TEST_VIS_DELE_STR "/"
344- #endif
345276// spiffs_printf argument for an index page for given object id
346- #ifndef SPIFFS_TEST_VIS_INDX_STR
347277#define SPIFFS_TEST_VIS_INDX_STR (id ) "i"
348- #endif
349278// spiffs_printf argument for a data page for given object id
350- #ifndef SPIFFS_TEST_VIS_DATA_STR
351279#define SPIFFS_TEST_VIS_DATA_STR (id ) "d"
352280#endif
353- #endif
354281
355282// Types depending on configuration such as the amount of flash bytes
356283// given to spiffs file system in total (spiffs_file_system_size),
0 commit comments