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
This commit is contained in:
Eitan Adler 2014-04-30 06:20:48 +00:00
parent c6f70658c3
commit a345aa5953
4 changed files with 73 additions and 1 deletions

47
share/man/man4/full.4 Normal file
View file

@ -0,0 +1,47 @@
.\" Copyright (c) 2014
.\" Eitan Adler <eadler@FreeBSD.org>. 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 .

View file

@ -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

View file

@ -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

View file

@ -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: <null device, zero device>\n");
printf("null: <full device, null device, zero device>\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;