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

SPIFFS says, File is present but not able to Read/Write/Delete. #294

Open
Kalpesh1990 opened this issue Jan 5, 2023 · 0 comments
Open

Comments

@Kalpesh1990
Copy link

Kalpesh1990 commented Jan 5, 2023

Highlights of operations what we do in our system

Upon power up of embedded device, We are reading some configurations from file and writing some initial data(Reset Counter) immediately in file.

Steps to generate problem

  • When we power cycle device continuously, Sometime file goes in this state (File is present (We can open it) but we can't Read/Write/Delete it).

Initial Analysis

  • When file corrupts (Goes in above mentioned state), Page header flag value was 254 or 124 (1st bit from 0th location was present mean writing is not finalized/under modification or 7th bit was zero mean page deleted respectively, Ref File: spiffs_nucleus.h, Line No - 288).
  • Return with error SPIFFS_ERR_NOT_FINALIZED/SPIFFS_ERR_DELETED respectively while read from below line of code, File : spiffs_nucleus.c, Line No : 27
    SPIFFS_VALIDATE_DATA(ph, fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG, spix);
  • Same flag was 252 when file was healthy (Not corrupted).

In Depth Analysis to generate the issue manually in debug mode

Flow of execution related to busy writing flag under

  1. spiffs_object_modify (clearing busy writing flag and then deleting original page)
    // write all data
    // write partial data
    // copy unmodified data
    // Clear flag
    Manual Reset the system (In debug mode)
    p_hdr.flags &= ~SPIFFS_PH_FLAG_FINAL;
    // delete original data page
    => In the first case if we reset the system manually , File is not corrupting. So I am assuming it will take data from original page which we haven't deleted.

  2. spiffs_object_truncate (deleting original page first and then clearing busy writing flag)
    // delete last page, partially
    // allocate new page and copy unmodified data
    // delete original data page
    Manual Reset the system (In debug mode)
    p_hdr.flags &= ~SPIFFS_PH_FLAG_FINAL;
    => But in second case, If we do manual reset (In debug mode), As original page is deleted it will take data from new page and chance that file is being corrupted.

What we do to recover system

  • As file number/name is fixed, We have to erase the full chip.

So can you suggest any solution to get out from this situation.
What best I can think of is, Always remove busy flag when user close the file.

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