Changeset 1b23e33 in mainline
- Timestamp:
- 2015-08-04T22:27:56Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f57ccb5
- Parents:
- 83dd743
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fdisk/src/fdisk.c
r83dd743 r1b23e33 63 63 static void fdisk_log_part_insert_lists(fdisk_dev_t *, fdisk_part_t *); 64 64 static int fdisk_update_dev_info(fdisk_dev_t *); 65 static uint64_t fdisk_ba_align_up(fdisk_dev_t *, uint64_t); 66 static uint64_t fdisk_ba_align_down(fdisk_dev_t *, uint64_t); 65 67 66 68 static void fdisk_dev_info_delete(fdisk_dev_info_t *info) … … 795 797 fdisk_part_t *part; 796 798 uint64_t avail; 797 int nba; 799 uint64_t pb0; 800 uint64_t nba; 801 802 printf("fdisk_part_get_free_range: align=%" PRIu64 "\n", 803 dev->align); 798 804 799 805 link = list_first(&dev->pri_ba); 800 nba = dev->dinfo.ablock0;806 nba = fdisk_ba_align_up(dev, dev->dinfo.ablock0); 801 807 while (link != NULL) { 802 808 part = list_get_instance(link, fdisk_part_t, lpri_ba); 803 if (part->block0 - nba >= nblocks) 809 pb0 = fdisk_ba_align_down(dev, part->block0); 810 if (pb0 >= nba && pb0 - nba >= nblocks) 804 811 break; 805 nba = part->block0 + part->nblocks;812 nba = fdisk_ba_align_up(dev, part->block0 + part->nblocks); 806 813 link = list_next(link, &dev->pri_ba); 807 814 } 808 815 809 816 if (link != NULL) { 817 printf("nba=%" PRIu64 " pb0=%" PRIu64 "\n", 818 nba, pb0); 810 819 /* Free range before a partition */ 811 avail = p art->block0 - nba;820 avail = pb0 - nba; 812 821 } else { 813 822 /* Free range at the end */ 814 avail = dev->dinfo.ablock0 + dev->dinfo.anblocks - nba; 815 816 /* Verify that the range is large enough */ 817 if (avail < nblocks) 823 pb0 = fdisk_ba_align_down(dev, dev->dinfo.ablock0 + 824 dev->dinfo.anblocks); 825 if (pb0 < nba) 818 826 return ELIMIT; 819 } 827 avail = pb0 - nba; 828 printf("nba=%" PRIu64 " avail=%" PRIu64 "\n", 829 nba, avail); 830 831 } 832 833 /* Verify that the range is large enough */ 834 if (avail < nblocks) 835 return ELIMIT; 820 836 821 837 *rblock0 = nba; … … 837 853 uint64_t avail; 838 854 uint64_t hdrb; 839 int nba; 840 855 uint64_t pb0; 856 uint64_t nba; 857 858 printf("fdisk_part_get_log_free_range\n"); 841 859 /* Number of header blocks */ 842 860 hdrb = max(1, dev->align); 843 861 844 862 link = list_first(&dev->log_ba); 845 nba = dev->ext_part->block0;863 nba = fdisk_ba_align_up(dev, dev->ext_part->block0); 846 864 while (link != NULL) { 847 865 part = list_get_instance(link, fdisk_part_t, llog_ba); 848 if (part->block0 - nba >= nblocks) 866 pb0 = fdisk_ba_align_down(dev, part->block0); 867 if (pb0 >= nba && pb0 - nba >= nblocks) 849 868 break; 850 nba = part->block0 + part->nblocks;869 nba = fdisk_ba_align_up(dev, part->block0 + part->nblocks); 851 870 link = list_next(link, &dev->log_ba); 852 871 } … … 854 873 if (link != NULL) { 855 874 /* Free range before a partition */ 856 avail = p art->block0 - nba;875 avail = pb0 - nba; 857 876 } else { 858 877 /* Free range at the end */ 859 avail = dev->ext_part->block0 + dev->ext_part->nblocks - nba;860 861 /* Verify that the range is large enough */862 if (avail < hdrb + nblocks)878 pb0 = fdisk_ba_align_down(dev, dev->ext_part->block0 + 879 dev->ext_part->nblocks); 880 if (pb0 < nba) { 881 printf("not enough space\n"); 863 882 return ELIMIT; 883 } 884 885 avail = pb0 - nba; 886 887 printf("nba=%" PRIu64 " pb0=%" PRIu64" avail=%" PRIu64 "\n", 888 nba, pb0, avail); 889 } 890 /* Verify that the range is large enough */ 891 if (avail < hdrb + nblocks) { 892 printf("not enough space\n"); 893 return ELIMIT; 864 894 } 865 895 … … 867 897 *rblock0 = nba + hdrb; 868 898 *rnblocks = avail; 899 printf("hdrb=%" PRIu64 " block0=%" PRIu64" avail=%" PRIu64 "\n", 900 hdrb, nba + hdrb, avail); 869 901 return EOK; 870 902 } … … 898 930 block_size); 899 931 req_blocks = (cbytes + block_size - 1) / block_size; 932 req_blocks = fdisk_ba_align_up(dev, req_blocks); 900 933 901 934 printf("fdisk_part_spec_prepare() - switch\n"); … … 945 978 int rc; 946 979 size_t align_bytes; 980 uint64_t avail_cap; 947 981 948 982 rc = vbd_disk_info(dev->fdisk->vbd, dev->sid, &dev->dinfo); … … 950 984 return EIO; 951 985 952 align_bytes = 512; //1024 * 1024; /* 1 MiB */ /* XXX */ 986 /* Capacity available for partition in bytes */ 987 avail_cap = dev->dinfo.anblocks * dev->dinfo.block_size; 988 989 /* Determine optimum alignment */ 990 align_bytes = 1024 * 1024; /* 1 MiB */ 991 while (align_bytes > 1 && avail_cap / align_bytes < 256) { 992 align_bytes = align_bytes / 16; 993 } 994 953 995 dev->align = align_bytes / dev->dinfo.block_size; 954 996 if (dev->align < 1) … … 957 999 } 958 1000 1001 static uint64_t fdisk_ba_align_up(fdisk_dev_t *dev, uint64_t ba) 1002 { 1003 return ((ba + dev->align - 1) / dev->align) * dev->align; 1004 } 1005 1006 static uint64_t fdisk_ba_align_down(fdisk_dev_t *dev, uint64_t ba) 1007 { 1008 return ba - (ba % dev->align); 1009 } 1010 959 1011 /** @} 960 1012 */
Note:
See TracChangeset
for help on using the changeset viewer.