Skip to content

Commit fcfa08d

Browse files
committed
Update SPIFFS to c6e94fd (0.3.5+)
1 parent a14ac2c commit fcfa08d

File tree

9 files changed

+173
-80
lines changed

9 files changed

+173
-80
lines changed

cores/esp8266/spiffs/README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPIFFS (SPI Flash File System)
2-
**V0.3.4**
2+
**V0.3.5**
33

44
Copyright (c) 2013-2016 Peter Andersson (pelleplutt1976 at gmail.com)
55

@@ -37,6 +37,7 @@ What spiffs does not:
3737
- It is not a realtime stack. One write operation might take much longer than another.
3838
- Poor scalability. Spiffs is intended for small memory devices - the normal sizes for SPI flashes. Going beyond ~128MB is probably a bad idea. This is a side effect of the design goal to use as little ram as possible.
3939
- Presently, it does not detect or handle bad blocks.
40+
- One configuration, one binary. There's no generic spiffs binary that handles all types of configurations.
4041

4142

4243
## MORE INFO
@@ -49,6 +50,17 @@ For a generic spi flash driver, see [this](https://github.com/pellepl/spiflash_d
4950

5051
## HISTORY
5152

53+
### 0.3.5
54+
- Fixed a bug in fs check
55+
- API returns actual error codes #84) (thanks @Nails)
56+
- Fix compiler warnings for non-gcc #83 #81 (thanks @Nails)
57+
- Unable to recover from full fs #82 (thanks @rojer)
58+
- Define SPIFFS_O_* flags #80
59+
- Problem with long filenames #79 (thanks @psjg)
60+
- Duplicate file name bug fix #74 (thanks @igrr)
61+
- SPIFFS_eof and SPIFFS_tell return wrong value #72 (thanks @ArtemPisarenko)
62+
- Bunch of testframe updates #77 #78 #86 (thanks @dpreussner, @psjg a.o)
63+
5264
### 0.3.4
5365
- Added user callback file func.
5466
- Fixed a stat bug with obj id.

cores/esp8266/spiffs/spiffs.h

+18-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ extern "C" {
5454
#define SPIFFS_ERR_RO_ABORTED_OPERATION -10033
5555
#define SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS -10034
5656
#define SPIFFS_ERR_PROBE_NOT_A_FS -10035
57+
#define SPIFFS_ERR_NAME_TOO_LONG -10036
58+
5759
#define SPIFFS_ERR_INTERNAL -10050
5860

5961
#define SPIFFS_ERR_TEST -10100
@@ -104,7 +106,7 @@ typedef enum {
104106
SPIFFS_CHECK_FIX_LOOKUP,
105107
SPIFFS_CHECK_DELETE_ORPHANED_INDEX,
106108
SPIFFS_CHECK_DELETE_PAGE,
107-
SPIFFS_CHECK_DELETE_BAD_FILE,
109+
SPIFFS_CHECK_DELETE_BAD_FILE
108110
} spiffs_check_report;
109111

110112
/* file system check callback function */
@@ -123,7 +125,7 @@ typedef enum {
123125
/* the file has been updated or moved to another page */
124126
SPIFFS_CB_UPDATED,
125127
/* the file has been deleted */
126-
SPIFFS_CB_DELETED,
128+
SPIFFS_CB_DELETED
127129
} spiffs_fileop_type;
128130

129131
/* file system listener callback function */
@@ -145,20 +147,28 @@ typedef void (*spiffs_file_callback)(struct spiffs_t *fs, spiffs_fileop_type op,
145147

146148
/* Any write to the filehandle is appended to end of the file */
147149
#define SPIFFS_APPEND (1<<0)
150+
#define SPIFFS_O_APPEND SPIFFS_APPEND
148151
/* If the opened file exists, it will be truncated to zero length before opened */
149152
#define SPIFFS_TRUNC (1<<1)
153+
#define SPIFFS_O_TRUNC SPIFFS_TRUNC
150154
/* If the opened file does not exist, it will be created before opened */
151155
#define SPIFFS_CREAT (1<<2)
156+
#define SPIFFS_O_CREAT SPIFFS_CREAT
152157
/* The opened file may only be read */
153158
#define SPIFFS_RDONLY (1<<3)
154-
/* The opened file may only be writted */
159+
#define SPIFFS_O_RDONLY SPIFFS_RDONLY
160+
/* The opened file may only be written */
155161
#define SPIFFS_WRONLY (1<<4)
156-
/* The opened file may be both read and writted */
162+
#define SPIFFS_O_WRONLY SPIFFS_WRONLY
163+
/* The opened file may be both read and written */
157164
#define SPIFFS_RDWR (SPIFFS_RDONLY | SPIFFS_WRONLY)
158-
/* Any writes to the filehandle will never be cached */
165+
#define SPIFFS_O_RDWR SPIFFS_RDWR
166+
/* Any writes to the filehandle will never be cached but flushed directly */
159167
#define SPIFFS_DIRECT (1<<5)
160-
/* If SPIFFS_CREAT and SPIFFS_EXCL are set, SPIFFS_open() shall fail if the file exists */
168+
#define SPIFFS_O_DIRECT SPIFFS_DIRECT
169+
/* If SPIFFS_O_CREAT and SPIFFS_O_EXCL are set, SPIFFS_open() shall fail if the file exists */
161170
#define SPIFFS_EXCL (1<<6)
171+
#define SPIFFS_O_EXCL SPIFFS_EXCL
162172

163173
#define SPIFFS_SEEK_SET (0)
164174
#define SPIFFS_SEEK_CUR (1)
@@ -375,8 +385,8 @@ s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode);
375385
* @param fs the file system struct
376386
* @param path the path of the new file
377387
* @param flags the flags for the open command, can be combinations of
378-
* SPIFFS_APPEND, SPIFFS_TRUNC, SPIFFS_CREAT, SPIFFS_RD_ONLY,
379-
* SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT
388+
* SPIFFS_O_APPEND, SPIFFS_O_TRUNC, SPIFFS_O_CREAT, SPIFFS_O_RDONLY,
389+
* SPIFFS_O_WRONLY, SPIFFS_O_RDWR, SPIFFS_O_DIRECT, SPIFFS_O_EXCL
380390
* @param mode ignored, for posix compliance
381391
*/
382392
spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode);

cores/esp8266/spiffs/spiffs_cache.c

+24-9
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ s32_t spiffs_phys_rd(
130130
spiffs_cache_page *cp = spiffs_cache_page_get(fs, SPIFFS_PADDR_TO_PAGE(fs, addr));
131131
cache->last_access++;
132132
if (cp) {
133+
// we've already got one, you see
133134
#if SPIFFS_CACHE_STATS
134135
fs->cache_hits++;
135136
#endif
136137
cp->last_access = cache->last_access;
138+
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
139+
memcpy(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
137140
} else {
138141
if ((op & SPIFFS_OP_TYPE_MASK) == SPIFFS_OP_T_OBJ_LU2) {
139142
// for second layer lookup functions, we do not cache in order to prevent shredding
@@ -142,22 +145,34 @@ s32_t spiffs_phys_rd(
142145
#if SPIFFS_CACHE_STATS
143146
fs->cache_misses++;
144147
#endif
148+
// this operation will always free one cache page (unless all already free),
149+
// the result code stems from the write operation of the possibly freed cache page
145150
res = spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0);
151+
146152
cp = spiffs_cache_page_allocate(fs);
147153
if (cp) {
148154
cp->flags = SPIFFS_CACHE_FLAG_WRTHRU;
149155
cp->pix = SPIFFS_PADDR_TO_PAGE(fs, addr);
150-
}
151-
s32_t res2 = SPIFFS_HAL_READ(fs,
152-
addr - SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr),
153-
SPIFFS_CFG_LOG_PAGE_SZ(fs),
154-
spiffs_get_cache_page(fs, cache, cp->ix));
155-
if (res2 != SPIFFS_OK) {
156-
res = res2;
156+
157+
s32_t res2 = SPIFFS_HAL_READ(fs,
158+
addr - SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr),
159+
SPIFFS_CFG_LOG_PAGE_SZ(fs),
160+
spiffs_get_cache_page(fs, cache, cp->ix));
161+
if (res2 != SPIFFS_OK) {
162+
// honor read failure before possible write failure (bad idea?)
163+
res = res2;
164+
}
165+
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
166+
memcpy(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
167+
} else {
168+
// this will never happen, last resort for sake of symmetry
169+
s32_t res2 = SPIFFS_HAL_READ(fs, addr, len, dst);
170+
if (res2 != SPIFFS_OK) {
171+
// honor read failure before possible write failure (bad idea?)
172+
res = res2;
173+
}
157174
}
158175
}
159-
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
160-
memcpy(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
161176
return res;
162177
}
163178

cores/esp8266/spiffs/spiffs_check.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
980980
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
981981
u32_t obj_id_log_ix = 0;
982982
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS, 0, 0);
983-
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, &obj_id_log_ix,
984-
0, 0, 0);
983+
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, 0, &obj_id_log_ix,
984+
0, 0);
985985
if (res == SPIFFS_VIS_END) {
986986
res = SPIFFS_OK;
987987
}

cores/esp8266/spiffs/spiffs_gc.c

-3
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,7 @@ s32_t spiffs_gc_find_candidate(
255255
s32_t *cand_scores = (s32_t *)(fs->work + max_candidates * sizeof(spiffs_block_ix));
256256

257257
// align cand_scores on s32_t boundary
258-
#pragma GCC diagnostic push
259-
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
260258
cand_scores = (s32_t*)(((ptrdiff_t)cand_scores + sizeof(ptrdiff_t) - 1) & ~(sizeof(ptrdiff_t) - 1));
261-
#pragma GCC diagnostic pop
262259

263260
*block_candidates = cand_blocks;
264261

0 commit comments

Comments
 (0)