Handling Long File Names
In a file system that supports long file names, a file or directory name can be as long as 255 characters including one or more dots and extensions. A file’s complete path has a maximum of 260 characters, however, so volumes with many levels of directories must use shorter names.
Each entry for an item with a long file name (LFN) has an 8.3 entry preceded by one or more 32-byte LFN entries. Systems that don’t support long file names use the 8.3 entry and ignore the LFN entries. Under Windows, typing dir /x at a command prompt shows both the short and long file names.
A small embedded system might choose to support 8.3 file names only. Because every file with a long file name also has an 8.3 file name, a system can access any file using 8.3 file names. If a system that supports only 8.3 file names renames a file that had a long file name, the checksums in the LFN entries will almost always be invalid so the 8.3 file name will be the only valid name.
Table 9-3 shows the fields in an LFN entry. Each entry stores up to 13 Unicode characters. Each character code is two bytes.
Table 9-3: Each long-file-name entry can store up to 13 characters.
A long file name can have lower-case characters, a leading dot (.myfile.txt), multiple dots (myfile.v1.txt), and spaces (my file.txt). Trailing dots (myfile.) and trailing spaces (myfile ) are ignored. Any character that is valid in an 8.3 entry is valid in a long file name. Long file names allow a few additional character codes as well.
Unused character locations should contain FFFFh. The name should end in a null (0000h) if there is room in the final long-file-name entry.
The first byte in an LFN entry is the Ordinal field. In the LFN entry that immediately precedes the file’s 8.3 entry, the Ordinal field contains 1. In the next LFN entry above, the Ordinal field contains 2, and so on up to a maximum of 20. In the Ordinal field with the highest number, bit 6 is set to 1 to indicate that the entry is the last one for the item.
Figure 9-2: A file with the name “This is a long file name.txt” requires four 32-byte entries. The 8.3 file name is THISIS~1.TXT.
Figure 9-2 shows a directory entry for a file named “This is a long file name.txt”. The entry at 00C0h contains the 8.3 file name and extension (“THISIS~1” and “TXT”). The entry at 00A0h contains the first 13 characters in the long file name: “This ”, “is a l”, “on”. The entry at 0080h contains the next 13 characters: “g fil”, “e name”, and “.t”. The entry at 0060h contains the final two characters: “xt”, with the remaining character locations set to FFFFh.
The characters in the LFN entry with the highest ordinal number appear first in the file name, with the rest following in sequence. The entry that follows the LFN entry with an ordinal number of 1 is the 8.3 entry.
In the attributes field, bits 0–3 are all set to 1 to indicate that the entry is a long-file-name entry. The cluster field is maintained for compatibility with the 8.3 entries and should equal zero.