|
Last change
on this file since cd1e3fc0 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago |
|
Replace some license headers with SPDX identifier
Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2015 Jiri Svoboda
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /** @addtogroup libc
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /**
|
|---|
| 11 | * @file Storage capacity specification.
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #ifndef _LIBC_CAPA_H_
|
|---|
| 15 | #define _LIBC_CAPA_H_
|
|---|
| 16 |
|
|---|
| 17 | #include <errno.h>
|
|---|
| 18 | #include <stddef.h>
|
|---|
| 19 | #include <stdint.h>
|
|---|
| 20 |
|
|---|
| 21 | /** Capacity unit */
|
|---|
| 22 | typedef enum {
|
|---|
| 23 | cu_byte = 0,
|
|---|
| 24 | cu_kbyte,
|
|---|
| 25 | cu_mbyte,
|
|---|
| 26 | cu_gbyte,
|
|---|
| 27 | cu_tbyte,
|
|---|
| 28 | cu_pbyte,
|
|---|
| 29 | cu_ebyte,
|
|---|
| 30 | cu_zbyte,
|
|---|
| 31 | cu_ybyte
|
|---|
| 32 | } capa_unit_t;
|
|---|
| 33 |
|
|---|
| 34 | /** Which of values within the precision of the capacity */
|
|---|
| 35 | typedef enum {
|
|---|
| 36 | /** The nominal (middling) value */
|
|---|
| 37 | cv_nom,
|
|---|
| 38 | /** The minimum value */
|
|---|
| 39 | cv_min,
|
|---|
| 40 | /** The maximum value */
|
|---|
| 41 | cv_max
|
|---|
| 42 | } capa_vsel_t;
|
|---|
| 43 |
|
|---|
| 44 | #define CU_LIMIT (cu_ybyte + 1)
|
|---|
| 45 |
|
|---|
| 46 | /** Storage capacity.
|
|---|
| 47 | *
|
|---|
| 48 | * Storage capacity represents both value and precision.
|
|---|
| 49 | * It is a decimal floating point value combined with a decimal
|
|---|
| 50 | * capacity unit. There is an integer mantisa @c m which in combination
|
|---|
| 51 | * with the number of decimal positions @c dp gives a decimal floating-point
|
|---|
| 52 | * number. E.g. for m = 1025 and dp = 2 the number is 10.25. If the unit
|
|---|
| 53 | * cunit = cu_kbyte, the capacity is 10.25 kByte, i.e. 10 250 bytes.
|
|---|
| 54 | *
|
|---|
| 55 | * Note that 1.000 kByte is equivalent to 1000 Byte, but 1 kByte is less
|
|---|
| 56 | * precise.
|
|---|
| 57 | */
|
|---|
| 58 | typedef struct {
|
|---|
| 59 | /** Mantisa */
|
|---|
| 60 | uint64_t m;
|
|---|
| 61 | /** Decimal positions */
|
|---|
| 62 | unsigned dp;
|
|---|
| 63 | /** Capacity unit */
|
|---|
| 64 | capa_unit_t cunit;
|
|---|
| 65 | } capa_spec_t;
|
|---|
| 66 |
|
|---|
| 67 | extern errno_t capa_format(capa_spec_t *, char **);
|
|---|
| 68 | extern errno_t capa_parse(const char *, capa_spec_t *);
|
|---|
| 69 | extern void capa_simplify(capa_spec_t *);
|
|---|
| 70 | extern void capa_from_blocks(uint64_t, size_t, capa_spec_t *);
|
|---|
| 71 | extern errno_t capa_to_blocks(capa_spec_t *, capa_vsel_t, size_t, uint64_t *);
|
|---|
| 72 |
|
|---|
| 73 | #endif
|
|---|
| 74 |
|
|---|
| 75 | /** @}
|
|---|
| 76 | */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.