From 7ea096298970b3084b3bc8dc7dfe9ca5bc272a48 Mon Sep 17 00:00:00 2001
From: fishpond <kai.niessen@online.de>
Date: Fri, 1 Feb 2013 22:24:50 +0100
Subject: [PATCH] Added capability to accept writes to dev/random
modified: driver.cpp
---
src/add-ons/kernel/drivers/random/driver.cpp | 29 +++++++++++++++++++-------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/add-ons/kernel/drivers/random/driver.cpp b/src/add-ons/kernel/drivers/random/driver.cpp
index a5853e4..920f3bf 100644
a
|
b
|
reseed(ch_randgen *prandgen, const uint32 initTimes)
|
189 | 189 | { |
190 | 190 | volatile uint32 i, j; |
191 | 191 | OCTET x, y; |
| 192 | |
| 193 | x.Q[0] = 0; |
192 | 194 | |
193 | 195 | for (j = initTimes; j; j--) { |
194 | 196 | for (i = NK * initTimes; i; i--) { |
… |
… |
random_read(void *cookie, off_t position, void *_buffer, size_t *_numBytes)
|
402 | 404 | int32 *buffer = (int32 *)_buffer; |
403 | 405 | uint8 *buffer8 = (uint8 *)_buffer; |
404 | 406 | uint32 i, j; |
405 | | TRACE((DRIVER_NAME ": read(%Ld,, %d)\n", position, *_numBytes)); |
| 407 | TRACE((DRIVER_NAME ": read(%Ld,, %ld)\n", position, *_numBytes)); |
406 | 408 | |
407 | 409 | mutex_lock(&sRandomLock); |
408 | 410 | sRandomCount += *_numBytes; |
… |
… |
random_read(void *cookie, off_t position, void *_buffer, size_t *_numBytes)
|
430 | 432 | static status_t |
431 | 433 | random_write(void *cookie, off_t position, const void *buffer, size_t *_numBytes) |
432 | 434 | { |
433 | | TRACE((DRIVER_NAME ": write(%Ld,, %d)\n", position, *_numBytes)); |
434 | | *_numBytes = 0; |
435 | | return EINVAL; |
| 435 | size_t i; |
| 436 | OCTET* data; |
| 437 | TRACE((DRIVER_NAME ": write(%Ld,, %ld)\n", position, *_numBytes)); |
| 438 | mutex_lock(&sRandomLock); |
| 439 | data = (OCTET*)buffer; |
| 440 | for (i = 0; i < *_numBytes / sizeof(OCTET); i++) { |
| 441 | chseed(sRandomEnv, data->Q[0]); |
| 442 | data++; |
| 443 | } |
| 444 | mutex_unlock(&sRandomLock); |
| 445 | return B_OK; |
436 | 446 | } |
437 | 447 | |
438 | 448 | |
439 | 449 | static status_t |
440 | 450 | random_control(void *cookie, uint32 op, void *arg, size_t length) |
441 | 451 | { |
442 | | TRACE((DRIVER_NAME ": ioctl(%d)\n", op)); |
| 452 | TRACE((DRIVER_NAME ": ioctl(%ld)\n", op)); |
443 | 453 | return B_ERROR; |
444 | 454 | } |
445 | 455 | |
… |
… |
random_select(void *cookie, uint8 event, uint32 ref, selectsync *sync)
|
473 | 483 | notify_select_event(sync, event); |
474 | 484 | #endif |
475 | 485 | } else if (event == B_SELECT_WRITE) { |
476 | | /* we're not writable */ |
477 | | return EINVAL; |
| 486 | /* we're now writable */ |
| 487 | #ifndef HAIKU_TARGET_PLATFORM_HAIKU |
| 488 | notify_select_event(sync, ref); |
| 489 | #else |
| 490 | notify_select_event(sync, event); |
| 491 | #endif |
478 | 492 | } |
479 | | |
480 | 493 | return B_OK; |
481 | 494 | } |
482 | 495 | |