Ver Fonte

Fix some broken stuff in VFS test environment.

It's still lagging behind the metal environment but here's some work towards
fixing it at least.
Andreas Kling há 6 anos atrás
pai
commit
61a84193d7

+ 1 - 0
VirtualFileSystem/Makefile

@@ -7,6 +7,7 @@ AK_OBJS = \
     ../AK/TemporaryFile.o \
     ../AK/TemporaryFile.o \
     ../AK/SimpleMalloc.o \
     ../AK/SimpleMalloc.o \
     ../AK/StringBuilder.o \
     ../AK/StringBuilder.o \
+    ../AK/FileSystemPath.o \
     ../AK/kmalloc.o
     ../AK/kmalloc.o
 
 
 VFS_OBJS = \
 VFS_OBJS = \

+ 5 - 5
VirtualFileSystem/VirtualFileSystem.cpp

@@ -258,10 +258,10 @@ void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode,
 }
 }
 
 
 #ifndef SERENITY
 #ifndef SERENITY
-void VirtualFileSystem::listDirectory(const String& path)
+void VirtualFileSystem::listDirectory(const String& path, InodeIdentifier base)
 {
 {
     int error;
     int error;
-    auto directoryInode = resolvePath(path, error);
+    auto directoryInode = resolvePath(path, error, base);
     if (!directoryInode.isValid())
     if (!directoryInode.isValid())
         return;
         return;
 
 
@@ -359,10 +359,10 @@ void VirtualFileSystem::listDirectory(const String& path)
     });
     });
 }
 }
 
 
-void VirtualFileSystem::listDirectoryRecursively(const String& path)
+void VirtualFileSystem::listDirectoryRecursively(const String& path, InodeIdentifier base)
 {
 {
     int error;
     int error;
-    auto directory = resolvePath(path, error);
+    auto directory = resolvePath(path, error, base);
     if (!directory.isValid())
     if (!directory.isValid())
         return;
         return;
 
 
@@ -374,7 +374,7 @@ void VirtualFileSystem::listDirectoryRecursively(const String& path)
             if (entry.name != "." && entry.name != "..") {
             if (entry.name != "." && entry.name != "..") {
                 char buf[4096];
                 char buf[4096];
                 ksprintf(buf, "%s/%s", path.characters(), entry.name.characters());
                 ksprintf(buf, "%s/%s", path.characters(), entry.name.characters());
-                listDirectoryRecursively(buf);
+                listDirectoryRecursively(buf, base);
             }
             }
         } else {
         } else {
             kprintf("%s/%s\n", path.characters(), entry.name.characters());
             kprintf("%s/%s\n", path.characters(), entry.name.characters());

+ 2 - 2
VirtualFileSystem/VirtualFileSystem.h

@@ -79,8 +79,8 @@ public:
     ~VirtualFileSystem();
     ~VirtualFileSystem();
 
 
     bool isDirectory(const String& path, InodeIdentifier base = InodeIdentifier());
     bool isDirectory(const String& path, InodeIdentifier base = InodeIdentifier());
-    void listDirectory(const String& path);
-    void listDirectoryRecursively(const String& path);
+    void listDirectory(const String& path, InodeIdentifier base);
+    void listDirectoryRecursively(const String& path, InodeIdentifier base);
 
 
     unsigned maxNodeCount() const { return m_maxNodeCount; }
     unsigned maxNodeCount() const { return m_maxNodeCount; }
     unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); }
     unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); }

+ 19 - 8
VirtualFileSystem/test.cpp

@@ -8,6 +8,7 @@
 #include "FullDevice.h"
 #include "FullDevice.h"
 #include "RandomDevice.h"
 #include "RandomDevice.h"
 #include <cstring>
 #include <cstring>
+#include <AK/FileSystemPath.h>
 #include <AK/SimpleMalloc.h>
 #include <AK/SimpleMalloc.h>
 #include <AK/StdLib.h>
 #include <AK/StdLib.h>
 #include <AK/kmalloc.h>
 #include <AK/kmalloc.h>
@@ -77,9 +78,9 @@ int main(int c, char** v)
 
 
     vfs.mount(std::move(synthfs), "/syn");
     vfs.mount(std::move(synthfs), "/syn");
 
 
-    vfs.listDirectory("/");
+    vfs.listDirectory(".", vfs.root()->inode);
     printf("list /syn:\n");
     printf("list /syn:\n");
-    vfs.listDirectory("/syn");
+    vfs.listDirectory("/syn", vfs.root()->inode);
 
 
 #if 0
 #if 0
     auto descriptor = vfs.open("/home/andreas/../../home/./andreas/./file2");
     auto descriptor = vfs.open("/home/andreas/../../home/./andreas/./file2");
@@ -94,6 +95,8 @@ int main(int c, char** v)
 
 
     String currentDirectory = "/";
     String currentDirectory = "/";
 
 
+    auto cwd = vfs.root()->inode;
+
     while (true) {
     while (true) {
         char cmdbuf[256];
         char cmdbuf[256];
         printf("::>");
         printf("::>");
@@ -120,22 +123,30 @@ int main(int c, char** v)
         }
         }
 
 
         if (cmd == "ls") {
         if (cmd == "ls") {
-            vfs.listDirectory(currentDirectory);
+            vfs.listDirectory(".", cwd);
             continue;
             continue;
         }
         }
 
 
         if (cmd == "lr") {
         if (cmd == "lr") {
-            vfs.listDirectoryRecursively(currentDirectory);
+            vfs.listDirectoryRecursively(".", cwd);
             continue;
             continue;
         }
         }
 
 
         if (cmd == "cd" && parts.size() > 1) {
         if (cmd == "cd" && parts.size() > 1) {
-            char buf[1024];
+            char buf[4096];
             sprintf(buf, "%s/%s", currentDirectory.characters(), parts[1].characters());
             sprintf(buf, "%s/%s", currentDirectory.characters(), parts[1].characters());
-            if (vfs.isDirectory(buf)) {
-                currentDirectory = buf;
+            FileSystemPath new_path(buf);
+            if (new_path.string() == "/") {
+                cwd = vfs.root()->inode;
+                continue;
+            }
+            int error;
+            auto new_cwd = vfs.open(new_path.string(), error, 0, cwd);
+            if (new_cwd && new_cwd->isDirectory()) {
+                currentDirectory = new_path.string();
+                cwd = new_cwd->metadata().inode;
             } else {
             } else {
-                printf("No such directory: %s\n", buf);
+                printf("No such directory: %s\n", parts[1].characters());
             }
             }
             continue;
             continue;
         }
         }