From 9b4ce124f950e1bebbf4e011804e0b8ed8472f6a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 27 Sep 2009 17:03:02 +0800 Subject: [PATCH] Fixed VFS_ChDir to handle symlinks by using VFS_Open --- Kernel/vfs/open.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index 7b651322..eebaa82d 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -510,7 +510,8 @@ void VFS_Close(int FD) int VFS_ChDir(char *New) { char *buf; - tVFS_Node *node; + int fd; + tVFS_Handle *h; // Create Absolute buf = VFS_GetAbsPath(New); @@ -519,23 +520,25 @@ int VFS_ChDir(char *New) return -1; } - // Check if path is valid - node = VFS_ParsePath(buf, NULL); - if(!node) { + // Check if path exists + fd = VFS_Open(buf, VFS_OPENFLAG_EXEC); + if(fd == -1) { Log("VFS_ChDir: Path is invalid"); return -1; } - // Check if is a directory - if( !(node->Flags & VFS_FFLAG_DIRECTORY) ) { - Log("VFS_ChDir: Not a directory"); - if(node->Close) node->Close(node); + // Get node so we can check for directory + h = VFS_GetHandle(fd); + if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) { + Log("VFS_ChDir: Path is not a directory"); + VFS_Close(fd); return -1; } - // Close node - if(node->Close) node->Close(node); - // Free old and set new + // Close file + VFS_Close(fd); + + // Free working directory and set new one free( CFGPTR(CFG_VFS_CWD) ); CFGPTR(CFG_VFS_CWD) = buf; -- 2.20.1