We will first talk about short directory entries and ignore long directory entries for the moment.
A FAT directory is nothing but a “file” composed of a linear list of 32-byte structures. The only special directory, which must always be present, is the root directory. For FAT12 and FAT16 media, the root directory is located in a fixed location on the disk immediately following the last FAT and is of a fixed size in sectors computed from the BPB_RootEntCnt value (see computations for RootDirSectors earlier in this document). For FAT12 and FAT16 media, the first sector of the root directory is sector number relative to the first sector of the FAT volume:
FirstRootDirSecNum = BPB_ResvdSecCnt + (BPB_NumFATs * BPB_FATSz16);
For FAT32, the root directory can be of variable size and is a cluster chain, just like any other directory is. The first cluster of the root directory on a FAT32 volume is stored in BPB_RootClus. Unlike other directories, the root directory itself on any FAT type does not have any date or time stamps, does not have a file name (other than the implied file name “\”), and does not contain “.” and “..” files as the first two directory entries in the directory. The only other special aspect of the root directory is that it is the only directory on the FAT volume for which it is valid to have a file that has only the ATTR_VOLUME_ID attribute bit set (see below).
FAT 32 Byte Directory Entry Structure
Name
|
Offset (byte)
|
Size (bytes)
|
Description
|
DIR_Name
|
0
|
11
|
Short name.
|
DIR_Attr
|
11
|
1
|
File attributes:
ATTR_READ_ONLY 0x01
ATTR_HIDDEN 0x02
ATTR_SYSTEM 0x04
ATTR_VOLUME_ID 0x08
ATTR_DIRECTORY 0x10
ATTR_ARCHIVE 0x20
ATTR_LONG_NAME ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID
The upper two bits of the attribute byte are reserved and should always be set to 0 when a file is created and never modified or looked at after that.
|
DIR_NTRes
|
12
|
1
|
Reserved for use by Windows NT. Set value to 0 when a file is created and never modify or look at it after that.
|
DIR_CrtTimeTenth
|
13
|
1
|
Millisecond stamp at file creation time. This field actually contains a count of tenths of a second. The granularity of the seconds part of DIR_CrtTime is 2 seconds so this field is a count of tenths of a second and its valid value range is 0-199 inclusive.
|
DIR_CrtTime
|
14
|
2
|
Time file was created.
|
DIR_CrtDate
|
16
|
2
|
Date file was created.
|
DIR_LstAccDate
|
18
|
2
|
Last access date. Note that there is no last access time, only a date. This is the date of last read or write. In the case of a write, this should be set to the same date as DIR_WrtDate.
|
DIR_FstClusHI
|
20
|
2
|
High word of this entry’s first cluster number (always 0 for a FAT12 or FAT16 volume).
|
DIR_WrtTime
|
22
|
2
|
Time of last write. Note that file creation is considered a write.
|
DIR_WrtDate
|
24
|
2
|
Date of last write. Note that file creation is considered a write.
|
DIR_FstClusLO
|
26
|
2
|
Low word of this entry’s first cluster number.
|
DIR_FileSize
|
28
|
4
|
32-bit DWORD holding this file’s size in bytes.
|
DIR_Name[0]
Special notes about the first byte (DIR_Name[0]) of a FAT directory entry:
-
If DIR_Name[0] == 0xE5, then the directory entry is free (there is no file or directory name in this entry).
-
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).
The special 0 value, rather than the 0xE5 value, indicates to FAT file system driver code that the rest of the entries in this directory do not need to be examined because they are all free.
-
If DIR_Name[0] == 0x05, then the actual file name character for this byte is 0xE5. 0xE5 is actually a valid KANJI lead byte value for the character set used in Japan. The special 0x05 value is used so that this special file name case for Japan can be handled properly and not cause FAT file system code to think that the entry is free.
The DIR_Name field is actually broken into two parts+ the 8-character main part of the name, and the 3-character extension. These two parts are “trailing space padded” with bytes of 0x20.
DIR_Name[0] may not equal 0x20. There is an implied ‘.’ character between the main part of the name and the extension part of the name that is not present in DIR_Name. Lower case characters are not allowed in DIR_Name (what these characters are is country specific).
The following characters are not legal in any bytes of DIR_Name:
-
Values less than 0x20 except for the special case of 0x05 in DIR_Name[0] described above.
-
0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, and 0x7C.
Here are some examples of how a user-entered name maps into DIR_Name:
Dostları ilə paylaş: |