Author Topic: Making Fat Sd Cards More Robust  (Read 4866 times)

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« on: March 26, 2007, 06:15:58 pm »
Hi guys,

I have observed, that when you remove a FAT-formatted SD card without unmounting it cleanly, the entire FAT contents may be erased.
Sometimes only the files which have been added to the FS are gone, but sometimtes the card will appear EMPTY after such faulty handling.

Two questions:

Is there a way to make a FAT-formatted SD card more robust, so something like this won't happen? (e.g. switching off some FAT write cache, adding more FAT copies etc. etc.)?

Is there a way to rebuild the FAT (automatically, not manually) after such an incident?

Windows' scandisk won't recover the FAT, and fsck.vfat won't, too, even when using the first OR the second FAT copy.

Thank you for your ideas!

Daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

InSearchOf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1144
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #1 on: March 26, 2007, 06:20:32 pm »
well you could change the mount option to async... that may help... instead of sync which is the default

Late
Sharp Zaurus SL-C3100 and SL-6000L
pdaXrom Developer
Please visit pdaXrom.org for updates
My Blog
IRC #pdaxrom @ FreeNode

desertrat

  • Hero Member
  • *****
  • Posts: 743
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #2 on: March 27, 2007, 12:57:56 am »
Quote
well you could change the mount option to async... that may help... instead of sync which is the default
But isn't sync supposed to keep the filesystem (hence FAT) updated immediately (at the expense of using extra flash write cycles) whereas async will cache changes to the filesystem until the kernel(?) decides it's time to write the changes or you do sync or umount, whichever is sooner.
« Last Edit: March 27, 2007, 12:59:13 am by desertrat »
SL-C3100 / Ambicon WL1100C-CF / pdaXrom 1.1.0beta3 / IceWM

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Making Fat Sd Cards More Robust
« Reply #3 on: March 27, 2007, 06:39:41 am »
Quote
Quote
well you could change the mount option to async... that may help... instead of sync which is the default
But isn't sync supposed to keep the filesystem (hence FAT) updated immediately (at the expense of using extra flash write cycles) whereas async will cache changes to the filesystem until the kernel(?) decides it's time to write the changes or you do sync or umount, whichever is sooner.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157263\"][{POST_SNAPBACK}][/a][/div]

yeah, desertrat got it right.

the only way is to properly unmount your partition, and adding an extra sleep in the eject script so it actually waits an additional second or two for the filesystem to sync up completely if it is a larger SD card.

note that the two FAT tables are only applicable if you are using FAT12 or FAT16. FAT32 uses both tables since it needs the extra space to store long file names and support larger filesystems...
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #4 on: March 27, 2007, 08:45:14 am »
Quote
yeah, desertrat got it right.

the only way is to properly unmount your partition, and adding an extra sleep in the eject script so it actually waits an additional second or two for the filesystem to sync up completely if it is a larger SD card.

note that the two FAT tables are only applicable if you are using FAT12 or FAT16. FAT32 uses both tables since it needs the extra space to store long file names and support larger filesystems...
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157273\"][{POST_SNAPBACK}][/a][/div]

aha, so for a card up to 2GB a FAT16 fs would be better (i.e. safer) than a FAT32, right?

Is the only disadvantage of FAT16 the large cluster size of 32kB and the fixed root directory size?

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #5 on: March 27, 2007, 09:21:25 am »
Quote
note that the two FAT tables are only applicable if you are using FAT12 or FAT16. FAT32 uses both tables since it needs the extra space to store long file names and support larger filesystems...
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157273\"][{POST_SNAPBACK}][/a][/div]

