]> git.decadent.org.uk Git - nfs-utils.git/blob - support/misc/mountpoint.c
6d0f34eab4954826fd636dcf3a5dd4f1eef6b35f
[nfs-utils.git] / support / misc / mountpoint.c
1
2 /*
3  * check if a given path is a mountpoint 
4  */
5
6 #include <string.h>
7 #include <malloc.h>
8 #include <sys/stat.h>
9
10 int
11 is_mountpoint(char *path)
12 {
13         /* Check if 'path' is a current mountpoint.
14          * Possibly we should also check it is the mountpoint of the 
15          * filesystem holding the target directory, but there doesn't
16          * seem a lot of point.
17          *
18          * We deem it to be a mountpoint if appending a ".." gives a different
19          * device or the same inode number.
20          */
21         char *dotdot;
22         struct stat stb, pstb;
23
24         dotdot = malloc(strlen(path)+4);
25         strcat(strcpy(dotdot, path), "/..");
26         if (lstat(path, &stb) != 0 ||
27             lstat(dotdot, &pstb) != 0)
28                 return 0;
29
30         if (stb.st_dev != pstb.st_dev
31             || stb.st_ino == pstb.st_ino)
32                 return 1;
33         return 0;
34 }