15

I have an application which will search for a corrupted FAT file system and repair it.

For testing the application I will need a corrupted file system.

What is a good and reproducible way for corrupting a FAT file system? Creating bad sectors for example.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
arash javan
  • 381
  • 1
  • 12

1 Answers1

20

a partial solution

 dd if=/dev/zero count=100 bs=1k of=fs.fat
 mkfs -t vfat fs.fat
 mount fs.fat /mnt ## as root
 # cp some file
 umount /mnt ## as root

 cp fs.fat fs.ref
 vi fs.ref ## change some bytes
 cp fs.ref fs.sampleX

now you have a good fs (fs.fat) and a corrupted one (fs.ref)

sudo mount -t vfat fs.ref /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
  • you can try to fix fs.sampleX
  • knowing a bit about fat (or filesystem layout) might help to "cleverly corrupt" fs.ref
  • this can be applied to any fs type (extX, xfs, ... )
Archemar
  • 31,183
  • 18
  • 69
  • 104