7 tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path);
8 void VFS_MemFile_Close(tVFS_Node *Node);
9 Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
10 Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
13 tVFS_Node gVFS_MemRoot = {
14 .Flags = VFS_FFLAG_DIRECTORY,
16 .FindDir = VFS_MemFile_Create
21 * \fn tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
22 * \note Treated as finddir by VFS_ParsePath
24 tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
34 for( ; ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'F'); str++ )
37 if('A' <= *str && *str <= 'F')
38 base += *str - 'A' + 10;
44 if(*str++ != ':') return NULL;
48 for( ; ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'F'); str++ )
51 if('A' <= *str && *str <= 'F')
52 size += *str - 'A' + 10;
57 // Check for NULL byte
58 if(*str != '\0') return NULL;
60 Log(" VFS_MemFile_Create: base=0x%x, size=0x%x", base, size);
62 // Allocate and fill node
63 ret = malloc(sizeof(tVFS_Node));
64 memset(ret, 0, sizeof(tVFS_Node));
67 ret->ImplPtr = (void*)base;
72 ret->ACLs = &gVFS_ACL_EveryoneRWX;
75 ret->Close = VFS_MemFile_Close;
76 ret->Read = VFS_MemFile_Read;
77 ret->Write = VFS_MemFile_Write;
83 * \fn void VFS_MemFile_Close(tVFS_Node *Node)
84 * \brief Dereference and clean up a memory file
86 void VFS_MemFile_Close(tVFS_Node *Node)
88 Node->ReferenceCount --;
89 if( Node->ReferenceCount == 0 ) {
96 * \fn Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
97 * \brief Read from a memory file
99 Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
101 // Check for use of free'd file
102 if(Node->ImplPtr == NULL) return 0;
104 // Check for out of bounds read
105 if(Offset > Node->Size) return 0;
107 // Truncate data read if needed
108 if(Offset + Length > Node->Size)
109 Length = Node->Size - Offset;
112 memcpy(Buffer, Node->ImplPtr+Offset, Length);
118 * \fn Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
119 * \brief Write to a memory file
121 Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
123 // Check for use of free'd file
124 if(Node->ImplPtr == NULL) return 0;
126 // Check for out of bounds read
127 if(Offset > Node->Size) return 0;
129 // Truncate data read if needed
130 if(Offset + Length > Node->Size)
131 Length = Node->Size - Offset;
134 memcpy(Node->ImplPtr+Offset, Buffer, Length);