diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 06:03:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 06:03:02 +0000 |
commit | 4897093455a2bf08f3db3a1132cc2f6f5484d77c (patch) | |
tree | 9e6373544263f003139431fb4b08f9766e1ed530 /support/misc/mountpoint.c | |
parent | Initial commit. (diff) | |
download | nfs-utils-upstream.tar.xz nfs-utils-upstream.zip |
Adding upstream version 1:2.6.4.upstream/1%2.6.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'support/misc/mountpoint.c')
-rw-r--r-- | support/misc/mountpoint.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/support/misc/mountpoint.c b/support/misc/mountpoint.c new file mode 100644 index 0000000..14d6731 --- /dev/null +++ b/support/misc/mountpoint.c @@ -0,0 +1,46 @@ + +/* + * check if a given path is a mountpoint + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include "xcommon.h" +#include <sys/stat.h> +#include "misc.h" + +int +check_is_mountpoint(const char *path, int (mystat)(const char *, struct stat *)) +{ + if (!mystat) + mystat = lstat; + /* 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; + int rv; + + dotdot = xmalloc(strlen(path)+4); + + strcat(strcpy(dotdot, path), "/.."); + if (mystat(path, &stb) != 0 || + mystat(dotdot, &pstb) != 0) + rv = 0; + else + if (stb.st_dev != pstb.st_dev || + stb.st_ino == pstb.st_ino) + rv = 1; + else + rv = 0; + free(dotdot); + return rv; +} |