Kernel: remove warnings when a standard IO syscall returns an error
That will probably happen a lot. We want userspace to tell us IF THE ERROR IS RELEVANT. So, these unnecessary warnings are just noise. Userspace may also use these functions to check for file descriptors. For example, libc does this at program initialization, it checks whether fd 0 and 1 exist (by calling lseek() and seeing if it fails with errno=EBADF).
This commit is contained in:
parent
743aedcd49
commit
2dd3a23092
@ -15,26 +15,21 @@
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define STDIO_FAIL(function, error) kwarnln("%s failed with %s", #function, #error)
|
||||
|
||||
void sys_seek(Context* context, int fd, long offset, int whence)
|
||||
{
|
||||
if (whence < SEEK_SET || whence > SEEK_END)
|
||||
{
|
||||
STDIO_FAIL(seek, EINVAL);
|
||||
context->rax = -EINVAL;
|
||||
return;
|
||||
}
|
||||
if (fd >= TASK_MAX_FDS || fd < 0)
|
||||
{
|
||||
STDIO_FAIL(seek, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
Task* current_task = Scheduler::current_task();
|
||||
if (!current_task->files[fd].is_open())
|
||||
{
|
||||
STDIO_FAIL(seek, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
@ -48,7 +43,6 @@ void sys_seek(Context* context, int fd, long offset, int whence)
|
||||
__builtin_unreachable();
|
||||
if (new_offset < 0)
|
||||
{
|
||||
STDIO_FAIL(seek, EINVAL);
|
||||
context->rax = -EINVAL; // FIXME: Is this the right error?
|
||||
return;
|
||||
}
|
||||
@ -66,26 +60,22 @@ void sys_write(Context* context, int fd, size_t size, const char* addr)
|
||||
{
|
||||
if (!addr)
|
||||
{
|
||||
STDIO_FAIL(write, EFAULT);
|
||||
context->rax = -EFAULT;
|
||||
return;
|
||||
}
|
||||
if (fd >= TASK_MAX_FDS || fd < 0)
|
||||
{
|
||||
STDIO_FAIL(write, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
Task* current_task = Scheduler::current_task();
|
||||
if (!current_task->files[fd].is_open())
|
||||
{
|
||||
STDIO_FAIL(write, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
if (!current_task->files[fd].can_write())
|
||||
{
|
||||
STDIO_FAIL(write, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
@ -105,7 +95,6 @@ void sys_open(Context* context, const char* filename, int flags)
|
||||
|
||||
if (fd == TASK_MAX_FDS)
|
||||
{
|
||||
STDIO_FAIL(open, EMFILE);
|
||||
context->rax = -EMFILE;
|
||||
return;
|
||||
}
|
||||
@ -113,7 +102,6 @@ void sys_open(Context* context, const char* filename, int flags)
|
||||
VFS::Node* node = VFS::resolve_path(filename);
|
||||
if (!node)
|
||||
{
|
||||
STDIO_FAIL(open, ENOENT);
|
||||
context->rax = -ENOENT;
|
||||
return;
|
||||
}
|
||||
@ -122,7 +110,6 @@ void sys_open(Context* context, const char* filename, int flags)
|
||||
bool can_write = (flags & OPEN_WRITE) > 0;
|
||||
if (!can_read && !can_write)
|
||||
{
|
||||
STDIO_FAIL(open, EINVAL);
|
||||
context->rax = -EINVAL;
|
||||
return;
|
||||
}
|
||||
@ -142,20 +129,17 @@ void sys_read(Context* context, int fd, size_t size, char* buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
{
|
||||
STDIO_FAIL(read, EFAULT);
|
||||
context->rax = -EFAULT;
|
||||
return;
|
||||
}
|
||||
if (fd >= TASK_MAX_FDS || fd < 0)
|
||||
{
|
||||
STDIO_FAIL(read, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
Task* current_task = Scheduler::current_task();
|
||||
if (!current_task->files[fd].is_open() || !current_task->files[fd].can_read())
|
||||
{
|
||||
STDIO_FAIL(read, EBADF);
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
@ -168,14 +152,14 @@ void sys_close(Context* context, int fd)
|
||||
{
|
||||
if (fd >= TASK_MAX_FDS || fd < 0)
|
||||
{
|
||||
STDIO_FAIL(close, EBADF);
|
||||
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
Task* current_task = Scheduler::current_task();
|
||||
if (!current_task->files[fd].is_open())
|
||||
{
|
||||
STDIO_FAIL(close, EBADF);
|
||||
|
||||
context->rax = -EBADF;
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user