Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closing the file after writing the file in 128. the error SPIFFS_ERR_DELETED (-10004) #261

Closed
erkanakarcay opened this issue Feb 11, 2020 · 3 comments

Comments

@erkanakarcay
Copy link

Hello,
When I test the below code, I get constantly the same error( SPIFFS_ERR_DELETED). The error occurs that I close the file after writing the file in 128. step.

spiffs fs;
spiffs_file fd;
fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
if (fd < 0)
{
printf("errno %ld\n", SPIFFS_errno(&fs));
return;
}
// write to it
if (SPIFFS_write(&fs, fd, (u8_t *)"Test1", 6) < 0)
{
printf("errno %ld\n", SPIFFS_errno(&fs));
return;
}
// close it
if (SPIFFS_close(&fs, fd) < 0)
{
printf("errno %ld\n", SPIFFS_errno(&fs)); // SPIFFS_ERR_DELETED 128. step
return;
}
// open it
fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
if (fd < 0)
{
printf("errno %ld\n", SPIFFS_errno(&fs));
return;
// read it
if (SPIFFS_read(&fs, fd, (u8_t *)buf, 6) < 0)
{
printf("errno %ld\n", SPIFFS_errno(&fs));
return;
}
// close it
if (SPIFFS_close(&fs, fd) < 0)
{
printf("errno %ld\n", SPIFFS_errno(&fs));
return;
}

// check it
printf("--> %s <--\n", buf);

My Configurations;

#define SPIFFS_BUFFER_HELP 0
#define SPIFFS_CACHE 1
#define SPIFFS_CACHE_WR 1
#define SPIFFS_CACHE_STATS 1
#define SPIFFS_PAGE_CHECK 1
#define SPIFFS_GC_MAX_RUNS 5
#define SPIFFS_GC_STATS 1
#define SPIFFS_GC_HEUR_W_DELET (5)
#define SPIFFS_GC_HEUR_W_USED (-1)
#define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
#define SPIFFS_OBJ_NAME_LEN (32)
#define SPIFFS_OBJ_META_LEN (0)
#define SPIFFS_COPY_BUFFER_STACK (64)
#define SPIFFS_USE_MAGIC (1)
#define SPIFFS_USE_MAGIC_LENGTH (1)
#define SPIFFS_SINGLETON 1

#define SPIFFS_CFG_PHYS_SZ(ignore) (64UL126UL1024UL)
#define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (64UL1024UL)
#define SPIFFS_CFG_PHYS_ADDR(ignore) (0x10000)
#define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
#define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (64UL
1024UL)

#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
#define SPIFFS_HAL_CALLBACK_EXTRA 0
#define SPIFFS_FILEHDL_OFFSET 0
#define SPIFFS_READ_ONLY 0
#define SPIFFS_TEMPORAL_FD_CACHE 1
#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
#define SPIFFS_IX_MAP 1
#define SPIFFS_NO_BLIND_WRITES 0

@erkanakarcay
Copy link
Author

I forget to add mount routine.

 my_spiffs_mount();
  SPIFFS_unmount(&fs);
  SPIFFS_format(&fs);
   my_spiffs_mount();

Test outputs;

mount res:0                                                                     
mount res:0                                                                     
--> Test1 <--                                                                   
--> Test1 <--                                                                   
--> Test1 <--                                                                   
--> Test1 <--                                                                   
--> Test1 <--        
....
....
--> Test1 <--       
errno -10004      128. step (close the file after writing the file)

Also, I try to change,but it doesn't change the error.

#define SPIFFS_USE_MAGIC (0)
#define SPIFFS_USE_MAGIC_LENGTH (0)

Thanks.

@erkanakarcay
Copy link
Author

I try to change a lot of configuration in the spiffs_config.h but the error doesn't change. The error constantly occurs every 128. step when I close the file after writing the file.
Does anybody have any idea about the issue?

s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len)
{
  .........
  ........
     
 // create or load new object index page
            if (cur_objix_spix == 0)
            {
                // load object index header page, must always exist
                SPIFFS_DBG("append: "_SPIPRIid" load objixhdr page 
                "_SPIPRIpg":"_SPIPRIsp"\n", fd->obj_id, cur_objix_pix, cur_objix_spix);
                res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
                                 fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, cur_objix_pix), 
                                  SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
                SPIFFS_CHECK_RES(res);
               SPIFFS_VALIDATE_OBJIX(objix_hdr->p_hdr, fd->obj_id, cur_objix_spix); // Error occur this line every 128. step
            }

}


#define SPIFFS_VALIDATE_OBJIX(ph, objid, spix) \
    if (((ph).flags & SPIFFS_PH_FLAG_USED) != 0) return SPIFFS_ERR_IS_FREE; \
    if (((ph).flags & SPIFFS_PH_FLAG_DELET) == 0) return SPIFFS_ERR_DELETED; \ // Error occur this line every 128. step
            }
    if (((ph).flags & SPIFFS_PH_FLAG_FINAL) != 0) return SPIFFS_ERR_NOT_FINALIZED; \
    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;

The error constantly occurs every 128. step when I close the file after writing the file.

spiffs_object_append -> SPIFFS_VALIDATE_OBJIX -> if (((ph).flags & SPIFFS_PH_FLAG_DELET) == 0) return SPIFFS_ERR_DELETED;

@erkanakarcay erkanakarcay changed the title SPIFFS_ERR_DELETED (-10004) Error closing the file after writing the file in 128. the error SPIFFS_ERR_DELETED (-10004) Feb 17, 2020
@erkanakarcay
Copy link
Author

I changed SPIFFS_SINGLETON of configuration as 0 and the error fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant