From fa3fe7a3e497e92dc2c9fc28098e1307639304df Mon Sep 17 00:00:00 2001 From: Simone Piccardi Date: Sat, 21 Jan 2012 17:10:09 +0000 Subject: [PATCH] Clean comment for mymount.c (simple wrapper for mount syscall). --- sources/mymount.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/sources/mymount.c b/sources/mymount.c index 9c8da0d..c4e31a6 100644 --- a/sources/mymount.c +++ b/sources/mymount.c @@ -31,15 +31,14 @@ #include #include -#ifdef DEBUG /* done only on debugging */ +/* pass -D DEBUG to gcc to enable debug printing */ +#ifdef DEBUG #define debug printf #else #define debug(fmt, arg...) #endif /* DEBUG */ - /* Adding undefined flags in glibc headers */ - #ifndef MS_DIRSYNC #define MS_DIRSYNC 128 #endif @@ -81,12 +80,13 @@ /* Help printing routine */ void usage(void); +/* struct for name<->flag correspondence */ struct ms_flag { const char *name; int flag; }; -/* compare funtion */ +/* compare funtion to find a flag name */ int ms_flag_cmp(const void *c1, const void *c2) { struct ms_flag *v1 = (struct ms_flag *) c1; @@ -94,8 +94,7 @@ int ms_flag_cmp(const void *c1, const void *c2) return strcmp(v1->name, v2->name); } - - +/* main body */ int main(int argc, char *argv[]) { /* @@ -104,6 +103,7 @@ int main(int argc, char *argv[]) int i, flags=0; char * mountflags=NULL, *data=NULL, *filesystemtype=NULL; char *token; + /* mount flag table, must be alphabetically ordered */ struct ms_flag ms_values[]= { {"bind", MS_BIND}, @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) * Use getopt function */ opterr = 0; /* don't want writing to stderr */ - while ( (i = getopt(argc, argv, "d:f:t:h")) != -1) { + while ( (i = getopt(argc, argv, "o:f:t:h")) != -1) { switch (i) { /* * Handling options @@ -145,15 +145,15 @@ int main(int argc, char *argv[]) usage(); return -1; break; - case 'd': /* options data */ + case 'o': /* options data */ data = optarg; debug("passed option data: %s\n", data); break; - case 't': /* options data */ + case 't': /* filesystem type */ filesystemtype = optarg; debug("passed filesystem type: %s\n", filesystemtype); break; - case 'f': /* options data */ + case 'f': /* mount flags */ mountflags = optarg; debug("passed mount flags: %s\n", mountflags); break; @@ -171,14 +171,14 @@ int main(int argc, char *argv[]) * Main code beginning * * ***********************************************************/ - if ((argc - optind) != 2) { /* There must be 0 remaing arguments */ + /* There must be 2 arguments, source and target */ + if ((argc - optind) != 2) { printf("Wrong number of arguments %d\n", argc - optind); usage(); } debug("source %s, target %s\n",argv[optind], argv[optind+1]); - -// printf("\n",); + /* parse -f option parameter, and build mount flags argument */ if ( token = strtok(mountflags, ",") ) { do { key.name = token; @@ -194,6 +194,7 @@ int main(int argc, char *argv[]) } while (token=strtok(NULL,",")); } debug("flags value %X\n", flags); + /* do mount */ if (mount(argv[optind], argv[optind + 1], filesystemtype, flags, data) == -1) { perror("Mount call failed"); exit(EXIT_FAILURE); @@ -206,10 +207,14 @@ int main(int argc, char *argv[]) void usage(void) { printf("Program mymount: \n"); printf("Usage:\n"); - printf("mymount [-h] [-d opt1[,...]] [-t type] [-f fl1[,...]] source target\n"); + printf("mymount [-h] [-o opt1[,...]] [-t type] [-f fl1[,...]] source target\n"); printf(" -h print this help\n"); - printf(" -d options comma separated options data string\n"); + printf(" -o options comma separated options data string\n"); printf(" -t fstype filesystemtype string\n"); - printf(" -f flags comma separated mount flags string\n"); + printf(" -f flags comma separated mount flags string\n"); + printf("\n"); + printf("you always need to specify two argument, source and target,\n"); + printf("matching the system call ones, if one of them is not needed\n"); + printf("just pass an empty string\n"); exit(1); } -- 2.30.2