SYSCTL_INT(9)
๐ NAME ๐
okay bestie, welcome to the SYSCTL_INT(9) page from the Kernel Developer's Manual โ this is the kernel sysctl interface and it's literally a whole cast of characters. The lineup is sysctl_int, sysctl_bounded_arr, sysctl_quad, sysctl_string, sysctl_tstring, sysctl_rdint, sysctl_rdquad, sysctl_rdstring, sysctl_rdstruct, and sysctl_struct โ all giving kernel sysctl interface energy. ๐
โจ SYNOPSIS โจ
#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);
๐ DESCRIPTION ๐
These functions and data structures are here 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. ๐ฆ
๐ฎ Data Structures ๐ฎ
For each level of the MIB tree, the kernel header files provide a cpp(1) macro initialiser for an array of this data structure:
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:
CTLTYPE_NODEโ the name is a node;CTLTYPE_INTโ the name describes an integer;CTLTYPE_STRINGโ the name describes a string;CTLTYPE_QUADโ the name describes a 64-bit number;CTLTYPE_STRUCTโ the name describes a structure.
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. ๐
๐ Functions ๐
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)โ the variable referenced byvalpis a 32-bit integer. Read or write returning the previous value in the user memory location pointed to by theoldpargument. The value pointed to byoldlenphas to be no less than four.sysctl_rdint(void *oldp, size_t *oldlenp, void *newp, int val)โ a read-only version of the above.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)โ asserts the new value is in the range specified by the element ofvalppwith the value of themibfield equal toname[0], before invokingsysctl_int()to read/write as normal.sysctl_quad(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int64_t *valp)โ the variable referenced is a 64-bit integer. Read or write returning the previous value in the user memory location pointed to by theoldpargument. The value pointed to byoldlenphas to be no less than eight.sysctl_rdquad(void *oldp, size_t *oldlenp, void *newp, int64_t val)โ a read-only version of the above.sysctl_string(void *oldp, size_t *oldlenp, void *newp, size_t newlen, char *str, int maxlen)โ the variable referenced by thestrargument is a string of maximum length ofmaxlen. The old value is copied out into a user buffer pointed to by theoldpargument. If there is not enough space to store it, anENOMEMis returned. Ifnewlenis larger thanmaxlen, anEINVALerror is returned.sysctl_tstring(void *oldp, size_t *oldlenp, void *newp, size_t newlen, char *str, int maxlen)โ a version of the above that truncates the old value that does not fit into the buffer provided byoldpinstead of returningENOMEM.sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, const char *str)โ a read-only version ofsysctl_string().sysctl_struct(void *oldp, size_t *oldlenp, void *newp, size_t newlen, void *sp, int len)โ assume the area pointed to by thespargument is an opaque array of bytes of sizelen. Old and new length checks are performed and data is copied in and/or out.sysctl_rdstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp, int len)โ a read-only version of the above. ๐
๐ฅ SEE ALSO ๐ฅ
sysctl(2), sysctl.conf(5), sysctl(8), syscall(9)
๐ HISTORY ๐
These functions first appeared in 4.4BSD. ๐
mwah ๐ this cute little page is from Debian, dated September 1, 2020, and it's SYSCTL_INT(9) โ periodt. ๐ซถ
๐ฆ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2006 Michael Shalayeff
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms