summaryrefslogtreecommitdiff
path: root/src/user/knob/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/knob/file.c')
-rw-r--r--src/user/knob/file.c21
1 files changed, 20 insertions, 1 deletions
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