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);
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 ++ )
{
}
Mutex_Release(&DirNode->Lock);
- return -1;
+ return -ENOENT;
}
/*
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;
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 ) {
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) {
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
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
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
// 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
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
\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
\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
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
{
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
}