# vim: set et ts=4 sw=4: package AdminPanel::Rpmdragora::gurpm; #***************************************************************************** # # Copyright (c) 2002 Guillaume Cottenceau # Copyright (c) 2002-2007 Thierry Vignaud # Copyright (c) 2003, 2004, 2005 MandrakeSoft SA # Copyright (c) 2005-2007 Mandriva SA # Copyright (c) 2013 Matteo Pasotti # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2, as # published by the Free Software Foundation. # # 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, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # #***************************************************************************** # # $Id: gurpm.pm 255450 2009-04-03 16:00:16Z tv $ use strict; use lib qw(/usr/lib/libDrakX); use yui; use Time::HiRes; use feature 'state'; sub new { my ($class, $title, $initializing, %options) = @_; my $self = { my $label = 0, my $factory = 0, my $mainw = 0, my $vbox = 0, my $progressbar = 0, my $cancel = 0 }; bless $self, 'AdminPanel::Rpmdragora::gurpm'; #my $mainw = bless(ugtk2->new($title, %options, default_width => 600, width => 600), $self); $self->{factory} = yui::YUI::widgetFactory; $self->{mainw} = $self->{factory}->createPopupDialog(); #$::main_window = $self->{mainw}; $self->{vbox} = $self->{factory}->createVBox($self->{mainw}); #OLD $mainw->{label} = gtknew('Label', text => $initializing, alignment => [ 0.5, 0 ]); $self->{label} = $self->{factory}->createLabel($self->{vbox}, $initializing); # size label's heigh to 2 lines in order to prevent dummy vertical resizing: #my $context = $mainw->{label}->get_layout->get_context; #my $metrics = $context->get_metrics($mainw->{label}->style->font_desc, $context->get_language); #$mainw->{label}->set_size_request(-1, 2 * Gtk2::Pango->PANGO_PIXELS($metrics->get_ascent + $metrics->get_descent)); #OLD $mainw->{progressbar} = gtknew('ProgressBar'); $self->{progressbar} = $self->{factory}->createProgressBar($self->{vbox}, ""); #gtkadd($mainw->{window}, $mainw->{vbox} = gtknew('VBox', spacing => 5, border_width => 6, children_tight => [ # $mainw->{label}, # $mainw->{progressbar} #])); #$mainw->{rwindow}->set_position('center-on-parent'); #$mainw->{real_window}->show_all; #select(undef, undef, undef, 0.1); #- hackish :-( #$mainw->SUPER::sync; $self->{mainw}->pollEvent(); $self->flush(); $self; } sub flush { my ($self) = @_; $self->{mainw}->recalcLayout(); $self->{mainw}->doneMultipleChanges(); } sub label { my ($self, $label) = @_; $self->{label} = $self->{factory}->createLabel($self->{vbox},$label); #select(undef, undef, undef, 0.1); #- hackish :-( $self->flush(); } sub progress { my ($self, $value) = @_; state $time; $time = 0 if(!defined($time)); $value = 0 if $value < 0; $value = 100 if 1 < $value; $self->{progressbar}->setValue($value); return if Time::HiRes::clock_gettime() - $time < 0.333; $time = Time::HiRes::clock_gettime(); $self->flush(); } sub DESTROY { my ($self) = @_; #mygtk2::may_destroy($self); $self and $self->{mainw}->destroy; #$self = undef; $self->{cancel} = undef; #- in case we'll do another one later } sub validate_cancel { my ($self, $cancel_msg, $cancel_cb) = @_; if (!$self->{cancel}) { $self->{cancel} = $self->{factory}->createIconButton($self->{vbox},"",$cancel_msg); #gtkpack__( #$self->{vbox}, #$self->{hbox_cancel} = gtkpack__( #gtknew('HButtonBox'), #$self->{cancel} = gtknew('Button', text => $cancel_msg, clicked => \&$cancel_cb), #), #); } #$self->{cancel}->set_sensitive(1); #$self->{cancel}->show; $self->flush(); } sub invalidate_cancel { my ($self) = @_; $self->{cancel} and $self->{cancel}->setEnabled(0); } sub invalidate_cancel_forever { my ($self) = @_; #$self->{hbox_cancel} or return; #$self->{hbox_cancel}->destroy; # FIXME: temporary workaround that prevents # Gtk2::Label::set_text() set_text_internal() -> queue_resize() -> # size_allocate() call chain to mess up when ->shrink_topwindow() # has been called (#32613): #$self->shrink_topwindow; } 1; '>log msg
blob: 1346eeac48b095da61422b96f9b8b46d9c23adb2 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package partition_table::raw; # $Id$

use diagnostics;
use strict;

use common;
use devices;
use detect_devices;
use fs::type;
use log;
use c;

my @MBR_signatures = (
if_(arch() =~ /ppc/,
    (map { [ 'yaboot', 0, "PM", 0x200 * $_ + 0x10, "bootstrap\0" ] } 0 .. 61), #- "PM" is a Partition Map
    [ 'yaboot', 0x400, "BD", 0x424, "\011bootstrap" ], #- "BD" is a HFS filesystem
),
    [ 'empty', 0, "\0\0\0\0" ],
    [ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ],
    [ 'grub', 0, "\xEBH", 0x17e, "stage1 \0" ],
    [ 'grub', 0, "\xEBH", 0x18a, "stage1 \0" ],
    sub { my ($F) = @_;
	  #- standard grub has no good magic (Mandriva's grub is patched to have "GRUB" at offset 6)
	  #- so scanning a range of possible places where grub can have its string
	  #- 0x176 found on Conectiva 10
	  my ($min, $max, $magic) = (0x176, 0x181, "GRUB \0");
	  my $tmp;
	  sysseek($F, 0, 0) && sysread($F, $tmp, $max + length($magic)) or return;
	  substr($tmp, 0, 2) eq "\xEBH" or return;
	  index($tmp, $magic, $min) >= 0 && "grub";
      },
    [ 'lilo', 0x2,  "LILO" ],
    [ 'lilo', 0x6,  "LILO" ],
    [ 'lilo', 0x6 + 0x40,  "LILO" ], #- when relocated in lilo's bsect_update(), variable "space" on paragraph boundary gives 0x40
    [ 'grub', 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' ],
    [ 'os2', 0, "\xFA\xB8\x30\x00", 0xfA, "OS/2" ],
    [ '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, "\x0A" ],
    [ 'Acronis', 0, "\xE8\x12\x01" ],
);

sub typeOfMBR($) { typeFromMagic(devices::make($_[0]), @MBR_signatures) }
sub typeOfMBR_($) { typeFromMagic($_[0], @MBR_signatures) }

sub use_pt_type { 0 }
sub hasExtended { 0 }
sub set_best_geometry_for_the_partition_table {}

sub cylinder_size($) {
    my ($hd) = @_;
    $hd->{geom}{sectors} * $hd->{geom}{heads};
}
sub first_usable_sector { 1 }
sub last_usable_sector { 
    my ($hd) = @_;
    $hd->{totalsectors};
}
# no limit
sub max_partition_start { 1e99 }
sub max_partition_size { 1e99 }

#- 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};

    if (cylinder_size($hd)) {
	$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));