Changeset 9854a8f in mainline


Ignore:
Timestamp:
2015-10-24T22:06:34Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03661d19
Parents:
ef9dac04
Message:

Capacity simplification, for display.

Location:
uspace
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/fdisk/fdisk.c

    ref9dac04 r9854a8f  
    167167                }
    168168
     169                fdisk_cap_simplify(&cap);
     170
    169171                rc = fdisk_cap_format(&cap, &scap);
    170172                if (rc != EOK) {
     
    518520                        goto error;
    519521                }
     522
     523                fdisk_cap_simplify(&pinfo.capacity);
    520524
    521525                rc = fdisk_cap_format(&pinfo.capacity, &scap);
     
    662666        }
    663667
     668        fdisk_cap_simplify(&cap);
     669
    664670        rc = fdisk_cap_format(&cap, &sdcap);
    665671        if (rc != EOK) {
     
    713719                        goto error;
    714720                }
     721
     722                fdisk_cap_simplify(&pinfo.capacity);
    715723
    716724                rc = fdisk_cap_format(&pinfo.capacity, &scap);
     
    774782                }
    775783
     784                fdisk_cap_simplify(&mcap);
     785
    776786                rc = fdisk_cap_format(&mcap, &smcap);
    777787                if (rc != EOK) {
     
    794804                }
    795805
     806                fdisk_cap_simplify(&mcap);
     807
    796808                rc = fdisk_cap_format(&mcap, &smcap);
    797809                if (rc != EOK) {
     
    817829                }
    818830
     831                fdisk_cap_simplify(&mcap);
     832
    819833                rc = fdisk_cap_format(&mcap, &smcap);
    820834                if (rc != EOK) {
     
    832846                        goto error;
    833847                }
     848
     849                fdisk_cap_simplify(&mcap);
    834850
    835851                rc = fdisk_cap_format(&mcap, &smcap);
  • uspace/lib/c/Makefile

    ref9dac04 r9854a8f  
    9696        generic/task.c \
    9797        generic/futex.c \
     98        generic/imath.c \
    9899        generic/inet/addr.c \
    99100        generic/inet/endpoint.c \
  • uspace/lib/fdisk/Makefile

    ref9dac04 r9854a8f  
    3333
    3434SOURCES = \
     35        src/cap.c \
    3536        src/fdisk.c
    3637
  • uspace/lib/fdisk/include/fdisk.h

    ref9dac04 r9854a8f  
    7373extern int fdisk_cap_format(fdisk_cap_t *, char **);
    7474extern int fdisk_cap_parse(const char *, fdisk_cap_t *);
     75extern void fdisk_cap_simplify(fdisk_cap_t *);
     76extern void fdisk_cap_from_blocks(uint64_t, size_t, fdisk_cap_t *);
     77extern int fdisk_cap_to_blocks(fdisk_cap_t *, size_t, uint64_t *);
     78
    7579extern int fdisk_ltype_format(label_type_t, char **);
    7680extern int fdisk_fstype_format(vol_fstype_t, char **);
  • uspace/lib/fdisk/include/types/fdisk.h

    ref9dac04 r9854a8f  
    7777#define CU_LIMIT (cu_ybyte + 1)
    7878
    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 */
     91typedef struct {
     92        /** Mantisa */
     93        uint64_t m;
     94        /** Decimal positions */
     95        unsigned dp;
     96        /** Capacity unit */
    8297        fdisk_cunit_t cunit;
    8398} fdisk_cap_t;
  • uspace/lib/fdisk/src/fdisk.c

    ref9dac04 r9854a8f  
    4646#include <vol.h>
    4747
    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 
    6048static int fdisk_dev_add_parts(fdisk_dev_t *);
    6149static void fdisk_dev_remove_parts(fdisk_dev_t *);
     
    257245                return EIO;
    258246
    259         cap->value = bsize * nblocks;
    260         cap->cunit = cu_byte;
    261 
     247        fdisk_cap_from_blocks(nblocks, bsize, cap);
    262248        return EOK;
    263249}
     
    330316                dev->ext_part = part;
    331317
    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);
    334320        part->part_id = partid;
    335321
     
    619605        block_fini(dev->sid);
    620606
    621         cap->value = bsize * nblocks;
    622         cap->cunit = cu_byte;
    623 
     607        fdisk_cap_from_blocks(nblocks, bsize, cap);
    624608        return EOK;
    625609}
     
    783767        }
    784768
    785         cap->value = nb * dev->dinfo.block_size;
    786         cap->cunit = cu_byte;
     769        fdisk_cap_from_blocks(nb, dev->dinfo.block_size, cap);
    787770        return EOK;
    788771}
     
    812795        } while (fdisk_free_range_next(&fr));
    813796
    814         cap->value = totb * dev->dinfo.block_size;
    815         cap->cunit = cu_byte;
     797        fdisk_cap_from_blocks(totb, dev->dinfo.block_size, cap);
    816798        return EOK;
    817799}
     
    882864{
    883865        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;
    937866}
    938867
     
    11081037    vbd_part_spec_t *vpspec)
    11091038{
    1110         uint64_t cbytes;
    11111039        aoff64_t req_blocks;
    11121040        aoff64_t fblock0;
    11131041        aoff64_t fnblocks;
    11141042        aoff64_t hdrb;
    1115         uint64_t block_size;
    11161043        label_pcnt_t pcnt;
    1117         unsigned i;
    11181044        int index;
    11191045        int rc;
     
    11211047        printf("fdisk_part_spec_prepare() - dev=%p pspec=%p vpspec=%p\n", dev, pspec,
    11221048            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
    11341051        req_blocks = fdisk_ba_align_up(dev, req_blocks);
    11351052
Note: See TracChangeset for help on using the changeset viewer.