Reputation: 1380
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).
Upvotes: 4
Views: 2457
Reputation: 182734
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:
Upvotes: 8