Changeset 913a821c in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2008-11-09T17:23:53Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ac49f5d1
- Parents:
- 6c8d267
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
r6c8d267 r913a821c 635 635 uint16_t bps; 636 636 unsigned spc; 637 unsigned bpc; /* bytes per cluster */ 637 638 off_t boundary; 638 639 … … 650 651 return; 651 652 } 653 654 bs = block_bb_get(dev_handle); 655 bps = uint16_t_le2host(bs->bps); 656 spc = bs->spc; 657 bpc = bps * spc; 652 658 653 659 /* … … 659 665 */ 660 666 bytes = min(len, bps - pos % bps); 661 662 bs = block_bb_get(dev_handle); 663 bps = uint16_t_le2host(bs->bps); 664 spc = bs->spc; 665 666 boundary = ROUND_UP(nodep->size, bps * spc); 667 668 boundary = ROUND_UP(nodep->size, bpc); 667 669 if (pos < boundary) { 668 670 /* … … 694 696 fat_cluster_t mcl, lcl; 695 697 696 nclsts = (ROUND_UP(pos + bytes, bps * spc) - boundary) / 697 bps * spc; 698 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc; 698 699 /* create an independent chain of nclsts clusters in all FATs */ 699 status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, 700 &lcl); 700 status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl); 701 701 if (status != EOK) { 702 702 /* could not allocate a chain of nclsts clusters */ … … 732 732 size_t size = (off_t)IPC_GET_ARG3(*request); 733 733 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 734 fat_bs_t *bs; 735 uint16_t bps; 736 uint8_t spc; 737 unsigned bpc; /* bytes per cluster */ 734 738 int rc; 735 739 … … 738 742 return; 739 743 } 744 745 bs = block_bb_get(dev_handle); 746 bps = uint16_t_le2host(bs->bps); 747 spc = bs->spc; 748 bpc = bps * spc; 740 749 741 750 if (nodep->size == size) { … … 743 752 } else if (nodep->size < size) { 744 753 /* 745 * T ODO: the standard says we have the freedom to grow the file.754 * The standard says we have the freedom to grow the node. 746 755 * For now, we simply return an error. 747 756 */ 748 757 rc = EINVAL; 758 } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) { 759 /* 760 * The node will be shrunk, but no clusters will be deallocated. 761 */ 762 nodep->size = size; 763 nodep->dirty = true; /* need to sync node */ 764 rc = EOK; 749 765 } else { 750 766 /* 751 * The file is to be shrunk. 752 */ 753 rc = ENOTSUP; /* XXX */ 767 * The node will be shrunk, clusters will be deallocated. 768 */ 769 if (size == 0) { 770 fat_chop_clusters(bs, nodep, FAT_CLST_RES0); 771 } else { 772 fat_cluster_t lastc; 773 (void) fat_cluster_walk(bs, dev_handle, nodep->firstc, 774 &lastc, (size - 1) / bpc); 775 fat_chop_clusters(bs, nodep, lastc); 776 } 777 nodep->size = size; 778 nodep->dirty = true; /* need to sync node */ 779 rc = EOK; 754 780 } 755 781 fat_node_put(nodep); 756 782 ipc_answer_0(rid, rc); 757 783 return; 758 759 784 } 760 785
Note:
See TracChangeset
for help on using the changeset viewer.