spiffs_config.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. // compile time switches
  15. // Set generic spiffs debug output call.
  16. #ifndef SPIFFS_DBG
  17. #define SPIFFS_DBG(...) //printf(__VA_ARGS__)
  18. #endif
  19. // Set spiffs debug output call for garbage collecting.
  20. #ifndef SPIFFS_GC_DBG
  21. #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
  22. #endif
  23. // Set spiffs debug output call for caching.
  24. #ifndef SPIFFS_CACHE_DBG
  25. #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
  26. #endif
  27. // Set spiffs debug output call for system consistency checks.
  28. #ifndef SPIFFS_CHECK_DBG
  29. #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
  30. #endif
  31. // Enable/disable API functions to determine exact number of bytes
  32. // for filedescriptor and cache buffers. Once decided for a configuration,
  33. // this can be disabled to reduce flash.
  34. #ifndef SPIFFS_BUFFER_HELP
  35. #define SPIFFS_BUFFER_HELP 0
  36. #endif
  37. // Enables/disable memory read caching of nucleus file system operations.
  38. // If enabled, memory area must be provided for cache in SPIFFS_mount.
  39. #ifndef SPIFFS_CACHE
  40. #define SPIFFS_CACHE 1
  41. #endif
  42. #if SPIFFS_CACHE
  43. // Enables memory write caching for file descriptors in hydrogen
  44. #ifndef SPIFFS_CACHE_WR
  45. #define SPIFFS_CACHE_WR 1
  46. #endif
  47. // Enable/disable statistics on caching. Debug/test purpose only.
  48. #ifndef SPIFFS_CACHE_STATS
  49. #define SPIFFS_CACHE_STATS 1
  50. #endif
  51. #endif
  52. // Always check header of each accessed page to ensure consistent state.
  53. // If enabled it will increase number of reads, will increase flash.
  54. #ifndef SPIFFS_PAGE_CHECK
  55. #define SPIFFS_PAGE_CHECK 1
  56. #endif
  57. // Define maximum number of gc runs to perform to reach desired free pages.
  58. #ifndef SPIFFS_GC_MAX_RUNS
  59. #define SPIFFS_GC_MAX_RUNS 5
  60. #endif
  61. // Enable/disable statistics on gc. Debug/test purpose only.
  62. #ifndef SPIFFS_GC_STATS
  63. #define SPIFFS_GC_STATS 1
  64. #endif
  65. // Garbage collecting examines all pages in a block which and sums up
  66. // to a block score. Deleted pages normally gives positive score and
  67. // used pages normally gives a negative score (as these must be moved).
  68. // To have a fair wear-leveling, the erase age is also included in score,
  69. // whose factor normally is the most positive.
  70. // The larger the score, the more likely it is that the block will
  71. // picked for garbage collection.
  72. // Garbage collecting heuristics - weight used for deleted pages.
  73. #ifndef SPIFFS_GC_HEUR_W_DELET
  74. #define SPIFFS_GC_HEUR_W_DELET (5)
  75. #endif
  76. // Garbage collecting heuristics - weight used for used pages.
  77. #ifndef SPIFFS_GC_HEUR_W_USED
  78. #define SPIFFS_GC_HEUR_W_USED (-1)
  79. #endif
  80. // Garbage collecting heuristics - weight used for time between
  81. // last erased and erase of this block.
  82. #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
  83. #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
  84. #endif
  85. // Object name maximum length. Note that this length include the
  86. // zero-termination character, meaning maximum string of characters
  87. // can at most be SPIFFS_OBJ_NAME_LEN - 1.
  88. #ifndef SPIFFS_OBJ_NAME_LEN
  89. #define SPIFFS_OBJ_NAME_LEN (32)
  90. #endif
  91. // Size of buffer allocated on stack used when copying data.
  92. // Lower value generates more read/writes. No meaning having it bigger
  93. // than logical page size.
  94. #ifndef SPIFFS_COPY_BUFFER_STACK
  95. #define SPIFFS_COPY_BUFFER_STACK (64)
  96. #endif
  97. // Enable this to have an identifiable spiffs filesystem. This will look for
  98. // a magic in all sectors to determine if this is a valid spiffs system or
  99. // not on mount point. If not, SPIFFS_format must be called prior to mounting
  100. // again.
  101. #ifndef SPIFFS_USE_MAGIC
  102. #define SPIFFS_USE_MAGIC (0)
  103. #endif
  104. #if SPIFFS_USE_MAGIC
  105. // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
  106. // enabled, the magic will also be dependent on the length of the filesystem.
  107. // For example, a filesystem configured and formatted for 4 megabytes will not
  108. // be accepted for mounting with a configuration defining the filesystem as 2
  109. // megabytes.
  110. #ifndef SPIFFS_USE_MAGIC_LENGTH
  111. #define SPIFFS_USE_MAGIC_LENGTH (0)
  112. #endif
  113. #endif
  114. // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
  115. // These should be defined on a multithreaded system
  116. // define this to enter a mutex if you're running on a multithreaded system
  117. #ifndef SPIFFS_LOCK
  118. #define SPIFFS_LOCK(fs)
  119. #endif
  120. // define this to exit a mutex if you're running on a multithreaded system
  121. #ifndef SPIFFS_UNLOCK
  122. #define SPIFFS_UNLOCK(fs)
  123. #endif
  124. // Enable if only one spiffs instance with constant configuration will exist
  125. // on the target. This will reduce calculations, flash and memory accesses.
  126. // Parts of configuration must be defined below instead of at time of mount.
  127. #ifndef SPIFFS_SINGLETON
  128. #define SPIFFS_SINGLETON 0
  129. #endif
  130. #if SPIFFS_SINGLETON
  131. // Instead of giving parameters in config struct, singleton build must
  132. // give parameters in defines below.
  133. #ifndef SPIFFS_CFG_PHYS_SZ
  134. #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
  135. #endif
  136. #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
  137. #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
  138. #endif
  139. #ifndef SPIFFS_CFG_PHYS_ADDR
  140. #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
  141. #endif
  142. #ifndef SPIFFS_CFG_LOG_PAGE_SZ
  143. #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
  144. #endif
  145. #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
  146. #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
  147. #endif
  148. #endif
  149. // Enable this if your target needs aligned data for index tables
  150. #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
  151. #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
  152. #endif
  153. // Enable this if you want the HAL callbacks to be called with the spiffs struct
  154. #ifndef SPIFFS_HAL_CALLBACK_EXTRA
  155. #define SPIFFS_HAL_CALLBACK_EXTRA 0
  156. #endif
  157. // Enable this if you want to add an integer offset to all file handles
  158. // (spiffs_file). This is useful if running multiple instances of spiffs on
  159. // same target, in order to recognise to what spiffs instance a file handle
  160. // belongs.
  161. // NB: This adds config field fh_ix_offset in the configuration struct when
  162. // mounting, which must be defined.
  163. #ifndef SPIFFS_FILEHDL_OFFSET
  164. #define SPIFFS_FILEHDL_OFFSET 0
  165. #endif
  166. // Enable this to compile a read only version of spiffs.
  167. // This will reduce binary size of spiffs. All code comprising modification
  168. // of the file system will not be compiled. Some config will be ignored.
  169. // HAL functions for erasing and writing to spi-flash may be null. Cache
  170. // can be disabled for even further binary size reduction (and ram savings).
  171. // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
  172. // If the file system cannot be mounted due to aborted erase operation and
  173. // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
  174. // returned.
  175. // Might be useful for e.g. bootloaders and such.
  176. #ifndef SPIFFS_READ_ONLY
  177. #define SPIFFS_READ_ONLY 0
  178. #endif
  179. // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
  180. // in the api. This function will visualize all filesystem using given printf
  181. // function.
  182. #ifndef SPIFFS_TEST_VISUALISATION
  183. #define SPIFFS_TEST_VISUALISATION 1
  184. #endif
  185. #if SPIFFS_TEST_VISUALISATION
  186. #ifndef spiffs_printf
  187. #define spiffs_printf(...) printf(__VA_ARGS__)
  188. #endif
  189. // spiffs_printf argument for a free page
  190. #ifndef SPIFFS_TEST_VIS_FREE_STR
  191. #define SPIFFS_TEST_VIS_FREE_STR "_"
  192. #endif
  193. // spiffs_printf argument for a deleted page
  194. #ifndef SPIFFS_TEST_VIS_DELE_STR
  195. #define SPIFFS_TEST_VIS_DELE_STR "/"
  196. #endif
  197. // spiffs_printf argument for an index page for given object id
  198. #ifndef SPIFFS_TEST_VIS_INDX_STR
  199. #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
  200. #endif
  201. // spiffs_printf argument for a data page for given object id
  202. #ifndef SPIFFS_TEST_VIS_DATA_STR
  203. #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
  204. #endif
  205. #endif
  206. // Types depending on configuration such as the amount of flash bytes
  207. // given to spiffs file system in total (spiffs_file_system_size),
  208. // the logical block size (log_block_size), and the logical page size
  209. // (log_page_size)
  210. // Block index type. Make sure the size of this type can hold
  211. // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
  212. typedef u16_t spiffs_block_ix;
  213. // Page index type. Make sure the size of this type can hold
  214. // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
  215. typedef u16_t spiffs_page_ix;
  216. // Object id type - most significant bit is reserved for index flag. Make sure the
  217. // size of this type can hold the highest object id on a full system,
  218. // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
  219. typedef u16_t spiffs_obj_id;
  220. // Object span index type. Make sure the size of this type can
  221. // hold the largest possible span index on the system -
  222. // i.e. (spiffs_file_system_size / log_page_size) - 1
  223. typedef u16_t spiffs_span_ix;
  224. #endif /* SPIFFS_CONFIG_H_ */