Question

I've got a bash script that deals with files in Mac OS X 10.5 & 10.6. It now needs to determine whether the files are on a local volume or a remote AFP volume. All mountpoints are in /Volumes on Mac OS X, but I cannot see any difference between local & remote volumes, at least with ls -al (except for the boot volume, which is a symlink to /).

Is there a way to programatically, esp. something that can be easily called from a bash script (I really don't want to rewrite this in C/Obj-C with OS X-specific APIs, unless absolutely necessary), to determine the source or type of a mountpoint? Even what device a volume maps to (assuming volumes mounted with mount_afp, mount_smbfs, mount_webdav, etc., won't point back to a device in /dev) so I have some way of guessing whether it's local or not?

Was it helpful?

Solution

Off the top of my head, I don't believe there's an API for it that's common across platforms. You could, however parse the output of the mount command:

~$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk1s2 on /Users/nknight (hfs, local, nodev, nosuid, journaled, nobrowse)

mount without arguments has roughly the same effect on most *nix-ish systems, though I don't believe the output format is standardized anywhere.


I would encourage you to rethink your approach, however. The whole point of network filesystems is that applications aren't supposed to care about them. Consider posting another question explaining what you're trying to accomplish by doing this. Someone can probably offer a superior and more generalized solution.

OTHER TIPS

Does the plain

$ mount

command without any additional args tell you what you need?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top