9
9
10
10
#ifndef SPIFFS_H_
11
11
#define SPIFFS_H_
12
- #ifdef __cplusplus
12
+ #if defined( __cplusplus )
13
13
extern "C" {
14
14
#endif
15
15
@@ -47,6 +47,9 @@ extern "C" {
47
47
#define SPIFFS_ERR_ERASE_FAIL -10027
48
48
#define SPIFFS_ERR_MAGIC_NOT_POSSIBLE -10028
49
49
50
+ #define SPIFFS_ERR_NO_DELETED_BLOCKS -10029
51
+
52
+ #define SPIFFS_ERR_FILE_EXISTS -10030
50
53
51
54
#define SPIFFS_ERR_INTERNAL -10050
52
55
@@ -62,12 +65,25 @@ typedef u16_t spiffs_mode;
62
65
// object type
63
66
typedef u8_t spiffs_obj_type ;
64
67
68
+ #if SPIFFS_HAL_CALLBACK_EXTRA
69
+ struct spiffs_t ;
70
+
71
+ /* spi read call function type */
72
+ typedef s32_t (* spiffs_read )(struct spiffs_t * fs , u32_t addr , u32_t size , u8_t * dst );
73
+ /* spi write call function type */
74
+ typedef s32_t (* spiffs_write )(struct spiffs_t * fs , u32_t addr , u32_t size , u8_t * src );
75
+ /* spi erase call function type */
76
+ typedef s32_t (* spiffs_erase )(struct spiffs_t * fs , u32_t addr , u32_t size );
77
+
78
+ #else // SPIFFS_HAL_CALLBACK_EXTRA
79
+
65
80
/* spi read call function type */
66
81
typedef s32_t (* spiffs_read )(u32_t addr , u32_t size , u8_t * dst );
67
82
/* spi write call function type */
68
83
typedef s32_t (* spiffs_write )(u32_t addr , u32_t size , u8_t * src );
69
84
/* spi erase call function type */
70
85
typedef s32_t (* spiffs_erase )(u32_t addr , u32_t size );
86
+ #endif // SPIFFS_HAL_CALLBACK_EXTRA
71
87
72
88
/* file system check callback report operation */
73
89
typedef enum {
@@ -88,21 +104,26 @@ typedef enum {
88
104
} spiffs_check_report ;
89
105
90
106
/* file system check callback function */
107
+ #if SPIFFS_HAL_CALLBACK_EXTRA
108
+ typedef void (* spiffs_check_callback )(struct spiffs_t * fs , spiffs_check_type type , spiffs_check_report report ,
109
+ u32_t arg1 , u32_t arg2 );
110
+ #else // SPIFFS_HAL_CALLBACK_EXTRA
91
111
typedef void (* spiffs_check_callback )(spiffs_check_type type , spiffs_check_report report ,
92
112
u32_t arg1 , u32_t arg2 );
113
+ #endif // SPIFFS_HAL_CALLBACK_EXTRA
93
114
94
115
#ifndef SPIFFS_DBG
95
116
#define SPIFFS_DBG (...) \
96
117
print(__VA_ARGS__)
97
118
#endif
98
119
#ifndef SPIFFS_GC_DBG
99
- #define SPIFFS_GC_DBG (...) c_printf (__VA_ARGS__)
120
+ #define SPIFFS_GC_DBG (...) printf (__VA_ARGS__)
100
121
#endif
101
122
#ifndef SPIFFS_CACHE_DBG
102
- #define SPIFFS_CACHE_DBG (...) c_printf (__VA_ARGS__)
123
+ #define SPIFFS_CACHE_DBG (...) printf (__VA_ARGS__)
103
124
#endif
104
125
#ifndef SPIFFS_CHECK_DBG
105
- #define SPIFFS_CHECK_DBG (...) c_printf (__VA_ARGS__)
126
+ #define SPIFFS_CHECK_DBG (...) printf (__VA_ARGS__)
106
127
#endif
107
128
108
129
/* Any write to the filehandle is appended to end of the file */
@@ -119,6 +140,8 @@ typedef void (*spiffs_check_callback)(spiffs_check_type type, spiffs_check_repor
119
140
#define SPIFFS_RDWR (SPIFFS_RDONLY | SPIFFS_WRONLY)
120
141
/* Any writes to the filehandle will never be cached */
121
142
#define SPIFFS_DIRECT (1<<5)
143
+ /* If SPIFFS_CREAT and SPIFFS_EXCL are set, SPIFFS_open() shall fail if the file exists */
144
+ #define SPIFFS_EXCL (1<<6)
122
145
123
146
#define SPIFFS_SEEK_SET (0)
124
147
#define SPIFFS_SEEK_CUR (1)
@@ -166,7 +189,7 @@ typedef struct {
166
189
#endif
167
190
} spiffs_config ;
168
191
169
- typedef struct {
192
+ typedef struct spiffs_t {
170
193
// file system configuration
171
194
spiffs_config cfg ;
172
195
// number of logical blocks
@@ -224,6 +247,8 @@ typedef struct {
224
247
225
248
// mounted flag
226
249
u8_t mounted ;
250
+ // user data
251
+ void * user_data ;
227
252
// config magic
228
253
u32_t config_magic ;
229
254
} spiffs ;
@@ -387,7 +412,7 @@ s32_t SPIFFS_fflush(spiffs *fs, spiffs_file fh);
387
412
* @param fs the file system struct
388
413
* @param fh the filehandle of the file to close
389
414
*/
390
- void SPIFFS_close (spiffs * fs , spiffs_file fh );
415
+ s32_t SPIFFS_close (spiffs * fs , spiffs_file fh );
391
416
392
417
/**
393
418
* Renames a file
@@ -440,7 +465,6 @@ struct spiffs_dirent *SPIFFS_readdir(spiffs_DIR *d, struct spiffs_dirent *e);
440
465
*/
441
466
s32_t SPIFFS_check (spiffs * fs );
442
467
443
-
444
468
/**
445
469
* Returns number of total bytes available and number of used bytes.
446
470
* This is an estimation, and depends on if there a many files with little
@@ -465,27 +489,60 @@ s32_t SPIFFS_info(spiffs *fs, u32_t *total, u32_t *used);
465
489
* SPIFFS_format.
466
490
* If SPIFFS_mount fails, SPIFFS_format can be called directly without calling
467
491
* SPIFFS_unmount first.
492
+ *
493
+ * @param fs the file system struct
468
494
*/
469
495
s32_t SPIFFS_format (spiffs * fs );
470
496
471
497
/**
472
498
* Returns nonzero if spiffs is mounted, or zero if unmounted.
499
+ * @param fs the file system struct
473
500
*/
474
501
u8_t SPIFFS_mounted (spiffs * fs );
475
502
476
503
/**
477
- * Check if EOF reached.
478
- * @param fs the file system struct
479
- * @param fh the filehandle of the file to check
504
+ * Tries to find a block where most or all pages are deleted, and erase that
505
+ * block if found. Does not care for wear levelling. Will not move pages
506
+ * around.
507
+ * If parameter max_free_pages are set to 0, only blocks with only deleted
508
+ * pages will be selected.
509
+ *
510
+ * NB: the garbage collector is automatically called when spiffs needs free
511
+ * pages. The reason for this function is to give possibility to do background
512
+ * tidying when user knows the system is idle.
513
+ *
514
+ * Use with care.
515
+ *
516
+ * Setting max_free_pages to anything larger than zero will eventually wear
517
+ * flash more as a block containing free pages can be erased.
518
+ *
519
+ * Will set err_no to SPIFFS_OK if a block was found and erased,
520
+ * SPIFFS_ERR_NO_DELETED_BLOCK if no matching block was found,
521
+ * or other error.
522
+ *
523
+ * @param fs the file system struct
524
+ * @param max_free_pages maximum number allowed free pages in block
480
525
*/
481
- s32_t SPIFFS_eof (spiffs * fs , spiffs_file fh );
526
+ s32_t SPIFFS_gc_quick (spiffs * fs , u16_t max_free_pages );
482
527
483
528
/**
484
- * Get the current position of the data pointer.
529
+ * Will try to make room for given amount of bytes in the filesystem by moving
530
+ * pages and erasing blocks.
531
+ * If it is physically impossible, err_no will be set to SPIFFS_ERR_FULL. If
532
+ * there already is this amount (or more) of free space, SPIFFS_gc will
533
+ * silently return. It is recommended to call SPIFFS_info before invoking
534
+ * this method in order to determine what amount of bytes to give.
535
+ *
536
+ * NB: the garbage collector is automatically called when spiffs needs free
537
+ * pages. The reason for this function is to give possibility to do background
538
+ * tidying when user knows the system is idle.
539
+ *
540
+ * Use with care.
541
+ *
485
542
* @param fs the file system struct
486
- * @param fh the filehandle of the open file
543
+ * @param size amount of bytes that should be freed
487
544
*/
488
- s32_t SPIFFS_tell (spiffs * fs , spiffs_file fh );
545
+ s32_t SPIFFS_gc (spiffs * fs , u32_t size );
489
546
490
547
#if SPIFFS_TEST_VISUALISATION
491
548
/**
@@ -511,8 +568,9 @@ u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages);
511
568
#endif
512
569
#endif
513
570
514
-
515
- #ifdef __cplusplus
571
+ #if SPIFFS_CACHE
572
+ #endif
573
+ #if defined(__cplusplus )
516
574
}
517
575
#endif
518
576
0 commit comments