Changeset 9854a8f in mainline for uspace/lib/fdisk/src/fdisk.c
- Timestamp:
- 2015-10-24T22:06:34Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03661d19
- Parents:
- ef9dac04
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fdisk/src/fdisk.c
ref9dac04 r9854a8f 46 46 #include <vol.h> 47 47 48 static const char *cu_str[] = {49 [cu_byte] = "B",50 [cu_kbyte] = "kB",51 [cu_mbyte] = "MB",52 [cu_gbyte] = "GB",53 [cu_tbyte] = "TB",54 [cu_pbyte] = "PB",55 [cu_ebyte] = "EB",56 [cu_zbyte] = "ZB",57 [cu_ybyte] = "YB"58 };59 60 48 static int fdisk_dev_add_parts(fdisk_dev_t *); 61 49 static void fdisk_dev_remove_parts(fdisk_dev_t *); … … 257 245 return EIO; 258 246 259 cap->value = bsize * nblocks; 260 cap->cunit = cu_byte; 261 247 fdisk_cap_from_blocks(nblocks, bsize, cap); 262 248 return EOK; 263 249 } … … 330 316 dev->ext_part = part; 331 317 332 part->capacity.cunit = cu_byte;333 part->capacity.value = part->nblocks * dev->dinfo.block_size;318 fdisk_cap_from_blocks(part->nblocks, dev->dinfo.block_size, 319 &part->capacity); 334 320 part->part_id = partid; 335 321 … … 619 605 block_fini(dev->sid); 620 606 621 cap->value = bsize * nblocks; 622 cap->cunit = cu_byte; 623 607 fdisk_cap_from_blocks(nblocks, bsize, cap); 624 608 return EOK; 625 609 } … … 783 767 } 784 768 785 cap->value = nb * dev->dinfo.block_size; 786 cap->cunit = cu_byte; 769 fdisk_cap_from_blocks(nb, dev->dinfo.block_size, cap); 787 770 return EOK; 788 771 } … … 812 795 } while (fdisk_free_range_next(&fr)); 813 796 814 cap->value = totb * dev->dinfo.block_size; 815 cap->cunit = cu_byte; 797 fdisk_cap_from_blocks(totb, dev->dinfo.block_size, cap); 816 798 return EOK; 817 799 } … … 882 864 { 883 865 memset(pspec, 0, sizeof(fdisk_part_spec_t)); 884 }885 886 int fdisk_cap_format(fdisk_cap_t *cap, char **rstr)887 {888 int rc;889 const char *sunit;890 891 sunit = NULL;892 893 if (cap->cunit < 0 || cap->cunit >= CU_LIMIT)894 assert(false);895 896 sunit = cu_str[cap->cunit];897 rc = asprintf(rstr, "%" PRIu64 " %s", cap->value, sunit);898 if (rc < 0)899 return ENOMEM;900 901 return EOK;902 }903 904 int fdisk_cap_parse(const char *str, fdisk_cap_t *cap)905 {906 char *eptr;907 char *p;908 unsigned long val;909 int i;910 911 val = strtoul(str, &eptr, 10);912 913 while (*eptr == ' ')914 ++eptr;915 916 if (*eptr == '\0') {917 cap->cunit = cu_byte;918 } else {919 for (i = 0; i < CU_LIMIT; i++) {920 if (str_lcasecmp(eptr, cu_str[i],921 str_length(cu_str[i])) == 0) {922 p = eptr + str_size(cu_str[i]);923 while (*p == ' ')924 ++p;925 if (*p == '\0')926 goto found;927 }928 }929 930 return EINVAL;931 found:932 cap->cunit = i;933 }934 935 cap->value = val;936 return EOK;937 866 } 938 867 … … 1108 1037 vbd_part_spec_t *vpspec) 1109 1038 { 1110 uint64_t cbytes;1111 1039 aoff64_t req_blocks; 1112 1040 aoff64_t fblock0; 1113 1041 aoff64_t fnblocks; 1114 1042 aoff64_t hdrb; 1115 uint64_t block_size;1116 1043 label_pcnt_t pcnt; 1117 unsigned i;1118 1044 int index; 1119 1045 int rc; … … 1121 1047 printf("fdisk_part_spec_prepare() - dev=%p pspec=%p vpspec=%p\n", dev, pspec, 1122 1048 vpspec); 1123 printf("fdisk_part_spec_prepare() - block size\n"); 1124 block_size = dev->dinfo.block_size; 1125 printf("fdisk_part_spec_prepare() - cbytes\n"); 1126 cbytes = pspec->capacity.value; 1127 printf("fdisk_part_spec_prepare() - cunit\n"); 1128 for (i = 0; i < pspec->capacity.cunit; i++) 1129 cbytes = cbytes * 1000; 1130 1131 printf("fdisk_part_spec_prepare() - req_blocks block_size=%zu\n", 1132 block_size); 1133 req_blocks = (cbytes + block_size - 1) / block_size; 1049 fdisk_cap_to_blocks(&pspec->capacity, dev->dinfo.block_size, &req_blocks); 1050 1134 1051 req_blocks = fdisk_ba_align_up(dev, req_blocks); 1135 1052
Note:
See TracChangeset
for help on using the changeset viewer.