0

I am on Mac. However, I use gstat (GNU stat) so my understanding is that behavior should match linux.

I cd to a folder. Then I use gstat --format=%h .. The output is 65.

Next, I use gfind . -maxdepth 1 | wc -l. The output is 64.

I expected the gstat command to return the number of hard links for the folder. But it seems to be returning the number of count of files + folders it contains directly inside of it, + 1 for itself).

I have the following questions:

  1. How do I get the number of hard links of a folder?
  2. Do hardlinks work differently for folders than they do for files?
  3. Is a folder just a special kind of file, or is it entirely different?
  4. Do folders have an inode?
  5. Are the inodes of folders in any way connected to the inodes of the files and folders contained within it?

I don't know if this matters, but just in case here are some more specifics about my machine and versions:

  • Chip: Apple M1 Max
  • macOS: Venture 13.5.2
  • gstat version: stat (GNU coreutils) 9.1

mount output (information on my filesystem format):

/dev/disk3s1s1 on / (apfs, sealed, local, read-only, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
/dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
/dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
/dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
/dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)
  • "How do I get the number of hard links of a folder?" -- generally, you cannot create hard links to a folder (because this can lead to circular filesystem paths that will cause recursive filesystems traversals to run infinitely). – larsks Sep 18 '23 at 16:36
  • Related: https://unix.stackexchange.com/q/22394/86440, https://unix.stackexchange.com/q/101515/86440. Note that macOS does allow hard links to directories (but prevents loops). – Stephen Kitt Sep 18 '23 at 16:57

0 Answers0