Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Framework for sysctl descriptions. Implementation to fo...
details: https://anonhg.NetBSD.org/src/rev/161a9b18c4b8
branches: trunk
changeset: 559841:161a9b18c4b8
user: atatat <atatat%NetBSD.org@localhost>
date: Wed Mar 24 17:40:02 2004 +0000
description:
Framework for sysctl descriptions. Implementation to follow shortly.
diffstat:
sys/kern/kern_sysctl.c | 35 ++++++++++++++++++++++++++++++-----
sys/sys/sysctl.h | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 6 deletions(-)
diffs (147 lines):
diff -r fc01f998a87a -r 161a9b18c4b8 sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c Wed Mar 24 17:26:53 2004 +0000
+++ b/sys/kern/kern_sysctl.c Wed Mar 24 17:40:02 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sysctl.c,v 1.164 2004/03/24 17:21:02 atatat Exp $ */
+/* $NetBSD: kern_sysctl.c,v 1.165 2004/03/24 17:40:02 atatat Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.164 2004/03/24 17:21:02 atatat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.165 2004/03/24 17:40:02 atatat Exp $");
#include "opt_defcorename.h"
#include "opt_insecure.h"
@@ -410,6 +410,9 @@
case CTL_MMAP:
fn = (sysctlfn)sysctl_mmap; /* we own the rnode */
break;
+ case CTL_DESCRIBE:
+ fn = sysctl_describe;
+ break;
default:
error = EOPNOTSUPP;
break;
@@ -573,9 +576,8 @@
}
/*
- * sysctl_query -- The auto-discovery engine. Copies out the
- * descriptions on nodes under the given node and handles overlay
- * trees.
+ * sysctl_query -- The auto-discovery engine. Copies out the structs
+ * describing nodes under the given node and handles overlay trees.
*/
int
sysctl_query(SYSCTLFN_ARGS)
@@ -1578,6 +1580,29 @@
return ((*node->sysctl_func)(SYSCTLFN_CALL(node)));
}
+int
+sysctl_describe(SYSCTLFN_ARGS)
+{
+
+ if (SYSCTL_VERS(rnode->sysctl_flags) != SYSCTL_VERSION) {
+ printf("sysctl_query: rnode %p wrong version\n", rnode);
+ return (EINVAL);
+ }
+
+ if (SYSCTL_TYPE(rnode->sysctl_flags) != CTLTYPE_NODE)
+ return (ENOTDIR);
+ if (namelen != 1 || name[0] != CTL_DESCRIBE)
+ return (EINVAL);
+
+ /*
+ * implementation to be filled in later
+ */
+
+ *oldlenp = 0;
+
+ return (0);
+}
+
/*
* ********************************************************************
* Section 3: Create and destroy from inside the kernel
diff -r fc01f998a87a -r 161a9b18c4b8 sys/sys/sysctl.h
--- a/sys/sys/sysctl.h Wed Mar 24 17:26:53 2004 +0000
+++ b/sys/sys/sysctl.h Wed Mar 24 17:40:02 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysctl.h,v 1.112 2004/03/24 17:21:02 atatat Exp $ */
+/* $NetBSD: sysctl.h,v 1.113 2004/03/24 17:40:02 atatat Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -46,6 +46,13 @@
#include <sys/proc.h>
#include <uvm/uvm_extern.h>
+/* For offsetof() */
+#ifdef _KERNEL
+#include <sys/systm.h>
+#else
+#include <stddef.h>
+#endif
+
/*
* Definitions for sysctl call. The sysctl call uses a hierarchical name
* for objects that can be examined or modified. The name is expressed as
@@ -97,6 +104,7 @@
#define CTLFLAG_HIDDEN 0x00008000
#define CTLFLAG_ALIAS 0x00010000
#define CTLFLAG_MMAP 0x00020000
+#define CTLFLAG_OWNDESC 0x00040000
/*
* sysctl API version
@@ -135,6 +143,7 @@
#define CTL_CREATESYM -4 /* node create request with symbol */
#define CTL_DESTROY -5 /* node destroy request */
#define CTL_MMAP -6 /* mmap request */
+#define CTL_DESCRIBE -7 /* get node descriptions */
/*
* Top-level identifiers
@@ -944,6 +953,7 @@
int sysctl_create(SYSCTLFN_RWPROTO);
int sysctl_destroy(SYSCTLFN_RWPROTO);
int sysctl_lookup(SYSCTLFN_RWPROTO);
+int sysctl_describe(SYSCTLFN_PROTO);
/*
* simple variadic interface for adding/removing nodes
@@ -1095,6 +1105,29 @@
#define sysctl_idata sysctl_un.scu_idata
#define sysctl_qdata sysctl_un.scu_qdata
+/*
+ * when requesting a description of a node (a set of nodes, actually),
+ * you get back an "array" of these, where the actual length of the
+ * descr_str is noted in descr_len (which includes the trailing nul
+ * byte), rounded up to the nearest four (sizeof(int32_t) actually).
+ *
+ * NEXT_DESCR() will take a pointer to a description and advance it to
+ * the next description.
+ */
+struct sysctldesc {
+ int32_t descr_num; /* mib number of node */
+ uint32_t descr_ver; /* version of node */
+ uint32_t descr_len; /* length of description string */
+ char descr_str[1]; /* not really 1...see above */
+};
+
+#define __sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
+#define __sysc_desc_adv(d, l) \
+ (((const char*)(d)) + offsetof(struct sysctldesc, descr_str) + \
+ __sysc_desc_roundup(l))
+#define NEXT_DESCR(d) ((struct sysctldesc *) \
+ __sysc_desc_adv((d), (d)->descr_len))
+
static __inline struct sysctlnode *
sysctl_rootof(struct sysctlnode *n)
{
Home |
Main Index |
Thread Index |
Old Index