From 406dc0ee9e3d5332850e8a9352ee417b7564e847 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Tue, 2 May 2023 18:01:53 +0200 Subject: [PATCH] feature (VFS): returning amount of written/read bytes --- inc/drivers/fs/ramfs.h | 6 +++--- inc/drivers/fs/vfs.h | 4 ++-- src/drivers/fs/ramfs.c | 9 ++++++--- src/drivers/fs/vfs.c | 14 ++++++++------ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/inc/drivers/fs/ramfs.h b/inc/drivers/fs/ramfs.h index 5ba16be..ece93b5 100644 --- a/inc/drivers/fs/ramfs.h +++ b/inc/drivers/fs/ramfs.h @@ -5,9 +5,9 @@ #include "drivers/fs/vfs.h" -void ramfs_file_delete (vfs_node_T* node); -void ramfs_file_write (vfs_node_T* node, uint64_t size, uint8_t* buffer_in); -void ramfs_file_read (vfs_node_T* node, uint64_t size, uint8_t* buffer_out); +void ramfs_file_delete (vfs_node_T* node); +uint64_t ramfs_file_write (vfs_node_T* node, uint64_t size, uint8_t* buffer_in); +uint64_t ramfs_file_read (vfs_node_T* node, uint64_t size, uint8_t* buffer_out); #endif //NOX_RAMFS_H diff --git a/inc/drivers/fs/vfs.h b/inc/drivers/fs/vfs.h index 01bb3cd..631487d 100644 --- a/inc/drivers/fs/vfs.h +++ b/inc/drivers/fs/vfs.h @@ -65,8 +65,8 @@ vfs_node_T* vfs_node_resolve_child (vfs_node_T* node, string_t chil vfs_node_T* vfs_file_create (fs_T* filesystem, string_t path); void vfs_file_delete (vfs_node_T* file); -void vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in); -void vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out); +uint64_t vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in); +uint64_t vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out); vfs_node_T* vfs_directory_create (fs_T* filesystem, string_t path); void vfs_directory_delete (vfs_node_T* directory); diff --git a/src/drivers/fs/ramfs.c b/src/drivers/fs/ramfs.c index 7d89aa4..bf5ae62 100644 --- a/src/drivers/fs/ramfs.c +++ b/src/drivers/fs/ramfs.c @@ -10,7 +10,7 @@ void ramfs_file_delete(vfs_node_T* node) { vfs_node_cache_destruct(node->cache); } -void ramfs_file_write(vfs_node_T* node, uint64_t size, uint8_t* buffer_in) { +uint64_t ramfs_file_write(vfs_node_T* node, uint64_t size, uint8_t* buffer_in) { if (node->cache != NULL) { vfs_node_cache_destruct(node->cache); } @@ -18,10 +18,13 @@ void ramfs_file_write(vfs_node_T* node, uint64_t size, uint8_t* buffer_in) { vfs_node_cache_create(node, size); memory_copy(buffer_in, node->cache->buffer, size); + + return size; } -void ramfs_file_read(vfs_node_T* node, uint64_t size, uint8_t* buffer_out) { - if (node->cache == NULL) { return; } +uint64_t ramfs_file_read(vfs_node_T* node, uint64_t size, uint8_t* buffer_out) { + if (node->cache == NULL) { return 0; } memory_copy(node->cache->buffer, buffer_out, MIN(size, node->cache->buffer_size)); + return size; } \ No newline at end of file diff --git a/src/drivers/fs/vfs.c b/src/drivers/fs/vfs.c index 53773c8..ce833c7 100644 --- a/src/drivers/fs/vfs.c +++ b/src/drivers/fs/vfs.c @@ -224,31 +224,33 @@ void vfs_file_delete(vfs_node_T* file) { vfs_node_destruct(file); } -void vfs_file_write(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in) { +uint64_t vfs_file_write(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in) { // in future this probably isn't a good way to determine the size of a file: file->size = size; switch (file->filesystem->type) { case FS_RAMFS: { - ramfs_file_write(file, size, buffer_in); - break; + return ramfs_file_write(file, size, buffer_in); } default: { break; } } + + return 0; } -void vfs_file_read(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out) { +uint64_t vfs_file_read(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out) { switch (file->filesystem->type) { case FS_RAMFS: { - ramfs_file_read(file, size, buffer_out); - break; + return ramfs_file_read(file, size, buffer_out); } default: { break; } } + + return 0; } vfs_node_T* vfs_directory_create(fs_T* filesystem, string_t path) {