diff --git a/tasks/fs0/main.c b/tasks/fs0/main.c index 57974bd..c34709d 100644 --- a/tasks/fs0/main.c +++ b/tasks/fs0/main.c @@ -100,21 +100,12 @@ void handle_fs_requests(void) void main(void) { - struct timeval tv; - printf("\n%s: Started with tid: %d\n", __TASKNAME__, self_tid()); initialise(); wait_pager(PAGER_TID); - if (gettimeofday(&tv, 0) < 0) { - printf("Reading the time has failed.\n"); - } else { - printf("Current time since system started: %u useconds, " - "%u seconds.\n", tv.tv_usec, tv.tv_sec); - } - printf("%s: Listening requests.\n", __TASKNAME__); while (1) { handle_fs_requests(); diff --git a/tasks/libposix/close.c b/tasks/libposix/close.c new file mode 100644 index 0000000..1b73fb0 --- /dev/null +++ b/tasks/libposix/close.c @@ -0,0 +1,46 @@ +/* + * l4/posix glue for close() + * + * Copyright (C) 2007 Bahadir Balban + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include INC_GLUE(memory.h) + +static inline int l4_close(int fd) +{ + write_mr(L4SYS_ARG0, fd); + + /* Call pager with close() request. Check ipc error. */ + if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_CLOSE)) < 0) { + printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + return fd; + } + /* Check if syscall itself was successful */ + if ((fd = l4_get_retval()) < 0) { + printf("%s: CLOSE Error: %d.\n", __FUNCTION__, fd); + return fd; + } + return fd; +} + +int close(int fd) +{ + int ret = l4_close(fd); + + /* If error, return positive error code */ + if (ret < 0) { + errno = -ret; + return -1; + } + + /* else return value */ + return ret; +} + diff --git a/tasks/libposix/open.c b/tasks/libposix/open.c index b473863..575a57a 100644 --- a/tasks/libposix/open.c +++ b/tasks/libposix/open.c @@ -22,13 +22,12 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode) { int fd; - // write_mr(L4SYS_ARG0, (unsigned long)pathname); copy_to_utcb((void *)pathname, 0, strlen(pathname) + 1); write_mr(L4SYS_ARG0, (unsigned long)utcb_page); write_mr(L4SYS_ARG1, flags); write_mr(L4SYS_ARG2, (u32)mode); - /* Call pager with shmget() request. Check ipc error. */ + /* Call pager with open() request. Check ipc error. */ if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_OPEN)) < 0) { printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; diff --git a/tasks/libposix/write.c b/tasks/libposix/write.c index b64b31c..d6bfcf8 100644 --- a/tasks/libposix/write.c +++ b/tasks/libposix/write.c @@ -19,7 +19,7 @@ static inline int l4_write(int fd, const void *buf, size_t count) write_mr(L4SYS_ARG1, (const unsigned long)buf); write_mr(L4SYS_ARG2, count); - /* Call pager with shmget() request. Check ipc error. */ + /* Call pager with write() request. Check ipc error. */ if ((wrcnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_WRITE)) < 0) { printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt); return wrcnt; diff --git a/tasks/test0/include/tests.h b/tasks/test0/include/tests.h index 1801837..9780e15 100644 --- a/tasks/test0/include/tests.h +++ b/tasks/test0/include/tests.h @@ -6,5 +6,6 @@ int shmtest(void); int mmaptest(void); int dirtest(void); +int fileio(void); #endif /* __TEST0_TESTS_H__ */ diff --git a/tasks/test0/main.c b/tasks/test0/main.c index 5dd4772..4e6f4c7 100644 --- a/tasks/test0/main.c +++ b/tasks/test0/main.c @@ -28,7 +28,7 @@ void main(void) wait_pager(0); dirtest(); - + fileio(); while (1) wait_pager(0); #if 0 diff --git a/tasks/test0/src/fileio.c b/tasks/test0/src/fileio.c new file mode 100644 index 0000000..7054cd3 --- /dev/null +++ b/tasks/test0/src/fileio.c @@ -0,0 +1,33 @@ + +#include +#include +#include +#include +#include +#include +#include + +int fileio(void) +{ + int fd; + ssize_t cnt; + int err; + + char *str = "I WROTE TO THIS FILE\n"; + + if ((fd = open("/home/bahadir/newfile.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) { + perror("OPEN"); + return 0; + } + + if ((int)(cnt = write(fd, str, strlen(str))) < 0) { + perror("WRITE"); + return 0; + } + + if ((err = close(fd)) < 0) + perror("CLOSE"); + + return 0; +} +