2
libparted - a library for manipulating disk partitions
3
Copyright (C) 2000, 2007-2012 Free Software Foundation, Inc.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
* \addtogroup PedAlignment
24
/** \file natmath.h */
26
#ifndef PED_NATMATH_H_INCLUDED
27
#define PED_NATMATH_H_INCLUDED
30
typedef struct _PedAlignment PedAlignment;
32
#include <parted/disk.h>
33
#include <parted/device.h>
34
#include <parted/geom.h>
36
#define PED_MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
37
#define PED_MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
39
/* this is weird (I'm still not sure I should be doing this!)
41
* For the functions: new, destroy, duplicate and merge: the following values
42
* for align are valid:
43
* * align == NULL (!) represents no solution
44
* * align->grain_size == 0 represents a single solution
46
* * align->grain_size > 0 represents a set of solutions
49
* * align->offset < 0 Note: this gets "normalized"
50
* * align->grain_size < 0
52
* For the align_* operations, there must be a solution. i.e. align != NULL
53
* All solutions must be greater than zero.
56
struct _PedAlignment {
61
extern PedSector ped_round_up_to (PedSector sector, PedSector grain_size)
63
extern PedSector ped_round_down_to (PedSector sector, PedSector grain_size)
65
extern PedSector ped_round_to_nearest (PedSector sector, PedSector grain_size)
67
extern PedSector ped_greatest_common_divisor (PedSector a, PedSector b)
70
extern int ped_alignment_init (PedAlignment* align, PedSector offset,
71
PedSector grain_size);
72
extern PedAlignment* ped_alignment_new (PedSector offset, PedSector grain_size);
73
extern void ped_alignment_destroy (PedAlignment* align);
74
extern PedAlignment* ped_alignment_duplicate (const PedAlignment* align);
75
extern PedAlignment* ped_alignment_intersect (const PedAlignment* a,
76
const PedAlignment* b);
79
ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
80
PedSector sector) _GL_ATTRIBUTE_PURE;
82
ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
83
PedSector sector) _GL_ATTRIBUTE_PURE;
85
ped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
86
PedSector sector) _GL_ATTRIBUTE_PURE;
89
ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
90
PedSector sector) _GL_ATTRIBUTE_PURE;
92
extern const PedAlignment* ped_alignment_any;
93
extern const PedAlignment* ped_alignment_none;
95
static inline PedSector
96
ped_div_round_up (PedSector numerator, PedSector divisor)
98
return (numerator + divisor - 1) / divisor;
102
static inline PedSector
103
ped_div_round_to_nearest (PedSector numerator, PedSector divisor)
105
return (numerator + divisor/2) / divisor;
108
#endif /* PED_NATMATH_H_INCLUDED */