libparted 3.6
Loading...
Searching...
No Matches
Files | Macros | Enumerations | Functions
PedUnit

The PedUnit module provides a standard mechanism for describing and parsing locations within devices in human-friendly plain text. More...

Files

file  unit.h
 
file  unit.h
 

Macros

#define _(String)   (String)
 
#define N_(String)   String
 
#define PED_GIBIBYTE_SIZE   1073741824LL
 
#define PED_GIBIBYTE_SIZE   1073741824LL
 
#define PED_GIGABYTE_SIZE   1000000000LL
 
#define PED_GIGABYTE_SIZE   1000000000LL
 
#define PED_KIBIBYTE_SIZE   1024LL
 
#define PED_KIBIBYTE_SIZE   1024LL
 
#define PED_KILOBYTE_SIZE   1000LL
 
#define PED_KILOBYTE_SIZE   1000LL
 
#define PED_MEBIBYTE_SIZE   1048576LL
 
#define PED_MEBIBYTE_SIZE   1048576LL
 
#define PED_MEGABYTE_SIZE   1000000LL
 
#define PED_MEGABYTE_SIZE   1000000LL
 
#define PED_SECTOR_SIZE_DEFAULT   512LL
 
#define PED_SECTOR_SIZE_DEFAULT   512LL
 
#define PED_TEBIBYTE_SIZE   1099511627776LL
 
#define PED_TEBIBYTE_SIZE   1099511627776LL
 
#define PED_TERABYTE_SIZE   1000000000000LL
 
#define PED_TERABYTE_SIZE   1000000000000LL
 
#define PED_UNIT_FIRST   PED_UNIT_SECTOR
 
#define PED_UNIT_FIRST   PED_UNIT_SECTOR
 
#define PED_UNIT_LAST   PED_UNIT_TEBIBYTE
 
#define PED_UNIT_LAST   PED_UNIT_TEBIBYTE
 

Enumerations

enum  PedUnit {
  PED_UNIT_SECTOR , PED_UNIT_BYTE , PED_UNIT_KILOBYTE , PED_UNIT_MEGABYTE ,
  PED_UNIT_GIGABYTE , PED_UNIT_TERABYTE , PED_UNIT_COMPACT , PED_UNIT_CYLINDER ,
  PED_UNIT_CHS , PED_UNIT_PERCENT , PED_UNIT_KIBIBYTE , PED_UNIT_MEBIBYTE ,
  PED_UNIT_GIBIBYTE , PED_UNIT_TEBIBYTE , PED_UNIT_SECTOR , PED_UNIT_BYTE ,
  PED_UNIT_KILOBYTE , PED_UNIT_MEGABYTE , PED_UNIT_GIGABYTE , PED_UNIT_TERABYTE ,
  PED_UNIT_COMPACT , PED_UNIT_CYLINDER , PED_UNIT_CHS , PED_UNIT_PERCENT ,
  PED_UNIT_KIBIBYTE , PED_UNIT_MEBIBYTE , PED_UNIT_GIBIBYTE , PED_UNIT_TEBIBYTE
}
 Human-friendly unit for representation of a location within device. More...
 
enum  PedUnit {
  PED_UNIT_SECTOR , PED_UNIT_BYTE , PED_UNIT_KILOBYTE , PED_UNIT_MEGABYTE ,
  PED_UNIT_GIGABYTE , PED_UNIT_TERABYTE , PED_UNIT_COMPACT , PED_UNIT_CYLINDER ,
  PED_UNIT_CHS , PED_UNIT_PERCENT , PED_UNIT_KIBIBYTE , PED_UNIT_MEBIBYTE ,
  PED_UNIT_GIBIBYTE , PED_UNIT_TEBIBYTE , PED_UNIT_SECTOR , PED_UNIT_BYTE ,
  PED_UNIT_KILOBYTE , PED_UNIT_MEGABYTE , PED_UNIT_GIGABYTE , PED_UNIT_TERABYTE ,
  PED_UNIT_COMPACT , PED_UNIT_CYLINDER , PED_UNIT_CHS , PED_UNIT_PERCENT ,
  PED_UNIT_KIBIBYTE , PED_UNIT_MEBIBYTE , PED_UNIT_GIBIBYTE , PED_UNIT_TEBIBYTE
}
 Human-friendly unit for representation of a location within device. More...
 

