{\r
int preSkip, count;\r
int i, cluster, pos;\r
- int bpc;\r
- void *tmpBuf;\r
tFAT_VolInfo *disk = Node->ImplPtr;\r
+ char tmpBuf[disk->BytesPerCluster];\r
+ int bpc = disk->BytesPerCluster;\r
\r
ENTER("pNode Xoffset Xlength pbuffer", Node, Offset, Length, Buffer);\r
\r
return 0;\r
}\r
\r
- // Calculate and Allocate Bytes Per Cluster\r
- bpc = disk->BytesPerCluster;\r
- tmpBuf = (void*) malloc(bpc);\r
- if( !tmpBuf ) return 0;\r
- \r
// Cluster is stored in the low 32-bits of the Inode field\r
cluster = Node->Inode & 0xFFFFFFFF;\r
\r
LOG("First cluster only");\r
FAT_int_ReadCluster(disk, cluster, bpc, tmpBuf);\r
memcpy( Buffer, (void*)( tmpBuf + Offset%bpc ), Length );\r
- free(tmpBuf);\r
#if DEBUG\r
//Debug_HexDump("FAT_Read", Buffer, Length);\r
#endif\r
cluster = FAT_int_GetFatValue(disk, cluster);\r
if(cluster == -1) {\r
Log_Warning("FAT", "Offset is past end of cluster chain mark");\r
- free(tmpBuf);\r
LEAVE('i', 0);\r
return 0;\r
}\r
#if DEBUG\r
//Debug_HexDump("FAT_Read", Buffer, Length);\r
#endif\r
- free(tmpBuf);\r
LEAVE('i', 1);\r
return Length;\r
}\r
// Get next cluster in the chain\r
cluster = FAT_int_GetFatValue(disk, cluster);\r
if(cluster == -1) {\r
- Warning("FAT_Read - Read past End of Cluster Chain");\r
- free(tmpBuf);\r
+ Log_Warning("FAT", "FAT_Read: Read past End of Cluster Chain");\r
LEAVE('i', 0);\r
return 0;\r
}\r
// Get next cluster in the chain\r
cluster = FAT_int_GetFatValue(disk, cluster);\r
if(cluster == -1) {\r
- Warning("FAT_Read - Read past End of Cluster Chain");\r
- free(tmpBuf);\r
+ Log_Warning("FAT", "FAT_Read: Read past End of Cluster Chain");\r
LEAVE('i', 0);\r
return 0;\r
}\r
//Debug_HexDump("FAT_Read", Buffer, Length);\r
#endif\r
\r
- free(tmpBuf);\r
LEAVE('X', Length);\r
return Length;\r
}\r
Uint64 FAT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)\r
{\r
tFAT_VolInfo *disk = Node->ImplPtr;\r
- void *tmpBuf;\r
+ char tmpBuf[disk->BytesPerCluster];\r
int remLength = Length;\r
Uint32 cluster, tmpCluster;\r
int bNewCluster = 0;\r
\r
if( Offset + Length < disk->BytesPerCluster )\r
{\r
- tmpBuf = malloc( disk->BytesPerCluster );\r
+ char tmpBuf[disk->BytesPerCluster];\r
\r
// Read-Modify-Write\r
FAT_int_ReadCluster( disk, cluster, disk->BytesPerCluster, tmpBuf );\r
memcpy( tmpBuf + Offset, Buffer, Length );\r
FAT_int_WriteCluster( disk, cluster, tmpBuf );\r
\r
- free(tmpBuf);\r
return Length;\r
}\r
\r
// Clean up changes within a cluster\r
if( Offset )\r
- {\r
- tmpBuf = malloc( disk->BytesPerCluster );\r
- \r
+ { \r
// Read-Modify-Write\r
FAT_int_ReadCluster( disk, cluster, disk->BytesPerCluster, tmpBuf );\r
memcpy( tmpBuf + Offset, Buffer, disk->BytesPerCluster - Offset );\r
FAT_int_WriteCluster( disk, cluster, tmpBuf );\r
\r
- free(tmpBuf);\r
- \r
remLength -= disk->BytesPerCluster - Offset;\r
Buffer += disk->BytesPerCluster - Offset;\r
\r