Subversion Repositories HelenOS

Rev

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

Rev 3022 Rev 4055
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 = 1;
238
    root->lnkcnt = 0;   /* FS root is not linked */
237
    return true;
239
    return true;
238
}
240
}
239
 
241
 
240
/** Compare one component of path to a directory entry.
242
/** Compare one component of path to a directory entry.
241
 *
243
 *
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;
Line 391... Line 393...
391
        free(dentry->data);
393
        free(dentry->data);
392
    free(dentry);
394
    free(dentry);
393
    return EOK;
395
    return EOK;
394
}
396
}
395
 
397
 
396
void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
398
void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
397
{
399
{
398
    dev_handle_t mr_dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
400
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
399
    fs_index_t mr_index = (fs_index_t)IPC_GET_ARG2(*request);
-
 
400
    fs_handle_t mp_fs_handle = (fs_handle_t)IPC_GET_ARG3(*request);
-
 
401
    dev_handle_t mp_dev_handle = (dev_handle_t)IPC_GET_ARG4(*request);
-
 
402
    fs_index_t mp_index = (fs_index_t)IPC_GET_ARG5(*request);
-
 
403
    if ((mr_index == root->index) &&
-
 
404
        (mp_fs_handle == tmpfs_reg.fs_handle) &&
-
 
405
        (mp_index == mr_index))
-
 
406
        ipc_answer_0(rid, EOK);
-
 
407
    else
-
 
408
        ipc_answer_0(rid, ENOTSUP);
-
 
409
}
-
 
410
 
401
 
411
void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request)
-
 
412
{
-
 
413
    /* Initialize TMPFS. */
402
    /* Initialize TMPFS. */
414
    if (!root && !tmpfs_init()) {
403
    if (!root && !tmpfs_init()) {
415
        ipc_answer_0(rid, ENOMEM);
404
        ipc_answer_0(rid, ENOMEM);
416
        return;
405
        return;
417
    }
406
    }
-
 
407
 
-
 
408
    if (dev_handle >= 0) {
-
 
409
        if (tmpfs_restore(dev_handle))
-
 
410
            ipc_answer_3(rid, EOK, root->index, root->size,
-
 
411
                root->lnkcnt);
-
 
412
        else
-
 
413
            ipc_answer_0(rid, ELIMIT);
-
 
414
    } else {
-
 
415
        ipc_answer_3(rid, EOK, root->index, root->size, root->lnkcnt);
-
 
416
    }
-
 
417
}
-
 
418
 
-
 
419
void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
-
 
420
{
-
 
421
    dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
-
 
422
    fs_index_t mp_index = (fs_index_t) IPC_GET_ARG2(*request);
-
 
423
    fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request);
-
 
424
    dev_handle_t mr_dev_handle = (dev_handle_t) IPC_GET_ARG4(*request);
-
 
425
   
-
 
426
    ipc_answer_0(rid, ENOTSUP);
-
 
427
}
-
 
428
 
-
 
429
void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request)
-
 
430
{
418
    libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
431
    libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
419
}
432
}
420
 
433
 
421
void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
434
void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
422
{
435
{