From 219138f3906a91a433d1506955c14d6e1ccdeb16 Mon Sep 17 00:00:00 2001 From: eadler Date: Wed, 30 Apr 2014 06:20:48 +0000 Subject: Add a /dev/full device. /dev/full is similar to /dev/zero except it always returns ENOSPC when you attempt to write to it. Reviewed by: jhibbits Discussed with: rpaulo --- share/man/man4/full.4 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ share/man/man4/null.4 | 1 + share/man/man4/zero.4 | 1 + sys/dev/null/null.c | 25 ++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 share/man/man4/full.4 diff --git a/share/man/man4/full.4 b/share/man/man4/full.4 new file mode 100644 index 0000000..ba7bba0 --- /dev/null +++ b/share/man/man4/full.4 @@ -0,0 +1,47 @@ +.\" Copyright (c) 2014 +.\" Eitan Adler . All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 29, 2014 +.Dt FULL 4 +.Os +.Sh NAME +.Nm full +.Nd the full device +.Sh DESCRIPTION +The +.Nm +device supplies an endless stream of zeros when read. +However, it will always be full when writing to it. +.Sh FILES +.Bl -tag -width /dev/full +.It Pa /dev/full +.El +.Sh SEE ALSO +.Xr null 4 +.Xr zero 4 +.Sh Author +This device and man page was written by +.An Eitan Adler Aq eadler@FreeBSD.org . diff --git a/share/man/man4/null.4 b/share/man/man4/null.4 index 05ba12a..b322301 100644 --- a/share/man/man4/null.4 +++ b/share/man/man4/null.4 @@ -48,6 +48,7 @@ device is always zero. .It Pa /dev/null .El .Sh SEE ALSO +.Xr full 4 .Xr zero 4 .Sh HISTORY A diff --git a/share/man/man4/zero.4 b/share/man/man4/zero.4 index cb73a2c..e1a2238 100644 --- a/share/man/man4/zero.4 +++ b/share/man/man4/zero.4 @@ -49,6 +49,7 @@ supply of null bytes when read. .It Pa /dev/zero .El .Sh SEE ALSO +.Xr full 4 .Xr null 4 .Sh HISTORY A diff --git a/sys/dev/null/null.c b/sys/dev/null/null.c index c1208c11..730f8dd 100644 --- a/sys/dev/null/null.c +++ b/sys/dev/null/null.c @@ -1,6 +1,7 @@ /*- * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen * Copyright (c) 2001-2004 Mark R. V. Murray + * Copyright (c) 2014 Eitan Adler * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,7 +48,9 @@ __FBSDID("$FreeBSD$"); /* For use with destroy_dev(9). */ static struct cdev *null_dev; static struct cdev *zero_dev; +static struct cdev *full_dev; +static d_write_t full_write; static d_write_t null_write; static d_ioctl_t null_ioctl; static d_ioctl_t zero_ioctl; @@ -70,6 +73,23 @@ static struct cdevsw zero_cdevsw = { .d_flags = D_MMAP_ANON, }; +static struct cdevsw full_cdevsw = { + .d_version = D_VERSION, + .d_read = zero_read, + .d_write = full_write, + .d_ioctl = zero_ioctl, + .d_name = "full", +}; + + +/* ARGSUSED */ +static int +full_write(struct cdev *dev __unused, struct uio *uio, int flags __unused) +{ + + return (ENOSPC); +} + /* ARGSUSED */ static int null_write(struct cdev *dev __unused, struct uio *uio, int flags __unused) @@ -155,7 +175,9 @@ null_modevent(module_t mod __unused, int type, void *data __unused) switch(type) { case MOD_LOAD: if (bootverbose) - printf("null: \n"); + printf("null: \n"); + full_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &full_cdevsw, 0, + NULL, UID_ROOT, GID_WHEEL, 0666, "full"); null_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &null_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0666, "null"); zero_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &zero_cdevsw, 0, @@ -163,6 +185,7 @@ null_modevent(module_t mod __unused, int type, void *data __unused) break; case MOD_UNLOAD: + destroy_dev(full_dev); destroy_dev(null_dev); destroy_dev(zero_dev); break; -- cgit v1.1