Kernel - Added fast random (ala /dev/urandom), good random is stubbed
authorJohn Hodge <[email protected]>
Tue, 14 May 2013 07:48:17 +0000 (15:48 +0800)
committerJohn Hodge <[email protected]>
Tue, 14 May 2013 07:48:17 +0000 (15:48 +0800)
KernelLand/Kernel/drv/zero-one.c

index 824f927..fd14ed1 100644 (file)
@@ -16,6 +16,8 @@ size_t        CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *
 size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
 size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
 size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
+size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
+size_t CoreDevs_Read_GRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
 
 // === GLOBALS ===
 MODULE_DEFINE(0, 0x0100, CoreDevs, CoreDevs_Install, NULL, NULL);
@@ -34,11 +36,20 @@ tVFS_NodeType       gCoreDevs_NT_One = {
        .Read  = CoreDevs_Read_One,
        .Write = CoreDevs_Write
 };
+tVFS_NodeType  gCoreDevs_NT_FRandom = {
+       .TypeName = "CoreDevs-frandom",
+       .Read  = CoreDevs_Read_FRandom,
+       .Write = CoreDevs_Write
+};
+tVFS_NodeType  gCoreDevs_NT_GRandom = {
+       .TypeName = "CoreDevs-grandom",
+       .Read  = CoreDevs_Read_GRandom,
+       .Write = CoreDevs_Write
+};
 tDevFS_Driver  gCoreDevs_Null = {
        NULL, "null",
        {
-       .Size = 0,
-       .NumACLs = 1,
+       .Size = 0, .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRW,
        .Type = &gCoreDevs_NT_Null
        }
@@ -46,8 +57,7 @@ tDevFS_Driver gCoreDevs_Null = {
 tDevFS_Driver  gCoreDevs_Zero = {
        NULL, "zero",
        {
-       .Size = 0,
-       .NumACLs = 1,
+       .Size = 0, .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRW,
        .Type = &gCoreDevs_NT_Zero
        }
@@ -55,12 +65,27 @@ tDevFS_Driver       gCoreDevs_Zero = {
 tDevFS_Driver  gCoreDevs_One = {
        NULL, "one",
        {
-       .Size = 0,
-       .NumACLs = 1,
+       .Size = 0, .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRW,
        .Type = &gCoreDevs_NT_One
        }
 };
+tDevFS_Driver  gCoreDevs_FRandom = {
+       NULL, "frandom",
+       {
+       .Size = 0, .NumACLs = 1,
+       .ACLs = &gVFS_ACL_EveryoneRW,
+       .Type = &gCoreDevs_NT_FRandom
+       }
+};
+tDevFS_Driver  gCoreDevs_GRandom = {
+       NULL, "grandom",
+       {
+       .Size = 0, .NumACLs = 1,
+       .ACLs = &gVFS_ACL_EveryoneRW,
+       .Type = &gCoreDevs_NT_GRandom
+       }
+};
 
 // === CODE ===
 /**
@@ -71,6 +96,8 @@ int CoreDevs_Install(char **Options)
        DevFS_AddDevice( &gCoreDevs_Null );
        DevFS_AddDevice( &gCoreDevs_Zero );
        DevFS_AddDevice( &gCoreDevs_One  );
+       DevFS_AddDevice( &gCoreDevs_FRandom  );
+       //DevFS_AddDevice( &gCoreDevs_GRandom  );
        return MODULE_ERR_OK;
 }
 
@@ -99,3 +126,18 @@ size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Bu
        return 0;
 }
 
+//! Fast random number generator
+size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
+{
+       Uint8   *cbuf = Buffer;
+       for( int i = 0; i < Length; i ++ )
+               *cbuf++ = rand();
+       return Length;
+}
+
+size_t CoreDevs_Read_GRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
+{
+       Log_Error("CoreDevs", "GRandom is unimplimented");
+       return -1;
+}
+

UCC git Repository :: git.ucc.asn.au