Loading...
Searching...
No Matches
natmath.h
Go to the documentation of this file.
/*
libparted - a library for manipulating disk partitions
Copyright (C) 2000, 2007-2014, 2019-2023, 2026 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PED_NATMATH_H_INCLUDED
#define PED_NATMATH_H_INCLUDED
typedef struct _PedAlignment PedAlignment;
#include <parted/disk.h>
#include <parted/device.h>
#include <parted/geom.h>
#define PED_MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
#define PED_MAX(a, b) ( ((a)>(b)) ? (a) : (b) )
/* this is weird (I'm still not sure I should be doing this!)
*
* For the functions: new, destroy, duplicate and merge: the following values
* for align are valid:
* * align == NULL (!) represents no solution
* * align->grain_size == 0 represents a single solution
* (align->offset)
* * align->grain_size > 0 represents a set of solutions
*
* These are invalid:
* * align->offset < 0 Note: this gets "normalized"
* * align->grain_size < 0
*
* For the align_* operations, there must be a solution. i.e. align != NULL
* All solutions must be greater than zero.
*/
struct _PedAlignment {
PedSector offset;
PedSector grain_size;
};
extern PedSector ped_round_up_to (PedSector sector, PedSector grain_size)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__const__))
#endif
;
extern PedSector ped_round_down_to (PedSector sector, PedSector grain_size)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__const__))
#endif
;
extern PedSector ped_round_to_nearest (PedSector sector, PedSector grain_size)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__const__))
#endif
;
extern PedSector ped_greatest_common_divisor (PedSector a, PedSector b)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__pure__))
#endif
;
extern int ped_alignment_init (PedAlignment* align, PedSector offset,
PedSector grain_size);
extern PedAlignment* ped_alignment_new (PedSector offset, PedSector grain_size);
extern void ped_alignment_destroy (PedAlignment* align);
extern PedAlignment* ped_alignment_duplicate (const PedAlignment* align);
extern PedAlignment* ped_alignment_intersect (const PedAlignment* a,
const PedAlignment* b);
extern PedSector
ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
PedSector sector)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__pure__))
#endif
;
extern PedSector
ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
PedSector sector)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__pure__))
#endif
;
extern PedSector
ped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
PedSector sector)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__pure__))
#endif
;
extern int
ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
PedSector sector)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
__attribute ((__pure__))
#endif
;
extern const PedAlignment* ped_alignment_any;
extern const PedAlignment* ped_alignment_none;
static inline PedSector
ped_div_round_up (PedSector numerator, PedSector divisor)
{
return (numerator + divisor - 1) / divisor;
}
static inline PedSector
ped_div_round_to_nearest (PedSector numerator, PedSector divisor)
{
return (numerator + divisor/2) / divisor;
}
#endif /* PED_NATMATH_H_INCLUDED */
device.h
disk.h
offset
offset
Definition fdasd.h:264
geom.h
ped_alignment_align_nearest
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
ped_alignment_none
const PedAlignment * ped_alignment_none
Definition natmath.c:53
ped_round_to_nearest
PedSector ped_round_to_nearest(PedSector sector, PedSector grain_size)
Definition natmath.c:92
ped_alignment_destroy
void ped_alignment_destroy(PedAlignment *align)
Free up memory associated with align.
Definition natmath.c:173
ped_round_up_to
PedSector ped_round_up_to(PedSector sector, PedSector grain_size)
Definition natmath.c:82
PedAlignment
struct _PedAlignment PedAlignment
Definition natmath.h:31
ped_alignment_new
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
ped_alignment_any
const PedAlignment * ped_alignment_any
Definition natmath.c:52
ped_alignment_intersect
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
ped_alignment_align_up
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
ped_alignment_is_aligned
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
ped_alignment_align_down
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
ped_alignment_duplicate
PedAlignment * ped_alignment_duplicate(const PedAlignment *align)
Return a duplicate of align.
Definition natmath.c:182
ped_greatest_common_divisor
PedSector ped_greatest_common_divisor(PedSector a, PedSector b)
Definition natmath.c:104
ped_alignment_init
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
ped_round_down_to
PedSector ped_round_down_to(PedSector sector, PedSector grain_size)
Definition natmath.c:73
PedSector
long long PedSector
We can address 2^63 sectors.
Definition device.h:31
PedGeometry
struct _PedGeometry PedGeometry
Definition geom.h:30
__attribute
#define __attribute(arg)
Definition parted.h:32
sector
uint8_t sector
Definition pc98.c:7
_PedAlignment
Definition natmath.h:57
_PedAlignment::offset
PedSector offset
Definition natmath.h:58
_PedAlignment::grain_size
PedSector grain_size
Definition natmath.h:59