FAT12 Root Directory Entries

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
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

FAT12 Root Directory Entries

Post by AlfaOmega08 »

I'm writing code for the FAT filesystem.
On the Bios Parameter Block of the floppy I'm using I find the string "FAT12 ".
So I'm tring to implement the FAT12.

Now I can read the different directory entries.
At http://www.brokenthorn.com/Resources/OSDev6.html you can find:
* Bytes 0-7 : DOS File name (Padded with spaces)
* Bytes 8-10 : DOS File extension (Padded with spaces)
* Bytes 11 : File attributes. This is a bit pattern:
o Bit 0 : Read Only
o Bit 1 : Hidden
o Bit 2 : System
o Bit 3 : Volume Label
o Bit 4 : This is a subdirectory
o Bit 5 : Archive
o Bit 6 : Device (Internal use)
o Bit 6 : Unused
* Bytes 12 : Unused
* Bytes 13 : Create time in ms
* Bytes 14-15 : Created time, using the following format:
o Bit 0-4 : Seconds (0-29)
o Bit 5-10 : Minutes (0-59)
o Bit 11-15 : Hours (0-23)
* Bytes 16-17 : Created year in the following format:
o Bit 0-4 : Year (0=1980; 127=2107
o Bit 5-8 : Month (1=January; 12=December)
o Bit 9-15 : Hours (0-23)
* Bytes 18-19 : Last access date (Uses same format as above)
* Bytes 20-21 : EA Index (Used in OS/2 and NT, dont worry about it)
* Bytes 22-23 : Last Modified time (See byte 14-15 for format)
* Bytes 24-25 : Last modified date (See bytes 16-17 for format)
* Bytes 26-27 : First Cluster
* Bytes 28-32 : File Size
This should be the structure for a FAT Directory Entries.
On my floppy I expect to find 3 entries:
dos wrote: . <dir>
.. <dir>
boot <dir>
But there isn't this on my floppy...
On an hexadecimal editor, I find one entry with the name of the dir coded with utf-16 (b.o.o.t). The second entry is the same name with capital letters (BOOT) coded with ascii.

Why? Maybe beacause I formatted the image with linux, and it's now using vfat that is different from fat?
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:

Post by Combuster »

You're looking at long filenames. That means you have a DOS-style filename, which is in uppercase, plus the official filename in LFN style.

You can simply ignore the LFN entries and everything will still work - it's backwards compatible. Just use the "BOOT" entry.
"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
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Post by AlfaOmega08 »

So I've to read one entry each two... only the second

Thanks
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:

Post by Combuster »

LFNs can be far longer than one directory entry. Rather look at the atrributes to see if any unexpected bits have been set:
* Bytes 11 : File attributes. This is a bit pattern
o Bit 0 : Read Only
o Bit 1 : Hidden
o Bit 2 : System
o Bit 3 : Volume Label
o Bit 4 : This is a subdirectory
o Bit 5 : Archive
o Bit 6 : Device (Internal use)
IIRC bit 3 was set for all LFN entries.
"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
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Post by AlfaOmega08 »

OK. Thanks a lot.

Now I've another question:
* Bytes 26-27 : First Cluster
This is ok for fat12 and fat16 that use 12-bit and 16-bit cluster size.
On fat-32 2 bytes are too small to represent a cluster.
What's happen on fat32?
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Theres two parts one at offset 0x14 and one at offset 0x1a

Code: Select all

;====================================================;
;  Directory Entry format file                       ;
;====================================================;
FileEntry:
FileName		rb	8		; 0x00
FileExten		rb	3		; 0x08
FileAttr		rb	1		; 0x0B
FileReserved		rb	1		; 0x0C
FileCreate10MS		rb	1		; 0x0D
FileCreateTime		rw	1		; 0x0E
FileCreateDate		rw	1		; 0x10
FileAccessDate		rw	1		; 0x12
FileClusterHigh 	rw	1		; 0x14
FileTime		rw	1		; 0x16
FileDate		rw	1		; 0x18
FileCluster		rw	1		; 0x1A
FileSize		rd	1		; 0x1C
You use both "FileClusterHigh" and "FileCluster", something like this :

Code: Select all

	xor   eax,eax
	mov   ax,[es:edi+20]  ; es:edi points to "FileEntry" for the file/dir wanted
	shl   eax,16
	mov   ax,[es:edi+26]
	mov   dword [cluster32],eax
	sub  eax,2
Post Reply