summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perl-install/c/Makefile.PL2
-rw-r--r--perl-install/c/stuff.xs.pl162
2 files changed, 158 insertions, 6 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 145858d78..cd2c6bf03 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 '
@@ -262,8 +263,9 @@ pci_probe()
EXTEND(SP, entries.nb);
for (i = 0; i < entries.nb; i++) {
struct pciusb_entry *e = &entries.entries[i];
- snprintf(buf, sizeof(buf), "%04x\t%04x\t%04x\t%04x\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s",
- e->vendor, e->device, e->subvendor, e->subdevice, e->pci_domain, e->pci_bus, e->pci_device, e->pci_function, e->pci_revision, e->is_pciexpress,
+ snprintf(buf, sizeof(buf), "%04x\t%04x\t%04x\t%04x\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s",
+ e->vendor, e->device, e->subvendor, e->subdevice, e->pci_domain, e->pci_bus,
+ e->pci_device, e->pci_function, e->pci_revision, e->is_pciexpress,
pci_class2text(e->class_id), e->class, e->module ? e->module : "unknown", e->text);
PUSHs(sv_2mortal(newSVpv(buf, 0)));
}
@@ -280,8 +282,10 @@ usb_probe()
for (i = 0; i < entries.nb; i++) {
struct pciusb_entry *e = &entries.entries[i];
struct usb_class_text class_text = usb_class2text(e->class_id);
- snprintf(buf, sizeof(buf), "%04x\t%04x\t%s|%s|%s\t%s\t%s\t%d\t%d",
- e->vendor, e->device, class_text.usb_class_text, class_text.usb_sub_text, class_text.usb_prot_text, e->module ? e->module : "unknown", e->text, e->pci_bus, e->pci_device);
+ snprintf(buf, sizeof(buf), "%04x\t%04x\t%s|%s|%s\t%s\t%s\t%d\t%d\t%d",
+ e->vendor, e->device, class_text.usb_class_text, class_text.usb_sub_text,
+ class_text.usb_prot_text, e->module ? e->module : "unknown", e->text,
+ e->pci_bus, e->pci_device, e->usb_port);
PUSHs(sv_2mortal(newSVpv(buf, 0)));
}
pciusb_free(&entries);
@@ -512,8 +516,156 @@ get_iso_volume_ids(int fd)
';
+print '
+
+const char *
+get_disk_type(char * device_path)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL = NULL;
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ if(disk) {
+ RETVAL = disk->type->name;
+ ped_disk_destroy(disk);
+ }
+ }
+ 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);
+ 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);
+ RETVAL = 0;
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ if(disk) {
+ RETVAL = ped_disk_delete_all(disk);
+ if(RETVAL)
+ RETVAL = ped_disk_commit(disk);
+ ped_disk_destroy(disk);
+ }
+ }
+ 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);
+ if(disk) {
+ 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);
+ if(disk) {
+ 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
+ [ qw(int S_IFCHR S_IFBLK S_IFIFO S_IFMT KDSKBENT K_NOSUCHMAP NR_KEYS MAX_NR_KEYMAPS BLKRRPART TIOCSCTTY
HDIO_GETGEO LOOP_GET_STATUS
MS_MGC_VAL O_WRONLY O_RDWR O_CREAT O_NONBLOCK F_SETFL F_GETFL WNOHANG
VT_ACTIVATE VT_WAITACTIVE VT_GETSTATE