// === PROTOTYPES ===\r
// --- Driver Core\r
int FAT_Install(char **Arguments);\r
-tVFS_Node *FAT_InitDevice(char *device, char **options);\r
+tVFS_Node *FAT_InitDevice(const char *device, const char **options);\r
void FAT_Unmount(tVFS_Node *Node);\r
// --- Helpers\r
int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Cluster);\r
}\r
\r
/**\r
- * \fn tVFS_Node *FAT_InitDevice(char *Device, char **Options)\r
* \brief Reads the boot sector of a disk and prepares the structures for it\r
*/\r
-tVFS_Node *FAT_InitDevice(char *Device, char **Options)\r
+tVFS_Node *FAT_InitDevice(const char *Device, const char **Options)\r
{\r
fat_bootsect *bs;\r
int i;\r
{\r
char *ret;\r
ENTER("pft sLongFileName", ft, LongFileName);\r
+ //Log_Debug("FAT", "FAT_int_CreateName(ft=%p, LongFileName=%p'%s')", ft, LongFileName);\r
#if USE_LFN\r
if(LongFileName && LongFileName[0] != '\0')\r
{ \r
tFAT_LFNCache *cache;\r
int i, firstFree;\r
\r
+ Mutex_Acquire( &Node->Lock );\r
+ \r
// TODO: Thread Safety (Lock things)\r
cache = Node->Data;\r
\r
cache->NumEntries = 1;\r
cache->Entries[0].ID = ID;\r
cache->Entries[0].Data[0] = '\0';\r
+ Mutex_Release( &Node->Lock );\r
+ //Log_Debug("FAT", "Return = %p (new)", cache->Entries[0].Data);\r
return cache->Entries[0].Data;\r
}\r
\r
- // Scan for a current entry\r
+ // Scan for this entry\r
firstFree = -1;\r
for( i = 0; i < cache->NumEntries; i++ )\r
{\r
- if( cache->Entries[i].ID == ID )\r
+ if( cache->Entries[i].ID == ID ) {\r
+ Mutex_Release( &Node->Lock );\r
+ //Log_Debug("FAT", "Return = %p (match)", cache->Entries[i].Data);\r
return cache->Entries[i].Data;\r
+ }\r
if( cache->Entries[i].ID == -1 && firstFree == -1 )\r
firstFree = i;\r
}\r
i = sizeof(tFAT_LFNCache) + (cache->NumEntries+1)*sizeof(tFAT_LFNCacheEnt);\r
Node->Data = realloc( Node->Data, i );\r
if( !Node->Data ) {\r
- Log_Error("FAT", "malloc() fail, unable to allocate %i for LFN cache", i);\r
+ Log_Error("FAT", "realloc() fail, unable to allocate %i for LFN cache", i);\r
+ Mutex_Release( &Node->Lock );\r
return NULL;\r
}\r
+ //Log_Debug("FAT", "Realloc (%i)\n", i);\r
cache = Node->Data;\r
i = cache->NumEntries;\r
cache->NumEntries ++;\r
cache->Entries[ i ].ID = ID;\r
cache->Entries[ i ].Data[0] = '\0';\r
\r
- //TODO: Unlock\r
+ Mutex_Release( &Node->Lock );\r
+ //Log_Debug("FAT", "Return = %p (firstFree, i = %i)", cache->Entries[i].Data, i);\r
return cache->Entries[ i ].Data;\r
}\r
\r
// Bit 6 indicates the start of an entry\r
if(lfnInfo->id & 0x40) memset(lfn, 0, 256);\r
\r
- a = (lfnInfo->id & 0x3F) * 13;\r
+ a = ((lfnInfo->id & 0x3F) - 1) * 13;\r
+ //Log_Debug("FAT", "ID = 0x%02x, a = %i", lfnInfo->id, a);\r
\r
// Sanity Check (FAT implementations should not allow >255 character names)\r
if(a > 255) return VFS_SKIP;\r
lfn[a+ 9] = lfnInfo->name2[4]; lfn[a+10] = lfnInfo->name2[5];\r
lfn[a+11] = lfnInfo->name3[0]; lfn[a+12] = lfnInfo->name3[1];\r
LOG("lfn = '%s'", lfn);\r
+ //Log_Debug("FAT", "lfn = '%s'", lfn);\r
LEAVE('p', VFS_SKIP);\r
return VFS_SKIP;\r
}\r
LEAVE('p', VFS_SKIP);\r
return VFS_SKIP;\r
}\r
- // Ignore . and ..\r
- if(fileinfo[a].name[0] == '.') {\r
+ // Ignore .\r
+ if(fileinfo[a].name[0] == '.' && fileinfo[a].name[1] == ' ') {\r
LEAVE('p', VFS_SKIP);\r
return VFS_SKIP;\r
- } \r
+ }\r
+ // and ..\r
+ if(fileinfo[a].name[0] == '.' && fileinfo[a].name[1] == '.' && fileinfo[a].name[2] == ' ') {\r
+ LEAVE('p', VFS_SKIP);\r
+ return VFS_SKIP;\r
+ }\r
\r
LOG("name='%c%c%c%c%c%c%c%c.%c%c%c'",\r
fileinfo[a].name[0], fileinfo[a].name[1], fileinfo[a].name[2], fileinfo[a].name[3],\r
\r
#if USE_LFN\r
lfn = FAT_int_GetLFN(Node, ID);\r
+ //Log_Debug("FAT", "lfn = %p'%s'", lfn, lfn);\r
ret = FAT_int_CreateName(&fileinfo[a], lfn);\r
#else\r
ret = FAT_int_CreateName(&fileinfo[a], NULL);\r