Thu Jan 30 07:58:34 2020 UTC ()
Align major numbers in example modules with sys/conf/majors

Patch submitted by: Aditya Vardhan Padala (silv3r)


(kamil)
diff -r1.1 -r1.2 src/sys/modules/examples/luareadhappy/luareadhappy.c
diff -r1.1 -r1.2 src/sys/modules/examples/mapper/mapper.c
diff -r1.1 -r1.2 src/sys/modules/examples/panic_string/panic_string.c
diff -r1.1 -r1.2 src/sys/modules/examples/ping/ping.c
diff -r1.1 -r1.2 src/sys/modules/examples/readhappy_mpsafe/readhappy_mpsafe.c

cvs diff -r1.1 -r1.2 src/sys/modules/examples/luareadhappy/luareadhappy.c (expand / switch to unified diff)

--- src/sys/modules/examples/luareadhappy/luareadhappy.c 2017/04/15 04:27:30 1.1
+++ src/sys/modules/examples/luareadhappy/luareadhappy.c 2020/01/30 07:58:33 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: luareadhappy.c,v 1.1 2017/04/15 04:27:30 kamil Exp $ */ 1/* $NetBSD: luareadhappy.c,v 1.2 2020/01/30 07:58:33 kamil Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2015 The NetBSD Foundation, Inc. 4 * Copyright (c) 2015 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,42 +17,42 @@ @@ -17,42 +17,42 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: luareadhappy.c,v 1.1 2017/04/15 04:27:30 kamil Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: luareadhappy.c,v 1.2 2020/01/30 07:58:33 kamil Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/conf.h> 33#include <sys/conf.h>
34#include <sys/device.h> 34#include <sys/device.h>
35#include <sys/kernel.h> 35#include <sys/kernel.h>
36#include <sys/lua.h> 36#include <sys/lua.h>
37#include <sys/module.h> 37#include <sys/module.h>
38#include <lua.h> 38#include <lua.h>
39 39
40/* 40/*
41 * Create a device /dev/happy from which you can read sequential 41 * Create a device /dev/happy from which you can read sequential
42 * happy numbers. 42 * happy numbers.
43 * 43 *
44 * To use this device you need to do: 44 * To use this device you need to do:
45 * mknod /dev/happy c 210 0 45 * mknod /dev/happy c 351 0
46 * 46 *
47 * Commentary: 47 * Commentary:
48 * A happy number is a number defined by the following process: Starting with 48 * A happy number is a number defined by the following process: Starting with
49 * any positive integer, replace the number by the sum of the squares of its 49 * any positive integer, replace the number by the sum of the squares of its
50 * digits, and repeat the process until the number equals 1 (where it will 50 * digits, and repeat the process until the number equals 1 (where it will
51 * stay), or it loops endlessly in a cycle which does not include 1. Those 51 * stay), or it loops endlessly in a cycle which does not include 1. Those
52 * numbers for which this process ends in 1 are happy numbers, while those that 52 * numbers for which this process ends in 1 are happy numbers, while those that
53 * do not end in 1 are unhappy numbers (or sad numbers). 53 * do not end in 1 are unhappy numbers (or sad numbers).
54 * 54 *
55 * For more information on happy numbers, and the algorithms, see 55 * For more information on happy numbers, and the algorithms, see
56 * http://en.wikipedia.org/wiki/Happy_number  56 * http://en.wikipedia.org/wiki/Happy_number
57 * 57 *
58 * The happy number generator is here only to have something that the user 58 * The happy number generator is here only to have something that the user
@@ -179,27 +179,27 @@ happy_read(dev_t self __unused, struct u @@ -179,27 +179,27 @@ happy_read(dev_t self __unused, struct u
179 if ((e = uiomove(line, len, uio))) 179 if ((e = uiomove(line, len, uio)))
180 return e; 180 return e;
181 181
182 return 0; 182 return 0;
183} 183}
184 184
185MODULE(MODULE_CLASS_MISC, happy, "lua"); 185MODULE(MODULE_CLASS_MISC, happy, "lua");
186 186
187static int 187static int
188happy_modcmd(modcmd_t cmd, void *arg __unused) 188happy_modcmd(modcmd_t cmd, void *arg __unused)
189{ 189{
190 /* The major should be verified and changed if needed to avoid 190 /* The major should be verified and changed if needed to avoid
191 * conflicts with other devices. */ 191 * conflicts with other devices. */
192 int cmajor = 210, bmajor = -1; 192 int cmajor = 351, bmajor = -1;
193 193
194 switch (cmd) { 194 switch (cmd) {
195 case MODULE_CMD_INIT: 195 case MODULE_CMD_INIT:
196 if (devsw_attach("happy", NULL, &bmajor, &happy_cdevsw, 196 if (devsw_attach("happy", NULL, &bmajor, &happy_cdevsw,
197 &cmajor)) 197 &cmajor))
198 return ENXIO; 198 return ENXIO;
199 if ((sc.kL = kluaL_newstate("happy", 199 if ((sc.kL = kluaL_newstate("happy",
200 "Example Happy Number calculator", 200 "Example Happy Number calculator",
201 IPL_NONE)) == NULL) { 201 IPL_NONE)) == NULL) {
202 devsw_detach(NULL, &happy_cdevsw); 202 devsw_detach(NULL, &happy_cdevsw);
203 return ENXIO; 203 return ENXIO;
204 } 204 }
205 return 0; 205 return 0;

cvs diff -r1.1 -r1.2 src/sys/modules/examples/mapper/mapper.c (expand / switch to unified diff)

--- src/sys/modules/examples/mapper/mapper.c 2019/01/17 20:47:42 1.1
+++ src/sys/modules/examples/mapper/mapper.c 2020/01/30 07:58:33 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mapper.c,v 1.1 2019/01/17 20:47:42 kamil Exp $ */ 1/* $NetBSD: mapper.c,v 1.2 2020/01/30 07:58:33 kamil Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2019 The NetBSD Foundation, Inc. 4 * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,42 +17,42 @@ @@ -17,42 +17,42 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: mapper.c,v 1.1 2019/01/17 20:47:42 kamil Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: mapper.c,v 1.2 2020/01/30 07:58:33 kamil Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/conf.h> 33#include <sys/conf.h>
34#include <sys/device.h> 34#include <sys/device.h>
35#include <sys/kernel.h> 35#include <sys/kernel.h>
36#include <sys/kmem.h> 36#include <sys/kmem.h>
37#include <sys/module.h> 37#include <sys/module.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39 39
40#include <uvm/uvm.h> 40#include <uvm/uvm.h>
41 41
42/* 42/*
43 * Creating a device /dev/mapper for demonstration. 43 * Creating a device /dev/mapper for demonstration.
44 * To use this device you need to do: 44 * To use this device you need to do:
45 * mknod /dev/mapper c 210 0 45 * mknod /dev/mapper c 351 0
46 * 46 *
47 */ 47 */
48 48
49dev_type_open(mapper_open); 49dev_type_open(mapper_open);
50dev_type_close(mapper_close); 50dev_type_close(mapper_close);
51dev_type_mmap(mapper_mmap); 51dev_type_mmap(mapper_mmap);
52 52
53static struct cdevsw mapper_cdevsw = { 53static struct cdevsw mapper_cdevsw = {
54 .d_open = mapper_open, 54 .d_open = mapper_open,
55 .d_close = mapper_close, 55 .d_close = mapper_close,
56 .d_read = noread, 56 .d_read = noread,
57 .d_write = nowrite, 57 .d_write = nowrite,
58 .d_ioctl = noioctl, 58 .d_ioctl = noioctl,
@@ -111,27 +111,27 @@ mapper_mmap(dev_t dev, off_t off, int pr @@ -111,27 +111,27 @@ mapper_mmap(dev_t dev, off_t off, int pr
111 if (pmap_extract(pmap_kernel(), (vaddr_t)sc.buffer, &pa)) 111 if (pmap_extract(pmap_kernel(), (vaddr_t)sc.buffer, &pa))
112 return (paddr_t)atop(pa); 112 return (paddr_t)atop(pa);
113 113
114 return (paddr_t)-1; 114 return (paddr_t)-1;
115} 115}
116 116
117MODULE(MODULE_CLASS_MISC, mapper, NULL); 117MODULE(MODULE_CLASS_MISC, mapper, NULL);
118 118
119static int 119static int
120mapper_modcmd(modcmd_t cmd, void *arg __unused) 120mapper_modcmd(modcmd_t cmd, void *arg __unused)
121{ 121{
122 /* The major should be verified and changed if needed to avoid 122 /* The major should be verified and changed if needed to avoid
123 * conflicts with other devices. */ 123 * conflicts with other devices. */
124 int cmajor = 210, bmajor = -1; 124 int cmajor = 351, bmajor = -1;
125 125
126 switch (cmd) { 126 switch (cmd) {
127 case MODULE_CMD_INIT: 127 case MODULE_CMD_INIT:
128 if (devsw_attach("mapper", NULL, &bmajor, &mapper_cdevsw, 128 if (devsw_attach("mapper", NULL, &bmajor, &mapper_cdevsw,
129 &cmajor)) 129 &cmajor))
130 return ENXIO; 130 return ENXIO;
131 return 0; 131 return 0;
132 case MODULE_CMD_FINI: 132 case MODULE_CMD_FINI:
133 if (sc.refcnt > 0) 133 if (sc.refcnt > 0)
134 return EBUSY; 134 return EBUSY;
135 devsw_detach(NULL, &mapper_cdevsw); 135 devsw_detach(NULL, &mapper_cdevsw);
136 return 0; 136 return 0;
137 default: 137 default:

cvs diff -r1.1 -r1.2 src/sys/modules/examples/panic_string/panic_string.c (expand / switch to unified diff)

--- src/sys/modules/examples/panic_string/panic_string.c 2018/05/29 16:53:56 1.1
+++ src/sys/modules/examples/panic_string/panic_string.c 2020/01/30 07:58:33 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: panic_string.c,v 1.1 2018/05/29 16:53:56 kamil Exp $ */ 1/* $NetBSD: panic_string.c,v 1.2 2020/01/30 07:58:33 kamil Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,45 +18,45 @@ @@ -18,45 +18,45 @@
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: panic_string.c,v 1.1 2018/05/29 16:53:56 kamil Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: panic_string.c,v 1.2 2020/01/30 07:58:33 kamil Exp $");
32 32
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/conf.h> 35#include <sys/conf.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/filedesc.h> 37#include <sys/filedesc.h>
38#include <sys/kernel.h> 38#include <sys/kernel.h>
39#include <sys/kmem.h> 39#include <sys/kmem.h>
40#include <sys/lwp.h> 40#include <sys/lwp.h>
41#include <sys/module.h> 41#include <sys/module.h>
42#include <sys/vfs_syscalls.h> 42#include <sys/vfs_syscalls.h>
43 43
44/* 44/*
45 * Create a device /dev/panic from which you can read sequential 45 * Create a device /dev/panic from which you can read sequential
46 * user input. 46 * user input.
47 * 47 *
48 * To use this device you need to do: 48 * To use this device you need to do:
49 * mknod /dev/panic c 210 0 49 * mknod /dev/panic c 351 0
50 * 50 *
51 * To write to the device you might need: 51 * To write to the device you might need:
52 * chmod 666 /dev/panic 52 * chmod 666 /dev/panic
53 * 53 *
54 * Commentary: 54 * Commentary:
55 * This module manages the device /dev/panic, 55 * This module manages the device /dev/panic,
56 * tranfers a string from userspace to kernel space 56 * tranfers a string from userspace to kernel space
57 * and calls kernel panic with the passed string. 57 * and calls kernel panic with the passed string.
58 * 58 *
59 * echo 'string' > /dev/panic 59 * echo 'string' > /dev/panic
60 * will do the trick after loading the module. 60 * will do the trick after loading the module.
61 */ 61 */
62 62
@@ -163,27 +163,27 @@ panic_string_write(dev_t self, struct ui @@ -163,27 +163,27 @@ panic_string_write(dev_t self, struct ui
163 } 163 }
164 164
165 kmem_free(buffer, len); 165 kmem_free(buffer, len);
166 return 0; 166 return 0;
167} 167}
168 168
169MODULE(MODULE_CLASS_MISC, panic_string, NULL); 169MODULE(MODULE_CLASS_MISC, panic_string, NULL);
170 170
171static int 171static int
172panic_string_modcmd(modcmd_t cmd, void *arg __unused) 172panic_string_modcmd(modcmd_t cmd, void *arg __unused)
173{ 173{
174 /* The major should be verified and changed if needed to avoid 174 /* The major should be verified and changed if needed to avoid
175 * conflicts with other devices. */ 175 * conflicts with other devices. */
176 int cmajor = 210, bmajor = -1; 176 int cmajor = 351, bmajor = -1;
177 177
178 switch (cmd) { 178 switch (cmd) {
179 case MODULE_CMD_INIT: 179 case MODULE_CMD_INIT:
180 printf("Panic String module loaded.\n"); 180 printf("Panic String module loaded.\n");
181 if (devsw_attach("panic", NULL, &bmajor, &panic_string_cdevsw, 181 if (devsw_attach("panic", NULL, &bmajor, &panic_string_cdevsw,
182 &cmajor)) 182 &cmajor))
183 return ENXIO; 183 return ENXIO;
184 return 0; 184 return 0;
185 185
186 case MODULE_CMD_FINI: 186 case MODULE_CMD_FINI:
187 printf("Panic String module unloaded.\n"); 187 printf("Panic String module unloaded.\n");
188 if (sc.refcnt > 0) 188 if (sc.refcnt > 0)
189 return EBUSY; 189 return EBUSY;

cvs diff -r1.1 -r1.2 src/sys/modules/examples/ping/ping.c (expand / switch to unified diff)

--- src/sys/modules/examples/ping/ping.c 2015/05/13 07:07:36 1.1
+++ src/sys/modules/examples/ping/ping.c 2020/01/30 07:58:33 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ping.c,v 1.1 2015/05/13 07:07:36 pgoyette Exp $ */ 1/* $NetBSD: ping.c,v 1.2 2020/01/30 07:58:33 kamil Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2015 The NetBSD Foundation, Inc. 4 * Copyright (c) 2015 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,41 +17,41 @@ @@ -17,41 +17,41 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: ping.c,v 1.1 2015/05/13 07:07:36 pgoyette Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: ping.c,v 1.2 2020/01/30 07:58:33 kamil Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/conf.h> 33#include <sys/conf.h>
34#include <sys/device.h> 34#include <sys/device.h>
35#include <sys/kernel.h> 35#include <sys/kernel.h>
36#include <sys/module.h> 36#include <sys/module.h>
37 37
38#include "ping.h" 38#include "ping.h"
39 39
40/* 40/*
41 * Create a device /dev/ping in order to test this module. 41 * Create a device /dev/ping in order to test this module.
42 * 42 *
43 * To use this device you need to do: 43 * To use this device you need to do:
44 * mknod /dev/ping c 210 0 44 * mknod /dev/ping c 351 0
45 * 45 *
46 */ 46 */
47 47
48dev_type_open(ping_open); 48dev_type_open(ping_open);
49dev_type_close(ping_close); 49dev_type_close(ping_close);
50dev_type_ioctl(ping_ioctl); 50dev_type_ioctl(ping_ioctl);
51 51
52static struct cdevsw ping_cdevsw = { 52static struct cdevsw ping_cdevsw = {
53 .d_open = ping_open, 53 .d_open = ping_open,
54 .d_close = ping_close, 54 .d_close = ping_close,
55 .d_read = noread, 55 .d_read = noread,
56 .d_write = nowrite, 56 .d_write = nowrite,
57 .d_ioctl = ping_ioctl, 57 .d_ioctl = ping_ioctl,
@@ -102,27 +102,27 @@ ping_ioctl(dev_t self __unused, u_long c @@ -102,27 +102,27 @@ ping_ioctl(dev_t self __unused, u_long c
102 return 0; 102 return 0;
103 default: 103 default:
104 return 1; 104 return 1;
105 } 105 }
106} 106}
107 107
108MODULE(MODULE_CLASS_MISC, ping, NULL); 108MODULE(MODULE_CLASS_MISC, ping, NULL);
109 109
110static int 110static int
111ping_modcmd(modcmd_t cmd, void *arg __unused) 111ping_modcmd(modcmd_t cmd, void *arg __unused)
112{ 112{
113 /* The major should be verified and changed if needed to avoid 113 /* The major should be verified and changed if needed to avoid
114 * conflicts with other devices. */ 114 * conflicts with other devices. */
115 int cmajor = 210, bmajor = -1; 115 int cmajor = 351, bmajor = -1;
116 116
117 switch (cmd) { 117 switch (cmd) {
118 case MODULE_CMD_INIT: 118 case MODULE_CMD_INIT:
119 if (devsw_attach("ping", NULL, &bmajor, &ping_cdevsw, &cmajor)) 119 if (devsw_attach("ping", NULL, &bmajor, &ping_cdevsw, &cmajor))
120 return ENXIO; 120 return ENXIO;
121 return 0; 121 return 0;
122 case MODULE_CMD_FINI: 122 case MODULE_CMD_FINI:
123 if (sc.refcnt > 0) 123 if (sc.refcnt > 0)
124 return EBUSY; 124 return EBUSY;
125 125
126 devsw_detach(NULL, &ping_cdevsw); 126 devsw_detach(NULL, &ping_cdevsw);
127 return 0; 127 return 0;
128 default: 128 default:

cvs diff -r1.1 -r1.2 src/sys/modules/examples/readhappy_mpsafe/readhappy_mpsafe.c (expand / switch to unified diff)

--- src/sys/modules/examples/readhappy_mpsafe/readhappy_mpsafe.c 2018/04/20 00:06:45 1.1
+++ src/sys/modules/examples/readhappy_mpsafe/readhappy_mpsafe.c 2020/01/30 07:58:34 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: readhappy_mpsafe.c,v 1.1 2018/04/20 00:06:45 kamil Exp $ */ 1/* $NetBSD: readhappy_mpsafe.c,v 1.2 2020/01/30 07:58:34 kamil Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,48 +17,48 @@ @@ -17,48 +17,48 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: readhappy_mpsafe.c,v 1.1 2018/04/20 00:06:45 kamil Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: readhappy_mpsafe.c,v 1.2 2020/01/30 07:58:34 kamil Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/module.h> 33#include <sys/module.h>
34#include <sys/condvar.h> 34#include <sys/condvar.h>
35#include <sys/conf.h> 35#include <sys/conf.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/mutex.h> 38#include <sys/mutex.h>
39 39
40/* 40/*
41 * This module is a modification of the readhappy module to illustrate 41 * This module is a modification of the readhappy module to illustrate
42 * how to make a device MPSAFE (Multiprocessor Safe). 42 * how to make a device MPSAFE (Multiprocessor Safe).
43 * 43 *
44 * 1. Supports opening device by multiple processes but allows only one at a time. 44 * 1. Supports opening device by multiple processes but allows only one at a time.
45 * 2. Supports multiple read() functions but allows only one at a time. 45 * 2. Supports multiple read() functions but allows only one at a time.
46 * 3. Uses mutex for ensuring synchonization. 46 * 3. Uses mutex for ensuring synchonization.
47 * 47 *
48 * Create a device /dev/happy_mpsafe from which you can read sequential happy numbers. 48 * Create a device /dev/happy_mpsafe from which you can read sequential happy numbers.
49 * 49 *
50 * To use this device you need to do: 50 * To use this device you need to do:
51 * mknod /dev/happy_mpsafe c 210 0 51 * mknod /dev/happy_mpsafe c 351 0
52 * 52 *
53 * To test whether the device is MPSAFE. Compile and run the test_readhappy file 53 * To test whether the device is MPSAFE. Compile and run the test_readhappy file
54 * provided. 54 * provided.
55 */ 55 */
56 56
57 57
58#define HAPPY_NUMBER 1 58#define HAPPY_NUMBER 1
59 59
60#define SAD_NUMBER 4 60#define SAD_NUMBER 4
61 61
62/* 62/*
63 * kmutex_t variables have been added to the structure to 63 * kmutex_t variables have been added to the structure to
64 * ensure proper synchronization while opened by multiple devices. 64 * ensure proper synchronization while opened by multiple devices.
@@ -209,27 +209,27 @@ fin: @@ -209,27 +209,27 @@ fin:
209 209
210 return error; 210 return error;
211} 211}
212 212
213MODULE(MODULE_CLASS_MISC, happy_mpsafe, NULL); 213MODULE(MODULE_CLASS_MISC, happy_mpsafe, NULL);
214 214
215/* 215/*
216 * Initializing mutex and conditional variables for read() and open(). 216 * Initializing mutex and conditional variables for read() and open().
217 * when the module is being loaded. 217 * when the module is being loaded.
218 */ 218 */
219static int 219static int
220happy_mpsafe_modcmd(modcmd_t cmd, void *arg __unused) 220happy_mpsafe_modcmd(modcmd_t cmd, void *arg __unused)
221{ 221{
222 int cmajor = 210, bmajor = -1; 222 int cmajor = 351, bmajor = -1;
223 223
224 switch (cmd) { 224 switch (cmd) {
225 case MODULE_CMD_INIT: 225 case MODULE_CMD_INIT:
226 if (devsw_attach("happy_mpsafe", NULL, &bmajor, &happy_cdevsw, 226 if (devsw_attach("happy_mpsafe", NULL, &bmajor, &happy_cdevsw,
227 &cmajor)) 227 &cmajor))
228 return ENXIO; 228 return ENXIO;
229 229
230 mutex_init(&sc.lock, MUTEX_DEFAULT, IPL_NONE); 230 mutex_init(&sc.lock, MUTEX_DEFAULT, IPL_NONE);
231 mutex_init(&sc.read_lock, MUTEX_DEFAULT, IPL_NONE); 231 mutex_init(&sc.read_lock, MUTEX_DEFAULT, IPL_NONE);
232 cv_init(&sc.cv, "example conditional variable"); 232 cv_init(&sc.cv, "example conditional variable");
233 return 0; 233 return 0;
234 case MODULE_CMD_FINI: 234 case MODULE_CMD_FINI:
235 mutex_destroy(&sc.lock); 235 mutex_destroy(&sc.lock);