Skip to content

Commit 1149cad

Browse files
committed
update to spiffs 0.3.3
1 parent 67edcbc commit 1149cad

File tree

7 files changed

+202
-98
lines changed

7 files changed

+202
-98
lines changed

spiffs/spiffs.h

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Author: petera
66
*/
77

8-
9-
108
#ifndef SPIFFS_H_
119
#define SPIFFS_H_
1210
#if defined(__cplusplus)
@@ -186,6 +184,11 @@ typedef struct {
186184
// logical size of a page, must be at least
187185
// log_block_size / 8
188186
u32_t log_page_size;
187+
188+
#endif
189+
#if SPIFFS_FILEHDL_OFFSET
190+
// an integer offset added to each file handle
191+
u16_t fh_ix_offset;
189192
#endif
190193
} spiffs_config;
191194

@@ -310,7 +313,7 @@ void SPIFFS_unmount(spiffs *fs);
310313
* @param path the path of the new file
311314
* @param mode ignored, for posix compliance
312315
*/
313-
s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode);
316+
s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode);
314317

315318
/**
316319
* Opens/creates a file.
@@ -321,7 +324,7 @@ s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode);
321324
* SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT
322325
* @param mode ignored, for posix compliance
323326
*/
324-
spiffs_file SPIFFS_open(spiffs *fs, char *path, spiffs_flags flags, spiffs_mode mode);
327+
spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode);
325328

326329

327330
/**
@@ -360,13 +363,14 @@ s32_t SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, s32_t len);
360363
s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len);
361364

362365
/**
363-
* Moves the read/write file offset
366+
* Moves the read/write file offset. Resulting offset is returned or negative if error.
367+
* lseek(fs, fd, 0, SPIFFS_SEEK_CUR) will thus return current offset.
364368
* @param fs the file system struct
365369
* @param fh the filehandle
366370
* @param offs how much/where to move the offset
367371
* @param whence if SPIFFS_SEEK_SET, the file offset shall be set to offset bytes
368372
* if SPIFFS_SEEK_CUR, the file offset shall be set to its current location plus offset
369-
* if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offset
373+
* if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offse, which should be negative
370374
*/
371375
s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence);
372376

@@ -375,7 +379,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence);
375379
* @param fs the file system struct
376380
* @param path the path of the file to remove
377381
*/
378-
s32_t SPIFFS_remove(spiffs *fs, char *path);
382+
s32_t SPIFFS_remove(spiffs *fs, const char *path);
379383

380384
/**
381385
* Removes a file by filehandle
@@ -390,7 +394,7 @@ s32_t SPIFFS_fremove(spiffs *fs, spiffs_file fh);
390394
* @param path the path of the file to stat
391395
* @param s the stat struct to populate
392396
*/
393-
s32_t SPIFFS_stat(spiffs *fs, char *path, spiffs_stat *s);
397+
s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s);
394398

395399
/**
396400
* Gets file status by filehandle
@@ -420,7 +424,7 @@ s32_t SPIFFS_close(spiffs *fs, spiffs_file fh);
420424
* @param old path of file to rename
421425
* @param newPath new path of file
422426
*/
423-
s32_t SPIFFS_rename(spiffs *fs, char *old, char *newPath);
427+
s32_t SPIFFS_rename(spiffs *fs, const char *old, const char *newPath);
424428

425429
/**
426430
* Returns last error of last file operation.
@@ -443,7 +447,7 @@ void SPIFFS_clearerr(spiffs *fs);
443447
* @param name the name of the directory
444448
* @param d pointer the directory stream to be populated
445449
*/
446-
spiffs_DIR *SPIFFS_opendir(spiffs *fs, char *name, spiffs_DIR *d);
450+
spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d);
447451

448452
/**
449453
* Closes a directory stream
@@ -544,6 +548,20 @@ s32_t SPIFFS_gc_quick(spiffs *fs, u16_t max_free_pages);
544548
*/
545549
s32_t SPIFFS_gc(spiffs *fs, u32_t size);
546550

