1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:57:34 +00:00

Implement sys$chdir() and teach sh+ls to cd around and browse different dirs.

This commit is contained in:
Andreas Kling 2018-10-26 14:24:11 +02:00
parent ac738b03d6
commit 2749e7f1c2
16 changed files with 147 additions and 33 deletions

View file

@ -128,6 +128,11 @@ ByteBuffer FileHandle::readEntireFile()
return m_vnode->fileSystem()->readEntireInode(m_vnode->inode);
}
bool FileHandle::isDirectory() const
{
return m_vnode->metadata().isDirectory();
}
ssize_t FileHandle::get_dir_entries(byte* buffer, size_t size)
{
Locker locker(VirtualFileSystem::lock());

View file

@ -20,6 +20,10 @@ public:
String absolutePath() const;
bool isDirectory() const;
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
#ifdef SERENITY
int fd() const { return m_fd; }
void setFD(int fd) { m_fd = fd; }

View file

@ -168,9 +168,9 @@ void VirtualFileSystem::freeNode(Node* node)
m_nodeFreeList.append(move(node));
}
bool VirtualFileSystem::isDirectory(const String& path)
bool VirtualFileSystem::isDirectory(const String& path, Node* base)
{
auto inode = resolvePath(path);
auto inode = resolvePath(path, base);
if (!inode.isValid())
return false;
@ -355,11 +355,11 @@ bool VirtualFileSystem::touch(const String& path)
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
}
OwnPtr<FileHandle> VirtualFileSystem::open(const String& path)
OwnPtr<FileHandle> VirtualFileSystem::open(const String& path, Node* base)
{
Locker locker(VirtualFileSystem::lock());
auto inode = resolvePath(path);
auto inode = resolvePath(path, base);
if (!inode.isValid())
return nullptr;
auto vnode = getOrCreateNode(inode);
@ -368,7 +368,7 @@ OwnPtr<FileHandle> VirtualFileSystem::open(const String& path)
return make<FileHandle>(move(vnode));
}
OwnPtr<FileHandle> VirtualFileSystem::create(const String& path)
OwnPtr<FileHandle> VirtualFileSystem::create(const String& path, Node* base)
{
Locker locker(VirtualFileSystem::lock());
@ -378,7 +378,7 @@ OwnPtr<FileHandle> VirtualFileSystem::create(const String& path)
return nullptr;
}
OwnPtr<FileHandle> VirtualFileSystem::mkdir(const String& path)
OwnPtr<FileHandle> VirtualFileSystem::mkdir(const String& path, Node* base)
{
Locker locker(VirtualFileSystem::lock());
@ -398,10 +398,18 @@ InodeIdentifier VirtualFileSystem::resolveSymbolicLink(const String& basePath, I
return resolvePath(buf);
}
InodeIdentifier VirtualFileSystem::resolvePath(const String& path)
InodeIdentifier VirtualFileSystem::resolvePath(const String& path, Node* base)
{
if (path.isEmpty())
return { };
auto parts = path.split('/');
InodeIdentifier inode = m_rootNode->inode;
InodeIdentifier inode;
if (path[0] == '/')
inode = m_rootNode->inode;
else
inode = base ? base->inode : m_rootNode->inode;
for (unsigned i = 0; i < parts.size(); ++i) {
auto& part = parts[i];

View file

@ -51,7 +51,7 @@ public:
VirtualFileSystem();
~VirtualFileSystem();
bool isDirectory(const String& path);
bool isDirectory(const String& path, Node* base = nullptr);
void listDirectory(const String& path);
void listDirectoryRecursively(const String& path);
@ -64,9 +64,9 @@ public:
bool mountRoot(RetainPtr<FileSystem>&&);
bool mount(RetainPtr<FileSystem>&&, const String& path);
OwnPtr<FileHandle> open(const String& path);
OwnPtr<FileHandle> create(const String& path);
OwnPtr<FileHandle> mkdir(const String& path);
OwnPtr<FileHandle> open(const String& path, Node* base = nullptr);
OwnPtr<FileHandle> create(const String& path, Node* base = nullptr);
OwnPtr<FileHandle> mkdir(const String& path, Node* base = nullptr);
bool isRoot(InodeIdentifier) const;
@ -79,7 +79,7 @@ private:
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
String absolutePath(InodeIdentifier);
InodeIdentifier resolvePath(const String& path);
InodeIdentifier resolvePath(const String& path, Node* base = nullptr);
InodeIdentifier resolveSymbolicLink(const String& basePath, InodeIdentifier symlinkInode);
RetainPtr<Node> allocateNode();