Data Recovery Software :: File systems :: FAT recovery ::

FAT Data Structures (Directory Entries)

Directory Entries

The FAT directory entry contains the name and metadata for a file or directory. One of these entries is allocated for every file and directory, and they are located in the clusters allocated to the file's parent directory. This data structure supports a name that has only 8 characters in the name and 3 characters in the extension. If the file has a more complex name, there will be a long file name directory entry in addition to a directory entry. The long file name version is discussed in the next section of this chapter. The basic directory entry structure has the fields given in table.

Data structure for a basic FAT directory entry

Byte Range Description Essential
0–0 First character of file name in ASCII and allocation status (0xe5 or 0x00 if unallocated) Yes
1–10 Characters 2 to 11 of file name in ASCII Yes
11–11 File Attributes Yes
12–12 Reserved No
13–13 Created time (tenths of second) No
14–15 Created time (hours, minutes, seconds) No
16–17 Created day No
18–19 Accessed day No
20–21 High 2 bytes of first cluster address (0 for FAT12 and FAT16) Yes
22–23 Written time (hours, minutes, seconds) No
24–25 Written day No
26–27 Low 2 bytes of first cluster address Yes
28–31 Size of file (0 for directories) Yes

The first byte of the data structure works as the allocation status, and if it is set to 0xe5 or 0x00, the directory entry is unallocated. Otherwise, the byte is used to store the first character of the file name. The name is typically in ASCII, but could also use one of the Microsoft code pages if the name uses non-ASCII symbols. If the file name has the value 0xe5 in that byte, 0x05 should be used instead. If the name does not have 8 characters in its name, unused bytes are typically filled in with the ASCII value for a space, which is 0x20.

The file size field is 4 bytes and, therefore, the maximum file size is 4GB. Directories will have a size of 0 and the FAT structure must be used to determine the number of clusters allocated to it. The attributes field can have one or more of the bits in table set.

Flag values for the directory entry attributes field

Flag Value Description Essential
0000 0001 (0x01) Read only No
0000 0010 (0x02) Hidden file No
0000 0100 (0x04) System file No
0000 1000 (0x08) Volume label Yes
0000 1111 (0x0f) Long file name Yes
0001 0000 (0x10) Directory Yes
0010 0000 (0x20) Archive No

The upper two bits of the attribute byte are reserved. Directory entries that have the long file name attribute set have a different structure because they are storing the long name for a file, and they will be described in the next section. Notice that the long file name attribute is a bit-wise combination of the first four attributes. Microsoft found that older OSes would ignore directory entries with all the bits set and would not complain about the different layout.

The date portion of each timestamp is a 16-bit value that has three parts. The lower 5 bits are for the day of the month, and the valid values are 1 to 31. Bits 5 to 8 are for the month, and the valid values are 1 to 12. Bits 9 to 15 are for the year, and the value is added to 1980. The valid range is from 0 to 127, which gives a year range of 1980 to 2107.

The time value is also a 16-bit value and also has three parts. The lower 5 bits are for the second, and it uses two-second intervals. The valid range of this value is 0 to 29, which allows a second range of 0 to 58 in two-second intervals. The next 6 bits are for the minute and have a valid range of 0 to 59. The last 5 bits are for the hour and have a valid range of 0 to 23.

Fortunately, there are file recovery software that will convert these values for you so that you do not have do always do it by hand. Many hex editors will show the date if you highlight the value and have the correct options set. As we will see in the later chapters, this method of saving the time is much different from other file systems, which save the time as the number of seconds since a given time.