Rev 2787 | Rev 3011 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2787 | Rev 2925 | ||
|---|---|---|---|
| Line 67... | Line 67... | ||
| 67 | /* |
67 | /* |
| 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 void *tmpfs_match(void *, const char *); |
| 73 | static void *tmpfs_node_get(fs_handle_t, dev_handle_t, fs_index_t); |
73 | static void *tmpfs_node_get(dev_handle_t, fs_index_t); |
| - | 74 | static void tmpfs_node_put(void *); |
|
| 74 | static void *tmpfs_create_node(int); |
75 | static void *tmpfs_create_node(int); |
| 75 | static bool tmpfs_link_node(void *, void *, const char *); |
76 | static bool tmpfs_link_node(void *, void *, const char *); |
| 76 | static int tmpfs_unlink_node(void *, void *); |
77 | static int tmpfs_unlink_node(void *, void *); |
| 77 | static void tmpfs_destroy_node(void *); |
78 | static int tmpfs_destroy_node(void *); |
| 78 | 79 | ||
| 79 | /* Implementation of helper functions. */ |
80 | /* Implementation of helper functions. */ |
| 80 | static fs_index_t tmpfs_index_get(void *nodep) |
81 | static fs_index_t tmpfs_index_get(void *nodep) |
| 81 | { |
82 | { |
| 82 | return ((tmpfs_dentry_t *) nodep)->index; |
83 | return ((tmpfs_dentry_t *) nodep)->index; |
| Line 90... | Line 91... | ||
| 90 | static unsigned tmpfs_lnkcnt_get(void *nodep) |
91 | static unsigned tmpfs_lnkcnt_get(void *nodep) |
| 91 | { |
92 | { |
| 92 | return ((tmpfs_dentry_t *) nodep)->lnkcnt; |
93 | return ((tmpfs_dentry_t *) nodep)->lnkcnt; |
| 93 | } |
94 | } |
| 94 | 95 | ||
| 95 | static void *tmpfs_child_get(void *nodep) |
96 | static bool tmpfs_has_children(void *nodep) |
| 96 | { |
97 | { |
| 97 | return ((tmpfs_dentry_t *) nodep)->child; |
98 | return ((tmpfs_dentry_t *) nodep)->child != NULL; |
| 98 | } |
99 | } |
| 99 | 100 | ||
| 100 | static void *tmpfs_sibling_get(void *nodep) |
- | |
| 101 | { |
- | |
| 102 | return ((tmpfs_dentry_t *) nodep)->sibling; |
- | |
| 103 | } |
- | |
| 104 | - | ||
| 105 | static void *tmpfs_root_get(void) |
101 | static void *tmpfs_root_get(dev_handle_t dev_handle) |
| 106 | { |
102 | { |
| 107 | return root; |
103 | return root; |
| 108 | } |
104 | } |
| 109 | 105 | ||
| 110 | static char tmpfs_plb_get_char(unsigned pos) |
106 | static char tmpfs_plb_get_char(unsigned pos) |
| Line 124... | Line 120... | ||
| 124 | 120 | ||
| 125 | /** libfs operations */ |
121 | /** libfs operations */ |
| 126 | libfs_ops_t tmpfs_libfs_ops = { |
122 | libfs_ops_t tmpfs_libfs_ops = { |
| 127 | .match = tmpfs_match, |
123 | .match = tmpfs_match, |
| 128 | .node_get = tmpfs_node_get, |
124 | .node_get = tmpfs_node_get, |
| - | 125 | .node_put = tmpfs_node_put, |
|
| 129 | .create = tmpfs_create_node, |
126 | .create = tmpfs_create_node, |
| 130 | .destroy = tmpfs_destroy_node, |
127 | .destroy = tmpfs_destroy_node, |
| 131 | .link = tmpfs_link_node, |
128 | .link = tmpfs_link_node, |
| 132 | .unlink = tmpfs_unlink_node, |
129 | .unlink = tmpfs_unlink_node, |
| 133 | .index_get = tmpfs_index_get, |
130 | .index_get = tmpfs_index_get, |
| 134 | .size_get = tmpfs_size_get, |
131 | .size_get = tmpfs_size_get, |
| 135 | .lnkcnt_get = tmpfs_lnkcnt_get, |
132 | .lnkcnt_get = tmpfs_lnkcnt_get, |
| 136 | .child_get = tmpfs_child_get, |
133 | .has_children = tmpfs_has_children, |
| 137 | .sibling_get = tmpfs_sibling_get, |
- | |
| 138 | .root_get = tmpfs_root_get, |
134 | .root_get = tmpfs_root_get, |
| 139 | .plb_get_char = tmpfs_plb_get_char, |
135 | .plb_get_char = tmpfs_plb_get_char, |
| 140 | .is_directory = tmpfs_is_directory, |
136 | .is_directory = tmpfs_is_directory, |
| 141 | .is_file = tmpfs_is_file |
137 | .is_file = tmpfs_is_file |
| 142 | }; |
138 | }; |
| Line 241... | Line 237... | ||
| 241 | return true; |
237 | return true; |
| 242 | } |
238 | } |
| 243 | 239 | ||
| 244 | /** Compare one component of path to a directory entry. |
240 | /** Compare one component of path to a directory entry. |
| 245 | * |
241 | * |
| 246 | * @param prnt Node from which we descended. |
242 | * @param parentp Pointer to node from which we descended. |
| 247 | * @param chld Node to compare the path component with. |
243 | * @param childp Pointer to node to compare the path component with. |
| 248 | * @param component Array of characters holding component name. |
244 | * @param component Array of characters holding component name. |
| 249 | * |
245 | * |
| 250 | * @return True on match, false otherwise. |
246 | * @return True on match, false otherwise. |
| 251 | */ |
247 | */ |
| - | 248 | static bool |
|
| 252 | bool tmpfs_match(void *prnt, void *chld, const char *component) |
249 | tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp, |
| - | 250 | const char *component) |
|
| 253 | { |
251 | { |
| 254 | tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; |
- | |
| 255 | tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld; |
- | |
| 256 | - | ||
| 257 | unsigned long key = (unsigned long) parentp; |
252 | unsigned long key = (unsigned long) parentp; |
| 258 | link_t *hlp = hash_table_find(&childp->names, &key); |
253 | link_t *hlp = hash_table_find(&childp->names, &key); |
| 259 | assert(hlp); |
254 | assert(hlp); |
| 260 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
255 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
| 261 | - | ||
| 262 | return !strcmp(namep->name, component); |
256 | return !strcmp(namep->name, component); |
| 263 | } |
257 | } |
| 264 | 258 | ||
| - | 259 | void *tmpfs_match(void *prnt, const char *component) |
|
| - | 260 | { |
|
| - | 261 | tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; |
|
| - | 262 | tmpfs_dentry_t *childp = parentp->child; |
|
| - | 263 | ||
| - | 264 | while (childp && !tmpfs_match_one(parentp, childp, component)) |
|
| - | 265 | childp = childp->sibling; |
|
| - | 266 | ||
| - | 267 | return (void *) childp; |
|
| - | 268 | } |
|
| - | 269 | ||
| 265 | void * |
270 | void * |
| 266 | tmpfs_node_get(fs_handle_t fs_handle, dev_handle_t dev_handle, fs_index_t index) |
271 | tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) |
| 267 | { |
272 | { |
| 268 | unsigned long key = index; |
273 | unsigned long key = index; |
| 269 | link_t *lnk = hash_table_find(&dentries, &key); |
274 | link_t *lnk = hash_table_find(&dentries, &key); |
| 270 | if (!lnk) |
275 | if (!lnk) |
| 271 | return NULL; |
276 | return NULL; |
| 272 | return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link); |
277 | return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link); |
| 273 | } |
278 | } |
| 274 | 279 | ||
| - | 280 | void tmpfs_node_put(void *node) |
|
| - | 281 | { |
|
| - | 282 | /* nothing to do */ |
|
| - | 283 | } |
|
| - | 284 | ||
| 275 | void *tmpfs_create_node(int lflag) |
285 | void *tmpfs_create_node(int lflag) |
| 276 | { |
286 | { |
| 277 | assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); |
287 | assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); |
| 278 | 288 | ||
| 279 | tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); |
289 | tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); |
| Line 362... | Line 372... | ||
| 362 | childp->lnkcnt--; |
372 | childp->lnkcnt--; |
| 363 | 373 | ||
| 364 | return EOK; |
374 | return EOK; |
| 365 | } |
375 | } |
| 366 | 376 | ||
| 367 | void tmpfs_destroy_node(void *nodep) |
377 | int tmpfs_destroy_node(void *nodep) |
| 368 | { |
378 | { |
| 369 | tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; |
379 | tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; |
| 370 | 380 | ||
| 371 | assert(!dentry->lnkcnt); |
381 | assert(!dentry->lnkcnt); |
| 372 | assert(!dentry->child); |
382 | assert(!dentry->child); |
| Line 378... | Line 388... | ||
| 378 | hash_table_destroy(&dentry->names); |
388 | hash_table_destroy(&dentry->names); |
| 379 | 389 | ||
| 380 | if (dentry->type == TMPFS_FILE) |
390 | if (dentry->type == TMPFS_FILE) |
| 381 | free(dentry->data); |
391 | free(dentry->data); |
| 382 | free(dentry); |
392 | free(dentry); |
| - | 393 | return EOK; |
|
| 383 | } |
394 | } |
| 384 | 395 | ||
| 385 | void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request) |
396 | void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request) |
| 386 | { |
397 | { |
| 387 | /* Initialize TMPFS. */ |
398 | /* Initialize TMPFS. */ |
| Line 566... | Line 577... | ||
| 566 | 577 | ||
| 567 | void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) |
578 | void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) |
| 568 | { |
579 | { |
| 569 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
580 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
| 570 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
581 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
| - | 582 | int rc; |
|
| 571 | 583 | ||
| 572 | link_t *hlp; |
584 | link_t *hlp; |
| 573 | unsigned long key = index; |
585 | unsigned long key = index; |
| 574 | hlp = hash_table_find(&dentries, &key); |
586 | hlp = hash_table_find(&dentries, &key); |
| 575 | if (!hlp) { |
587 | if (!hlp) { |
| 576 | ipc_answer_0(rid, ENOENT); |
588 | ipc_answer_0(rid, ENOENT); |
| 577 | return; |
589 | return; |
| 578 | } |
590 | } |
| 579 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
591 | tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, |
| 580 | dh_link); |
592 | dh_link); |
| 581 | tmpfs_destroy_node(dentry); |
593 | rc = tmpfs_destroy_node(dentry); |
| 582 | ipc_answer_0(rid, EOK); |
594 | ipc_answer_0(rid, rc); |
| 583 | } |
595 | } |
| 584 | 596 | ||
| 585 | /** |
597 | /** |
| 586 | * @} |
598 | * @} |
| 587 | */ |
599 | */ |