.\"
.\" Copyright (c) 2000, Andrzej Bialecki <abial@FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" %FreeBSD: src/share/man/man9/sysctl_add_oid.9,v 1.20 2004/07/03 18:29:24 ru Exp %
.\" $FreeBSD$
.\"
.Dd July 15, 2000
.Dt SYSCTL_ADD_OID 9
.Os
.Sh ̾��
.Nm sysctl_add_oid ,
.Nm sysctl_move_oid ,
.Nm sysctl_remove_oid
.Nd ��󥿥��� sysctl �ĥ꡼���
.Sh ��
.In sys/types.h
.In sys/sysctl.h
.Ft struct sysctl_oid *
.Fo sysctl_add_oid
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int kind"
.Fa "void *arg1"
.Fa "int arg2"
.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
.Fa "const char *format"
.Fa "const char *descr"
.Fc
.Ft int
.Fo sysctl_move_oid
.Fa "struct sysctl_oid *oidp"
.Fa "struct sysctl_oid_list *parent"
.Fc
.Ft int
.Fo sysctl_remove_oid
.Fa "struct sysctl_oid *oidp"
.Fa "int del"
.Fa "int recurse"
.Fc
.Ft struct sysctl_oid_list *
.Fo SYSCTL_CHILDREN
.Fa "struct sysctl_oid *oidp"
.Fc
.Ft struct sysctl_oid_list *
.Fo SYSCTL_STATIC_CHILDREN
.Fa "struct sysctl_oid_list OID_NAME"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_OID
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int kind"
.Fa "void *arg1"
.Fa "int arg2"
.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
.Fa "const char *format"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_NODE
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_STRING
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "char *arg"
.Fa "int len"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_INT
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "int *arg"
.Fa "int len"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_UINT
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "unsigned int *arg"
.Fa "int len"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_LONG
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "long *arg"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_ULONG
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "unsigned long *arg"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_OPAQUE
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "void *arg"
.Fa "int len"
.Fa "const char *format"
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_STRUCT
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "void *arg"
.Fa STRUCT_NAME
.Fa "const char *descr"
.Fc
.Ft struct sysctl_oid *
.Fo SYSCTL_ADD_PROC
.Fa "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *parent"
.Fa "int number"
.Fa "const char *name"
.Fa "int access"
.Fa "void *arg1"
.Fa "int arg2"
.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
.Fa "const char *format"
.Fa "const char *descr"
.Fc
.Sh ����
�����δؿ�����ӥޥ����� sysctl oid �Υ�󥿥��� (�㤨�Х⥸�塼���
¸�ߴ���) �Ǥκ����Ⱥ���Τ���Υ��󥿥ե��������󶡤��ޤ���
��󥫥��å� (�ܺ٤�
.In sys/linker_set.h
�����
.\" XXX �ޥ˥奢��ڡ����ϥ������ե�����λ��Ȥ��򤱤�٤��Ǥ���
.Pa src/sys/kern/kern_sysctl.c
�򻲾�) 
�˴�Ť��������ˡ�ϡ��ơ��Υ⥸�塼��Υ����ɻ�����ӥ�������ɻ���
�����Ⱥ���Τߤ��ǽ�ˤ��ޤ���
.Pp
��
.Dv CTLTYPE_NODE
��ưŪ�� oid �Ϻ����Ѳ�ǽ�Ǥ��뤿�ᡢʣ���Υ����ɥ�������󤬡�
oid ���������Ӻ�����뤳�Ȥ���ǽ�Ǥ���
�ºݤˤϡ����ȥ�����Ȥ˴�Ť��ơ����γ�����Ƥ���Ӳ������Ԥ��ޤ���
���η�̤Ȥ��ơ�2 �İʾ�Υ����ɥ�������󤬡���ʬŪ�˽Ťʤꡢ
ξ�Ԥ����ѤǤ���ĥ꡼�������ǽ�ˤ��ޤ���
�Ťʤ��դκ����䡢Ʊ���̾���ȿƤ���İۤʤ뷿�λҤκ����ϡ�
�Բ�ǽ�Ǥ���
.Pp
�������������줿 oid �ϿƤΥΡ��ɤ���³����ޤ���
��������Ƥδؿ�����ӥޥ���
.Fn ( sysctl_remove_oid
���㳰) �ˤ����ơ�ɬ�ܥѥ�᡼���� 1 ��
.Fa parent
�ϡ��Ҥοƥꥹ�Ȥ���Ƭ��ؤ��ޤ���
.Pp
�ؤɤΥȥåץ�٥�Υ��ƥ������Ū�˺�������ޤ���
��¸����Ū�� oid ����³����Ȥ��ˡ����Υݥ��󥿤�
.Fn SYSCTL_STATIC_CHILDREN
�ޥ����ˤ�äƼ������뤳�Ȥ���ǽ�ǡ�����
.Fa OID_NAME
������
.Dv CTLTYPE_NODE
���ο� oid ��̾�� (���ʤ����
.Xr sysctl 8
�ˤ�ä�ɽ�������̾���ˡ�
����������������֤������ƤΥɥåȤ򥢥�����������֤�������̾��) �Ǥ���
.Pp
��¸��ưŪ�� oid ����³����Ȥ��ˡ����Υݥ��󥿤�
.Fn SYSCTL_CHILDREN
�ޥ����ˤ�äƼ������뤳�Ȥ���ǽ�ǡ�����
.Fa oidp
������
.Dv CTLTYPE_NODE
���ο� oid ��ؤ��ޤ���
.Pp
.Fn sysctl_add_oid
�ؿ��Ϥ����뷿������ oid ��������ޤ���
oid �κ����������������ˤϡ����δؿ��Ϥ��� oid �ؤΥݥ��󥿤��֤��ޤ���
�����Ǥʤ����ˤϡ�
.Dv NULL
���֤��ޤ���
.Fn sysctl_add_oid
�Τ���ΰ�����¿���ϥޥ����ȶ��̤Ǥ���
�����ϰʲ��ΤȤ���Ǥ���
.Bl -tag -width handler
.It Fa ctx
���ץ����� sysctl ����ƥ����ȤؤΥݥ��󥿡��ޤ���
.Dv NULL
�Ǥ���
�ܺ٤�
.Xr sysctl_ctx_init 9
�򻲾Ȥ��Ƥ���������
���̤ʺ�������Ӻ���Υ������󥹤��׵ᤵ���ΤǤʤ���С�
��������ưŪ�� oid ���ȿ����뤿��˥���ƥ����Ȥ���Ѥ��뤳�Ȥ�
�ץ�����ޤ϶������𤵤�Ƥ��ޤ���
.Fa ctx
��
.Dv NULL
�Ǥʤ����ˤϡ���������������� oid �Ϻǽ�Υ���ȥ�Ȥ��Ƥ��Υ���ƥ����Ȥ�
�ɲä���ޤ���
.It Fa parent
�Ҥοƥꥹ�Ȥ���Ƭ�Ǥ���
.Li struct sysctl_oid_list
�ؤΥݥ��󥿤Ǥ���
.It Fa number
���� oid �˳�����Ƥ��� oid �ֹ�Ǥ���
�ؤ����Ƥξ�硢����ϳ�����ƻ��˼������Ѳ�ǽ�� oid �ֹ�ˤʤ�
.Dv OID_AUTO
�����ꤵ���٤��Ǥ���
.It Fa name
���� oid ��̾���Ǥ���
�������������줿 oid ��̾���Υ��ԡ���ޤ�Ǥ��ޤ���
.It Fa kind
oid �μ���ǡ�
.In sys/sysctl.h
�إå��ե����������������뷿�ȥ��������ͤΥӥåȥޥ����Ȥ�����������ޤ���
ưŪ�˺������줿 oid �Ͼ��
.Dv CTLFLAG_DYN
�ե饰�����ꤵ��ޤ���
���������ե饰�Ϥ��� oid ���ɤ߼�����Ѥ��ɤ߽񤭲�ǽ���������
���ƤΥ桼���ˤ�äƤޤ��ϥ����ѥ桼���ˤ�äƤΤ߽�����ǽ�����������ޤ���
.It Fa arg1
oid �����Ȥ��٤�������ǡ����ؤΥݥ��󥿡��ޤ���
.Dv NULL
�Ǥ���
.It Fa arg2
.Fa arg1
���礭�����ޤ���
.Fa arg1
��
.Dv NULL
�Ǥ���� 0 �Ǥ���
.It Fa handler
���� oid �ؤ��ɤ߽��׵���갷����Ǥ������ؿ��ؤΥݥ��󥿤Ǥ���
�Ρ��ɡ�������ʸ���󡢤������Ʃ���ʥ��֥������Ȥ����򥵥ݡ��Ȥ���
���Ĥ���ɸ��ϥ�ɥ餬¸�ߤ��Ƥ��ޤ���
.Fn SYSCTL_ADD_PROC
�ޥ�������Ѥ��ƿ������ϥ�ɥ��������뤳�Ȥ��ǽ�Ǥ���
.It Fa format
oid �Υե����ޥåȤ򵭹�Ū����������ʸ����ؤΥݥ��󥿤Ǥ���
���Υե����ޥåȤϡ�ɽ����Ū�Τ����Ŭ�ڤʥǡ����ե����ޥåȤ�Ŭ�Ѥ��뤿���
.Xr sysctl 8
�ˤ�äƥҥ�ȤȤ��ƻ��Ѥ���ޤ���
���߻��Ѥ���Ƥ���ե����ޥå�̾�ϰʲ��ΤȤ���Ǥ���
.Dq N
�ϥΡ��ɡ�
.Dq A
��
.Li "char *"
����
.Dq I
��
.Li "int"
����
.Dq IU
��
.Li "unsigned int"
����
.Dq L
��
.Li "long"
����
.Dq LU
��
.Li "unsigned long"
���������
.Dq S,TYPE
��
.Li "struct TYPE"
��¤�ΤǤ���
.It Fa descr
���� oid �β���ƥ����ȤؤΥݥ��󥿤Ǥ���
.El
.Pp
.Fn sysctl_move_oid
�ؿ���¸�ߤ��Ƥ��� oid �οƤ��դ��Ѥ��ޤ���
���� oid �ϡ��ޤ��
.Fa number
��
.Dv OID_AUTO
�����ꤵ��ƺ������줿�����ͤˡ��������ֹ�������Ƥ��ޤ���
.Pp
.Fn sysctl_remove_oid
�ؿ���ưŪ�˺������줿 oid ��ĥ꡼����������
���ץ����Ǥ��Υ꥽������������ޤ���
����ϰʲ��ΰ�������ޤ���
.Bl -tag -width recurse
.It Fa oidp
��������٤�ưŪ�� oid �ؤΥݥ��󥿤Ǥ���
oid ��ưŪ�Ǥʤ����ޤ��ϥݥ��󥿤�
.Dv NULL
�ξ��ˤϡ����δؿ���
.Er EINVAL
���֤��ޤ���
.It Fa del
0 �Ǥʤ����ˤϡ�oid �λ��ȥ�����Ȥ� 0 �ˤʤä����ˡ�
.Fn sysctl_remove_oid
�� oid �Υ꥽������������褦�Ȥ��ޤ���
�������ʤ���
.Fa del
�� 0 �����ꤵ��Ƥ�����ˤϡ����Υ롼����� oid �Υ꥽�����β����򤻤���
�ĥ꡼���� oid ����Ͽ���äΤߤ�Ԥʤ��ޤ���
���ο��񤤤ϡ��ƤӽФ�¦����� (�Ҥ�äȤ������ʬŪ�˼��Ԥ���) ¿���� oid ��
����Υ�����Хå���ͽ�����Ƥ�����ˡ�ͭ�ѤǤ���
.It Fa recurse
0 �Ǥʤ����ˤϡ����ΥΡ��ɤȤ��λҤ������褦�Ȥ��ޤ���
.Pa recurse
�� 0 �����ꤵ��Ƥ�����ˤϡ�������Ҥ�ޤ�Ρ��ɤκ���λ�ߤ�
.Er ENOTEMPTY
���顼��ȯ�������ޤ���
.Em �ٹ� : "�Ƶ�Ū�ʺ�����������դ�ʧ�äƻ��Ѥ��뤳��" !
�̾����ƥ����Ȥ����Ѥ���Ƥ���С�ɬ�פȤ����٤��ǤϤ���ޤ���
����ƥ����Ȥϥĥ꡼�����ѼԴ֤ΰ�¸�������פ����դ��Ƥ��ޤ���
�������ʤ��顢�����ü�ʾ��ˤϡ�����¾�Υ꥽������������뤿��ˡ�
���줬�ɤΤ褦�˺������줿��ΤǤ��졢���֥ĥ꡼�ΰ����������뤳�Ȥ�
ɬ�פˤʤ뤳�Ȥ�����ޤ���
�������ʤ��顢���Τ��Ȥϡ��̤Υ����ɥ�������󤬺�����줿���֥ĥ꡼��
���Ѥ�³������ˡ������ƥ��
.Xr panic 9
��������������Ȥ����뤳�Ȥ��ΤäƤ��Ƥ���������
.El
.Pp
.\" XXX sheldonh �Ϥ����ޤǻž夲�ޤ�����
���ٸ����ޤ������ؤ�ɤξ�硢�������줿 oid �򸫼���ʤ��褦�ˤ��뤿�ᡢ
����Ӹ�������Ȥ���ή���Ǥ����������뤿�ᡢ
.Xr sysctl_ctx_init 9
�Dz��⤵��Ƥ���褦�ˡ��ץ�����ޤϥ���ƥ����Ȥ���Ѥ���٤��Ǥ���
.Pp
Ϳ����줿���� oid �κ��������������ѤߤΥޥ������åȤ�����ޤ���
.Bl -tag -width SYSCTL_ADD_STRINGXX
������ʲ��˼����ޤ���
.It Fn SYSCTL_ADD_OID
������ oid ��������ޤ���
���Υޥ����ϵ�ǽŪ�ˤ�
.Fn sysctl_add_oid
�ؿ���Ʊ���Ǥ���
.It Fn SYSCTL_ADD_NODE
�Ϸ�
.Dv CTLTYPE_NODE
�� oid ��������ޤ���
���� oid ���Ф��ơ��Ҥ� oid ���ɲò�ǽ�Ǥ���
.It Fn SYSCTL_ADD_STRING
�� 0 �ǽ�ü���줿ʸ������갷�� oid ��������ޤ���
.It Fn SYSCTL_ADD_INT
��
.Li int
�ѿ����갷�� oid ��������ޤ���
.It Fn SYSCTL_ADD_UINT
��
.Li unsigned int
�ѿ����갷�� oid ��������ޤ���
.It Fn SYSCTL_ADD_LONG
��
.Li long
�ѿ����갷�� oid ��������ޤ���
.It Fn SYSCTL_ADD_ULONG
��
.Li unsigned long
�ѿ����갷�� oid ��������ޤ���
.It Fn SYSCTL_ADD_OPAQUE
��
.Li "size_t *"
�ؤΥݥ��󥿤Ǥ���
.Fa len
�����ˤ�ä��������줿�礭���Τ�������Ʃ���ʥǡ����Τ����ޤ��
��갷�� oid ��������ޤ���
.It Fn SYSCTL_ADD_STRUCT
��
.Li "struct TYPE"
��¤�Τ��갷�� oid ��������ޤ���
.Fa format
������
.Xr sysctl 8
�桼�ƥ���ƥ��ؤ�Ŭ�ڤʥҥ�Ȥ��󶡤��뤿���
.Dq S,TYPE
�����ꤵ��ޤ���
.It Fn SYSCTL_ADD_PROC
���������줿
.Pa handler
�ϥ�ɥ�ؿ������ oid ��������ޤ���
�ϥ�ɥ�� oid ���Ф��Ƥ��ɤ߽��׵���갷����Ǥ������ޤ���
�����ͥ�ǡ�������ñ�˥��������Ǥ��ʤ���硢�ޤ��ϼ��Ф�������˽��������
ɬ�פ�������ˡ����� oid �����ä�ͭ�ѤǤ���
.El
.Sh ������
�ʲ��ϡ��ɤΤ褦�˿������ȥåץ�٥�Υ��ƥ����������뤫�������
�ɤΤ褦�˴�¸����Ū�ʥΡ��ɤ��̤Υ��֥ĥ꡼����óݤ��뤫
�򼨤�������Ǥ���
���λ�����ϥ���ƥ����Ȥ���Ѥ��Ƥ��ޤ���
��������Ƥθ�Ǥ������������Ȥ��ä���
��֤� oid ������ʴ������̤Ȥ������������ޤ���
.Bd -literal
#include <sys/sysctl.h>
 ...
