default/spiffs_config.h
Go to the documentation of this file.
1 /*
2  * spiffs_config.h
3  *
4  * Created on: Jul 3, 2013
5  * Author: petera
6  */
7 
8 #ifndef SPIFFS_CONFIG_H_
9 #define SPIFFS_CONFIG_H_
10 
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 "params_test.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stddef.h>
19 #include <unistd.h>
20 #ifdef _SPIFFS_TEST
21 #include "testrunner.h"
22 #endif
23 // ----------- >8 ------------
24 
25 // compile time switches
26 
27 // Set generic spiffs debug output call.
28 #ifndef SPIFFS_DBG
29 #define SPIFFS_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
30 #endif
31 // Set spiffs debug output call for garbage collecting.
32 #ifndef SPIFFS_GC_DBG
33 #define SPIFFS_GC_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
34 #endif
35 // Set spiffs debug output call for caching.
36 #ifndef SPIFFS_CACHE_DBG
37 #define SPIFFS_CACHE_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
38 #endif
39 // Set spiffs debug output call for system consistency checks.
40 #ifndef SPIFFS_CHECK_DBG
41 #define SPIFFS_CHECK_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
42 #endif
43 // Set spiffs debug output call for all api invocations.
44 #ifndef SPIFFS_API_DBG
45 #define SPIFFS_API_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
46 #endif
47 
48 
49 
50 // Defines spiffs debug print formatters
51 // some general signed number
52 #ifndef _SPIPRIi
53 #define _SPIPRIi "%d"
54 #endif
55 // address
56 #ifndef _SPIPRIad
57 #define _SPIPRIad "%08x"
58 #endif
59 // block
60 #ifndef _SPIPRIbl
61 #define _SPIPRIbl "%04x"
62 #endif
63 // page
64 #ifndef _SPIPRIpg
65 #define _SPIPRIpg "%04x"
66 #endif
67 // span index
68 #ifndef _SPIPRIsp
69 #define _SPIPRIsp "%04x"
70 #endif
71 // file descriptor
72 #ifndef _SPIPRIfd
73 #define _SPIPRIfd "%d"
74 #endif
75 // file object id
76 #ifndef _SPIPRIid
77 #define _SPIPRIid "%04x"
78 #endif
79 // file flags
80 #ifndef _SPIPRIfl
81 #define _SPIPRIfl "%02x"
82 #endif
83 
84 
85 // Enable/disable API functions to determine exact number of bytes
86 // for filedescriptor and cache buffers. Once decided for a configuration,
87 // this can be disabled to reduce flash.
88 #ifndef SPIFFS_BUFFER_HELP
89 #define SPIFFS_BUFFER_HELP 0
90 #endif
91 
92 // Enables/disable memory read caching of nucleus file system operations.
93 // If enabled, memory area must be provided for cache in SPIFFS_mount.
94 #ifndef SPIFFS_CACHE
95 #define SPIFFS_CACHE 1
96 #endif
97 #if SPIFFS_CACHE
98 // Enables memory write caching for file descriptors in hydrogen
99 #ifndef SPIFFS_CACHE_WR
100 #define SPIFFS_CACHE_WR 1
101 #endif
102 
103 // Enable/disable statistics on caching. Debug/test purpose only.
104 #ifndef SPIFFS_CACHE_STATS
105 #define SPIFFS_CACHE_STATS 1
106 #endif
107 #endif
108 
109 // Always check header of each accessed page to ensure consistent state.
110 // If enabled it will increase number of reads, will increase flash.
111 #ifndef SPIFFS_PAGE_CHECK
112 #define SPIFFS_PAGE_CHECK 1
113 #endif
114 
115 // Define maximum number of gc runs to perform to reach desired free pages.
116 #ifndef SPIFFS_GC_MAX_RUNS
117 #define SPIFFS_GC_MAX_RUNS 5
118 #endif
119 
120 // Enable/disable statistics on gc. Debug/test purpose only.
121 #ifndef SPIFFS_GC_STATS
122 #define SPIFFS_GC_STATS 1
123 #endif
124 
125 // Garbage collecting examines all pages in a block which and sums up
126 // to a block score. Deleted pages normally gives positive score and
127 // used pages normally gives a negative score (as these must be moved).
128 // To have a fair wear-leveling, the erase age is also included in score,
129 // whose factor normally is the most positive.
130 // The larger the score, the more likely it is that the block will
131 // picked for garbage collection.
132 
133 // Garbage collecting heuristics - weight used for deleted pages.
134 #ifndef SPIFFS_GC_HEUR_W_DELET
135 #define SPIFFS_GC_HEUR_W_DELET (5)
136 #endif
137 // Garbage collecting heuristics - weight used for used pages.
138 #ifndef SPIFFS_GC_HEUR_W_USED
139 #define SPIFFS_GC_HEUR_W_USED (-1)
140 #endif
141 // Garbage collecting heuristics - weight used for time between
142 // last erased and erase of this block.
143 #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
144 #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
145 #endif
146 
147 // Object name maximum length. Note that this length include the
148 // zero-termination character, meaning maximum string of characters
149 // can at most be SPIFFS_OBJ_NAME_LEN - 1.
150 #ifndef SPIFFS_OBJ_NAME_LEN
151 #define SPIFFS_OBJ_NAME_LEN (32)
152 #endif
153 
154 // Maximum length of the metadata associated with an object.
155 // Setting to non-zero value enables metadata-related API but also
156 // changes the on-disk format, so the change is not backward-compatible.
157 //
158 // Do note: the meta length must never exceed
159 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
160 //
161 // This is derived from following:
162 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
163 // spiffs_object_ix_header fields + at least some LUT entries)
164 #ifndef SPIFFS_OBJ_META_LEN
165 #define SPIFFS_OBJ_META_LEN (0)
166 #endif
167 
168 // Size of buffer allocated on stack used when copying data.
169 // Lower value generates more read/writes. No meaning having it bigger
170 // than logical page size.
171 #ifndef SPIFFS_COPY_BUFFER_STACK
172 #define SPIFFS_COPY_BUFFER_STACK (64)
173 #endif
174 
175 // Enable this to have an identifiable spiffs filesystem. This will look for
176 // a magic in all sectors to determine if this is a valid spiffs system or
177 // not on mount point. If not, SPIFFS_format must be called prior to mounting
178 // again.
179 #ifndef SPIFFS_USE_MAGIC
180 #define SPIFFS_USE_MAGIC (0)
181 #endif
182 
183 #if SPIFFS_USE_MAGIC
184 // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
185 // enabled, the magic will also be dependent on the length of the filesystem.
186 // For example, a filesystem configured and formatted for 4 megabytes will not
187 // be accepted for mounting with a configuration defining the filesystem as 2
188 // megabytes.
189 #ifndef SPIFFS_USE_MAGIC_LENGTH
190 #define SPIFFS_USE_MAGIC_LENGTH (0)
191 #endif
192 #endif
193 
194 // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
195 // These should be defined on a multithreaded system
196 
197 // define this to enter a mutex if you're running on a multithreaded system
198 #ifndef SPIFFS_LOCK
199 #define SPIFFS_LOCK(fs)
200 #endif
201 // define this to exit a mutex if you're running on a multithreaded system
202 #ifndef SPIFFS_UNLOCK
203 #define SPIFFS_UNLOCK(fs)
204 #endif
205 
206 // Enable if only one spiffs instance with constant configuration will exist
207 // on the target. This will reduce calculations, flash and memory accesses.
208 // Parts of configuration must be defined below instead of at time of mount.
209 #ifndef SPIFFS_SINGLETON
210 #define SPIFFS_SINGLETON 0
211 #endif
212 
213 #if SPIFFS_SINGLETON
214 // Instead of giving parameters in config struct, singleton build must
215 // give parameters in defines below.
216 #ifndef SPIFFS_CFG_PHYS_SZ
217 #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
218 #endif
219 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
220 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
221 #endif
222 #ifndef SPIFFS_CFG_PHYS_ADDR
223 #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
224 #endif
225 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
226 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
227 #endif
228 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
229 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
230 #endif
231 #endif
232 
233 // Enable this if your target needs aligned data for index tables
234 #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
235 #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
236 #endif
237 
238 // Enable this if you want the HAL callbacks to be called with the spiffs struct
239 #ifndef SPIFFS_HAL_CALLBACK_EXTRA
240 #define SPIFFS_HAL_CALLBACK_EXTRA 0
241 #endif
242 
243 // Enable this if you want to add an integer offset to all file handles
244 // (spiffs_file). This is useful if running multiple instances of spiffs on
245 // same target, in order to recognise to what spiffs instance a file handle
246 // belongs.
247 // NB: This adds config field fh_ix_offset in the configuration struct when
248 // mounting, which must be defined.
249 #ifndef SPIFFS_FILEHDL_OFFSET
250 #define SPIFFS_FILEHDL_OFFSET 0
251 #endif
252 
253 // Enable this to compile a read only version of spiffs.
254 // This will reduce binary size of spiffs. All code comprising modification
255 // of the file system will not be compiled. Some config will be ignored.
256 // HAL functions for erasing and writing to spi-flash may be null. Cache
257 // can be disabled for even further binary size reduction (and ram savings).
258 // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
259 // If the file system cannot be mounted due to aborted erase operation and
260 // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
261 // returned.
262 // Might be useful for e.g. bootloaders and such.
263 #ifndef SPIFFS_READ_ONLY
264 #define SPIFFS_READ_ONLY 0
265 #endif
266 
267 // Enable this to add a temporal file cache using the fd buffer.
268 // The effects of the cache is that SPIFFS_open will find the file faster in
269 // certain cases. It will make it a lot easier for spiffs to find files
270 // opened frequently, reducing number of readings from the spi flash for
271 // finding those files.
272 // This will grow each fd by 6 bytes. If your files are opened in patterns
273 // with a degree of temporal locality, the system is optimized.
274 // Examples can be letting spiffs serve web content, where one file is the css.
275 // The css is accessed for each html file that is opened, meaning it is
276 // accessed almost every second time a file is opened. Another example could be
277 // a log file that is often opened, written, and closed.
278 // The size of the cache is number of given file descriptors, as it piggybacks
279 // on the fd update mechanism. The cache lives in the closed file descriptors.
280 // When closed, the fd know the whereabouts of the file. Instead of forgetting
281 // this, the temporal cache will keep handling updates to that file even if the
282 // fd is closed. If the file is opened again, the location of the file is found
283 // directly. If all available descriptors become opened, all cache memory is
284 // lost.
285 #ifndef SPIFFS_TEMPORAL_FD_CACHE
286 #define SPIFFS_TEMPORAL_FD_CACHE 1
287 #endif
288 
289 // Temporal file cache hit score. Each time a file is opened, all cached files
290 // will lose one point. If the opened file is found in cache, that entry will
291 // gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this
292 // value for the specific access patterns of the application. However, it must
293 // be between 1 (no gain for hitting a cached entry often) and 255.
294 #ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
295 #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
296 #endif
297 
298 // Enable to be able to map object indices to memory.
299 // This allows for faster and more deterministic reading if cases of reading
300 // large files and when changing file offset by seeking around a lot.
301 // When mapping a file's index, the file system will be scanned for index pages
302 // and the info will be put in memory provided by user. When reading, the
303 // memory map can be looked up instead of searching for index pages on the
304 // medium. This way, user can trade memory against performance.
305 // Whole, parts of, or future parts not being written yet can be mapped. The
306 // memory array will be owned by spiffs and updated accordingly during garbage
307 // collecting or when modifying the indices. The latter is invoked by when the
308 // file is modified in some way. The index buffer is tied to the file
309 // descriptor.
310 #ifndef SPIFFS_IX_MAP
311 #define SPIFFS_IX_MAP 1
312 #endif
313 
314 // By default SPIFFS in some cases relies on the property of NOR flash that bits
315 // cannot be set from 0 to 1 by writing and that controllers will ignore such
316 // bit changes. This results in fewer reads as SPIFFS can in some cases perform
317 // blind writes, with all bits set to 1 and only those it needs reset set to 0.
318 // Most of the chips and controllers allow this behavior, so the default is to
319 // use this technique. If your controller is one of the rare ones that don't,
320 // turn this option on and SPIFFS will perform a read-modify-write instead.
321 #ifndef SPIFFS_NO_BLIND_WRITES
322 #define SPIFFS_NO_BLIND_WRITES 0
323 #endif
324 
325 // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
326 // in the api. This function will visualize all filesystem using given printf
327 // function.
328 #ifndef SPIFFS_TEST_VISUALISATION
329 #define SPIFFS_TEST_VISUALISATION 1
330 #endif
331 #if SPIFFS_TEST_VISUALISATION
332 #ifndef spiffs_printf
333 #define spiffs_printf(...) printf(__VA_ARGS__)
334 #endif
335 // spiffs_printf argument for a free page
336 #ifndef SPIFFS_TEST_VIS_FREE_STR
337 #define SPIFFS_TEST_VIS_FREE_STR "_"
338 #endif
339 // spiffs_printf argument for a deleted page
340 #ifndef SPIFFS_TEST_VIS_DELE_STR
341 #define SPIFFS_TEST_VIS_DELE_STR "/"
342 #endif
343 // spiffs_printf argument for an index page for given object id
344 #ifndef SPIFFS_TEST_VIS_INDX_STR
345 #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
346 #endif
347 // spiffs_printf argument for a data page for given object id
348 #ifndef SPIFFS_TEST_VIS_DATA_STR
349 #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
350 #endif
351 #endif
352 
353 // Types depending on configuration such as the amount of flash bytes
354 // given to spiffs file system in total (spiffs_file_system_size),
355 // the logical block size (log_block_size), and the logical page size
356 // (log_page_size)
357 
358 // Block index type. Make sure the size of this type can hold
359 // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
361 // Page index type. Make sure the size of this type can hold
362 // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
364 // Object id type - most significant bit is reserved for index flag. Make sure the
365 // size of this type can hold the highest object id on a full system,
366 // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
368 // Object span index type. Make sure the size of this type can
369 // hold the largest possible span index on the system -
370 // i.e. (spiffs_file_system_size / log_page_size) - 1
372 
373 #endif /* SPIFFS_CONFIG_H_ */
u16_t spiffs_obj_id
Definition: default/spiffs_config.h:367
u16_t spiffs_span_ix
Definition: default/spiffs_config.h:371
uint16_t u16_t
Definition: spiffs_config.h:19
u16_t spiffs_block_ix
Definition: default/spiffs_config.h:360
u16_t spiffs_page_ix
Definition: default/spiffs_config.h:363
Copyright 2018, Texas Instruments Incorporated