551+
/**
552+
* Check if EOF reached.
553+
* @param fs the file system struct
554+
* @param fh the filehandle of the file to check
555+
*/
556+
s32_t SPIFFS_eof(spiffs *fs, spiffs_file fh);
557+
558+
/**
559+
* Get position in file.
560+
* @param fs the file system struct
561+
* @param fh the filehandle of the file to check
562+
*/
563+
s32_t SPIFFS_tell(spiffs *fs, spiffs_file fh);
564+
547565
#if SPIFFS_TEST_VISUALISATION
548566
/**
549567
* Prints out a visualization of the filesystem.

spiffs/spiffs_check.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
440440
}
441441

442442
static s32_t spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block, int cur_entry,
443-
u32_t user_data, void *user_p) {
444-
(void)user_data;
445-
(void)user_p;
443+
const void *user_const_p, void *user_var_p) {
444+
(void)user_const_p;
445+
(void)user_var_p;
446446
s32_t res = SPIFFS_OK;
447447
spiffs_page_header p_hdr;
448448
spiffs_page_ix cur_pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, cur_block, cur_entry);
@@ -873,11 +873,11 @@ static int spiffs_object_index_search(spiffs *fs, spiffs_obj_id obj_id) {
873873
}
874874

875875
static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block,
876-
int cur_entry, u32_t user_data, void *user_p) {
877-
(void)user_data;
876+
int cur_entry, const void *user_const_p, void *user_var_p) {
877+
(void)user_const_p;
878878
s32_t res_c = SPIFFS_VIS_COUNTINUE;
879879
s32_t res = SPIFFS_OK;
880-
u32_t *log_ix = (u32_t *)user_p;
880+
u32_t *log_ix = (u32_t*)user_var_p;
881881
spiffs_obj_id *obj_table = (spiffs_obj_id *)fs->work;
882882

883883
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS,
@@ -977,8 +977,8 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
977977
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
978978
u32_t obj_id_log_ix = 0;
979979
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS, 0, 0);
980-
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, 0, &obj_id_log_ix,
981-
0, 0);
980+
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, &obj_id_log_ix,
981+
0, 0, 0);
982982
if (res == SPIFFS_VIS_END) {
983983
res = SPIFFS_OK;
984984
}

spiffs/spiffs_config.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ typedef uint8_t u8_t;
4141
// compile time switches
4242

4343
// Set generic spiffs debug output call.
44-
#ifndef SPIFFS_DGB
44+
#ifndef SPIFFS_DBG
4545
#define SPIFFS_DBG(...) //printf(__VA_ARGS__)
4646
#endif
4747
// Set spiffs debug output call for garbage collecting.
48-
#ifndef SPIFFS_GC_DGB
48+
#ifndef SPIFFS_GC_DBG
4949
#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
5050
#endif
5151
// Set spiffs debug output call for caching.
52-
#ifndef SPIFFS_CACHE_DGB
52+
#ifndef SPIFFS_CACHE_DBG
5353
#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
5454
#endif
5555
// Set spiffs debug output call for system consistency checks.
56-
#ifndef SPIFFS_CHECK_DGB
56+
#ifndef SPIFFS_CHECK_DBG
5757
#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
5858
#endif
5959

@@ -142,11 +142,11 @@ typedef uint8_t u8_t;
142142
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
143143
// These should be defined on a multithreaded system
144144

145-
// define this to entering a mutex if you're running on a multithreaded system
145+
// define this to enter a mutex if you're running on a multithreaded system
146146
#ifndef SPIFFS_LOCK
147147
#define SPIFFS_LOCK(fs)
148148
#endif
149-
// define this to exiting a mutex if you're running on a multithreaded system
149+
// define this to exit a mutex if you're running on a multithreaded system
150150
#ifndef SPIFFS_UNLOCK
151151
#define SPIFFS_UNLOCK(fs)
152152
#endif
@@ -184,7 +184,22 @@ typedef uint8_t u8_t;
184184
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
185185
#endif
186186

187-
// Set SPFIFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
187+
// Enable this if you want the HAL callbacks to be called with the spiffs struct
188+
#ifndef SPIFFS_HAL_CALLBACK_EXTRA
189+
#define SPIFFS_HAL_CALLBACK_EXTRA 0
190+
#endif
191+
192+
// Enable this if you want to add an integer offset to all file handles
193+
// (spiffs_file). This is useful if running multiple instances of spiffs on
194+
// same target, in order to recognise to what spiffs instance a file handle
195+
// belongs.
196+
// NB: This adds config field fh_ix_offset in the configuration struct when
197+
// mounting, which must be defined.
198+
#ifndef SPIFFS_FILEHDL_OFFSET
199+
#define SPIFFS_FILEHDL_OFFSET 0
200+
#endif
201+
202+
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
188203
// in the api. This function will visualize all filesystem using given printf
189204
// function.
190205
#ifndef SPIFFS_TEST_VISUALISATION

spiffs/spiffs_gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ s32_t spiffs_gc_quick(
3636
int cur_entry = 0;
3737
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
3838

39-
SPIFFS_GC_DBG("gc_quick: running\n", cur_block);
39+
SPIFFS_GC_DBG("gc_quick: running\n");
4040
#if SPIFFS_GC_STATS
4141
fs->stats_gc_runs++;
4242
#endif

0 commit comments

Comments
 (0)