/* �����������������֥ĥ꡼�ؤΥݥ��󥿤ϡ���Ǥ�����������뤿���
 * ��¸���Ƥ���ɬ�פ�����ޤ���
 */
struct sysctl_oid *root1, *root2, *oidp;
int a_int;
char *string = "dynamic sysctl";
 ...

root1 = SYSCTL_ADD_NODE( NULL, SYSCTL_STATIC_CHILDREN(/* tree top */),
	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
oidp = SYSCTL_ADD_INT( NULL, SYSCTL_CHILDREN(root1),
	OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
 ...
root2 = SYSCTL_ADD_NODE( NULL, SYSCTL_STATIC_CHILDREN(_debug),
	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
oidp = SYSCTL_ADD_STRING( NULL, SYSCTL_CHILDREN(root2),
	OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
.Ed
.Pp
���λ�����ϰʲ��Υ��֥ĥ꡼��������ޤ���
.Bd -literal -offset indent
debug.newtree.newstring
newtree.newint
.Ed
.Pp
.Em "����ʾ�ɬ�פǤʤ��ʤä����Ƥ� oid �ϲ��������٤��Ǥ��뤳�Ȥ�����!"
.Sh ��Ϣ����
.Xr sysctl 8 ,
.Xr sysctl_ctx_free 9 ,
.Xr sysctl_ctx_init 9
.Sh ���
�����δؿ���
.Fx 4.2
�ǤϤ�����о줷�ޤ�����
.Sh ���
.An Andrzej Bialecki Aq abial@FreeBSD.org
.Sh �Х�
¿���Υ����ɥ��������֤ǥΡ��ɤ�ͭ���뤳�Ȥϡ�
�����꥽��������å����뤳�Ȥ�������߰�¸������������ޤ���
�㤨�С��⥸�塼�� B �ˤ�äƺ������줿 oid ���Ф���
�⥸�塼�� A �����֥ĥ꡼����óݤ������ˤϡ�
�⥸�塼�� B �Ϥ��� oid �����Ǥ��ʤ��Ǥ��礦��
����������� sysctl ����ƥ����Ȥˤ�ä�Ŭ�ڤ˼�갷���ޤ���
.Pp
�ĥ꡼���¿�������ϥ�󥯥ꥹ�Ȥ��ڤ뤳�Ȥ�ɬ�פȤ��ޤ���
������ͳ�Τ��ᡢoid �κ����Ⱥ��������Ū�˥����Ȥ�������ޤ���