Functions

char * ped_unit_format (const PedDevice *dev, PedSector sector)
 Get a string that describes the location sector on device dev.
 
char * ped_unit_format_byte (const PedDevice *dev, PedSector byte)
 Get a string that describes the location of the byte on device dev.
 
char * ped_unit_format_custom (const PedDevice *dev, PedSector sector, PedUnit unit)
 Get a string that describes the location sector on device dev.
 
char * ped_unit_format_custom_byte (const PedDevice *dev, PedSector byte, PedUnit unit)
 Get a string that describes the location of the byte on device dev.
 
PedUnit ped_unit_get_by_name (const char *unit_name)
 Get a unit based on its textual representation: unit_name.
 
PedUnit ped_unit_get_default ()
 Get the current default unit.
 
const char * ped_unit_get_name (PedUnit unit)
 Get a textual (non-internationalized) representation of a unit.
 
long long ped_unit_get_size (const PedDevice *dev, PedUnit unit)
 Get the byte size of a given unit.
 
int ped_unit_parse (const char *str, const PedDevice *dev, PedSector *sector, PedGeometry **range)
 If str contains a valid description of a location on dev, then *sector is modified to describe the location and a geometry is created in *range describing a 2 units large area centered on *sector.
 
int ped_unit_parse_custom (const char *str, const PedDevice *dev, PedUnit unit, PedSector *sector, PedGeometry **range)
 If str contains a valid description of a location on dev, then *sector is modified to describe the location and a geometry is created in *range describing a 2 units large area centered on *sector.
 
void ped_unit_set_default (PedUnit unit)
 Set the default unit used by subsequent calls to the PedUnit API.
 

Detailed Description

The PedUnit module provides a standard mechanism for describing and parsing locations within devices in human-friendly plain text.

