summaryrefslogtreecommitdiffstats
path: root/perl-install/c
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/c')
-rwxr-xr-x[-rw-r--r--]perl-install/c/Makefile.PL4
-rw-r--r--perl-install/c/README1
-rw-r--r--perl-install/c/stuff.pm2
-rwxr-xr-x[-rw-r--r--]perl-install/c/stuff.xs.pl360
4 files changed, 337 insertions, 30 deletions
diff --git a/perl-install/c/Makefile.PL b/perl-install/c/Makefile.PL
index 405c02ecc..f776d27f2 100644..100755
--- a/perl-install/c/Makefile.PL
+++ b/perl-install/c/Makefile.PL
@@ -6,13 +6,13 @@ 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";
WriteMakefile(
'NAME' => 'stuff',
- 'OPTIMIZE' => '-Os',
+ 'OPTIMIZE' => '-Os -Wall',
'MAKEFILE' => 'Makefile_c',
'OBJECT' => "stuff.o " . (-e $pcmcia_probe_o && " $pcmcia_probe_o"),
'VERSION_FROM' => 'stuff.pm', # finds $VERSION
diff --git a/perl-install/c/README b/perl-install/c/README
deleted file mode 100644
index 2453a5121..000000000
--- a/perl-install/c/README
+++ /dev/null
@@ -1 +0,0 @@
-md5.c, md5_crypt.c and md5.h are taken from pam (dir modules/pam_pwdb)
diff --git a/perl-install/c/stuff.pm b/perl-install/c/stuff.pm
index 37e0c9a3b..72b5b0bd3 100644
--- a/perl-install/c/stuff.pm
+++ b/perl-install/c/stuff.pm
@@ -1,4 +1,4 @@
-package c::stuff; # $Id$
+package c::stuff;
use strict;
use vars qw($VERSION @ISA);
diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl
index a94de81fa..1a148b497 100644..100755
--- a/perl-install/c/stuff.xs.pl
+++ b/perl-install/c/stuff.xs.pl
@@ -36,14 +36,9 @@ print '
#include <net/route.h>
#include <netinet/in.h>
#include <linux/sockios.h>
-
-// for ethtool structs:
-typedef unsigned long long u64;
-typedef __uint32_t u32;
-typedef __uint16_t u16;
-typedef __uint8_t u8;
-
#include <linux/ethtool.h>
+#include <linux/input.h>
+#include <execinfo.h>
// for UPS on USB:
# define HID_MAX_USAGES 1024
@@ -55,6 +50,7 @@ typedef __uint8_t u8;
#define SECTORSIZE 512
+#include <parted/parted.h>
';
$Config{archname} =~ /i.86/ and print '
@@ -92,6 +88,18 @@ void log_perror(const char *msg) {
log_message("%s: %s", msg, strerror(errno));
}
+HV* common_pciusb_hash_init(struct pciusb_entry *e) {
+ HV *rh = (HV *)sv_2mortal((SV *)newHV());
+ hv_store(rh, "vendor", 6, newSViv(e->vendor), 0);
+ hv_store(rh, "subvendor", 9, newSViv(e->subvendor), 0);
+ hv_store(rh, "id", 2, newSViv(e->device), 0);
+ hv_store(rh, "subid", 5, newSViv(e->subdevice), 0);
+ hv_store(rh, "driver", 6, newSVpv(e->module ? e->module : "unknown", 0), 0);
+ hv_store(rh, "description", 11, newSVpv(e->text, 0), 0);
+ hv_store(rh, "pci_bus", 7, newSViv(e->pci_bus), 0);
+ hv_store(rh, "pci_device", 10, newSViv(e->pci_device), 0);
+ return rh;
+}
';
@@ -103,6 +111,31 @@ int length_of_space_padded(char *str, int len) {
return len;
}
+PedPartitionFlag string_to_pedpartflag(char*type) {
+ PedPartitionFlag flag = 0;
+ if (!strcmp(type, "ESP")) {
+ flag = PED_PARTITION_ESP;
+ } else if (!strcmp(type, "BIOS_GRUB")) {
+ flag = PED_PARTITION_BIOS_GRUB;
+ } else if (!strcmp(type, "LVM")) {
+ flag = PED_PARTITION_LVM;
+ } else if (!strcmp(type, "RAID")) {
+ flag = PED_PARTITION_RAID;
+ } else {
+ printf("set_partition_flag: unknown type: %s\n", type);
+ }
+ return flag;
+}
+
+int is_recovery_partition(PedPartition*part) {
+ /* FIXME: not sure everything is covered ... */
+ return ped_partition_get_flag(part, PED_PARTITION_HPSERVICE) // HP-UX service partition
+ || ped_partition_get_flag(part, PED_PARTITION_MSFT_RESERVED) // Microsoft Reserved Partition -> LDM metadata, ...
+ || ped_partition_get_flag(part, PED_PARTITION_DIAG) // ==> PARTITION_MSFT_RECOVERY (Windows Recovery Environment)
+ || ped_partition_get_flag(part, PED_PARTITION_APPLE_TV_RECOVERY)
+ || ped_partition_get_flag(part, PED_PARTITION_HIDDEN);
+}
+
MODULE = c::stuff PACKAGE = c::stuff
';
@@ -163,14 +196,14 @@ init_setlocale()
setlocale(LC_NUMERIC, "C"); /* otherwise eval "1.5" returns 1 in fr_FR for example */
char *
-setlocale(category, locale = 0)
+setlocale(category, locale = NULL)
int category
char * locale
int
lseek_sector(fd, sector, offset)
int fd
- long sector
+ unsigned long sector
long offset
CODE:
RETVAL = lseek64(fd, (off64_t) sector * SECTORSIZE + offset, SEEK_SET) >= 0;
@@ -251,21 +284,43 @@ void
usleep(microseconds)
unsigned long microseconds
+
+char*
+get_pci_description(int vendor_id,int device_id)
+
+void
+hid_probe()
+ PPCODE:
+ struct hid_entries entries = hid_probe();
+ int i;
+
+ EXTEND(SP, entries.nb);
+ for (i = 0; i < entries.nb; i++) {
+ struct hid_entry *e = &entries.entries[i];
+ HV *rh = (HV *)sv_2mortal((SV *)newHV());
+ hv_store(rh, "description", 11, newSVpv(e->text, 0), 0);
+ hv_store(rh, "driver", 6, newSVpv(e->module, 0), 0);
+ PUSHs(newRV((SV *)rh));
+ }
+ hid_entries_free(&entries);
+
void
pci_probe()
PPCODE:
- //proc_pci_path = "/tmp/pci";
struct pciusb_entries entries = pci_probe();
- char buf[2048];
int i;
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%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,
- pci_class2text(e->class_id), e->class, e->module ? e->module : "unknown", e->text);
- PUSHs(sv_2mortal(newSVpv(buf, 0)));
+ HV * rh = common_pciusb_hash_init(e);
+ hv_store(rh, "pci_domain", 10, newSViv(e->pci_domain), 0);
+ hv_store(rh, "pci_function", 12, newSViv(e->pci_function), 0);
+ hv_store(rh, "pci_revision", 12, newSViv(e->pci_revision), 0);
+ hv_store(rh, "is_pciexpress", 13, newSViv(e->is_pciexpress), 0);
+ hv_store(rh, "nice_media_type", 15, newSVpv(e->class, 0), 0);
+ hv_store(rh, "media_type", 10, newSVpv(pci_class2text(e->class_id), 0), 0);
+ PUSHs(newRV((SV *)rh));
}
pciusb_free(&entries);
@@ -280,9 +335,11 @@ 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);
- PUSHs(sv_2mortal(newSVpv(buf, 0)));
+ snprintf(buf, sizeof(buf), "%s|%s|%s", class_text.usb_class_text, class_text.usb_sub_text, class_text.usb_prot_text);
+ HV * rh = common_pciusb_hash_init(e);
+ hv_store(rh, "usb_port", 8, newSViv(e->usb_port), 0);
+ hv_store(rh, "media_type", 10, newSVpv(buf, 0), 0);
+ PUSHs(newRV((SV *)rh));
}
pciusb_free(&entries);
@@ -293,14 +350,14 @@ dmi_probe()
//dmidecode_file = "../../soft/ldetect-lst/test/dmidecode.Laptop.Sony-Vaio-GRX316MP";
struct dmi_entries entries = dmi_probe();
- char buf[2048];
int i;
EXTEND(SP, entries.nb);
for (i = 0; i < entries.nb; i++) {
- snprintf(buf, sizeof(buf), "%s\t%s",
- entries.entries[i].module, entries.entries[i].constraints);
- PUSHs(sv_2mortal(newSVpv(buf, 0)));
+ HV * rh = (HV *)sv_2mortal((SV *)newHV());
+ hv_store(rh, "driver", 6, newSVpv(entries.entries[i].module, 0), 0);
+ hv_store(rh, "description", 11, newSVpv(entries.entries[i].constraints, 0), 0);
+ PUSHs(newRV((SV *)rh));
}
dmi_entries_free(entries);
@@ -322,6 +379,9 @@ get_usb_ups_name(int fd)
int
+res_init()
+
+int
isNetDeviceWirelessAware(device)
char * device
CODE:
@@ -481,7 +541,41 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
}
}
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x) ((x)%BITS_PER_LONG)
+#define BIT(x) (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
+void
+EVIocGBitKey (char *file)
+ PPCODE:
+ int fd;
+ int i;
+ long bitmask[NBITS(KEY_MAX)];
+
+ fd = open (file, O_RDONLY);
+ if (fd < 0) {
+ warn("Cannot open %s: %s\n", file, strerror(errno));
+ return;
+ }
+
+ if (ioctl (fd, EVIOCGBIT(EV_KEY, sizeof (bitmask)), bitmask) < 0) {
+ perror ("ioctl EVIOCGBIT failed");
+ close (fd);
+ return;
+ }
+
+ close (fd);
+ for (i = NBITS(KEY_MAX) - 1; i > 0; i--)
+ if (bitmask[i])
+ break;
+
+ for (; i >= 0; i--) {
+ EXTEND(sp, 1);
+ PUSHs(sv_2mortal(newSViv(bitmask[i])));
+ }
char *
kernel_version()
@@ -505,15 +599,230 @@ get_iso_volume_ids(int fd)
lseek(fd, 16 * ISOFS_BLOCK_SIZE, SEEK_SET);
if (read(fd, &voldesc, sizeof(struct iso_primary_descriptor)) == sizeof(struct iso_primary_descriptor)) {
if (voldesc.type[0] == ISO_VD_PRIMARY && !strncmp(voldesc.id, ISO_STANDARD_ID, sizeof(voldesc.id))) {
- XPUSHs(sv_2mortal(newSVpv(voldesc.volume_id, length_of_space_padded(voldesc.volume_id, sizeof(voldesc.volume_id)))));
- XPUSHs(sv_2mortal(newSVpv(voldesc.application_id, length_of_space_padded(voldesc.application_id, sizeof(voldesc.application_id)))));
+ size_t vol_id_len = length_of_space_padded(voldesc.volume_id, sizeof(voldesc.volume_id));
+ size_t app_id_len = length_of_space_padded(voldesc.application_id, sizeof(voldesc.application_id));
+ XPUSHs(vol_id_len != -1 ? sv_2mortal(newSVpv(voldesc.volume_id, vol_id_len)) : newSVpvs(""));
+ XPUSHs(app_id_len != -1 ? sv_2mortal(newSVpv(voldesc.application_id, app_id_len)) : newSVpvs(""));
}
}
';
+print '
+
+TYPEMAP: <<HERE
+PedDisk* T_PTROBJ
+HERE
+
+
+
+int
+set_partition_flag(PedDisk *disk, int part_number, char * type)
+ CODE:
+ RETVAL = 0;
+ PedPartition* part = ped_disk_get_partition(disk, part_number);
+ if (!part) {
+ printf("set_partition_flag: failed to find partition\n");
+ } else {
+ PedPartitionFlag flag = string_to_pedpartflag(type);
+ if (flag) {
+ RETVAL = ped_partition_set_flag(part, flag, 1);
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+
+const char *
+get_disk_type(char * device_path)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL = NULL;
+ if(dev) {
+ PedDiskType* type = ped_disk_probe(dev);
+ if(type) {
+ RETVAL = type->name;
+ }
+ }
+ 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, *first_part = NULL;
+ int count = 1;
+ if(!disk)
+ return;
+ 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 *path = ped_partition_get_path(part);
+ char *flag = "";
+ if (ped_partition_get_flag(part, PED_PARTITION_ESP)) {
+ flag = "ESP";
+ } else if (ped_partition_get_flag(part, PED_PARTITION_BIOS_GRUB)) {
+ flag = "BIOS_GRUB";
+ } else if (ped_partition_get_flag(part, PED_PARTITION_LVM)) {
+ flag = "LVM";
+ } else if (ped_partition_get_flag(part, PED_PARTITION_RAID)) {
+ flag = "RAID";
+ } else if (is_recovery_partition(part)) {
+ flag = "RECOVERY";
+ }
+ 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);
+ hv_store(rh, "flag", 4, newSVpv(flag, 0), 0);
+ free(path);
+ if(part->fs_type)
+ 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);
+ }
+
+PedDisk*
+disk_open(char * device_path, const char * type_name = NULL)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL = NULL;
+ if(dev) {
+ if(type_name) {
+ PedDiskType* type = ped_disk_type_get(type_name);
+ if(type) {
+ RETVAL = ped_disk_new_fresh(dev, type);
+ }
+ } else {
+ RETVAL = ped_disk_new(dev);
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+int
+disk_delete_all(PedDisk* disk)
+ CODE:
+ RETVAL = 0;
+ if (ped_disk_delete_all(disk)) {
+ RETVAL = 1;
+ }
+ OUTPUT:
+ RETVAL
+
+int
+disk_del_partition(PedDisk* disk, int part_number)
+ CODE:
+ RETVAL = 0;
+ 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);
+ }
+ OUTPUT:
+ RETVAL
+
+int
+disk_add_partition(PedDisk* disk, double start, double length, const char * fs_type)
+ CODE:
+ RETVAL=0;
+ PedGeometry* geom = ped_geometry_new(disk->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);
+ }
+ ped_geometry_destroy(geom);
+ ped_constraint_destroy(constraint);
+ OUTPUT:
+ RETVAL
+
+int
+disk_commit(PedDisk *disk)
+ CODE:
+ RETVAL = 0;
+ /* As done in ped_disk_commit(), open the device here, so that the underlying
+ file descriptor is not closed between the call to ped_disk_commit_to_dev()
+ and the call to ped_disk_commit_to_os(). This avoids unwanted udev events. */
+ if (ped_device_open(disk->dev)) {
+ if (ped_disk_commit_to_dev(disk)) {
+ RETVAL = 1;
+ if (ped_disk_commit_to_os(disk)) {
+ RETVAL = 2;
+ }
+ }
+ ped_device_close(disk->dev);
+ }
+ ped_disk_destroy(disk);
+ OUTPUT:
+ RETVAL
+
+int
+tell_kernel_to_reread_partition_table(char * device_path)
+ CODE:
+ PedDevice *dev = ped_device_get(device_path);
+ RETVAL=0;
+ if(dev) {
+ PedDisk* disk = ped_disk_new(dev);
+ if (disk) {
+ if (ped_disk_commit_to_os (disk))
+ RETVAL=1;
+ ped_disk_destroy(disk);
+ }
+ }
+ OUTPUT:
+ RETVAL
+
+#define BACKTRACE_DEPTH 20
+
+
+char*
+C_backtrace()
+ CODE:
+ static char buf[1024];
+ int nAddresses, i;
+ unsigned long idx = 0;
+ void * addresses[BACKTRACE_DEPTH];
+ char ** symbols = NULL;
+ nAddresses = backtrace(addresses, BACKTRACE_DEPTH);
+ symbols = backtrace_symbols(addresses, nAddresses);
+ if (symbols == NULL) {
+ idx += sprintf(buf+idx, "ERROR: Retrieving symbols failed.\n");
+ } else {
+ /* dump stack trace */
+ for (i = 0; i < nAddresses; ++i)
+ idx += sprintf(buf+idx, "%d: %s\n", i, symbols[i]);
+ }
+ RETVAL = strdup(buf);
+ 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
@@ -546,4 +855,3 @@ print '
PROTOTYPES: DISABLE
';
-