Subversion Repositories HelenOS

Rev

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

Rev 4305 Rev 4306
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    tmpfs_ops.c
34
 * @file    tmpfs_ops.c
35
 * @brief   Implementation of VFS operations for the TMPFS file system
35
 * @brief   Implementation of VFS operations for the TMPFS file system
36
 *      server.
36
 *      server.
37
 */
37
 */
38
 
38
 
39
#include "tmpfs.h"
39
#include "tmpfs.h"
40
#include "../../vfs/vfs.h"
40
#include "../../vfs/vfs.h"
41
#include <ipc/ipc.h>
41
#include <ipc/ipc.h>
42
#include <async.h>
42
#include <async.h>
43
#include <errno.h>
43
#include <errno.h>
44
#include <atomic.h>
44
#include <atomic.h>
45
#include <stdlib.h>
45
#include <stdlib.h>
46
#include <string.h>
46
#include <string.h>
47
#include <stdio.h>
47
#include <stdio.h>
48
#include <assert.h>
48
#include <assert.h>
49
#include <sys/types.h>
49
#include <sys/types.h>
50
#include <libadt/hash_table.h>
50
#include <libadt/hash_table.h>
51
#include <as.h>
51
#include <as.h>
52
#include <libfs.h>
52
#include <libfs.h>
53
 
53
 
54
#define min(a, b)       ((a) < (b) ? (a) : (b))
54
#define min(a, b)       ((a) < (b) ? (a) : (b))
55
#define max(a, b)       ((a) > (b) ? (a) : (b))
55
#define max(a, b)       ((a) > (b) ? (a) : (b))
56
 
56
 
57
#define DENTRIES_BUCKETS    256
57
#define DENTRIES_BUCKETS    256
58
 
58
 
59
#define NAMES_BUCKETS       4
59
#define NAMES_BUCKETS       4
60
 
60
 
61
/*
-
 
62
 * For now, we don't distinguish between different dev_handles/instances. All
61
/** All root nodes have index 0. */
-
 
62
#define TMPFS_SOME_ROOT     0
63
 * requests resolve to the only instance, rooted in the following variable.
63
/** Global counter for assigning node indices. Shared by all instances. */
64
 */
-
 
65
static tmpfs_dentry_t *root;
64
fs_index_t tmpfs_next_index = 1;
66
 
-
 
67
#define TMPFS_DEV       0   /**< Dummy device handle for TMPFS */
-
 
68
 
65
 
69
/*
66
/*
70
 * Implementation of the libfs interface.
67
 * Implementation of the libfs interface.
71
 */
68
 */
72
 
69
 
73
/* Forward declarations of static functions. */
70
/* Forward declarations of static functions. */
74
static void *tmpfs_match(void *, const char *);
71
static void *tmpfs_match(void *, const char *);
75
static void *tmpfs_node_get(dev_handle_t, fs_index_t);
72
static void *tmpfs_node_get(dev_handle_t, fs_index_t);
76
static void tmpfs_node_put(void *);
73
static void tmpfs_node_put(void *);
77
static void *tmpfs_create_node(dev_handle_t, int);
74
static void *tmpfs_create_node(dev_handle_t, int);
78
static int tmpfs_link_node(void *, void *, const char *);
75
static int tmpfs_link_node(void *, void *, const char *);
79
static int tmpfs_unlink_node(void *, void *);
76
static int tmpfs_unlink_node(void *, void *);
80
static int tmpfs_destroy_node(void *);
77
static int tmpfs_destroy_node(void *);
81
 
78
 
82
/* Implementation of helper functions. */
79
/* Implementation of helper functions. */
83
static fs_index_t tmpfs_index_get(void *nodep)
80
static fs_index_t tmpfs_index_get(void *nodep)
84
{
81
{
85
    return ((tmpfs_dentry_t *) nodep)->index;
82
    return ((tmpfs_dentry_t *) nodep)->index;
86
}
83
}
87
 
84
 
88
static size_t tmpfs_size_get(void *nodep)
85
static size_t tmpfs_size_get(void *nodep)
89
{
86
{
90
    return ((tmpfs_dentry_t *) nodep)->size;
87
    return ((tmpfs_dentry_t *) nodep)->size;
91
}
88
}
92
 
89
 
93
static unsigned tmpfs_lnkcnt_get(void *nodep)
90
static unsigned tmpfs_lnkcnt_get(void *nodep)
94
{
91
{
95
    return ((tmpfs_dentry_t *) nodep)->lnkcnt;
92
    return ((tmpfs_dentry_t *) nodep)->lnkcnt;
96
}
93
}
97
 
94
 
98
static bool tmpfs_has_children(void *nodep)
95
static bool tmpfs_has_children(void *nodep)
99
{
96
{
100
    return ((tmpfs_dentry_t *) nodep)->child != NULL;
97
    return ((tmpfs_dentry_t *) nodep)->child != NULL;
101
}
98
}
102
 
99
 
103
static void *tmpfs_root_get(dev_handle_t dev_handle)
100
static void *tmpfs_root_get(dev_handle_t dev_handle)
104
{
101
{
105
    return root;
102
    return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT);
106
}
103
}
107
 
