summaryrefslogtreecommitdiffstats
path: root/perl-install/c
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mandriva.org>2009-01-27 18:08:22 +0000
committerPascal Terjan <pterjan@mandriva.org>2009-01-27 18:08:22 +0000
commit9e6b327ca2b1f46db62e0811fabf0a6cf0b114a7 (patch)
tree9d057f0db2a322b2722c4789ea5b92499451cf09 /perl-install/c
parent2c28392672c97ba41d2a9af43ecb3c8fb031681b (diff)
downloaddrakx-9e6b327ca2b1f46db62e0811fabf0a6cf0b114a7.tar
drakx-9e6b327ca2b1f46db62e0811fabf0a6cf0b114a7.tar.gz
drakx-9e6b327ca2b1f46db62e0811fabf0a6cf0b114a7.tar.bz2
drakx-9e6b327ca2b1f46db62e0811fabf0a6cf0b114a7.tar.xz
drakx-9e6b327ca2b1f46db62e0811fabf0a6cf0b114a7.zip
Rewrite gpt support with libparted
Diffstat (limited to 'perl-install/c')
-rw-r--r--perl-install/c/Makefile.PL2
-rw-r--r--perl-install/c/stuff.xs.pl139
2 files changed, 140 insertions, 1 deletions
diff --git a/perl-install/c/Makefile.PL b/perl-install/c/Makefile.PL
index 405c02ecc..8cb2524c9 100644
--- a/perl-install/c/Makefile.PL
+++ b/perl-install/c/Makefile.PL
@@ -6,7 +6,7 @@ use Config;
my $lib = arch() =~ /x86_64/ ? 'lib64' : 'lib';
-my $libs = '-lldetect';
+my $libs = '-lldetect -lparted';
my $pcmcia_probe_o = "/usr/$lib/drakx-installer-binaries/pcmcia_probe.o";
diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl
index a94de81fa..bf8e35bc1 100644
--- a/perl-install/c/stuff.xs.pl
+++ b/perl-install/c/stuff.xs.pl
@@ -55,6 +55,7 @@ typedef __uint8_t u8;
#define SECTORSIZE 512
+#include <parted/parted.h>
';
$Config{archname} =~ /i.86/ and print '
@@ -512,6 +513,144 @@ get_iso_volume_ids(int fd)
';
+print '
+
+const char *
+get_disk_type(char * device_path)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ RETVAL = disk->type->name;
+ ped_disk_destroy(disk);
+ } else RETVAL = NULL;
+ OUTPUT:
+ RETVAL
+
+void
+get_disk_partitions(char * device_path)
+ PPCODE:
+ PedDevice *dev = ped_device_get(device_path);
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ PedPartition *part = NULL;
+ if(disk)
+ part = ped_disk_next_partition(disk, NULL);
+ while(part) {
+ if(part->num != -1) {
+ char desc[4196];
+ char *path = ped_partition_get_path(part);
+ sprintf(desc, "%d ", part->num);
+ sprintf(desc+strlen(desc), "%s ", path);
+ ped_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)));
+ }
+ part = ped_disk_next_partition(disk, part);
+ }
+ if(disk)
+ ped_disk_destroy(disk);
+ }
+
+int
+set_disk_type(char * device_path, const char * type_name)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL = 0;
+ if(dev) {
+ PedDiskType* type = ped_disk_type_get(type_name);
+ if(type) {
+ PedDisk* disk = ped_disk_new_fresh(dev, type);
+ if(disk) {
+ RETVAL = ped_disk_commit(disk);
+ ped_disk_destroy(disk);
+ }
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+int
+disk_delete_all(char * device_path)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ RETVAL = ped_disk_delete_all(disk);
+ if(RETVAL)
+ RETVAL = ped_disk_commit(disk);
+ ped_disk_destroy(disk);
+ } else RETVAL = 0;
+ OUTPUT:
+ RETVAL
+
+int
+disk_del_partition(char * device_path, int part_number)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL = 0;
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ PedPartition* part = ped_disk_get_partition(disk, part_number);
+ if(!part) {
+ printf("disk_del_partition: failed to find partition\n");
+ } else {
+ RETVAL=ped_disk_delete_partition(disk, part);
+ if(RETVAL) {
+ RETVAL = ped_disk_commit(disk);
+ } else {
+ printf("del_partition failed\n");
+ }
+ }
+ ped_disk_destroy(disk);
+ }
+ OUTPUT:
+ RETVAL
+
+int
+disk_add_partition(char * device_path, double start, double length, const char * fs_type)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL=0;
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ PedGeometry* geom = ped_geometry_new(dev, (long long)start, (long long)length);
+ PedPartition* part = ped_partition_new (disk, PED_PARTITION_NORMAL, ped_file_system_type_get(fs_type), (long long)start, (long long)start+length-1);
+ PedConstraint* constraint = ped_constraint_new_from_max(geom);
+ if(!part) {
+ printf("ped_partition_new failed\n");
+ } else
+ RETVAL = ped_disk_add_partition (disk, part, constraint);
+ if(RETVAL) {
+ RETVAL = ped_disk_commit(disk);
+ } else {
+ printf("add_partition failed\n");
+ }
+ ped_geometry_destroy(geom);
+ ped_constraint_destroy(constraint);
+ ped_disk_destroy(disk);
+ }
+ OUTPUT:
+ RETVAL
+
+';
+
@macros = (
[ qw(int S_IFCHR S_IFBLK S_IFIFO KDSKBENT K_NOSUCHMAP NR_KEYS MAX_NR_KEYMAPS BLKRRPART TIOCSCTTY
HDIO_GETGEO LOOP_GET_STATUS