The Protected-Mode FAT File System (VFAT)

Like the FAT file system, the VFAT file system used in Windows 95 organizes data on both hard disks and floppy disks. Because it is compatible with the FAT file system, using file allocation tables and directory entries to store information about the contents of a disk, you do not need to reformat your disk structure when you install Windows 95. VFAT supports long filenames by storing the names and other information, such as the date and time each file was last accessed, in extended FAT structures.

In the VFAT system, a filename can contain as many as 255 characters, including a terminating null character. VFAT allows pathnames of as many as 260 characters, including the terminating null. Remember that the pathname contains the full filename; if your filename is 255 characters, only 4 characters are left for the path. (The last character is the terminating null.)

The VFAT file system supports dual name spaces—that is, it keeps track of both short (8.3) and long filenames—so that it can work with older applications that allow only short names as well as newer applications that permit long names. When you run an older application with a VFAT file system, you will see the 8.3 filename.

When an application creates a file, the API that is used (Win32 or Win16) determines whether long filenames are supported. Using the Win32 CreateFile function sets up a file with both a long filename and an associated 8.3 “alias.” An 8.3 alias is generated for every long filename, and the file can be accessed by either name. Your application can use the GetShortName function to get the alias. The alias is based on the long filename and on the directory in which the file resides. If you change a long filename or copy the file to a different directory, the alias might change. The alias is created using the following basic algorithm:

  1. Select the first eight characters (not including any embedded spaces) of the long filename.
  2. If there is an extension, select its first three characters (not including any embedded spaces) and its preceding dot.
  3. Convert letters to uppercase.
  4. Convert to underscores (_) any characters that are illegal under the FAT file system.
  5. If the resulting name already exists in the same directory, replace the last two characters with a tilde (~) and a unique integer—NEWREP~2, for instance. (Even if the resulting name is unique, replace the last two characters if the long filename has embedded spaces or illegal characters.)

An interesting side effect of filename aliasing occurs when you use the FindFirstFile and FindNextFile functions. Windows 95 checks for both the long filename and the alias, for compatibility reasons. If, for instance, you search for a file using the pattern *1, you might find a file named Whatchamacallit, whose alias is WHATCH~1. To determine the name that actually caused the match, you can check both the cFileName and cAlternateFileName members of the WIN32_FIND_DATA structure.