SYSCTL_INT(9) | Kernel Developer's Manual | SYSCTL_INT(9) |
sysctl_int
,
sysctl_bounded_arr
,
sysctl_quad
, sysctl_string
,
sysctl_tstring
,
sysctl_rdint
, sysctl_rdquad
,
sysctl_rdstring
,
sysctl_rdstruct
,
sysctl_struct
— kernel
sysctl interface
#include
<sys/types.h>
#include <sys/sysctl.h>
int
sysctl_int
(void *oldp,
size_t *oldlenp, void *newp,
size_t newlen, int *valp);
int
sysctl_bounded_arr
(const struct
sysctl_bounded_args *valpp, u_int valplen,
int *name, u_int namelen,
void *oldp, size_t *oldlenp,
void *newp, size_t newlen);
int
sysctl_quad
(void *oldp,
size_t *oldlenp, void *newp,
size_t newlen, int64_t
*valp);
int
sysctl_string
(void *oldp,
size_t *oldlenp, void *newp,
size_t newlen, char *str,
int maxlen);
int
sysctl_tstring
(void *oldp,
size_t *oldlenp, void *newp,
size_t newlen, char *str,
int maxlen);
int
sysctl_rdint
(void *oldp,
size_t *oldlenp, void *newp,
int val);
int
sysctl_rdquad
(void *oldp,
size_t *oldlenp, void *newp,
int64_t val);
int
sysctl_rdstring
(void *oldp,
size_t *oldlenp, void *newp,
const char *str);
int
sysctl_rdstruct
(void *oldp,
size_t *oldlenp, void *newp,
const void *sp, int len);
int
sysctl_struct
(void *oldp,
size_t *oldlenp, void *newp,
size_t newlen, void *sp,
int len);
These functions and data structures aim to simplify and partially implement operations for the kernel and user implementations of the sysctl(2) interface. A single syscall(9) is used to request and modify kernel variables. The mib argument is recursively scanned as an array of integers, either calling further functions for parsing the rest of the MIB for nodes or operating on kernel data for leaf nodes.
For each level of the MIB tree, the kernel header files provide a cpp(1) macro initialiser for an array of the following data structures:
struct ctlname { char *ctl_name; /* subsystem name */ int ctl_type; /* type of name */ };
For example:
#define CTL_NAMES { \ { 0, 0 }, \ { "kern", CTLTYPE_NODE }, \ { "vm", CTLTYPE_NODE }, \ { "fs", CTLTYPE_NODE }, \ { "net", CTLTYPE_NODE }, \ { "debug", CTLTYPE_NODE }, \ { "hw", CTLTYPE_NODE }, \ { "machdep", CTLTYPE_NODE }, \ { "user", CTLTYPE_NODE }, \ { "ddb", CTLTYPE_NODE }, \ { "vfs", CTLTYPE_NODE }, \ }
Each array element initialiser maps the correspondent MIB identifier. The ctl_name field provides a string name. The ctl_type field describes the identifier type, where possible values are:
For each of the types there are two functions provided to perform both read and write or only a read operation on the identifier (see the following subsection).
These data structures are used by the sysctl(8) program to provide mapping into MIB identifiers.
All of the functions perform a write provided that
newp is not a NULL
pointer and
newlen specifies an appropriate data length. All
read-only versions of the functions return EPERM
if
a write operation is requested.
The following helper functions are provided to aid operation on the kernel data variables referenced by the leaf nodes in the MIBs:
sysctl_int
(void
*oldp, size_t *oldlenp, void
*newp, size_t newlen, int
*valp)sysctl_rdint
(void
*oldp, size_t *oldlenp, void
*newp, int val)sysctl_bounded_arr
(const
struct sysctl_bounded_args *valpp, u_int
valplen, int *name, u_int
namelen, void *oldp, size_t
*oldlenp, void *newp, size_t
newlen)sysctl_int
() to read/write as
normal.sysctl_quad
(void
*oldp, size_t *oldlenp, void
*newp, size_t newlen, int64_t
*valp)sysctl_rdquad
(void
*oldp, size_t *oldlenp, void
*newp, int64_t val)sysctl_string
(void
*oldp, size_t *oldlenp, void
*newp, size_t newlen, char
*str, int maxlen)ENOMEM
is returned. If
newlen is larger than maxlen,
an EINVAL
error is returned.sysctl_tstring
(void
*oldp, size_t *oldlenp, void
*newp, size_t newlen, char
*str, int maxlen)ENOMEM
.sysctl_rdstring
(void
*oldp, size_t *oldlenp, void
*newp, const char *str)sysctl_string
().sysctl_struct
(void
*oldp, size_t *oldlenp, void
*newp, size_t newlen, void
*sp, int len)sysctl_rdstruct
(void
*oldp, size_t *oldlenp, void
*newp, const void *sp, int
len)These functions first appeared in 4.4BSD.
September 1, 2020 | OpenBSD-current |