Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/config Salvage pre-devsw config support so that one...



details:   https://anonhg.NetBSD.org/src/rev/434e4517d832
branches:  trunk
changeset: 536205:434e4517d832
user:      enami <enami%NetBSD.org@localhost>
date:      Wed Sep 11 06:20:09 2002 +0000

description:
Salvage pre-devsw config support so that one can config such as other
branch's kernel.

diffstat:

 usr.sbin/config/defs.h     |   3 +-
 usr.sbin/config/gram.y     |   4 +-
 usr.sbin/config/main.c     |   4 +-
 usr.sbin/config/mkioconf.c |  33 +++++++++++++++++++++++-
 usr.sbin/config/sem.c      |  61 +++++++++++++++++++++++++++++++++------------
 5 files changed, 82 insertions(+), 23 deletions(-)

diffs (222 lines):

diff -r 3fb222cce3d8 -r 434e4517d832 usr.sbin/config/defs.h
--- a/usr.sbin/config/defs.h    Wed Sep 11 05:36:26 2002 +0000
+++ b/usr.sbin/config/defs.h    Wed Sep 11 06:20:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */
+/*     $NetBSD: defs.h,v 1.6 2002/09/11 06:20:09 enami Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -378,6 +378,7 @@
 int    ndevi;                          /* number of devi's (before packing) */
 int    maxbdevm;                       /* max number of block major */
 int    maxcdevm;                       /* max number of character major */
+int    do_devsw;                       /* 0 if pre-devsw config */
 
 TAILQ_HEAD(, files)    allfiles;       /* list of all kernel source files */
 TAILQ_HEAD(, objects)  allobjects;     /* list of all kernel object and
diff -r 3fb222cce3d8 -r 434e4517d832 usr.sbin/config/gram.y
--- a/usr.sbin/config/gram.y    Wed Sep 11 05:36:26 2002 +0000
+++ b/usr.sbin/config/gram.y    Wed Sep 11 06:20:09 2002 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.35 2002/09/06 13:18:43 gehenna Exp $        */
+/*     $NetBSD: gram.y,v 1.36 2002/09/11 06:20:09 enami Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -263,7 +263,7 @@
 one_def:
        file |
        object |
-       device_major |
+       device_major                    { do_devsw = 1; } |
        include |
        prefix |
        DEVCLASS WORD                   { (void)defattr($2, NULL, 1); } |
diff -r 3fb222cce3d8 -r 434e4517d832 usr.sbin/config/main.c
--- a/usr.sbin/config/main.c    Wed Sep 11 05:36:26 2002 +0000
+++ b/usr.sbin/config/main.c    Wed Sep 11 06:20:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.69 2002/09/06 13:18:43 gehenna Exp $        */
+/*     $NetBSD: main.c,v 1.70 2002/09/11 06:20:09 enami Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -311,7 +311,7 @@
         * Ready to go.  Build all the various files.
         */
        if (mksymlinks() || mkmakefile() || mkheaders() || mkswap() ||
-           mkioconf() || mkdevsw() || mkident())
+           mkioconf() || (do_devsw ? mkdevsw() : 0) || mkident())
                stop();
        (void)printf("Don't forget to run \"make depend\"\n");
        exit(0);
