Subversion Repositories HelenOS

Rev

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

Rev 2687 Rev 2691
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2007 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:
Line 119... Line 119...
119
 * table. In case the triplet is not found there, a new VFS node is created.
119
 * table. In case the triplet is not found there, a new VFS node is created.
120
 * 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
121
 * 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
122
 * vfs_node_put() on it.
122
 * vfs_node_put() on it.
123
 *
123
 *
124
 * @param triplet   Triplet encoding the identity of the VFS node.
124
 * @param result    Populated lookup result structure.
125
 * @param size      Size of the node as filled by vfs_lookup_internal().
-
 
126
 *
125
 *
127
 * @return      VFS node corresponding to the given triplet.
126
 * @return      VFS node corresponding to the given triplet.
128
 */
127
 */
129
vfs_node_t *vfs_node_get(vfs_triplet_t *triplet, size_t size)
128
vfs_node_t *vfs_node_get(vfs_lookup_res_t *result)
130
{
129
{
131
    unsigned long key[] = {
130
    unsigned long key[] = {
132
        [KEY_FS_HANDLE] = triplet->fs_handle,
131
        [KEY_FS_HANDLE] = result->triplet.fs_handle,
133
        [KEY_DEV_HANDLE] = triplet->dev_handle,
132
        [KEY_DEV_HANDLE] = result->triplet.dev_handle,
134
        [KEY_INDEX] = triplet->index
133
        [KEY_INDEX] = result->triplet.index
135
    };
134
    };
136
    link_t *tmp;
135
    link_t *tmp;
137
    vfs_node_t *node;
136
    vfs_node_t *node;
138
 
137
 
139
    futex_down(&nodes_futex);
138
    futex_down(&nodes_futex);
Line 143... Line 142...
143
        if (!node) {
142
        if (!node) {
144
            futex_up(&nodes_futex);
143
            futex_up(&nodes_futex);
145
            return NULL;
144
            return NULL;
146
        }
145
        }
147
        memset(node, 0, sizeof(vfs_node_t));
146
        memset(node, 0, sizeof(vfs_node_t));
148
        node->fs_handle = triplet->fs_handle;
147
        node->fs_handle = result->triplet.fs_handle;
149
        node->dev_handle = triplet->fs_handle;
148
        node->dev_handle = result->triplet.fs_handle;
150
        node->index = triplet->index;
149
        node->index = result->triplet.index;
151
        node->size = size;
150
        node->size = result->size;
152
        link_initialize(&node->nh_link);
151
        link_initialize(&node->nh_link);
153
        rwlock_initialize(&node->contents_rwlock);
152
        rwlock_initialize(&node->contents_rwlock);
154
        hash_table_insert(&nodes, key, &node->nh_link);
153
        hash_table_insert(&nodes, key, &node->nh_link);
155
    } else {
154
    } else {
156
        node = hash_table_get_instance(tmp, vfs_node_t, nh_link);  
155
        node = hash_table_get_instance(tmp, vfs_node_t, nh_link);  
157
    }
156
    }
158
 
157
 
159
    assert(node->size == size);
158
    assert(node->size == result->size);
160
 
159
 
161
    _vfs_node_addref(node);
160
    _vfs_node_addref(node);
162
    futex_up(&nodes_futex);
161
    futex_up(&nodes_futex);
163
 
162
 
164
    return node;
163
    return node;