mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-30 11:39:14 -07:00
make style
This commit is contained in:
parent
b4d54ae0a2
commit
9beabaabf5
29 changed files with 4784 additions and 4778 deletions
|
@ -102,7 +102,7 @@ void ReadLastTagFromFlash() {
|
|||
uint8_t *mem = BigBuf_malloc(size);
|
||||
|
||||
//this one will handle filetype (symlink or not) and resolving by itself
|
||||
rdv40_spiffs_read_as_filetype((char *)HFCOLIN_LASTTAG_SYMLINK,(uint8_t *)mem,len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_read_as_filetype((char *)HFCOLIN_LASTTAG_SYMLINK, (uint8_t *)mem, len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
|
||||
emlSetMem(mem, 0, 64);
|
||||
|
||||
|
@ -126,14 +126,14 @@ void WriteTagToFlash(uint32_t uid, size_t size) {
|
|||
|
||||
char dest[SPIFFS_OBJ_NAME_LEN];
|
||||
uint8_t buid[4];
|
||||
num_to_bytes(uid,4,buid);
|
||||
sprintf(dest,"hf_colin/mf_%02x%02x%02x%02x.bin",buid[0],buid[1],buid[2],buid[3]);
|
||||
num_to_bytes(uid, 4, buid);
|
||||
sprintf(dest, "hf_colin/mf_%02x%02x%02x%02x.bin", buid[0], buid[1], buid[2], buid[3]);
|
||||
|
||||
// TODO : by using safe function for multiple writes we are both breaking cache mecanisms and making useless and unoptimized mount operations
|
||||
// we should manage at out level the mount status before and after the whole standalone mode
|
||||
rdv40_spiffs_write((char *)dest,(uint8_t *)data,len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_write((char *)dest, (uint8_t *)data, len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
// lastag will only contain filename/path to last written tag file so we don't loose time or space.
|
||||
rdv40_spiffs_make_symlink((char *)dest,(char *)HFCOLIN_LASTTAG_SYMLINK,RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_make_symlink((char *)dest, (char *)HFCOLIN_LASTTAG_SYMLINK, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
|
||||
DbprintfEx(FLAG_NEWLINE, "[OK] TAG WRITTEN TO FLASH !");
|
||||
cjSetCursLeft();
|
||||
|
|
|
@ -1614,7 +1614,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
LED_B_ON();
|
||||
uint8_t filename[32];
|
||||
uint8_t *pfilename = packet->data.asBytes;
|
||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
||||
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs dump : %s", filename);
|
||||
|
||||
//uint32_t size = 0;
|
||||
|
@ -1623,7 +1623,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
//uint8_t buff[size];
|
||||
|
||||
uint8_t *buff = BigBuf_malloc(size);
|
||||
rdv40_spiffs_read_as_filetype((char *)filename,(uint8_t *)buff, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_read_as_filetype((char *)filename, (uint8_t *)buff, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
|
||||
// arg0 = filename
|
||||
// arg1 = size
|
||||
|
@ -1640,11 +1640,11 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
LED_B_OFF();
|
||||
break;
|
||||
}
|
||||
case CMD_SPIFFS_STAT:{
|
||||
case CMD_SPIFFS_STAT: {
|
||||
LED_B_ON();
|
||||
uint8_t filename[32];
|
||||
uint8_t *pfilename = packet->data.asBytes;
|
||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
||||
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs STAT : %s", filename);
|
||||
int changed = rdv40_spiffs_lazy_mount();
|
||||
uint32_t size = size_in_spiffs((char *)filename);
|
||||
|
@ -1653,45 +1653,45 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
LED_B_OFF();
|
||||
break;
|
||||
}
|
||||
case CMD_SPIFFS_REMOVE:{
|
||||
case CMD_SPIFFS_REMOVE: {
|
||||
LED_B_ON();
|
||||
uint8_t filename[32];
|
||||
uint8_t *pfilename = packet->data.asBytes;
|
||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
||||
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs REMOVE : %s", filename);
|
||||
rdv40_spiffs_remove((char *) filename,RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_remove((char *) filename, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
LED_B_OFF();
|
||||
break;
|
||||
}
|
||||
case CMD_SPIFFS_RENAME:{
|
||||
case CMD_SPIFFS_RENAME: {
|
||||
LED_B_ON();
|
||||
uint8_t srcfilename[32];
|
||||
uint8_t destfilename[32];
|
||||
uint8_t *pfilename = packet->data.asBytes;
|
||||
char *token;
|
||||
token = strtok((char *)pfilename, ",");
|
||||
strcpy((char*)srcfilename,token);
|
||||
token = strtok(NULL,",");
|
||||
strcpy((char *)destfilename,token);
|
||||
strcpy((char *)srcfilename, token);
|
||||
token = strtok(NULL, ",");
|
||||
strcpy((char *)destfilename, token);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as source for spiffs RENAME : %s", srcfilename);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as destination for spiffs RENAME : %s", destfilename);
|
||||
rdv40_spiffs_rename((char *) srcfilename,(char *)destfilename,RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_rename((char *) srcfilename, (char *)destfilename, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
LED_B_OFF();
|
||||
break;
|
||||
}
|
||||
case CMD_SPIFFS_COPY:{
|
||||
case CMD_SPIFFS_COPY: {
|
||||
LED_B_ON();
|
||||
uint8_t srcfilename[32];
|
||||
uint8_t destfilename[32];
|
||||
uint8_t *pfilename = packet->data.asBytes;
|
||||
char *token;
|
||||
token = strtok((char *)pfilename, ",");
|
||||
strcpy((char*)srcfilename,token);
|
||||
token = strtok(NULL,",");
|
||||
strcpy((char *)destfilename,token);
|
||||
strcpy((char *)srcfilename, token);
|
||||
token = strtok(NULL, ",");
|
||||
strcpy((char *)destfilename, token);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as source for spiffs COPY : %s", srcfilename);
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as destination for spiffs COPY : %s", destfilename);
|
||||
rdv40_spiffs_copy((char *) srcfilename,(char *)destfilename,RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_copy((char *) srcfilename, (char *)destfilename, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
LED_B_OFF();
|
||||
break;
|
||||
}
|
||||
|
@ -1705,14 +1705,14 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
//rdv40_spiffs_lazy_mount();
|
||||
|
||||
uint8_t *pfilename = packet->data.asBytes;
|
||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
||||
data+=SPIFFS_OBJ_NAME_LEN;
|
||||
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||
data += SPIFFS_OBJ_NAME_LEN;
|
||||
|
||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs WRITE : %s with APPEND SET TO : %d", filename, append);
|
||||
if (!append) {
|
||||
rdv40_spiffs_write((char *) filename,(uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_write((char *) filename, (uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
} else {
|
||||
rdv40_spiffs_append((char *) filename,(uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
rdv40_spiffs_append((char *) filename, (uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
}
|
||||
reply_old(CMD_ACK, 1, 0, 0, 0, 0);
|
||||
LED_B_OFF();
|
||||
|
|
|
@ -467,7 +467,7 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD
|
|||
if (DBGLEVEL > 1) Dbprintf("Symlink destination is : %s", linkdest);
|
||||
read_from_spiffs((char *)linkdest, (uint8_t *)dst, size); //
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// BEWARE ! This function is DESTRUCTIVE as it will UPDATE an existing symlink
|
||||
// Since it creates a .lnk extension file it may be minor to mistake the order of arguments
|
||||
|
@ -507,7 +507,8 @@ int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, R
|
|||
break;
|
||||
case RDV40_SPIFFS_FILETYPE_BOTH:
|
||||
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
||||
default:;
|
||||
default:
|
||||
;
|
||||
} //
|
||||
)
|
||||
}
|
||||
|
|
|
@ -22,15 +22,14 @@ typedef enum spiffs_file_type {
|
|||
RDV40_SPIFFS_FILETYPE_UNKNOWN
|
||||
} RDV40SpiFFSFileType;
|
||||
|
||||
typedef struct rdv40_spiffs_fsinfo
|
||||
{
|
||||
typedef struct rdv40_spiffs_fsinfo {
|
||||
uint32_t blockSize;
|
||||
uint32_t pageSize;
|
||||
uint32_t maxOpenFiles;
|
||||
uint32_t maxPathLenght;
|
||||
uint32_t totalBytes, usedBytes, freeBytes;
|
||||
uint32_t usedPercent, freePercent;
|
||||
} rdv40_spiffs_fsinfo;
|
||||
} rdv40_spiffs_fsinfo;
|
||||
|
||||
int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level);
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix)
|
|||
int i;
|
||||
for (i = 0; i < cache->cpage_count; i++) {
|
||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||
if ((cache->cpage_use_map & (1<<i)) &&
|
||||
if ((cache->cpage_use_map & (1 << i)) &&
|
||||
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 &&
|
||||
cp->ucache.spix.pix == pix ) {
|
||||
cp->ucache.spix.pix == pix) {
|
||||
//SPIFFS_CACHE_DBG("CACHE_GET: have cache page "_SPIPRIi" for "_SPIPRIpg"\n", i, pix);
|
||||
cp->last_access = cache->last_access;
|
||||
return cp;
|
||||
|
@ -34,7 +34,7 @@ static s32_t spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) {
|
|||
s32_t res = SPIFFS_OK;
|
||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, ix);
|
||||
if (cache->cpage_use_map & (1<<ix)) {
|
||||
if (cache->cpage_use_map & (1 << ix)) {
|
||||
if (write_back &&
|
||||
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 &&
|
||||
(cp->flags & SPIFFS_CACHE_FLAG_DIRTY)) {
|
||||
|
@ -97,9 +97,9 @@ static spiffs_cache_page *spiffs_cache_page_allocate(spiffs *fs) {
|
|||
}
|
||||
int i;
|
||||
for (i = 0; i < cache->cpage_count; i++) {
|
||||
if ((cache->cpage_use_map & (1<<i)) == 0) {
|
||||
if ((cache->cpage_use_map & (1 << i)) == 0) {
|
||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||
cache->cpage_use_map |= (1<<i);
|
||||
cache->cpage_use_map |= (1 << i);
|
||||
cp->last_access = cache->last_access;
|
||||
//SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi"\n", i);
|
||||
return cp;
|
||||
|
@ -235,7 +235,7 @@ spiffs_cache_page *spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) {
|
|||
int i;
|
||||
for (i = 0; i < cache->cpage_count; i++) {
|
||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||
if ((cache->cpage_use_map & (1<<i)) &&
|
||||
if ((cache->cpage_use_map & (1 << i)) &&
|
||||
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) &&
|
||||
cp->ucache.swrc.obj_id == fd->obj_id) {
|
||||
return cp;
|
||||
|
|
|
@ -76,7 +76,7 @@ static s32_t spiffs_object_get_data_page_index_reference(
|
|||
// copies page contents to a new page
|
||||
static s32_t spiffs_rewrite_page(spiffs *fs, spiffs_page_ix cur_pix, spiffs_page_header *p_hdr, spiffs_page_ix *new_pix) {
|
||||
s32_t res;
|
||||
res = spiffs_page_allocate_data(fs, p_hdr->obj_id, p_hdr, 0,0,0,0, new_pix);
|
||||
res = spiffs_page_allocate_data(fs, p_hdr->obj_id, p_hdr, 0, 0, 0, 0, new_pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
res = spiffs_phys_cpy(fs, 0,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, *new_pix) + sizeof(spiffs_page_header),
|
||||
|
@ -134,9 +134,9 @@ static s32_t spiffs_rewrite_index(spiffs *fs, spiffs_obj_id obj_id, spiffs_span_
|
|||
|
||||
// rewrite in mem
|
||||
if (objix_spix == 0) {
|
||||
((spiffs_page_ix*)((u8_t *)fs->lu_work + sizeof(spiffs_page_object_ix_header)))[data_spix] = new_data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)fs->lu_work + sizeof(spiffs_page_object_ix_header)))[data_spix] = new_data_pix;
|
||||
} else {
|
||||
((spiffs_page_ix*)((u8_t *)fs->lu_work + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = new_data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)fs->lu_work + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = new_data_pix;
|
||||
}
|
||||
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
|
||||
|
@ -343,7 +343,7 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
|
|||
*reload_lu = 1;
|
||||
} else {
|
||||
// cannot safely do anything
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: nothing to do, just delete\n",NULL);
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: nothing to do, just delete\n", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,11 +370,11 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
|
|||
delete_page = 1;
|
||||
// if other data page exists and object index exists, just delete page
|
||||
if (data_pix && objix_pix_d) {
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other index and data page exists, simply remove\n",NULL);
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other index and data page exists, simply remove\n", NULL);
|
||||
} else
|
||||
// if only data page exists, make this page index
|
||||
if (data_pix && objix_pix_d == 0) {
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other data page exists, make this index\n",NULL);
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other data page exists, make this index\n", NULL);
|
||||
CHECK_CB(fs, SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_FIX_INDEX, lu_obj_id, p_hdr->span_ix);
|
||||
spiffs_page_header new_ph;
|
||||
spiffs_page_ix new_pix;
|
||||
|
@ -390,7 +390,7 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
|
|||
} else
|
||||
// if only index exists, make data page
|
||||
if (data_pix == 0 && objix_pix_d) {
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other index page exists, make this data\n",NULL);
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other index page exists, make this data\n", NULL);
|
||||
CHECK_CB(fs, SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_FIX_LOOKUP, lu_obj_id, p_hdr->span_ix);
|
||||
spiffs_page_header new_ph;
|
||||
spiffs_page_ix new_pix;
|
||||
|
@ -406,8 +406,7 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
|
|||
} else {
|
||||
// if nothing exists, we cannot safely make a decision - delete
|
||||
}
|
||||
}
|
||||
else if ((p_hdr->flags & SPIFFS_PH_FLAG_DELET) == 0) {
|
||||
} else if ((p_hdr->flags & SPIFFS_PH_FLAG_DELET) == 0) {
|
||||
SPIFFS_CHECK_DBG("LU: pix "_SPIPRIpg" busy in lu but deleted on page\n", cur_pix);
|
||||
delete_page = 1;
|
||||
} else if ((p_hdr->flags & SPIFFS_PH_FLAG_FINAL)) {
|
||||
|
@ -422,12 +421,12 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
|
|||
} else {
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (ref_pix != cur_pix) {
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other finalized page is referred, just delete\n",NULL);
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: other finalized page is referred, just delete\n", NULL);
|
||||
delete_page = 1;
|
||||
} else {
|
||||
// page referenced by object index but not final
|
||||
// just finalize
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: unfinalized page is referred, finalizing\n",NULL);
|
||||
SPIFFS_CHECK_DBG("LU: FIXUP: unfinalized page is referred, finalizing\n", NULL);
|
||||
CHECK_CB(fs, SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_FIX_LOOKUP, p_hdr->obj_id, p_hdr->span_ix);
|
||||
u8_t flags = 0xff;
|
||||
#if SPIFFS_NO_BLIND_WRITES
|
||||
|
@ -464,11 +463,11 @@ static s32_t spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_bloc
|
|||
spiffs_page_ix cur_pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, cur_block, cur_entry);
|
||||
|
||||
CHECK_CB(fs, SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_PROGRESS,
|
||||
(cur_block * 256)/fs->block_count, 0);
|
||||
(cur_block * 256) / fs->block_count, 0);
|
||||
|
||||
// load header
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
int reload_lu = 0;
|
||||
|
@ -536,12 +535,12 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
// build consistency bitmap for id range traversing all blocks
|
||||
while (!restart && cur_block < fs->block_count) {
|
||||
CHECK_CB(fs, SPIFFS_CHECK_PAGE, SPIFFS_CHECK_PROGRESS,
|
||||
(pix_offset*256)/(SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count) +
|
||||
((((cur_block * pages_per_scan * 256)/ (SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count))) / fs->block_count),
|
||||
(pix_offset * 256) / (SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count) +
|
||||
((((cur_block * pages_per_scan * 256) / (SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count))) / fs->block_count),
|
||||
0);
|
||||
// traverse each page except for lookup pages
|
||||
spiffs_page_ix cur_pix = SPIFFS_OBJ_LOOKUP_PAGES(fs) + SPIFFS_PAGES_PER_BLOCK(fs) * cur_block;
|
||||
while (!restart && cur_pix < SPIFFS_PAGES_PER_BLOCK(fs) * (cur_block+1)) {
|
||||
while (!restart && cur_pix < SPIFFS_PAGES_PER_BLOCK(fs) * (cur_block + 1)) {
|
||||
//if ((cur_pix & 0xff) == 0)
|
||||
// SPIFFS_CHECK_DBG("PA: processing pix "_SPIPRIpg", block "_SPIPRIbl" of pix "_SPIPRIpg", block "_SPIPRIbl"\n",
|
||||
// cur_pix, cur_block, SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count, fs->block_count);
|
||||
|
@ -549,24 +548,24 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
// read header
|
||||
spiffs_page_header p_hdr;
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
u8_t within_range = (cur_pix >= pix_offset && cur_pix < pix_offset + pages_per_scan);
|
||||
const u32_t pix_byte_ix = (cur_pix - pix_offset) / (8/bits);
|
||||
const u8_t pix_bit_ix = (cur_pix & ((8/bits)-1)) * bits;
|
||||
const u32_t pix_byte_ix = (cur_pix - pix_offset) / (8 / bits);
|
||||
const u8_t pix_bit_ix = (cur_pix & ((8 / bits) - 1)) * bits;
|
||||
|
||||
if (within_range &&
|
||||
(p_hdr.flags & SPIFFS_PH_FLAG_DELET) && (p_hdr.flags & SPIFFS_PH_FLAG_USED) == 0) {
|
||||
// used
|
||||
fs->work[pix_byte_ix] |= (1<<(pix_bit_ix + 0));
|
||||
fs->work[pix_byte_ix] |= (1 << (pix_bit_ix + 0));
|
||||
}
|
||||
if ((p_hdr.flags & SPIFFS_PH_FLAG_DELET) &&
|
||||
(p_hdr.flags & SPIFFS_PH_FLAG_IXDELE) &&
|
||||
(p_hdr.flags & (SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_USED)) == 0) {
|
||||
// found non-deleted index
|
||||
if (within_range) {
|
||||
fs->work[pix_byte_ix] |= (1<<(pix_bit_ix + 2));
|
||||
fs->work[pix_byte_ix] |= (1 << (pix_bit_ix + 2));
|
||||
}
|
||||
|
||||
// load non-deleted index
|
||||
|
@ -598,7 +597,7 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
spiffs_page_ix rpix = object_page_index[i];
|
||||
u8_t rpix_within_range = rpix >= pix_offset && rpix < pix_offset + pages_per_scan;
|
||||
|
||||
if ((rpix != (spiffs_page_ix)-1 && rpix > SPIFFS_MAX_PAGES(fs))
|
||||
if ((rpix != (spiffs_page_ix) - 1 && rpix > SPIFFS_MAX_PAGES(fs))
|
||||
|| (rpix_within_range && SPIFFS_IS_LOOKUP_PAGE(fs, rpix))) {
|
||||
|
||||
// bad reference
|
||||
|
@ -645,7 +644,7 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
// read referenced page header
|
||||
spiffs_page_header rp_hdr;
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, rpix), sizeof(spiffs_page_header), (u8_t*)&rp_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, rpix), sizeof(spiffs_page_header), (u8_t *)&rp_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
// cross reference page header check
|
||||
|
@ -688,12 +687,11 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
SPIFFS_CHECK_RES(res);
|
||||
restart = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// mark rpix as referenced
|
||||
const u32_t rpix_byte_ix = (rpix - pix_offset) / (8/bits);
|
||||
const u8_t rpix_bit_ix = (rpix & ((8/bits)-1)) * bits;
|
||||
if (fs->work[rpix_byte_ix] & (1<<(rpix_bit_ix + 1))) {
|
||||
const u32_t rpix_byte_ix = (rpix - pix_offset) / (8 / bits);
|
||||
const u8_t rpix_bit_ix = (rpix & ((8 / bits) - 1)) * bits;
|
||||
if (fs->work[rpix_byte_ix] & (1 << (rpix_bit_ix + 1))) {
|
||||
SPIFFS_CHECK_DBG("PA: pix "_SPIPRIpg" multiple referenced from page "_SPIPRIpg"\n",
|
||||
rpix, cur_pix);
|
||||
// Here, we should have fixed all broken references - getting this means there
|
||||
|
@ -709,7 +707,7 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
SPIFFS_CHECK_RES(res);
|
||||
restart = 1;
|
||||
}
|
||||
fs->work[rpix_byte_ix] |= (1<<(rpix_bit_ix + 1));
|
||||
fs->work[rpix_byte_ix] |= (1 << (rpix_bit_ix + 1));
|
||||
}
|
||||
}
|
||||
} // for all index entries
|
||||
|
@ -729,9 +727,9 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
u32_t byte_ix;
|
||||
u8_t bit_ix;
|
||||
for (byte_ix = 0; !restart && byte_ix < SPIFFS_CFG_LOG_PAGE_SZ(fs); byte_ix++) {
|
||||
for (bit_ix = 0; !restart && bit_ix < 8/bits; bit_ix ++) {
|
||||
for (bit_ix = 0; !restart && bit_ix < 8 / bits; bit_ix ++) {
|
||||
u8_t bitmask = (fs->work[byte_ix] >> (bit_ix * bits)) & 0x7;
|
||||
spiffs_page_ix cur_pix = pix_offset + byte_ix * (8/bits) + bit_ix;
|
||||
spiffs_page_ix cur_pix = pix_offset + byte_ix * (8 / bits) + bit_ix;
|
||||
|
||||
// 000 ok - free, unreferenced, not index
|
||||
|
||||
|
@ -745,13 +743,13 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
// check corresponding object index entry
|
||||
spiffs_page_header p_hdr;
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
res = spiffs_object_get_data_page_index_reference(fs, p_hdr.obj_id, p_hdr.span_ix,
|
||||
&rpix, &objix_pix);
|
||||
if (res == SPIFFS_OK) {
|
||||
if (((rpix == (spiffs_page_ix)-1 || rpix > SPIFFS_MAX_PAGES(fs)) || (SPIFFS_IS_LOOKUP_PAGE(fs, rpix)))) {
|
||||
if (((rpix == (spiffs_page_ix) - 1 || rpix > SPIFFS_MAX_PAGES(fs)) || (SPIFFS_IS_LOOKUP_PAGE(fs, rpix)))) {
|
||||
// pointing to a bad page altogether, rewrite index to this
|
||||
rewrite_ix_to_this = 1;
|
||||
SPIFFS_CHECK_DBG("PA: corresponding ref is bad: "_SPIPRIpg", rewrite to this "_SPIPRIpg"\n", rpix, cur_pix);
|
||||
|
@ -759,7 +757,7 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
|
|||
// pointing to something else, check what
|
||||
spiffs_page_header rp_hdr;
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, rpix), sizeof(spiffs_page_header), (u8_t*)&rp_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, rpix), sizeof(spiffs_page_header), (u8_t *)&rp_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (((p_hdr.obj_id & ~SPIFFS_OBJ_ID_IX_FLAG) == rp_hdr.obj_id) &&
|
||||
((rp_hdr.flags & (SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED | SPIFFS_PH_FLAG_FINAL)) ==
|
||||
|
@ -893,11 +891,11 @@ static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id o
|
|||
(void)user_const_p;
|
||||
s32_t res_c = SPIFFS_VIS_COUNTINUE;
|
||||
s32_t res = SPIFFS_OK;
|
||||
u32_t *log_ix = (u32_t*)user_var_p;
|
||||
u32_t *log_ix = (u32_t *)user_var_p;
|
||||
spiffs_obj_id *obj_table = (spiffs_obj_id *)fs->work;
|
||||
|
||||
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS,
|
||||
(cur_block * 256)/fs->block_count, 0);
|
||||
(cur_block * 256) / fs->block_count, 0);
|
||||
|
||||
if (obj_id != SPIFFS_OBJ_ID_FREE && obj_id != SPIFFS_OBJ_ID_DELETED && (obj_id & SPIFFS_OBJ_ID_IX_FLAG)) {
|
||||
spiffs_page_header p_hdr;
|
||||
|
@ -905,7 +903,7 @@ static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id o
|
|||
|
||||
// load header
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
if (p_hdr.span_ix == 0 &&
|
||||
|
|
|
@ -25,12 +25,12 @@ void Dbprintf(const char *fmt, ...);
|
|||
// ----------- >8 ------------
|
||||
|
||||
|
||||
typedef int s32_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef int16_t s16_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef int8_t s8_t;
|
||||
typedef uint8_t u8_t;
|
||||
typedef int s32_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef int16_t s16_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef int8_t s8_t;
|
||||
typedef uint8_t u8_t;
|
||||
|
||||
// compile time switches
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ s32_t spiffs_gc_quick(
|
|||
// check each entry
|
||||
while (res == SPIFFS_OK &&
|
||||
cur_entry - entry_offset < entries_per_page &&
|
||||
cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry-entry_offset];
|
||||
cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry - entry_offset];
|
||||
if (obj_id == SPIFFS_OBJ_ID_DELETED) {
|
||||
deleted_pages_in_block++;
|
||||
} else if (obj_id == SPIFFS_OBJ_ID_FREE) {
|
||||
|
@ -85,7 +85,7 @@ s32_t spiffs_gc_quick(
|
|||
if (res == 1) res = SPIFFS_OK;
|
||||
|
||||
if (res == SPIFFS_OK &&
|
||||
deleted_pages_in_block + free_pages_in_block == SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs) &&
|
||||
deleted_pages_in_block + free_pages_in_block == SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs) &&
|
||||
free_pages_in_block <= max_free_pages) {
|
||||
// found a fully deleted block
|
||||
fs->stats_p_deleted -= deleted_pages_in_block;
|
||||
|
@ -111,7 +111,7 @@ s32_t spiffs_gc_check(
|
|||
u32_t len) {
|
||||
s32_t res;
|
||||
s32_t free_pages =
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->block_count-2)
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->block_count - 2)
|
||||
- fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
int tries = 0;
|
||||
|
||||
|
@ -133,8 +133,8 @@ s32_t spiffs_gc_check(
|
|||
do {
|
||||
SPIFFS_GC_DBG("\ngc_check #"_SPIPRIi": run gc free_blocks:"_SPIPRIi" pfree:"_SPIPRIi" pallo:"_SPIPRIi" pdele:"_SPIPRIi" ["_SPIPRIi"] len:"_SPIPRIi" of "_SPIPRIi"\n",
|
||||
tries,
|
||||
fs->free_blocks, free_pages, fs->stats_p_allocated, fs->stats_p_deleted, (free_pages+fs->stats_p_allocated+fs->stats_p_deleted),
|
||||
len, (u32_t)(free_pages*SPIFFS_DATA_PAGE_SIZE(fs)));
|
||||
fs->free_blocks, free_pages, fs->stats_p_allocated, fs->stats_p_deleted, (free_pages + fs->stats_p_allocated + fs->stats_p_deleted),
|
||||
len, (u32_t)(free_pages * SPIFFS_DATA_PAGE_SIZE(fs)));
|
||||
|
||||
spiffs_block_ix *cands;
|
||||
int count;
|
||||
|
@ -179,12 +179,12 @@ s32_t spiffs_gc_check(
|
|||
}
|
||||
|
||||
} while (++tries < SPIFFS_GC_MAX_RUNS && (fs->free_blocks <= 2 ||
|
||||
(s32_t)len > free_pages*(s32_t)SPIFFS_DATA_PAGE_SIZE(fs)));
|
||||
(s32_t)len > free_pages * (s32_t)SPIFFS_DATA_PAGE_SIZE(fs)));
|
||||
|
||||
free_pages =
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs)) * (fs->block_count - 2)
|
||||
- fs->stats_p_allocated - fs->stats_p_deleted;
|
||||
if ((s32_t)len > free_pages*(s32_t)SPIFFS_DATA_PAGE_SIZE(fs)) {
|
||||
if ((s32_t)len > free_pages * (s32_t)SPIFFS_DATA_PAGE_SIZE(fs)) {
|
||||
res = SPIFFS_ERR_FULL;
|
||||
}
|
||||
|
||||
|
@ -214,8 +214,8 @@ s32_t spiffs_gc_erase_page_stats(
|
|||
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
// check each entry
|
||||
while (res == SPIFFS_OK &&
|
||||
cur_entry - entry_offset < entries_per_page && cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry-entry_offset];
|
||||
cur_entry - entry_offset < entries_per_page && cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry - entry_offset];
|
||||
if (obj_id == SPIFFS_OBJ_ID_FREE) {
|
||||
} else if (obj_id == SPIFFS_OBJ_ID_DELETED) {
|
||||
dele++;
|
||||
|
@ -246,7 +246,7 @@ s32_t spiffs_gc_find_candidate(
|
|||
int cur_entry = 0;
|
||||
|
||||
// using fs->work area as sorted candidate memory, (spiffs_block_ix)cand_bix/(s32_t)score
|
||||
int max_candidates = MIN(fs->block_count, (SPIFFS_CFG_LOG_PAGE_SZ(fs)-8)/(sizeof(spiffs_block_ix) + sizeof(s32_t)));
|
||||
int max_candidates = MIN(fs->block_count, (SPIFFS_CFG_LOG_PAGE_SZ(fs) - 8) / (sizeof(spiffs_block_ix) + sizeof(s32_t)));
|
||||
*candidate_count = 0;
|
||||
memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
|
||||
|
@ -255,7 +255,7 @@ s32_t spiffs_gc_find_candidate(
|
|||
s32_t *cand_scores = (s32_t *)(fs->work + max_candidates * sizeof(spiffs_block_ix));
|
||||
|
||||
// align cand_scores on s32_t boundary
|
||||
cand_scores = (s32_t*)(((intptr_t)cand_scores + sizeof(intptr_t) - 1) & ~(sizeof(intptr_t) - 1));
|
||||
cand_scores = (s32_t *)(((intptr_t)cand_scores + sizeof(intptr_t) - 1) & ~(sizeof(intptr_t) - 1));
|
||||
|
||||
*block_candidates = cand_blocks;
|
||||
|
||||
|
@ -275,8 +275,8 @@ s32_t spiffs_gc_find_candidate(
|
|||
// check each entry
|
||||
while (res == SPIFFS_OK &&
|
||||
cur_entry - entry_offset < entries_per_page &&
|
||||
cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry-entry_offset];
|
||||
cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry - entry_offset];
|
||||
if (obj_id == SPIFFS_OBJ_ID_FREE) {
|
||||
// when a free entry is encountered, scan logic ensures that all following entries are free also
|
||||
res = 1; // kill object lu loop
|
||||
|
@ -316,7 +316,7 @@ s32_t spiffs_gc_find_candidate(
|
|||
int cand_ix = 0;
|
||||
SPIFFS_GC_DBG("gc_check: bix:"_SPIPRIbl" del:"_SPIPRIi" use:"_SPIPRIi" score:"_SPIPRIi"\n", cur_block, deleted_pages_in_block, used_pages_in_block, score);
|
||||
while (cand_ix < max_candidates) {
|
||||
if (cand_blocks[cand_ix] == (spiffs_block_ix)-1) {
|
||||
if (cand_blocks[cand_ix] == (spiffs_block_ix) - 1) {
|
||||
cand_blocks[cand_ix] = cur_block;
|
||||
cand_scores[cand_ix] = score;
|
||||
break;
|
||||
|
@ -392,7 +392,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||
|
||||
if (fs->free_cursor_block_ix == bix) {
|
||||
// move free cursor to next block, cannot use free pages from the block we want to clean
|
||||
fs->free_cursor_block_ix = (bix+1)%fs->block_count;
|
||||
fs->free_cursor_block_ix = (bix + 1) % fs->block_count;
|
||||
fs->free_cursor_obj_lu_entry = 0;
|
||||
SPIFFS_GC_DBG("gc_clean: move free cursor to block "_SPIPRIbl"\n", fs->free_cursor_block_ix);
|
||||
}
|
||||
|
@ -412,8 +412,8 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
// check each object lookup entry
|
||||
while (scan && res == SPIFFS_OK &&
|
||||
cur_entry - entry_offset < entries_per_page && cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry-entry_offset];
|
||||
cur_entry - entry_offset < entries_per_page && cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry - entry_offset];
|
||||
cur_pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, bix, cur_entry);
|
||||
|
||||
// act upon object id depending on gc state
|
||||
|
@ -436,7 +436,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||
if (obj_id == gc.cur_obj_id) {
|
||||
spiffs_page_header p_hdr;
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_GC_DBG("gc_clean: MOVE_DATA found data page "_SPIPRIid":"_SPIPRIsp" @ "_SPIPRIpg"\n", gc.cur_obj_id, p_hdr.span_ix, cur_pix);
|
||||
if (SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, p_hdr.span_ix) != gc.cur_objix_spix) {
|
||||
|
@ -465,11 +465,11 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||
// update memory representation of object index page with new data page
|
||||
if (gc.cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[p_hdr.span_ix] = new_data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[p_hdr.span_ix] = new_data_pix;
|
||||
SPIFFS_GC_DBG("gc_clean: MOVE_DATA wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, p_hdr.span_ix));
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, p_hdr.span_ix)] = new_data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, p_hdr.span_ix)] = new_data_pix;
|
||||
SPIFFS_GC_DBG("gc_clean: MOVE_DATA wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, p_hdr.span_ix));
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||
spiffs_page_ix new_pix;
|
||||
// load header
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (p_hdr.flags & SPIFFS_PH_FLAG_DELET) {
|
||||
// move page
|
||||
|
@ -534,7 +534,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||
cur_entry = 0; // restart scan from start
|
||||
gc.state = MOVE_OBJ_DATA;
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t*)&p_hdr);
|
||||
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix), sizeof(spiffs_page_header), (u8_t *)&p_hdr);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
gc.cur_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, p_hdr.span_ix);
|
||||
SPIFFS_GC_DBG("gc_clean: FIND_DATA find objix span_ix:"_SPIPRIsp"\n", gc.cur_objix_spix);
|
||||
|
|
|
@ -96,30 +96,30 @@ s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work,
|
|||
fs->lu_work = &work[SPIFFS_CFG_LOG_PAGE_SZ(fs)];
|
||||
memset(fd_space, 0, fd_space_size);
|
||||
// align fd_space pointer to pointer size byte boundary
|
||||
u8_t ptr_size = sizeof(void*);
|
||||
u8_t addr_lsb = ((u8_t)(intptr_t)fd_space) & (ptr_size-1);
|
||||
u8_t ptr_size = sizeof(void *);
|
||||
u8_t addr_lsb = ((u8_t)(intptr_t)fd_space) & (ptr_size - 1);
|
||||
if (addr_lsb) {
|
||||
fd_space += (ptr_size-addr_lsb);
|
||||
fd_space_size -= (ptr_size-addr_lsb);
|
||||
fd_space += (ptr_size - addr_lsb);
|
||||
fd_space_size -= (ptr_size - addr_lsb);
|
||||
}
|
||||
fs->fd_space = fd_space;
|
||||
fs->fd_count = (fd_space_size/sizeof(spiffs_fd));
|
||||
fs->fd_count = (fd_space_size / sizeof(spiffs_fd));
|
||||
|
||||
// align cache pointer to 4 byte boundary
|
||||
addr_lsb = ((u8_t)(intptr_t)cache) & (ptr_size-1);
|
||||
addr_lsb = ((u8_t)(intptr_t)cache) & (ptr_size - 1);
|
||||
if (addr_lsb) {
|
||||
u8_t *cache_8 = (u8_t *)cache;
|
||||
cache_8 += (ptr_size-addr_lsb);
|
||||
cache_8 += (ptr_size - addr_lsb);
|
||||
cache = cache_8;
|
||||
cache_size -= (ptr_size-addr_lsb);
|
||||
cache_size -= (ptr_size - addr_lsb);
|
||||
}
|
||||
if (cache_size & (ptr_size-1)) {
|
||||
cache_size -= (cache_size & (ptr_size-1));
|
||||
if (cache_size & (ptr_size - 1)) {
|
||||
cache_size -= (cache_size & (ptr_size - 1));
|
||||
}
|
||||
|
||||
#if SPIFFS_CACHE
|
||||
fs->cache = cache;
|
||||
fs->cache_size = (cache_size > (SPIFFS_CFG_LOG_PAGE_SZ(fs)*32)) ? SPIFFS_CFG_LOG_PAGE_SZ(fs)*32 : cache_size;
|
||||
fs->cache_size = (cache_size > (SPIFFS_CFG_LOG_PAGE_SZ(fs) * 32)) ? SPIFFS_CFG_LOG_PAGE_SZ(fs) * 32 : cache_size;
|
||||
spiffs_cache_init(fs);
|
||||
#endif
|
||||
|
||||
|
@ -185,7 +185,9 @@ void SPIFFS_clearerr(spiffs *fs) {
|
|||
s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode) {
|
||||
SPIFFS_API_DBG("%s '%s'\n", __func__, path);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)path; (void)mode;
|
||||
(void)fs;
|
||||
(void)path;
|
||||
(void)mode;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
(void)mode;
|
||||
|
@ -198,9 +200,9 @@ s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode) {
|
|||
spiffs_obj_id obj_id;
|
||||
s32_t res;
|
||||
|
||||
res = spiffs_obj_lu_find_free_obj_id(fs, &obj_id, (const u8_t*)path);
|
||||
res = spiffs_obj_lu_find_free_obj_id(fs, &obj_id, (const u8_t *)path);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
res = spiffs_object_create(fs, obj_id, (const u8_t*)path, 0, SPIFFS_TYPE_FILE, 0);
|
||||
res = spiffs_object_create(fs, obj_id, (const u8_t *)path, 0, SPIFFS_TYPE_FILE, 0);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
SPIFFS_UNLOCK(fs);
|
||||
return 0;
|
||||
|
@ -228,7 +230,7 @@ spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs
|
|||
s32_t res = spiffs_fd_find_new(fs, &fd, path);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)path, &pix);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t *)path, &pix);
|
||||
if ((flags & SPIFFS_O_CREAT) == 0) {
|
||||
if (res < SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
|
@ -253,7 +255,7 @@ spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs
|
|||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
res = spiffs_object_create(fs, obj_id, (const u8_t*)path, 0, SPIFFS_TYPE_FILE, &pix);
|
||||
res = spiffs_object_create(fs, obj_id, (const u8_t *)path, 0, SPIFFS_TYPE_FILE, &pix);
|
||||
if (res < SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
|
@ -401,7 +403,7 @@ static s32_t spiffs_hydro_read(spiffs *fs, spiffs_file fh, void *buf, s32_t len)
|
|||
if (avail <= 0) {
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, SPIFFS_ERR_END_OF_OBJECT);
|
||||
}
|
||||
res = spiffs_object_read(fd, fd->fdoffset, avail, (u8_t*)buf);
|
||||
res = spiffs_object_read(fd, fd->fdoffset, avail, (u8_t *)buf);
|
||||
if (res == SPIFFS_ERR_END_OF_OBJECT) {
|
||||
fd->fdoffset += avail;
|
||||
SPIFFS_UNLOCK(fs);
|
||||
|
@ -412,7 +414,7 @@ static s32_t spiffs_hydro_read(spiffs *fs, spiffs_file fh, void *buf, s32_t len)
|
|||
}
|
||||
} else {
|
||||
// reading within file size
|
||||
res = spiffs_object_read(fd, fd->fdoffset, len, (u8_t*)buf);
|
||||
res = spiffs_object_read(fd, fd->fdoffset, len, (u8_t *)buf);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
}
|
||||
fd->fdoffset += len;
|
||||
|
@ -459,7 +461,10 @@ static s32_t spiffs_hydro_write(spiffs *fs, spiffs_fd *fd, void *buf, u32_t offs
|
|||
s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) {
|
||||
SPIFFS_API_DBG("%s "_SPIPRIfd " "_SPIPRIi "\n", __func__, fh, len);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)fh; (void)buf; (void)len;
|
||||
(void)fs;
|
||||
(void)fh;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
|
@ -512,8 +517,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) {
|
|||
// have a cached page for this fd already, check cache page boundaries
|
||||
if (offset < fd->cache_page->ucache.swrc.offset || // writing before cache
|
||||
offset > fd->cache_page->ucache.swrc.offset + fd->cache_page->ucache.swrc.size || // writing after cache
|
||||
offset + len > fd->cache_page->ucache.swrc.offset + SPIFFS_CFG_LOG_PAGE_SZ(fs)) // writing beyond cache page
|
||||
{
|
||||
offset + len > fd->cache_page->ucache.swrc.offset + SPIFFS_CFG_LOG_PAGE_SZ(fs)) { // writing beyond cache page
|
||||
// boundary violation, write back cache first and allocate new
|
||||
SPIFFS_CACHE_DBG("CACHE_WR_DUMP: dumping cache page "_SPIPRIi" for fd "_SPIPRIfd":"_SPIPRIid", boundary viol, offs:"_SPIPRIi" size:"_SPIPRIi"\n",
|
||||
fd->cache_page->ix, fd->file_nbr, fd->obj_id, fd->cache_page->ucache.swrc.offset, fd->cache_page->ucache.swrc.size);
|
||||
|
@ -547,8 +551,8 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) {
|
|||
u8_t *cpage_data = spiffs_get_cache_page(fs, cache, fd->cache_page->ix);
|
||||
#ifdef _SPIFFS_TEST
|
||||
{
|
||||
intptr_t __a1 = (u8_t*)&cpage_data[offset_in_cpage]-(u8_t*)cache;
|
||||
intptr_t __a2 = (u8_t*)&cpage_data[offset_in_cpage]+len-(u8_t*)cache;
|
||||
intptr_t __a1 = (u8_t *)&cpage_data[offset_in_cpage] - (u8_t *)cache;
|
||||
intptr_t __a2 = (u8_t *)&cpage_data[offset_in_cpage] + len - (u8_t *)cache;
|
||||
intptr_t __b = sizeof(spiffs_cache) + cache->cpage_count * (sizeof(spiffs_cache_page) + SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
if (__a1 > __b || __a2 > __b) {
|
||||
printf("FATAL OOB: CACHE_WR: memcpy to cache buffer ixs:%4ld..%4ld of %4ld\n", __a1, __a2, __b);
|
||||
|
@ -596,7 +600,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) {
|
|||
}
|
||||
|
||||
s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
|
||||
SPIFFS_API_DBG("%s "_SPIPRIfd " "_SPIPRIi " %s\n", __func__, fh, offs, (const char* []){"SET","CUR","END","???"}[MIN(whence,3)]);
|
||||
SPIFFS_API_DBG("%s "_SPIPRIfd " "_SPIPRIi " %s\n", __func__, fh, offs, (const char *[]) {"SET", "CUR", "END", "???"}[MIN(whence, 3)]);
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
SPIFFS_LOCK(fs);
|
||||
|
@ -615,7 +619,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
|
|||
|
||||
switch (whence) {
|
||||
case SPIFFS_SEEK_CUR:
|
||||
offs = fd->fdoffset+offs;
|
||||
offs = fd->fdoffset + offs;
|
||||
break;
|
||||
case SPIFFS_SEEK_END:
|
||||
offs = file_size + offs;
|
||||
|
@ -630,7 +634,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
|
|||
}
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
spiffs_span_ix data_spix = (offs > 0 ? (offs-1) : 0) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
spiffs_span_ix data_spix = (offs > 0 ? (offs - 1) : 0) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
spiffs_span_ix objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, data_spix);
|
||||
if (fd->cursor_objix_spix != objix_spix) {
|
||||
spiffs_page_ix pix;
|
||||
|
@ -650,7 +654,8 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
|
|||
s32_t SPIFFS_remove(spiffs *fs, const char *path) {
|
||||
SPIFFS_API_DBG("%s '%s'\n", __func__, path);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)path;
|
||||
(void)fs;
|
||||
(void)path;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
|
@ -667,13 +672,13 @@ s32_t SPIFFS_remove(spiffs *fs, const char *path) {
|
|||
res = spiffs_fd_find_new(fs, &fd, 0);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)path, &pix);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t *)path, &pix);
|
||||
if (res != SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_open_by_page(fs, pix, fd, 0,0);
|
||||
res = spiffs_object_open_by_page(fs, pix, fd, 0, 0);
|
||||
if (res != SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
|
@ -693,7 +698,8 @@ s32_t SPIFFS_remove(spiffs *fs, const char *path) {
|
|||
s32_t SPIFFS_fremove(spiffs *fs, spiffs_file fh) {
|
||||
SPIFFS_API_DBG("%s "_SPIPRIfd "\n", __func__, fh);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)fh;
|
||||
(void)fs;
|
||||
(void)fh;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
|
@ -729,13 +735,13 @@ static s32_t spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, spiffs_file fh, spi
|
|||
(void)fh;
|
||||
spiffs_page_object_ix_header objix_hdr;
|
||||
spiffs_obj_id obj_id;
|
||||
s32_t res =_spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ, fh,
|
||||
s32_t res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ, fh,
|
||||
SPIFFS_PAGE_TO_PADDR(fs, pix), sizeof(spiffs_page_object_ix_header), (u8_t *)&objix_hdr);
|
||||
SPIFFS_API_CHECK_RES(fs, res);
|
||||
|
||||
u32_t obj_id_addr = SPIFFS_BLOCK_TO_PADDR(fs, SPIFFS_BLOCK_FOR_PAGE(fs , pix)) +
|
||||
u32_t obj_id_addr = SPIFFS_BLOCK_TO_PADDR(fs, SPIFFS_BLOCK_FOR_PAGE(fs, pix)) +
|
||||
SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, pix) * sizeof(spiffs_obj_id);
|
||||
res =_spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, fh,
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, fh,
|
||||
obj_id_addr, sizeof(spiffs_obj_id), (u8_t *)&obj_id);
|
||||
SPIFFS_API_CHECK_RES(fs, res);
|
||||
|
||||
|
@ -763,7 +769,7 @@ s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s) {
|
|||
s32_t res;
|
||||
spiffs_page_ix pix;
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)path, &pix);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t *)path, &pix);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_stat_pix(fs, pix, 0, s);
|
||||
|
@ -843,7 +849,7 @@ s32_t SPIFFS_fflush(spiffs *fs, spiffs_file fh) {
|
|||
SPIFFS_LOCK(fs);
|
||||
fh = SPIFFS_FH_UNOFFS(fs, fh);
|
||||
res = spiffs_fflush_cache(fs, fh);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs,res);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
SPIFFS_UNLOCK(fs);
|
||||
#endif
|
||||
|
||||
|
@ -874,7 +880,9 @@ s32_t SPIFFS_close(spiffs *fs, spiffs_file fh) {
|
|||
s32_t SPIFFS_rename(spiffs *fs, const char *old_path, const char *new_path) {
|
||||
SPIFFS_API_DBG("%s %s %s\n", __func__, old_path, new_path);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)old_path; (void)new_path;
|
||||
(void)fs;
|
||||
(void)old_path;
|
||||
(void)new_path;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
|
@ -888,10 +896,10 @@ s32_t SPIFFS_rename(spiffs *fs, const char *old_path, const char *new_path) {
|
|||
spiffs_page_ix pix_old, pix_dummy;
|
||||
spiffs_fd *fd;
|
||||
|
||||
s32_t res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)old_path, &pix_old);
|
||||
s32_t res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t *)old_path, &pix_old);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)new_path, &pix_dummy);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t *)new_path, &pix_dummy);
|
||||
if (res == SPIFFS_ERR_NOT_FOUND) {
|
||||
res = SPIFFS_OK;
|
||||
} else if (res == SPIFFS_OK) {
|
||||
|
@ -908,7 +916,7 @@ s32_t SPIFFS_rename(spiffs *fs, const char *old_path, const char *new_path) {
|
|||
}
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id, fd->objix_hdr_pix, 0, (const u8_t*)new_path,
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id, fd->objix_hdr_pix, 0, (const u8_t *)new_path,
|
||||
0, 0, &pix_dummy);
|
||||
#if SPIFFS_TEMPORAL_FD_CACHE
|
||||
if (res == SPIFFS_OK) {
|
||||
|
@ -929,7 +937,9 @@ s32_t SPIFFS_rename(spiffs *fs, const char *old_path, const char *new_path) {
|
|||
#if SPIFFS_OBJ_META_LEN
|
||||
s32_t SPIFFS_update_meta(spiffs *fs, const char *name, const void *meta) {
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)name; (void)meta;
|
||||
(void)fs;
|
||||
(void)name;
|
||||
(void)meta;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
|
@ -939,7 +949,7 @@ s32_t SPIFFS_update_meta(spiffs *fs, const char *name, const void *meta) {
|
|||
spiffs_page_ix pix, pix_dummy;
|
||||
spiffs_fd *fd;
|
||||
|
||||
s32_t res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)name, &pix);
|
||||
s32_t res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t *)name, &pix);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_fd_find_new(fs, &fd, 0);
|
||||
|
@ -966,7 +976,9 @@ s32_t SPIFFS_update_meta(spiffs *fs, const char *name, const void *meta) {
|
|||
|
||||
s32_t SPIFFS_fupdate_meta(spiffs *fs, spiffs_file fh, const void *meta) {
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)fh; (void)meta;
|
||||
(void)fs;
|
||||
(void)fh;
|
||||
(void)meta;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
|
@ -1041,7 +1053,7 @@ static s32_t spiffs_read_dir_v(
|
|||
objix_hdr.p_hdr.span_ix == 0 &&
|
||||
(objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
|
||||
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
|
||||
struct spiffs_dirent *e = (struct spiffs_dirent*)user_var_p;
|
||||
struct spiffs_dirent *e = (struct spiffs_dirent *)user_var_p;
|
||||
e->obj_id = obj_id;
|
||||
strcpy((char *)e->name, (char *)objix_hdr.name);
|
||||
e->type = objix_hdr.type;
|
||||
|
@ -1149,7 +1161,8 @@ s32_t SPIFFS_info(spiffs *fs, u32_t *total, u32_t *used) {
|
|||
s32_t SPIFFS_gc_quick(spiffs *fs, u16_t max_free_pages) {
|
||||
SPIFFS_API_DBG("%s "_SPIPRIi "\n", __func__, max_free_pages);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)max_free_pages;
|
||||
(void)fs;
|
||||
(void)max_free_pages;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
s32_t res;
|
||||
|
@ -1169,7 +1182,8 @@ s32_t SPIFFS_gc_quick(spiffs *fs, u16_t max_free_pages) {
|
|||
s32_t SPIFFS_gc(spiffs *fs, u32_t size) {
|
||||
SPIFFS_API_DBG("%s "_SPIPRIi "\n", __func__, size);
|
||||
#if SPIFFS_READ_ONLY
|
||||
(void)fs; (void)size;
|
||||
(void)fs;
|
||||
(void)size;
|
||||
return SPIFFS_ERR_RO_NOT_IMPL;
|
||||
#else
|
||||
s32_t res;
|
||||
|
@ -1333,7 +1347,7 @@ s32_t SPIFFS_ix_remap(spiffs *fs, spiffs_file fh, u32_t offset) {
|
|||
// moving beyond range
|
||||
memset(&map->map_buf, 0, vec_len * sizeof(spiffs_page_ix));
|
||||
// populate_ix_map is inclusive
|
||||
res = spiffs_populate_ix_map(fs, fd, 0, vec_len-1);
|
||||
res = spiffs_populate_ix_map(fs, fd, 0, vec_len - 1);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
} else if (spix_diff > 0) {
|
||||
// diff positive
|
||||
|
@ -1343,7 +1357,7 @@ s32_t SPIFFS_ix_remap(spiffs *fs, spiffs_file fh, u32_t offset) {
|
|||
// memset is non-inclusive
|
||||
memset(&map->map_buf[vec_len - spix_diff], 0, spix_diff * sizeof(spiffs_page_ix));
|
||||
// populate_ix_map is inclusive
|
||||
res = spiffs_populate_ix_map(fs, fd, vec_len - spix_diff, vec_len-1);
|
||||
res = spiffs_populate_ix_map(fs, fd, vec_len - spix_diff, vec_len - 1);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
} else {
|
||||
// diff negative
|
||||
|
@ -1366,7 +1380,7 @@ s32_t SPIFFS_ix_remap(spiffs *fs, spiffs_file fh, u32_t offset) {
|
|||
s32_t SPIFFS_bytes_to_ix_map_entries(spiffs *fs, u32_t bytes) {
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
// always add one extra page, the offset might change to the middle of a page
|
||||
return (bytes + SPIFFS_DATA_PAGE_SIZE(fs) ) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
return (bytes + SPIFFS_DATA_PAGE_SIZE(fs)) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
}
|
||||
|
||||
s32_t SPIFFS_ix_map_entries_to_bytes(spiffs *fs, u32_t map_page_ix_entries) {
|
||||
|
@ -1398,8 +1412,8 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
|||
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||
// check each entry
|
||||
while (res == SPIFFS_OK &&
|
||||
cur_entry - entry_offset < entries_per_page && cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry-entry_offset];
|
||||
cur_entry - entry_offset < entries_per_page && cur_entry < (int)(SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))) {
|
||||
spiffs_obj_id obj_id = obj_lu_buf[cur_entry - entry_offset];
|
||||
if (cur_entry == 0) {
|
||||
spiffs_printf(_SPIPRIbl" ", bix);
|
||||
} else if ((cur_entry & 0x3f) == 0) {
|
||||
|
@ -1409,7 +1423,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
|||
spiffs_printf(SPIFFS_TEST_VIS_FREE_STR);
|
||||
} else if (obj_id == SPIFFS_OBJ_ID_DELETED) {
|
||||
spiffs_printf(SPIFFS_TEST_VIS_DELE_STR);
|
||||
} else if (obj_id & SPIFFS_OBJ_ID_IX_FLAG){
|
||||
} else if (obj_id & SPIFFS_OBJ_ID_IX_FLAG) {
|
||||
spiffs_printf(SPIFFS_TEST_VIS_INDX_STR(obj_id));
|
||||
} else {
|
||||
spiffs_printf(SPIFFS_TEST_VIS_DATA_STR(obj_id));
|
||||
|
@ -1428,7 +1442,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
|||
sizeof(spiffs_obj_id), (u8_t *)&erase_count);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
if (erase_count != (spiffs_obj_id)-1) {
|
||||
if (erase_count != (spiffs_obj_id) - 1) {
|
||||
spiffs_printf("\tera_cnt: "_SPIPRIi"\n", erase_count);
|
||||
} else {
|
||||
spiffs_printf("\tera_cnt: N/A\n");
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
static s32_t spiffs_page_data_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
if (pix == (spiffs_page_ix)-1) {
|
||||
if (pix == (spiffs_page_ix) - 1) {
|
||||
// referring to page 0xffff...., bad object index
|
||||
return SPIFFS_ERR_INDEX_REF_FREE;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ static s32_t spiffs_page_data_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pi
|
|||
#if !SPIFFS_READ_ONLY
|
||||
static s32_t spiffs_page_index_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
if (pix == (spiffs_page_ix)-1) {
|
||||
if (pix == (spiffs_page_ix) - 1) {
|
||||
// referring to page 0xffff...., bad object index
|
||||
return SPIFFS_ERR_INDEX_FREE;
|
||||
}
|
||||
|
@ -169,15 +169,14 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
|||
// check each entry
|
||||
while (res == SPIFFS_OK &&
|
||||
cur_entry - entry_offset < entries_per_page && // for non-last obj lookup pages
|
||||
cur_entry < (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) // for last obj lookup page
|
||||
{
|
||||
if ((flags & SPIFFS_VIS_CHECK_ID) == 0 || obj_lu_buf[cur_entry-entry_offset] == obj_id) {
|
||||
cur_entry < (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) { // for last obj lookup page
|
||||
if ((flags & SPIFFS_VIS_CHECK_ID) == 0 || obj_lu_buf[cur_entry - entry_offset] == obj_id) {
|
||||
if (block_ix) *block_ix = cur_block;
|
||||
if (lu_entry) *lu_entry = cur_entry;
|
||||
if (v) {
|
||||
res = v(
|
||||
fs,
|
||||
(flags & SPIFFS_VIS_CHECK_PH) ? obj_id : obj_lu_buf[cur_entry-entry_offset],
|
||||
(flags & SPIFFS_VIS_CHECK_PH) ? obj_id : obj_lu_buf[cur_entry - entry_offset],
|
||||
cur_block,
|
||||
cur_entry,
|
||||
user_const_p,
|
||||
|
@ -298,7 +297,7 @@ s32_t spiffs_probe(
|
|||
// check that the order is correct, take aborted erases in calculation
|
||||
// first block aborted erase
|
||||
if (magic[0] == (spiffs_obj_id)(-1) && bix_count[1] - bix_count[2] == 1) {
|
||||
return (bix_count[1]+1) * cfg->log_block_size;
|
||||
return (bix_count[1] + 1) * cfg->log_block_size;
|
||||
}
|
||||
// second block aborted erase
|
||||
if (magic[1] == (spiffs_obj_id)(-1) && bix_count[0] - bix_count[2] == 2) {
|
||||
|
@ -352,7 +351,7 @@ s32_t spiffs_obj_lu_scan(
|
|||
spiffs_block_ix bix;
|
||||
int entry;
|
||||
#if SPIFFS_USE_MAGIC
|
||||
spiffs_block_ix unerased_bix = (spiffs_block_ix)-1;
|
||||
spiffs_block_ix unerased_bix = (spiffs_block_ix) - 1;
|
||||
#endif
|
||||
|
||||
// find out erase count
|
||||
|
@ -366,12 +365,12 @@ s32_t spiffs_obj_lu_scan(
|
|||
spiffs_obj_id magic;
|
||||
res = _spiffs_rd(fs,
|
||||
SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_MAGIC_PADDR(fs, bix) ,
|
||||
0, SPIFFS_MAGIC_PADDR(fs, bix),
|
||||
sizeof(spiffs_obj_id), (u8_t *)&magic);
|
||||
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (magic != SPIFFS_MAGIC(fs, bix)) {
|
||||
if (unerased_bix == (spiffs_block_ix)-1) {
|
||||
if (unerased_bix == (spiffs_block_ix) - 1) {
|
||||
// allow one unerased block as it might be powered down during an erase
|
||||
unerased_bix = bix;
|
||||
} else {
|
||||
|
@ -383,7 +382,7 @@ s32_t spiffs_obj_lu_scan(
|
|||
spiffs_obj_id erase_count;
|
||||
res = _spiffs_rd(fs,
|
||||
SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_ERASE_COUNT_PADDR(fs, bix) ,
|
||||
0, SPIFFS_ERASE_COUNT_PADDR(fs, bix),
|
||||
sizeof(spiffs_obj_id), (u8_t *)&erase_count);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (erase_count != SPIFFS_OBJ_ID_FREE) {
|
||||
|
@ -396,17 +395,17 @@ s32_t spiffs_obj_lu_scan(
|
|||
if (erase_count_min == 0 && erase_count_max == SPIFFS_OBJ_ID_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_OBJ_ID_FREE) / 2) {
|
||||
// wrap, take min
|
||||
erase_count_final = erase_count_min+1;
|
||||
erase_count_final = erase_count_min + 1;
|
||||
} else {
|
||||
erase_count_final = erase_count_max+1;
|
||||
erase_count_final = erase_count_max + 1;
|
||||
}
|
||||
|
||||
fs->max_erase_count = erase_count_final;
|
||||
|
||||
#if SPIFFS_USE_MAGIC
|
||||
if (unerased_bix != (spiffs_block_ix)-1) {
|
||||
if (unerased_bix != (spiffs_block_ix) - 1) {
|
||||
// found one unerased block, remedy
|
||||
SPIFFS_DBG("mount: erase block "_SPIPRIbl"\n", bix);
|
||||
#if SPIFFS_READ_ONLY
|
||||
|
@ -513,10 +512,10 @@ static s32_t spiffs_obj_lu_find_id_and_span_v(
|
|||
SPIFFS_PAGE_TO_PADDR(fs, pix), sizeof(spiffs_page_header), (u8_t *)&ph);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (ph.obj_id == obj_id &&
|
||||
ph.span_ix == *((spiffs_span_ix*)user_var_p) &&
|
||||
ph.span_ix == *((spiffs_span_ix *)user_var_p) &&
|
||||
(ph.flags & (SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED)) == SPIFFS_PH_FLAG_DELET &&
|
||||
!((obj_id & SPIFFS_OBJ_ID_IX_FLAG) && (ph.flags & SPIFFS_PH_FLAG_IXDELE) == 0 && ph.span_ix == 0) &&
|
||||
(user_const_p == 0 || *((const spiffs_page_ix*)user_const_p) != pix)) {
|
||||
(user_const_p == 0 || *((const spiffs_page_ix *)user_const_p) != pix)) {
|
||||
return SPIFFS_OK;
|
||||
} else {
|
||||
return SPIFFS_VIS_COUNTINUE;
|
||||
|
@ -634,13 +633,13 @@ static void spiffs_update_ix_map(spiffs *fs,
|
|||
spiffs_page_ix objix_data_pix;
|
||||
if (objix_spix == 0) {
|
||||
// get data page from object index header page
|
||||
objix_data_pix = ((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix_header)))[map_spix];
|
||||
objix_data_pix = ((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix_header)))[map_spix];
|
||||
} else {
|
||||
// get data page from object index page
|
||||
objix_data_pix = ((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, map_spix)];
|
||||
objix_data_pix = ((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, map_spix)];
|
||||
}
|
||||
|
||||
if (objix_data_pix == (spiffs_page_ix)-1) {
|
||||
if (objix_data_pix == (spiffs_page_ix) - 1) {
|
||||
// reached end of object, abort
|
||||
break;
|
||||
}
|
||||
|
@ -770,7 +769,7 @@ s32_t spiffs_page_allocate_data(
|
|||
|
||||
// occupy page in object lookup
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_UPDT,
|
||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + entry * sizeof(spiffs_obj_id), sizeof(spiffs_obj_id), (u8_t*)&obj_id);
|
||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + entry * sizeof(spiffs_obj_id), sizeof(spiffs_obj_id), (u8_t *)&obj_id);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
fs->stats_p_allocated++;
|
||||
|
@ -778,13 +777,13 @@ s32_t spiffs_page_allocate_data(
|
|||
// write page header
|
||||
ph->flags &= ~SPIFFS_PH_FLAG_USED;
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry), sizeof(spiffs_page_header), (u8_t*)ph);
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry), sizeof(spiffs_page_header), (u8_t *)ph);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
// write page data
|
||||
if (data) {
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
|
||||
0,SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry) + sizeof(spiffs_page_header) + page_offs, len, data);
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry) + sizeof(spiffs_page_header) + page_offs, len, data);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
|
||||
|
@ -934,7 +933,7 @@ s32_t spiffs_object_create(
|
|||
|
||||
// occupy page in object lookup
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_UPDT,
|
||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + entry * sizeof(spiffs_obj_id), sizeof(spiffs_obj_id), (u8_t*)&obj_id);
|
||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + entry * sizeof(spiffs_obj_id), sizeof(spiffs_obj_id), (u8_t *)&obj_id);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
fs->stats_p_allocated++;
|
||||
|
@ -945,7 +944,7 @@ s32_t spiffs_object_create(
|
|||
oix_hdr.p_hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_USED);
|
||||
oix_hdr.type = type;
|
||||
oix_hdr.size = SPIFFS_UNDEFINED_LEN; // keep ones so we can update later without wasting this page
|
||||
strncpy((char*)oix_hdr.name, (const char*)name, SPIFFS_OBJ_NAME_LEN);
|
||||
strncpy((char *)oix_hdr.name, (const char *)name, SPIFFS_OBJ_NAME_LEN);
|
||||
#if SPIFFS_OBJ_META_LEN
|
||||
if (meta) {
|
||||
_SPIFFS_MEMCPY(oix_hdr.meta, meta, SPIFFS_OBJ_META_LEN);
|
||||
|
@ -958,7 +957,7 @@ s32_t spiffs_object_create(
|
|||
|
||||
// update page
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry), sizeof(spiffs_page_object_ix_header), (u8_t*)&oix_hdr);
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry), sizeof(spiffs_page_object_ix_header), (u8_t *)&oix_hdr);
|
||||
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)&oix_hdr,
|
||||
|
@ -1008,7 +1007,7 @@ s32_t spiffs_object_update_index_hdr(
|
|||
|
||||
// change name
|
||||
if (name) {
|
||||
strncpy((char*)objix_hdr->name, (const char*)name, SPIFFS_OBJ_NAME_LEN);
|
||||
strncpy((char *)objix_hdr->name, (const char *)name, SPIFFS_OBJ_NAME_LEN);
|
||||
}
|
||||
#if SPIFFS_OBJ_META_LEN
|
||||
if (meta) {
|
||||
|
@ -1022,7 +1021,7 @@ s32_t spiffs_object_update_index_hdr(
|
|||
}
|
||||
|
||||
// move and update page
|
||||
res = spiffs_page_move(fs, fd == 0 ? 0 : fd->file_nbr, (u8_t*)objix_hdr, obj_id, 0, objix_hdr_pix, &new_objix_hdr_pix);
|
||||
res = spiffs_page_move(fs, fd == 0 ? 0 : fd->file_nbr, (u8_t *)objix_hdr, obj_id, 0, objix_hdr_pix, &new_objix_hdr_pix);
|
||||
|
||||
if (res == SPIFFS_OK) {
|
||||
if (new_pix) {
|
||||
|
@ -1054,7 +1053,7 @@ 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)],
|
||||
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];
|
||||
|
@ -1086,7 +1085,7 @@ void spiffs_cb_object_event(
|
|||
cur_fd->fdoffset = act_new_size;
|
||||
}
|
||||
#if SPIFFS_CACHE_WR
|
||||
if (cur_fd->cache_page && cur_fd->cache_page->ucache.swrc.offset > act_new_size+1) {
|
||||
if (cur_fd->cache_page && cur_fd->cache_page->ucache.swrc.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);
|
||||
}
|
||||
|
@ -1233,7 +1232,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
spiffs_page_header p_hdr;
|
||||
|
||||
spiffs_span_ix cur_objix_spix = 0;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix)-1;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix) - 1;
|
||||
spiffs_page_ix cur_objix_pix = fd->objix_hdr_pix;
|
||||
spiffs_page_ix new_objix_hdr_page;
|
||||
|
||||
|
@ -1256,7 +1255,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
cur_objix_pix, prev_objix_spix, written);
|
||||
if (prev_objix_spix == 0) {
|
||||
// this is an update to object index header page
|
||||
objix_hdr->size = offset+written;
|
||||
objix_hdr->size = offset + written;
|
||||
if (offset == 0) {
|
||||
// was an empty object, update same page (size was 0xffffffff)
|
||||
res = spiffs_page_index_check(fs, fd, cur_objix_pix, 0);
|
||||
|
@ -1267,7 +1266,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
} else {
|
||||
// was a nonempty object, update to new page
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, offset + written, &new_objix_hdr_page);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new objix_hdr, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id,
|
||||
new_objix_hdr_page, 0, written);
|
||||
|
@ -1281,16 +1280,16 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, cur_objix_pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)fs->work,
|
||||
SPIFFS_EV_IX_UPD,fd->obj_id, objix->p_hdr.span_ix, cur_objix_pix, 0);
|
||||
SPIFFS_EV_IX_UPD, fd->obj_id, objix->p_hdr.span_ix, cur_objix_pix, 0);
|
||||
// update length in object index header page
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
fd->objix_hdr_pix, 0, 0, 0, offset + written, &new_objix_hdr_page);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new size I "_SPIPRIi" in objix_hdr, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id,
|
||||
offset+written, new_objix_hdr_page, 0, written);
|
||||
offset + written, new_objix_hdr_page, 0, written);
|
||||
}
|
||||
fd->size = offset+written;
|
||||
fd->offset = offset+written;
|
||||
fd->size = offset + written;
|
||||
fd->offset = offset + written;
|
||||
}
|
||||
|
||||
// create or load new object index page
|
||||
|
@ -1302,7 +1301,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_VALIDATE_OBJIX(objix_hdr->p_hdr, fd->obj_id, cur_objix_spix);
|
||||
} else {
|
||||
spiffs_span_ix len_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, (fd->size-1)/SPIFFS_DATA_PAGE_SIZE(fs));
|
||||
spiffs_span_ix len_objix_spix = SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, (fd->size - 1) / SPIFFS_DATA_PAGE_SIZE(fs));
|
||||
// on subsequent passes, create a new object index page
|
||||
if (written > 0 || cur_objix_spix > len_objix_spix) {
|
||||
p_hdr.obj_id = fd->obj_id | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
|
@ -1337,14 +1336,14 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
}
|
||||
fd->cursor_objix_pix = cur_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
fd->offset = offset+written;
|
||||
fd->size = offset+written;
|
||||
fd->offset = offset + written;
|
||||
fd->size = offset + written;
|
||||
}
|
||||
prev_objix_spix = cur_objix_spix;
|
||||
}
|
||||
|
||||
// write data
|
||||
u32_t to_write = MIN(len-written, SPIFFS_DATA_PAGE_SIZE(fs) - page_offs);
|
||||
u32_t to_write = MIN(len - written, SPIFFS_DATA_PAGE_SIZE(fs) - page_offs);
|
||||
if (page_offs == 0) {
|
||||
// at beginning of a page, allocate and write a new page of data
|
||||
p_hdr.obj_id = fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
|
@ -1358,10 +1357,10 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
// append to existing page, fill out free data in existing page
|
||||
if (cur_objix_spix == 0) {
|
||||
// get data page from object index header page
|
||||
data_page = ((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
data_page = ((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
} else {
|
||||
// get data page from object index page
|
||||
data_page = ((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
data_page = ((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
}
|
||||
|
||||
res = spiffs_page_data_check(fs, fd, data_page, data_spix);
|
||||
|
@ -1378,13 +1377,13 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
// update memory representation of object index page with new data page
|
||||
if (cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = data_page;
|
||||
((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = data_page;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", fd->obj_id
|
||||
, data_page, data_spix);
|
||||
objix_hdr->size = offset+written;
|
||||
objix_hdr->size = offset + written;
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = data_page;
|
||||
((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = data_page;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", fd->obj_id
|
||||
, data_page, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
}
|
||||
|
@ -1395,8 +1394,8 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
written += to_write;
|
||||
} // while all data
|
||||
|
||||
fd->size = offset+written;
|
||||
fd->offset = offset+written;
|
||||
fd->size = offset + written;
|
||||
fd->offset = offset + written;
|
||||
fd->cursor_objix_pix = cur_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
|
||||
|
@ -1419,15 +1418,15 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
|
||||
// update size in object header index page
|
||||
res2 = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
fd->objix_hdr_pix, 0, 0, 0, offset + written, &new_objix_hdr_page);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new size II "_SPIPRIi" in objix_hdr, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi", res "_SPIPRIi"\n", fd->obj_id
|
||||
, offset+written, new_objix_hdr_page, 0, written, res2);
|
||||
, offset + written, new_objix_hdr_page, 0, written, res2);
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
} else {
|
||||
// wrote within object index header page
|
||||
if (offset == 0) {
|
||||
// wrote to empty object - simply update size and write whole page
|
||||
objix_hdr->size = offset+written;
|
||||
objix_hdr->size = offset + written;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store fresh objix_hdr page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id
|
||||
, cur_objix_pix, cur_objix_spix, written);
|
||||
|
||||
|
@ -1443,7 +1442,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
} else {
|
||||
// modifying object index header page, update size and make new copy
|
||||
res2 = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, offset + written, &new_objix_hdr_page);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store modified objix_hdr page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id
|
||||
, new_objix_hdr_page, 0, written);
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
|
@ -1470,7 +1469,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
spiffs_page_header p_hdr;
|
||||
|
||||
spiffs_span_ix cur_objix_spix = 0;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix)-1;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix) - 1;
|
||||
spiffs_page_ix cur_objix_pix = fd->objix_hdr_pix;
|
||||
spiffs_page_ix new_objix_hdr_pix;
|
||||
|
||||
|
@ -1503,7 +1502,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
res = spiffs_page_index_check(fs, fd, cur_objix_pix, prev_objix_spix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
res = spiffs_page_move(fs, fd->file_nbr, (u8_t*)objix, fd->obj_id, 0, cur_objix_pix, &new_objix_pix);
|
||||
res = spiffs_page_move(fs, fd->file_nbr, (u8_t *)objix, fd->obj_id, 0, cur_objix_pix, &new_objix_pix);
|
||||
SPIFFS_DBG("modify: store previous modified objix page, "_SPIPRIid":"_SPIPRIsp", written "_SPIPRIi"\n", new_objix_pix, objix->p_hdr.span_ix, written);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)objix,
|
||||
|
@ -1538,19 +1537,19 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
}
|
||||
fd->cursor_objix_pix = cur_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
fd->offset = offset+written;
|
||||
fd->offset = offset + written;
|
||||
prev_objix_spix = cur_objix_spix;
|
||||
}
|
||||
|
||||
// write partial data
|
||||
u32_t to_write = MIN(len-written, SPIFFS_DATA_PAGE_SIZE(fs) - page_offs);
|
||||
u32_t to_write = MIN(len - written, SPIFFS_DATA_PAGE_SIZE(fs) - page_offs);
|
||||
spiffs_page_ix orig_data_pix;
|
||||
if (cur_objix_spix == 0) {
|
||||
// get data page from object index header page
|
||||
orig_data_pix = ((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
orig_data_pix = ((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
} else {
|
||||
// get data page from object index page
|
||||
orig_data_pix = ((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
orig_data_pix = ((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
}
|
||||
|
||||
p_hdr.obj_id = fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
|
@ -1610,11 +1609,11 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
// update memory representation of object index page with new data page
|
||||
if (cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = data_pix;
|
||||
SPIFFS_DBG("modify: wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", data_pix, data_spix);
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = data_pix;
|
||||
SPIFFS_DBG("modify: wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
}
|
||||
|
||||
|
@ -1624,7 +1623,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
written += to_write;
|
||||
} // while all data
|
||||
|
||||
fd->offset = offset+written;
|
||||
fd->offset = offset + written;
|
||||
fd->cursor_objix_pix = cur_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
|
||||
|
@ -1639,7 +1638,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|||
res2 = spiffs_page_index_check(fs, fd, cur_objix_pix, cur_objix_spix);
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
|
||||
res2 = spiffs_page_move(fs, fd->file_nbr, (u8_t*)objix, fd->obj_id, 0, cur_objix_pix, &new_objix_pix);
|
||||
res2 = spiffs_page_move(fs, fd->file_nbr, (u8_t *)objix, fd->obj_id, 0, cur_objix_pix, &new_objix_pix);
|
||||
SPIFFS_DBG("modify: store modified objix page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", new_objix_pix, cur_objix_spix, written);
|
||||
fd->cursor_objix_pix = new_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
|
@ -1680,7 +1679,7 @@ static s32_t spiffs_object_find_object_index_header_by_name_v(
|
|||
if (objix_hdr.p_hdr.span_ix == 0 &&
|
||||
(objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
|
||||
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
|
||||
if (strcmp((const char*)user_const_p, (char*)objix_hdr.name) == 0) {
|
||||
if (strcmp((const char *)user_const_p, (char *)objix_hdr.name) == 0) {
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -1744,10 +1743,10 @@ s32_t spiffs_object_truncate(
|
|||
}
|
||||
|
||||
spiffs_page_ix objix_pix = fd->objix_hdr_pix;
|
||||
spiffs_span_ix data_spix = (fd->size > 0 ? fd->size-1 : 0) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
spiffs_span_ix data_spix = (fd->size > 0 ? fd->size - 1 : 0) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
u32_t cur_size = fd->size == (u32_t)SPIFFS_UNDEFINED_LEN ? 0 : fd->size ;
|
||||
spiffs_span_ix cur_objix_spix = 0;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix)-1;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix) - 1;
|
||||
spiffs_page_object_ix_header *objix_hdr = (spiffs_page_object_ix_header *)fs->work;
|
||||
spiffs_page_object_ix *objix = (spiffs_page_object_ix *)fs->work;
|
||||
spiffs_page_ix data_pix;
|
||||
|
@ -1755,7 +1754,7 @@ s32_t spiffs_object_truncate(
|
|||
|
||||
// before truncating, check if object is to be fully removed and mark this
|
||||
if (remove_full && new_size == 0) {
|
||||
u8_t flags = ~( SPIFFS_PH_FLAG_USED | SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE);
|
||||
u8_t flags = ~(SPIFFS_PH_FLAG_USED | SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE);
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_UPDT,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, fd->objix_hdr_pix) + offsetof(spiffs_page_header, flags),
|
||||
sizeof(u8_t),
|
||||
|
@ -1769,7 +1768,7 @@ s32_t spiffs_object_truncate(
|
|||
|
||||
// put object index for current data span index in work buffer
|
||||
if (prev_objix_spix != cur_objix_spix) {
|
||||
if (prev_objix_spix != (spiffs_span_ix)-1) {
|
||||
if (prev_objix_spix != (spiffs_span_ix) - 1) {
|
||||
// remove previous object index page
|
||||
SPIFFS_DBG("truncate: delete objix page "_SPIPRIpg":"_SPIPRIsp"\n", objix_pix, prev_objix_spix);
|
||||
|
||||
|
@ -1818,12 +1817,12 @@ s32_t spiffs_object_truncate(
|
|||
|
||||
if (cur_objix_spix == 0) {
|
||||
// get data page from object index header page
|
||||
data_pix = ((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = SPIFFS_OBJ_ID_FREE;
|
||||
data_pix = ((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = SPIFFS_OBJ_ID_FREE;
|
||||
} else {
|
||||
// get data page from object index page
|
||||
data_pix = ((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = SPIFFS_OBJ_ID_FREE;
|
||||
data_pix = ((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = SPIFFS_OBJ_ID_FREE;
|
||||
}
|
||||
|
||||
SPIFFS_DBG("truncate: got data pix "_SPIPRIpg"\n", data_pix);
|
||||
|
@ -1891,11 +1890,11 @@ s32_t spiffs_object_truncate(
|
|||
// update memory representation of object index page with new data page
|
||||
if (cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = new_data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = new_data_pix;
|
||||
SPIFFS_DBG("truncate: wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = new_data_pix;
|
||||
((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = new_data_pix;
|
||||
SPIFFS_DBG("truncate: wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
}
|
||||
cur_size = new_size;
|
||||
|
@ -1945,7 +1944,7 @@ s32_t spiffs_object_truncate(
|
|||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
// move and update object index page
|
||||
res = spiffs_page_move(fs, fd->file_nbr, (u8_t*)objix_hdr, fd->obj_id, 0, objix_pix, &new_objix_pix);
|
||||
res = spiffs_page_move(fs, fd->file_nbr, (u8_t *)objix_hdr, fd->obj_id, 0, objix_pix, &new_objix_pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)objix_hdr,
|
||||
SPIFFS_EV_IX_UPD, fd->obj_id, objix->p_hdr.span_ix, new_objix_pix, 0);
|
||||
|
@ -1976,7 +1975,7 @@ s32_t spiffs_object_read(
|
|||
spiffs_span_ix data_spix = offset / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
u32_t cur_offset = offset;
|
||||
spiffs_span_ix cur_objix_spix;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix)-1;
|
||||
spiffs_span_ix prev_objix_spix = (spiffs_span_ix) - 1;
|
||||
spiffs_page_object_ix_header *objix_hdr = (spiffs_page_object_ix_header *)fs->work;
|
||||
spiffs_page_object_ix *objix = (spiffs_page_object_ix *)fs->work;
|
||||
|
||||
|
@ -2018,10 +2017,10 @@ s32_t spiffs_object_read(
|
|||
|
||||
if (cur_objix_spix == 0) {
|
||||
// get data page from object index header page
|
||||
data_pix = ((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
data_pix = ((spiffs_page_ix *)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix];
|
||||
} else {
|
||||
// get data page from object index page
|
||||
data_pix = ((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
data_pix = ((spiffs_page_ix *)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)];
|
||||
}
|
||||
#if SPIFFS_IX_MAP
|
||||
}
|
||||
|
@ -2067,8 +2066,8 @@ typedef struct {
|
|||
static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
|
||||
const void *user_const_p, void *user_var_p) {
|
||||
if (id != SPIFFS_OBJ_ID_FREE && id != SPIFFS_OBJ_ID_DELETED) {
|
||||
spiffs_obj_id min_obj_id = *((spiffs_obj_id*)user_var_p);
|
||||
const u8_t *conflicting_name = (const u8_t*)user_const_p;
|
||||
spiffs_obj_id min_obj_id = *((spiffs_obj_id *)user_var_p);
|
||||
const u8_t *conflicting_name = (const u8_t *)user_const_p;
|
||||
|
||||
// if conflicting name parameter is given, also check if this name is found in object index hdrs
|
||||
if (conflicting_name && (id & SPIFFS_OBJ_ID_IX_FLAG)) {
|
||||
|
@ -2081,17 +2080,17 @@ static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id i
|
|||
if (objix_hdr.p_hdr.span_ix == 0 &&
|
||||
(objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
|
||||
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
|
||||
if (strcmp((const char*)user_const_p, (char*)objix_hdr.name) == 0) {
|
||||
if (strcmp((const char *)user_const_p, (char *)objix_hdr.name) == 0) {
|
||||
return SPIFFS_ERR_CONFLICTING_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
id &= ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
u32_t bit_ix = (id-min_obj_id) & 7;
|
||||
int byte_ix = (id-min_obj_id) >> 3;
|
||||
u32_t bit_ix = (id - min_obj_id) & 7;
|
||||
int byte_ix = (id - min_obj_id) >> 3;
|
||||
if (byte_ix >= 0 && (u32_t)byte_ix < SPIFFS_CFG_LOG_PAGE_SZ(fs)) {
|
||||
fs->work[byte_ix] |= (1<<bit_ix);
|
||||
fs->work[byte_ix] |= (1 << bit_ix);
|
||||
}
|
||||
}
|
||||
return SPIFFS_VIS_COUNTINUE;
|
||||
|
@ -2102,11 +2101,11 @@ static s32_t spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id
|
|||
(void)user_var_p;
|
||||
if (id != SPIFFS_OBJ_ID_FREE && id != SPIFFS_OBJ_ID_DELETED && (id & SPIFFS_OBJ_ID_IX_FLAG)) {
|
||||
s32_t res;
|
||||
const spiffs_free_obj_id_state *state = (const spiffs_free_obj_id_state*)user_const_p;
|
||||
const spiffs_free_obj_id_state *state = (const spiffs_free_obj_id_state *)user_const_p;
|
||||
spiffs_page_object_ix_header objix_hdr;
|
||||
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, ix_entry), sizeof(spiffs_page_object_ix_header), (u8_t*)&objix_hdr);
|
||||
0, SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, ix_entry), sizeof(spiffs_page_object_ix_header), (u8_t *)&objix_hdr);
|
||||
if (res == SPIFFS_OK && objix_hdr.p_hdr.span_ix == 0 &&
|
||||
((objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_DELET)) ==
|
||||
(SPIFFS_PH_FLAG_DELET))) {
|
||||
|
@ -2139,12 +2138,12 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
|||
state.min_obj_id = 1;
|
||||
state.max_obj_id = max_objects + 1;
|
||||
if (state.max_obj_id & SPIFFS_OBJ_ID_IX_FLAG) {
|
||||
state.max_obj_id = ((spiffs_obj_id)-1) & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
state.max_obj_id = ((spiffs_obj_id) - 1) & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
}
|
||||
state.compaction = 0;
|
||||
state.conflicting_name = conflicting_name;
|
||||
while (res == SPIFFS_OK && free_obj_id == SPIFFS_OBJ_ID_FREE) {
|
||||
if (state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs)*8) {
|
||||
if (state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs) * 8) {
|
||||
// possible to represent in bitmap
|
||||
u32_t i, j;
|
||||
SPIFFS_DBG("free_obj_id: BITM min:"_SPIPRIid" max:"_SPIPRIid"\n", state.min_obj_id, state.max_obj_id);
|
||||
|
@ -2161,8 +2160,8 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
|||
continue;
|
||||
}
|
||||
for (j = 0; j < 8; j++) {
|
||||
if ((mask & (1<<j)) == 0) {
|
||||
*obj_id = (i<<3)+j+state.min_obj_id;
|
||||
if ((mask & (1 << j)) == 0) {
|
||||
*obj_id = (i << 3) + j + state.min_obj_id;
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -2176,7 +2175,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
|||
u8_t *map = (u8_t *)fs->work;
|
||||
u8_t min_count = 0xff;
|
||||
|
||||
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs)/sizeof(u8_t); i++) {
|
||||
for (i = 0; i < SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(u8_t); i++) {
|
||||
if (map[i] < min_count) {
|
||||
min_count = map[i];
|
||||
min_i = i;
|
||||
|
@ -2204,14 +2203,14 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
|||
state.max_obj_id = state.min_obj_id + state.compaction;
|
||||
// decrease compaction
|
||||
}
|
||||
if ((state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs)*8)) {
|
||||
if ((state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs) * 8)) {
|
||||
// no need for compacting, use bitmap
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// in a work memory of log_page_size bytes, we may fit in log_page_size ids
|
||||
// todo what if compaction is > 255 - then we cannot fit it in a byte
|
||||
state.compaction = (state.max_obj_id-state.min_obj_id) / ((SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(u8_t)));
|
||||
state.compaction = (state.max_obj_id - state.min_obj_id) / ((SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(u8_t)));
|
||||
SPIFFS_DBG("free_obj_id: COMP min:"_SPIPRIid" max:"_SPIPRIid" compact:"_SPIPRIi"\n", state.min_obj_id, state.max_obj_id, state.compaction);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
|
@ -2244,7 +2243,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd, const char *name) {
|
|||
#if SPIFFS_TEMPORAL_FD_CACHE
|
||||
u32_t i;
|
||||
u16_t min_score = 0xffff;
|
||||
u32_t cand_ix = (u32_t)-1;
|
||||
u32_t cand_ix = (u32_t) -1;
|
||||
u32_t name_hash = name ? spiffs_hash(fs, (const u8_t *)name) : 0;
|
||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||
|
||||
|
@ -2275,7 +2274,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd, const char *name) {
|
|||
}
|
||||
}
|
||||
|
||||
if (cand_ix != (u32_t)-1) {
|
||||
if (cand_ix != (u32_t) -1) {
|
||||
spiffs_fd *cur_fd = &fds[cand_ix];
|
||||
if (name) {
|
||||
if (cur_fd->name_hash == name_hash && cur_fd->score > 0) {
|
||||
|
@ -2285,7 +2284,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd, const char *name) {
|
|||
fs->cursor_block_ix = SPIFFS_BLOCK_FOR_PAGE(fs, cur_fd->objix_hdr_pix);
|
||||
fs->cursor_obj_lu_entry = SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, cur_fd->objix_hdr_pix);
|
||||
// update score
|
||||
if (cur_fd->score < 0xffff-SPIFFS_TEMPORAL_CACHE_HIT_SCORE) {
|
||||
if (cur_fd->score < 0xffff - SPIFFS_TEMPORAL_CACHE_HIT_SCORE) {
|
||||
cur_fd->score += SPIFFS_TEMPORAL_CACHE_HIT_SCORE;
|
||||
} else {
|
||||
cur_fd->score = 0xffff;
|
||||
|
@ -2296,7 +2295,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd, const char *name) {
|
|||
cur_fd->name_hash = name_hash;
|
||||
}
|
||||
}
|
||||
cur_fd->file_nbr = cand_ix+1;
|
||||
cur_fd->file_nbr = cand_ix + 1;
|
||||
*fd = cur_fd;
|
||||
return SPIFFS_OK;
|
||||
} else {
|
||||
|
@ -2309,7 +2308,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd, const char *name) {
|
|||
for (i = 0; i < fs->fd_count; i++) {
|
||||
spiffs_fd *cur_fd = &fds[i];
|
||||
if (cur_fd->file_nbr == 0) {
|
||||
cur_fd->file_nbr = i+1;
|
||||
cur_fd->file_nbr = i + 1;
|
||||
*fd = cur_fd;
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
|
@ -2323,7 +2322,7 @@ s32_t spiffs_fd_return(spiffs *fs, spiffs_file f) {
|
|||
return SPIFFS_ERR_BAD_DESCRIPTOR;
|
||||
}
|
||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||
spiffs_fd *fd = &fds[f-1];
|
||||
spiffs_fd *fd = &fds[f - 1];
|
||||
if (fd->file_nbr == 0) {
|
||||
return SPIFFS_ERR_FILE_CLOSED;
|
||||
}
|
||||
|
@ -2339,7 +2338,7 @@ s32_t spiffs_fd_get(spiffs *fs, spiffs_file f, spiffs_fd **fd) {
|
|||
return SPIFFS_ERR_BAD_DESCRIPTOR;
|
||||
}
|
||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||
*fd = &fds[f-1];
|
||||
*fd = &fds[f - 1];
|
||||
if ((*fd)->file_nbr == 0) {
|
||||
return SPIFFS_ERR_FILE_CLOSED;
|
||||
}
|
||||
|
|
|
@ -144,14 +144,14 @@
|
|||
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__TI_COMPILER_VERSION__)
|
||||
/* For GCC, clang and TI compilers */
|
||||
/* For GCC, clang and TI compilers */
|
||||
#define SPIFFS_PACKED __attribute__((packed))
|
||||
#elif defined(__ICCARM__) || defined(__CC_ARM)
|
||||
/* For IAR ARM and Keil MDK-ARM compilers */
|
||||
/* For IAR ARM and Keil MDK-ARM compilers */
|
||||
#define SPIFFS_PACKED
|
||||
|
||||
#else
|
||||
/* Unknown compiler */
|
||||
/* Unknown compiler */
|
||||
#define SPIFFS_PACKED
|
||||
#endif
|
||||
|
||||
|
@ -338,7 +338,7 @@
|
|||
if (((ph).flags & SPIFFS_PH_FLAG_INDEX) != 0) return SPIFFS_ERR_NOT_INDEX; \
|
||||
if (((objid) & SPIFFS_OBJ_ID_IX_FLAG) == 0) return SPIFFS_ERR_NOT_INDEX; \
|
||||
if ((ph).span_ix != (spix)) return SPIFFS_ERR_INDEX_SPAN_MISMATCH;
|
||||
//if ((spix) == 0 && ((ph).flags & SPIFFS_PH_FLAG_IXDELE) == 0) return SPIFFS_ERR_DELETED;
|
||||
//if ((spix) == 0 && ((ph).flags & SPIFFS_PH_FLAG_IXDELE) == 0) return SPIFFS_ERR_DELETED;
|
||||
|
||||
#define SPIFFS_VALIDATE_DATA(ph, objid, spix) \
|
||||
if (((ph).flags & SPIFFS_PH_FLAG_USED) != 0) return SPIFFS_ERR_IS_FREE; \
|
||||
|
@ -492,13 +492,13 @@ typedef struct SPIFFS_PACKED {
|
|||
// object index header page header
|
||||
typedef struct SPIFFS_PACKED
|
||||
#if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
|
||||
__attribute(( aligned(sizeof(spiffs_page_ix)) ))
|
||||
__attribute((aligned(sizeof(spiffs_page_ix))))
|
||||
#endif
|
||||
{
|
||||
// common page header
|
||||
spiffs_page_header p_hdr;
|
||||
// alignment
|
||||
u8_t _align[4 - ((sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3))];
|
||||
u8_t _align[4 - ((sizeof(spiffs_page_header) & 3) == 0 ? 4 : (sizeof(spiffs_page_header) & 3))];
|
||||
// size of object
|
||||
u32_t size;
|
||||
// type of object
|
||||
|
@ -509,12 +509,13 @@ typedef struct SPIFFS_PACKED
|
|||
// metadata. not interpreted by SPIFFS in any way.
|
||||
u8_t meta[SPIFFS_OBJ_META_LEN];
|
||||
#endif
|
||||
} spiffs_page_object_ix_header;
|
||||
}
|
||||
spiffs_page_object_ix_header;
|
||||
|
||||
// object index page header
|
||||
typedef struct SPIFFS_PACKED {
|
||||
spiffs_page_header p_hdr;
|
||||
u8_t _align[4 - ((sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3))];
|
||||
u8_t _align[4 - ((sizeof(spiffs_page_header) & 3) == 0 ? 4 : (sizeof(spiffs_page_header) & 3))];
|
||||
} spiffs_page_object_ix;
|
||||
|
||||
// callback func for object lookup visitor
|
||||
|
|
|
@ -109,16 +109,14 @@ void itoa(int n, char s[]) {
|
|||
|
||||
|
||||
|
||||
char *strcpy(char *dst, const char *src)
|
||||
{
|
||||
char *strcpy(char *dst, const char *src) {
|
||||
char *save = dst;
|
||||
|
||||
for (; (*dst = *src) != '\0'; ++src, ++dst);
|
||||
return save;
|
||||
}
|
||||
}
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t n)
|
||||
{
|
||||
char *strncpy(char *dst, const char *src, size_t n) {
|
||||
if (n != 0) {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
@ -134,41 +132,38 @@ char *strncpy(char *dst, const char *src, size_t n)
|
|||
} while (--n);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 == *s2++) {
|
||||
if (*s1++ == 0) {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (*(unsigned char *) s1 - *(unsigned char *) --s2);
|
||||
return (*(unsigned char *) s1 - * (unsigned char *) --s2);
|
||||
}
|
||||
|
||||
char* __strtok_r(char*, const char*, char**);
|
||||
char *__strtok_r(char *, const char *, char **);
|
||||
|
||||
char* __strtok_r(char* s, const char* delim, char** last)
|
||||
{
|
||||
char *__strtok_r(char *s, const char *delim, char **last) {
|
||||
char *spanp, *tok;
|
||||
int c, sc;
|
||||
|
||||
if(s == NULL && (s = *last) == NULL)
|
||||
if (s == NULL && (s = *last) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for(spanp = (char*)delim; (sc = *spanp++) != 0;)
|
||||
{
|
||||
if(c == sc)
|
||||
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
|
||||
if (c == sc)
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if(c == 0)
|
||||
{ /* no non-delimiter characters */
|
||||
if (c == 0) {
|
||||
/* no non-delimiter characters */
|
||||
*last = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
|
@ -178,29 +173,25 @@ cont:
|
|||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
c = *s++;
|
||||
spanp = (char*)delim;
|
||||
do
|
||||
{
|
||||
if((sc = *spanp++) == c)
|
||||
{
|
||||
if(c == 0)
|
||||
spanp = (char *)delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = '\0';
|
||||
*last = s;
|
||||
return (tok);
|
||||
}
|
||||
} while(sc != 0);
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
char* strtok(char* s, const char* delim)
|
||||
{
|
||||
static char* last;
|
||||
char *strtok(char *s, const char *delim) {
|
||||
static char *last;
|
||||
|
||||
return (__strtok_r(s, delim, &last));
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ char *strcat(char *dest, const char *src);
|
|||
void strreverse(char s[]);
|
||||
void itoa(int n, char s[]);
|
||||
char *strcpy(char *dst, const char *src);
|
||||
char* strncpy(char* destination, const char* source, size_t num);
|
||||
char *strncpy(char *destination, const char *source, size_t num);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
char* strtok(char* s, const char* delim);
|
||||
char *strtok(char *s, const char *delim);
|
||||
|
||||
#endif /* __STRING_H */
|
||||
|
|
|
@ -865,7 +865,7 @@ static int CmdBitsamples(const char *Cmd) {
|
|||
int cnt = 0;
|
||||
uint8_t got[12288];
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
@ -1397,7 +1397,7 @@ static int CmdHexsamples(const char *Cmd) {
|
|||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, got, requested, offset,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, got, requested, offset, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
@ -1470,7 +1470,7 @@ int getSamples(uint32_t n, bool silent) {
|
|||
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
|
||||
|
||||
PacketResponseNG response;
|
||||
if (!GetFromDevice(BIG_BUF, got, n, 0,NULL,0, &response, 10000, true)) {
|
||||
if (!GetFromDevice(BIG_BUF, got, n, 0, NULL, 0, &response, 10000, true)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ static int CmdFlashMemDump(const char *Cmd) {
|
|||
}
|
||||
|
||||
PrintAndLogEx(INFO, "downloading "_YELLOW_("%u")"bytes from flashmem", len);
|
||||
if (!GetFromDevice(FLASH_MEM, dump, len, start_index,NULL,0, NULL, -1, true)) {
|
||||
if (!GetFromDevice(FLASH_MEM, dump, len, start_index, NULL, 0, NULL, -1, true)) {
|
||||
PrintAndLogEx(FAILED, "ERROR; downloading from flashmemory");
|
||||
free(dump);
|
||||
return PM3_EFLASH;
|
||||
|
|
|
@ -432,8 +432,10 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) {
|
|||
static command_t CommandTable[] = {
|
||||
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"copy", CmdFlashMemSpiFFSCopy, IfPm3Flash,
|
||||
"Copy a file to another (destructively) in SPIFFS FileSystem in FlashMEM (spiffs)"},
|
||||
{
|
||||
"copy", CmdFlashMemSpiFFSCopy, IfPm3Flash,
|
||||
"Copy a file to another (destructively) in SPIFFS FileSystem in FlashMEM (spiffs)"
|
||||
},
|
||||
{"dump", CmdFlashMemSpiFFSDump, IfPm3Flash, "Dump a file from SPIFFS FileSystem in FlashMEM (spiffs)"},
|
||||
{"info", CmdFlashMemSpiFFSInfo, IfPm3Flash, "Print filesystem info and usage statistics (spiffs)"},
|
||||
{"load", CmdFlashMemSpiFFSLoad, IfPm3Flash, "Upload file into SPIFFS Filesystem (spiffs)"},
|
||||
|
@ -443,7 +445,8 @@ static command_t CommandTable[] = {
|
|||
{"test", CmdFlashMemSpiFFSTest, IfPm3Flash, "Test SPIFFS Functionning (require wiping pages 0 and 1)"},
|
||||
{"tree", CmdFlashMemSpiFFSTree, IfPm3Flash, "Print the Flash Memory FileSystem Tree (spiffs)"},
|
||||
{"unmount", CmdFlashMemSpiFFSUnmount, IfPm3Flash, "Un-mount the SPIFFS Filesystem if not already mounted (spiffs)"},
|
||||
{NULL, NULL, NULL, NULL}};
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static int CmdHelp(const char *Cmd) {
|
||||
(void)Cmd; // Cmd is not used so far
|
||||
|
|
|
@ -383,7 +383,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, trace, tracelen, 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, trace, tracelen, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(trace);
|
||||
return 0;
|
||||
|
|
|
@ -990,7 +990,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
|||
}
|
||||
|
||||
// response ok - now get bigbuf content of the dump
|
||||
if (!GetFromDevice(BIG_BUF, tag_data + (blockno * 8), blocksRead * 8, startindex,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, tag_data + (blockno * 8), blocksRead * 8, startindex, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1033,7 +1033,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
|||
blocksRead = (sizeof(tag_data) - gotBytes) / 8;
|
||||
}
|
||||
// get dumped data from bigbuf
|
||||
if (!GetFromDevice(BIG_BUF, tag_data + gotBytes, blocksRead * 8, startindex,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, tag_data + gotBytes, blocksRead * 8, startindex, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -781,7 +781,7 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
|
|||
PrintAndLogEx(WARNING, "Fail, only managed to read %u bytes", *outlen);
|
||||
|
||||
// copy data from device
|
||||
if (!GetFromDevice(BIG_BUF_EML, out, *outlen, 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF_EML, out, *outlen, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
return 4;
|
||||
}
|
||||
|
@ -930,7 +930,7 @@ static int CmdLegicDump(const char *Cmd) {
|
|||
PrintAndLogEx(WARNING, "Fail, only managed to read 0x%02X bytes of 0x%02X", readlen, dumplen);
|
||||
|
||||
// copy data from device
|
||||
if (!GetFromDevice(BIG_BUF_EML, data, readlen, 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF_EML, data, readlen, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
free(data);
|
||||
return 4;
|
||||
|
@ -1200,7 +1200,7 @@ static int CmdLegicESave(const char *Cmd) {
|
|||
|
||||
// download emulator memory
|
||||
PrintAndLogEx(SUCCESS, "Reading emulator memory...");
|
||||
if (!GetFromDevice(BIG_BUF_EML, data, numofbytes, 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF_EML, data, numofbytes, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
free(data);
|
||||
return 4;
|
||||
|
|
|
@ -2693,7 +2693,7 @@ static int CmdHF14AMfESave(const char *Cmd) {
|
|||
memset(dump, 0, bytes);
|
||||
|
||||
PrintAndLogEx(INFO, "downloading from emulator memory");
|
||||
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
free(dump);
|
||||
return PM3_ETIMEOUT;
|
||||
|
|
|
@ -1931,7 +1931,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
|
|||
bufferSize = sizeof(data);
|
||||
}
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, data, bufferSize, startindex,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, data, bufferSize, startindex, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ static int CmdCOTAGRead(const char *Cmd) {
|
|||
}
|
||||
case 1: {
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, DemodBuffer, COTAG_BITS, 0,NULL,0, NULL, 1000, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, DemodBuffer, COTAG_BITS, 0, NULL, 0, NULL, 1000, false)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
|
|
@ -986,7 +986,7 @@ static bool downloadSamplesEM() {
|
|||
|
||||
// 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
|
||||
uint8_t got[6000];
|
||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1804,7 +1804,7 @@ static int CmdResetRead(const char *Cmd) {
|
|||
}
|
||||
|
||||
uint8_t got[BIGBUF_SIZE - 1];
|
||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
|
|
@ -759,7 +759,7 @@ int CmdTraceList(const char *Cmd) {
|
|||
if (isOnline) {
|
||||
// Query for the size of the trace, downloading PM3_CMD_DATA_SIZE
|
||||
PacketResponseNG response;
|
||||
if (!GetFromDevice(BIG_BUF, trace, PM3_CMD_DATA_SIZE, 0,NULL,0, &response, 4000, true)) {
|
||||
if (!GetFromDevice(BIG_BUF, trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &response, 4000, true)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return 1;
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ int CmdTraceList(const char *Cmd) {
|
|||
return 2;
|
||||
}
|
||||
trace = p;
|
||||
if (!GetFromDevice(BIG_BUF, trace, traceLen, 0,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, trace, traceLen, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(trace);
|
||||
return 3;
|
||||
|
|
|
@ -223,7 +223,7 @@ static int l_GetFromBigBuf(lua_State *L) {
|
|||
return returnToLuaWithError(L, "Allocating memory failed");
|
||||
}
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, data, len, startindex,NULL,0, NULL, 2500, false)) {
|
||||
if (!GetFromDevice(BIG_BUF, data, len, startindex, NULL, 0, NULL, 2500, false)) {
|
||||
free(data);
|
||||
return returnToLuaWithError(L, "command execution time out");
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ static int l_GetFromFlashMem(lua_State *L) {
|
|||
if (!data)
|
||||
return returnToLuaWithError(L, "Allocating memory failed");
|
||||
|
||||
if (!GetFromDevice(FLASH_MEM, data, len, startindex,NULL,0, NULL, -1, false)) {
|
||||
if (!GetFromDevice(FLASH_MEM, data, len, startindex, NULL, 0, NULL, -1, false)) {
|
||||
free(data);
|
||||
return returnToLuaWithError(L, "command execution time out");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue