Page 1 of 2

Understanding FAT16 operation

Posted: Wed May 29, 2013 3:18 am
by stdcall
I'm developing a flash based USB mass storage device with FAT16 file system.
It's working properly, however I have difficulties understanding what's happening on the FAT segments.

When I begin, I have a single file, 56 bytes long on the root directory, it's 32bits long and the data is stored on the 2nd cluster (the 0 and the 1 can't be used in FAT).

if I look at the memory dump of the FAT segment I see:

Code: Select all

f8 ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00... zeros until the end
As I understand, the last 0xFFFF means that this cluster is the last cluster in the chain for this file.

so far so good.

But... when I extend the size of the actual file to 4,032 bytes , the FAT segment turn into

Code: Select all

f8 ff ff 00 f0 ff 05 60 00 07 f0 ff 00 00 00 00 00... zeros until the end
Can anyone explain what's going on here ?

I see several things I can't explain:

1. why does the 4 system reserved bytes change ?

2. I can't see any 0xFFFF which means, there isn't an end to the cluster chain ?



If it helps anyone, the block size is 512 bytes, the file system is formatted 2 segments per cluster.

Re: Understanding FAT16 operation

Posted: Wed May 29, 2013 4:20 am
by Antti
You somehow managed to get a FAT 12 layout. Something went wrong.

Re: Understanding FAT16 operation

Posted: Sat Jun 01, 2013 4:27 am
by stdcall
You're right, I only considered the option that it's FAT16, but it's FAT12, now it's clear...
Well.... I still have to mingle those ugly unalligned bytes...

Re: Understanding FAT12 operation

Posted: Sun Jun 16, 2013 2:08 pm
by stdcall
I'm still struggling with the FAT12 addressing, I just don't get it...

I need an example if someone can help me.

I want to understand how a FAT12 block for single file that starts on cluster 2 and continues through cluster 3, 4, and ends on the 5th cluster looks like

on FAT 16 it will be something like:

Code: Select all

F8 FF FF FF 03 00 04 00 05 00 FF FF 00 00 00 00 00... zeros until the end
How will it look on FAT 12 ?

Thanks.

Re: Understanding FAT16 operation

Posted: Sun Jun 16, 2013 2:30 pm
by iansjack
You know, you could always try it on a FAT12 file system (use a disk image if you like) and see what the result is.

Re: Understanding FAT16 operation

Posted: Sun Jun 16, 2013 3:28 pm
by Casm
Why bother with FAT12? Nobody uses floppy disks anymore.

Come to that, FAT16 wouldn't be much use for a pen drive with maybe 16Gb on it.

Re: Understanding FAT16 operation

Posted: Sun Jun 16, 2013 6:07 pm
by Kazinsal
Casm wrote:Why bother with FAT12? Nobody uses floppy disks anymore.
Because someone will, at some point, and if you don't support that function, they're going to say your OS is crap. All because you couldn't take a few hours to add in 12-bit FAT handling and write/pillage an ISA floppy driver.

Re: Understanding FAT16 operation

Posted: Sun Jun 16, 2013 6:50 pm
by Casm
Blacklight wrote:
Casm wrote:Why bother with FAT12? Nobody uses floppy disks anymore.
Because someone will, at some point, and if you don't support that function, they're going to say your OS is crap. All because you couldn't take a few hours to add in 12-bit FAT handling and write/pillage an ISA floppy driver.
In the first place I doubt if my OS will become quite as widely distributed as Linux, and, in the second place, does even Windows still have support for 360kb floppies? Because not very many years from now, 1.44mb floppies will be about as common as they are today.

Re: Understanding FAT16 operation

Posted: Mon Jun 17, 2013 12:45 am
by VolTeK
Blacklight wrote:does even Windows still have support for 360kb floppies
http://support.microsoft.com/kb/309623

Install device driver in XP Mode.

Re: Understanding FAT12 operation

Posted: Mon Jun 17, 2013 1:24 am
by egos
mellowcandle wrote:How will it look on FAT 12 ?
You can look at any FAT12 cluster chain to see that. It should look like this: FX FF FF 03 40 00 05 F0 FF ...
Casm wrote:Why bother with FAT12? Nobody uses floppy disks anymore.
You can have FAT12 volume on hard disk as well.

Re: Understanding FAT12 operation

Posted: Mon Jun 17, 2013 4:39 am
by Casm
egos wrote:
mellowcandle wrote:How will it look on FAT 12 ?
You can look at any FAT12 cluster chain to see that. It should look like this: FX FF FF 03 40 00 05 F0 FF ...
Casm wrote:Why bother with FAT12? Nobody uses floppy disks anymore.
You can have FAT12 volume on hard disk as well.
12 bits will get you about 4096 clusters, so, unless you are prepared to entertain a truly enormous cluster size, you can't use FAT12 on a hard disk. That is why FAT16, and then FAT32, were invented.

Re: Understanding FAT16 operation

Posted: Mon Jun 17, 2013 4:40 am
by Casm
VolTeK wrote:
Blacklight wrote:does even Windows still have support for 360kb floppies
http://support.microsoft.com/kb/309623

Install device driver in XP Mode.
I expect Windows 98 supports them as well, but they are still obsolete.

Re: Understanding FAT12 operation

Posted: Mon Jun 17, 2013 6:08 am
by egos
Casm wrote:12 bits will get you about 4096 clusters, so, unless you are prepared to entertain a truly enormous cluster size, you can't use FAT12 on a hard disk. That is why FAT16, and then FAT32, were invented.
Which FS is used depends on partition size. Sometimes a necessity arises to use small partition, especially for OSDev.

Re: Understanding FAT16 operation

Posted: Mon Jun 17, 2013 2:21 pm
by VolTeK
Casm wrote:I expect Windows 98 supports them as well, but they are still obsolete.
Hiding information. Almost no one has a machine that contains a drive for floppies.



Except 99% of everyone on this forum who has built and tested their own FAT12 file system drivers.

Re: Understanding FAT12 operation

Posted: Mon Jun 17, 2013 2:51 pm
by Casm
egos wrote:
Casm wrote:12 bits will get you about 4096 clusters, so, unless you are prepared to entertain a truly enormous cluster size, you can't use FAT12 on a hard disk. That is why FAT16, and then FAT32, were invented.
Which FS is used depends on partition size. Sometimes a necessity arises to use small partition, especially for OSDev.
If I was going to create a reserved partition, I would make it at least 100mb, so that I had the option of stuffing things into it in the future.