X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FFilesystems%2FFAT%2Ffat.c;h=26b1961396ae65aab08e66e8eeff28bc791291e4;hb=18a6f0a17a50c25007a8f9b910af02bdf6fbcb78;hp=e3a681af8b2e9afc6ba39a2f7d3eafa246be08e2;hpb=586a47ab9343a85c944a2cf7b27a74cf459a8423;p=tpg%2Facess2.git diff --git a/Modules/Filesystems/FAT/fat.c b/Modules/Filesystems/FAT/fat.c index e3a681af..26b19613 100644 --- a/Modules/Filesystems/FAT/fat.c +++ b/Modules/Filesystems/FAT/fat.c @@ -40,6 +40,7 @@ typedef struct sFAT_LFNCacheEnt { int ID; + // TODO: Handle UTF16 names correctly char Data[256]; } tFAT_LFNCacheEnt; /** @@ -73,10 +74,10 @@ Uint64 FAT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); #endif // --- Directory IO char *FAT_ReadDir(tVFS_Node *Node, int ID); -tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name); #if SUPPORT_WRITE - int FAT_Mknod(tVFS_Node *Node, char *Name, Uint Flags); - int FAT_Relink(tVFS_Node *node, char *OldName, char *NewName); + int FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags); + int FAT_Relink(tVFS_Node *node, const char *OldName, const char *NewName); #endif void FAT_CloseFile(tVFS_Node *node); @@ -393,7 +394,7 @@ Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) Uint32 val = 0; Uint32 ofs; ENTER("pDisk xCluster", Disk, cluster); - LOCK( &Disk->lFAT ); + Mutex_Acquire( &Disk->lFAT ); #if CACHE_FAT if( Disk->ClusterCount <= giFAT_MaxCachedClusters ) { @@ -420,7 +421,7 @@ Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) #if CACHE_FAT } #endif /*CACHE_FAT*/ - RELEASE( &Disk->lFAT ); + Mutex_Release( &Disk->lFAT ); LEAVE('x', val); return val; } @@ -920,6 +921,10 @@ char *FAT_int_CreateName(fat_filetable *ft, char *LongFileName) { #endif ret = (char*) malloc(13); + if( !ret ) { + Log_Warning("FAT", "FAT_int_CreateName: malloc(13) failed"); + return NULL; + } FAT_int_ProperFilename(ret, ft->name); #if USE_LFN } @@ -941,6 +946,7 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry, int Pos) tFAT_VolInfo *disk = Parent->ImplPtr; ENTER("pParent pFT", Parent, Entry); + LOG("disk = %p", disk); memset(&node, 0, sizeof(tVFS_Node)); @@ -1098,12 +1104,7 @@ int FAT_int_WriteDirEntry(tVFS_Node *Node, int ID, fat_filetable *Entry) } #endif -#if USE_LFN -// I should probably more tightly associate the LFN cache with the node -// somehow, maybe by adding a field to tVFS_Node before locking it -// Maybe .Cache or something like that (something that is free'd by the -// Inode_UncacheNode function) - +#if USE_LFN /** * \fn char *FAT_int_GetLFN(tVFS_Node *node) * \brief Return pointer to LFN cache entry @@ -1240,32 +1241,29 @@ char *FAT_ReadDir(tVFS_Node *Node, int ID) if(fileinfo[a].attrib == ATTR_LFN) { fat_longfilename *lfnInfo; - int len; lfnInfo = (fat_longfilename *) &fileinfo[a]; // Get cache for corresponding file + // > ID + Index gets the corresponding short node lfn = FAT_int_GetLFN( Node, ID + (lfnInfo->id & 0x3F) ); // Bit 6 indicates the start of an entry if(lfnInfo->id & 0x40) memset(lfn, 0, 256); - // Get the current length - len = strlen(lfn); + a = (lfnInfo->id & 0x3F) * 13; // Sanity Check (FAT implementations should not allow >255 character names) - if(len + 13 > 255) return VFS_SKIP; - // Rebase all bytes - for(a=len+1;a--;) lfn[a+13] = lfn[a]; + if(a > 255) return VFS_SKIP; // Append new bytes - lfn[ 0] = lfnInfo->name1[0]; lfn[ 1] = lfnInfo->name1[1]; - lfn[ 2] = lfnInfo->name1[2]; lfn[ 3] = lfnInfo->name1[3]; - lfn[ 4] = lfnInfo->name1[4]; - lfn[ 5] = lfnInfo->name2[0]; lfn[ 6] = lfnInfo->name2[1]; - lfn[ 7] = lfnInfo->name2[2]; lfn[ 8] = lfnInfo->name2[3]; - lfn[ 9] = lfnInfo->name2[4]; lfn[10] = lfnInfo->name2[5]; - lfn[11] = lfnInfo->name3[0]; lfn[12] = lfnInfo->name3[1]; + lfn[a+ 0] = lfnInfo->name1[0]; lfn[a+ 1] = lfnInfo->name1[1]; + lfn[a+ 2] = lfnInfo->name1[2]; lfn[a+ 3] = lfnInfo->name1[3]; + lfn[a+ 4] = lfnInfo->name1[4]; + lfn[a+ 5] = lfnInfo->name2[0]; lfn[a+ 6] = lfnInfo->name2[1]; + lfn[a+ 7] = lfnInfo->name2[2]; lfn[a+ 8] = lfnInfo->name2[3]; + lfn[a+ 9] = lfnInfo->name2[4]; lfn[a+10] = lfnInfo->name2[5]; + lfn[a+11] = lfnInfo->name3[0]; lfn[a+12] = lfnInfo->name3[1]; LOG("lfn = '%s'", lfn); LEAVE('p', VFS_SKIP); return VFS_SKIP; @@ -1303,7 +1301,7 @@ char *FAT_ReadDir(tVFS_Node *Node, int ID) * \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, char *Name) +tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name) { fat_filetable fileinfo[16]; char tmpName[13];