How can I determine the mount path of a given file on Linux in C?
<p>I have an arbitrary file for which I would like to determine the mount point. Let's say that it is /mnt/bar/foo.txt, where we have the following mount points in addition to the "normal" Linux mount points:</p>

<p>[some device mounted to] -> /mnt/bar
[some device mounted to] -> /mnt/other</p>

<p>I've taken a look at stat() and statvfs(). statvfs() can give me the filesystem id, and stat can give me the id of the device, but neither of these can really correlate to the mount point.</p>

<p>I'm thinking that what I will have to do is call readlink() on the arbitrary file, and then read through /proc/mounts, figuring out which path most closely matches the filename. Is this a good approach, or is there some great libc function I'm missing out on to to this?</p>