bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH parted 1/7] libparted: add ped_device_get_xxx_alignment() functio


From: Hans de Goede
Subject: [PATCH parted 1/7] libparted: add ped_device_get_xxx_alignment() functions
Date: Thu, 29 Oct 2009 16:26:16 +0100

Add ped_device_get_minimum_alignment() and ped_device_get_optimum_alignment()
functions to libparted.

Note this is a resent of my previous patchset with a number of typos corrected:
aligment -> alignment
minimal_alignment -> minimum_aligment
optimal_alignment -> optimum_aligment

Sorry for the noise.
---
 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..5095b18 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_minimum_alignment)(const PedDevice *dev);
+        PedAlignment *(*get_optimum_alignment)(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_minimum_alignment(const PedDevice *dev);
+extern PedAlignment *ped_device_get_optimum_alignment(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..4fec1a9 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 alignment.
+ * 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 alignment for the start sector of the
+ * partition, the end sector should be aligned too, to get the end sector
+ * alignment 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_minimum_alignment(const PedDevice *dev)
+{
+        if (ped_architecture->dev_ops->get_minimum_alignment)
+                return ped_architecture->dev_ops->get_minimum_alignment(dev);
+
+        return NULL; /* ped_alignment_none */
+}
+
+/**
+ * Get an alignment that represents the hardware requirements for optimal
+ * performance.
+ *
+ * The returned alignment describes the alignment for the start sector of the
+ * partition, the end sector should be aligned too, to get the end sector
+ * alignment 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_optimum_alignment(const PedDevice *dev)
+{
+        if (ped_architecture->dev_ops->get_optimum_alignment)
+                return ped_architecture->dev_ops->get_optimum_alignment(dev);
+
+        return NULL; /* ped_alignment_none */
+}
+
 /** @} */
 
-- 
1.6.5.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]