Directories on ext4 file systems generally have at least 2 links. The entry in their parent directory and the .
entry in themselves. See there for more details.
Having said that, if the file system is inconsistent, you may very well have a directory linked in more than one place and the link count not to reflect it.
For instance, with debugfs -w
(on an unmounted fs), you can do link a/b c/d
to force the creation of a link to a directory. You'll notice that the link count is not updated (you'd need sif a/b links_count 3
to update it):
$ ls -lid a/b c/d a/b/. c/d/.
12 drwxr-xr-x 2 chazelas chazelas 1024 May 14 08:37 a/b/
12 drwxr-xr-x 2 chazelas chazelas 1024 May 14 08:37 a/b/./
12 drwxr-xr-x 2 chazelas chazelas 1024 May 14 08:37 c/d/
12 drwxr-xr-x 2 chazelas chazelas 1024 May 14 08:37 c/d/./
The link count is 2 above, even though there are 3 links (to a, to c, and the "." to itself).
Note that fsck
would report a problem with that:
Pass 2: Checking directory structure
Entry 'd' in /c (1282) is a link to directory /a/b (12).
Clear<y>?
So it's unlikely to be your case here if the fs has just gone through a fsck.
To remove one of those links, you can use debugfs -w
again (after having unmounted the filesystem) and do unlink c/d
in it, or use fsck
. If a directory
has more than one link, you can check the ..
entry within it (with debugfs
ls
) to check which is the correct one (..
will have the same inode number as its correct parent).