determine NFS file, C

You can use GETMNTINFO(3) to query all mount points, and then traverse towards the root until the node's path (as in "filename") is a mount point.

EDIT:
traverse towards root as in either looping with chdir("..") or alternately REALPATH(3) and walking to the left until the next '/' character each time (or evaluate the longest matching sequence).
 
The stuct stat contains a st_dev that has the ID of the device containing the file.
 
I found: statfs(2) does it ok. It has:

Code:
struct statfs {
...
uint32_t f_type;		     /* type of filesystem */
char      f_fstypename[MFSNAMELEN]; /* filesystem type name */
...
}

Code:
f_fstypename == "nfs"
f_type == 6

String compare is a bit clunky. All I need is to find a safe way of checking f_type. Can't see any handy macros or #defines yet.
 
Actually I found a much nicer way, if anyone is interested. Works with files and directories too, so just for completeness:

Code:
#include <sys/param.h>
#include <sys/mount.h>

int is_local_fs(char const * path)
{
    struct statfs sb;

    if (statfs(path, &sb) == -1) {
        perror(path);
        return 0;
    }


    return sb.f_flags & MNT_LOCAL;

}
 
Back
Top