OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [read.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * l4/posix glue for read() / sys_readdir()
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
 
7
#include <errno.h>
8
#include <stdio.h>
9
#include <string.h>
10
#include <sys/types.h>
11
#include <unistd.h>
12
#include <l4lib/ipcdefs.h>
13
#include <l4lib/os/posix/readdir.h>
14
#include <l4/macros.h>
15
#include INC_GLUE(memory.h)
16
#include INC_GLUE(message.h)
17
#include <libposix.h>
18
 
19
/*
20
 * TODO:
21
 *
22
 * Do this as follows:
23
 *
24
 * A short ipc l4_send() to indicate request
25
 * An extended l4_receive_extended() to get back extended buffer.
26
 *
27
 * Or do it just like read()
28
 */
29
static inline int l4_readdir(int fd, void *buf, size_t count)
30
{
31
        int cnt, err;
32
 
33
        write_mr(L4SYS_ARG0, fd);
34
        write_mr(L4SYS_ARG1, count);
35
 
36
        /* Call pager with readdir() request. Check ipc error. */
37
        if ((err = l4_send(pagerid, L4_IPC_TAG_READDIR)) < 0) {
38
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
39
                return err;
40
        }
41
 
42
        /* Call pager with readdir() request. Check ipc error. */
43
        if ((err = l4_receive_extended(pagerid,
44
                                       L4_IPC_EXTENDED_MAX_SIZE,
45
                                       buf)) < 0) {
46
                print_err("%s: L4 Extended IPC error: %d.\n", __FUNCTION__, err);
47
                return err;
48
        }
49
 
50
        /* Check if syscall itself was successful */
51
        if ((cnt = l4_get_retval()) < 0) {
52
                print_err("%s: READDIR Error: %d.\n", __FUNCTION__, (int)cnt);
53
                return cnt;
54
        }
55
 
56
        return cnt;
57
}
58
 
59
#if 0
60
static inline int l4_readdir(int fd, void *buf, size_t count)
61
{
62
        int cnt;
63
 
64
        write_mr(L4SYS_ARG0, fd);
65
        write_mr(L4SYS_ARG1, (unsigned long)buf);
66
        write_mr(L4SYS_ARG2, count);
67
 
68
        /* Call pager with readdir() request. Check ipc error. */
69
        if ((cnt = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_READDIR)) < 0) {
70
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
71
                return cnt;
72
        }
73
        /* Check if syscall itself was successful */
74
        if ((cnt = l4_get_retval()) < 0) {
75
                print_err("%s: READDIR Error: %d.\n", __FUNCTION__, (int)cnt);
76
                return cnt;
77
 
78
        }
79
 
80
        return cnt;
81
}
82
#endif
83
static inline int l4_read(int fd, void *buf, size_t count)
84
{
85
        int cnt;
86
 
87
        write_mr(L4SYS_ARG0, fd);
88
        write_mr(L4SYS_ARG1, (unsigned long)buf);
89
        write_mr(L4SYS_ARG2, count);
90
 
91
        /* Call pager with read() request. Check ipc error. */
92
        if ((cnt = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_READ)) < 0) {
93
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
94
                return cnt;
95
        }
96
        /* Check if syscall itself was successful */
97
        if ((cnt = l4_get_retval()) < 0) {
98
                print_err("%s: READ Error: %d.\n", __FUNCTION__, (int)cnt);
99
                return cnt;
100
 
101
        }
102
        return cnt;
103
}
104
 
105
ssize_t read(int fd, void *buf, size_t count)
106
{
107
        int ret;
108
 
109
        if (!count)
110
                return 0;
111
 
112
        ret = l4_read(fd, buf, count);
113
 
114
        /* If error, return positive error code */
115
        if (ret < 0) {
116
                errno = -ret;
117
                return -1;
118
        }
119
        /* else return value */
120
        return ret;
121
 
122
}
123
 
124
ssize_t os_readdir(int fd, void *buf, size_t count)
125
{
126
        int ret;
127
 
128
        if (!count)
129
                return 0;
130
 
131
        ret = l4_readdir(fd, buf, count);
132
 
133
        /* If error, return positive error code */
134
        if (ret < 0) {
135
                errno = -ret;
136
                return -1;
137
        }
138
        /* else return value */
139
        return ret;
140
}
141
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.