I want to find the mount options for /var. I can get a list of mounts and their options with mount. but how do I find the right one for a particular file? I could start with the filename (/var) and chip away at it until the directory matches a mount point, but is there already something that can do this?
statvfs contains some options for any given file's path on the mounted filesystem in its f_flags member.
You can also parse /etc/mtab or /etc/fstab.
Beware of the listed options however, since some are just ignored by the kernel depending on the kernel config/options, and since you can't know what the kernel will do, you should limit to the minimum set of options.