Modules/Ext2 - Fixed zero-length filenames and memory leaks
[tpg/acess2.git] / KernelLand / Kernel / drv / zero-one.c
1 /*
2  * Acess2 Kernel
3  * - By John Hodge (thePowersGang)
4  *
5  * drv/zero-one.c
6  * - /Devices/{null,zero,one}
7  */
8 #define DEBUG   0
9 #include <acess.h>
10 #include <modules.h>
11 #include <fs_devfs.h>
12
13 // === PROTOTYPES ===
14  int    CoreDevs_Install(char **Arguments);
15 size_t  CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer);
16 size_t  CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
17 size_t  CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
18 size_t  CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
19
20 // === GLOBALS ===
21 MODULE_DEFINE(0, 0x0100, CoreDevs, CoreDevs_Install, NULL, NULL);
22 tVFS_NodeType   gCoreDevs_NT_Null = {
23         .TypeName = "CoreDevs-null",
24         .Read  = CoreDevs_Read_Null,
25         .Write = CoreDevs_Write
26 };
27 tVFS_NodeType   gCoreDevs_NT_Zero = {
28         .TypeName = "CoreDevs-zero",
29         .Read  = CoreDevs_Read_Zero,
30         .Write = CoreDevs_Write
31 };
32 tVFS_NodeType   gCoreDevs_NT_One = {
33         .TypeName = "CoreDevs-one",
34         .Read  = CoreDevs_Read_One,
35         .Write = CoreDevs_Write
36 };
37 tDevFS_Driver   gCoreDevs_Null = {
38         NULL, "null",
39         {
40         .Size = 0,
41         .NumACLs = 1,
42         .ACLs = &gVFS_ACL_EveryoneRW,
43         .Type = &gCoreDevs_NT_Null
44         }
45 };
46 tDevFS_Driver   gCoreDevs_Zero = {
47         NULL, "zero",
48         {
49         .Size = 0,
50         .NumACLs = 1,
51         .ACLs = &gVFS_ACL_EveryoneRW,
52         .Type = &gCoreDevs_NT_Zero
53         }
54 };
55 tDevFS_Driver   gCoreDevs_One = {
56         NULL, "one",
57         {
58         .Size = 0,
59         .NumACLs = 1,
60         .ACLs = &gVFS_ACL_EveryoneRW,
61         .Type = &gCoreDevs_NT_One
62         }
63 };
64
65 // === CODE ===
66 /**
67  * \brief Installs the CoreDevs driver
68  */
69 int CoreDevs_Install(char **Options)
70 {
71         DevFS_AddDevice( &gCoreDevs_Null );
72         DevFS_AddDevice( &gCoreDevs_Zero );
73         DevFS_AddDevice( &gCoreDevs_One  );
74         return MODULE_ERR_OK;
75 }
76
77 size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer)
78 {
79         return Length;  // Ignore
80 }
81
82 size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
83 {
84         memset(Buffer, 0, Length);
85         return Length;
86 }
87
88 size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
89 {
90         Uint8   *ptr = Buffer;
91         size_t  rem;
92         for( rem = Length; rem --; ptr ++ )
93                 *ptr = 0xFF;
94         return Length;
95 }
96
97 size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
98 {
99         return 0;
100 }
101

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