FAT32 - parse root directory

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
tomka
Posts: 2
Joined: Fri Dec 27, 2013 8:08 am

FAT32 - parse root directory

Post 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!
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: FAT32 - parse root directory

Post 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.
lexected
Posts: 23
Joined: Wed Aug 14, 2013 11:48 am

Re: FAT32 - parse root directory

Post 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.
tomka
Posts: 2
Joined: Fri Dec 27, 2013 8:08 am

Re: FAT32 - parse root directory

Post 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!
lexected
Posts: 23
Joined: Wed Aug 14, 2013 11:48 am

Re: FAT32 - parse root directory

Post 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.
Post Reply