Skip to contentSkip to conversation

parser for mount options

RFC PATCH [email protected] 2 participants 2 messages Aug 7, 2001 – Aug 8, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

it breeds global variables for no good reason

Globals? What globals?

Quoted 2 lines

Switch that will keep growing, BTW.
would turn into complete mess two years down the road.

But this was written five and a half years ago, and I think it still suffices.

Quoted 3 lines

There are two different tasks - one of them is to decide which option we are dealing with and another - decode and act upon it. Mixing parsing and data conversion in that kind of situations is a Bad Thing(tm).

Possibly. I like the option parsing for each filesystem:

	parse_mount_options((char *) data, SIZE(opts), opts);

and this does parse_and_assign. You do

	while (more_tokens) {
		t = type_of_next_token();
		switch (t) {
		case ...
		}
	}

where the type_of_next_token() does the parsing, and the switch does the assigning. Much more code. Much uglier - but tastes differ. The reason that I call it uglier is that you have the same, or nearly the same code for each filesystem. But then discrepancies arise, and things are not treated uniformly across filesystems. A single parser and assigner forces uniformity.
You have a coherency problem. In

+enum { Opt_mode, ...};
+
+static match_table_t tokens = {
+ {Opt_mode, "mode=%o"},
...
+ case Opt_mode:
+ mode = match_octal(args);
+ break;

the %o must correspond to the match_octal().
But that is unfortunate duplication.
That same code is

	{ "mode", OPT_INT_8, 0, &mode},

for me. Not only much more compact, but no coherency problem either. Of course one might write

	{ "mode", "%o", 0, &mode},

to save the reader the trouble of looking up what OPT_INT_8 means.

If you see strange warts in my parser it is mostly because it was a patch without user-visible changes, so all existing msdos option peculiarities had to be accommodated. Once such code is in place one needs a very good reason to invent option syntax not covered by it.

Andries

#1 lore raw
Quoted 9 lines · On Tue, 7 Aug 2001 [email protected] wrote:
	while (more_tokens) {
		t = type_of_next_token();
		switch (t) {
		case ...
		}
	}

where the type_of_next_token() does the parsing, and the switch does the assigning. Much more code. Much uglier - but tastes differ.

I would agree, if in all cases it was about assigning a single value. It isn't.

Quoted 3 lines

If you see strange warts in my parser it is mostly because it was a patch without user-visible changes, so all existing msdos option peculiarities had to be accommodated.

But that's precisely the point. It's accomodated to warts of random syntax and basically says "OK, nobody will ever want something that would not be covered by it".

Quoted 2 lines

Once such code is in place one needs a very good reason to invent option syntax not covered by it.

In other words, we can optimize for pretty arbitrary limitations. Sure. It had been done before. Who might think that we'll ever need something besides the array of integers or a string for sysctls? Not too random, in that case... Well, just look at the thing now. Famous last words:
"nobody will ever do that"...

By the way, I wouldn't be surprised if it turned out that now we have a wart not covered by ones that were there 5 years ago. I'm sure that it also can be dealt with - no arguments here. However, it still doesn't deal with:

* syntax being not transparent.
* the whole interface being basically _defined_ by a snapshot
of warts taken at some point.

How it was? "The difference between good and bad programs is that good ones end up used in ways authors had never anticipated"?

Sigh... Let me put it that way - what you had described is, IMO, a kludge. I don't think that it would be an improvement compared to the current state of the things, but if you want it in the tree - you know where to submit it. Tastes differ, your and mine - quite seriously.