4 * - Memory Pseudo Files
10 tVFS_Node *VFS_MemFile_Create(const char *Path);
11 void VFS_MemFile_Close(tVFS_Node *Node);
12 size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags);
13 size_t VFS_MemFile_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags);
16 tVFS_NodeType gVFS_MemFileType = {
17 .Close = VFS_MemFile_Close,
18 .Read = VFS_MemFile_Read,
19 .Write = VFS_MemFile_Write
24 * \fn tVFS_Node *VFS_MemFile_Create(const char *Path)
26 tVFS_Node *VFS_MemFile_Create(const char *Path)
29 const char *str = Path;
36 for( ; ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'F'); str++ )
39 if('A' <= *str && *str <= 'F')
40 base += *str - 'A' + 10;
46 if(*str++ != ':') return NULL;
50 for( ; ('0' <= *str && *str <= '9') || ('A' <= *str && *str <= 'F'); str++ )
53 if('A' <= *str && *str <= 'F')
54 size += *str - 'A' + 10;
59 // Check for NULL byte
60 if(*str != '\0') return NULL;
62 // Allocate and fill node
63 ret = malloc(sizeof(tVFS_Node));
64 memset(ret, 0, sizeof(tVFS_Node));
68 ret->ImplPtr = (void*)base;
73 ret->ACLs = &gVFS_ACL_EveryoneRWX;
76 ret->Type = &gVFS_MemFileType;
82 * \fn void VFS_MemFile_Close(tVFS_Node *Node)
83 * \brief Dereference and clean up a memory file
85 void VFS_MemFile_Close(tVFS_Node *Node)
87 Node->ReferenceCount --;
88 if( Node->ReferenceCount == 0 ) {
95 * \brief Read from a memory file
97 size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags)
99 // Check for use of free'd file
100 if(Node->ImplPtr == NULL) return 0;
102 // Check for out of bounds read
103 if(Offset > Node->Size) return 0;
105 // Truncate data read if needed
106 if(Length > Node->Size)
108 if(Offset + Length > Node->Size)
109 Length = Node->Size - Offset;
112 memcpy(Buffer, (Uint8*)Node->ImplPtr + Offset, Length);
118 * \brief Write to a memory file
120 size_t VFS_MemFile_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags)
122 // Check for use of free'd file
123 if(Node->ImplPtr == NULL) return 0;
125 // Check for out of bounds read
126 if(Offset > Node->Size) return 0;
128 // Truncate data read if needed
129 if(Length > Node->Size)
131 if(Offset + Length > Node->Size)
132 Length = Node->Size - Offset;
135 memcpy((Uint8*)Node->ImplPtr + Offset, Buffer, Length);