Question

If in fat16 system i am much confused about distinguishing a sub-directory and a file. As sub directory and a file have similar structure, how do we distinguish a directory and a file and how do we traverse through directories to reach the file?

I initially thought all the directory entries will start with '0x2e' as 1st byte of 8.3 naming convention in fat16. But practically i couldn't find all the directories starting with 0x2e but directly the name of the directory. So, how can i distinguish directory and a file in fat16?

Was it helpful?

Solution

Directories have the 0x10 bit set in the attribute field; files do not. The first byte is "." (0x2E) for self and parent directories, if present (which they aren't in the root).

The content of the directory "file" is an array of directory entries.

Ignoring long file names, the way you search for a file is:

  1. SearchDirectory = root
  2. Parse off 8.3 name from remaining path
  3. DirectoryEntry = Look up 8.3 name in SearchDirectory
  4. If remaining path is empty, then DirectoryEntry is the requested entity
  5. If Directory.Attribute & 0x10 == 0 then ERROR (expecting a directory)
  6. SearchDirectory = DirectoryEntry.contents
  7. Goto 2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top