syscalls: add chdir and getcwd syscalls, not tested yet
This commit is contained in:
@@ -65,6 +65,7 @@ typedef struct Process
|
|||||||
struct Process* next; // Следующий процесс
|
struct Process* next; // Следующий процесс
|
||||||
|
|
||||||
file_t* file_descriptors[MAX_OPEN_FILES];
|
file_t* file_descriptors[MAX_OPEN_FILES];
|
||||||
|
dir_t* cwd;
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
extern Process* current;
|
extern Process* current;
|
||||||
|
|||||||
@@ -230,6 +230,22 @@ int sys_close(TrapFrame *tf)
|
|||||||
return -1;
|
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)
|
int sys_getpid(TrapFrame *tf)
|
||||||
{
|
{
|
||||||
return current->pid;
|
return current->pid;
|
||||||
@@ -268,9 +284,18 @@ void handle_syscall(TrapFrame *tf)
|
|||||||
tf->eax = sys_close(tf);
|
tf->eax = sys_close(tf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 12://chdir
|
||||||
|
tf->eax = sys_chdir(tf);
|
||||||
|
break;
|
||||||
|
|
||||||
case 20://getpid
|
case 20://getpid
|
||||||
tf->eax = sys_getpid(tf);
|
tf->eax = sys_getpid(tf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 183://getcwd
|
||||||
|
tf->eax = sys_getcwd(tf);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_log("unknown syscall: %X\n", tf->eax);
|
debug_log("unknown syscall: %X\n", tf->eax);
|
||||||
tf->eax = -1;
|
tf->eax = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user