natmath.h

Go to the documentation of this file.
00001 /*
00002     libparted - a library for manipulating disk partitions
00003     Copyright (C) 2000 Free Software Foundation, Inc.
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018 */
00019 
00027 #ifndef PED_NATMATH_H_INCLUDED
00028 #define PED_NATMATH_H_INCLUDED
00029 
00030 
00031 typedef struct _PedAlignment    PedAlignment;
00032 
00033 #include <parted/disk.h>
00034 
00035 #define PED_MIN(a, b)   ( ((a)<(b)) ? (a) : (b) )
00036 #define PED_MAX(a, b)   ( ((a)>(b)) ? (a) : (b) )
00037 
00038 /* this is weird (I'm still not sure I should be doing this!)
00039  * 
00040  * For the functions: new, destroy, duplicate and merge: the following values
00041  * for align are valid:
00042  *      * align == NULL  (!)            represents no solution
00043  *      * align->grain_size == 0        represents a single solution
00044  *                                      (align->offset)
00045  *      * align->grain_size > 0         represents a set of solutions
00046  *
00047  * These are invalid:
00048  *      * align->offset < 0             Note: this gets "normalized"
00049  *      * align->grain_size < 0
00050  *
00051  * For the align_* operations, there must be a solution.  i.e. align != NULL
00052  * All solutions must be greater than zero.
00053  */
00054 
00055 struct _PedAlignment {
00056         PedSector       offset;
00057         PedSector       grain_size;
00058 };
00059 
00060 extern PedSector ped_round_up_to (PedSector sector, PedSector grain_size);
00061 extern PedSector ped_round_down_to (PedSector sector, PedSector grain_size);
00062 extern PedSector ped_round_to_nearest (PedSector sector, PedSector grain_size);
00063 extern PedSector ped_greatest_common_divisor (PedSector a, PedSector b);
00064 
00065 extern int ped_alignment_init (PedAlignment* align, PedSector offset,
00066                                PedSector grain_size);
00067 extern PedAlignment* ped_alignment_new (PedSector offset, PedSector grain_size);
00068 extern void ped_alignment_destroy (PedAlignment* align);
00069 extern PedAlignment* ped_alignment_duplicate (const PedAlignment* align);
00070 extern PedAlignment* ped_alignment_intersect (const PedAlignment* a,
00071                                               const PedAlignment* b);
00072 
00073 extern PedSector
00074 ped_alignment_align_up (const PedAlignment* align, const PedGeometry* geom,
00075                         PedSector sector);
00076 extern PedSector
00077 ped_alignment_align_down (const PedAlignment* align, const PedGeometry* geom,
00078                           PedSector sector);
00079 extern PedSector
00080 ped_alignment_align_nearest (const PedAlignment* align, const PedGeometry* geom,
00081                              PedSector sector);
00082 
00083 extern int
00084 ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
00085                           PedSector sector);
00086 
00087 extern const PedAlignment* ped_alignment_any;
00088 extern const PedAlignment* ped_alignment_none;
00089 
00090 extern inline PedSector
00091 ped_div_round_up (PedSector numerator, PedSector divisor);
00092 
00093 extern inline PedSector
00094 ped_div_round_to_nearest (PedSector numerator, PedSector divisor);
00095 
00096 #endif /* PED_NATMATH_H_INCLUDED */
00097 

Generated on Fri May 4 05:15:31 2007 for libparted by  doxygen 1.5.2