Understanding FAT16 operation

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Understanding FAT16 operation

Post 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.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Understanding FAT16 operation

Post by Antti »

You somehow managed to get a FAT 12 layout. Something went wrong.
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Re: Understanding FAT16 operation

Post 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...
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Re: Understanding FAT12 operation

Post 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.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Understanding FAT16 operation

Post 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.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Understanding FAT16 operation

Post 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.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Understanding FAT16 operation

Post 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.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Understanding FAT16 operation

Post 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.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Understanding FAT16 operation

Post 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.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Understanding FAT12 operation

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Understanding FAT12 operation

Post 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.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Understanding FAT16 operation

Post 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.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Understanding FAT12 operation

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Understanding FAT16 operation

Post 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.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Understanding FAT12 operation

Post 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.
Post Reply