1 /* $NetBSD: k_helper.c,v 1.1 2008/02/10 12:40:10 jmmv Exp $ */ 2 /* 3 * Copyright (c) 2008 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 * 3. All advertising materials mentioning features or use of this 15 * software must display the following acknowledgement: 16 * This product includes software developed by the NetBSD 17 * Foundation, Inc. and its contributors. 18 * 4. Neither the name of The NetBSD Foundation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 29 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 31 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: k_helper.c,v 1.1 2008/02/10 12:40:10 jmmv Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/kernel.h> 41 #include <sys/module.h> 42 #include <sys/sysctl.h> 43 44 MODULE(MODULE_CLASS_MISC, k_helper, NULL); 45 46 /* --------------------------------------------------------------------- */ 47 /* Sysctl interface to query information about the module. */ 48 /* --------------------------------------------------------------------- */ 49 50 static struct sysctllog *clog; 51 static int present = 1; 52 53 #define K_HELPER 0x12345678 54 #define K_HELPER_PRESENT 0 55 56 SYSCTL_SETUP(sysctl_k_helper_setup, "sysctl k_helper subtree setup") 57 { 58 59 sysctl_createv(clog, 0, NULL, NULL, 60 CTLFLAG_PERMANENT, 61 CTLTYPE_NODE, "k_helper", NULL, 62 NULL, 0, NULL, 0, 63 CTL_VENDOR, K_HELPER, CTL_EOL); 64 65 sysctl_createv(clog, 0, NULL, NULL, 66 CTLFLAG_PERMANENT, 67 CTLTYPE_INT, "present", 68 SYSCTL_DESCR("Whether the module was loaded or not"), 69 NULL, 0, &present, 0, 70 CTL_VENDOR, K_HELPER, K_HELPER_PRESENT, CTL_EOL); 71 } 72 73 /* --------------------------------------------------------------------- */ 74 /* Module management. */ 75 /* --------------------------------------------------------------------- */ 76 77 static 78 int 79 k_helper_init(void *arg) 80 { 81 82 sysctl_k_helper_setup(&clog); 83 84 return 0; 85 } 86 87 static 88 int 89 k_helper_fini(void *arg) 90 { 91 92 sysctl_teardown(&clog); 93 94 return 0; 95 } 96 97 static 98 int 99 k_helper_modcmd(modcmd_t cmd, void *arg) 100 { 101 int ret; 102 103 switch (cmd) { 104 case MODULE_CMD_INIT: 105 ret = k_helper_init(arg); 106 break; 107 108 case MODULE_CMD_FINI: 109 ret = k_helper_fini(arg); 110 break; 111 112 case MODULE_CMD_STAT: 113 default: 114 ret = ENOTTY; 115 } 116 117 return ret; 118 } 119