| Sign In/My Account | View Cart |
| 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,
|
||
Showing messages 1 through 5 of 5.
$ 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 .
$
$ cd /tmp/foo
$ ls -ld .
drwxr-xr-x 2 user wheel 68 Mar 16 00:55 .
$ touch a b c d e f g h
$ ls -ld .
drwxr-xr-x 10 user wheel 340 Mar 16 00:56 .
$ mkdir 1 2 3
$ ls -ld .
drwxr-xr-x 13 user wheel 442 Mar 16 00:56 .
$
st_nlink for directories. Yet, if you read one of these standards carefully enough, it is not required for st_nlink for directories to be what you were expecting it to be.
Directories don't have hard links on Mac OS X (well, not yet), or on any typical Unix system for that matter. The rationale is that with directory hard links, it would be all too easy to create cycles.
st_nlink *would* be the number of hard links, but for files. Looks like the man page for stat(2) fails to mention that.
On Mac OS X, for directories, you can either set st_nlink to the number of objects within the directory ("." and ".." + the rest), or if the volume is such that the number is hard to calculate, you can set st_nlink to 1.
-A