projects
/
gapil.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
975734e
)
Clean comment for mymount.c (simple wrapper for mount syscall).
author
Simone Piccardi
<piccardi@gnulinux.it>
Sat, 21 Jan 2012 17:10:09 +0000
(17:10 +0000)
committer
Simone Piccardi
<piccardi@gnulinux.it>
Sat, 21 Jan 2012 17:10:09 +0000
(17:10 +0000)
sources/mymount.c
patch
|
blob
|
history
diff --git
a/sources/mymount.c
b/sources/mymount.c
index 9c8da0d423d3eb81d9c0ddedb1ded75e44804943..c4e31a6daa6cd73880ea7277e6d6d35c303bae27 100644
(file)
--- a/
sources/mymount.c
+++ b/
sources/mymount.c
@@
-31,15
+31,14
@@
#include <string.h>
#include <sys/mount.h>
#include <string.h>
#include <sys/mount.h>
-#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 */
#define debug printf
#else
#define debug(fmt, arg...)
#endif /* DEBUG */
-
/* Adding undefined flags in glibc headers */
/* Adding undefined flags in glibc headers */
-
#ifndef MS_DIRSYNC
#define MS_DIRSYNC 128
#endif
#ifndef MS_DIRSYNC
#define MS_DIRSYNC 128
#endif
@@
-81,12
+80,13
@@
/* Help printing routine */
void usage(void);
/* Help printing routine */
void usage(void);
+/* struct for name<->flag correspondence */
struct ms_flag {
const char *name;
int flag;
};
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;
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);
}
return strcmp(v1->name, v2->name);
}
-
-
+/* main body */
int main(int argc, char *argv[])
{
/*
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;
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},
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 */
* 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
switch (i) {
/*
* Handling options
@@
-145,15
+145,15
@@
int main(int argc, char *argv[])
usage();
return -1;
break;
usage();
return -1;
break;
- case '
d
': /* options data */
+ case '
o
': /* options data */
data = optarg;
debug("passed option data: %s\n", data);
break;
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;
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;
mountflags = optarg;
debug("passed mount flags: %s\n", mountflags);
break;
@@
-171,14
+171,14
@@
int main(int argc, char *argv[])
* Main code beginning
*
* ***********************************************************/
* 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("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;
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);
} 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);
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");
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(" -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(" -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);
}
exit(1);
}