[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH parted 5/7] libparted: add ped_device_get_xxx_aligned_constraint(
From: |
Hans de Goede |
Subject: |
[PATCH parted 5/7] libparted: add ped_device_get_xxx_aligned_constraint() functions |
Date: |
Thu, 29 Oct 2009 16:26:20 +0100 |
Add ped_device_get_minimal_aligned_constraint() and
ped_device_get_optimal_aligned_constraint() functions to libparted.
These functions can be used to get a device constraint taking alignment into
account.
---
include/parted/device.h | 5 +++
libparted/device.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/include/parted/device.h b/include/parted/device.h
index 5095b18..3580c2a 100644
--- a/include/parted/device.h
+++ b/include/parted/device.h
@@ -146,6 +146,11 @@ extern PedSector ped_device_check (PedDevice* dev, void*
buffer,
PedSector start, PedSector count);
extern PedConstraint* ped_device_get_constraint (PedDevice* dev);
+extern PedConstraint *ped_device_get_minimal_aligned_constraint(
+ const PedDevice *dev);
+extern PedConstraint *ped_device_get_optimal_aligned_constraint(
+ const PedDevice *dev);
+
extern PedAlignment *ped_device_get_minimum_alignment(const PedDevice *dev);
extern PedAlignment *ped_device_get_optimum_alignment(const PedDevice *dev);
diff --git a/libparted/device.c b/libparted/device.c
index 483011a..cd10a91 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -445,6 +445,75 @@ ped_device_get_constraint (PedDevice* dev)
return c;
}
+static PedConstraint*
+_ped_device_get_aligned_constraint(const PedDevice *dev,
+ PedAlignment* start_align)
+{
+ PedAlignment *end_align = NULL;
+ PedGeometry *whole_dev_geom = NULL;
+ PedConstraint *c = NULL;
+
+ if (start_align) {
+ end_align = ped_alignment_new(start_align->offset - 1,
+ start_align->grain_size);
+ if (!end_align)
+ goto free_start_align;
+ }
+
+ whole_dev_geom = ped_geometry_new (dev, 0, dev->length);
+
+ if (start_align)
+ c = ped_constraint_new (start_align, end_align,
+ whole_dev_geom, whole_dev_geom,
+ 1, dev->length);
+ else
+ c = ped_constraint_new (ped_alignment_any, ped_alignment_any,
+ whole_dev_geom, whole_dev_geom,
+ 1, dev->length);
+
+ free (whole_dev_geom);
+ free (end_align);
+free_start_align:
+ free (start_align);
+ return c;
+}
+
+/**
+ * Get a constraint that represents hardware requirements on geometry and
+ * alignment.
+ *
+ * This function will return a constraint representing the limits imposed
+ * by the size of the disk and the minimal alignment requirements for proper
+ * performance of the disk.
+ *
+ * \return NULL on error, otherwise a pointer to a dynamically allocated
+ * constraint.
+ */
+PedConstraint*
+ped_device_get_minimal_aligned_constraint(const PedDevice *dev)
+{
+ return _ped_device_get_aligned_constraint(dev,
+
ped_device_get_minimum_alignment(dev));
+}
+
+/**
+ * Get a constraint that represents hardware requirements on geometry and
+ * alignment.
+ *
+ * This function will return a constraint representing the limits imposed
+ * by the size of the disk and the alignment requirements for optimal
+ * performance of the disk.
+ *
+ * \return NULL on error, otherwise a pointer to a dynamically allocated
+ * constraint.
+ */
+PedConstraint*
+ped_device_get_optimal_aligned_constraint(const PedDevice *dev)
+{
+ return _ped_device_get_aligned_constraint(dev,
+
ped_device_get_optimum_alignment(dev));
+}
+
/**
* Get an alignment that represents minimum hardware requirements on alignment.
* When for example using media that has a physical sector size that is a
--
1.6.5.1
Re: [PATCH parted 1/7] libparted: add ped_device_get_xxx_alignment() functions, Jim Meyering, 2009/10/29