Kernel/LibC: Implement pread()

This commit is contained in:
Bananymous 2023-11-28 23:47:30 +02:00
parent 4c3da66c92
commit 09b7cb2f33
5 changed files with 19 additions and 0 deletions

View File

@ -105,6 +105,8 @@ namespace Kernel
BAN::ErrorOr<long> sys_readlink(const char* path, char* buffer, size_t bufsize);
BAN::ErrorOr<long> sys_readlinkat(int fd, const char* path, char* buffer, size_t bufsize);
BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset);
BAN::ErrorOr<long> sys_chmod(const char*, mode_t);
BAN::ErrorOr<long> sys_pipe(int fildes[2]);

View File

@ -823,6 +823,14 @@ namespace Kernel
return readlink_impl(absolute_path.sv(), buffer, bufsize);
}
BAN::ErrorOr<long> Process::sys_pread(int fd, void* buffer, size_t count, off_t offset)
{
LockGuard _(m_lock);
validate_pointer_access(buffer, count);
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
return TRY(inode->read(offset, { (uint8_t*)buffer, count }));
}
BAN::ErrorOr<long> Process::sys_chmod(const char* path, mode_t mode)
{
if (mode & S_IFMASK)

View File

@ -220,6 +220,9 @@ namespace Kernel
case SYS_MSYNC:
ret = Process::current().sys_msync((void*)arg1, (size_t)arg2, (int)arg3);
break;
case SYS_PREAD:
ret = Process::current().sys_pread((int)arg1, (void*)arg2, (size_t)arg3, (off_t)arg4);
break;
default:
dwarnln("Unknown syscall {}", syscall);
break;

View File

@ -62,6 +62,7 @@ __BEGIN_DECLS
#define SYS_READLINK 59
#define SYS_READLINKAT 60
#define SYS_MSYNC 61
#define SYS_PREAD 62
__END_DECLS

View File

@ -88,6 +88,11 @@ ssize_t readlinkat(int fd, const char* __restrict path, char* __restrict buf, si
return syscall(SYS_READLINKAT, fd, path, buf, bufsize);
}
ssize_t pread(int fildes, void* buf, size_t nbyte, off_t offset)
{
return syscall(SYS_PREAD, fildes, buf, nbyte, offset);
}
int dup(int fildes)
{
return syscall(SYS_DUP, fildes);