Kernel - Added /Devices/{zero,one,null}
authorJohn Hodge <[email protected]>
Thu, 14 Jun 2012 08:41:40 +0000 (16:41 +0800)
committerJohn Hodge <[email protected]>
Thu, 14 Jun 2012 08:41:40 +0000 (16:41 +0800)
KernelLand/Kernel/Makefile
KernelLand/Kernel/drv/zero-one.c [new file with mode: 0644]

index 81a2928..a5a5c03 100644 (file)
@@ -54,7 +54,7 @@ OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ))
 OBJ += heap.o drvutil.o logging.o debug.o lib.o adt.o time.o
 OBJ += messages.o modules.o syscalls.o system.o
 OBJ += threads.o mutex.o semaphore.o workqueue.o events.o
-OBJ += drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o
+OBJ += drv/zero-one.o drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o
 OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_vt100.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o
 OBJ += binary.o bin/elf.o bin/pe.o
 OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o
diff --git a/KernelLand/Kernel/drv/zero-one.c b/KernelLand/Kernel/drv/zero-one.c
new file mode 100644 (file)
index 0000000..824f927
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Acess2 Kernel
+ * - By John Hodge (thePowersGang)
+ *
+ * drv/zero-one.c
+ * - /Devices/{null,zero,one}
+ */
+#define DEBUG  0
+#include <acess.h>
+#include <modules.h>
+#include <fs_devfs.h>
+
+// === PROTOTYPES ===
+ int   CoreDevs_Install(char **Arguments);
+size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer);
+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);
+
+// === GLOBALS ===
+MODULE_DEFINE(0, 0x0100, CoreDevs, CoreDevs_Install, NULL, NULL);
+tVFS_NodeType  gCoreDevs_NT_Null = {
+       .TypeName = "CoreDevs-null",
+       .Read  = CoreDevs_Read_Null,
+       .Write = CoreDevs_Write
+};
+tVFS_NodeType  gCoreDevs_NT_Zero = {
+       .TypeName = "CoreDevs-zero",
+       .Read  = CoreDevs_Read_Zero,
+       .Write = CoreDevs_Write
+};
+tVFS_NodeType  gCoreDevs_NT_One = {
+       .TypeName = "CoreDevs-one",
+       .Read  = CoreDevs_Read_One,
+       .Write = CoreDevs_Write
+};
+tDevFS_Driver  gCoreDevs_Null = {
+       NULL, "null",
+       {
+       .Size = 0,
+       .NumACLs = 1,
+       .ACLs = &gVFS_ACL_EveryoneRW,
+       .Type = &gCoreDevs_NT_Null
+       }
+};
+tDevFS_Driver  gCoreDevs_Zero = {
+       NULL, "zero",
+       {
+       .Size = 0,
+       .NumACLs = 1,
+       .ACLs = &gVFS_ACL_EveryoneRW,
+       .Type = &gCoreDevs_NT_Zero
+       }
+};
+tDevFS_Driver  gCoreDevs_One = {
+       NULL, "one",
+       {
+       .Size = 0,
+       .NumACLs = 1,
+       .ACLs = &gVFS_ACL_EveryoneRW,
+       .Type = &gCoreDevs_NT_One
+       }
+};
+
+// === CODE ===
+/**
+ * \brief Installs the CoreDevs driver
+ */
+int CoreDevs_Install(char **Options)
+{
+       DevFS_AddDevice( &gCoreDevs_Null );
+       DevFS_AddDevice( &gCoreDevs_Zero );
+       DevFS_AddDevice( &gCoreDevs_One  );
+       return MODULE_ERR_OK;
+}
+
+size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer)
+{
+       return Length;  // Ignore
+}
+
+size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
+{
+       memset(Buffer, 0, Length);
+       return Length;
+}
+
+size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
+{
+       Uint8   *ptr = Buffer;
+       size_t  rem;
+       for( rem = Length; rem --; ptr ++ )
+               *ptr = 0xFF;
+       return Length;
+}
+
+size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
+{
+       return 0;
+}
+

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