On a German website (don#t remember where, though) I got other information.
There it was written "FAT32 uses, as opposed to FAT16, the second FAT really for error correction".
which seems to imply that the second FAT in FAT16 was simply redundant and unused...

Which information is correct?
Do you have a good source for correct information?
There is not much information about that on the internet.

thanks

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

InSearchOf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1144
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #6 on: March 27, 2007, 10:05:27 am »
Quote
Quote
well you could change the mount option to async... that may help... instead of sync which is the default
But isn't sync supposed to keep the filesystem (hence FAT) updated immediately (at the expense of using extra flash write cycles) whereas async will cache changes to the filesystem until the kernel(?) decides it's time to write the changes or you do sync or umount, whichever is sooner.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157263\"][{POST_SNAPBACK}][/a][/div]

But if Daniel was stating that removing a sd card on the fly instead of umount is where the issue is caused... this is the exact reason why floppy drives are mounted sync because a typical person doesnt umount mount a floppy before removing it.

Sync will allow a user to remove there sd with out the hassle of umount'in it but yes you will suffer when it comes to write counts on a "write limited" device...

Late
Sharp Zaurus SL-C3100 and SL-6000L
pdaXrom Developer
Please visit pdaXrom.org for updates
My Blog
IRC #pdaxrom @ FreeNode

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #7 on: March 28, 2007, 12:43:07 pm »
Quote
But if Daniel was stating that removing a sd card on the fly instead of umount is where the issue is caused... this is the exact reason why floppy drives are mounted sync because a typical person doesnt umount mount a floppy before removing it.

Sync will allow a user to remove there sd with out the hassle of umount'in it but yes you will suffer when it comes to write counts on a "write limited" device...

Late
[div align=\"right\"][{POST_SNAPBACK}][/a][/div]

Just found this text on Microsoft TechNet (and they should know well about their FSs):

Code: [Select]
FAT32 is more robust than FAT16. FAT32 has the ability to relocate the root directory and use the backup copy of the FAT instead of the default copy. In addition, the boot record on FAT32 drives has been expanded to include a backup of critical data structures. This means that FAT32 volumes are less susceptible to a single point of failure than FAT16 volumes.
It's found here:
[a href=\"http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/core/fncc_fil_blpd.mspx?mfr=true]http://www.microsoft.com/technet/prodtechn...d.mspx?mfr=true[/url]

Well, this is the theory and probably true in Windows.
but is it also true in Linux with the vfat fs driver?
The driver may be old and thus support FAT16 better than FAT32.

Who has experiences or even knowledge?


Regarding the sync mount:

Is sync the default?
in /etc/sdcontrol the line "FATOPTS=..." is commented out, and it even doesn't contain sync or async, so there is no parameter "sync" for the SD card mount command.
When looking at the mout table, there is no mention of "sync".

Also, as InSearchOf says, the mout man page says:

Code: [Select]
All I/O to the file system should be done synchronously. In case of media with limited number of write cycles (e.g. some flash drives) "sync" may cause life-cycle shortening
so actually from this point of view, sync is not good for flash cards.
However, I would rather be failsafe now than in the future because I expect to exchange my SD card anyway after some time.
Some even have swap on SD and say it works for months without a problem.
So lifeycle is probably not a big issue anymore.

Is there any known value in how mucht "sync" will increase the number of write processes? Probably depends heavily on the kind of usage. But typical usage, i.e. open a file, work on it, save it, will not let "sync" increase write cycles much, would it?

Maybe with a swap file on SD it would. Or with other random access type files.

What's your opinion?



daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #8 on: March 28, 2007, 12:51:56 pm »
Here is a very interesting article, discussing several aspects about mounting sync:

https://wiki.ubuntu.com/SyncMount

I think I will try it. :-)

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Making Fat Sd Cards More Robust
« Reply #9 on: March 28, 2007, 01:01:21 pm »
Code: [Select]
FAT32 is more robust than FAT16. FAT32 has the ability to relocate the root directory and use the backup copy of the FAT instead of the default copy. In addition, the boot record on FAT32 drives has been expanded to include a backup of critical data structures. This means that FAT32 volumes are less susceptible to a single point of failure than FAT16 volumes.
This is true if you are using a FAT32 enhanced driver and FAT32 enhanced fsck which should be win98 scandisk equivalent. however, the vfat support in linux and the corresponding fsck.vfat are not that advanced. vfat support has improved in that it can handle FAT32 lfn extensions, but fsck.vfat is still approximately equivalent to DOS6.0 chkdsk/scandisk. If you ever ran a DOS6.0 scandisk on a FAT32 filesystem (not a DOS 6.2 version which has been enhanced), then you will know what I mean.

as for sync/async mode, in SharpROM, I found that using sync mode on larger SD cards, ie 4GB cards, can prevent it from loosing its partition table, especially if the card is relatively full. When the card is empty, there is not much difference...
On OpenZaurus, sync mode causes the SD card to be extremely slow and almost unusable.
In pdaXrom depending on the kernel version and sd module being used, the default setting which I think is async, works fine...
« Last Edit: March 28, 2007, 01:06:33 pm by Meanie »
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Making Fat Sd Cards More Robust
« Reply #10 on: March 28, 2007, 01:04:19 pm »
so, maybe you need to run bochs or dosbox and fsck your fat32 flash memory card using that!
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #11 on: March 28, 2007, 01:17:22 pm »
Quote
This is true if you are using a FAT32 enhanced driver and FAT32 enhanced fsck which should be win98 scandisk equivalent. however, the vfat support in linux and the corresponding fsck.vfat are not that advanced. vfat support has improved in that it can handle FAT32 lfn extensions, but fsck.vfat is still approximately equivalent to DOS6.0 chkdsk/scandisk. If you ever ran a DOS6.0 scandisk on a FAT32 filesystem (not a DOS 6.2 version which has been enhanced), then you will know what I mean.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157435\"][{POST_SNAPBACK}][/a][/div]

Aha, so you mean that fsck.vfat can much better recover FAT16 than FAT32 corruption?
Would you recommend FAT16 over FAT32 on pdaXrom for an SD card which mainly holds user files?


I just did some tests with sync mounting:

1GB SD card with FAT32 sync-mounted.

Then:
touch /mnt/card/test
ls /mnt/card --> test is shown. Wait a few seconds, then:
Removed the card without cleanly unmounting it.
inserted the card
ls /mnt/card --> test is NOT shown.

touch /mnt/card/test && sync. Don't wait, but:
Removed the card without cleanly unmounting it.
inserted the card
ls /mnt/card --> test IS shown.

So - does the sync option have no effect??
Only when waiting quite a long time after the touch command (maybe half a minute) before ejecting the card preserves the new file entry.

So maybe a cronjob which executes "sync" every second would be good  

But at least I get no "filesystem panic" messages from the kernel now.
When doing similar tests without -o sync, this happened often.

Maybe, FAT16 with -o sync is really the safest option.

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

InSearchOf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1144
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #12 on: March 28, 2007, 01:21:31 pm »
Quote
Quote
This is true if you are using a FAT32 enhanced driver and FAT32 enhanced fsck which should be win98 scandisk equivalent. however, the vfat support in linux and the corresponding fsck.vfat are not that advanced. vfat support has improved in that it can handle FAT32 lfn extensions, but fsck.vfat is still approximately equivalent to DOS6.0 chkdsk/scandisk. If you ever ran a DOS6.0 scandisk on a FAT32 filesystem (not a DOS 6.2 version which has been enhanced), then you will know what I mean.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157435\"][{POST_SNAPBACK}][/a][/div]

Aha, so you mean that fsck.vfat can much better recover FAT16 than FAT32 corruption?
Would you recommend FAT16 over FAT32 on pdaXrom for an SD card which mainly holds user files?


I just did some tests with sync mounting:

1GB SD card with FAT32 sync-mounted.

Then:
touch /mnt/card/test
ls /mnt/card --> test is shown. Wait a few seconds, then:
Removed the card without cleanly unmounting it.
inserted the card
ls /mnt/card --> test is NOT shown.

touch /mnt/card/test && sync. Don't wait, but:
Removed the card without cleanly unmounting it.
inserted the card
ls /mnt/card --> test IS shown.

So - does the sync option have no effect??
Only when waiting quite a long time after the touch command (maybe half a minute) before ejecting the card preserves the new file entry.

So maybe a cronjob which executes "sync" every second would be good  

But at least I get no "filesystem panic" messages from the kernel now.
When doing similar tests without -o sync, this happened often.

Maybe, FAT16 with -o sync is really the safest option.

daniel
[div align=\"right\"][a href=\"index.php?act=findpost&pid=157442\"][{POST_SNAPBACK}][/a][/div]


How about add the sync option to fstab

Late
Sharp Zaurus SL-C3100 and SL-6000L
pdaXrom Developer
Please visit pdaXrom.org for updates
My Blog
IRC #pdaxrom @ FreeNode

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #13 on: March 28, 2007, 01:51:38 pm »
Quote
How about add the sync option to fstab

[div align=\"right\"][a href=\"index.php?act=findpost&pid=157444\"][{POST_SNAPBACK}][/a][/div]

Should this make a difference?
I have added it to the /etc/sdcontrol script, and the card IS mounted with the sync option ("mount" shows (rw,sync) as the mount options).

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

InSearchOf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1144
    • View Profile
    • http://
Making Fat Sd Cards More Robust
« Reply #14 on: March 28, 2007, 02:24:10 pm »
yea your right... I forgot sdcontrol mounts it... unless you umount and remount from the console... that uses fstab data...

Late
Sharp Zaurus SL-C3100 and SL-6000L
pdaXrom Developer
Please visit pdaXrom.org for updates
My Blog
IRC #pdaxrom @ FreeNode