Rev 4566 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4566 | Rev 4567 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jakub Jermar |
2 | * Copyright (c) 2008 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_register.c |
34 | * @file vfs_register.c |
35 | * @brief |
35 | * @brief |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <ipc/services.h> |
39 | #include <ipc/services.h> |
40 | #include <async.h> |
40 | #include <async.h> |
41 | #include <fibril.h> |
41 | #include <fibril.h> |
42 | #include <errno.h> |
42 | #include <errno.h> |
43 | #include <stdio.h> |
43 | #include <stdio.h> |
44 | #include <stdlib.h> |
44 | #include <stdlib.h> |
45 | #include <string.h> |
45 | #include <string.h> |
46 | #include <ctype.h> |
46 | #include <ctype.h> |
47 | #include <bool.h> |
47 | #include <bool.h> |
48 | #include <fibril_sync.h> |
48 | #include <fibril_sync.h> |
49 | #include <adt/list.h> |
49 | #include <adt/list.h> |
50 | #include <as.h> |
50 | #include <as.h> |
51 | #include <assert.h> |
51 | #include <assert.h> |
52 | #include <atomic.h> |
52 | #include <atomic.h> |
53 | #include "vfs.h" |
53 | #include "vfs.h" |
54 | 54 | ||
55 | FIBRIL_CONDVAR_INITIALIZE(fs_head_cv); |
55 | FIBRIL_CONDVAR_INITIALIZE(fs_head_cv); |
56 | FIBRIL_MUTEX_INITIALIZE(fs_head_lock); |
56 | FIBRIL_MUTEX_INITIALIZE(fs_head_lock); |
57 | LIST_INITIALIZE(fs_head); |
57 | LIST_INITIALIZE(fs_head); |
58 | 58 | ||
59 | atomic_t fs_handle_next = { |
59 | atomic_t fs_handle_next = { |
60 | .count = 1 |
60 | .count = 1 |
61 | }; |
61 | }; |
62 | 62 | ||
63 | /** Verify the VFS info structure. |
63 | /** Verify the VFS info structure. |
64 | * |
64 | * |
65 | * @param info Info structure to be verified. |
65 | * @param info Info structure to be verified. |
66 | * |
66 | * |
67 | * @return Non-zero if the info structure is sane, zero otherwise. |
67 | * @return Non-zero if the info structure is sane, zero otherwise. |
68 | */ |
68 | */ |
69 | static bool vfs_info_sane(vfs_info_t *info) |
69 | static bool vfs_info_sane(vfs_info_t *info) |
70 | { |
70 | { |
71 | int i; |
71 | int i; |
72 | 72 | ||
73 | /* |
73 | /* |
74 | * Check if the name is non-empty and is composed solely of ASCII |
74 | * Check if the name is non-empty and is composed solely of ASCII |
75 | * characters [a-z]+[a-z0-9_-]*. |
75 | * characters [a-z]+[a-z0-9_-]*. |
76 | */ |
76 | */ |
77 | if (!islower(info->name[0])) { |
77 | if (!islower(info->name[0])) { |
78 | dprintf("The name doesn't start with a lowercase character.\n"); |
78 | dprintf("The name doesn't start with a lowercase character.\n"); |
79 | return false; |
79 | return false; |
80 | } |
80 | } |
81 | for (i = 1; i < FS_NAME_MAXLEN; i++) { |
81 | for (i = 1; i < FS_NAME_MAXLEN; i++) { |
82 | if (!(islower(info->name[i]) || isdigit(info->name[i])) && |
82 | if (!(islower(info->name[i]) || isdigit(info->name[i])) && |
83 | (info->name[i] != '-') && (info->name[i] != '_')) { |
83 | (info->name[i] != '-') && (info->name[i] != '_')) { |
84 | if (info->name[i] == '\0') { |
84 | if (info->name[i] == '\0') { |
85 | break; |
85 | break; |
86 | } else { |
86 | } else { |
87 | dprintf("The name contains illegal " |
87 | dprintf("The name contains illegal " |
88 | "characters.\n"); |
88 | "characters.\n"); |
89 | return false; |
89 | return false; |
90 | } |
90 | } |
91 | } |
91 | } |
92 | } |
92 | } |
93 | /* |
93 | /* |
94 | * This check is not redundant. It ensures that the name is |
94 | * This check is not redundant. It ensures that the name is |
95 | * NULL-terminated, even if FS_NAME_MAXLEN characters are used. |
95 | * NULL-terminated, even if FS_NAME_MAXLEN characters are used. |
96 | */ |
96 | */ |
97 | if (info->name[i] != '\0') { |
97 | if (info->name[i] != '\0') { |
98 | dprintf("The name is not properly NULL-terminated.\n"); |
98 | dprintf("The name is not properly NULL-terminated.\n"); |
99 | return false; |
99 | return false; |
100 | } |
100 | } |
101 | 101 | ||
102 | return true; |
102 | return true; |
103 | } |
103 | } |
104 | 104 | ||
105 | /** VFS_REGISTER protocol function. |
105 | /** VFS_REGISTER protocol function. |
106 | * |
106 | * |
107 | * @param rid Hash of the call with the request. |
107 | * @param rid Hash of the call with the request. |
108 | * @param request Call structure with the request. |
108 | * @param request Call structure with the request. |
109 | */ |
109 | */ |
110 | void vfs_register(ipc_callid_t rid, ipc_call_t *request) |
110 | void vfs_register(ipc_callid_t rid, ipc_call_t *request) |
111 | { |
111 | { |
112 | ipc_callid_t callid; |
112 | ipc_callid_t callid; |
113 | ipc_call_t call; |
113 | ipc_call_t call; |
114 | int rc; |
114 | int rc; |
115 | size_t size; |
115 | size_t size; |
116 | 116 | ||
117 | dprintf("Processing VFS_REGISTER request received from %p.\n", |
117 | dprintf("Processing VFS_REGISTER request received from %p.\n", |
118 | request->in_phone_hash); |
118 | request->in_phone_hash); |
119 | 119 | ||
120 | /* |
120 | /* |
121 | * The first call has to be IPC_M_DATA_SEND in which we receive the |
121 | * The first call has to be IPC_M_DATA_SEND in which we receive the |
122 | * VFS info structure from the client FS. |
122 | * VFS info structure from the client FS. |
123 | */ |
123 | */ |
124 | if (!ipc_data_write_receive(&callid, &size)) { |
124 | if (!ipc_data_write_receive(&callid, &size)) { |
125 | /* |
125 | /* |
126 | * The client doesn't obey the same protocol as we do. |
126 | * The client doesn't obey the same protocol as we do. |
127 | */ |
127 | */ |
128 | dprintf("Receiving of VFS info failed.\n"); |
128 | dprintf("Receiving of VFS info failed.\n"); |
129 | ipc_answer_0(callid, EINVAL); |
129 | ipc_answer_0(callid, EINVAL); |
130 | ipc_answer_0(rid, EINVAL); |
130 | ipc_answer_0(rid, EINVAL); |
131 | return; |
131 | return; |
132 | } |
132 | } |
133 | 133 | ||
134 | dprintf("VFS info received, size = %d\n", size); |
134 | dprintf("VFS info received, size = %d\n", size); |
135 | 135 | ||
136 | /* |
136 | /* |
137 | * We know the size of the VFS info structure. See if the client |
137 | * We know the size of the VFS info structure. See if the client |
138 | * understands this easy concept too. |
138 | * understands this easy concept too. |
139 | */ |
139 | */ |
140 | if (size != sizeof(vfs_info_t)) { |
140 | if (size != sizeof(vfs_info_t)) { |
141 | /* |
141 | /* |
142 | * The client is sending us something, which cannot be |
142 | * The client is sending us something, which cannot be |
143 | * the info structure. |
143 | * the info structure. |
144 | */ |
144 | */ |
145 | dprintf("Received VFS info has bad size.\n"); |
145 | dprintf("Received VFS info has bad size.\n"); |
146 | ipc_answer_0(callid, EINVAL); |
146 | ipc_answer_0(callid, EINVAL); |
147 | ipc_answer_0(rid, EINVAL); |
147 | ipc_answer_0(rid, EINVAL); |
148 | return; |
148 | return; |
149 | } |
149 | } |
150 | 150 | ||
151 | /* |
151 | /* |
152 | * Allocate and initialize a buffer for the fs_info structure. |
152 | * Allocate and initialize a buffer for the fs_info structure. |
153 | */ |
153 | */ |
154 | fs_info_t *fs_info; |
154 | fs_info_t *fs_info; |
155 | fs_info = (fs_info_t *) malloc(sizeof(fs_info_t)); |
155 | fs_info = (fs_info_t *) malloc(sizeof(fs_info_t)); |
156 | if (!fs_info) { |
156 | if (!fs_info) { |
157 | dprintf("Could not allocate memory for FS info.\n"); |
157 | dprintf("Could not allocate memory for FS info.\n"); |
158 | ipc_answer_0(callid, ENOMEM); |
158 | ipc_answer_0(callid, ENOMEM); |
159 | ipc_answer_0(rid, ENOMEM); |
159 | ipc_answer_0(rid, ENOMEM); |
160 | return; |
160 | return; |
161 | } |
161 | } |
162 | link_initialize(&fs_info->fs_link); |
162 | link_initialize(&fs_info->fs_link); |
163 | fibril_mutex_initialize(&fs_info->phone_lock); |
163 | fibril_mutex_initialize(&fs_info->phone_lock); |
164 | 164 | ||
165 | rc = ipc_data_write_finalize(callid, &fs_info->vfs_info, size); |
165 | rc = ipc_data_write_finalize(callid, &fs_info->vfs_info, size); |
166 | if (rc != EOK) { |
166 | if (rc != EOK) { |
167 | dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n", |
167 | dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n", |
168 | rc); |
168 | rc); |
169 | free(fs_info); |
169 | free(fs_info); |
170 | ipc_answer_0(callid, rc); |
170 | ipc_answer_0(callid, rc); |
171 | ipc_answer_0(rid, rc); |
171 | ipc_answer_0(rid, rc); |
172 | return; |
172 | return; |
173 | } |
173 | } |
174 | 174 | ||
175 | dprintf("VFS info delivered.\n"); |
175 | dprintf("VFS info delivered.\n"); |
176 | 176 | ||
177 | if (!vfs_info_sane(&fs_info->vfs_info)) { |
177 | if (!vfs_info_sane(&fs_info->vfs_info)) { |
178 | free(fs_info); |
178 | free(fs_info); |
179 | ipc_answer_0(callid, EINVAL); |
179 | ipc_answer_0(callid, EINVAL); |
180 | ipc_answer_0(rid, EINVAL); |
180 | ipc_answer_0(rid, EINVAL); |
181 | return; |
181 | return; |
182 | } |
182 | } |
183 | 183 | ||
184 | fibril_mutex_lock(&fs_head_lock); |
184 | fibril_mutex_lock(&fs_head_lock); |
185 | 185 | ||
186 | /* |
186 | /* |
187 | * Check for duplicit registrations. |
187 | * Check for duplicit registrations. |
188 | */ |
188 | */ |
189 | if (fs_name_to_handle(fs_info->vfs_info.name, false)) { |
189 | if (fs_name_to_handle(fs_info->vfs_info.name, false)) { |
190 | /* |
190 | /* |
191 | * We already register a fs like this. |
191 | * We already register a fs like this. |
192 | */ |
192 | */ |
193 | dprintf("FS is already registered.\n"); |
193 | dprintf("FS is already registered.\n"); |
194 | fibril_mutex_unlock(&fs_head_lock); |
194 | fibril_mutex_unlock(&fs_head_lock); |
195 | free(fs_info); |
195 | free(fs_info); |
196 | ipc_answer_0(callid, EEXISTS); |
196 | ipc_answer_0(callid, EEXISTS); |
197 | ipc_answer_0(rid, EEXISTS); |
197 | ipc_answer_0(rid, EEXISTS); |
198 | return; |
198 | return; |
199 | } |
199 | } |
200 | 200 | ||
201 | /* |
201 | /* |
202 | * Add fs_info to the list of registered FS's. |
202 | * Add fs_info to the list of registered FS's. |
203 | */ |
203 | */ |
204 | dprintf("Inserting FS into the list of registered file systems.\n"); |
204 | dprintf("Inserting FS into the list of registered file systems.\n"); |
205 | list_append(&fs_info->fs_link, &fs_head); |
205 | list_append(&fs_info->fs_link, &fs_head); |
206 | 206 | ||
207 | /* |
207 | /* |
208 | * Now we want the client to send us the IPC_M_CONNECT_TO_ME call so |
208 | * Now we want the client to send us the IPC_M_CONNECT_TO_ME call so |
209 | * that a callback connection is created and we have a phone through |
209 | * that a callback connection is created and we have a phone through |
210 | * which to forward VFS requests to it. |
210 | * which to forward VFS requests to it. |
211 | */ |
211 | */ |
212 | callid = async_get_call(&call); |
212 | callid = async_get_call(&call); |
213 | if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { |
213 | if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { |
214 | dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); |
214 | dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); |
215 | list_remove(&fs_info->fs_link); |
215 | list_remove(&fs_info->fs_link); |
216 | fibril_mutex_unlock(&fs_head_lock); |
216 | fibril_mutex_unlock(&fs_head_lock); |
217 | free(fs_info); |
217 | free(fs_info); |
218 | ipc_answer_0(callid, EINVAL); |
218 | ipc_answer_0(callid, EINVAL); |
219 | ipc_answer_0(rid, EINVAL); |
219 | ipc_answer_0(rid, EINVAL); |
220 | return; |
220 | return; |
221 | } |
221 | } |
222 | fs_info->phone = IPC_GET_ARG5(call); |
222 | fs_info->phone = IPC_GET_ARG5(call); |
223 | ipc_answer_0(callid, EOK); |
223 | ipc_answer_0(callid, EOK); |
224 | 224 | ||
225 | dprintf("Callback connection to FS created.\n"); |
225 | dprintf("Callback connection to FS created.\n"); |
226 | 226 | ||
227 | /* |
227 | /* |
228 | * The client will want us to send him the address space area with PLB. |
228 | * The client will want us to send him the address space area with PLB. |
229 | */ |
229 | */ |
230 | 230 | ||
231 | if (!ipc_share_in_receive(&callid, &size)) { |
231 | if (!ipc_share_in_receive(&callid, &size)) { |
232 | dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); |
232 | dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); |
233 | list_remove(&fs_info->fs_link); |
233 | list_remove(&fs_info->fs_link); |
234 | fibril_mutex_unlock(&fs_head_lock); |
234 | fibril_mutex_unlock(&fs_head_lock); |
235 | ipc_hangup(fs_info->phone); |
235 | ipc_hangup(fs_info->phone); |
236 | free(fs_info); |
236 | free(fs_info); |
237 | ipc_answer_0(callid, EINVAL); |
237 | ipc_answer_0(callid, EINVAL); |
238 | ipc_answer_0(rid, EINVAL); |
238 | ipc_answer_0(rid, EINVAL); |
239 | return; |
239 | return; |
240 | } |
240 | } |
241 | 241 | ||
242 | /* |
242 | /* |
243 | * We can only send the client address space area PLB_SIZE bytes long. |
243 | * We can only send the client address space area PLB_SIZE bytes long. |
244 | */ |
244 | */ |
245 | if (size != PLB_SIZE) { |
245 | if (size != PLB_SIZE) { |
246 | dprintf("Client suggests wrong size of PFB, size = %d\n", size); |
246 | dprintf("Client suggests wrong size of PFB, size = %d\n", size); |
247 | list_remove(&fs_info->fs_link); |
247 | list_remove(&fs_info->fs_link); |
248 | fibril_mutex_unlock(&fs_head_lock); |
248 | fibril_mutex_unlock(&fs_head_lock); |
249 | ipc_hangup(fs_info->phone); |
249 | ipc_hangup(fs_info->phone); |
250 | free(fs_info); |
250 | free(fs_info); |
251 | ipc_answer_0(callid, EINVAL); |
251 | ipc_answer_0(callid, EINVAL); |
252 | ipc_answer_0(rid, EINVAL); |
252 | ipc_answer_0(rid, EINVAL); |
253 | return; |
253 | return; |
254 | } |
254 | } |
255 | 255 | ||
256 | /* |
256 | /* |
257 | * Commit to read-only sharing the PLB with the client. |
257 | * Commit to read-only sharing the PLB with the client. |
258 | */ |
258 | */ |
259 | (void) ipc_share_in_finalize(callid, plb, |
259 | (void) ipc_share_in_finalize(callid, plb, |
260 | AS_AREA_READ | AS_AREA_CACHEABLE); |
260 | AS_AREA_READ | AS_AREA_CACHEABLE); |
261 | 261 | ||
262 | dprintf("Sharing PLB.\n"); |
262 | dprintf("Sharing PLB.\n"); |
263 | 263 | ||
264 | /* |
264 | /* |
265 | * That was it. The FS has been registered. |
265 | * That was it. The FS has been registered. |
266 | * In reply to the VFS_REGISTER request, we assign the client file |
266 | * In reply to the VFS_REGISTER request, we assign the client file |
267 | * system a global file system handle. |
267 | * system a global file system handle. |
268 | */ |
268 | */ |
269 | fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next); |
269 | fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next); |
270 | ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle); |
270 | ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle); |
271 | 271 | ||
272 | fibril_condvar_signal(&fs_head_cv); |
272 | fibril_condvar_broadcast(&fs_head_cv); |
273 | fibril_mutex_unlock(&fs_head_lock); |
273 | fibril_mutex_unlock(&fs_head_lock); |
274 | 274 | ||
275 | dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n", |
275 | dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n", |
276 | FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle); |
276 | FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle); |
277 | } |
277 | } |
278 | 278 | ||
279 | /** For a given file system handle, implement policy for allocating a phone. |
279 | /** For a given file system handle, implement policy for allocating a phone. |
280 | * |
280 | * |
281 | * @param handle File system handle. |
281 | * @param handle File system handle. |
282 | * |
282 | * |
283 | * @return Phone over which a multi-call request can be safely |
283 | * @return Phone over which a multi-call request can be safely |
284 | * sent. Return 0 if no phone was found. |
284 | * sent. Return 0 if no phone was found. |
285 | */ |
285 | */ |
286 | int vfs_grab_phone(fs_handle_t handle) |
286 | int vfs_grab_phone(fs_handle_t handle) |
287 | { |
287 | { |
288 | int phone; |
288 | int phone; |
289 | 289 | ||
290 | /* |
290 | /* |
291 | * For now, we don't try to be very clever and very fast. We simply |
291 | * For now, we don't try to be very clever and very fast. We simply |
292 | * lookup the phone in the fs_head list and duplicate it. The duplicate |
292 | * lookup the phone in the fs_head list and duplicate it. The duplicate |
293 | * phone will be returned to the client and the client will use it for |
293 | * phone will be returned to the client and the client will use it for |
294 | * communication. In the future, we should cache the connections so |
294 | * communication. In the future, we should cache the connections so |
295 | * that they do not have to be reestablished over and over again. |
295 | * that they do not have to be reestablished over and over again. |
296 | */ |
296 | */ |
297 | fibril_mutex_lock(&fs_head_lock); |
297 | fibril_mutex_lock(&fs_head_lock); |
298 | link_t *cur; |
298 | link_t *cur; |
299 | fs_info_t *fs; |
299 | fs_info_t *fs; |
300 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
300 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
301 | fs = list_get_instance(cur, fs_info_t, fs_link); |
301 | fs = list_get_instance(cur, fs_info_t, fs_link); |
302 | if (fs->fs_handle == handle) { |
302 | if (fs->fs_handle == handle) { |
303 | fibril_mutex_unlock(&fs_head_lock); |
303 | fibril_mutex_unlock(&fs_head_lock); |
304 | fibril_mutex_lock(&fs->phone_lock); |
304 | fibril_mutex_lock(&fs->phone_lock); |
305 | phone = ipc_connect_me_to(fs->phone, 0, 0, 0); |
305 | phone = ipc_connect_me_to(fs->phone, 0, 0, 0); |
306 | fibril_mutex_unlock(&fs->phone_lock); |
306 | fibril_mutex_unlock(&fs->phone_lock); |
307 | 307 | ||
308 | assert(phone > 0); |
308 | assert(phone > 0); |
309 | return phone; |
309 | return phone; |
310 | } |
310 | } |
311 | } |
311 | } |
312 | fibril_mutex_unlock(&fs_head_lock); |
312 | fibril_mutex_unlock(&fs_head_lock); |
313 | return 0; |
313 | return 0; |
314 | } |
314 | } |
315 | 315 | ||
316 | /** Tell VFS that the phone is not needed anymore. |
316 | /** Tell VFS that the phone is not needed anymore. |
317 | * |
317 | * |
318 | * @param phone Phone to FS task. |
318 | * @param phone Phone to FS task. |
319 | */ |
319 | */ |
320 | void vfs_release_phone(int phone) |
320 | void vfs_release_phone(int phone) |
321 | { |
321 | { |
322 | /* TODO: implement connection caching */ |
322 | /* TODO: implement connection caching */ |
323 | ipc_hangup(phone); |
323 | ipc_hangup(phone); |
324 | } |
324 | } |
325 | 325 | ||
326 | /** Convert file system name to its handle. |
326 | /** Convert file system name to its handle. |
327 | * |
327 | * |
328 | * @param name File system name. |
328 | * @param name File system name. |
329 | * @param lock If true, the function will lock and unlock the |
329 | * @param lock If true, the function will lock and unlock the |
330 | * fs_head_lock. |
330 | * fs_head_lock. |
331 | * |
331 | * |
332 | * @return File system handle or zero if file system not found. |
332 | * @return File system handle or zero if file system not found. |
333 | */ |
333 | */ |
334 | fs_handle_t fs_name_to_handle(char *name, bool lock) |
334 | fs_handle_t fs_name_to_handle(char *name, bool lock) |
335 | { |
335 | { |
336 | int handle = 0; |
336 | int handle = 0; |
337 | 337 | ||
338 | if (lock) |
338 | if (lock) |
339 | fibril_mutex_lock(&fs_head_lock); |
339 | fibril_mutex_lock(&fs_head_lock); |
340 | link_t *cur; |
340 | link_t *cur; |
341 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
341 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
342 | fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link); |
342 | fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link); |
343 | if (str_cmp(fs->vfs_info.name, name) == 0) { |
343 | if (str_cmp(fs->vfs_info.name, name) == 0) { |
344 | handle = fs->fs_handle; |
344 | handle = fs->fs_handle; |
345 | break; |
345 | break; |
346 | } |
346 | } |
347 | } |
347 | } |
348 | if (lock) |
348 | if (lock) |
349 | fibril_mutex_unlock(&fs_head_lock); |
349 | fibril_mutex_unlock(&fs_head_lock); |
350 | return handle; |
350 | return handle; |
351 | } |
351 | } |
352 | 352 | ||
353 | /** |
353 | /** |
354 | * @} |
354 | * @} |
355 | */ |
355 | */ |
356 | 356 |