What's up with stat on MacOSX/Darwin? Or filesystems without names...
Posted
by Charles Stewart
on Super User
See other posts from Super User
or by Charles Stewart
Published on 2010-02-02T10:40:54Z
Indexed on
2010/03/21
22:21 UTC
Read the original article
Hit count: 597
In response to a question I asked on SO, Give the mount point of a path, one respondant suggested using stat
to get the device name associated with the volume of a given path. This works nicely on Linux, but gives crazy results on MacOSX 10.4. For my system, df and mount give:
cas cas$ df
Filesystem 512-blocks Used Avail Capacity Mounted on
/dev/disk0s3 58342896 49924456 7906440 86% /
devfs 194 194 0 100% /dev
fdesc 2 2 0 100% /dev
<volfs> 1024 1024 0 100% /.vol
automount -nsl [166] 0 0 0 100% /Network
automount -fstab [170] 0 0 0 100% /automount/Servers
automount -static [170] 0 0 0 100% /automount/static
/dev/disk2s1 163577856 23225520 140352336 14% /Volumes/Snapshot
/dev/disk2s2 409404102 5745938 383187960 1% /Volumes/Sparse
cas cas$ mount
/dev/disk0s3 on / (local, journaled)
devfs on /dev (local)
fdesc on /dev (union)
<volfs> on /.vol
automount -nsl [166] on /Network (automounted)
automount -fstab [170] on /automount/Servers (automounted)
automount -static [170] on /automount/static (automounted)
/dev/disk2s1 on /Volumes/Snapshot (local, nodev, nosuid, journaled)
/dev/disk2s2 on /Volumes/Sparse (asynchronous, local, nodev, nosuid)
Trying to get the devices from the mount points, though:
cas cas$ df | grep -e/
| awk '{print $NF}'
| while read line; do echo $line $(stat -f"%Sdr" $line); done
/ disk0s3r
/dev ???r
/dev ???r
/.vol ???r
/Network ???r
/automount/Servers ???r
/automount/static ???r
/Volumes/Snapshot disk2s1r
/Volumes/Sparse disk2s2r
Here, I'm feeding each of the mount points scraped from df to stat, outputting the results of the "%Sdr" format string, which is supposed to be the device name: Cf. stat(1) man page:
The special output specifier S may be used to indicate that the output, if applicable, should be in string format. May be used in combination with: ... dr Display actual device name.
What's going on? Is it a bug in stat, or some Darwin VFS weirdness?
Postscript Per Andrew McGregor, try passing "%Sd" to stat for more weirdness. It lists some apparently arbitrary subset of files from CWD...
© Super User or respective owner