Changeset 46c20c8 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c
- Timestamp:
- 2010-11-26T20:08:10Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 45df59a
- Parents:
- fb150d78 (diff), ffdd2b9 (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
rfb150d78 r46c20c8 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> 42 44 #include <async.h> 43 45 #include <errno.h> 44 46 #include <atomic.h> 45 47 #include <stdlib.h> 46 #include <str ing.h>48 #include <str.h> 47 49 #include <stdio.h> 48 50 #include <assert.h> … … 68 70 /* Forward declarations of static functions. */ 69 71 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 70 static int tmpfs_node_get(fs_node_t **, dev _handle_t, fs_index_t);72 static int tmpfs_node_get(fs_node_t **, devmap_handle_t, fs_index_t); 71 73 static int tmpfs_node_open(fs_node_t *); 72 74 static int tmpfs_node_put(fs_node_t *); 73 static int tmpfs_create_node(fs_node_t **, dev _handle_t, int);75 static int tmpfs_create_node(fs_node_t **, devmap_handle_t, int); 74 76 static int tmpfs_destroy_node(fs_node_t *); 75 77 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); … … 77 79 78 80 /* Implementation of helper functions. */ 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);81 static int tmpfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle) 82 { 83 return tmpfs_node_get(rfn, devmap_handle, TMPFS_SOME_ROOT); 82 84 } 83 85 … … 93 95 } 94 96 95 static size_t tmpfs_size_get(fs_node_t *fn)97 static aoff64_t tmpfs_size_get(fs_node_t *fn) 96 98 { 97 99 return TMPFS_NODE(fn)->size; … … 118 120 } 119 121 120 static dev _handle_t tmpfs_device_get(fs_node_t *fn)122 static devmap_handle_t tmpfs_device_get(fs_node_t *fn) 121 123 { 122 124 return 0; … … 163 165 switch (keys) { 164 166 case 1: 165 return (nodep->dev _handle == key[NODES_KEY_DEV]);167 return (nodep->devmap_handle == key[NODES_KEY_DEV]); 166 168 case 2: 167 return ((nodep->dev _handle == key[NODES_KEY_DEV]) &&169 return ((nodep->devmap_handle == key[NODES_KEY_DEV]) && 168 170 (nodep->index == key[NODES_KEY_INDEX])); 169 171 default: … … 207 209 nodep->bp = NULL; 208 210 nodep->index = 0; 209 nodep->dev _handle = 0;211 nodep->devmap_handle = 0; 210 212 nodep->type = TMPFS_NONE; 211 213 nodep->lnkcnt = 0; … … 231 233 } 232 234 233 static bool tmpfs_instance_init(dev _handle_t dev_handle)235 static bool tmpfs_instance_init(devmap_handle_t devmap_handle) 234 236 { 235 237 fs_node_t *rfn; 236 238 int rc; 237 239 238 rc = tmpfs_create_node(&rfn, dev _handle, L_DIRECTORY);240 rc = tmpfs_create_node(&rfn, devmap_handle, L_DIRECTORY); 239 241 if (rc != EOK || !rfn) 240 242 return false; … … 243 245 } 244 246 245 static void tmpfs_instance_done(dev _handle_t dev_handle)247 static void tmpfs_instance_done(devmap_handle_t devmap_handle) 246 248 { 247 249 unsigned long key[] = { 248 [NODES_KEY_DEV] = dev _handle250 [NODES_KEY_DEV] = devmap_handle 249 251 }; 250 252 /* … … 277 279 } 278 280 279 int tmpfs_node_get(fs_node_t **rfn, dev _handle_t dev_handle, fs_index_t index)281 int tmpfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index) 280 282 { 281 283 unsigned long key[] = { 282 [NODES_KEY_DEV] = dev _handle,284 [NODES_KEY_DEV] = devmap_handle, 283 285 [NODES_KEY_INDEX] = index 284 286 }; … … 306 308 } 307 309 308 int tmpfs_create_node(fs_node_t **rfn, dev _handle_t dev_handle, int lflag)310 int tmpfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag) 309 311 { 310 312 fs_node_t *rootfn; … … 325 327 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 326 328 327 rc = tmpfs_root_get(&rootfn, dev _handle);329 rc = tmpfs_root_get(&rootfn, devmap_handle); 328 330 assert(rc == EOK); 329 331 if (!rootfn) … … 331 333 else 332 334 nodep->index = tmpfs_next_index++; 333 nodep->dev _handle = dev_handle;335 nodep->devmap_handle = devmap_handle; 334 336 if (lflag & L_DIRECTORY) 335 337 nodep->type = TMPFS_DIRECTORY; … … 339 341 /* Insert the new node into the nodes hash table. */ 340 342 unsigned long key[] = { 341 [NODES_KEY_DEV] = nodep->dev _handle,343 [NODES_KEY_DEV] = nodep->devmap_handle, 342 344 [NODES_KEY_INDEX] = nodep->index 343 345 }; … … 355 357 356 358 unsigned long key[] = { 357 [NODES_KEY_DEV] = nodep->dev _handle,359 [NODES_KEY_DEV] = nodep->devmap_handle, 358 360 [NODES_KEY_INDEX] = nodep->index 359 361 }; … … 440 442 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 441 443 { 442 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);444 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 443 445 fs_node_t *rootfn; 444 446 int rc; … … 453 455 454 456 /* Check if this device is not already mounted. */ 455 rc = tmpfs_root_get(&rootfn, dev _handle);457 rc = tmpfs_root_get(&rootfn, devmap_handle); 456 458 if ((rc == EOK) && (rootfn)) { 457 459 (void) tmpfs_node_put(rootfn); … … 462 464 463 465 /* Initialize TMPFS instance. */ 464 if (!tmpfs_instance_init(dev _handle)) {466 if (!tmpfs_instance_init(devmap_handle)) { 465 467 free(opts); 466 468 ipc_answer_0(rid, ENOMEM); … … 468 470 } 469 471 470 rc = tmpfs_root_get(&rootfn, dev _handle);472 rc = tmpfs_root_get(&rootfn, devmap_handle); 471 473 assert(rc == EOK); 472 474 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 473 475 if (str_cmp(opts, "restore") == 0) { 474 if (tmpfs_restore(dev _handle))476 if (tmpfs_restore(devmap_handle)) 475 477 ipc_answer_3(rid, EOK, rootp->index, rootp->size, 476 478 rootp->lnkcnt); … … 491 493 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 492 494 { 493 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);494 495 tmpfs_instance_done(dev _handle);495 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 496 497 tmpfs_instance_done(devmap_handle); 496 498 ipc_answer_0(rid, EOK); 497 499 } … … 509 511 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 510 512 { 511 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 512 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 513 off_t pos = (off_t)IPC_GET_ARG3(*request); 514 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 515 518 /* 516 519 * Lookup the respective TMPFS node. … … 518 521 link_t *hlp; 519 522 unsigned long key[] = { 520 [NODES_KEY_DEV] = dev _handle,523 [NODES_KEY_DEV] = devmap_handle, 521 524 [NODES_KEY_INDEX] = index 522 525 }; … … 528 531 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 529 532 nh_link); 530 533 531 534 /* 532 535 * Receive the read request. … … 535 538 size_t size; 536 539 if (!async_data_read_receive(&callid, &size)) { 537 ipc_answer_0(callid, EINVAL); 540 ipc_answer_0(callid, EINVAL); 538 541 ipc_answer_0(rid, EINVAL); 539 542 return; … … 542 545 size_t bytes; 543 546 if (nodep->type == TMPFS_FILE) { 544 bytes = m ax(0, min(nodep->size - pos, size));547 bytes = min(nodep->size - pos, size); 545 548 (void) async_data_read_finalize(callid, nodep->data + pos, 546 549 bytes); … … 548 551 tmpfs_dentry_t *dentryp; 549 552 link_t *lnk; 550 int i;553 aoff64_t i; 551 554 552 555 assert(nodep->type == TMPFS_DIRECTORY); … … 558 561 */ 559 562 for (i = 0, lnk = nodep->cs_head.next; 560 i < pos && lnk != &nodep->cs_head;563 (i < pos) && (lnk != &nodep->cs_head); 561 564 i++, lnk = lnk->next) 562 565 ; … … 583 586 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 584 587 { 585 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 586 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 587 off_t pos = (off_t)IPC_GET_ARG3(*request); 588 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 589 593 /* 590 594 * Lookup the respective TMPFS node. … … 592 596 link_t *hlp; 593 597 unsigned long key[] = { 594 [NODES_KEY_DEV] = dev _handle,598 [NODES_KEY_DEV] = devmap_handle, 595 599 [NODES_KEY_INDEX] = index 596 600 }; … … 647 651 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 648 652 { 649 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 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 658 /* 659 * Lookup the respective TMPFS node. 660 */ 661 unsigned long key[] = { 662 [NODES_KEY_DEV] = devmap_handle, 663 [NODES_KEY_INDEX] = index 664 }; 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); 650 707 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 651 size_t size = (off_t)IPC_GET_ARG3(*request); 652 653 /* 654 * Lookup the respective TMPFS node. 655 */ 708 int rc; 709 656 710 link_t *hlp; 657 711 unsigned long key[] = { 658 [NODES_KEY_DEV] = dev _handle,712 [NODES_KEY_DEV] = devmap_handle, 659 713 [NODES_KEY_INDEX] = index 660 714 }; … … 666 720 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 667 721 nh_link); 668 669 if (size == nodep->size) {670 ipc_answer_0(rid, EOK);671 return;672 }673 674 void *newdata = realloc(nodep->data, size);675 if (!newdata) {676 ipc_answer_0(rid, ENOMEM);677 return;678 }679 if (size > nodep->size) {680 size_t delta = size - nodep->size;681 memset(newdata + nodep->size, 0, delta);682 }683 nodep->size = size;684 nodep->data = newdata;685 ipc_answer_0(rid, EOK);686 }687 688 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)689 {690 ipc_answer_0(rid, EOK);691 }692 693 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)694 {695 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);696 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);697 int rc;698 699 link_t *hlp;700 unsigned long key[] = {701 [NODES_KEY_DEV] = dev_handle,702 [NODES_KEY_INDEX] = index703 };704 hlp = hash_table_find(&nodes, key);705 if (!hlp) {706 ipc_answer_0(rid, ENOENT);707 return;708 }709 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,710 nh_link);711 722 rc = tmpfs_destroy_node(FS_NODE(nodep)); 712 723 ipc_answer_0(rid, rc); … … 725 736 void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request) 726 737 { 727 /* Dummy implementation */ 738 /* 739 * TMPFS keeps its data structures always consistent, 740 * thus the sync operation is a no-op. 741 */ 728 742 ipc_answer_0(rid, EOK); 729 743 }
Note:
See TracChangeset
for help on using the changeset viewer.