예제 #1
0
파일: unit.c 프로젝트: Excito/parted
/**
 * \brief Get a string that describes the location \p sector on device \p 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().
 */
char*
ped_unit_format (const PedDevice* dev, PedSector sector)
{
	PED_ASSERT (dev != NULL);
	return ped_unit_format_custom_byte (dev, sector * dev->sector_size,
					    default_unit);
}
예제 #2
0
파일: pyunit.c 프로젝트: g2p/pyparted
PyObject *py_ped_unit_format_custom_byte(PyObject *s, PyObject *args) {
    PyObject *ret = NULL;
    char *pedret = NULL;
    PedSector sector;
    int unit;
    PedDevice *out_dev = NULL;

    if (!PyArg_ParseTuple(args, "Li", &sector, &unit)) {
        return NULL;
    }

    if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) {
        PyErr_SetString(PyExc_ValueError, "Invalid unit provided.");
        return NULL;
    }

    out_dev = _ped_Device2PedDevice(s);
    if (out_dev == NULL) {
        return NULL;
    }

    pedret = ped_unit_format_custom_byte(out_dev, sector, unit);
    if (pedret != NULL) {
        ret = PyUnicode_FromString(pedret);
        free(pedret);
    } else {
        ret = PyUnicode_FromString("");
    }

    return ret;
}
예제 #3
0
파일: unit.c 프로젝트: Excito/parted
/**
 * \brief Get a string that describes the location of the \p byte on
 * device \p 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().
 */
char*
ped_unit_format_byte (const PedDevice* dev, PedSector byte)
{
	PED_ASSERT (dev != NULL);
	return ped_unit_format_custom_byte (dev, byte, default_unit);
}