示例#1
0
PyObject *py_ped_device_get_next(PyObject *s, PyObject *args) {
    PyObject *in_device = NULL;
    PedDevice *cur = NULL, *next = NULL;
    _ped_Device *ret = NULL;

    if (!PyArg_ParseTuple(args, "|O!", &_ped_Device_Type_obj, &in_device)) {
        return NULL;
    }

    if (in_device) {
        cur = _ped_Device2PedDevice(in_device);
        if (!cur) {
            return NULL;
        }
    }

    next = ped_device_get_next(cur);
    if (next) {
        ret = PedDevice2_ped_Device(next);
        return (PyObject *) ret;
    }
    else {
        PyErr_SetNone(PyExc_IndexError);
        return NULL;
    }
}
示例#2
0
PyObject *py_ped_constraint_any(PyObject *s, PyObject *args) {
    PyObject *in_device = NULL;
    PedDevice *out_device = NULL;
    PedConstraint *constraint = NULL;
    _ped_Constraint *ret = NULL;

    if (!PyArg_ParseTuple(args, "O!", &_ped_Device_Type_obj, &in_device)) {
        return NULL;
    }

    out_device = _ped_Device2PedDevice(in_device);
    if (out_device == NULL) {
        return NULL;
    }

    constraint = ped_constraint_any(out_device);
    if (constraint) {
        ret = PedConstraint2_ped_Constraint(constraint);
    }
    else {
        PyErr_SetString(CreateException, "Could not create new constraint");
        return NULL;
    }

    ped_constraint_destroy(constraint);

    return (PyObject *) ret;
}
示例#3
0
文件: pyunit.c 项目: g2p/pyparted
PyObject *py_ped_unit_get_size(PyObject *s, PyObject *args) {
    long long ret = -1;
    PedDevice *dev = NULL;
    int unit;

    if (!PyArg_ParseTuple(args, "i", &unit))
        return NULL;

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

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

    ret = ped_unit_get_size(dev, unit);
    if (ret == 0) {
        if (partedExnRaised) {
            partedExnRaised = 0;

            if (!PyErr_Occurred()) {
                PyErr_SetString(PyExc_ValueError, partedExnMessage);
            }
        } else {
            PyErr_SetString(PyExc_ValueError, "Could not get size");
        }

        return NULL;
    }

    return PyLong_FromLong(ret);
}
示例#4
0
PyObject *py_ped_device_check(PyObject *s, PyObject *args) {
    PedSector start, count, ret;
    PedDevice *device = NULL;
    char *out_buf = NULL;

    if (!PyArg_ParseTuple(args, "LL", &start, &count)) {
        return NULL;
    }

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

    if (!device->open_count) {
        PyErr_Format(IOException, "Device %s is not open.", device->path);
        return NULL;
    }

    if (device->external_mode) {
        PyErr_Format(IOException, "Device %s is already open for external access.", device->path);
        return NULL;
    }

    if ((out_buf = malloc(device->sector_size * 32)) == NULL) {
        return PyErr_NoMemory();
    }

    ret = ped_device_check(device, out_buf, start, count);
    free(out_buf);

    return PyLong_FromLongLong(ret);
}
示例#5
0
文件: pyunit.c 项目: g2p/pyparted
PyObject *py_ped_unit_parse(PyObject *s, PyObject *args) {
    int ret;
    char *str = NULL;
    PedDevice *out_dev = NULL;
    PedSector sector;
    PyObject *in_geom = NULL;
    PedGeometry *out_geom = NULL;

    if (!PyArg_ParseTuple(args, "zLO!", &str, &sector,
                          &_ped_Geometry_Type_obj, &in_geom)) {
        return NULL;
    }

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

    out_geom = _ped_Geometry2PedGeometry(in_geom);
    if (out_geom == NULL) {
        return NULL;
    }

    ret = ped_unit_parse(str, out_dev, &sector, &out_geom);

    if (ret) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}
