Merge branch 'master' of [email protected]:acess2
[tpg/acess2.git] / Modules / Filesystems / FAT / fat.c
index 25b9cb0..93911de 100644 (file)
@@ -3,7 +3,7 @@
  * FAT12/16/32 Driver Version (Incl LFN)\r
  * \r
  * NOTE: This driver will only support _reading_ long file names, not\r
- * writing. I don't even know why i'm adding write-support. FAT sucks.\r
+ * writing. I don't even know why I'm adding write-support. FAT sucks.\r
  * \r
  * Known Bugs:\r
  * - LFN Is buggy in FAT_ReadDir\r
@@ -238,7 +238,8 @@ tVFS_Node *FAT_InitDevice(char *Device, char **Options)
        \r
        // == VFS Interface\r
        node = &diskInfo->rootNode;\r
-       node->Size = bs->files_in_root;\r
+       //node->Size = bs->files_in_root;\r
+       node->Size = -1;\r
        node->Inode = diskInfo->rootOffset;     // 0:31 - Cluster, 32:63 - Parent Directory Cluster\r
        node->ImplPtr = diskInfo;       // Disk info pointer\r
        node->ImplInt = 0;      // 0:15 - Directory Index, 16: Dirty Flag, 17: Deletion Flag\r
@@ -327,6 +328,8 @@ int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Clu
                if(Cluster)     *Cluster = cluster;\r
        }\r
        \r
+       LOG("cluster = %08x", cluster);\r
+       \r
        // Bounds Checking (Used to spot corruption)\r
        if(cluster > disk->ClusterCount + 2)\r
        {\r
@@ -599,14 +602,14 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 offset, Uint64 length, void *buffer)
        \r
        // Sanity Check offset\r
        if(offset > Node->Size) {\r
-               LOG("Reading past EOF (%i > %i)", offset, node->Size);\r
+               LOG("Reading past EOF (%i > %i)", offset, Node->Size);\r
                LEAVE('i', 0);\r
                return 0;\r
        }\r
        // Clamp Size\r
        if(offset + length > Node->Size) {\r
                LOG("Reading past EOF (%lli + %lli > %lli), clamped to %lli",\r
-                       offset, length, node->Size, node->Size - offset);\r
+                       offset, length, Node->Size, Node->Size - offset);\r
                length = Node->Size - offset;\r
        }\r
        \r
@@ -856,14 +859,11 @@ void FAT_int_ProperFilename(char *dest, char *src)
 char *FAT_int_CreateName(fat_filetable *ft, char *LongFileName)\r
 {\r
        char    *ret;\r
-        int    len;\r
        ENTER("pft sLongFileName", ft, LongFileName);\r
        #if USE_LFN\r
        if(LongFileName && LongFileName[0] != '\0')\r
        {       \r
-               len = strlen(LongFileName);\r
-               ret = malloc(len+1);\r
-               strcpy(ret, LongFileName);\r
+               ret = strdup(LongFileName);\r
        }\r
        else\r
        {\r
@@ -978,6 +978,7 @@ int FAT_int_ReadDirSector(tVFS_Node *Node, int Sector, fat_filetable *Buffer)
                return 1;\r
        }\r
        \r
+       LOG("addr = 0x%llx", addr);\r
        // Read Sector\r
        if(VFS_ReadAt(disk->fileHandle, addr, 512, Buffer) != 512)\r
        {\r
@@ -1108,6 +1109,7 @@ char *FAT_ReadDir(tVFS_Node *Node, int ID)
        \r
        if(FAT_int_ReadDirSector(Node, ID/16, fileinfo))\r
        {\r
+               LOG("End of chain, end of dir");\r
                LEAVE('n');\r
                return NULL;\r
        }\r
@@ -1115,9 +1117,7 @@ char *FAT_ReadDir(tVFS_Node *Node, int ID)
        // Offset in sector\r
        a = ID % 16;\r
 \r
-       LOG("a = %i", a);\r
-       \r
-       LOG("name[0] = 0x%x", (Uint8)fileinfo[a].name[0]);\r
+       LOG("fileinfo[%i].name[0] = 0x%x", a, (Uint8)fileinfo[a].name[0]);\r
        \r
        // Check if this is the last entry\r
        if( fileinfo[a].name[0] == '\0' ) {\r
@@ -1130,8 +1130,13 @@ char *FAT_ReadDir(tVFS_Node *Node, int ID)
        // Check for empty entry\r
        if( (Uint8)fileinfo[a].name[0] == 0xE5 ) {\r
                LOG("Empty Entry");\r
+               #if 0   // Stop on empty entry?\r
+               LEAVE('n');\r
+               return NULL;    // Stop\r
+               #else\r
                LEAVE('p', VFS_SKIP);\r
                return VFS_SKIP;        // Skip\r
+               #endif\r
        }\r
        \r
        #if USE_LFN\r
@@ -1260,6 +1265,8 @@ tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *Name)
                {\r
                        // Remove LFN if it does not apply\r
                        if(lfnId != i)  lfn[0] = '\0';\r
+               #else\r
+               if(fileinfo[i&0xF].attrib == ATTR_LFN)  continue;\r
                #endif\r
                        // Get Real Filename\r
                        FAT_int_ProperFilename(tmpName, fileinfo[i&0xF].name);\r

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