Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Apr 2015 19:40:01 +0200
From:      Mateusz Guzik <mjg@freebsd.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r280866 - in head/sys: modules/notrandom dev/notrandom dev/null
Message-ID:  <20150401174000.GA2575@dft-labs.eu>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Wed Apr  1 19:38:00 2015
New Revision: 280963
URL: https://svnweb.freebsd.org/changeset/base/280963

Log:
  Move /dev/notrandom implementation to /dev/null driver.

  Due to popular demand.

  While here tweak a comment justifying memset when unloading the module.

  MFC after:	1 week

Modified:
  head/sys/dev/null/null.c

Removed:
  head/sys/modules/notrandom/Makefile
  head/sys/dev/notrandom/notrandom.c

Modified: head/sys/dev/null/null.c
===================================================================
--- sys/dev/null/null.c	(revision 280404)
+++ sys/dev/null/null.c	(working copy)
@@ -1,9 +1,10 @@
 /*-
- * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
- * Copyright (c) 2001-2004 Mark R. V. Murray
- * Copyright (c) 2014 Eitan Adler
+ * Copyright (c) 2015 Mateusz Guzik
  * All rights reserved.
  *
+ * Some dudes which previously held the copyright:
+ * Marc V. R. Murray, Jeroen C. van Gelderen, Eytan Adrel
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -45,11 +46,14 @@
 #include <machine/vmparam.h>
 
 /* For use with destroy_dev(9). */
+static char notrandom_buf[1024];
 static struct cdev *full_dev;
+static struct cdev *notrandom_dev;
 static struct cdev *null_dev;
 static struct cdev *zero_dev;
 
 static d_write_t full_write;
+static d_read_t notrandom_read;
 static d_write_t null_write;
 static d_ioctl_t null_ioctl;
 static d_ioctl_t zero_ioctl;
@@ -63,6 +67,14 @@
 	.d_name =	"full",
 };
 
+static struct cdevsw notrandom_cdevsw = {
+	.d_version =	D_VERSION,
+	.d_read =	notrandom_read,
+	.d_ioctl =	zero_ioctl,
+	.d_name =	"notrandom",
+	.d_flags =	D_MMAP_ANON,
+};
+
 static struct cdevsw null_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_read =	(d_read_t *)nullop,
@@ -92,6 +104,23 @@
 
 /* ARGSUSED */
 static int
+notrandom_read(struct cdev *dev __unused, struct uio *uio, int flags __unused)
+{
+	ssize_t len;
+	int error = 0;
+
+	while (uio->uio_resid > 0 && error == 0) {
+		len = uio->uio_resid;
+		if (len > sizeof(notrandom_buf))
+			len = sizeof(notrandom_buf);
+		error = uiomove(notrandom_buf, len, uio);
+	}
+
+	return (error);
+}
+
+/* ARGSUSED */
+static int
 null_write(struct cdev *dev __unused, struct uio *uio, int flags __unused)
 {
 	uio->uio_resid = 0;
@@ -173,9 +202,14 @@
 	switch(type) {
 	case MOD_LOAD:
 		if (bootverbose)
-			printf("null: <full device, null device, zero device>\n");
+			printf("null: <full device, notrandomdevice, "
+			    "null device, zero device>\n");
 		full_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &full_cdevsw, 0,
 		    NULL, UID_ROOT, GID_WHEEL, 0666, "full");
+		memset(notrandom_buf, 7, sizeof(notrandom_buf));
+		notrandom_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD,
+		    &notrandom_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0666,
+		    "notrandom");
 		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,
@@ -185,6 +219,12 @@
 	case MOD_UNLOAD:
 		destroy_dev(full_dev);
 		destroy_dev(null_dev);
+		destroy_dev(notrandom_dev);
+		/*
+		 * Thrash notrandom region so that the content cannot be
+		 * retrieved. Better safe than sorry.
+		 */
+		memset(notrandom_buf, 123, sizeof(notrandom_buf));
 		destroy_dev(zero_dev);
 		break;
 
Removed: head/sys/dev/notrandom/notrandom.c
===================================================================
--- head/sys/dev/notrandom/notrandom.c	(revision r280962)
+++ head/sys/dev/notrandom/notrandom.c	(working copy)
@@ -0,0 +1,126 @@
-/*-
- * Copyright (c) 2015 Mateusz Guzik
- * 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
- *    in this position and unchanged.
- * 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 AUTHORS ``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 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.
- *
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/uio.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-#include <sys/filio.h>
-
-static struct cdev *notrandom_dev;
-
-static d_ioctl_t notrandom_ioctl;
-static d_read_t notrandom_read;
-
-static struct cdevsw notrandom_cdevsw = {
-	.d_version =	D_VERSION,
-	.d_read =	notrandom_read,
-	.d_ioctl =	notrandom_ioctl,
-	.d_name =	"notrandom",
-	.d_flags =	D_MMAP_ANON,
-};
-
-static char notrandom_buf[1024];
-
-static int
-notrandom_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unused,
-	   int flags __unused, struct thread *td)
-{
-	int error = 0;
-
-	switch (cmd) {
-	case FIONBIO:
-		break;
-	case FIOASYNC:
-		if (*(int *)data != 0)
-			error = EINVAL;
-		break;
-	default:
-		error = ENOIOCTL;
-	}
-	return (error);
-}
-
-
-/* ARGSUSED */
-static int
-notrandom_read(struct cdev *dev __unused, struct uio *uio, int flags __unused)
-{
-	ssize_t len;
-	int error = 0;
-
-	while (uio->uio_resid > 0 && error == 0) {
-		len = uio->uio_resid;
-		if (len > sizeof(notrandom_buf))
-			len = sizeof(notrandom_buf);
-		error = uiomove(notrandom_buf, len, uio);
-	}
-
-	return (error);
-}
-
-/* ARGSUSED */
-static int
-notrandom_modevent(module_t mod __unused, int type, void *data __unused)
-{
-	int error = 0;
-
-	switch(type) {
-	case MOD_LOAD:
-		memset(notrandom_buf, 7, sizeof(notrandom_buf));
-		notrandom_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD,
-		    &notrandom_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0666,
-		    "notrandom");
-		break;
-
-	case MOD_UNLOAD:
-		destroy_dev(notrandom_dev);
-		/*
-		 * Trash notrandom region so that the content cannot be
-		 * retrieved. Better to be safe than sorry.
-		 */
-		memset(notrandom_buf, 123, sizeof(notrandom_buf));
-		break;
-
-	case MOD_SHUTDOWN:
-		break;
-
-	default:
-		error = EOPNOTSUPP;
-	}
-
-	return (error);
-}
-
-DEV_MODULE(notrandom, notrandom_modevent, NULL);
-MODULE_VERSION(notrandom, 1);

Removed: head/sys/modules/notrandom/Makefile
===================================================================
--- head/sys/modules/notrandom/Makefile	(revision r280962)
+++ head/sys/modules/notrandom/Makefile	(working copy)
@@ -0,0 +1,8 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../../dev/notrandom
-
-KMOD=	notrandom
-SRCS=	notrandom.c
-
-.include <bsd.kmod.mk>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150401174000.GA2575>