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 /perl-install/c | |
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
Diffstat (limited to 'perl-install/c')
-rwxr-xr-x | perl-install/c/stuff.xs.pl | 39 |
1 files changed, 17 insertions, 22 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); |