advertisement

Article:
  MacFUSE: New Frontiers in File Systems
Subject:   st_nlink is the number of hard links.
Date:   2007-03-14 09:47:49
From:   ralph@inputplus.co.uk
Hi Scott,


"For a directory, the st_nlink field should be set to the total number of entries within the directory."


I think this is incorrect. stat(2) should confirm that st_nlink is the path's number of hard links. For an empty directory, this is normally two; one for . in the empty directory, and one for the directory's entry in the parent.

$ mkdir foo
$ ls -ld foo
drwxr-xr-x 2 ralph ralph 4096 2007-03-14 16:17 foo
$ stat foo | g Links
Device: 301h/769d Inode: 3107002 Links: 2
$ ls -di foo foo/.
3107002 foo 3107002 foo/.
$


For the root directory it is at least three; /, /., and /... Make a directory /foo and /foo/.. will have the same inode number as /, incrementing st_nlink.


Cheers, Ralph.


1 to 1 of 1
  1. st_nlink is the number of hard links.
    2007-03-14 23:30:00  osxbook [View]

    • st_nlink is the number of hard links.
      2007-03-15 07:33:36  ralph@inputplus.co.uk [View]

      • st_nlink is the number of hard links.
        2007-03-16 01:35:52  osxbook [View]

        • st_nlink is the number of hard links.
          2007-03-19 11:21:06  ralph@inputplus.co.uk [View]

          • st_nlink is the number of hard links.
            2007-03-21 14:57:17  osxbook [View]

1 to 1 of 1