advertisement

Article:
  MacFUSE: New Frontiers in File Systems
Subject:   st_nlink is the number of hard links.
Date:   2007-03-15 07:33:36
From:   ralph@inputplus.co.uk
Response to: st_nlink is the number of hard links.

Hi osxbook,


"Directories don't have hard links on Mac OS X (well, not yet), or on any typical Unix system for that matter."


Oh, but they do, at least on Unix as my post above shows. ls -ld foo is showing that foo's inode has a reference count of 2; the second word of output. And ls -di foo foo/. is showing that both paths have the same inode number, 3107002.


It's true that originally directories could also be hard linked with a system call but this was stopped because confusion could result, including hierarchy cycles. However, the kernel never stopped using hard links on directories, for example to implement .., and if you are writing a filesystem you still set up those hard links when making a directory; I doubt FUSE alters this.


As for Mac OS X altering this aspect, perhaps it does but I doubt it. Here's a test to do on the native, non-FUSE, shipped by Apple, filesystem.



$ mkdir foo
$ cd foo
$ ls -ld .
drwxr-xr-x 2 ralph ralph 4096 2007-03-15 14:29 .
$ touch a b c d e f g h
$ ls -ld .
drwxr-xr-x 2 ralph ralph 4096 2007-03-15 14:29 .
$ mkdir 1 2 3
$ ls -ld .
drwxr-xr-x 5 ralph ralph 4096 2007-03-15 14:29 .
$


Keep an eye on the second word of ls(1)'s output. On a newly created, empty, directory it should be 2. Creating files in the directory doesn't change this. But creating subdirectories does; the link count is incremented because 1/.., 2/.., and 3/.. are all hard links to foo.


Cheers, Ralph.


1 to 1 of 1
  1. 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