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

Defines

#define _(String)   (String)
#define N_(String)   String
#define PED_GIBIBYTE_SIZE   1073741824LL
#define PED_GIGABYTE_SIZE   1000000000LL
#define PED_KIBIBYTE_SIZE   1024LL
#define PED_KILOBYTE_SIZE   1000LL
#define PED_MEBIBYTE_SIZE   1048576LL
#define PED_MEGABYTE_SIZE   1000000LL
#define PED_SECTOR_SIZE_DEFAULT   512LL
#define PED_TEBIBYTE_SIZE   1099511627776LL
#define PED_TERABYTE_SIZE   1000000000000LL
#define PED_UNIT_FIRST   PED_UNIT_SECTOR
#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
}
 Human-friendly unit for representation of a location within device.

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.


Function Documentation

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 ped_free().

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 ped_free().

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 ped_free().

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 ped_free().

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.

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".

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

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_ERROR if str contains invalid description of a location
PED_EXCEPTION_ERROR if location described by str is outside of the device dev->path
Returns:
1 if str is a valid location description, 0 otherwise.

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.


Generated on Fri May 4 05:15:31 2007 for libparted by  doxygen 1.5.2