Reading FAT12 entries sector by sector

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
cybek
Posts: 11
Joined: Tue Dec 27, 2011 4:41 pm

Reading FAT12 entries sector by sector

Post by cybek »

Hi!
I got confused reading about FAT12. Two FAT entries are saved on 3 bytes. But FDD sector is 512 bytes what is not divisible by 3. So what you have to do to read FAT table? You read 1 sector on demand. Do you need to check if entry is written on 2 sectors and read 1st sector, remember part of entry, than read 2nd sector and remember second part of this entry?
Am I right that you have to include this special case reading procedure, or I'm missing something?

Best regards,
cybek
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Reading FAT12 entries sector by sector

Post by iansjack »

For the sake of efficiency you want to cache the FAT in RAM. If I were to support FAT12 I would just read the whole table from the disk and treat it as a large array.
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: Reading FAT12 entries sector by sector

Post by mikegonta »

cybek wrote:I got confused reading about FAT12. Two FAT entries are saved on 3 bytes. But FDD sector is 512 bytes what is not divisible by 3.
FAT12 is not always floppy disk (and floppy disk is not always FAT12).
Mike Gonta
look and see - many look but few see

https://mikegonta.com
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Reading FAT12 entries sector by sector

Post by BenLunt »

I agree with both replies. :-)

Your understanding is correct. However, a FAT12 (legally) cannot be larger than 4,084 clusters which would use a 6,126 byte FAT table. Easily managed in 16-bit code.

Ben
http://www.fysnet.net/the_virtual_file_system.htm
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Reading FAT12 entries sector by sector

Post by alexfru »

If it helps, note that 3 512-byte sectors contain an integral number of 12-bit integers.
cybek
Posts: 11
Joined: Tue Dec 27, 2011 4:41 pm

Re: Reading FAT12 entries sector by sector

Post by cybek »

iansjack wrote:For the sake of efficiency you want to cache the FAT in RAM. If I were to support FAT12 I would just read the whole table from the disk and treat it as a large array.
Yeah, but my main thought is RAM efficiency. If I would write 32bit OS, I would cache whole FAT :)
mikegonta wrote:FAT12 is not always floppy disk (and floppy disk is not always FAT12).
Yes, I know. But I'm thinking about floppy. And is there really anything else what use FAT12? Maybe first hdds were.
BenLunt wrote:I agree with both replies. :-)
Your understanding is correct. However, a FAT12 (legally) cannot be larger than 4,084 clusters which would use a 6,126 byte FAT table. Easily managed in 16-bit code.
Thanks for answer. Right, 6kB is not much, maybe I'm wondering too much about RAM efficiency.
alexfru wrote:If it helps, note that 3 512-byte sectors contain an integral number of 12-bit integers.
I feel stupid now. This is the method I will probably use. Thank you very much!
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Reading FAT12 entries sector by sector

Post by iansjack »

cybek wrote:
iansjack wrote:For the sake of efficiency you want to cache the FAT in RAM. If I were to support FAT12 I would just read the whole table from the disk and treat it as a large array.
Yeah, but my main thought is RAM efficiency.
You are accepting abysmal performance to save 4.5KB of RAM?

Poor design decision.
Post Reply