FAT12 format

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
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

FAT12 format

Post by xDDunce »

ok, so now i have finally sorted out my problems, i can get down to some serious work.

i have decided to make the boot module, containing my future drivers and such, a FAT formatted floppy disk image.

many of you may think this is a BIG mistake, but i am doing it for ease, speed, im going to want to know this eventually anyway, and to get to know more for my computing class :D (i like to be ahead of the class). but on to my new struggle...

im trying to read my image, its all loaded and i can access the boot sector using the FAT12/16 structure from the wiki, but im moving on to interpretting the FATs to be able to discover that i have 2 files in the image already (appropriately named file1.txt and file2.txt). but i cannot find any information on the structure of the raw data within the FATs themselves. so can anyone point me to any information about the FATs or give me any C structures they may have used or can throw together from their knowledge?

i've tried googling, serached the wiki, etc. but couldn't find what i was looking for. the wiki contains alot of useful information, but does not cover everything that is needed (as far as i can see) to solve this problem.

Thanks in advance!im sure many people will find this useful.

James.
posman
Posts: 19
Joined: Fri Sep 05, 2008 12:55 pm

Re: FAT12 format

Post by posman »

M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: FAT12 format

Post by M-Saunders »

This is what I used to implement FAT12 writing in MikeOS -- it's a very good and concise doc IMO:

http://www.eit.lth.se/fileadmin/eit/cou ... iption.pdf

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: FAT12 format

Post by Stevo14 »

Have a look at the section called "Programming Guide" on the wiki's FAT page; specifically the section on reading directories. Basically you read the first data cluster (see the wiki) into memory. This block contains 32 file entries (also described on the wiki). Just read the file entries into structures and read the files. In your case the fist file entry will probably be named "file1.txt" and the second "file2.txt". All of the rest should be empty. This is a very simplistic explanation but it suffices as long as the files are not too large and there aren't any sub dir's.
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: FAT12 format

Post by xDDunce »

thanks alot everyone, this is exactly what i needed.

and stevo, i did say i had checked the wiki, and i know the information on there is what i needed, the explanation on there was not clear. it does not explain what each variable is used for. sorry for not making that clear.

Thanks again!

James.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: FAT12 format

Post by Combuster »

All the necessary information is in FAT. Specifically what you asked for:

Code: Select all

unsigned char FAT_table[cluster_size];
unsigned int fat_offset = active_cluster + (active_cluster / 2);// multiply by 1.5
unsigned int fat_sector = first_fat_sector + (fat_offset / cluster_size);
unsigned int ent_offset = fat_offset % cluster_size;

//at this point you need to read from sector "fat_sector" on the disk into "FAT_table".

unsigned short table_value = *(unsigned short*)&FAT_table[ent_offset];

if(current_cluster & 0x0001)
   table_value = table_value >> 4;
else
   table_value = table_value & 0x0FFF;

//the variable "table_value" now has the information you need about the next cluster in the chain.
If you could be more specific about what you do not get would allow us to give a more precise answer
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bubach
Member
Member
Posts: 1224
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: FAT12 format

Post by bubach »

Maybe this can help? I've noticed that it's easier finding good FAT-code by googling for embedded projects, like homemade mp3 players and such.

http://www.larwe.com/zws/products/dosfs/index.html
Features:

Supports FAT12, FAT16 and FAT32 volumes
Supports storage devices up to 2048Gbytes in size (LBA32)
Supports devices with or without MBRs (hard disks vs. floppy disks or ZIP drives formatted as "big floppies")
Supports multiple partitions on disks with MBRs
Supports subdirectories
Can be operated with a single global 512-byte sector buffer
Fully reentrant code (assuming the underlying physical device driver is reentrant and global sector buffers are not used). There are no global variables in the filesystem
Does not perform any memory allocation
Partial support for random-access files
No memory allocation and stuff like that should make it ideal for OSdev.
Post Reply