From f669c5be8f9c44846857a283ec6cd3a85b0bd88c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 27 Jul 2011 17:47:17 +0800 Subject: [PATCH] Kernel - Fixed a bug in VFS_ParsePath that cause symlinks to break --- Kernel/lib.c | 1 + Kernel/vfs/handle.c | 2 +- Kernel/vfs/io.c | 2 ++ Kernel/vfs/open.c | 14 +++++++------- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Kernel/lib.c b/Kernel/lib.c index 0b5ccfe8..acf36aac 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -495,6 +495,7 @@ char *strncpy(char *__str1, const char *__str2, size_t max) char *strcat(char *__dest, const char *__src) { while(*__dest++); + __dest--; while(*__src) *__dest++ = *__src++; *__dest = '\0'; diff --git a/Kernel/vfs/handle.c b/Kernel/vfs/handle.c index ecf3f5c0..55c841ec 100644 --- a/Kernel/vfs/handle.c +++ b/Kernel/vfs/handle.c @@ -19,7 +19,7 @@ tVFS_Handle *VFS_GetHandle(int FD); int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode); // === GLOBALS === -tVFS_Handle *gaUserHandles = (void*)MM_PPD_VFS; +tVFS_Handle *gaUserHandles = (void*)MM_PPD_HANDLES; tVFS_Handle *gaKernelHandles = (void*)MM_KERNEL_VFS; // === CODE === diff --git a/Kernel/vfs/io.c b/Kernel/vfs/io.c index 7260df70..212a7c21 100644 --- a/Kernel/vfs/io.c +++ b/Kernel/vfs/io.c @@ -144,6 +144,8 @@ int VFS_Seek(int FD, Sint64 Offset, int Whence) // Set relative to end of file if(Whence < 0) { + if( h->Node->Size == -1 ) return -1; + h->Position = h->Node->Size - Offset; return 0; } diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index 02c9266f..70d3c247 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -203,7 +203,7 @@ restart_parse: // Check if there is anything mounted if(!gVFS_Mounts) { - Warning("WTF! There's nothing mounted?"); + Log_Error("VFS", "VFS_ParsePath - No filesystems mounted"); return NULL; } @@ -318,7 +318,7 @@ restart_parse: *TruePath = NULL; } if(!curNode->Read) { - Warning("VFS_ParsePath - Read of node %p is NULL (%s)", + Log_Warning("VFS", "VFS_ParsePath - Read of symlink node %p'%s' is NULL", curNode, Path); if(curNode->Close) curNode->Close(curNode); // No need to free *TruePath, it should already be NULL @@ -345,12 +345,12 @@ restart_parse: } curNode->Read( curNode, 0, curNode->Size, path_buffer ); path_buffer[ curNode->Size ] = '\0'; - strcat(path_buffer, &Path[ofs+nextSlash]); + strcat(path_buffer, Path + ofs+nextSlash); Path = path_buffer; +// Log_Debug("VFS", "VFS_ParsePath: Symlink translated to '%s'", Path); iNestedLinks ++; } - // EVIL: Goto :) goto restart_parse; @@ -359,7 +359,7 @@ restart_parse: // Handle Non-Directories if( !(curNode->Flags & VFS_FFLAG_DIRECTORY) ) { - Warning("VFS_ParsePath - File in directory context"); + Log_Warning("VFS", "VFS_ParsePath - Path segment is not a directory"); if(TruePath) free(*TruePath); LEAVE('n'); return NULL; @@ -372,7 +372,7 @@ restart_parse: tmp = realloc( *TruePath, retLength + strlen(pathEle) + 1 + 1 ); // Check if allocation succeeded if(!tmp) { - Warning("VFS_ParsePath - Unable to reallocate true path buffer"); + Log_Warning("VFS", "VFS_ParsePath - Unable to reallocate true path buffer"); free(*TruePath); *TruePath = NULL; if(curNode->Close) curNode->Close(curNode); @@ -396,7 +396,7 @@ restart_parse: free(*TruePath); *TruePath = NULL; } - Log("FindDir fail on '%s'", Path); + Log_Warning("VFS", "VFS_ParsePath - FindDir doesn't exist for element of '%s'", Path); LEAVE('n'); return NULL; } -- 2.20.1