diff options
author | Thierry Vignaud <thierry.vignaud@gmail.com> | 2015-03-24 10:16:41 -0400 |
---|---|---|
committer | Thierry Vignaud <thierry.vignaud@gmail.com> | 2015-03-25 19:55:33 +0100 |
commit | 134d2506afa228492d0a61f2d31486ca41ec54ef (patch) | |
tree | 6197e32a0d3ea2fe30bbd269c2ced79f2a945d03 | |
parent | 7f7356af622b3762f8a4b16c28e5daee2a69b220 (diff) | |
download | drakx-134d2506afa228492d0a61f2d31486ca41ec54ef.tar drakx-134d2506afa228492d0a61f2d31486ca41ec54ef.tar.gz drakx-134d2506afa228492d0a61f2d31486ca41ec54ef.tar.bz2 drakx-134d2506afa228492d0a61f2d31486ca41ec54ef.tar.xz drakx-134d2506afa228492d0a61f2d31486ca41ec54ef.zip |
use a proper interface between parted/perl worlds
create directly the hash in XS instead of instead of sprintf()ing it
into a string which was then parsed in perl in order to actually create
the hash
this fixes several issues:
- due to adding some fields to the string under if (),
we could silently have ignored some partitions
-
this also simplifies adding further fields
-rwxr-xr-x | perl-install/c/stuff.xs.pl | 39 | ||||
-rw-r--r-- | perl-install/partition_table/gpt.pm | 13 |
2 files changed, 19 insertions, 33 deletions
diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index 4b7ce74c3..d4d90ac16 100755 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -597,38 +597,33 @@ get_disk_partitions(char * device_path) PedDevice *dev = ped_device_get(device_path); if(dev) { PedDisk* disk = ped_disk_new(dev); - PedPartition *part = NULL; + PedPartition *part = NULL, *first_part = NULL; + int count = 1; if(!disk) return; - part = ped_disk_next_partition(disk, NULL); + first_part = part = ped_disk_next_partition(disk, NULL); + while(part) { + part = ped_disk_next_partition(disk, part); + count++; + } + EXTEND(SP, count); + part = first_part; while(part) { if(part->num == -1) { part = ped_disk_next_partition(disk, part); continue; } - char desc[4196]; char *path = ped_partition_get_path(part); - sprintf(desc, "%d ", part->num); - sprintf(desc+strlen(desc), "%s ", path); + HV * rh = (HV *)sv_2mortal((SV *)newHV()); + hv_store(rh, "part_number", 11, newSViv(part->num), 0); + hv_store(rh, "real_device", 11, newSVpv(path, 0), 0); + hv_store(rh, "start", 5, newSViv(part->geom.start), 0); + hv_store(rh, "size", 4, newSViv(part->geom.length), 0); + hv_store(rh, "pt_type", 7, newSViv(0xba), 0); free(path); if(part->fs_type) - strcat(desc, part->fs_type->name); - if(part->type == 0x0) - strcat(desc, " normal"); - else { - if(part->type & PED_PARTITION_LOGICAL) - strcat(desc, " logical"); - if(part->type & PED_PARTITION_EXTENDED) - strcat(desc, " extended"); - if(part->type & PED_PARTITION_FREESPACE) - strcat(desc, " freespace"); - if(part->type & PED_PARTITION_METADATA) - strcat(desc, " metadata"); - if(part->type & PED_PARTITION_PROTECTED) - strcat(desc, " protected"); - } - sprintf(desc+strlen(desc), " (%lld,%lld,%lld)", part->geom.start, part->geom.end, part->geom.length); - XPUSHs(sv_2mortal(newSVpv(desc, 0))); + hv_store(rh, "fs_type", 7, newSVpv(part->fs_type->name, 0), 0); + PUSHs(newRV((SV *)rh)); part = ped_disk_next_partition(disk, part); } ped_disk_destroy(disk); diff --git a/perl-install/partition_table/gpt.pm b/perl-install/partition_table/gpt.pm index a1d8b84f8..77173b268 100644 --- a/perl-install/partition_table/gpt.pm +++ b/perl-install/partition_table/gpt.pm @@ -107,18 +107,9 @@ sub read_one { c::get_disk_type($hd->{file}) eq "gpt" or die "$hd->{device} not a GPT disk ($hd->{file})"; my @pt; + # FIXME: just use '@pt = c::...' if part_numbers are always linear: foreach (c::get_disk_partitions($hd->{file})) { - log::l($_); - if (/^([^ ]*) ([^ ]*) ([^ ]*) (.*) \((\d*),(\d*),(\d*)\)$/) { - my %p; - $p{part_number} = $1; - $p{real_device} = $2; - $p{fs_type} = $3; - $p{pt_type} = 0xba; - $p{start} = $5; - $p{size} = $7; - @pt[$p{part_number}-1] = \%p; - } + @pt[$_->{part_number}-1] = $_; } for (my $part_number = 1; $part_number < $nb_primary; $part_number++) { |