#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;
}