int giFAT_MaxCachedClusters = 1024*512/4;\r
\r
// === SEMI-GLOBALS ===\r
-MODULE_DEFINE(0, VER2(1,1) /*v1.01*/, VFAT, FAT_Install, NULL, NULL);\r
+MODULE_DEFINE(0, VER2(0,80) /*v0.80*/, VFAT, FAT_Install, NULL, NULL);\r
tFAT_VolInfo gFAT_Disks[8];\r
int giFAT_PartCount = 0;\r
tVFS_Driver gFAT_FSInfo = {"fat", 0, FAT_InitDevice, FAT_Unmount, FAT_GetNodeFromINode, NULL};\r
ENTER("pNode XOffset", Node, Offset);\r
\r
cluster = base_cluster = Node->Inode & 0xFFFFFFF; // Cluster ID\r
- LOG("base cluster = 0x%07x", cluster);\r
+// LOG("base cluster = 0x%07x", cluster);\r
\r
// Do Cluster Skip\r
// - Pre FAT32 had a reserved area for the root.\r
}\r
else {\r
// TODO: Bounds checking on root\r
- LOG("Root cluster count %i", disk->bootsect.files_in_root*32/disk->BytesPerCluster);\r
+// LOG("Root cluster count %i", disk->bootsect.files_in_root*32/disk->BytesPerCluster);\r
// Increment by clusters in offset\r
cluster += Offset / disk->BytesPerCluster;\r
}\r
\r
- LOG("cluster = 0x%07x", cluster);\r
+// LOG("cluster = 0x%07x", cluster);\r
\r
// Bounds Checking (Used to spot corruption)\r
if(cluster > disk->ClusterCount + 2)\r
int remLength = Length;\r
Uint32 cluster, tmpCluster;\r
int bNewCluster = 0;\r
+ off_t original_offset = Offset;\r
\r
if(Offset > Node->Size) return 0;\r
\r
+ ENTER("pNode Xoffset xlength pbuffer", Node, Offset, Length, Buffer);\r
+ \r
// Seek Clusters\r
cluster = Node->Inode & 0xFFFFFFFF;\r
while( Offset > disk->BytesPerCluster )\r
cluster = FAT_int_GetFatValue( disk, cluster );\r
if(cluster == -1) {\r
Log_Warning("FAT", "EOC Unexpectedly Reached");\r
+ LEAVE('i', 0);\r
return 0;\r
}\r
Offset -= disk->BytesPerCluster;\r
if( Offset == disk->BytesPerCluster )\r
{\r
Uint32 tmp = FAT_int_AllocateCluster(disk, cluster);\r
- if(!tmp) return 0;\r
+ if(!tmp) {\r
+ LEAVE('i', 0);\r
+ return 0;\r
+ }\r
cluster = tmp;\r
Offset -= disk->BytesPerCluster;\r
}\r
{\r
char tmpBuf[disk->BytesPerCluster];\r
\r
+ LOG("Read-Modify-Write single");\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
- return Length;\r
+ goto return_full;\r
}\r
\r
// Clean up changes within a cluster\r
if( Offset )\r
{ \r
+ LOG("Read-Modify-Write first");\r
+\r
// Read-Modify-Write\r
FAT_int_ReadCluster( disk, cluster, disk->BytesPerCluster, tmpBuf );\r
memcpy( tmpBuf + Offset, Buffer, disk->BytesPerCluster - Offset );\r
tmpCluster = FAT_int_GetFatValue(disk, cluster);\r
if(tmpCluster == -1) {\r
tmpCluster = FAT_int_AllocateCluster(disk, cluster);\r
- if( tmpCluster == 0 ) {\r
- return Length - remLength;\r
- }\r
+ if( tmpCluster == 0 )\r
+ goto ret_incomplete;\r
}\r
cluster = tmpCluster;\r
}\r
{\r
FAT_int_WriteCluster( disk, cluster, Buffer );\r
Buffer += disk->BytesPerCluster;\r
+ remLength -= disk->BytesPerCluster;\r
\r
// Get next cluster (allocating if needed)\r
tmpCluster = FAT_int_GetFatValue(disk, cluster);\r
if(tmpCluster == -1) {\r
bNewCluster = 1;\r
tmpCluster = FAT_int_AllocateCluster(disk, cluster);\r
- if( tmpCluster == 0 ) {\r
- return Length - remLength;\r
- }\r
+ if( tmpCluster == 0 )\r
+ goto ret_incomplete;\r
}\r
cluster = tmpCluster;\r
}\r
\r
// Finish off\r
- if( bNewCluster )\r
- memset(tmpBuf, 0, disk->BytesPerCluster);\r
- else\r
- FAT_int_ReadCluster( disk, cluster, disk->BytesPerCluster, tmpBuf );\r
- memcpy( tmpBuf, Buffer, remLength );\r
- FAT_int_WriteCluster( disk, cluster, tmpBuf );\r
- free( tmpBuf );\r
- \r
+ if( remLength )\r
+ {\r
+ if( bNewCluster )\r
+ memset(tmpBuf, 0, disk->BytesPerCluster);\r
+ else\r
+ FAT_int_ReadCluster( disk, cluster, disk->BytesPerCluster, tmpBuf );\r
+ memcpy( tmpBuf, Buffer, remLength );\r
+ FAT_int_WriteCluster( disk, cluster, tmpBuf );\r
+ }\r
+\r
+return_full:\r
+ if( original_offset + Length > Node->Size ) {\r
+ Node->Size = original_offset + Length;\r
+ LOG("Updated size to %x", Node->Size);\r
+ Node->ImplInt |= FAT_FLAG_DIRTY;\r
+ }\r
+\r
+ LEAVE('i', Length);\r
+ return Length;\r
+ret_incomplete:\r
+ LOG("Write incomplete");\r
+ Length -= remLength;\r
+ if( original_offset + Length > Node->Size ) {\r
+ Node->Size = original_offset + Length; \r
+ Node->ImplInt |= FAT_FLAG_DIRTY;\r
+ }\r
+ LEAVE('i', Length);\r
return Length;\r
}\r
#endif\r
{\r
tFAT_VolInfo *disk = Node->ImplPtr;\r
if(Node == NULL) return ;\r
- \r
+\r
+ ENTER("pNode", Node); \r
+\r
#if SUPPORT_WRITE\r
// Update the node if it's dirty (don't bother if it's marked for\r
// deletion)\r
dirnode = FAT_int_CreateIncompleteDirNode(disk, Node->Inode >> 32);\r
if( !dirnode ) {\r
Log_Error("FAT", "Can't get node for directory cluster #0x%x", Node->Inode>>32);\r
+ LEAVE('-');\r
return ;\r
}\r
\r
Node->ImplInt &= ~FAT_FLAG_DIRTY;\r
}\r
#endif\r
+\r
+ Uint32 cluster = Node->Inode;\r
+ Uint32 implint = Node->ImplInt;\r
\r
- // TODO: Make this more thread safe somehow, probably by moving the\r
- // Inode_UncacheNode higher up and saving the cluster value somewhere\r
- if( Node->ReferenceCount == 1 )\r
- { \r
- #if SUPPORT_WRITE\r
+ #if SUPPORT_WRITE\r
+ if( FAT_int_DerefNode(Node) == 1 )\r
+ {\r
+ LOG("implint = %x", implint);\r
// Delete File\r
- if( Node->ImplInt & FAT_FLAG_DELETE ) {\r
+ if( implint & FAT_FLAG_DELETE ) {\r
+ Log_Debug("FAT", "Deallocating chain stating at 0x%07x", cluster);\r
// Since the node is marked, we only need to remove it's data\r
- Uint32 cluster = Node->Inode & 0xFFFFFFFF;\r
while( cluster != -1 )\r
- cluster = FAT_int_FreeCluster(Node->ImplPtr, cluster);\r
+ cluster = FAT_int_FreeCluster(disk, cluster);\r
}\r
- #endif\r
}\r
- \r
- FAT_int_DerefNode(Node);\r
- return ;\r
+ #endif\r
+ LEAVE('-');\r
}\r