VFS - Rework to remove function pointers from tVFS_Node
[tpg/acess2.git] / Kernel / vfs / memfile.c
index 2fc38e7..14b3948 100644 (file)
@@ -1,30 +1,32 @@
-/*
+/* 
+ * Acess 2
+ * Virtual File System
+ * - Memory Pseudo Files
  */
-#include <common.h>
+#include <acess.h>
 #include <vfs.h>
 
 // === PROTOTYPES ===
-tVFS_Node      *VFS_MemFile_Create(tVFS_Node *Unused, char *Path);
+tVFS_Node      *VFS_MemFile_Create(const char *Path);
 void   VFS_MemFile_Close(tVFS_Node *Node);
 Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
-Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
+Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer);
 
 // === GLOBALS ===
-tVFS_Node      gVFS_MemRoot = {
-       .Flags = VFS_FFLAG_DIRECTORY,
-       .NumACLs = 0,
-       .FindDir = VFS_MemFile_Create
+tVFS_NodeType  gVFS_MemFileType = {
+       .Close = VFS_MemFile_Close,
+       .Read = VFS_MemFile_Read,
+       .Write = VFS_MemFile_Write
        };
 
 // === CODE ===
 /**
- * \fn tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
- * \note Treated as finddir by VFS_ParsePath
+ * \fn tVFS_Node *VFS_MemFile_Create(const char *Path)
  */
-tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
+tVFS_Node *VFS_MemFile_Create(const char *Path)
 {
        Uint    base, size;
-       char    *str = Path;
+       const char      *str = Path;
        tVFS_Node       *ret;
        
        str++;  // Eat '$'
@@ -57,8 +59,6 @@ tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
        // Check for NULL byte
        if(*str != '\0')        return NULL;
        
-       Log(" VFS_MemFile_Create: base=0x%x, size=0x%x", base, size);
-       
        // Allocate and fill node
        ret = malloc(sizeof(tVFS_Node));
        memset(ret, 0, sizeof(tVFS_Node));
@@ -72,9 +72,7 @@ tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
        ret->ACLs = &gVFS_ACL_EveryoneRWX;
        
        // Functions
-       ret->Close = VFS_MemFile_Close;
-       ret->Read = VFS_MemFile_Read;
-       ret->Write = VFS_MemFile_Write;
+       ret->Type = &gVFS_MemFileType;
        
        return ret;
 }
@@ -109,7 +107,7 @@ Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf
                Length = Node->Size - Offset;
        
        // Copy Data
-       memcpy(Buffer, Node->ImplPtr+Offset, Length);
+       memcpy(Buffer, (Uint8*)Node->ImplPtr + Offset, Length);
        
        return Length;
 }
@@ -118,7 +116,7 @@ Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf
  * \fn Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
  * \brief Write to a memory file
  */
-Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
 {
        // Check for use of free'd file
        if(Node->ImplPtr == NULL)       return 0;
@@ -131,7 +129,7 @@ Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Bu
                Length = Node->Size - Offset;
        
        // Copy Data
-       memcpy(Node->ImplPtr+Offset, Buffer, Length);
+       memcpy((Uint8*)Node->ImplPtr + Offset, Buffer, Length);
        
        return Length;
 }

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