open(): Add a third optional mode argument

This commit is contained in:
apio 2022-10-27 07:52:57 +02:00
parent a3c6635f3e
commit 1c35eabb2b
6 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include "interrupts/Context.h"
#include <stddef.h>
#include <sys/types.h>
#define SYS_exit 0
#define SYS_yield 1
@ -45,7 +46,7 @@ void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h,
void sys_getprocid(Context* context, int field);
void sys_mmap(Context* context, void* address, size_t size, int prot);
void sys_munmap(Context* context, void* address, size_t size);
void sys_open(Context* context, const char* filename, int flags);
void sys_open(Context* context, const char* filename, int flags, mode_t mode);
void sys_read(Context* context, int fd, size_t size, char* buffer);
void sys_close(Context* context, int fd);
void sys_seek(Context* context, int fd, long offset, int whence);

View File

@ -19,7 +19,7 @@ void Syscall::entry(Context* context)
case SYS_getprocid: sys_getprocid(context, (int)context->rdi); break;
case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx); break;
case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break;
case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi); break;
case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi, (mode_t)context->rdx); break;
case SYS_read: sys_read(context, (int)context->rdi, context->rsi, (char*)context->rdx); break;
case SYS_close: sys_close(context, (int)context->rdi); break;
case SYS_seek: sys_seek(context, (int)context->rdi, (long)context->rsi, (int)context->rdx); break;

View File

@ -11,6 +11,7 @@
#include "sys/UserMemory.h"
#include "thread/Scheduler.h"
#include "thread/Task.h"
#include <sys/types.h>
#define OPEN_READ 1
#define OPEN_WRITE 2
@ -137,7 +138,7 @@ void sys_write(Context* context, int fd, size_t size, const char* addr)
return;
}
void sys_open(Context* context, const char* filename, int flags)
void sys_open(Context* context, const char* filename, int flags, mode_t) // FIXME: mode is not used.
{
Task* current_task = Scheduler::current_task();
int fd = current_task->alloc_fd();

View File

@ -31,7 +31,7 @@ extern "C"
#endif
/* Opens the file specified by pathname. Returns a file descriptor on success, or -1 on error. */
int open(const char* pathname, int flags);
int open(const char* pathname, int flags, ...);
/* Performs an operation on the file descriptor fd determined by cmd. */
int fcntl(int fd, int cmd, ...);

View File

@ -6,9 +6,13 @@
extern "C"
{
int open(const char* pathname, int flags)
int open(const char* pathname, int flags, ...)
{
return (int)syscall(SYS_open, pathname, flags);
va_list ap;
va_start(ap, flags);
long result = syscall(SYS_open, pathname, flags, va_arg(ap, unsigned int));
va_end(ap);
return (int)result;
}
int fcntl(int fd, int cmd, ...)

View File

@ -26,13 +26,13 @@ extern "C" long syscall(long number, ...)
case SYS_fstat:
case SYS_stat:
case SYS_dup2:
case SYS_pstat:
case SYS_open: {
case SYS_pstat: {
arg arg0 = va_arg(ap, arg);
arg arg1 = va_arg(ap, arg);
result = __luna_syscall2(number, arg0, arg1);
break;
}
case SYS_open:
case SYS_getdents:
case SYS_fcntl:
case SYS_seek: