From 20853582d5385d12421433d21910e783caa00764 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 13 Sep 2020 22:59:42 -0400 Subject: dirinfo command --- src/kernel/idt.c | 7 +++++- src/kernel/isrs.asm | 2 +- src/user/dirinfo/dirinfo.c | 49 ++++++++++++++++++++++++++++++++++++++++ src/user/include/pland/syscall.h | 13 ++++++++++- src/user/knob/entry.asm | 2 +- 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/user/dirinfo/dirinfo.c (limited to 'src') diff --git a/src/kernel/idt.c b/src/kernel/idt.c index 4ffa1e2..90d8dc3 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -96,6 +96,10 @@ static void sc_wait_for_task(uint32_t handle) { active_task->wait_arg = handle; } +static uint32_t sc_enumerate_dir(uint32_t drive_number, const char *path, struct directory_content_info *buffer, uint32_t max_entries) { + return drives[drive_number].enumerate_dir(drives + drive_number, path, buffer, max_entries); +} + void const *syscall_table[] = { &sc_open_file, &sc_close_file, @@ -106,7 +110,8 @@ void const *syscall_table[] = { &get_key_code, &sc_allocate_ram, &sc_memory_info, - &sc_wait_for_task + &sc_wait_for_task, + &sc_enumerate_dir }; //these aren't really void ()'s, but gcc complains if we take an address of a void, so we give it a type diff --git a/src/kernel/isrs.asm b/src/kernel/isrs.asm index 8a27d57..6ad469d 100644 --- a/src/kernel/isrs.asm +++ b/src/kernel/isrs.asm @@ -23,7 +23,7 @@ extern on_kbd_isr extern make_sure_tasks extern exception_halt -n_syscalls equ 0xa +n_syscalls equ 0xb ;section .bss ;_debug_is_start_task resb 1 diff --git a/src/user/dirinfo/dirinfo.c b/src/user/dirinfo/dirinfo.c new file mode 100644 index 0000000..7484eb8 --- /dev/null +++ b/src/user/dirinfo/dirinfo.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#define MAX_DIR_ENTRIES 20 + +void main(const char *arg) { + uint8_t dn; + const char *path = remove_prefix(arg, &dn); + + tell_user_sz("Directory info for "); + tell_user_sz(*arg ? arg : "drive root"); + tell_user_sz("\n"); + + _dir_info_entry infos[MAX_DIR_ENTRIES]; + uint8_t count = _enumerate_dir(dn, path, infos, MAX_DIR_ENTRIES); + tell_user_sz( + count == MAX_DIR_ENTRIES + ? "Truncated to 20 entries.\n\n" + : "\n" + ); + + uint32_t total_size = 0; + + if (!count) + tell_user_sz("(none)\n"); + + for (uint8_t i = 0; i < count; ++i) { + tell_user_sz(infos[i].name); + tell_user_sz(": "); + if (infos[i].is_dir) + tell_user_sz("dir"); + else { + char nbuf[11]; + itosz(infos[i].size, nbuf); + tell_user_sz(nbuf); + tell_user_sz(" bytes"); + total_size += infos[i].size; + } + tell_user_sz("\n"); + } + + tell_user_sz("\nTotal size without subdirectories: "); + char nbuf[11]; + itosz(total_size, nbuf); + tell_user_sz(nbuf); + tell_user_sz(" bytes\n"); +} \ No newline at end of file diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h index 75383fc..e16a7fb 100644 --- a/src/user/include/pland/syscall.h +++ b/src/user/include/pland/syscall.h @@ -45,9 +45,16 @@ enum _scn { _SCN_GET_KEY, _SCN_ALLOCATE_RAM, _SCN_MEMORY_INFO, - _SCN_WAIT_FOR_TASK + _SCN_WAIT_FOR_TASK, + _SCN_ENUMERATE_DIR }; +typedef struct { + bool is_dir; + char name[100]; + uint32_t size; +} _dir_info_entry; + static inline uint32_t _sc0(enum _scn eax) { volatile uint32_t out; asm ( @@ -166,4 +173,8 @@ static inline void _wait_for_task(_process_handle_t handle) { _sc1(_SCN_WAIT_FOR_TASK, handle); } +static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char *path, _dir_info_entry *buffer, uint32_t max_count) { + return _sc4(_SCN_ENUMERATE_DIR, drive_number, (uint32_t)path, (uint32_t)buffer, max_count); +} + #endif \ No newline at end of file diff --git a/src/user/knob/entry.asm b/src/user/knob/entry.asm index acf6f5f..e9548d4 100644 --- a/src/user/knob/entry.asm +++ b/src/user/knob/entry.asm @@ -19,5 +19,5 @@ _entry: jmp main section .stack nobits alloc noexec write align=16 -resb 1024 +resb 4096 stack: \ No newline at end of file -- cgit v1.2.3