mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 18:58:40 +00:00
sys: unify write operations to prioritize VFS handles
This commit is contained in:
parent
61647f0e1f
commit
3fd1899f01
3 changed files with 14 additions and 9 deletions
|
|
@ -2519,8 +2519,18 @@ static const syscall_handler_fn sys_cmd_table[SYS_CMD_TABLE_SIZE] = {
|
|||
static uint64_t handle_sys_write(const syscall_args_t *args) {
|
||||
extern void cmd_write_len(const char *str, size_t len);
|
||||
process_t *proc = process_get_current();
|
||||
int fd = (int)args->arg1;
|
||||
const char *buf = (const char*)args->arg2;
|
||||
size_t len = (size_t)args->arg3;
|
||||
|
||||
if (proc && fd >= 0 && fd < MAX_PROCESS_FDS && proc->fds[fd]) {
|
||||
syscall_args_t fs_args = *args;
|
||||
fs_args.arg2 = args->arg1; // fd
|
||||
fs_args.arg3 = args->arg2; // buf
|
||||
fs_args.arg4 = args->arg3; // len
|
||||
return fs_cmd_write(&fs_args);
|
||||
}
|
||||
|
||||
if (!proc || !proc->is_user) {
|
||||
cmd_write_len(buf, len);
|
||||
return len;
|
||||
|
|
|
|||
|
|
@ -391,13 +391,9 @@ __attribute__((weak)) ssize_t write(int fd, const void *buf, size_t count) {
|
|||
return (ssize_t)n;
|
||||
}
|
||||
|
||||
if (_b_is_stdio_handle(h)) {
|
||||
n = sys_write_fs(h->kernel_fd, buf, (uint32_t)count);
|
||||
if (n < 0 && _b_is_stdio_handle(h)) {
|
||||
n = sys_write(h->kernel_fd, (const char *)buf, (int)count);
|
||||
} else {
|
||||
n = sys_write_fs(h->kernel_fd, buf, (uint32_t)count);
|
||||
if (n < 0) {
|
||||
n = sys_write(h->kernel_fd, (const char *)buf, (int)count);
|
||||
}
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
|
|
|
|||
|
|
@ -152,10 +152,9 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
|||
return 0;
|
||||
}
|
||||
total = size * nmemb;
|
||||
if (stream->fd <= 2) {
|
||||
n = sys_write_fs(stream->fd, ptr, (uint32_t)total);
|
||||
if (n < 0 && stream->fd <= 2) {
|
||||
n = sys_write(stream->fd, (const char *)ptr, (int)total);
|
||||
} else {
|
||||
n = sys_write_fs(stream->fd, ptr, (uint32_t)total);
|
||||
}
|
||||
if (n < 0) {
|
||||
stream->err = 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue