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
|
package partition_table::gpt; # $Id: gpt.pm 252200 2009-01-27 18:08:22Z pterjan $
use diagnostics;
use strict;
use vars qw(@ISA);
@ISA = qw(partition_table::raw);
use partition_table::raw;
use c;
#sub use_pt_type { 1 }
sub read_one {
my ($hd, $_sector) = @_;
my $info;
c::get_disk_type($hd->{file}) eq "gpt" or die "not a GPT disk";
my @pt = map {
my %p;
print $_;
if (/^([^ ]*) ([^ ]*) ([^ ]*) (.*) \((\d*),(\d*),(\d*)\)$/) {
$p{part_number} = $1;
$p{real_device} = $2;
$p{fs_type} = $3;
$p{pt_type} = 0xba;
$p{start} = $5;
$p{size} = $7;
}
\%p;
} c::get_disk_partitions($hd->{file});
[ @pt ], $info;
}
sub write {
my ($hd, $_sector, $_pt, $_info) = @_;
# Initialize the disk if current partition table is not gpt
if (c::get_disk_type($hd->{file}) ne "gpt") {
c::set_disk_type($hd->{file}, "gpt");
}
foreach (@{$hd->{will_tell_kernel}}) {
my ($action, $part_number, $o_start, $o_size) = @$_;
my $part;
print "($action, $part_number, $o_start, $o_size)\n";
if ($action eq 'add') {
c::disk_add_partition($hd->{file}, $o_start, $o_size, $part->{fs_type}) or die "failed to add partition";
} elsif ($action eq 'del') {
c::disk_del_partition($hd->{file}, $part_number) or die "failed to del partition";
}
}
common::sync();
1;
}
sub initialize {
my ($class, $hd) = @_;
$hd->{primary} = { raw => [] };
bless $hd, $class;
}
sub can_add { &can_raw_add }
sub can_raw_add { 1 }
sub raw_add {
my ($hd, $raw, $part) = @_;
$hd->can_raw_add or die "raw_add: partition table already full";
push @$raw, $part;
}
sub adjustStart {}
sub adjustEnd {}
1;
|