MFS Corruption

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MFS Corruption

Jump to solution
1,995 Views
Ardoster
Contributor III

Hi

Checking in this forum, i've seen this is a very recurrent discussion, but i can't see a good solution or good recovery way.

My problem is I have a device with a 2 MB memory flash, and I'm using it to receive a 800K file through FTP. I've verified my system, including the filesystem and everithing is OK. Now, I'm testing the system against power or conection losts, and it's here where the problems begin: if the transfer is interrupted due to a power lost, when the system reboot, i verify the file and I detect is not a valid file (remember the transfer was interrupted), so I delete it. If I repeat this process 2 or 3 times, I arrive to a moment where the transfer can't be completed because, apparently, the flash memory is full.

I guess than because MFS corruption, when I delete the file, it is not being deleted completely, so there are sectors still marked as occupied.

What can i do??? I've tried my system using 2 FAT tables, or using CACHE, in the 3 different modes (write_back, mixed or through).... using codes like :

param = MFS_WRITE_THROUGH_CACHE;

_io_ioctl ( g_MFS_SYSTEM_filesystem_handle, IO_IOCTL_SET_FAT_CACHE_MODE, &param );

_io_ioctl ( g_MFS_SYSTEM_filesystem_handle, IO_IOCTL_SET_WRITE_CACHE_MODE, &param );

_io_ioctl ( g_MFS_SYSTEM_filesystem_handle, IO_IOCTL_FAT_CACHE_OFF, NULL );

But the problem remains. I've too applied the patch mentioned in this thread (Howto flush MFS? (Use case: mfs onto ramdisk)), but with no results.

Is there a chkdsk function for MQX MFS???? Any other solution to avoid corruption????

Any help would be very appreciated. Thanks in advance.

Regards

Labels (1)
Tags (2)
0 Kudos
1 Solution
672 Views
pavel_chromy
NXP Employee
NXP Employee

Hello Ardoster,

I am sorry to say that but there is really no 100% reliable way to prevent corruption of a FAT filesystem.

The only thing which could be done is to minimize the risk this happens by using write-through or regularly flushing cache.

Please see the forum topic about flushing one more time, I have posted a complete patch for flush which did not previously work as expected.

Please note that filesystem corruption on unexpected power loss this is not a problem of MQX or MFS but rather a generic property of FAT filesystem. You would have to use a filesystem which features journaling for this to be reliable.

Regards, Pavel

View solution in original post

0 Kudos
5 Replies
673 Views
pavel_chromy
NXP Employee
NXP Employee

Hello Ardoster,

I am sorry to say that but there is really no 100% reliable way to prevent corruption of a FAT filesystem.

The only thing which could be done is to minimize the risk this happens by using write-through or regularly flushing cache.

Please see the forum topic about flushing one more time, I have posted a complete patch for flush which did not previously work as expected.

Please note that filesystem corruption on unexpected power loss this is not a problem of MQX or MFS but rather a generic property of FAT filesystem. You would have to use a filesystem which features journaling for this to be reliable.

Regards, Pavel

0 Kudos
672 Views
Ardoster
Contributor III

Hi

Thanks you for your reply. It has been really very useful.

The decission I took yesterday was to disable caching (so I'm using write-through), and to modify the FTP application to open & write & close the file constantly. At this way, the corruption of the FAT should be limited to one page. I've made several tests and they are OK, although the writing proccess is quite slower (about twice slower).

I can't assure this method is 100% reliable, but at least should be quite more robust.

Thanks you again.

Regards,

Eduardo

0 Kudos
672 Views
pavel_chromy
NXP Employee
NXP Employee

Please try the patch in my last post here:  Howto flush MFS? (Use case: mfs onto ramdisk)

Whit this patch there is no need to open/write/close if you regularly call fflush (prefferably after each write or write sequence).

Pavel

0 Kudos
672 Views
JerryFan
NXP Employee
NXP Employee

What's the media you are using, NAND, SPINOR, or something else? If Nand, did you ever enable FFS? And did you ever reproduce this on any FSL reference board?

0 Kudos
672 Views
Ardoster
Contributor III

Hi

Thanks you for your interest. In fact, I'm using a SPI NOR memory. I made an adaptation to MFS to use this memory like a SD card memory. This adaptation has been working correctly for months, the problem is until now, i've not tested transfer interruptions with big size files. And this is the result.

It's not a problem about the media. The problem is the FAT table of MFS.

Thanks you

0 Kudos