Source-Changes-HG archive

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

[src/netbsd-3]: src Pull up following revision(s) (requested by lukem in tick...



details:   https://anonhg.NetBSD.org/src/rev/a71c30543fe6
branches:  netbsd-3
changeset: 577848:a71c30543fe6
user:      tron <tron%NetBSD.org@localhost>
date:      Mon Feb 20 15:26:49 2006 +0000

description:
Pull up following revision(s) (requested by lukem in ticket #1178):
        sys/dev/ccd.c: revision 1.108
        sbin/ccdconfig/ccdconfig.c: revision 1.42
* The kernel's struct ccd_softc has extra structure members over the
  userland version; provide another ccd global variable (ccd_softc_elemsize)
  containing the kernel's size, and use that it ccdconfig(8) to convert the
  kernel's ccd_softc into userland versions.
  Fixes 'ccdconfig -g'.
* Use DISKUNIT() instead of home-grown cruft to determine the `N' of "ccdN".
  Fixes 'ccdconfig -g ccd1'.
* Use (void *) instead of (char *) in the calls to kvm_read().
XXX: ccd could be converted from nlist to sysctl.  "Someone else's yak shave".

diffstat:

 sbin/ccdconfig/ccdconfig.c |  62 ++++++++++++++++++++++++++++++---------------
 sys/dev/ccd.c              |  13 +++++----
 2 files changed, 48 insertions(+), 27 deletions(-)

diffs (190 lines):

diff -r 71c5d5ee3b93 -r a71c30543fe6 sbin/ccdconfig/ccdconfig.c
--- a/sbin/ccdconfig/ccdconfig.c        Mon Feb 20 15:23:44 2006 +0000
+++ b/sbin/ccdconfig/ccdconfig.c        Mon Feb 20 15:26:49 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccdconfig.c,v 1.40 2005/01/20 15:49:24 xtraeme Exp $   */
+/*     $NetBSD: ccdconfig.c,v 1.40.2.1 2006/02/20 15:26:49 tron Exp $  */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 __COPYRIGHT(
 "@(#) Copyright (c) 1996, 1997\
        The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: ccdconfig.c,v 1.40 2005/01/20 15:49:24 xtraeme Exp $");
+__RCSID("$NetBSD: ccdconfig.c,v 1.40.2.1 2006/02/20 15:26:49 tron Exp $");
 #endif
 
 #include <sys/param.h>
@@ -91,6 +91,8 @@
 #define SYM_CCDSOFTC           0
        { "_numccd" },
 #define SYM_NUMCCD             1
+       { "_ccd_softc_elemsize" },
+#define SYM_CCDSOFTCELEMSIZE   2
        { NULL },
 };
 
@@ -405,7 +407,6 @@
 pathtounit(char *path, int *unitp)
 {
        struct stat st;
-       int maxpartitions;
 
        if (stat(path, &st) != 0)
                return (errno);
@@ -413,10 +414,7 @@
        if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
                return (EINVAL);
 
-       if ((maxpartitions = getmaxpartitions()) < 0)
-               return (errno);
-
-       *unitp = minor(st.st_rdev) / maxpartitions;
+       *unitp = DISKUNIT(st.st_rdev);
 
        return (0);
 }
@@ -491,12 +489,14 @@
 {
        char errbuf[_POSIX2_LINE_MAX], *ccd, *cp;
        struct ccd_softc *cs, *kcs;
+       void *vcs;
        size_t readsize;
-       int i, error, numccd, numconfiged = 0;
+       int i, error, numccd, ccd_softc_elemsize, numconfiged = 0;
        kvm_t *kd;
 
        memset(errbuf, 0, sizeof(errbuf));
 
+       vcs = NULL;
        (void)setegid(egid);
        if ((kd = kvm_openfiles(kernel, core, NULL, O_RDONLY,
            errbuf)) == NULL) {
@@ -509,7 +509,7 @@
                KVM_ABORT(kd, "ccd-related symbols not available");
 
        /* Check to see how many ccds are currently configured. */
-       if (kvm_read(kd, nl[SYM_NUMCCD].n_value, (char *)&numccd,
+       if (kvm_read(kd, nl[SYM_NUMCCD].n_value, (void *)&numccd,
            sizeof(numccd)) != sizeof(numccd))
                KVM_ABORT(kd, "can't determine number of configured ccds");
 
@@ -518,28 +518,48 @@
                goto done;
        }
 
-       /* Allocate space for the configuration data. */
-       readsize = numccd * sizeof(struct ccd_softc);
-       if ((cs = malloc(readsize)) == NULL) {
+       if (kvm_read(kd, nl[SYM_CCDSOFTCELEMSIZE].n_value,
+           (void *)&ccd_softc_elemsize, sizeof(ccd_softc_elemsize))
+           != sizeof(ccd_softc_elemsize))
+               KVM_ABORT(kd, "can't determine size of ccd_softc");
+
+       /* Allocate space for the kernel's configuration data. */
+       readsize = numccd * ccd_softc_elemsize;
+       if ((vcs = malloc(readsize)) == NULL) {
                warnx("no memory for configuration data");
                goto bad;
        }
-       memset(cs, 0, readsize);
+       memset(vcs, 0, readsize);
 
        /*
-        * Read the ccd configuration data from the kernel and dump
-        * it to stdout.
+        * Read the ccd configuration data from the kernel.
+        * The kernel's ccd_softc is larger than userland's
+        * (the former contains extra structure members at
+        * the end of the structure), so read the kernel
+        * ccd_softcs into a temporary buffer and convert
+        * into userland ccd_softcs.
         */
-       if (kvm_read(kd, nl[SYM_CCDSOFTC].n_value, (char *)&kcs,
+       if (kvm_read(kd, nl[SYM_CCDSOFTC].n_value, (void *)&kcs,
            sizeof(kcs)) != sizeof(kcs)) {
-               free(cs);
+               free(vcs);
                KVM_ABORT(kd, "can't find pointer to configuration data");
        }
-       if (kvm_read(kd, (u_long)kcs, (char *)cs, readsize) != readsize) {
-               free(cs);
+       if (kvm_read(kd, (u_long)kcs, vcs, readsize) != readsize) {
+               free(vcs);
                KVM_ABORT(kd, "can't read configuration data");
        }
 
+       if ((cs = calloc(numccd, sizeof(struct ccd_softc))) == NULL) {
+               warnx("no memory for configuration data");
+               goto bad;
+       }
+       for (i = 0; i < numccd; i++) {
+               memcpy(&cs[i], (char *)vcs + i * ccd_softc_elemsize,
+                   sizeof(struct ccd_softc));
+       }
+       free(vcs);
+
+       /* Dump ccd configuration to stdout. */
        if (argc == 0) {
                for (i = 0; i < numccd; ++i)
                        if (cs[i].sc_flags & CCDF_INITED) {
@@ -613,7 +633,7 @@
        fflush(stdout);
 
        /* Read in the component info. */
-       if (kvm_read(kd, (u_long)cs->sc_cinfo, (char *)cip,
+       if (kvm_read(kd, (u_long)cs->sc_cinfo, (void *)cip,
            readsize) != readsize) {
                printf("\n");
                warnx("can't read component info");
@@ -623,7 +643,7 @@
 
        /* Read component pathname and display component info. */
        for (i = 0; i < cs->sc_nccdisks; ++i) {
-               if (kvm_read(kd, (u_long)cip[i].ci_path, (char *)path,
+               if (kvm_read(kd, (u_long)cip[i].ci_path, (void *)path,
                    cip[i].ci_pathlen) != cip[i].ci_pathlen) {
                        printf("\n");
                        warnx("can't read component pathname");
diff -r 71c5d5ee3b93 -r a71c30543fe6 sys/dev/ccd.c
--- a/sys/dev/ccd.c     Mon Feb 20 15:23:44 2006 +0000
+++ b/sys/dev/ccd.c     Mon Feb 20 15:26:49 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccd.c,v 1.102.2.1 2005/04/06 11:57:27 tron Exp $       */
+/*     $NetBSD: ccd.c,v 1.102.2.2 2006/02/20 15:26:49 tron Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.102.2.1 2005/04/06 11:57:27 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.102.2.2 2006/02/20 15:26:49 tron Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -222,9 +222,10 @@
 static void printiinfo(struct ccdiinfo *);
 #endif
 
-/* Non-private for the benefit of libkvm. */
-struct ccd_softc *ccd_softc;
-int    numccd = 0;
+/* Publically visible for the benefit of libkvm and ccdconfig(8). */
+struct ccd_softc       *ccd_softc;
+const int              ccd_softc_elemsize = sizeof(struct ccd_softc);
+int                    numccd = 0;
 
 /*
  * Called by main() during pseudo-device attachment.  All we need
@@ -243,7 +244,7 @@
                return;
        }
 
-       ccd_softc = (struct ccd_softc *)malloc(num * sizeof(struct ccd_softc),
+       ccd_softc = (struct ccd_softc *)malloc(num * ccd_softc_elemsize,
            M_DEVBUF, M_NOWAIT|M_ZERO);
        if (ccd_softc == NULL) {
                printf("WARNING: no memory for concatenated disks\n");



Home | Main Index | Thread Index | Old Index