-
spiffs.h@0:1f44439df816, 2021-04-22 (annotated)
- Committer:
- aguscahya
- Date:
- Thu Apr 22 03:49:45 2021 +0000
- Revision:
- 0:1f44439df816
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aguscahya | 0:1f44439df816 | 1 | /* |
aguscahya | 0:1f44439df816 | 2 | * spiffs.h |
aguscahya | 0:1f44439df816 | 3 | * |
aguscahya | 0:1f44439df816 | 4 | * Created on: May 26, 2013 |
aguscahya | 0:1f44439df816 | 5 | * Author: petera |
aguscahya | 0:1f44439df816 | 6 | */ |
aguscahya | 0:1f44439df816 | 7 | |
aguscahya | 0:1f44439df816 | 8 | |
aguscahya | 0:1f44439df816 | 9 | |
aguscahya | 0:1f44439df816 | 10 | #ifndef SPIFFS_H_ |
aguscahya | 0:1f44439df816 | 11 | #define SPIFFS_H_ |
aguscahya | 0:1f44439df816 | 12 | |
aguscahya | 0:1f44439df816 | 13 | #include "spiffs_config.h" |
aguscahya | 0:1f44439df816 | 14 | |
aguscahya | 0:1f44439df816 | 15 | #ifdef __cplusplus |
aguscahya | 0:1f44439df816 | 16 | extern "C" |
aguscahya | 0:1f44439df816 | 17 | { |
aguscahya | 0:1f44439df816 | 18 | #endif |
aguscahya | 0:1f44439df816 | 19 | |
aguscahya | 0:1f44439df816 | 20 | #define SPIFFS_OK 0 |
aguscahya | 0:1f44439df816 | 21 | #define SPIFFS_ERR_NOT_MOUNTED -10000 |
aguscahya | 0:1f44439df816 | 22 | #define SPIFFS_ERR_FULL -10001 |
aguscahya | 0:1f44439df816 | 23 | #define SPIFFS_ERR_NOT_FOUND -10002 |
aguscahya | 0:1f44439df816 | 24 | #define SPIFFS_ERR_END_OF_OBJECT -10003 |
aguscahya | 0:1f44439df816 | 25 | #define SPIFFS_ERR_DELETED -10004 |
aguscahya | 0:1f44439df816 | 26 | #define SPIFFS_ERR_NOT_FINALIZED -10005 |
aguscahya | 0:1f44439df816 | 27 | #define SPIFFS_ERR_NOT_INDEX -10006 |
aguscahya | 0:1f44439df816 | 28 | #define SPIFFS_ERR_OUT_OF_FILE_DESCS -10007 |
aguscahya | 0:1f44439df816 | 29 | #define SPIFFS_ERR_FILE_CLOSED -10008 |
aguscahya | 0:1f44439df816 | 30 | #define SPIFFS_ERR_FILE_DELETED -10009 |
aguscahya | 0:1f44439df816 | 31 | #define SPIFFS_ERR_BAD_DESCRIPTOR -10010 |
aguscahya | 0:1f44439df816 | 32 | #define SPIFFS_ERR_IS_INDEX -10011 |
aguscahya | 0:1f44439df816 | 33 | #define SPIFFS_ERR_IS_FREE -10012 |
aguscahya | 0:1f44439df816 | 34 | #define SPIFFS_ERR_INDEX_SPAN_MISMATCH -10013 |
aguscahya | 0:1f44439df816 | 35 | #define SPIFFS_ERR_DATA_SPAN_MISMATCH -10014 |
aguscahya | 0:1f44439df816 | 36 | #define SPIFFS_ERR_INDEX_REF_FREE -10015 |
aguscahya | 0:1f44439df816 | 37 | #define SPIFFS_ERR_INDEX_REF_LU -10016 |
aguscahya | 0:1f44439df816 | 38 | #define SPIFFS_ERR_INDEX_REF_INVALID -10017 |
aguscahya | 0:1f44439df816 | 39 | #define SPIFFS_ERR_INDEX_FREE -10018 |
aguscahya | 0:1f44439df816 | 40 | #define SPIFFS_ERR_INDEX_LU -10019 |
aguscahya | 0:1f44439df816 | 41 | #define SPIFFS_ERR_INDEX_INVALID -10020 |
aguscahya | 0:1f44439df816 | 42 | #define SPIFFS_ERR_NOT_WRITABLE -10021 |
aguscahya | 0:1f44439df816 | 43 | #define SPIFFS_ERR_NOT_READABLE -10022 |
aguscahya | 0:1f44439df816 | 44 | |
aguscahya | 0:1f44439df816 | 45 | #define SPIFFS_ERR_INTERNAL -10050 |
aguscahya | 0:1f44439df816 | 46 | |
aguscahya | 0:1f44439df816 | 47 | #define SPIFFS_ERR_TEST -10100 |
aguscahya | 0:1f44439df816 | 48 | |
aguscahya | 0:1f44439df816 | 49 | |
aguscahya | 0:1f44439df816 | 50 | // spiffs file descriptor index type. must be signed |
aguscahya | 0:1f44439df816 | 51 | typedef s16_t spiffs_file; |
aguscahya | 0:1f44439df816 | 52 | // spiffs file descriptor flags |
aguscahya | 0:1f44439df816 | 53 | typedef u16_t spiffs_flags; |
aguscahya | 0:1f44439df816 | 54 | // spiffs file mode |
aguscahya | 0:1f44439df816 | 55 | typedef u16_t spiffs_mode; |
aguscahya | 0:1f44439df816 | 56 | // object type |
aguscahya | 0:1f44439df816 | 57 | typedef u8_t spiffs_obj_type; |
aguscahya | 0:1f44439df816 | 58 | |
aguscahya | 0:1f44439df816 | 59 | /* spi read call function type */ |
aguscahya | 0:1f44439df816 | 60 | typedef s32_t (*spiffs_read)(u32_t addr, u32_t size, u8_t *dst); |
aguscahya | 0:1f44439df816 | 61 | /* spi write call function type */ |
aguscahya | 0:1f44439df816 | 62 | typedef s32_t (*spiffs_write)(u32_t addr, u32_t size, u8_t *src); |
aguscahya | 0:1f44439df816 | 63 | /* spi erase call function type */ |
aguscahya | 0:1f44439df816 | 64 | typedef s32_t (*spiffs_erase)(u32_t addr, u32_t size); |
aguscahya | 0:1f44439df816 | 65 | |
aguscahya | 0:1f44439df816 | 66 | /* file system check callback report operation */ |
aguscahya | 0:1f44439df816 | 67 | typedef enum { |
aguscahya | 0:1f44439df816 | 68 | SPIFFS_CHECK_LOOKUP = 0, |
aguscahya | 0:1f44439df816 | 69 | SPIFFS_CHECK_INDEX, |
aguscahya | 0:1f44439df816 | 70 | SPIFFS_CHECK_PAGE |
aguscahya | 0:1f44439df816 | 71 | } spiffs_check_type; |
aguscahya | 0:1f44439df816 | 72 | |
aguscahya | 0:1f44439df816 | 73 | /* file system check callback report type */ |
aguscahya | 0:1f44439df816 | 74 | typedef enum { |
aguscahya | 0:1f44439df816 | 75 | SPIFFS_CHECK_PROGRESS = 0, |
aguscahya | 0:1f44439df816 | 76 | SPIFFS_CHECK_ERROR, |
aguscahya | 0:1f44439df816 | 77 | SPIFFS_CHECK_FIX_INDEX, |
aguscahya | 0:1f44439df816 | 78 | SPIFFS_CHECK_FIX_LOOKUP, |
aguscahya | 0:1f44439df816 | 79 | SPIFFS_CHECK_DELETE_ORPHANED_INDEX, |
aguscahya | 0:1f44439df816 | 80 | SPIFFS_CHECK_DELETE_PAGE, |
aguscahya | 0:1f44439df816 | 81 | SPIFFS_CHECK_DELETE_BAD_FILE, |
aguscahya | 0:1f44439df816 | 82 | } spiffs_check_report; |
aguscahya | 0:1f44439df816 | 83 | |
aguscahya | 0:1f44439df816 | 84 | /* file system check callback function */ |
aguscahya | 0:1f44439df816 | 85 | typedef void (*spiffs_check_callback)(spiffs_check_type type, spiffs_check_report report, |
aguscahya | 0:1f44439df816 | 86 | u32_t arg1, u32_t arg2); |
aguscahya | 0:1f44439df816 | 87 | |
aguscahya | 0:1f44439df816 | 88 | #ifndef SPIFFS_DBG |
aguscahya | 0:1f44439df816 | 89 | #define SPIFFS_DBG(...) \ |
aguscahya | 0:1f44439df816 | 90 | print(__VA_ARGS__) |
aguscahya | 0:1f44439df816 | 91 | #endif |
aguscahya | 0:1f44439df816 | 92 | #ifndef SPIFFS_GC_DBG |
aguscahya | 0:1f44439df816 | 93 | #define SPIFFS_GC_DBG(...) printf(__VA_ARGS__) |
aguscahya | 0:1f44439df816 | 94 | #endif |
aguscahya | 0:1f44439df816 | 95 | #ifndef SPIFFS_CACHE_DBG |
aguscahya | 0:1f44439df816 | 96 | #define SPIFFS_CACHE_DBG(...) printf(__VA_ARGS__) |
aguscahya | 0:1f44439df816 | 97 | #endif |
aguscahya | 0:1f44439df816 | 98 | #ifndef SPIFFS_CHECK_DBG |
aguscahya | 0:1f44439df816 | 99 | #define SPIFFS_CHECK_DBG(...) printf(__VA_ARGS__) |
aguscahya | 0:1f44439df816 | 100 | #endif |
aguscahya | 0:1f44439df816 | 101 | |
aguscahya | 0:1f44439df816 | 102 | /* Any write to the filehandle is appended to end of the file */ |
aguscahya | 0:1f44439df816 | 103 | #define SPIFFS_APPEND (1<<0) |
aguscahya | 0:1f44439df816 | 104 | /* If the opened file exists, it will be truncated to zero length before opened */ |
aguscahya | 0:1f44439df816 | 105 | #define SPIFFS_TRUNC (1<<1) |
aguscahya | 0:1f44439df816 | 106 | /* If the opened file does not exist, it will be created before opened */ |
aguscahya | 0:1f44439df816 | 107 | #define SPIFFS_CREAT (1<<2) |
aguscahya | 0:1f44439df816 | 108 | /* The opened file may only be read */ |
aguscahya | 0:1f44439df816 | 109 | #define SPIFFS_RDONLY (1<<3) |
aguscahya | 0:1f44439df816 | 110 | /* The opened file may only be writted */ |
aguscahya | 0:1f44439df816 | 111 | #define SPIFFS_WRONLY (1<<4) |
aguscahya | 0:1f44439df816 | 112 | /* The opened file may be both read and writted */ |
aguscahya | 0:1f44439df816 | 113 | #define SPIFFS_RDWR (SPIFFS_RDONLY | SPIFFS_WRONLY) |
aguscahya | 0:1f44439df816 | 114 | /* Any writes to the filehandle will never be cached */ |
aguscahya | 0:1f44439df816 | 115 | #define SPIFFS_DIRECT (1<<5) |
aguscahya | 0:1f44439df816 | 116 | |
aguscahya | 0:1f44439df816 | 117 | #define SPIFFS_SEEK_SET (0) |
aguscahya | 0:1f44439df816 | 118 | #define SPIFFS_SEEK_CUR (1) |
aguscahya | 0:1f44439df816 | 119 | #define SPIFFS_SEEK_END (2) |
aguscahya | 0:1f44439df816 | 120 | |
aguscahya | 0:1f44439df816 | 121 | #define SPIFFS_TYPE_FILE (1) |
aguscahya | 0:1f44439df816 | 122 | #define SPIFFS_TYPE_DIR (2) |
aguscahya | 0:1f44439df816 | 123 | #define SPIFFS_TYPE_HARD_LINK (3) |
aguscahya | 0:1f44439df816 | 124 | #define SPIFFS_TYPE_SOFT_LINK (4) |
aguscahya | 0:1f44439df816 | 125 | |
aguscahya | 0:1f44439df816 | 126 | #ifndef SPIFFS_LOCK |
aguscahya | 0:1f44439df816 | 127 | #define SPIFFS_LOCK(fs) |
aguscahya | 0:1f44439df816 | 128 | #endif |
aguscahya | 0:1f44439df816 | 129 | |
aguscahya | 0:1f44439df816 | 130 | #ifndef SPIFFS_UNLOCK |
aguscahya | 0:1f44439df816 | 131 | #define SPIFFS_UNLOCK(fs) |
aguscahya | 0:1f44439df816 | 132 | #endif |
aguscahya | 0:1f44439df816 | 133 | |
aguscahya | 0:1f44439df816 | 134 | // phys structs |
aguscahya | 0:1f44439df816 | 135 | |
aguscahya | 0:1f44439df816 | 136 | // spiffs spi configuration struct |
aguscahya | 0:1f44439df816 | 137 | typedef struct { |
aguscahya | 0:1f44439df816 | 138 | // physical read function |
aguscahya | 0:1f44439df816 | 139 | spiffs_read hal_read_f; |
aguscahya | 0:1f44439df816 | 140 | // physical write function |
aguscahya | 0:1f44439df816 | 141 | spiffs_write hal_write_f; |
aguscahya | 0:1f44439df816 | 142 | // physical erase function |
aguscahya | 0:1f44439df816 | 143 | spiffs_erase hal_erase_f; |
aguscahya | 0:1f44439df816 | 144 | #if SPIFFS_SINGLETON == 0 |
aguscahya | 0:1f44439df816 | 145 | // physical size of the spi flash |
aguscahya | 0:1f44439df816 | 146 | u32_t phys_size; |
aguscahya | 0:1f44439df816 | 147 | // physical offset in spi flash used for spiffs, |
aguscahya | 0:1f44439df816 | 148 | // must be on block boundary |
aguscahya | 0:1f44439df816 | 149 | u32_t phys_addr; |
aguscahya | 0:1f44439df816 | 150 | // physical size when erasing a block |
aguscahya | 0:1f44439df816 | 151 | u32_t phys_erase_block; |
aguscahya | 0:1f44439df816 | 152 | |
aguscahya | 0:1f44439df816 | 153 | // logical size of a block, must be on physical |
aguscahya | 0:1f44439df816 | 154 | // block size boundary and must never be less than |
aguscahya | 0:1f44439df816 | 155 | // a physical block |
aguscahya | 0:1f44439df816 | 156 | u32_t log_block_size; |
aguscahya | 0:1f44439df816 | 157 | // logical size of a page, must be at least |
aguscahya | 0:1f44439df816 | 158 | // log_block_size / 8 |
aguscahya | 0:1f44439df816 | 159 | u32_t log_page_size; |
aguscahya | 0:1f44439df816 | 160 | #endif |
aguscahya | 0:1f44439df816 | 161 | } spiffs_config; |
aguscahya | 0:1f44439df816 | 162 | |
aguscahya | 0:1f44439df816 | 163 | typedef struct { |
aguscahya | 0:1f44439df816 | 164 | // file system configuration |
aguscahya | 0:1f44439df816 | 165 | spiffs_config cfg; |
aguscahya | 0:1f44439df816 | 166 | // number of logical blocks |
aguscahya | 0:1f44439df816 | 167 | u32_t block_count; |
aguscahya | 0:1f44439df816 | 168 | |
aguscahya | 0:1f44439df816 | 169 | // cursor for free blocks, block index |
aguscahya | 0:1f44439df816 | 170 | spiffs_block_ix free_cursor_block_ix; |
aguscahya | 0:1f44439df816 | 171 | // cursor for free blocks, entry index |
aguscahya | 0:1f44439df816 | 172 | int free_cursor_obj_lu_entry; |
aguscahya | 0:1f44439df816 | 173 | // cursor when searching, block index |
aguscahya | 0:1f44439df816 | 174 | spiffs_block_ix cursor_block_ix; |
aguscahya | 0:1f44439df816 | 175 | // cursor when searching, entry index |
aguscahya | 0:1f44439df816 | 176 | int cursor_obj_lu_entry; |
aguscahya | 0:1f44439df816 | 177 | |
aguscahya | 0:1f44439df816 | 178 | // primary work buffer, size of a logical page |
aguscahya | 0:1f44439df816 | 179 | u8_t *lu_work; |
aguscahya | 0:1f44439df816 | 180 | // secondary work buffer, size of a logical page |
aguscahya | 0:1f44439df816 | 181 | u8_t *work; |
aguscahya | 0:1f44439df816 | 182 | // file descriptor memory area |
aguscahya | 0:1f44439df816 | 183 | u8_t *fd_space; |
aguscahya | 0:1f44439df816 | 184 | // available file descriptors |
aguscahya | 0:1f44439df816 | 185 | u32_t fd_count; |
aguscahya | 0:1f44439df816 | 186 | |
aguscahya | 0:1f44439df816 | 187 | // last error |
aguscahya | 0:1f44439df816 | 188 | s32_t errno; |
aguscahya | 0:1f44439df816 | 189 | |
aguscahya | 0:1f44439df816 | 190 | // current number of free blocks |
aguscahya | 0:1f44439df816 | 191 | u32_t free_blocks; |
aguscahya | 0:1f44439df816 | 192 | // current number of busy pages |
aguscahya | 0:1f44439df816 | 193 | u32_t stats_p_allocated; |
aguscahya | 0:1f44439df816 | 194 | // current number of deleted pages |
aguscahya | 0:1f44439df816 | 195 | u32_t stats_p_deleted; |
aguscahya | 0:1f44439df816 | 196 | // flag indicating that garbage collector is cleaning |
aguscahya | 0:1f44439df816 | 197 | u8_t cleaning; |
aguscahya | 0:1f44439df816 | 198 | // max erase count amongst all blocks |
aguscahya | 0:1f44439df816 | 199 | spiffs_obj_id max_erase_count; |
aguscahya | 0:1f44439df816 | 200 | |
aguscahya | 0:1f44439df816 | 201 | #if SPIFFS_GC_STATS |
aguscahya | 0:1f44439df816 | 202 | u32_t stats_gc_runs; |
aguscahya | 0:1f44439df816 | 203 | #endif |
aguscahya | 0:1f44439df816 | 204 | |
aguscahya | 0:1f44439df816 | 205 | #if SPIFFS_CACHE |
aguscahya | 0:1f44439df816 | 206 | // cache memory |
aguscahya | 0:1f44439df816 | 207 | u8_t *cache; |
aguscahya | 0:1f44439df816 | 208 | // cache size |
aguscahya | 0:1f44439df816 | 209 | u32_t cache_size; |
aguscahya | 0:1f44439df816 | 210 | #if SPIFFS_CACHE_STATS |
aguscahya | 0:1f44439df816 | 211 | u32_t cache_hits; |
aguscahya | 0:1f44439df816 | 212 | u32_t cache_misses; |
aguscahya | 0:1f44439df816 | 213 | #endif |
aguscahya | 0:1f44439df816 | 214 | #endif |
aguscahya | 0:1f44439df816 | 215 | |
aguscahya | 0:1f44439df816 | 216 | // check callback function |
aguscahya | 0:1f44439df816 | 217 | spiffs_check_callback check_cb_f; |
aguscahya | 0:1f44439df816 | 218 | } spiffs; |
aguscahya | 0:1f44439df816 | 219 | |
aguscahya | 0:1f44439df816 | 220 | /* spiffs file status struct */ |
aguscahya | 0:1f44439df816 | 221 | typedef struct { |
aguscahya | 0:1f44439df816 | 222 | spiffs_obj_id obj_id; |
aguscahya | 0:1f44439df816 | 223 | u32_t size; |
aguscahya | 0:1f44439df816 | 224 | spiffs_obj_type type; |
aguscahya | 0:1f44439df816 | 225 | u8_t name[SPIFFS_OBJ_NAME_LEN]; |
aguscahya | 0:1f44439df816 | 226 | } spiffs_stat; |
aguscahya | 0:1f44439df816 | 227 | |
aguscahya | 0:1f44439df816 | 228 | struct spiffs_dirent { |
aguscahya | 0:1f44439df816 | 229 | spiffs_obj_id obj_id; |
aguscahya | 0:1f44439df816 | 230 | u8_t name[SPIFFS_OBJ_NAME_LEN]; |
aguscahya | 0:1f44439df816 | 231 | spiffs_obj_type type; |
aguscahya | 0:1f44439df816 | 232 | u32_t size; |
aguscahya | 0:1f44439df816 | 233 | }; |
aguscahya | 0:1f44439df816 | 234 | |
aguscahya | 0:1f44439df816 | 235 | typedef struct { |
aguscahya | 0:1f44439df816 | 236 | spiffs *fs; |
aguscahya | 0:1f44439df816 | 237 | spiffs_block_ix block; |
aguscahya | 0:1f44439df816 | 238 | int entry; |
aguscahya | 0:1f44439df816 | 239 | } spiffs_DIR; |
aguscahya | 0:1f44439df816 | 240 | |
aguscahya | 0:1f44439df816 | 241 | // functions |
aguscahya | 0:1f44439df816 | 242 | |
aguscahya | 0:1f44439df816 | 243 | /** |
aguscahya | 0:1f44439df816 | 244 | * Initializes the file system dynamic parameters and mounts the filesystem |
aguscahya | 0:1f44439df816 | 245 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 246 | * @param config the physical and logical configuration of the file system |
aguscahya | 0:1f44439df816 | 247 | * @param work a memory work buffer comprising 2*config->log_page_size |
aguscahya | 0:1f44439df816 | 248 | * bytes used throughout all file system operations |
aguscahya | 0:1f44439df816 | 249 | * @param fd_space memory for file descriptors |
aguscahya | 0:1f44439df816 | 250 | * @param fd_space_size memory size of file descriptors |
aguscahya | 0:1f44439df816 | 251 | * @param cache memory for cache, may be null |
aguscahya | 0:1f44439df816 | 252 | * @param cache_size memory size of cache |
aguscahya | 0:1f44439df816 | 253 | * @param check_cb_f callback function for reporting during consistency checks |
aguscahya | 0:1f44439df816 | 254 | */ |
aguscahya | 0:1f44439df816 | 255 | s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work, |
aguscahya | 0:1f44439df816 | 256 | u8_t *fd_space, u32_t fd_space_size, |
aguscahya | 0:1f44439df816 | 257 | u8_t *cache, u32_t cache_size, |
aguscahya | 0:1f44439df816 | 258 | spiffs_check_callback check_cb_f); |
aguscahya | 0:1f44439df816 | 259 | |
aguscahya | 0:1f44439df816 | 260 | /** |
aguscahya | 0:1f44439df816 | 261 | * Unmounts the file system. All file handles will be flushed of any |
aguscahya | 0:1f44439df816 | 262 | * cached writes and closed. |
aguscahya | 0:1f44439df816 | 263 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 264 | */ |
aguscahya | 0:1f44439df816 | 265 | void SPIFFS_unmount(spiffs *fs); |
aguscahya | 0:1f44439df816 | 266 | |
aguscahya | 0:1f44439df816 | 267 | /** |
aguscahya | 0:1f44439df816 | 268 | * Creates a new file. |
aguscahya | 0:1f44439df816 | 269 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 270 | * @param path the path of the new file |
aguscahya | 0:1f44439df816 | 271 | * @param mode ignored, for posix compliance |
aguscahya | 0:1f44439df816 | 272 | */ |
aguscahya | 0:1f44439df816 | 273 | s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode); |
aguscahya | 0:1f44439df816 | 274 | |
aguscahya | 0:1f44439df816 | 275 | /** |
aguscahya | 0:1f44439df816 | 276 | * Opens/creates a file. |
aguscahya | 0:1f44439df816 | 277 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 278 | * @param path the path of the new file |
aguscahya | 0:1f44439df816 | 279 | * @param flags the flags for the open command, can be combinations of |
aguscahya | 0:1f44439df816 | 280 | * SPIFFS_APPEND, SPIFFS_TRUNC, SPIFFS_CREAT, SPIFFS_RD_ONLY, |
aguscahya | 0:1f44439df816 | 281 | * SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT |
aguscahya | 0:1f44439df816 | 282 | * @param mode ignored, for posix compliance |
aguscahya | 0:1f44439df816 | 283 | */ |
aguscahya | 0:1f44439df816 | 284 | spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode); |
aguscahya | 0:1f44439df816 | 285 | |
aguscahya | 0:1f44439df816 | 286 | /** |
aguscahya | 0:1f44439df816 | 287 | * Reads from given filehandle. |
aguscahya | 0:1f44439df816 | 288 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 289 | * @param fh the filehandle |
aguscahya | 0:1f44439df816 | 290 | * @param buf where to put read data |
aguscahya | 0:1f44439df816 | 291 | * @param len how much to read |
aguscahya | 0:1f44439df816 | 292 | * @returns number of bytes read, or -1 if error |
aguscahya | 0:1f44439df816 | 293 | */ |
aguscahya | 0:1f44439df816 | 294 | s32_t SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, s32_t len); |
aguscahya | 0:1f44439df816 | 295 | |
aguscahya | 0:1f44439df816 | 296 | /** |
aguscahya | 0:1f44439df816 | 297 | * Writes to given filehandle. |
aguscahya | 0:1f44439df816 | 298 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 299 | * @param fh the filehandle |
aguscahya | 0:1f44439df816 | 300 | * @param buf the data to write |
aguscahya | 0:1f44439df816 | 301 | * @param len how much to write |
aguscahya | 0:1f44439df816 | 302 | * @returns number of bytes written, or -1 if error |
aguscahya | 0:1f44439df816 | 303 | */ |
aguscahya | 0:1f44439df816 | 304 | s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len); |
aguscahya | 0:1f44439df816 | 305 | |
aguscahya | 0:1f44439df816 | 306 | /** |
aguscahya | 0:1f44439df816 | 307 | * Moves the read/write file offset |
aguscahya | 0:1f44439df816 | 308 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 309 | * @param fh the filehandle |
aguscahya | 0:1f44439df816 | 310 | * @param offs how much/where to move the offset |
aguscahya | 0:1f44439df816 | 311 | * @param whence if SPIFFS_SEEK_SET, the file offset shall be set to offset bytes |
aguscahya | 0:1f44439df816 | 312 | * if SPIFFS_SEEK_CUR, the file offset shall be set to its current location plus offset |
aguscahya | 0:1f44439df816 | 313 | * if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offset |
aguscahya | 0:1f44439df816 | 314 | */ |
aguscahya | 0:1f44439df816 | 315 | s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence); |
aguscahya | 0:1f44439df816 | 316 | |
aguscahya | 0:1f44439df816 | 317 | /** |
aguscahya | 0:1f44439df816 | 318 | * Removes a file by path |
aguscahya | 0:1f44439df816 | 319 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 320 | * @param path the path of the file to remove |
aguscahya | 0:1f44439df816 | 321 | */ |
aguscahya | 0:1f44439df816 | 322 | s32_t SPIFFS_remove(spiffs *fs, const char *path); |
aguscahya | 0:1f44439df816 | 323 | |
aguscahya | 0:1f44439df816 | 324 | /** |
aguscahya | 0:1f44439df816 | 325 | * Removes a file by filehandle |
aguscahya | 0:1f44439df816 | 326 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 327 | * @param fh the filehandle of the file to remove |
aguscahya | 0:1f44439df816 | 328 | */ |
aguscahya | 0:1f44439df816 | 329 | s32_t SPIFFS_fremove(spiffs *fs, spiffs_file fh); |
aguscahya | 0:1f44439df816 | 330 | |
aguscahya | 0:1f44439df816 | 331 | /** |
aguscahya | 0:1f44439df816 | 332 | * Gets file status by path |
aguscahya | 0:1f44439df816 | 333 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 334 | * @param path the path of the file to stat |
aguscahya | 0:1f44439df816 | 335 | * @param s the stat struct to populate |
aguscahya | 0:1f44439df816 | 336 | */ |
aguscahya | 0:1f44439df816 | 337 | s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s); |
aguscahya | 0:1f44439df816 | 338 | |
aguscahya | 0:1f44439df816 | 339 | /** |
aguscahya | 0:1f44439df816 | 340 | * Gets file status by filehandle |
aguscahya | 0:1f44439df816 | 341 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 342 | * @param fh the filehandle of the file to stat |
aguscahya | 0:1f44439df816 | 343 | * @param s the stat struct to populate |
aguscahya | 0:1f44439df816 | 344 | */ |
aguscahya | 0:1f44439df816 | 345 | s32_t SPIFFS_fstat(spiffs *fs, spiffs_file fh, spiffs_stat *s); |
aguscahya | 0:1f44439df816 | 346 | |
aguscahya | 0:1f44439df816 | 347 | /** |
aguscahya | 0:1f44439df816 | 348 | * Flushes all pending write operations from cache for given file |
aguscahya | 0:1f44439df816 | 349 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 350 | * @param fh the filehandle of the file to flush |
aguscahya | 0:1f44439df816 | 351 | */ |
aguscahya | 0:1f44439df816 | 352 | s32_t SPIFFS_fflush(spiffs *fs, spiffs_file fh); |
aguscahya | 0:1f44439df816 | 353 | |
aguscahya | 0:1f44439df816 | 354 | /** |
aguscahya | 0:1f44439df816 | 355 | * Closes a filehandle. If there are pending write operations, these are finalized before closing. |
aguscahya | 0:1f44439df816 | 356 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 357 | * @param fh the filehandle of the file to close |
aguscahya | 0:1f44439df816 | 358 | */ |
aguscahya | 0:1f44439df816 | 359 | void SPIFFS_close(spiffs *fs, spiffs_file fh); |
aguscahya | 0:1f44439df816 | 360 | |
aguscahya | 0:1f44439df816 | 361 | /** |
aguscahya | 0:1f44439df816 | 362 | * Returns last error of last file operation. |
aguscahya | 0:1f44439df816 | 363 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 364 | */ |
aguscahya | 0:1f44439df816 | 365 | s32_t SPIFFS_errno(spiffs *fs); |
aguscahya | 0:1f44439df816 | 366 | |
aguscahya | 0:1f44439df816 | 367 | /** |
aguscahya | 0:1f44439df816 | 368 | * Opens a directory stream corresponding to the given name. |
aguscahya | 0:1f44439df816 | 369 | * The stream is positioned at the first entry in the directory. |
aguscahya | 0:1f44439df816 | 370 | * On hydrogen builds the name argument is ignored as hydrogen builds always correspond |
aguscahya | 0:1f44439df816 | 371 | * to a flat file structure - no directories. |
aguscahya | 0:1f44439df816 | 372 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 373 | * @param name the name of the directory |
aguscahya | 0:1f44439df816 | 374 | * @param d pointer the directory stream to be populated |
aguscahya | 0:1f44439df816 | 375 | */ |
aguscahya | 0:1f44439df816 | 376 | spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d); |
aguscahya | 0:1f44439df816 | 377 | |
aguscahya | 0:1f44439df816 | 378 | /** |
aguscahya | 0:1f44439df816 | 379 | * Closes a directory stream |
aguscahya | 0:1f44439df816 | 380 | * @param d the directory stream to close |
aguscahya | 0:1f44439df816 | 381 | */ |
aguscahya | 0:1f44439df816 | 382 | s32_t SPIFFS_closedir(spiffs_DIR *d); |
aguscahya | 0:1f44439df816 | 383 | |
aguscahya | 0:1f44439df816 | 384 | /** |
aguscahya | 0:1f44439df816 | 385 | * Reads a directory into given spifs_dirent struct. |
aguscahya | 0:1f44439df816 | 386 | * @param d pointer to the directory stream |
aguscahya | 0:1f44439df816 | 387 | * @param e the dirent struct to be populated |
aguscahya | 0:1f44439df816 | 388 | * @returns null if error or end of stream, else given dirent is returned |
aguscahya | 0:1f44439df816 | 389 | */ |
aguscahya | 0:1f44439df816 | 390 | struct spiffs_dirent *SPIFFS_readdir(spiffs_DIR *d, struct spiffs_dirent *e); |
aguscahya | 0:1f44439df816 | 391 | |
aguscahya | 0:1f44439df816 | 392 | /** |
aguscahya | 0:1f44439df816 | 393 | * Runs a consistency check on given filesystem. |
aguscahya | 0:1f44439df816 | 394 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 395 | */ |
aguscahya | 0:1f44439df816 | 396 | s32_t SPIFFS_check(spiffs *fs); |
aguscahya | 0:1f44439df816 | 397 | |
aguscahya | 0:1f44439df816 | 398 | #if SPIFFS_TEST_VISUALISATION |
aguscahya | 0:1f44439df816 | 399 | /** |
aguscahya | 0:1f44439df816 | 400 | * Prints out a visualization of the filesystem. |
aguscahya | 0:1f44439df816 | 401 | * @param fs the file system struct |
aguscahya | 0:1f44439df816 | 402 | */ |
aguscahya | 0:1f44439df816 | 403 | s32_t SPIFFS_vis(spiffs *fs); |
aguscahya | 0:1f44439df816 | 404 | #endif |
aguscahya | 0:1f44439df816 | 405 | |
aguscahya | 0:1f44439df816 | 406 | #if SPIFFS_BUFFER_HELP |
aguscahya | 0:1f44439df816 | 407 | /** |
aguscahya | 0:1f44439df816 | 408 | * Returns number of bytes needed for the filedescriptor buffer given |
aguscahya | 0:1f44439df816 | 409 | * amount of file descriptors. |
aguscahya | 0:1f44439df816 | 410 | */ |
aguscahya | 0:1f44439df816 | 411 | u32_t SPIFFS_buffer_bytes_for_filedescs(spiffs *fs, u32_t num_descs); |
aguscahya | 0:1f44439df816 | 412 | |
aguscahya | 0:1f44439df816 | 413 | #if SPIFFS_CACHE |
aguscahya | 0:1f44439df816 | 414 | /** |
aguscahya | 0:1f44439df816 | 415 | * Returns number of bytes needed for the cache buffer given |
aguscahya | 0:1f44439df816 | 416 | * amount of cache pages. |
aguscahya | 0:1f44439df816 | 417 | */ |
aguscahya | 0:1f44439df816 | 418 | u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages); |
aguscahya | 0:1f44439df816 | 419 | #endif |
aguscahya | 0:1f44439df816 | 420 | #endif |
aguscahya | 0:1f44439df816 | 421 | |
aguscahya | 0:1f44439df816 | 422 | #if SPIFFS_CHACHE |
aguscahya | 0:1f44439df816 | 423 | #endif |
aguscahya | 0:1f44439df816 | 424 | |
aguscahya | 0:1f44439df816 | 425 | #ifdef __cplusplus |
aguscahya | 0:1f44439df816 | 426 | } |
aguscahya | 0:1f44439df816 | 427 | #endif |
aguscahya | 0:1f44439df816 | 428 | |
aguscahya | 0:1f44439df816 | 429 | #endif /* SPIFFS_H_ */ |