Rev 2643 | Rev 2677 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2643 | Rev 2660 | ||
---|---|---|---|
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 libfs |
29 | /** @addtogroup libfs |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * Glue code which is commonod to all FS implementations. |
34 | * Glue code which is commonod to all FS implementations. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include "libfs.h" |
37 | #include "libfs.h" |
38 | #include "../../srv/vfs/vfs.h" |
38 | #include "../../srv/vfs/vfs.h" |
39 | #include <errno.h> |
39 | #include <errno.h> |
40 | #include <async.h> |
40 | #include <async.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
42 | #include <as.h> |
42 | #include <as.h> |
43 | 43 | ||
44 | /** Register file system server. |
44 | /** Register file system server. |
45 | * |
45 | * |
46 | * This function abstracts away the tedious registration protocol from |
46 | * This function abstracts away the tedious registration protocol from |
47 | * file system implementations and lets them to reuse this registration glue |
47 | * file system implementations and lets them to reuse this registration glue |
48 | * code. |
48 | * code. |
49 | * |
49 | * |
50 | * @param vfs_phone Open phone for communication with VFS. |
50 | * @param vfs_phone Open phone for communication with VFS. |
51 | * @param reg File system registration structure. It will be |
51 | * @param reg File system registration structure. It will be |
52 | * initialized by this function. |
52 | * initialized by this function. |
53 | * @param info VFS info structure supplied by the file system |
53 | * @param info VFS info structure supplied by the file system |
54 | * implementation. |
54 | * implementation. |
55 | * @param conn Connection fibril for handling all calls originating in |
55 | * @param conn Connection fibril for handling all calls originating in |
56 | * VFS. |
56 | * VFS. |
57 | * |
57 | * |
58 | * @return EOK on success or a non-zero error code on errror. |
58 | * @return EOK on success or a non-zero error code on errror. |
59 | */ |
59 | */ |
60 | int fs_register(int vfs_phone, fs_reg_t *reg, vfs_info_t *info, |
60 | int fs_register(int vfs_phone, fs_reg_t *reg, vfs_info_t *info, |
61 | async_client_conn_t conn) |
61 | async_client_conn_t conn) |
62 | { |
62 | { |
63 | /* |
63 | /* |
64 | * Tell VFS that we are here and want to get registered. |
64 | * Tell VFS that we are here and want to get registered. |
65 | * We use the async framework because VFS will answer the request |
65 | * We use the async framework because VFS will answer the request |
66 | * out-of-order, when it knows that the operation succeeded or failed. |
66 | * out-of-order, when it knows that the operation succeeded or failed. |
67 | */ |
67 | */ |
68 | ipc_call_t answer; |
68 | ipc_call_t answer; |
69 | aid_t req = async_send_0(vfs_phone, VFS_REGISTER, &answer); |
69 | aid_t req = async_send_0(vfs_phone, VFS_REGISTER, &answer); |
70 | 70 | ||
71 | /* |
71 | /* |
72 | * Send our VFS info structure to VFS. |
72 | * Send our VFS info structure to VFS. |
73 | */ |
73 | */ |
74 | int rc = ipc_data_send(vfs_phone, info, sizeof(*info)); |
74 | int rc = ipc_data_write_send(vfs_phone, info, sizeof(*info)); |
75 | if (rc != EOK) { |
75 | if (rc != EOK) { |
76 | async_wait_for(req, NULL); |
76 | async_wait_for(req, NULL); |
77 | return rc; |
77 | return rc; |
78 | } |
78 | } |
79 | 79 | ||
80 | /* |
80 | /* |
81 | * Ask VFS for callback connection. |
81 | * Ask VFS for callback connection. |
82 | */ |
82 | */ |
83 | ipc_connect_to_me(vfs_phone, 0, 0, 0, ®->vfs_phonehash); |
83 | ipc_connect_to_me(vfs_phone, 0, 0, 0, ®->vfs_phonehash); |
84 | 84 | ||
85 | /* |
85 | /* |
86 | * Allocate piece of address space for PLB. |
86 | * Allocate piece of address space for PLB. |
87 | */ |
87 | */ |
88 | reg->plb_ro = as_get_mappable_page(PLB_SIZE); |
88 | reg->plb_ro = as_get_mappable_page(PLB_SIZE); |
89 | if (!reg->plb_ro) { |
89 | if (!reg->plb_ro) { |
90 | async_wait_for(req, NULL); |
90 | async_wait_for(req, NULL); |
91 | return ENOMEM; |
91 | return ENOMEM; |
92 | } |
92 | } |
93 | 93 | ||
94 | /* |
94 | /* |
95 | * Request sharing the Path Lookup Buffer with VFS. |
95 | * Request sharing the Path Lookup Buffer with VFS. |
96 | */ |
96 | */ |
97 | rc = ipc_call_sync_2_0(vfs_phone, IPC_M_AS_AREA_RECV, |
97 | rc = ipc_call_sync_2_0(vfs_phone, IPC_M_AS_AREA_RECV, |
98 | (ipcarg_t) reg->plb_ro, PLB_SIZE); |
98 | (ipcarg_t) reg->plb_ro, PLB_SIZE); |
99 | if (rc) { |
99 | if (rc) { |
100 | async_wait_for(req, NULL); |
100 | async_wait_for(req, NULL); |
101 | return rc; |
101 | return rc; |
102 | } |
102 | } |
103 | 103 | ||
104 | /* |
104 | /* |
105 | * Pick up the answer for the request to the VFS_REQUEST call. |
105 | * Pick up the answer for the request to the VFS_REQUEST call. |
106 | */ |
106 | */ |
107 | async_wait_for(req, NULL); |
107 | async_wait_for(req, NULL); |
108 | reg->fs_handle = (int) IPC_GET_ARG1(answer); |
108 | reg->fs_handle = (int) IPC_GET_ARG1(answer); |
109 | 109 | ||
110 | /* |
110 | /* |
111 | * Create a connection fibril to handle the callback connection. |
111 | * Create a connection fibril to handle the callback connection. |
112 | */ |
112 | */ |
113 | async_new_connection(reg->vfs_phonehash, 0, NULL, conn); |
113 | async_new_connection(reg->vfs_phonehash, 0, NULL, conn); |
114 | 114 | ||
115 | /* |
115 | /* |
116 | * Tell the async framework that other connections are to be handled by |
116 | * Tell the async framework that other connections are to be handled by |
117 | * the same connection fibril as well. |
117 | * the same connection fibril as well. |
118 | */ |
118 | */ |
119 | async_set_client_connection(conn); |
119 | async_set_client_connection(conn); |
120 | 120 | ||
121 | return IPC_GET_RETVAL(answer); |
121 | return IPC_GET_RETVAL(answer); |
122 | } |
122 | } |
123 | 123 | ||
124 | /** @} |
124 | /** @} |
125 | */ |
125 | */ |
126 | 126 |