File: mountpoint.c

package info (click to toggle)
nfs-utils 1%3A2.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,380 kB
  • sloc: ansic: 52,371; sh: 5,775; python: 2,166; makefile: 973
file content (46 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
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;
}