File: xmount.c

package info (click to toggle)
busybox 1:1.17.1-8+deb6u11
  • links: PTS
  • area: main
  • in suites: squeeze-lts
  • size: 15,608 kB
  • ctags: 26,465
  • sloc: ansic: 182,252; sh: 6,047; cpp: 1,428; makefile: 1,031; yacc: 570; lex: 355; perl: 309; python: 251; awk: 29
file content (80 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "libbb.h"
#include "xmount.h"

#ifdef __linux__

/* xmount and xumount short-circuited to mount and umount2 in xmount.h */

#elif defined(__FreeBSD_kernel__)

static void build_iovec(struct iovec **iov, int *iovlen, const char *name,
		void *val, size_t len)
{
	int i;

	if (*iovlen < 0)
		return;
	i = *iovlen;
	*iov = realloc(*iov, sizeof **iov * (i + 2));
	if (*iov == NULL) {
		*iovlen = -1;
		return;
	}
	(*iov)[i].iov_base = strdup(name);
	(*iov)[i].iov_len = strlen(name) + 1;
	i++;
	(*iov)[i].iov_base = val;
	if (len == (size_t)-1) {
		if (val != NULL)
			len = strlen(val) + 1;
		else
			len = 0;
	}
	(*iov)[i].iov_len = (int)len;
	*iovlen = ++i;
}

int FAST_FUNC xmount(const char *source, const char *target,
		const char *filesystemtype, unsigned long mountflags,
		const void *data UNUSED_PARAM)
{
	struct iovec *iov = NULL;
	int iovlen = 0;
	char *fspath, *from;
	int ret;

	fspath = realpath(target, NULL);
	from = realpath(source, NULL);

	build_iovec(&iov, &iovlen, "fstype", (void*)filesystemtype, (size_t)-1);
	build_iovec(&iov, &iovlen, "fspath", fspath, (size_t)-1);
	if (!strcmp(filesystemtype, "nullfs"))
		/* nullfs uses a "target" instead of "from" */
		build_iovec(&iov, &iovlen, "target", from, (size_t)-1);
	else
		build_iovec(&iov, &iovlen, "from", from, (size_t)-1);

	ret = nmount(iov, iovlen, mountflags);

	free(from);
	free(fspath);
	
	return ret;
}

int FAST_FUNC xumount(const char *target, int flags)
{
	return unmount(target, flags);
}

int FAST_FUNC xswapon(const char *path, int swapflags UNUSED_PARAM)
{
	return swapon(path);
}

int FAST_FUNC xswapoff(const char *path)
{
	return swapoff(path);
}

#endif