Help with FAT

Can someone help me with understanding FAT? I have a window formatted FA16 flash drive with FAT at 0 and 62, and the actual root directory entry at sector 542 (from data dump). The app is trying to read from sector 224 instead. I just can't figure out the relationships. What other data do I need to provide?

no MBR, FAT16 SecPerClus = 32 fat = 2 fatcopy = 2 fatsize = 239 root = 224 maxcls = 64 RootDirSectors = 32

Reply to
linnix
Loading thread data ...

Here you go:

formatting link

Reply to
Dave Nadler

Not that FAT.

Reply to
linnix

Can you post a dump of the LBR for the volume? Or just the (E)BPB really, bytes 11-60. There is at least one field you didn't mention, which is "number of sectors before volume" and I'm curious what it contains.

The "rules" for MS-DOS volumes are variously interpreted. If you look at the rules my FAT fs follows when reading the LBR, you should be in pretty good shape - there are no known bugs there and I took the processing steps from canonical MS documentation.

Reply to
larwe

d

Here are the parameters out of the BPB:

OEM ID =3D MSDOS5.0 Bytes per sector =3D 512 Sector per cluster =3D 32 Sector per FAT (spf) =3D 238 (239) Reserved sector =3D 2 Number of FATs =3D 2 Number of head =3D 1 Root entries =3D 512 Small sectors =3D 0 Hidden sectors =3D 0 PIC Starting root =3D 478 (480) Real Starting root =3D 542 (543)

I formatted it under window and created a file "DISKID.TXT". I scanned the raw image and determined that it was at sector 542 (spf of

238). I forced the PIC FSIO library to use root of 542, then it worked properly. But i moved things a bit, then the file moved to 543 (spf of 239) and it does not work anymore.

The PIC library use: root =3D fat + fatcopy * fatsize =3D 480; which is totally wrong anyway.

Reply to
linnix

You do understand that if the flash is wear-leveling then things will move every time you update them?

See:

formatting link

The basics are covered in the article and there are links to more information than you can possibly care about.

And a freeware implementation to study is here:

formatting link

George

Reply to
George Neuner

tted

rom

My understanding of wear leveling is that it is transparent to the=20 interface. The hardware may move the physical location of the FAT, or=20 any other item, but when sector 0 is requested you get what has always=20 been at sector 0, not some physical address into the FLASH ICs. You=20 could never make a SD or Compact Flash card work as a boot device=20 otherwise. If sector 0 got moved to sector 100, it isn't sector 0=20 anymore. I don't know how you would access the raw addresses of the ICs anyway. It should be translated through the on board hardware.

Reply to
WangoTango

You're right.

The FAT file system (and others as well) operates on a logical disk layer provided by the stick hardware. The translation between the logical disk sectors and the physical Flash locations takes care of the relocation of used sectors and wear leveling.

The logical disk addresses stay the same, even as the physical location of the data changes.

--

Tauno Voipio
Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.