Immense cleanup of libc, implemening login program. Slight changes to ACL handling...
[tpg/acess2.git] / Kernel / vfs / fs / fat.c
index 5bd7bac..01c90c2 100644 (file)
@@ -1,28 +1,15 @@
 /*\r
- * Acess2\r
+ * Acess 2\r
  * FAT12/16/32 Driver Version (Incl LFN)\r
  */\r
-//INCLUDES\r
+#define DEBUG  0\r
 #include <common.h>\r
 #include <modules.h>\r
 #include <vfs.h>\r
 #include "fs_fat.h"\r
 \r
-#define DEBUG  0\r
 #define VERBOSE        1\r
 \r
-#if DEBUG\r
-# define DEBUGS(v...)  Log(v)\r
-#else\r
-# define DEBUGS(v...)\r
-# undef ENTER\r
-# undef LOG\r
-# undef LEAVE\r
-# define ENTER(...)\r
-# define LOG(...)\r
-# define LEAVE(...)\r
-#endif\r
-\r
 #define CACHE_FAT      1       //!< Caches the FAT in memory\r
 #define USE_LFN                1       //!< Enables the use of Long File Names\r
 \r
@@ -213,16 +200,13 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options)
                        fat_cache[giFAT_PartCount][i] = buf[i&127];\r
                }\r
        }\r
-       DEBUGS(" FAT_InitDisk: FAT Fully Cached\n");\r
+       LOG("FAT Fully Cached");\r
        }\r
        #endif /*CACHE_FAT*/\r
        \r
        //Initalise inode cache for FAT\r
        gFAT_Disks[giFAT_PartCount].inodeHandle = Inode_GetHandle();\r
-       \r
-       #if DEBUG\r
-               Log(" FAT_InitDisk: Inode Cache handle is %i\n", gFAT_Disks[giFAT_PartCount].inodeHandle);\r
-       #endif\r
+       LOG("Inode Cache handle is %i", gFAT_Disks[giFAT_PartCount].inodeHandle);\r
        \r
        // == VFS Interface\r
        node = &gFAT_Disks[giFAT_PartCount].rootNode;\r
@@ -292,9 +276,7 @@ static Uint32 FAT_int_GetFatValue(int handle, Uint32 cluster)
  */\r
 static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Buffer)\r
 {\r
-       #if DEBUG\r
        ENTER("iHandle xCluster iLength pBuffer", Handle, Cluster, Length, Buffer);\r
-       #endif\r
        VFS_ReadAt(\r
                gFAT_Disks[Handle].fileHandle,\r
                (gFAT_Disks[Handle].firstDataSect + (Cluster-2)*gFAT_Disks[Handle].bootsect.spc )\r
@@ -302,9 +284,7 @@ static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Bu
                Length,\r
                Buffer\r
                );\r
-       #if DEBUG\r
        LEAVE('-');\r
-       #endif\r
 }\r
 \r
 /**\r
@@ -342,6 +322,18 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer)
                return 0;\r
        }\r
        \r
+       // Sanity Check offset\r
+       if(offset > node->Size) {\r
+               //Log("FAT_Read: Reading past EOF (%i > %i)", offset, node->Size);\r
+               return 0;\r
+       }\r
+       // Clamp Size\r
+       if(offset + length > node->Size) {\r
+               //Log("FAT_Read: Reading past EOF (%lli + %lli > %lli), clamped to %lli",\r
+               //      offset, length, node->Size, node->Size - offset);\r
+               length = node->Size - offset;\r
+       }\r
+       \r
        // Single Cluster including offset\r
        if(length + offset < bpc)\r
        {\r
@@ -349,7 +341,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer)
                memcpy( buffer, (void*)( tmpBuf + offset%bpc ), length );\r
                free(tmpBuf);\r
                LEAVE('i', 1);\r
-               return 1;\r
+               return length;\r
        }\r
        \r
        preSkip = offset / bpc;\r
@@ -379,7 +371,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer)
        if (count == 1) {\r
                free(tmpBuf);\r
                LEAVE('i', 1);\r
-               return 1;\r
+               return length;\r
        }\r
        \r
        cluster = FAT_int_GetFatValue(handle, cluster);\r
@@ -743,7 +735,7 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos)
        #endif\r
        \r
        LEAVE('s', ret);\r
-       return VFS_FREEPLZ(ret);\r
+       return ret;\r
 }\r
 \r
 /**\r

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