Comment 28 for bug 817326

Revision history for this message
In , Tristan Schmelcher (tschmelcher) wrote :

(In reply to comment #13)
> If some
> enterprising kernel hacker wants to create a nice, ultra-liberally licensed
> library that turns a dev_t into a boolean: int is_it_safe_to_fsync (dev_t *t);
> then I'd be more than happy to see it used un-conditionally in our
> system-abstraction for Unix / Linux.

I was actually looking into that recently as part of another project and it's pretty easy. Basically,

1) Stat the file to get the st_dev.
2) Stat each file in /dev/disk/by-uuid to find one with a matching st_rdev.
3) Run realpath() on that file. Now you have the device file holding the filesystem.

From there you can easily look up the filesystem type in many places, e.g. /etc/mtab, /proc/fs, or /sys/fs. Probably /etc/mtab is your best bet since it is a generic UNIX thing.

On non-Linux or on Linux without udev you could fall back to stat'ing each file in /dev rather than /dev/disk/by-uuid.