Implement read_dir_entry () VFS op, CE add ls command

This commit is contained in:
2026-02-25 16:25:43 +01:00
parent 704db2dfa4
commit 29bbcea435
12 changed files with 189 additions and 23 deletions

View File

@@ -371,7 +371,7 @@ DEFINE_SYSCALL (sys_read) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_read (proc, proc->cwv, path, buffer, off, size, rctx);
int ret = vfs_read (proc, proc->cwv, path, buffer, off, size);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -401,7 +401,7 @@ DEFINE_SYSCALL (sys_describe) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_describe (proc, proc->cwv, path, desc, rctx);
int ret = vfs_describe (proc, proc->cwv, path, desc);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -419,6 +419,37 @@ DEFINE_SYSCALL (sys_get_procgroup) {
return SYSRESULT (target_proc->procgroup->pgid);
}
/* int read_dir_entry (char* path, struct dir_entry* entry, size_t entry_num) */
DEFINE_SYSCALL (sys_read_dir_entry) {
uintptr_t uvaddr_path = a1;
uintptr_t uvaddr_entry = a2;
size_t entry_num = (size_t)a3;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
uintptr_t out_paddr;
spin_lock (&proc->procgroup->lock);
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
spin_unlock (&proc->procgroup->lock);
if (out_paddr == 0)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
struct dir_entry* entry = sys_get_user_buffer (proc, uvaddr_entry, sizeof (struct dir_entry));
if (entry == NULL)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_read_dir_entry (proc, proc->cwv, path, entry, entry_num);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
}
/* int get_exec_pid (void) */
DEFINE_SYSCALL (sys_get_exec_pid) { return SYSRESULT (proc->exec_pid); }
@@ -444,6 +475,7 @@ static syscall_handler_func_t handler_table[] = {
[SYS_MAIL_RECEIVE] = &sys_mail_receive,
[SYS_GET_PROCGROUP] = &sys_get_procgroup,
[SYS_GET_EXEC_PID] = &sys_get_exec_pid,
[SYS_READ_DIR_ENTRY] = &sys_read_dir_entry,
};
syscall_handler_func_t syscall_find_handler (int syscall_num) {