15 #if defined(__cplusplus) 19 #include "spiffs_config.h" 22 #define SPIFFS_ERR_NOT_MOUNTED -10000 23 #define SPIFFS_ERR_FULL -10001 24 #define SPIFFS_ERR_NOT_FOUND -10002 25 #define SPIFFS_ERR_END_OF_OBJECT -10003 26 #define SPIFFS_ERR_DELETED -10004 27 #define SPIFFS_ERR_NOT_FINALIZED -10005 28 #define SPIFFS_ERR_NOT_INDEX -10006 29 #define SPIFFS_ERR_OUT_OF_FILE_DESCS -10007 30 #define SPIFFS_ERR_FILE_CLOSED -10008 31 #define SPIFFS_ERR_FILE_DELETED -10009 32 #define SPIFFS_ERR_BAD_DESCRIPTOR -10010 33 #define SPIFFS_ERR_IS_INDEX -10011 34 #define SPIFFS_ERR_IS_FREE -10012 35 #define SPIFFS_ERR_INDEX_SPAN_MISMATCH -10013 36 #define SPIFFS_ERR_DATA_SPAN_MISMATCH -10014 37 #define SPIFFS_ERR_INDEX_REF_FREE -10015 38 #define SPIFFS_ERR_INDEX_REF_LU -10016 39 #define SPIFFS_ERR_INDEX_REF_INVALID -10017 40 #define SPIFFS_ERR_INDEX_FREE -10018 41 #define SPIFFS_ERR_INDEX_LU -10019 42 #define SPIFFS_ERR_INDEX_INVALID -10020 43 #define SPIFFS_ERR_NOT_WRITABLE -10021 44 #define SPIFFS_ERR_NOT_READABLE -10022 45 #define SPIFFS_ERR_CONFLICTING_NAME -10023 46 #define SPIFFS_ERR_NOT_CONFIGURED -10024 48 #define SPIFFS_ERR_NOT_A_FS -10025 49 #define SPIFFS_ERR_MOUNTED -10026 50 #define SPIFFS_ERR_ERASE_FAIL -10027 51 #define SPIFFS_ERR_MAGIC_NOT_POSSIBLE -10028 53 #define SPIFFS_ERR_NO_DELETED_BLOCKS -10029 55 #define SPIFFS_ERR_FILE_EXISTS -10030 57 #define SPIFFS_ERR_NOT_A_FILE -10031 58 #define SPIFFS_ERR_RO_NOT_IMPL -10032 59 #define SPIFFS_ERR_RO_ABORTED_OPERATION -10033 60 #define SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS -10034 61 #define SPIFFS_ERR_PROBE_NOT_A_FS -10035 62 #define SPIFFS_ERR_NAME_TOO_LONG -10036 64 #define SPIFFS_ERR_IX_MAP_UNMAPPED -10037 65 #define SPIFFS_ERR_IX_MAP_MAPPED -10038 66 #define SPIFFS_ERR_IX_MAP_BAD_RANGE -10039 68 #define SPIFFS_ERR_SEEK_BOUNDS -10040 71 #define SPIFFS_ERR_INTERNAL -10050 73 #define SPIFFS_ERR_OUT_OF_MEMORY -10060 75 #define SPIFFS_ERR_TEST -10100 79 typedef s16_t spiffs_file;
81 typedef u16_t spiffs_flags;
83 typedef u16_t spiffs_mode;
85 typedef u8_t spiffs_obj_type;
89 #if SPIFFS_HAL_CALLBACK_EXTRA 92 typedef s32_t (*spiffs_read)(
struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *dst);
94 typedef s32_t (*spiffs_write)(
struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *src);
96 typedef s32_t (*spiffs_erase)(
struct spiffs_t *fs, u32_t addr, u32_t size);
98 #else // SPIFFS_HAL_CALLBACK_EXTRA 101 typedef s32_t (*spiffs_read)(u32_t addr, u32_t size, u8_t *dst);
103 typedef s32_t (*spiffs_write)(u32_t addr, u32_t size, u8_t *src);
105 typedef s32_t (*spiffs_erase)(u32_t addr, u32_t size);
106 #endif // SPIFFS_HAL_CALLBACK_EXTRA 110 SPIFFS_CHECK_LOOKUP = 0,
117 SPIFFS_CHECK_PROGRESS = 0,
119 SPIFFS_CHECK_FIX_INDEX,
120 SPIFFS_CHECK_FIX_LOOKUP,
121 SPIFFS_CHECK_DELETE_ORPHANED_INDEX,
122 SPIFFS_CHECK_DELETE_PAGE,
123 SPIFFS_CHECK_DELETE_BAD_FILE
124 } spiffs_check_report;
127 #if SPIFFS_HAL_CALLBACK_EXTRA 128 typedef void (*spiffs_check_callback)(
struct spiffs_t *fs, spiffs_check_type type, spiffs_check_report report,
129 u32_t arg1, u32_t arg2);
130 #else // SPIFFS_HAL_CALLBACK_EXTRA 131 typedef void (*spiffs_check_callback)(spiffs_check_type type, spiffs_check_report report,
132 u32_t arg1, u32_t arg2);
133 #endif // SPIFFS_HAL_CALLBACK_EXTRA 138 SPIFFS_CB_CREATED = 0,
143 } spiffs_fileop_type;
146 typedef void (*spiffs_file_callback)(
struct spiffs_t *fs, spiffs_fileop_type op, spiffs_obj_id obj_id, spiffs_page_ix pix);
149 #define SPIFFS_DBG(...) \ 152 #ifndef SPIFFS_GC_DBG 153 #define SPIFFS_GC_DBG(...) printf(__VA_ARGS__) 155 #ifndef SPIFFS_CACHE_DBG 156 #define SPIFFS_CACHE_DBG(...) printf(__VA_ARGS__) 158 #ifndef SPIFFS_CHECK_DBG 159 #define SPIFFS_CHECK_DBG(...) printf(__VA_ARGS__) 163 #define SPIFFS_APPEND (1<<0) 164 #define SPIFFS_O_APPEND SPIFFS_APPEND 166 #define SPIFFS_TRUNC (1<<1) 167 #define SPIFFS_O_TRUNC SPIFFS_TRUNC 169 #define SPIFFS_CREAT (1<<2) 170 #define SPIFFS_O_CREAT SPIFFS_CREAT 172 #define SPIFFS_RDONLY (1<<3) 173 #define SPIFFS_O_RDONLY SPIFFS_RDONLY 175 #define SPIFFS_WRONLY (1<<4) 176 #define SPIFFS_O_WRONLY SPIFFS_WRONLY 178 #define SPIFFS_RDWR (SPIFFS_RDONLY | SPIFFS_WRONLY) 179 #define SPIFFS_O_RDWR SPIFFS_RDWR 181 #define SPIFFS_DIRECT (1<<5) 182 #define SPIFFS_O_DIRECT SPIFFS_DIRECT 184 #define SPIFFS_EXCL (1<<6) 185 #define SPIFFS_O_EXCL SPIFFS_EXCL 187 #define SPIFFS_SEEK_SET (0) 188 #define SPIFFS_SEEK_CUR (1) 189 #define SPIFFS_SEEK_END (2) 191 #define SPIFFS_TYPE_FILE (1) 192 #define SPIFFS_TYPE_DIR (2) 193 #define SPIFFS_TYPE_HARD_LINK (3) 194 #define SPIFFS_TYPE_SOFT_LINK (4) 197 #define SPIFFS_LOCK(fs) 200 #ifndef SPIFFS_UNLOCK 201 #define SPIFFS_UNLOCK(fs) 209 spiffs_read hal_read_f;
211 spiffs_write hal_write_f;
213 spiffs_erase hal_erase_f;
214 #if SPIFFS_SINGLETON == 0 221 u32_t phys_erase_block;
226 u32_t log_block_size;
232 #if SPIFFS_FILEHDL_OFFSET 245 spiffs_block_ix free_cursor_block_ix;
247 int free_cursor_obj_lu_entry;
249 spiffs_block_ix cursor_block_ix;
251 int cursor_obj_lu_entry;
268 u32_t stats_p_allocated;
270 u32_t stats_p_deleted;
274 spiffs_obj_id max_erase_count;
285 #if SPIFFS_CACHE_STATS 292 spiffs_check_callback check_cb_f;
294 spiffs_file_callback file_cb_f;
305 spiffs_obj_id obj_id;
307 spiffs_obj_type type;
309 u8_t name[SPIFFS_OBJ_NAME_LEN];
310 #if SPIFFS_OBJ_META_LEN 311 u8_t meta[SPIFFS_OBJ_META_LEN];
316 spiffs_obj_id obj_id;
317 u8_t name[SPIFFS_OBJ_NAME_LEN];
318 spiffs_obj_type type;
321 #if SPIFFS_OBJ_META_LEN 322 u8_t meta[SPIFFS_OBJ_META_LEN];
328 spiffs_block_ix block;
336 spiffs_page_ix *map_buf;
340 spiffs_span_ix start_spix;
342 spiffs_span_ix end_spix;
349 #if SPIFFS_USE_MAGIC && SPIFFS_USE_MAGIC_LENGTH && SPIFFS_SINGLETON==0 381 #endif // SPIFFS_USE_MAGIC && SPIFFS_USE_MAGIC_LENGTH && SPIFFS_SINGLETON==0 399 u8_t *fd_space, u32_t fd_space_size,
400 void *cache, u32_t cache_size,
401 spiffs_check_callback check_cb_f);
408 void SPIFFS_unmount(
spiffs *fs);
415 void SPIFFS_flush(
spiffs *fs);
423 s32_t SPIFFS_creat(
spiffs *fs,
const char *path, spiffs_mode mode);
434 spiffs_file SPIFFS_open(
spiffs *fs,
const char *path, spiffs_flags flags, spiffs_mode mode);
449 spiffs_file SPIFFS_open_by_dirent(
spiffs *fs,
struct spiffs_dirent *e, spiffs_flags flags, spiffs_mode mode);
465 spiffs_file SPIFFS_open_by_page(
spiffs *fs, spiffs_page_ix page_ix, spiffs_flags flags, spiffs_mode mode);
475 s32_t SPIFFS_read(
spiffs *fs, spiffs_file fh,
void *buf, s32_t len);
485 s32_t SPIFFS_write(
spiffs *fs, spiffs_file fh,
void *buf, s32_t len);
497 s32_t SPIFFS_lseek(
spiffs *fs, spiffs_file fh, s32_t offs,
int whence);
504 s32_t SPIFFS_remove(
spiffs *fs,
const char *path);
511 s32_t SPIFFS_fremove(
spiffs *fs, spiffs_file fh);
522 s32_t SPIFFS_truncate(
spiffs *fs,
const char *path, s32_t len);
534 s32_t SPIFFS_ftruncate(
spiffs *fs, spiffs_file fh, s32_t len);
557 s32_t SPIFFS_fflush(
spiffs *fs, spiffs_file fh);
564 s32_t SPIFFS_close(
spiffs *fs, spiffs_file fh);
572 s32_t SPIFFS_rename(
spiffs *fs,
const char *old,
const char *newPath);
574 #if SPIFFS_OBJ_META_LEN 581 s32_t SPIFFS_update_meta(
spiffs *fs,
const char *name,
const void *meta);
589 s32_t SPIFFS_fupdate_meta(
spiffs *fs, spiffs_file fh,
const void *meta);
596 s32_t SPIFFS_errno(
spiffs *fs);
602 void SPIFFS_clearerr(
spiffs *fs);
633 s32_t SPIFFS_check(
spiffs *fs);
647 s32_t SPIFFS_info(
spiffs *fs, u32_t *total, u32_t *used);
662 s32_t SPIFFS_format(
spiffs *fs);
668 u8_t SPIFFS_mounted(
spiffs *fs);
693 s32_t SPIFFS_gc_quick(
spiffs *fs, u16_t max_free_pages);
712 s32_t SPIFFS_gc(
spiffs *fs, u32_t size);
719 s32_t SPIFFS_eof(
spiffs *fs, spiffs_file fh);
726 s32_t SPIFFS_tell(
spiffs *fs, spiffs_file fh);
742 s32_t SPIFFS_set_file_callback_func(
spiffs *fs, spiffs_file_callback cb_func);
774 u32_t offset, u32_t len, spiffs_page_ix *map_buf);
787 s32_t SPIFFS_ix_unmap(
spiffs *fs, spiffs_file fh);
796 s32_t SPIFFS_ix_remap(
spiffs *fs, spiffs_file fh, u32_t offs);
807 s32_t SPIFFS_bytes_to_ix_map_entries(
spiffs *fs, u32_t bytes);
818 s32_t SPIFFS_ix_map_entries_to_bytes(
spiffs *fs, u32_t map_page_ix_entries);
820 #endif // SPIFFS_IX_MAP 823 #if SPIFFS_TEST_VISUALISATION 828 s32_t SPIFFS_vis(
spiffs *fs);
831 #if SPIFFS_BUFFER_HELP 836 u32_t SPIFFS_buffer_bytes_for_filedescs(
spiffs *fs, u32_t num_descs);
843 u32_t SPIFFS_buffer_bytes_for_cache(
spiffs *fs, u32_t num_pages);
849 #if defined(__cplusplus)