|
11 | 11 | // ----------- 8< ------------ |
12 | 12 | // Following includes are for the linux test build of spiffs |
13 | 13 | // These may/should/must be removed/altered/replaced in your target |
14 | | -#include <stdio.h> |
15 | | -#include <stdlib.h> |
16 | | -#include <string.h> |
17 | | -#include <stddef.h> |
18 | | -#include "freertos/FreeRTOS.h" |
19 | | -#include "freertos/task.h" |
20 | | - |
| 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 |
21 | 23 | // ----------- >8 ------------ |
22 | 24 |
|
| 25 | +#include "freertos/FreeRTOS.h" |
| 26 | + |
23 | 27 | // compile time switches |
24 | 28 |
|
25 | 29 | // Set generic spiffs debug output call. |
26 | 30 | #ifndef SPIFFS_DBG |
27 | | -#define SPIFFS_DBG(...) //printf(__VA_ARGS__) |
| 31 | +#define SPIFFS_DBG(_f, ...) //printf(_f, ## __VA_ARGS__) |
28 | 32 | #endif |
29 | 33 | // Set spiffs debug output call for garbage collecting. |
30 | 34 | #ifndef SPIFFS_GC_DBG |
31 | | -#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__) |
| 35 | +#define SPIFFS_GC_DBG(_f, ...) //printf(_f, ## __VA_ARGS__) |
32 | 36 | #endif |
33 | 37 | // Set spiffs debug output call for caching. |
34 | 38 | #ifndef SPIFFS_CACHE_DBG |
35 | | -#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__) |
| 39 | +#define SPIFFS_CACHE_DBG(_f, ...) //printf(_f, ## __VA_ARGS__) |
36 | 40 | #endif |
37 | 41 | // Set spiffs debug output call for system consistency checks. |
38 | 42 | #ifndef SPIFFS_CHECK_DBG |
39 | | -#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__) |
| 43 | +#define SPIFFS_CHECK_DBG(_f, ...) //printf(_f, ## __VA_ARGS__) |
| 44 | +#endif |
| 45 | +// Set spiffs debug output call for all api invocations. |
| 46 | +#ifndef SPIFFS_API_DBG |
| 47 | +#define SPIFFS_API_DBG(_f, ...) //printf(_f, ## __VA_ARGS__) |
40 | 48 | #endif |
41 | 49 |
|
| 50 | + |
| 51 | + |
| 52 | +// Defines spiffs debug print formatters |
| 53 | +// some general signed number |
| 54 | +#ifndef _SPIPRIi |
| 55 | +#define _SPIPRIi "%d" |
| 56 | +#endif |
| 57 | +// address |
| 58 | +#ifndef _SPIPRIad |
| 59 | +#define _SPIPRIad "%08x" |
| 60 | +#endif |
| 61 | +// block |
| 62 | +#ifndef _SPIPRIbl |
| 63 | +#define _SPIPRIbl "%04x" |
| 64 | +#endif |
| 65 | +// page |
| 66 | +#ifndef _SPIPRIpg |
| 67 | +#define _SPIPRIpg "%04x" |
| 68 | +#endif |
| 69 | +// span index |
| 70 | +#ifndef _SPIPRIsp |
| 71 | +#define _SPIPRIsp "%04x" |
| 72 | +#endif |
| 73 | +// file descriptor |
| 74 | +#ifndef _SPIPRIfd |
| 75 | +#define _SPIPRIfd "%d" |
| 76 | +#endif |
| 77 | +// file object id |
| 78 | +#ifndef _SPIPRIid |
| 79 | +#define _SPIPRIid "%04x" |
| 80 | +#endif |
| 81 | +// file flags |
| 82 | +#ifndef _SPIPRIfl |
| 83 | +#define _SPIPRIfl "%02x" |
| 84 | +#endif |
| 85 | + |
| 86 | + |
42 | 87 | // Enable/disable API functions to determine exact number of bytes |
43 | 88 | // for filedescriptor and cache buffers. Once decided for a configuration, |
44 | 89 | // this can be disabled to reduce flash. |
|
51 | 96 | #ifndef SPIFFS_CACHE |
52 | 97 | #define SPIFFS_CACHE 1 |
53 | 98 | #endif |
54 | | - |
55 | 99 | #if SPIFFS_CACHE |
56 | 100 | // Enables memory write caching for file descriptors in hydrogen |
57 | 101 | #ifndef SPIFFS_CACHE_WR |
|
60 | 104 |
|
61 | 105 | // Enable/disable statistics on caching. Debug/test purpose only. |
62 | 106 | #ifndef SPIFFS_CACHE_STATS |
63 | | -#define SPIFFS_CACHE_STATS 1 |
| 107 | +#define SPIFFS_CACHE_STATS 0 |
64 | 108 | #endif |
65 | 109 | #endif |
66 | 110 |
|
|
72 | 116 |
|
73 | 117 | // Define maximum number of gc runs to perform to reach desired free pages. |
74 | 118 | #ifndef SPIFFS_GC_MAX_RUNS |
75 | | -#define SPIFFS_GC_MAX_RUNS 5 |
| 119 | +#define SPIFFS_GC_MAX_RUNS 10 |
76 | 120 | #endif |
77 | 121 |
|
78 | 122 | // Enable/disable statistics on gc. Debug/test purpose only. |
79 | 123 | #ifndef SPIFFS_GC_STATS |
80 | | -#define SPIFFS_GC_STATS 1 |
| 124 | +#define SPIFFS_GC_STATS 0 |
81 | 125 | #endif |
82 | 126 |
|
83 | 127 | // Garbage collecting examines all pages in a block which and sums up |
|
102 | 146 | #define SPIFFS_GC_HEUR_W_ERASE_AGE (50) |
103 | 147 | #endif |
104 | 148 |
|
105 | | -// Object name maximum length. |
| 149 | +// Object name maximum length. Note that this length include the |
| 150 | +// zero-termination character, meaning maximum string of characters |
| 151 | +// can at most be SPIFFS_OBJ_NAME_LEN - 1. |
106 | 152 | #ifndef SPIFFS_OBJ_NAME_LEN |
107 | 153 | #define SPIFFS_OBJ_NAME_LEN (32) |
108 | 154 | #endif |
109 | 155 |
|
| 156 | +// Maximum length of the metadata associated with an object. |
| 157 | +// Setting to non-zero value enables metadata-related API but also |
| 158 | +// changes the on-disk format, so the change is not backward-compatible. |
| 159 | +// |
| 160 | +// Do note: the meta length must never exceed |
| 161 | +// logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64) |
| 162 | +// |
| 163 | +// This is derived from following: |
| 164 | +// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) + |
| 165 | +// spiffs_object_ix_header fields + at least some LUT entries) |
| 166 | +#ifndef SPIFFS_OBJ_META_LEN |
| 167 | +#define SPIFFS_OBJ_META_LEN (0) |
| 168 | +#endif |
| 169 | + |
110 | 170 | // Size of buffer allocated on stack used when copying data. |
111 | 171 | // Lower value generates more read/writes. No meaning having it bigger |
112 | 172 | // than logical page size. |
|
122 | 182 | #define SPIFFS_USE_MAGIC (0) |
123 | 183 | #endif |
124 | 184 |
|
| 185 | +#if SPIFFS_USE_MAGIC |
| 186 | +// Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is |
| 187 | +// enabled, the magic will also be dependent on the length of the filesystem. |
| 188 | +// For example, a filesystem configured and formatted for 4 megabytes will not |
| 189 | +// be accepted for mounting with a configuration defining the filesystem as 2 |
| 190 | +// megabytes. |
| 191 | +#ifndef SPIFFS_USE_MAGIC_LENGTH |
| 192 | +#define SPIFFS_USE_MAGIC_LENGTH (1) |
| 193 | +#endif |
| 194 | +#endif |
| 195 | + |
125 | 196 | // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level |
126 | 197 | // These should be defined on a multithreaded system |
127 | 198 |
|
|
134 | 205 | #define SPIFFS_UNLOCK(fs) |
135 | 206 | #endif |
136 | 207 |
|
137 | | - |
138 | 208 | // Enable if only one spiffs instance with constant configuration will exist |
139 | 209 | // on the target. This will reduce calculations, flash and memory accesses. |
140 | 210 | // Parts of configuration must be defined below instead of at time of mount. |
|
167 | 237 | #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1 |
168 | 238 | #endif |
169 | 239 |
|
| 240 | +// Enable this if you want the HAL callbacks to be called with the spiffs struct |
| 241 | +#ifndef SPIFFS_HAL_CALLBACK_EXTRA |
| 242 | +#define SPIFFS_HAL_CALLBACK_EXTRA 0 |
| 243 | +#endif |
| 244 | + |
| 245 | +// Enable this if you want to add an integer offset to all file handles |
| 246 | +// (spiffs_file). This is useful if running multiple instances of spiffs on |
| 247 | +// same target, in order to recognise to what spiffs instance a file handle |
| 248 | +// belongs. |
| 249 | +// NB: This adds config field fh_ix_offset in the configuration struct when |
| 250 | +// mounting, which must be defined. |
| 251 | +#ifndef SPIFFS_FILEHDL_OFFSET |
| 252 | +#define SPIFFS_FILEHDL_OFFSET 0 |
| 253 | +#endif |
| 254 | + |
| 255 | +// Enable this to compile a read only version of spiffs. |
| 256 | +// This will reduce binary size of spiffs. All code comprising modification |
| 257 | +// of the file system will not be compiled. Some config will be ignored. |
| 258 | +// HAL functions for erasing and writing to spi-flash may be null. Cache |
| 259 | +// can be disabled for even further binary size reduction (and ram savings). |
| 260 | +// Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL. |
| 261 | +// If the file system cannot be mounted due to aborted erase operation and |
| 262 | +// SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be |
| 263 | +// returned. |
| 264 | +// Might be useful for e.g. bootloaders and such. |
| 265 | +#ifndef SPIFFS_READ_ONLY |
| 266 | +#define SPIFFS_READ_ONLY 0 |
| 267 | +#endif |
| 268 | + |
| 269 | +// Enable this to add a temporal file cache using the fd buffer. |
| 270 | +// The effects of the cache is that SPIFFS_open will find the file faster in |
| 271 | +// certain cases. It will make it a lot easier for spiffs to find files |
| 272 | +// opened frequently, reducing number of readings from the spi flash for |
| 273 | +// finding those files. |
| 274 | +// This will grow each fd by 6 bytes. If your files are opened in patterns |
| 275 | +// with a degree of temporal locality, the system is optimized. |
| 276 | +// Examples can be letting spiffs serve web content, where one file is the css. |
| 277 | +// The css is accessed for each html file that is opened, meaning it is |
| 278 | +// accessed almost every second time a file is opened. Another example could be |
| 279 | +// a log file that is often opened, written, and closed. |
| 280 | +// The size of the cache is number of given file descriptors, as it piggybacks |
| 281 | +// on the fd update mechanism. The cache lives in the closed file descriptors. |
| 282 | +// When closed, the fd know the whereabouts of the file. Instead of forgetting |
| 283 | +// this, the temporal cache will keep handling updates to that file even if the |
| 284 | +// fd is closed. If the file is opened again, the location of the file is found |
| 285 | +// directly. If all available descriptors become opened, all cache memory is |
| 286 | +// lost. |
| 287 | +#ifndef SPIFFS_TEMPORAL_FD_CACHE |
| 288 | +#define SPIFFS_TEMPORAL_FD_CACHE 1 |
| 289 | +#endif |
| 290 | + |
| 291 | +// Temporal file cache hit score. Each time a file is opened, all cached files |
| 292 | +// will lose one point. If the opened file is found in cache, that entry will |
| 293 | +// gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this |
| 294 | +// value for the specific access patterns of the application. However, it must |
| 295 | +// be between 1 (no gain for hitting a cached entry often) and 255. |
| 296 | +#ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE |
| 297 | +#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4 |
| 298 | +#endif |
| 299 | + |
| 300 | +// Enable to be able to map object indices to memory. |
| 301 | +// This allows for faster and more deterministic reading if cases of reading |
| 302 | +// large files and when changing file offset by seeking around a lot. |
| 303 | +// When mapping a file's index, the file system will be scanned for index pages |
| 304 | +// and the info will be put in memory provided by user. When reading, the |
| 305 | +// memory map can be looked up instead of searching for index pages on the |
| 306 | +// medium. This way, user can trade memory against performance. |
| 307 | +// Whole, parts of, or future parts not being written yet can be mapped. The |
| 308 | +// memory array will be owned by spiffs and updated accordingly during garbage |
| 309 | +// collecting or when modifying the indices. The latter is invoked by when the |
| 310 | +// file is modified in some way. The index buffer is tied to the file |
| 311 | +// descriptor. |
| 312 | +#ifndef SPIFFS_IX_MAP |
| 313 | +#define SPIFFS_IX_MAP 1 |
| 314 | +#endif |
| 315 | + |
| 316 | +// By default SPIFFS in some cases relies on the property of NOR flash that bits |
| 317 | +// cannot be set from 0 to 1 by writing and that controllers will ignore such |
| 318 | +// bit changes. This results in fewer reads as SPIFFS can in some cases perform |
| 319 | +// blind writes, with all bits set to 1 and only those it needs reset set to 0. |
| 320 | +// Most of the chips and controllers allow this behavior, so the default is to |
| 321 | +// use this technique. If your controller is one of the rare ones that don't, |
| 322 | +// turn this option on and SPIFFS will perform a read-modify-write instead. |
| 323 | +#ifndef SPIFFS_NO_BLIND_WRITES |
| 324 | +#define SPIFFS_NO_BLIND_WRITES 0 |
| 325 | +#endif |
| 326 | + |
170 | 327 | // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function |
171 | 328 | // in the api. This function will visualize all filesystem using given printf |
172 | 329 | // function. |
173 | 330 | #ifndef SPIFFS_TEST_VISUALISATION |
174 | | -#define SPIFFS_TEST_VISUALISATION 0 |
| 331 | +#define SPIFFS_TEST_VISUALISATION 1 |
175 | 332 | #endif |
176 | 333 | #if SPIFFS_TEST_VISUALISATION |
177 | 334 | #ifndef spiffs_printf |
|
0 commit comments