Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [472c09d:0da4e41] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
r472c09d r0da4e41 69 69 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 70 70 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t); 71 static int tmpfs_node_open(fs_node_t *);72 71 static int tmpfs_node_put(fs_node_t *); 73 72 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); … … 118 117 } 119 118 120 static dev_handle_t tmpfs_device_get(fs_node_t *fn)121 {122 return 0;123 }124 125 119 /** libfs operations */ 126 120 libfs_ops_t tmpfs_libfs_ops = { … … 128 122 .match = tmpfs_match, 129 123 .node_get = tmpfs_node_get, 130 .node_open = tmpfs_node_open,131 124 .node_put = tmpfs_node_put, 132 125 .create = tmpfs_create_node, … … 140 133 .plb_get_char = tmpfs_plb_get_char, 141 134 .is_directory = tmpfs_is_directory, 142 .is_file = tmpfs_is_file, 143 .device_get = tmpfs_device_get 135 .is_file = tmpfs_is_file 144 136 }; 145 137 … … 147 139 hash_table_t nodes; 148 140 149 #define NODES_KEY_ DEV 0150 #define NODES_KEY_ INDEX1141 #define NODES_KEY_INDEX 0 142 #define NODES_KEY_DEV 1 151 143 152 144 /* Implementation of hash table interface for the nodes hash table. */ … … 160 152 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 161 153 nh_link); 162 163 switch (keys) { 164 case 1: 165 return (nodep->dev_handle == key[NODES_KEY_DEV]); 166 case 2: 167 return ((nodep->dev_handle == key[NODES_KEY_DEV]) && 168 (nodep->index == key[NODES_KEY_INDEX])); 169 default: 170 abort(); 171 } 154 return (nodep->index == key[NODES_KEY_INDEX] && 155 nodep->dev_handle == key[NODES_KEY_DEV]); 172 156 } 173 157 174 158 static void nodes_remove_callback(link_t *item) 175 159 { 176 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,177 nh_link);178 179 while (!list_empty(&nodep->cs_head)) {180 tmpfs_dentry_t *dentryp = list_get_instance(nodep->cs_head.next,181 tmpfs_dentry_t, link);182 183 assert(nodep->type == TMPFS_DIRECTORY);184 list_remove(&dentryp->link);185 free(dentryp);186 }187 188 if (nodep->data) {189 assert(nodep->type == TMPFS_FILE);190 free(nodep->data);191 }192 free(nodep->bp);193 free(nodep);194 160 } 195 161 … … 241 207 } 242 208 243 static void tmpfs_instance_done(dev_handle_t dev_handle)244 {245 unsigned long key[] = {246 [NODES_KEY_DEV] = dev_handle247 };248 /*249 * Here we are making use of one special feature of our hash table250 * implementation, which allows to remove more items based on a partial251 * key match. In the following, we are going to remove all nodes252 * matching our device handle. The nodes_remove_callback() function will253 * take care of resource deallocation.254 */255 hash_table_remove(&nodes, key, 1);256 }257 258 209 int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 259 210 { … … 278 229 { 279 230 unsigned long key[] = { 280 [NODES_KEY_ DEV] = dev_handle,281 [NODES_KEY_ INDEX] = index231 [NODES_KEY_INDEX] = index, 232 [NODES_KEY_DEV] = dev_handle 282 233 }; 283 234 link_t *lnk = hash_table_find(&nodes, key); … … 290 241 } 291 242 return EOK; 292 }293 294 int tmpfs_node_open(fs_node_t *fn)295 {296 /* nothing to do */297 return EOK;298 243 } 299 244 … … 337 282 /* Insert the new node into the nodes hash table. */ 338 283 unsigned long key[] = { 339 [NODES_KEY_ DEV] = nodep->dev_handle,340 [NODES_KEY_ INDEX] = nodep->index284 [NODES_KEY_INDEX] = nodep->index, 285 [NODES_KEY_DEV] = nodep->dev_handle 341 286 }; 342 287 hash_table_insert(&nodes, key, &nodep->nh_link); … … 353 298 354 299 unsigned long key[] = { 355 [NODES_KEY_ DEV] = nodep->dev_handle,356 [NODES_KEY_ INDEX] = nodep->index300 [NODES_KEY_INDEX] = nodep->index, 301 [NODES_KEY_DEV] = nodep->dev_handle 357 302 }; 358 303 hash_table_remove(&nodes, key, 2); 359 304 360 /*361 * The nodes_remove_callback() function takes care of the actual362 * resource deallocation.363 */305 if (nodep->type == TMPFS_FILE) 306 free(nodep->data); 307 free(nodep->bp); 308 free(nodep); 364 309 return EOK; 365 310 } … … 439 384 { 440 385 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 441 442 /* Accept the mount options */ 443 char *opts; 444 int rc = async_string_receive(&opts, 0, NULL); 445 446 if (rc != EOK) { 447 ipc_answer_0(rid, rc); 448 return; 449 } 386 int rc; 387 388 /* accept the mount options */ 389 ipc_callid_t callid; 390 size_t size; 391 if (!async_data_write_receive(&callid, &size)) { 392 ipc_answer_0(callid, EINVAL); 393 ipc_answer_0(rid, EINVAL); 394 return; 395 } 396 char *opts = malloc(size + 1); 397 if (!opts) { 398 ipc_answer_0(callid, ENOMEM); 399 ipc_answer_0(rid, ENOMEM); 400 return; 401 } 402 ipcarg_t retval = async_data_write_finalize(callid, opts, size); 403 if (retval != EOK) { 404 ipc_answer_0(rid, retval); 405 free(opts); 406 return; 407 } 408 opts[size] = '\0'; 450 409 451 410 /* Initialize TMPFS instance. */ 452 411 if (!tmpfs_instance_init(dev_handle)) { 453 free(opts);454 412 ipc_answer_0(rid, ENOMEM); 455 413 return; … … 470 428 rootp->lnkcnt); 471 429 } 472 free(opts);473 430 } 474 431 … … 476 433 { 477 434 libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 478 }479 480 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)481 {482 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);483 484 tmpfs_instance_done(dev_handle);485 ipc_answer_0(rid, EOK);486 }487 488 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request)489 {490 libfs_unmount(&tmpfs_libfs_ops, rid, request);491 435 } 492 436 … … 507 451 link_t *hlp; 508 452 unsigned long key[] = { 453 [NODES_KEY_INDEX] = index, 509 454 [NODES_KEY_DEV] = dev_handle, 510 [NODES_KEY_INDEX] = index511 455 }; 512 456 hlp = hash_table_find(&nodes, key); … … 581 525 link_t *hlp; 582 526 unsigned long key[] = { 583 [NODES_KEY_ DEV] = dev_handle,584 [NODES_KEY_ INDEX] = index527 [NODES_KEY_INDEX] = index, 528 [NODES_KEY_DEV] = dev_handle 585 529 }; 586 530 hlp = hash_table_find(&nodes, key); … … 645 589 link_t *hlp; 646 590 unsigned long key[] = { 647 [NODES_KEY_ DEV] = dev_handle,648 [NODES_KEY_ INDEX] = index591 [NODES_KEY_INDEX] = index, 592 [NODES_KEY_DEV] = dev_handle 649 593 }; 650 594 hlp = hash_table_find(&nodes, key); … … 688 632 link_t *hlp; 689 633 unsigned long key[] = { 690 [NODES_KEY_ DEV] = dev_handle,691 [NODES_KEY_ INDEX] = index634 [NODES_KEY_INDEX] = index, 635 [NODES_KEY_DEV] = dev_handle 692 636 }; 693 637 hlp = hash_table_find(&nodes, key);
Note:
See TracChangeset
for help on using the changeset viewer.