FAT - Removed unneeded malloc() calls
authorJohn Hodge <[email protected]>
Sat, 6 Aug 2011 00:37:00 +0000 (08:37 +0800)
committerJohn Hodge <[email protected]>
Sat, 6 Aug 2011 00:37:00 +0000 (08:37 +0800)
Modules/Filesystems/FAT/fat.c

index 936ca4a..80bf391 100644 (file)
@@ -610,9 +610,9 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
 {\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
@@ -623,11 +623,6 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                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
@@ -644,7 +639,6 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                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
@@ -658,7 +652,6 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                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
@@ -688,7 +681,6 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                #if DEBUG\r
                //Debug_HexDump("FAT_Read", Buffer, Length);\r
                #endif\r
-               free(tmpBuf);\r
                LEAVE('i', 1);\r
                return Length;\r
        }\r
@@ -704,8 +696,7 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                // 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
@@ -717,8 +708,7 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        // 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
@@ -738,7 +728,6 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        //Debug_HexDump("FAT_Read", Buffer, Length);\r
        #endif\r
        \r
-       free(tmpBuf);\r
        LEAVE('X', Length);\r
        return Length;\r
 }\r
@@ -770,7 +759,7 @@ void FAT_int_WriteCluster(tFAT_VolInfo *Disk, Uint32 Cluster, void *Buffer)
 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
@@ -798,29 +787,24 @@ Uint64 FAT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        \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

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