mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
Kernel: FileDescription::is_directory() should not assert !is_fifo()
I have no idea why this was here. It makes no sense. If you're trying to find out if something is a directory, why wouldn't you be allowed to ask that about a FIFO? :^) Thanks to Brandon for spotting this! Also, while we're here, cache the directory state in a bool member so we don't have to keep fetching inode metadata when checking this repeatedly. This is important since sys$read() now calls it.
This commit is contained in:
parent
4e25d69dba
commit
558c63a6f9
2 changed files with 6 additions and 8 deletions
|
@ -34,6 +34,7 @@ FileDescription::FileDescription(File& file)
|
||||||
m_inode = static_cast<InodeFile&>(file).inode();
|
m_inode = static_cast<InodeFile&>(file).inode();
|
||||||
if (is_socket())
|
if (is_socket())
|
||||||
socket()->attach(*this);
|
socket()->attach(*this);
|
||||||
|
m_is_directory = metadata().is_directory();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescription::~FileDescription()
|
FileDescription::~FileDescription()
|
||||||
|
@ -138,19 +139,15 @@ ByteBuffer FileDescription::read_entire_file()
|
||||||
return m_inode->read_entire(this);
|
return m_inode->read_entire(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescription::is_directory() const
|
|
||||||
{
|
|
||||||
ASSERT(!is_fifo());
|
|
||||||
return metadata().is_directory();
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size)
|
ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
|
if (!is_directory())
|
||||||
|
return -ENOTDIR;
|
||||||
|
|
||||||
auto metadata = this->metadata();
|
auto metadata = this->metadata();
|
||||||
if (!metadata.is_valid())
|
if (!metadata.is_valid())
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (!metadata.is_directory())
|
|
||||||
return -ENOTDIR;
|
|
||||||
|
|
||||||
int size_to_allocate = max(PAGE_SIZE, metadata.size);
|
int size_to_allocate = max(PAGE_SIZE, metadata.size);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
|
|
||||||
String absolute_path() const;
|
String absolute_path() const;
|
||||||
|
|
||||||
bool is_directory() const;
|
bool is_directory() const { return m_is_directory; }
|
||||||
|
|
||||||
File& file() { return *m_file; }
|
File& file() { return *m_file; }
|
||||||
const File& file() const { return *m_file; }
|
const File& file() const { return *m_file; }
|
||||||
|
@ -115,6 +115,7 @@ private:
|
||||||
u32 m_file_flags { 0 };
|
u32 m_file_flags { 0 };
|
||||||
|
|
||||||
bool m_is_blocking { true };
|
bool m_is_blocking { true };
|
||||||
|
bool m_is_directory { false };
|
||||||
bool m_should_append { false };
|
bool m_should_append { false };
|
||||||
FIFO::Direction m_fifo_direction { FIFO::Direction::Neither };
|
FIFO::Direction m_fifo_direction { FIFO::Direction::Neither };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue