PyObject *py_ped_geometry_test_inside(PyObject *s, PyObject *args) { int ret = -1; PyObject *in_b = NULL; PedGeometry *out_a = NULL, *out_b = NULL; if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_b)) { return NULL; } out_a = _ped_Geometry2PedGeometry(s); if (out_a == NULL) { return NULL; } out_b = _ped_Geometry2PedGeometry(in_b); if (out_b == NULL) { return NULL; } ret = ped_geometry_test_inside(out_a, out_b); if (ret) { Py_RETURN_TRUE; } else { Py_RETURN_FALSE; } }
/** * This function opens the file system stored on \p geom, if it * can find one. * It is often called in the following manner: * \code * fs = ped_file_system_open (&part.geom) * \endcode * * \throws PED_EXCEPTION_ERROR if file system could not be detected * \throws PED_EXCEPTION_ERROR if the file system is bigger than its volume * \throws PED_EXCEPTION_NO_FEATURE if opening of a file system stored on * \p geom is not implemented * * \return a PedFileSystem on success, \c NULL on failure. */ PedFileSystem * ped_file_system_open (PedGeometry* geom) { PED_ASSERT (geom != NULL); if (!ped_device_open (geom->dev)) goto error; PedFileSystemType *type = ped_file_system_probe (geom); if (!type) { ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("Could not detect file system.")); goto error_close_dev; } open_fn_t open_f = open_fn (type->name); if (open_f == NULL) { ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("resizing %s file systems is not supported"), type->name); goto error_close_dev; } PedGeometry *probed_geom = ped_file_system_probe_specific (type, geom); if (!probed_geom) goto error_close_dev; if (!ped_geometry_test_inside (geom, probed_geom)) { if (ped_exception_throw ( PED_EXCEPTION_ERROR, PED_EXCEPTION_IGNORE_CANCEL, _("The file system is bigger than its volume!")) != PED_EXCEPTION_IGNORE) goto error_destroy_probed_geom; } PedFileSystem *fs = (*open_f) (probed_geom); if (!fs) goto error_destroy_probed_geom; ped_geometry_destroy (probed_geom); fs->type = type; return fs; error_destroy_probed_geom: ped_geometry_destroy (probed_geom); error_close_dev: ped_device_close (geom->dev); error: return NULL; }
/* 1:1 function mappings for constraint.h in libparted */ PyObject *py_ped_constraint_new_from_min_max(PyObject *s, PyObject *args) { PyObject *in_min = NULL, *in_max = NULL; PedGeometry *out_min = NULL, *out_max = NULL; PedConstraint *constraint = NULL; _ped_Constraint *ret = NULL; if (!PyArg_ParseTuple(args, "O!O!", &_ped_Geometry_Type_obj, &in_min, &_ped_Geometry_Type_obj, &in_max)) { return NULL; } out_min = _ped_Geometry2PedGeometry(in_min); if (out_min == NULL) { return NULL; } out_max = _ped_Geometry2PedGeometry(in_max); if (out_max == NULL) { return NULL; } /* ped_constraint_new_from_min_max will ASSERT if this isn't enforced. */ if (!ped_geometry_test_inside(out_max, out_min)) { PyErr_SetString(CreateException, "min geometry must be contained within max geometry"); return NULL; } constraint = ped_constraint_new_from_min_max(out_min, out_max); if (constraint) { ret = PedConstraint2_ped_Constraint(constraint); } else { PyErr_SetString(CreateException, "Could not create new constraint from min/max"); return NULL; } ped_constraint_destroy(constraint); return (PyObject *) ret; }
/** * Return a constraint that requires a region to be entirely contained inside * \p max, and to entirely contain \p min. * * \return \c NULL on failure. */ PedConstraint* ped_constraint_new_from_min_max ( const PedGeometry* min, const PedGeometry* max) { PedGeometry start_range; PedGeometry end_range; PED_ASSERT (min != NULL); PED_ASSERT (max != NULL); PED_ASSERT (ped_geometry_test_inside (max, min)); ped_geometry_init (&start_range, min->dev, max->start, min->start - max->start + 1); ped_geometry_init (&end_range, min->dev, min->end, max->end - min->end + 1); return ped_constraint_new ( ped_alignment_any, ped_alignment_any, &start_range, &end_range, min->length, max->length); }