Internally, libparted uses PedSector (which is typedef'ed to be long long in <parted/device.h>) to describe device locations such as the start and end of partitions. However, sector numbers are often long and unintuitive. For example, my extended partition starts at sector 208845. PedUnit allows this location to be represented in more intutitive ways, including "106Mb", "0Gb" and "0%", as well as "208845s". PedUnit aims to provide facilities to provide a consistent system for describing device locations all throughout libparted.

PedUnit provides two basic services: converting a PedSector into a text representation, and parsing a text representation into a PedSector. PedUnit currently supports these units:

    sectors, bytes, kilobytes, megabytes, gigabytes, terabytes, compact,
    cylinder and percent.

PedUnit has a global variable that contains the default unit for all conversions.

Macro Definition Documentation

◆ _

#define _ (   String)    (String)

◆ N_

#define N_ (   String)    String

◆ PED_GIBIBYTE_SIZE [1/2]

#define PED_GIBIBYTE_SIZE   1073741824LL

◆ PED_GIBIBYTE_SIZE [2/2]

#define PED_GIBIBYTE_SIZE   1073741824LL

◆ PED_GIGABYTE_SIZE [1/2]

#define PED_GIGABYTE_SIZE   1000000000LL

◆ PED_GIGABYTE_SIZE [2/2]

#define PED_GIGABYTE_SIZE   1000000000LL

◆ PED_KIBIBYTE_SIZE [1/2]

#define PED_KIBIBYTE_SIZE   1024LL

◆ PED_KIBIBYTE_SIZE [2/2]

#define PED_KIBIBYTE_SIZE   1024LL

◆ PED_KILOBYTE_SIZE [1/2]

#define PED_KILOBYTE_SIZE   1000LL

◆ PED_KILOBYTE_SIZE [2/2]

#define PED_KILOBYTE_SIZE   1000LL

◆ PED_MEBIBYTE_SIZE [1/2]

#define PED_MEBIBYTE_SIZE   1048576LL

◆ PED_MEBIBYTE_SIZE [2/2]

#define PED_MEBIBYTE_SIZE   1048576LL

◆ PED_MEGABYTE_SIZE [1/2]

#define PED_MEGABYTE_SIZE   1000000LL

◆ PED_MEGABYTE_SIZE [2/2]

#define PED_MEGABYTE_SIZE   1000000LL

◆ PED_SECTOR_SIZE_DEFAULT [1/2]

#define PED_SECTOR_SIZE_DEFAULT   512LL

◆ PED_SECTOR_SIZE_DEFAULT [2/2]

#define PED_SECTOR_SIZE_DEFAULT   512LL

◆ PED_TEBIBYTE_SIZE [1/2]

#define PED_TEBIBYTE_SIZE   1099511627776LL

◆ PED_TEBIBYTE_SIZE [2/2]

#define PED_TEBIBYTE_SIZE   1099511627776LL

◆ PED_TERABYTE_SIZE [1/2]

#define PED_TERABYTE_SIZE   1000000000000LL

◆ PED_TERABYTE_SIZE [2/2]

#define PED_TERABYTE_SIZE   1000000000000LL

◆ PED_UNIT_FIRST [1/2]

#define PED_UNIT_FIRST   PED_UNIT_SECTOR

◆ PED_UNIT_FIRST [2/2]

#define PED_UNIT_FIRST   PED_UNIT_SECTOR

◆ PED_UNIT_LAST [1/2]

#define PED_UNIT_LAST   PED_UNIT_TEBIBYTE

◆ PED_UNIT_LAST [2/2]

#define PED_UNIT_LAST   PED_UNIT_TEBIBYTE

Enumeration Type Documentation

◆ PedUnit [1/2]

enum PedUnit

Human-friendly unit for representation of a location within device.

Enumerator
PED_UNIT_SECTOR 
PED_UNIT_BYTE 
PED_UNIT_KILOBYTE 
PED_UNIT_MEGABYTE 
PED_UNIT_GIGABYTE 
PED_UNIT_TERABYTE 
PED_UNIT_COMPACT 
PED_UNIT_CYLINDER 
PED_UNIT_CHS 
PED_UNIT_PERCENT 
PED_UNIT_KIBIBYTE 
PED_UNIT_MEBIBYTE 
PED_UNIT_GIBIBYTE 
PED_UNIT_TEBIBYTE 
PED_UNIT_SECTOR 
PED_UNIT_BYTE 
PED_UNIT_KILOBYTE 
PED_UNIT_MEGABYTE 
PED_UNIT_GIGABYTE 
PED_UNIT_TERABYTE 
PED_UNIT_COMPACT 
PED_UNIT_CYLINDER 
PED_UNIT_CHS 
PED_UNIT_PERCENT 
PED_UNIT_KIBIBYTE 
PED_UNIT_MEBIBYTE 
PED_UNIT_GIBIBYTE 
PED_UNIT_TEBIBYTE 

◆ PedUnit [2/2]

enum PedUnit

Human-friendly unit for representation of a location within device.

Enumerator
PED_UNIT_SECTOR 
PED_UNIT_BYTE 
PED_UNIT_KILOBYTE 
PED_UNIT_MEGABYTE 
PED_UNIT_GIGABYTE 
PED_UNIT_TERABYTE 
PED_UNIT_COMPACT 
PED_UNIT_CYLINDER 
PED_UNIT_CHS 
PED_UNIT_PERCENT 
PED_UNIT_KIBIBYTE 
PED_UNIT_MEBIBYTE 
PED_UNIT_GIBIBYTE 
PED_UNIT_TEBIBYTE 
PED_UNIT_SECTOR 
PED_UNIT_BYTE 
PED_UNIT_KILOBYTE 
PED_UNIT_MEGABYTE 
PED_UNIT_GIGABYTE 
PED_UNIT_TERABYTE 
PED_UNIT_COMPACT 
PED_UNIT_CYLINDER 
PED_UNIT_CHS 
PED_UNIT_PERCENT 
PED_UNIT_KIBIBYTE 
PED_UNIT_MEBIBYTE 
PED_UNIT_GIBIBYTE 
PED_UNIT_TEBIBYTE 

Function Documentation

◆ ped_unit_format()

char * ped_unit_format ( const PedDevice dev,
PedSector  sector 
)

Get a string that describes the location sector on device dev.

The string is described with the default unit, which is set by ped_unit_set_default(). The returned string must be freed with free().

◆ ped_unit_format_byte()

char * ped_unit_format_byte ( const PedDevice dev,
PedSector  byte 
)

Get a string that describes the location of the byte on device dev.

The string is described with the default unit, which is set by ped_unit_set_default(). The returned string must be freed with free().

◆ ped_unit_format_custom()

char * ped_unit_format_custom ( const PedDevice dev,
PedSector  sector,
PedUnit  unit 
)

Get a string that describes the location sector on device dev.

The string is described with the desired unit. The returned string must be freed with free().

◆ ped_unit_format_custom_byte()

char * ped_unit_format_custom_byte ( const PedDevice dev,
PedSector  byte,
PedUnit  unit 
)

Get a string that describes the location of the byte on device dev.

The string is described with the desired unit. The returned string must be freed with free().

◆ ped_unit_get_by_name()

PedUnit ped_unit_get_by_name ( const char *  unit_name)

Get a unit based on its textual representation: unit_name.

For example, ped_unit_get_by_name("Mb") returns PED_UNIT_MEGABYTE.

◆ ped_unit_get_default()

PedUnit _GL_ATTRIBUTE_PURE ped_unit_get_default ( )

Get the current default unit.

◆ ped_unit_get_name()

const char * ped_unit_get_name ( PedUnit  unit)

Get a textual (non-internationalized) representation of a unit.

For example, the textual representation of PED_UNIT_SECTOR is "s".

◆ ped_unit_get_size()

long long ped_unit_get_size ( const PedDevice dev,
PedUnit  unit 
)

Get the byte size of a given unit.

◆ ped_unit_parse()

int ped_unit_parse ( const char *  str,
const PedDevice dev,
PedSector sector,
PedGeometry **  range 
)

If str contains a valid description of a location on dev, then *sector is modified to describe the location and a geometry is created in *range describing a 2 units large area centered on *sector.

If the range as described here would be partially outside the device dev, the geometry returned is the intersection between the former and the whole device geometry. If no units are specified, then the default unit is assumed.

Returns
1 if str is a valid location description, 0 otherwise

◆ ped_unit_parse_custom()

int ped_unit_parse_custom ( const char *  str,
const PedDevice dev,
PedUnit  unit,
PedSector sector,
PedGeometry **  range 
)

If str contains a valid description of a location on dev, then *sector is modified to describe the location and a geometry is created in *range describing a 2 units large area centered on *sector.

If the range as described here would be partially outside the device dev, the geometry returned is the intersection between the former and the whole device geometry. If no units are specified, then the default unit is assumed.

Exceptions
PED_EXCEPTION_ERRORif str contains invalid description of a location
PED_EXCEPTION_ERRORif location described by str is outside of the device dev->path
Returns
1 if str is a valid location description, 0 otherwise.

◆ ped_unit_set_default()

void ped_unit_set_default ( PedUnit  unit)

Set the default unit used by subsequent calls to the PedUnit API.

In particular, this affects how locations inside error messages (exceptions) are displayed.