libparted 3.6
Loading...
Searching...
No Matches
natmath.in.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
57struct _PedAlignment {
60};
61
63 _GL_ATTRIBUTE_CONST;
65 _GL_ATTRIBUTE_CONST;
67 _GL_ATTRIBUTE_CONST;
69 _GL_ATTRIBUTE_PURE;
70
72 PedSector grain_size);
74extern void ped_alignment_destroy (PedAlignment* align);
77 const PedAlignment* b);
78
79extern PedSector
80ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
81 PedSector sector) _GL_ATTRIBUTE_PURE;
82extern PedSector
83ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
84 PedSector sector) _GL_ATTRIBUTE_PURE;
85extern PedSector
87 PedSector sector) _GL_ATTRIBUTE_PURE;
88
89extern int
90ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
91 PedSector sector) _GL_ATTRIBUTE_PURE;
92
95
96static inline PedSector
97ped_div_round_up (PedSector numerator, PedSector divisor)
98{
99 return (numerator + divisor - 1) / divisor;
100}
101
102
103static inline PedSector
104ped_div_round_to_nearest (PedSector numerator, PedSector divisor)
105{
106 return (numerator + divisor/2) / divisor;
107}
108
109#endif /* PED_NATMATH_H_INCLUDED */
110
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
uint8_t sector
Definition pc98.c:7
Definition natmath.h:57
PedSector grain_size
Definition natmath.h:59