示例#6
0
文件: pyunit.c 项目: g2p/pyparted
PyObject *py_ped_unit_format(PyObject *s, PyObject *args) {
    PyObject *ret = NULL;
    char *pedret = NULL;
    PedDevice *out_dev = NULL;
    PedSector sector;

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

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

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

    return ret;
}
示例#7
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;
}
示例#8
0
PyObject *py_ped_device_cache_remove(PyObject *s, PyObject *args) {
    PedDevice *device = NULL;

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

    ped_device_cache_remove(device);

    Py_INCREF(Py_None);
    return Py_None;
}
示例#9
0
int _ped_Geometry_init(_ped_Geometry *self, PyObject *args, PyObject *kwds) {
    static char *kwlist[] = {"dev", "start", "length", "end", NULL};
    PedDevice *device = NULL;
    long long start, length, end;

    self->dev = NULL;
    self->ped_geometry = NULL;

    if (kwds == NULL) {
        if (!PyArg_ParseTuple(args, "O!LL|L", &_ped_Device_Type_obj, &self->dev,
                              &start, &length, &end)) {
            self->dev = NULL;
            return -1;
        }
    } else {
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!LL|L", kwlist,
                                         &_ped_Device_Type_obj, &self->dev,
                                         &start, &length, &end)) {
            self->dev = NULL;
            return -2;
        }
    }

    device = _ped_Device2PedDevice(self->dev);
    if (device == NULL) {
        self->dev = NULL;
        return -3;
    }
    self->ped_geometry = ped_geometry_new(device, start, length);

    if (self->ped_geometry == NULL) {
        if (partedExnRaised) {
            partedExnRaised = 0;

            if (!PyErr_ExceptionMatches(PartedException) &&
                    !PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
                PyErr_SetString(CreateException, partedExnMessage);
            }
        } else {
            PyErr_SetString(CreateException, "Could not create new geometry");
        }

        self->dev = NULL;
        return -3;
    }

    Py_INCREF(self->dev);

    return 0;
}
示例#10
0
PyObject *py_ped_device_read(PyObject *s, PyObject *args) {
    PyObject *ret = NULL;
    PedSector start, count;
    PedDevice *device = NULL;
    char *out_buf = NULL;

    if (!PyArg_ParseTuple(args, "LL", &start, &count)) {
        return NULL;
    }

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

    if (!device->open_count) {
        PyErr_Format(IOException, "Device %s is not open.", device->path);
        return NULL;
    }

    if (device->external_mode) {
        PyErr_Format(IOException, "Device %s is already open for external access.", device->path);
        return NULL;
    }

    if ((out_buf = malloc(device->sector_size * count)) == NULL) {
        return PyErr_NoMemory();
    }

    if (ped_device_read(device, out_buf, start, count) == 0) {
        if (partedExnRaised) {
            partedExnRaised = 0;

            if (!PyErr_ExceptionMatches(PartedException) &&
                !PyErr_ExceptionMatches(PyExc_NotImplementedError))
                PyErr_SetString(IOException, partedExnMessage);
        }
        else
            PyErr_Format(IOException, "Could not read from device %s", device->path);

        free(out_buf);
        return NULL;
    }

    ret = PyUnicode_FromString(out_buf);
    free(out_buf);

    return ret;
}
示例#11
0
PyObject *py_ped_device_write(PyObject *s, PyObject *args) {
    PyObject *in_buf = NULL;
    PedSector start, count, ret;
    PedDevice *device = NULL;
    void *out_buf = NULL;

    if (!PyArg_ParseTuple(args, "OLL", &in_buf, &start, &count)) {
        return NULL;
    }

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

    out_buf = PyCapsule_GetPointer(in_buf, 0);
    if (out_buf == NULL) {
        return NULL;
    }

    if (!device->open_count) {
        PyErr_Format(IOException, "Device %s is not open.", device->path);
        return NULL;
    }

    if (device->external_mode) {
        PyErr_Format(IOException, "Device %s is already open for external access.", device->path);
        return NULL;
    }

    ret = ped_device_write(device, out_buf, start, count);
    if (ret == 0) {
        if (partedExnRaised) {
            partedExnRaised = 0;

            if (!PyErr_ExceptionMatches(PartedException) &&
                !PyErr_ExceptionMatches(PyExc_NotImplementedError))
                PyErr_SetString(IOException, partedExnMessage);
        }
        else
            PyErr_Format(IOException, "Could not write to device %s", device->path);

        return NULL;
    }

    return PyLong_FromLong(ret);
}
示例#12
0
PyObject *py_ped_device_is_busy(PyObject *s, PyObject *args) {
    int ret = -1;
    PedDevice *device = NULL;

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

    ret = ped_device_is_busy(device);

    if (ret) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}
