constraint.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/*
libparted - a library for manipulating disk partitions
Copyright (C) 2000, 2001, 2007 Free Software Foundation, Inc.
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \addtogroup PedConstraint
*
* \brief Constraint solver interface.
*
* Constraints are used to communicate restrictions on operations Constraints
* are restrictions on the location and alignment of the start and end of a
* partition, and the minimum and maximum size.
*
* Constraints are closed under intersection (for the proof see the source
* code). For background information see the Chinese Remainder Theorem.
*
* This interface consists of construction constraints, finding the intersection
* of constraints, and finding solutions to constraints.
*
* The constraint solver allows you to specify constraints on where a partition
* you might want to make sure that a file system is at least 10 Gb, or that it
* starts at the beginning of new cylinder.
*
* The constraint solver in this file unifies solver in geom.c (which allows you
* to specify constraints on ranges) and natmath.c (which allows you to specify
* alignment constraints).
*
* @{
*/
#include <config.h>
/**
* Initializes a pre-allocated piece of memory to contain a constraint
* with the supplied default values.
*
* \return \c 0 on failure.
*/
int
const PedAlignment* start_align,
const PedAlignment* end_align,
const PedGeometry* start_range,
const PedGeometry* end_range,
{
PED_ASSERT (min_size > 0, return 0);
PED_ASSERT (max_size > 0, return 0);
return 1;
}
/**
* Convenience wrapper for ped_constraint_init().
*
* Allocates a new piece of memory and initializes the constraint.
*
* \return \c NULL on failure.
*/
const PedAlignment* start_align,
const PedAlignment* end_align,
const PedGeometry* start_range,
const PedGeometry* end_range,
{
if (!constraint)
goto error;
goto error_free_constraint;
return constraint;
return NULL;
}
/**
* 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.
*/
const PedGeometry* min,
const PedGeometry* max)
{
return ped_constraint_new (
&start_range, &end_range,
}
/**
* Return a constraint that requires a region to entirely contain \p min.
*
* \return \c NULL on failure.
*/
{
}
/**
* Return a constraint that requires a region to be entirely contained inside
* \p max.
*
* \return \c NULL on failure.
*/
{
return ped_constraint_new (
}
/**
* Duplicate a constraint.
*
* \return \c NULL on failure.
*/
{
return ped_constraint_new (
}
/**
* Return a constraint that requires a region to satisfy both \p a and \p b.
*
* Moreover, any region satisfying \p a and \p b will also satisfy the returned
* constraint.
*
* \return \c NULL if no solution could be found (note that \c NULL is a valid
* PedConstraint).
*/
{
if (!a || !b)
return NULL;
if (!start_align)
goto empty;
if (!end_align)
if (!start_range)
goto empty_destroy_end_align;
if (!end_range)
if (!constraint)
goto empty_destroy_end_range;
return constraint;
return NULL;
}
/**
* Release the memory allocated for a PedConstraint constructed with
* ped_constraint_init().
*/
void
{
}
/**
* Release the memory allocated for a PedConstraint constructed with
* ped_constraint_new().
*/
void
{
if (constraint) {
}
}
/*
* Return the region within which the start must lie
* in order to satisfy a constriant. It takes into account
* constraint->start_range, constraint->min_size and constraint->max_size.
* All sectors in this range that also satisfy alignment requirements have
* an end, such that the (start, end) satisfy the constraint.
*/
static PedGeometry*
{
return NULL;
return NULL;
if (min_start < 0)
min_start = 0;
if (max_start < 0)
return NULL;
return ped_geometry_intersect (&start_min_max_range,
}
/*
* Return the nearest start that will have at least one other end that
* together satisfy the constraint.
*/
static PedSector
{
if (!start_range)
return -1;
return result;
}
/*
* Given a constraint and a start ("half of the solution"), find the
* range of all possible ends, such that all (start, end) are solutions
* to constraint (subject to additional alignment requirements).
*/
static PedGeometry*
{
return NULL;
return ped_geometry_intersect (&end_min_max_range,
}
/*
* Given "constraint" and "start", find the end that is nearest to
* "end", such that ("start", the end) together form a solution to
* "constraint".
*/
static PedSector
{
if (!end_range)
return -1;
end);
return result;
}
/**
* Return the nearest region to \p geom that satisfy a \p constraint.
*
* Note that "nearest" is somewhat ambiguous. This function makes
* no guarantees about how this ambiguity is resovled.
*
* \return PedGeometry, or NULL when a \p constrain cannot be satisfied
*/
{
if (constraint == NULL)
return NULL;
if (start == -1)
return NULL;
if (end == -1)
return NULL;
if (!result)
return NULL;
return NULL);
return result;
}
/**
* Find the largest region that satisfies a constraint.
*
* There might be more than one solution. This function makes no
* guarantees about which solution it will choose in this case.
*/
{
if (!constraint)
return NULL;
}
/**
* Check whether \p geom satisfies the given constraint.
*
* \return \c 1 if it does.
**/
int
const PedGeometry* geom)
{
return 0;
return 0;
return 0;
return 0;
return 0;
return 0;
return 1;
}
/**
* Return a constraint that any region on the given device will satisfy.
*/
{
return NULL;
return ped_constraint_new (
&full_dev,
&full_dev,
1,
}
/**
* Return a constraint that only the given region will satisfy.
*/
{
}
/**
* @}
*/