The FAT32 File System

To answer the question in the preceding section, recall that the directory in FAT file systems [ii] is divided into 32-byte records. Table 11.1 outlines the structure of the FAT32 record. Blank records are the ones containing 0 bytes or starting from the E5H code (for deleted records). For files with short names (8 bytes for the name and 3 bytes for the filename extension), 32 bytes are allocated. The byte located by offset +11 (see Table 11.2) contains the file attribute. If the file attribute is equal to 0FH , then the system considers the filename to be long. Long names are encoded as Unicode and are written in reverse order before short names, which means that one or more records with a long name must be followed by a record with a short name containing the ~ character in the seventh position. The ~ character is followed by digits starting from 1. The digits are needed to distinguish the short names of the files, to which the first six characters of a long name match. Here, the record with a short name contains all the other information about the file. As you can see, the algorithm of directory viewing with detection of information about the file is easy. Now, consider the structure of the directory record containing the short filename. In MS-DOS, bytes from 12 to 21 were not used by the system. The new system has found an application for them. Table 11.1 describes the new structure of the directory record.

Table 11.1: Structure of the FAT32 directory record

Offset

Size

Contents

(+0)

8

Name of the file or the directory aligned by the left boundary and padded with blank characters

(+8)

3

Filename extension aligned by the left boundary and padded with blank characters

(+11)

1

File attribute

(+12)

2

Used by operating systems of the Windows NT family; ensures that case-sensitive filenames are displayed correctly

(+14)

2

Creation time

(+16)

2

Creation date

(+18)

2

Access date

(+20)

2

Two most significant bytes of the number of the first cluster of the file

(+22)

2

File modification time

(+24)

2

File modification date

(+26)

2

Two least significant bytes of the first cluster of the file

(+28)

4

File size in bytes

As you can see, now all bytes of the 32-byte record are used. This is just more evidence that initially, the MS-DOS file system was designed inefficiently. In particular, it relates to the file length. As can be easily noticed, only 4 bytes are allocated for storing the file length. How do you find the file length if it requires more than 4 bytes? In this case, it is necessary to consider that the directory stores only the least significant bytes of the length, and the full length can be determined by the FAT. However, no one would argue that this is an obvious drawback. The GetFileSize function also looks strange because it returns the four least significant bytes of the file length; most significant bytes are returned in the second parameter.

As I have already mentioned, the record with a short filename and file characteristics can be preceded by one or more records with long names. Table 11.2 outlines the structure of such a record.

Table 11.2: Structure of a directory record with a long name

Offset

Size

Contents

(+0)

1

Ordinal number of the long filename fragment. Only 6 bits are used. In the last fragment, the ordinal number is increased by 64 (6 th bit is set to 1).

(+1)

10

Five characters of the long filename in Unicode (10 bytes).

(+11)

1

The attribute field. It must be always set to 0FH . Old MS-DOS programs ignore such directory entries; therefore, they see only short filenames. [*]

(+12)

1

The byte must be zero.

(+13)

1

The checksum. It was intended for avoiding collisions that might occur when simultaneously running MS-DOS and Windows applications. The program might arise when an MS-DOS application deletes a file with a long name and creates a new file, overwriting the record of the deleted file. In this case, Windows will have to determine that the long filename has no relation to the short filename. Now, this field is obsolete.

(+14)

12

Six symbols of long filename in Unicode.

(+26)

2

Two 0 bytes.

(+28)

4

Two characters of the long filename in Unicode.

[*] I wonder if the developers of MS-DOS and FAT had foreseen the possibility of using this attribute in such a way.

From Table 11.2, it follows that the maximum length of the filename can be 819 characters (63 — 13 = 819); however, the system won't allow you to set a filename length exceeding 260 characters.

In addition to directories, the file system also contains the FATthe table, using which the operating system traces file allocation in the data area. The directory record stores the starting cluster of the file and the file length in bytes. Knowing the cluster size (information about the sector size and the number of sectors in the cluster), it is possible to determine how many clusters are required for storing the file. However, this is not enough, because the file can be stored in several nonadjacent chains of clusters. FAT is located directly after the reserved sectors at the beginning. The number of these sectors is specified in the boot sector. The size of the FAT element is 4 bytes. [i] The first two FAT elements are reserved. The first byte is always set to F8H . The other 3 bytes can be used at the discretion of the operating system and are undocumented.

Thus, the first meaningful table element of the table has the number 2 and corresponds to the cluster in the file areathe numbers of elements and clusters match. Their possible values are as follows:

  • 0The cluster is free.

  • 1The cluster is damaged.

  • 0FFFFFF8h - 0FFFFFFFh The cluster is the last in the chain of file clusters.

  • Other values determine the number of the next cluster in the chain for a given file. The four most significant bits do not participate in cluster numbering. Thus, the maximum cluster number is 268,435,455.

This table structure allows the operating system to easily find all clusters of any given file using the chain of elements.

[ii] Initially, Windows 95 worked with FAT16; however, support for long filenames was also provided. FAT is one of the elements, upon which file systems of MS-DOS and Windows 9x are based. Because of this, such file systems are called FAT systems.

[i] Naturally, I mean FAT32. In FAT16, the FAT element size is 2 bytes. In the FAT12 file system, which is used in file systems for diskettes, the FAT element length is 12 bits.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net