mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
Kernel+LibC: Implement fsync
This commit is contained in:
parent
fd3735199b
commit
a81b21c1a7
Notes:
sideshowbarker
2024-07-18 04:12:18 +09:00
Author: https://github.com/SeekingBlues Commit: https://github.com/SerenityOS/serenity/commit/a81b21c1a7f Pull-request: https://github.com/SerenityOS/serenity/pull/9983
@ -79,6 +79,7 @@ enum class NeedsBigProcessLock {
|
||||
S(fork, NeedsBigProcessLock::Yes) \
|
||||
S(fstat, NeedsBigProcessLock::Yes) \
|
||||
S(fstatvfs, NeedsBigProcessLock::Yes) \
|
||||
S(fsync, NeedsBigProcessLock::Yes) \
|
||||
S(ftruncate, NeedsBigProcessLock::Yes) \
|
||||
S(futex, NeedsBigProcessLock::Yes) \
|
||||
S(get_dir_entries, NeedsBigProcessLock::Yes) \
|
||||
|
@ -204,6 +204,7 @@ set(KERNEL_SOURCES
|
||||
Syscalls/exit.cpp
|
||||
Syscalls/fcntl.cpp
|
||||
Syscalls/fork.cpp
|
||||
Syscalls/fsync.cpp
|
||||
Syscalls/ftruncate.cpp
|
||||
Syscalls/futex.cpp
|
||||
Syscalls/get_dir_entries.cpp
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
virtual String absolute_path(const OpenFileDescription&) const = 0;
|
||||
|
||||
virtual KResult truncate(u64) { return EINVAL; }
|
||||
virtual KResult sync() { return EINVAL; }
|
||||
virtual KResult chown(OpenFileDescription&, UserID, GroupID) { return EBADF; }
|
||||
virtual KResult chmod(OpenFileDescription&, mode_t) { return EBADF; }
|
||||
|
||||
|
@ -51,7 +51,7 @@ FileSystem::DirectoryEntryView::DirectoryEntryView(const StringView& n, InodeIde
|
||||
|
||||
void FileSystem::sync()
|
||||
{
|
||||
Inode::sync();
|
||||
Inode::sync_all();
|
||||
|
||||
NonnullRefPtrVector<FileSystem, 32> file_systems;
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ SpinlockProtected<Inode::AllInstancesList>& Inode::all_instances()
|
||||
return s_all_instances;
|
||||
}
|
||||
|
||||
void Inode::sync()
|
||||
void Inode::sync_all()
|
||||
{
|
||||
NonnullRefPtrVector<Inode, 32> inodes;
|
||||
Inode::all_instances().with([&](auto& all_inodes) {
|
||||
@ -45,6 +45,13 @@ void Inode::sync()
|
||||
}
|
||||
}
|
||||
|
||||
void Inode::sync()
|
||||
{
|
||||
if (is_metadata_dirty())
|
||||
flush_metadata();
|
||||
fs().flush_writes();
|
||||
}
|
||||
|
||||
KResultOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(OpenFileDescription* description) const
|
||||
{
|
||||
auto builder = TRY(KBufferBuilder::try_create());
|
||||
|
@ -87,7 +87,8 @@ public:
|
||||
void set_shared_vmobject(Memory::SharedInodeVMObject&);
|
||||
RefPtr<Memory::SharedInodeVMObject> shared_vmobject() const;
|
||||
|
||||
static void sync();
|
||||
static void sync_all();
|
||||
void sync();
|
||||
|
||||
bool has_watchers() const { return !m_watchers.is_empty(); }
|
||||
|
||||
|
@ -107,6 +107,12 @@ KResult InodeFile::truncate(u64 size)
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
KResult InodeFile::sync()
|
||||
{
|
||||
m_inode->sync();
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
KResult InodeFile::chown(OpenFileDescription& description, UserID uid, GroupID gid)
|
||||
{
|
||||
VERIFY(description.inode() == m_inode);
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
virtual String absolute_path(const OpenFileDescription&) const override;
|
||||
|
||||
virtual KResult truncate(u64) override;
|
||||
virtual KResult sync() override;
|
||||
virtual KResult chown(OpenFileDescription&, UserID, GroupID) override;
|
||||
virtual KResult chmod(OpenFileDescription&, mode_t) override;
|
||||
|
||||
|
@ -383,6 +383,12 @@ KResult OpenFileDescription::truncate(u64 length)
|
||||
return m_file->truncate(length);
|
||||
}
|
||||
|
||||
KResult OpenFileDescription::sync()
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
return m_file->sync();
|
||||
}
|
||||
|
||||
bool OpenFileDescription::is_fifo() const
|
||||
{
|
||||
return m_file->is_fifo();
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
void set_original_custody(Badge<VirtualFileSystem>, Custody& custody);
|
||||
|
||||
KResult truncate(u64);
|
||||
KResult sync();
|
||||
|
||||
off_t offset() const { return m_current_offset; }
|
||||
|
||||
|
@ -363,6 +363,7 @@ public:
|
||||
KResultOr<FlatPtr> sys$fchmod(int fd, mode_t);
|
||||
KResultOr<FlatPtr> sys$chown(Userspace<const Syscall::SC_chown_params*>);
|
||||
KResultOr<FlatPtr> sys$fchown(int fd, UserID, GroupID);
|
||||
KResultOr<FlatPtr> sys$fsync(int fd);
|
||||
KResultOr<FlatPtr> sys$socket(int domain, int type, int protocol);
|
||||
KResultOr<FlatPtr> sys$bind(int sockfd, Userspace<const sockaddr*> addr, socklen_t);
|
||||
KResultOr<FlatPtr> sys$listen(int sockfd, int backlog);
|
||||
|
19
Kernel/Syscalls/fsync.cpp
Normal file
19
Kernel/Syscalls/fsync.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
KResultOr<FlatPtr> Process::sys$fsync(int fd)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||
REQUIRE_PROMISE(stdio);
|
||||
auto description = TRY(fds().open_file_description(fd));
|
||||
return description->sync();
|
||||
}
|
||||
|
||||
}
|
@ -709,10 +709,10 @@ void sysbeep()
|
||||
syscall(SC_beep);
|
||||
}
|
||||
|
||||
int fsync([[maybe_unused]] int fd)
|
||||
int fsync(int fd)
|
||||
{
|
||||
dbgln("FIXME: Implement fsync()");
|
||||
return 0;
|
||||
int rc = syscall(SC_fsync, fd);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int halt()
|
||||
|
Loading…
Reference in New Issue
Block a user