Add ped_device_get_minimal_aligment() and ped_device_get_optimal_aligment() functions to libparted. --- include/parted/device.h | 8 ++++++++ include/parted/natmath.h | 1 + libparted/device.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/include/parted/device.h b/include/parted/device.h index 151305f..7c34081 100644 --- a/include/parted/device.h +++ b/include/parted/device.h @@ -92,6 +92,8 @@ struct _PedDevice { void* arch_specific; }; +#include <parted/natmath.h> + /** * List of functions implementing architecture-specific operations. */ @@ -112,6 +114,9 @@ struct _PedDeviceArchOps { PedSector (*check) (PedDevice* dev, void* buffer, PedSector start, PedSector count); void (*probe_all) (); + /* These functions are optional */ + PedAlignment *(*get_minimal_aligment)(const PedDevice *dev); + PedAlignment *(*get_optimal_aligment)(const PedDevice *dev); }; #include <parted/constraint.h> @@ -141,6 +146,9 @@ extern PedSector ped_device_check (PedDevice* dev, void* buffer, PedSector start, PedSector count); extern PedConstraint* ped_device_get_constraint (PedDevice* dev); +extern PedAlignment *ped_device_get_minimal_aligment(const PedDevice *dev); +extern PedAlignment *ped_device_get_optimal_aligment(const PedDevice *dev); + /* private stuff ;-) */ extern void _ped_device_probe (const char* path); diff --git a/include/parted/natmath.h b/include/parted/natmath.h index cd7679d..eaa84d1 100644 --- a/include/parted/natmath.h +++ b/include/parted/natmath.h @@ -31,6 +31,7 @@ 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) ) diff --git a/libparted/device.c b/libparted/device.c index 294fec4..34b8eb5 100644 --- a/libparted/device.c +++ b/libparted/device.c @@ -444,5 +444,48 @@ ped_device_get_constraint (PedDevice* dev) return c; } +/** + * Get an alignment that represents minimum hardware requirements on aligment. + * When for example using media that has a physical sector size that is a + * multiple of the logical sector size, it is desirable to have disk accesses + * (and thus partitions) properly aligned. Having partitions not aligned to + * the minimum hardware requirements may lead to a performance penalty. + * + * The returned alignment describes the aligment for the start sector of the + * partition, the end sector should be aligned too, to get the end sector + * aligment decrease the returned alignment's offset by 1. + * + * \return the minimum alignment of partition start sectors, or NULL if this + * information is not available. + */ +PedAlignment* +ped_device_get_minimal_aligment(const PedDevice *dev) +{ + if (ped_architecture->dev_ops->get_minimal_aligment) + return ped_architecture->dev_ops->get_minimal_aligment(dev); + + return NULL; /* ped_alignment_none */ +} + +/** + * Get an alignment that represents the hardware requirements for optimal + * performance. + * + * The returned alignment describes the aligment for the start sector of the + * partition, the end sector should be aligned too, to get the end sector + * aligment decrease the returned alignment's offset by 1. + * + * \return the optimal alignment of partition start sectors, or NULL if this + * information is not available. + */ +PedAlignment* +ped_device_get_optimal_aligment(const PedDevice *dev) +{ + if (ped_architecture->dev_ops->get_optimal_aligment) + return ped_architecture->dev_ops->get_optimal_aligment(dev); + + return NULL; /* ped_alignment_none */ +} + /** @} */ -- 1.6.5.1 _______________________________________________ bug-parted mailing list bug-parted@gnu.org http://lists.gnu.org/mailman/listinfo/bug-parted