mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:48:12 +00:00
Kernel: Add a basic lock to FileDescription
Let's prevent two processes sharing a FileDescription from messing with it at the same time for now.
This commit is contained in:
parent
9513f54932
commit
14d4b1058e
2 changed files with 11 additions and 0 deletions
|
@ -67,6 +67,7 @@ KResult FileDescription::fstat(stat& buffer)
|
|||
|
||||
off_t FileDescription::seek(off_t offset, int whence)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
if (!m_file->is_seekable())
|
||||
return -EINVAL;
|
||||
|
||||
|
@ -103,6 +104,7 @@ off_t FileDescription::seek(off_t offset, int whence)
|
|||
|
||||
ssize_t FileDescription::read(u8* buffer, ssize_t count)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
SmapDisabler disabler;
|
||||
int nread = m_file->read(*this, buffer, count);
|
||||
if (nread > 0 && m_file->is_seekable())
|
||||
|
@ -112,6 +114,7 @@ ssize_t FileDescription::read(u8* buffer, ssize_t count)
|
|||
|
||||
ssize_t FileDescription::write(const u8* data, ssize_t size)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
SmapDisabler disabler;
|
||||
int nwritten = m_file->write(*this, data, size);
|
||||
if (nwritten > 0 && m_file->is_seekable())
|
||||
|
@ -140,6 +143,7 @@ ByteBuffer FileDescription::read_entire_file()
|
|||
|
||||
ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
if (!is_directory())
|
||||
return -ENOTDIR;
|
||||
|
||||
|
@ -245,11 +249,13 @@ InodeMetadata FileDescription::metadata() const
|
|||
|
||||
KResultOr<Region*> FileDescription::mmap(Process& process, VirtualAddress vaddr, size_t offset, size_t size, int prot)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return m_file->mmap(process, *this, vaddr, offset, size, prot);
|
||||
}
|
||||
|
||||
KResult FileDescription::truncate(off_t length)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return m_file->truncate(length);
|
||||
}
|
||||
|
||||
|
@ -286,6 +292,7 @@ const Socket* FileDescription::socket() const
|
|||
|
||||
void FileDescription::set_file_flags(u32 flags)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
m_is_blocking = !(flags & O_NONBLOCK);
|
||||
m_should_append = flags & O_APPEND;
|
||||
m_direct = flags & O_DIRECT;
|
||||
|
@ -294,10 +301,12 @@ void FileDescription::set_file_flags(u32 flags)
|
|||
|
||||
KResult FileDescription::chmod(mode_t mode)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return m_file->chmod(mode);
|
||||
}
|
||||
|
||||
KResult FileDescription::chown(uid_t uid, gid_t gid)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return m_file->chown(uid, gid);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue