1//
2//this code was developed my Miklos Szeredi <miklos@szeredi.hu>
3//and modified by Ram Pai <linuxram@us.ibm.com>
4// sample usage:
5//              newmount /tmp shared
6//
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10
11#include <unistd.h>
12#include <sys/mount.h>
13#include <sys/fsuid.h>
14
15#ifndef MS_REC
16#define MS_REC		0x4000	/* 16384: Recursive loopback */
17#endif
18
19#ifndef MS_SHARED
20#define MS_SHARED		1<<20	/* Shared */
21#endif
22
23#ifndef MS_PRIVATE
24#define MS_PRIVATE		1<<18	/* Private */
25#endif
26
27#ifndef MS_SLAVE
28#define MS_SLAVE		1<<19	/* Slave */
29#endif
30
31#ifndef MS_UNCLONE
32#define MS_UNCLONE		1<<17	/* UNCLONE */
33#endif
34
35int main(int argc, char *argv[])
36{
37	int type;
38	if (argc != 3) {
39		fprintf(stderr, "usage: %s DIR "
40			"[rshared|rslave|rprivate|runclone|shared|slave|private|unclone]\n",
41			argv[0]);
42		return 1;
43	}
44
45	fprintf(stdout, "%s %s %s\n", argv[0], argv[1], argv[2]);
46
47	if (strcmp(argv[2], "rshared") == 0)
48		type = (MS_SHARED | MS_REC);
49	else if (strcmp(argv[2], "rslave") == 0)
50		type = (MS_SLAVE | MS_REC);
51	else if (strcmp(argv[2], "rprivate") == 0)
52		type = (MS_PRIVATE | MS_REC);
53	else if (strcmp(argv[2], "runclone") == 0)
54		type = (MS_UNCLONE | MS_REC);
55	else if (strcmp(argv[2], "shared") == 0)
56		type = MS_SHARED;
57	else if (strcmp(argv[2], "slave") == 0)
58		type = MS_SLAVE;
59	else if (strcmp(argv[2], "private") == 0)
60		type = MS_PRIVATE;
61	else if (strcmp(argv[2], "unclone") == 0)
62		type = MS_UNCLONE;
63	else {
64		fprintf(stderr, "invalid operation: %s\n", argv[2]);
65		return 1;
66	}
67	setfsuid(getuid());
68	if (mount("", argv[1], "ext2", type, "") == -1) {
69		perror("mount");
70		return 1;
71	}
72	return 0;
73}
74