[parted-devel] [PATCH] parted: improve snapping to boundaries of free space

Brian C. Lane bcl at redhat.com
Tue Oct 27 20:53:32 UTC 2015


On Fri, Oct 23, 2015 at 04:08:14PM +0200, Petr Uzel wrote:
> When creating a new partition, parted tries to snap its boundaries.
> If the new partition lies within free space, it only makes sense
> to snap it so that is it bigger, not smaller.
> 
> * parted/parted.c (snap_to_boundaries): Limit direction in what snapping
> is done.
> ---
>  parted/parted.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/parted/parted.c b/parted/parted.c
> index a9426c4..840e9e3 100644
> --- a/parted/parted.c
> +++ b/parted/parted.c
> @@ -379,6 +379,14 @@ snap_to_boundaries (PedGeometry* new_geom, PedGeometry* old_geom,
>          end_part = ped_disk_get_partition_by_sector (disk, end);
>          adjacent = (start_part->geom.end + 1 == end_part->geom.start);
>  
> +	/* If start lies within free space, then don't allow it to move up.
> +	 * If end   lies within free space, then don't allow it to move down.
> +	 */
> +	if (start_part->type == PED_PARTITION_FREESPACE)
> +		start_allow &= ~MOVE_UP;
> +	if (end_part->type == PED_PARTITION_FREESPACE)
> +		end_allow &= ~MOVE_DOWN;
> +
>          /* If we can snap to old_geom, then we will... */
>          /* and this will enforce the snapped positions  */
>          if (old_geom) {
> -- 
> 1.8.4.5
> 
> 

Looks ok to me, but we could use a test to go along with it.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)



More information about the parted-devel mailing list