diff -r 3fb222cce3d8 -r 434e4517d832 usr.sbin/config/mkioconf.c
--- a/usr.sbin/config/mkioconf.c        Wed Sep 11 05:36:26 2002 +0000
+++ b/usr.sbin/config/mkioconf.c        Wed Sep 11 06:20:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkioconf.c,v 1.60 2002/09/06 13:18:43 gehenna Exp $    */
+/*     $NetBSD: mkioconf.c,v 1.61 2002/09/11 06:20:09 enami Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -65,6 +65,7 @@
 static int emitpv(FILE *);
 static int emitroots(FILE *);
 static int emitvfslist(FILE *);
+static int emitname2blk(FILE *);
 
 #define        SEP(pos, max)   (((u_int)(pos) % (max)) == 0 ? "\n\t" : " ")
 
@@ -91,7 +92,7 @@
        v = emithdr(fp);
        if (v != 0 || emitcfdrivers(fp) || emitexterns(fp) || emitloc(fp) ||
            emitpv(fp) || emitcfdata(fp) || emitroots(fp) || emitpseudo(fp) ||
-           emitvfslist(fp)) {
+           emitvfslist(fp) || (do_devsw ? 0 : emitname2blk(fp))) {
                if (v >= 0)
                        (void)fprintf(stderr,
                            "config: error writing ioconf.c: %s\n",
@@ -444,3 +445,31 @@
 
        return (0);
 }
+
+/*
+ * Emit name to major block number table.
+ */
+int
+emitname2blk(FILE *fp)
+{
+       struct devbase *dev;
+
+       if (fputs("\n/* device name to major block number */\n", fp) < 0)
+               return (1);
+
+       if (fprintf(fp, "struct devnametobdevmaj dev_name2blk[] = {\n") < 0)
+               return (1);
+
+       TAILQ_FOREACH(dev, &allbases, d_next) {
+               if (dev->d_major == NODEV)
+                       continue;
+
+               if (fprintf(fp, "\t{ \"%s\", %d },\n",
+                           dev->d_name, dev->d_major) < 0)
+                       return (1);
+       }
+       if (fprintf(fp, "\t{ NULL, 0 }\n};\n") < 0)
+               return (1);
+
+       return (0);
+}
diff -r 3fb222cce3d8 -r 434e4517d832 usr.sbin/config/sem.c
--- a/usr.sbin/config/sem.c     Wed Sep 11 05:36:26 2002 +0000
+++ b/usr.sbin/config/sem.c     Wed Sep 11 06:20:09 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.c,v 1.31 2002/09/06 13:18:43 gehenna Exp $ */
+/*     $NetBSD: sem.c,v 1.32 2002/09/11 06:20:10 enami Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -82,6 +82,8 @@
 static int onlist(struct nvlist *, void *);
 static const char **fixloc(const char *, struct attr *, struct nvlist *);
 static const char *makedevstr(int, int);
+static const char *major2name(int);
+static int dev2major(struct devbase *);
 
 extern const char *yyfile;
 
@@ -549,23 +551,55 @@
                d->d_major = n;
 }
 
+const char *
+major2name(int maj)
+{
+       struct devbase *dev;
+       struct devm *dm;
+
+       if (!do_devsw) {
+               TAILQ_FOREACH(dev, &allbases, d_next) {
+                       if (dev->d_major == maj)
+                               return (dev->d_name);
+               }
+       } else {
+               TAILQ_FOREACH(dm, &alldevms, dm_next) {
+                       if (dm->dm_bmajor == maj)
+                               return (dm->dm_name);
+               }
+       }
+       return (NULL);
+}
+
+int
+dev2major(struct devbase *dev)
+{
+       struct devm *dm;
+
+       if (!do_devsw)
+               return (dev->d_major);
+
+       TAILQ_FOREACH(dm, &alldevms, dm_next) {
+               if (strcmp(dm->dm_name, dev->d_name) == 0)
+                       return (dm->dm_bmajor);
+       }
+       return (NODEV);
+}
+
 /*
  * Make a string description of the device at maj/min.
  */
 static const char *
 makedevstr(int maj, int min)
 {
-       struct devm *dm;
+       const char *devname;
        char buf[32];
 
-       TAILQ_FOREACH(dm, &alldevms, dm_next) {
-               if (dm->dm_bmajor == maj)
-                       break;
-       }
-       if (dm == NULL)
+       devname = major2name(maj);
+       if (devname == NULL)
                (void)sprintf(buf, "<%d/%d>", maj, min);
        else
-               (void)sprintf(buf, "%s%d%c", dm->dm_name,
+               (void)sprintf(buf, "%s%d%c", devname,
                    min / maxpartitions, (min % maxpartitions) + 'a');
 
        return (intern(buf));
@@ -582,7 +616,6 @@
 {
        struct nvlist *nv;
        struct devbase *dev;
-       struct devm *dm;
        const char *cp;
        int maj, min, i, l;
        int unit;
@@ -654,17 +687,13 @@
                nv->nv_int = NODEV;
                nv->nv_ifunit = unit;   /* XXX XXX XXX */
        } else {
-               TAILQ_FOREACH(dm, &alldevms, dm_next) {
-                       if (strcmp(dm->dm_name, dev->d_name) == 0)
-                               break;
-               }
-               if (dm == NULL) {
+               maj = dev2major(dev);
+               if (maj == NODEV) {
                        error("%s: can't make %s device from `%s'",
                            name, what, nv->nv_str);
                        return (1);
                }
-               nv->nv_int =
-                   makedev(dm->dm_bmajor, unit * maxpartitions + part);
+               nv->nv_int = makedev(maj, unit * maxpartitions + part);
        }
 
        nv->nv_name = dev->d_name;



Home | Main Index | Thread Index | Old Index