pf-tools commit: r542 [ccaillet-guest] - /trunk/lib/PFTools/Disk.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Sep 13 14:51:06 UTC 2007
Author: ccaillet-guest
Date: Thu Sep 13 14:51:06 2007
New Revision: 542
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=542
Log:
new devs for sparc platform
Modified:
trunk/lib/PFTools/Disk.pm
Modified: trunk/lib/PFTools/Disk.pm
URL: http://svn.debian.org/wsvn/pf-tools/trunk/lib/PFTools/Disk.pm?rev=542&op=diff
==============================================================================
--- trunk/lib/PFTools/Disk.pm (original)
+++ trunk/lib/PFTools/Disk.pm Thu Sep 13 14:51:06 2007
@@ -81,6 +81,7 @@
### Misc files
my $DUMP_PART_FILE = '/tmp/device_part.dmp' ;
+my $TPL_SPARC_PART = '' ;
#
@@ -392,9 +393,16 @@
if ( $DEBUG ) {
print 'Exec :'.$cmd."\n" ;
} else {
- `$cmd` ;
- if ( $? << 8 ) {
- warn "Problem when managing SCSI device ".join ( " ", @{$ref_device} )."\n" if ( $VERBOSE ) ;
+ system ( $cmd ) ;
+ if ( $? ) {
+ warn "Problem when managing SCSI device with command ".$cmd." and with the following error(s)\n" if ( $VERBOSE ) ;
+ if ( $? == -1 ) {
+ warn "failed to execute: $!\n" if ( $VERBOSE ) ;
+ } elsif ( $? & 127 ) {
+ printf STDERR "child died with signal %d, %s coredump\n", ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without' if ( $VERBOSE ) ;
+ } else {
+ printf STDERR "child exited with value %d\n", $? >> 8 if ( $VERBOSE ) ;
+ }
return 0 ;
}
}
@@ -405,23 +413,37 @@
# Managing partitions (dump, restore, ...)
#
-sub Add_raid_disk_partition ($) {
- # Call parameter(s)
- my ( $device ) = @_ ;
+sub Add_raid_disk_partition ($;$) {
+ # Call parameter(s)
+ my ( $device, $arch ) = @_ ;
# Local(s) var(s)
my $cmd ;
- if ( $DEBUG ) {
- $cmd = $SFDISK.' -f '.$device.' << EOF '.$FOLLOW.','.$SIZE.','.$RAID_PART_TYPE.' EOF' ;
- print 'Exec : '.$cmd."\n" ;
- } else {
- if ( ! open ( $cmd, '|'.$SFDISK.' -f '.$device.' -N'.$RAID_PART_NUM ) ) {
- warn "Unable to add raid partition on root disk with ".$SFDISK."\n" if ( $VERBOSE ) ;
- return 0 ;
- }
- print $cmd $FOLLOW.','.$SIZE.','.$RAID_PART_TYPE."\n" ;
- close ( $cmd ) ;
- }
+ if ( ! defined ( $arch ) || $arch eq 'i386' ) {
+ if ( $DEBUG ) {
+ $cmd = $SFDISK.' -f '.$device.' << EOF '.$FOLLOW.','.$SIZE.','.$RAID_PART_TYPE.' EOF' ;
+ print 'Exec : '.$cmd."\n" ;
+ } else {
+ system ( $cmd ) ;
+ if ( $? ) {
+ warn "Unable to add raid partition on device ".$device." with command ".$cmd." and with the following error(s)\n" if ( $VERBOSE ) ;
+ if ( $? == -1 ) {
+ warn "failed to execute: $!\n" if ( $VERBOSE ) ;
+ } elsif ( $? & 127 ) {
+ printf STDERR "child died with signal %d, %s coredump\n", ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without' if ( $VERBOSE ) ;
+ } else {
+ printf STDERR "child exited with value %d\n", $? >> 8 if ( $VERBOSE ) ;
+ }
+ return 0 ;
+ }
+ }
+ } elsif ( $arch eq 'sparc' ) {
+
+ } else {
+ warn "Invalid architecture for platform : unable to add raid partition on device ".$device."\n" if ( $VERBOSE ) ;
+ return 0 ;
+ }
+
return 1 ;
}
@@ -436,21 +458,23 @@
if ( $DEBUG ) {
print 'Exec : '.$cmd."\n" ;
} else {
- `$cmd` ;
+ system ( $cmd ) ;
if ( $? ) {
+ warn "Unable to dump partiotion table from device ".$device." with command ".$cmd." and with the following error(s)\n"if ( $VERBOSE ) ;
if ( $? == -1 ) {
warn "failed to execute: $!\n" if ( $VERBOSE ) ;
- return 0 ;
} elsif ( $? & 127 ) {
printf STDERR "child died with signal %d, %s coredump\n", ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without' if ( $VERBOSE ) ;
- return 0 ;
} else {
printf STDERR "child exited with value %d\n", $? >> 8 if ( $VERBOSE ) ;
- return 0 ;
- }
+ }
+ return 0 ;
}
}
} elsif ( $arch eq 'sparc' ) {
+ my @actions ;
+ # Dumping partition via command $cmd
+ $cmd = $FDISK.' -l '.$device ;
# Device Boot Start End Blocks Id System
# /dev/sda1 1 893 7168000 1c Hidden W95 FAT32 (LBA)
# Partition 1 does not end on cylinder boundary.
@@ -464,13 +488,32 @@
return 0 ;
}
while ( <DUMP> ) {
+ my ( $part, $bootable, $first, $last, $type, $type_name ) ;
+ next if ( /$device\3.*Whole disk.*$/ ) ;
# Fetching partition description line(s)
- if ( /^\/dev\/$device([\d]+)\s*(\*)?\s*([\d]+)\s*([\d+])\s*[\d]+([^\s]+)\s*(.)*$/ ) {
- my ( $part, $bootable, $first, $last, $type, $type_name ) = ( $1, $2, $3, $4, $5, $6 ) ;
- }
- # Create the file with fdisk command to create partition which is parsed on this line
+ if ( /^$device([\d]+)\s*(\*)?\s*([\d]+)\s*([\d+])\s*[\d]+([^\s]+)\s*(.)*$/ ) {
+ ( $part, $bootable, $first, $last, $type, $type_name ) = ( $1, $2, $3, $4, $5, $6 ) ;
+ }
+ # Create the actions to do with fdisk command for creating partition which is parsed on this line
+ push ( @actions, "n\n$part\n$first\n$last\nt\n$part\n$type\n" ) ;
}
close ( DUMP ) ;
+ # Initialize dumpfile with sparc template ;
+ if ( ! open ( TPL, $TPL_SPARC_PART ) ) {
+ warn "Unable to initialize dump file for sparc device ".$device."\n" if ( $VERBOSE ) ;
+ return 0 ;
+ }
+ @actions = <TPL> ;
+ close ( TPL ) ;
+ # Adding partitions retrieved by command $cmd
+ if ( ! open ( DUMP, ">".$DUMP_PART_FILE ) ) {
+ warn "Unable to write dump partition for device ".$device." on file ".$DUMP_PART_FILE."\n" if ( $VERBOSE ) ;
+ return 0 ;
+ }
+ foreach my $action ( @actions ) {
+ print DUMP $action ;
+ }
+ close ( DUMP ) ;
} else {
warn "Invalid architecture for platform : unable to dump partition table for device ".$device."\n" if ( $VERBOSE ) ;
return 0 ;
@@ -478,30 +521,37 @@
return 1 ;
}
-sub Restore_disk_partitions ($) {
- # Call parameter(s)
- my ( $device ) = @_ ;
+sub Restore_disk_partitions ($;$) {
+ # Call parameter(s)
+ my ( $device, $arch ) = @_ ;
# Local(s) var(s)
my $cmd ;
- $cmd = $SFDISK.' /dev/'.$device.' < '.$DUMP_PART_FILE ;
- if ( $DEBUG ) {
- print 'Exec : '.$cmd."\n" ;
- } else {
- `$cmd` ;
- if ( $? ) {
- if ( $? == -1 ) {
- warn "failed to execute: $!\n" if ( $VERBOSE ) ;
- exit 1 ;
- } elsif ( $? & 127 ) {
- printf STDERR "child died with signal %d, %s coredump\n", ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without' if ( $VERBOSE ) ;
- exit 1 ;
- } else {
- printf STDERR "child exited with value %d\n", $? >> 8 if ( $VERBOSE ) ;
- exit 1 ;
- }
- }
- }
+ if ( ! defined ( $arch ) || $arch eq 'i386' ) {
+ $cmd = $SFDISK.' '.$device.' < '.$DUMP_PART_FILE ;
+ if ( $DEBUG ) {
+ print 'Exec : '.$cmd."\n" ;
+ } else {
+ system ( $cmd ) ;
+ if ( $? ) {
+ warn "Unable to restore partition table for ".$device." with command ".$cmd." and with the following error(s)\n" if ( $VERBOSE ) ;
+ if ( $? == -1 ) {
+ warn "failed to execute: $!\n" if ( $VERBOSE ) ;
+ } elsif ( $? & 127 ) {
+ printf STDERR "child died with signal %d, %s coredump\n", ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without' if ( $VERBOSE ) ;
+ } else {
+ printf STDERR "child exited with value %d\n", $? >> 8 if ( $VERBOSE ) ;
+ }
+ return 0 ;
+ }
+ }
+ } elsif ( $arch eq 'sparc' ) {
+
+ } else {
+ warn "Invalid architecture for platform : unable to restore partition table for device ".$device."\n" if ( $VERBOSE ) ;
+ return 0 ;
+ }
+
return 1 ;
}
More information about the Pf-tools-commits
mailing list