blob: 6d0f34eab4954826fd636dcf3a5dd4f1eef6b35f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}
|