xref: /minix3/tests/modules/k_helper2/k_helper2.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
2*11be35a1SLionel Sambuc /*
3*11be35a1SLionel Sambuc  * Copyright (c) 2010 The NetBSD Foundation, Inc.
4*11be35a1SLionel Sambuc  * All rights reserved.
5*11be35a1SLionel Sambuc  *
6*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
8*11be35a1SLionel Sambuc  * are met:
9*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
10*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
11*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
13*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
14*11be35a1SLionel Sambuc  *
15*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16*11be35a1SLionel Sambuc  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17*11be35a1SLionel Sambuc  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18*11be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*11be35a1SLionel Sambuc  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20*11be35a1SLionel Sambuc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22*11be35a1SLionel Sambuc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*11be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24*11be35a1SLionel Sambuc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25*11be35a1SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26*11be35a1SLionel Sambuc  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*11be35a1SLionel Sambuc  */
28*11be35a1SLionel Sambuc 
29*11be35a1SLionel Sambuc #include <sys/cdefs.h>
30*11be35a1SLionel Sambuc __KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $");
31*11be35a1SLionel Sambuc 
32*11be35a1SLionel Sambuc #include <sys/param.h>
33*11be35a1SLionel Sambuc #include <sys/kernel.h>
34*11be35a1SLionel Sambuc #include <sys/module.h>
35*11be35a1SLionel Sambuc #include <sys/sysctl.h>
36*11be35a1SLionel Sambuc 
37*11be35a1SLionel Sambuc #include <prop/proplib.h>
38*11be35a1SLionel Sambuc 
39*11be35a1SLionel Sambuc MODULE(MODULE_CLASS_MISC, k_helper2, NULL);
40*11be35a1SLionel Sambuc 
41*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
42*11be35a1SLionel Sambuc /* Sysctl interface to query information about the module.               */
43*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
44*11be35a1SLionel Sambuc 
45*11be35a1SLionel Sambuc /* TODO: Change the integer variables below that represent booleans to
46*11be35a1SLionel Sambuc  * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */
47*11be35a1SLionel Sambuc 
48*11be35a1SLionel Sambuc static struct sysctllog *clogp;
49*11be35a1SLionel Sambuc static int present = 1;
50*11be35a1SLionel Sambuc 
51*11be35a1SLionel Sambuc #define K_HELPER2 0x23456781
52*11be35a1SLionel Sambuc #define K_HELPER_PRESENT 0
53*11be35a1SLionel Sambuc 
54*11be35a1SLionel Sambuc SYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup")
55*11be35a1SLionel Sambuc {
56*11be35a1SLionel Sambuc 
57*11be35a1SLionel Sambuc 	sysctl_createv(clog, 0, NULL, NULL,
58*11be35a1SLionel Sambuc 	               CTLFLAG_PERMANENT,
59*11be35a1SLionel Sambuc 	               CTLTYPE_NODE, "k_helper2", NULL,
60*11be35a1SLionel Sambuc 	               NULL, 0, NULL, 0,
61*11be35a1SLionel Sambuc 	               CTL_VENDOR, K_HELPER2, CTL_EOL);
62*11be35a1SLionel Sambuc 
63*11be35a1SLionel Sambuc 	sysctl_createv(clog, 0, NULL, NULL,
64*11be35a1SLionel Sambuc 	               CTLFLAG_PERMANENT,
65*11be35a1SLionel Sambuc 	               CTLTYPE_INT, "present",
66*11be35a1SLionel Sambuc 		       SYSCTL_DESCR("Whether the module was loaded or not"),
67*11be35a1SLionel Sambuc 		       NULL, 0, &present, 0,
68*11be35a1SLionel Sambuc 	               CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL);
69*11be35a1SLionel Sambuc }
70*11be35a1SLionel Sambuc 
71*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
72*11be35a1SLionel Sambuc /* Module management.                                                    */
73*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
74*11be35a1SLionel Sambuc 
75*11be35a1SLionel Sambuc static
76*11be35a1SLionel Sambuc int
k_helper2_init(prop_dictionary_t props)77*11be35a1SLionel Sambuc k_helper2_init(prop_dictionary_t props)
78*11be35a1SLionel Sambuc {
79*11be35a1SLionel Sambuc 	sysctl_k_helper2_setup(&clogp);
80*11be35a1SLionel Sambuc 
81*11be35a1SLionel Sambuc 	return 0;
82*11be35a1SLionel Sambuc }
83*11be35a1SLionel Sambuc 
84*11be35a1SLionel Sambuc static
85*11be35a1SLionel Sambuc int
k_helper2_fini(void * arg)86*11be35a1SLionel Sambuc k_helper2_fini(void *arg)
87*11be35a1SLionel Sambuc {
88*11be35a1SLionel Sambuc 
89*11be35a1SLionel Sambuc 	sysctl_teardown(&clogp);
90*11be35a1SLionel Sambuc 
91*11be35a1SLionel Sambuc 	return 0;
92*11be35a1SLionel Sambuc }
93*11be35a1SLionel Sambuc 
94*11be35a1SLionel Sambuc static
95*11be35a1SLionel Sambuc int
k_helper2_modcmd(modcmd_t cmd,void * arg)96*11be35a1SLionel Sambuc k_helper2_modcmd(modcmd_t cmd, void *arg)
97*11be35a1SLionel Sambuc {
98*11be35a1SLionel Sambuc 	int ret;
99*11be35a1SLionel Sambuc 
100*11be35a1SLionel Sambuc 	switch (cmd) {
101*11be35a1SLionel Sambuc 	case MODULE_CMD_INIT:
102*11be35a1SLionel Sambuc 		ret = k_helper2_init(arg);
103*11be35a1SLionel Sambuc 		break;
104*11be35a1SLionel Sambuc 
105*11be35a1SLionel Sambuc 	case MODULE_CMD_FINI:
106*11be35a1SLionel Sambuc 		ret = k_helper2_fini(arg);
107*11be35a1SLionel Sambuc 		break;
108*11be35a1SLionel Sambuc 
109*11be35a1SLionel Sambuc 	case MODULE_CMD_STAT:
110*11be35a1SLionel Sambuc 	default:
111*11be35a1SLionel Sambuc 		ret = ENOTTY;
112*11be35a1SLionel Sambuc 	}
113*11be35a1SLionel Sambuc 
114*11be35a1SLionel Sambuc 	return ret;
115*11be35a1SLionel Sambuc }
116