Deleted Added
full compact
null.c (111758) null.c (111815)
1/*-
2 * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/null/null.c 111758 2003-03-02 19:17:51Z phk $
26 * $FreeBSD: head/sys/dev/null/null.c 111815 2003-03-03 12:15:54Z phk $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/conf.h>
32#include <sys/uio.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/module.h>
36#include <sys/disk.h>
37#include <sys/bus.h>
38#include <machine/bus.h>
39
40/* For use with destroy_dev(9). */
41static dev_t null_dev;
42static dev_t zero_dev;
43
44static d_write_t null_write;
45static d_ioctl_t null_ioctl;
46static d_read_t zero_read;
47static d_read_t null_read;
48
49#define CDEV_MAJOR 2
50#define NULL_MINOR 2
51#define ZERO_MINOR 12
52
53static struct cdevsw null_cdevsw = {
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/conf.h>
32#include <sys/uio.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/module.h>
36#include <sys/disk.h>
37#include <sys/bus.h>
38#include <machine/bus.h>
39
40/* For use with destroy_dev(9). */
41static dev_t null_dev;
42static dev_t zero_dev;
43
44static d_write_t null_write;
45static d_ioctl_t null_ioctl;
46static d_read_t zero_read;
47static d_read_t null_read;
48
49#define CDEV_MAJOR 2
50#define NULL_MINOR 2
51#define ZERO_MINOR 12
52
53static struct cdevsw null_cdevsw = {
54 /* open */ nullopen,
55 /* close */ nullclose,
56 /* read */ null_read,
57 /* write */ null_write,
58 /* ioctl */ null_ioctl,
59 /* poll */ nopoll,
60 /* mmap */ nommap,
61 /* strategy */ nostrategy,
62 /* name */ "null",
63 /* maj */ CDEV_MAJOR,
64 /* dump */ nodump,
65 /* psize */ nopsize,
66 /* flags */ 0,
67 /* kqfilter */ NULL
54 .d_open = nullopen,
55 .d_close = nullclose,
56 .d_read = null_read,
57 .d_write = null_write,
58 .d_ioctl = null_ioctl,
59 .d_name = "null",
60 .d_maj = CDEV_MAJOR,
68};
69
70static struct cdevsw zero_cdevsw = {
61};
62
63static struct cdevsw zero_cdevsw = {
71 /* open */ nullopen,
72 /* close */ nullclose,
73 /* read */ zero_read,
74 /* write */ null_write,
75 /* ioctl */ noioctl,
76 /* poll */ nopoll,
77 /* mmap */ nommap,
78 /* strategy */ nostrategy,
79 /* name */ "zero",
80 /* maj */ CDEV_MAJOR,
81 /* dump */ nodump,
82 /* psize */ nopsize,
83 /* flags */ D_MMAP_ANON,
84 /* kqfilter */ NULL
64 .d_open = nullopen,
65 .d_close = nullclose,
66 .d_read = zero_read,
67 .d_write = null_write,
68 .d_name = "zero",
69 .d_maj = CDEV_MAJOR,
70 .d_flags = D_MMAP_ANON,
85};
86
87static void *zbuf;
88
89static int
90null_read(dev_t dev __unused, struct uio *uio, int flags __unused)
91{
92
93 return 0;
94}
95
96/* ARGSUSED */
97static int
98null_write(dev_t dev __unused, struct uio *uio, int flags __unused)
99{
100 uio->uio_resid = 0;
101 return 0;
102}
103
104static int
105null_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td)
106{
107 int error;
108
109 if (cmd != DIOCSKERNELDUMP)
110 return (noioctl(dev, cmd, data, flags, td));
111 error = suser(td);
112 if (error)
113 return (error);
114 return (set_dumper(NULL));
115}
116
117/* ARGSUSED */
118static int
119zero_read(dev_t dev __unused, struct uio *uio, int flags __unused)
120{
121 int c;
122 int error = 0;
123
124 while (uio->uio_resid > 0 && error == 0) {
125 c = uio->uio_resid < PAGE_SIZE ? uio->uio_resid : PAGE_SIZE;
126 error = uiomove(zbuf, c, uio);
127 }
128 return error;
129}
130
131/* ARGSUSED */
132static int
133null_modevent(module_t mod __unused, int type, void *data __unused)
134{
135 switch(type) {
136 case MOD_LOAD:
137 if (bootverbose)
138 printf("null: <null device, zero device>\n");
139 zbuf = (void *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK | M_ZERO);
140 zero_dev = make_dev(&zero_cdevsw, ZERO_MINOR, UID_ROOT,
141 GID_WHEEL, 0666, "zero");
142 null_dev = make_dev(&null_cdevsw, NULL_MINOR, UID_ROOT,
143 GID_WHEEL, 0666, "null");
144 return 0;
145
146 case MOD_UNLOAD:
147 destroy_dev(null_dev);
148 destroy_dev(zero_dev);
149 free(zbuf, M_TEMP);
150 return 0;
151
152 case MOD_SHUTDOWN:
153 return 0;
154
155 default:
156 return EOPNOTSUPP;
157 }
158}
159
160DEV_MODULE(null, null_modevent, NULL);
71};
72
73static void *zbuf;
74
75static int
76null_read(dev_t dev __unused, struct uio *uio, int flags __unused)
77{
78
79 return 0;
80}
81
82/* ARGSUSED */
83static int
84null_write(dev_t dev __unused, struct uio *uio, int flags __unused)
85{
86 uio->uio_resid = 0;
87 return 0;
88}
89
90static int
91null_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td)
92{
93 int error;
94
95 if (cmd != DIOCSKERNELDUMP)
96 return (noioctl(dev, cmd, data, flags, td));
97 error = suser(td);
98 if (error)
99 return (error);
100 return (set_dumper(NULL));
101}
102
103/* ARGSUSED */
104static int
105zero_read(dev_t dev __unused, struct uio *uio, int flags __unused)
106{
107 int c;
108 int error = 0;
109
110 while (uio->uio_resid > 0 && error == 0) {
111 c = uio->uio_resid < PAGE_SIZE ? uio->uio_resid : PAGE_SIZE;
112 error = uiomove(zbuf, c, uio);
113 }
114 return error;
115}
116
117/* ARGSUSED */
118static int
119null_modevent(module_t mod __unused, int type, void *data __unused)
120{
121 switch(type) {
122 case MOD_LOAD:
123 if (bootverbose)
124 printf("null: <null device, zero device>\n");
125 zbuf = (void *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK | M_ZERO);
126 zero_dev = make_dev(&zero_cdevsw, ZERO_MINOR, UID_ROOT,
127 GID_WHEEL, 0666, "zero");
128 null_dev = make_dev(&null_cdevsw, NULL_MINOR, UID_ROOT,
129 GID_WHEEL, 0666, "null");
130 return 0;
131
132 case MOD_UNLOAD:
133 destroy_dev(null_dev);
134 destroy_dev(zero_dev);
135 free(zbuf, M_TEMP);
136 return 0;
137
138 case MOD_SHUTDOWN:
139 return 0;
140
141 default:
142 return EOPNOTSUPP;
143 }
144}
145
146DEV_MODULE(null, null_modevent, NULL);