[linux/fs/umsdos/namei.c,469]
#Specification: hard link / strategy
Well ... hard link are difficult to implement on top of an MsDOS fat file system. Unlike UNIX file systems, there are no inode. A directory entry hold the functionality of the inode and the entry.
We will used the same strategy as a normal Unix file system (with inode) except we will do it symbolically (using paths).
Because anything can happen during a DOS session (defragment, directory sorting, etc...), we can't rely on MsDOS pseudo inode number to record the link. For this reason, the link will be done using hidden symbolic links. The following scenario illustrate how it work.
Given a file /foo/file
ln /foo/file /tmp/file2become internally
mv /foo/file /foo/-LINK1 ln -s /foo/-LINK1 /foo/file ln -s /foo/-LINK1 /tmp/file2
Using this strategy, we can operate on /foo/file or /foo/file2. We can remove one and keep the other, like a normal Unix hard link. We can rename /foo/file or /tmp/file2 independently.
The entry -LINK1 will be hidden. It will hold a link count. When all link are erased, the hidden file is erased too.
[linux/fs/umsdos/namei.c,541]
#Specification: hard link / directory
A hard link can't be made on a directory. EPERM is returned in this case.
[linux/fs/umsdos/emd.c,405]
#Specification: hard link / hidden name
When a hard link is created, the original file is renamed to a hidden name. The name is "..LINKNNN" where NNN is a number define from the entry offset in the EMD file.
[linux/fs/umsdos/namei.c,560]
#Specification: hard link / first hard link
The first time a hard link is done on a file, this file must be renamed and hidden. Then an internal symbolic link must be done on the hidden file.
The second link is done after on this hidden file.
It is expected that the Linux MSDOS file system keeps the same pseudo inode when a rename operation is done on a file in the same directory.
[linux/fs/umsdos/namei.c,912]
#Specification: hard link / deleting a link
When we deletes a file, and this file is a link we must subtract 1 to the nlink field of the hidden link.
If the count goes to 0, we delete this hidden link too.