Concept - Filename Namespace
Old versions of the FAT filesystem had strict limits on filenames.
Many characters were forbidden, and the length was restricted to
11 characters (a small namespace). Newer versions of FAT allowed
more characters and longer filenames. NTFS has almost no restrictions.
Filenames are given a flag to show which namespace the name belongs
to. In order to support old applications, NTFS allocates a short
DOS-friendly name to any file with an DOS-incompatible name.
- 0: POSIX
This is the largest namespace. It is case sensitive and
allows all Unicode characters except for NULL (0) and
Forward Slash '/'. The maximum name length is 255 characters.
N.B. There are some characters, e.g. Colon ':', which are
valid in NTFS, but Windows will not allow you to use.
- 1: Win32
Win32 is a subset of the POSIX namespace and is case insensitive.
It uses all the Unicode characters, except:
'"' '*' '/' ':' '<' '>' '?' '\' '|'
N.B. Names cannot end with Dot '.', or Space ' '.
- 2: DOS
DOS is a subset of the Win32 namespace, allowing only 8 bit upper
case characters, greater than Space ' ', and excluding:
'"' '*' '+' ',' '/' ':' ';' '<' '=' '>' '?' '\'.
N.B. Names must match the following pattern:
1 to 8 characters, then '.', then 1 to 3 characters.
- 3: Win32 & DOS
This namespace means that both the Win32 and the DOS filenames are
identical and hence have been saved in this single filename record.
To convert a POSIX or Win32 filename to a DOS-friendly filename, follow these steps:
- Remove all Unicode characters
- Remove all '.' but the last one if it is not the first character
- Uppercase all letters
- Remove forbidden characters
- Truncate everything before the potential '.' to 6 characters, and add the string "~1"
- Truncate everything after the potential '.' to 3 characters
- While the name already exists, increment the string "~1"
N.B. Step 7 means that although the generated DOS name is unique,
it is impossible to deduce it from the Win32 name only.