From de20d7430df08731d9108acb83e1234ba7f1fe16 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 19 Sep 2020 14:53:29 -0400 Subject: file manager --- src/user/knob/file.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/user/knob/file.c') 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 +#include #include #include #include @@ -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 -- cgit v1.2.3