So I recently read most of the source for config (only stuff needed for kernel compilation), and I'm certainly no expert, but I have a few suggestions.
The first is that pathnames in gram.y should probably use right
recursion, correct? Unless you want to be limited to pathname lists
of length two. It doesn't matter anywhere yet, but it might someday.
The second is that one could add a precedence to the negation operator
so that you can negate an fexpr instead of just an fatom. I have to
admit I'm a little uncertain about using %nonassoc vs %right, but both
seem to work in toy parsers that I've written to emulate/check this.
Third, you would probably want pathtab to hold all the pathnames, but
it seems that, if we have more than one pathname, not all get put there
during addfile. I don't know how to deal with this exactly, but maybe
just putting it all in a for loop is okay.
Lastly, the emitlocnames function gets some things wrong. (It
sets the i_locnami field according to the i_plocnami field of the
first parent, and because i_plocnami is set according to locators of
its first child found in the packed devi list, things go awry). For
example, my ioconf.c file says that pci* has a sigle locname of "bus",
but because its first parent is mainbus0, and bios0 (with its single
locname of apid) is the first entry in packed with mainbus0 as a
parent, pci has the same index into the locnames array as bios0, which
means it appears to have an "apid" locname.
This last one seems as if it was written correctly 20 years ago and
then changed in the name of optimizing space. I say who cares about
optimizing this much space, keep it simple.
Anyway, that's all I can remember. I've applied the patches below, and
then made a new kernel with it, and everything seems to be working
okay. The locnamp array could definitely be compressed more, but at
least it's correct now.
Thank you,
Chris Waddey
Index: gram.y
===================================================================
RCS file: /cvs/src/usr.sbin/config/gram.y,v
retrieving revision 1.24
diff -u -p -r1.24 gram.y
--- gram.y 16 Jan 2015 06:40:16 -0000 1.24
+++ gram.y 14 Jan 2021 21:48:13 -0000
@@ -107,6 +107,7 @@ static void check_maxpart(void);
%left '|'
%left '&'
+%nonassoc '!'
%type <list> pathnames
%type <list> fopts fexpr fatom
@@ -169,7 +170,7 @@ dev_eof:
pathnames:
PATHNAME { $$ = new_nsi($1, NULL, 0); } |
- pathnames '|' PATHNAME { ($$ = $1)->nv_next = new_nsi($3,
NULL, 0); };
+ PATHNAME '|' pathnames { ($$ = new_nsi($1, NULL, 0))->nv_next
= $3; };
/*
* Various nonterminals shared between the grammars.
@@ -187,7 +188,7 @@ fopts:
fexpr:
fatom { $$ = $1; } |
- '!' fatom { $$ = fx_not($2); } |
+ '!' fexpr { $$ = fx_not($2); } |
fexpr '&' fexpr { $$ = fx_and($1, $3); } |
fexpr '|' fexpr { $$ = fx_or($1, $3); } |
'(' fexpr ')' { $$ = $2; };
Index: files.c
===================================================================
RCS file: /cvs/src/usr.sbin/config/files.c,v
retrieving revision 1.20
diff -u -p -r1.20 files.c
--- files.c 16 Jan 2015 06:40:16 -0000 1.20
+++ files.c 14 Jan 2021 21:49:15 -0000
@@ -143,13 +143,16 @@ addfile(struct nvlist *nvpath, struct nv
* will be used after all.
*/
fi = emalloc(sizeof *fi);
- if (ht_insert(pathtab, path, fi)) {
- free(fi);
- if ((fi = ht_lookup(pathtab, path)) == NULL)
- panic("addfile: ht_lookup(%s)", path);
- error("duplicate file %s", path);
- xerror(fi->fi_srcfile, fi->fi_srcline,
- "here is the original definition");
+ for (nv = nvpath; nv; nv = nv->nv_next) {
+ path = nv->nv_name;
+ if (ht_insert(pathtab, path, fi)) {
+ free(fi);
+ if ((fi = ht_lookup(pathtab, path)) == NULL)
+ panic("addfile: ht_lookup(%s)", path);
+ error("duplicate file %s", path);
+ xerror(fi->fi_srcfile, fi->fi_srcline,
+ "here is the original definition");
+ }
}
memcpy(base, tail, baselen);
base[baselen] = 0;
Index: mkioconf.c
===================================================================
RCS file: /cvs/src/usr.sbin/config/mkioconf.c,v
retrieving revision 1.38
diff -u -p -r1.38 mkioconf.c
--- mkioconf.c 28 Jun 2019 13:33:55 -0000 1.38
+++ mkioconf.c 14 Jan 2021 21:49:57 -0000
@@ -230,42 +230,29 @@ emitlocnames(FILE *fp)
struct devi **p, *i;
struct nvlist *nv;
struct attr *a;
- int added, start;
- int v, j, x;
+ int j, x, added;
addlocnami(-1);
for (p = packed; (i = *p) != NULL; p++) {
- /*printf("child %s\n", i->i_name);*/
+ i->i_locnami = nlocnami;
- /* initialize all uninitialized parents */
- for (x = 0; x < i->i_pvlen; x++) {
- if (i->i_parents[x]->i_plocnami)
- continue;
- start = nlocnami;
-
- /* add all the names */
- a = i->i_atattr;
- added = 0;
- for (nv = a->a_locs, v = 0; nv != NULL;
- nv = nv->nv_next, v++) {
- addlocnami(addlocname(nv->nv_name));
- added = 1;
- }
- /* terminate list of names */
- if (added)
- addlocnami(-1);
- else
- start--;
+ /* add all the names */
+ a = i->i_atattr;
+ nv = a->a_locs;
+ added = 0;
+ for (nv = a->a_locs; nv != NULL; nv = nv->nv_next) {
+ added = 1;
+ addlocnami(addlocname(nv->nv_name));
+ }
- /*printf("bus %s starts at %d\n",
i->i_parents[x]->i_name,
- start);*/
- i->i_parents[x]->i_plocnami = start;
+ /* terminate list of names, with a little space saving */
+ if (added)
+ addlocnami(-1);
+ else
+ i->i_locnami = nlocnami - 1;
- }
}
- for (p = packed; (i = *p) != NULL; p++)
- if (i->i_pvlen)
- i->i_locnami = i->i_parents[0]->i_plocnami;
+
if (fprintf(fp, "\nchar *locnames[] = {\n") < 0)
return (1);
for (j = 0; j < nlocnames; j++)
publickey - [email protected] - 0xF2C9C663.asc
Description: application/pgp-keys
