libparted 3.6
Loading...
Searching...
No Matches
natmath.h
Go to the documentation of this file.
1/*
2 libparted - a library for manipulating disk partitions
3 Copyright (C) 2000, 2007-2014, 2019-2023 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>.
17*/
18
26#ifndef PED_NATMATH_H_INCLUDED
27#define PED_NATMATH_H_INCLUDED
28
29
31
32#include <parted/disk.h>
33#include <parted/device.h>
34#include <parted/geom.h>
35
36#define PED_MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
37#define PED_MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
38
39/* this is weird (I'm still not sure I should be doing this!)
40 *
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
45 * (align->offset)
46 * * align->grain_size > 0 represents a set of solutions
47 *
48 * These are invalid:
49 * * align->offset < 0 Note: this gets "normalized"
50 * * align->grain_size < 0
51 *
52 * For the align_* operations, there must be a solution. i.e. align != NULL
53 * All solutions must be greater than zero.
54 */
55
59};
60
62
63#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
64 __attribute ((__const__))
65#endif
66;
68
69#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
70 __attribute ((__const__))
71#endif
72;
74
75#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
76 __attribute ((__const__))
77#endif
78;
80
81#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
82 __attribute ((__pure__))
83#endif
84;
85
87 PedSector grain_size);
89extern void ped_alignment_destroy (PedAlignment* align);
92 const PedAlignment* b);
93
94extern PedSector
95ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
97#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
98 __attribute ((__pure__))
99#endif
100;
101extern PedSector
102ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
104#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
105 __attribute ((__pure__))
106#endif
107;
108extern PedSector
109ped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
111#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
112 __attribute ((__pure__))
113#endif
114;
115
116extern int
117ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
119#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
120 __attribute ((__pure__))
121#endif
122;
123
124extern const PedAlignment* ped_alignment_any;
125extern const PedAlignment* ped_alignment_none;
126
127static inline PedSector
128ped_div_round_up (PedSector numerator, PedSector divisor)
129{
130 return (numerator + divisor - 1) / divisor;
131}
132
133
134static inline PedSector
135ped_div_round_to_nearest (PedSector numerator, PedSector divisor)
136{
137 return (numerator + divisor/2) / divisor;
138}
139
140#endif /* PED_NATMATH_H_INCLUDED */
141
offset
Definition: fdasd.h:264
PedSector ped_alignment_align_nearest(const PedAlignment *align, const PedGeometry *geom, PedSector sector)
This function returns the sector that is closest to sector, satisfies the align constraint and lies i...
Definition: natmath.c:448
const PedAlignment * ped_alignment_none
Definition: natmath.c:52
PedSector ped_round_to_nearest(PedSector sector, PedSector grain_size)
Definition: natmath.c:91
void ped_alignment_destroy(PedAlignment *align)
Free up memory associated with align.
Definition: natmath.c:172
PedSector ped_round_up_to(PedSector sector, PedSector grain_size)
Definition: natmath.c:81
PedAlignment * ped_alignment_new(PedSector offset, PedSector grain_size)
Return an alignment object (used by PedConstraint), representing all PedSector's that are of the form...
Definition: natmath.c:149
const PedAlignment * ped_alignment_any
Definition: natmath.c:51
PedAlignment * ped_alignment_intersect(const PedAlignment *a, const PedAlignment *b)
This function computes a PedAlignment object that describes the intersection of two alignments.
Definition: natmath.c:295
PedSector ped_alignment_align_up(const PedAlignment *align, const PedGeometry *geom, PedSector sector)
This function returns the closest sector to sector that lies inside geom that satisfies the given ali...
Definition: natmath.c:379
int ped_alignment_is_aligned(const PedAlignment *align, const PedGeometry *geom, PedSector sector)
This function returns 1 if sector satisfies the alignment constraint align and lies inside geom.
Definition: natmath.c:464
PedSector ped_alignment_align_down(const PedAlignment *align, const PedGeometry *geom, PedSector sector)
This function returns the closest sector to sector that lies inside geom that satisfies the given ali...
Definition: natmath.c:407
PedAlignment * ped_alignment_duplicate(const PedAlignment *align)
Return a duplicate of align.
Definition: natmath.c:181
PedSector ped_greatest_common_divisor(PedSector a, PedSector b)
Definition: natmath.c:103
int ped_alignment_init(PedAlignment *align, PedSector offset, PedSector grain_size)
Initialize a preallocated piece of memory for an alignment object (used by PedConstraint).
Definition: natmath.c:128
PedSector ped_round_down_to(PedSector sector, PedSector grain_size)
Definition: natmath.c:72
long long PedSector
We can address 2^63 sectors.
Definition: device.h:31
#define __attribute(arg)
Definition: parted.h:32
uint8_t sector
Definition: pc98.c:7
Definition: natmath.h:56
PedSector offset
Definition: natmath.h:57
PedSector grain_size
Definition: natmath.h:58
Geometry of the partition.
Definition: geom.h:35