]> git.decadent.org.uk Git - nfs-utils.git/blob - support/misc/mountpoint.c
mount.nfs - make sure program name in error message is correct.
[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 "xcommon.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         int rv;
24
25         dotdot = xmalloc(strlen(path)+4);
26
27         strcat(strcpy(dotdot, path), "/..");
28         if (lstat(path, &stb) != 0 ||
29             lstat(dotdot, &pstb) != 0)
30                 rv = 0;
31         else
32                 if (stb.st_dev != pstb.st_dev ||
33                     stb.st_ino == pstb.st_ino)
34                         rv = 1;
35                 else
36                         rv = 0;
37         free(dotdot);
38         return rv;
39 }