From 359e5c6d78d1a681dcd345af74ad46a84f0515f3 Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Wed, 16 Jul 2025 15:42:35 +0300 Subject: [PATCH] syscalls: add chdir and getcwd syscalls, not tested yet --- include/task.h | 1 + src/tasking/syscalls.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/task.h b/include/task.h index 062872e..8fdb46d 100644 --- a/include/task.h +++ b/include/task.h @@ -65,6 +65,7 @@ typedef struct Process struct Process* next; // Следующий процесс file_t* file_descriptors[MAX_OPEN_FILES]; + dir_t* cwd; } Process; extern Process* current; diff --git a/src/tasking/syscalls.c b/src/tasking/syscalls.c index f114a1b..b8998d8 100644 --- a/src/tasking/syscalls.c +++ b/src/tasking/syscalls.c @@ -230,6 +230,22 @@ int sys_close(TrapFrame *tf) return -1; } +int sys_chdir(TrapFrame *tf) +{ + return fat_opendir(current->cwd, (const char*)tf->ebx); +} + +int sys_getcwd(TrapFrame *tf) +{ + int len = tf->ecx; + + if(len >= 260) + return (int)NULL; + + memcpy((void*)tf->ebx, current->cwd->fat->name, current->cwd->fat->namelen); + return tf->ebx; +} + int sys_getpid(TrapFrame *tf) { return current->pid; @@ -268,9 +284,18 @@ void handle_syscall(TrapFrame *tf) tf->eax = sys_close(tf); break; + case 12://chdir + tf->eax = sys_chdir(tf); + break; + case 20://getpid tf->eax = sys_getpid(tf); break; + + case 183://getcwd + tf->eax = sys_getcwd(tf); + break; + default: debug_log("unknown syscall: %X\n", tf->eax); tf->eax = -1;