Hi,

I've modified IA.pm from systeminstaller-oscar-2.4.8-1 to as support for GPT 
partition tables and fix CCISS HP Raid Array as well.

After a few tests, it seems that it works realy well.:-)

As I'm a perl newbee, there is a strangeness that I don't understand, it seems 
that the 3 last parameters recieved by do_partition are references. Thus I need 
to address them using $$, and I don't understand why, aside that, every thing 
seems good.

Regards,

-- 
        Olivier LAHAYE
        CEA Saclay
        DRT-LIST-DETECS-SSTM
--- /usr/lib/systeminstaller/SystemInstaller/Partition/IA.pm	2009-11-27 18:52:52.000000000 +0100
+++ /usr/lib/systeminstaller/SystemInstaller/Partition/IA.pm.orig	2009-11-25 17:24:28.000000000 +0100
@@ -99,38 +99,16 @@
     return $flags;
 }
 
-# Bad work around to handle /dev/ccis/c#d#p# (handle the "p")
-sub get_partition_device ($$) {
-    my ($disk, $partnum) = @_;
+sub get_extended_partition_id ($) {
+    my $disk = @_;
+
     if ($disk =~ /\/dev\/cciss\/c[0-9]+d[0-9][0-9]*$/) {
-        return $disk."p".$partnum;
+        return "p5";
     } else {
-        return $disk.$partnum;
+        return "5";
     }
 }
-# Create <part= tag.
-# pnum: partition numer
-# psize: partition size (string) or "\*"
-# ptype: eiter "primary", "logical" "extended" or "41"
-# pflag: flags
-sub do_partition ($$$$) {
-	my ($pnum, $psize, $ptype, $pflags) = @_ ;
-	my $pid;
-	if ($$ptype eq "41") {
-		$pid = 41;
-		$ptype = "primary";
-	}
-	print AICONF "\t\t<part num=\"$pnum\" ";
-	print AICONF "size=\"$$psize\" ";
-	print AICONF "p_type=\"$$ptype\" ";
-	if($pid == 41) {
-		print AICONF "id=\"41\"";
-	}
-	if(defined($$pflags) && !($$pflags eq "")) {
-	        print AICONF "flags=\"$$pflags\" ";
-	}
-        print AICONF "/>\n";
-}
+
 
 # Create an autoinstallscript.conf file to be used
 # be used by SystemImager's mkautoinstallscript.
@@ -176,68 +154,53 @@
         print AICONF "\t<disk dev=\"$disk\" ";
         print AICONF "label_type=\"$DISKS{LABEL_TYPE}\" ";
         print AICONF "unit_of_measurement=\"$DISKS{UNITS}\">\n";
-	my $has_logicals = 0;
-	my $extended_part_num;
-	# 1st, check for incompatible layouts if we use msdos partition table.
-        if ($DISKS{LABEL_TYPE} eq "msdos")
-	{
-	    my $primary_count = 0;
-	    # Cycle thru partitions,; count primaries and see if we have logicals
-	    foreach my $partname ( @{$DISKS{DRIVES}{$disk}} ) {
-	        if ($DISKS{PARTITIONS}{$partname}{PNUM} > 4) {
-		    $has_logicals = 1;
-		} else {
-		    $primary_count++;
-		}
-	    }
-
-	    # Check if we have room for extended partition (if required)
-	    if ($has_logicals == 1) {
-		    # check 4 primary + extended impossible layout
-		    if ($primary_count == 4) {
-			carp "ERROR: $DISKS{FILENAME} layout incompatible with label_type=msdos. Use gpt or use less primary partitions"; 
-        		return 1;
-		    }
-		    # Determine which partition device name is available for extended partition (if required)
-		    # cycle thru ids 1 to 4 and see if a slot is available.
-		    foreach my $parnum (1..4) {
-			my $partname = get_partition_device ($disk,$parnum);
-			if (! defined ($DISKS{PARTITIONS}{$partname})) { # We found a slot
-			    $extended_part_num = $parnum ;
-			    last ;
-			}
-		    }
-	    }
-	} elsif (scalar @{$DISKS{DRIVES}{$disk}} > 128) { # Handle non probable case that could become probable in a long long future ;-)
-		carp "ERROR: $DISKS{FILENAME} layout incompatible with label_type=$DISKS{LABEL_TYPE}: partition count exceeded: max = 128 (gpt)";
-		return 1;
-	}
-
-	# Do all partitions at once. Be carefull when PNUM becomes > 4
-	my $partition_type;
-	foreach my $parname ( @{$DISKS{DRIVES}{$disk}} ) {
-	    if (($DISKS{LABEL_TYPE} eq "msdos") && $DISKS{PARTITIONS}{$parname}{PNUM} > 4) {
-		# on msdos partition table, if pnum >4 we need to be carefull
-		if (defined($extended_part_num)) {
-		    # We need to create $extended_part_num (not yet created)
-		    do_partition ( $extended_part_num,\
-				   "\*",\
-				   "extended",\
-				   undef );
-		    undef $extended_part_num; # Done, we won't go here again.
-		}
-		$partition_type = "logical" ; # msdos & PNUM > 4
-	    } else {
-	        $partition_type = "primary" ; # PNUM <= 4 or not msdos
-	    }
-	    $flags = get_partition_flags ($parname, %DISKS);
-	    do_partition ( $DISKS{PARTITIONS}{$parname}{PNUM},\
-			   $DISKS{PARTITIONS}{$parname}{SIZE},\
-			   $partition_type,\
-			   $flags );
-    	}
+        my $extparcreated=0;
+        my $extpartid = get_extended_partition_id ($disk);
+        # First do the primary partitions
+        # TODO: This will not work with gpt partitions.
+        foreach my $parnum (1..4) {
+            my $parname=$disk.$parnum;
+            if (defined $DISKS{PARTITIONS}{$parname}) {
+                print AICONF "\t\t<part num=\"$DISKS{PARTITIONS}{$parname}{PNUM}\" ";
+                print AICONF "size=\"$DISKS{PARTITIONS}{$parname}{SIZE}\" ";
+                if ($DISKS{PARTITIONS}{$parname}{TYPE} == 5) {
+                    print AICONF "p_type=\"extended\" ";
+                    $extparcreated++;
+                } else {
+                    print AICONF "p_type=\"primary\" ";
+                }
+                if ($DISKS{PARTITIONS}{$parname}{TYPE} == 41) {
+                    print AICONF "id=\"$DISKS{PARTITIONS}{$parname}{TYPE}\" ";
+                }
+                $flags = get_partition_flags ($parname, %DISKS);
+                if ($flags) {
+                    print AICONF "flags=\"$flags\" ";
+                }
+                print AICONF "/>\n";
+            } elsif ((! $extparcreated ) 
+                    && (defined $DISKS{PARTITIONS}{$disk.$extpartid}) ){
+                print AICONF "\t\t<part num=\"$parnum\" size=\"\*\" ";
+                print AICONF "p_type=\"extended\" ";
+                print AICONF "/>\n";
+                $extparcreated++;
+            }
+        }
+        # Now the logical partitions
+        foreach my $parname (@{$DISKS{DRIVES}{$disk}}) {
+            if ($DISKS{PARTITIONS}{$parname}{PNUM} > 4) {
+                print AICONF "\t\t<part num=\"$DISKS{PARTITIONS}{$parname}{PNUM}\" ";
+                print AICONF "size=\"$DISKS{PARTITIONS}{$parname}{SIZE}\" ";
+                print AICONF "p_type=\"logical\" ";
+                $flags = get_partition_flags ($parname, %DISKS);
+                if ($flags) {
+                    print AICONF "flags=\"$flags\" ";
+                }
+                print AICONF "/>\n";
+            }
+        }
         print AICONF "\t</disk>\n";
-    } # end foreach $disk
+    }
+
     # Write RAID structures - EF -
     for my $rlevel ("0", "1", "5", "6") {
         my $rraid = "RAID$rlevel";
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Oscar-devel mailing list
Oscar-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oscar-devel

Reply via email to