filesystemsnfslustre

Determine Filesystem at runtime in C/C++


How can I determine if a file my code is reading or writing is mounted on a path on top of Lustre, GPFS, or NFS at runtime, from within a C/C++ code?

Edit: Working code:

#include <sys/vfs.h>
#include <iostream>

int main(int argc, char** argv) {
  struct statfs sf;
  statfs(argv[0], &sf);

  std::cout << "f_type =" <<  std::hex << sf.f_type << "\n";
}

Sry about the half-C, half-C++.


Solution

  • You can use the statfs() system call and look at the f_type field. For Lustre the LL_SUPER_MAGIC is 0x0BD00BD0 (Object Based Disk). The NFS_SUPER_MAGIC is listed in the statfs(2) man page as 0x6969, no comment on what that might stand for. :-)