Is there a way to tell whether a file is in local disk or NFS in C? The code should be portable across various linux distros and shouldn't rely on system calls (e.g. stat -f).
You want to use statfs
from <sys/vfs.h>
.
int statfs(const char *path, struct statfs *buf); struct statfs { __SWORD_TYPE f_type; /* type of file system (see below) */
Here's how to use it:
struct statfs s;
if (statfs("/etc", &s))
perror("statfs");
switch (s->f_type) {
case EXT2_SUPER_MAGIC:
break;
case EXT3_SUPER_MAGIC:
break;
default:
break;
}
Also:
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