One of those unusual tests you sometimes need to do is to determine whether a given directory on the filesystem is a mount point for another filesystem.
A good approach to do this is to compare the directory with its parent directory, specifically the device ID as returned by the stat() system call.
The following code would work:
stat (path, &path_stat);
parent = dirname (path);
stat (parent, &parent_stat);
is_mountpoint = (path_stat.st_dev != parent_stat.st_dev);
If you want to know more information about the filesystem mounted there, you can use the statfs() system call. This returns, amongst other interesting details, the filesystem type.
if (statfs (path, &statfsbuf) == 0)
is_ext3 = statfsbuf.f_type == EXT3_SUPER_MAGIC;

Don’t use name of the parent directory; it will break, for example, in the common case of having /home as a symlink to /big-ass/mounted/nfs/drive.
Instead, stat the .. of your original path.
stat (path, &path_stat);
parent = path + “/..”;
stat (parent, &parent_stat);
is_mountpoint = as usual;
That’s going to depend on the exact situation you’re asking.
In your example, you may actually want to simply know whether /home is separate to / – in which case your approach would give the wrong answer (it would say “no”, because /big-ass/mounted/nfs and /big-ass/mounted/nfs/drive were both on the same NFS mount)
how about mountpoint, of the initscripts package?
Pingback: Links 28/3/2010: Sabayon 5.2 and GIMP Fun | Boycott Novell
This fails in the face of bind mounts. In all but exceptional cases I would think walking /proc/mounts would be more reliable.
I use the following little trick. When I create a new folder (directory) that I plan to use as a mount point, after the mkdir, I use the following commands
path# touch /mountFolder/_THIS_IS_A_MOUNT_POINT_.txt
path# emacs /mountFolder/_THIS_IS_A_MOUNT_POINT_.txt
… document my plans for using this mount point folder …
path# chmod a-w /mountFolder/_THIS_IS_A_MOUNT_POINT_.txt
If this file is visible, then nothing is mounted on that mount point.
As file systems come and go, I’ve orphaned mount points and find this useful to cull the orphans and also following a cold-iron recovery or re-install.
~~~ 0;-Dan