104
 
108
static char tmpfs_plb_get_char(unsigned pos)
105
static char tmpfs_plb_get_char(unsigned pos)
109
{
106
{
110
    return tmpfs_reg.plb_ro[pos % PLB_SIZE];
107
    return tmpfs_reg.plb_ro[pos % PLB_SIZE];
111
}
108
}
112
 
109
 
113
static bool tmpfs_is_directory(void *nodep)
110
static bool tmpfs_is_directory(void *nodep)
114
{
111
{
115
    return ((tmpfs_dentry_t *) nodep)->type == TMPFS_DIRECTORY;
112
    return ((tmpfs_dentry_t *) nodep)->type == TMPFS_DIRECTORY;
116
}
113
}
117
 
114
 
118
static bool tmpfs_is_file(void *nodep)
115
static bool tmpfs_is_file(void *nodep)
119
{
116
{
120
    return ((tmpfs_dentry_t *) nodep)->type == TMPFS_FILE;
117
    return ((tmpfs_dentry_t *) nodep)->type == TMPFS_FILE;
121
}
118
}
122
 
119
 
123
/** libfs operations */
120
/** libfs operations */
124
libfs_ops_t tmpfs_libfs_ops = {
121
libfs_ops_t tmpfs_libfs_ops = {
125
    .match = tmpfs_match,
122
    .match = tmpfs_match,
126
    .node_get = tmpfs_node_get,
123
    .node_get = tmpfs_node_get,
127
    .node_put = tmpfs_node_put,
124
    .node_put = tmpfs_node_put,
128
    .create = tmpfs_create_node,
125
    .create = tmpfs_create_node,
129
    .destroy = tmpfs_destroy_node,
126
    .destroy = tmpfs_destroy_node,
130
    .link = tmpfs_link_node,
127
    .link = tmpfs_link_node,
131
    .unlink = tmpfs_unlink_node,
128
    .unlink = tmpfs_unlink_node,
132
    .index_get = tmpfs_index_get,
129
    .index_get = tmpfs_index_get,
133
    .size_get = tmpfs_size_get,
130
    .size_get = tmpfs_size_get,
134
    .lnkcnt_get = tmpfs_lnkcnt_get,
131
    .lnkcnt_get = tmpfs_lnkcnt_get,
135
    .has_children = tmpfs_has_children,
132
    .has_children = tmpfs_has_children,
136
    .root_get = tmpfs_root_get,
133
    .root_get = tmpfs_root_get,
137
    .plb_get_char = tmpfs_plb_get_char,
134
    .plb_get_char = tmpfs_plb_get_char,
138
    .is_directory = tmpfs_is_directory,
135
    .is_directory = tmpfs_is_directory,
139
    .is_file = tmpfs_is_file
136
    .is_file = tmpfs_is_file
140
};
137
};
141
 
138
 
142
/** Hash table of all directory entries. */
139
/** Hash table of all directory entries. */
143
hash_table_t dentries;
140
hash_table_t dentries;
144
 
141
 
-
 
142
#define DENTRIES_KEY_INDEX  0
-
 
143
#define DENTRIES_KEY_DEV    1
-
 
144
 
145
/* Implementation of hash table interface for the dentries hash table. */
145
/* Implementation of hash table interface for the dentries hash table. */
146
static hash_index_t dentries_hash(unsigned long *key)
146
static hash_index_t dentries_hash(unsigned long key[])
147
{
147
{
148
    return *key % DENTRIES_BUCKETS;
148
    return key[DENTRIES_KEY_INDEX] % DENTRIES_BUCKETS;
149
}
149
}
150
 
150
 
151
static int dentries_compare(unsigned long *key, hash_count_t keys,
151
static int dentries_compare(unsigned long key[], hash_count_t keys,
152
    link_t *item)
152
    link_t *item)
153
{
153
{
154
    tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t,
154
    tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t,
155
        dh_link);
155
        dh_link);
156
    return dentry->index == *key;
156
    return (dentry->index == key[DENTRIES_KEY_INDEX] &&
-
 
157
        dentry->dev_handle == key[DENTRIES_KEY_DEV]);
157
}
158
}
158
 
159
 
159
static void dentries_remove_callback(link_t *item)
160
static void dentries_remove_callback(link_t *item)
160
{
161
{
161
}
162
}
162
 
163
 
163
/** TMPFS dentries hash table operations. */
164
/** TMPFS dentries hash table operations. */
164
hash_table_operations_t dentries_ops = {
165
hash_table_operations_t dentries_ops = {
165
    .hash = dentries_hash,
166
    .hash = dentries_hash,
166
    .compare = dentries_compare,
167
    .compare = dentries_compare,
167
    .remove_callback = dentries_remove_callback
168
    .remove_callback = dentries_remove_callback
168
};
169
};
169
 
170
 
170
fs_index_t tmpfs_next_index = 1;
-
 
171
 
-
 
