<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic MFS FAT Corruption in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201812#M4591</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We had a unit returned that we believe was powered down when MFS was in an unsafe state. It ended up on my desk with a wiped boot sector, and I tried to design an experiment to replicate the problem, by cutting power to a unit, with MFS in various random states such as:files open, the middle of write, and in process of deletion (this one really jacks things up BTW). I was able to seriously mangle things up, and was surprised to find that Microsoft chkdsk.exe couldn't make things even partly right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I remembered seeing a reference in MFS source that set&amp;nbsp; #define MFSCFG_NUM_OF_FATS 1, and reading some white papers on chkdsk.exe suggested that a single FAT table might cause prevent a chkdsk type program from fixing common errors as the secondary FAT provides backup and is relied on for certain errors (2 FAT tables are the standard).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well adding #define MFSCFG_NUM_OF_FATS 2 in my User_Config.h file really made a mess of things.&lt;/P&gt;&lt;P&gt;Here is a screen shot of the directory structure after rebuilding MQX 3.8 with the new setting. Then my code calling&lt;/P&gt;&lt;P&gt;ioctl(fshandle, IO_IOCTL_DEFAULT_FORMAT,NULL);&lt;/P&gt;&lt;P&gt;followed by several hundred ioctl(fshandle, IO_IOCTL_CREATE_SUBDIR, (uint_32_ptr)dirName) and fwrite operations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUESTION TIME: IF I missed a step what do I need to do to make it all work nice?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/38664iE23FB530C742F243/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Sep 2012 20:08:40 GMT</pubDate>
    <dc:creator>timias</dc:creator>
    <dc:date>2012-09-26T20:08:40Z</dc:date>
    <item>
      <title>MFS FAT Corruption</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201812#M4591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We had a unit returned that we believe was powered down when MFS was in an unsafe state. It ended up on my desk with a wiped boot sector, and I tried to design an experiment to replicate the problem, by cutting power to a unit, with MFS in various random states such as:files open, the middle of write, and in process of deletion (this one really jacks things up BTW). I was able to seriously mangle things up, and was surprised to find that Microsoft chkdsk.exe couldn't make things even partly right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I remembered seeing a reference in MFS source that set&amp;nbsp; #define MFSCFG_NUM_OF_FATS 1, and reading some white papers on chkdsk.exe suggested that a single FAT table might cause prevent a chkdsk type program from fixing common errors as the secondary FAT provides backup and is relied on for certain errors (2 FAT tables are the standard).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well adding #define MFSCFG_NUM_OF_FATS 2 in my User_Config.h file really made a mess of things.&lt;/P&gt;&lt;P&gt;Here is a screen shot of the directory structure after rebuilding MQX 3.8 with the new setting. Then my code calling&lt;/P&gt;&lt;P&gt;ioctl(fshandle, IO_IOCTL_DEFAULT_FORMAT,NULL);&lt;/P&gt;&lt;P&gt;followed by several hundred ioctl(fshandle, IO_IOCTL_CREATE_SUBDIR, (uint_32_ptr)dirName) and fwrite operations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUESTION TIME: IF I missed a step what do I need to do to make it all work nice?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/38664iE23FB530C742F243/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 20:08:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201812#M4591</guid>
      <dc:creator>timias</dc:creator>
      <dc:date>2012-09-26T20:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: MFS FAT Corruption</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201813#M4592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interestingly enough. I decided to rebuild one more time, redeploy, and retest, and this time it seemed to work fine. I am 100% convinced that rebuilding the PSP/ BSP was not out of sync as I did a complete clean and rebuild before deploying. . Could the fact that the SD Card had been formatted with a single FAT earlier, be contributing factor?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In either case I am not sure why it has decided to work. Clearly something didn't work right the first time, any Ideas where to start looking/ repeating the results?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 21:43:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201813#M4592</guid>
      <dc:creator>timias</dc:creator>
      <dc:date>2012-09-26T21:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: MFS FAT Corruption</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201814#M4593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I seem to have confirmed that the corruption happens, when formatting a disk where the previous format had been done using MFSCFG_NUM_OF_FATS 1 and you are now formatting MFSCFG_NUM_OF_FATS 2. But if you format it again, from the corrupted state to MFSCFG_NUM_OF_FATS 2 it works fine. UGH I thought I was going nuts. FYI the format command takes a really long time when it corrupts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 22:19:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201814#M4593</guid>
      <dc:creator>timias</dc:creator>
      <dc:date>2012-09-26T22:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: MFS FAT Corruption</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201815#M4594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Robert,&lt;/P&gt;&lt;P&gt;Thank you for sharing your experience with one and all.&lt;/P&gt;&lt;P&gt;Sorry for the hassle too.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2012 01:16:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201815#M4594</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2012-09-27T01:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: MFS FAT Corruption</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201816#M4595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Robert&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We use the FAT system as well and what we did was to do a flush of the file at each collection, then after n flushes, 64 in our case, we close the file and reopen. We also built the array of data into a size that was a set of structures that is 512 bytes. FAT writes best in 512 byte blocks although you can do other sizes.&amp;nbsp; The reason was, that way we only loose the last block if a problem occurs and all the file table information is updated properly. Failing this method, we found that there are a lot of things that can cause the FAT system to go sideways and with 0 blocks written, names all muddled up and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last file software we used that was our own, and a flush moved the end of file marker (0x55, 0xAA) to after the record written and all was well if the system crashed. But the FSL FAT system doesn't move the marker except on a close and if the file is not closed the whole sorry mess was lost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is an overhead in doing it this way but at least all the enteries are completed correctly. It is on our list todo, to mod the system to move the EOF after each flush.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Robert Lewis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2012 23:02:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201816#M4595</guid>
      <dc:creator>Cdn_aye</dc:creator>
      <dc:date>2012-09-27T23:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: MFS FAT Corruption</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201817#M4596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The patch from &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/aimozg"&gt;aimozg&lt;/A&gt; may help you (see &lt;A href="https://community.nxp.com/thread/112014"&gt;Howto flush MFS? (Use case: mfs onto ramdisk)&lt;/A&gt;). Good luck!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2012 08:42:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MFS-FAT-Corruption/m-p/201817#M4596</guid>
      <dc:creator>Fabi</dc:creator>
      <dc:date>2012-10-01T08:42:27Z</dc:date>
    </item>
  </channel>
</rss>

