4

Is there a way to purposefully corrupt a FAT file system using only Win32 calls or must you do it at lower level? We're encountering FAT corruption on a WinCE 5.0 device and have written a utility to detect and attempt to correct it, but don't have a means to create FAT corruption on demand. Thanks.

The media is a CF card, but it's not removable as a normal course as it's mounted internal to the device.

Damon8or
  • 527
  • 2
  • 11
  • 1
    Does the WinCE device use removable storage of some kind? – Adam Eberlin Sep 29 '11 at 15:15
  • 2
    I'd hope you can't do it using the API. That would be a bug. I'm sure you'll have to look at using lower level instructions. If you can just kill the power during writes or 'eject' the drive that should corrupt it. – Matthijs Bierman Sep 29 '11 at 15:15

2 Answers2

3

You can access device data as a raw file and write random data in that file to corrupt FAT. E.g. if you write random data on:

\?\Device\HarddiskVolume1

This would corrupt first partition.

This page has some hints on how to figure out paths for HDD/USB drive etc.

http://www.chrysocome.net/dd

Shamit Verma
  • 3,839
  • 23
  • 22
  • 1
    @Adam, thats one of the reasons why nobody should login as Admin for day to day work. Generic file API gives raw access to data to admin users. – Shamit Verma Sep 29 '11 at 15:27
  • 6
    @Shamit: Login as admin? Windows CE doesn't have logins or user authentication so there's no such thing as an "admin user" – ctacke Sep 29 '11 at 15:53
3

What's the FAT on (e.g. inserted USB, on-board flash, etc)? That's going to make a large difference.

If it's the on-board flash, you need to get underneath the file system driver (FSD), which is typically going to be the flash driver itself. It's going to have access to the raw flash sectors (it's what the FSD uses for its reads and writes) either through Xxx_Write or Xxx_Ioctl. Exactly how it works is going to depend on the flash driver in use, so looking at the driver source is your best path.

ctacke
  • 66,480
  • 18
  • 94
  • 155