Rev 2625 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2625 | Rev 2635 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Jakub Jermar |
2 | * Copyright (c) 2007 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup fs |
29 | /** @addtogroup fs |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file vfs_read.c |
34 | * @file vfs_read.c |
35 | * @brief |
35 | * @brief |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include "vfs.h" |
38 | #include "vfs.h" |
39 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
40 | #include <async.h> |
40 | #include <async.h> |
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | 42 | ||
43 | void vfs_read(ipc_callid_t rid, ipc_call_t *request) |
43 | void vfs_read(ipc_callid_t rid, ipc_call_t *request) |
44 | { |
44 | { |
45 | 45 | ||
46 | /* |
46 | /* |
47 | * The following code strongly depends on the fact that the files data |
47 | * The following code strongly depends on the fact that the files data |
48 | * structure can be only accessed by a single fibril and all file |
48 | * structure can be only accessed by a single fibril and all file |
49 | * operations are serialized (i.e. the reads and writes cannot |
49 | * operations are serialized (i.e. the reads and writes cannot |
50 | * interleave and a file cannot be closed while it is being read). |
50 | * interleave and a file cannot be closed while it is being read). |
51 | * |
51 | * |
52 | * Additional synchronization needs to be added once table table of |
52 | * Additional synchronization needs to be added once table table of |
53 | * open files supports parallel access! |
53 | * open files supports parallel access! |
54 | */ |
54 | */ |
55 | 55 | ||
56 | /* |
56 | /* |
57 | * Because we don't support the receive analogy of IPC_M_DATA_SEND, |
57 | * Because we don't support the receive analogy of IPC_M_DATA_SEND, |
58 | * VFS_READ is emulutating its behavior via sharing an address space |
58 | * VFS_READ is emulutating its behavior via sharing an address space |
59 | * area. |
59 | * area. |
60 | */ |
60 | */ |
61 | 61 | ||
62 | int fd = IPC_GET_ARG1(*request); |
62 | int fd = IPC_GET_ARG1(*request); |
63 | 63 | ||
64 | /* |
64 | /* |
65 | * Lookup the file structure corresponding to the file descriptor. |
65 | * Lookup the file structure corresponding to the file descriptor. |
66 | */ |
66 | */ |
67 | vfs_file_t *file = vfs_file_get(fd); |
67 | vfs_file_t *file = vfs_file_get(fd); |
68 | if (!file) { |
68 | if (!file) { |
69 | ipc_answer_0(rid, ENOENT); |
69 | ipc_answer_0(rid, ENOENT); |
70 | return; |
70 | return; |
71 | } |
71 | } |
72 | 72 | ||
73 | /* |
73 | /* |
74 | * Now we need to receive a call with client's address space area. |
74 | * Now we need to receive a call with client's address space area. |
75 | */ |
75 | */ |
76 | ipc_callid_t callid; |
76 | ipc_callid_t callid; |
77 | ipc_call_t call; |
77 | ipc_call_t call; |
78 | callid = async_get_call(&call); |
78 | callid = async_get_call(&call); |
79 | if (IPC_GET_METHOD(call) != IPC_M_AS_AREA_SEND) { |
79 | if (IPC_GET_METHOD(call) != IPC_M_AS_AREA_SEND) { |
80 | ipc_answer_0(callid, EINVAL); |
80 | ipc_answer_0(callid, EINVAL); |
81 | ipc_answer_0(rid, EINVAL); |
81 | ipc_answer_0(rid, EINVAL); |
82 | return; |
82 | return; |
83 | } |
83 | } |
84 | 84 | ||
85 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
85 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
86 | 86 | ||
87 | /* |
87 | /* |
88 | * Make a VFS_READ request at the destination FS server. |
88 | * Make a VFS_READ request at the destination FS server. |
89 | */ |
89 | */ |
90 | aid_t msg; |
90 | aid_t msg; |
91 | msg = async_send_3(fs_phone, VFS_READ, file->node->dev_handle, |
91 | msg = async_send_3(fs_phone, VFS_READ, file->node->dev_handle, |
92 | file->node->index, file->pos, NULL); |
92 | file->node->index, file->pos, NULL); |
93 | 93 | ||
94 | /* |
94 | /* |
95 | * Forward the address space area offer to the destination FS server. |
95 | * Forward the address space area offer to the destination FS server. |
96 | * The call will be routed as if sent by ourselves. |
96 | * The call will be routed as if sent by ourselves. |
97 | */ |
97 | */ |
98 | ipc_forward_fast(callid, fs_phone, IPC_GET_METHOD(call), |
98 | ipc_forward_fast(callid, fs_phone, IPC_GET_METHOD(call), |
99 | IPC_GET_ARG1(call), IPC_FF_ROUTE_FROM_ME); |
99 | IPC_GET_ARG1(call), 0, IPC_FF_ROUTE_FROM_ME); |
100 | 100 | ||
101 | vfs_release_phone(fs_phone); |
101 | vfs_release_phone(fs_phone); |
102 | 102 | ||
103 | /* |
103 | /* |
104 | * Wait for reply from the FS server. |
104 | * Wait for reply from the FS server. |
105 | */ |
105 | */ |
106 | ipcarg_t rc; |
106 | ipcarg_t rc; |
107 | async_wait_for(msg, &rc); |
107 | async_wait_for(msg, &rc); |
108 | 108 | ||
109 | /* |
109 | /* |
110 | * FS server's reply is the final result of the whole operation we |
110 | * FS server's reply is the final result of the whole operation we |
111 | * return to the client. |
111 | * return to the client. |
112 | */ |
112 | */ |
113 | ipc_answer_0(rid, rc); |
113 | ipc_answer_0(rid, rc); |
114 | } |
114 | } |
115 | 115 | ||
116 | /** |
116 | /** |
117 | * @} |
117 | * @} |
118 | */ |
118 | */ |
119 | 119 |