From owner-p4-projects@FreeBSD.ORG Sat Jul 28 00:26:10 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E4FA216A41B; Sat, 28 Jul 2007 00:26:09 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 863D816A417 for ; Sat, 28 Jul 2007 00:26:09 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5892313C428 for ; Sat, 28 Jul 2007 00:26:09 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l6S0Q9oA091179 for ; Sat, 28 Jul 2007 00:26:09 GMT (envelope-from cnst@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l6S0Q9uN091176 for perforce@freebsd.org; Sat, 28 Jul 2007 00:26:09 GMT (envelope-from cnst@FreeBSD.org) Date: Sat, 28 Jul 2007 00:26:09 GMT Message-Id: <200707280026.l6S0Q9uN091176@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to cnst@FreeBSD.org using -f From: "Constantine A. Murenin" To: Perforce Change Reviews Cc: Subject: PERFORCE change 124231 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Jul 2007 00:26:10 -0000 http://perforce.freebsd.org/chv.cgi?CH=124231 Change 124231 by cnst@dale on 2007/07/28 00:25:14 bring a some sysctl glue from OpenBSD Obtained from: OpenBSD: kern_sysctl.c,v 1.154 2007/06/01 Affected files ... .. //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#3 edit Differences ... ==== //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#3 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $P4: //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#2 $ */ +/* $P4: //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#3 $ */ /* $FreeBSD$ */ /* $OpenBSD: kern_sensors.c,v 1.19 2007/06/04 18:42:05 deraadt Exp $ */ @@ -264,3 +264,89 @@ /* must be an empty list, or at the end of the list */ TAILQ_INSERT_TAIL(&tasklist, st, entry); } + +/* + * sysctl glue code + */ +int sysctl_rdstruct(void *, size_t *, void *, const void *, int); +int sysctl_sensors(int *, u_int, void *, size_t *, void *, size_t); + +/* + * Validate parameters and get old parameters + * for a structure oriented sysctl function. + */ +int +sysctl_rdstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp, + int len) +{ + int error = 0; + + if (oldp && *oldlenp < len) + return (ENOMEM); + if (newp) + return (EPERM); + *oldlenp = len; + if (oldp) + error = copyout(sp, oldp, len); + return (error); +} + +int +sysctl_sensors(int *name, u_int namelen, void *oldp, size_t *oldlenp, + void *newp, size_t newlen) +{ + struct ksensor *ks; + struct sensor *us; + struct ksensordev *ksd; + struct sensordev *usd; + int dev, numt, ret; + enum sensor_type type; + + if (namelen != 1 && namelen != 3) + return (ENOTDIR); + + dev = name[0]; + if (namelen == 1) { + ksd = sensordev_get(dev); + if (ksd == NULL) + return (ENOENT); + + /* Grab a copy, to clear the kernel pointers */ + usd = malloc(sizeof(*usd), M_TEMP, M_WAITOK); + bzero(usd, sizeof(*usd)); + usd->num = ksd->num; + strlcpy(usd->xname, ksd->xname, sizeof(usd->xname)); + memcpy(usd->maxnumt, ksd->maxnumt, sizeof(usd->maxnumt)); + usd->sensors_count = ksd->sensors_count; + + ret = sysctl_rdstruct(oldp, oldlenp, newp, usd, + sizeof(struct sensordev)); + + free(usd, M_TEMP); + return (ret); + } + + type = name[1]; + numt = name[2]; + + ks = sensor_find(dev, type, numt); + if (ks == NULL) + return (ENOENT); + + /* Grab a copy, to clear the kernel pointers */ + us = malloc(sizeof(*us), M_TEMP, M_WAITOK); + bzero(us, sizeof(*us)); + memcpy(us->desc, ks->desc, sizeof(ks->desc)); + us->tv = ks->tv; + us->value = ks->value; + us->type = ks->type; + us->status = ks->status; + us->numt = ks->numt; + us->flags = ks->flags; + + ret = sysctl_rdstruct(oldp, oldlenp, newp, us, + sizeof(struct sensor)); + free(us, M_TEMP); + return (ret); +} +