Files
codezero/tasks/libposix/open.c
Bahadir Balban 16617eed36 Various changes to incorporate new utcb setup.
Issues with l4_return value not reaching client side
	modified:   libs/c/include/stdio.h
	modified:   src/arch/arm/exception.c
	modified:   src/glue/arm/init.c
	modified:   tasks/fs0/src/task.c
	modified:   tasks/libl4/include/l4lib/arch-arm/utcb.h
	modified:   tasks/libl4/src/arm/syscalls.S
	modified:   tasks/libl4/src/init.c
	deleted:    tasks/libl4/tagfilelist
	modified:   tasks/libposix/open.c
	modified:   tasks/mm0/include/utcb.h
	modified:   tasks/mm0/include/vm_area.h
	modified:   tasks/mm0/main.c
	modified:   tasks/mm0/src/init.c
	modified:   tasks/mm0/src/task.c
	modified:   tasks/mm0/src/utcb.c
	modified:   tasks/mm0/src/vm_object.c
2008-03-19 02:27:53 +00:00

77 lines
1.6 KiB
C

/*
* l4/posix glue for open()
*
* Copyright (C) 2007 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)
/*
* Arguments that are too large to fit in message registers are
* copied onto another area that is still on the utcb, and the servers
* map-in the task utcb and read those arguments from there.
*/
void *copy_to_utcb(void *arg, int size)
{
BUG_ON(size > PAGE_SIZE);
memcpy(utcb_page, arg, size);
}
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, strlen(pathname));
write_mr(L4SYS_ARG1, flags);
write_mr(L4SYS_ARG2, (u32)mode);
/* Call pager with shmget() 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;
}
/* Check if syscall itself was successful */
if ((fd = l4_get_retval()) < 0) {
printf("%s: OPEN Error: %d.\n", __FUNCTION__, fd);
return fd;
}
return fd;
}
int open(const char *pathname, int oflag, ...)
{
int ret;
mode_t mode = 0;
if (oflag & O_CREAT) {
va_list arg;
va_start(arg, oflag);
mode = va_arg(arg, mode_t);
va_end(arg);
}
ret = l4_open(pathname, oflag, mode);
/* If error, return positive error code */
if (ret < 0) {
errno = -ret;
return -1;
}
/* else return value */
return ret;
}