From cdcb61a47f132926aa8fef37472f80199ff9bb0d Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Mon, 7 May 2018 18:31:42 +0300 Subject: [PATCH] Implement read command, add test/t_read. --- README | 19 +++++++++++++++++++ kocdecl.asm | 20 +++++++++----------- kofu.c | 21 ++++++++++++++++++--- test/t_read | 1 + 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 test/t_read diff --git a/README b/README index 184a827..af21569 100644 --- a/README +++ b/README @@ -1 +1,20 @@ +This is a common project for two related tools, kofuse and kofu. The idea is to +make UNIX tools that use unchanged KolibriOS dyndisk and fs source to test these +parts in native environment. + + +Kofuse +is a short for KolibriOS and FUSE [1]. + + +Kofu +is Kolibri Filesystem in Userspace. + + +Architecture + + Find img files here: https://baravy.by/kofuse/img/ + + +[1] https://github.com/libfuse/libfuse diff --git a/kocdecl.asm b/kocdecl.asm index 5359f61..0798a81 100644 --- a/kocdecl.asm +++ b/kocdecl.asm @@ -135,23 +135,21 @@ kos_fuse_read: mov edx, sf70_params mov dword[edx + 0x00], 0 - mov eax, [esp + 0x20] + mov eax, [esp + 0x20] ; offset lo mov dword[edx + 0x04], eax - mov dword[edx + 0x08], 0 - mov eax, [esp + 0x1c] + mov dword[edx + 0x08], 0 ; offset hi + mov eax, [esp + 0x1c] ; size mov dword[edx + 0x0c], eax - mov eax, [esp + 0x18] + mov eax, [esp + 0x18] ; buf mov dword[edx + 0x10], eax mov eax, [esp + 0x14] ; path - inc eax ; skip '/' - mov [edx + 0x14], eax + mov byte[edx + 0x14], 0 + mov [edx + 0x15], eax - mov ebp, [fs_struct] mov ebx, sf70_params - mov esi, eax - push 0 - call xfs_Read - pop eax + pushad ; file_system_lfn writes here + call file_system_lfn + popad pop ebp edi esi ebx mov eax, 0 diff --git a/kofu.c b/kofu.c index 50ee740..6c8deb2 100644 --- a/kofu.c +++ b/kofu.c @@ -55,6 +55,23 @@ void kofu_stat(char **arg) { return; } +void kofu_read(char **arg) { + size_t size; + size_t offset; + sscanf(arg[2], "%zu", &size); + sscanf(arg[3], "%zu", &offset); + char *buf = (char*)malloc(size + 4096); + kos_fuse_read(arg[1], buf, size, offset); + for (size_t i = 0; i < size; i++) { + if (i % 32 == 0 && i != 0) { + printf("\n"); + } + printf("%2.2x", buf[i]); + } + printf("\n"); + return; +} + struct func_table { char *name; void (*func) (char **arg); @@ -63,6 +80,7 @@ struct func_table { struct func_table funcs[] = { { "ls", kofu_ls }, { "stat", kofu_stat }, + { "read", kofu_read }, { NULL, NULL }, }; @@ -93,9 +111,6 @@ int main(int argc, char **argv) { if (!strcmp(arg[0], ft->name)) { found = true; ft->func(arg); - if (!is_tty) { - fprintf(stderr, "\n"); - } cmd_num++; break; } diff --git a/test/t_read b/test/t_read new file mode 100644 index 0000000..3461b9e --- /dev/null +++ b/test/t_read @@ -0,0 +1 @@ +read /hd0/1/123/two 2 2