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

Corrupted SD Filesystem on remount/reset #128

Open
Chasbrot opened this issue Jan 1, 2023 · 3 comments
Open

Corrupted SD Filesystem on remount/reset #128

Chasbrot opened this issue Jan 1, 2023 · 3 comments

Comments

@Chasbrot
Copy link

Chasbrot commented Jan 1, 2023

First Happy New Year!

Description:
When using the example sd_msc, everything works fine, i can create, update and delete files. BUT when I remount or reset the esp, the filesystem is corrupted. Windows cannot open or remove directories anymore, sometimes files are missing or parts of files are missing. When i access the SD card via the esp after unmount, the same strange behavior happens as in windows. The test script goes completly haywire.

I tried:

  • Multiple different SD cards (mainly older models)
  • Different FAT settings
  • Windows write cache disabled in volume settings
  • Controlled power supply, no ripple or voltage sags

After formating the SD cards are completly fine and work normally. Only after remount/reset this happens.

Enviroment:

@chegewara
Copy link
Owner

Hi,
its possible there is missing fs sync command or something else.
I never tested it with windows and on linux i had similar issue few times, when i remove "pendrive" without unmounting it.

You can try to add this in you code, in main.ino:

void tud_msc_write10_complete_cb(uint8_t lun)
{
    if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
    {
        Serial.printf("failed to sync\n");
    }
}

@Chasbrot
Copy link
Author

Chasbrot commented Jan 6, 2023

hi, thanks for the quick response. i also tried safe remove with windows, but that didn't help. After a while i just tired it with the target system (which is some kind of embedded "os") and it just worked. I am developing under windows, so my testing was with windows. Probably windows doing windows things. I tried your code (just copied it under the loop function):

C:\Users\Michael\Desktop\USBMonitor\USBMonitor.ino: In function 'void tud_msc_write10_complete_cb(uint8_t)':
USBMonitor:436:23: error: 'CTRL_SYNC' was not declared in this scope
     if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
                       ^~~~~~~~~
C:\Users\Michael\Desktop\USBMonitor\USBMonitor.ino:436:23: note: suggested alternative: 'CARD_SDHC'
     if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
                       ^~~~~~~~~
                       CARD_SDHC
USBMonitor:436:9: error: 'disk_ioctl' was not declared in this scope
     if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
         ^~~~~~~~~~
C:\Users\Michael\Desktop\USBMonitor\USBMonitor.ino:436:9: note: suggested alternative: 'ioctl'
     if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
         ^~~~~~~~~~
         ioctl
USBMonitor:436:43: error: 'RES_OK' was not declared in this scope
     if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
                                           ^~~~~~
C:\Users\Michael\Desktop\USBMonitor\USBMonitor.ino:436:43: note: suggested alternative: 'ETS_OK'
     if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
                                           ^~~~~~
                                           ETS_OK

@chegewara
Copy link
Owner

I didnt post included headers:

#include "ff.h"
#include "diskio.h"
void tud_msc_write10_complete_cb(uint8_t lun)
{
    if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
    {
        Serial.printf("failed to sync\n");
    }
}

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

2 participants