1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

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.
This commit is contained in:
Andreas Kling 2018-11-07 15:51:39 +01:00
parent 981a3ae4b3
commit 61a84193d7
4 changed files with 27 additions and 15 deletions

View file

@ -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 = \

View file

@ -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());

View file

@ -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 listDirectory(const String& path, InodeIdentifier base);
void listDirectoryRecursively(const String& path); 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(); }

View file

@ -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)) { FileSystemPath new_path(buf);
currentDirectory = 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;
} }