Subversion Repositories HelenOS

Rev

Rev 4341 | Rev 4348 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4341 Rev 4345
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 <futex.h>
48
#include <futex.h>
49
#include <libadt/list.h>
49
#include <libadt/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
atomic_t fs_head_futex = FUTEX_INITIALIZER;
55
atomic_t fs_head_futex = FUTEX_INITIALIZER;
56
link_t fs_head;
56
link_t fs_head;
57
 
57
 
58
atomic_t fs_handle_next = {
58
atomic_t fs_handle_next = {
59
    .count = 1
59
    .count = 1
60
};
60
};
61
 
61
 
62
/** Verify the VFS info structure.
62
/** Verify the VFS info structure.
63
 *
63
 *
64
 * @param info      Info structure to be verified.
64
 * @param info      Info structure to be verified.
65
 *
65
 *
66
 * @return      Non-zero if the info structure is sane, zero otherwise.
66
 * @return      Non-zero if the info structure is sane, zero otherwise.
67
 */
67
 */
68
static bool vfs_info_sane(vfs_info_t *info)
68
static bool vfs_info_sane(vfs_info_t *info)
69
{
69
{
70
    int i;
70
    int i;
71
 
71
 
72
    /*
72
    /*
73
     * Check if the name is non-empty and is composed solely of ASCII
73
     * Check if the name is non-empty and is composed solely of ASCII
74
     * characters [a-z]+[a-z0-9_-]*.
74
     * characters [a-z]+[a-z0-9_-]*.
75
     */
75
     */
76
    if (!islower(info->name[0])) {
76
    if (!islower(info->name[0])) {
77
        dprintf("The name doesn't start with a lowercase character.\n");
77
        dprintf("The name doesn't start with a lowercase character.\n");
78
        return false;
78
        return false;
79
    }
79
    }
80
    for (i = 1; i < FS_NAME_MAXLEN; i++) {
80
    for (i = 1; i < FS_NAME_MAXLEN; i++) {
81
        if (!(islower(info->name[i]) || isdigit(info->name[i])) &&
81
        if (!(islower(info->name[i]) || isdigit(info->name[i])) &&
82
            (info->name[i] != '-') && (info->name[i] != '_')) {
82
            (info->name[i] != '-') && (info->name[i] != '_')) {
83
            if (info->name[i] == '\0') {
83
            if (info->name[i] == '\0') {
84
                break;
84
                break;
85
            } else {
85
            } else {
86
                dprintf("The name contains illegal "
86
                dprintf("The name contains illegal "
87
                    "characters.\n");
87
                    "characters.\n");
88
                return false;
88
                return false;
89
            }
89
            }
90
        }
90
        }
91
    }
91
    }
92
    /*
92
    /*
93
     * This check is not redundant. It ensures that the name is
93
     * This check is not redundant. It ensures that the name is
94
     * NULL-terminated, even if FS_NAME_MAXLEN characters are used.
94
     * NULL-terminated, even if FS_NAME_MAXLEN characters are used.
95
     */
95
     */
96
    if (info->name[i] != '\0') {
96
    if (info->name[i] != '\0') {
97
        dprintf("The name is not properly NULL-terminated.\n");
97
        dprintf("The name is not properly NULL-terminated.\n");
98
        return false;
98
        return false;
99
    }
99
    }
100
   
100
   
101
    return true;
101
    return true;
102
}
102
}
103
 
103
 
104
/** VFS_REGISTER protocol function.
104
/** VFS_REGISTER protocol function.
105
 *
105
 *
106
 * @param rid       Hash of the call with the request.
106
 * @param rid       Hash of the call with the request.
107
 * @param request   Call structure with the request.
107
 * @param request   Call structure with the request.
108
 */
108
 */
