1 /*
2 * Copyright 2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _FBSD_COMPAT_SYS_SYSCTL_H_
6 #define _FBSD_COMPAT_SYS_SYSCTL_H_
7
8
9 #include <sys/queue.h>
10
11
12 #ifdef _KERNEL
13
14 struct sysctl_req {
15 void *newptr;
16 };
17
18 struct sysctl_ctx_list {
19 };
20
21 struct sysctl_oid_list {
22 };
23
24 struct sysctl_oid {
25 };
26
27
28 #define SYSCTL_HANDLER_ARGS void *oidp, void *arg1, int arg2, \
29 struct sysctl_req *req
30
31 #define OID_AUTO (-1)
32
33 #define CTLTYPE 0xf /* Mask for the type */
34 #define CTLTYPE_NODE 1 /* name is a node */
35 #define CTLTYPE_INT 2 /* name describes an integer */
36 #define CTLTYPE_STRING 3 /* name describes a string */
37 #define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
38 #define CTLTYPE_OPAQUE 5 /* name describes a structure */
39 #define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
40 #define CTLTYPE_UINT 6 /* name describes an unsigned integer */
41 #define CTLTYPE_LONG 7 /* name describes a long */
42 #define CTLTYPE_ULONG 8 /* name describes an unsigned long */
43 #define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */
44
45 #define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
46 #define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
47 #define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
48 #define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */
49 #define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
50 #define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
51 #define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
52 #define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
53 #define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
54 #define CTLMASK_SECURE 0x00F00000 /* Secure level */
55 #define CTLFLAG_TUN 0x00080000 /* Tunable variable */
56 #define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
57 #define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN)
58 #define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */
59 #define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */
60 #define CTLFLAG_DYING 0x00010000 /* Oid is being removed */
61 #define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */
62 #define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */
63 #define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */
64 #define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */
65 #define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR)
66 /*
67 * This is transient flag to be used until all sysctl handlers are converted
68 * to not lock Giant.
69 * One, and only one of CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT is required
70 * for SYSCTL_PROC and SYSCTL_NODE.
71 */
72 #define CTLFLAG_NEEDGIANT 0x00000800 /* Handler require Giant */
73
74
75 static inline int
sysctl_ctx_init(struct sysctl_ctx_list * clist)76 sysctl_ctx_init(struct sysctl_ctx_list *clist)
77 {
78 return -1;
79 }
80
81
82 static inline int
sysctl_ctx_free(struct sysctl_ctx_list * clist)83 sysctl_ctx_free(struct sysctl_ctx_list *clist)
84 {
85 return -1;
86 }
87
88
89 static inline int
sysctl_wire_old_buffer(struct sysctl_req * req,size_t len)90 sysctl_wire_old_buffer(struct sysctl_req *req, size_t len)
91 {
92 return -1;
93 }
94
95
96 static inline struct sbuf *
sbuf_new_for_sysctl(struct sbuf * s,char * buf,int length,struct sysctl_req * req)97 sbuf_new_for_sysctl(struct sbuf *s, char *buf, int length,
98 struct sysctl_req *req)
99 {
100 return NULL;
101 }
102
103
104 static inline void *
sysctl_add_oid(struct sysctl_ctx_list * clist,void * parent,int nbr,const char * name,int kind,void * arg1,int arg2,int (* handler)(SYSCTL_HANDLER_ARGS),const char * fmt,const char * descr)105 sysctl_add_oid(struct sysctl_ctx_list *clist, void *parent, int nbr,
106 const char *name, int kind, void *arg1, int arg2,
107 int (*handler) (SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr)
108 {
109 return NULL;
110 }
111
112
sysctl_handle_long(SYSCTL_HANDLER_ARGS)113 static inline int sysctl_handle_long(SYSCTL_HANDLER_ARGS) { return -1; }
sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)114 static inline int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS) { return -1; }
sysctl_handle_quad(SYSCTL_HANDLER_ARGS)115 static inline int sysctl_handle_quad(SYSCTL_HANDLER_ARGS) { return -1; }
sysctl_handle_int(SYSCTL_HANDLER_ARGS)116 static inline int sysctl_handle_int(SYSCTL_HANDLER_ARGS) { return -1; }
sysctl_handle_64(SYSCTL_HANDLER_ARGS)117 static inline int sysctl_handle_64(SYSCTL_HANDLER_ARGS) { return -1; }
sysctl_handle_string(SYSCTL_HANDLER_ARGS)118 static inline int sysctl_handle_string(SYSCTL_HANDLER_ARGS) { return -1; }
119
120
121 #define SYSCTL_OUT(r, p, l) -1
122
123 #define __DESCR(x) ""
124
125 #define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
126 sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, \
127 __DESCR(descr))
128
129 #define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \
130 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \
131 0, 0, handler, "N", __DESCR(descr))
132
133 #define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
134 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \
135 arg, len, sysctl_handle_string, "A", __DESCR(descr))
136
137 #define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \
138 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_INT|(access), \
139 ptr, val, sysctl_handle_int, "I", __DESCR(descr))
140
141 #define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
142 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \
143 ptr, val, sysctl_handle_int, "IU", __DESCR(descr))
144
145 #define SYSCTL_ADD_XINT(ctx, parent, nbr, name, access, ptr, val, descr) \
146 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \
147 ptr, val, sysctl_handle_int, "IX", __DESCR(descr))
148
149 #define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \
150 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_LONG|(access), \
151 ptr, 0, sysctl_handle_long, "L", __DESCR(descr))
152
153 #define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \
154 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \
155 ptr, 0, sysctl_handle_long, "LU", __DESCR(descr))
156
157 #define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \
158 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_QUAD|(access), \
159 ptr, 0, sysctl_handle_quad, "Q", __DESCR(descr))
160
161 #define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr) \
162 sysctl_add_oid(ctx, parent, nbr, name, \
163 CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
164 ptr, 0, sysctl_handle_64, "QU", __DESCR(descr))
165
166 #define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr) \
167 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \
168 ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr))
169
170 #define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
171 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \
172 ptr, sizeof(struct type), sysctl_handle_opaque, "S," #type, __DESCR(descr))
173
174 #define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
175 sysctl_add_oid(ctx, parent, nbr, name, (access), ptr, arg, handler, fmt, \
176 __DESCR(descr))
177
178
179 static inline void *
SYSCTL_CHILDREN(void * ptr)180 SYSCTL_CHILDREN(void *ptr)
181 {
182 return NULL;
183 }
184
185
186 #define SYSCTL_STATIC_CHILDREN(...) NULL
187
188 #define SYSCTL_DECL(name) \
189 extern struct sysctl_oid_list sysctl_##name##_children
190
191 #define SYSCTL_NODE(...)
192 #define SYSCTL_INT(...)
193 #define SYSCTL_UINT(...)
194 #define SYSCTL_BOOL(...)
195 #define SYSCTL_PROC(...)
196
197 #endif
198
199 #endif
200