4 * - Memory Pseudo Files
10 tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path);
11 void VFS_MemFile_Close(tVFS_Node *Node);
12 Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
13 Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
16 tVFS_Node gVFS_MemRoot = {
17 .Flags = VFS_FFLAG_DIRECTORY,
19 .FindDir = VFS_MemFile_Create
24 * \fn tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
25 * \note Treated as finddir by VFS_ParsePath
27 tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path)
37 for( ; ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'F'); str++ )
40 if('A' <= *str && *str <= 'F')
41 base += *str - 'A' + 10;
47 if(*str++ != ':') return NULL;
51 for( ; ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'F'); str++ )
54 if('A' <= *str && *str <= 'F')
55 size += *str - 'A' + 10;
60 // Check for NULL byte
61 if(*str != '\0') return NULL;
63 Log(" VFS_MemFile_Create: base=0x%x, size=0x%x", base, size);
65 // Allocate and fill node
66 ret = malloc(sizeof(tVFS_Node));
67 memset(ret, 0, sizeof(tVFS_Node));
70 ret->ImplPtr = (void*)base;
75 ret->ACLs = &gVFS_ACL_EveryoneRWX;
78 ret->Close = VFS_MemFile_Close;
79 ret->Read = VFS_MemFile_Read;
80 ret->Write = VFS_MemFile_Write;
86 * \fn void VFS_MemFile_Close(tVFS_Node *Node)
87 * \brief Dereference and clean up a memory file
89 void VFS_MemFile_Close(tVFS_Node *Node)
91 Node->ReferenceCount --;
92 if( Node->ReferenceCount == 0 ) {
99 * \fn Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
100 * \brief Read from a memory file
102 Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
104 // Check for use of free'd file
105 if(Node->ImplPtr == NULL) return 0;
107 // Check for out of bounds read
108 if(Offset > Node->Size) return 0;
110 // Truncate data read if needed
111 if(Offset + Length > Node->Size)
112 Length = Node->Size - Offset;
115 memcpy(Buffer, Node->ImplPtr+Offset, Length);
121 * \fn Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
122 * \brief Write to a memory file
124 Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
126 // Check for use of free'd file
127 if(Node->ImplPtr == NULL) return 0;
129 // Check for out of bounds read
130 if(Offset > Node->Size) return 0;
132 // Truncate data read if needed
133 if(Offset + Length > Node->Size)
134 Length = Node->Size - Offset;
137 memcpy(Node->ImplPtr+Offset, Buffer, Length);