toaruos/kernel/fs/randomdev.c

54 lines
1.3 KiB
C
Raw Normal View History

2013-03-23 09:38:10 +04:00
/* vim: tabstop=4 shiftwidth=4 noexpandtab
2013-05-22 01:34:18 +04:00
* Provides access to the kernel RNG
2013-03-23 09:38:10 +04:00
*/
#include <system.h>
#include <logging.h>
#include <fs.h>
uint32_t read_random(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
uint32_t write_random(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
void open_random(fs_node_t *node, unsigned int flags);
2013-03-23 09:38:10 +04:00
void close_random(fs_node_t *node);
uint32_t read_random(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
uint32_t s = 0;
while (s < size) {
buffer[s] = krand() % 0xFF;
offset++;
s++;
}
return size;
}
uint32_t write_random(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
return size;
}
void open_random(fs_node_t * node, unsigned int flags) {
2013-03-23 09:38:10 +04:00
return;
}
void close_random(fs_node_t * node) {
return;
}
2013-06-06 10:10:36 +04:00
fs_node_t * random_device_create(void) {
2013-03-23 09:38:10 +04:00
fs_node_t * fnode = malloc(sizeof(fs_node_t));
memset(fnode, 0x00, sizeof(fs_node_t));
fnode->inode = 0;
strcpy(fnode->name, "random");
fnode->uid = 0;
fnode->gid = 0;
fnode->length = 1024;
fnode->flags = FS_CHARDEVICE;
fnode->read = read_random;
fnode->write = write_random;
fnode->open = open_random;
fnode->close = close_random;
fnode->readdir = NULL;
fnode->finddir = NULL;
fnode->ioctl = NULL;
return fnode;
}