1 /*
   2     libparted - a library for manipulating disk partitions
   3     Copyright (C) 2000, 2007 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 
  19 /**
  20  * \addtogroup PedAlignment
  21  * @{
  22  */
  23 
  24 /** \file natmath.h */
  25 
  26 #ifndef PED_NATMATH_H_INCLUDED
  27 #define PED_NATMATH_H_INCLUDED
  28 
  29 
  30 typedef struct _PedAlignment    PedAlignment;
  31 
  32 #include <parted/disk.h>
  33 
  34 #define PED_MIN(a, b)   ( ((a)<(b)) ? (a) : (b) )
  35 #define PED_MAX(a, b)   ( ((a)>(b)) ? (a) : (b) )
  36 
  37 /* this is weird (I'm still not sure I should be doing this!)
  38  * 
  39  * For the functions: new, destroy, duplicate and merge: the following values
  40  * for align are valid:
  41  *      * align == NULL  (!)            represents no solution
  42  *      * align->grain_size == 0     represents a single solution
  43  *                                      (align->offset)
  44  *      * align->grain_size > 0           represents a set of solutions
  45  *
  46  * These are invalid:
  47  *      * align->offset < 0               Note: this gets "normalized"
  48  *      * align->grain_size < 0
  49  *
  50  * For the align_* operations, there must be a solution.  i.e. align != NULL
  51  * All solutions must be greater than zero.
  52  */
  53 
  54 struct _PedAlignment {
  55         PedSector       offset;
  56         PedSector       grain_size;
  57 };
  58 
  59 extern PedSector ped_round_up_to (PedSector sector, PedSector grain_size);
  60 extern PedSector ped_round_down_to (PedSector sector, PedSector grain_size);
  61 extern PedSector ped_round_to_nearest (PedSector sector, PedSector grain_size);
  62 extern PedSector ped_greatest_common_divisor (PedSector a, PedSector b);
  63 
  64 extern int ped_alignment_init (PedAlignment* align, PedSector offset,
  65                                PedSector grain_size);
  66 extern PedAlignment* ped_alignment_new (PedSector offset, PedSector grain_size);
  67 extern void ped_alignment_destroy (PedAlignment* align);
  68 extern PedAlignment* ped_alignment_duplicate (const PedAlignment* align);
  69 extern PedAlignment* ped_alignment_intersect (const PedAlignment* a,
  70                                               const PedAlignment* b);
  71 
  72 extern PedSector
  73 ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
  74                         PedSector sector);
  75 extern PedSector
  76 ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
  77                           PedSector sector);
  78 extern PedSector
  79 ped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
  80                              PedSector sector);
  81 
  82 extern int
  83 ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
  84                           PedSector sector);
  85 
  86 extern const PedAlignment* ped_alignment_any;
  87 extern const PedAlignment* ped_alignment_none;
  88 
  89 #ifdef __sun
  90 extern PedSector
  91 #else
  92 extern inline PedSector
  93 #endif
  94 ped_div_round_up (PedSector numerator, PedSector divisor);
  95 
  96 #ifdef __sun
  97 extern PedSector
  98 #else
  99 extern inline PedSector
 100 #endif
 101 ped_div_round_to_nearest (PedSector numerator, PedSector divisor);
 102 
 103 #endif /* PED_NATMATH_H_INCLUDED */
 104 
 105 /**
 106  * @}
 107  */
 108