Subversion Repositories HelenOS

Rev

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

Rev 3386 Rev 4153
Line 62... Line 62...
62
 * For now, we don't distinguish between different dev_handles/instances. All
62
 * For now, we don't distinguish between different dev_handles/instances. All
63
 * requests resolve to the only instance, rooted in the following variable.
63
 * requests resolve to the only instance, rooted in the following variable.
64
 */
64
 */
65
static tmpfs_dentry_t *root;
65
static tmpfs_dentry_t *root;
66
 
66
 
-
 
67
#define TMPFS_DEV       0   /**< Dummy device handle for TMPFS */
-
 
68
 
67
/*
69
/*
68
 * Implementation of the libfs interface.
70
 * Implementation of the libfs interface.
69
 */
71
 */
70
 
72
 
71
/* Forward declarations of static functions. */
73
/* Forward declarations of static functions. */
72
static void *tmpfs_match(void *, const char *);
74
static void *tmpfs_match(void *, const char *);
73
static void *tmpfs_node_get(dev_handle_t, fs_index_t);
75
static void *tmpfs_node_get(dev_handle_t, fs_index_t);
74
static void tmpfs_node_put(void *);
76
static void tmpfs_node_put(void *);
75
static void *tmpfs_create_node(int);
77
static void *tmpfs_create_node(dev_handle_t, int);
76
static bool tmpfs_link_node(void *, void *, const char *);
78
static int tmpfs_link_node(void *, void *, const char *);
77
static int tmpfs_unlink_node(void *, void *);
79
static int tmpfs_unlink_node(void *, void *);
78
static int tmpfs_destroy_node(void *);
80
static int tmpfs_destroy_node(void *);
79
 
81
 
80
/* Implementation of helper functions. */
82
/* Implementation of helper functions. */
81
static fs_index_t tmpfs_index_get(void *nodep)
83
static fs_index_t tmpfs_index_get(void *nodep)
Line 226... Line 228...
226
 
228
 
227
static bool tmpfs_init(void)
229
static bool tmpfs_init(void)
228
{
230
{
229
    if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops))
231
    if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops))
230
        return false;
232
        return false;
231
    root = (tmpfs_dentry_t *) tmpfs_create_node(L_DIRECTORY);
233
    root = (tmpfs_dentry_t *) tmpfs_create_node(TMPFS_DEV, L_DIRECTORY);
232
    if (!root) {
234
    if (!root) {
233
        hash_table_destroy(&dentries);
235
        hash_table_destroy(&dentries);
234
        return false;
236
        return false;
235
    }
237
    }
236
    root->lnkcnt = 0;   /* FS root is not linked */
238
    root->lnkcnt = 0;   /* FS root is not linked */
Line 280... Line 282...
280
void tmpfs_node_put(void *node)
282
void tmpfs_node_put(void *node)
281
{
283
{
282
    /* nothing to do */
284
    /* nothing to do */
283
}
285
}
284
 
286
 
285
void *tmpfs_create_node(int lflag)
287
void *tmpfs_create_node(dev_handle_t dev_handle, int lflag)
286
{
288
{
287
    assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
289
    assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
288
 
290
 
289
    tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
291
    tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
290
    if (!node)
292
    if (!node)
Line 304... Line 306...
304
    unsigned long key = node->index;
306
    unsigned long key = node->index;
305
    hash_table_insert(&dentries, &key, &node->dh_link);
307
    hash_table_insert(&dentries, &key, &node->dh_link);
306
    return (void *) node;
308
    return (void *) node;
307
}
309
}
308
 
310
 
309
bool tmpfs_link_node(void *prnt, void *chld, const char *nm)
311
int tmpfs_link_node(void *prnt, void *chld, const char *nm)
310
{
312
{
311
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
313
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
312
    tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
314
    tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
313
 
315
 
314
    assert(parentp->type == TMPFS_DIRECTORY);
316
    assert(parentp->type == TMPFS_DIRECTORY);
315
 
317
 
316
    tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t));
318
    tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t));
317
    if (!namep)
319
    if (!namep)
318
        return false;
320
        return ENOMEM;
319
    tmpfs_name_initialize(namep);
321
    tmpfs_name_initialize(namep);
320
    size_t len = strlen(nm);
322
    size_t len = strlen(nm);
321
    namep->name = malloc(len + 1);
323
    namep->name = malloc(len + 1);
322
    if (!namep->name) {
324
    if (!namep->name) {
323
        free(namep);
325
        free(namep);
324
        return false;
326
        return ENOMEM;
325
    }
327
    }
326
    strcpy(namep->name, nm);
328
    strcpy(namep->name, nm);
327
    namep->parent = parentp;
329
    namep->parent = parentp;
328
   
330
   
329
    childp->lnkcnt++;
331
    childp->lnkcnt++;
Line 339... Line 341...
339
        tmp->sibling = childp;
341
        tmp->sibling = childp;
340
    } else {
342
    } else {
341
        parentp->child = childp;
343
        parentp->child = childp;
342
    }
344
    }
343
 
345
 
344
    return true;
346
    return EOK;
345
}
347
}
346
 
348
 
347
int tmpfs_unlink_node(void *prnt, void *chld)
349
int tmpfs_unlink_node(void *prnt, void *chld)
348
{
350
{
349
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;
351
    tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;