Changeset 6c4eedf in mainline for uspace/lib/fdisk


Ignore:
Timestamp:
2017-09-13T20:14:49Z (8 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/lib/fdisk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.