diff options
author | Benji Dial <benji6283@gmail.com> | 2020-09-19 14:53:29 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2020-09-19 14:53:29 -0400 |
commit | de20d7430df08731d9108acb83e1234ba7f1fe16 (patch) | |
tree | 8646f3d1bae3d30391df34766e3e58c0c2af8aab /src/user/knob | |
parent | 20853582d5385d12421433d21910e783caa00764 (diff) | |
download | portland-os-de20d7430df08731d9108acb83e1234ba7f1fe16.tar.gz |
file manager
Diffstat (limited to 'src/user/knob')
-rw-r--r-- | src/user/knob/block.c | 9 | ||||
-rw-r--r-- | src/user/knob/entry.asm | 23 | ||||
-rw-r--r-- | src/user/knob/file.c | 21 | ||||
-rw-r--r-- | src/user/knob/quit.c | 8 | ||||
-rw-r--r-- | src/user/knob/user.c | 13 |
5 files changed, 38 insertions, 36 deletions
diff --git a/src/user/knob/block.c b/src/user/knob/block.c index 7524ad3..4ec0564 100644 --- a/src/user/knob/block.c +++ b/src/user/knob/block.c @@ -14,4 +14,13 @@ bool blockequ(const void *a, const void *b, uint32_t size) { if (*(uint8_t *)(a++) != *(uint8_t *)(b++)) return false; return true; +} + +//returns length without null-terminator +uint32_t strcpy(char *to, const char *from) { + uint32_t i = 0; + do + to[i] = from[i]; + while (from[i++]); + return i - 1; }
\ No newline at end of file diff --git a/src/user/knob/entry.asm b/src/user/knob/entry.asm deleted file mode 100644 index e9548d4..0000000 --- a/src/user/knob/entry.asm +++ /dev/null @@ -1,23 +0,0 @@ -bits 32 - -global _entry - -extern main -extern quit - -extern current_disk - -section .text -_entry: - mov esp, stack - push edx - - ;TODO: determine current_disk - ;any further needed initialization - - push quit - jmp main - -section .stack nobits alloc noexec write align=16 -resb 4096 -stack:
\ No newline at end of file diff --git a/src/user/knob/file.c b/src/user/knob/file.c index 23b7564..f1a039d 100644 --- a/src/user/knob/file.c +++ b/src/user/knob/file.c @@ -1,4 +1,5 @@ #include <pland/syscall.h> +#include <pland/pcrt.h> #include <knob/format.h> #include <knob/heap.h> #include <knob/env.h> @@ -11,11 +12,13 @@ struct ofl_node { static struct ofl_node *head_ofl_node = 0; -void _close_all_files() { +static void _close_all_files() { for (struct ofl_node *i = head_ofl_node; i; i = i->next) _close_file(i->handle); } +BEFORE_QUIT(_close_all_files) + struct file { struct ofl_node *node; _file_handle_t handle; @@ -121,4 +124,20 @@ int32_t seek_file_by(struct file *f, int32_t by) { __attribute__ ((pure)) uint32_t file_size(struct file *f) { return f->length; +} + +//return value must be manually freed, unless it is a null pointer +_dir_info_entry_t *get_directory_info(const char *path, uint32_t *count_out) { + uint8_t dn; + path = remove_prefix(path, &dn); + + uint32_t count = _count_of_dir(dn, path); + if (!count) { + *count_out = 0; + return 0; + } + + _dir_info_entry_t *buffer = get_block(count * sizeof(_dir_info_entry_t)); + *count_out = _enumerate_dir(dn, path, buffer, count); + return buffer; }
\ No newline at end of file diff --git a/src/user/knob/quit.c b/src/user/knob/quit.c deleted file mode 100644 index 98881b7..0000000 --- a/src/user/knob/quit.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <pland/syscall.h> -#include <knob/file.h> - -__attribute__ ((noreturn)) -void quit() { - _close_all_files(); - _exit_task(); -}
\ No newline at end of file diff --git a/src/user/knob/user.c b/src/user/knob/user.c index b642f79..dfcb791 100644 --- a/src/user/knob/user.c +++ b/src/user/knob/user.c @@ -116,10 +116,8 @@ static const uint8_t shifted[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static char get_key_char() { - _key_code_t key; - while (!(key = _get_key())) - _yield_task(); +__attribute__ ((const)) +char key_to_char(_key_code_t key) { return key & _KEY_CAPS ? key & _KEY_SHIFT @@ -130,6 +128,13 @@ static char get_key_char() { : key & 0xff; } +static char get_key_char() { + _key_code_t key; + while (!(key = _get_key())) + _yield_task(); + return key_to_char(key); +} + void tell_user_sz(const char *sz) { _log_string(sz); } |