[Previous] - [Main menu] - [Next]

Specifications

VFAT Long File Names

Usage: Stores long filenames (LFN) for Windows


Introduction

This isn't a file system in itself, but a kind of sub file system, which can be placed over a FAT12, FAT16 or FAT32 file system. The VFAT system is a way of hiding long file names in the directory structure of the FAT file systems.

The filenames are stored using unicode characters which are 16 bit long.


Coexistence with FAT12, FAT16 & FAT32

Depending on the length of the long filename, the system will create a number of invalid 8.3 entries in the Directory Table, these are the LFN (Long Filename) entries. These LFN entries are stored with the with the last LFN entry topmost, and the first LFN entry just above a valid Directory Entry. So when looked upon from the top and down, the Directory Table looks something like this:

Directory Example
Entry Nr. Without LFN Entries With LFN Entries
.........
nNormal 1Normal 1
n+1Normal 2LFN for Normal 2 - Part 3
n+2Normal 3LFN for Normal 2 - Part 2
n+3Normal 4LFN for Normal 2 - Part 1
n+4Normal 5Normal 2
n+5Normal 6Normal 3
.........

The LFN entries have the Volume Name, Hidden, System and the Read-Only flags set. So most programs won't display them because of the Volume Name flag (Volume entries are rarely displayed), and they won't be overwridden because of the Read-Only flag.


Directory Entries

The VFAT Directory Format, can coexist on a normal FATxx system. The LFN entries are hidden from normal programs, and available to those who know how to read them. But in addition to the LFN entries the VFAT Directory Format enhances the original structure of the Directory Table as found in FAT16. The Directory Table can still be read by older applications, but all the unused space from the FAT16 format, is now used to store some additional information. This is the format of the VFAT Directory entries:

Structure of the VFAT Directory Entries
Offset Size Description
00h8 bytesFilename
08h3 bytesFilename extension
0Bh1 bytesFlag byte
0Ch1 bytesNT - Reserved for Windows NT - Should always be 0000h
0Dh1 bytesCreation Time - Millisecond
0Eh2 bytesCreation Time - Hour & Minute
10h2 bytesCreated Date
12h2 bytesLast Accessed Data
14h2 bytesStarting cluster (High word) on FAT32 file systems, else 0000h
16h2 bytesTime
18h2 bytesDate
1Ah2 bytesStarting cluster (Low word)
1Ch4 bytesFile size in bytes

Flag Byte

The flag byte defines a set of flags which is set for directories, volume name, hidden files, system files, etc. These are the flags:

Flags in the flag byte
7 6 5 4 3 2 1 0
Unused A D V S H R 0000h

Achieved Flag

The A flag is set by a backup program, so that the user/program knows which files that has been backed up. This flag is not used correctly by many user and perhaps also by many operating systems.

System

This flag shows that the file/directory is important for the system, and shouldn't be manipulated.

Hidden

This flag tell the system and programs that the file should be hidden for the user. But in a lot of programs this can be overwritten by the user.

Read Only

The flag is used to prevent programs from not automatically overwriting or deleting this file/directory.

Directory

This flag is set, when an entry in the directory table is not pointing to the beginning of a file, but to another directory table. A sub-directory. The sub-directory is placed in the cluster, where the Starting Cluster field points to. The format of this sub-directory table is identical to the root directory table.

Volume Name

When this flag is set, the directory entry is not pointing to a file, but to nothing. The only information used from this entry is the filename (8 bytes) plus the filename extension (3 bytes). These bytes form an 11 bytes long volume label (without any .) There may be only one valid entry on the entire disk with this flag set. And preferably this entry should be among the first 3 entries in the root directory table, if not, then MS-DOS can have trouble displaying the right volume label. This volume name should be the same as the one in the boot sector. The latter one is infact rarely used.


LFN Entry

The LFN entries are, as described, placed above the real directory entry, for which they contain the long filename. The first 13 letters are in the first entry, letters 14-26 are in the second LFN entry, letters 27-39 are in the third LFN entry, and so on until the filename has ended. The maximum length of a filename has been limited to 255, even though this scheme has the potential to make them 1664 bytes long, Microsoft - who designed FAT32 - decided not to. The structure of each LFN entry is as follows:

Structure of a LFN Entry
Offset Size Description
00h1 bytesOrdinal field
01h2 bytesUnicode Character 1
03h2 bytesUnicode Character 2
05h2 bytesUnicode Character 3
07h2 bytesUnicode Character 4
09h2 bytesUnicode Character 5
0Bh1 bytesFlag byte
0Ch1 bytesReserved - Always 00h
0Dh1 bytesChecksum
0Eh2 bytesUnicode Character 6
10h2 bytesUnicode Character 7
12h2 bytesUnicode Character 8
14h2 bytesUnicode Character 9
16h2 bytesUnicode Character 10
18h2 bytesUnicode Character 11
1Ah2 bytesAlways 0000h
1Ch2 bytesUnicode Character 12
1Eh2 bytesUnicode Character 13

Only the cluster word (offset 1Ah) and the flag byte (offset 0Bh), are required for compatibility reasons.

Ordinal Field

The ordinal field is used to tell the system which number the LFN entry has, in the LFN string. The first LFN entry will have a value of 01h. The second LFN entry, if there is one, will have a value of 02h, and so on it continues. When a LFN entry contains the last character in the name the Last LFN bit is set (bit 6 in the Ordinal Field).

The Ordinal Field
7 6 5 4 3 2 1 0
Deleted LFN Last LFN LFN Number 0000h

Calculating the Checksum

The Checksum byte in each LFN entry is there to make sure that the LFN entry points to the right file. The checksum value is calculated on the basis of the 8.3 filename, which is present in the valid Directory Table entry. Spaces (ASCII: 20h) are also calculated. The algorithm for calculating the checksum is:

  1. The ASCII value of the first character is the base sum.
  2. Rotate the sum bitwise one bit to the right.
  3. Add the ASCII value of the next character to the sum.
  4. Repeat step 2 and 3 until all 11 characters has been added.

Unicode Characters

The Unicode characters in the specification is a 16 bit value, where the lower 8 bits represent the respective ASCII value and the upper 8 bits are clear. The means that the LFN names are just ASCII style names, with extra holes.


Conclusion

The VFAT Directory Format is a very clever way to add long filename support to the older FAT file systems, while still maintaining compatibility. It is however strange why Microsoft (who designed FAT32) didn't implemented native support for long filenames in FAT32 when they created it a few years back.