Kernel/vfs - Fixed edge case bug with chroots
authorJohn Hodge <[email protected]>
Tue, 14 Feb 2012 07:34:05 +0000 (15:34 +0800)
committerJohn Hodge <[email protected]>
Tue, 14 Feb 2012 07:34:05 +0000 (15:34 +0800)
- Trims trailing slash off chroot

KernelLand/Kernel/vfs/fs/devfs.c
KernelLand/Kernel/vfs/fs/root.c
KernelLand/Kernel/vfs/open.c

index b3f4a57..1355226 100644 (file)
@@ -3,6 +3,7 @@
  * Device Filesystem (DevFS)
  * - vfs/fs/devfs.c
  */
+#define DEBUG  0
 #include <acess.h>
 #include <vfs.h>
 #include <fs_devfs.h>
@@ -44,6 +45,9 @@ int DevFS_AddDevice(tDevFS_Driver *Device)
 {
         int    ret = 0;
        tDevFS_Driver   *dev;
+
+       ENTER("pDevice", Device);
+       LOG("Device->Name = '%s'", Device->Name);
        
        SHORTLOCK( &glDevFS_ListLock );
        
@@ -61,7 +65,7 @@ int DevFS_AddDevice(tDevFS_Driver *Device)
                else
                        Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p",
                                Device, dev->Name, dev);
-               ret = 0;        // Error
+               ret = -1;       // Error
        }
        else {
                Device->Next = gDevFS_Drivers;
@@ -71,6 +75,7 @@ int DevFS_AddDevice(tDevFS_Driver *Device)
        }
        SHORTREL( &glDevFS_ListLock );
        
+       LEAVE('i', ret);
        return ret;
 }
 
@@ -140,7 +145,7 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
 {
        tDevFS_Driver   *dev;
        
-       //ENTER("pNode sName", Node, Name);
+       ENTER("pNode sName", Node, Name);
        
        for(dev = gDevFS_Drivers;
                dev;
@@ -148,14 +153,14 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
                )
        {
                //LOG("dev = %p", dev);
-               //LOG("dev->Name = '%s'", dev->Name);
+               LOG("dev->Name = '%s'", dev->Name);
                if(strcmp(dev->Name, Name) == 0) {
-                       //LEAVE('p', &dev->RootNode);
+                       LEAVE('p', &dev->RootNode);
                        return &dev->RootNode;
                }
        }
        
-       //LEAVE('n');
+       LEAVE('n');
        return NULL;
 }
 
index 9fa1732..bee2030 100644 (file)
@@ -142,14 +142,20 @@ tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name)
        tRamFS_File     *parent = Node->ImplPtr;
        tRamFS_File     *child = parent->Data.FirstChild;
        
+       ENTER("pNode sName", Node, Name);
        //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name);
        
        for(;child;child = child->Next)
        {
                //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name);
-               if(strcmp(child->Name, Name) == 0)      return &child->Node;
+               LOG("child->Name = '%s'", child->Name);
+               if(strcmp(child->Name, Name) == 0) {
+                       LEAVE('p', &child->Node);
+                       return &child->Node;
+               }
        }
        
+       LEAVE('n');
        return NULL;
 }
 
index 1536d1a..cfb296b 100644 (file)
@@ -59,6 +59,9 @@ char *VFS_GetAbsPath(const char *Path)
        if( chroot == NULL )
                chroot = "";
        chrootLen = strlen(chroot);
+       // Trim trailing slash off chroot
+       if( chrootLen && chroot[chrootLen - 1] == '/' )
+               chrootLen -= 1;
        
        // Check if the path is already absolute
        if(Path[0] == '/') {
@@ -269,14 +272,14 @@ restart_parse:
        
                // Check permissions on root of filesystem
                if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) {
-                       //Log("Permissions fail on '%s'", Path);
+                       LOG("Permissions failure on '%s'", Path);
                        goto _error;
                }
                
                // Check if the node has a FindDir method
                if( !curNode->Type->FindDir )
                {
-                       //Log("FindDir fail on '%s'", Path);
+                       LOG("Finddir failure on '%s'", Path);
                        goto _error;
                }
                LOG("FindDir{=%p}(%p, '%s')", curNode->Type->FindDir, curNode, pathEle);

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