XNU's /sys/stat.h contains an SF_FIRMLINK flag:
Code: Select all
https://github.com/apple/darwin-xnu/blob/main/bsd/sys/stat.h#L512
Now, let's look at /Applications as an example, which is a firmlink (flag: 0x00800000) and also has the SF_NOUNLINK flag (0x00100000). That would be a combined flag (hexadecimal) of 0x00900000, which we can test bitwise:#define SF_FIRMLINK 0x00800000 /* file is a firmlink */
Code: Select all
# example: /Applications
# SF_NOUNLINK & SF_FIRMLINK
# 0x00100000 & 0x00800000 = 0x00900000
# positive example: bitwise check for SF_NOUNLINK
fstat_flags="0x00900000" ; fhex="0x00100000" ; result=$((( $(echo "$fstat_flags") & $fhex ))) ; echo "$result"
# result should be "1048576" (non-zero)
# positive example: bitwise check for SF_FIRMLINK
fstat_flags="0x00900000" ; fhex="0x00800000" ; result=$((( $(echo "$fstat_flags") & $fhex ))) ; echo "$result"
# result should be "8388608" (non-zero)
# negative example: bitwise check for UF_HIDDEN (0x00008000)
fstat_flags="0x00900000" ; fhex="0x00008000" ; result=$((( $(echo "$fstat_flags") & $fhex ))) ; echo "$result"
# result should be "0"
Code: Select all
printf '0x%x' "$(stat -f %f "/Applications")"
In Nimble Commander, however, /Applications is correctly represented with "No unlink" and "Firmlink" under Command > File Attributes.
So how does NC do it? Is there another way to get the actual flags in Terminal, or is this an Apple problem specific to the command-line, i.e. certain flags are omitted from (were never included in) the stat output?
Or is this a general macOS problem, i.e. NC actually has to parse /usr/share/firmlinks to check if a certain filepath is a firmlink or not?