172
typedef struct {
171
typedef struct {
173
    char *name;
172
    char *name;
174
    tmpfs_dentry_t *parent;
173
    tmpfs_dentry_t *parent;
175
    link_t link;
174
    link_t link;
176
} tmpfs_name_t;
175
} tmpfs_name_t;
177
 
176
 
178
/* Implementation of hash table interface for the names hash table. */
177
/* Implementation of hash table interface for the names hash table. */
179
static hash_index_t names_hash(unsigned long *key)
178
static hash_index_t names_hash(unsigned long *key)
180
{
179
{
181
    tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
180
    tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
182
    return dentry->index % NAMES_BUCKETS;
181
    return dentry->index % NAMES_BUCKETS;
183
}
182
}
184
 
183
 
185
static int names_compare(unsigned long *key, hash_count_t keys, link_t *item)
184
static int names_compare(unsigned long *key, hash_count_t keys, link_t *item)
186
{
185
{
187
    tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
186
    tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
188
    tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
187
    tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
189
        link);
188
        link);
190
    return dentry == namep->parent;
189
    return dentry == namep->parent;
191
}
190
}
192
 
191
 
193
static void names_remove_callback(link_t *item)
192
static void names_remove_callback(link_t *item)
194
{
193
{
195
    tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
194
    tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
196
        link);
195
        link);
197
    free(namep->name);
196
    free(namep->name);
198
    free(namep);
197
    free(namep);
199
}
198
}
200
 
199
 
201
/** TMPFS node names hash table operations. */
200
/** TMPFS node names hash table operations. */
202
static hash_table_operations_t names_ops = {
201
static hash_table_operations_t names_ops = {
203
    .hash = names_hash,
202
    .hash = names_hash,
204
    .compare = names_compare,
203
    .compare = names_compare,
205
    .remove_callback = names_remove_callback
204
    .remove_callback = names_remove_callback
206
};
205
};
207
 
206
 
208
static void tmpfs_name_initialize(tmpfs_name_t *namep)
207
static void tmpfs_name_initialize(tmpfs_name_t *namep)
209
{
208
{
210
    namep->name = NULL;
209
    namep->name = NULL;
211
    namep->parent = NULL;
210
    namep->parent = NULL;
212
    link_initialize(&namep->link);
211
    link_initialize(&namep->link);
213
}
212
}
214
 
213
 
215
static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry)
214
static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry)
216
{
215
{
217
    dentry->index = 0;
216
    dentry->index = 0;
-
 
217
    dentry->dev_handle = 0;
218
    dentry->sibling = NULL;
218
    dentry->sibling = NULL;
219
    dentry->child = NULL;
219
    dentry->child = NULL;
220
    dentry->type = TMPFS_NONE;
220
    dentry->type = TMPFS_NONE;
221
    dentry->lnkcnt = 0;
221
    dentry->lnkcnt = 0;
222
    dentry->size = 0;
222
    dentry->size = 0;
223
    dentry->data = NULL;
223
    dentry->data = NULL;
224
    link_initialize(&dentry->dh_link);
224
    link_initialize(&dentry->dh_link);
225
    return (bool)hash_table_create(&dentry->names, NAMES_BUCKETS, 1,
225
    return (bool)hash_table_create(&dentry->names, NAMES_BUCKETS, 1,
226
        &names_ops);
226
        &names_ops);
227
}
227
}
228
 
228
 
229
static bool tmpfs_init(void)
229
bool tmpfs_init(void)
230
{
230
{
231
    if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops))
231
    if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 2, &dentries_ops))
232
        return false;
232
        return false;
-
 
233
   
-
 
234
    return true;
-
 
235
}
-
 
236
 
-
 
237
static bool tmpfs_instance_init(dev_handle_t dev_handle)
-
 
238
{
-
 
239
    tmpfs_dentry_t *root;
-
 
240
   
233
    root = (tmpfs_dentry_t *) tmpfs_create_node(TMPFS_DEV, L_DIRECTORY);
241
    root = (tmpfs_dentry_t *) tmpfs_create_node(dev_handle, L_DIRECTORY);
234
    if (!root) {
242
    if (!root)
235
        hash_table_destroy(&dentries);
-
 
236
        return false;
243
        return false;
237
    }
-
 
238
    root->lnkcnt = 0;   /* FS root is not linked */
244
    root->lnkcnt = 0;   /* FS root is not linked */
239
    return true;
245
    return true;
240
}
246
}
241
 
247
 
242
/** Compare one component of path to a directory entry.
248
/** Compare one component of path to a directory entry.
243
 *
249
 *
244
 * @param parentp   Pointer to node from which we descended.
250
 * @param parentp   Pointer to node from which we descended.
245
 * @param childp    Pointer to node to compare the path component with.
251
 * @param childp    Pointer to node to compare the path component with.
246
 * @param component Array of characters holding component name.
252
 * @param component Array of characters holding component name.
247
 *
253
 *
248
 * @return      True on match, false otherwise.
254
 * @return      True on match, false otherwise.
249
 */
255
 */
250
static bool
256
static bool
251
tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp,
257
tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp,
252
    const char *component)
258
    const char *component)
