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