diff options
-rw-r--r-- | doc/ints.txt | 43 | ||||
-rw-r--r-- | makefile | 10 | ||||
-rw-r--r-- | src/kernel/idt.c | 7 | ||||
-rw-r--r-- | src/kernel/isrs.asm | 2 | ||||
-rw-r--r-- | src/user/dirinfo/dirinfo.c | 49 | ||||
-rw-r--r-- | src/user/include/pland/syscall.h | 13 | ||||
-rw-r--r-- | src/user/knob/entry.asm | 2 |
7 files changed, 104 insertions, 22 deletions
diff --git a/doc/ints.txt b/doc/ints.txt index 191d719..d8abd6d 100644 --- a/doc/ints.txt +++ b/doc/ints.txt @@ -24,20 +24,19 @@ invalid system call numbers change eax to -1, and have no other effect. table 1: - function | eax | eax out | ebx | ecx | edx | esi | edi ----------------|-----|---------------|---------------|-------------|-----------|--------|----- - open file | 0x0 | handle | drive number | path | | | - close file | 0x1 | | handle | | | | - file read | 0x2 | read | handle | file offset | count | buffer | - get file size | 0x3 | size | handle | | | | - start task | 0x4 | handle | drive number | path | passed sz | | - log string | 0x5 | | sz string | | | | - get key | 0x6 | keycode | | | | | - allocate ram | 0x7 | start pointer | pages | | | | - memory info | 0x8 | see table 2 | see table 2 | | | | - wait for task | 0x9 | | handle | | | | - - + function | eax | eax out | ebx | ecx | edx | esi | edi +---------------|-----|---------------|---------------|-------------|-------------|--------|----- + open file | 0x0 | handle | drive number | path | | | + close file | 0x1 | | handle | | | | + file read | 0x2 | read | handle | file offset | count | buffer | + get file size | 0x3 | size | handle | | | | + start task | 0x4 | handle | drive number | path | passed sz | | + log string | 0x5 | | sz string | | | | + get key | 0x6 | keycode | | | | | + allocate ram | 0x7 | start pointer | pages | | | | + memory info | 0x8 | see table 2 | see table 2 | | | | + wait for task | 0x9 | | handle | | | | + enumerate dir | 0xa | count | drive number | path | see table 3 | max | table 2: @@ -50,4 +49,18 @@ eax -1 indicates unrecognized ebx 0x1 | kernel dynamic area left 0x2 | total userspace size 0x3 | total userspace left - 0x4 | this process memory left
\ No newline at end of file + 0x4 | this process memory left + + +table 3: +edx of "enumerate dir" is a pointer to a buffer where an array of "directory info"s can be put. +esi is the maximum number of "directory info"s to be placed in the buffer. +the "directory info" structure is defined as follows: + struct { + bool is_dir; + char name[100]; + uint32_t size; + } +"is_dir" here indicates whether or not the entry is another directory. +"name" is a null-terminated string, up to 99 characters, indicating the name of the entry. +"size" is the size of the file this entry refers to, in bytes.
\ No newline at end of file @@ -28,8 +28,9 @@ out/fs/bin/%: obj/%.elf mkdir -p $(shell dirname $@) objcopy -S $< $@ -out/fs: out/fs/bin/init out/fs/bin/meminfo out/fs/bin/highway \ - out/fs/bin/hello out/fs/bin/dumptext out/fs/bin/dumphex +out/fs: out/fs/bin/init out/fs/bin/meminfo out/fs/bin/highway \ + out/fs/bin/hello out/fs/bin/dumptext out/fs/bin/dumphex \ + out/fs/bin/dirinfo mkdir -p out/fs cp -r fs-skel/* out/fs/ @@ -85,4 +86,7 @@ obj/dumptext.elf: obj/dumptext/dumptext.o obj/knob.so ld -T src/user/elf.ld obj/dumptext/* obj/knob.so -o obj/dumptext.elf obj/dumphex.elf: obj/dumphex/dumphex.o obj/knob.so - ld -T src/user/elf.ld obj/dumphex/* obj/knob.so -o obj/dumphex.elf
\ No newline at end of file + ld -T src/user/elf.ld obj/dumphex/* obj/knob.so -o obj/dumphex.elf + +obj/dirinfo.elf: obj/dirinfo/dirinfo.o obj/knob.so + ld -T src/user/elf.ld obj/dirinfo/* obj/knob.so -o obj/dirinfo.elf
\ No newline at end of file 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 <pland/syscall.h> +#include <knob/format.h> +#include <knob/file.h> +#include <knob/user.h> + +#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 |