Keep a list of all mount options
This makes it easier to parse all other options as well.
This commit is contained in:
parent
c903b0da96
commit
80c3bdae3d
79
mount.c
79
mount.c
@ -28,6 +28,11 @@ struct {
|
|||||||
{ NULL, NULL, 0 }
|
{ NULL, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct option {
|
||||||
|
char *name;
|
||||||
|
struct option *next;
|
||||||
|
} *opthead;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
@ -40,14 +45,16 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned long flags = 0;
|
unsigned long flags = 0;
|
||||||
char *types = NULL, *opt = NULL, *p;
|
char *types = NULL, *arg = NULL, *p;
|
||||||
const char *source;
|
const char *source;
|
||||||
const char *target;
|
const char *target;
|
||||||
struct stat st1, st2;
|
struct stat st1, st2;
|
||||||
int validopt;
|
int validopt;
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
struct mntinfo *minfo = NULL;
|
struct mntinfo *minfo = NULL;
|
||||||
|
struct option *opt, *tmp;
|
||||||
int siz;
|
int siz;
|
||||||
|
int oflag = 0;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'B':
|
case 'B':
|
||||||
@ -63,32 +70,18 @@ main(int argc, char *argv[])
|
|||||||
data = EARGF(usage());
|
data = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
opt = EARGF(usage());
|
oflag = 1;
|
||||||
p = strtok(opt, ",");
|
arg = EARGF(usage());
|
||||||
while (p) {
|
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
|
||||||
validopt = 0;
|
opt = malloc(sizeof(*opt));
|
||||||
for (i = 0; optnames[i].v; i++) {
|
if (!opt)
|
||||||
if (optnames[i].opt) {
|
eprintf("malloc:");
|
||||||
if (!strcmp(p, optnames[i].opt)) {
|
opt->name = strdup(p);
|
||||||
flags |= optnames[i].v;
|
if (!opt->name)
|
||||||
validopt = 1;
|
eprintf("strdup:");
|
||||||
break;
|
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;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
types = EARGF(usage());
|
types = EARGF(usage());
|
||||||
@ -100,6 +93,32 @@ main(int argc, char *argv[])
|
|||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage();
|
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];
|
source = argv[0];
|
||||||
target = argv[1];
|
target = argv[1];
|
||||||
|
|
||||||
@ -130,5 +149,13 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
free(minfo);
|
free(minfo);
|
||||||
|
|
||||||
|
opt = opthead;
|
||||||
|
while (opt) {
|
||||||
|
tmp = opt->next;
|
||||||
|
free(opt->name);
|
||||||
|
free(opt);
|
||||||
|
opt = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user