Rev 2763 | Rev 2791 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2763 | Rev 2770 | ||
|---|---|---|---|
| Line 68... | Line 68... | ||
| 68 | * Implementation of the libfs interface. |
68 | * Implementation of the libfs interface. |
| 69 | */ |
69 | */ |
| 70 | 70 | ||
| 71 | /* Forward declarations of static functions. */ |
71 | /* Forward declarations of static functions. */ |
| 72 | static bool tmpfs_match(void *, void *, const char *); |
72 | static bool tmpfs_match(void *, void *, const char *); |
| 73 | static void *tmpfs_node_get(int, int, unsigned long); |
73 | static void *tmpfs_node_get(fs_handle_t, dev_handle_t, fs_index_t); |
| 74 | static void *tmpfs_create_node(int); |
74 | static void *tmpfs_create_node(int); |
| 75 | static bool tmpfs_link_node(void *, void *, const char *); |
75 | static bool tmpfs_link_node(void *, void *, const char *); |
| 76 | static int tmpfs_unlink_node(void *, void *); |
76 | static int tmpfs_unlink_node(void *, void *); |
| 77 | static void tmpfs_destroy_node(void *); |
77 | static void tmpfs_destroy_node(void *); |
| 78 | 78 | ||
| 79 | /* Implementation of helper functions. */ |
79 | /* Implementation of helper functions. */ |
| 80 | static unsigned long tmpfs_index_get(void *nodep) |
80 | static fs_index_t tmpfs_index_get(void *nodep) |
| 81 | { |
81 | { |
| 82 | return ((tmpfs_dentry_t *) nodep)->index; |
82 | return ((tmpfs_dentry_t *) nodep)->index; |
| 83 | } |
83 | } |
| 84 | 84 | ||
| 85 | static unsigned long tmpfs_size_get(void *nodep) |
85 | static size_t tmpfs_size_get(void *nodep) |
| 86 | { |
86 | { |
| 87 | return ((tmpfs_dentry_t *) nodep)->size; |
87 | return ((tmpfs_dentry_t *) nodep)->size; |
| 88 | } |
88 | } |
| 89 | 89 | ||
| 90 | static unsigned tmpfs_lnkcnt_get(void *nodep) |
90 | static unsigned tmpfs_lnkcnt_get(void *nodep) |
| Line 167... | Line 167... | ||
| 167 | .hash = dentries_hash, |
167 | .hash = dentries_hash, |
| 168 | .compare = dentries_compare, |
168 | .compare = dentries_compare, |
| 169 | .remove_callback = dentries_remove_callback |
169 | .remove_callback = dentries_remove_callback |
| 170 | }; |
170 | }; |
| 171 | 171 | ||
| 172 | unsigned tmpfs_next_index = 1; |
172 | fs_index_t tmpfs_next_index = 1; |
| 173 | 173 | ||
| 174 | typedef struct { |
174 | typedef struct { |
| 175 | char *name; |
175 | char *name; |
| 176 | tmpfs_dentry_t *parent; |
176 | tmpfs_dentry_t *parent; |
| 177 | link_t link; |
177 | link_t link; |
| Line 260... | Line 260... | ||
| 260 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
260 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
| 261 | 261 | ||
| 262 | return !strcmp(namep->name, component); |
262 | return !strcmp(namep->name, component); |
| 263 | } |
263 | } |
| 264 | 264 | ||
| - | 265 | void * |
|
| 265 | void *tmpfs_node_get(int fs_handle, int dev_handle, unsigned long index) |
266 | tmpfs_node_get(fs_handle_t fs_handle, dev_handle_t dev_handle, fs_index_t index) |
| 266 | { |
267 | { |
| - | 268 | unsigned long key = index; |
|
| 267 | link_t *lnk = hash_table_find(&dentries, &index); |
269 | link_t *lnk = hash_table_find(&dentries, &key); |
| 268 | if (!lnk) |
270 | if (!lnk) |
| 269 | return NULL; |
271 | return NULL; |
| 270 | return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link); |
272 | return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link); |
| 271 | } |
273 | } |
| 272 | 274 | ||
| Line 287... | Line 289... | ||
| 287 | node->type = TMPFS_DIRECTORY; |
289 | node->type = TMPFS_DIRECTORY; |
| 288 | else |
290 | else |
| 289 | node->type = TMPFS_FILE; |
291 | node->type = TMPFS_FILE; |
| 290 | 292 | ||
| 291 | /* Insert the new node into the dentry hash table. */ |
293 | /* Insert the new node into the dentry hash table. */ |
| - | 294 | unsigned long key = node->index; |
|
| 292 | hash_table_insert(&dentries, &node->index, &node->dh_link); |
295 | hash_table_insert(&dentries, &key, &node->dh_link); |
| 293 | return (void *) node; |
296 | return (void *) node; |
| 294 | } |
297 | } |
| 295 | 298 | ||
| 296 | bool tmpfs_link_node(void *prnt, void *chld, const char *nm) |
299 | bool tmpfs_link_node(void *prnt, void *chld, const char *nm) |
| 297 | { |
300 | { |
| Line 367... | Line 370... | ||
| 367 | 370 | ||
| 368 | assert(!dentry->lnkcnt); |
371 | assert(!dentry->lnkcnt); |
| 369 | assert(!dentry->child); |
372 | assert(!dentry->child); |
| 370 | assert(!dentry->sibling); |
373 | assert(!dentry->sibling); |
| 371 | 374 | ||
| 372 | unsigned long index = dentry->index; |
375 | unsigned long key = dentry->index; |
| 373 | hash_table_remove(&dentries, &index, 1); |
376 | hash_table_remove(&dentries, &key, 1); |
| 374 | 377 | ||
| 375 | hash_table_destroy(&dentry->names); |
378 | hash_table_destroy(&dentry->names); |
| 376 | 379 | ||
| 377 | if (dentry->type == TMPFS_FILE) |
380 | if (dentry->type == TMPFS_FILE) |
| 378 | free(dentry->data); |
381 | free(dentry->data); |
| Line 389... | Line 392... | ||
| 389 | libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); |
392 | libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); |
| 390 | } |
393 | } |
| 391 | 394 | ||
| 392 | void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) |
395 | void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) |
| 393 | { |
396 | { |
| 394 | int dev_handle = IPC_GET_ARG1(*request); |
397 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
| 395 | unsigned long index = IPC_GET_ARG2(*request); |
398 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
| 396 | off_t pos = IPC_GET_ARG3(*request); |
399 | off_t pos = (off_t)IPC_GET_ARG3(*request); |
| 397 | 400 | ||
| 398 | /* |
401 | /* |
| 399 | * Lookup the respective dentry. |
402 | * Lookup the respective dentry. |
| 400 | */ |
403 | */ |
| 401 | link_t *hlp; |
404 | link_t *hlp; |
| - | 405 | unsigned long key = index; |
|
| 402 | hlp = hash_table_find(&dentries, &index); |
406 | hlp = hash_table_find(&dentries, &key); |
| 403 | if (!hlp) { |
407 | if (!hlp) { |
| 404 | ipc_answer_0(rid, ENOENT); |
408 | ipc_answer_0(rid, ENOENT); |
| 405 | return; |
409 | return; |
| 406 | } |
410 | } |
| 407 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
411 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
| Line 461... | Line 465... | ||
| 461 | ipc_answer_1(rid, EOK, bytes); |
465 | ipc_answer_1(rid, EOK, bytes); |
| 462 | } |
466 | } |
| 463 | 467 | ||
| 464 | void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) |
468 | void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) |
| 465 | { |
469 | { |
| 466 | int dev_handle = IPC_GET_ARG1(*request); |
470 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
| 467 | unsigned long index = IPC_GET_ARG2(*request); |
471 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
| 468 | off_t pos = IPC_GET_ARG3(*request); |
472 | off_t pos = (off_t)IPC_GET_ARG3(*request); |
| 469 | 473 | ||
| 470 | /* |
474 | /* |
| 471 | * Lookup the respective dentry. |
475 | * Lookup the respective dentry. |
| 472 | */ |
476 | */ |
| 473 | link_t *hlp; |
477 | link_t *hlp; |
| - | 478 | unsigned long key = index; |
|
| 474 | hlp = hash_table_find(&dentries, &index); |
479 | hlp = hash_table_find(&dentries, &key); |
| 475 | if (!hlp) { |
480 | if (!hlp) { |
| 476 | ipc_answer_0(rid, ENOENT); |
481 | ipc_answer_0(rid, ENOENT); |
| 477 | return; |
482 | return; |
| 478 | } |
483 | } |
| 479 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
484 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
| Line 521... | Line 526... | ||
| 521 | ipc_answer_2(rid, EOK, len, dentry->size); |
526 | ipc_answer_2(rid, EOK, len, dentry->size); |
| 522 | } |
527 | } |
| 523 | 528 | ||
| 524 | void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) |
529 | void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) |
| 525 | { |
530 | { |
| 526 | int dev_handle = IPC_GET_ARG1(*request); |
531 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
| 527 | unsigned long index = IPC_GET_ARG2(*request); |
532 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
| 528 | size_t size = IPC_GET_ARG3(*request); |
533 | size_t size = (off_t)IPC_GET_ARG3(*request); |
| 529 | 534 | ||
| 530 | /* |
535 | /* |
| 531 | * Lookup the respective dentry. |
536 | * Lookup the respective dentry. |
| 532 | */ |
537 | */ |
| 533 | link_t *hlp; |
538 | link_t *hlp; |
| - | 539 | unsigned long key = index; |
|
| 534 | hlp = hash_table_find(&dentries, &index); |
540 | hlp = hash_table_find(&dentries, &key); |
| 535 | if (!hlp) { |
541 | if (!hlp) { |
| 536 | ipc_answer_0(rid, ENOENT); |
542 | ipc_answer_0(rid, ENOENT); |
| 537 | return; |
543 | return; |
| 538 | } |
544 | } |
| 539 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
545 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
| Line 558... | Line 564... | ||
| 558 | ipc_answer_0(rid, EOK); |
564 | ipc_answer_0(rid, EOK); |
| 559 | } |
565 | } |
| 560 | 566 | ||
| 561 | void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) |
567 | void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) |
| 562 | { |
568 | { |
| 563 | int dev_handle = IPC_GET_ARG1(*request); |
569 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
| 564 | unsigned long index = IPC_GET_ARG2(*request); |
570 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
| 565 | 571 | ||
| 566 | link_t *hlp; |
572 | link_t *hlp; |
| - | 573 | unsigned long key = index; |
|
| 567 | hlp = hash_table_find(&dentries, &index); |
574 | hlp = hash_table_find(&dentries, &key); |
| 568 | if (!hlp) { |
575 | if (!hlp) { |
| 569 | ipc_answer_0(rid, ENOENT); |
576 | ipc_answer_0(rid, ENOENT); |
| 570 | return; |
577 | return; |
| 571 | } |
578 | } |
| 572 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
579 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |