From 07f5b8fe9112ab19cf7a4794026764b8ea7a8e91 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 2 Sep 2012 19:55:42 +0800 Subject: [PATCH] Modules/FAT - Replaced literal -1 for EOC with GETFATVALUE_EOC --- KernelLand/Modules/Filesystems/FAT/common.h | 1 + KernelLand/Modules/Filesystems/FAT/dir.c | 19 ++++++++++++++----- KernelLand/Modules/Filesystems/FAT/fat.c | 14 +++++++------- KernelLand/Modules/Filesystems/FAT/fatio.c | 13 +++++++------ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/KernelLand/Modules/Filesystems/FAT/common.h b/KernelLand/Modules/Filesystems/FAT/common.h index 9402830b..3983b93c 100644 --- a/KernelLand/Modules/Filesystems/FAT/common.h +++ b/KernelLand/Modules/Filesystems/FAT/common.h @@ -97,6 +97,7 @@ extern int FAT_int_DerefNode(tVFS_Node *Node); extern void FAT_int_ClearNodeCache(tFAT_VolInfo *Disk); // --- FAT Access --- +#define GETFATVALUE_EOC 0xFFFFFFFF extern Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 Cluster); #if SUPPORT_WRITE extern Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous); diff --git a/KernelLand/Modules/Filesystems/FAT/dir.c b/KernelLand/Modules/Filesystems/FAT/dir.c index 96b90beb..c7268d73 100644 --- a/KernelLand/Modules/Filesystems/FAT/dir.c +++ b/KernelLand/Modules/Filesystems/FAT/dir.c @@ -278,7 +278,10 @@ int FAT_int_GetEntryByCluster(tVFS_Node *DirNode, Uint32 Cluster, fat_filetable fat_filetable fileinfo[ents_per_sector]; int i, sector; - Mutex_Acquire(&DirNode->Lock); + if( Mutex_Acquire(&DirNode->Lock) ) { + return -EINTR; + } + sector = 0; for( i = 0; ; i ++ ) { @@ -318,7 +321,7 @@ int FAT_int_GetEntryByCluster(tVFS_Node *DirNode, Uint32 Cluster, fat_filetable } Mutex_Release(&DirNode->Lock); - return -1; + return -ENOENT; } /* @@ -445,7 +448,9 @@ Uint16 *FAT_int_GetLFN(tVFS_Node *Node, int ID) tFAT_LFNCache *cache; int i, firstFree; - Mutex_Acquire( &Node->Lock ); + if( Mutex_Acquire( &Node->Lock ) ) { + return NULL; + } // TODO: Thread Safety (Lock things) cache = Node->Data; @@ -813,7 +818,9 @@ int FAT_Link(tVFS_Node *DirNode, const char *NewName, tVFS_Node *NewNode) const int eps = 512 / sizeof(fat_filetable); fat_filetable fileinfo[eps]; - Mutex_Acquire( &DirNode->Lock ); + if( Mutex_Acquire( &DirNode->Lock ) ) { + return EINTR; + } // -- Ensure duplicates aren't created -- if( FAT_int_GetEntryByName(DirNode, NewName, &ft) >= 0 ) { @@ -1097,7 +1104,9 @@ int FAT_Unlink(tVFS_Node *Node, const char *OldName) tVFS_Node *child; fat_filetable ft; - Mutex_Acquire(&Node->Lock); + if( Mutex_Acquire(&Node->Lock) ) { + return EINTR; + } int id = FAT_int_GetEntryByName(Node, OldName, &ft); if(id == -1) { diff --git a/KernelLand/Modules/Filesystems/FAT/fat.c b/KernelLand/Modules/Filesystems/FAT/fat.c index f7ebafe5..c9304976 100644 --- a/KernelLand/Modules/Filesystems/FAT/fat.c +++ b/KernelLand/Modules/Filesystems/FAT/fat.c @@ -334,7 +334,7 @@ int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Clu if(Cluster) *Cluster = cluster; cluster = FAT_int_GetFatValue(disk, cluster); // Check for end of cluster chain - if(cluster == 0xFFFFFFFF) { LEAVE('i', 1); return 1;} + if(cluster == GETFATVALUE_EOC) { LEAVE('i', 1); return 1; } } if(Cluster) *Cluster = cluster; } @@ -417,7 +417,7 @@ size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) for(i = preSkip; i--; ) { cluster = FAT_int_GetFatValue(disk, cluster); - if(cluster == -1) { + if(cluster == GETFATVALUE_EOC) { Log_Warning("FAT", "Offset is past end of cluster chain mark"); LEAVE('i', 0); return 0; @@ -443,7 +443,7 @@ size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) LOG("pos = %i, Reading the rest of the clusters"); // Get next cluster in the chain cluster = FAT_int_GetFatValue(disk, cluster); - if(cluster == -1) { + if(cluster == GETFATVALUE_EOC) { Log_Warning("FAT", "Read past End of Cluster Chain (Align)"); LEAVE('X', pos); return pos; @@ -461,7 +461,7 @@ size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) // Read the rest of the cluster data for( ; count; count -- ) { - if(cluster == -1) { + if(cluster == GETFATVALUE_EOC) { Log_Warning("FAT", "Read past End of Cluster Chain (Bulk)"); LEAVE('X', pos); return pos; @@ -519,7 +519,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe while( Offset > disk->BytesPerCluster ) { cluster = FAT_int_GetFatValue( disk, cluster ); - if(cluster == -1) { + if(cluster == GETFATVALUE_EOC) { Log_Warning("FAT", "EOC Unexpectedly Reached"); LEAVE('i', 0); return 0; @@ -565,7 +565,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe // Get next cluster (allocating if needed) tmpCluster = FAT_int_GetFatValue(disk, cluster); - if(tmpCluster == -1) { + if(tmpCluster == GETFATVALUE_EOC) { tmpCluster = FAT_int_AllocateCluster(disk, cluster); if( tmpCluster == 0 ) goto ret_incomplete; @@ -581,7 +581,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe // Get next cluster (allocating if needed) tmpCluster = FAT_int_GetFatValue(disk, cluster); - if(tmpCluster == -1) { + if(tmpCluster == GETFATVALUE_EOC) { bNewCluster = 1; tmpCluster = FAT_int_AllocateCluster(disk, cluster); if( tmpCluster == 0 ) diff --git a/KernelLand/Modules/Filesystems/FAT/fatio.c b/KernelLand/Modules/Filesystems/FAT/fatio.c index 340ccf82..7bf62efc 100644 --- a/KernelLand/Modules/Filesystems/FAT/fatio.c +++ b/KernelLand/Modules/Filesystems/FAT/fatio.c @@ -20,14 +20,15 @@ Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) Uint32 val = 0; Uint32 ofs; ENTER("pDisk xCluster", Disk, cluster); + Mutex_Acquire( &Disk->lFAT ); #if CACHE_FAT if( Disk->ClusterCount <= giFAT_MaxCachedClusters ) { val = Disk->FATCache[cluster]; - if(Disk->type == FAT12 && val == EOC_FAT12) val = -1; - if(Disk->type == FAT16 && val == EOC_FAT16) val = -1; - if(Disk->type == FAT32 && val == EOC_FAT32) val = -1; + if(Disk->type == FAT12 && val == EOC_FAT12) val = GETFATVALUE_EOC; + if(Disk->type == FAT16 && val == EOC_FAT16) val = GETFATVALUE_EOC; + if(Disk->type == FAT32 && val == EOC_FAT32) val = GETFATVALUE_EOC; } else { @@ -37,13 +38,13 @@ Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) VFS_ReadAt(Disk->fileHandle, ofs+(cluster/2)*3, 3, &val); LOG("3 bytes at 0x%x are (Uint32)0x%x", ofs+(cluster/2)*3, val); val = (cluster & 1) ? (val>>12) : (val & 0xFFF); - if(val == EOC_FAT12) val = -1; + if(val == EOC_FAT12) val = GETFATVALUE_EOC; } else if(Disk->type == FAT16) { VFS_ReadAt(Disk->fileHandle, ofs+cluster*2, 2, &val); - if(val == EOC_FAT16) val = -1; + if(val == EOC_FAT16) val = GETFATVALUE_EOC; } else { VFS_ReadAt(Disk->fileHandle, ofs+cluster*4, 4, &val); - if(val == EOC_FAT32) val = -1; + if(val == EOC_FAT32) val = GETFATVALUE_EOC; } #if CACHE_FAT } -- 2.20.1