Changes in uspace/srv/fs/fat/fat_ops.c [69a60c4:991f645] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
r69a60c4 r991f645 60 60 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 61 61 62 #define DPS(bs) (BPS((bs)) / sizeof(fat_dentry_t)) 63 #define BPC(bs) (BPS((bs)) * SPC((bs))) 64 62 65 /** Mutex protecting the list of cached free FAT nodes. */ 63 66 static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); … … 69 72 * Forward declarations of FAT libfs operations. 70 73 */ 71 static int fat_root_get(fs_node_t **, dev _handle_t);74 static int fat_root_get(fs_node_t **, devmap_handle_t); 72 75 static int fat_match(fs_node_t **, fs_node_t *, const char *); 73 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); 74 77 static int fat_node_open(fs_node_t *); 75 78 static int fat_node_put(fs_node_t *); 76 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); 77 80 static int fat_destroy_node(fs_node_t *); 78 81 static int fat_link(fs_node_t *, fs_node_t *, const char *); … … 85 88 static bool fat_is_directory(fs_node_t *); 86 89 static bool fat_is_file(fs_node_t *node); 87 static dev _handle_t fat_device_get(fs_node_t *node);90 static devmap_handle_t fat_device_get(fs_node_t *node); 88 91 89 92 /* … … 101 104 node->refcnt = 0; 102 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; 103 111 } 104 112 … … 108 116 fat_bs_t *bs; 109 117 fat_dentry_t *d; 110 uint16_t bps;111 unsigned dps;112 118 int rc; 113 119 114 120 assert(node->dirty); 115 121 116 bs = block_bb_get(node->idx->dev_handle); 117 bps = uint16_t_le2host(bs->bps); 118 dps = bps / sizeof(fat_dentry_t); 122 bs = block_bb_get(node->idx->devmap_handle); 119 123 120 124 /* Read the block that contains the dentry of interest. */ 121 rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc, 122 (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); 123 128 if (rc != EOK) 124 129 return rc; 125 130 126 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);131 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs)); 127 132 128 133 d->firstc = host2uint16_t_le(node->firstc); … … 140 145 } 141 146 142 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) 143 148 { 144 149 link_t *lnk; … … 165 170 goto restart; 166 171 } 167 if (nodep->idx->dev _handle != dev_handle) {172 if (nodep->idx->devmap_handle != devmap_handle) { 168 173 fibril_mutex_unlock(&nodep->idx->lock); 169 174 fibril_mutex_unlock(&nodep->lock); … … 266 271 fat_dentry_t *d; 267 272 fat_node_t *nodep = NULL; 268 unsigned bps;269 unsigned spc;270 unsigned dps;271 273 int rc; 272 274 … … 297 299 return rc; 298 300 299 bs = block_bb_get(idxp->dev_handle); 300 bps = uint16_t_le2host(bs->bps); 301 spc = bs->spc; 302 dps = bps / sizeof(fat_dentry_t); 301 bs = block_bb_get(idxp->devmap_handle); 303 302 304 303 /* Read the block that contains the dentry of interest. */ 305 rc = _fat_block_get(&b, bs, idxp->dev _handle, idxp->pfc,306 (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); 307 306 if (rc != EOK) { 308 307 (void) fat_node_put(FS_NODE(nodep)); … … 310 309 } 311 310 312 d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);311 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 313 312 if (d->attr & FAT_ATTR_SUBDIR) { 314 313 /* … … 324 323 */ 325 324 uint16_t clusters; 326 rc = fat_clusters_get(&clusters, bs, idxp->dev _handle,325 rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle, 327 326 uint16_t_le2host(d->firstc)); 328 327 if (rc != EOK) { … … 330 329 return rc; 331 330 } 332 nodep->size = bps * spc* clusters;331 nodep->size = BPS(bs) * SPC(bs) * clusters; 333 332 } else { 334 333 nodep->type = FAT_FILE; … … 357 356 */ 358 357 359 int fat_root_get(fs_node_t **rfn, dev _handle_t dev_handle)360 { 361 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); 362 361 } 363 362 … … 368 367 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 369 368 unsigned i, j; 370 unsigned bps; /* bytes per sector */371 unsigned dps; /* dentries per sector */372 369 unsigned blocks; 373 370 fat_dentry_t *d; 371 devmap_handle_t devmap_handle; 374 372 block_t *b; 375 373 int rc; 376 374 377 375 fibril_mutex_lock(&parentp->idx->lock); 378 bs = block_bb_get(parentp->idx->dev_handle); 379 bps = uint16_t_le2host(bs->bps); 380 dps = bps / sizeof(fat_dentry_t); 381 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); 382 381 for (i = 0; i < blocks; i++) { 383 382 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); 384 if (rc != EOK) { 385 fibril_mutex_unlock(&parentp->idx->lock); 383 if (rc != EOK) 386 384 return rc; 387 } 388 for (j = 0; j < dps; j++) { 385 for (j = 0; j < DPS(bs); j++) { 389 386 d = ((fat_dentry_t *)b->data) + j; 390 387 switch (fat_classify_dentry(d)) { … … 395 392 /* miss */ 396 393 rc = block_put(b); 397 fibril_mutex_unlock(&parentp->idx->lock);398 394 *rfn = NULL; 399 395 return rc; … … 406 402 /* hit */ 407 403 fat_node_t *nodep; 408 /* 409 * Assume tree hierarchy for locking. We 410 * already have the parent and now we are going 411 * to lock the child. Never lock in the oposite 412 * order. 413 */ 414 fat_idx_t *idx = fat_idx_get_by_pos( 415 parentp->idx->dev_handle, parentp->firstc, 416 i * dps + j); 417 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); 418 406 if (!idx) { 419 407 /* … … 438 426 } 439 427 rc = block_put(b); 440 if (rc != EOK) { 441 fibril_mutex_unlock(&parentp->idx->lock); 428 if (rc != EOK) 442 429 return rc; 443 } 444 } 445 446 fibril_mutex_unlock(&parentp->idx->lock); 430 } 431 447 432 *rfn = NULL; 448 433 return EOK; … … 450 435 451 436 /** Instantiate a FAT in-core node. */ 452 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) 453 438 { 454 439 fat_node_t *nodep; … … 456 441 int rc; 457 442 458 idxp = fat_idx_get_by_index(dev _handle, index);443 idxp = fat_idx_get_by_index(devmap_handle, index); 459 444 if (!idxp) { 460 445 *rfn = NULL; … … 507 492 } 508 493 509 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) 510 495 { 511 496 fat_idx_t *idxp; … … 513 498 fat_bs_t *bs; 514 499 fat_cluster_t mcl, lcl; 515 uint16_t bps;516 500 int rc; 517 501 518 bs = block_bb_get(dev_handle); 519 bps = uint16_t_le2host(bs->bps); 502 bs = block_bb_get(devmap_handle); 520 503 if (flags & L_DIRECTORY) { 521 504 /* allocate a cluster */ 522 rc = fat_alloc_clusters(bs, dev _handle, 1, &mcl, &lcl);505 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl); 523 506 if (rc != EOK) 524 507 return rc; 525 508 /* populate the new cluster with unused dentries */ 526 rc = fat_zero_cluster(bs, dev _handle, mcl);509 rc = fat_zero_cluster(bs, devmap_handle, mcl); 527 510 if (rc != EOK) { 528 (void) fat_free_clusters(bs, dev _handle, mcl);511 (void) fat_free_clusters(bs, devmap_handle, mcl); 529 512 return rc; 530 513 } … … 533 516 rc = fat_node_get_new(&nodep); 534 517 if (rc != EOK) { 535 (void) fat_free_clusters(bs, dev _handle, mcl);518 (void) fat_free_clusters(bs, devmap_handle, mcl); 536 519 return rc; 537 520 } 538 rc = fat_idx_get_new(&idxp, dev _handle);539 if (rc != EOK) { 540 (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); 541 524 (void) fat_node_put(FS_NODE(nodep)); 542 525 return rc; … … 546 529 nodep->type = FAT_DIRECTORY; 547 530 nodep->firstc = mcl; 548 nodep->size = bps * bs->spc;531 nodep->size = BPS(bs) * SPC(bs); 549 532 } else { 550 533 nodep->type = FAT_FILE; … … 587 570 assert(!has_children); 588 571 589 bs = block_bb_get(nodep->idx->dev _handle);572 bs = block_bb_get(nodep->idx->devmap_handle); 590 573 if (nodep->firstc != FAT_CLST_RES0) { 591 574 assert(nodep->size); 592 575 /* Free all clusters allocated to the node. */ 593 rc = fat_free_clusters(bs, nodep->idx->dev _handle,576 rc = fat_free_clusters(bs, nodep->idx->devmap_handle, 594 577 nodep->firstc); 595 578 } … … 609 592 block_t *b; 610 593 unsigned i, j; 611 uint16_t bps;612 unsigned dps;613 594 unsigned blocks; 614 595 fat_cluster_t mcl, lcl; … … 639 620 640 621 fibril_mutex_lock(&parentp->idx->lock); 641 bs = block_bb_get(parentp->idx->dev_handle); 642 bps = uint16_t_le2host(bs->bps); 643 dps = bps / sizeof(fat_dentry_t); 644 645 blocks = parentp->size / bps; 622 bs = block_bb_get(parentp->idx->devmap_handle); 623 624 blocks = parentp->size / BPS(bs); 646 625 647 626 for (i = 0; i < blocks; i++) { … … 651 630 return rc; 652 631 } 653 for (j = 0; j < dps; j++) {632 for (j = 0; j < DPS(bs); j++) { 654 633 d = ((fat_dentry_t *)b->data) + j; 655 634 switch (fat_classify_dentry(d)) { … … 680 659 return ENOSPC; 681 660 } 682 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); 683 662 if (rc != EOK) { 684 663 fibril_mutex_unlock(&parentp->idx->lock); 685 664 return rc; 686 665 } 687 rc = fat_zero_cluster(bs, parentp->idx->dev _handle, mcl);688 if (rc != EOK) { 689 (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); 690 669 fibril_mutex_unlock(&parentp->idx->lock); 691 670 return rc; 692 671 } 693 rc = fat_append_clusters(bs, parentp, mcl );694 if (rc != EOK) { 695 (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); 696 675 fibril_mutex_unlock(&parentp->idx->lock); 697 676 return rc; 698 677 } 699 parentp->size += bps * bs->spc;678 parentp->size += BPS(bs) * SPC(bs); 700 679 parentp->dirty = true; /* need to sync node */ 701 680 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 771 750 772 751 childp->idx->pfc = parentp->firstc; 773 childp->idx->pdi = i * dps+ j;752 childp->idx->pdi = i * DPS(bs) + j; 774 753 fibril_mutex_unlock(&childp->idx->lock); 775 754 … … 793 772 fat_bs_t *bs; 794 773 fat_dentry_t *d; 795 uint16_t bps;796 774 block_t *b; 797 775 bool has_children; … … 811 789 assert(childp->lnkcnt == 1); 812 790 fibril_mutex_lock(&childp->idx->lock); 813 bs = block_bb_get(childp->idx->dev_handle); 814 bps = uint16_t_le2host(bs->bps); 815 816 rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc, 817 (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), 818 795 BLOCK_FLAGS_NONE); 819 796 if (rc != EOK) 820 797 goto error; 821 798 d = (fat_dentry_t *)b->data + 822 (childp->idx->pdi % ( bps/ sizeof(fat_dentry_t)));799 (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t))); 823 800 /* mark the dentry as not-currently-used */ 824 801 d->name[0] = FAT_DENTRY_ERASED; … … 852 829 fat_bs_t *bs; 853 830 fat_node_t *nodep = FAT_NODE(fn); 854 unsigned bps;855 unsigned dps;856 831 unsigned blocks; 857 832 block_t *b; … … 865 840 866 841 fibril_mutex_lock(&nodep->idx->lock); 867 bs = block_bb_get(nodep->idx->dev_handle); 868 bps = uint16_t_le2host(bs->bps); 869 dps = bps / sizeof(fat_dentry_t); 870 871 blocks = nodep->size / bps; 842 bs = block_bb_get(nodep->idx->devmap_handle); 843 844 blocks = nodep->size / BPS(bs); 872 845 873 846 for (i = 0; i < blocks; i++) { … … 879 852 return rc; 880 853 } 881 for (j = 0; j < dps; j++) {854 for (j = 0; j < DPS(bs); j++) { 882 855 d = ((fat_dentry_t *)b->data) + j; 883 856 switch (fat_classify_dentry(d)) { … … 941 914 } 942 915 943 dev _handle_t fat_device_get(fs_node_t *node)916 devmap_handle_t fat_device_get(fs_node_t *node) 944 917 { 945 918 return 0; … … 973 946 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 974 947 { 975 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); 976 949 enum cache_mode cmode; 977 950 fat_bs_t *bs; 978 uint16_t bps;979 uint16_t rde;980 951 981 952 /* Accept the mount options */ … … 997 968 998 969 /* initialize libblock */ 999 rc = block_init(dev _handle, BS_SIZE);970 rc = block_init(devmap_handle, BS_SIZE); 1000 971 if (rc != EOK) { 1001 972 ipc_answer_0(rid, rc); … … 1004 975 1005 976 /* prepare the boot block */ 1006 rc = block_bb_read(dev _handle, BS_BLOCK);1007 if (rc != EOK) { 1008 block_fini(dev _handle);977 rc = block_bb_read(devmap_handle, BS_BLOCK); 978 if (rc != EOK) { 979 block_fini(devmap_handle); 1009 980 ipc_answer_0(rid, rc); 1010 981 return; … … 1012 983 1013 984 /* get the buffer with the boot sector */ 1014 bs = block_bb_get(dev_handle); 1015 1016 /* Read the number of root directory entries. */ 1017 bps = uint16_t_le2host(bs->bps); 1018 rde = uint16_t_le2host(bs->root_ent_max); 1019 1020 if (bps != BS_SIZE) { 1021 block_fini(dev_handle); 985 bs = block_bb_get(devmap_handle); 986 987 if (BPS(bs) != BS_SIZE) { 988 block_fini(devmap_handle); 1022 989 ipc_answer_0(rid, ENOTSUP); 1023 990 return; … … 1025 992 1026 993 /* Initialize the block cache */ 1027 rc = block_cache_init(dev _handle, bps, 0 /* XXX */, cmode);1028 if (rc != EOK) { 1029 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); 1030 997 ipc_answer_0(rid, rc); 1031 998 return; … … 1033 1000 1034 1001 /* Do some simple sanity checks on the file system. */ 1035 rc = fat_sanity_check(bs, dev _handle);1036 if (rc != EOK) { 1037 (void) block_cache_fini(dev _handle);1038 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); 1039 1006 ipc_answer_0(rid, rc); 1040 1007 return; 1041 1008 } 1042 1009 1043 rc = fat_idx_init_by_dev _handle(dev_handle);1044 if (rc != EOK) { 1045 (void) block_cache_fini(dev _handle);1046 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); 1047 1014 ipc_answer_0(rid, rc); 1048 1015 return; … … 1052 1019 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 1053 1020 if (!rfn) { 1054 (void) block_cache_fini(dev _handle);1055 block_fini(dev _handle);1056 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); 1057 1024 ipc_answer_0(rid, ENOMEM); 1058 1025 return; … … 1062 1029 if (!rootp) { 1063 1030 free(rfn); 1064 (void) block_cache_fini(dev _handle);1065 block_fini(dev _handle);1066 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); 1067 1034 ipc_answer_0(rid, ENOMEM); 1068 1035 return; … … 1070 1037 fat_node_initialize(rootp); 1071 1038 1072 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); 1073 1040 if (!ridxp) { 1074 1041 free(rfn); 1075 1042 free(rootp); 1076 (void) block_cache_fini(dev _handle);1077 block_fini(dev _handle);1078 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); 1079 1046 ipc_answer_0(rid, ENOMEM); 1080 1047 return; … … 1087 1054 rootp->refcnt = 1; 1088 1055 rootp->lnkcnt = 0; /* FS root is not linked */ 1089 rootp->size = rde* sizeof(fat_dentry_t);1056 rootp->size = RDE(bs) * sizeof(fat_dentry_t); 1090 1057 rootp->idx = ridxp; 1091 1058 ridxp->nodep = rootp; … … 1105 1072 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1106 1073 { 1107 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); 1108 1075 fs_node_t *fn; 1109 1076 fat_node_t *nodep; 1110 1077 int rc; 1111 1078 1112 rc = fat_root_get(&fn, dev _handle);1079 rc = fat_root_get(&fn, devmap_handle); 1113 1080 if (rc != EOK) { 1114 1081 ipc_answer_0(rid, rc); … … 1138 1105 * stop using libblock for this instance. 1139 1106 */ 1140 (void) fat_node_fini_by_dev _handle(dev_handle);1141 fat_idx_fini_by_dev _handle(dev_handle);1142 (void) block_cache_fini(dev _handle);1143 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); 1144 1111 1145 1112 ipc_answer_0(rid, EOK); … … 1158 1125 void fat_read(ipc_callid_t rid, ipc_call_t *request) 1159 1126 { 1160 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1127 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1161 1128 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1162 1129 aoff64_t pos = … … 1165 1132 fat_node_t *nodep; 1166 1133 fat_bs_t *bs; 1167 uint16_t bps;1168 1134 size_t bytes; 1169 1135 block_t *b; 1170 1136 int rc; 1171 1137 1172 rc = fat_node_get(&fn, dev _handle, index);1138 rc = fat_node_get(&fn, devmap_handle, index); 1173 1139 if (rc != EOK) { 1174 1140 ipc_answer_0(rid, rc); … … 1190 1156 } 1191 1157 1192 bs = block_bb_get(dev_handle); 1193 bps = uint16_t_le2host(bs->bps); 1158 bs = block_bb_get(devmap_handle); 1194 1159 1195 1160 if (nodep->type == FAT_FILE) { … … 1204 1169 (void) async_data_read_finalize(callid, NULL, 0); 1205 1170 } else { 1206 bytes = min(len, bps - pos % bps);1171 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1207 1172 bytes = min(bytes, nodep->size - pos); 1208 rc = fat_block_get(&b, bs, nodep, pos / bps,1173 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), 1209 1174 BLOCK_FLAGS_NONE); 1210 1175 if (rc != EOK) { … … 1214 1179 return; 1215 1180 } 1216 (void) async_data_read_finalize(callid, b->data + pos % bps,1217 b ytes);1181 (void) async_data_read_finalize(callid, 1182 b->data + pos % BPS(bs), bytes); 1218 1183 rc = block_put(b); 1219 1184 if (rc != EOK) { … … 1230 1195 1231 1196 assert(nodep->type == FAT_DIRECTORY); 1232 assert(nodep->size % bps== 0);1233 assert( bps% sizeof(fat_dentry_t) == 0);1197 assert(nodep->size % BPS(bs) == 0); 1198 assert(BPS(bs) % sizeof(fat_dentry_t) == 0); 1234 1199 1235 1200 /* … … 1239 1204 * the position pointer accordingly. 1240 1205 */ 1241 bnum = (pos * sizeof(fat_dentry_t)) / bps;1242 while (bnum < nodep->size / bps) {1206 bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs); 1207 while (bnum < nodep->size / BPS(bs)) { 1243 1208 aoff64_t o; 1244 1209 … … 1247 1212 if (rc != EOK) 1248 1213 goto err; 1249 for (o = pos % ( bps/ sizeof(fat_dentry_t));1250 o < bps/ sizeof(fat_dentry_t);1214 for (o = pos % (BPS(bs) / sizeof(fat_dentry_t)); 1215 o < BPS(bs) / sizeof(fat_dentry_t); 1251 1216 o++, pos++) { 1252 1217 d = ((fat_dentry_t *)b->data) + o; … … 1297 1262 void fat_write(ipc_callid_t rid, ipc_call_t *request) 1298 1263 { 1299 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1264 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1300 1265 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1301 1266 aoff64_t pos = … … 1306 1271 size_t bytes, size; 1307 1272 block_t *b; 1308 uint16_t bps;1309 unsigned spc;1310 unsigned bpc; /* bytes per cluster */1311 1273 aoff64_t boundary; 1312 1274 int flags = BLOCK_FLAGS_NONE; 1313 1275 int rc; 1314 1276 1315 rc = fat_node_get(&fn, dev _handle, index);1277 rc = fat_node_get(&fn, devmap_handle, index); 1316 1278 if (rc != EOK) { 1317 1279 ipc_answer_0(rid, rc); … … 1333 1295 } 1334 1296 1335 bs = block_bb_get(dev_handle); 1336 bps = uint16_t_le2host(bs->bps); 1337 spc = bs->spc; 1338 bpc = bps * spc; 1297 bs = block_bb_get(devmap_handle); 1339 1298 1340 1299 /* … … 1345 1304 * value signalizing a smaller number of bytes written. 1346 1305 */ 1347 bytes = min(len, bps - pos % bps);1348 if (bytes == bps)1306 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1307 if (bytes == BPS(bs)) 1349 1308 flags |= BLOCK_FLAGS_NOREAD; 1350 1309 1351 boundary = ROUND_UP(nodep->size, bpc);1310 boundary = ROUND_UP(nodep->size, BPC(bs)); 1352 1311 if (pos < boundary) { 1353 1312 /* … … 1364 1323 return; 1365 1324 } 1366 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);1325 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags); 1367 1326 if (rc != EOK) { 1368 1327 (void) fat_node_put(fn); … … 1371 1330 return; 1372 1331 } 1373 (void) async_data_write_finalize(callid, b->data + pos % bps,1374 b ytes);1332 (void) async_data_write_finalize(callid, 1333 b->data + pos % BPS(bs), bytes); 1375 1334 b->dirty = true; /* need to sync block */ 1376 1335 rc = block_put(b); … … 1396 1355 fat_cluster_t mcl, lcl; 1397 1356 1398 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;1357 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1399 1358 /* create an independent chain of nclsts clusters in all FATs */ 1400 rc = fat_alloc_clusters(bs, dev _handle, nclsts, &mcl, &lcl);1359 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl); 1401 1360 if (rc != EOK) { 1402 1361 /* could not allocate a chain of nclsts clusters */ … … 1409 1368 rc = fat_fill_gap(bs, nodep, mcl, pos); 1410 1369 if (rc != EOK) { 1411 (void) fat_free_clusters(bs, dev _handle, mcl);1370 (void) fat_free_clusters(bs, devmap_handle, mcl); 1412 1371 (void) fat_node_put(fn); 1413 1372 ipc_answer_0(callid, rc); … … 1415 1374 return; 1416 1375 } 1417 rc = _fat_block_get(&b, bs, dev _handle, lcl, (pos / bps) % spc,1418 flags);1376 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL, 1377 (pos / BPS(bs)) % SPC(bs), flags); 1419 1378 if (rc != EOK) { 1420 (void) fat_free_clusters(bs, dev _handle, mcl);1379 (void) fat_free_clusters(bs, devmap_handle, mcl); 1421 1380 (void) fat_node_put(fn); 1422 1381 ipc_answer_0(callid, rc); … … 1424 1383 return; 1425 1384 } 1426 (void) async_data_write_finalize(callid, b->data + pos % bps,1427 b ytes);1385 (void) async_data_write_finalize(callid, 1386 b->data + pos % BPS(bs), bytes); 1428 1387 b->dirty = true; /* need to sync block */ 1429 1388 rc = block_put(b); 1430 1389 if (rc != EOK) { 1431 (void) fat_free_clusters(bs, dev _handle, mcl);1390 (void) fat_free_clusters(bs, devmap_handle, mcl); 1432 1391 (void) fat_node_put(fn); 1433 1392 ipc_answer_0(rid, rc); … … 1438 1397 * node's cluster chain. 1439 1398 */ 1440 rc = fat_append_clusters(bs, nodep, mcl );1399 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1441 1400 if (rc != EOK) { 1442 (void) fat_free_clusters(bs, dev _handle, mcl);1401 (void) fat_free_clusters(bs, devmap_handle, mcl); 1443 1402 (void) fat_node_put(fn); 1444 1403 ipc_answer_0(rid, rc); … … 1455 1414 void fat_truncate(ipc_callid_t rid, ipc_call_t *request) 1456 1415 { 1457 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1416 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1458 1417 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1459 1418 aoff64_t size = … … 1462 1421 fat_node_t *nodep; 1463 1422 fat_bs_t *bs; 1464 uint16_t bps;1465 uint8_t spc;1466 unsigned bpc; /* bytes per cluster */1467 1423 int rc; 1468 1424 1469 rc = fat_node_get(&fn, dev _handle, index);1425 rc = fat_node_get(&fn, devmap_handle, index); 1470 1426 if (rc != EOK) { 1471 1427 ipc_answer_0(rid, rc); … … 1478 1434 nodep = FAT_NODE(fn); 1479 1435 1480 bs = block_bb_get(dev_handle); 1481 bps = uint16_t_le2host(bs->bps); 1482 spc = bs->spc; 1483 bpc = bps * spc; 1436 bs = block_bb_get(devmap_handle); 1484 1437 1485 1438 if (nodep->size == size) { … … 1491 1444 */ 1492 1445 rc = EINVAL; 1493 } 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))) { 1494 1447 /* 1495 1448 * The node will be shrunk, but no clusters will be deallocated. … … 1508 1461 } else { 1509 1462 fat_cluster_t lastc; 1510 rc = fat_cluster_walk(bs, dev _handle, nodep->firstc,1511 &lastc, NULL, (size - 1) / bpc);1463 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc, 1464 &lastc, NULL, (size - 1) / BPC(bs)); 1512 1465 if (rc != EOK) 1513 1466 goto out; … … 1533 1486 void fat_destroy(ipc_callid_t rid, ipc_call_t *request) 1534 1487 { 1535 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); 1536 1489 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1537 1490 fs_node_t *fn; 1538 1491 int rc; 1539 1492 1540 rc = fat_node_get(&fn, dev _handle, index);1493 rc = fat_node_get(&fn, devmap_handle, index); 1541 1494 if (rc != EOK) { 1542 1495 ipc_answer_0(rid, rc); … … 1564 1517 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1565 1518 { 1566 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1519 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1567 1520 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1568 1521 1569 1522 fs_node_t *fn; 1570 int rc = fat_node_get(&fn, dev _handle, index);1523 int rc = fat_node_get(&fn, devmap_handle, index); 1571 1524 if (rc != EOK) { 1572 1525 ipc_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.