Subversion Repositories HelenOS

Rev

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

Rev 2560 Rev 2589
Line 41... Line 41...
41
#include <stdlib.h>
41
#include <stdlib.h>
42
#include <string.h>
42
#include <string.h>
43
#include <bool.h>
43
#include <bool.h>
44
#include <futex.h>
44
#include <futex.h>
45
#include <libadt/list.h>
45
#include <libadt/list.h>
-
 
46
#include <sys/types.h>
46
#include "vfs.h"
47
#include "vfs.h"
47
 
48
 
-
 
49
/** Per-connection futex protecting the files array. */
-
 
50
__thread atomic_t files_futex = FUTEX_INITIALIZER;
-
 
51
 
48
/**
52
/**
49
 * This is a per-connection table of open files.
53
 * This is a per-connection table of open files.
50
 * Our assumption is that each client opens only one connection and therefore
54
 * Our assumption is that each client opens only one connection and therefore
51
 * there is one table of open files per task. However, this may not be the case
55
 * there is one table of open files per task. However, this may not be the case
52
 * and the client can open more connections to VFS. In that case, there will be
56
 * and the client can open more connections to VFS. In that case, there will be
53
 * several tables and several file handle name spaces per task. Besides of this,
57
 * several tables and several file handle name spaces per task. Besides of this,
54
 * the functionality will stay unchanged. So unless the client knows what it is
58
 * the functionality will stay unchanged. So unless the client knows what it is
55
 * doing, it should open one connection to VFS only.
59
 * doing, it should open one connection to VFS only.
-
 
60
 *
-
 
61
 * Allocation of the open files table is deferred until the client makes the
-
 
62
 * first VFS_OPEN operation.
56
 */
63
 */
57
__thread vfs_file_t files[MAX_OPEN_FILES];
64
__thread vfs_file_t *files = NULL;
58
 
65
 
59
/** Initialize the table of open files. */
66
/** Initialize the table of open files. */
60
bool vfs_conn_open_files_init(void)
67
static bool vfs_conn_open_files_init(void)
61
{
68
{
-
 
69
    futex_down(&files_futex);
-
 
70
    if (!files) {
-
 
71
        files = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t));
-
 
72
        if (!files) {
-
 
73
            futex_up(&files_futex);
-
 
74
            return false;
-
 
75
        }
62
    memset(files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t));
76
        memset(files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t));
-
 
77
    }
-
 
78
    futex_up(&files_futex);
63
    return true;
79
    return true;
64
}
80
}
65
 
81
 
66
void vfs_open(ipc_callid_t rid, ipc_call_t *request)
82
void vfs_open(ipc_callid_t rid, ipc_call_t *request)
67
{
83
{
-
 
84
    if (!vfs_conn_open_files_init()) {
-
 
85
        ipc_answer_fast_0(rid, ENOMEM);
-
 
86
        return;
-
 
87
    }
68
}
88
}
69
 
89
 
70
/**
90
/**
71
 * @}
91
 * @}
72
 */
92
 */