25 Mar

This chapter explains how directories store information and shows how to access and store information in directories and subdirectories. The code in this chapter uses the FILE and DISK structures from Chapter 8.

The Contents of an Entry
The root directory contains a 32-byte entry for each file in the root directory and each subdirectory directly under the root directory. These entries are sometimes called DOS 8.3 entries or just 8.3 entries because each can store a file name no longer than eight characters before the dot and three characters after the dot (for example, MYFILE01.TXT). The limitation dates to the MS-DOS operating system.

If the file-system driver supports long file names, any name that doesn’t fit in an 8.3 entry is stored in one or more additional 32-byte entries that precede the 8.3 entry, and the 8.3 entry stores a short version of the file name. An 8.3 entry uses upper-case text only, so another use for long-file-name entries is to support lower-case text.

Every file and subdirectory has a directory entry. The root directory doesn’t have an entry.

File Entries
Table 9-1 shows the contents of a directory entry. The essential fields are the DOS 8.3 fields. The additional fields are optional for many applications.

The File Name
The file-name field at byte zero contains the characters before the dot. The file-extension field at byte 8 contains the characters after the dot. (The dot isn’t stored in the directory.) All text is upper case.

In an entry that contains a file name, any unused locations in the file-name and extension fields should contain the code for a space (20h).

In an unused entry, the first byte in the file-name field is 00h or E5h. The value 00h means that all of the entries that follow in the directory are also available.

An 8.3 name has several limitations:

• Each character code in the file name and extension is eight bits. Original 8.3 entries in PCs use character codes from the system’s OEM code page, which defines character codes for a geographical region.
• All text characters are stored as upper case.
• An 8.3 file name must begin with a letter or a number. In addition to upper-case letters and numbers, a name can contain spaces and any of these characters:

$ % ’ – _ @ ~ ‘ ! ( )

• Windows doesn’t allow any of these as file names: CON, AUX, COM1– COM4, LPT1–LPT3, PRN, NUL.

The Attributes field at byte 11 contains six bits that provide information about the entry. Table 9-2 lists the bits and their meanings. If bits 0–3 are all 1s, the entry is a long-file-name entry.

Table 9-1: The main directory entry for a file has 32 bytes.

Table 9-2: The attribute bits in a directory entry provide additional information about a file.

Random Posts

No comments yet

Leave a Reply

You must be logged in to post a comment.