From 33e37fb872683b6f6b5d192d23146167187679bf Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 14 Oct 2024 23:09:52 +0200 Subject: [PATCH] Mon 14 Oct 23:09:15 CEST 2024 --- user/test/writebig.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 user/test/writebig.c diff --git a/user/test/writebig.c b/user/test/writebig.c new file mode 100644 index 0000000..8a4690d --- /dev/null +++ b/user/test/writebig.c @@ -0,0 +1,46 @@ +/* +Copyright (C) 2016-2019 The University of Notre Dame +This software is distributed under the GNU General Public License. +See the file LICENSE for details. +*/ + +/* +A trivial user level program to try out basic system calls. +*/ + +#include "library/syscalls.h" +#include "library/string.h" +#include "library/user-io.h" + +int main(int argc, char *argv[]) +{ + syscall_chdir("/"); + printf("got root\n"); + int fd = syscall_open_file("kevin", 2, 0); + printf("got fd %d\n", fd); + printf("writing to file...\n"); + for(int i = 0; i < 12; i++) { + char buffer[4096] = {'a'+i}; + int n; + n = syscall_object_write(fd, buffer, strlen(buffer)); + if(n < 0) + break; + printf("wrote %d chars: %s\n", n, buffer); + } + syscall_object_close(fd); + fd = syscall_open_file("kevin", 1, 0); + printf("reading file...\n"); + for (int i = 0; i < 12; i++) { + char buffer[4096]; + int n; + while((n = syscall_object_read(fd, buffer, 4096-1)) > 0) { + buffer[n] = 0; + printf("%s"); + flush(); + } + } + syscall_object_close(fd); + syscall_process_exit(0); + + return 0; +}