aboutsummaryrefslogtreecommitdiffstats
path: root/nmount.c
blob: 8e51ec30ab1d901d5f606b5f2fac0d296eeb4863 (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <stdio.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>

/////////////////////////////////////////////////////////////////////////////////////////
/*FLAGS FROM KERNEL*/

//#define MS_RDONLY	 1	/* Mount read-only */
//#define MS_NOSUID	 2	/* Ignore suid and sgid bits */
//#define MS_NODEV	 4	/* Disallow access to device special files */
//#define MS_NOEXEC	 8	/* Disallow program execution */
//#define MS_SYNCHRONOUS	16	/* Writes are synced at once */
//#define MS_REMOUNT	32	/* Alter flags of a mounted FS */
//#define MS_MANDLOCK	64	/* Allow mandatory locks on an FS */
//#define MS_DIRSYNC	128	/* Directory modifications are synchronous */
//#define MS_NOATIME	1024	/* Do not update access times. */
//#define MS_NODIRATIME	2048	/* Do not update directory access times */
//#define MS_BIND		4096
//#define MS_MOVE		8192
//#define MS_REC		16384
//#define MS_VERBOSE	32768	/* War is peace. Verbosity is silence.
//				   MS_VERBOSE is deprecated. */
//#define MS_SILENT	32768
//#define MS_POSIXACL	(1<<16)	/* VFS does not apply the umask */
//#define MS_UNBINDABLE	(1<<17)	/* change to unbindable */
//#define MS_PRIVATE	(1<<18)	/* change to private */
//#define MS_SLAVE	(1<<19)	/* change to slave */
//#define MS_SHARED	(1<<20)	/* change to shared */
//#define MS_RELATIME	(1<<21)	/* Update atime relative to mtime/ctime. */
//#define MS_KERNMOUNT	(1<<22) /* this is a kern_mount call */
//#define MS_I_VERSION	(1<<23) /* Update inode I_version field */
//#define MS_STRICTATIME	(1<<24) /* Always perform atime updates */
//#define MS_LAZYTIME	(1<<25) /* Update the on-disk [acm]times lazily */

#define STRUCT_LEN(VAR,STRUCT) ((sizeof(VAR)/sizeof(STRUCT))-1)

typedef struct vfs_option_params {
    char *val;
    char *descr;
} vfs_option_params;

vfs_option_params vfs_options_proc_params_hidepid[] = {
    {"0","Everybody may access all proc"},
    {"1","User can access only their own proc, not other /proc/[pid]"},
    {"2","As for mode 1, extra hides pid directories of others"},
    {NULL,NULL},
};

vfs_option_params vfs_options_proc_params_gid[] = {
    {"gid","usergroup who sees /proc in mode 0"},
    {NULL,NULL},
};

typedef struct vfs_options 
{
    char *options;
    char *description;
    vfs_option_params **params;
} vfs_options;

vfs_options vfs_options_proc[] =
{
    {"hidepid=\%u" ,"",                                     &vfs_options_proc_params_hidepid},
    {"gid=\%u"     ,"user group that can access process",   &vfs_options_proc_params_gid},
    {NULL,NULL,NULL}
};

static const struct vfs {
    char *name;
    long flags;
    char *mountpoint;
    vfs_options *options;
} vfstab[] = {
    {"devtmpfs",  0, "/Device",  NULL},
    {"mqueue",    0, "/MQueue/", NULL},
    {"proc",      0, "/Process", &vfs_options_proc},
    {"tmpfs",     0, "/Ram",     NULL},
    {"sysfs",     0, "/System",  NULL},
    {"ext4",      0, NULL,       NULL},
    {"vfat",      0, NULL,       NULL},
    {NULL,        0, NULL,       NULL},
};

typedef struct {
    char *f_device;
    char *f_type;
    char *f_dir;
    char *f_flags;//g_params.f_output = 1;
    char *f_options;
    int   f_verbose;
    int   f_helper;
} mount_params;

static mount_params g_params;

void helper(char *progname)
{
    printf("Usage: %s [OPTS]\n\n"
        "Version: 0.0.1 \n"
        "-d device to mount\n"
        "-t filesystem type\n"
        "-d mount directory\n"
        "-f mount flags\n"
        "-o mount fs options\n"
        "-v verbose output\n"
        "-h help options\n"
        "-a helper for filetype options\n"
        "\n"
        , progname);
}

void sig_handler(int signo)
{
    switch(signo)
    {
        case SIGINT:
            //printf("Catch SIGINT Exit\n");
            //if (g_params.f_output)
            //{
            //    printf("Data in %d bytes Data out %d bytes",g_stats.cnt_in,g_stats.cnt_out);
            //}
        default:
            printf("Unknown signal %d\n",signo);
    }
    exit(0);
}

int smount(
    const char *source, 
    const char *target,
    const char *filesystemtype,
    unsigned long mountflags,
    const void *data)
{

    return 0;
}

int main(int argc, char **argv)
{
    int c;
    int i;

    printf("One big real mount\n");

    if (signal(SIGINT,sig_handler) == SIG_ERR)
    {
        printf("cannot register signal handler\n");
        exit(1);
    }
    
    //process arguments
    while ((c = getopt(argc, argv, "a")) != -1)
    {
        switch (c)
        {
            case 'a':
                //g_params.f_output = 1;
                g_params.f_helper = 1;
                break;
            
            default:
                helper(argv[0]);
                exit(1);
        }
    }

    if (1 == g_params.f_helper)
    {
        for (i=0;i<STRUCT_LEN(vfstab,struct vfs);i++)
        {
            printf("%s %s\n",vfstab[i].name,vfstab[i].mountpoint);
        }
    }


    return 0;
}