NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/38280: config(1) should emit devsw.h for devsw declarations in devsw.c



>Number:         38280
>Category:       toolchain
>Synopsis:       config(1) should emit devsw.h for devsw declarations in devsw.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 22 20:30:00 +0000 2008
>Originator:     Izumi Tsutsui
>Release:        NetBSD 4.99.55
>Organization:
>Environment:
Machine independent
>Description:
Currently many sources and drivers have declarations like
"extern const struct cdevsw foo_cdevsw;"
but it should be autogenerated by config(1) as well as ioconf.h.

>How-To-Repeat:
Code inspection.

>Fix:
Apply the attached patch.

Note this also contains the following changes:
- use __arraycount()
- put "DO NOT EDIT" header into locators.h and ioconf.h too

Index: defs.h
===================================================================
RCS file: /cvsroot/src/usr.bin/config/defs.h,v
retrieving revision 1.22
diff -u -r1.22 defs.h
--- defs.h      12 Dec 2007 00:03:33 -0000      1.22
+++ defs.h      22 Mar 2008 20:16:27 -0000
@@ -98,7 +98,7 @@
  * The next two lines define the current version of the config(1) binary,
  * and the minimum version of the configuration files it supports.
  */
-#define CONFIG_VERSION         20071109
+#define CONFIG_VERSION         20080323
 #define CONFIG_MINVERSION      0
 
 /*
Index: mkdevsw.c
===================================================================
RCS file: /cvsroot/src/usr.bin/config/mkdevsw.c,v
retrieving revision 1.5
diff -u -r1.5 mkdevsw.c
--- mkdevsw.c   12 Dec 2007 00:03:33 -0000      1.5
+++ mkdevsw.c   22 Mar 2008 20:16:27 -0000
@@ -91,8 +91,8 @@
 
        fputs("#include <sys/param.h>\n"
                  "#include <sys/conf.h>\n"
-                 "\n#define\tDEVSW_ARRAY_SIZE(x)\t"
-                 "(sizeof((x))/sizeof((x)[0]))\n", fp);
+                 "#include \"devsw.h\"\n"
+                 "\n#define\tDEVSW_ARRAY_SIZE(x)\t__arraycount(x)\n", fp);
 }
 
 /*
@@ -107,15 +107,6 @@
 
        fputs("\n/* device switch table for block device */\n", fp);
 
