Keep a list of all mount options

This makes it easier to parse all other options as well.
This commit is contained in:
sin 2013-09-03 14:33:52 +01:00
parent c903b0da96
commit 80c3bdae3d
1 changed files with 53 additions and 26 deletions

79
mount.c
View File

@ -28,6 +28,11 @@ struct {
{ NULL, NULL, 0 }
};
static struct option {
char *name;
struct option *next;
} *opthead;
static void
usage(void)
{
@ -40,14 +45,16 @@ main(int argc, char *argv[])
{
int i;
unsigned long flags = 0;
char *types = NULL, *opt = NULL, *p;
char *types = NULL, *arg = NULL, *p;
const char *source;
const char *target;
struct stat st1, st2;
int validopt;
void *data = NULL;
struct mntinfo *minfo = NULL;
struct option *opt, *tmp;
int siz;
int oflag = 0;
ARGBEGIN {
case 'B':
@ -63,32 +70,18 @@ main(int argc, char *argv[])
data = EARGF(usage());
break;
case 'o':
opt = EARGF(usage());
p = strtok(opt, ",");
while (p) {
validopt = 0;
for (i = 0; optnames[i].v; i++) {
if (optnames[i].opt) {
if (!strcmp(p, optnames[i].opt)) {
flags |= optnames[i].v;
validopt = 1;
break;
oflag = 1;
arg = EARGF(usage());
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
opt = malloc(sizeof(*opt));
if (!opt)
eprintf("malloc:");
opt->name = strdup(p);
if (!opt->name)
eprintf("strdup:");
opt->next = opthead;
opthead = opt;
}
}
if (optnames[i].notopt) {
if (!strcmp(p, optnames[i].notopt)) {
flags &= ~optnames[i].v;
validopt = 1;
break;
}
}
}
if (!validopt)
break;
p = strtok(NULL, ",");
}
if (!validopt)
enprintf(1, "unknown option: %s\n", p);
break;
case 't':
types = EARGF(usage());
@ -100,6 +93,32 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
for (opt = opthead; opt; opt = opt->next) {
validopt = 0;
for (i = 0; optnames[i].v; i++) {
if (optnames[i].opt) {
if (!strcmp(opt->name,
optnames[i].opt)) {
flags |= optnames[i].v;
validopt = 1;
break;
}
}
if (optnames[i].notopt) {
if (!strcmp(opt->name,
optnames[i].notopt)) {
flags &= ~optnames[i].v;
validopt = 1;
break;
}
}
}
if (!validopt)
break;
}
if (oflag && !validopt)
enprintf(1, "unknown option: %s\n", opt->name);
source = argv[0];
target = argv[1];
@ -130,5 +149,13 @@ main(int argc, char *argv[])
free(minfo);
opt = opthead;
while (opt) {
tmp = opt->next;
free(opt->name);
free(opt);
opt = tmp;
}
return 0;
}