Changeset b79d450 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c
- Timestamp:
- 2010-01-27T20:35:49Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fb6f1a5
- Parents:
- fccc236 (diff), 95e6c4f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
rfccc236 rb79d450 147 147 hash_table_t nodes; 148 148 149 #define NODES_KEY_ INDEX 0150 #define NODES_KEY_ DEV1149 #define NODES_KEY_DEV 0 150 #define NODES_KEY_INDEX 1 151 151 152 152 /* Implementation of hash table interface for the nodes hash table. */ … … 160 160 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 161 161 nh_link); 162 return (nodep->index == key[NODES_KEY_INDEX] && 163 nodep->dev_handle == key[NODES_KEY_DEV]); 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 } 164 172 } 165 173 166 174 static void nodes_remove_callback(link_t *item) 167 175 { 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); 168 194 } 169 195 … … 215 241 } 216 242 243 static void tmpfs_instance_done(dev_handle_t dev_handle) 244 { 245 unsigned long key[] = { 246 [NODES_KEY_DEV] = dev_handle 247 }; 248 /* 249 * Here we are making use of one special feature of our hash table 250 * implementation, which allows to remove more items based on a partial 251 * key match. In the following, we are going to remove all nodes 252 * matching our device handle. The nodes_remove_callback() function will 253 * take care of resource deallocation. 254 */ 255 hash_table_remove(&nodes, key, 1); 256 } 257 217 258 int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 218 259 { … … 237 278 { 238 279 unsigned long key[] = { 239 [NODES_KEY_ INDEX] = index,240 [NODES_KEY_ DEV] = dev_handle280 [NODES_KEY_DEV] = dev_handle, 281 [NODES_KEY_INDEX] = index 241 282 }; 242 283 link_t *lnk = hash_table_find(&nodes, key); … … 296 337 /* Insert the new node into the nodes hash table. */ 297 338 unsigned long key[] = { 298 [NODES_KEY_ INDEX] = nodep->index,299 [NODES_KEY_ DEV] = nodep->dev_handle339 [NODES_KEY_DEV] = nodep->dev_handle, 340 [NODES_KEY_INDEX] = nodep->index 300 341 }; 301 342 hash_table_insert(&nodes, key, &nodep->nh_link); … … 312 353 313 354 unsigned long key[] = { 314 [NODES_KEY_ INDEX] = nodep->index,315 [NODES_KEY_ DEV] = nodep->dev_handle355 [NODES_KEY_DEV] = nodep->dev_handle, 356 [NODES_KEY_INDEX] = nodep->index 316 357 }; 317 358 hash_table_remove(&nodes, key, 2); 318 359 319 if (nodep->type == TMPFS_FILE)320 free(nodep->data);321 free(nodep->bp);322 free(nodep);360 /* 361 * The nodes_remove_callback() function takes care of the actual 362 * resource deallocation. 363 */ 323 364 return EOK; 324 365 } … … 424 465 /* Initialize TMPFS instance. */ 425 466 if (!tmpfs_instance_init(dev_handle)) { 467 free(opts); 426 468 ipc_answer_0(rid, ENOMEM); 427 469 return; … … 442 484 rootp->lnkcnt); 443 485 } 486 free(opts); 444 487 } 445 488 … … 447 490 { 448 491 libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 492 } 493 494 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 495 { 496 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 497 498 tmpfs_instance_done(dev_handle); 499 ipc_answer_0(rid, EOK); 500 } 501 502 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request) 503 { 504 libfs_unmount(&tmpfs_libfs_ops, rid, request); 449 505 } 450 506 … … 465 521 link_t *hlp; 466 522 unsigned long key[] = { 467 [NODES_KEY_INDEX] = index,468 523 [NODES_KEY_DEV] = dev_handle, 524 [NODES_KEY_INDEX] = index 469 525 }; 470 526 hlp = hash_table_find(&nodes, key); … … 539 595 link_t *hlp; 540 596 unsigned long key[] = { 541 [NODES_KEY_ INDEX] = index,542 [NODES_KEY_ DEV] = dev_handle597 [NODES_KEY_DEV] = dev_handle, 598 [NODES_KEY_INDEX] = index 543 599 }; 544 600 hlp = hash_table_find(&nodes, key); … … 603 659 link_t *hlp; 604 660 unsigned long key[] = { 605 [NODES_KEY_ INDEX] = index,606 [NODES_KEY_ DEV] = dev_handle661 [NODES_KEY_DEV] = dev_handle, 662 [NODES_KEY_INDEX] = index 607 663 }; 608 664 hlp = hash_table_find(&nodes, key); … … 646 702 link_t *hlp; 647 703 unsigned long key[] = { 648 [NODES_KEY_ INDEX] = index,649 [NODES_KEY_ DEV] = dev_handle704 [NODES_KEY_DEV] = dev_handle, 705 [NODES_KEY_INDEX] = index 650 706 }; 651 707 hlp = hash_table_find(&nodes, key);
Note:
See TracChangeset
for help on using the changeset viewer.