From 58033e79279b0311e65142f69a3e9b80f547aca9 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Wed, 16 Apr 2008 16:00:17 +0100 Subject: [PATCH] CHDIR works. Lookups on different current directory, including /./././/// works as expected. --- tasks/fs0/src/path.c | 2 +- tasks/fs0/src/syscalls.c | 13 +++++++--- tasks/libposix/chdir.c | 52 +++++++++++++++++++++++++++++++++++++++ tasks/test0/src/dirtest.c | 9 ++++++- 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 tasks/libposix/chdir.c diff --git a/tasks/fs0/src/path.c b/tasks/fs0/src/path.c index 48d5122..4274440 100644 --- a/tasks/fs0/src/path.c +++ b/tasks/fs0/src/path.c @@ -134,7 +134,7 @@ struct pathdata *pathdata_parse(const char *pathname, /* Next component */ str = splitpath(&pathbuf, VFS_CHAR_SEP); } - // pathdata_print(pdata); + pathdata_print(pdata); return pdata; } diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index 2c0d5a1..2d93c35 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -181,18 +181,23 @@ int sys_chdir(l4id_t sender, const char *pathname) } /* Get the vnode */ - if (IS_ERR(v = vfs_lookup_bypath(pdata))) - return (int)v; + if (IS_ERR(v = vfs_lookup_bypath(pdata))) { + l4_ipc_return((int)v); + return 0; + } /* Ensure it's a directory */ - if (!vfs_isdir(v)) - return -ENOTDIR; + if (!vfs_isdir(v)) { + l4_ipc_return(-ENOTDIR); + return 0; + } /* Assign the current directory pointer */ task->curdir = v; /* Destroy extracted path data */ pathdata_destroy(pdata); + l4_ipc_return(0); return 0; } diff --git a/tasks/libposix/chdir.c b/tasks/libposix/chdir.c new file mode 100644 index 0000000..c25e76b --- /dev/null +++ b/tasks/libposix/chdir.c @@ -0,0 +1,52 @@ +/* + * l4/posix glue for mkdir() + * + * Copyright (C) 2008 Bahadir Balban + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include INC_GLUE(memory.h) + +static inline int l4_chdir(const char *pathname) +{ + 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); + + /* Call pager with shmget() request. Check ipc error. */ + if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_CHDIR)) < 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: MKDIR Error: %d.\n", __FUNCTION__, fd); + return fd; + } + return fd; +} + +int chdir(const char *pathname) +{ + int ret; + + /* If error, return positive error code */ + if ((ret = l4_chdir(pathname)) < 0) { + errno = -ret; + return -1; + } + /* else return value */ + return ret; +} + diff --git a/tasks/test0/src/dirtest.c b/tasks/test0/src/dirtest.c index 1c04047..92f74d4 100644 --- a/tasks/test0/src/dirtest.c +++ b/tasks/test0/src/dirtest.c @@ -111,7 +111,7 @@ int lsdir(char *path) memset(dents, 0, sizeof(struct dirent) * DENTS_TOTAL); if ((fd = open(path, O_RDONLY)) < 0) { - perror("OPEN"); + printf("OPEN failed."); return 0; } else printf("Got fd: %d for opening %s\n", fd, path); @@ -158,6 +158,9 @@ int dirtest(void) perror("MKDIR"); if (mkdir("/home/bahadir", 0) < 0) perror("MKDIR"); + if (chdir("/home/bahadir") < 0) + perror("CHDIR"); + printf("Changed curdir to /home/bahadir\n"); printf("\nlsdir root directory:\n"); lsdir("/"); @@ -165,6 +168,10 @@ int dirtest(void) printf("\nlsdir /usr:\n"); lsdir("/usr"); + printf("\nlsdir current directory:\n"); + lsdir("."); + printf("\nlsdir /usr/./././bin//\n"); + lsdir("/usr/./././bin//"); return 0; }