253
{
259
{
254
    unsigned long key = (unsigned long) parentp;
260
    unsigned long key = (unsigned long) parentp;
255
    link_t *hlp = hash_table_find(&childp->names, &key);
261
    link_t *hlp = hash_table_find(&childp->names, &key);
256
    assert(hlp);
262
    assert(hlp);
257
    tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);
263
    tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);
258
    return !str_cmp(namep->name, component);
264
    return !str_cmp(namep->name, component);
259
}
265
}
260
 
266
 
261
void *tmpfs_match(void *prnt, const char *component)
267
void *tmpfs_match(void *prnt, const char *component)
262
{
268
{
263
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
269
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
264
    tmpfs_dentry_t *childp = parentp->child;
270
    tmpfs_dentry_t *childp = parentp->child;
265
 
271
 
266
    while (childp && !tmpfs_match_one(parentp, childp, component))
272
    while (childp && !tmpfs_match_one(parentp, childp, component))
267
        childp = childp->sibling;
273
        childp = childp->sibling;
268
 
274
 
269
    return (void *) childp;
275
    return (void *) childp;
270
}
276
}
271
 
277
 
272
void *
278
void *
273
tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
279
tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
274
{
280
{
275
    unsigned long key = index;
281
    unsigned long key[] = {
-
 
282
        [DENTRIES_KEY_INDEX] = index,
-
 
283
        [DENTRIES_KEY_DEV] = dev_handle
-
 
284
    };
276
    link_t *lnk = hash_table_find(&dentries, &key);
285
    link_t *lnk = hash_table_find(&dentries, key);
277
    if (!lnk)
286
    if (!lnk)
278
        return NULL;
287
        return NULL;
279
    return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link);
288
    return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link);
280
}
289
}
281
 
290
 
282
void tmpfs_node_put(void *node)
291
void tmpfs_node_put(void *node)
283
{
292
{
284
    /* nothing to do */
293
    /* nothing to do */
285
}
294
}
286
 
295
 
287
void *tmpfs_create_node(dev_handle_t dev_handle, int lflag)
296
void *tmpfs_create_node(dev_handle_t dev_handle, int lflag)
288
{
297
{
289
    assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
298
    assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
290
 
299
 
291
    tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
300
    tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
292
    if (!node)
301
    if (!node)
293
        return NULL;
302
        return NULL;
294
 
303
 
295
    if (!tmpfs_dentry_initialize(node)) {
304
    if (!tmpfs_dentry_initialize(node)) {
296
        free(node);
305
        free(node);
297
        return NULL;
306
        return NULL;
298
    }
307
    }
-
 
308
    if (!tmpfs_root_get(dev_handle))
-
 
309
        node->index = TMPFS_SOME_ROOT;
-
 
310
    else
299
    node->index = tmpfs_next_index++;
311
        node->index = tmpfs_next_index++;
-
 
312
    node->dev_handle = dev_handle;
300
    if (lflag & L_DIRECTORY)
313
    if (lflag & L_DIRECTORY)
301
        node->type = TMPFS_DIRECTORY;
314
        node->type = TMPFS_DIRECTORY;
302
    else
315
    else
303
        node->type = TMPFS_FILE;
316
        node->type = TMPFS_FILE;
304
 
317
 
305
    /* Insert the new node into the dentry hash table. */
318
    /* Insert the new node into the dentry hash table. */
306
    unsigned long key = node->index;
319
    unsigned long key[] = {
-
 
320
        [DENTRIES_KEY_INDEX] = node->index,
-
 
321
        [DENTRIES_KEY_DEV] = node->dev_handle
-
 
322
    };
307
    hash_table_insert(&dentries, &key, &node->dh_link);
323
    hash_table_insert(&dentries, key, &node->dh_link);
308
    return (void *) node;
324
    return (void *) node;
309
}
325
}
310
 
326
 
311
int tmpfs_link_node(void *prnt, void *chld, const char *nm)
327
int tmpfs_link_node(void *prnt, void *chld, const char *nm)
312
{
328
{
313
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
329
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
314
    tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
330
    tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
315
 
331
 
316
    assert(parentp->type == TMPFS_DIRECTORY);
332
    assert(parentp->type == TMPFS_DIRECTORY);
317
 
333
 
318
    tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t));
334
    tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t));
319
    if (!namep)
335
    if (!namep)
320
        return ENOMEM;
336
        return ENOMEM;
321
    tmpfs_name_initialize(namep);
337
    tmpfs_name_initialize(namep);
322
    size_t size = str_size(nm);
338
    size_t size = str_size(nm);
323
    namep->name = malloc(size + 1);
339
    namep->name = malloc(size + 1);
324
    if (!namep->name) {
340
    if (!namep->name) {
325
        free(namep);
341
        free(namep);
326
        return ENOMEM;
342
        return ENOMEM;
327
    }
343
    }
328
    str_cpy(namep->name, size + 1, nm);
344
    str_cpy(namep->name, size + 1, nm);
329
    namep->parent = parentp;
345
    namep->parent = parentp;
330
   
346
   
331
    childp->lnkcnt++;
347
    childp->lnkcnt++;
