spiffs_config.h 14 KB

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