109
void vfs_register(ipc_callid_t rid, ipc_call_t *request)
109
void vfs_register(ipc_callid_t rid, ipc_call_t *request)
110
{
110
{
111
    ipc_callid_t callid;
111
    ipc_callid_t callid;
112
    ipc_call_t call;
112
    ipc_call_t call;
113
    int rc;
113
    int rc;
114
    size_t size;
114
    size_t size;
115
 
115
 
116
    dprintf("Processing VFS_REGISTER request received from %p.\n",
116
    dprintf("Processing VFS_REGISTER request received from %p.\n",
117
        request->in_phone_hash);
117
        request->in_phone_hash);
118
 
118
 
119
    /*
119
    /*
120
     * The first call has to be IPC_M_DATA_SEND in which we receive the
120
     * The first call has to be IPC_M_DATA_SEND in which we receive the
121
     * VFS info structure from the client FS.
121
     * VFS info structure from the client FS.
122
     */
122
     */
123
    if (!ipc_data_write_receive(&callid, &size)) {
123
    if (!ipc_data_write_receive(&callid, &size)) {
124
        /*
124
        /*
125
         * The client doesn't obey the same protocol as we do.
125
         * The client doesn't obey the same protocol as we do.
126
         */
126
         */
127
        dprintf("Receiving of VFS info failed.\n");
127
        dprintf("Receiving of VFS info failed.\n");
128
        ipc_answer_0(callid, EINVAL);
128
        ipc_answer_0(callid, EINVAL);
129
        ipc_answer_0(rid, EINVAL);
129
        ipc_answer_0(rid, EINVAL);
130
        return;
130
        return;
131
    }
131
    }
132
   
132
   
133
    dprintf("VFS info received, size = %d\n", size);
133
    dprintf("VFS info received, size = %d\n", size);
134
   
134
   
135
    /*
135
    /*
136
     * We know the size of the VFS info structure. See if the client
136
     * We know the size of the VFS info structure. See if the client
137
     * understands this easy concept too.
137
     * understands this easy concept too.
138
     */
138
     */
139
    if (size != sizeof(vfs_info_t)) {
139
    if (size != sizeof(vfs_info_t)) {
140
        /*
140
        /*
141
         * The client is sending us something, which cannot be
141
         * The client is sending us something, which cannot be
142
         * the info structure.
142
         * the info structure.
143
         */
143
         */
144
        dprintf("Received VFS info has bad size.\n");
144
        dprintf("Received VFS info has bad size.\n");
145
        ipc_answer_0(callid, EINVAL);
145
        ipc_answer_0(callid, EINVAL);
146
        ipc_answer_0(rid, EINVAL);
146
        ipc_answer_0(rid, EINVAL);
147
        return;
147
        return;
148
    }
148
    }
149
 
149
 
150
    /*
150
    /*
151
     * Allocate and initialize a buffer for the fs_info structure.
151
     * Allocate and initialize a buffer for the fs_info structure.
152
     */
152
     */
153
    fs_info_t *fs_info;
153
    fs_info_t *fs_info;
154
    fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
154
    fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
155
    if (!fs_info) {
155
    if (!fs_info) {
156
        dprintf("Could not allocate memory for FS info.\n");
156
        dprintf("Could not allocate memory for FS info.\n");
157
        ipc_answer_0(callid, ENOMEM);
157
        ipc_answer_0(callid, ENOMEM);
158
        ipc_answer_0(rid, ENOMEM);
158
        ipc_answer_0(rid, ENOMEM);
159
        return;
159
        return;
160
    }
160
    }
161
    link_initialize(&fs_info->fs_link);
161
    link_initialize(&fs_info->fs_link);
162
    futex_initialize(&fs_info->phone_futex, 1);
162
    futex_initialize(&fs_info->phone_futex, 1);
163
       
163
       
164
    rc = ipc_data_write_finalize(callid, &fs_info->vfs_info, size);
164
    rc = ipc_data_write_finalize(callid, &fs_info->vfs_info, size);
165
    if (rc != EOK) {
165
    if (rc != EOK) {
166
        dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
166
        dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
167
            rc);
167
            rc);
168
        free(fs_info);
168
        free(fs_info);
169
        ipc_answer_0(callid, rc);
169
        ipc_answer_0(callid, rc);
170
        ipc_answer_0(rid, rc);
170
        ipc_answer_0(rid, rc);
171
        return;
171
        return;
172
    }
172
    }
173
 
173
 
174
    dprintf("VFS info delivered.\n");
174
    dprintf("VFS info delivered.\n");
175
       
175
       
176
    if (!vfs_info_sane(&fs_info->vfs_info)) {
176
    if (!vfs_info_sane(&fs_info->vfs_info)) {
177
        free(fs_info);
177
        free(fs_info);
178
        ipc_answer_0(callid, EINVAL);
178
        ipc_answer_0(callid, EINVAL);
179
        ipc_answer_0(rid, EINVAL);
179
        ipc_answer_0(rid, EINVAL);
180
        return;
180
        return;
181
    }
181
    }
182
       
182
       
183
    futex_down(&fs_head_futex);
183
    futex_down(&fs_head_futex);
184
    fibril_inc_sercount();
184
    fibril_inc_sercount();
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_dec_sercount();
194
        fibril_dec_sercount();
195
        futex_up(&fs_head_futex);
195
        futex_up(&fs_head_futex);
196
        free(fs_info);
196
        free(fs_info);
197
        ipc_answer_0(callid, EEXISTS);
197
        ipc_answer_0(callid, EEXISTS);
198
        ipc_answer_0(rid, EEXISTS);
198
        ipc_answer_0(rid, EEXISTS);
199
        return;
199
        return;
200
    }
200
    }
201
 
201
 
202
    /*
202
    /*
203
     * Add fs_info to the list of registered FS's.
203
     * Add fs_info to the list of registered FS's.
204
     */
204
     */
205
    dprintf("Inserting FS into the list of registered file systems.\n");
205
    dprintf("Inserting FS into the list of registered file systems.\n");
206
    list_append(&fs_info->fs_link, &fs_head);
206
    list_append(&fs_info->fs_link, &fs_head);
207
   
207
   
208
    /*
208
    /*
209
     * Now we want the client to send us the IPC_M_CONNECT_TO_ME call so
209
     * Now we want the client to send us the IPC_M_CONNECT_TO_ME call so
210
     * that a callback connection is created and we have a phone through
210
     * that a callback connection is created and we have a phone through
211
     * which to forward VFS requests to it.
211
     * which to forward VFS requests to it.
212
     */
212
     */
213
    callid = async_get_call(&call);
213
    callid = async_get_call(&call);
214
    if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
214
    if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
215
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
215
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
216
        list_remove(&fs_info->fs_link);
216
        list_remove(&fs_info->fs_link);
217
        fibril_dec_sercount();
217
        fibril_dec_sercount();
218
        futex_up(&fs_head_futex);
218
        futex_up(&fs_head_futex);
219
        free(fs_info);
219
        free(fs_info);
220
        ipc_answer_0(callid, EINVAL);
220
        ipc_answer_0(callid, EINVAL);
221
        ipc_answer_0(rid, EINVAL);
221
        ipc_answer_0(rid, EINVAL);
222
        return;
222
        return;
223
    }
223
    }
224
    fs_info->phone = IPC_GET_ARG5(call);
224
    fs_info->phone = IPC_GET_ARG5(call);
225
    ipc_answer_0(callid, EOK);
225
    ipc_answer_0(callid, EOK);
226
 
226
 
227
    dprintf("Callback connection to FS created.\n");
227
    dprintf("Callback connection to FS created.\n");
228
 
228
 
229
    /*
229
    /*
230
     * The client will want us to send him the address space area with PLB.
230
     * The client will want us to send him the address space area with PLB.
231
     */
231
     */
232
 
232
 
233
    if (!ipc_share_in_receive(&callid, &size)) {
233
    if (!ipc_share_in_receive(&callid, &size)) {
234
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
234
        dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
235
        list_remove(&fs_info->fs_link);
235
        list_remove(&fs_info->fs_link);
236
        fibril_dec_sercount();
236
        fibril_dec_sercount();
237
        futex_up(&fs_head_futex);
237
        futex_up(&fs_head_futex);
238
        ipc_hangup(fs_info->phone);
238
        ipc_hangup(fs_info->phone);
239
        free(fs_info);
239
        free(fs_info);
240
        ipc_answer_0(callid, EINVAL);
240
        ipc_answer_0(callid, EINVAL);
241
        ipc_answer_0(rid, EINVAL);
241
        ipc_answer_0(rid, EINVAL);
242
        return;
242
        return;
243
    }
243
    }
244
   
244
   
245
    /*
245
    /*
246
     * We can only send the client address space area PLB_SIZE bytes long.
246
     * We can only send the client address space area PLB_SIZE bytes long.
247
     */
247
     */
248
    if (size != PLB_SIZE) {
248
    if (size != PLB_SIZE) {
249
        dprintf("Client suggests wrong size of PFB, size = %d\n", size);
249
        dprintf("Client suggests wrong size of PFB, size = %d\n", size);
250
        list_remove(&fs_info->fs_link);
250
        list_remove(&fs_info->fs_link);
251
        fibril_dec_sercount();
251
        fibril_dec_sercount();
252
        futex_up(&fs_head_futex);
252
        futex_up(&fs_head_futex);
253
        ipc_hangup(fs_info->phone);
253
        ipc_hangup(fs_info->phone);
254
        free(fs_info);
254
        free(fs_info);
255
        ipc_answer_0(callid, EINVAL);
255
        ipc_answer_0(callid, EINVAL);
256
        ipc_answer_0(rid, EINVAL);
256
        ipc_answer_0(rid, EINVAL);
257
        return;
257
        return;
258
    }
258
    }
259
 
259
 
260
    /*
260
    /*
261
     * Commit to read-only sharing the PLB with the client.
261
     * Commit to read-only sharing the PLB with the client.
262
     */
262
     */
263
    (void) ipc_share_in_finalize(callid, plb,
263
    (void) ipc_share_in_finalize(callid, plb,
264
        AS_AREA_READ | AS_AREA_CACHEABLE);
264
        AS_AREA_READ | AS_AREA_CACHEABLE);
265
 
265
 
266
    dprintf("Sharing PLB.\n");
266
    dprintf("Sharing PLB.\n");
267
 
267
 
268
    /*
268
    /*
269
     * That was it. The FS has been registered.
269
     * That was it. The FS has been registered.
270
     * In reply to the VFS_REGISTER request, we assign the client file
270
     * In reply to the VFS_REGISTER request, we assign the client file
271
     * system a global file system handle.
271
     * system a global file system handle.
272
     */
272
     */
273
    fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next);
273
    fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next);
274
    ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle);
274
    ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle);
275
   
275
   
276
    fibril_dec_sercount();
276
    fibril_dec_sercount();
277
    futex_up(&fs_head_futex);
277
    futex_up(&fs_head_futex);
278
   
278
   
279
    dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
279
    dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
280
        FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle);
280
        FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle);
-
 
281
   
-
 
282
    /* Process pending mount requests possibly waiting
-
 
283
     * for this filesystem implementation.
-
 
284
     */
-
 
285
    vfs_process_pending_mount();
281
}
286
}
282
 
287
 
283
/** For a given file system handle, implement policy for allocating a phone.
288
/** For a given file system handle, implement policy for allocating a phone.
284
 *
289
 *
285
 * @param handle    File system handle.
290
 * @param handle    File system handle.
286
 *
291
 *
287
 * @return      Phone over which a multi-call request can be safely
292
 * @return      Phone over which a multi-call request can be safely
288
 *          sent. Return 0 if no phone was found.
293
 *          sent. Return 0 if no phone was found.
289
 */
294
 */
290
int vfs_grab_phone(fs_handle_t handle)
295
int vfs_grab_phone(fs_handle_t handle)
291
{
296
{
292
    /*
297
    /*
293
     * For now, we don't try to be very clever and very fast.
298
     * For now, we don't try to be very clever and very fast.
294
     * We simply lookup the phone in the fs_head list. We currently don't
299
     * We simply lookup the phone in the fs_head list. We currently don't
295
     * open any additional phones (even though that itself would be pretty
300
     * open any additional phones (even though that itself would be pretty
296
     * straightforward; housekeeping multiple open phones to a FS task would
301
     * straightforward; housekeeping multiple open phones to a FS task would
297
     * be more demanding). Instead, we simply take the respective
302
     * be more demanding). Instead, we simply take the respective
298
     * phone_futex and keep it until vfs_release_phone().
303
     * phone_futex and keep it until vfs_release_phone().
299
     */
304
     */
300
    futex_down(&fs_head_futex);
305
    futex_down(&fs_head_futex);
301
    link_t *cur;
306
    link_t *cur;
302
    fs_info_t *fs;
307
    fs_info_t *fs;
303
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
308
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
304
        fs = list_get_instance(cur, fs_info_t, fs_link);
309
        fs = list_get_instance(cur, fs_info_t, fs_link);
305
        if (fs->fs_handle == handle) {
310
        if (fs->fs_handle == handle) {
306
            futex_up(&fs_head_futex);
311
            futex_up(&fs_head_futex);
307
            /*
312
            /*
308
             * For now, take the futex unconditionally.
313
             * For now, take the futex unconditionally.
309
             * Oh yeah, serialization rocks.
314
             * Oh yeah, serialization rocks.
310
             * It will be up'ed in vfs_release_phone().
315
             * It will be up'ed in vfs_release_phone().
311
             */
316
             */
312
            futex_down(&fs->phone_futex);
317
            futex_down(&fs->phone_futex);
313
            /*
318
            /*
314
             * Avoid deadlock with other fibrils in the same thread
319
             * Avoid deadlock with other fibrils in the same thread
315
             * by disabling fibril preemption.
320
             * by disabling fibril preemption.
316
             */
321
             */
317
            fibril_inc_sercount();
322
            fibril_inc_sercount();
318
            return fs->phone;
323
            return fs->phone;
319
        }
324
        }
320
    }
325
    }
321
    futex_up(&fs_head_futex);
326
    futex_up(&fs_head_futex);
322
    return 0;
327
    return 0;
323
}
328
}
324
 
329
 
325
/** Tell VFS that the phone is in use for any request.
330
/** Tell VFS that the phone is in use for any request.
326
 *
331
 *
327
 * @param phone     Phone to FS task.
332
 * @param phone     Phone to FS task.
328
 */
333
 */
329
void vfs_release_phone(int phone)
334
void vfs_release_phone(int phone)
330
{
335
{
331
    bool found = false;
336
    bool found = false;
332
 
337
 
333
    /*
338
    /*
334
     * Undo the fibril_inc_sercount() done in vfs_grab_phone().
339
     * Undo the fibril_inc_sercount() done in vfs_grab_phone().
335
     */
340
     */
336
    fibril_dec_sercount();
341
    fibril_dec_sercount();
337
   
342
   
338
    futex_down(&fs_head_futex);
343
    futex_down(&fs_head_futex);
339
    link_t *cur;
344
    link_t *cur;
340
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
345
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
341
        fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
346
        fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
342
        if (fs->phone == phone) {
347
        if (fs->phone == phone) {
343
            found = true;
348
            found = true;
344
            futex_up(&fs_head_futex);
349
            futex_up(&fs_head_futex);
345
            futex_up(&fs->phone_futex);
350
            futex_up(&fs->phone_futex);
346
            return;
351
            return;
347
        }
352
        }
348
    }
353
    }
349
    futex_up(&fs_head_futex);
354
    futex_up(&fs_head_futex);
350
 
355
 
351
    /*
356
    /*
352
     * Not good to get here.
357
     * Not good to get here.
353
     */
358
     */
354
    assert(found == true);
359
    assert(found == true);
355
}
360
}
356
 
361
 
357
/** Convert file system name to its handle.
362
/** Convert file system name to its handle.
358
 *
363
 *
359
 * @param name      File system name.
364
 * @param name      File system name.
360
 * @param lock      If true, the function will down and up the
365
 * @param lock      If true, the function will down and up the
361
 *          fs_head_futex.
366
 *          fs_head_futex.
362
 *
367
 *
363
 * @return      File system handle or zero if file system not found.
368
 * @return      File system handle or zero if file system not found.
364
 */
369
 */
365
fs_handle_t fs_name_to_handle(char *name, bool lock)
370
fs_handle_t fs_name_to_handle(char *name, bool lock)
366
{
371
{
367
    int handle = 0;
372
    int handle = 0;
368
   
373
   
369
    if (lock)
374
    if (lock)
370
        futex_down(&fs_head_futex);
375
        futex_down(&fs_head_futex);
371
    link_t *cur;
376
    link_t *cur;
372
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
377
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
373
        fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
378
        fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
374
        if (strncmp(fs->vfs_info.name, name,
379
        if (strncmp(fs->vfs_info.name, name,
375
            sizeof(fs->vfs_info.name)) == 0) {
380
            sizeof(fs->vfs_info.name)) == 0) {
376
            handle = fs->fs_handle;
381
            handle = fs->fs_handle;
377
            break;
382
            break;
378
        }
383
        }
379
    }
384
    }
380
    if (lock)
385
    if (lock)
381
        futex_up(&fs_head_futex);
386
        futex_up(&fs_head_futex);
382
    return handle;
387
    return handle;
383
}
388
}
384
 
389
 
385
/**
390
/**
386
 * @}
391
 * @}
387
 */
392
 */
388
 
393