Changeset 6c4eedf in mainline


Ignore:
Timestamp:
2017-09-13T20:14:49Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
120d5bc
Parents:
1d40c93d
Message:

Move capacity specification to libc.

Location:
uspace
Files:
1 added
7 edited
1 moved

Legend:

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

    r1d40c93d r6c4eedf  
    3535 */
    3636
     37#include <cap.h>
    3738#include <errno.h>
    3839#include <nchoice.h>
     
    151152        nchoice_t *choice = NULL;
    152153        char *svcname = NULL;
    153         fdisk_cap_t cap;
     154        cap_spec_t cap;
    154155        fdisk_dev_info_t *sdev;
    155156        char *scap = NULL;
     
    200201                }
    201202
    202                 fdisk_cap_simplify(&cap);
    203 
    204                 rc = fdisk_cap_format(&cap, &scap);
     203                cap_simplify(&cap);
     204
     205                rc = cap_format(&cap, &scap);
    205206                if (rc != EOK) {
    206207                        assert(rc == ENOMEM);
     
    445446        int rc;
    446447        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;
    449450        vol_label_supp_t vlsupp;
    450451        vol_fstype_t fstype = 0;
     
    466467        }
    467468
    468         fdisk_cap_simplify(&mcap);
    469 
    470         rc = fdisk_cap_format(&mcap, &smcap);
     469        cap_simplify(&mcap);
     470
     471        rc = cap_format(&mcap, &smcap);
    471472        if (rc != EOK) {
    472473                rc = ENOMEM;
     
    490491                        goto error;
    491492
    492                 rc = fdisk_cap_parse(scap, &cap);
     493                rc = cap_parse(scap, &cap);
    493494                if (rc == EOK)
    494495                        break;
     
    586587                }
    587588
    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);
    591592                if (rc != EOK) {
    592593                        printf("Out of memory.\n");
     
    703704        fdisk_part_t *part;
    704705        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;
    707708        fdisk_dev_flags_t dflags;
    708709        char *sltype = NULL;
     
    738739        }
    739740
    740         fdisk_cap_simplify(&cap);
    741 
    742         rc = fdisk_cap_format(&cap, &sdcap);
     741        cap_simplify(&cap);
     742
     743        rc = cap_format(&cap, &sdcap);
    743744        if (rc != EOK) {
    744745                printf("Out of memory.\n");
     
    792793                }
    793794
    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);
    797798                if (rc != EOK) {
    798799                        printf("Out of memory.\n");
     
    849850                }
    850851
    851                 fdisk_cap_simplify(&mcap);
    852 
    853                 rc = fdisk_cap_format(&mcap, &smcap);
     852                cap_simplify(&mcap);
     853
     854                rc = cap_format(&mcap, &smcap);
    854855                if (rc != EOK) {
    855856                        rc = ENOMEM;
     
    871872                }
    872873
    873                 fdisk_cap_simplify(&mcap);
    874 
    875                 rc = fdisk_cap_format(&mcap, &smcap);
     874                cap_simplify(&mcap);
     875
     876                rc = cap_format(&mcap, &smcap);
    876877                if (rc != EOK) {
    877878                        rc = ENOMEM;
     
    896897                }
    897898
    898                 fdisk_cap_simplify(&mcap);
    899 
    900                 rc = fdisk_cap_format(&mcap, &smcap);
     899                cap_simplify(&mcap);
     900
     901                rc = cap_format(&mcap, &smcap);
    901902                if (rc != EOK) {
    902903                        rc = ENOMEM;
     
    914915                }
    915916
    916                 fdisk_cap_simplify(&mcap);
    917 
    918                 rc = fdisk_cap_format(&mcap, &smcap);
     917                cap_simplify(&mcap);
     918
     919                rc = cap_format(&mcap, &smcap);
    919920                if (rc != EOK) {
    920921                        rc = ENOMEM;
  • uspace/app/sysinst/sysinst.c

    r1d40c93d r6c4eedf  
    3838#include <block.h>
    3939#include <byteorder.h>
     40#include <cap.h>
    4041#include <errno.h>
    4142#include <fdisk.h>
     
    8990        fdisk_part_t *part;
    9091        fdisk_part_spec_t pspec;
    91         fdisk_cap_t cap;
     92        cap_spec_t cap;
    9293        service_id_t sid;
    9394        int rc;
  • uspace/lib/c/Makefile

    r1d40c93d r6c4eedf  
    6464        generic/bd_srv.c \
    6565        generic/perm.c \
     66        generic/cap.c \
    6667        generic/clipboard.c \
    6768        generic/config.c \
  • uspace/lib/c/generic/cap.c

    r1d40c93d r6c4eedf  
    2727 */
    2828
    29 /** @addtogroup libfdisk
     29/** @addtogroup libc
    3030 * @{
    3131 */
    3232/**
    33  * @file Disk management library.
    34  */
    35 
     33 * @file Storage capacity specification.
     34 */
     35
     36#include <cap.h>
    3637#include <errno.h>
    37 #include <fdisk.h>
    3838#include <imath.h>
    3939#include <stdio.h>
     
    6060};
    6161
    62 void fdisk_cap_from_blocks(uint64_t nblocks, size_t block_size,
    63     fdisk_cap_t *cap)
     62void cap_from_blocks(uint64_t nblocks, size_t block_size, cap_spec_t *cap)
    6463{
    6564        uint64_t tsize;
     
    7877 *
    7978 * 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 gives
    81  * the nominal (middle) value, @c fcv_min gives the minimum value
    82  * 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 */
     83int cap_spec_to_blocks(cap_spec_t *cap, cap_vsel_t cvsel, size_t block_size,
     84    uint64_t *rblocks)
    8685{
    8786        int exp;
     
    108107                adj = 0;
    109108                switch (cvsel) {
    110                 case fcv_nom:
     109                case cv_nom:
    111110                        adj = 0;
    112111                        break;
    113                 case fcv_min:
     112                case cv_min:
    114113                        adj = -(f / 2);
    115114                        break;
    116                 case fcv_max:
     115                case cv_max:
    117116                        adj = f / 2 - 1;
    118117                        break;
     
    139138 * digits and at most two fractional digits, e.g abc.xy <unit>.
    140139 */
    141 void fdisk_cap_simplify(fdisk_cap_t *cap)
     140void cap_simplify(cap_spec_t *cap)
    142141{
    143142        uint64_t div;
     
    176175}
    177176
    178 int fdisk_cap_format(fdisk_cap_t *cap, char **rstr)
     177int cap_format(cap_spec_t *cap, char **rstr)
    179178{
    180179        int rc;
     
    209208}
    210209
    211 static int fdisk_digit_val(char c, int *val)
     210static int cap_digit_val(char c, int *val)
    212211{
    213212        switch (c) {
     
    229228}
    230229
    231 int fdisk_cap_parse(const char *str, fdisk_cap_t *cap)
     230int cap_parse(const char *str, cap_spec_t *cap)
    232231{
    233232        const char *eptr;
     
    241240
    242241        eptr = str;
    243         while (fdisk_digit_val(*eptr, &d) == EOK) {
     242        while (cap_digit_val(*eptr, &d) == EOK) {
    244243                m = m * 10 + d;
    245244                ++eptr;
     
    249248                ++eptr;
    250249                dp = 0;
    251                 while (fdisk_digit_val(*eptr, &d) == EOK) {
     250                while (cap_digit_val(*eptr, &d) == EOK) {
    252251                        m = m * 10 + d;
    253252                        ++dp;
  • uspace/lib/fdisk/Makefile

    r1d40c93d r6c4eedf  
    3333
    3434SOURCES = \
    35         src/cap.c \
    3635        src/fdisk.c
    3736
  • uspace/lib/fdisk/include/fdisk.h

    r1d40c93d r6c4eedf  
    4949extern int fdisk_dev_info_get_svcname(fdisk_dev_info_t *, char **);
    5050extern 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 *);
     51extern int fdisk_dev_info_capacity(fdisk_dev_info_t *, cap_spec_t *);
    5252
    5353extern int fdisk_dev_open(fdisk_t *, service_id_t, fdisk_dev_t **);
     
    5656extern void fdisk_dev_get_flags(fdisk_dev_t *, fdisk_dev_flags_t *);
    5757extern int fdisk_dev_get_svcname(fdisk_dev_t *, char **);
    58 extern int fdisk_dev_capacity(fdisk_dev_t *, fdisk_cap_t *);
     58extern int fdisk_dev_capacity(fdisk_dev_t *, cap_spec_t *);
    5959
    6060extern int fdisk_label_get_info(fdisk_dev_t *, fdisk_label_info_t *);
     
    6565extern fdisk_part_t *fdisk_part_next(fdisk_part_t *);
    6666extern 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 *);
     67extern int fdisk_part_get_max_avail(fdisk_dev_t *, fdisk_spc_t, cap_spec_t *);
     68extern int fdisk_part_get_tot_avail(fdisk_dev_t *, fdisk_spc_t, cap_spec_t *);
    6969extern int fdisk_part_create(fdisk_dev_t *, fdisk_part_spec_t *,
    7070    fdisk_part_t **);
    7171extern int fdisk_part_destroy(fdisk_part_t *);
    7272extern 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 *);
    7973
    8074extern int fdisk_ltype_format(label_type_t, char **);
  • uspace/lib/fdisk/include/types/fdisk.h

    r1d40c93d r6c4eedf  
    3838
    3939#include <adt/list.h>
     40#include <cap.h>
    4041#include <loc.h>
    4142#include <stdint.h>
     
    4344#include <types/vol.h>
    4445#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_ybyte
    57 } 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_max
    67 } fdisk_cvsel_t;
    6846
    6947typedef enum {
     
    8563
    8664#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 decimal
    92  * capacity unit. There is an integer mantisa @c m which in combination
    93  * with the number of decimal positions @c dp gives a decimal floating-point
    94  * number. E.g. for m = 1025 and dp = 2 the number is 10.25. If the unit
    95  * 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 less
    98  * 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;
    10865
    10966/** List of devices available for managing by fdisk */
     
    169126        link_t llog_ba;
    170127        /** Capacity */
    171         fdisk_cap_t capacity;
     128        cap_spec_t capacity;
    172129        /** Partition kind */
    173130        label_pkind_t pkind;
     
    193150typedef struct {
    194151        /** Desired capacity */
    195         fdisk_cap_t capacity;
     152        cap_spec_t capacity;
    196153        /** Partition kind */
    197154        label_pkind_t pkind;
     
    205162typedef struct {
    206163        /** Capacity */
    207         fdisk_cap_t capacity;
     164        cap_spec_t capacity;
    208165        /** Partition kind */
    209166        label_pkind_t pkind;
  • uspace/lib/fdisk/src/fdisk.c

    r1d40c93d r6c4eedf  
    3535
    3636#include <adt/list.h>
     37#include <cap.h>
    3738#include <errno.h>
    3839#include <fdisk.h>
     
    218219}
    219220
    220 int fdisk_dev_info_capacity(fdisk_dev_info_t *info, fdisk_cap_t *cap)
     221int fdisk_dev_info_capacity(fdisk_dev_info_t *info, cap_spec_t *cap)
    221222{
    222223        vbd_disk_info_t vinfo;
     
    227228                return EIO;
    228229
    229         fdisk_cap_from_blocks(vinfo.nblocks, vinfo.block_size, cap);
     230        cap_from_blocks(vinfo.nblocks, vinfo.block_size, cap);
    230231        return EOK;
    231232}
     
    294295                dev->ext_part = part;
    295296
    296         fdisk_cap_from_blocks(part->nblocks, dev->dinfo.block_size,
     297        cap_from_blocks(part->nblocks, dev->dinfo.block_size,
    297298            &part->capacity);
    298299        part->part_id = partid;
     
    535536}
    536537
    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);
     538int fdisk_dev_capacity(fdisk_dev_t *dev, cap_spec_t *cap)
     539{
     540        cap_from_blocks(dev->dinfo.nblocks, dev->dinfo.block_size, cap);
    540541        return EOK;
    541542}
     
    677678
    678679/** 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)
     680int fdisk_part_get_max_avail(fdisk_dev_t *dev, fdisk_spc_t spc, cap_spec_t *cap)
    680681{
    681682        int rc;
     
    696697        }
    697698
    698         fdisk_cap_from_blocks(nb, dev->dinfo.block_size, cap);
     699        cap_from_blocks(nb, dev->dinfo.block_size, cap);
    699700        return EOK;
    700701}
     
    702703/** Get total free space capacity. */
    703704int fdisk_part_get_tot_avail(fdisk_dev_t *dev, fdisk_spc_t spc,
    704     fdisk_cap_t *cap)
     705    cap_spec_t *cap)
    705706{
    706707        fdisk_free_range_t fr;
     
    724725        } while (fdisk_free_range_next(&fr));
    725726
    726         fdisk_cap_from_blocks(totb, dev->dinfo.block_size, cap);
     727        cap_from_blocks(totb, dev->dinfo.block_size, cap);
    727728        return EOK;
    728729}
     
    995996        int rc;
    996997
    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,
    998999            &nom_blocks);
    9991000        if (rc != EOK)
    10001001                return rc;
    10011002
    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,
    10031004            &min_blocks);
    10041005        if (rc != EOK)
    10051006                return rc;
    10061007
    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,
    10081009            &max_blocks);
    10091010        if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.