void FAT_int_DelLFN(tVFS_Node *Node, int ID);
#endif
int FAT_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]);
-tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name);
+tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode);
#if SUPPORT_WRITE
tVFS_Node *FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags);
{
int len = FAT_int_ConvertUTF16_to_UTF8(NULL, LongFileName);
if( len > FILENAME_MAX ) {
+ LEAVE('i', -1);
return -1;
}
FAT_int_ConvertUTF16_to_UTF8((Uint8*)Dest, LongFileName);
#if USE_LFN
}
#endif
+ LEAVE('i', 0);
return 0;
}
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;
}
/*
*/
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;
+ tFAT_LFNCache *cache = Node->Data;
// Create a cache if it isn't there
if(!cache) {
}
// Scan for this entry
- firstFree = -1;
- for( i = 0; i < cache->NumEntries; i++ )
+ int firstFree = -1;
+ for( int i = 0; i < cache->NumEntries; i++ )
{
if( cache->Entries[i].ID == ID ) {
Mutex_Release( &Node->Lock );
firstFree = i;
}
- if(firstFree == -1) {
- // Use `i` for temp length
- i = sizeof(tFAT_LFNCache) + (cache->NumEntries+1)*sizeof(tFAT_LFNCacheEnt);
- Node->Data = realloc( Node->Data, i );
- if( !Node->Data ) {
- Log_Error("FAT", "realloc() fail, unable to allocate %i for LFN cache", i);
+ int cache_entry = firstFree;
+
+ if(firstFree == -1)
+ {
+ size_t newsize = offsetof(tFAT_LFNCache, Entries[cache->NumEntries+1]);
+ tFAT_LFNCache *new_alloc = realloc( Node->Data, newsize );
+ if( !new_alloc ) {
+ Log_Error("FAT", "realloc() fail, unable to allocate %zi for LFN cache", newsize);
Mutex_Release( &Node->Lock );
return NULL;
}
+ Node->Data = new_alloc;
//Log_Debug("FAT", "Realloc (%i)\n", i);
cache = Node->Data;
- i = cache->NumEntries;
+ cache_entry = cache->NumEntries;
cache->NumEntries ++;
}
- else {
- i = firstFree;
+ else
+ {
+ cache_entry = firstFree;
}
// Create new entry
- cache->Entries[ i ].ID = ID;
- cache->Entries[ i ].Data[0] = '\0';
+ cache->Entries[ cache_entry ].ID = ID;
+ cache->Entries[ cache_entry ].Data[0] = '\0';
Mutex_Release( &Node->Lock );
//Log_Debug("FAT", "Return = %p (firstFree, i = %i)", cache->Entries[i].Data, i);
- return cache->Entries[ i ].Data;
+ return cache->Entries[ cache_entry ].Data;
}
/**
* \fn tVFS_Node *FAT_FindDir(tVFS_Node *node, char *name)
* \brief Finds an entry in the current directory
*/
-tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name)
+tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
{
fat_filetable fileent;
if( ret ) {
if( (ret->Inode >> 32) != 0 ) {
LOG("Node in cache, quick return");
+ LEAVE('p', ret);
return ret;
}
else {
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) {