Kernel/LibC: Implement flock

This commit is contained in:
2025-06-25 18:46:20 +03:00
parent 0cbc39698c
commit 93e5d09a63
8 changed files with 120 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <BAN/Array.h>
#include <BAN/HashSet.h>
#include <kernel/FS/Inode.h>
#include <kernel/FS/VirtualFileSystem.h>
@@ -43,6 +44,8 @@ namespace Kernel
void close_all();
void close_cloexec();
BAN::ErrorOr<void> flock(int fd, int op);
BAN::ErrorOr<size_t> read(int fd, BAN::ByteSpan);
BAN::ErrorOr<size_t> write(int fd, BAN::ConstByteSpan);
@@ -69,6 +72,15 @@ namespace Kernel
off_t offset { 0 };
int status_flags;
struct flock_t
{
bool locked;
bool shared;
ThreadBlocker thread_blocker;
BAN::HashSet<pid_t> lockers;
};
flock_t flock;
friend class BAN::RefPtr<OpenFileDescription>;
};

View File

@@ -112,6 +112,8 @@ namespace Kernel
BAN::ErrorOr<long> sys_symlinkat(const char* path1, int fd, const char* path2);
BAN::ErrorOr<long> sys_flock(int fd, int op);
BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset);
BAN::ErrorOr<long> sys_pwrite(int fd, const void* buffer, size_t count, off_t offset);