Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [991f645:4cac2d69] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
r991f645 r4cac2d69 29 29 /** @addtogroup fs 30 30 * @{ 31 */ 31 */ 32 32 33 33 /** … … 40 40 #include "../../vfs/vfs.h" 41 41 #include <ipc/ipc.h> 42 #include <macros.h>43 #include <stdint.h>44 42 #include <async.h> 45 43 #include <errno.h> 46 44 #include <atomic.h> 47 45 #include <stdlib.h> 48 #include <str .h>46 #include <string.h> 49 47 #include <stdio.h> 50 48 #include <assert.h> … … 70 68 /* Forward declarations of static functions. */ 71 69 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 72 static int tmpfs_node_get(fs_node_t **, dev map_handle_t, fs_index_t);70 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t); 73 71 static int tmpfs_node_open(fs_node_t *); 74 72 static int tmpfs_node_put(fs_node_t *); 75 static int tmpfs_create_node(fs_node_t **, dev map_handle_t, int);73 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); 76 74 static int tmpfs_destroy_node(fs_node_t *); 77 75 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); … … 79 77 80 78 /* Implementation of helper functions. */ 81 static int tmpfs_root_get(fs_node_t **rfn, dev map_handle_t devmap_handle)82 { 83 return tmpfs_node_get(rfn, dev map_handle, TMPFS_SOME_ROOT);79 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle) 80 { 81 return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT); 84 82 } 85 83 … … 95 93 } 96 94 97 static aoff64_t tmpfs_size_get(fs_node_t *fn)95 static size_t tmpfs_size_get(fs_node_t *fn) 98 96 { 99 97 return TMPFS_NODE(fn)->size; … … 120 118 } 121 119 122 static dev map_handle_t tmpfs_device_get(fs_node_t *fn)120 static dev_handle_t tmpfs_device_get(fs_node_t *fn) 123 121 { 124 122 return 0; … … 165 163 switch (keys) { 166 164 case 1: 167 return (nodep->dev map_handle == key[NODES_KEY_DEV]);165 return (nodep->dev_handle == key[NODES_KEY_DEV]); 168 166 case 2: 169 return ((nodep->dev map_handle == key[NODES_KEY_DEV]) &&167 return ((nodep->dev_handle == key[NODES_KEY_DEV]) && 170 168 (nodep->index == key[NODES_KEY_INDEX])); 171 169 default: 172 assert((keys == 1) || (keys == 2)); 173 } 174 175 return 0; 170 abort(); 171 } 176 172 } 177 173 … … 209 205 nodep->bp = NULL; 210 206 nodep->index = 0; 211 nodep->dev map_handle = 0;207 nodep->dev_handle = 0; 212 208 nodep->type = TMPFS_NONE; 213 209 nodep->lnkcnt = 0; … … 233 229 } 234 230 235 static bool tmpfs_instance_init(dev map_handle_t devmap_handle)231 static bool tmpfs_instance_init(dev_handle_t dev_handle) 236 232 { 237 233 fs_node_t *rfn; 238 234 int rc; 239 235 240 rc = tmpfs_create_node(&rfn, dev map_handle, L_DIRECTORY);236 rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY); 241 237 if (rc != EOK || !rfn) 242 238 return false; … … 245 241 } 246 242 247 static void tmpfs_instance_done(dev map_handle_t devmap_handle)243 static void tmpfs_instance_done(dev_handle_t dev_handle) 248 244 { 249 245 unsigned long key[] = { 250 [NODES_KEY_DEV] = dev map_handle246 [NODES_KEY_DEV] = dev_handle 251 247 }; 252 248 /* … … 279 275 } 280 276 281 int tmpfs_node_get(fs_node_t **rfn, dev map_handle_t devmap_handle, fs_index_t index)277 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index) 282 278 { 283 279 unsigned long key[] = { 284 [NODES_KEY_DEV] = dev map_handle,280 [NODES_KEY_DEV] = dev_handle, 285 281 [NODES_KEY_INDEX] = index 286 282 }; … … 308 304 } 309 305 310 int tmpfs_create_node(fs_node_t **rfn, dev map_handle_t devmap_handle, int lflag)306 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag) 311 307 { 312 308 fs_node_t *rootfn; … … 327 323 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 328 324 329 rc = tmpfs_root_get(&rootfn, dev map_handle);325 rc = tmpfs_root_get(&rootfn, dev_handle); 330 326 assert(rc == EOK); 331 327 if (!rootfn) … … 333 329 else 334 330 nodep->index = tmpfs_next_index++; 335 nodep->dev map_handle = devmap_handle;331 nodep->dev_handle = dev_handle; 336 332 if (lflag & L_DIRECTORY) 337 333 nodep->type = TMPFS_DIRECTORY; … … 341 337 /* Insert the new node into the nodes hash table. */ 342 338 unsigned long key[] = { 343 [NODES_KEY_DEV] = nodep->dev map_handle,339 [NODES_KEY_DEV] = nodep->dev_handle, 344 340 [NODES_KEY_INDEX] = nodep->index 345 341 }; … … 357 353 358 354 unsigned long key[] = { 359 [NODES_KEY_DEV] = nodep->dev map_handle,355 [NODES_KEY_DEV] = nodep->dev_handle, 360 356 [NODES_KEY_INDEX] = nodep->index 361 357 }; … … 442 438 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 443 439 { 444 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 445 fs_node_t *rootfn; 446 int rc; 440 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 447 441 448 /* Accept the mount options .*/442 /* Accept the mount options */ 449 443 char *opts; 450 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 444 int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 445 451 446 if (rc != EOK) { 452 447 ipc_answer_0(rid, rc); … … 454 449 } 455 450 456 /* Check if this device is not already mounted. */457 rc = tmpfs_root_get(&rootfn, devmap_handle);458 if ((rc == EOK) && (rootfn)) {459 (void) tmpfs_node_put(rootfn);460 free(opts);461 ipc_answer_0(rid, EEXIST);462 return;463 }464 465 451 /* Initialize TMPFS instance. */ 466 if (!tmpfs_instance_init(dev map_handle)) {452 if (!tmpfs_instance_init(dev_handle)) { 467 453 free(opts); 468 454 ipc_answer_0(rid, ENOMEM); … … 470 456 } 471 457 472 rc = tmpfs_root_get(&rootfn, devmap_handle); 458 fs_node_t *rootfn; 459 rc = tmpfs_root_get(&rootfn, dev_handle); 473 460 assert(rc == EOK); 474 461 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 475 462 if (str_cmp(opts, "restore") == 0) { 476 if (tmpfs_restore(dev map_handle))463 if (tmpfs_restore(dev_handle)) 477 464 ipc_answer_3(rid, EOK, rootp->index, rootp->size, 478 465 rootp->lnkcnt); … … 493 480 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 494 481 { 495 dev map_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);496 497 tmpfs_instance_done(dev map_handle);482 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 483 484 tmpfs_instance_done(dev_handle); 498 485 ipc_answer_0(rid, EOK); 499 486 } … … 511 498 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 512 499 { 513 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 514 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 515 aoff64_t pos = 516 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 517 500 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 501 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 502 off_t pos = (off_t)IPC_GET_ARG3(*request); 503 518 504 /* 519 505 * Lookup the respective TMPFS node. … … 521 507 link_t *hlp; 522 508 unsigned long key[] = { 523 [NODES_KEY_DEV] = dev map_handle,509 [NODES_KEY_DEV] = dev_handle, 524 510 [NODES_KEY_INDEX] = index 525 511 }; … … 531 517 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 532 518 nh_link); 533 519 534 520 /* 535 521 * Receive the read request. … … 538 524 size_t size; 539 525 if (!async_data_read_receive(&callid, &size)) { 540 ipc_answer_0(callid, EINVAL); 526 ipc_answer_0(callid, EINVAL); 541 527 ipc_answer_0(rid, EINVAL); 542 528 return; … … 545 531 size_t bytes; 546 532 if (nodep->type == TMPFS_FILE) { 547 bytes = m in(nodep->size - pos, size);533 bytes = max(0, min(nodep->size - pos, size)); 548 534 (void) async_data_read_finalize(callid, nodep->data + pos, 549 535 bytes); … … 551 537 tmpfs_dentry_t *dentryp; 552 538 link_t *lnk; 553 aoff64_t i;539 int i; 554 540 555 541 assert(nodep->type == TMPFS_DIRECTORY); … … 561 547 */ 562 548 for (i = 0, lnk = nodep->cs_head.next; 563 (i < pos) && (lnk != &nodep->cs_head);549 i < pos && lnk != &nodep->cs_head; 564 550 i++, lnk = lnk->next) 565 551 ; … … 586 572 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 587 573 { 588 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 589 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 590 aoff64_t pos = 591 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 592 574 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 575 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 576 off_t pos = (off_t)IPC_GET_ARG3(*request); 577 593 578 /* 594 579 * Lookup the respective TMPFS node. … … 596 581 link_t *hlp; 597 582 unsigned long key[] = { 598 [NODES_KEY_DEV] = dev map_handle,583 [NODES_KEY_DEV] = dev_handle, 599 584 [NODES_KEY_INDEX] = index 600 585 }; … … 651 636 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 652 637 { 653 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 654 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 655 aoff64_t size = 656 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 657 638 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 639 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 640 size_t size = (off_t)IPC_GET_ARG3(*request); 641 658 642 /* 659 643 * Lookup the respective TMPFS node. 660 644 */ 661 unsigned long key[] = {662 [NODES_KEY_DEV] = devmap_handle,663 [NODES_KEY_INDEX] = index664 };665 link_t *hlp = hash_table_find(&nodes, key);666 if (!hlp) {667 ipc_answer_0(rid, ENOENT);668 return;669 }670 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,671 nh_link);672 673 if (size == nodep->size) {674 ipc_answer_0(rid, EOK);675 return;676 }677 678 if (size > SIZE_MAX) {679 ipc_answer_0(rid, ENOMEM);680 return;681 }682 683 void *newdata = realloc(nodep->data, size);684 if (!newdata) {685 ipc_answer_0(rid, ENOMEM);686 return;687 }688 689 if (size > nodep->size) {690 size_t delta = size - nodep->size;691 memset(newdata + nodep->size, 0, delta);692 }693 694 nodep->size = size;695 nodep->data = newdata;696 ipc_answer_0(rid, EOK);697 }698 699 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)700 {701 ipc_answer_0(rid, EOK);702 }703 704 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)705 {706 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);707 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);708 int rc;709 710 645 link_t *hlp; 711 646 unsigned long key[] = { 712 [NODES_KEY_DEV] = dev map_handle,647 [NODES_KEY_DEV] = dev_handle, 713 648 [NODES_KEY_INDEX] = index 714 649 }; … … 720 655 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 721 656 nh_link); 657 658 if (size == nodep->size) { 659 ipc_answer_0(rid, EOK); 660 return; 661 } 662 663 void *newdata = realloc(nodep->data, size); 664 if (!newdata) { 665 ipc_answer_0(rid, ENOMEM); 666 return; 667 } 668 if (size > nodep->size) { 669 size_t delta = size - nodep->size; 670 memset(newdata + nodep->size, 0, delta); 671 } 672 nodep->size = size; 673 nodep->data = newdata; 674 ipc_answer_0(rid, EOK); 675 } 676 677 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request) 678 { 679 ipc_answer_0(rid, EOK); 680 } 681 682 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 683 { 684 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 685 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 686 int rc; 687 688 link_t *hlp; 689 unsigned long key[] = { 690 [NODES_KEY_DEV] = dev_handle, 691 [NODES_KEY_INDEX] = index 692 }; 693 hlp = hash_table_find(&nodes, key); 694 if (!hlp) { 695 ipc_answer_0(rid, ENOENT); 696 return; 697 } 698 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 699 nh_link); 722 700 rc = tmpfs_destroy_node(FS_NODE(nodep)); 723 701 ipc_answer_0(rid, rc); … … 736 714 void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request) 737 715 { 738 /* 739 * TMPFS keeps its data structures always consistent, 740 * thus the sync operation is a no-op. 741 */ 716 /* Dummy implementation */ 742 717 ipc_answer_0(rid, EOK); 743 718 }
Note:
See TracChangeset
for help on using the changeset viewer.