PERFORCE change 124231 for review
Constantine A. Murenin
cnst at FreeBSD.org
Sat Jul 28 00:26:10 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124231
Change 124231 by cnst at 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);
+}
+
More information about the p4-projects
mailing list