mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 10:53:16 +01:00
Towards working mkdir.
This commit is contained in:
@@ -51,8 +51,6 @@ void handle_fs_requests(void)
|
||||
int err;
|
||||
u32 tag;
|
||||
|
||||
printf("%s: Listening requests.\n", __TASKNAME__);
|
||||
|
||||
if ((err = l4_receive(L4_ANYTHREAD)) < 0) {
|
||||
printf("%s: %s: IPC Error: %d. Quitting...\n", __TASKNAME__,
|
||||
__FUNCTION__, err);
|
||||
@@ -107,6 +105,7 @@ void main(void)
|
||||
|
||||
wait_pager(PAGER_TID);
|
||||
|
||||
printf("%s: Listening requests.\n", __TASKNAME__);
|
||||
while (1) {
|
||||
handle_fs_requests();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ char *splitpath(char **str, char sep)
|
||||
char *cursor = *str;
|
||||
char *end;
|
||||
|
||||
/* Root is the special case, return it as is. */
|
||||
if (strcmp(*str, "/"))
|
||||
return *str;
|
||||
|
||||
/* Move forward until no seperator */
|
||||
while (*cursor == sep) {
|
||||
*cursor = '\0';
|
||||
@@ -67,6 +71,9 @@ char *splitpath_end(char **path, char sep)
|
||||
/* Reverse the rest back to original. */
|
||||
strreverse(*path);
|
||||
|
||||
/* Reverse component back to original */
|
||||
strreverse(component);
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ struct vnode *generic_vnode_lookup(struct vnode *thisnode, char *path)
|
||||
}
|
||||
|
||||
/* Not found, return nothing */
|
||||
return 0;
|
||||
return PTR_ERR(-ENOENT);
|
||||
}
|
||||
|
||||
int generic_dentry_compare(struct dentry *d, char *name)
|
||||
|
||||
@@ -228,6 +228,8 @@ int memfs_vnode_mknod(struct vnode *v, char *dirname, unsigned int mode)
|
||||
BUG_ON(parent->vref.next != &v->dentries);
|
||||
BUG_ON(!vfs_isdir(v));
|
||||
|
||||
printf("Parent name: %s\n", parent->name);
|
||||
|
||||
/* Populate the children */
|
||||
if ((err = v->ops.readdir(v)) < 0)
|
||||
return err;
|
||||
|
||||
@@ -127,7 +127,8 @@ int sys_mkdir(l4id_t sender, const char *pathname, unsigned int mode)
|
||||
/* Get the task */
|
||||
BUG_ON(!(task = find_task(sender)));
|
||||
|
||||
return vfs_create(task, pathname, mode);
|
||||
l4_ipc_return(vfs_create(task, pathname, mode));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_chdir(l4id_t sender, const char *pathname)
|
||||
@@ -284,7 +285,6 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
if (count < dirent_size)
|
||||
return 0;
|
||||
|
||||
printf("%s: Filling in . (curdir)\n", __TASKNAME__);
|
||||
fill_dirent(buf, v->vnum, nbytes, ".");
|
||||
nbytes += dirent_size;
|
||||
buf += dirent_size;
|
||||
@@ -293,13 +293,11 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
if (count < dirent_size)
|
||||
return 0;
|
||||
|
||||
printf("%s: Filling in .. (pardir)\n", __TASKNAME__);
|
||||
fill_dirent(buf, d->parent->vnode->vnum, nbytes, "..");
|
||||
nbytes += dirent_size;
|
||||
buf += dirent_size;
|
||||
count -= dirent_size;
|
||||
|
||||
printf("%s: Filling in other dir contents\n", __TASKNAME__);
|
||||
/* Copy fs-specific dir to buf in struct dirent format */
|
||||
if ((total = v->ops.filldir(buf, v, count)) < 0) {
|
||||
l4_ipc_return(total);
|
||||
|
||||
@@ -101,8 +101,8 @@ struct task_data_head *receive_pager_taskdata(void)
|
||||
}
|
||||
|
||||
/* Data is expected in the utcb page */
|
||||
printf("%s: %d Total tasks.\n", __FUNCTION__,
|
||||
((struct task_data_head *)utcb_page)->total);
|
||||
// printf("%s: %d Total tasks.\n", __FUNCTION__,
|
||||
// ((struct task_data_head *)utcb_page)->total);
|
||||
|
||||
return (struct task_data_head *)utcb_page;
|
||||
}
|
||||
@@ -141,8 +141,8 @@ int task_utcb_attach(struct tcb *t)
|
||||
if ((unsigned long)shmaddr != t->utcb_address)
|
||||
return -EINVAL;
|
||||
|
||||
printf("%s: Mapped utcb of task %d @ 0x%x\n",
|
||||
__TASKNAME__, t->tid, shmaddr);
|
||||
// printf("%s: Mapped utcb of task %d @ 0x%x\n",
|
||||
// __TASKNAME__, t->tid, shmaddr);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -90,8 +90,8 @@ int utcb_init(void)
|
||||
|
||||
/* Obtain our utcb page address */
|
||||
utcb_page = l4_utcb_page();
|
||||
printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__,
|
||||
(unsigned long)utcb_page);
|
||||
//printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__,
|
||||
// (unsigned long)utcb_page);
|
||||
|
||||
/* Use it as a key to create a shared memory region */
|
||||
BUG_ON((shmid = shmget((key_t)utcb_page,
|
||||
|
||||
55
tasks/libposix/mkdir.c
Normal file
55
tasks/libposix/mkdir.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* l4/posix glue for mkdir()
|
||||
*
|
||||
* Copyright (C) 2008 Bahadir Balban
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <l4lib/utcb.h>
|
||||
#include <fcntl.h>
|
||||
#include <l4/macros.h>
|
||||
#include INC_GLUE(memory.h)
|
||||
|
||||
static inline int l4_mkdir(const char *pathname, mode_t mode)
|
||||
{
|
||||
int fd;
|
||||
|
||||
// write_mr(L4SYS_ARG0, (unsigned long)pathname);
|
||||
copy_to_utcb((void *)pathname, 0, strlen(pathname));
|
||||
write_mr(L4SYS_ARG0, (unsigned long)utcb_page);
|
||||
write_mr(L4SYS_ARG1, (u32)mode);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_MKDIR)) < 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 mkdir(const char *pathname, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* If error, return positive error code */
|
||||
if ((ret = l4_mkdir(pathname, mode)) < 0) {
|
||||
errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
/* else return value */
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -113,14 +113,12 @@ int lsdir(char *path)
|
||||
if ((fd = open(path, O_RDONLY)) < 0) {
|
||||
perror("OPEN");
|
||||
return 0;
|
||||
} else
|
||||
printf("OPEN OK.\n");
|
||||
}
|
||||
|
||||
if ((bytes = os_readdir(fd, dents, sizeof(struct dirent) * DENTS_TOTAL)) < 0) {
|
||||
printf("%s: GETDENTS failed.\n", __TASKNAME__);
|
||||
perror("GETDENTS\n");
|
||||
return 0;
|
||||
} else {
|
||||
printf("GETDENTS OK.\n");
|
||||
print_dirents(path, dents, bytes);
|
||||
}
|
||||
|
||||
@@ -135,6 +133,13 @@ int dirtest(void)
|
||||
printf("\nlsdir root directory:\n");
|
||||
lsdir("/");
|
||||
|
||||
printf("\nCreating directories: usr, etc, tmp, var, home, opt, bin, boot, lib, dev\n");
|
||||
if (mkdir("/usr", 0) < 0)
|
||||
perror("MKDIR");
|
||||
|
||||
printf("\nlsdir root directory:\n");
|
||||
lsdir("/");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user