Changeset c24b0dcb in mainline
- Timestamp:
- 2019-09-30T16:38:33Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8f57fb2
- Parents:
- ef0a3375
- git-author:
- Jakub Jermar <jakub@…> (2019-09-30 16:34:10)
- git-committer:
- Jakub Jermar <jakub@…> (2019-09-30 16:38:33)
- Location:
- uspace
- Files:
-
- 9 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/ls/ls.c
ref0a3375 rc24b0dcb 42 42 #include <vfs/vfs.h> 43 43 #include <str.h> 44 #include <cap .h>44 #include <capa.h> 45 45 46 46 #include "ls.h" … … 106 106 } 107 107 108 cap _spec_t cap;109 cap _from_blocks(de->s.size, 1, &cap);110 cap _simplify(&cap);108 capa_spec_t capa; 109 capa_from_blocks(de->s.size, 1, &capa); 110 capa_simplify(&capa); 111 111 112 112 char *rptr; 113 errno_t rc = cap _format(&cap, &rptr);113 errno_t rc = capa_format(&capa, &rptr); 114 114 if (rc != EOK) { 115 115 return rc; -
uspace/app/df/df.c
ref0a3375 rc24b0dcb 35 35 */ 36 36 37 #include <cap .h>37 #include <capa.h> 38 38 #include <stdbool.h> 39 39 #include <stdio.h> … … 124 124 static errno_t size_to_human_readable(uint64_t nblocks, size_t block_size, char **rptr) 125 125 { 126 cap _spec_t cap;127 128 cap _from_blocks(nblocks, block_size, &cap);129 cap _simplify(&cap);130 return cap _format(&cap, rptr);126 capa_spec_t capa; 127 128 capa_from_blocks(nblocks, block_size, &capa); 129 capa_simplify(&capa); 130 return capa_format(&capa, rptr); 131 131 } 132 132 -
uspace/app/fdisk/fdisk.c
ref0a3375 rc24b0dcb 34 34 */ 35 35 36 #include <cap .h>36 #include <capa.h> 37 37 #include <errno.h> 38 38 #include <fdisk.h> … … 136 136 nchoice_t *choice = NULL; 137 137 char *svcname = NULL; 138 cap _spec_t cap;138 capa_spec_t capa; 139 139 fdisk_dev_info_t *sdev; 140 char *scap = NULL;140 char *scapa = NULL; 141 141 char *dtext = NULL; 142 142 service_id_t svcid; … … 177 177 } 178 178 179 rc = fdisk_dev_info_capacity(info, &cap );179 rc = fdisk_dev_info_capacity(info, &capa); 180 180 if (rc != EOK) { 181 181 printf("Error getting device capacity " … … 185 185 } 186 186 187 cap _simplify(&cap);188 189 rc = cap _format(&cap, &scap);187 capa_simplify(&capa); 188 189 rc = capa_format(&capa, &scapa); 190 190 if (rc != EOK) { 191 191 assert(rc == ENOMEM); … … 194 194 } 195 195 196 int ret = asprintf(&dtext, "%s (%s)", svcname, scap );196 int ret = asprintf(&dtext, "%s (%s)", svcname, scapa); 197 197 if (ret < 0) { 198 198 rc = ENOMEM; … … 203 203 free(svcname); 204 204 svcname = NULL; 205 free(scap );206 scap = NULL;205 free(scapa); 206 scapa = NULL; 207 207 208 208 rc = nchoice_add(choice, dtext, info, 0); … … 261 261 free(dtext); 262 262 free(svcname); 263 free(scap );263 free(scapa); 264 264 return rc; 265 265 } … … 432 432 errno_t rc; 433 433 fdisk_part_spec_t pspec; 434 cap _spec_t cap;435 cap _spec_t mcap;434 capa_spec_t capa; 435 capa_spec_t mcapa; 436 436 vol_label_supp_t vlsupp; 437 437 vol_fstype_t fstype = 0; 438 438 tinput_t *tinput = NULL; 439 439 fdisk_spc_t spc; 440 char *scap ;441 char *smcap = NULL;440 char *scapa; 441 char *smcapa = NULL; 442 442 char *label = NULL; 443 443 char *mountp = NULL; … … 448 448 spc = spc_pri; 449 449 450 rc = fdisk_part_get_max_avail(dev, spc, &mcap );450 rc = fdisk_part_get_max_avail(dev, spc, &mcapa); 451 451 if (rc != EOK) { 452 452 rc = EIO; … … 454 454 } 455 455 456 cap _simplify(&mcap);457 458 rc = cap _format(&mcap, &smcap);456 capa_simplify(&mcapa); 457 458 rc = capa_format(&mcapa, &smcapa); 459 459 if (rc != EOK) { 460 460 rc = ENOMEM; … … 474 474 while (true) { 475 475 printf("Enter capacity of new partition.\n"); 476 rc = tinput_read_i(tinput, smcap , &scap);476 rc = tinput_read_i(tinput, smcapa, &scapa); 477 477 if (rc != EOK) 478 478 goto error; 479 479 480 rc = cap _parse(scap, &cap);480 rc = capa_parse(scapa, &capa); 481 481 if (rc == EOK) 482 482 break; … … 485 485 tinput_destroy(tinput); 486 486 tinput = NULL; 487 free(smcap );488 smcap = NULL;487 free(smcapa); 488 smcapa = NULL; 489 489 490 490 if (pkind != lpk_extended) { … … 545 545 546 546 fdisk_pspec_init(&pspec); 547 pspec.capacity = cap ;547 pspec.capacity = capa; 548 548 pspec.pkind = pkind; 549 549 pspec.fstype = fstype; … … 561 561 return EOK; 562 562 error: 563 free(smcap );563 free(smcapa); 564 564 free(label); 565 565 free(mountp); … … 581 581 fdisk_part_t *part; 582 582 fdisk_part_info_t pinfo; 583 char *scap = NULL;583 char *scapa = NULL; 584 584 char *spkind = NULL; 585 585 char *sfstype = NULL; … … 596 596 } 597 597 598 cap _simplify(&pinfo.capacity);599 600 rc = cap _format(&pinfo.capacity, &scap);598 capa_simplify(&pinfo.capacity); 599 600 rc = capa_format(&pinfo.capacity, &scapa); 601 601 if (rc != EOK) { 602 602 printf("Out of memory.\n"); … … 623 623 624 624 int ret = asprintf(&sdesc, "%s %s, %s, %s", label, 625 scap , spkind, sfstype);625 scapa, spkind, sfstype); 626 626 if (ret < 0) { 627 627 rc = ENOMEM; … … 630 630 631 631 } else { 632 int ret = asprintf(&sdesc, "%s, %s", scap , spkind);632 int ret = asprintf(&sdesc, "%s, %s", scapa, spkind); 633 633 if (ret < 0) { 634 634 rc = ENOMEM; … … 644 644 } 645 645 646 free(scap );647 scap = NULL;646 free(scapa); 647 scapa = NULL; 648 648 free(spkind); 649 649 spkind = NULL; … … 658 658 return EOK; 659 659 error: 660 free(scap );660 free(scapa); 661 661 free(spkind); 662 662 free(sfstype); … … 907 907 fdisk_part_t *part; 908 908 fdisk_part_info_t pinfo; 909 cap _spec_t cap;910 cap _spec_t mcap;909 capa_spec_t capa; 910 capa_spec_t mcapa; 911 911 fdisk_dev_flags_t dflags; 912 912 char *sltype = NULL; 913 char *sdcap = NULL;914 char *scap = NULL;915 char *smcap = NULL;913 char *sdcapa = NULL; 914 char *scapa = NULL; 915 char *smcapa = NULL; 916 916 char *sfstype = NULL; 917 917 char *svcname = NULL; … … 936 936 } 937 937 938 rc = fdisk_dev_capacity(dev, &cap );938 rc = fdisk_dev_capacity(dev, &capa); 939 939 if (rc != EOK) { 940 940 printf("Error getting device capacity.\n"); … … 942 942 } 943 943 944 cap _simplify(&cap);945 946 rc = cap _format(&cap, &sdcap);944 capa_simplify(&capa); 945 946 rc = capa_format(&capa, &sdcapa); 947 947 if (rc != EOK) { 948 948 printf("Out of memory.\n"); … … 958 958 fdisk_dev_get_flags(dev, &dflags); 959 959 960 printf("Device: %s (%s)\n", svcname, sdcap );961 free(sdcap );962 sdcap = NULL;960 printf("Device: %s (%s)\n", svcname, sdcapa); 961 free(sdcapa); 962 sdcapa = NULL; 963 963 964 964 rc = fdisk_label_get_info(dev, &linfo); … … 996 996 } 997 997 998 cap _simplify(&pinfo.capacity);999 1000 rc = cap _format(&pinfo.capacity, &scap);998 capa_simplify(&pinfo.capacity); 999 1000 rc = capa_format(&pinfo.capacity, &scapa); 1001 1001 if (rc != EOK) { 1002 1002 printf("Out of memory.\n"); … … 1016 1016 1017 1017 if (linfo.ltype == lt_none) 1018 printf("Entire disk: %s %s", label, scap );1018 printf("Entire disk: %s %s", label, scapa); 1019 1019 else 1020 printf("Partition %d: %s %s", npart, label, scap );1020 printf("Partition %d: %s %s", npart, label, scapa); 1021 1021 1022 1022 if ((linfo.flags & lf_ext_supp) != 0) { … … 1037 1037 printf("\n"); 1038 1038 1039 free(scap );1040 scap = NULL;1039 free(scapa); 1040 scapa = NULL; 1041 1041 free(sfstype); 1042 1042 sfstype = NULL; … … 1047 1047 /* Display available space */ 1048 1048 if ((linfo.flags & lf_can_create_pri) != 0) { 1049 rc = fdisk_part_get_max_avail(dev, spc_pri, &mcap );1049 rc = fdisk_part_get_max_avail(dev, spc_pri, &mcapa); 1050 1050 if (rc != EOK) { 1051 1051 rc = EIO; … … 1053 1053 } 1054 1054 1055 cap _simplify(&mcap);1056 1057 rc = cap _format(&mcap, &smcap);1055 capa_simplify(&mcapa); 1056 1057 rc = capa_format(&mcapa, &smcapa); 1058 1058 if (rc != EOK) { 1059 1059 rc = ENOMEM; … … 1062 1062 1063 1063 if ((linfo.flags & lf_ext_supp) != 0) 1064 printf("Maximum free primary block: %s\n", smcap );1064 printf("Maximum free primary block: %s\n", smcapa); 1065 1065 else 1066 printf("Maximum free block: %s\n", smcap );1067 1068 free(smcap );1069 smcap = NULL;1070 1071 rc = fdisk_part_get_tot_avail(dev, spc_pri, &mcap );1066 printf("Maximum free block: %s\n", smcapa); 1067 1068 free(smcapa); 1069 smcapa = NULL; 1070 1071 rc = fdisk_part_get_tot_avail(dev, spc_pri, &mcapa); 1072 1072 if (rc != EOK) { 1073 1073 rc = EIO; … … 1075 1075 } 1076 1076 1077 cap _simplify(&mcap);1078 1079 rc = cap _format(&mcap, &smcap);1077 capa_simplify(&mcapa); 1078 1079 rc = capa_format(&mcapa, &smcapa); 1080 1080 if (rc != EOK) { 1081 1081 rc = ENOMEM; … … 1084 1084 1085 1085 if ((linfo.flags & lf_ext_supp) != 0) 1086 printf("Total free primary space: %s\n", smcap );1086 printf("Total free primary space: %s\n", smcapa); 1087 1087 else 1088 printf("Total free space: %s\n", smcap );1089 1090 free(smcap );1091 smcap = NULL;1088 printf("Total free space: %s\n", smcapa); 1089 1090 free(smcapa); 1091 smcapa = NULL; 1092 1092 } 1093 1093 1094 1094 /* Display available space */ 1095 1095 if ((linfo.flags & lf_can_create_log) != 0) { 1096 rc = fdisk_part_get_max_avail(dev, spc_log, &mcap );1096 rc = fdisk_part_get_max_avail(dev, spc_log, &mcapa); 1097 1097 if (rc != EOK) { 1098 1098 rc = EIO; … … 1100 1100 } 1101 1101 1102 cap _simplify(&mcap);1103 1104 rc = cap _format(&mcap, &smcap);1102 capa_simplify(&mcapa); 1103 1104 rc = capa_format(&mcapa, &smcapa); 1105 1105 if (rc != EOK) { 1106 1106 rc = ENOMEM; … … 1108 1108 } 1109 1109 1110 printf("Maximum free logical block: %s\n", smcap );1111 free(smcap );1112 smcap = NULL;1113 1114 rc = fdisk_part_get_tot_avail(dev, spc_log, &mcap );1110 printf("Maximum free logical block: %s\n", smcapa); 1111 free(smcapa); 1112 smcapa = NULL; 1113 1114 rc = fdisk_part_get_tot_avail(dev, spc_log, &mcapa); 1115 1115 if (rc != EOK) { 1116 1116 rc = EIO; … … 1118 1118 } 1119 1119 1120 cap _simplify(&mcap);1121 1122 rc = cap _format(&mcap, &smcap);1120 capa_simplify(&mcapa); 1121 1122 rc = capa_format(&mcapa, &smcapa); 1123 1123 if (rc != EOK) { 1124 1124 rc = ENOMEM; … … 1126 1126 } 1127 1127 1128 printf("Total free logical space: %s\n", smcap );1129 free(smcap );1130 smcap = NULL;1128 printf("Total free logical space: %s\n", smcapa); 1129 free(smcapa); 1130 smcapa = NULL; 1131 1131 } 1132 1132 … … 1279 1279 return EOK; 1280 1280 error: 1281 free(sdcap );1282 free(scap );1283 free(smcap );1281 free(sdcapa); 1282 free(scapa); 1283 free(smcapa); 1284 1284 free(sfstype); 1285 1285 free(svcname); -
uspace/app/sysinst/sysinst.c
ref0a3375 rc24b0dcb 38 38 #include <block.h> 39 39 #include <byteorder.h> 40 #include <cap .h>40 #include <capa.h> 41 41 #include <errno.h> 42 42 #include <fdisk.h> … … 98 98 fdisk_part_spec_t pspec; 99 99 fdisk_part_info_t pinfo; 100 cap _spec_t cap;100 capa_spec_t capa; 101 101 service_id_t sid; 102 102 errno_t rc; … … 137 137 printf("sysinst_label_dev(): create partition\n"); 138 138 139 rc = fdisk_part_get_max_avail(fdev, spc_pri, &cap );139 rc = fdisk_part_get_max_avail(fdev, spc_pri, &capa); 140 140 if (rc != EOK) { 141 141 printf("Error getting available capacity: %s.\n", str_error(rc)); … … 144 144 145 145 fdisk_pspec_init(&pspec); 146 pspec.capacity = cap ;146 pspec.capacity = capa; 147 147 pspec.pkind = lpk_primary; 148 148 pspec.fstype = fs_ext4; /* Cannot be changed without modifying core.img */ -
uspace/lib/c/generic/capa.c
ref0a3375 rc24b0dcb 34 34 */ 35 35 36 #include <cap .h>36 #include <capa.h> 37 37 #include <errno.h> 38 38 #include <imath.h> … … 43 43 enum { 44 44 /** Simplified capacity maximum integer digits */ 45 scap _max_idig = 3,45 scapa_max_idig = 3, 46 46 /** Simplified capacity maximum significant digits */ 47 scap _max_sdig = 447 scapa_max_sdig = 4 48 48 }; 49 49 … … 60 60 }; 61 61 62 void cap _from_blocks(uint64_t nblocks, size_t block_size, cap_spec_t *cap)62 void capa_from_blocks(uint64_t nblocks, size_t block_size, capa_spec_t *capa) 63 63 { 64 64 uint64_t tsize; 65 65 66 66 tsize = nblocks * block_size; 67 cap ->m = tsize;68 cap ->dp = 0;69 cap ->cunit = cu_byte;67 capa->m = tsize; 68 capa->dp = 0; 69 capa->cunit = cu_byte; 70 70 } 71 71 … … 81 81 * and @c cv_max gives the maximum value. 82 82 */ 83 errno_t cap _to_blocks(cap_spec_t *cap, cap_vsel_t cvsel, size_t block_size,83 errno_t capa_to_blocks(capa_spec_t *capa, capa_vsel_t cvsel, size_t block_size, 84 84 uint64_t *rblocks) 85 85 { … … 92 92 errno_t rc; 93 93 94 exp = cap ->cunit * 3 - cap->dp;94 exp = capa->cunit * 3 - capa->dp; 95 95 if (exp < 0) { 96 96 rc = ipow10_u64(-exp, &f); 97 97 if (rc != EOK) 98 98 return ERANGE; 99 bytes = (cap ->m + (f / 2)) / f;100 if (bytes * f - (f / 2) != cap ->m)99 bytes = (capa->m + (f / 2)) / f; 100 if (bytes * f - (f / 2) != capa->m) 101 101 return ERANGE; 102 102 } else { … … 118 118 } 119 119 120 bytes = cap ->m * f + adj;121 if ((bytes - adj) / f != cap ->m)120 bytes = capa->m * f + adj; 121 if ((bytes - adj) / f != capa->m) 122 122 return ERANGE; 123 123 } … … 138 138 * digits and at most two fractional digits, e.g abc.xy <unit>. 139 139 */ 140 void cap _simplify(cap_spec_t *cap)140 void capa_simplify(capa_spec_t *capa) 141 141 { 142 142 uint64_t div; … … 146 146 errno_t rc; 147 147 148 /* Change units so that we have at most @c scap _max_idig integer digits */149 rc = ipow10_u64(scap _max_idig, &maxv);148 /* Change units so that we have at most @c scapa_max_idig integer digits */ 149 rc = ipow10_u64(scapa_max_idig, &maxv); 150 150 assert(rc == EOK); 151 151 152 rc = ipow10_u64(cap ->dp, &div);152 rc = ipow10_u64(capa->dp, &div); 153 153 assert(rc == EOK); 154 154 155 while (cap ->m / div >= maxv) {156 ++cap ->cunit;157 cap ->dp += 3;155 while (capa->m / div >= maxv) { 156 ++capa->cunit; 157 capa->dp += 3; 158 158 div = div * 1000; 159 159 } 160 160 161 /* Round the number so that we have at most @c scap _max_sdig significant digits */162 sdig = 1 + ilog10_u64(cap ->m); /* number of significant digits */163 if (sdig > scap _max_sdig) {161 /* Round the number so that we have at most @c scapa_max_sdig significant digits */ 162 sdig = 1 + ilog10_u64(capa->m); /* number of significant digits */ 163 if (sdig > scapa_max_sdig) { 164 164 /* Number of digits to remove */ 165 rdig = sdig - scap _max_sdig;166 if (rdig > cap ->dp)167 rdig = cap ->dp;165 rdig = sdig - scapa_max_sdig; 166 if (rdig > capa->dp) 167 rdig = capa->dp; 168 168 169 169 rc = ipow10_u64(rdig, &div); 170 170 assert(rc == EOK); 171 171 172 cap ->m = (cap->m + (div / 2)) / div;173 cap ->dp -= rdig;174 } 175 } 176 177 errno_t cap _format(cap_spec_t *cap, char **rstr)172 capa->m = (capa->m + (div / 2)) / div; 173 capa->dp -= rdig; 174 } 175 } 176 177 errno_t capa_format(capa_spec_t *capa, char **rstr) 178 178 { 179 179 errno_t rc; … … 186 186 sunit = NULL; 187 187 188 assert(cap ->cunit < CU_LIMIT);189 190 rc = ipow10_u64(cap ->dp, &div);188 assert(capa->cunit < CU_LIMIT); 189 190 rc = ipow10_u64(capa->dp, &div); 191 191 if (rc != EOK) 192 192 return rc; 193 193 194 ipart = cap ->m / div;195 fpart = cap ->m % div;196 197 sunit = cu_str[cap ->cunit];198 if (cap ->dp > 0) {194 ipart = capa->m / div; 195 fpart = capa->m % div; 196 197 sunit = cu_str[capa->cunit]; 198 if (capa->dp > 0) { 199 199 ret = asprintf(rstr, "%" PRIu64 ".%0*" PRIu64 " %s", ipart, 200 (int)cap ->dp, fpart, sunit);200 (int)capa->dp, fpart, sunit); 201 201 } else { 202 202 ret = asprintf(rstr, "%" PRIu64 " %s", ipart, sunit); … … 208 208 } 209 209 210 static errno_t cap _digit_val(char c, int *val)210 static errno_t capa_digit_val(char c, int *val) 211 211 { 212 212 switch (c) { … … 248 248 } 249 249 250 errno_t cap _parse(const char *str, cap_spec_t *cap)250 errno_t capa_parse(const char *str, capa_spec_t *capa) 251 251 { 252 252 const char *eptr; … … 260 260 261 261 eptr = str; 262 while (cap _digit_val(*eptr, &d) == EOK) {262 while (capa_digit_val(*eptr, &d) == EOK) { 263 263 m = m * 10 + d; 264 264 ++eptr; … … 268 268 ++eptr; 269 269 dp = 0; 270 while (cap _digit_val(*eptr, &d) == EOK) {270 while (capa_digit_val(*eptr, &d) == EOK) { 271 271 m = m * 10 + d; 272 272 ++dp; … … 281 281 282 282 if (*eptr == '\0') { 283 cap ->cunit = cu_byte;283 capa->cunit = cu_byte; 284 284 } else { 285 285 for (i = 0; i < CU_LIMIT; i++) { … … 296 296 return EINVAL; 297 297 found: 298 cap ->cunit = i;299 } 300 301 cap ->m = m;302 cap ->dp = dp;298 capa->cunit = i; 299 } 300 301 capa->m = m; 302 capa->dp = dp; 303 303 return EOK; 304 304 } -
uspace/lib/c/include/capa.h
ref0a3375 rc24b0dcb 55 55 cu_zbyte, 56 56 cu_ybyte 57 } cap _unit_t;57 } capa_unit_t; 58 58 59 59 /** Which of values within the precision of the capacity */ … … 65 65 /** The maximum value */ 66 66 cv_max 67 } cap _vsel_t;67 } capa_vsel_t; 68 68 69 69 #define CU_LIMIT (cu_ybyte + 1) … … 87 87 unsigned dp; 88 88 /** Capacity unit */ 89 cap _unit_t cunit;90 } cap _spec_t;89 capa_unit_t cunit; 90 } capa_spec_t; 91 91 92 extern errno_t cap _format(cap_spec_t *, char **);93 extern errno_t cap _parse(const char *, cap_spec_t *);94 extern void cap _simplify(cap_spec_t *);95 extern void cap _from_blocks(uint64_t, size_t, cap_spec_t *);96 extern errno_t cap _to_blocks(cap_spec_t *, cap_vsel_t, size_t, uint64_t *);92 extern errno_t capa_format(capa_spec_t *, char **); 93 extern errno_t capa_parse(const char *, capa_spec_t *); 94 extern void capa_simplify(capa_spec_t *); 95 extern void capa_from_blocks(uint64_t, size_t, capa_spec_t *); 96 extern errno_t capa_to_blocks(capa_spec_t *, capa_vsel_t, size_t, uint64_t *); 97 97 98 98 #endif -
uspace/lib/c/meson.build
ref0a3375 rc24b0dcb 65 65 'generic/bd_srv.c', 66 66 'generic/perm.c', 67 'generic/cap .c',67 'generic/capa.c', 68 68 'generic/clipboard.c', 69 69 'generic/config.c', … … 204 204 'test/adt/circ_buf.c', 205 205 'test/adt/odict.c', 206 'test/cap .c',206 'test/capa.c', 207 207 'test/casting.c', 208 208 'test/double_to_str.c', -
uspace/lib/c/test/capa.c
ref0a3375 rc24b0dcb 28 28 29 29 #include <pcut/pcut.h> 30 #include <cap .h>30 #include <capa.h> 31 31 32 32 PCUT_INIT; 33 33 34 PCUT_TEST_SUITE(cap );35 36 PCUT_TEST(cap _format)34 PCUT_TEST_SUITE(capa); 35 36 PCUT_TEST(capa_format) 37 37 { 38 38 int block_size = 4; … … 86 86 }; 87 87 88 cap _spec_t cap;88 capa_spec_t capa; 89 89 char *str; 90 90 errno_t rc; … … 93 93 for (i = 0; i < input_size; i++) { 94 94 for (x = 0; x < block_size; x++) { 95 cap _from_blocks(input[i], block[x], &cap);96 cap _simplify(&cap);97 98 rc = cap _format(&cap, &str);95 capa_from_blocks(input[i], block[x], &capa); 96 capa_simplify(&capa); 97 98 rc = capa_format(&capa, &str); 99 99 100 100 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 102 102 free(str); 103 103 104 cap _from_blocks(block[x], input[i], &cap);105 cap _simplify(&cap);106 107 rc = cap _format(&cap, &str);104 capa_from_blocks(block[x], input[i], &capa); 105 capa_simplify(&capa); 106 107 rc = capa_format(&capa, &str); 108 108 109 109 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 114 114 } 115 115 116 PCUT_TEST(cap _format_rounding)116 PCUT_TEST(capa_format_rounding) 117 117 { 118 118 int input_size = 8; … … 139 139 }; 140 140 141 cap _spec_t cap;141 capa_spec_t capa; 142 142 char *str; 143 143 errno_t rc; … … 145 145 int i; 146 146 for (i = 0; i < input_size; i++) { 147 cap _from_blocks(input[i], 1, &cap);148 cap _simplify(&cap);149 150 rc = cap _format(&cap, &str);147 capa_from_blocks(input[i], 1, &capa); 148 capa_simplify(&capa); 149 150 rc = capa_format(&capa, &str); 151 151 152 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 154 154 free(str); 155 155 156 cap _from_blocks(1, input[i], &cap);157 cap _simplify(&cap);158 159 rc = cap _format(&cap, &str);156 capa_from_blocks(1, input[i], &capa); 157 capa_simplify(&capa); 158 159 rc = capa_format(&capa, &str); 160 160 161 161 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 165 165 } 166 166 167 PCUT_TEST(cap _parse)167 PCUT_TEST(capa_parse) 168 168 { 169 169 int input_size = 4; … … 196 196 }; 197 197 198 cap _spec_t cap;198 capa_spec_t capa; 199 199 errno_t rc; 200 200 int i; 201 201 202 202 for (i = 0; i < input_size; i++) { 203 rc = cap _parse(input[i], &cap);204 205 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 206 PCUT_ASSERT_INT_EQUALS(out_cunit[i], cap .cunit);207 PCUT_ASSERT_INT_EQUALS(out_dp[i], cap .dp);208 PCUT_ASSERT_INT_EQUALS(out_m[i], cap .m);209 } 210 } 211 212 PCUT_TEST(cap _to_blocks)203 rc = capa_parse(input[i], &capa); 204 205 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 206 PCUT_ASSERT_INT_EQUALS(out_cunit[i], capa.cunit); 207 PCUT_ASSERT_INT_EQUALS(out_dp[i], capa.dp); 208 PCUT_ASSERT_INT_EQUALS(out_m[i], capa.m); 209 } 210 } 211 212 PCUT_TEST(capa_to_blocks) 213 213 { 214 214 int input_size = 0; … … 261 261 }; 262 262 263 cap _spec_t cap;263 capa_spec_t capa; 264 264 errno_t rc; 265 265 int i; … … 267 267 268 268 for (i = 0; i < input_size; i++) { 269 cap .m = input_m[i];270 cap .dp = input_dp[i];271 cap .cunit = cu_kbyte;272 273 rc = cap _to_blocks(&cap, cv_nom, block[i], &ret);269 capa.m = input_m[i]; 270 capa.dp = input_dp[i]; 271 capa.cunit = cu_kbyte; 272 273 rc = capa_to_blocks(&capa, cv_nom, block[i], &ret); 274 274 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 275 275 PCUT_ASSERT_INT_EQUALS(out_nom[i], ret); 276 276 277 rc = cap _to_blocks(&cap, cv_min, block[i], &ret);277 rc = capa_to_blocks(&capa, cv_min, block[i], &ret); 278 278 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 279 279 PCUT_ASSERT_INT_EQUALS(out_min[i], ret); 280 280 281 rc = cap _to_blocks(&cap, cv_max, block[i], &ret);281 rc = capa_to_blocks(&capa, cv_max, block[i], &ret); 282 282 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 283 283 PCUT_ASSERT_INT_EQUALS(out_max[i], ret); … … 285 285 } 286 286 287 PCUT_EXPORT(cap );287 PCUT_EXPORT(capa); -
uspace/lib/c/test/main.c
ref0a3375 rc24b0dcb 32 32 PCUT_INIT; 33 33 34 PCUT_IMPORT(cap );34 PCUT_IMPORT(capa); 35 35 PCUT_IMPORT(casting); 36 36 PCUT_IMPORT(circ_buf); -
uspace/lib/fdisk/include/fdisk.h
ref0a3375 rc24b0dcb 50 50 extern errno_t fdisk_dev_info_get_svcname(fdisk_dev_info_t *, char **); 51 51 extern void fdisk_dev_info_get_svcid(fdisk_dev_info_t *, service_id_t *); 52 extern errno_t fdisk_dev_info_capacity(fdisk_dev_info_t *, cap _spec_t *);52 extern errno_t fdisk_dev_info_capacity(fdisk_dev_info_t *, capa_spec_t *); 53 53 54 54 extern errno_t fdisk_dev_open(fdisk_t *, service_id_t, fdisk_dev_t **); … … 57 57 extern void fdisk_dev_get_flags(fdisk_dev_t *, fdisk_dev_flags_t *); 58 58 extern errno_t fdisk_dev_get_svcname(fdisk_dev_t *, char **); 59 extern errno_t fdisk_dev_capacity(fdisk_dev_t *, cap _spec_t *);59 extern errno_t fdisk_dev_capacity(fdisk_dev_t *, capa_spec_t *); 60 60 61 61 extern errno_t fdisk_label_get_info(fdisk_dev_t *, fdisk_label_info_t *); … … 66 66 extern fdisk_part_t *fdisk_part_next(fdisk_part_t *); 67 67 extern errno_t fdisk_part_get_info(fdisk_part_t *, fdisk_part_info_t *); 68 extern errno_t fdisk_part_get_max_avail(fdisk_dev_t *, fdisk_spc_t, cap _spec_t *);69 extern errno_t fdisk_part_get_tot_avail(fdisk_dev_t *, fdisk_spc_t, cap _spec_t *);68 extern errno_t fdisk_part_get_max_avail(fdisk_dev_t *, fdisk_spc_t, capa_spec_t *); 69 extern errno_t fdisk_part_get_tot_avail(fdisk_dev_t *, fdisk_spc_t, capa_spec_t *); 70 70 extern errno_t fdisk_part_create(fdisk_dev_t *, fdisk_part_spec_t *, 71 71 fdisk_part_t **); -
uspace/lib/fdisk/include/types/fdisk.h
ref0a3375 rc24b0dcb 38 38 39 39 #include <adt/list.h> 40 #include <cap .h>40 #include <capa.h> 41 41 #include <loc.h> 42 42 #include <stdint.h> … … 126 126 link_t llog_ba; 127 127 /** Capacity */ 128 cap _spec_t capacity;128 capa_spec_t capacity; 129 129 /** Partition kind */ 130 130 label_pkind_t pkind; … … 150 150 typedef struct { 151 151 /** Desired capacity */ 152 cap _spec_t capacity;152 capa_spec_t capacity; 153 153 /** Partition kind */ 154 154 label_pkind_t pkind; … … 164 164 typedef struct { 165 165 /** Capacity */ 166 cap _spec_t capacity;166 capa_spec_t capacity; 167 167 /** Partition kind */ 168 168 label_pkind_t pkind; -
uspace/lib/fdisk/src/fdisk.c
ref0a3375 rc24b0dcb 35 35 36 36 #include <adt/list.h> 37 #include <cap .h>37 #include <capa.h> 38 38 #include <errno.h> 39 39 #include <fdisk.h> … … 219 219 } 220 220 221 errno_t fdisk_dev_info_capacity(fdisk_dev_info_t *info, cap _spec_t *cap)221 errno_t fdisk_dev_info_capacity(fdisk_dev_info_t *info, capa_spec_t *capa) 222 222 { 223 223 vbd_disk_info_t vinfo; … … 228 228 return EIO; 229 229 230 cap _from_blocks(vinfo.nblocks, vinfo.block_size, cap);230 capa_from_blocks(vinfo.nblocks, vinfo.block_size, capa); 231 231 return EOK; 232 232 } … … 295 295 dev->ext_part = part; 296 296 297 cap _from_blocks(part->nblocks, dev->dinfo.block_size,297 capa_from_blocks(part->nblocks, dev->dinfo.block_size, 298 298 &part->capacity); 299 299 part->part_id = partid; … … 536 536 } 537 537 538 errno_t fdisk_dev_capacity(fdisk_dev_t *dev, cap _spec_t *cap)539 { 540 cap _from_blocks(dev->dinfo.nblocks, dev->dinfo.block_size, cap);538 errno_t fdisk_dev_capacity(fdisk_dev_t *dev, capa_spec_t *capa) 539 { 540 capa_from_blocks(dev->dinfo.nblocks, dev->dinfo.block_size, capa); 541 541 return EOK; 542 542 } … … 679 679 680 680 /** Get size of largest free block. */ 681 errno_t fdisk_part_get_max_avail(fdisk_dev_t *dev, fdisk_spc_t spc, cap_spec_t *cap) 681 errno_t fdisk_part_get_max_avail(fdisk_dev_t *dev, fdisk_spc_t spc, 682 capa_spec_t *capa) 682 683 { 683 684 errno_t rc; … … 698 699 } 699 700 700 cap _from_blocks(nb, dev->dinfo.block_size, cap);701 capa_from_blocks(nb, dev->dinfo.block_size, capa); 701 702 return EOK; 702 703 } … … 704 705 /** Get total free space capacity. */ 705 706 errno_t fdisk_part_get_tot_avail(fdisk_dev_t *dev, fdisk_spc_t spc, 706 cap _spec_t *cap)707 capa_spec_t *capa) 707 708 { 708 709 fdisk_free_range_t fr; … … 726 727 } while (fdisk_free_range_next(&fr)); 727 728 728 cap _from_blocks(totb, dev->dinfo.block_size, cap);729 capa_from_blocks(totb, dev->dinfo.block_size, capa); 729 730 return EOK; 730 731 } … … 938 939 errno_t rc; 939 940 940 rc = cap _to_blocks(&pspec->capacity, cv_nom, dev->dinfo.block_size,941 rc = capa_to_blocks(&pspec->capacity, cv_nom, dev->dinfo.block_size, 941 942 &nom_blocks); 942 943 if (rc != EOK) 943 944 return rc; 944 945 945 rc = cap _to_blocks(&pspec->capacity, cv_min, dev->dinfo.block_size,946 rc = capa_to_blocks(&pspec->capacity, cv_min, dev->dinfo.block_size, 946 947 &min_blocks); 947 948 if (rc != EOK) 948 949 return rc; 949 950 950 rc = cap _to_blocks(&pspec->capacity, cv_max, dev->dinfo.block_size,951 rc = capa_to_blocks(&pspec->capacity, cv_max, dev->dinfo.block_size, 951 952 &max_blocks); 952 953 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.