-       for (i = 0 ; i <= maxbdevm ; i++) {
-               (void)snprintf(mstr, sizeof(mstr), "%d", i);
-               if ((dm = ht_lookup(bdevmtab, intern(mstr))) == NULL)
-                       continue;
-
-               fprintf(fp, "extern const struct bdevsw %s_bdevsw;\n",
-                           dm->dm_name);
-       }
-
        fputs("\nconst struct bdevsw *bdevsw0[] = {\n", fp);
 
        for (i = 0 ; i <= maxbdevm ; i++) {
@@ -134,15 +125,6 @@
 
        fputs("\n/* device switch table for character device */\n", fp);
 
-       for (i = 0 ; i <= maxcdevm ; i++) {
-               (void)snprintf(mstr, sizeof(mstr), "%d", i);
-               if ((dm = ht_lookup(cdevmtab, intern(mstr))) == NULL)
-                       continue;
-
-               fprintf(fp, "extern const struct cdevsw %s_cdevsw;\n",
-                           dm->dm_name);
-       }
-
        fputs("\nconst struct cdevsw *cdevsw0[] = {\n", fp);
 
        for (i = 0 ; i <= maxcdevm ; i++) {
Index: mkheaders.c
===================================================================
RCS file: /cvsroot/src/usr.bin/config/mkheaders.c,v
retrieving revision 1.13
diff -u -r1.13 mkheaders.c
--- mkheaders.c 9 Nov 2007 05:21:30 -0000       1.13
+++ mkheaders.c 22 Mar 2008 20:16:27 -0000
@@ -61,6 +61,7 @@
 static int emitlocs(void);
 static int emitopts(void);
 static int emitioconfh(void);
+static int emitdevswh(void);
 static int emittime(void);
 static int herr(const char *, const char *, FILE *);
 static int defopts_print(const char *, void *, void *);
@@ -95,7 +96,8 @@
                        return (1);
        }
 
-       if (emitopts() || emitlocs() || emitioconfh() || emittime())
+       if (emitopts() || emitlocs() || emitioconfh() || emitdevswh() ||
+           emittime())
                return (1);
 
        return (0);
@@ -354,6 +356,8 @@
        if ((tfp = fopen(tfname, "w")) == NULL)
                return (herr("open", tfname, NULL));
 
+       autogen_comment(tfp, "locators.h");
+
        rval = ht_enumerate(attrtab, locators_print, tfp);
 
        fflush(tfp);
@@ -381,6 +385,8 @@
        if ((tfp = fopen(tfname, "w")) == NULL)
                return (herr("open", tfname, NULL));
 
+       autogen_comment(tfp, "ioconf.h");
+
        TAILQ_FOREACH(d, &allbases, d_next) {
                if (!devbase_has_instances(d, WILD))
                        continue;
@@ -398,6 +404,68 @@
 }
 
 /*
+ * Build the "devsw.h" file with extern declarations for all configured
+ * bdevsw and cdevsw.
+ */
+static int
+emitdevswh(void)
+{
+       const char *tfname;
+       FILE *tfp;
+       struct devm *dm;
+       char mstr[16];
+       int i;
+
+       tfname = "tmp_devsw.h";
+       if ((tfp = fopen(tfname, "w")) == NULL)
+               return (herr("open", tfname, NULL));
+
+       autogen_comment(tfp, "devsw.h");
+
+       for (i = 0 ; i <= maxbdevm ; i++) {
+               (void)snprintf(mstr, sizeof(mstr), "%d", i);
+               if ((dm = ht_lookup(bdevmtab, intern(mstr))) == NULL)
+                       continue;
+
+               fprintf(tfp, "extern const struct bdevsw %s_bdevsw;\n",
+                   dm->dm_name);
+       }
+       fprintf(tfp, "\n");
+
+       fprintf(tfp, "extern const struct bdevsw **bdevsw, *bdevsw0[];\n");
+       fprintf(tfp, "extern const int sys_bdevsws;\n");
+       fprintf(tfp, "extern int max_bdevsws;\n");
+       fprintf(tfp, "\n");
+
+       for (i = 0 ; i <= maxcdevm ; i++) {
+               (void)snprintf(mstr, sizeof(mstr), "%d", i);
+               if ((dm = ht_lookup(cdevmtab, intern(mstr))) == NULL)
+                       continue;
+
+               fprintf(tfp, "extern const struct cdevsw %s_cdevsw;\n",
+                   dm->dm_name);
+       }
+       fprintf(tfp, "\n");
+
+       fprintf(tfp, "extern const struct cdevsw **cdevsw, *cdevsw0[];\n");
+       fprintf(tfp, "extern const int sys_cdevsws;\n");
+       fprintf(tfp, "extern int max_cdevsws;\n");
+       fprintf(tfp, "\n");
+
+       fprintf(tfp, "extern struct devsw_conv *devsw_conv;\n");
+       fprintf(tfp, "extern struct devsw_conv devsw_conv0[];\n");
+       fprintf(tfp, "extern int max_devsw_convs;\n");
+                       
+       fflush(tfp);
+       if (ferror(tfp))
+               return herr("writ", tfname, tfp);
+
+       if (fclose(tfp) == EOF)
+               return (herr("clos", tfname, NULL));
+
+       return (moveifchanged(tfname, "devsw.h"));
+}
+/*
  * Make a file that config_time.h can use as a source, if required.
  */
 static int



Home | Main Index | Thread Index | Old Index