1N/A/*
1N/A libparted - a library for manipulating disk partitions
1N/A Copyright (C) 2000, 2007-2010 Free Software Foundation, Inc.
1N/A
1N/A This program is free software; you can redistribute it and/or modify
1N/A it under the terms of the GNU General Public License as published by
1N/A the Free Software Foundation; either version 3 of the License, or
1N/A (at your option) any later version.
1N/A
1N/A This program is distributed in the hope that it will be useful,
1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A GNU General Public License for more details.
1N/A
1N/A You should have received a copy of the GNU General Public License
1N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
1N/A*/
1N/A
1N/A/**
1N/A * \addtogroup PedAlignment
1N/A * @{
1N/A */
1N/A
1N/A/** \file natmath.h */
1N/A
1N/A#ifndef PED_NATMATH_H_INCLUDED
1N/A#define PED_NATMATH_H_INCLUDED
1N/A
1N/A
1N/Atypedef struct _PedAlignment PedAlignment;
1N/A
1N/A#include <parted/disk.h>
1N/A#include <parted/device.h>
1N/A#include <parted/geom.h>
1N/A
1N/A#define PED_MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
1N/A#define PED_MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
1N/A
1N/A/* this is weird (I'm still not sure I should be doing this!)
1N/A *
1N/A * For the functions: new, destroy, duplicate and merge: the following values
1N/A * for align are valid:
1N/A * * align == NULL (!) represents no solution
1N/A * * align->grain_size == 0 represents a single solution
1N/A * (align->offset)
1N/A * * align->grain_size > 0 represents a set of solutions
1N/A *
1N/A * These are invalid:
1N/A * * align->offset < 0 Note: this gets "normalized"
1N/A * * align->grain_size < 0
1N/A *
1N/A * For the align_* operations, there must be a solution. i.e. align != NULL
1N/A * All solutions must be greater than zero.
1N/A */
1N/A
1N/Astruct _PedAlignment {
1N/A PedSector offset;
1N/A PedSector grain_size;
1N/A};
1N/A
1N/Aextern PedSector ped_round_up_to (PedSector sector, PedSector grain_size);
1N/Aextern PedSector ped_round_down_to (PedSector sector, PedSector grain_size);
1N/Aextern PedSector ped_round_to_nearest (PedSector sector, PedSector grain_size);
1N/Aextern PedSector ped_greatest_common_divisor (PedSector a, PedSector b);
1N/A
1N/Aextern int ped_alignment_init (PedAlignment* align, PedSector offset,
1N/A PedSector grain_size);
1N/Aextern PedAlignment* ped_alignment_new (PedSector offset, PedSector grain_size);
1N/Aextern void ped_alignment_destroy (PedAlignment* align);
1N/Aextern PedAlignment* ped_alignment_duplicate (const PedAlignment* align);
1N/Aextern PedAlignment* ped_alignment_intersect (const PedAlignment* a,
1N/A const PedAlignment* b);
1N/A
1N/Aextern PedSector
1N/Aped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
1N/A PedSector sector);
1N/Aextern PedSector
1N/Aped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
1N/A PedSector sector);
1N/Aextern PedSector
1N/Aped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
1N/A PedSector sector);
1N/A
1N/Aextern int
1N/Aped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
1N/A PedSector sector);
1N/A
1N/Aextern const PedAlignment* ped_alignment_any;
1N/Aextern const PedAlignment* ped_alignment_none;
1N/A
1N/Astatic inline PedSector
1N/Aped_div_round_up (PedSector numerator, PedSector divisor)
1N/A{
1N/A return (numerator + divisor - 1) / divisor;
1N/A}
1N/A
1N/A
1N/Astatic inline PedSector
1N/Aped_div_round_to_nearest (PedSector numerator, PedSector divisor)
1N/A{
1N/A return (numerator + divisor/2) / divisor;
1N/A}
1N/A
1N/A#endif /* PED_NATMATH_H_INCLUDED */
1N/A
1N/A/**
1N/A * @}
1N/A */