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