2

I just noticed that the link between .. and the parent dir is hardlink, they have the same inode number:

starpinker@host /home/starpinker/unix $ ls -ail
8200794 drwxrwxr-x 2 starpinker starpinker 4096 Aug 23 11:22 .
1409238 drwxrwxr-x 2 starpinker starpinker 4096 Aug 23 11:22 ..

where the inode number of /home/starpinker/unix is 8200794, and the inode number of /home/starpinker is exactly 1409238.

I have a question on this:

The hardlink cannot be create across different file systems. Then what if the parent directory and child directory are in different file systems? For example in my case, if the /home/starpinker and /home/starpinker/unix are in different file system, the unix is just a mount point, then will the link between /home/starpinker/unix/.. and /home/starpinker still be hardlink?

3
  • Apparently so, I just checked with my Windows mount point and it has a normal hard link to the Linux / which is .. for it. Don't know how that works though. If you don't get an answer here after a while, try flagging for migration to U&L. The question is on topic on both sites and is more than welcome to stay here, there are just more hard core *nix experts on U&L.
    – terdon
    Aug 31, 2013 at 13:28
  • Thanks, @terdon, Can you revise your link? I follow the U&L link, but it seems incorrect.
    – StarPinkER
    Aug 31, 2013 at 13:49
  • unix.stackexchange.com But please don't post the same question there, either flag for migration, or delete this one. Also, as I said before, you can leave it here, it is on topic and there may well be someone who can answer for you.
    – terdon
    Aug 31, 2013 at 14:01

1 Answer 1

4

Why is it a hardlink? Because it points to the parent directory. What else could it be, if not a link?

For the filesystem root directory, .. is still a hardlink – but it points to the directory itself, i.e. it's equivalent to .. The kernel's VFS layer (which manages mountpoints and filesystems) handles this special case and magically resolves /home/starpinker/unix/.. to /home/starpinker without actually looking at the filesystem.

(Also, I haven't researched this, but I think some filesystems don't really keep the . and .. links on disk, but present emulated ones instead. It wouldn't surprise me if the VFS layer actually did that for all .. links, not just the special case...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .