Subversion Repositories HelenOS

Rev

Rev 2543 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2543 Rev 2546
Line 45... Line 45...
45
#include <ctype.h>
45
#include <ctype.h>
46
#include <bool.h>
46
#include <bool.h>
47
#include <futex.h>
47
#include <futex.h>
48
#include <as.h>
48
#include <as.h>
49
#include <libadt/list.h>
49
#include <libadt/list.h>
-
 
50
#include <assert.h>
50
#include "vfs.h"
51
#include "vfs.h"
51
 
52
 
52
atomic_t fs_head_futex = FUTEX_INITIALIZER;
53
atomic_t fs_head_futex = FUTEX_INITIALIZER;
53
link_t fs_head;
54
link_t fs_head;
54
 
55
 
-
 
56
atomic_t fs_handle_next = {
-
 
57
    .count = 1
-
 
58
};
-
 
59
 
55
/** Verify the VFS info structure.
60
/** Verify the VFS info structure.
56
 *
61
 *
57
 * @param info      Info structure to be verified.
62
 * @param info      Info structure to be verified.
58
 *
63
 *
59
 * @return      Non-zero if the info structure is sane, zero otherwise.
64
 * @return      Non-zero if the info structure is sane, zero otherwise.
Line 303... Line 308...
303
 
308
 
304
    futex_up(&fs_head_futex);
309
    futex_up(&fs_head_futex);
305
 
310
 
306
    /*
311
    /*
307
     * That was it. The FS has been registered.
312
     * That was it. The FS has been registered.
-
 
313
     * In reply to the VFS_REGISTER request, we assign the client file
-
 
314
     * system a global file system handle.
308
     */
315
     */
-
 
316
    fs_info->fs_handle = (int) atomic_postinc(&fs_handle_next);
309
    ipc_answer_fast(rid, EOK, 0, 0);
317
    ipc_answer_fast(rid, EOK, (ipcarg_t) fs_info->fs_handle, 0);
310
    dprintf("\"%s\" filesystem successfully registered.\n",
318
    dprintf("\"%s\" filesystem successfully registered, handle=%d.\n",
311
        fs_info->vfs_info.name);
319
        fs_info->vfs_info.name, fs_info->fs_handle);
-
 
320
 
-
 
321
}
312
 
322
 
-
 
323
/** For a given file system handle, implement policy for allocating a phone.
-
 
324
 *
-
 
325
 * @param handle    File system handle.
-
 
326
 *
-
 
327
 * @return      Phone over which a multi-call request can be safely
-
 
328
 *          sent. Return 0 if no phone was found.
-
 
329
 */
-
 
330
int vfs_grab_phone(int handle)
-
 
331
{
-
 
332
    /*
-
 
333
     * For now, we don't try to be very clever and very fast.
-
 
334
     * We simply lookup the phone in the fs_head list. We currently don't
-
 
335
     * open any additional phones (even though that itself would be pretty
-
 
336
     * straightforward; housekeeping multiple open phones to a FS task would
-
 
337
     * be more demanding). Instead, we simply take the respective
-
 
338
     * phone_futex and keep it until vfs_release_phone().
-
 
339
     */
-
 
340
    futex_down(&fs_head_futex);
-
 
341
    link_t *cur;
-
 
342
    fs_info_t *fs;
-
 
343
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
-
 
344
        fs = list_get_instance(cur, fs_info_t, fs_link);
-
 
345
        if (fs->fs_handle == handle) {
-
 
346
            futex_up(&fs_head_futex);
-
 
347
            /*
-
 
348
             * For now, take the futex unconditionally.
-
 
349
             * Oh yeah, serialization rocks.
-
 
350
             * It will be up'ed in vfs_release_phone().
-
 
351
             */
-
 
352
            futex_down(&fs->phone_futex);
-
 
353
            return fs->phone;
-
 
354
        }
-
 
355
    }
-
 
356
    futex_up(&fs_head_futex);
-
 
357
    return 0;
-
 
358
}
-
 
359
 
-
 
360
/** Tell VFS that the phone is in use for any request.
-
 
361
 *
-
 
362
 * @param phone     Phone to FS task.
-
 
363
 */
-
 
364
void vfs_release_phone(int phone)
-
 
365
{
-
 
366
    bool found = false;
-
 
367
 
-
 
368
    futex_down(&fs_head_futex);
-
 
369
    link_t *cur;
-
 
370
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
-
 
371
        fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
-
 
372
        if (fs->phone == phone) {
-
 
373
            found = true;
-
 
374
            futex_up(&fs_head_futex);
-
 
375
            futex_up(&fs->phone_futex);
-
 
376
            return;
-
 
377
        }
-
 
378
    }
-
 
379
    futex_up(&fs_head_futex);
-
 
380
 
-
 
381
    /*
-
 
382
     * Not good to get here.
-
 
383
     */
-
 
384
    assert(found == true);
313
}
385
}
314
 
386
 
315
/**
387
/**
316
 * @}
388
 * @}
317
 */
389
 */