332
 
348
 
333
    unsigned long key = (unsigned long) parentp;
349
    unsigned long key = (unsigned long) parentp;
334
    hash_table_insert(&childp->names, &key, &namep->link);
350
    hash_table_insert(&childp->names, &key, &namep->link);
335
 
351
 
336
    /* Insert the new node into the namespace. */
352
    /* Insert the new node into the namespace. */
337
    if (parentp->child) {
353
    if (parentp->child) {
338
        tmpfs_dentry_t *tmp = parentp->child;
354
        tmpfs_dentry_t *tmp = parentp->child;
339
        while (tmp->sibling)
355
        while (tmp->sibling)
340
            tmp = tmp->sibling;
356
            tmp = tmp->sibling;
341
        tmp->sibling = childp;
357
        tmp->sibling = childp;
342
    } else {
358
    } else {
343
        parentp->child = childp;
359
        parentp->child = childp;
344
    }
360
    }
345
 
361
 
346
    return EOK;
362
    return EOK;
347
}
363
}
348
 
364
 
349
int tmpfs_unlink_node(void *prnt, void *chld)
365
int tmpfs_unlink_node(void *prnt, void *chld)
350
{
366
{
351
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;
367
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;
352
    tmpfs_dentry_t *childp = (tmpfs_dentry_t *)chld;
368
    tmpfs_dentry_t *childp = (tmpfs_dentry_t *)chld;
353
 
369
 
354
    if (!parentp)
370
    if (!parentp)
355
        return EBUSY;
371
        return EBUSY;
356
 
372
 
357
    if (childp->child)
373
    if (childp->child)
358
        return ENOTEMPTY;
374
        return ENOTEMPTY;
359
 
375
 
360
    if (parentp->child == childp) {
376
    if (parentp->child == childp) {
361
        parentp->child = childp->sibling;
377
        parentp->child = childp->sibling;
362
    } else {
378
    } else {
363
        /* TODO: consider doubly linked list for organizing siblings. */
379
        /* TODO: consider doubly linked list for organizing siblings. */
364
        tmpfs_dentry_t *tmp = parentp->child;
380
        tmpfs_dentry_t *tmp = parentp->child;
365
        while (tmp->sibling != childp)
381
        while (tmp->sibling != childp)
366
            tmp = tmp->sibling;
382
            tmp = tmp->sibling;
367
        tmp->sibling = childp->sibling;
383
        tmp->sibling = childp->sibling;
368
    }
384
    }
369
    childp->sibling = NULL;
385
    childp->sibling = NULL;
370
 
386
 
371
    unsigned long key = (unsigned long) parentp;
387
    unsigned long key = (unsigned long) parentp;
372
    hash_table_remove(&childp->names, &key, 1);
388
    hash_table_remove(&childp->names, &key, 1);
373
 
389
 
374
    childp->lnkcnt--;
390
    childp->lnkcnt--;
375
 
391
 
376
    return EOK;
392
    return EOK;
377
}
393
}
378
 
394
 
379
int tmpfs_destroy_node(void *nodep)
395
int tmpfs_destroy_node(void *nodep)
380
{
396
{
381
    tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;
397
    tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;
382
   
398
   
383
    assert(!dentry->lnkcnt);
399
    assert(!dentry->lnkcnt);
384
    assert(!dentry->child);
400
    assert(!dentry->child);
385
    assert(!dentry->sibling);
401
    assert(!dentry->sibling);
386
 
402
 
387
    unsigned long key = dentry->index;
403
    unsigned long key[] = {
-
 
404
        [DENTRIES_KEY_INDEX] = dentry->index,
-
 
405
        [DENTRIES_KEY_DEV] = dentry->dev_handle
-
 
406
    };
388
    hash_table_remove(&dentries, &key, 1);
407
    hash_table_remove(&dentries, key, 2);
389
 
408
 
390
    hash_table_destroy(&dentry->names);
409
    hash_table_destroy(&dentry->names);
391
 
410
 
392
    if (dentry->type == TMPFS_FILE)
411
    if (dentry->type == TMPFS_FILE)
393
        free(dentry->data);
412
        free(dentry->data);
394
    free(dentry);
413
    free(dentry);
395
    return EOK;
414
    return EOK;
396
}
415
}
397
 
416
 
