Changeset 6c4eedf in mainline for uspace/lib/fdisk
- Timestamp:
- 2017-09-13T20:14:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 120d5bc
- Parents:
- 1d40c93d
- Location:
- uspace/lib/fdisk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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.