Changeset 3b3e776 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c
- Timestamp:
- 2010-02-05T10:57:50Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0358da0
- Parents:
- 3f085132 (diff), b4cbef1 (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
r3f085132 r3b3e776 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 *); 71 72 static int tmpfs_node_put(fs_node_t *); 72 73 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); … … 117 118 } 118 119 120 static dev_handle_t tmpfs_device_get(fs_node_t *fn) 121 { 122 return 0; 123 } 124 119 125 /** libfs operations */ 120 126 libfs_ops_t tmpfs_libfs_ops = { … … 122 128 .match = tmpfs_match, 123 129 .node_get = tmpfs_node_get, 130 .node_open = tmpfs_node_open, 124 131 .node_put = tmpfs_node_put, 125 132 .create = tmpfs_create_node, … … 133 140 .plb_get_char = tmpfs_plb_get_char, 134 141 .is_directory = tmpfs_is_directory, 135 .is_file = tmpfs_is_file 142 .is_file = tmpfs_is_file, 143 .device_get = tmpfs_device_get 136 144 }; 137 145 … … 139 147 hash_table_t nodes; 140 148 141 #define NODES_KEY_ INDEX 0142 #define NODES_KEY_ DEV1149 #define NODES_KEY_DEV 0 150 #define NODES_KEY_INDEX 1 143 151 144 152 /* Implementation of hash table interface for the nodes hash table. */ … … 152 160 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 153 161 nh_link); 154 return (nodep->index == key[NODES_KEY_INDEX] && 155 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 } 156 172 } 157 173 158 174 static void nodes_remove_callback(link_t *item) 159 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); 160 194 } 161 195 … … 207 241 } 208 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 209 258 int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 210 259 { … … 229 278 { 230 279 unsigned long key[] = { 231 [NODES_KEY_ INDEX] = index,232 [NODES_KEY_ DEV] = dev_handle280 [NODES_KEY_DEV] = dev_handle, 281 [NODES_KEY_INDEX] = index 233 282 }; 234 283 link_t *lnk = hash_table_find(&nodes, key); … … 241 290 } 242 291 return EOK; 292 } 293 294 int tmpfs_node_open(fs_node_t *fn) 295 { 296 /* nothing to do */ 297 return EOK; 243 298 } 244 299 … … 282 337 /* Insert the new node into the nodes hash table. */ 283 338 unsigned long key[] = { 284 [NODES_KEY_ INDEX] = nodep->index,285 [NODES_KEY_ DEV] = nodep->dev_handle339 [NODES_KEY_DEV] = nodep->dev_handle, 340 [NODES_KEY_INDEX] = nodep->index 286 341 }; 287 342 hash_table_insert(&nodes, key, &nodep->nh_link); … … 298 353 299 354 unsigned long key[] = { 300 [NODES_KEY_ INDEX] = nodep->index,301 [NODES_KEY_ DEV] = nodep->dev_handle355 [NODES_KEY_DEV] = nodep->dev_handle, 356 [NODES_KEY_INDEX] = nodep->index 302 357 }; 303 358 hash_table_remove(&nodes, key, 2); 304 359 305 if (nodep->type == TMPFS_FILE)306 free(nodep->data);307 free(nodep->bp);308 free(nodep);360 /* 361 * The nodes_remove_callback() function takes care of the actual 362 * resource deallocation. 363 */ 309 364 return EOK; 310 365 } … … 384 439 { 385 440 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 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'; 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 } 409 450 410 451 /* Initialize TMPFS instance. */ 411 452 if (!tmpfs_instance_init(dev_handle)) { 453 free(opts); 412 454 ipc_answer_0(rid, ENOMEM); 413 455 return; … … 428 470 rootp->lnkcnt); 429 471 } 472 free(opts); 430 473 } 431 474 … … 433 476 { 434 477 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); 435 491 } 436 492 … … 451 507 link_t *hlp; 452 508 unsigned long key[] = { 453 [NODES_KEY_INDEX] = index,454 509 [NODES_KEY_DEV] = dev_handle, 510 [NODES_KEY_INDEX] = index 455 511 }; 456 512 hlp = hash_table_find(&nodes, key); … … 525 581 link_t *hlp; 526 582 unsigned long key[] = { 527 [NODES_KEY_ INDEX] = index,528 [NODES_KEY_ DEV] = dev_handle583 [NODES_KEY_DEV] = dev_handle, 584 [NODES_KEY_INDEX] = index 529 585 }; 530 586 hlp = hash_table_find(&nodes, key); … … 589 645 link_t *hlp; 590 646 unsigned long key[] = { 591 [NODES_KEY_ INDEX] = index,592 [NODES_KEY_ DEV] = dev_handle647 [NODES_KEY_DEV] = dev_handle, 648 [NODES_KEY_INDEX] = index 593 649 }; 594 650 hlp = hash_table_find(&nodes, key); … … 632 688 link_t *hlp; 633 689 unsigned long key[] = { 634 [NODES_KEY_ INDEX] = index,635 [NODES_KEY_ DEV] = dev_handle690 [NODES_KEY_DEV] = dev_handle, 691 [NODES_KEY_INDEX] = index 636 692 }; 637 693 hlp = hash_table_find(&nodes, key);
Note:
See TracChangeset
for help on using the changeset viewer.