On Sun, 2008-12-21 at 23:39 +0100, Jim Meyering wrote:
> If you feel like one more iteration,
> it'd be nice if you would add a ChangeLog-style log entry
> and create diffs against the latest upstream git repository.

Sure, here's the updated patch.

Thanks again,

~spot
>From d3964a84ead6e897476e24de347e74e3b7e41e24 Mon Sep 17 00:00:00 2001
From: Tom "spot" Callaway <tcall...@redhat.com>
Date: Mon, 22 Dec 2008 09:39:23 -0500
Subject: [PATCH] Add support for RAID partition types for Sun disk layouts

This patch enables RAID as a supported partition type on Sun disk
layouts, commonly found/used on SPARC hardware. It has been tested
on Aurora SPARC Linux (and Fedora SPARC). I have no idea if Solaris
supports Software RAID or not...

Along with the code change, I wrote a test case that checks if the
RAID partition type is supported on sun disk labels.
---
 libparted/labels/sun.c       |   41 ++++++++++++++++++++++----
 tests/Makefile.am            |    1 +
 tests/t4000-sun-raid-type.sh |   65 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+), 6 deletions(-)
 create mode 100755 tests/t4000-sun-raid-type.sh

diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 6f1900b..76f2b78 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -87,6 +87,7 @@ struct _SunPartitionData {
 	int			is_boot;
 	int			is_root;
 	int			is_lvm;
+	int			is_raid;
 };
 
 struct _SunDiskData {
@@ -347,6 +348,7 @@ sun_read (PedDisk* disk)
 		sun_data->is_boot = sun_data->type == 0x1;
 		sun_data->is_root = sun_data->type == 0x2;
 		sun_data->is_lvm = sun_data->type == 0x8e;
+		sun_data->is_raid = sun_data->type == 0xfd;
 
 		part->num = i + 1;
 		part->fs_type = ped_file_system_probe (&part->geom);
@@ -482,6 +484,7 @@ sun_partition_new (const PedDisk* disk, PedPartitionType part_type,
 		sun_data->is_boot = 0;
 		sun_data->is_root = 0;
 		sun_data->is_lvm = 0;
+		sun_data->is_raid = 0;
 	} else {
 		part->disk_specific = NULL;
 	}
@@ -515,6 +518,7 @@ sun_partition_duplicate (const PedPartition* part)
 	new_sun_data->is_boot = old_sun_data->is_boot;
 	new_sun_data->is_root = old_sun_data->is_root;
 	new_sun_data->is_lvm = old_sun_data->is_lvm;
+	new_sun_data->is_raid = old_sun_data->is_raid;
 	return new_part;
 }
 
@@ -547,6 +551,10 @@ sun_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
 		sun_data->type = 0x8e;
 		return 1;
 	}
+	if (sun_data->is_raid) {
+		sun_data->type = 0xfd;
+		return 1;
+	}
 
 	sun_data->type = 0x83;
 	if (fs_type) {
@@ -573,20 +581,38 @@ sun_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
 	switch (flag) {
 		case PED_PARTITION_BOOT:
 			sun_data->is_boot = state;
-			if (state)
-				sun_data->is_root = sun_data->is_lvm = 0;
+			if (state) {
+				sun_data->is_lvm = 0;
+				sun_data->is_raid = 0;
+				sun_data->is_root = 0;
+			}
 			return ped_partition_set_system (part, part->fs_type);
 
 		case PED_PARTITION_ROOT:
 			sun_data->is_root = state;
-			if (state)
-				sun_data->is_boot = sun_data->is_lvm = 0;
+			if (state) {
+				sun_data->is_boot = 0;
+				sun_data->is_lvm = 0;
+				sun_data->is_raid = 0;
+			}
 			return ped_partition_set_system (part, part->fs_type);
 
 		case PED_PARTITION_LVM:
 			sun_data->is_lvm = state;
-			if (state)
-				sun_data->is_root = sun_data->is_boot = 0;
+			if (state) {
+				sun_data->is_boot = 0;
+				sun_data->is_raid = 0;
+				sun_data->is_root = 0;
+			}
+			return ped_partition_set_system (part, part->fs_type);
+
+		case PED_PARTITION_RAID:
+			sun_data->is_raid = state;
+			if (state) {
+				sun_data->is_boot = 0;
+				sun_data->is_lvm = 0;
+				sun_data->is_root = 0;
+			}
 			return ped_partition_set_system (part, part->fs_type);
 
 		default:
@@ -612,6 +638,8 @@ sun_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
 			return sun_data->is_root;
 		case PED_PARTITION_LVM:
 			return sun_data->is_lvm;
+		case PED_PARTITION_RAID:
+			return sun_data->is_raid;
 
 		default:
 			return 0;
@@ -627,6 +655,7 @@ sun_partition_is_flag_available (const PedPartition* part,
 		case PED_PARTITION_BOOT:
 		case PED_PARTITION_ROOT:
 		case PED_PARTITION_LVM:
+		case PED_PARTITION_RAID:
 			return 1;
 
 		default:
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1c8c753..ab3b7cb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,6 +9,7 @@ TESTS = \
   t2200-dos-label-recog.sh \
   t3000-constraints.sh \
   t3100-resize-ext2-partion.sh \
+  t4000-sun-raid-type.sh \
   t4100-msdos-partition-limits.sh \
   t4100-dvh-partition-limits.sh \
   t4200-partprobe.sh \
diff --git a/tests/t4000-sun-raid-type.sh b/tests/t4000-sun-raid-type.sh
new file mode 100755
index 0000000..ca38601
--- /dev/null
+++ b/tests/t4000-sun-raid-type.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+# Copyright (C) 2008 Tom "spot" Callaway <tcall...@redhat.com>
+# Derived from an example by Jim Meyering <j...@meyering.net>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+test_description="RAID support on sun disk type"
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+N=10M
+dev=sun-disk-file
+pwd=`pwd`
+exp="BYT;\n$pwd/$dev:20480s:file:512:512:sun:;\n1:0s:50s:51s"
+test_expect_success \
+    'create an empty file as a test disk' \
+    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
+
+test_expect_success \
+    'label the test disk as a sun disk' \
+    'parted -s $dev mklabel sun > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'create a single partition' \
+    'parted -s $dev unit s mkpart ext2 0s 50s > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'print the partition data in machine readable format' \
+    'parted -m -s $dev unit s p > out 2>&1'
+
+test_expect_success \
+    'check for expected values for the partition' '
+    printf "$exp:::;\n" > exp &&
+    $compare out exp'
+
+test_expect_success \
+    'set the raid flag' \
+    'parted -s $dev set 1 raid >out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'print the partition data in machine readable format again' \
+    'parted -m -s $dev unit s p > out 2>&1'
+
+test_expect_success \
+    'check for expected values (including raid flag) for the partition' '
+    printf "$exp:::raid;\n" > exp &&
+    $compare out exp'
+
+test_done
-- 
1.6.0.5

_______________________________________________
bug-parted mailing list
bug-parted@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-parted

Reply via email to