X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Ffs%2Ffat.c;h=5712da9102bb4e37a89948c435018551e6d2aa30;hb=95a7eaaa4a1065334125b65130866f8d1048ddb7;hp=c0c3fbabbd00abee0279e2c9e4112d87f337e8d1;hpb=0d8269e320f58621cfe393cd7ce9b8e8544e2f9c;p=tpg%2Facess2.git diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index c0c3fbab..5712da91 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -1,28 +1,15 @@ /* - * Acess2 + * Acess 2 * FAT12/16/32 Driver Version (Incl LFN) */ -//INCLUDES +#define DEBUG 0 #include #include #include #include "fs_fat.h" -#define DEBUG 1 #define VERBOSE 1 -#if DEBUG -# define DEBUGS(v...) Log(v) -#else -# define DEBUGS(v...) -# undef ENTER -# undef LOG -# undef LEAVE -# define ENTER(...) -# define LOG(...) -# define LEAVE(...) -#endif - #define CACHE_FAT 1 //!< Caches the FAT in memory #define USE_LFN 1 //!< Enables the use of Long File Names @@ -38,7 +25,7 @@ typedef struct s_lfncache { // === PROTOTYPES === int FAT_Install(char **Arguments); -tVFS_Node *FAT_InitDevice(char *device, char *options); +tVFS_Node *FAT_InitDevice(char *device, char **options); void FAT_Unmount(tVFS_Node *Node); Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); Uint64 FAT_Write(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); @@ -49,7 +36,7 @@ tVFS_Node *FAT_FindDir(tVFS_Node *dirNode, char *file); void FAT_CloseFile(tVFS_Node *node); // === SEMI-GLOBALS === -MODULE_DEFINE(0, 0x5B /*v0.90*/, FAT32, FAT_Install, NULL); +MODULE_DEFINE(0, 0x51 /*v0.80*/, FAT32, FAT_Install, NULL, NULL); tFAT_VolInfo gFAT_Disks[8]; int giFAT_PartCount = 0; #if CACHE_FAT @@ -74,10 +61,10 @@ int FAT_Install(char **Arguments) } /** - * \fn tVFS_Node *FAT_InitDevice(char *Device, char *options) + * \fn tVFS_Node *FAT_InitDevice(char *Device, char **options) * \brief Reads the boot sector of a disk and prepares the structures for it */ -tVFS_Node *FAT_InitDevice(char *Device, char *options) +tVFS_Node *FAT_InitDevice(char *Device, char **options) { fat_bootsect *bs; int i; @@ -213,16 +200,13 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options) fat_cache[giFAT_PartCount][i] = buf[i&127]; } } - DEBUGS(" FAT_InitDisk: FAT Fully Cached\n"); + LOG("FAT Fully Cached"); } #endif /*CACHE_FAT*/ //Initalise inode cache for FAT gFAT_Disks[giFAT_PartCount].inodeHandle = Inode_GetHandle(); - - #if DEBUG - Log(" FAT_InitDisk: Inode Cache handle is %i\n", gFAT_Disks[giFAT_PartCount].inodeHandle); - #endif + LOG("Inode Cache handle is %i", gFAT_Disks[giFAT_PartCount].inodeHandle); // == VFS Interface node = &gFAT_Disks[giFAT_PartCount].rootNode; @@ -292,9 +276,7 @@ static Uint32 FAT_int_GetFatValue(int handle, Uint32 cluster) */ static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Buffer) { - #if DEBUG ENTER("iHandle xCluster iLength pBuffer", Handle, Cluster, Length, Buffer); - #endif VFS_ReadAt( gFAT_Disks[Handle].fileHandle, (gFAT_Disks[Handle].firstDataSect + (Cluster-2)*gFAT_Disks[Handle].bootsect.spc ) @@ -302,9 +284,7 @@ static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Bu Length, Buffer ); - #if DEBUG LEAVE('-'); - #endif } /** @@ -342,6 +322,18 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) return 0; } + // Sanity Check offset + if(offset > node->Size) { + //LOG("Reading past EOF (%i > %i)", offset, node->Size); + return 0; + } + // Clamp Size + if(offset + length > node->Size) { + //LOG("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 +341,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 +371,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 +481,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 +519,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 +657,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 +735,7 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos) #endif LEAVE('s', ret); - return VFS_FREEPLZ(ret); + return ret; } /**