Determining the file system type of a file, using BSD functions

376 Views Asked by At

I like to get the properties for a specific file path's volume properties as shown by the mount command, without using that command and instead calling the POSIX or related APIs.

When using the mount command on OS X, I get a listing of all available volumes. man mount points me to getfsent, which returns a struct fstab structure with the data I am interested in.

When I invoke getfsent() the first time, I get the information about the root fs, i.e. for "/".

Problem is that I cannot get further mount points that way. man getfsent suggests that I should simply repeatedly call it to learn of further mount points, but the next call returns NULL. I suspec that this function only returns what the actual "/etc/fstab" file contains, not the other volumes that OS X dynamically mounts later on.

But since the mount command can list those additional vols, there must be a way. What is it? Alternatively, I might just look at the source code, but I cannot figure out in which of the many downloads available from opensource.apple.com it is included.

Update: For a solution to list all mounted volumes, see How to iterate all mounted file systems on OSX.

1

There are 1 best solutions below

0
On

Turns out that, for learning the properties, such as file system type, of a particular file's volume, I can also call statfs() and read out the fstypename field. That way, I don't have to iterate over the mounted file systems. I will edit the question accodingly now.