1N/A libparted - a library for manipulating disk partitions 1N/A Copyright (C) 2005, 2007, 2009-2010 Free Software Foundation, Inc. 1N/A This program is free software; you can redistribute it and/or modify 1N/A it under the terms of the GNU General Public License as published by 1N/A the Free Software Foundation; either version 3 of the License, or 1N/A (at your option) any later version. 1N/A This program is distributed in the hope that it will be useful, 1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A GNU General Public License for more details. 1N/A You should have received a copy of the GNU General Public License 1N/A * \addtogroup PedUnit 1N/A * \brief The PedUnit module provides a standard mechanism for describing 1N/A * and parsing locations within devices in human-friendly plain text. 1N/A * Internally, libparted uses PedSector (which is typedef'ed to be long long 1N/A * end of partitions. However, sector numbers are often long and unintuitive. 1N/A * For example, my extended partition starts at sector 208845. PedUnit allows 1N/A * this location to be represented in more intutitive ways, including "106Mb", 1N/A * "0Gb" and "0%", as well as "208845s". PedUnit aims to provide facilities 1N/A * to provide a consistent system for describing device locations all 1N/A * throughout libparted. 1N/A * PedUnit provides two basic services: converting a PedSector into a text 1N/A * representation, and parsing a text representation into a PedSector. 1N/A * PedUnit currently supports these units: 1N/A * sectors, bytes, kilobytes, megabytes, gigabytes, terabytes, compact, 1N/A * cylinder and percent. 1N/A * PedUnit has a global variable that contains the default unit for all 1N/A#
endif /* ENABLE_NLS */ 1N/A * \brief Set the default \p unit used by subsequent calls to the PedUnit API. 1N/A * In particular, this affects how locations inside error messages 1N/A * (exceptions) are displayed. 1N/A * \brief Get the current default unit. 1N/A * Get the byte size of a given \p unit. 1N/A _(
"Cannot get unit size for special unit " 1N/A * Get a textual (non-internationalized) representation of a \p unit. 1N/A * For example, the textual representation of PED_UNIT_SECTOR is "s". 1N/A * Get a unit based on its textual representation: \p unit_name. 1N/A * For example, ped_unit_get_by_name("Mb") returns PED_UNIT_MEGABYTE. 1N/A * \brief Get a string that describes the location of the \p byte on 1N/A * The string is described with the desired \p unit. 1N/A * The returned string must be freed with free(). 1N/A /* CHS has a special comma-separated format. */ 1N/A /* Cylinders, sectors and bytes should be rounded down... */ 1N/A /* IEEE754 says that 100.5 has to be rounded to 100 (by printf) */ 1N/A /* but 101.5 has to be rounded to 102... so we multiply by 1+E. */ 1N/A /* This just divide by 2 the natural IEEE754 extended precision */ 1N/A /* and won't cause any trouble before 1000 TB */ 1N/A w = d + ( (d <
10. ) ?
0.005 :
1N/A p = (w <
10. ) ?
2 :
1N/A * \brief Get a string that describes the location of the \p byte on 1N/A * The string is described with the default unit, which is set 1N/A * by ped_unit_set_default(). 1N/A * The returned string must be freed with free(). 1N/A * \brief Get a string that describes the location \p sector on device \p dev. 1N/A * The string is described with the desired \p unit. 1N/A * The returned string must be freed with free(). 1N/A * \brief Get a string that describes the location \p sector on device \p dev. 1N/A * The string is described with the default unit, which is set 1N/A * by ped_unit_set_default(). 1N/A * The returned string must be freed with free(). 1N/A * If \p str contains a valid description of a location on \p dev, 1N/A * then \p *sector is modified to describe the location and a geometry 1N/A * is created in \p *range describing a 2 units large area centered on 1N/A * \p *sector. If the \p range as described here would be partially outside 1N/A * the device \p dev, the geometry returned is the intersection between the 1N/A * former and the whole device geometry. If no units are specified, then the 1N/A * default unit is assumed. 1N/A * \return \c 1 if \p str is a valid location description, \c 0 otherwise 1N/A/* Inefficiently removes all spaces from a string, in-place. */ 1N/A for (i = 0;
str[i] != 0; i++) {
1N/A for (j = i +
1;
str[j] != 0; j++)
1N/A/* Find non-number suffix. Eg: find_suffix("32Mb") returns a pointer to 1N/A _(
"\"%s\" has invalid syntax for locations."),
1N/A _(
"The maximum head value is %d."),
1N/A _(
"The maximum sector value is %d."),
1N/A _(
"The location %s is outside of the " 1N/A * If \p str contains a valid description of a location on \p dev, then 1N/A * \p *sector is modified to describe the location and a geometry is created 1N/A * in \p *range describing a 2 units large area centered on \p *sector. If the 1N/A * \p range as described here would be partially outside the device \p dev, the 1N/A * geometry returned is the intersection between the former and the whole 1N/A * device geometry. If no units are specified, then the default unit is 1N/A * \throws PED_EXCEPTION_ERROR if \p str contains invalid description of a 1N/A * \throws PED_EXCEPTION_ERROR if location described by \p str 1N/A * is outside of the device \p dev->path 1N/A * \return \c 1 if \p str is a valid location description, \c 0 otherwise. 1N/A _(
"Invalid number."));
1N/A /* negative numbers count from the end */ 1N/A _(
"The location %s is outside of the "