kern/68961: [PATCH] Implement /dev/full

Robert Millan rmh at debian.org
Mon Jul 12 14:30:23 PDT 2004


>Number:         68961
>Category:       kern
>Synopsis:       [PATCH] Implement /dev/full
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 12 21:30:22 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Robert Millan
>Release:        FreeBSD 5.2.1
>Organization:
Debian
>Environment:
System: GNU/Linux aragorn 2.4.26-1-k7 #1 Sat May 1 21:40:09 EST 2004 i686
Architecture: i686

	
>Description:
	This patch implements /dev/full, a device that returns ENOSPC when
	attempting to write on it. It is commonly used on other Un*x OSes
	(e.g. GNU/Linux) and some applications assume it is present.

	Note: I'm the maintainer of the Debian package "kfreebsd5" (kernel
	of FreeBSD 5.x). I have made some changes to the kernel for portability
	and some improvements, and I'll be forwarding more patches in the
	future.

>How-To-Repeat:
	
>Fix:

I don't know the policy for assigning minor numbers, so I just defined
FULL_MINOR as 3 which apparently is free. Let me know if I missed something.

--- src/sys/dev/null/null.c.old	2004-07-12 20:20:37.000000000 +0200
+++ src/sys/dev/null/null.c	2004-07-12 20:27:10.000000000 +0200
@@ -41,14 +41,17 @@
 
 /* For use with destroy_dev(9). */
 static dev_t null_dev;
+static dev_t full_dev;
 static dev_t zero_dev;
 
 static d_write_t null_write;
+static d_write_t full_write;
 static d_ioctl_t null_ioctl;
 static d_read_t zero_read;
 
 #define CDEV_MAJOR	2
 #define NULL_MINOR	2
+#define FULL_MINOR	3
 #define ZERO_MINOR	12
 
 static struct cdevsw null_cdevsw = {
@@ -60,6 +63,15 @@
 	.d_flags =	D_NOGIANT,
 };
 
+static struct cdevsw full_cdevsw = {
+	.d_read =	(d_read_t *)nullop,
+	.d_write =	full_write,
+	.d_ioctl =	null_ioctl,
+	.d_name =	"full",
+	.d_maj =	CDEV_MAJOR,
+	.d_flags =	D_NOGIANT,
+};
+
 static struct cdevsw zero_cdevsw = {
 	.d_read =	zero_read,
 	.d_write =	null_write,
@@ -80,6 +92,14 @@
 
 /* ARGSUSED */
 static int
+full_write(dev_t dev __unused, struct uio *uio, int flags __unused)
+{
+	uio->uio_resid = 0;
+	return (ENOSPC);
+}
+
+/* ARGSUSED */
+static int
 null_ioctl(dev_t dev __unused, u_long cmd, caddr_t data __unused,
     int flags __unused, struct thread *td)
 {
@@ -120,10 +140,13 @@
 			GID_WHEEL, 0666, "zero");
 		null_dev = make_dev(&null_cdevsw, NULL_MINOR, UID_ROOT,
 			GID_WHEEL, 0666, "null");
+		full_dev = make_dev(&full_cdevsw, FULL_MINOR, UID_ROOT,
+			GID_WHEEL, 0666, "full");
 		return 0;
 
 	case MOD_UNLOAD:
 		destroy_dev(null_dev);
+		destroy_dev(full_dev);
 		destroy_dev(zero_dev);
 		free(zbuf, M_TEMP);
 		return 0;

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list