fs/spiffs: Various fixes from initial testing. Still lots of issues. Also changes from further review to get better naming consistency and functional partitioning.
This commit is contained in:
parent
c21dfbb93c
commit
9984e209ab
@ -2,6 +2,7 @@ CONFIG_ARCH="sim"
|
||||
CONFIG_ARCH_BOARD="sim"
|
||||
CONFIG_ARCH_BOARD_SIM=y
|
||||
CONFIG_ARCH_SIM=y
|
||||
CONFIG_BOARD_INITIALIZE=y
|
||||
CONFIG_DEBUG_ASSERTIONS=y
|
||||
CONFIG_DEBUG_FEATURES=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
@ -11,6 +12,7 @@ CONFIG_DISABLE_POSIX_TIMERS=y
|
||||
CONFIG_DISABLE_PTHREAD=y
|
||||
CONFIG_DISABLE_SIGNALS=y
|
||||
CONFIG_EXAMPLES_FSTEST=y
|
||||
CONFIG_EXAMPLES_FSTEST_MOUNTPT="/mnt/spiffs"
|
||||
CONFIG_EXPERIMENTAL=y
|
||||
CONFIG_FS_SPIFFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=4096
|
||||
|
@ -181,6 +181,16 @@ int sim_bringup(void)
|
||||
ret);
|
||||
}
|
||||
|
||||
/* Mount the SPIFFS file system */
|
||||
|
||||
ret = mount("/dev/rammtd", "/mnt/spiffs", "spiffs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to mount SPIFFS at /mnt/spiffs: %d\n",
|
||||
ret);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_FS_NXFFS)
|
||||
/* Initialize to provide NXFFS on the MTD interface */
|
||||
|
||||
|
@ -147,12 +147,13 @@ struct spiffs_s
|
||||
FAR uint8_t *work; /* Secondary work buffer, size of a logical page */
|
||||
FAR void *cache; /* Cache memory */
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
off64_t phys_size; /* Physical size of the SPI flash */
|
||||
off64_t media_size; /* Physical size of the SPI flash */
|
||||
#else
|
||||
off_t phys_size; /* Physical size of the SPI flash */
|
||||
off_t media_size; /* Physical size of the SPI flash */
|
||||
#endif
|
||||
int free_entry; /* Cursor for free blocks, entry index */
|
||||
int lu_entry; /* Cursor when searching, entry index */
|
||||
uint32_t total_pages; /* Total number of pages on the media */
|
||||
uint32_t free_blocks; /* Current number of free blocks */
|
||||
uint32_t stats_p_allocated; /* Current number of busy pages */
|
||||
uint32_t stats_p_deleted; /* Current number of deleted pages */
|
||||
@ -164,10 +165,10 @@ struct spiffs_s
|
||||
uint32_t cache_hits; /* Number of cache hits */
|
||||
uint32_t cache_misses; /* Number of cache misses */
|
||||
#endif
|
||||
uint32_t config_magic; /* Config magic */
|
||||
int16_t free_blkndx; /* cursor for free blocks, block index */
|
||||
int16_t free_blkndx; /* Cursor for free blocks, block index */
|
||||
int16_t lu_blkndx; /* Cursor when searching, block index */
|
||||
int16_t max_erase_count; /* Max erase count amongst all blocks */
|
||||
uint8_t pages_per_block; /* Pages per block */
|
||||
};
|
||||
|
||||
/* This structure represents the state of an open file */
|
||||
|
@ -144,7 +144,7 @@ static int spiffs_cache_page_free(FAR struct spiffs_s *fs, int cpndx,
|
||||
cpndx, cp->pgndx);
|
||||
|
||||
ret = spiffs_mtd_write(fs, SPIFFS_PAGE_TO_PADDR(fs, cp->pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), mem);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), mem);
|
||||
}
|
||||
|
||||
if (cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR)
|
||||
@ -460,7 +460,7 @@ ssize_t spiffs_cache_read(FAR struct spiffs_s *fs, uint8_t op, int16_t objid,
|
||||
|
||||
ret = spiffs_mtd_read(fs, addr -
|
||||
SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
spiffs_get_cache_page(fs, cache, cp->cpndx));
|
||||
|
||||
mem = spiffs_get_cache_page(fs, cache, cp->cpndx);
|
||||
|
@ -61,7 +61,7 @@ extern "C"
|
||||
#define SPIFFS_CACHE_FLAG_TYPE_WR (1 << 7)
|
||||
|
||||
#define SPIFFS_CACHE_PAGE_SIZE(fs) \
|
||||
(sizeof(struct spiffs_cache_page_s) + SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
(sizeof(struct spiffs_cache_page_s) + SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
#define spiffs_get_cache(fs) \
|
||||
((FAR struct spiffs_cache_s *)((fs)->cache))
|
||||
|
@ -109,7 +109,7 @@ static int spiffs_check_get_data_pgndx(FAR struct spiffs_s *fs,
|
||||
|
||||
/* Find the object index for the object ID and span index */
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs, objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
ret = spiffs_objlu_find_id_and_span(fs, objid | SPIFFS_OBJID_NDXFLAG,
|
||||
objndx_spndx, 0, objndx_pgndx);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -226,7 +226,7 @@ static int spiffs_check_rewrite_index(FAR struct spiffs_s *fs,
|
||||
int entry;
|
||||
int ret;
|
||||
|
||||
objid |= SPIFFS_OBJ_ID_IX_FLAG;
|
||||
objid |= SPIFFS_OBJID_NDXFLAG;
|
||||
|
||||
/* Find free entry */
|
||||
|
||||
@ -260,7 +260,7 @@ static int spiffs_check_rewrite_index(FAR struct spiffs_s *fs,
|
||||
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -311,7 +311,7 @@ static int spiffs_check_rewrite_index(FAR struct spiffs_s *fs,
|
||||
|
||||
ret = spiffs_cache_write(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT, 0,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, free_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_write() failed: %d\n", ret);
|
||||
@ -436,9 +436,9 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
|
||||
/* Check validity, take actions */
|
||||
|
||||
if (((lu_objid == SPIFFS_OBJ_ID_DELETED) &&
|
||||
if (((lu_objid == SPIFFS_OBJID_DELETED) &&
|
||||
(pghdr->flags & SPIFFS_PH_FLAG_DELET)) ||
|
||||
((lu_objid == SPIFFS_OBJ_ID_FREE) &&
|
||||
((lu_objid == SPIFFS_OBJID_FREE) &&
|
||||
(pghdr->flags & SPIFFS_PH_FLAG_USED) == 0))
|
||||
{
|
||||
/* Look up entry deleted / free but used in page header */
|
||||
@ -532,7 +532,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
pghdr->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
pghdr->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
pghdr->spndx, cur_pgndx, 0);
|
||||
if (ret == -ENOENT)
|
||||
{
|
||||
@ -541,7 +541,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span_byphdr(fs,
|
||||
pghdr->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
pghdr->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
0, 0, 0);
|
||||
if (ret == OK)
|
||||
{
|
||||
@ -574,12 +574,12 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
}
|
||||
}
|
||||
|
||||
if (lu_objid != SPIFFS_OBJ_ID_FREE && lu_objid != SPIFFS_OBJ_ID_DELETED)
|
||||
if (lu_objid != SPIFFS_OBJID_FREE && lu_objid != SPIFFS_OBJID_DELETED)
|
||||
{
|
||||
/* look up entry used */
|
||||
|
||||
if ((pghdr->objid | SPIFFS_OBJ_ID_IX_FLAG) !=
|
||||
(lu_objid | SPIFFS_OBJ_ID_IX_FLAG))
|
||||
if ((pghdr->objid | SPIFFS_OBJID_NDXFLAG) !=
|
||||
(lu_objid | SPIFFS_OBJID_NDXFLAG))
|
||||
{
|
||||
spiffs_checkinfo("LU: pgndx %04x differ in objid lu="
|
||||
"%04x ph:%04x\n", cur_pgndx, lu_objid,
|
||||
@ -676,7 +676,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
lu_objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
lu_objid | SPIFFS_OBJID_NDXFLAG,
|
||||
pghdr->spndx, 0,
|
||||
&objndx_pgndx_lu);
|
||||
if (ret == -ENOENT)
|
||||
@ -695,7 +695,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
pghdr->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
pghdr->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
pghdr->spndx, 0,
|
||||
&objndx_pgndx_ph);
|
||||
if (ret == -ENOENT)
|
||||
@ -725,7 +725,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
lu_objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
lu_objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
0, 0, &data_pgndx_lu);
|
||||
if (ret == -ENOENT)
|
||||
{
|
||||
@ -743,7 +743,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
pghdr->objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
pghdr->objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
0, 0, &data_pgndx_ph);
|
||||
if (ret == -ENOENT)
|
||||
{
|
||||
@ -767,7 +767,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* Got a data page for page header objid rewrite as objid_ph */
|
||||
|
||||
new_ph.objid = pghdr->objid | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
new_ph.objid = pghdr->objid | SPIFFS_OBJID_NDXFLAG;
|
||||
ret = spiffs_check_rewrite_page(fs, cur_pgndx, &new_ph, &new_pgndx);
|
||||
|
||||
spiffs_checkinfo("Rewrite page %04x as %04x to pgndx %04x\n",
|
||||
@ -788,7 +788,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* Got a data page for look up objid rewrite as objid_lu */
|
||||
|
||||
new_ph.objid = lu_objid | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
new_ph.objid = lu_objid | SPIFFS_OBJID_NDXFLAG;
|
||||
|
||||
spiffs_checkinfo("Rewrite page %04x as %04x\n",
|
||||
cur_pgndx, new_ph.objid);
|
||||
@ -811,9 +811,9 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (((lu_objid & SPIFFS_OBJ_ID_IX_FLAG) != 0 &&
|
||||
else if (((lu_objid & SPIFFS_OBJID_NDXFLAG) != 0 &&
|
||||
(pghdr->flags & SPIFFS_PH_FLAG_INDEX) != 0) ||
|
||||
((lu_objid & SPIFFS_OBJ_ID_IX_FLAG) == 0 &&
|
||||
((lu_objid & SPIFFS_OBJID_NDXFLAG) == 0 &&
|
||||
(pghdr->flags & SPIFFS_PH_FLAG_INDEX) == 0))
|
||||
{
|
||||
int16_t data_pgndx;
|
||||
@ -824,7 +824,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
/* see if other data page exists for given objid and span index */
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
lu_objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
lu_objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
pghdr->spndx, cur_pgndx, &data_pgndx);
|
||||
if (ret == -ENOENT)
|
||||
{
|
||||
@ -840,7 +840,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
/* See if other object index exists for given objid and span index */
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
lu_objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
lu_objid | SPIFFS_OBJID_NDXFLAG,
|
||||
pghdr->spndx, cur_pgndx,
|
||||
&objndx_pgndx_d);
|
||||
if (ret == -ENOENT)
|
||||
@ -876,7 +876,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
|
||||
new_ph.flags = 0xff & ~(SPIFFS_PH_FLAG_USED | SPIFFS_PH_FLAG_FINAL |
|
||||
SPIFFS_PH_FLAG_INDEX);
|
||||
new_ph.objid = lu_objid | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
new_ph.objid = lu_objid | SPIFFS_OBJID_NDXFLAG;
|
||||
new_ph.spndx = pghdr->spndx;
|
||||
|
||||
ret = spiffs_page_allocate_data(fs, new_ph.objid, &new_ph,
|
||||
@ -891,7 +891,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
sizeof(struct spiffs_page_header_s),
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_pgndx) +
|
||||
sizeof(struct spiffs_page_header_s),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs) -
|
||||
SPIFFS_GEO_PAGE_SIZE(fs) -
|
||||
sizeof(struct spiffs_page_header_s));
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -910,7 +910,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
spiffs_checkinfo("Other index page exists, make this data\n");
|
||||
|
||||
new_ph.flags = 0xff & ~(SPIFFS_PH_FLAG_USED | SPIFFS_PH_FLAG_FINAL);
|
||||
new_ph.objid = lu_objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
new_ph.objid = lu_objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
new_ph.spndx = pghdr->spndx;
|
||||
|
||||
ret = spiffs_page_allocate_data(fs, new_ph.objid, &new_ph,
|
||||
@ -925,7 +925,7 @@ static int spiffs_check_luentry_validate(FAR struct spiffs_s *fs,
|
||||
sizeof(struct spiffs_page_header_s),
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_pgndx) +
|
||||
sizeof(struct spiffs_page_header_s),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs) -
|
||||
SPIFFS_GEO_PAGE_SIZE(fs) -
|
||||
sizeof(struct spiffs_page_header_s));
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -1099,10 +1099,10 @@ static int spifss_check_objndx_search(FAR struct spiffs_s *fs, int16_t objid)
|
||||
FAR int16_t *obj_table = (FAR int16_t *)fs->work;
|
||||
int i;
|
||||
|
||||
objid &= ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t); i++)
|
||||
objid &= ~SPIFFS_OBJID_NDXFLAG;
|
||||
for (i = 0; i < SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t); i++)
|
||||
{
|
||||
if ((obj_table[i] & ~SPIFFS_OBJ_ID_IX_FLAG) == objid)
|
||||
if ((obj_table[i] & ~SPIFFS_OBJID_NDXFLAG) == objid)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@ -1145,8 +1145,8 @@ static int spiffs_check_objidconsistency_callback(FAR struct spiffs_s *fs,
|
||||
int retc = SPIFFS_VIS_COUNTINUE;
|
||||
int ret = OK;
|
||||
|
||||
if (objid != SPIFFS_OBJ_ID_FREE && objid != SPIFFS_OBJ_ID_DELETED &&
|
||||
(objid & SPIFFS_OBJ_ID_IX_FLAG) != 0)
|
||||
if (objid != SPIFFS_OBJID_FREE && objid != SPIFFS_OBJID_DELETED &&
|
||||
(objid & SPIFFS_OBJID_NDXFLAG) != 0)
|
||||
{
|
||||
struct spiffs_page_header_s pghdr;
|
||||
int16_t cur_pgndx;
|
||||
@ -1201,9 +1201,9 @@ static int spiffs_check_objidconsistency_callback(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* Not registered, do it */
|
||||
|
||||
obj_table[*log_ndx] = objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
obj_table[*log_ndx] = objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
(*log_ndx)++;
|
||||
if (*log_ndx >= SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t))
|
||||
if (*log_ndx >= SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t))
|
||||
{
|
||||
*log_ndx = 0;
|
||||
}
|
||||
@ -1225,7 +1225,7 @@ static int spiffs_check_objidconsistency_callback(FAR struct spiffs_s *fs,
|
||||
|
||||
/* Not in temporary index, try finding it */
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs, objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
ret = spiffs_objlu_find_id_and_span(fs, objid | SPIFFS_OBJID_NDXFLAG,
|
||||
0, 0, &objhdr_pgndx);
|
||||
retc = SPIFFS_VIS_COUNTINUE_RELOAD;
|
||||
|
||||
@ -1233,14 +1233,14 @@ static int spiffs_check_objidconsistency_callback(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* Found, register as reachable */
|
||||
|
||||
obj_table[*log_ndx] = objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
obj_table[*log_ndx] = objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
}
|
||||
else if (ret == -ENOENT)
|
||||
{
|
||||
/* Not found, register as unreachable */
|
||||
|
||||
delete = true;
|
||||
obj_table[*log_ndx] = objid | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
obj_table[*log_ndx] = objid | SPIFFS_OBJID_NDXFLAG;
|
||||
}
|
||||
else if (ret < 0)
|
||||
{
|
||||
@ -1249,7 +1249,7 @@ static int spiffs_check_objidconsistency_callback(FAR struct spiffs_s *fs,
|
||||
}
|
||||
|
||||
(*log_ndx)++;
|
||||
if (*log_ndx >= SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t))
|
||||
if (*log_ndx >= SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t))
|
||||
{
|
||||
*log_ndx = 0;
|
||||
}
|
||||
@ -1258,7 +1258,7 @@ static int spiffs_check_objidconsistency_callback(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* In temporary index, check reachable flag */
|
||||
|
||||
if ((obj_table[ret2] & SPIFFS_OBJ_ID_IX_FLAG))
|
||||
if ((obj_table[ret2] & SPIFFS_OBJID_NDXFLAG))
|
||||
{
|
||||
/* Registered as unreachable */
|
||||
|
||||
@ -1353,30 +1353,30 @@ int spiffs_check_luconsistency(FAR struct spiffs_s *fs)
|
||||
int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
{
|
||||
const uint32_t bits = 4;
|
||||
const int16_t pages_per_scan = SPIFFS_CFG_LOG_PAGE_SZ(fs) * 8 / bits;
|
||||
const int16_t pages_per_scan = SPIFFS_GEO_PAGE_SIZE(fs) * 8 / bits;
|
||||
int16_t pgndx_offset = 0;
|
||||
int ret = OK;
|
||||
|
||||
/* For each range of pages fitting into work memory */
|
||||
|
||||
while (pgndx_offset < SPIFFS_PAGES_PER_BLOCK(fs) * fs->geo.neraseblocks)
|
||||
while (pgndx_offset < SPIFFS_GEO_PAGES_PER_BLOCK(fs) * SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
int16_t cur_block = 0;
|
||||
bool restart = false;
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
memset(fs->work, 0, SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
|
||||
/* Build consistency bitmap for ID range traversing all blocks */
|
||||
|
||||
while (!restart && cur_block < fs->geo.neraseblocks)
|
||||
while (!restart && cur_block < SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
/* Traverse each page except for lookup pages */
|
||||
|
||||
int16_t cur_pgndx = SPIFFS_OBJ_LOOKUP_PAGES(fs) +
|
||||
SPIFFS_PAGES_PER_BLOCK(fs) * cur_block;
|
||||
SPIFFS_GEO_PAGES_PER_BLOCK(fs) * cur_block;
|
||||
|
||||
while (!restart &&
|
||||
cur_pgndx < SPIFFS_PAGES_PER_BLOCK(fs) * (cur_block + 1))
|
||||
cur_pgndx < SPIFFS_GEO_PAGES_PER_BLOCK(fs) * (cur_block + 1))
|
||||
{
|
||||
struct spiffs_page_header_s pghdr;
|
||||
uint32_t pgndx_bytendx;
|
||||
@ -1429,7 +1429,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -1473,7 +1473,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
rpgndx < pgndx_offset + pages_per_scan);
|
||||
|
||||
if ((rpgndx != (int16_t) - 1 &&
|
||||
rpgndx > SPIFFS_MAX_PAGES(fs)) ||
|
||||
rpgndx > SPIFFS_GEO_PAGE_COUNT(fs)) ||
|
||||
(rpgndx_within_range && SPIFFS_IS_LOOKUP_PAGE(fs, rpgndx)))
|
||||
{
|
||||
int16_t data_pgndx;
|
||||
@ -1487,7 +1487,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
objndx_phdr->objid &
|
||||
~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
~SPIFFS_OBJID_NDXFLAG,
|
||||
data_spndx_offset + i,
|
||||
0, &data_pgndx);
|
||||
if (ret == -ENOENT)
|
||||
@ -1510,7 +1510,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
|
||||
new_ph.flags = 0xff & ~(SPIFFS_PH_FLAG_USED |
|
||||
SPIFFS_PH_FLAG_FINAL);
|
||||
new_ph.objid = objndx_phdr->objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
new_ph.objid = objndx_phdr->objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
new_ph.spndx = data_spndx_offset + i;
|
||||
|
||||
ret = spiffs_page_allocate_data(fs, new_ph.objid,
|
||||
@ -1531,7 +1531,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
spiffs_checkinfo("Rewriting index pgndx=%04x\n", cur_pgndx);
|
||||
|
||||
ret = spiffs_check_rewrite_index(fs,
|
||||
objndx_phdr->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
objndx_phdr->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
data_spndx_offset + i,
|
||||
data_pgndx, cur_pgndx);
|
||||
if (ret == -EFAULT)
|
||||
@ -1576,7 +1576,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
|
||||
/* Cross reference page header check */
|
||||
|
||||
if (rphdr.objid != (pghdr.objid & ~SPIFFS_OBJ_ID_IX_FLAG) ||
|
||||
if (rphdr.objid != (pghdr.objid & ~SPIFFS_OBJID_NDXFLAG) ||
|
||||
rphdr.spndx != data_spndx_offset + i ||
|
||||
(rphdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_INDEX |
|
||||
SPIFFS_PH_FLAG_USED)) !=
|
||||
@ -1587,7 +1587,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
spiffs_checkinfo("pgndx=%04x has inconsistent page header index objid/span:"
|
||||
"%04x/%04x, ref objid/span:%04x/%04x flags=%02x\n",
|
||||
rpgndx,
|
||||
pghdr.objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
pghdr.objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
data_spndx_offset + i,
|
||||
rphdr.objid, rphdr.spndx,
|
||||
rphdr.flags);
|
||||
@ -1596,7 +1596,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
pghdr.objid &
|
||||
~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
~SPIFFS_OBJID_NDXFLAG,
|
||||
data_spndx_offset + i, rpgndx,
|
||||
&data_pgndx);
|
||||
if (ret == -ENOENT)
|
||||
@ -1726,7 +1726,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
uint8_t bit_ndx;
|
||||
|
||||
for (byte_ndx = 0;
|
||||
!restart && byte_ndx < SPIFFS_CFG_LOG_PAGE_SZ(fs);
|
||||
!restart && byte_ndx < SPIFFS_GEO_PAGE_SIZE(fs);
|
||||
byte_ndx++)
|
||||
{
|
||||
for (bit_ndx = 0; !restart && bit_ndx < 8 / bits; bit_ndx++)
|
||||
@ -1770,7 +1770,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
if (ret == OK)
|
||||
{
|
||||
if (((rpgndx == (int16_t) - 1 ||
|
||||
rpgndx > SPIFFS_MAX_PAGES(fs)) ||
|
||||
rpgndx > SPIFFS_GEO_PAGE_COUNT(fs)) ||
|
||||
(SPIFFS_IS_LOOKUP_PAGE(fs, rpgndx))))
|
||||
{
|
||||
/* Pointing to a bad page altogether, rewrite
|
||||
@ -1801,7 +1801,7 @@ int spiffs_check_pgconsistency(FAR struct spiffs_s *fs)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (((pghdr.objid & ~SPIFFS_OBJ_ID_IX_FLAG) ==
|
||||
if (((pghdr.objid & ~SPIFFS_OBJID_NDXFLAG) ==
|
||||
rphdr.objid) &&
|
||||
((rphdr.flags & (SPIFFS_PH_FLAG_INDEX |
|
||||
SPIFFS_PH_FLAG_DELET |
|
||||
@ -2011,11 +2011,11 @@ int spiffs_check_objidconsistency(FAR struct spiffs_s *fs)
|
||||
* fs->work is used for a temporary object index memory, listing found
|
||||
* object ids and indicating whether they can be reached or not. Acting
|
||||
* as a FIFO if object ids cannot fit. In the temporary object index
|
||||
* memory, SPIFFS_OBJ_ID_IX_FLAG bit is used to indicate a reachable/
|
||||
* memory, SPIFFS_OBJID_NDXFLAG bit is used to indicate a reachable/
|
||||
* unreachable object ID.
|
||||
*/
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
memset(fs->work, 0, SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
|
||||
ret = spiffs_foreach_objlu(fs, 0, 0, 0, 0,
|
||||
spiffs_check_objidconsistency_callback, 0,
|
||||
|
@ -94,14 +94,14 @@ static int spiffs_page_data_check(FAR struct spiffs_s *fs,
|
||||
return SPIFFS_ERR_INDEX_REF_FREE;
|
||||
}
|
||||
|
||||
if (pgndx % SPIFFS_PAGES_PER_BLOCK(fs) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
if (pgndx % SPIFFS_GEO_PAGES_PER_BLOCK(fs) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
{
|
||||
/* Referring to an object lookup page, bad object index */
|
||||
|
||||
return SPIFFS_ERR_INDEX_REF_LU;
|
||||
}
|
||||
|
||||
if (pgndx > SPIFFS_MAX_PAGES(fs))
|
||||
if (pgndx > SPIFFS_GEO_PAGE_COUNT(fs))
|
||||
{
|
||||
/* Referring to a bad page */
|
||||
|
||||
@ -165,14 +165,14 @@ static int spiffs_page_index_check(FAR struct spiffs_s *fs,
|
||||
return SPIFFS_ERR_INDEX_FREE;
|
||||
}
|
||||
|
||||
if (pgndx % SPIFFS_PAGES_PER_BLOCK(fs) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
if (pgndx % SPIFFS_GEO_PAGES_PER_BLOCK(fs) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
{
|
||||
/* Referring to an object lookup page, bad object index */
|
||||
|
||||
return SPIFFS_ERR_INDEX_LU;
|
||||
}
|
||||
|
||||
if (pgndx > SPIFFS_MAX_PAGES(fs))
|
||||
if (pgndx > SPIFFS_GEO_PAGE_COUNT(fs))
|
||||
{
|
||||
/* Referring to a bad page */
|
||||
|
||||
@ -212,7 +212,7 @@ static int spiffs_objlu_scan_callback(FAR struct spiffs_s *fs, int16_t objid,
|
||||
FAR const void *user_const,
|
||||
FAR void *user_var)
|
||||
{
|
||||
if (objid == SPIFFS_OBJ_ID_FREE)
|
||||
if (objid == SPIFFS_OBJID_FREE)
|
||||
{
|
||||
if (entry == 0)
|
||||
{
|
||||
@ -221,7 +221,7 @@ static int spiffs_objlu_scan_callback(FAR struct spiffs_s *fs, int16_t objid,
|
||||
fs->free_blocks++;
|
||||
}
|
||||
}
|
||||
else if (objid == SPIFFS_OBJ_ID_DELETED)
|
||||
else if (objid == SPIFFS_OBJID_DELETED)
|
||||
{
|
||||
fs->stats_p_deleted++;
|
||||
}
|
||||
@ -264,7 +264,7 @@ static int spiffs_objlu_find_id_and_span_callback(FAR struct spiffs_s *fs,
|
||||
if (ph.objid == objid && ph.spndx == *((FAR int16_t *)user_var) &&
|
||||
(ph.flags & (SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_DELET |
|
||||
SPIFFS_PH_FLAG_USED)) == SPIFFS_PH_FLAG_DELET &&
|
||||
!((objid & SPIFFS_OBJ_ID_IX_FLAG) != 0 &&
|
||||
!((objid & SPIFFS_OBJID_NDXFLAG) != 0 &&
|
||||
(ph.flags & SPIFFS_PH_FLAG_IXDELE) == 0 && ph.spndx == 0) &&
|
||||
(user_const == NULL || *((FAR const int16_t *)user_const) != pgndx))
|
||||
{
|
||||
@ -292,8 +292,8 @@ static int spiffs_find_objhdr_pgndx_callback(FAR struct spiffs_s *fs, int16_t ob
|
||||
int16_t pgndx;
|
||||
int ret;
|
||||
|
||||
if (objid == SPIFFS_OBJ_ID_FREE || objid == SPIFFS_OBJ_ID_DELETED ||
|
||||
(objid & SPIFFS_OBJ_ID_IX_FLAG) == 0)
|
||||
if (objid == SPIFFS_OBJID_FREE || objid == SPIFFS_OBJID_DELETED ||
|
||||
(objid & SPIFFS_OBJID_NDXFLAG) == 0)
|
||||
{
|
||||
return SPIFFS_VIS_COUNTINUE;
|
||||
}
|
||||
@ -338,7 +338,7 @@ static int
|
||||
FAR const void *user_const,
|
||||
FAR void *user_var)
|
||||
{
|
||||
if (objid != SPIFFS_OBJ_ID_FREE && objid != SPIFFS_OBJ_ID_DELETED)
|
||||
if (objid != SPIFFS_OBJID_FREE && objid != SPIFFS_OBJID_DELETED)
|
||||
{
|
||||
int16_t min_objid = *((FAR int16_t *)user_var);
|
||||
FAR const uint8_t *conflicting_name = (FAR const uint8_t *)user_const;
|
||||
@ -349,7 +349,7 @@ static int
|
||||
* found in object index headers
|
||||
*/
|
||||
|
||||
if (conflicting_name != NULL && (objid & SPIFFS_OBJ_ID_IX_FLAG) != 0)
|
||||
if (conflicting_name != NULL && (objid & SPIFFS_OBJID_NDXFLAG) != 0)
|
||||
{
|
||||
struct spiffs_pgobj_ndxheader_s objhdr;
|
||||
int16_t pgndx = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, blkndx, entry);
|
||||
@ -379,11 +379,11 @@ static int
|
||||
}
|
||||
}
|
||||
|
||||
objid &= ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
objid &= ~SPIFFS_OBJID_NDXFLAG;
|
||||
bitndx = (objid - min_objid) & 7;
|
||||
bytendx = (objid - min_objid) >> 3;
|
||||
|
||||
if (bytendx >= 0 && (uint32_t)bytendx < SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
if (bytendx >= 0 && (uint32_t)bytendx < SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
{
|
||||
fs->work[bytendx] |= (1 << bitndx);
|
||||
}
|
||||
@ -406,8 +406,8 @@ spiffs_objlu_find_free_objid_compact_callback(FAR struct spiffs_s *fs,
|
||||
FAR const void *user_const,
|
||||
FAR void *user_var)
|
||||
{
|
||||
if (objid != SPIFFS_OBJ_ID_FREE && objid != SPIFFS_OBJ_ID_DELETED &&
|
||||
(objid & SPIFFS_OBJ_ID_IX_FLAG) != 0)
|
||||
if (objid != SPIFFS_OBJID_FREE && objid != SPIFFS_OBJID_DELETED &&
|
||||
(objid & SPIFFS_OBJID_NDXFLAG) != 0)
|
||||
{
|
||||
FAR const struct spiffs_free_objid_s *state =
|
||||
(FAR const struct spiffs_free_objid_s *)user_const;
|
||||
@ -433,7 +433,7 @@ spiffs_objlu_find_free_objid_compact_callback(FAR struct spiffs_s *fs,
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
objid &= ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
objid &= ~SPIFFS_OBJID_NDXFLAG;
|
||||
if (objid >= state->min_objid && objid <= state->max_objid)
|
||||
{
|
||||
FAR uint8_t *map = (FAR uint8_t *)fs->work;
|
||||
@ -480,7 +480,7 @@ int spiffs_validate_objix(FAR struct spiffs_page_header_s *ph, int16_t objid,
|
||||
{
|
||||
ret = SPIFFS_ERR_NOT_INDEX;
|
||||
}
|
||||
else if ((objid & SPIFFS_OBJ_ID_IX_FLAG) == 0)
|
||||
else if ((objid & SPIFFS_OBJID_NDXFLAG) == 0)
|
||||
{
|
||||
ret = SPIFFS_ERR_NOT_INDEX;
|
||||
}
|
||||
@ -581,12 +581,12 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
int entries_per_page;
|
||||
int ret;
|
||||
|
||||
entry_count = fs->geo.neraseblocks * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs);
|
||||
entry_count = SPIFFS_GEO_BLOCK_COUNT(fs) * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs);
|
||||
cur_block = starting_block;
|
||||
cur_block_addr = starting_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||
cur_block_addr = starting_block * SPIFFS_GEO_BLOCK_SIZE(fs);
|
||||
objlu_buf = (FAR int16_t *) fs->lu_work;
|
||||
cur_entry = starting_lu_entry;
|
||||
entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t));
|
||||
entries_per_page = (SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t));
|
||||
ret = OK;
|
||||
|
||||
/* Wrap initial */
|
||||
@ -595,9 +595,9 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
{
|
||||
cur_entry = 0;
|
||||
cur_block++;
|
||||
cur_block_addr = cur_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||
cur_block_addr = cur_block * SPIFFS_GEO_BLOCK_SIZE(fs);
|
||||
|
||||
if (cur_block >= fs->geo.neraseblocks)
|
||||
if (cur_block >= SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
if (flags & SPIFFS_VIS_NO_WRAP)
|
||||
{
|
||||
@ -628,7 +628,7 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||
0, cur_block_addr +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
|
||||
/* Check each entry */
|
||||
|
||||
@ -666,7 +666,7 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
SPIFFS_OP_C_READ, 0,
|
||||
cur_block_addr +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
fs->lu_work);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -701,9 +701,9 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
|
||||
cur_entry = 0;
|
||||
cur_block++;
|
||||
cur_block_addr += SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||
cur_block_addr += SPIFFS_GEO_BLOCK_SIZE(fs);
|
||||
|
||||
if (cur_block >= fs->geo.neraseblocks)
|
||||
if (cur_block >= SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
if (flags & SPIFFS_VIS_NO_WRAP)
|
||||
{
|
||||
@ -737,7 +737,7 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
int spiffs_erase_block(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
{
|
||||
uint32_t addr = SPIFFS_BLOCK_TO_PADDR(fs, blkndx);
|
||||
int32_t size = SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||
int32_t size = SPIFFS_GEO_BLOCK_SIZE(fs);
|
||||
int ret;
|
||||
|
||||
/* Here we ignore the return value and just try erasing the block */
|
||||
@ -745,12 +745,12 @@ int spiffs_erase_block(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
while (size > 0)
|
||||
{
|
||||
finfo("erase %08lx:%d\n",
|
||||
(unsigned long)addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
|
||||
(unsigned long)addr, SPIFFS_GEO_EBLOCK_SIZE(fs));
|
||||
|
||||
(void)spiffs_mtd_erase(fs, addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
|
||||
(void)spiffs_mtd_erase(fs, addr, SPIFFS_GEO_EBLOCK_SIZE(fs));
|
||||
|
||||
addr += SPIFFS_CFG_PHYS_ERASE_SZ(fs);
|
||||
size -= SPIFFS_CFG_PHYS_ERASE_SZ(fs);
|
||||
addr += SPIFFS_GEO_EBLOCK_SIZE(fs);
|
||||
size -= SPIFFS_GEO_EBLOCK_SIZE(fs);
|
||||
}
|
||||
|
||||
fs->free_blocks++;
|
||||
@ -768,7 +768,7 @@ int spiffs_erase_block(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
}
|
||||
|
||||
fs->max_erase_count++;
|
||||
if (fs->max_erase_count == SPIFFS_OBJ_ID_IX_FLAG)
|
||||
if (fs->max_erase_count == SPIFFS_OBJID_NDXFLAG)
|
||||
{
|
||||
fs->max_erase_count = 0;
|
||||
}
|
||||
@ -797,12 +797,13 @@ int spiffs_objlu_scan(FAR struct spiffs_s *fs)
|
||||
/* Find out erase count. */
|
||||
|
||||
blkndx = 0;
|
||||
erase_count_min = SPIFFS_OBJ_ID_FREE;
|
||||
erase_count_min = SPIFFS_OBJID_FREE;
|
||||
erase_count_max = 0;
|
||||
|
||||
while (blkndx < fs->geo.neraseblocks)
|
||||
while (blkndx < SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
int16_t erase_count;
|
||||
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_ERASE_COUNT_PADDR(fs, blkndx),
|
||||
sizeof(int16_t), (FAR uint8_t *)&erase_count);
|
||||
@ -812,7 +813,7 @@ int spiffs_objlu_scan(FAR struct spiffs_s *fs)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (erase_count != SPIFFS_OBJ_ID_FREE)
|
||||
if (erase_count != SPIFFS_OBJID_FREE)
|
||||
{
|
||||
erase_count_min = MIN(erase_count_min, erase_count);
|
||||
erase_count_max = MAX(erase_count_max, erase_count);
|
||||
@ -821,13 +822,13 @@ int spiffs_objlu_scan(FAR struct spiffs_s *fs)
|
||||
blkndx++;
|
||||
}
|
||||
|
||||
if (erase_count_min == 0 && erase_count_max == SPIFFS_OBJ_ID_FREE)
|
||||
if (erase_count_min == 0 && erase_count_max == SPIFFS_OBJID_FREE)
|
||||
{
|
||||
/* Clean system, set counter to zero */
|
||||
|
||||
erase_count_final = 0;
|
||||
}
|
||||
else if (erase_count_max - erase_count_min > (SPIFFS_OBJ_ID_FREE) / 2)
|
||||
else if (erase_count_max - erase_count_min > (SPIFFS_OBJID_FREE / 2))
|
||||
{
|
||||
/* Wrap, take min */
|
||||
|
||||
@ -898,7 +899,7 @@ int spiffs_objlu_find_free(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
}
|
||||
|
||||
ret = spiffs_objlu_find_id(fs, starting_block, starting_lu_entry,
|
||||
SPIFFS_OBJ_ID_FREE, blkndx, lu_entry);
|
||||
SPIFFS_OBJID_FREE, blkndx, lu_entry);
|
||||
if (ret == OK)
|
||||
{
|
||||
fs->free_blkndx = *blkndx;
|
||||
@ -1183,7 +1184,7 @@ int spiffs_page_move(FAR struct spiffs_s *fs,
|
||||
phdr->flags &= ~SPIFFS_PH_FLAG_USED;
|
||||
ret = spiffs_cache_write(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT, 0,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, free_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), page_data);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), page_data);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_write() failed: %d\n", ret);
|
||||
@ -1196,7 +1197,7 @@ int spiffs_page_move(FAR struct spiffs_s *fs,
|
||||
|
||||
ret = spiffs_phys_cpy(fs, objid, SPIFFS_PAGE_TO_PADDR(fs, free_pgndx),
|
||||
SPIFFS_PAGE_TO_PADDR(fs, src_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_phys_cpy() failed: %d\n", ret);
|
||||
@ -1256,7 +1257,7 @@ int spiffs_page_delete(FAR struct spiffs_s *fs, int16_t pgndx)
|
||||
|
||||
/* Mark deleted entry in source object lookup */
|
||||
|
||||
int16_t d_objid = SPIFFS_OBJ_ID_DELETED;
|
||||
int16_t d_objid = SPIFFS_OBJID_DELETED;
|
||||
ret = spiffs_cache_write(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_DELE, 0,
|
||||
SPIFFS_BLOCK_TO_PADDR(fs, SPIFFS_BLOCK_FOR_PAGE(fs, pgndx)) +
|
||||
SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, pgndx) *
|
||||
@ -1327,7 +1328,7 @@ int spiffs_object_create(FAR struct spiffs_s *fs,
|
||||
return ret;
|
||||
}
|
||||
|
||||
objid |= SPIFFS_OBJ_ID_IX_FLAG;
|
||||
objid |= SPIFFS_OBJID_NDXFLAG;
|
||||
|
||||
/* Find free entry */
|
||||
|
||||
@ -1382,7 +1383,7 @@ int spiffs_object_create(FAR struct spiffs_s *fs,
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, (FAR struct spiffs_page_objndx_s *)&objndx_hdr,
|
||||
SPIFFS_EV_IX_NEW, objid, 0,
|
||||
SPIFFS_EV_NDXNEW, objid, 0,
|
||||
SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, blkndx, entry),
|
||||
SPIFFS_UNDEFINED_LEN);
|
||||
|
||||
@ -1416,7 +1417,7 @@ int spiffs_object_update_index_hdr(FAR struct spiffs_s *fs,
|
||||
int16_t new_objhdr_pgndx;
|
||||
int ret = OK;
|
||||
|
||||
objid |= SPIFFS_OBJ_ID_IX_FLAG;
|
||||
objid |= SPIFFS_OBJID_NDXFLAG;
|
||||
|
||||
if (new_objhdr_data)
|
||||
{
|
||||
@ -1431,7 +1432,7 @@ int spiffs_object_update_index_hdr(FAR struct spiffs_s *fs,
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, objhdr_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -1477,8 +1478,8 @@ int spiffs_object_update_index_hdr(FAR struct spiffs_s *fs,
|
||||
/* callback on object index update */
|
||||
|
||||
spiffs_object_event(fs, (FAR struct spiffs_page_objndx_s *)objhdr,
|
||||
new_objhdr_data ? SPIFFS_EV_IX_UPD :
|
||||
SPIFFS_EV_IX_UPD_HDR, objid,
|
||||
new_objhdr_data ? SPIFFS_EV_NDXUPD :
|
||||
SPIFFS_EV_NDXUPD_HDR, objid,
|
||||
objhdr->phdr.spndx, new_objhdr_pgndx,
|
||||
objhdr->size);
|
||||
if (fobj != NULL)
|
||||
@ -1512,7 +1513,7 @@ void spiffs_object_event(FAR struct spiffs_s *fs,
|
||||
|
||||
FAR struct spiffs_file_s *fobj;
|
||||
FAR struct spiffs_file_s *next;
|
||||
int16_t objid = objid_raw & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
int16_t objid = objid_raw & ~SPIFFS_OBJID_NDXFLAG;
|
||||
|
||||
finfo("Event=%s objid=%04x spndx=%04x npgndx=%04x nsz=%d\n",
|
||||
evname[MIN(ev, 5)], objid_raw, spndx, new_pgndx, new_size);
|
||||
@ -1529,7 +1530,7 @@ void spiffs_object_event(FAR struct spiffs_s *fs,
|
||||
|
||||
/* Is this the object we are looking for? */
|
||||
|
||||
if ((fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG) != objid)
|
||||
if ((fobj->objid & ~SPIFFS_OBJID_NDXFLAG) != objid)
|
||||
{
|
||||
continue; /* Object not related to updated file */
|
||||
}
|
||||
@ -1538,7 +1539,7 @@ void spiffs_object_event(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* Object index header update */
|
||||
|
||||
if (ev != SPIFFS_EV_IX_DEL)
|
||||
if (ev != SPIFFS_EV_NDXDEL)
|
||||
{
|
||||
finfo("Setting objid=%d (offset=%d) objhdr_pgndx to %04x size=%d\n",
|
||||
fobj->objid, fobj->offset, new_pgndx, new_size);
|
||||
@ -1602,7 +1603,7 @@ void spiffs_object_event(FAR struct spiffs_s *fs,
|
||||
|
||||
if (fobj->objndx_spndx == spndx)
|
||||
{
|
||||
if (ev != SPIFFS_EV_IX_DEL)
|
||||
if (ev != SPIFFS_EV_NDXDEL)
|
||||
{
|
||||
finfo("callback: setting objid=%d span=%04x objndx_pgndx to %04x\n",
|
||||
fobj->objid, spndx, new_pgndx);
|
||||
@ -1773,7 +1774,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_UPDT,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -1818,7 +1819,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_UPDT,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -1827,7 +1828,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, (FAR struct spiffs_page_objndx_s *)fs->work,
|
||||
SPIFFS_EV_IX_UPD, fobj->objid,
|
||||
SPIFFS_EV_NDXUPD, fobj->objid,
|
||||
objndx->phdr.spndx, cur_objndx_pgndx,
|
||||
0);
|
||||
|
||||
@ -1867,7 +1868,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -1894,13 +1895,13 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
|
||||
if (written > 0 || cur_objndx_spndx > len_objndx_spndx)
|
||||
{
|
||||
phdr.objid = fobj->objid | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
phdr.objid = fobj->objid | SPIFFS_OBJID_NDXFLAG;
|
||||
phdr.spndx = cur_objndx_spndx;
|
||||
phdr.flags =
|
||||
0xff & ~(SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_INDEX);
|
||||
|
||||
ret = spiffs_page_allocate_data(fs,
|
||||
fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
&phdr, 0, 0, 0, 1,
|
||||
&cur_objndx_pgndx);
|
||||
if (ret < 0)
|
||||
@ -1912,12 +1913,12 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
|
||||
/* Quick "load" of new object index page */
|
||||
|
||||
memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
memset(fs->work, 0xff, SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
memcpy(fs->work, &phdr, sizeof(struct spiffs_page_header_s));
|
||||
|
||||
spiffs_object_event(fs,
|
||||
(FAR struct spiffs_page_objndx_s *)fs->work,
|
||||
SPIFFS_EV_IX_NEW, fobj->objid,
|
||||
SPIFFS_EV_NDXNEW, fobj->objid,
|
||||
cur_objndx_spndx, cur_objndx_pgndx, 0);
|
||||
|
||||
finfo("objid=%04x create objndx page, %04x:%04x, written=%d\n",
|
||||
@ -1940,7 +1941,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
else
|
||||
{
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
cur_objndx_spndx, 0,
|
||||
&pgndx);
|
||||
if (ret < 0)
|
||||
@ -1958,7 +1959,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -1995,12 +1996,12 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
{
|
||||
/* ATt beginning of a page, allocate and write a new page of data */
|
||||
|
||||
phdr.objid = fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
phdr.objid = fobj->objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
phdr.spndx = data_spndx;
|
||||
phdr.flags = 0xff & ~(SPIFFS_PH_FLAG_FINAL); /* Finalize immediately */
|
||||
|
||||
ret = spiffs_page_allocate_data(fs,
|
||||
fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
&phdr, &data[written], to_write,
|
||||
page_offs, 1, &data_page);
|
||||
|
||||
@ -2117,7 +2118,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
ret2 = spiffs_cache_write(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_UPDT,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret2 < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_write() failed: %d\n", ret2);
|
||||
@ -2126,7 +2127,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
|
||||
spiffs_object_event(fs,
|
||||
(FAR struct spiffs_page_objndx_s *)fs->work,
|
||||
SPIFFS_EV_IX_UPD, fobj->objid,
|
||||
SPIFFS_EV_NDXUPD, fobj->objid,
|
||||
objndx->phdr.spndx, cur_objndx_pgndx, 0);
|
||||
|
||||
/* Update size in object header index page */
|
||||
@ -2173,7 +2174,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_UPDT,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret2 < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_write() failed: %d\n", ret2);
|
||||
@ -2182,7 +2183,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
||||
|
||||
spiffs_object_event(fs,
|
||||
(FAR struct spiffs_page_objndx_s *)fs->work,
|
||||
SPIFFS_EV_IX_UPD_HDR, fobj->objid,
|
||||
SPIFFS_EV_NDXUPD_HDR, fobj->objid,
|
||||
objhdr->phdr.spndx, cur_objndx_pgndx,
|
||||
objhdr->size);
|
||||
}
|
||||
@ -2331,7 +2332,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
|
||||
spiffs_object_event(fs,
|
||||
(FAR struct spiffs_page_objndx_s *)objndx,
|
||||
SPIFFS_EV_IX_UPD, fobj->objid,
|
||||
SPIFFS_EV_NDXUPD, fobj->objid,
|
||||
objndx->phdr.spndx, new_objndx_pgndx,
|
||||
0);
|
||||
}
|
||||
@ -2350,7 +2351,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, cur_objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -2380,7 +2381,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
else
|
||||
{
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
cur_objndx_spndx, 0,
|
||||
&pgndx);
|
||||
if (ret < 0)
|
||||
@ -2397,7 +2398,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -2443,7 +2444,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
[SPIFFS_OBJ_IX_ENTRY(fs, data_spndx)];
|
||||
}
|
||||
|
||||
phdr.objid = fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
phdr.objid = fobj->objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
phdr.spndx = data_spndx;
|
||||
phdr.flags = 0xff;
|
||||
|
||||
@ -2452,7 +2453,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
/* A full page, allocate and write a new page of data */
|
||||
|
||||
ret = spiffs_page_allocate_data(fs,
|
||||
fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
&phdr, &data[written], to_write,
|
||||
page_offs, 1, &data_pgndx);
|
||||
finfo("Store new data page, %04x:%04x offset=%d, len=%d, written=%d\n",
|
||||
@ -2470,7 +2471,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
}
|
||||
|
||||
ret = spiffs_page_allocate_data(fs,
|
||||
fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
&phdr, 0, 0, 0, 0, &data_pgndx);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -2624,7 +2625,7 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, (FAR struct spiffs_page_objndx_s *)objndx,
|
||||
SPIFFS_EV_IX_UPD, fobj->objid, objndx->phdr.spndx,
|
||||
SPIFFS_EV_NDXUPD, fobj->objid, objndx->phdr.spndx,
|
||||
new_objndx_pgndx, 0);
|
||||
}
|
||||
else
|
||||
@ -2809,7 +2810,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
return ret;
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, NULL, SPIFFS_EV_IX_DEL, fobj->objid,
|
||||
spiffs_object_event(fs, NULL, SPIFFS_EV_NDXDEL, fobj->objid,
|
||||
objndx->phdr.spndx, objndx_pgndx, 0);
|
||||
if (prev_objndx_spndx > 0)
|
||||
{
|
||||
@ -2857,7 +2858,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
else
|
||||
{
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
cur_objndx_spndx, 0,
|
||||
&objndx_pgndx);
|
||||
if (ret < 0)
|
||||
@ -2874,7 +2875,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -2906,7 +2907,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
|
||||
((FAR int16_t *)((FAR uint8_t *)objhdr +
|
||||
sizeof(struct spiffs_pgobj_ndxheader_s)))[data_spndx] =
|
||||
SPIFFS_OBJ_ID_FREE;
|
||||
SPIFFS_OBJID_FREE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2919,7 +2920,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
|
||||
((FAR int16_t *)((FAR uint8_t *)objndx +
|
||||
sizeof(struct spiffs_page_objndx_s)))
|
||||
[SPIFFS_OBJ_IX_ENTRY(fs, data_spndx)] = SPIFFS_OBJ_ID_FREE;
|
||||
[SPIFFS_OBJ_IX_ENTRY(fs, data_spndx)] = SPIFFS_OBJID_FREE;
|
||||
}
|
||||
|
||||
finfo("Got data pgndx %04x\n", data_pgndx);
|
||||
@ -2990,14 +2991,14 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
break;
|
||||
}
|
||||
|
||||
phdr.objid = fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
phdr.objid = fobj->objid & ~SPIFFS_OBJID_NDXFLAG;
|
||||
phdr.spndx = data_spndx;
|
||||
phdr.flags = 0xff;
|
||||
|
||||
/* Allocate new page and copy unmodified data */
|
||||
|
||||
ret = spiffs_page_allocate_data(fs,
|
||||
fobj->objid & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid & ~SPIFFS_OBJID_NDXFLAG,
|
||||
&phdr, 0, 0, 0, 0,
|
||||
&new_data_pgndx);
|
||||
if (ret < 0)
|
||||
@ -3106,7 +3107,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
return ret;
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, NULL, SPIFFS_EV_IX_DEL, fobj->objid,
|
||||
spiffs_object_event(fs, NULL, SPIFFS_EV_NDXDEL, fobj->objid,
|
||||
0, objndx_pgndx, 0);
|
||||
}
|
||||
else
|
||||
@ -3117,7 +3118,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
|
||||
memset(fs->work + sizeof(struct spiffs_pgobj_ndxheader_s),
|
||||
0xff,
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs) -
|
||||
SPIFFS_GEO_PAGE_SIZE(fs) -
|
||||
sizeof(struct spiffs_pgobj_ndxheader_s));
|
||||
|
||||
ret = spiffs_object_update_index_hdr(fs, fobj, fobj->objid,
|
||||
@ -3175,7 +3176,7 @@ int spiffs_object_truncate(FAR struct spiffs_s *fs,
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, (FAR struct spiffs_page_objndx_s *)objhdr,
|
||||
SPIFFS_EV_IX_UPD, fobj->objid, objndx->phdr.spndx,
|
||||
SPIFFS_EV_NDXUPD, fobj->objid, objndx->phdr.spndx,
|
||||
new_objndx_pgndx, 0);
|
||||
|
||||
finfo("Store modified objndx page, %04x:%04x\n",
|
||||
@ -3254,7 +3255,7 @@ ssize_t spiffs_object_read(FAR struct spiffs_s *fs,
|
||||
else
|
||||
{
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
cur_objndx_spndx, 0,
|
||||
&objndx_pgndx);
|
||||
if (ret < 0)
|
||||
@ -3272,7 +3273,7 @@ ssize_t spiffs_object_read(FAR struct spiffs_s *fs,
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fobj->objid,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -3385,24 +3386,24 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
|
||||
int16_t free_objid;
|
||||
int ret = OK;
|
||||
|
||||
max_objects = (fs->geo.neraseblocks * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) / 2;
|
||||
free_objid = SPIFFS_OBJ_ID_FREE;
|
||||
max_objects = (SPIFFS_GEO_BLOCK_COUNT(fs) * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) / 2;
|
||||
free_objid = SPIFFS_OBJID_FREE;
|
||||
|
||||
state.min_objid = 1;
|
||||
state.max_objid = max_objects + 1;
|
||||
|
||||
if ((state.max_objid & SPIFFS_OBJ_ID_IX_FLAG) != 0)
|
||||
if ((state.max_objid & SPIFFS_OBJID_NDXFLAG) != 0)
|
||||
{
|
||||
state.max_objid = ((int16_t) - 1) & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
state.max_objid = ((int16_t) - 1) & ~SPIFFS_OBJID_NDXFLAG;
|
||||
}
|
||||
|
||||
state.compaction = 0;
|
||||
state.conflicting_name = conflicting_name;
|
||||
|
||||
while (ret >= 0 && free_objid == SPIFFS_OBJ_ID_FREE)
|
||||
while (ret >= 0 && free_objid == SPIFFS_OBJID_FREE)
|
||||
{
|
||||
if (state.max_objid - state.min_objid <=
|
||||
(int16_t)SPIFFS_CFG_LOG_PAGE_SZ(fs) * 8)
|
||||
(int16_t)SPIFFS_GEO_PAGE_SIZE(fs) * 8)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t j;
|
||||
@ -3412,7 +3413,7 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
|
||||
finfo("BITM min=%04x max=%04x\n",
|
||||
state.min_objid, state.max_objid);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
memset(fs->work, 0, SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
ret = spiffs_foreach_objlu(fs, 0, 0, 0, 0,
|
||||
spiffs_objlu_find_free_objid_bitmap_callback,
|
||||
conflicting_name, &state.min_objid,
|
||||
@ -3429,7 +3430,7 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
|
||||
|
||||
/* Traverse bitmask until found free objid */
|
||||
|
||||
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs); i++)
|
||||
for (i = 0; i < SPIFFS_GEO_PAGE_SIZE(fs); i++)
|
||||
{
|
||||
uint8_t mask = fs->work[i];
|
||||
|
||||
@ -3472,7 +3473,7 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
|
||||
min_count = 0xff;
|
||||
|
||||
for (i = 0;
|
||||
i < SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(uint8_t);
|
||||
i < SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(uint8_t);
|
||||
i++)
|
||||
{
|
||||
if (map[i] < min_count)
|
||||
@ -3518,7 +3519,7 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
|
||||
}
|
||||
|
||||
if ((state.max_objid - state.min_objid <=
|
||||
(int16_t)SPIFFS_CFG_LOG_PAGE_SZ(fs) * 8))
|
||||
(int16_t)SPIFFS_GEO_PAGE_SIZE(fs) * 8))
|
||||
{
|
||||
/* No need for compacting, use bitmap */
|
||||
|
||||
@ -3536,12 +3537,12 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
|
||||
|
||||
state.compaction =
|
||||
(state.max_objid -
|
||||
state.min_objid) / ((SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(uint8_t)));
|
||||
state.min_objid) / ((SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(uint8_t)));
|
||||
|
||||
finfo("COMP min=%04x max=%04x compact=%d\n",
|
||||
state.min_objid, state.max_objid, state.compaction);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
memset(fs->work, 0, SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
ret = spiffs_foreach_objlu(fs, 0, 0, 0, 0,
|
||||
spiffs_objlu_find_free_objid_compact_callback,
|
||||
&state, 0, 0, 0);
|
||||
|
@ -174,138 +174,116 @@
|
||||
|
||||
#define SPIFFS_VIS_END (SPIFFS_ERR_INTERNAL - 22)
|
||||
|
||||
/* updating an object index contents */
|
||||
/* Events */
|
||||
|
||||
#define SPIFFS_EV_IX_UPD (0)
|
||||
#define SPIFFS_EV_NDXUPD (0) /* Updating object index contents */
|
||||
#define SPIFFS_EV_NDXNEW (1) /* Creating new object index */
|
||||
#define SPIFFS_EV_NDXDEL (2) /* Deleting object index */
|
||||
#define SPIFFS_EV_NDXMOV (3) /* Moving abject index without
|
||||
* updating contents */
|
||||
#define SPIFFS_EV_NDXUPD_HDR (4) /* Updating object index header
|
||||
* data only (not the table itself */
|
||||
|
||||
/* creating a new object index */
|
||||
|
||||
#define SPIFFS_EV_IX_NEW (1)
|
||||
|
||||
/* deleting an object index */
|
||||
|
||||
#define SPIFFS_EV_IX_DEL (2)
|
||||
|
||||
/* moving an object index without updating contents */
|
||||
|
||||
#define SPIFFS_EV_IX_MOV (3)
|
||||
|
||||
/* updating an object index header data only, not the table itself */
|
||||
|
||||
#define SPIFFS_EV_IX_UPD_HDR (4)
|
||||
|
||||
#define SPIFFS_OBJ_ID_IX_FLAG ((int16_t)(1<<(8*sizeof(int16_t)-1)))
|
||||
#define SPIFFS_OBJID_NDXFLAG ((int16_t)(1 << (8 * sizeof(int16_t) - 1)))
|
||||
|
||||
#define SPIFFS_UNDEFINED_LEN (uint32_t)(-1)
|
||||
|
||||
#define SPIFFS_OBJ_ID_DELETED ((int16_t)0)
|
||||
#define SPIFFS_OBJ_ID_FREE ((int16_t)-1)
|
||||
#define SPIFFS_OBJID_DELETED ((int16_t)0)
|
||||
#define SPIFFS_OBJID_FREE ((int16_t)-1)
|
||||
|
||||
/* total number of pages */
|
||||
/* Number of object lookup pages per block */
|
||||
|
||||
#define SPIFFS_MAX_PAGES(fs) \
|
||||
(SPIFFS_CFG_PHYS_SZ(fs)/SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_OBJ_LOOKUP_PAGES(fs) \
|
||||
(MAX(1, (SPIFFS_GEO_PAGES_PER_BLOCK(fs) * sizeof(int16_t)) / SPIFFS_GEO_PAGE_SIZE(fs)))
|
||||
|
||||
/* total number of pages per block, including object lookup pages */
|
||||
|
||||
#define SPIFFS_PAGES_PER_BLOCK(fs) \
|
||||
(SPIFFS_CFG_LOG_BLOCK_SZ(fs)/SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
|
||||
/* number of object lookup pages per block */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_PAGES(fs) \
|
||||
(MAX(1, (SPIFFS_PAGES_PER_BLOCK(fs) * sizeof(int16_t)) / SPIFFS_CFG_LOG_PAGE_SZ(fs)))
|
||||
|
||||
/* checks if page index belongs to object lookup */
|
||||
/* Checks if page index belongs to object lookup */
|
||||
|
||||
#define SPIFFS_IS_LOOKUP_PAGE(fs,pgndx) \
|
||||
(((pgndx) % SPIFFS_PAGES_PER_BLOCK(fs)) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
(((pgndx) % SPIFFS_GEO_PAGES_PER_BLOCK(fs)) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
|
||||
/* number of object lookup entries in all object lookup pages */
|
||||
/* Number of object lookup entries in all object lookup pages */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) \
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
(SPIFFS_GEO_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
|
||||
/* converts a block to physical address */
|
||||
/* Converts a block to physical address */
|
||||
|
||||
#define SPIFFS_BLOCK_TO_PADDR(fs, block) ((block) * SPIFFS_CFG_LOG_BLOCK_SZ(fs))
|
||||
#define SPIFFS_BLOCK_TO_PADDR(fs, block) ((block) * SPIFFS_GEO_BLOCK_SIZE(fs))
|
||||
|
||||
/* converts a object lookup entry to page index */
|
||||
/* Converts a object lookup entry to page index */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, block, entry) \
|
||||
((block)*SPIFFS_PAGES_PER_BLOCK(fs) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry))
|
||||
((block)*SPIFFS_GEO_PAGES_PER_BLOCK(fs) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry))
|
||||
|
||||
/* converts a object lookup entry to physical address of corresponding page */
|
||||
/* Converts a object lookup entry to physical address of corresponding page */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, block, entry) \
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, block) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry) * SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, block) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry) * SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* converts a page to physical address */
|
||||
/* Converts a page to physical address */
|
||||
|
||||
#define SPIFFS_PAGE_TO_PADDR(fs, page) ((page) * SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_PAGE_TO_PADDR(fs, page) ((page) * SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* converts a physical address to page */
|
||||
/* Converts a physical address to page */
|
||||
|
||||
#define SPIFFS_PADDR_TO_PAGE(fs, addr) ((addr) / SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_PADDR_TO_PAGE(fs, addr) ((addr) / SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* gives index in page for a physical address */
|
||||
/* Gives index in page for a physical address */
|
||||
|
||||
#define SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr) ((addr) % SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr) ((addr) % SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* returns containing block for given page */
|
||||
/* Returns containing block for given page */
|
||||
|
||||
#define SPIFFS_BLOCK_FOR_PAGE(fs, page) ((page) / SPIFFS_PAGES_PER_BLOCK(fs))
|
||||
#define SPIFFS_BLOCK_FOR_PAGE(fs, page) ((page) / SPIFFS_GEO_PAGES_PER_BLOCK(fs))
|
||||
|
||||
/* returns starting page for block */
|
||||
/* Returns starting page for block */
|
||||
|
||||
#define SPIFFS_PAGE_FOR_BLOCK(fs, block) ((block) * SPIFFS_PAGES_PER_BLOCK(fs))
|
||||
#define SPIFFS_PAGE_FOR_BLOCK(fs, block) ((block) * SPIFFS_GEO_PAGES_PER_BLOCK(fs))
|
||||
|
||||
/* converts page to entry in object lookup page */
|
||||
/* Converts page to entry in object lookup page */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, page) \
|
||||
((page) % SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
((page) % SPIFFS_GEO_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
|
||||
/* returns data size in a data page */
|
||||
/* Returns data size in a data page */
|
||||
|
||||
#define SPIFFS_DATA_PAGE_SIZE(fs) \
|
||||
(SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(struct spiffs_page_header_s))
|
||||
(SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(struct spiffs_page_header_s))
|
||||
|
||||
/* returns physical address for block's erase count,
|
||||
/* Returns physical address for block's erase count,
|
||||
* always in the physical last entry of the last object lookup page
|
||||
*/
|
||||
|
||||
#define SPIFFS_ERASE_COUNT_PADDR(fs, blkndx) \
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, blkndx) + SPIFFS_OBJ_LOOKUP_PAGES(fs) * SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(int16_t))
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, blkndx) + SPIFFS_OBJ_LOOKUP_PAGES(fs) * SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(int16_t))
|
||||
|
||||
/* checks if there is any room for magic in the object luts */
|
||||
/* Checks if there is any room for magic in the object luts */
|
||||
|
||||
#define SPIFFS_CHECK_MAGIC_POSSIBLE(fs) \
|
||||
((SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) % (SPIFFS_CFG_LOG_PAGE_SZ(fs)/sizeof(int16_t))) * sizeof(int16_t) \
|
||||
<= (SPIFFS_CFG_LOG_PAGE_SZ(fs)-sizeof(int16_t)*2))
|
||||
((SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) % (SPIFFS_GEO_PAGE_SIZE(fs)/sizeof(int16_t))) * sizeof(int16_t) \
|
||||
<= (SPIFFS_GEO_PAGE_SIZE(fs)-sizeof(int16_t)*2))
|
||||
|
||||
/* define helpers object */
|
||||
|
||||
/* entries in an object header page index */
|
||||
/* Entries in an object header page index */
|
||||
|
||||
#define SPIFFS_OBJ_HDR_IX_LEN(fs) \
|
||||
((SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(struct spiffs_pgobj_ndxheader_s))/sizeof(int16_t))
|
||||
((SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(struct spiffs_pgobj_ndxheader_s))/sizeof(int16_t))
|
||||
|
||||
/* entries in an object page index */
|
||||
/* Entries in an object page index */
|
||||
|
||||
#define SPIFFS_OBJ_IX_LEN(fs) \
|
||||
((SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(struct spiffs_page_objndx_s))/sizeof(int16_t))
|
||||
((SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(struct spiffs_page_objndx_s))/sizeof(int16_t))
|
||||
|
||||
/* object index entry for given data span index */
|
||||
/* Object index entry for given data span index */
|
||||
|
||||
#define SPIFFS_OBJ_IX_ENTRY(fs, spndx) \
|
||||
((spndx) < SPIFFS_OBJ_HDR_IX_LEN(fs) ? (spndx) : (((spndx)-SPIFFS_OBJ_HDR_IX_LEN(fs))%SPIFFS_OBJ_IX_LEN(fs)))
|
||||
|
||||
/* object index span index number for given data span index or entry */
|
||||
/* Object index span index number for given data span index or entry */
|
||||
|
||||
#define SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, spndx) \
|
||||
((spndx) < SPIFFS_OBJ_HDR_IX_LEN(fs) ? 0 : (1+((spndx)-SPIFFS_OBJ_HDR_IX_LEN(fs))/SPIFFS_OBJ_IX_LEN(fs)))
|
||||
|
||||
/* get data span index for object index span index */
|
||||
/* Get data span index for object index span index */
|
||||
|
||||
#define SPIFFS_DATA_SPAN_IX_FOR_OBJ_IX_SPAN_IX(fs, spndx) \
|
||||
((spndx) == 0 ? 0 : (SPIFFS_OBJ_HDR_IX_LEN(fs) + (((spndx)-1) * SPIFFS_OBJ_IX_LEN(fs))))
|
||||
@ -422,7 +400,7 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
FAR void *user_var, FAR int16_t *blkndx, int *lu_entry);
|
||||
int spiffs_erase_block(FAR struct spiffs_s *fs, int16_t blkndx);
|
||||
int spiffs_objlu_scan(FAR struct spiffs_s *fs);
|
||||
int spiffs_objlu_find_free_obj_id(FAR struct spiffs_s *fs,
|
||||
int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs,
|
||||
int16_t *objid, FAR const uint8_t *conflicting_name);
|
||||
int spiffs_objlu_find_free(FAR struct spiffs_s *fs,
|
||||
int16_t starting_block, int starting_lu_entry,
|
||||
|
@ -117,7 +117,7 @@ static int spiffs_gc_erase_block(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
|
||||
/* Then remove the pages from the cache. */
|
||||
|
||||
for (i = 0; i < SPIFFS_PAGES_PER_BLOCK(fs); i++)
|
||||
for (i = 0; i < SPIFFS_GEO_PAGES_PER_BLOCK(fs); i++)
|
||||
{
|
||||
spiffs_cache_drop_page(fs, SPIFFS_PAGE_FOR_BLOCK(fs, blkndx) + i);
|
||||
}
|
||||
@ -161,7 +161,7 @@ static int spiffs_gc_epage_stats(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
FAR int16_t *objlu_buf = (int16_t *) fs->lu_work;
|
||||
uint32_t dele = 0;
|
||||
uint32_t allo = 0;
|
||||
int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t));
|
||||
int entries_per_page = (SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t));
|
||||
int cur_entry = 0;
|
||||
int obj_lookup_page = 0;
|
||||
int ret = OK;
|
||||
@ -172,23 +172,23 @@ static int spiffs_gc_epage_stats(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
{
|
||||
int entry_offset = obj_lookup_page * entries_per_page;
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, 0,
|
||||
blkndx * SPIFFS_CFG_LOG_BLOCK_SZ(fs) +
|
||||
blkndx * SPIFFS_GEO_BLOCK_SIZE(fs) +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
|
||||
/* Check each entry */
|
||||
|
||||
while (ret == OK &&
|
||||
cur_entry - entry_offset < entries_per_page &&
|
||||
cur_entry <
|
||||
(int)(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs)))
|
||||
(int)(SPIFFS_GEO_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs)))
|
||||
{
|
||||
int16_t id = objlu_buf[cur_entry - entry_offset];
|
||||
|
||||
if (id == SPIFFS_OBJ_ID_FREE)
|
||||
if (id == SPIFFS_OBJID_FREE)
|
||||
{
|
||||
}
|
||||
else if (id == SPIFFS_OBJ_ID_DELETED)
|
||||
else if (id == SPIFFS_OBJID_DELETED)
|
||||
{
|
||||
dele++;
|
||||
}
|
||||
@ -235,7 +235,7 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
FAR int32_t *cand_scores;
|
||||
FAR int16_t *objlu_buf = (FAR int16_t *)fs->lu_work;
|
||||
FAR int16_t *cand_blocks;
|
||||
uint32_t blocks = fs->geo.neraseblocks;
|
||||
uint32_t blocks = SPIFFS_GEO_BLOCK_COUNT(fs);
|
||||
int16_t cur_block = 0;
|
||||
uint32_t cur_block_addr = 0;
|
||||
int entries_per_page;
|
||||
@ -248,11 +248,11 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
*/
|
||||
|
||||
max_candidates =
|
||||
MIN(fs->geo.neraseblocks,
|
||||
(SPIFFS_CFG_LOG_PAGE_SZ(fs) - 8) /
|
||||
MIN(SPIFFS_GEO_BLOCK_COUNT(fs),
|
||||
(SPIFFS_GEO_PAGE_SIZE(fs) - 8) /
|
||||
(sizeof(int16_t) + sizeof(int32_t)));
|
||||
*candidate_count = 0;
|
||||
memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
memset(fs->work, 0xff, SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
|
||||
/* Divide up work area into block indices and scores */
|
||||
|
||||
@ -268,7 +268,7 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
|
||||
*block_candidates = cand_blocks;
|
||||
|
||||
entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t));
|
||||
entries_per_page = (SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t));
|
||||
|
||||
/* Check each block */
|
||||
|
||||
@ -287,19 +287,19 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, 0,
|
||||
cur_block_addr +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
|
||||
/* Check each entry */
|
||||
|
||||
while (ret == OK &&
|
||||
cur_entry - entry_offset < entries_per_page &&
|
||||
cur_entry <
|
||||
(int)(SPIFFS_PAGES_PER_BLOCK(fs) -
|
||||
(int)(SPIFFS_GEO_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)))
|
||||
{
|
||||
int16_t id = objlu_buf[cur_entry - entry_offset];
|
||||
|
||||
if (id == SPIFFS_OBJ_ID_FREE)
|
||||
if (id == SPIFFS_OBJID_FREE)
|
||||
{
|
||||
/* When a free entry is encountered, scan logic ensures that
|
||||
* all following entries are free also
|
||||
@ -308,7 +308,7 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
ret = 1; /* Kill object lu loop */
|
||||
break;
|
||||
}
|
||||
else if (id == SPIFFS_OBJ_ID_DELETED)
|
||||
else if (id == SPIFFS_OBJID_DELETED)
|
||||
{
|
||||
deleted_pages_in_block++;
|
||||
}
|
||||
@ -359,7 +359,7 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
else
|
||||
{
|
||||
erase_age =
|
||||
SPIFFS_OBJ_ID_FREE - (erase_count - fs->max_erase_count);
|
||||
SPIFFS_OBJID_FREE - (erase_count - fs->max_erase_count);
|
||||
}
|
||||
|
||||
score =
|
||||
@ -406,7 +406,7 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
|
||||
cur_entry = 0;
|
||||
cur_block++;
|
||||
cur_block_addr += SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||
cur_block_addr += SPIFFS_GEO_BLOCK_SIZE(fs);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -444,7 +444,7 @@ static int spiffs_gc_find_candidate(FAR struct spiffs_s *fs,
|
||||
|
||||
static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
{
|
||||
const int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t));
|
||||
const int entries_per_page = (SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t));
|
||||
int ret = OK;
|
||||
|
||||
/* This is the global localizer being pushed and popped */
|
||||
@ -471,7 +471,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
* we want to clean
|
||||
*/
|
||||
|
||||
fs->free_blkndx = (blkndx + 1) % fs->geo.neraseblocks;
|
||||
fs->free_blkndx = (blkndx + 1) % SPIFFS_GEO_BLOCK_COUNT(fs);
|
||||
fs->free_entry = 0;
|
||||
spiffs_gcinfo("Move free cursor to block=%0rx\n", fs->free_blkndx);
|
||||
}
|
||||
@ -498,16 +498,16 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
int entry_offset = obj_lookup_page * entries_per_page;
|
||||
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, 0,
|
||||
blkndx * SPIFFS_CFG_LOG_BLOCK_SZ(fs) +
|
||||
blkndx * SPIFFS_GEO_BLOCK_SIZE(fs) +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
|
||||
/* Check each object lookup entry */
|
||||
|
||||
while (scan && ret == OK &&
|
||||
cur_entry - entry_offset < entries_per_page &&
|
||||
cur_entry <
|
||||
(int)(SPIFFS_PAGES_PER_BLOCK(fs) -
|
||||
(int)(SPIFFS_GEO_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)))
|
||||
{
|
||||
int16_t id = objlu_buf[cur_entry - entry_offset];
|
||||
@ -521,9 +521,9 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
case FIND_OBJ_DATA:
|
||||
/* Find a data page. */
|
||||
|
||||
if (id != SPIFFS_OBJ_ID_DELETED &&
|
||||
id != SPIFFS_OBJ_ID_FREE &&
|
||||
((id & SPIFFS_OBJ_ID_IX_FLAG) == 0))
|
||||
if (id != SPIFFS_OBJID_DELETED &&
|
||||
id != SPIFFS_OBJID_FREE &&
|
||||
((id & SPIFFS_OBJID_NDXFLAG) == 0))
|
||||
{
|
||||
/* Found a data page, stop scanning and handle in switch
|
||||
* case below
|
||||
@ -592,9 +592,9 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
ret = spiffs_cache_read(fs,
|
||||
SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||
0,
|
||||
blkndx * SPIFFS_CFG_LOG_BLOCK_SZ(fs) +
|
||||
blkndx * SPIFFS_GEO_BLOCK_SIZE(fs) +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
fs->lu_work);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -619,7 +619,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
return ret;
|
||||
}
|
||||
|
||||
new_data_pgndx = SPIFFS_OBJ_ID_FREE;
|
||||
new_data_pgndx = SPIFFS_OBJID_FREE;
|
||||
}
|
||||
|
||||
/* Update memory representation of object index page
|
||||
@ -658,9 +658,9 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
case MOVE_OBJ_IX:
|
||||
/* Find and evacuate object index pages */
|
||||
|
||||
if (id != SPIFFS_OBJ_ID_DELETED &&
|
||||
id != SPIFFS_OBJ_ID_FREE &&
|
||||
(id & SPIFFS_OBJ_ID_IX_FLAG) != 0)
|
||||
if (id != SPIFFS_OBJID_DELETED &&
|
||||
id != SPIFFS_OBJID_FREE &&
|
||||
(id & SPIFFS_OBJID_NDXFLAG) != 0)
|
||||
{
|
||||
/* Found an index object id */
|
||||
|
||||
@ -700,7 +700,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
|
||||
spiffs_object_event(fs,
|
||||
(FAR struct spiffs_page_objndx_s *)&phdr,
|
||||
SPIFFS_EV_IX_MOV, id,
|
||||
SPIFFS_EV_NDXMOV, id,
|
||||
phdr.spndx, new_pgndx, 0);
|
||||
|
||||
/* Move wipes obj_lu, reload it */
|
||||
@ -708,9 +708,9 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
ret = spiffs_cache_read(fs,
|
||||
SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||
0,
|
||||
blkndx * SPIFFS_CFG_LOG_BLOCK_SZ(fs) +
|
||||
blkndx * SPIFFS_GEO_BLOCK_SIZE(fs) +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -735,7 +735,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
}
|
||||
|
||||
spiffs_object_event(fs, NULL,
|
||||
SPIFFS_EV_IX_DEL, id,
|
||||
SPIFFS_EV_NDXDEL, id,
|
||||
phdr.spndx, cur_pgndx, 0);
|
||||
}
|
||||
}
|
||||
@ -794,7 +794,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
spiffs_gcinfo("Find objndx spndx=%04x\n", gc.cur_objndx_spndx);
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs,
|
||||
gc.cur_objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
gc.cur_objid | SPIFFS_OBJID_NDXFLAG,
|
||||
gc.cur_objndx_spndx, 0,
|
||||
&objndx_pgndx);
|
||||
if (ret == -ENOENT)
|
||||
@ -834,7 +834,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, objndx_pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: spiffs_cache_read() failed: %d\n", ret);
|
||||
@ -846,7 +846,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
*/
|
||||
|
||||
ret = spiffs_validate_objix(&objndx->phdr,
|
||||
gc.cur_objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
gc.cur_objid | SPIFFS_OBJID_NDXFLAG,
|
||||
gc.cur_objndx_spndx);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -884,7 +884,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
/* Store object index header page */
|
||||
|
||||
ret = spiffs_object_update_index_hdr(fs, 0,
|
||||
gc.cur_objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
gc.cur_objid | SPIFFS_OBJID_NDXFLAG,
|
||||
gc.cur_objndx_pgndx, fs->work, 0,
|
||||
0, &new_objndx_pgndx);
|
||||
|
||||
@ -902,7 +902,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
/* Store object index page */
|
||||
|
||||
ret = spiffs_page_move(fs, 0, fs->work,
|
||||
gc.cur_objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
gc.cur_objid | SPIFFS_OBJID_NDXFLAG,
|
||||
0, gc.cur_objndx_pgndx,
|
||||
&new_objndx_pgndx);
|
||||
|
||||
@ -917,7 +917,7 @@ static int spiffs_gc_clean(FAR struct spiffs_s *fs, int16_t blkndx)
|
||||
|
||||
spiffs_object_event(fs,
|
||||
(FAR struct spiffs_page_objndx_s *)fs->work,
|
||||
SPIFFS_EV_IX_UPD, gc.cur_objid,
|
||||
SPIFFS_EV_NDXUPD, gc.cur_objid,
|
||||
objndx->phdr.spndx,
|
||||
new_objndx_pgndx, 0);
|
||||
}
|
||||
@ -968,9 +968,9 @@ int spiffs_gc_quick(FAR struct spiffs_s *fs, uint16_t max_free_pages)
|
||||
{
|
||||
FAR int16_t *objlu_buf = (int16_t *) fs->lu_work;
|
||||
uint32_t cur_block_addr = 0;
|
||||
uint32_t blocks = fs->geo.neraseblocks;
|
||||
uint32_t blocks = SPIFFS_GEO_BLOCK_COUNT(fs);
|
||||
int16_t cur_block = 0;
|
||||
int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(int16_t));
|
||||
int entries_per_page = (SPIFFS_GEO_PAGE_SIZE(fs) / sizeof(int16_t));
|
||||
int cur_entry = 0;
|
||||
int ret = OK;
|
||||
|
||||
@ -997,23 +997,23 @@ int spiffs_gc_quick(FAR struct spiffs_s *fs, uint16_t max_free_pages)
|
||||
ret = spiffs_cache_read(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, 0,
|
||||
cur_block_addr +
|
||||
SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), fs->lu_work);
|
||||
|
||||
/* Check each entry */
|
||||
|
||||
while (ret == OK &&
|
||||
cur_entry - entry_offset < entries_per_page &&
|
||||
cur_entry <
|
||||
(int)(SPIFFS_PAGES_PER_BLOCK(fs) -
|
||||
(int)(SPIFFS_GEO_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)))
|
||||
{
|
||||
int16_t id = objlu_buf[cur_entry - entry_offset];
|
||||
|
||||
if (id == SPIFFS_OBJ_ID_DELETED)
|
||||
if (id == SPIFFS_OBJID_DELETED)
|
||||
{
|
||||
deleted_pages_in_block++;
|
||||
}
|
||||
else if (id == SPIFFS_OBJ_ID_FREE)
|
||||
else if (id == SPIFFS_OBJID_FREE)
|
||||
{
|
||||
/* Kill scan, go for next block */
|
||||
|
||||
@ -1047,7 +1047,7 @@ int spiffs_gc_quick(FAR struct spiffs_s *fs, uint16_t max_free_pages)
|
||||
|
||||
if (ret == OK &&
|
||||
deleted_pages_in_block + free_pages_in_block ==
|
||||
SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs) &&
|
||||
SPIFFS_GEO_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs) &&
|
||||
free_pages_in_block <= max_free_pages)
|
||||
{
|
||||
/* Found a fully deleted block */
|
||||
@ -1059,7 +1059,7 @@ int spiffs_gc_quick(FAR struct spiffs_s *fs, uint16_t max_free_pages)
|
||||
|
||||
cur_entry = 0;
|
||||
cur_block++;
|
||||
cur_block_addr += SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||
cur_block_addr += SPIFFS_GEO_BLOCK_SIZE(fs);
|
||||
}
|
||||
|
||||
if (ret == OK)
|
||||
@ -1103,21 +1103,27 @@ int spiffs_gc_quick(FAR struct spiffs_s *fs, uint16_t max_free_pages)
|
||||
|
||||
int spiffs_gc_check(FAR struct spiffs_s *fs, off_t len)
|
||||
{
|
||||
int32_t free_pages =
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->geo.neraseblocks - 2) -
|
||||
fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
int32_t free_pages;
|
||||
uint32_t needed_pages;
|
||||
int tries = 0;
|
||||
int ret;
|
||||
|
||||
/* Get the number of free pages */
|
||||
|
||||
free_pages = (SPIFFS_GEO_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (SPIFFS_GEO_BLOCK_COUNT(fs) - 2) -
|
||||
fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
|
||||
if (fs->free_blocks > 3 &&
|
||||
(int32_t) len < free_pages * (int32_t) SPIFFS_DATA_PAGE_SIZE(fs))
|
||||
(int32_t)len < free_pages * (int32_t)SPIFFS_DATA_PAGE_SIZE(fs))
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t needed_pages =
|
||||
(len + SPIFFS_DATA_PAGE_SIZE(fs) - 1) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
/* Get the number of pages needed */
|
||||
|
||||
needed_pages = (len + SPIFFS_DATA_PAGE_SIZE(fs) - 1) /
|
||||
SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
|
||||
#if 0
|
||||
if (fs->free_blocks <= 2 && (int32_t)needed_pages > free_pages)
|
||||
@ -1129,7 +1135,7 @@ int spiffs_gc_check(FAR struct spiffs_s *fs, off_t len)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((int32_t) needed_pages > (int32_t)(free_pages + fs->stats_p_deleted))
|
||||
if ((int32_t)needed_pages > (int32_t)(free_pages + fs->stats_p_deleted))
|
||||
{
|
||||
spiffs_gcinfo("Full freeblk=%d needed=%d free=%d dele=%d\n",
|
||||
fs->free_blocks, needed_pages, free_pages,
|
||||
@ -1196,8 +1202,8 @@ int spiffs_gc_check(FAR struct spiffs_s *fs, off_t len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
free_pages = (SPIFFS_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->geo.neraseblocks - 2) -
|
||||
free_pages = (SPIFFS_GEO_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (SPIFFS_GEO_BLOCK_COUNT(fs) - 2) -
|
||||
fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
|
||||
if (prev_free_pages <= 0 && prev_free_pages == free_pages)
|
||||
@ -1213,19 +1219,21 @@ int spiffs_gc_check(FAR struct spiffs_s *fs, off_t len)
|
||||
(fs->free_blocks <= 2 ||
|
||||
(int32_t) len > free_pages * (int32_t) SPIFFS_DATA_PAGE_SIZE(fs)));
|
||||
|
||||
free_pages =
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->geo.neraseblocks - 2) -
|
||||
fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
/* Re-caculate the number of free pages */
|
||||
|
||||
free_pages = (SPIFFS_GEO_PAGES_PER_BLOCK(fs) -
|
||||
SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (SPIFFS_GEO_BLOCK_COUNT(fs) - 2) -
|
||||
fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
|
||||
if ((int32_t) len > free_pages * (int32_t) SPIFFS_DATA_PAGE_SIZE(fs))
|
||||
{
|
||||
ret = -ENOSPC;
|
||||
}
|
||||
|
||||
spiffs_gcinfo("Finished, %d dirty, blocks, %d free, %d pages free, %d tries, ret=%d\n",
|
||||
fs->stats_p_allocated + fs->stats_p_deleted, fs->free_blocks,
|
||||
free_pages, tries, ret);
|
||||
spiffs_gcinfo("Finished, %d dirty, blocks, %d free, %d pages free, "
|
||||
"%d tries, ret=%d\n",
|
||||
fs->stats_p_allocated + fs->stats_p_deleted,
|
||||
fs->free_blocks, free_pages, tries, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -64,13 +64,13 @@
|
||||
* Write data to FLASH memory
|
||||
*
|
||||
* Input Parameters:
|
||||
* fs - A reference to the volume structure
|
||||
* fs - A reference to the volume structure
|
||||
* offset - The physical offset to write to
|
||||
* len - The number of bytes to write
|
||||
* src - A reference to the bytes to be written
|
||||
* len - The number of bytes to write
|
||||
* src - A reference to the bytes to be written
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -81,28 +81,30 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
int16_t blksize;
|
||||
off_t blkstart;
|
||||
off_t blkend;
|
||||
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(fs != NULL && fs->mtd != NULL && src != NULL);
|
||||
|
||||
#warning REVISIT: What are units of offset and len?
|
||||
|
||||
#ifdef CONFIG_MTD_BYTE_WRITE
|
||||
ret = MTD_WRITE(fs->mtd, offset, len, src);
|
||||
if (ret < 0)
|
||||
#endif
|
||||
{
|
||||
/* We will have to do a block read */
|
||||
|
||||
blksize = fs->geo.blocksize;
|
||||
DEBUGASSERT(offset = offset % blksize);
|
||||
DEBUGASSERT(len = len % blksize);
|
||||
DEBUGASSERT(offset == offset % blksize);
|
||||
DEBUGASSERT(len == len % blksize);
|
||||
|
||||
blkstart = offset / blksize; /* Truncates to floor */
|
||||
blkend = (offset + len + blksize - 1) / blksize; /* Rounds up to ceil */
|
||||
|
||||
#warning WRONG: Needs to use page work buffer, not 'src'
|
||||
ret = MTD_BWRITE(fs->mtd, blkstart, blkend - blkstart, src);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret < 0 ret : len;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -118,7 +120,7 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* dest - The user provide location to store the bytes read from FLASH.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -133,22 +135,21 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
|
||||
DEBUGASSERT(fs != NULL && fs->mtd != NULL && dest != NULL);
|
||||
|
||||
#warning REVISIT: What are units of offset and len?
|
||||
|
||||
ret = MTD_READ(fs->mtd, offset, len, dest);
|
||||
if (ret < 0)
|
||||
{
|
||||
blksize = fs->geo.blocksize;
|
||||
DEBUGASSERT(offset = offset % blksize);
|
||||
DEBUGASSERT(len = len % blksize);
|
||||
DEBUGASSERT(offset == offset % blksize);
|
||||
DEBUGASSERT(len == len % blksize);
|
||||
|
||||
blkstart = offset / blksize; /* Truncates to floor */
|
||||
blkend = (offset + len + blksize - 1) / blksize; /* Rounds up to ceil */
|
||||
|
||||
#warning WRONG: Needs to use page work buffer, not 'dest'
|
||||
ret = MTD_BREAD(fs->mtd, blkstart, blkend - blkstart, dest);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret < 0 ret : len;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -163,7 +164,7 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* len - The number of bytes to erase
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
@ -53,11 +53,18 @@ extern "C"
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SPIFFS_CFG_EBLOCK_COUNT(fs) ((fs)->geo.neraseblocks)
|
||||
#define SPIFFS_CFG_LOG_PAGE_SZ(fs) ((fs)->geo.blocksize)
|
||||
#define SPIFFS_CFG_LOG_BLOCK_SZ(fs) ((fs)->geo.blocksize)
|
||||
#define SPIFFS_CFG_PHYS_SZ(fs) ((fs)->phys_size)
|
||||
#define SPIFFS_CFG_PHYS_ERASE_SZ(fs) ((fs)->geo.erasesize)
|
||||
/* The MTD interface does not deal with pages explicitly. With most
|
||||
* hardware a logical block is the same as an SPIFFS page.
|
||||
*/
|
||||
|
||||
#define SPIFFS_GEO_MEDIA_SIZE(fs) ((fs)->media_size)
|
||||
#define SPIFFS_GEO_EBLOCK_COUNT(fs) ((fs)->geo.neraseblocks)
|
||||
#define SPIFFS_GEO_EBLOCK_SIZE(fs) ((fs)->geo.erasesize)
|
||||
#define SPIFFS_GEO_BLOCK_COUNT(fs) ((fs)->geo.neraseblocks)
|
||||
#define SPIFFS_GEO_BLOCK_SIZE(fs) ((fs)->geo.erasesize)
|
||||
#define SPIFFS_GEO_PAGE_COUNT(fs) ((fs)->total_pages)
|
||||
#define SPIFFS_GEO_PAGE_SIZE(fs) ((fs)->geo.blocksize)
|
||||
#define SPIFFS_GEO_PAGES_PER_BLOCK(fs) ((fs)->pages_per_block)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@ -76,7 +83,7 @@ extern "C"
|
||||
* src - A reference to the bytes to be written
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -97,7 +104,7 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* dest - The user provide location to store the bytes read from FLASH.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -117,7 +124,7 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* len - The number of bytes to erase
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
@ -297,8 +297,8 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
|
||||
int16_t pgndx;
|
||||
int ret;
|
||||
|
||||
if (objid == SPIFFS_OBJ_ID_FREE || objid == SPIFFS_OBJ_ID_DELETED ||
|
||||
(objid & SPIFFS_OBJ_ID_IX_FLAG) == 0)
|
||||
if (objid == SPIFFS_OBJID_FREE || objid == SPIFFS_OBJID_DELETED ||
|
||||
(objid & SPIFFS_OBJID_NDXFLAG) == 0)
|
||||
{
|
||||
return SPIFFS_VIS_COUNTINUE;
|
||||
}
|
||||
@ -314,7 +314,7 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((objid & SPIFFS_OBJ_ID_IX_FLAG) &&
|
||||
if ((objid & SPIFFS_OBJID_NDXFLAG) &&
|
||||
objhdr.phdr.spndx == 0 &&
|
||||
(objhdr.phdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL |
|
||||
SPIFFS_PH_FLAG_IXDELE)) ==
|
||||
@ -411,7 +411,7 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
|
||||
/* The file does not exist. We need to create the it. */
|
||||
|
||||
ret = spiffs_objlu_find_free_obj_id(fs, &objid, 0);
|
||||
ret = spiffs_objlu_find_free_objid(fs, &objid, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_fileobject;
|
||||
@ -644,7 +644,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
|
||||
|
||||
if ((fobj->flags & O_DIRECT) == 0)
|
||||
{
|
||||
if (buflen < (size_t)SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
if (buflen < (size_t)SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
{
|
||||
/* Small write, try to cache it */
|
||||
|
||||
@ -657,7 +657,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
|
||||
|
||||
if (offset < fobj->cache_page->offset ||
|
||||
offset > fobj->cache_page->offset + fobj->cache_page->size ||
|
||||
offset + buflen > fobj->cache_page->offset + SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
offset + buflen > fobj->cache_page->offset + SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
{
|
||||
/* Boundary violation, write back cache first and allocate
|
||||
* new
|
||||
@ -881,7 +881,7 @@ static off_t spiffs_seek(FAR struct file *filep, off_t offset, int whence)
|
||||
{
|
||||
int16_t pgndx;
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs, fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
ret = spiffs_objlu_find_id_and_span(fs, fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
objndx_spndx, 0, &pgndx);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -956,7 +956,7 @@ static int spiffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
/* No.. we will have to erase a block at a time */
|
||||
|
||||
int16_t blkndx = 0;
|
||||
while (blkndx < fs->geo.neraseblocks)
|
||||
while (blkndx < SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
fs->max_erase_count = 0;
|
||||
ret = spiffs_erase_block(fs, blkndx);
|
||||
@ -1289,7 +1289,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
int ret;
|
||||
|
||||
finfo("mtdinode: %p data: %p handle: %p\n", mtdinode, data, handle);
|
||||
DEBUGASSERT(mtdinode == NULL && handle != NULL);
|
||||
DEBUGASSERT(mtdinode != NULL && handle != NULL);
|
||||
|
||||
/* Extract the MTD interface reference */
|
||||
|
||||
@ -1316,7 +1316,9 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
goto errout_with_volume;
|
||||
}
|
||||
|
||||
fs->phys_size = fs->geo.neraseblocks * fs->geo.erasesize;
|
||||
fs->media_size = SPIFFS_GEO_EBLOCK_COUNT(fs) * SPIFFS_GEO_EBLOCK_SIZE(fs);
|
||||
fs->total_pages = fs->media_size / SPIFFS_GEO_PAGE_SIZE(fs);
|
||||
fs->pages_per_block = SPIFFS_GEO_EBLOCK_SIZE(fs) / SPIFFS_GEO_PAGE_SIZE(fs);
|
||||
|
||||
/* Get the aligned cache size */
|
||||
|
||||
@ -1325,7 +1327,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
|
||||
/* Don't let the cache size exceed the maximum that is needed */
|
||||
|
||||
cache_max = SPIFFS_CFG_LOG_PAGE_SZ(fs) << 5;
|
||||
cache_max = SPIFFS_GEO_PAGE_SIZE(fs) << 5;
|
||||
if (cache_size > cache_max)
|
||||
{
|
||||
cache_size = cache_max;
|
||||
@ -1351,7 +1353,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
* NOTE: Currently page size is equivalent to block size.
|
||||
*/
|
||||
|
||||
work_size = SPIFFS_CFG_LOG_PAGE_SZ(fs) << 1;
|
||||
work_size = SPIFFS_GEO_PAGE_SIZE(fs) << 1;
|
||||
work = (FAR uint8_t *)kmm_malloc(work_size);
|
||||
|
||||
if (work == NULL)
|
||||
@ -1363,7 +1365,8 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
|
||||
fs->work = &work[0];
|
||||
fs->lu_work = &work[work_size >> 1];
|
||||
fs->config_magic = SPIFFS_SUPER_MAGIC;
|
||||
|
||||
(void)nxsem_init(&fs->exclsem.sem, 0, 1);
|
||||
|
||||
/* Check the file system */
|
||||
|
||||
@ -1375,11 +1378,11 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
}
|
||||
|
||||
finfo("page index byte len: %u\n",
|
||||
(unsigned int)SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
(unsigned int)SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
finfo("object lookup pages: %u\n",
|
||||
(unsigned int)SPIFFS_OBJ_LOOKUP_PAGES(fs));
|
||||
finfo("page pages per block: %u\n",
|
||||
(unsigned int)SPIFFS_PAGES_PER_BLOCK(fs));
|
||||
(unsigned int)SPIFFS_GEO_PAGES_PER_BLOCK(fs));
|
||||
finfo("page header length: %u\n",
|
||||
(unsigned int)sizeof(struct spiffs_page_header_s));
|
||||
finfo("object header index entries: %u\n",
|
||||
@ -1505,8 +1508,8 @@ static int spiffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
|
||||
|
||||
/* Collect some statistics */
|
||||
|
||||
pages_per_block = SPIFFS_PAGES_PER_BLOCK(fs);
|
||||
blocks = fs->geo.neraseblocks;
|
||||
pages_per_block = SPIFFS_GEO_PAGES_PER_BLOCK(fs);
|
||||
blocks = SPIFFS_GEO_BLOCK_COUNT(fs);
|
||||
obj_lupages = SPIFFS_OBJ_LOOKUP_PAGES(fs);
|
||||
data_pgsize = SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
|
||||
|
@ -116,7 +116,7 @@ int spiffs_stat_pgndx(FAR struct spiffs_s *fs, int16_t pgndx, int16_t objid,
|
||||
buf->st_mode = mode;
|
||||
buf->st_size = objhdr.size == SPIFFS_UNDEFINED_LEN ? 0 : objhdr.size;
|
||||
buf->st_blksize = fs->geo.blocksize;
|
||||
buf->st_blocks = fs->phys_size / fs->geo.blocksize;
|
||||
buf->st_blocks = fs->media_size / fs->geo.blocksize;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user