398
void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
417
void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
399
{
418
{
400
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
419
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
401
 
420
 
402
    /* accept the mount options */
421
    /* accept the mount options */
403
    ipc_callid_t callid;
422
    ipc_callid_t callid;
404
    size_t size;
423
    size_t size;
405
    if (!ipc_data_write_receive(&callid, &size)) {
424
    if (!ipc_data_write_receive(&callid, &size)) {
406
        ipc_answer_0(callid, EINVAL);
425
        ipc_answer_0(callid, EINVAL);
407
        ipc_answer_0(rid, EINVAL);
426
        ipc_answer_0(rid, EINVAL);
408
        return;
427
        return;
409
    }
428
    }
410
    char *opts = malloc(size + 1);
429
    char *opts = malloc(size + 1);
411
    if (!opts) {
430
    if (!opts) {
412
        ipc_answer_0(callid, ENOMEM);
431
        ipc_answer_0(callid, ENOMEM);
413
        ipc_answer_0(rid, ENOMEM);
432
        ipc_answer_0(rid, ENOMEM);
414
        return;
433
        return;
415
    }
434
    }
416
    ipcarg_t retval = ipc_data_write_finalize(callid, opts, size);
435
    ipcarg_t retval = ipc_data_write_finalize(callid, opts, size);
417
    if (retval != EOK) {
436
    if (retval != EOK) {
418
        ipc_answer_0(rid, retval);
437
        ipc_answer_0(rid, retval);
419
        free(opts);
438
        free(opts);
420
        return;
439
        return;
421
    }
440
    }
422
    opts[size] = '\0';
441
    opts[size] = '\0';
423
 
442
 
424
    /* Initialize TMPFS. */
443
    /* Initialize TMPFS instance. */
425
    if (!root && !tmpfs_init()) {
444
    if (!tmpfs_instance_init(dev_handle)) {
426
        ipc_answer_0(rid, ENOMEM);
445
        ipc_answer_0(rid, ENOMEM);
427
        return;
446
        return;
428
    }
447
    }
429
 
448
 
-
 
449
    tmpfs_dentry_t *root = tmpfs_root_get(dev_handle);
430
    if (str_cmp(opts, "restore") == 0) {
450
    if (str_cmp(opts, "restore") == 0) {
431
        if (tmpfs_restore(dev_handle))
451
        if (tmpfs_restore(dev_handle))
432
            ipc_answer_3(rid, EOK, root->index, root->size,
452
            ipc_answer_3(rid, EOK, root->index, root->size,
433
                root->lnkcnt);
453
                root->lnkcnt);
434
        else
454
        else
435
            ipc_answer_0(rid, ELIMIT);
455
            ipc_answer_0(rid, ELIMIT);
436
    } else {
456
    } else {
437
        ipc_answer_3(rid, EOK, root->index, root->size, root->lnkcnt);
457
        ipc_answer_3(rid, EOK, root->index, root->size, root->lnkcnt);
438
    }
458
    }
439
}
459
}
440
 
460
 
441
void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
461
void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
442
{
462
{
443
    dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
463
    dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
444
    fs_index_t mp_index = (fs_index_t) IPC_GET_ARG2(*request);
464
    fs_index_t mp_index = (fs_index_t) IPC_GET_ARG2(*request);
445
    fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request);
465
    fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request);
446
    dev_handle_t mr_dev_handle = (dev_handle_t) IPC_GET_ARG4(*request);
466
    dev_handle_t mr_dev_handle = (dev_handle_t) IPC_GET_ARG4(*request);
447
   
467
   
448
    ipc_answer_0(rid, ENOTSUP);
468
    ipc_answer_0(rid, ENOTSUP);
449
}
469
}
450
 
470
 
451
void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request)
471
void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request)
452
{
472
{
453
    libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
473
    libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
454
}
474
}
455
 
475
 
456
void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
476
void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
457
{
477
{
458
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
478
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
459
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
479
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
460
    off_t pos = (off_t)IPC_GET_ARG3(*request);
480
    off_t pos = (off_t)IPC_GET_ARG3(*request);
461
 
481
 
462
    /*
482
    /*
463
     * Lookup the respective dentry.
483
     * Lookup the respective dentry.
464
     */
484
     */
465
    link_t *hlp;
485
    link_t *hlp;
466
    unsigned long key = index;
486
    unsigned long key[] = {
-
 
487
        [DENTRIES_KEY_INDEX] = index,
-
 
488
        [DENTRIES_KEY_DEV] = dev_handle,
-
 
489
    };
467
    hlp = hash_table_find(&dentries, &key);
490
    hlp = hash_table_find(&dentries, key);
468
    if (!hlp) {
491
    if (!hlp) {
469
        ipc_answer_0(rid, ENOENT);
492
        ipc_answer_0(rid, ENOENT);
470
        return;
493
        return;
471
    }
494
    }
472
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
495
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
473
        dh_link);
496
        dh_link);
474
 
497
 
475
    /*
498
    /*
476
     * Receive the read request.
499
     * Receive the read request.
477
     */
500
     */
478
    ipc_callid_t callid;
501
    ipc_callid_t callid;
479
    size_t size;
502
    size_t size;
480
    if (!ipc_data_read_receive(&callid, &size)) {
503
    if (!ipc_data_read_receive(&callid, &size)) {
481
        ipc_answer_0(callid, EINVAL);  
504
        ipc_answer_0(callid, EINVAL);  
482
        ipc_answer_0(rid, EINVAL);
505
        ipc_answer_0(rid, EINVAL);
483
        return;
506
        return;
484
    }
507
    }
485
 
508
 
486
    size_t bytes;
509
    size_t bytes;
