2

I am trying to parse the root directory of FAT32 in order to get a dir list in the root folder.

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?

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
  • You are not mentioning what programming language you are using. Wouldn't it just be easier to explore an alternative like this first before creating a parser/loop? (Pseudo code) `var diskSize = RootFolder.TotalSize();` Why do you assume that you need to parse anything if you can define the root path and use something like .TotalSize() assuming that it works recursively to include the files in all subfolders? – WP_ Dec 27 '13 at 10:10

1 Answers1

1

The short integer at address 17 of the boot sector is 0 for FAT32 by definition, it's non-zero only for older FATs. The integer at address 44 should instead point you to the first cluster where the root directory resides. (That cluster is usually cluster #2.)

For FAT32 your code should treat the root directory as any other (non-root) directory.

mockinterface
  • 14,452
  • 5
  • 28
  • 49
  • OK, So I still don't understand how to iterate all the entries in the root directory in FAT32 if I don't have the size of the directory? – user3139046 Dec 27 '13 at 14:04
  • OK. I still need your help.. 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! – user3139046 Dec 27 '13 at 17:02
  • You may need a separately formulated question where you can attach your parsing code and a hex/binary text dump of the FAT32 where it doesn't work. It's hard to answer your comment without knowing explicitly how you obtained the DIR_Name, and how do you know that there is really a directory entry that you seem to miss. – mockinterface Dec 27 '13 at 22:19
  • Does the root directory can be exceeded one cluster? – user3139046 Dec 28 '13 at 07:37
  • I think it is impossible to have a cluster size less than 2KB for FAT32. – mockinterface Dec 28 '13 at 08:51