Page 1 of 1

Reading FAT12 entries sector by sector

Posted: Sat Jul 09, 2016 3:25 pm
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

Re: Reading FAT12 entries sector by sector

Posted: Sat Jul 09, 2016 3:34 pm
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.

Re: Reading FAT12 entries sector by sector

Posted: Sat Jul 09, 2016 3:44 pm
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).

Re: Reading FAT12 entries sector by sector

Posted: Sat Jul 09, 2016 6:29 pm
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

Re: Reading FAT12 entries sector by sector

Posted: Sat Jul 09, 2016 9:55 pm
by alexfru
If it helps, note that 3 512-byte sectors contain an integral number of 12-bit integers.

Re: Reading FAT12 entries sector by sector

Posted: Sun Jul 10, 2016 4:46 am
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!

Re: Reading FAT12 entries sector by sector

Posted: Sun Jul 10, 2016 10:36 am
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.