mirror of
https://github.com/pellepl/spiffs.git
synced 2026-07-26 13:39:07 +00:00
fixes #157
This commit is contained in:
@@ -8,14 +8,6 @@
|
||||
#include "spiffs.h"
|
||||
#include "spiffs_nucleus.h"
|
||||
|
||||
#if SPIFFS_FILEHDL_OFFSET
|
||||
#define SPIFFS_FH_OFFS(fs, fh) ((fh) != 0 ? ((fh) + (fs)->cfg.fh_ix_offset) : 0)
|
||||
#define SPIFFS_FH_UNOFFS(fs, fh) ((fh) != 0 ? ((fh) - (fs)->cfg.fh_ix_offset) : 0)
|
||||
#else
|
||||
#define SPIFFS_FH_OFFS(fs, fh) (fh)
|
||||
#define SPIFFS_FH_UNOFFS(fs, fh) (fh)
|
||||
#endif
|
||||
|
||||
#if SPIFFS_CACHE == 1
|
||||
static s32_t spiffs_fflush_cache(spiffs *fs, spiffs_file fh);
|
||||
#endif
|
||||
|
||||
+19
-4
@@ -1048,6 +1048,8 @@ void spiffs_cb_object_event(
|
||||
spiffs_obj_id obj_id = obj_id_raw & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
u32_t i;
|
||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||
SPIFFS_DBG(" CALLBACK %s obj_id:"_SPIPRIid" spix:"_SPIPRIsp" npix:"_SPIPRIpg" nsz:"_SPIPRIi"\n", (const char *[]){"UPD", "NEW", "DEL", "MOV", "HUP","???"}[MIN(ev,5)],
|
||||
obj_id_raw, spix, new_pix, new_size);
|
||||
for (i = 0; i < fs->fd_count; i++) {
|
||||
spiffs_fd *cur_fd = &fds[i];
|
||||
#if SPIFFS_TEMPORAL_FD_CACHE
|
||||
@@ -1057,12 +1059,25 @@ void spiffs_cb_object_event(
|
||||
#endif
|
||||
if (spix == 0) {
|
||||
if (ev != SPIFFS_EV_IX_DEL) {
|
||||
SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid" objix_hdr_pix to "_SPIPRIpg", size:"_SPIPRIi"\n", cur_fd->file_nbr, cur_fd->obj_id, new_pix, new_size);
|
||||
SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid"(fdoffs:"_SPIPRIi" offs:"_SPIPRIi") objix_hdr_pix to "_SPIPRIpg", size:"_SPIPRIi"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, cur_fd->fdoffset, cur_fd->offset, new_pix, new_size);
|
||||
cur_fd->objix_hdr_pix = new_pix;
|
||||
if (new_size != 0) {
|
||||
// update size and offsets for fds to this file
|
||||
cur_fd->size = new_size;
|
||||
u32_t act_new_size = new_size == SPIFFS_UNDEFINED_LEN ? 0 : new_size;
|
||||
if (cur_fd->offset > act_new_size) {
|
||||
cur_fd->offset = act_new_size;
|
||||
}
|
||||
if (cur_fd->fdoffset > act_new_size) {
|
||||
cur_fd->fdoffset = act_new_size;
|
||||
}
|
||||
if (cur_fd->cache_page && cur_fd->cache_page->offset > act_new_size+1) {
|
||||
SPIFFS_CACHE_DBG("CACHE_DROP: file trunced, dropping cache page "_SPIPRIi", no writeback\n", cur_fd->cache_page->ix);
|
||||
spiffs_cache_fd_release(fs, cur_fd->cache_page);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// removing file
|
||||
#if SPIFFS_CACHE_WR
|
||||
if (cur_fd->file_nbr && cur_fd->cache_page) {
|
||||
SPIFFS_CACHE_DBG("CACHE_DROP: file deleted, dropping cache page "_SPIPRIi", no writeback\n", cur_fd->cache_page->ix);
|
||||
@@ -1075,7 +1090,7 @@ void spiffs_cb_object_event(
|
||||
}
|
||||
if (cur_fd->cursor_objix_spix == spix) {
|
||||
if (ev != SPIFFS_EV_IX_DEL) {
|
||||
SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp" objix_pix to "_SPIPRIpg"\n", cur_fd->file_nbr, cur_fd->obj_id, spix, new_pix);
|
||||
SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp" objix_pix to "_SPIPRIpg"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix, new_pix);
|
||||
cur_fd->cursor_objix_pix = new_pix;
|
||||
} else {
|
||||
cur_fd->cursor_objix_pix = 0;
|
||||
@@ -1093,7 +1108,7 @@ void spiffs_cb_object_event(
|
||||
if (cur_fd->file_nbr == 0 ||
|
||||
cur_fd->ix_map == 0 ||
|
||||
(cur_fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG) != obj_id) continue;
|
||||
SPIFFS_DBG(" callback: map ix update fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp"\n", cur_fd->file_nbr, cur_fd->obj_id, spix);
|
||||
SPIFFS_DBG(" callback: map ix update fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix);
|
||||
spiffs_update_ix_map(fs, cur_fd, spix, objix);
|
||||
}
|
||||
}
|
||||
@@ -1170,7 +1185,7 @@ s32_t spiffs_object_open_by_page(
|
||||
|
||||
SPIFFS_VALIDATE_OBJIX(oix_hdr.p_hdr, fd->obj_id, 0);
|
||||
|
||||
SPIFFS_DBG("open: fd "_SPIPRIfd" is obj id "_SPIPRIid"\n", fd->file_nbr, fd->obj_id);
|
||||
SPIFFS_DBG("open: fd "_SPIPRIfd" is obj id "_SPIPRIid"\n", SPIFFS_FH_OFFS(fs, fd->file_nbr), fd->obj_id);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
+10
-1
@@ -242,6 +242,15 @@
|
||||
#define SPIFFS_DATA_SPAN_IX_FOR_OBJ_IX_SPAN_IX(fs, spix) \
|
||||
( (spix) == 0 ? 0 : (SPIFFS_OBJ_HDR_IX_LEN(fs) + (((spix)-1) * SPIFFS_OBJ_IX_LEN(fs))) )
|
||||
|
||||
#if SPIFFS_FILEHDL_OFFSET
|
||||
#define SPIFFS_FH_OFFS(fs, fh) ((fh) != 0 ? ((fh) + (fs)->cfg.fh_ix_offset) : 0)
|
||||
#define SPIFFS_FH_UNOFFS(fs, fh) ((fh) != 0 ? ((fh) - (fs)->cfg.fh_ix_offset) : 0)
|
||||
#else
|
||||
#define SPIFFS_FH_OFFS(fs, fh) (fh)
|
||||
#define SPIFFS_FH_UNOFFS(fs, fh) (fh)
|
||||
#endif
|
||||
|
||||
|
||||
#define SPIFFS_OP_T_OBJ_LU (0<<0)
|
||||
#define SPIFFS_OP_T_OBJ_LU2 (1<<0)
|
||||
#define SPIFFS_OP_T_OBJ_IX (2<<0)
|
||||
@@ -430,7 +439,7 @@ typedef struct {
|
||||
spiffs_span_ix cursor_objix_spix;
|
||||
// current absolute offset
|
||||
u32_t offset;
|
||||
// current file descriptor offset
|
||||
// current file descriptor offset (cached)
|
||||
u32_t fdoffset;
|
||||
// fd flags
|
||||
spiffs_flags flags;
|
||||
|
||||
@@ -1192,10 +1192,10 @@ SUITE_TESTS(bug_tests)
|
||||
ADD_TEST(seek_bug_148)
|
||||
//ADD_TEST(small_free_space)
|
||||
ADD_TEST(lots_of_overwrite)
|
||||
ADD_TEST_NON_DEFAULT(fuzzer_found_1)
|
||||
ADD_TEST_NON_DEFAULT(fuzzer_found_2)
|
||||
ADD_TEST_NON_DEFAULT(fuzzer_found_3)
|
||||
ADD_TEST_NON_DEFAULT(fuzzer_found_4)
|
||||
ADD_TEST(fuzzer_found_1)
|
||||
ADD_TEST(fuzzer_found_2)
|
||||
ADD_TEST(fuzzer_found_3)
|
||||
ADD_TEST(fuzzer_found_4)
|
||||
ADD_TEST_NON_DEFAULT(fuzzer_found_single_1)
|
||||
ADD_TEST_NON_DEFAULT(log_afl_test)
|
||||
ADD_TEST_NON_DEFAULT(afl_test)
|
||||
|
||||
Reference in New Issue
Block a user