From 38ac9052c03a83735ca3afedbb3da0ddee520735 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 13 Oct 2009 13:51:30 +0300 Subject: [PATCH] Few minor fixes --- conts/posix/mm0/mm/file.c | 9 +++-- conts/posix/test0/container.c | 6 ++-- .../posix/test0/include/test_exec_linker.lds | 2 +- conts/posix/test0/include/tests.h | 3 +- conts/posix/test0/main.c | 6 ++-- conts/posix/test0/src/exectest.c | 6 ++-- conts/posix/test0/src/fileio.c | 35 +++++++++++++++++++ 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/conts/posix/mm0/mm/file.c b/conts/posix/mm0/mm/file.c index 952bfe6..f103efb 100644 --- a/conts/posix/mm0/mm/file.c +++ b/conts/posix/mm0/mm/file.c @@ -402,9 +402,11 @@ int fsync_common(struct tcb *task, int fd) if (!task->files->fd[fd].vmfile) return 0; + /* printf("Thread %d flushing fd: %d, vnum: 0x%lx, vnode: %p\n", task->tid, fd, task->files->fd[fd].vmfile->vnode->vnum, task->files->fd[fd].vmfile->vnode); + */ /* Finish I/O on file */ if ((err = flush_file_pages(task->files->fd[fd].vmfile)) < 0) @@ -795,7 +797,8 @@ int sys_write(struct tcb *task, int fd, void *buf, int count) vmfile = task->files->fd[fd].vmfile; cursor = task->files->fd[fd].cursor; - printf("Thread %d writing to fd: %d, vnum: 0x%lx, vnode: %p\n", task->tid, fd, vmfile->vnode->vnum, vmfile->vnode); + //printf("Thread %d writing to fd: %d, vnum: 0x%lx, vnode: %p\n", + //task->tid, fd, vmfile->vnode->vnum, vmfile->vnode); /* See what pages user wants to write */ pfn_wstart = __pfn(cursor); @@ -1080,10 +1083,6 @@ int sys_open(struct tcb *task, const char *pathname, global_add_vm_file(vmfile); out: - if (retval < 0) - printf("Thread %d Opening %s, fd: %d, error: %d\n", task->tid, pathname, fd, retval); - else - printf("Thread %d Opening %s, fd: %d, vnum: %lx, vnode: %p\n", task->tid, pathname, fd, v->vnum, v); pathdata_destroy(pdata); return retval; } diff --git a/conts/posix/test0/container.c b/conts/posix/test0/container.c index 66af085..f9734f1 100644 --- a/conts/posix/test0/container.c +++ b/conts/posix/test0/container.c @@ -15,15 +15,15 @@ int main(int argc, char *argv[]); int __container_init(int argc, char **argv) { void *envp = &argv[argc + 1]; -// char *pagerval; + char *pagerval; if ((char *)envp == *argv) envp = &argv[argc]; __libposix_init(envp); - //pagerval = getenv("pagerid"); - //printf("Pager id: %s\n", pagerval); + pagerval = getenv("pagerid"); + printf("Pager id: %s\n", pagerval); /* Generic L4 thread initialisation */ __l4_init(); diff --git a/conts/posix/test0/include/test_exec_linker.lds b/conts/posix/test0/include/test_exec_linker.lds index f858b07..2a5bdfe 100644 --- a/conts/posix/test0/include/test_exec_linker.lds +++ b/conts/posix/test0/include/test_exec_linker.lds @@ -5,7 +5,7 @@ */ virtual_base = 0x10000000; -/* __stack = (0x20000000 - 0x1000 - 8); */ + /* First page before the env/args */ diff --git a/conts/posix/test0/include/tests.h b/conts/posix/test0/include/tests.h index ba219b0..07d2da4 100644 --- a/conts/posix/test0/include/tests.h +++ b/conts/posix/test0/include/tests.h @@ -3,7 +3,7 @@ #define __TASKNAME__ "test0" - #define TEST_VERBOSE_PRINT +//#define TEST_VERBOSE_PRINT #if defined (TEST_VERBOSE_PRINT) #define test_printf(...) printf(__VA_ARGS__) #else @@ -24,5 +24,6 @@ int fileio(void); int clonetest(void); int exectest(pid_t); int user_mutex_test(void); +int small_io_test(void); #endif /* __TEST0_TESTS_H__ */ diff --git a/conts/posix/test0/main.c b/conts/posix/test0/main.c index 65dd75a..d88620f 100644 --- a/conts/posix/test0/main.c +++ b/conts/posix/test0/main.c @@ -23,6 +23,7 @@ void wait_pager(l4id_t partner) // printf("Pager synced with us.\n"); } + pid_t parent_of_all; int main(int argc, char *argv[]) @@ -36,7 +37,8 @@ int main(int argc, char *argv[]) printf("\n%s: Running POSIX API tests.\n", __TASKNAME__); -/* + small_io_test(); + dirtest(); mmaptest(); @@ -56,7 +58,7 @@ int main(int argc, char *argv[]) if (parent_of_all == getpid()) { user_mutex_test(); } -*/ + exectest(parent_of_all); while (1) diff --git a/conts/posix/test0/src/exectest.c b/conts/posix/test0/src/exectest.c index dc32e4b..36582b7 100644 --- a/conts/posix/test0/src/exectest.c +++ b/conts/posix/test0/src/exectest.c @@ -26,10 +26,9 @@ int exectest(pid_t parent_of_all) int left, cnt; char *argv[5]; char *envp[2]; - void *buf; memset(filename, 0, 128); - sprintf(filename, "/execfile%d", getpid()); + sprintf(filename, "/home/bahadir/execfile%d", getpid()); /* First create a new file and write the executable data to that file */ if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) { @@ -67,6 +66,7 @@ int exectest(pid_t parent_of_all) goto out_err; } +#if 0 /* Reopen */ if ((fd = open(filename, O_RDONLY, S_IRWXU)) < 0) { err = errno; @@ -82,7 +82,7 @@ int exectest(pid_t parent_of_all) printf("First page of read and written file doesn't match\n"); else printf("First page matches.\n"); - +#endif /* Set up some arguments */ argv[0] = "FIRST ARG"; argv[1] = "SECOND ARG"; diff --git a/conts/posix/test0/src/fileio.c b/conts/posix/test0/src/fileio.c index 4e5579e..f5b398c 100644 --- a/conts/posix/test0/src/fileio.c +++ b/conts/posix/test0/src/fileio.c @@ -8,6 +8,41 @@ #include #include +#define PAGE_SIZE 0x1000 + +int small_io_test(void) +{ + int fd1, fd2; + char *string = "abcdefg"; + char strbuf[30]; + char *path = "/text.txt"; + fd1 = open(path, O_TRUNC | O_RDWR | O_CREAT, S_IRWXU); + fd2 = open(path, O_RDWR, 0); + + printf("fd1: %d, fd2: %d\n", fd1, fd2); + perror("OPEN"); + + for (int i = 0; i < 4; i++) { + sprintf(strbuf, "%s%d", string, i); + printf("Writing to %s offset %x, string: %s\n", + path, i*PAGE_SIZE, strbuf); + lseek(fd1, i*PAGE_SIZE, SEEK_SET); + write(fd1, strbuf, strlen(strbuf) + 1); + } + close(fd1); + + memset(strbuf, 0, 30); + for (int i = 0; i < 4; i++) { + lseek(fd2, i*PAGE_SIZE, SEEK_SET); + read(fd2, strbuf, 30); + printf("Read %s, offset %x as %s\n", path, i*PAGE_SIZE, strbuf); + } + + close(fd2); + + return 0; +} + int fileio(void) { int fd;