Page 1 of 1

FAT12 format

Posted: Tue Nov 04, 2008 5:07 pm
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.

Re: FAT12 format

Posted: Tue Nov 04, 2008 6:06 pm
by posman

Re: FAT12 format

Posted: Thu Nov 06, 2008 1:55 am
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

Re: FAT12 format

Posted: Thu Nov 06, 2008 5:52 am
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.

Re: FAT12 format

Posted: Thu Nov 06, 2008 9:40 am
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.

Re: FAT12 format

Posted: Thu Nov 06, 2008 10:01 am
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

Re: FAT12 format

Posted: Thu Nov 06, 2008 10:13 am
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.