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