Page 1 of 1

FAT32 - parse root directory

Posted: Fri Dec 27, 2013 8:13 am
by tomka
Hi friends!

I'm trying to parse the root directory of FAT32 in order to get a dir list in the root folder. I'm writing in C++.
So I need to go over all the directory entries in the root directory and parse them.
My problem is that I don't know when to stop the iteration - How to get the size of the root directory?

I noticed that there is a byte in the boot sector - the number of the entries in the root - but in FAT32 the value is always 0, So how can i get the size of the directory?

Please help me,
Thanks!

Re: FAT32 - parse root directory

Posted: Fri Dec 27, 2013 8:37 am
by rdos
If I remember it correctly, the root directory in FAT32 is like any other directory, and uses the FAT chain for contents. The only thing you need is the starting cluster.

Re: FAT32 - parse root directory

Posted: Fri Dec 27, 2013 9:59 am
by lexected
My problem is that I don't know when to stop the iteration - How to get the size of the root directory?
Microsoft EFI FAT32 File System Specification, Version 1.03, December 6, 2000 wrote:• If DIR_Name[0] == 0x00, then the directory entry is free (same as for 0xE5), and there are no
allocated directory entries after this one (all of the DIR_Name[0] bytes in all of the entries after
this one are also set to 0).
I'm not sure, but directories may also be terminated by invalid continuation cluster in FAT.

Re: FAT32 - parse root directory

Posted: Fri Dec 27, 2013 11:01 am
by tomka
OK. I still need your help . :roll:

So I iterate over the entries until I get DIR_Name[0] == 0x00.
It works but not always.

I have an image of FAT32 where I noticed that one of his directory entry(*) is in the middle of the image. (so the entries are not sequential).
The weird point is that I get DIR_Name[0] == 0x00 before I get to that directory entry(*) and hence miss this entry..

somebody ideas?
Thanks!

Re: FAT32 - parse root directory

Posted: Fri Dec 27, 2013 11:33 am
by lexected
If understand you correctly, you have FAT32-formatted image and you're trying to read it's root directory entries. Within the single directory, the position of entry in the image doesn't matter, but position in directory does. I think you're reading the image sector-by-sector, but
Microsoft EFI FAT32 File System Specification, Version 1.03, December 6, 2000 wrote:A FAT directory is nothing but a “file” composed of a linear list of 32-byte structures.
Therefore you need to read the directory cluster-by-cluster, as a normal file.
You should always read only one cluster (N sectors), then look for its continuation in FAT table, and continue reading the next cluster.