[PATCH 2/2] msdos, sun: implement disk flag operations
Hans de Goede
hdegoede at redhat.com
Wed Dec 9 14:38:01 UTC 2009
* libparted/labels/dos.c (DosDiskData): New struct.
* libparted/labels/dos.c (msdos_alloc, msdos_duplicate, msdos_free):
Handle per disk DosDiskData.
* libparted/labels/dos.c (msdos_disk_set_flag, msdos_disk_get_flag,
msdos_disk_is_flag_available): New functions.
* libparted/labels/sun.c (sun_disk_set_flag, sun_disk_get_flag,
sun_disk_is_flag_available): New functions.
---
libparted/labels/dos.c | 70 ++++++++++++++++++++++++++++++++++++++++++++---
libparted/labels/sun.c | 57 +++++++++++++++++++++++++++++++++++----
2 files changed, 116 insertions(+), 11 deletions(-)
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index f1ccb0a..ea8fc0b 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -143,6 +143,10 @@ typedef struct {
} OrigState;
typedef struct {
+ int cylinder_alignment;
+} DosDiskData;
+
+typedef struct {
unsigned char system;
int boot;
int hidden;
@@ -227,8 +231,16 @@ msdos_alloc (const PedDevice* dev)
PED_ASSERT (dev != NULL, return NULL);
disk = _ped_disk_alloc ((PedDevice*)dev, &msdos_disk_type);
- if (disk)
- disk->disk_specific = NULL;
+ if (disk) {
+ DosDiskData *disk_specific = ped_malloc(sizeof *disk_specific);
+ if (!disk_specific) {
+ free (disk);
+ return NULL;
+ }
+ disk_specific->cylinder_alignment = 1;
+ disk->disk_specific = disk_specific;
+ }
+
return disk;
}
@@ -240,7 +252,10 @@ msdos_duplicate (const PedDisk* disk)
new_disk = ped_disk_new_fresh (disk->dev, &msdos_disk_type);
if (!new_disk)
return NULL;
- new_disk->disk_specific = NULL;
+
+ memcpy(new_disk->disk_specific, disk->disk_specific,
+ sizeof(DosDiskData));
+
return new_disk;
}
@@ -249,7 +264,45 @@ msdos_free (PedDisk* disk)
{
PED_ASSERT (disk != NULL, return);
+ DosDiskData *disk_specific = disk->disk_specific;
_ped_disk_free (disk);
+ free(disk_specific);
+}
+
+static int
+msdos_disk_set_flag (PedDisk *disk, PedDiskFlag flag, int state)
+{
+ DosDiskData *disk_specific = disk->disk_specific;
+ switch (flag) {
+ case PED_DISK_CYLINDER_ALIGNMENT:
+ disk_specific->cylinder_alignment = !!state;
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static int
+msdos_disk_get_flag (const PedDisk *disk, PedDiskFlag flag)
+{
+ DosDiskData *disk_specific = disk->disk_specific;
+ switch (flag) {
+ case PED_DISK_CYLINDER_ALIGNMENT:
+ return disk_specific->cylinder_alignment;
+ default:
+ return 0;
+ }
+}
+
+static int
+msdos_disk_is_flag_available (const PedDisk *disk, PedDiskFlag flag)
+{
+ switch (flag) {
+ case PED_DISK_CYLINDER_ALIGNMENT:
+ return 1;
+ default:
+ return 0;
+ }
}
#ifndef DISCOVER_ONLY
@@ -1974,10 +2027,11 @@ msdos_partition_align (PedPartition* part, const PedConstraint* constraint)
PedCHSGeometry bios_geom;
DosPartitionData* dos_data;
- PED_ASSERT (part != NULL, return 0);
+ PED_ASSERT (part != NULL, return 0);
PED_ASSERT (part->disk_specific != NULL, return 0);
dos_data = part->disk_specific;
+
if (dos_data->system == PARTITION_LDM && dos_data->orig) {
PedGeometry *orig_geom = &dos_data->orig->geom;
@@ -1997,7 +2051,9 @@ msdos_partition_align (PedPartition* part, const PedConstraint* constraint)
partition_probe_bios_geometry (part, &bios_geom);
- if (_align (part, &bios_geom, constraint))
+ DosDiskData *disk_specific = part->disk->disk_specific;
+ if (disk_specific->cylinder_alignment
+ && _align(part, &bios_geom, constraint))
return 1;
if (_align_no_geom (part, constraint))
return 1;
@@ -2281,6 +2337,10 @@ static PedDiskOps msdos_disk_ops = {
clobber: NULL_IF_DISCOVER_ONLY (msdos_clobber),
write: NULL_IF_DISCOVER_ONLY (msdos_write),
+ disk_set_flag: msdos_disk_set_flag,
+ disk_get_flag: msdos_disk_get_flag,
+ disk_is_flag_available: msdos_disk_is_flag_available,
+
partition_set_name: NULL,
partition_get_name: NULL,
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 1909cc7..1622433 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -96,6 +96,7 @@ struct _SunPartitionData {
struct _SunDiskData {
PedSector length; /* This is based on cyl - alt-cyl */
SunRawLabel raw_label;
+ int cylinder_alignment;
};
static PedDiskType sun_disk_type;
@@ -196,6 +197,7 @@ sun_alloc (const PedDevice* dev)
PED_ASSERT (bios_geom->cylinders == (PedSector) (dev->length / cyl_size),
return NULL);
sun_specific->length = ped_round_down_to (dev->length, cyl_size);
+ sun_specific->cylinder_alignment = 1;
label = &sun_specific->raw_label;
memset(label, 0, sizeof(SunRawLabel));
@@ -258,6 +260,42 @@ sun_free (PedDisk *disk)
}
static int
+sun_disk_set_flag (PedDisk *disk, PedDiskFlag flag, int state)
+{
+ SunDiskData *disk_specific = disk->disk_specific;
+ switch (flag) {
+ case PED_DISK_CYLINDER_ALIGNMENT:
+ disk_specific->cylinder_alignment = !!state;
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static int
+sun_disk_get_flag (const PedDisk *disk, PedDiskFlag flag)
+{
+ SunDiskData *disk_specific = disk->disk_specific;
+ switch (flag) {
+ case PED_DISK_CYLINDER_ALIGNMENT:
+ return disk_specific->cylinder_alignment;
+ default:
+ return 0;
+ }
+}
+
+static int
+sun_disk_is_flag_available (const PedDisk *disk, PedDiskFlag flag)
+{
+ switch (flag) {
+ case PED_DISK_CYLINDER_ALIGNMENT:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static int
_check_geometry_sanity (PedDisk* disk, SunRawLabel* label)
{
PedDevice* dev = disk->dev;
@@ -768,12 +806,15 @@ sun_partition_align (PedPartition* part, const PedConstraint* constraint)
{
PED_ASSERT (part != NULL, return 0);
- if (_ped_partition_attempt_align (part, constraint,
- _get_strict_constraint (part->disk)))
- return 1;
- if (_ped_partition_attempt_align (part, constraint,
- _get_lax_constraint (part->disk)))
- return 1;
+ SunDiskData *disk_specific = part->disk->disk_specific;
+
+ if (disk_specific->cylinder_alignment &&
+ _ped_partition_attempt_align (part, constraint,
+ _get_strict_constraint (part->disk)))
+ return 1;
+ if (_ped_partition_attempt_align (part, constraint,
+ _get_lax_constraint (part->disk)))
+ return 1;
#ifndef DISCOVER_ONLY
ped_exception_throw (
@@ -882,6 +923,10 @@ static PedDiskOps sun_disk_ops = {
clobber: NULL_IF_DISCOVER_ONLY (sun_clobber),
write: NULL_IF_DISCOVER_ONLY (sun_write),
+ disk_set_flag: sun_disk_set_flag,
+ disk_get_flag: sun_disk_get_flag,
+ disk_is_flag_available: sun_disk_is_flag_available,
+
get_partition_alignment: sun_get_partition_alignment,
partition_set_name: NULL,
--
1.6.6.rc1.319.g9b57d
More information about the parted-devel
mailing list