mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
CHDIR works.
Lookups on different current directory, including /./././/// works as expected.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
52
tasks/libposix/chdir.c
Normal file
52
tasks/libposix/chdir.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* l4/posix glue for mkdir()
|
||||
*
|
||||
* Copyright (C) 2008 Bahadir Balban
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <l4lib/utcb.h>
|
||||
#include <l4/macros.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user