In my C/C++ program I would like to check whether the data directory specified by user resides on NFS file system. The check is needed because the data processing latency / bandwidth is worse for the remote NFS directory. I would like to issue a warning to the user in case if the data directory is NFS.
How can I do that? I figured there is stat() call that should be able to help me, but the details are not clear.
I am on Linux.
You should use statfs(2)
and check f_type
.
#include <sys/statfs.h>
struct statfs foo;
if (statfs ("/foo/bar", &foo)) {
/* error handling */
}
if (foo.f_type == NFS_SUPER_MAGIC) {
/* nfs warning */
}
I agree with Basile on the usefulness of doing it.
You could use the statfs syscall to get information about the file system of a given path (of some file inside that file system).
I'm not sure it is useful to warn the users. The kernel is doing some file caching, and some remote file systems might be faster than some local ones (e.g. on a slow USB stick, or on a CDROM).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With