1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 00:35:06 +00:00

Add support for removing directories.

It's really only supported in Ext2FS since SynthFS doesn't really want you
mucking around with its files. This is pretty neat though :^)

I ran into some trouble with HashMap while working on this but opted to work
around it and leave that for a separate investigation.
This commit is contained in:
Andreas Kling 2019-01-28 04:16:01 +01:00
parent 031c62a21e
commit c95228b128
19 changed files with 185 additions and 40 deletions

View file

@ -200,7 +200,7 @@ InodeMetadata SynthFSInode::metadata() const
return m_metadata;
}
ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor)
ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor) const
{
#ifdef SYNTHFS_DEBUG
kprintf("SynthFS: read_bytes %u\n", index());
@ -211,10 +211,10 @@ ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileD
ByteBuffer generatedData;
if (m_generator) {
if (!descriptor) {
generatedData = m_generator(*this);
generatedData = m_generator(const_cast<SynthFSInode&>(*this));
} else {
if (!descriptor->generator_cache())
descriptor->generator_cache() = m_generator(*this);
descriptor->generator_cache() = m_generator(const_cast<SynthFSInode&>(*this));
generatedData = descriptor->generator_cache();
}
}
@ -227,7 +227,7 @@ ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileD
return nread;
}
bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback)
bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
{
InterruptDisabler disabler;
#ifdef SYNTHFS_DEBUG
@ -305,3 +305,10 @@ bool SynthFSInode::remove_child(const String& name, int& error)
SynthFSInodeCustomData::~SynthFSInodeCustomData()
{
}
size_t SynthFSInode::directory_entry_count() const
{
ASSERT(is_directory());
// NOTE: The 2 is for '.' and '..'
return m_children.size() + 2;
}