diff options
author | neilbrown <neilbrown> | 2003-05-30 05:16:52 +0000 |
---|---|---|
committer | neilbrown <neilbrown> | 2003-05-30 05:16:52 +0000 |
commit | d38ea02d0e4bcdc4e0114567028596f7bcba45b9 (patch) | |
tree | a464ad88e48a90c4efa48fd4caefc843caa88d05 /support/misc | |
parent | 936ecbb5750e0e29b9e2464998a8e03eca617b72 (diff) | |
download | nfs-utils-d38ea02d0e4bcdc4e0114567028596f7bcba45b9.tar.gz nfs-utils-d38ea02d0e4bcdc4e0114567028596f7bcba45b9.tar.xz nfs-utils-d38ea02d0e4bcdc4e0114567028596f7bcba45b9.zip |
new "mountpoint" export option.
Diffstat (limited to 'support/misc')
-rw-r--r-- | support/misc/Makefile | 2 | ||||
-rw-r--r-- | support/misc/mountpoint.c | 34 |
2 files changed, 35 insertions, 1 deletions
diff --git a/support/misc/Makefile b/support/misc/Makefile index b2f73f8..c738564 100644 --- a/support/misc/Makefile +++ b/support/misc/Makefile @@ -3,7 +3,7 @@ # LIBNAME = libmisc.a -OBJS = tcpwrapper.o from_local.o +OBJS = tcpwrapper.o from_local.o mountpoint.o include $(TOP)rules.mk diff --git a/support/misc/mountpoint.c b/support/misc/mountpoint.c new file mode 100644 index 0000000..6d0f34e --- /dev/null +++ b/support/misc/mountpoint.c @@ -0,0 +1,34 @@ + +/* + * check if a given path is a mountpoint + */ + +#include <string.h> +#include <malloc.h> +#include <sys/stat.h> + +int +is_mountpoint(char *path) +{ + /* Check if 'path' is a current mountpoint. + * Possibly we should also check it is the mountpoint of the + * filesystem holding the target directory, but there doesn't + * seem a lot of point. + * + * We deem it to be a mountpoint if appending a ".." gives a different + * device or the same inode number. + */ + char *dotdot; + struct stat stb, pstb; + + dotdot = malloc(strlen(path)+4); + strcat(strcpy(dotdot, path), "/.."); + if (lstat(path, &stb) != 0 || + lstat(dotdot, &pstb) != 0) + return 0; + + if (stb.st_dev != pstb.st_dev + || stb.st_ino == pstb.st_ino) + return 1; + return 0; +} |