2 * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
3 * Copyright (c) 2001-2004 Mark R. V. Murray
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer
11 * in this position and unchanged.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
43 #include <machine/bus.h>
44 #include <machine/vmparam.h>
46 /* For use with destroy_dev(9). */
47 static struct cdev *null_dev;
48 static struct cdev *zero_dev;
50 static d_write_t null_write;
51 static d_ioctl_t null_ioctl;
52 static d_read_t zero_read;
54 static struct cdevsw null_cdevsw = {
55 .d_version = D_VERSION,
56 .d_read = (d_read_t *)nullop,
57 .d_write = null_write,
58 .d_ioctl = null_ioctl,
62 static struct cdevsw zero_cdevsw = {
63 .d_version = D_VERSION,
65 .d_write = null_write,
67 .d_flags = D_MMAP_ANON,
72 null_write(struct cdev *dev __unused, struct uio *uio, int flags __unused)
81 null_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unused,
82 int flags __unused, struct thread *td)
86 if (cmd != DIOCSKERNELDUMP)
88 error = priv_check(td, PRIV_SETDUMPER);
91 return (set_dumper(NULL));
96 zero_read(struct cdev *dev __unused, struct uio *uio, int flags __unused)
102 KASSERT(uio->uio_rw == UIO_READ,
103 ("Can't be in %s for write", __func__));
104 zbuf = __DECONST(void *, zero_region);
105 while (uio->uio_resid > 0 && error == 0) {
106 len = uio->uio_resid;
107 if (len > ZERO_REGION_SIZE)
108 len = ZERO_REGION_SIZE;
109 error = uiomove(zbuf, len, uio);
117 null_modevent(module_t mod __unused, int type, void *data __unused)
122 printf("null: <null device, zero device>\n");
123 null_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &null_cdevsw, 0,
124 NULL, UID_ROOT, GID_WHEEL, 0666, "null");
125 zero_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &zero_cdevsw, 0,
126 NULL, UID_ROOT, GID_WHEEL, 0666, "zero");
130 destroy_dev(null_dev);
131 destroy_dev(zero_dev);
144 DEV_MODULE(null, null_modevent, NULL);
145 MODULE_VERSION(null, 1);