Changeset 46c20c8 in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2010-11-26T20:08:10Z (15 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/fat/fat_ops.c
rfb150d78 r46c20c8 45 45 #include <ipc/services.h> 46 46 #include <ipc/devmap.h> 47 #include <macros.h> 47 48 #include <async.h> 48 49 #include <errno.h> 49 #include <str ing.h>50 #include <str.h> 50 51 #include <byteorder.h> 51 52 #include <adt/hash_table.h> … … 59 60 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 60 61 62 #define DPS(bs) (BPS((bs)) / sizeof(fat_dentry_t)) 63 #define BPC(bs) (BPS((bs)) * SPC((bs))) 64 61 65 /** Mutex protecting the list of cached free FAT nodes. */ 62 66 static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); … … 68 72 * Forward declarations of FAT libfs operations. 69 73 */ 70 static int fat_root_get(fs_node_t **, dev _handle_t);74 static int fat_root_get(fs_node_t **, devmap_handle_t); 71 75 static int fat_match(fs_node_t **, fs_node_t *, const char *); 72 static int fat_node_get(fs_node_t **, dev _handle_t, fs_index_t);76 static int fat_node_get(fs_node_t **, devmap_handle_t, fs_index_t); 73 77 static int fat_node_open(fs_node_t *); 74 78 static int fat_node_put(fs_node_t *); 75 static int fat_create_node(fs_node_t **, dev _handle_t, int);79 static int fat_create_node(fs_node_t **, devmap_handle_t, int); 76 80 static int fat_destroy_node(fs_node_t *); 77 81 static int fat_link(fs_node_t *, fs_node_t *, const char *); … … 79 83 static int fat_has_children(bool *, fs_node_t *); 80 84 static fs_index_t fat_index_get(fs_node_t *); 81 static size_t fat_size_get(fs_node_t *);85 static aoff64_t fat_size_get(fs_node_t *); 82 86 static unsigned fat_lnkcnt_get(fs_node_t *); 83 87 static char fat_plb_get_char(unsigned); 84 88 static bool fat_is_directory(fs_node_t *); 85 89 static bool fat_is_file(fs_node_t *node); 86 static dev _handle_t fat_device_get(fs_node_t *node);90 static devmap_handle_t fat_device_get(fs_node_t *node); 87 91 88 92 /* … … 100 104 node->refcnt = 0; 101 105 node->dirty = false; 106 node->lastc_cached_valid = false; 107 node->lastc_cached_value = FAT_CLST_LAST1; 108 node->currc_cached_valid = false; 109 node->currc_cached_bn = 0; 110 node->currc_cached_value = FAT_CLST_LAST1; 102 111 } 103 112 … … 107 116 fat_bs_t *bs; 108 117 fat_dentry_t *d; 109 uint16_t bps;110 unsigned dps;111 118 int rc; 112 119 113 120 assert(node->dirty); 114 121 115 bs = block_bb_get(node->idx->dev_handle); 116 bps = uint16_t_le2host(bs->bps); 117 dps = bps / sizeof(fat_dentry_t); 122 bs = block_bb_get(node->idx->devmap_handle); 118 123 119 124 /* Read the block that contains the dentry of interest. */ 120 rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc, 121 (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE); 125 rc = _fat_block_get(&b, bs, node->idx->devmap_handle, node->idx->pfc, 126 NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 127 BLOCK_FLAGS_NONE); 122 128 if (rc != EOK) 123 129 return rc; 124 130 125 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);131 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs)); 126 132 127 133 d->firstc = host2uint16_t_le(node->firstc); … … 139 145 } 140 146 141 static int fat_node_fini_by_dev _handle(dev_handle_t dev_handle)147 static int fat_node_fini_by_devmap_handle(devmap_handle_t devmap_handle) 142 148 { 143 149 link_t *lnk; … … 164 170 goto restart; 165 171 } 166 if (nodep->idx->dev _handle != dev_handle) {172 if (nodep->idx->devmap_handle != devmap_handle) { 167 173 fibril_mutex_unlock(&nodep->idx->lock); 168 174 fibril_mutex_unlock(&nodep->lock); … … 265 271 fat_dentry_t *d; 266 272 fat_node_t *nodep = NULL; 267 unsigned bps;268 unsigned spc;269 unsigned dps;270 273 int rc; 271 274 … … 296 299 return rc; 297 300 298 bs = block_bb_get(idxp->dev_handle); 299 bps = uint16_t_le2host(bs->bps); 300 spc = bs->spc; 301 dps = bps / sizeof(fat_dentry_t); 301 bs = block_bb_get(idxp->devmap_handle); 302 302 303 303 /* Read the block that contains the dentry of interest. */ 304 rc = _fat_block_get(&b, bs, idxp->dev _handle, idxp->pfc,305 (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);304 rc = _fat_block_get(&b, bs, idxp->devmap_handle, idxp->pfc, NULL, 305 (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE); 306 306 if (rc != EOK) { 307 307 (void) fat_node_put(FS_NODE(nodep)); … … 309 309 } 310 310 311 d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);311 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 312 312 if (d->attr & FAT_ATTR_SUBDIR) { 313 313 /* … … 323 323 */ 324 324 uint16_t clusters; 325 rc = fat_clusters_get(&clusters, bs, idxp->dev _handle,325 rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle, 326 326 uint16_t_le2host(d->firstc)); 327 327 if (rc != EOK) { … … 329 329 return rc; 330 330 } 331 nodep->size = bps * spc* clusters;331 nodep->size = BPS(bs) * SPC(bs) * clusters; 332 332 } else { 333 333 nodep->type = FAT_FILE; … … 356 356 */ 357 357 358 int fat_root_get(fs_node_t **rfn, dev _handle_t dev_handle)359 { 360 return fat_node_get(rfn, dev _handle, 0);358 int fat_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle) 359 { 360 return fat_node_get(rfn, devmap_handle, 0); 361 361 } 362 362 … … 367 367 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 368 368 unsigned i, j; 369 unsigned bps; /* bytes per sector */370 unsigned dps; /* dentries per sector */371 369 unsigned blocks; 372 370 fat_dentry_t *d; 371 devmap_handle_t devmap_handle; 373 372 block_t *b; 374 373 int rc; 375 374 376 375 fibril_mutex_lock(&parentp->idx->lock); 377 bs = block_bb_get(parentp->idx->dev_handle); 378 bps = uint16_t_le2host(bs->bps); 379 dps = bps / sizeof(fat_dentry_t); 380 blocks = parentp->size / bps; 376 devmap_handle = parentp->idx->devmap_handle; 377 fibril_mutex_unlock(&parentp->idx->lock); 378 379 bs = block_bb_get(devmap_handle); 380 blocks = parentp->size / BPS(bs); 381 381 for (i = 0; i < blocks; i++) { 382 382 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); 383 if (rc != EOK) { 384 fibril_mutex_unlock(&parentp->idx->lock); 383 if (rc != EOK) 385 384 return rc; 386 } 387 for (j = 0; j < dps; j++) { 385 for (j = 0; j < DPS(bs); j++) { 388 386 d = ((fat_dentry_t *)b->data) + j; 389 387 switch (fat_classify_dentry(d)) { … … 394 392 /* miss */ 395 393 rc = block_put(b); 396 fibril_mutex_unlock(&parentp->idx->lock);397 394 *rfn = NULL; 398 395 return rc; … … 405 402 /* hit */ 406 403 fat_node_t *nodep; 407 /* 408 * Assume tree hierarchy for locking. We 409 * already have the parent and now we are going 410 * to lock the child. Never lock in the oposite 411 * order. 412 */ 413 fat_idx_t *idx = fat_idx_get_by_pos( 414 parentp->idx->dev_handle, parentp->firstc, 415 i * dps + j); 416 fibril_mutex_unlock(&parentp->idx->lock); 404 fat_idx_t *idx = fat_idx_get_by_pos(devmap_handle, 405 parentp->firstc, i * DPS(bs) + j); 417 406 if (!idx) { 418 407 /* … … 437 426 } 438 427 rc = block_put(b); 439 if (rc != EOK) { 440 fibril_mutex_unlock(&parentp->idx->lock); 428 if (rc != EOK) 441 429 return rc; 442 } 443 } 444 445 fibril_mutex_unlock(&parentp->idx->lock); 430 } 431 446 432 *rfn = NULL; 447 433 return EOK; … … 449 435 450 436 /** Instantiate a FAT in-core node. */ 451 int fat_node_get(fs_node_t **rfn, dev _handle_t dev_handle, fs_index_t index)437 int fat_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index) 452 438 { 453 439 fat_node_t *nodep; … … 455 441 int rc; 456 442 457 idxp = fat_idx_get_by_index(dev _handle, index);443 idxp = fat_idx_get_by_index(devmap_handle, index); 458 444 if (!idxp) { 459 445 *rfn = NULL; … … 506 492 } 507 493 508 int fat_create_node(fs_node_t **rfn, dev _handle_t dev_handle, int flags)494 int fat_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags) 509 495 { 510 496 fat_idx_t *idxp; … … 512 498 fat_bs_t *bs; 513 499 fat_cluster_t mcl, lcl; 514 uint16_t bps;515 500 int rc; 516 501 517 bs = block_bb_get(dev_handle); 518 bps = uint16_t_le2host(bs->bps); 502 bs = block_bb_get(devmap_handle); 519 503 if (flags & L_DIRECTORY) { 520 504 /* allocate a cluster */ 521 rc = fat_alloc_clusters(bs, dev _handle, 1, &mcl, &lcl);505 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl); 522 506 if (rc != EOK) 523 507 return rc; 524 508 /* populate the new cluster with unused dentries */ 525 rc = fat_zero_cluster(bs, dev _handle, mcl);509 rc = fat_zero_cluster(bs, devmap_handle, mcl); 526 510 if (rc != EOK) { 527 (void) fat_free_clusters(bs, dev _handle, mcl);511 (void) fat_free_clusters(bs, devmap_handle, mcl); 528 512 return rc; 529 513 } … … 532 516 rc = fat_node_get_new(&nodep); 533 517 if (rc != EOK) { 534 (void) fat_free_clusters(bs, dev _handle, mcl);518 (void) fat_free_clusters(bs, devmap_handle, mcl); 535 519 return rc; 536 520 } 537 rc = fat_idx_get_new(&idxp, dev _handle);538 if (rc != EOK) { 539 (void) fat_free_clusters(bs, dev _handle, mcl);521 rc = fat_idx_get_new(&idxp, devmap_handle); 522 if (rc != EOK) { 523 (void) fat_free_clusters(bs, devmap_handle, mcl); 540 524 (void) fat_node_put(FS_NODE(nodep)); 541 525 return rc; … … 545 529 nodep->type = FAT_DIRECTORY; 546 530 nodep->firstc = mcl; 547 nodep->size = bps * bs->spc;531 nodep->size = BPS(bs) * SPC(bs); 548 532 } else { 549 533 nodep->type = FAT_FILE; … … 586 570 assert(!has_children); 587 571 588 bs = block_bb_get(nodep->idx->dev _handle);572 bs = block_bb_get(nodep->idx->devmap_handle); 589 573 if (nodep->firstc != FAT_CLST_RES0) { 590 574 assert(nodep->size); 591 575 /* Free all clusters allocated to the node. */ 592 rc = fat_free_clusters(bs, nodep->idx->dev _handle,576 rc = fat_free_clusters(bs, nodep->idx->devmap_handle, 593 577 nodep->firstc); 594 578 } … … 608 592 block_t *b; 609 593 unsigned i, j; 610 uint16_t bps;611 unsigned dps;612 594 unsigned blocks; 613 595 fat_cluster_t mcl, lcl; … … 638 620 639 621 fibril_mutex_lock(&parentp->idx->lock); 640 bs = block_bb_get(parentp->idx->dev_handle); 641 bps = uint16_t_le2host(bs->bps); 642 dps = bps / sizeof(fat_dentry_t); 643 644 blocks = parentp->size / bps; 622 bs = block_bb_get(parentp->idx->devmap_handle); 623 624 blocks = parentp->size / BPS(bs); 645 625 646 626 for (i = 0; i < blocks; i++) { … … 650 630 return rc; 651 631 } 652 for (j = 0; j < dps; j++) {632 for (j = 0; j < DPS(bs); j++) { 653 633 d = ((fat_dentry_t *)b->data) + j; 654 634 switch (fat_classify_dentry(d)) { … … 679 659 return ENOSPC; 680 660 } 681 rc = fat_alloc_clusters(bs, parentp->idx->dev _handle, 1, &mcl, &lcl);661 rc = fat_alloc_clusters(bs, parentp->idx->devmap_handle, 1, &mcl, &lcl); 682 662 if (rc != EOK) { 683 663 fibril_mutex_unlock(&parentp->idx->lock); 684 664 return rc; 685 665 } 686 rc = fat_zero_cluster(bs, parentp->idx->dev _handle, mcl);687 if (rc != EOK) { 688 (void) fat_free_clusters(bs, parentp->idx->dev _handle, mcl);666 rc = fat_zero_cluster(bs, parentp->idx->devmap_handle, mcl); 667 if (rc != EOK) { 668 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl); 689 669 fibril_mutex_unlock(&parentp->idx->lock); 690 670 return rc; 691 671 } 692 rc = fat_append_clusters(bs, parentp, mcl );693 if (rc != EOK) { 694 (void) fat_free_clusters(bs, parentp->idx->dev _handle, mcl);672 rc = fat_append_clusters(bs, parentp, mcl, lcl); 673 if (rc != EOK) { 674 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl); 695 675 fibril_mutex_unlock(&parentp->idx->lock); 696 676 return rc; 697 677 } 698 parentp->size += bps * bs->spc;678 parentp->size += BPS(bs) * SPC(bs); 699 679 parentp->dirty = true; /* need to sync node */ 700 680 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 722 702 fibril_mutex_lock(&childp->idx->lock); 723 703 724 /* 725 * If possible, create the Sub-directory Identifier Entry and the 726 * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries 727 * are not mandatory according to Standard ECMA-107 and HelenOS VFS does 728 * not use them anyway, so this is rather a sign of our good will. 729 */ 730 rc = fat_block_get(&b, bs, childp, 0, BLOCK_FLAGS_NONE); 731 if (rc != EOK) { 704 if (childp->type == FAT_DIRECTORY) { 732 705 /* 733 * Rather than returning an error, simply skip the creation of 734 * these two entries. 706 * If possible, create the Sub-directory Identifier Entry and 707 * the Sub-directory Parent Pointer Entry (i.e. "." and ".."). 708 * These entries are not mandatory according to Standard 709 * ECMA-107 and HelenOS VFS does not use them anyway, so this is 710 * rather a sign of our good will. 735 711 */ 736 goto skip_dots; 737 } 738 d = (fat_dentry_t *)b->data; 739 if (fat_classify_dentry(d) == FAT_DENTRY_LAST || 740 str_cmp(d->name, FAT_NAME_DOT) == 0) { 741 memset(d, 0, sizeof(fat_dentry_t)); 742 str_cpy(d->name, 8, FAT_NAME_DOT); 743 str_cpy(d->ext, 3, FAT_EXT_PAD); 744 d->attr = FAT_ATTR_SUBDIR; 745 d->firstc = host2uint16_t_le(childp->firstc); 746 /* TODO: initialize also the date/time members. */ 747 } 748 d++; 749 if (fat_classify_dentry(d) == FAT_DENTRY_LAST || 750 str_cmp(d->name, FAT_NAME_DOT_DOT) == 0) { 751 memset(d, 0, sizeof(fat_dentry_t)); 752 str_cpy(d->name, 8, FAT_NAME_DOT_DOT); 753 str_cpy(d->ext, 3, FAT_EXT_PAD); 754 d->attr = FAT_ATTR_SUBDIR; 755 d->firstc = (parentp->firstc == FAT_CLST_ROOT) ? 756 host2uint16_t_le(FAT_CLST_RES0) : 757 host2uint16_t_le(parentp->firstc); 758 /* TODO: initialize also the date/time members. */ 759 } 760 b->dirty = true; /* need to sync block */ 761 /* 762 * Ignore the return value as we would have fallen through on error 763 * anyway. 764 */ 765 (void) block_put(b); 712 rc = fat_block_get(&b, bs, childp, 0, BLOCK_FLAGS_NONE); 713 if (rc != EOK) { 714 /* 715 * Rather than returning an error, simply skip the 716 * creation of these two entries. 717 */ 718 goto skip_dots; 719 } 720 d = (fat_dentry_t *) b->data; 721 if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) || 722 (str_cmp((char *) d->name, FAT_NAME_DOT)) == 0) { 723 memset(d, 0, sizeof(fat_dentry_t)); 724 str_cpy((char *) d->name, 8, FAT_NAME_DOT); 725 str_cpy((char *) d->ext, 3, FAT_EXT_PAD); 726 d->attr = FAT_ATTR_SUBDIR; 727 d->firstc = host2uint16_t_le(childp->firstc); 728 /* TODO: initialize also the date/time members. */ 729 } 730 d++; 731 if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) || 732 (str_cmp((char *) d->name, FAT_NAME_DOT_DOT) == 0)) { 733 memset(d, 0, sizeof(fat_dentry_t)); 734 str_cpy((char *) d->name, 8, FAT_NAME_DOT_DOT); 735 str_cpy((char *) d->ext, 3, FAT_EXT_PAD); 736 d->attr = FAT_ATTR_SUBDIR; 737 d->firstc = (parentp->firstc == FAT_CLST_ROOT) ? 738 host2uint16_t_le(FAT_CLST_RES0) : 739 host2uint16_t_le(parentp->firstc); 740 /* TODO: initialize also the date/time members. */ 741 } 742 b->dirty = true; /* need to sync block */ 743 /* 744 * Ignore the return value as we would have fallen through on error 745 * anyway. 746 */ 747 (void) block_put(b); 748 } 766 749 skip_dots: 767 750 768 751 childp->idx->pfc = parentp->firstc; 769 childp->idx->pdi = i * dps+ j;752 childp->idx->pdi = i * DPS(bs) + j; 770 753 fibril_mutex_unlock(&childp->idx->lock); 771 754 … … 789 772 fat_bs_t *bs; 790 773 fat_dentry_t *d; 791 uint16_t bps;792 774 block_t *b; 793 775 bool has_children; … … 807 789 assert(childp->lnkcnt == 1); 808 790 fibril_mutex_lock(&childp->idx->lock); 809 bs = block_bb_get(childp->idx->dev_handle); 810 bps = uint16_t_le2host(bs->bps); 811 812 rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc, 813 (childp->idx->pdi * sizeof(fat_dentry_t)) / bps, 791 bs = block_bb_get(childp->idx->devmap_handle); 792 793 rc = _fat_block_get(&b, bs, childp->idx->devmap_handle, childp->idx->pfc, 794 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 814 795 BLOCK_FLAGS_NONE); 815 796 if (rc != EOK) 816 797 goto error; 817 798 d = (fat_dentry_t *)b->data + 818 (childp->idx->pdi % ( bps/ sizeof(fat_dentry_t)));799 (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t))); 819 800 /* mark the dentry as not-currently-used */ 820 801 d->name[0] = FAT_DENTRY_ERASED; … … 848 829 fat_bs_t *bs; 849 830 fat_node_t *nodep = FAT_NODE(fn); 850 unsigned bps;851 unsigned dps;852 831 unsigned blocks; 853 832 block_t *b; … … 861 840 862 841 fibril_mutex_lock(&nodep->idx->lock); 863 bs = block_bb_get(nodep->idx->dev_handle); 864 bps = uint16_t_le2host(bs->bps); 865 dps = bps / sizeof(fat_dentry_t); 866 867 blocks = nodep->size / bps; 842 bs = block_bb_get(nodep->idx->devmap_handle); 843 844 blocks = nodep->size / BPS(bs); 868 845 869 846 for (i = 0; i < blocks; i++) { … … 875 852 return rc; 876 853 } 877 for (j = 0; j < dps; j++) {854 for (j = 0; j < DPS(bs); j++) { 878 855 d = ((fat_dentry_t *)b->data) + j; 879 856 switch (fat_classify_dentry(d)) { … … 912 889 } 913 890 914 size_t fat_size_get(fs_node_t *fn)891 aoff64_t fat_size_get(fs_node_t *fn) 915 892 { 916 893 return FAT_NODE(fn)->size; … … 937 914 } 938 915 939 dev _handle_t fat_device_get(fs_node_t *node)916 devmap_handle_t fat_device_get(fs_node_t *node) 940 917 { 941 918 return 0; … … 969 946 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 970 947 { 971 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);948 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 972 949 enum cache_mode cmode; 973 950 fat_bs_t *bs; 974 uint16_t bps;975 uint16_t rde;976 951 977 952 /* Accept the mount options */ … … 993 968 994 969 /* initialize libblock */ 995 rc = block_init(dev _handle, BS_SIZE);970 rc = block_init(devmap_handle, BS_SIZE); 996 971 if (rc != EOK) { 997 972 ipc_answer_0(rid, rc); … … 1000 975 1001 976 /* prepare the boot block */ 1002 rc = block_bb_read(dev _handle, BS_BLOCK);1003 if (rc != EOK) { 1004 block_fini(dev _handle);977 rc = block_bb_read(devmap_handle, BS_BLOCK); 978 if (rc != EOK) { 979 block_fini(devmap_handle); 1005 980 ipc_answer_0(rid, rc); 1006 981 return; … … 1008 983 1009 984 /* get the buffer with the boot sector */ 1010 bs = block_bb_get(dev_handle); 1011 1012 /* Read the number of root directory entries. */ 1013 bps = uint16_t_le2host(bs->bps); 1014 rde = uint16_t_le2host(bs->root_ent_max); 1015 1016 if (bps != BS_SIZE) { 1017 block_fini(dev_handle); 985 bs = block_bb_get(devmap_handle); 986 987 if (BPS(bs) != BS_SIZE) { 988 block_fini(devmap_handle); 1018 989 ipc_answer_0(rid, ENOTSUP); 1019 990 return; … … 1021 992 1022 993 /* Initialize the block cache */ 1023 rc = block_cache_init(dev _handle, bps, 0 /* XXX */, cmode);1024 if (rc != EOK) { 1025 block_fini(dev _handle);994 rc = block_cache_init(devmap_handle, BPS(bs), 0 /* XXX */, cmode); 995 if (rc != EOK) { 996 block_fini(devmap_handle); 1026 997 ipc_answer_0(rid, rc); 1027 998 return; … … 1029 1000 1030 1001 /* Do some simple sanity checks on the file system. */ 1031 rc = fat_sanity_check(bs, dev _handle);1032 if (rc != EOK) { 1033 (void) block_cache_fini(dev _handle);1034 block_fini(dev _handle);1002 rc = fat_sanity_check(bs, devmap_handle); 1003 if (rc != EOK) { 1004 (void) block_cache_fini(devmap_handle); 1005 block_fini(devmap_handle); 1035 1006 ipc_answer_0(rid, rc); 1036 1007 return; 1037 1008 } 1038 1009 1039 rc = fat_idx_init_by_dev _handle(dev_handle);1040 if (rc != EOK) { 1041 (void) block_cache_fini(dev _handle);1042 block_fini(dev _handle);1010 rc = fat_idx_init_by_devmap_handle(devmap_handle); 1011 if (rc != EOK) { 1012 (void) block_cache_fini(devmap_handle); 1013 block_fini(devmap_handle); 1043 1014 ipc_answer_0(rid, rc); 1044 1015 return; … … 1048 1019 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 1049 1020 if (!rfn) { 1050 (void) block_cache_fini(dev _handle);1051 block_fini(dev _handle);1052 fat_idx_fini_by_dev _handle(dev_handle);1021 (void) block_cache_fini(devmap_handle); 1022 block_fini(devmap_handle); 1023 fat_idx_fini_by_devmap_handle(devmap_handle); 1053 1024 ipc_answer_0(rid, ENOMEM); 1054 1025 return; … … 1058 1029 if (!rootp) { 1059 1030 free(rfn); 1060 (void) block_cache_fini(dev _handle);1061 block_fini(dev _handle);1062 fat_idx_fini_by_dev _handle(dev_handle);1031 (void) block_cache_fini(devmap_handle); 1032 block_fini(devmap_handle); 1033 fat_idx_fini_by_devmap_handle(devmap_handle); 1063 1034 ipc_answer_0(rid, ENOMEM); 1064 1035 return; … … 1066 1037 fat_node_initialize(rootp); 1067 1038 1068 fat_idx_t *ridxp = fat_idx_get_by_pos(dev _handle, FAT_CLST_ROOTPAR, 0);1039 fat_idx_t *ridxp = fat_idx_get_by_pos(devmap_handle, FAT_CLST_ROOTPAR, 0); 1069 1040 if (!ridxp) { 1070 1041 free(rfn); 1071 1042 free(rootp); 1072 (void) block_cache_fini(dev _handle);1073 block_fini(dev _handle);1074 fat_idx_fini_by_dev _handle(dev_handle);1043 (void) block_cache_fini(devmap_handle); 1044 block_fini(devmap_handle); 1045 fat_idx_fini_by_devmap_handle(devmap_handle); 1075 1046 ipc_answer_0(rid, ENOMEM); 1076 1047 return; … … 1083 1054 rootp->refcnt = 1; 1084 1055 rootp->lnkcnt = 0; /* FS root is not linked */ 1085 rootp->size = rde* sizeof(fat_dentry_t);1056 rootp->size = RDE(bs) * sizeof(fat_dentry_t); 1086 1057 rootp->idx = ridxp; 1087 1058 ridxp->nodep = rootp; … … 1101 1072 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1102 1073 { 1103 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1074 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1104 1075 fs_node_t *fn; 1105 1076 fat_node_t *nodep; 1106 1077 int rc; 1107 1078 1108 rc = fat_root_get(&fn, dev _handle);1079 rc = fat_root_get(&fn, devmap_handle); 1109 1080 if (rc != EOK) { 1110 1081 ipc_answer_0(rid, rc); … … 1134 1105 * stop using libblock for this instance. 1135 1106 */ 1136 (void) fat_node_fini_by_dev _handle(dev_handle);1137 fat_idx_fini_by_dev _handle(dev_handle);1138 (void) block_cache_fini(dev _handle);1139 block_fini(dev _handle);1107 (void) fat_node_fini_by_devmap_handle(devmap_handle); 1108 fat_idx_fini_by_devmap_handle(devmap_handle); 1109 (void) block_cache_fini(devmap_handle); 1110 block_fini(devmap_handle); 1140 1111 1141 1112 ipc_answer_0(rid, EOK); … … 1154 1125 void fat_read(ipc_callid_t rid, ipc_call_t *request) 1155 1126 { 1156 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 1157 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1158 off_t pos = (off_t)IPC_GET_ARG3(*request); 1127 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1128 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1129 aoff64_t pos = 1130 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1159 1131 fs_node_t *fn; 1160 1132 fat_node_t *nodep; 1161 1133 fat_bs_t *bs; 1162 uint16_t bps;1163 1134 size_t bytes; 1164 1135 block_t *b; 1165 1136 int rc; 1166 1137 1167 rc = fat_node_get(&fn, dev _handle, index);1138 rc = fat_node_get(&fn, devmap_handle, index); 1168 1139 if (rc != EOK) { 1169 1140 ipc_answer_0(rid, rc); … … 1185 1156 } 1186 1157 1187 bs = block_bb_get(dev_handle); 1188 bps = uint16_t_le2host(bs->bps); 1158 bs = block_bb_get(devmap_handle); 1189 1159 1190 1160 if (nodep->type == FAT_FILE) { … … 1199 1169 (void) async_data_read_finalize(callid, NULL, 0); 1200 1170 } else { 1201 bytes = min(len, bps - pos % bps);1171 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1202 1172 bytes = min(bytes, nodep->size - pos); 1203 rc = fat_block_get(&b, bs, nodep, pos / bps,1173 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), 1204 1174 BLOCK_FLAGS_NONE); 1205 1175 if (rc != EOK) { … … 1209 1179 return; 1210 1180 } 1211 (void) async_data_read_finalize(callid, b->data + pos % bps,1212 b ytes);1181 (void) async_data_read_finalize(callid, 1182 b->data + pos % BPS(bs), bytes); 1213 1183 rc = block_put(b); 1214 1184 if (rc != EOK) { … … 1220 1190 } else { 1221 1191 unsigned bnum; 1222 off_t spos = pos;1192 aoff64_t spos = pos; 1223 1193 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 1224 1194 fat_dentry_t *d; 1225 1195 1226 1196 assert(nodep->type == FAT_DIRECTORY); 1227 assert(nodep->size % bps== 0);1228 assert( bps% sizeof(fat_dentry_t) == 0);1197 assert(nodep->size % BPS(bs) == 0); 1198 assert(BPS(bs) % sizeof(fat_dentry_t) == 0); 1229 1199 1230 1200 /* … … 1234 1204 * the position pointer accordingly. 1235 1205 */ 1236 bnum = (pos * sizeof(fat_dentry_t)) / bps;1237 while (bnum < nodep->size / bps) {1238 off_t o;1206 bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs); 1207 while (bnum < nodep->size / BPS(bs)) { 1208 aoff64_t o; 1239 1209 1240 1210 rc = fat_block_get(&b, bs, nodep, bnum, … … 1242 1212 if (rc != EOK) 1243 1213 goto err; 1244 for (o = pos % ( bps/ sizeof(fat_dentry_t));1245 o < bps/ sizeof(fat_dentry_t);1214 for (o = pos % (BPS(bs) / sizeof(fat_dentry_t)); 1215 o < BPS(bs) / sizeof(fat_dentry_t); 1246 1216 o++, pos++) { 1247 1217 d = ((fat_dentry_t *)b->data) + o; … … 1292 1262 void fat_write(ipc_callid_t rid, ipc_call_t *request) 1293 1263 { 1294 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 1295 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1296 off_t pos = (off_t)IPC_GET_ARG3(*request); 1264 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1265 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1266 aoff64_t pos = 1267 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1297 1268 fs_node_t *fn; 1298 1269 fat_node_t *nodep; … … 1300 1271 size_t bytes, size; 1301 1272 block_t *b; 1302 uint16_t bps; 1303 unsigned spc; 1304 unsigned bpc; /* bytes per cluster */ 1305 off_t boundary; 1273 aoff64_t boundary; 1306 1274 int flags = BLOCK_FLAGS_NONE; 1307 1275 int rc; 1308 1276 1309 rc = fat_node_get(&fn, dev _handle, index);1277 rc = fat_node_get(&fn, devmap_handle, index); 1310 1278 if (rc != EOK) { 1311 1279 ipc_answer_0(rid, rc); … … 1327 1295 } 1328 1296 1329 bs = block_bb_get(dev_handle); 1330 bps = uint16_t_le2host(bs->bps); 1331 spc = bs->spc; 1332 bpc = bps * spc; 1297 bs = block_bb_get(devmap_handle); 1333 1298 1334 1299 /* … … 1339 1304 * value signalizing a smaller number of bytes written. 1340 1305 */ 1341 bytes = min(len, bps - pos % bps);1342 if (bytes == bps)1306 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1307 if (bytes == BPS(bs)) 1343 1308 flags |= BLOCK_FLAGS_NOREAD; 1344 1309 1345 boundary = ROUND_UP(nodep->size, bpc);1310 boundary = ROUND_UP(nodep->size, BPC(bs)); 1346 1311 if (pos < boundary) { 1347 1312 /* … … 1358 1323 return; 1359 1324 } 1360 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);1325 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags); 1361 1326 if (rc != EOK) { 1362 1327 (void) fat_node_put(fn); … … 1365 1330 return; 1366 1331 } 1367 (void) async_data_write_finalize(callid, b->data + pos % bps,1368 b ytes);1332 (void) async_data_write_finalize(callid, 1333 b->data + pos % BPS(bs), bytes); 1369 1334 b->dirty = true; /* need to sync block */ 1370 1335 rc = block_put(b); … … 1390 1355 fat_cluster_t mcl, lcl; 1391 1356 1392 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;1357 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1393 1358 /* create an independent chain of nclsts clusters in all FATs */ 1394 rc = fat_alloc_clusters(bs, dev _handle, nclsts, &mcl, &lcl);1359 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl); 1395 1360 if (rc != EOK) { 1396 1361 /* could not allocate a chain of nclsts clusters */ … … 1403 1368 rc = fat_fill_gap(bs, nodep, mcl, pos); 1404 1369 if (rc != EOK) { 1405 (void) fat_free_clusters(bs, dev _handle, mcl);1370 (void) fat_free_clusters(bs, devmap_handle, mcl); 1406 1371 (void) fat_node_put(fn); 1407 1372 ipc_answer_0(callid, rc); … … 1409 1374 return; 1410 1375 } 1411 rc = _fat_block_get(&b, bs, dev _handle, lcl, (pos / bps) % spc,1412 flags);1376 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL, 1377 (pos / BPS(bs)) % SPC(bs), flags); 1413 1378 if (rc != EOK) { 1414 (void) fat_free_clusters(bs, dev _handle, mcl);1379 (void) fat_free_clusters(bs, devmap_handle, mcl); 1415 1380 (void) fat_node_put(fn); 1416 1381 ipc_answer_0(callid, rc); … … 1418 1383 return; 1419 1384 } 1420 (void) async_data_write_finalize(callid, b->data + pos % bps,1421 b ytes);1385 (void) async_data_write_finalize(callid, 1386 b->data + pos % BPS(bs), bytes); 1422 1387 b->dirty = true; /* need to sync block */ 1423 1388 rc = block_put(b); 1424 1389 if (rc != EOK) { 1425 (void) fat_free_clusters(bs, dev _handle, mcl);1390 (void) fat_free_clusters(bs, devmap_handle, mcl); 1426 1391 (void) fat_node_put(fn); 1427 1392 ipc_answer_0(rid, rc); … … 1432 1397 * node's cluster chain. 1433 1398 */ 1434 rc = fat_append_clusters(bs, nodep, mcl );1399 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1435 1400 if (rc != EOK) { 1436 (void) fat_free_clusters(bs, dev _handle, mcl);1401 (void) fat_free_clusters(bs, devmap_handle, mcl); 1437 1402 (void) fat_node_put(fn); 1438 1403 ipc_answer_0(rid, rc); … … 1449 1414 void fat_truncate(ipc_callid_t rid, ipc_call_t *request) 1450 1415 { 1451 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 1452 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1453 size_t size = (off_t)IPC_GET_ARG3(*request); 1416 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1417 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1418 aoff64_t size = 1419 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1454 1420 fs_node_t *fn; 1455 1421 fat_node_t *nodep; 1456 1422 fat_bs_t *bs; 1457 uint16_t bps;1458 uint8_t spc;1459 unsigned bpc; /* bytes per cluster */1460 1423 int rc; 1461 1424 1462 rc = fat_node_get(&fn, dev _handle, index);1425 rc = fat_node_get(&fn, devmap_handle, index); 1463 1426 if (rc != EOK) { 1464 1427 ipc_answer_0(rid, rc); … … 1471 1434 nodep = FAT_NODE(fn); 1472 1435 1473 bs = block_bb_get(dev_handle); 1474 bps = uint16_t_le2host(bs->bps); 1475 spc = bs->spc; 1476 bpc = bps * spc; 1436 bs = block_bb_get(devmap_handle); 1477 1437 1478 1438 if (nodep->size == size) { … … 1484 1444 */ 1485 1445 rc = EINVAL; 1486 } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {1446 } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) { 1487 1447 /* 1488 1448 * The node will be shrunk, but no clusters will be deallocated. … … 1501 1461 } else { 1502 1462 fat_cluster_t lastc; 1503 rc = fat_cluster_walk(bs, dev _handle, nodep->firstc,1504 &lastc, NULL, (size - 1) / bpc);1463 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc, 1464 &lastc, NULL, (size - 1) / BPC(bs)); 1505 1465 if (rc != EOK) 1506 1466 goto out; … … 1526 1486 void fat_destroy(ipc_callid_t rid, ipc_call_t *request) 1527 1487 { 1528 dev _handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);1488 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request); 1529 1489 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1530 1490 fs_node_t *fn; 1531 1491 int rc; 1532 1492 1533 rc = fat_node_get(&fn, dev _handle, index);1493 rc = fat_node_get(&fn, devmap_handle, index); 1534 1494 if (rc != EOK) { 1535 1495 ipc_answer_0(rid, rc); … … 1557 1517 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1558 1518 { 1559 /* Dummy implementation */ 1560 ipc_answer_0(rid, EOK); 1519 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1520 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1521 1522 fs_node_t *fn; 1523 int rc = fat_node_get(&fn, devmap_handle, index); 1524 if (rc != EOK) { 1525 ipc_answer_0(rid, rc); 1526 return; 1527 } 1528 if (!fn) { 1529 ipc_answer_0(rid, ENOENT); 1530 return; 1531 } 1532 1533 fat_node_t *nodep = FAT_NODE(fn); 1534 1535 nodep->dirty = true; 1536 rc = fat_node_sync(nodep); 1537 1538 fat_node_put(fn); 1539 ipc_answer_0(rid, rc); 1561 1540 } 1562 1541
Note:
See TracChangeset
for help on using the changeset viewer.