示例#13
0
PyObject *py_ped_device_close(PyObject *s, PyObject *args) {
    int ret = -1;
    PedDevice *device = NULL;

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

    if (!device->open_count) {
        PyErr_Format(IOException, "Device %s is not open.", device->path);
        return NULL;
    }

    if (device->external_mode) {
        PyErr_Format(IOException, "Device %s is already open for external access.", device->path);
        return NULL;
    }

    ret = ped_device_close(device);
    if (ret == 0) {
        if (partedExnRaised) {
            partedExnRaised = 0;

            if (!PyErr_ExceptionMatches(PartedException) &&
                !PyErr_ExceptionMatches(PyExc_NotImplementedError))
                PyErr_SetString(IOException, partedExnMessage);
        }
        else
            PyErr_Format(IOException, "Could not close device %s", device->path);

        return NULL;
    }

    ((_ped_Device *) s)->open_count = device->open_count;

    if (ret) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}
示例#14
0
PyObject *py_ped_device_get_optimum_alignment(PyObject *s, PyObject *args) {
    PedDevice *device = NULL;
    PedAlignment *alignment = NULL;
    _ped_Alignment *ret = NULL;

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

    alignment = ped_device_get_optimum_alignment(device);
    if (!alignment) {
        PyErr_SetString(CreateException, "Could not get alignment for device");
        return NULL;
    }

    ret = PedAlignment2_ped_Alignment(alignment);
    ped_alignment_destroy(alignment);

    return (PyObject *) ret;
}
示例#15
0
PyObject *py_ped_device_get_optimal_aligned_constraint(PyObject *s, PyObject *args) {
    PedDevice *device = NULL;
    PedConstraint *constraint = NULL;
    _ped_Constraint *ret = NULL;

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

    constraint = ped_device_get_optimal_aligned_constraint(device);
    if (!constraint) {
        PyErr_SetString(CreateException, "Could not create constraint");
        return NULL;
    }

    ret = PedConstraint2_ped_Constraint(constraint);
    ped_constraint_destroy(constraint);

    return (PyObject *) ret;
}
示例#16
0
/*
 * Returns the _ped.DiskType for the specified _ped.Device.
 * Even though this function is part of pydisk.c, it's a method
 * on _ped.Device since it operates on _ped.Device objects and
 * not on _ped.Disk objects.
 */
PyObject *py_ped_disk_probe(PyObject *s, PyObject *args) {
    PedDevice *device = NULL;
    PedDiskType *type = NULL;
    _ped_DiskType *ret = NULL;

    device = _ped_Device2PedDevice(s);
    if (device) {
        type = ped_disk_probe(device);
        if (type == NULL) {
            PyErr_Format(IOException, "Could not probe device %s", device->path);
            return NULL;
        }

        ret = PedDiskType2_ped_DiskType(type);
        if (ret == NULL) {
            return NULL;
        }
    }

    return (PyObject *) ret;
}
示例#17
0
PyObject *py_ped_device_destroy(PyObject *s, PyObject *args) {
    _ped_Device *dev = (_ped_Device *) s;
    PedDevice *device = NULL;

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

    ped_device_destroy(device);

    Py_CLEAR(dev->hw_geom);
    dev->hw_geom = NULL;

    Py_CLEAR(dev->bios_geom);
    dev->bios_geom = NULL;

    Py_CLEAR(dev);

    Py_INCREF(Py_None);
    return Py_None;
}
示例#18
0
文件: pyunit.c 项目: g2p/pyparted
PyObject *py_ped_unit_parse_custom(PyObject *s, PyObject *args) {
    int ret;
    char *str = NULL;
    PedDevice *out_dev = NULL;
    int unit;
    PedSector sector;
    PyObject *in_geom = NULL;
    PedGeometry *out_geom = NULL;

    if (!PyArg_ParseTuple(args, "ziLO!", &str, &unit, &sector,
                          &_ped_Geometry_Type_obj, &in_geom)) {
        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;
    }

    out_geom = _ped_Geometry2PedGeometry(in_geom);
    if (out_geom == NULL) {
        return NULL;
    }

    ret = ped_unit_parse_custom(str, out_dev, unit, &sector, &out_geom);

    if (ret) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}