mirror of
https://github.com/drasko/codezero.git
synced 2026-04-17 01:09:05 +02:00
Added test code for testing of directory listing.
Added system call prototypes and posix glue for reading a directory. TODO: FS0 should implement the L4_IPC_TAG_READDIR ipc call.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* l4/posix glue for read()
|
||||
* l4/posix glue for read() / sys_readdir()
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
@@ -10,35 +10,86 @@
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <l4lib/os/posix/readdir.h>
|
||||
|
||||
static inline int l4_read(int fd, void *buf, size_t count)
|
||||
static inline int l4_readdir(int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t rcnt;
|
||||
size_t cnt;
|
||||
|
||||
write_mr(L4SYS_ARG0, fd);
|
||||
write_mr(L4SYS_ARG1, (unsigned long)buf);
|
||||
write_mr(L4SYS_ARG2, count);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((errno = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_READ)) < 0) {
|
||||
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, errno);
|
||||
return -1;
|
||||
if ((cnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_READDIR)) < 0) {
|
||||
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
|
||||
return cnt;
|
||||
}
|
||||
/* Check if syscall itself was successful */
|
||||
if ((rcnt = l4_get_retval()) < 0) {
|
||||
printf("%s: READ Error: %d.\n", __FUNCTION__, (int)rcnt);
|
||||
errno = (int)rcnt;
|
||||
return -1;
|
||||
if ((cnt = l4_get_retval()) < 0) {
|
||||
printf("%s: READ Error: %d.\n", __FUNCTION__, (int)cnt);
|
||||
return cnt;
|
||||
|
||||
}
|
||||
return rcnt;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static inline int l4_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t cnt;
|
||||
|
||||
write_mr(L4SYS_ARG0, fd);
|
||||
write_mr(L4SYS_ARG1, (unsigned long)buf);
|
||||
write_mr(L4SYS_ARG2, count);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((cnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_READ)) < 0) {
|
||||
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
|
||||
return cnt;
|
||||
}
|
||||
/* Check if syscall itself was successful */
|
||||
if ((cnt = l4_get_retval()) < 0) {
|
||||
printf("%s: READ Error: %d.\n", __FUNCTION__, (int)cnt);
|
||||
return cnt;
|
||||
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
return l4_read(fd, buf, count);
|
||||
ret = l4_read(fd, buf, count);
|
||||
|
||||
/* If error, return positive error code */
|
||||
if (ret < 0) {
|
||||
errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
/* else return value */
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
ssize_t os_readdir(int fd, void *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
ret = l4_readdir(fd, buf, count);
|
||||
|
||||
/* If error, return positive error code */
|
||||
if (ret < 0) {
|
||||
errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
/* else return value */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user