487
    if (dentry->type == TMPFS_FILE) {
510
    if (dentry->type == TMPFS_FILE) {
488
        bytes = max(0, min(dentry->size - pos, size));
511
        bytes = max(0, min(dentry->size - pos, size));
489
        (void) ipc_data_read_finalize(callid, dentry->data + pos,
512
        (void) ipc_data_read_finalize(callid, dentry->data + pos,
490
            bytes);
513
            bytes);
491
    } else {
514
    } else {
492
        int i;
515
        int i;
493
        tmpfs_dentry_t *cur;
516
        tmpfs_dentry_t *cur;
494
       
517
       
495
        assert(dentry->type == TMPFS_DIRECTORY);
518
        assert(dentry->type == TMPFS_DIRECTORY);
496
       
519
       
497
        /*
520
        /*
498
         * Yes, we really use O(n) algorithm here.
521
         * Yes, we really use O(n) algorithm here.
499
         * If it bothers someone, it could be fixed by introducing a
522
         * If it bothers someone, it could be fixed by introducing a
500
         * hash table.
523
         * hash table.
501
         */
524
         */
502
        for (i = 0, cur = dentry->child; i < pos && cur; i++,
525
        for (i = 0, cur = dentry->child; i < pos && cur; i++,
503
            cur = cur->sibling)
526
            cur = cur->sibling)
504
            ;
527
            ;
505
 
528
 
506
        if (!cur) {
529
        if (!cur) {
507
            ipc_answer_0(callid, ENOENT);
530
            ipc_answer_0(callid, ENOENT);
508
            ipc_answer_1(rid, ENOENT, 0);
531
            ipc_answer_1(rid, ENOENT, 0);
509
            return;
532
            return;
510
        }
533
        }
511
 
534
 
512
        unsigned long key = (unsigned long) dentry;
535
        unsigned long key = (unsigned long) dentry;
513
        link_t *hlp = hash_table_find(&cur->names, &key);
536
        link_t *hlp = hash_table_find(&cur->names, &key);
514
        assert(hlp);
537
        assert(hlp);
515
        tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t,
538
        tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t,
516
            link);
539
            link);
517
 
540
 
518
        (void) ipc_data_read_finalize(callid, namep->name,
541
        (void) ipc_data_read_finalize(callid, namep->name,
519
            str_size(namep->name) + 1);
542
            str_size(namep->name) + 1);
520
        bytes = 1;
543
        bytes = 1;
521
    }
544
    }
522
 
545
 
523
    /*
546
    /*
524
     * Answer the VFS_READ call.
547
     * Answer the VFS_READ call.
525
     */
548
     */
526
    ipc_answer_1(rid, EOK, bytes);
549
    ipc_answer_1(rid, EOK, bytes);
527
}
550
}
528
 
551
 
529
void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
552
void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
530
{
553
{
531
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
554
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
532
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
555
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
533
    off_t pos = (off_t)IPC_GET_ARG3(*request);
556
    off_t pos = (off_t)IPC_GET_ARG3(*request);
534
 
557
 
535
    /*
558
    /*
536
     * Lookup the respective dentry.
559
     * Lookup the respective dentry.
537
     */
560
     */
538
    link_t *hlp;
561
    link_t *hlp;
539
    unsigned long key = index;
562
    unsigned long key[] = {
-
 
563
        [DENTRIES_KEY_INDEX] = index,
-
 
564
        [DENTRIES_KEY_DEV] = dev_handle
-
 
565
    };
540
    hlp = hash_table_find(&dentries, &key);
566
    hlp = hash_table_find(&dentries, key);
541
    if (!hlp) {
567
    if (!hlp) {
542
        ipc_answer_0(rid, ENOENT);
568
        ipc_answer_0(rid, ENOENT);
543
        return;
569
        return;
544
    }
570
    }
545
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
571
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
546
        dh_link);
572
        dh_link);
547
 
573
 
548
    /*
574
    /*
549
     * Receive the write request.
575
     * Receive the write request.
550
     */
576
     */
551
    ipc_callid_t callid;
577
    ipc_callid_t callid;
552
    size_t size;
578
    size_t size;
553
    if (!ipc_data_write_receive(&callid, &size)) {
579
    if (!ipc_data_write_receive(&callid, &size)) {
554
        ipc_answer_0(callid, EINVAL);  
580
        ipc_answer_0(callid, EINVAL);  
555
        ipc_answer_0(rid, EINVAL);
581
        ipc_answer_0(rid, EINVAL);
556
        return;
582
        return;
557
    }
583
    }
558
 
584
 
559
    /*
585
    /*
560
     * Check whether the file needs to grow.
586
     * Check whether the file needs to grow.
561
     */
587
     */
