More VFS cleanup.
This commit is contained in:
parent
396a32835b
commit
8fa2d7104a
Notes:
sideshowbarker
2024-07-19 16:10:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8fa2d7104a2
22 changed files with 92 additions and 95 deletions
|
@ -46,7 +46,7 @@ IDEDiskDevice::~IDEDiskDevice()
|
|||
{
|
||||
}
|
||||
|
||||
const char* IDEDiskDevice::className() const
|
||||
const char* IDEDiskDevice::class_name() const
|
||||
{
|
||||
return "IDEDiskDevice";
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ private:
|
|||
virtual void handleIRQ() override;
|
||||
|
||||
// ^DiskDevice
|
||||
virtual const char* className() const override;
|
||||
virtual const char* class_name() const override;
|
||||
|
||||
struct CHS {
|
||||
dword cylinder;
|
||||
|
|
|
@ -217,10 +217,10 @@ ByteBuffer procfs$mounts()
|
|||
auto buffer = ByteBuffer::createUninitialized(VFS::the().mount_count() * 80);
|
||||
char* ptr = (char*)buffer.pointer();
|
||||
VFS::the().for_each_mount([&ptr] (auto& mount) {
|
||||
auto& fs = mount.fileSystem();
|
||||
ptr += ksprintf(ptr, "%s @ ", fs.className());
|
||||
auto& fs = mount.guest_fs();
|
||||
ptr += ksprintf(ptr, "%s @ ", fs.class_name());
|
||||
if (!mount.host().isValid())
|
||||
ptr += ksprintf(ptr, "/\n", fs.className());
|
||||
ptr += ksprintf(ptr, "/\n", fs.class_name());
|
||||
else
|
||||
ptr += ksprintf(ptr, "%u:%u\n", mount.host().fsid(), mount.host().index());
|
||||
});
|
||||
|
@ -367,7 +367,7 @@ bool ProcFileSystem::initialize()
|
|||
return true;
|
||||
}
|
||||
|
||||
const char* ProcFileSystem::className() const
|
||||
const char* ProcFileSystem::class_name() const
|
||||
{
|
||||
return "procfs";
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
static RetainPtr<ProcFileSystem> create();
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual const char* className() const override;
|
||||
virtual const char* class_name() const override;
|
||||
|
||||
void addProcess(Process&);
|
||||
void removeProcess(Process&);
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
virtual unsigned blockSize() const = 0;
|
||||
virtual bool readBlock(unsigned index, byte*) const = 0;
|
||||
virtual bool writeBlock(unsigned index, const byte*) = 0;
|
||||
virtual const char* className() const = 0;
|
||||
virtual const char* class_name() const = 0;
|
||||
bool read(DiskOffset, unsigned length, byte*) const;
|
||||
bool write(DiskOffset, unsigned length, const byte*);
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ bool Ext2FileSystem::initialize()
|
|||
return true;
|
||||
}
|
||||
|
||||
const char* Ext2FileSystem::className() const
|
||||
const char* Ext2FileSystem::class_name() const
|
||||
{
|
||||
return "ext2fs";
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ Unix::ssize_t Ext2Inode::read_bytes(Unix::off_t offset, Unix::size_t count, byte
|
|||
return nread;
|
||||
}
|
||||
|
||||
Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const
|
||||
Unix::ssize_t Ext2FileSystem::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const
|
||||
{
|
||||
ASSERT(offset >= 0);
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
@ -778,7 +778,7 @@ bool Ext2FileSystem::modifyLinkCount(InodeIndex inode, int delta)
|
|||
return writeExt2Inode(inode, *e2inode);
|
||||
}
|
||||
|
||||
bool Ext2FileSystem::setModificationTime(InodeIdentifier inode, dword timestamp)
|
||||
bool Ext2FileSystem::set_mtime(InodeIdentifier inode, dword timestamp)
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
|
@ -991,7 +991,7 @@ bool Ext2FileSystem::setBlockAllocationState(GroupIndex group, BlockIndex bi, bo
|
|||
return true;
|
||||
}
|
||||
|
||||
InodeIdentifier Ext2FileSystem::makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode)
|
||||
InodeIdentifier Ext2FileSystem::create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode)
|
||||
{
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(parentInode.index()));
|
||||
|
@ -1003,7 +1003,7 @@ InodeIdentifier Ext2FileSystem::makeDirectory(InodeIdentifier parentInode, const
|
|||
|
||||
// NOTE: When creating a new directory, make the size 1 block.
|
||||
// There's probably a better strategy here, but this works for now.
|
||||
auto inode = createInode(parentInode, name, mode, blockSize());
|
||||
auto inode = create_inode(parentInode, name, mode, blockSize());
|
||||
if (!inode.isValid())
|
||||
return { };
|
||||
|
||||
|
@ -1030,7 +1030,7 @@ InodeIdentifier Ext2FileSystem::makeDirectory(InodeIdentifier parentInode, const
|
|||
return inode;
|
||||
}
|
||||
|
||||
InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size)
|
||||
InodeIdentifier Ext2FileSystem::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size)
|
||||
{
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(parentInode.index()));
|
||||
|
|
|
@ -66,15 +66,15 @@ private:
|
|||
ByteBuffer readSuperBlock() const;
|
||||
bool writeSuperBlock(const ext2_super_block&);
|
||||
|
||||
virtual const char* className() const override;
|
||||
virtual const char* class_name() const override;
|
||||
virtual InodeIdentifier rootInode() const override;
|
||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) override;
|
||||
virtual bool enumerateDirectoryInode(InodeIdentifier, Function<bool(const DirectoryEntry&)>) const override;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual bool set_mtime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ bool FileBackedDiskDevice::writeInternal(DiskOffset offset, unsigned length, con
|
|||
return true;
|
||||
}
|
||||
|
||||
const char* FileBackedDiskDevice::className() const
|
||||
const char* FileBackedDiskDevice::class_name() const
|
||||
{
|
||||
return "FileBackedDiskDevice";
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
virtual bool writeBlock(unsigned index, const byte*) override;
|
||||
|
||||
private:
|
||||
virtual const char* className() const override;
|
||||
virtual const char* class_name() const override;
|
||||
|
||||
bool readInternal(DiskOffset, unsigned length, byte* out) const;
|
||||
bool writeInternal(DiskOffset, unsigned length, const byte* data);
|
||||
|
|
|
@ -143,7 +143,7 @@ Unix::ssize_t FileDescriptor::read(byte* buffer, Unix::size_t count)
|
|||
// FIXME: What should happen to m_currentOffset?
|
||||
return m_vnode->characterDevice()->read(buffer, count);
|
||||
}
|
||||
Unix::ssize_t nread = m_vnode->fileSystem()->readInodeBytes(m_vnode->inode, m_currentOffset, count, buffer, this);
|
||||
Unix::ssize_t nread = m_vnode->fileSystem()->read_inode_bytes(m_vnode->inode, m_currentOffset, count, buffer, this);
|
||||
m_currentOffset += nread;
|
||||
return nread;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, Unix::size_t size)
|
|||
// FIXME: Compute the actual size needed.
|
||||
auto tempBuffer = ByteBuffer::createUninitialized(2048);
|
||||
BufferStream stream(tempBuffer);
|
||||
m_vnode->vfs()->enumerateDirectoryInode(m_vnode->inode, [&stream] (auto& entry) {
|
||||
m_vnode->vfs()->traverse_directory_inode(*m_vnode->core_inode(), [&stream] (auto& entry) {
|
||||
stream << (dword)entry.inode.index();
|
||||
stream << (byte)entry.fileType;
|
||||
stream << (dword)entry.name_length;
|
||||
|
|
|
@ -114,7 +114,7 @@ ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode, FileDescriptor* ha
|
|||
byte* out = contents.pointer();
|
||||
Unix::off_t offset = 0;
|
||||
for (;;) {
|
||||
nread = readInodeBytes(inode, offset, sizeof(buffer), buffer, handle);
|
||||
nread = read_inode_bytes(inode, offset, sizeof(buffer), buffer, handle);
|
||||
//kprintf("nread: %u, bufsiz: %u, initialSize: %u\n", nread, sizeof(buffer), initialSize);
|
||||
ASSERT(nread <= (Unix::ssize_t)sizeof(buffer));
|
||||
if (nread <= 0)
|
||||
|
|
|
@ -28,12 +28,12 @@ public:
|
|||
static FileSystem* fromID(dword);
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual const char* className() const = 0;
|
||||
virtual const char* class_name() const = 0;
|
||||
virtual InodeIdentifier rootInode() const = 0;
|
||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0;
|
||||
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const = 0;
|
||||
virtual Unix::ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const = 0;
|
||||
|
||||
struct DirectoryEntry {
|
||||
DirectoryEntry(const char* name, InodeIdentifier, byte fileType);
|
||||
|
@ -45,9 +45,9 @@ public:
|
|||
};
|
||||
virtual bool enumerateDirectoryInode(InodeIdentifier, Function<bool(const DirectoryEntry&)>) const = 0;
|
||||
|
||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) = 0;
|
||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) = 0;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) = 0;
|
||||
virtual bool set_mtime(InodeIdentifier, dword timestamp) = 0;
|
||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) = 0;
|
||||
virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t) = 0;
|
||||
|
||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const = 0;
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ bool SyntheticFileSystem::removeFile(InodeIndex inode)
|
|||
return true;
|
||||
}
|
||||
|
||||
const char* SyntheticFileSystem::className() const
|
||||
const char* SyntheticFileSystem::class_name() const
|
||||
{
|
||||
return "synthfs";
|
||||
}
|
||||
|
@ -172,14 +172,14 @@ InodeMetadata SyntheticFileSystem::inodeMetadata(InodeIdentifier inode) const
|
|||
return (*it).value->m_metadata;
|
||||
}
|
||||
|
||||
bool SyntheticFileSystem::setModificationTime(InodeIdentifier, dword timestamp)
|
||||
bool SyntheticFileSystem::set_mtime(InodeIdentifier, dword timestamp)
|
||||
{
|
||||
(void) timestamp;
|
||||
kprintf("FIXME: Implement SyntheticFileSystem::setModificationTime().\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
InodeIdentifier SyntheticFileSystem::createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size)
|
||||
InodeIdentifier SyntheticFileSystem::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size)
|
||||
{
|
||||
(void) parentInode;
|
||||
(void) name;
|
||||
|
@ -195,7 +195,7 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&)
|
|||
return false;
|
||||
}
|
||||
|
||||
Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor* handle) const
|
||||
Unix::ssize_t SyntheticFileSystem::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor* handle) const
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
#ifdef SYNTHFS_DEBUG
|
||||
|
@ -232,7 +232,7 @@ Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::o
|
|||
return nread;
|
||||
}
|
||||
|
||||
InodeIdentifier SyntheticFileSystem::makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t)
|
||||
InodeIdentifier SyntheticFileSystem::create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t)
|
||||
{
|
||||
(void) parentInode;
|
||||
(void) name;
|
||||
|
|
|
@ -12,15 +12,15 @@ public:
|
|||
static RetainPtr<SyntheticFileSystem> create();
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual const char* className() const override;
|
||||
virtual const char* class_name() const override;
|
||||
virtual InodeIdentifier rootInode() const override;
|
||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) override;
|
||||
virtual bool enumerateDirectoryInode(InodeIdentifier, Function<bool(const DirectoryEntry&)>) const override;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual bool set_mtime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ auto VFS::makeNode(CharacterDevice& device) -> RetainPtr<Vnode>
|
|||
return vnode;
|
||||
}
|
||||
|
||||
auto VFS::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
||||
auto VFS::get_or_create_node(InodeIdentifier inode) -> RetainPtr<Vnode>
|
||||
{
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
@ -118,7 +118,7 @@ auto VFS::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
|||
return makeNode(inode);
|
||||
}
|
||||
|
||||
auto VFS::getOrCreateNode(CharacterDevice& device) -> RetainPtr<Vnode>
|
||||
auto VFS::get_or_create_node(CharacterDevice& device) -> RetainPtr<Vnode>
|
||||
{
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
@ -139,7 +139,7 @@ bool VFS::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", fileSystem->className(), fileSystem.ptr(), path.characters(), inode.index());
|
||||
kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", fileSystem->class_name(), fileSystem.ptr(), path.characters(), inode.index());
|
||||
// FIXME: check that this is not already a mount point
|
||||
auto mount = make<Mount>(inode, move(fileSystem));
|
||||
m_mounts.append(move(mount));
|
||||
|
@ -168,7 +168,7 @@ bool VFS::mount_root(RetainPtr<FileSystem>&& fileSystem)
|
|||
m_root_vnode = move(node);
|
||||
|
||||
kprintf("VFS: mounted root on %s{%p}\n",
|
||||
m_root_vnode->fileSystem()->className(),
|
||||
m_root_vnode->fileSystem()->class_name(),
|
||||
m_root_vnode->fileSystem());
|
||||
|
||||
m_mounts.append(move(mount));
|
||||
|
@ -212,7 +212,7 @@ void VFS::freeNode(Vnode* node)
|
|||
bool VFS::isDirectory(const String& path, InodeIdentifier base)
|
||||
{
|
||||
int error;
|
||||
auto inode = resolvePath(path, error, base);
|
||||
auto inode = resolve_path(path, error, base);
|
||||
if (!inode.isValid())
|
||||
return false;
|
||||
|
||||
|
@ -243,19 +243,16 @@ bool VFS::is_vfs_root(InodeIdentifier inode) const
|
|||
return inode == m_root_vnode->inode;
|
||||
}
|
||||
|
||||
void VFS::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(const FileSystem::DirectoryEntry&)> callback)
|
||||
void VFS::traverse_directory_inode(CoreInode& dir_inode, Function<bool(const FileSystem::DirectoryEntry&)> callback)
|
||||
{
|
||||
if (!directoryInode.isValid())
|
||||
return;
|
||||
|
||||
directoryInode.fileSystem()->enumerateDirectoryInode(directoryInode, [&] (const FileSystem::DirectoryEntry& entry) {
|
||||
dir_inode.traverse_as_directory([&] (const FileSystem::DirectoryEntry& entry) {
|
||||
InodeIdentifier resolvedInode;
|
||||
if (auto mount = find_mount_for_host(entry.inode))
|
||||
resolvedInode = mount->guest();
|
||||
else
|
||||
resolvedInode = entry.inode;
|
||||
|
||||
if (directoryInode.isRootInode() && !is_vfs_root(directoryInode) && !strcmp(entry.name, "..")) {
|
||||
if (dir_inode.identifier().isRootInode() && !is_vfs_root(dir_inode.identifier()) && !strcmp(entry.name, "..")) {
|
||||
auto mount = find_mount_for_guest(entry.inode);
|
||||
ASSERT(mount);
|
||||
resolvedInode = mount->host();
|
||||
|
@ -269,11 +266,11 @@ void VFS::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(
|
|||
void VFS::listDirectory(const String& path, InodeIdentifier base)
|
||||
{
|
||||
int error;
|
||||
auto directoryInode = resolvePath(path, error, base);
|
||||
auto directoryInode = resolve_path(path, error, base);
|
||||
if (!directoryInode.isValid())
|
||||
return;
|
||||
|
||||
kprintf("VFS: ls %s -> %s %02u:%08u\n", path.characters(), directoryInode.fileSystem()->className(), directoryInode.fsid(), directoryInode.index());
|
||||
kprintf("VFS: ls %s -> %s %02u:%08u\n", path.characters(), directoryInode.fileSystem()->class_name(), directoryInode.fsid(), directoryInode.index());
|
||||
enumerateDirectoryInode(directoryInode, [&] (const FileSystem::DirectoryEntry& entry) {
|
||||
const char* nameColorBegin = "";
|
||||
const char* nameColorEnd = "";
|
||||
|
@ -370,7 +367,7 @@ void VFS::listDirectory(const String& path, InodeIdentifier base)
|
|||
void VFS::listDirectoryRecursively(const String& path, InodeIdentifier base)
|
||||
{
|
||||
int error;
|
||||
auto directory = resolvePath(path, error, base);
|
||||
auto directory = resolve_path(path, error, base);
|
||||
if (!directory.isValid())
|
||||
return;
|
||||
|
||||
|
@ -398,14 +395,14 @@ bool VFS::touch(const String& path)
|
|||
auto inode = resolve_path(path, error);
|
||||
if (!inode.isValid())
|
||||
return false;
|
||||
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
||||
return inode.fileSystem()->set_mtime(inode, ktime(nullptr));
|
||||
}
|
||||
|
||||
RetainPtr<FileDescriptor> VFS::open(CharacterDevice& device, int options)
|
||||
{
|
||||
// FIXME: Respect options.
|
||||
(void) options;
|
||||
auto vnode = getOrCreateNode(device);
|
||||
auto vnode = get_or_create_node(device);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return FileDescriptor::create(move(vnode));
|
||||
|
@ -416,7 +413,7 @@ RetainPtr<FileDescriptor> VFS::open(const String& path, int& error, int options,
|
|||
auto inode = resolve_path(path, error, base, options);
|
||||
if (!inode.isValid())
|
||||
return nullptr;
|
||||
auto vnode = getOrCreateNode(inode);
|
||||
auto vnode = get_or_create_node(inode);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return FileDescriptor::create(move(vnode));
|
||||
|
@ -427,7 +424,7 @@ RetainPtr<FileDescriptor> VFS::create(const String& path, InodeIdentifier base)
|
|||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
(void) base;
|
||||
m_root_vnode->fileSystem()->createInode(m_root_vnode->fileSystem()->rootInode(), "empty", 0100644, 0);
|
||||
m_root_vnode->fileSystem()->create_inode(m_root_vnode->fileSystem()->rootInode(), "empty", 0100644, 0);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -436,16 +433,16 @@ RetainPtr<FileDescriptor> VFS::mkdir(const String& path, InodeIdentifier base)
|
|||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
(void) base;
|
||||
m_root_vnode->fileSystem()->makeDirectory(m_root_vnode->fileSystem()->rootInode(), "mydir", 0400755);
|
||||
m_root_vnode->fileSystem()->create_directory(m_root_vnode->fileSystem()->rootInode(), "mydir", 0400755);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||
{
|
||||
auto symlink_contents = symlinkInode.readEntireFile();
|
||||
if (!symlink_contents)
|
||||
auto symlinkContents = symlinkInode.readEntireFile();
|
||||
if (!symlinkContents)
|
||||
return { };
|
||||
auto linkee = String((const char*)symlink_contents.pointer(), symlink_contents.size());
|
||||
auto linkee = String((const char*)symlinkContents.pointer(), symlinkContents.size());
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("linkee (%s)(%u) from %u:%u\n", linkee.characters(), linkee.length(), base.fsid(), base.index());
|
||||
#endif
|
||||
|
@ -500,19 +497,19 @@ InodeIdentifier VFS::resolve_path(const String& path, int& error, InodeIdentifie
|
|||
return { };
|
||||
|
||||
auto parts = path.split('/');
|
||||
InodeIdentifier inode;
|
||||
InodeIdentifier crumb_id;
|
||||
|
||||
if (path[0] == '/')
|
||||
inode = m_root_vnode->inode;
|
||||
crumb_id = m_root_vnode->inode;
|
||||
else
|
||||
inode = base.isValid() ? base : m_root_vnode->inode;
|
||||
crumb_id = base.isValid() ? base : m_root_vnode->inode;
|
||||
|
||||
for (unsigned i = 0; i < parts.size(); ++i) {
|
||||
bool inode_was_root_at_head_of_loop = inode.isRootInode();
|
||||
bool inode_was_root_at_head_of_loop = crumb_id.isRootInode();
|
||||
auto& part = parts[i];
|
||||
if (part.isEmpty())
|
||||
break;
|
||||
auto metadata = inode.metadata();
|
||||
auto metadata = crumb_id.metadata();
|
||||
if (!metadata.isValid()) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("invalid metadata\n");
|
||||
|
@ -527,9 +524,9 @@ InodeIdentifier VFS::resolve_path(const String& path, int& error, InodeIdentifie
|
|||
error = -EIO;
|
||||
return { };
|
||||
}
|
||||
auto parent = inode;
|
||||
inode = inode.fileSystem()->child_of_directory_inode_with_name(inode, part);
|
||||
if (!inode.isValid()) {
|
||||
auto parent = crumb_id;
|
||||
crumb_id = crumb_id.fileSystem()->child_of_directory_inode_with_name(crumb_id, part);
|
||||
if (!crumb_id.isValid()) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("child <%s>(%u) not found in directory, %02u:%08u\n", part.characters(), part.length(), parent.fsid(), parent.index());
|
||||
#endif
|
||||
|
@ -539,21 +536,21 @@ InodeIdentifier VFS::resolve_path(const String& path, int& error, InodeIdentifie
|
|||
#ifdef VFS_DEBUG
|
||||
kprintf("<%s> %u:%u\n", part.characters(), inode.fsid(), inode.index());
|
||||
#endif
|
||||
if (auto mount = find_mount_for_host(inode)) {
|
||||
if (auto mount = find_mount_for_host(crumb_id)) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf(" -- is host\n");
|
||||
#endif
|
||||
inode = mount->guest();
|
||||
crumb_id = mount->guest();
|
||||
}
|
||||
if (inode_was_root_at_head_of_loop && inode.isRootInode() && !is_vfs_root(inode) && part == "..") {
|
||||
if (inode_was_root_at_head_of_loop && crumb_id.isRootInode() && !is_vfs_root(crumb_id) && part == "..") {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf(" -- is guest\n");
|
||||
#endif
|
||||
auto mount = find_mount_for_guest(inode);
|
||||
inode = mount->host();
|
||||
inode = inode.fileSystem()->child_of_directory_inode_with_name(inode, "..");
|
||||
auto mount = find_mount_for_guest(crumb_id);
|
||||
crumb_id = mount->host();
|
||||
crumb_id = crumb_id.fileSystem()->child_of_directory_inode_with_name(crumb_id, "..");
|
||||
}
|
||||
metadata = inode.metadata();
|
||||
metadata = crumb_id.metadata();
|
||||
if (metadata.isSymbolicLink()) {
|
||||
if (i == parts.size() - 1) {
|
||||
if (options & O_NOFOLLOW) {
|
||||
|
@ -561,17 +558,17 @@ InodeIdentifier VFS::resolve_path(const String& path, int& error, InodeIdentifie
|
|||
return { };
|
||||
}
|
||||
if (options & O_NOFOLLOW_NOERROR)
|
||||
return inode;
|
||||
return crumb_id;
|
||||
}
|
||||
inode = resolveSymbolicLink(parent, inode, error);
|
||||
if (!inode.isValid()) {
|
||||
crumb_id = resolveSymbolicLink(parent, crumb_id, error);
|
||||
if (!crumb_id.isValid()) {
|
||||
kprintf("Symbolic link resolution failed :(\n");
|
||||
return { };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return inode;
|
||||
return crumb_id;
|
||||
}
|
||||
|
||||
void Vnode::retain()
|
||||
|
@ -598,10 +595,10 @@ const InodeMetadata& Vnode::metadata() const
|
|||
return m_cachedMetadata;
|
||||
}
|
||||
|
||||
VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
||||
VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guest_fs)
|
||||
: m_host(host)
|
||||
, m_guest(guestFileSystem->rootInode())
|
||||
, m_fileSystem(move(guestFileSystem))
|
||||
, m_guest(guest_fs->rootInode())
|
||||
, m_guest_fs(move(guest_fs))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -85,12 +85,12 @@ public:
|
|||
InodeIdentifier host() const { return m_host; }
|
||||
InodeIdentifier guest() const { return m_guest; }
|
||||
|
||||
const FileSystem& fileSystem() const { return *m_fileSystem; }
|
||||
const FileSystem& guest_fs() const { return *m_guest_fs; }
|
||||
|
||||
private:
|
||||
InodeIdentifier m_host;
|
||||
InodeIdentifier m_guest;
|
||||
RetainPtr<FileSystem> m_fileSystem;
|
||||
RetainPtr<FileSystem> m_guest_fs;
|
||||
};
|
||||
|
||||
static VFS& the() PURE;
|
||||
|
@ -135,7 +135,7 @@ private:
|
|||
|
||||
bool is_vfs_root(InodeIdentifier) const;
|
||||
|
||||
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
|
||||
void traverse_directory_inode(CoreInode&, Function<bool(const FileSystem::DirectoryEntry&)>);
|
||||
InodeIdentifier resolve_path(const String& path, int& error, CoreInode& base, int options = 0);
|
||||
InodeIdentifier resolve_path(const String& path, int& error, InodeIdentifier base = InodeIdentifier(), int options = 0);
|
||||
InodeIdentifier resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
|
||||
|
@ -145,8 +145,8 @@ private:
|
|||
|
||||
RetainPtr<Vnode> makeNode(InodeIdentifier);
|
||||
RetainPtr<Vnode> makeNode(CharacterDevice&);
|
||||
RetainPtr<Vnode> getOrCreateNode(InodeIdentifier);
|
||||
RetainPtr<Vnode> getOrCreateNode(CharacterDevice&);
|
||||
RetainPtr<Vnode> get_or_create_node(InodeIdentifier);
|
||||
RetainPtr<Vnode> get_or_create_node(CharacterDevice&);
|
||||
|
||||
Mount* find_mount_for_host(InodeIdentifier);
|
||||
Mount* find_mount_for_guest(InodeIdentifier);
|
||||
|
|
|
@ -18,7 +18,7 @@ private:
|
|||
virtual void mouseDownEvent(MouseEvent&) override;
|
||||
virtual void mouseUpEvent(MouseEvent&) override;
|
||||
|
||||
virtual const char* className() const override { return "Button"; }
|
||||
virtual const char* class_name() const override { return "Button"; }
|
||||
|
||||
String m_caption;
|
||||
bool m_beingPressed { false };
|
||||
|
|
|
@ -18,7 +18,7 @@ private:
|
|||
virtual void paintEvent(PaintEvent&) override;
|
||||
virtual void mouseDownEvent(MouseEvent&) override;
|
||||
|
||||
virtual const char* className() const override { return "CheckBox"; }
|
||||
virtual const char* class_name() const override { return "CheckBox"; }
|
||||
|
||||
String m_caption;
|
||||
bool m_isChecked { false };
|
||||
|
|
|
@ -15,7 +15,7 @@ private:
|
|||
virtual void paintEvent(PaintEvent&) override;
|
||||
virtual void mouseMoveEvent(MouseEvent&) override;
|
||||
|
||||
virtual const char* className() const override { return "Label"; }
|
||||
virtual const char* class_name() const override { return "Label"; }
|
||||
|
||||
String m_text;
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
Object(Object* parent = nullptr);
|
||||
virtual ~Object();
|
||||
|
||||
virtual const char* className() const { return "Object"; }
|
||||
virtual const char* class_name() const { return "Object"; }
|
||||
|
||||
virtual void event(Event&);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
};
|
||||
HitTestResult hitTest(int x, int y);
|
||||
|
||||
virtual const char* className() const override { return "Widget"; }
|
||||
virtual const char* class_name() const override { return "Widget"; }
|
||||
|
||||
void setWindowRelativeRect(const Rect&);
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ void Window::event(Event& event)
|
|||
//printf("Window{%p}: %s %d,%d\n", this, me.name(), me.x(), me.y());
|
||||
if (m_mainWidget) {
|
||||
auto result = m_mainWidget->hitTest(me.x(), me.y());
|
||||
//printf("hit test for %d,%d found: %s{%p} %d,%d\n", me.x(), me.y(), result.widget->className(), result.widget, result.localX, result.localY);
|
||||
//printf("hit test for %d,%d found: %s{%p} %d,%d\n", me.x(), me.y(), result.widget->class_name(), result.widget, result.localX, result.localY);
|
||||
// FIXME: Re-use the existing event instead of crafting a new one?
|
||||
auto localEvent = make<MouseEvent>(event.type(), result.localX, result.localY, me.button());
|
||||
return result.widget->event(*localEvent);
|
||||
|
@ -67,7 +67,7 @@ void Window::event(Event& event)
|
|||
|
||||
if (event.isPaintEvent()) {
|
||||
auto& pe = static_cast<PaintEvent&>(event);
|
||||
printf("Window[\"%s\"]: paintEvent %d,%d %dx%d\n", className(),
|
||||
printf("Window[\"%s\"]: paintEvent %d,%d %dx%d\n", class_name(),
|
||||
pe.rect().x(),
|
||||
pe.rect().y(),
|
||||
pe.rect().width(),
|
||||
|
|
Loading…
Add table
Reference in a new issue