Subversion Repositories HelenOS

Rev

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

Rev 2680 Rev 2687
Line 40... Line 40...
40
#include <string.h>
40
#include <string.h>
41
#include <atomic.h>
41
#include <atomic.h>
42
#include <futex.h>
42
#include <futex.h>
43
#include <rwlock.h>
43
#include <rwlock.h>
44
#include <libadt/hash_table.h>
44
#include <libadt/hash_table.h>
-
 
45
#include <assert.h>
45
 
46
 
46
/** Futex protecting the VFS node hash table. */
47
/** Futex protecting the VFS node hash table. */
47
atomic_t nodes_futex = FUTEX_INITIALIZER;
48
atomic_t nodes_futex = FUTEX_INITIALIZER;
48
 
49
 
49
#define NODES_BUCKETS_LOG   8
50
#define NODES_BUCKETS_LOG   8
Line 119... Line 120...
119
 * In any case, the VFS node will have its reference count incremented. Every
120
 * In any case, the VFS node will have its reference count incremented. Every
120
 * node returned by this call should be eventually put back by calling
121
 * node returned by this call should be eventually put back by calling
121
 * vfs_node_put() on it.
122
 * vfs_node_put() on it.
122
 *
123
 *
123
 * @param triplet   Triplet encoding the identity of the VFS node.
124
 * @param triplet   Triplet encoding the identity of the VFS node.
-
 
125
 * @param size      Size of the node as filled by vfs_lookup_internal().
124
 *
126
 *
125
 * @return      VFS node corresponding to the given triplet.
127
 * @return      VFS node corresponding to the given triplet.
126
 */
128
 */
127
vfs_node_t *vfs_node_get(vfs_triplet_t *triplet)
129
vfs_node_t *vfs_node_get(vfs_triplet_t *triplet, size_t size)
128
{
130
{
129
    unsigned long key[] = {
131
    unsigned long key[] = {
130
        [KEY_FS_HANDLE] = triplet->fs_handle,
132
        [KEY_FS_HANDLE] = triplet->fs_handle,
131
        [KEY_DEV_HANDLE] = triplet->dev_handle,
133
        [KEY_DEV_HANDLE] = triplet->dev_handle,
132
        [KEY_INDEX] = triplet->index
134
        [KEY_INDEX] = triplet->index
Line 144... Line 146...
144
        }
146
        }
145
        memset(node, 0, sizeof(vfs_node_t));
147
        memset(node, 0, sizeof(vfs_node_t));
146
        node->fs_handle = triplet->fs_handle;
148
        node->fs_handle = triplet->fs_handle;
147
        node->dev_handle = triplet->fs_handle;
149
        node->dev_handle = triplet->fs_handle;
148
        node->index = triplet->index;
150
        node->index = triplet->index;
-
 
151
        node->size = size;
149
        link_initialize(&node->nh_link);
152
        link_initialize(&node->nh_link);
150
        rwlock_initialize(&node->contents_rwlock);
153
        rwlock_initialize(&node->contents_rwlock);
151
        hash_table_insert(&nodes, key, &node->nh_link);
154
        hash_table_insert(&nodes, key, &node->nh_link);
152
    } else {
155
    } else {
153
        node = hash_table_get_instance(tmp, vfs_node_t, nh_link);  
156
        node = hash_table_get_instance(tmp, vfs_node_t, nh_link);  
154
    }
157
    }
-
 
158
 
-
 
159
    assert(node->size == size);
-
 
160
 
155
    _vfs_node_addref(node);
161
    _vfs_node_addref(node);
156
    futex_up(&nodes_futex);
162
    futex_up(&nodes_futex);
157
 
163
 
158
    return node;
164
    return node;
159
}
165
}