Changeset 377cce8 in mainline
- Timestamp:
- 2010-07-25T21:08:47Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 746f623
- Parents:
- c621f4aa
- Location:
- uspace/srv/fs/fat
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat.h
rc621f4aa r377cce8 198 198 unsigned refcnt; 199 199 bool dirty; 200 201 /* 202 * Cache of the node's last cluster to avoid some unnecessary FAT walks. 203 */ 204 bool lastc_cached_valid; 205 fat_cluster_t lastc_cached_value; 200 206 } fat_node_t; 201 207 -
uspace/srv/fs/fat/fat_fat.c
rc621f4aa r377cce8 511 511 * @param nodep Node representing the file. 512 512 * @param mcl First cluster of the cluster chain to append. 513 * @param lcl Last cluster of the cluster chain to append. 513 514 * 514 515 * @return EOK on success or a negative error code. 515 516 */ 516 int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) 517 int 518 fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, 519 fat_cluster_t lcl) 517 520 { 518 521 dev_handle_t dev_handle = nodep->idx->dev_handle; 519 fat_cluster_t l cl;522 fat_cluster_t lastc; 520 523 uint16_t numc; 521 524 uint8_t fatno; 522 525 int rc; 523 526 524 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc, 525 (uint16_t) -1); 526 if (rc != EOK) 527 return rc; 528 529 if (numc == 0) { 530 /* No clusters allocated to the node yet. */ 531 nodep->firstc = mcl; 532 nodep->dirty = true; /* need to sync node */ 533 return EOK; 527 if (nodep->lastc_cached_valid) { 528 lastc = nodep->lastc_cached_value; 529 nodep->lastc_cached_valid = false; 530 } else { 531 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lastc, 532 &numc, (uint16_t) -1); 533 if (rc != EOK) 534 return rc; 535 536 if (numc == 0) { 537 /* No clusters allocated to the node yet. */ 538 nodep->firstc = mcl; 539 nodep->dirty = true; /* need to sync node */ 540 return EOK; 541 } 534 542 } 535 543 536 544 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 537 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, l cl,545 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lastc, 538 546 mcl); 539 547 if (rc != EOK) 540 548 return rc; 541 549 } 550 551 nodep->lastc_cached_valid = true; 552 nodep->lastc_cached_value = lcl; 542 553 543 554 return EOK; … … 548 559 * @param bs Buffer holding the boot sector of the file system. 549 560 * @param nodep FAT node where the chopping will take place. 550 * @param l astcLast cluster which will remain in the node. If this561 * @param lcl Last cluster which will remain in the node. If this 551 562 * argument is FAT_CLST_RES0, then all clusters will 552 563 * be chopped off. … … 554 565 * @return EOK on success or a negative return code. 555 566 */ 556 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc) 557 { 558 int rc; 559 567 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lcl) 568 { 569 int rc; 560 570 dev_handle_t dev_handle = nodep->idx->dev_handle; 561 if (lastc == FAT_CLST_RES0) { 571 572 nodep->lastc_cached_valid = false; 573 if (lcl == FAT_CLST_RES0) { 562 574 /* The node will have zero size and no clusters allocated. */ 563 575 rc = fat_free_clusters(bs, dev_handle, nodep->firstc); … … 570 582 unsigned fatno; 571 583 572 rc = fat_get_cluster(bs, dev_handle, FAT1, l astc, &nextc);584 rc = fat_get_cluster(bs, dev_handle, FAT1, lcl, &nextc); 573 585 if (rc != EOK) 574 586 return rc; … … 576 588 /* Terminate the cluster chain in all copies of FAT. */ 577 589 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 578 rc = fat_set_cluster(bs, dev_handle, fatno, l astc,590 rc = fat_set_cluster(bs, dev_handle, fatno, lcl, 579 591 FAT_CLST_LAST1); 580 592 if (rc != EOK) … … 587 599 return rc; 588 600 } 601 602 nodep->lastc_cached_valid = true; 603 nodep->lastc_cached_value = lcl; 589 604 590 605 return EOK; -
uspace/srv/fs/fat/fat_fat.h
rc621f4aa r377cce8 72 72 73 73 extern int fat_append_clusters(struct fat_bs *, struct fat_node *, 74 fat_cluster_t );74 fat_cluster_t, fat_cluster_t); 75 75 extern int fat_chop_clusters(struct fat_bs *, struct fat_node *, 76 76 fat_cluster_t); -
uspace/srv/fs/fat/fat_ops.c
rc621f4aa r377cce8 101 101 node->refcnt = 0; 102 102 node->dirty = false; 103 node->lastc_cached_valid = false; 104 node->lastc_cached_value = FAT_CLST_LAST1; 103 105 } 104 106 … … 691 693 return rc; 692 694 } 693 rc = fat_append_clusters(bs, parentp, mcl );695 rc = fat_append_clusters(bs, parentp, mcl, lcl); 694 696 if (rc != EOK) { 695 697 (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl); … … 1438 1440 * node's cluster chain. 1439 1441 */ 1440 rc = fat_append_clusters(bs, nodep, mcl );1442 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1441 1443 if (rc != EOK) { 1442 1444 (void) fat_free_clusters(bs, dev_handle, mcl);
Note:
See TracChangeset
for help on using the changeset viewer.