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, 2026 Free Software Foundation,
4 Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
24
26
27#ifndef PED_NATMATH_H_INCLUDED
28#define PED_NATMATH_H_INCLUDED
29
30
32
33#include <parted/disk.h>
34#include <parted/device.h>
35#include <parted/geom.h>
36
37#define PED_MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
38#define PED_MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
39
40/* this is weird (I'm still not sure I should be doing this!)
41 *
42 * For the functions: new, destroy, duplicate and merge: the following values
43 * for align are valid:
44 * * align == NULL (!) represents no solution
45 * * align->grain_size == 0 represents a single solution
46 * (align->offset)
47 * * align->grain_size > 0 represents a set of solutions
48 *
49 * These are invalid:
50 * * align->offset < 0 Note: this gets "normalized"
51 * * align->grain_size < 0
52 *
53 * For the align_* operations, there must be a solution. i.e. align != NULL
54 * All solutions must be greater than zero.
55 */
56
61
63
64#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
65 __attribute ((__const__))
66#endif
67;
69
70#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
71 __attribute ((__const__))
72#endif
73;
75
76#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
77 __attribute ((__const__))
78#endif
79;
81
82#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
83 __attribute ((__pure__))
84#endif
85;
86
88 PedSector grain_size);
90extern void ped_alignment_destroy (PedAlignment* align);
93 const PedAlignment* b);
94
95extern PedSector
96ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
98#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
99 __attribute ((__pure__))
100#endif
101;
102extern PedSector
103ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
105#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
106 __attribute ((__pure__))
107#endif
108;
109extern PedSector
110ped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
112#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
113 __attribute ((__pure__))
114#endif
115;
116
117extern int
118ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
120#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
121 __attribute ((__pure__))
122#endif
123;
124
125extern const PedAlignment* ped_alignment_any;
126extern const PedAlignment* ped_alignment_none;
127
128static inline PedSector
129ped_div_round_up (PedSector numerator, PedSector divisor)
130{
131 return (numerator + divisor - 1) / divisor;
132}
133
134
135static inline PedSector
136ped_div_round_to_nearest (PedSector numerator, PedSector divisor)
137{
138 return (numerator + divisor/2) / divisor;
139}
140
141#endif /* PED_NATMATH_H_INCLUDED */
142
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:449
const PedAlignment * ped_alignment_none
Definition natmath.c:53
PedSector ped_round_to_nearest(PedSector sector, PedSector grain_size)
Definition natmath.c:92
void ped_alignment_destroy(PedAlignment *align)
Free up memory associated with align.
Definition natmath.c:173
PedSector ped_round_up_to(PedSector sector, PedSector grain_size)
Definition natmath.c:82
struct _PedAlignment PedAlignment
Definition natmath.h:31
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:150
const PedAlignment * ped_alignment_any
Definition natmath.c:52
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:296
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:380
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:465
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:408
PedAlignment * ped_alignment_duplicate(const PedAlignment *align)
Return a duplicate of align.
Definition natmath.c:182
PedSector ped_greatest_common_divisor(PedSector a, PedSector b)
Definition natmath.c:104
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:129
PedSector ped_round_down_to(PedSector sector, PedSector grain_size)
Definition natmath.c:73
long long PedSector
We can address 2^63 sectors.
Definition device.h:31
struct _PedGeometry PedGeometry
Definition geom.h:30
#define __attribute(arg)
Definition parted.h:32
uint8_t sector
Definition pc98.c:7
Definition natmath.h:57
PedSector offset
Definition natmath.h:58
PedSector grain_size
Definition natmath.h:59