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