Changeset 6c4eedf in mainline
- Timestamp:
- 2017-09-13T20:14:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 120d5bc
- Parents:
- 1d40c93d
- Location:
- uspace
- Files:
-
- 1 added
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fdisk/fdisk.c
r1d40c93d r6c4eedf 35 35 */ 36 36 37 #include <cap.h> 37 38 #include <errno.h> 38 39 #include <nchoice.h> … … 151 152 nchoice_t *choice = NULL; 152 153 char *svcname = NULL; 153 fdisk_cap_t cap;154 cap_spec_t cap; 154 155 fdisk_dev_info_t *sdev; 155 156 char *scap = NULL; … … 200 201 } 201 202 202 fdisk_cap_simplify(&cap);203 204 rc = fdisk_cap_format(&cap, &scap);203 cap_simplify(&cap); 204 205 rc = cap_format(&cap, &scap); 205 206 if (rc != EOK) { 206 207 assert(rc == ENOMEM); … … 445 446 int rc; 446 447 fdisk_part_spec_t pspec; 447 fdisk_cap_t cap;448 fdisk_cap_t mcap;448 cap_spec_t cap; 449 cap_spec_t mcap; 449 450 vol_label_supp_t vlsupp; 450 451 vol_fstype_t fstype = 0; … … 466 467 } 467 468 468 fdisk_cap_simplify(&mcap);469 470 rc = fdisk_cap_format(&mcap, &smcap);469 cap_simplify(&mcap); 470 471 rc = cap_format(&mcap, &smcap); 471 472 if (rc != EOK) { 472 473 rc = ENOMEM; … … 490 491 goto error; 491 492 492 rc = fdisk_cap_parse(scap, &cap);493 rc = cap_parse(scap, &cap); 493 494 if (rc == EOK) 494 495 break; … … 586 587 } 587 588 588 fdisk_cap_simplify(&pinfo.capacity);589 590 rc = fdisk_cap_format(&pinfo.capacity, &scap);589 cap_simplify(&pinfo.capacity); 590 591 rc = cap_format(&pinfo.capacity, &scap); 591 592 if (rc != EOK) { 592 593 printf("Out of memory.\n"); … … 703 704 fdisk_part_t *part; 704 705 fdisk_part_info_t pinfo; 705 fdisk_cap_t cap;706 fdisk_cap_t mcap;706 cap_spec_t cap; 707 cap_spec_t mcap; 707 708 fdisk_dev_flags_t dflags; 708 709 char *sltype = NULL; … … 738 739 } 739 740 740 fdisk_cap_simplify(&cap);741 742 rc = fdisk_cap_format(&cap, &sdcap);741 cap_simplify(&cap); 742 743 rc = cap_format(&cap, &sdcap); 743 744 if (rc != EOK) { 744 745 printf("Out of memory.\n"); … … 792 793 } 793 794 794 fdisk_cap_simplify(&pinfo.capacity);795 796 rc = fdisk_cap_format(&pinfo.capacity, &scap);795 cap_simplify(&pinfo.capacity); 796 797 rc = cap_format(&pinfo.capacity, &scap); 797 798 if (rc != EOK) { 798 799 printf("Out of memory.\n"); … … 849 850 } 850 851 851 fdisk_cap_simplify(&mcap);852 853 rc = fdisk_cap_format(&mcap, &smcap);852 cap_simplify(&mcap); 853 854 rc = cap_format(&mcap, &smcap); 854 855 if (rc != EOK) { 855 856 rc = ENOMEM; … … 871 872 } 872 873 873 fdisk_cap_simplify(&mcap);874 875 rc = fdisk_cap_format(&mcap, &smcap);874 cap_simplify(&mcap); 875 876 rc = cap_format(&mcap, &smcap); 876 877 if (rc != EOK) { 877 878 rc = ENOMEM; … … 896 897 } 897 898 898 fdisk_cap_simplify(&mcap);899 900 rc = fdisk_cap_format(&mcap, &smcap);899 cap_simplify(&mcap); 900 901 rc = cap_format(&mcap, &smcap); 901 902 if (rc != EOK) { 902 903 rc = ENOMEM; … … 914 915 } 915 916 916 fdisk_cap_simplify(&mcap);917 918 rc = fdisk_cap_format(&mcap, &smcap);917 cap_simplify(&mcap); 918 919 rc = cap_format(&mcap, &smcap); 919 920 if (rc != EOK) { 920 921 rc = ENOMEM; -
uspace/app/sysinst/sysinst.c
r1d40c93d r6c4eedf 38 38 #include <block.h> 39 39 #include <byteorder.h> 40 #include <cap.h> 40 41 #include <errno.h> 41 42 #include <fdisk.h> … … 89 90 fdisk_part_t *part; 90 91 fdisk_part_spec_t pspec; 91 fdisk_cap_t cap;92 cap_spec_t cap; 92 93 service_id_t sid; 93 94 int rc; -
uspace/lib/c/Makefile
r1d40c93d r6c4eedf 64 64 generic/bd_srv.c \ 65 65 generic/perm.c \ 66 generic/cap.c \ 66 67 generic/clipboard.c \ 67 68 generic/config.c \ -
uspace/lib/c/generic/cap.c
r1d40c93d r6c4eedf 27 27 */ 28 28 29 /** @addtogroup lib fdisk29 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 32 /** 33 * @file Disk management library. 34 */ 35 33 * @file Storage capacity specification. 34 */ 35 36 #include <cap.h> 36 37 #include <errno.h> 37 #include <fdisk.h>38 38 #include <imath.h> 39 39 #include <stdio.h> … … 60 60 }; 61 61 62 void fdisk_cap_from_blocks(uint64_t nblocks, size_t block_size, 63 fdisk_cap_t *cap) 62 void cap_from_blocks(uint64_t nblocks, size_t block_size, cap_spec_t *cap) 64 63 { 65 64 uint64_t tsize; … … 78 77 * 79 78 * A capacity value entails precision, i.e. it corresponds to a range 80 * of values. @a cvsel selects the value to return. @c fcv_nom gives81 * the nominal (middle) value, @c fcv_min gives the minimum value82 * and @c fcv_max gives the maximum value.83 */ 84 int fdisk_cap_to_blocks(fdisk_cap_t *cap, fdisk_cvsel_t cvsel,85 size_t block_size,uint64_t *rblocks)79 * of values. @a cvsel selects the value to return. @c cv_nom gives 80 * the nominal (middle) value, @c cv_min gives the minimum value 81 * and @c cv_max gives the maximum value. 82 */ 83 int cap_spec_to_blocks(cap_spec_t *cap, cap_vsel_t cvsel, size_t block_size, 84 uint64_t *rblocks) 86 85 { 87 86 int exp; … … 108 107 adj = 0; 109 108 switch (cvsel) { 110 case fcv_nom:109 case cv_nom: 111 110 adj = 0; 112 111 break; 113 case fcv_min:112 case cv_min: 114 113 adj = -(f / 2); 115 114 break; 116 case fcv_max:115 case cv_max: 117 116 adj = f / 2 - 1; 118 117 break; … … 139 138 * digits and at most two fractional digits, e.g abc.xy <unit>. 140 139 */ 141 void fdisk_cap_simplify(fdisk_cap_t *cap)140 void cap_simplify(cap_spec_t *cap) 142 141 { 143 142 uint64_t div; … … 176 175 } 177 176 178 int fdisk_cap_format(fdisk_cap_t *cap, char **rstr)177 int cap_format(cap_spec_t *cap, char **rstr) 179 178 { 180 179 int rc; … … 209 208 } 210 209 211 static int fdisk_digit_val(char c, int *val)210 static int cap_digit_val(char c, int *val) 212 211 { 213 212 switch (c) { … … 229 228 } 230 229 231 int fdisk_cap_parse(const char *str, fdisk_cap_t *cap)230 int cap_parse(const char *str, cap_spec_t *cap) 232 231 { 233 232 const char *eptr; … … 241 240 242 241 eptr = str; 243 while ( fdisk_digit_val(*eptr, &d) == EOK) {242 while (cap_digit_val(*eptr, &d) == EOK) { 244 243 m = m * 10 + d; 245 244 ++eptr; … … 249 248 ++eptr; 250 249 dp = 0; 251 while ( fdisk_digit_val(*eptr, &d) == EOK) {250 while (cap_digit_val(*eptr, &d) == EOK) { 252 251 m = m * 10 + d; 253 252 ++dp; -
uspace/lib/fdisk/Makefile
r1d40c93d r6c4eedf 33 33 34 34 SOURCES = \ 35 src/cap.c \36 35 src/fdisk.c 37 36 -
uspace/lib/fdisk/include/fdisk.h
r1d40c93d r6c4eedf 49 49 extern int fdisk_dev_info_get_svcname(fdisk_dev_info_t *, char **); 50 50 extern void fdisk_dev_info_get_svcid(fdisk_dev_info_t *, service_id_t *); 51 extern int fdisk_dev_info_capacity(fdisk_dev_info_t *, fdisk_cap_t *);51 extern int fdisk_dev_info_capacity(fdisk_dev_info_t *, cap_spec_t *); 52 52 53 53 extern int fdisk_dev_open(fdisk_t *, service_id_t, fdisk_dev_t **); … … 56 56 extern void fdisk_dev_get_flags(fdisk_dev_t *, fdisk_dev_flags_t *); 57 57 extern int fdisk_dev_get_svcname(fdisk_dev_t *, char **); 58 extern int fdisk_dev_capacity(fdisk_dev_t *, fdisk_cap_t *);58 extern int fdisk_dev_capacity(fdisk_dev_t *, cap_spec_t *); 59 59 60 60 extern int fdisk_label_get_info(fdisk_dev_t *, fdisk_label_info_t *); … … 65 65 extern fdisk_part_t *fdisk_part_next(fdisk_part_t *); 66 66 extern int fdisk_part_get_info(fdisk_part_t *, fdisk_part_info_t *); 67 extern int fdisk_part_get_max_avail(fdisk_dev_t *, fdisk_spc_t, fdisk_cap_t *);68 extern int fdisk_part_get_tot_avail(fdisk_dev_t *, fdisk_spc_t, fdisk_cap_t *);67 extern int fdisk_part_get_max_avail(fdisk_dev_t *, fdisk_spc_t, cap_spec_t *); 68 extern int fdisk_part_get_tot_avail(fdisk_dev_t *, fdisk_spc_t, cap_spec_t *); 69 69 extern int fdisk_part_create(fdisk_dev_t *, fdisk_part_spec_t *, 70 70 fdisk_part_t **); 71 71 extern int fdisk_part_destroy(fdisk_part_t *); 72 72 extern void fdisk_pspec_init(fdisk_part_spec_t *); 73 74 extern int fdisk_cap_format(fdisk_cap_t *, char **);75 extern int fdisk_cap_parse(const char *, fdisk_cap_t *);76 extern void fdisk_cap_simplify(fdisk_cap_t *);77 extern void fdisk_cap_from_blocks(uint64_t, size_t, fdisk_cap_t *);78 extern int fdisk_cap_to_blocks(fdisk_cap_t *, fdisk_cvsel_t, size_t, uint64_t *);79 73 80 74 extern int fdisk_ltype_format(label_type_t, char **); -
uspace/lib/fdisk/include/types/fdisk.h
r1d40c93d r6c4eedf 38 38 39 39 #include <adt/list.h> 40 #include <cap.h> 40 41 #include <loc.h> 41 42 #include <stdint.h> … … 43 44 #include <types/vol.h> 44 45 #include <vbd.h> 45 46 /** Capacity unit */47 typedef enum {48 cu_byte = 0,49 cu_kbyte,50 cu_mbyte,51 cu_gbyte,52 cu_tbyte,53 cu_pbyte,54 cu_ebyte,55 cu_zbyte,56 cu_ybyte57 } fdisk_cunit_t;58 59 /** Which of values within the precision of the capacity */60 typedef enum {61 /** The nominal (middling) value */62 fcv_nom,63 /** The minimum value */64 fcv_min,65 /** The maximum value */66 fcv_max67 } fdisk_cvsel_t;68 46 69 47 typedef enum { … … 85 63 86 64 #define CU_LIMIT (cu_ybyte + 1) 87 88 /** Partition capacity.89 *90 * Partition capacity represents both value and precision.91 * It is a decimal floating point value combined with a decimal92 * capacity unit. There is an integer mantisa @c m which in combination93 * with the number of decimal positions @c dp gives a decimal floating-point94 * number. E.g. for m = 1025 and dp = 2 the number is 10.25. If the unit95 * cunit = cu_kbyte, the capacity is 10.25 kByte, i.e. 10 250 bytes.96 *97 * Note that 1.000 kByte is equivalent to 1000 Byte, but 1 kByte is less98 * precise.99 */100 typedef struct {101 /** Mantisa */102 uint64_t m;103 /** Decimal positions */104 unsigned dp;105 /** Capacity unit */106 fdisk_cunit_t cunit;107 } fdisk_cap_t;108 65 109 66 /** List of devices available for managing by fdisk */ … … 169 126 link_t llog_ba; 170 127 /** Capacity */ 171 fdisk_cap_t capacity;128 cap_spec_t capacity; 172 129 /** Partition kind */ 173 130 label_pkind_t pkind; … … 193 150 typedef struct { 194 151 /** Desired capacity */ 195 fdisk_cap_t capacity;152 cap_spec_t capacity; 196 153 /** Partition kind */ 197 154 label_pkind_t pkind; … … 205 162 typedef struct { 206 163 /** Capacity */ 207 fdisk_cap_t capacity;164 cap_spec_t capacity; 208 165 /** Partition kind */ 209 166 label_pkind_t pkind; -
uspace/lib/fdisk/src/fdisk.c
r1d40c93d r6c4eedf 35 35 36 36 #include <adt/list.h> 37 #include <cap.h> 37 38 #include <errno.h> 38 39 #include <fdisk.h> … … 218 219 } 219 220 220 int fdisk_dev_info_capacity(fdisk_dev_info_t *info, fdisk_cap_t *cap)221 int fdisk_dev_info_capacity(fdisk_dev_info_t *info, cap_spec_t *cap) 221 222 { 222 223 vbd_disk_info_t vinfo; … … 227 228 return EIO; 228 229 229 fdisk_cap_from_blocks(vinfo.nblocks, vinfo.block_size, cap);230 cap_from_blocks(vinfo.nblocks, vinfo.block_size, cap); 230 231 return EOK; 231 232 } … … 294 295 dev->ext_part = part; 295 296 296 fdisk_cap_from_blocks(part->nblocks, dev->dinfo.block_size,297 cap_from_blocks(part->nblocks, dev->dinfo.block_size, 297 298 &part->capacity); 298 299 part->part_id = partid; … … 535 536 } 536 537 537 int fdisk_dev_capacity(fdisk_dev_t *dev, fdisk_cap_t *cap)538 { 539 fdisk_cap_from_blocks(dev->dinfo.nblocks, dev->dinfo.block_size, cap);538 int fdisk_dev_capacity(fdisk_dev_t *dev, cap_spec_t *cap) 539 { 540 cap_from_blocks(dev->dinfo.nblocks, dev->dinfo.block_size, cap); 540 541 return EOK; 541 542 } … … 677 678 678 679 /** Get size of largest free block. */ 679 int fdisk_part_get_max_avail(fdisk_dev_t *dev, fdisk_spc_t spc, fdisk_cap_t *cap)680 int fdisk_part_get_max_avail(fdisk_dev_t *dev, fdisk_spc_t spc, cap_spec_t *cap) 680 681 { 681 682 int rc; … … 696 697 } 697 698 698 fdisk_cap_from_blocks(nb, dev->dinfo.block_size, cap);699 cap_from_blocks(nb, dev->dinfo.block_size, cap); 699 700 return EOK; 700 701 } … … 702 703 /** Get total free space capacity. */ 703 704 int fdisk_part_get_tot_avail(fdisk_dev_t *dev, fdisk_spc_t spc, 704 fdisk_cap_t *cap)705 cap_spec_t *cap) 705 706 { 706 707 fdisk_free_range_t fr; … … 724 725 } while (fdisk_free_range_next(&fr)); 725 726 726 fdisk_cap_from_blocks(totb, dev->dinfo.block_size, cap);727 cap_from_blocks(totb, dev->dinfo.block_size, cap); 727 728 return EOK; 728 729 } … … 995 996 int rc; 996 997 997 rc = fdisk_cap_to_blocks(&pspec->capacity, fcv_nom, dev->dinfo.block_size,998 rc = cap_spec_to_blocks(&pspec->capacity, cv_nom, dev->dinfo.block_size, 998 999 &nom_blocks); 999 1000 if (rc != EOK) 1000 1001 return rc; 1001 1002 1002 rc = fdisk_cap_to_blocks(&pspec->capacity, fcv_min, dev->dinfo.block_size,1003 rc = cap_spec_to_blocks(&pspec->capacity, cv_min, dev->dinfo.block_size, 1003 1004 &min_blocks); 1004 1005 if (rc != EOK) 1005 1006 return rc; 1006 1007 1007 rc = fdisk_cap_to_blocks(&pspec->capacity, fcv_max, dev->dinfo.block_size,1008 rc = cap_spec_to_blocks(&pspec->capacity, cv_max, dev->dinfo.block_size, 1008 1009 &max_blocks); 1009 1010 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.