Modules/FAT - Replaced literal -1 for EOC with GETFATVALUE_EOC
authorJohn Hodge <[email protected]>
Sun, 2 Sep 2012 11:55:42 +0000 (19:55 +0800)
committerJohn Hodge <[email protected]>
Sun, 2 Sep 2012 11:55:42 +0000 (19:55 +0800)
KernelLand/Modules/Filesystems/FAT/common.h
KernelLand/Modules/Filesystems/FAT/dir.c
KernelLand/Modules/Filesystems/FAT/fat.c
KernelLand/Modules/Filesystems/FAT/fatio.c

index 9402830..3983b93 100644 (file)
@@ -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);
index 96b90be..c7268d7 100644 (file)
@@ -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) {
index f7ebafe..c930497 100644 (file)
@@ -334,7 +334,7 @@ int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Clu
                        if(Cluster)     *Cluster = cluster;\r
                        cluster = FAT_int_GetFatValue(disk, cluster);\r
                        // Check for end of cluster chain\r
-                       if(cluster == 0xFFFFFFFF) {     LEAVE('i', 1);  return 1;}\r
+                       if(cluster == GETFATVALUE_EOC) { LEAVE('i', 1); return 1; }\r
                }\r
                if(Cluster)     *Cluster = cluster;\r
        }\r
@@ -417,7 +417,7 @@ size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
        for(i = preSkip; i--; )\r
        {\r
                cluster = FAT_int_GetFatValue(disk, cluster);\r
-               if(cluster == -1) {\r
+               if(cluster == GETFATVALUE_EOC) {\r
                        Log_Warning("FAT", "Offset is past end of cluster chain mark");\r
                        LEAVE('i', 0);\r
                        return 0;\r
@@ -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");\r
                // Get next cluster in the chain\r
                cluster = FAT_int_GetFatValue(disk, cluster);\r
-               if(cluster == -1) {\r
+               if(cluster == GETFATVALUE_EOC) {\r
                        Log_Warning("FAT", "Read past End of Cluster Chain (Align)");\r
                        LEAVE('X', pos);\r
                        return pos;\r
@@ -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\r
        for( ; count; count -- )\r
        {\r
-               if(cluster == -1) {\r
+               if(cluster == GETFATVALUE_EOC) {\r
                        Log_Warning("FAT", "Read past End of Cluster Chain (Bulk)");\r
                        LEAVE('X', pos);\r
                        return pos;\r
@@ -519,7 +519,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe
        while( Offset > disk->BytesPerCluster )\r
        {\r
                cluster = FAT_int_GetFatValue( disk, cluster );\r
-               if(cluster == -1) {\r
+               if(cluster == GETFATVALUE_EOC) {\r
                        Log_Warning("FAT", "EOC Unexpectedly Reached");\r
                        LEAVE('i', 0);\r
                        return 0;\r
@@ -565,7 +565,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe
                \r
                // Get next cluster (allocating if needed)\r
                tmpCluster = FAT_int_GetFatValue(disk, cluster);\r
-               if(tmpCluster == -1) {\r
+               if(tmpCluster == GETFATVALUE_EOC) {\r
                        tmpCluster = FAT_int_AllocateCluster(disk, cluster);\r
                        if( tmpCluster == 0 )\r
                                goto ret_incomplete;\r
@@ -581,7 +581,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe
                \r
                // Get next cluster (allocating if needed)\r
                tmpCluster = FAT_int_GetFatValue(disk, cluster);\r
-               if(tmpCluster == -1) {\r
+               if(tmpCluster == GETFATVALUE_EOC) {\r
                        bNewCluster = 1;\r
                        tmpCluster = FAT_int_AllocateCluster(disk, cluster);\r
                        if( tmpCluster == 0 )\r
index 340ccf8..7bf62ef 100644 (file)
@@ -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
        }

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