2 * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include <sys/param.h>
30 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
38 #include <machine/bus.h>
39 #include <machine/resource.h>
42 /* For use with destroy_dev(9). */
43 static dev_t null_dev;
44 static dev_t zero_dev;
46 static d_write_t null_write;
47 static d_ioctl_t null_ioctl;
48 static d_read_t zero_read;
54 static struct cdevsw null_cdevsw = {
55 /* open */ (d_open_t *)nullop,
56 /* close */ (d_close_t *)nullop,
57 /* read */ (d_read_t *)nullop,
58 /* write */ null_write,
59 /* ioctl */ null_ioctl,
62 /* strategy */ nostrategy,
70 static struct cdevsw zero_cdevsw = {
71 /* open */ (d_open_t *)nullop,
72 /* close */ (d_close_t *)nullop,
74 /* write */ null_write,
78 /* strategy */ nostrategy,
83 /* flags */ D_MMAP_ANON,
89 null_write(dev_t dev, struct uio *uio, int flag)
96 null_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
100 if (cmd != DIOCSKERNELDUMP)
101 return (noioctl(dev, cmd, data, fflag, td));
105 return (set_dumper(NULL));
110 zero_read(dev_t dev, struct uio *uio, int flag)
115 while (uio->uio_resid > 0 && error == 0) {
116 c = min(uio->uio_resid, PAGE_SIZE);
117 error = uiomove(zbuf, c, uio);
123 null_modevent(module_t mod, int type, void *data)
128 printf("null: <null device, zero device>\n");
129 zbuf = (void *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK | M_ZERO);
130 zero_dev = make_dev(&zero_cdevsw, ZERO_MINOR, UID_ROOT,
131 GID_WHEEL, 0666, "zero");
132 null_dev = make_dev(&null_cdevsw, NULL_MINOR, UID_ROOT,
133 GID_WHEEL, 0666, "null");
137 destroy_dev(null_dev);
138 destroy_dev(zero_dev);
150 DEV_MODULE(null, null_modevent, NULL);