From: Lionel Sambuc Date: Wed, 16 Apr 2014 11:57:52 +0000 (+0200) Subject: From Ben Gras, add select support on /dev/random. X-Git-Tag: v3.3.0~363 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/NetBSD.png?a=commitdiff_plain;h=6a309697f483f38eb136d97aa677544ab1f75dac;p=minix.git From Ben Gras, add select support on /dev/random. Change-Id: I47bf4c45285458ecc224df0564edf98afdb2c9d6 --- diff --git a/drivers/random/main.c b/drivers/random/main.c index 1ded6f37e..619a20d56 100644 --- a/drivers/random/main.c +++ b/drivers/random/main.c @@ -28,15 +28,20 @@ static ssize_t r_write(devminor_t minor, u64_t position, endpoint_t endpt, static int r_open(devminor_t minor, int access, endpoint_t user_endpt); static void r_random(clock_t stamp); static void r_updatebin(int source, struct k_randomness_bin *rb); +static int r_select(devminor_t, unsigned int, endpoint_t); /* Entry points to this driver. */ static struct chardriver r_dtab = { .cdr_open = r_open, /* open device */ .cdr_read = r_read, /* read from device */ .cdr_write = r_write, /* write to device (seeding it) */ + .cdr_select = r_select, /* select hook */ .cdr_alarm = r_random /* get randomness from kernel (alarm) */ }; +/* select requestor */ +static endpoint_t random_select = NONE; + /* Buffer for the /dev/random number generator. */ #define RANDOM_BUF_SIZE 1024 static char random_buf[RANDOM_BUF_SIZE]; @@ -253,3 +258,16 @@ static void r_random(clock_t UNUSED(stamp)) printf("RANDOM: sys_setalarm failed: %d\n", s); } +/*===========================================================================* + * r_select * + *===========================================================================*/ +static int r_select(devminor_t minor, unsigned int ops, endpoint_t ep) +{ + /* random device is always writable; it's infinitely readable + * once seeded, and doesn't block when it's not, so all operations + * are instantly possible. we ignore CDEV_OP_ERR. + */ + int ready_ops = 0; + if (minor != RANDOM_DEV) return(EIO); + return ops & (CDEV_OP_RD | CDEV_OP_WR); +}