562
    if (pos + size <= dentry->size) {
588
    if (pos + size <= dentry->size) {
563
        /* The file size is not changing. */
589
        /* The file size is not changing. */
564
        (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
590
        (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
565
        ipc_answer_2(rid, EOK, size, dentry->size);
591
        ipc_answer_2(rid, EOK, size, dentry->size);
566
        return;
592
        return;
567
    }
593
    }
568
    size_t delta = (pos + size) - dentry->size;
594
    size_t delta = (pos + size) - dentry->size;
569
    /*
595
    /*
570
     * At this point, we are deliberately extremely straightforward and
596
     * At this point, we are deliberately extremely straightforward and
571
     * simply realloc the contents of the file on every write that grows the
597
     * simply realloc the contents of the file on every write that grows the
572
     * file. In the end, the situation might not be as bad as it may look:
598
     * file. In the end, the situation might not be as bad as it may look:
573
     * our heap allocator can save us and just grow the block whenever
599
     * our heap allocator can save us and just grow the block whenever
574
     * possible.
600
     * possible.
575
     */
601
     */
576
    void *newdata = realloc(dentry->data, dentry->size + delta);
602
    void *newdata = realloc(dentry->data, dentry->size + delta);
577
    if (!newdata) {
603
    if (!newdata) {
578
        ipc_answer_0(callid, ENOMEM);
604
        ipc_answer_0(callid, ENOMEM);
579
        ipc_answer_2(rid, EOK, 0, dentry->size);
605
        ipc_answer_2(rid, EOK, 0, dentry->size);
580
        return;
606
        return;
581
    }
607
    }
582
    /* Clear any newly allocated memory in order to emulate gaps. */
608
    /* Clear any newly allocated memory in order to emulate gaps. */
583
    memset(newdata + dentry->size, 0, delta);
609
    memset(newdata + dentry->size, 0, delta);
584
    dentry->size += delta;
610
    dentry->size += delta;
585
    dentry->data = newdata;
611
    dentry->data = newdata;
586
    (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
612
    (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
587
    ipc_answer_2(rid, EOK, size, dentry->size);
613
    ipc_answer_2(rid, EOK, size, dentry->size);
588
}
614
}
589
 
615
 
590
void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
616
void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
591
{
617
{
592
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
618
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
593
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
619
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
594
    size_t size = (off_t)IPC_GET_ARG3(*request);
620
    size_t size = (off_t)IPC_GET_ARG3(*request);
595
 
621
 
596
    /*
622
    /*
597
     * Lookup the respective dentry.
623
     * Lookup the respective dentry.
598
     */
624
     */
599
    link_t *hlp;
625
    link_t *hlp;
600
    unsigned long key = index;
626
    unsigned long key[] = {
-
 
627
        [DENTRIES_KEY_INDEX] = index,
-
 
628
        [DENTRIES_KEY_DEV] = dev_handle
-
 
629
    };
601
    hlp = hash_table_find(&dentries, &key);
630
    hlp = hash_table_find(&dentries, key);
602
    if (!hlp) {
631
    if (!hlp) {
603
        ipc_answer_0(rid, ENOENT);
632
        ipc_answer_0(rid, ENOENT);
604
        return;
633
        return;
605
    }
634
    }
606
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
635
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
607
        dh_link);
636
        dh_link);
608
 
637
 
609
    if (size == dentry->size) {
638
    if (size == dentry->size) {
610
        ipc_answer_0(rid, EOK);
639
        ipc_answer_0(rid, EOK);
611
        return;
640
        return;
612
    }
641
    }
613
 
642
 
614
    void *newdata = realloc(dentry->data, size);
643
    void *newdata = realloc(dentry->data, size);
615
    if (!newdata) {
644
    if (!newdata) {
616
        ipc_answer_0(rid, ENOMEM);
645
        ipc_answer_0(rid, ENOMEM);
617
        return;
646
        return;
618
    }
647
    }
619
    if (size > dentry->size) {
648
    if (size > dentry->size) {
620
        size_t delta = size - dentry->size;
649
        size_t delta = size - dentry->size;
621
        memset(newdata + dentry->size, 0, delta);
650
        memset(newdata + dentry->size, 0, delta);
622
    }
651
    }
623
    dentry->size = size;
652
    dentry->size = size;
624
    dentry->data = newdata;
653
    dentry->data = newdata;
625
    ipc_answer_0(rid, EOK);
654
    ipc_answer_0(rid, EOK);
626
}
655
}
627
 
656
 
628
void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
657
void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
629
{
658
{
630
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
659
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
631
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
660
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
632
    int rc;
661
    int rc;
633
 
662
 
634
    link_t *hlp;
663
    link_t *hlp;
635
    unsigned long key = index;
664
    unsigned long key[] = {
-
 
665
        [DENTRIES_KEY_INDEX] = index,
-
 
666
        [DENTRIES_KEY_DEV] = dev_handle
-
 
667
    };
636
    hlp = hash_table_find(&dentries, &key);
668
    hlp = hash_table_find(&dentries, key);
637
    if (!hlp) {
669
    if (!hlp) {
638
        ipc_answer_0(rid, ENOENT);
670
        ipc_answer_0(rid, ENOENT);
639
        return;
671
        return;
640
    }
672
    }
641
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
673
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
642
        dh_link);
674
        dh_link);
643
    rc = tmpfs_destroy_node(dentry);
675
    rc = tmpfs_destroy_node(dentry);
644
    ipc_answer_0(rid, rc);
676
    ipc_answer_0(rid, rc);
645
}
677
}
646
 
678
 
647
/**
679
/**
648
 * @}
680
 * @}
649
 */
681
 */
650
 
682