Fwd: svn commit: r280955 - in head/sys: modules/notrandom dev/notrandom

Matteo Riondato <[email protected]> Wed, 1 Apr 2015 08:41:25 -0400
Newsgroups gmane.os.freebsd.italian.varie
Message-ID <CA+fiBi484fK9KozsPD2-ZYwuXEeCqR+V1HY4VpawwJ5d=vhBEA@mail.gmail.com>
Finalmente!

---------- Forwarded message ----------
From: Mateusz Guzik <[email protected]>
Date: Wed, Apr 1, 2015 at 7:36 AM
Subject: svn commit: r280955 - in head/sys: modules/notrandom dev/notrandom
To: [email protected], [email protected],
[email protected]


Author: mjg
Date: Wed Apr  1 13:37:00 2015
New Revision: 280955
URL: https://svnweb.freebsd.org/changeset/base/280955

Log:
  Add /dev/notrandom

  notrandom provides fast and reliable not random numbers.

  This was added in an effort to increase feature-compatiblity with
  Solaris 10.

  See http://www.brendangregg.com/Specials/notrandom.c for Solaris
  implementation.

  Reviewed-by: Bruce Schneier (ok, not really)
  MFC after:    1 week

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

Added: sys/dev/notrandom/notrandom.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- head/sys/dev/notrandom/notrandom.c  (revision 0)
+++ 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 WARRANTI=
ES
+ * 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 US=
E,
+ * 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 =3D {
+       .d_version =3D    D_VERSION,
+       .d_read =3D       notrandom_read,
+       .d_ioctl =3D      notrandom_ioctl,
+       .d_name =3D       "notrandom",
+       .d_flags =3D      D_MMAP_ANON,
+};
+
+static char notrandom_buf[1024];
+
+static int
+notrandom_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unus=
ed,
+          int flags __unused, struct thread *td)
+{
+       int error =3D 0;
+
+       switch (cmd) {
+       case FIONBIO:
+               break;
+       case FIOASYNC:
+               if (*(int *)data !=3D 0)
+                       error =3D EINVAL;
+               break;
+       default:
+               error =3D ENOIOCTL;
+       }
+       return (error);
+}
+
+
+/* ARGSUSED */
+static int
+notrandom_read(struct cdev *dev __unused, struct uio *uio, int flags __unu=
sed)
+{
+       ssize_t len;
+       int error =3D 0;
+
+       while (uio->uio_resid > 0 && error =3D=3D 0) {
+               len =3D uio->uio_resid;
+               if (len > sizeof(notrandom_buf))
+                       len =3D sizeof(notrandom_buf);
+               error =3D uiomove(notrandom_buf, len, uio);
+       }
+
+       return (error);
+}
+
+/* ARGSUSED */
+static int
+notrandom_modevent(module_t mod __unused, int type, void *data __unused)
+{
+       int error =3D 0;
+
+       switch(type) {
+       case MOD_LOAD:
+               memset(notrandom_buf, 7, sizeof(notrandom_buf));
+               notrandom_dev =3D 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 safe than sorry.
+                */
+               memset(notrandom_buf, 123, sizeof(notrandom_buf));
+               break;
+
+       case MOD_SHUTDOWN:
+               break;
+
+       default:
+               error =3D EOPNOTSUPP;
+       }
+
+       return (error);
+}
+
+DEV_MODULE(notrandom, notrandom_modevent, NULL);
+MODULE_VERSION(notrandom, 1);

Property changes on: head/sys/dev/notrandom/notrandom.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=3D%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: sys/modules/notrandom/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- head/sys/modules/notrandom/Makefile (revision 0)
+++ head/sys/modules/notrandom/Makefile (working copy)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../../dev/notrandom
+
+KMOD=3D  notrandom
+SRCS=3D  notrandom.c
+
+.include <bsd.kmod.mk>

Property changes on: head/sys/modules/notrandom/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=3D%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

_______________________________________________
Varie mailing list
[email protected]
http://mailman.gufi.org/mailman/listinfo/varie