Date and Time Fields

25 Mar

Date and Time Fields
Three sets of data-and-time fields can store when a file was created, when the file was last modified, and when the file was last accessed.

On file creation, the file-modified date and time fields (bytes 22–25) store the current date and time. Every time the file’s contents are modified, the file-system driver should update the values to the current date and time. The time is specified in units of two seconds. These fields were in the original 8.3 entries, and every system that has a real-time clock should store values in these fields on creating or modifying a file. When copying or moving a file, this date and time should remain unchanged.

The file-creation date and time fields (bytes 13–17) store the date and time when a file was created. As with the file-modified time, one field stores the time with a resolution of two seconds. An additional time field stores hundredths of a second (0–199). The two values added together give the time. These fields weren’t part of the original 8.3 entries.When copying a file, the copy’s entry should have the current date and time. When moving a file, the creation date and time should remain unchanged. If unused, these fields should contain zeros.

The file-last-accessed date (bytes 18–19) stores the date when the file was last accessed. Many applications don’t update this value or do so in inconsistent ways, so the stored information is of little use. If unused, these fields should contain zeros.

The FAT32 specification says that the file-modified date and time are required. The other dates and times are optional. An embedded system should support the file-modified fields if possible.

First Cluster
The first-cluster entry at offset 26 is the number of the file’s first data cluster (FAT16) or the low word of the file’s first data cluster (FAT32). For FAT32 volumes, offset 20 contains the high word of the file’s first data cluster. The first data cluster in the data area is cluster 2, so the first-cluster number must be 2 or greater.

File Size
The file size field at offset 28 stores the size of the file in bytes.

Directory Entries
A directory entry is the same as a file entry with these exceptions:
Bit 1 in the Attributes field is set to 1 to indicate that the entry is for a directory.

The file-size field is zero.

In a FAT16 partition, the root directory follows the FATs. In a FAT32 partition, the root directory typically begins in cluster 2 in the data area. Offset 44 in a FAT32 volume’s boot sector contains the cluster number where the root directory begins.

The first two entries in a subdirectory are the dot and dotdot entries:

Figure 9-1: Directory entries for a subdirectory with three files and one subdirectory. The first two entries are the dot and dotdot entries.

To help in understanding these entries, assume that a volume has a directory called sub1, and that sub1 has a subdirectory called sub2. Figure 9-1 shows the directory entries.

The dot entry points to the current subdirectory, sub2. The entry’s file name is a dot followed by seven spaces (“. ” ). The file size is zero. The contents of the date and time fields and the directory’s high and low cluster numbers match the values in sub1’s directory entry for sub2.

The dotdot entry points one level up, to the sub1 subdirectory in the example. The entry’s file name is two dots followed by six spaces (“.. ” ). The file size is zero. The contents of the date and time fields are the same as in the dot entry. The high and low cluster numbers match the values for the directory one level up. These values are the cluster number in sub1’s dot entry. If sub1 is the root directory, the cluster number is zero.

The Volume Label Entry
A volume’s root directory contains the one and only volume-label entry. The entry’s fields have the same meanings as they do for files with two exceptions: bit 0 in the Attributes field is set to 1 to indicate that the entry is for a volume label, and for names longer than 8 characters, the file-system software doesn’t insert a dot between the file-name and file-extension fields. (Long-file-name entries also set the volume bit but are not volume entries.) Most software uses this volume label rather than the label stored in the par-tition’s boot sector. The volume-label entry doesn’t display in the root directory’s directory listing.

Subdirectory Entries
A directory entry with the directory attribute equal to 1 and the volume attribute equal to zero defines a subdirectory under the directory. A subdirectory can use any available data clusters.

A small embedded system might support only the root directory, ignoring any subdirectory entries in the root directory and any files stored in subdirectories. Firmware that doesn’t support subdirectories can avoid overwriting any inaccessible files and directories created by another host because the FATs identify the clusters as in use.

Random Posts

No comments yet

Leave a Reply

You must be logged in to post a comment.