Changeset 9854a8f in mainline
- 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
- Location:
- uspace
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fdisk/fdisk.c
ref9dac04 r9854a8f 167 167 } 168 168 169 fdisk_cap_simplify(&cap); 170 169 171 rc = fdisk_cap_format(&cap, &scap); 170 172 if (rc != EOK) { … … 518 520 goto error; 519 521 } 522 523 fdisk_cap_simplify(&pinfo.capacity); 520 524 521 525 rc = fdisk_cap_format(&pinfo.capacity, &scap); … … 662 666 } 663 667 668 fdisk_cap_simplify(&cap); 669 664 670 rc = fdisk_cap_format(&cap, &sdcap); 665 671 if (rc != EOK) { … … 713 719 goto error; 714 720 } 721 722 fdisk_cap_simplify(&pinfo.capacity); 715 723 716 724 rc = fdisk_cap_format(&pinfo.capacity, &scap); … … 774 782 } 775 783 784 fdisk_cap_simplify(&mcap); 785 776 786 rc = fdisk_cap_format(&mcap, &smcap); 777 787 if (rc != EOK) { … … 794 804 } 795 805 806 fdisk_cap_simplify(&mcap); 807 796 808 rc = fdisk_cap_format(&mcap, &smcap); 797 809 if (rc != EOK) { … … 817 829 } 818 830 831 fdisk_cap_simplify(&mcap); 832 819 833 rc = fdisk_cap_format(&mcap, &smcap); 820 834 if (rc != EOK) { … … 832 846 goto error; 833 847 } 848 849 fdisk_cap_simplify(&mcap); 834 850 835 851 rc = fdisk_cap_format(&mcap, &smcap); -
uspace/lib/c/Makefile
ref9dac04 r9854a8f 96 96 generic/task.c \ 97 97 generic/futex.c \ 98 generic/imath.c \ 98 99 generic/inet/addr.c \ 99 100 generic/inet/endpoint.c \ -
uspace/lib/fdisk/Makefile
ref9dac04 r9854a8f 33 33 34 34 SOURCES = \ 35 src/cap.c \ 35 36 src/fdisk.c 36 37 -
uspace/lib/fdisk/include/fdisk.h
ref9dac04 r9854a8f 73 73 extern int fdisk_cap_format(fdisk_cap_t *, char **); 74 74 extern int fdisk_cap_parse(const char *, fdisk_cap_t *); 75 extern void fdisk_cap_simplify(fdisk_cap_t *); 76 extern void fdisk_cap_from_blocks(uint64_t, size_t, fdisk_cap_t *); 77 extern int fdisk_cap_to_blocks(fdisk_cap_t *, size_t, uint64_t *); 78 75 79 extern int fdisk_ltype_format(label_type_t, char **); 76 80 extern int fdisk_fstype_format(vol_fstype_t, char **); -
uspace/lib/fdisk/include/types/fdisk.h
ref9dac04 r9854a8f 77 77 #define CU_LIMIT (cu_ybyte + 1) 78 78 79 /** Partition capacity */ 80 typedef struct { 81 uint64_t value; 79 /** Partition capacity. 80 * 81 * Partition capacity represents both value and precision. 82 * It is a decimal floating point value combined with a decimal 83 * capacity unit. There is an integer mantisa @c m which in combination 84 * with the number of decimal positions @c dp gives a decimal floating-point 85 * number. E.g. for m = 1025 and dp = 2 the number is 10.25. If the unit 86 * cunit = cu_kbyte, the capacity is 10.25 kByte, i.e. 10 250 bytes. 87 * 88 * Note that 1.000 kByte is equivalent to 1000 Byte, but 1 kByte is less 89 * precise. 90 */ 91 typedef struct { 92 /** Mantisa */ 93 uint64_t m; 94 /** Decimal positions */ 95 unsigned dp; 96 /** Capacity unit */ 82 97 fdisk_cunit_t cunit; 83 98 } fdisk_cap_t; -
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.