summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_raw.pm
blob: 20a883b1102954c30d09d033c1cac3429ceab606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Diffstat (limited to 'bin/draknetprofile')
-rwxr-xr-xbin/draknetprofile42
1 files changed, 21 insertions, 21 deletions
diff --git a/bin/draknetprofile b/bin/draknetprofile
index e836c06..d2e5cce 100755
--- a/bin/draknetprofile
+++ b/bin/draknetprofile
@@ -28,16 +28,16 @@ use standalone;
use common;
use network::network;
-use mygtk2;
-use Gtk2::SimpleList;
-use ugtk2 qw(:create :helpers :wrappers :dialogs :ask);
+use mygtk3;
+use Gtk3::SimpleList;
+use ugtk3 qw(:create :helpers :wrappers :dialogs :ask);
use POSIX ();
require_root_capability();
-$ugtk2::wm_icon = 'draknetprofile-16';
+$ugtk3::wm_icon = 'draknetprofile-16';
my $title = N("Network profiles");
-my $w = ugtk2->new($title);
+my $w = ugtk3->new($title);
$::main_window = $w->{real_window}; #- so that transient_for is defined for wait messages and dialogs
my $net = {};
@@ -45,10 +45,10 @@ my @profiles;
my $default_profile = "default";
my %buttons;
-package Gtk2::CellRendererRadio;
+package Gtk3::CellRendererRadio;
sub new {
- my $renderer = Gtk2::CellRendererToggle->new;
+ my $renderer = Gtk3::CellRendererToggle->new;
$renderer->set_radio(1);
$renderer;
}
@@ -57,14 +57,14 @@ sub new {
package main;
-Gtk2::SimpleList->add_column_type(
+Gtk3::SimpleList->add_column_type(
'radio',
type => 'Glib::Boolean',
- renderer => 'Gtk2::CellRendererRadio',
+ renderer => 'Gtk3::CellRendererRadio',
attr => 'active',
);
-my $modules_list = Gtk2::SimpleList->new(
+my $modules_list = Gtk3::SimpleList->new(
N("Module") => 'hidden',
N("Enabled") => 'bool',
N("Description") => 'text',
@@ -81,7 +81,7 @@ $r[0]->signal_connect('toggled' => sub {
});
-my $profiles_list = Gtk2::SimpleList->new(
+my $profiles_list = Gtk3::SimpleList->new(
"" => 'hidden',
N("Profile") => 'text',
);
@@ -157,15 +157,15 @@ sub set_profile {
sub clone_profile() {
#my $source_profile = get_selected_profile();
my $dialog = _create_dialog(N("New profile..."));
- my $entry_dialog = Gtk2::Entry->new;
+ my $entry_dialog = Gtk3::Entry->new;
gtkpack($dialog->vbox,
- Gtk2::WrappedLabel->new(N("Please specify the name of the new network profile to be created (e.g., work, home, roaming, ..). This new profile will be created based on current settings, and you'll be able to configure your system configuration as usual afterwards.")),
+ Gtk3::WrappedLabel->new(N("Please specify the name of the new network profile to be created (e.g., work, home, roaming, ..). This new profile will be created based on current settings, and you'll be able to configure your system configuration as usual afterwards.")),
$entry_dialog,
);
gtkpack($dialog->action_area,
- gtksignal_connect(Gtk2::Button->new(N("Cancel")),
+ gtksignal_connect(Gtk3::Button->new(N("Cancel")),
clicked => sub { $dialog->destroy }),
- gtksignal_connect(my $bok = Gtk2::Button->new(N("Ok")), clicked => sub {
+ gtksignal_connect(my $bok = Gtk3::Button->new(N("Ok")), clicked => sub {
my $dest_profile = $entry_dialog->get_text;
# netprofile does not like spaces in profile names...
$dest_profile =~ s/ /_/g;
@@ -198,10 +198,10 @@ sub delete_selected_profile() {
}
# create advanced view to configure modules
-my $expander = Gtk2::Expander->new(N("Advanced"));
-$expander->add(gtkpack_(Gtk2::VBox->new,
- 0, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 1),
- 1, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0),
+my $expander = Gtk3::Expander->new(N("Advanced"));
+$expander->add(gtkpack_(Gtk3::VBox->new,
+ 0, gtkpack_(gtkset_border_width(Gtk3::HBox->new, 1),
+ 1, gtkpack_(gtkset_border_width(Gtk3::VBox->new, 0),
0, gtknew('WrappedLabel', text => N("Select the netprofile modules:")),
0, gtknew('ScrolledWindow', width => 300, height => 150, child => $modules_list),
),
@@ -214,7 +214,7 @@ $expander->show_all;
gtkadd($w->{window},
gtknew('VBox', spacing => 5, children => [
- $::isEmbedded ? () : (0, Gtk2::Banner->new('draknetprofile', $title)),
+ $::isEmbedded ? () : (0, Gtk3::Banner->new('draknetprofile', $title)),
0, gtknew('WrappedLabel', text => N("This tool allows you to control network profiles.")),
0, gtknew('WrappedLabel', text => N("Select a network profile:")),
1, gtknew('ScrolledWindow', width => 300, height => 150, child => $profiles_list),
@@ -223,7 +223,7 @@ gtkadd($w->{window},
$buttons{activate} = gtknew('Button', text => N("Activate"), clicked => \&set_selected_profile, sensitive => 0),
$buttons{clone} = gtknew('Button', text => N("New"), clicked => \&clone_profile, sensitive => 0),
$buttons{delete} = gtknew('Button', text => N("Delete"), clicked => \&delete_selected_profile, sensitive => 0),
- gtknew('Button', text => N("Quit"), clicked => sub { Gtk2->main_quit }),
+ gtknew('Button', text => N("Quit"), clicked => sub { Gtk3->main_quit }),
]),
]),
);
pos;, 0x6, "GRUB" ], [ 'osbs', 0x2, "OSBS" ], #- http://www.prz.tu-berlin.de/~wolf/os-bs.html [ 'pqmagic', 0xef, "PQV" ], [ 'BootStar', 0x130, "BootStar:" ], [ 'DocsBoot', 0x148, 'DocsBoot' ], [ 'system_commander', 0x1ad, "SYSCMNDRSYS" ], [ 'Be Os', 0x24, 'Boot Manager' ], [ 'TimO', 0, 'IBM Thinkpad hibernation partition' ], [ 'dos', 0xa0, "\x25\x03\x4E\x02\xCD\x13" ], [ 'dos', 0xa0, "\x00\xB4\x08\xCD\x13\x72" ], #- nt2k's [ 'dos', 0x60, "\xBB\x00\x7C\xB8\x01\x02\x57\xCD\x13\x5F\x73\x0C\x33\xC0\xCD\x13" ], #- nt's [ 'dos', 0x70, "\x0C\x33\xC0\xCD\x13\x4F\x75\xED\xBE\xA3" ], [ 'freebsd', 0xC0, "\x00\x30\xE4\xCD\x16\xCD\x19\xBB\x07\x00\xB4" ], [ 'freebsd', 0x160, "\x6A\x10\x89\xE6\x48\x80\xCC\x40\xCD\x13" ], [ 'dummy', 0xAC, "\x0E\xB3\x07\x56\xCD\x10\x5E\xEB" ], #- caldera? [ 'ranish', 0x100, "\x6A\x10\xB4\x42\x8B\xF4\xCD\x13\x8B\xE5\x73" ], [ 'os2', 0x1c2, "\xA" ], ); sub typeOfMBR($) { typeFromMagic(devices::make($_[0]), @MBR_signatures) } sub typeOfMBR_($) { typeFromMagic($_[0], @MBR_signatures) } sub hasExtended { 0 } sub cylinder_size($) { my ($hd) = @_; $hd->{geom}{sectors} * $hd->{geom}{heads}; } sub first_usable_sector { 1 } sub last_usable_sector { my ($hd) = @_; $hd->{totalsectors}; } #- default method for starting a partition, only head size or twice #- is allowed for starting a partition after a cylinder boundarie. sub adjustStart($$) { my ($hd, $part) = @_; my $end = $part->{start} + $part->{size}; $part->{start} = round_up($part->{start}, $part->{start} % cylinder_size($hd) < 2 * $hd->{geom}{sectors} ? $hd->{geom}{sectors} : cylinder_size($hd)); $part->{size} = $end - $part->{start}; $part->{size} > 0 or die "adjustStart get a too small partition to handle correctly"; } #- adjusting end to match a cylinder boundary, two methods are used and must #- match at the end, else something is wrong and nothing will be done on #- partition table. #- $end2 is computed by removing 2 (or only 1 if only 2 heads on drive) groups #- of sectors, this is necessary to handle extended partition where logical #- partition start after 1 (or 2 accepted) groups of sectors (typically 63). #- $end is floating (is not on cylinder boudary) so we have to choice a good #- candidate, $end1 or $end2 should always be good except $end1 for small #- partition size. sub adjustEnd($$) { my ($hd, $part) = @_; my $end = $part->{start} + $part->{size}; $end > $hd->{geom}{cylinders} * cylinder_size($hd) && $end <= $hd->{totalsectors} and return; my $end1 = round_down($end, cylinder_size($hd)); my $end2 = round_up($end - ($hd->{geom}{heads} > 2 ? 2 : 1) * $hd->{geom}{sectors}, cylinder_size($hd)); $end2 <= $hd->{geom}{cylinders} * cylinder_size($hd) or die "adjustEnd go beyond end of device geometry ($end2 > $hd->{totalsectors})"; $part->{size} = ($end1 - $part->{start} > cylinder_size($hd) ? $end1 : $end2) - $part->{start}; $part->{size} > 0 or die "adjustEnd get a too small partition to handle correctly"; } sub get_geometry($) { my ($dev) = @_; my $g = ""; local *F; sysopen F, $dev, 0 or return; ioctl(F, c::HDIO_GETGEO(), $g) or return; my %geom; @geom{qw(heads sectors cylinders start)} = unpack "CCSL", $g; $geom{totalcylinders} = $geom{cylinders}; my $total; #- $geom{cylinders} is no good (only a ushort, that means less than 2^16 => at best 512MB) if ($total = c::total_sectors(fileno F)) { $geom{cylinders} = int $total / $geom{heads} / $geom{sectors}; } else { $total = $geom{heads} * $geom{sectors} * $geom{cylinders} } { geom => \%geom, totalsectors => $total }; } sub openit($$;$) { sysopen $_[1], $_[0]{file}, $_[2] || 0; } # cause kernel to re-read partition table sub kernel_read($) { my ($hd) = @_; common::sync(); local *F; openit($hd, *F) or return 0; common::sync(); sleep(1); $hd->{rebootNeeded} = !ioctl(F, c::BLKRRPART(), 0); common::sync(); close F; common::sync(); sleep(1); } sub raw_removed { my ($hd, $raw) = @_; } sub can_raw_add { my ($hd) = @_; $_->{size} || $_->{type} or return 1 foreach @{$hd->{primary}{raw}}; 0; } sub raw_add { my ($hd, $raw, $part) = @_; foreach (@$raw) { $_->{size} || $_->{type} and next; $_ = $part; return; } die "raw_add: partition table already full"; } sub zero_MBR { my ($hd) = @_; #- force the standard partition type for the architecture my $type = arch() =~ /ia64/ ? 'gpt' : arch() eq "alpha" ? "bsd" : arch() =~ /^sparc/ ? "sun" : arch() eq "ppc" ? "mac" : "dos"; #- override standard mac type on PPC for IBM machines to dos $type = "dos" if (arch() =~ /ppc/ && detect_devices::get_mac_model() =~ /^IBM/); require("partition_table_$type.pm"); bless $hd, "partition_table_$type"; $hd->{primary} = $hd->clear_raw(); delete $hd->{extended}; } sub zero_MBR_and_dirty { my ($hd) = @_; zero_MBR($hd); $hd->{isDirty} = $hd->{needKernelReread} = 1; } #- ugly stuff needed mainly for Western Digital IDE drives #- try writing what we've just read, yells if it fails #- testing on last sector of head #0 (unused in 99% cases) #- #- return false if the device can't be written to (especially for Smartmedia) sub test_for_bad_drives { my ($hd) = @_; log::l("test_for_bad_drives($hd->{file})"); my $sector = $hd->{geom}{sectors} - 1; local *F; openit($hd, *F, 2) or die "can't open device"; my $seek = sub { c::lseek_sector(fileno(F), $sector, 0) or die "seeking to sector $sector failed"; }; my $tmp; &$seek; sysread F, $tmp, $SECTORSIZE or die "test_for_bad_drives: can't even read ($!)"; &$seek; syswrite F, $tmp or die "test_for_bad_drives: can't even write ($!)"; my $tmp2; &$seek; sysread F, $tmp2, $SECTORSIZE or die "test_for_bad_drives: can't even read again ($!)"; $tmp eq $tmp2 or die _("Something bad is happening on your drive. A test to check the integrity of data has failed. It means writing anything on the disk will end up with random trash"); 1; } 1;