Implement read command, add test/t_read.

This commit is contained in:
Ivan Baravy 2018-05-07 18:31:42 +03:00
parent 9c7ebc5136
commit cdcb61a47f
4 changed files with 47 additions and 14 deletions

19
README
View File

@ -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

View File

@ -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

21
kofu.c
View File

@ -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;
}

1
test/t_read Normal file
View File

@ -0,0 +1 @@
read /hd0/1/123/two 2 2