X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Ffs%2Ffat.c;h=bfae4058e82d30a4925cb3b4d592ef00f43ba9a7;hb=1a96e0dd77d6922078edd703fc7c2e809b9499b8;hp=c0c3fbabbd00abee0279e2c9e4112d87f337e8d1;hpb=0d8269e320f58621cfe393cd7ce9b8e8544e2f9c;p=tpg%2Facess2.git diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index c0c3fbab..bfae4058 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -8,7 +8,7 @@ #include #include "fs_fat.h" -#define DEBUG 1 +#define DEBUG 0 #define VERBOSE 1 #if DEBUG @@ -342,6 +342,18 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) return 0; } + // Sanity Check offset + if(offset > node->Size) { + //Log("FAT_Read: Reading past EOF (%i > %i)", offset, node->Size); + return 0; + } + // Clamp Size + if(offset + length > node->Size) { + //Log("FAT_Read: Reading past EOF (%lli + %lli > %lli), clamped to %lli", + // offset, length, node->Size, node->Size - offset); + length = node->Size - offset; + } + // Single Cluster including offset if(length + offset < bpc) { @@ -349,7 +361,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) memcpy( buffer, (void*)( tmpBuf + offset%bpc ), length ); free(tmpBuf); LEAVE('i', 1); - return 1; + return length; } preSkip = offset / bpc; @@ -379,7 +391,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) if (count == 1) { free(tmpBuf); LEAVE('i', 1); - return 1; + return length; } cluster = FAT_int_GetFatValue(handle, cluster); @@ -489,8 +501,6 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *parent, fat_filetable *ft, char *LongFi ENTER("pParent pFT sLongFileName", parent, ft, LongFileName); - // Get Name - //node.Name = FAT_int_CreateName(parent, ft, LongFileName); // Set Other Data node.Inode = ft->cluster | (ft->clusterHi<<16); node.Size = ft->size; @@ -529,6 +539,7 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *parent, fat_filetable *ft, char *LongFi node.ReadDir = FAT_ReadDir; node.FindDir = FAT_FindDir; node.MkNod = FAT_Mknod; + node.Size = -1; } else { node.Read = FAT_Read; node.Write = FAT_Write; @@ -666,16 +677,16 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos) // Offset in sector a = dirpos & 0xF; - LOG("offset=%i, a=%i\n", (Uint)offset, a); + LOG("offset=%i, a=%i", (Uint)offset, a); // Read Sector VFS_ReadAt(disk->fileHandle, offset*512, 512, fileinfo); // Read Dir Data - LOG("name[0] = 0x%x\n", (Uint8)fileinfo[a].name[0]); + LOG("name[0] = 0x%x", (Uint8)fileinfo[a].name[0]); //Check if this is the last entry if(fileinfo[a].name[0] == '\0') { dirNode->Size = dirpos; - LOG("End of list\n"); + LOG("End of list"); LEAVE('n'); return NULL; // break } @@ -744,7 +755,7 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos) #endif LEAVE('s', ret); - return VFS_FREEPLZ(ret); + return ret; } /**