diff options
Diffstat (limited to 'src/user/knob/file.c')
-rw-r--r-- | src/user/knob/file.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/user/knob/file.c b/src/user/knob/file.c index 3083503..283f984 100644 --- a/src/user/knob/file.c +++ b/src/user/knob/file.c @@ -1,4 +1,5 @@ #include <knob/format.h> +#include <knob/block.h> #include <knob/panic.h> #include <knob/heap.h> @@ -83,6 +84,16 @@ uint32_t read_from_file(struct file *f, uint32_t max, void *buf) { return read; } +uint32_t write_to_file(struct file *f, uint32_t max, void *buf) { + if (f->position + max > f->length) + _set_file_size(f->handle, f->length = f->position + max); + + uint32_t written = _file_write(f->handle, f->position, max, buf); + + f->position += written; + return written; +} + //return value and max_length don't include null terminator uint32_t read_line_from_file(struct file *f, char *sz, uint32_t max_length) { uint8_t i; @@ -114,6 +125,10 @@ uint32_t file_size(struct file *f) { return f->length; } +void trunc_file(struct file *f) { + _set_file_size(f->handle, f->length = f->position); +} + //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; |