diff options
Diffstat (limited to 'perl-install/c')
| -rw-r--r-- | perl-install/c/.cvsignore | 9 | ||||
| -rw-r--r-- | perl-install/c/Makefile | 9 | ||||
| -rwxr-xr-x[-rw-r--r--] | perl-install/c/Makefile.PL | 13 | ||||
| -rw-r--r-- | perl-install/c/README | 3 | ||||
| -rw-r--r-- | perl-install/c/sbus.c | 156 | ||||
| -rw-r--r-- | perl-install/c/silo.c | 817 | ||||
| -rw-r--r-- | perl-install/c/smp-dmi.c | 213 | ||||
| -rw-r--r-- | perl-install/c/smp-test.c | 6 | ||||
| -rw-r--r-- | perl-install/c/smp.c | 511 | ||||
| -rw-r--r-- | perl-install/c/smp.h | 6 | ||||
| -rw-r--r-- | perl-install/c/stuff.pm | 5 | ||||
| -rwxr-xr-x[-rw-r--r--] | perl-install/c/stuff.xs.pl | 667 | 
12 files changed, 393 insertions, 2022 deletions
| diff --git a/perl-install/c/.cvsignore b/perl-install/c/.cvsignore deleted file mode 100644 index 665b57e54..000000000 --- a/perl-install/c/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -Makefile -Makefile_c -stuff.c -stuff.bs -pm_to_blib -Makefile_c.old -blib -stuff.xs -pcmcia_probe.c diff --git a/perl-install/c/Makefile b/perl-install/c/Makefile index eba1a3cb0..0d09a8919 100644 --- a/perl-install/c/Makefile +++ b/perl-install/c/Makefile @@ -1,12 +1,9 @@  .PHONY: clean -C_RPM = 1 -C_DRAKX = 1 -MYENV = C_RPM=$(C_RPM) C_DRAKX=$(C_DRAKX) -MAKEIT = $(MYENV) $(MAKE) -f Makefile_c LD_RUN_PATH= +MAKEIT = $(MAKE) -f Makefile_c LD_RUN_PATH=  stuff: %: %.xs -	test -e Makefile_c || $(MYENV) perl Makefile.PL +	test -e Makefile_c || perl Makefile.PL  	$(MAKEIT) || $(MAKEIT)  	rm -f ../auto/c ; ln -s ../c/blib/arch/auto ../auto/c @@ -16,5 +13,5 @@ clean:  stuff.xs: %: %.pl  	rm -f $@ -	C_RPM=$(C_RPM) C_DRAKX=$(C_DRAKX) perl $< > $@ +	perl $< > $@  	chmod a-w $@ diff --git a/perl-install/c/Makefile.PL b/perl-install/c/Makefile.PL index 7bf7ce128..f776d27f2 100644..100755 --- a/perl-install/c/Makefile.PL +++ b/perl-install/c/Makefile.PL @@ -6,21 +6,16 @@ use Config;  my $lib = arch() =~ /x86_64/ ? 'lib64' : 'lib'; -my $libs = '-lldetect -lext2fs'; -$libs .= " -L/usr/X11R6/$lib -lX11 -lXext -lXxf86misc" if $ENV{C_DRAKX}; -$libs .= ' -lrpm -lrpmdb -lrpmio -lpopt -lz' if $ENV{C_RPM}; +my $libs = '-lldetect -lparted'; -my $pcmcia_dir = $ENV{C_DRAKX} && $Config{archname} =~ /i.86/ ? '../../mdk-stage1/pcmcia_' : ''; - -symlink "$pcmcia_dir/probe.c", "probe.c" if $pcmcia_dir; +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 smp.o sbus.o silo.o smp-dmi.o" . ($pcmcia_dir && " probe.o"), +    'OBJECT'    => "stuff.o " . (-e $pcmcia_probe_o && " $pcmcia_probe_o"),      'VERSION_FROM' => 'stuff.pm', # finds $VERSION      'LIBS'	=> [$libs],   # e.g., '-lm'       'DEFINE'	=> '',     # e.g., '-DHAVE_SOMETHING'  -    'INC'	=> "-I/usr/include/rpm " . ($pcmcia_dir && " -I$pcmcia_dir -I$pcmcia_dir/.."),   ); diff --git a/perl-install/c/README b/perl-install/c/README deleted file mode 100644 index b5ad1224f..000000000 --- a/perl-install/c/README +++ /dev/null @@ -1,3 +0,0 @@ -md5.c, md5_crypt.c and md5.h are taken from pam (dir modules/pam_pwdb) - -smp.c is taken from RedHat's install diff --git a/perl-install/c/sbus.c b/perl-install/c/sbus.c deleted file mode 100644 index 85d44fa79..000000000 --- a/perl-install/c/sbus.c +++ /dev/null @@ -1,156 +0,0 @@ -/* This file is inspired from source code of kudzu from Red Hat, Inc. - * It has been modified to keep only "what is needed" in C, the prom_walk - * has been rewritten in perl for convenience :-) - * - * Copyright notice from original version. - * sbus.c: Probe for Sun SBUS and UPA framebuffers using OpenPROM, - *         SBUS SCSI and Ethernet cards and SBUS or EBUS audio chips. - * - * Copyright (C) 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz) - *           (C) 1999 Red Hat, Inc. - *  - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - */ - -#ifdef __sparc__ - -#include <fcntl.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <sys/ioctl.h> -#include <asm/openpromio.h> - -static char *promdev = "/dev/openprom"; -static int promfd = -1; -static int prom_current_node; -#define MAX_PROP        128 -#define MAX_VAL         (4096-128-4) -static char buf[4096]; -#define DECL_OP(size) struct openpromio *op = (struct openpromio *)buf; op->oprom_size = (size) - -int prom_open() -{ -    int prom_root_node; - -    if (promfd == -1) { -        promfd = open(promdev, O_RDONLY); -	if (promfd == -1) -	    return 0; -    } -    prom_root_node = prom_getsibling(0); -    if (!prom_root_node) { -        close(promfd); -	promfd = -1; -	return 0; -    } -    return prom_root_node; -} - -void prom_close() -{ -    if (promfd != -1) { -        close(promfd); -	promfd = -1; -    } -} - -int prom_getsibling(int node) -{ -    DECL_OP(sizeof(int)); -         -    if (node == -1) return 0; -    *(int *)op->oprom_array = node; -    if (ioctl (promfd, OPROMNEXT, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -int prom_getchild(int node) -{ -    DECL_OP(sizeof(int)); -         -    if (!node || node == -1) return 0; -    *(int *)op->oprom_array = node; -    if (ioctl (promfd, OPROMCHILD, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -char *prom_getopt(char *var, int *lenp) -{ -    DECL_OP(MAX_VAL); -         -    strcpy (op->oprom_array, var); -    if (ioctl (promfd, OPROMGETOPT, op) < 0) -        return 0; -    if (lenp) *lenp = op->oprom_size; -    return op->oprom_array; -} - -void prom_setopt(char *var, char *value) { -    DECL_OP(MAX_VAL); - -    strcpy (op->oprom_array, var); -    strcpy (op->oprom_array + strlen (var) + 1, value); -    ioctl (promfd, OPROMSETOPT, op); -} - -char *prom_getproperty(char *prop, int *lenp) -{ -    DECL_OP(MAX_VAL); -         -    strcpy (op->oprom_array, prop); -    if (ioctl (promfd, OPROMGETPROP, op) < 0) -        return 0; -    if (lenp) *lenp = op->oprom_size; -    return op->oprom_array; -} - -int prom_getbool(char *prop) -{ -    DECL_OP(0); - -    *(int *)op->oprom_array = 0; -    for (;;) { -        op->oprom_size = MAX_PROP; -	if (ioctl(promfd, OPROMNXTPROP, op) < 0) -	    return 0; -	if (!op->oprom_size) -	    return 0; -	if (!strcmp (op->oprom_array, prop)) -	    return 1; -    } -} - -int prom_pci2node(int bus, int devfn) { -    DECL_OP(2*sizeof(int)); -     -    ((int *)op->oprom_array)[0] = bus; -    ((int *)op->oprom_array)[1] = devfn; -    if (ioctl (promfd, OPROMPCI2NODE, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -#else -int prom_open() { return 0; } -void prom_close() {} -int prom_getsibling(int node) { return 0; } -int prom_getchild(int node) { return 0; } -char *prom_getopt(char *var, int *lenp) { return 0; /* NULL */ } -void prom_setopt(char *var, char *value) {} -char *prom_getproperty(char *prop, int *lenp) { return 0; /* NULL */ } -int prom_getbool(char *prop) { return 0; } -int prom_pci2node(int bus, int devfn) { return 0; } -#endif /* __sparc__ */ diff --git a/perl-install/c/silo.c b/perl-install/c/silo.c deleted file mode 100644 index 2fd621f4e..000000000 --- a/perl-install/c/silo.c +++ /dev/null @@ -1,817 +0,0 @@ -/* silo.c: Conversions between SCSI and IDE disk names - *	   and OpenPROM fully qualified paths. - * - * Modified for DrakX light integration. - * Copyright (C) 1999, 2000 Jakub Jelinek <jakub@redhat.com> - *  - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifdef __sparc__ - -#define _GNU_SOURCE -#include <fcntl.h> -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <sys/ioctl.h> -#include <asm/openpromio.h> -#include <ctype.h> -#include <dirent.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/utsname.h> - -#ifndef OPROMSETCUR -#define OPROMSETCUR	0x20004FF0 -#define OPROMPCI2NODE	0x20004FF1 -#define OPROMPATH2NODE	0x20004FF2 -#endif - -static int hasaliases; -static char *promdev = "/dev/openprom"; -static int promfd; -static char sd_targets[10] = "31204567"; -static int p1275 = 0; -static int prom_root_node, prom_current_node; -static int promvers; -static void (*prom_walk_callback)(int node); -static char prom_path[1024]; -#define MAX_PROP	128 -#define MAX_VAL		(4096-128-4) -static char buf[4096]; -static char regstr[40]; -#define DECL_OP(size) struct openpromio *op = (struct openpromio *)buf; op->oprom_size = (size) - -static int -prom_setcur(int node) { -    DECL_OP(sizeof(int)); -     -    if (node == -1) return 0; -    *(int *)op->oprom_array = node; -    if (ioctl (promfd, OPROMSETCUR, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -static int -prom_getsibling(int node) { -    DECL_OP(sizeof(int)); -     -    if (node == -1) return 0; -    *(int *)op->oprom_array = node; -    if (ioctl (promfd, OPROMNEXT, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -static int -prom_getchild(int node) { -    DECL_OP(sizeof(int)); -     -    if (!node || node == -1) return 0; -    *(int *)op->oprom_array = node; -    if (ioctl (promfd, OPROMCHILD, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -static char * -prom_getproperty(char *prop, int *lenp) { -    DECL_OP(MAX_VAL); -     -    strcpy (op->oprom_array, prop); -    if (ioctl (promfd, OPROMGETPROP, op) < 0) -        return 0; -    if (lenp) *lenp = op->oprom_size; -    return op->oprom_array; -} - -static char * -prom_getopt(char *var, int *lenp) { -    DECL_OP(MAX_VAL); - -    strcpy (op->oprom_array, var); -    if (ioctl (promfd, OPROMGETOPT, op) < 0) -        return 0; -    if (lenp) *lenp = op->oprom_size; -    return op->oprom_array; -} - -static void -prom_setopt(char *var, char *value) { -    DECL_OP(MAX_VAL); - -    strcpy (op->oprom_array, var); -    strcpy (op->oprom_array + strlen (var) + 1, value); -    ioctl (promfd, OPROMSETOPT, op); -} - -static int -prom_getbool(char *prop) { -    DECL_OP(0); - -    *(int *)op->oprom_array = 0; -    for (;;) { -        op->oprom_size = MAX_PROP; -            if (ioctl(promfd, OPROMNXTPROP, op) < 0) -                return 0; -            if (!op->oprom_size) -                return 0; -            if (!strcmp (op->oprom_array, prop)) -                return 1; -    } -} - -static int -prom_pci2node(int bus, int devfn) { -    DECL_OP(2*sizeof(int)); -     -    ((int *)op->oprom_array)[0] = bus; -    ((int *)op->oprom_array)[1] = devfn; -    if (ioctl (promfd, OPROMPCI2NODE, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -static int -prom_path2node(char *path) { -    DECL_OP(MAX_VAL); -     -    strcpy (op->oprom_array, path); -    if (ioctl (promfd, OPROMPATH2NODE, op) < 0) -        return 0; -    prom_current_node = *(int *)op->oprom_array; -    return *(int *)op->oprom_array; -} - -#define PW_TYPE_SBUS	1 -#define PW_TYPE_PCI	2 -#define PW_TYPE_EBUS	3 - -static void -prom_walk(char *path, int parent, int node, int type) { -    int nextnode; -    int len, ntype = type; -    char *prop; -     -    prop = prom_getproperty("name", &len); -    if (prop && len > 0) { -        if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) -            ntype = PW_TYPE_SBUS; -        else if (!strcmp(prop, "ebus") && type == PW_TYPE_PCI) -            ntype = PW_TYPE_EBUS; -        else if (!strcmp(prop, "pci") && !type) -            ntype = PW_TYPE_PCI; -    } -    *path = '/'; -    strcpy (path + 1, prop); -    prop = prom_getproperty("reg", &len); -    if (prop && len >= 4) { -        unsigned int *reg = (unsigned int *)prop; -        int cnt = 0; -        if (!p1275 || (type == PW_TYPE_SBUS)) -	    sprintf (regstr, "@%x,%x", reg[0], reg[1]); -        else if (type == PW_TYPE_PCI) { -	    if ((reg[0] >> 8) & 7) -		sprintf (regstr, "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); -	    else -		sprintf (regstr, "@%x", (reg[0] >> 11) & 0x1f); -        } else if (len == 4) -	    sprintf (regstr, "@%x", reg[0]); -        else { -	    unsigned int regs[2]; - -	    /* Things get more complicated on UPA. If upa-portid exists, -	       then address is @upa-portid,second-int-in-reg, otherwise -	       it is @first-int-in-reg/16,second-int-in-reg (well, probably -	       upa-portid always exists, but just to be safe). */ -	    memcpy (regs, reg, sizeof(regs)); -	    prop = prom_getproperty("upa-portid", &len); -	    if (prop && len == 4) { -		reg = (unsigned int *)prop; -		sprintf (regstr, "@%x,%x", reg[0], regs[1]);  -	    } else -	        sprintf (regstr, "@%x,%x", regs[0] >> 4, regs[1]); -	} -        for (nextnode = prom_getchild(parent); nextnode; nextnode = prom_getsibling(nextnode)) { -	    prop = prom_getproperty("name", &len); -	    if (prop && len > 0 && !strcmp (path + 1, prop)) -		cnt++; -	} -        if (cnt > 1) -	    strcat (path, regstr); -    } - -    prom_walk_callback(node); - -    nextnode = prom_getchild(node); -    if (nextnode) -        prom_walk(strchr (path, 0), node, nextnode, ntype); -    nextnode = prom_getsibling(node); -    if (nextnode) -        prom_walk(path, parent, nextnode, type); -} - -static int -prom_init(int mode) {     -    struct utsname u; - -    promfd = open(promdev, mode); -    if (promfd == -1) -	return -1; -    prom_root_node = prom_getsibling(0); -    if (!prom_root_node) -	return -1; - -    if (!uname (&u) && !strcmp (u.machine, "sparc64")) -	p1275 = 1; -    return 0; -} - -#define SDSK_TYPE_IDE	1 -#define SDSK_TYPE_SD	2 -#define SDSK_TYPE_PLN	3 -#define SDSK_TYPE_FC	4 - -static struct sdsk_disk { -    unsigned int prom_node; -    unsigned int type, host, hi, mid, lo; -    unsigned char *prom_name; -} *hd = NULL, *sd = NULL; -static int hdlen, sdlen; - -static void -scan_walk_callback(int node) { -    int nextnode; -    char *prop; -    int len, disk; -    static int v0ctrl = 0; - -    for (disk = 0; disk < hdlen + sdlen; disk++) { -	if (hd[disk].prom_node == node) { -	    switch (hd[disk].type) { -	    case SDSK_TYPE_IDE: -		for (nextnode = prom_getchild(node); nextnode; nextnode = prom_getsibling(nextnode)) { -		    prop = prom_getproperty("name", &len); -		    if (prop && len > 0 && (!strcmp (prop, "ata") || !strcmp (prop, "disk"))) -			break; -		} -		if (!nextnode) -		    continue; -		if (prop[0] == 'a') -		    sprintf (prop, "/ata@%x,0/cmdk@%x,0", hd[disk].hi, hd[disk].lo); -		else -		    sprintf (prop, "/disk@%x,0", hd[disk].hi * 2 + hd[disk].lo); -		break; -	    case SDSK_TYPE_SD: -		for (nextnode = prom_getchild(node); nextnode; nextnode = prom_getsibling(nextnode)) { -		    prop = prom_getproperty("compatible", &len); -		    if (prop && len > 0 && !strcmp (prop, "sd")) -			break; -		    prop = prom_getproperty("name", &len); -		    if (prop && len > 0 && (!strcmp (prop, "sd") || !strcmp (prop, "disk"))) -			break; -		} -		if (!nextnode || hd[disk].hi) -		    continue; -		if (promvers) { -		    char name[1024]; -		    prop = prom_getproperty("name", &len); -		    if (prop && len > 0) -			strcpy (name, prop); -		    else -			strcpy (name, "sd"); -		    if (!prop) -			prop = ((struct openpromio *)buf)->oprom_array; -		    sprintf (prop, "/%s@%x,%x", name, hd[disk].mid, hd[disk].lo); -		} else { -		    int i; -		    for (i = 0; sd_targets[i]; i++) -			if (sd_targets[i] == '0' + hd[disk].mid) -			    break; -		    if (!sd_targets[i]) -			i = hd[disk].mid; -		    sprintf (prop, "sd(%d,%d,", v0ctrl, i); -		} -		break; -	    case SDSK_TYPE_PLN: -		prop = ((struct openpromio *)buf)->oprom_array; -		sprintf (prop, "/SUNW,pln@%x,%x/SUNW,ssd@%x,%x", -			 hd[disk].lo & 0xf0000000, hd[disk].lo & 0xffffff, -			 hd[disk].hi, hd[disk].mid); -		break; -	    case SDSK_TYPE_FC: -		prop = ((struct openpromio *)buf)->oprom_array; -		sprintf (prop, "/sf@0,0/ssd@w%08x%08x,%x", hd[disk].hi, hd[disk].mid, hd[disk].lo); -		break; -	    default: -		continue; -	    } -	    hd[disk].prom_name = malloc (strlen (prom_path) + strlen(prop) + 3); -	    if (!hd[disk].prom_name) -		continue; -	    if (promvers) -		strcpy (hd[disk].prom_name, prom_path); -	    else -		hd[disk].prom_name[0] = '\0'; -	    strcat (hd[disk].prom_name, prop); -	} -    } -    v0ctrl++; -} - -static int -scan_ide(void) { -    DIR * dir; -    char path[80]; -    char buffer[512]; -    int fd, i, disk; -    struct dirent * ent; -    int pci_bus, pci_devfn; - -    if (access("/proc/ide", R_OK)) return 0; - -    if (!(dir = opendir("/proc/ide"))) { -	return 1; -    } - -    while ((ent = readdir(dir))) { -	if (ent->d_name[0] == 'h' && ent->d_name[1] == 'd' && -	    ent->d_name[2] >= 'a' && ent->d_name[2] <= 'z' && -	    ent->d_name[3] == '\0') { -	    disk = ent->d_name[2] - 'a'; -	    if (disk >= hdlen) { -		hd = (struct sdsk_disk *)realloc(hd, ((disk&~3)+4)*sizeof(struct sdsk_disk)); -		memset (hd + hdlen, 0, ((disk&~3)+4-hdlen)*sizeof(struct sdsk_disk)); -		hdlen = (disk&~3)+4; -	    } -	    for (i = (disk & ~3); i <= (disk | 3); i++) { -		if (hd[i].type) -		    break; -	    } -	    if (i > (disk | 3)) { -		sprintf(path, "/proc/ide/%s", ent->d_name); -		if (readlink(path, buffer, 512) < 5) -		    continue; -		if (strncmp(buffer, "ide", 3) || -		    !isdigit(buffer[3]) || -		    buffer[4] != '/') -		    continue; -		buffer[4] = 0; -		sprintf(path, "/proc/ide/%s/config", buffer); -		if ((fd = open(path, O_RDONLY)) < 0) -		    continue; -		i = read(fd, buffer, 50); -		close(fd); -		if (i < 50) continue; -		if (sscanf (buffer, "pci bus %x device %x ", -			    &pci_bus, &pci_devfn) != 2) -			continue; -		hd[disk].prom_node = prom_pci2node (pci_bus, pci_devfn); -	    } else -	    	hd[disk].prom_node = hd[i].prom_node; -	    hd[disk].type = SDSK_TYPE_IDE; -	    hd[disk].hi = (disk & 2) >> 1; -	    hd[disk].lo = (disk & 1); -	} -    } - -    closedir(dir); - -    return 0; -} - -static int -scan_scsi(void) { -    FILE *f; -    DIR * dir, *dirhba; -    struct dirent * ent, *enthba; -    struct stat st; -    char * p, * q; -    char buf[512]; -    char path[128]; -    int disk = 0; -    int host, channel, id, lun; -    int prom_node, pci_bus, pci_devfn; - -    if (access("/proc/scsi/scsi", R_OK)) { -	return 0; -    } - -    f = fopen("/proc/scsi/scsi", "r"); -    if (f == NULL) return 1; - -    if (fgets(buf, sizeof(buf), f) == NULL) { -	fclose(f); -	return 1; -    } -    if (!strcmp(buf, "Attached devices: none\n")) { -	fclose(f); -	return 0; -    } - -    while (fgets(buf, sizeof(buf), f) != NULL) { -	if (sscanf(buf, "Host: scsi%d Channel: %d Id: %d Lun: %d\n", -		   &host, &channel, &id, &lun) != 4) -	    break; -	if (fgets(buf, sizeof(buf), f) == NULL) -	    break; -	if (strncmp(buf, "  Vendor:", 9)) -	    break; -	if (fgets(buf, sizeof(buf), f) == NULL) -	    break; -	if (strncmp(buf, "  Type:   ", 10)) -	    break; -	if (!strncmp(buf+10, "Direct-Access", 13)) { -	    if (disk >= sdlen) { -		hd = (struct sdsk_disk *) -		     realloc(hd, (hdlen+(disk&~3)+4)*sizeof(struct sdsk_disk)); -		sd = hd + hdlen; -		memset (sd + sdlen, 0, -			((disk&~3)+4-sdlen)*sizeof(struct sdsk_disk)); -		sdlen = (disk&~3)+4; -	    } -	    sd[disk].type = SDSK_TYPE_SD; -	    sd[disk].host = host; -	    sd[disk].hi = channel; -	    sd[disk].mid = id; -	    sd[disk].lo = lun; -	    disk++; -	} -    } -    fclose (f); - -    if (!(dir = opendir("/proc/scsi"))) { -	if (!hdlen && hd) { -	    free(hd); -	    hd = NULL; -	} -	sd = NULL; -	sdlen = 0; -	return 1; -    } - -    while ((ent = readdir(dir))) { -	if (!strcmp (ent->d_name, "scsi") || ent->d_name[0] == '.') -	    continue; -	sprintf (path, "/proc/scsi/%s", ent->d_name); -	if (stat (path, &st) < 0 || !S_ISDIR (st.st_mode)) -	    continue; -	if (!(dirhba = opendir(path))) -	    continue; - -	while ((enthba = readdir(dirhba))) { -	    if (enthba->d_name[0] == '.') -		continue; -	    host = atoi(enthba->d_name); -	    sprintf (path, "/proc/scsi/%s/%s", ent->d_name, enthba->d_name); -	    f = fopen (path, "r"); -	    if (f == NULL) continue; - -	    if (!strcmp (ent->d_name, "esp") || -		!strcmp (ent->d_name, "qlogicpti") || -		!strcmp (ent->d_name, "fcal")) -		p = "PROM node"; -	    else if (!strcmp (ent->d_name, "pluto")) -		p = "serial "; -	    else -		p = "PCI bus"; -	    while (fgets (buf, sizeof(buf), f) != NULL) { -		q = strstr (buf, p); -		if (q == NULL) continue; -		prom_node = 0; -		switch (p[1]) { -		case 'R': -		    if (sscanf (q, "PROM node %x", &prom_node) == 1) -			q = NULL; -		    break; -		case 'e': -		    if (sscanf (q, "serial 000000%x %*dx%*d on soc%*d port %x PROM node %x", -				&id, &lun, &prom_node) == 3 && -			lun >= 10 && lun <= 11) { -			q = NULL; -		    } -		    break; -		case 'C': -		    if (sscanf (q, "PCI bus %x device %x", &pci_bus, &pci_devfn) == 2) { -			q = NULL; -			prom_node = prom_pci2node (pci_bus, pci_devfn); -		    } -		    break; -		} -		if (q == NULL) { -		    for (disk = 0; disk < sdlen; disk++) -			if (sd[disk].host == host && sd[disk].type) { -			    sd[disk].prom_node = prom_node; -			    if (p[1] == 'e') { -				sd[disk].type = SDSK_TYPE_PLN; -				sd[disk].lo = (lun << 28) | id; -			    } else if (!strcmp (ent->d_name, "fcal")) -				sd[disk].type = SDSK_TYPE_FC; -			} -		} -	    } -	    if (!strcmp (ent->d_name, "fcal")) { -		while (fgets (buf, sizeof(buf), f) != NULL) { -		    unsigned long long ll; -		    if (sscanf (buf, " [AL-PA: %*x, Id: %d, Port WWN: %Lx, Node WWN: ", &id, &ll) == 2) { -			for (disk = 0; disk < sdlen; disk++) -			if (sd[disk].host == host && sd[disk].mid == id) { -			    sd[disk].hi = ll >> 32; -			    sd[disk].mid = ll; -			} -		    } -		} -	    } -	    fclose(f); -	} -	closedir(dirhba); -    } -    closedir(dir); -    return 0; -} - -static int get_prom_ver(void) -{ -    FILE *f = fopen ("/proc/cpuinfo","r"); -    int ver = 0; -    char buffer[1024]; -    char *p; -                     -    if (f) { -	while (fgets (buffer, 1024, f)) { -	    if (!strncmp (buffer, "promlib", 7)) { -		p = strstr (buffer, "Version "); -		if (p) { -		    p += 8; -		    if (*p == '0' || (*p >= '2' && *p <= '3')) { -			ver = *p - '0'; -		    } -		} -		break; -	    } -	} -	fclose(f); -    } -    if (!ver) { -	int len; -        p = prom_getopt("sd-targets", &len); -        if (p && len > 0 && len <= 8) -	    strcpy(sd_targets, p); -    } -    return ver; -} - -static void check_aliases(void) { -    int nextnode, len; -    char *prop; -    hasaliases = 0; -    for (nextnode = prom_getchild(prom_root_node); nextnode; nextnode = prom_getsibling(nextnode)) { -	prop = prom_getproperty("name", &len); -	if (prop && len > 0 && !strcmp (prop, "aliases")) -	    hasaliases = 1; -    } -} - -char *prom_root_name = NULL; - -static void get_root_name(void) { -    int len; -    char *prop; -     -    prom_getsibling(0); -    prop = prom_getproperty("name", &len); -    if (prop && len > 0) -	prom_root_name = strdup(prop); -} - -int init_sbusdisk(void) { -    if (prom_init(O_RDONLY)) -	return -1; -    promvers = get_prom_ver(); -    check_aliases(); -    get_root_name(); -    scan_ide(); -    scan_scsi(); -    prom_walk_callback = scan_walk_callback; -    prom_walk(prom_path, prom_root_node, prom_getchild (prom_root_node), 0); -    close(promfd); -    return 0; -} - -void set_prom_vars(char *linuxAlias, char *bootDevice) { -    int len; -    int aliasDone = 0; -    if (prom_init(O_RDWR)) -	return; -    if (linuxAlias && hasaliases) { -	char *use_nvramrc; -	char nvramrc[2048]; -	char *p, *q, *r, *s; -	int enabled = -1; -	int count; - -	use_nvramrc = prom_getopt ("use-nvramrc?", &len); -	if (len > 0) { -	    if (!strcasecmp (use_nvramrc, "false")) -		enabled = 0; -	    else if (!strcasecmp (use_nvramrc, "true")) -		enabled = 1; -	} -	if (enabled != -1) { -	    p = prom_getopt ("nvramrc", &len); -	    if (p) { -		memcpy (nvramrc, p, len); -		nvramrc [len] = 0; -		q = nvramrc; -		for (;;) { -		    /* If there is already `devalias linux /some/ugly/prom/path' -		       make sure we fully understand that and remove it. */ -		    if (!strncmp (q, "devalias", 8) && (q[8] == ' ' || q[8] == '\t')) { -			for (r = q + 9; *r == ' ' || *r == '\t'; r++); -			if (!strncmp (r, "linux", 5)) { -			    for (s = r + 5; *s && *s != ' ' && *s != '\t'; s++); -			    if (!*s) break; -			    if (s == r + 5 || -				(r[5] == '#' && r[6] >= '0' && r[6] <= '9' && -				 (s == r + 7 || -				  (r[7] >= '0' && r[7] <= '9' && s == r + 8)))) { -				for (r = s + 1; *r == ' ' || *r == '\t'; r++); -				for (; *r && *r != ' ' && *r != '\t' && *r != '\n'; r++); -				for (; *r == ' ' || *r == '\t'; r++); -				if (*r == '\n') { -				    r++; -				    memmove (q, r, strlen(r) + 1); -				    continue; -				} -			    } -			} -		    } -		    q = strchr (q, '\n'); -		    if (!q) break; -		    q++; -		} -		len = strlen (nvramrc); -		if (len && nvramrc [len-1] != '\n') -		    nvramrc [len++] = '\n'; -		p = nvramrc + len; -		p = stpcpy (p, "devalias linux "); -		r = linuxAlias; -		q = strchr (r, ';'); -		count = 1; -		while (q) { -		    memcpy (p, r, q - r); -		    p += q - r; -		    sprintf (p, "\ndevalias linux#%d ", count++); -		    p = strchr (p, 0); -		    r = q + 1; -		    q = strchr (r, ';'); -		} -		p = stpcpy (p, r); -		*p++ = '\n'; -		*p = 0; -		prom_setopt ("nvramrc", nvramrc); -		if (!enabled) -		    prom_setopt ("use-nvramrc?", "true"); -		aliasDone = 1; -	    } -	} -    } -    if (bootDevice) { -	char *p; -	if (aliasDone) -	    bootDevice = "linux"; -	p = prom_getopt ("boot-device", &len); -	if (p) { -	    prom_setopt ("boot-device", bootDevice); -	    prom_setopt ("boot-file", ""); -	} else { -	    p = prom_getopt ("boot-from", &len); -	    if (p) -		prom_setopt ("boot-from", bootDevice); -	} -    } -    close(promfd); -} - -#ifdef STANDALONE_SILO - -int main(void) { -    int i; - -    init_sbusdisk(); -    set_prom_vars ("/sbus@1f,0/espdma/esp/sd@1,0:c;/sbus@1f,0/espdma/esp/sd@1,0:g;/sbus@1f,0/espdma/esp/sd@1,0:h", "linux"); -    printf ("prom root name `%s'\n", prom_root_name); -    for (i = 0; i < hdlen; i++) { -	if (hd[i].type) -		printf ("hd%c %x %d %d %d\n", i + 'a', hd[i].prom_node, -						    hd[i].hi, hd[i].mid, hd[i].lo); -	if (hd[i].prom_name) printf ("%s\n", hd[i].prom_name); -    } -    for (i = 0; i < sdlen; i++) { -	if (sd[i].type) { -	    if (i < 26) -		printf ("sd%c %x %d %d %d\n", i + 'a', sd[i].prom_node, -						    sd[i].hi, sd[i].mid, sd[i].lo); -	    else -		printf ("sd%c%c %x %d %d %d\n", (i / 26) + 'a' - 1, (i % 26) + 'a', sd[i].prom_node, -						    sd[i].hi, sd[i].mid, sd[i].lo); -	} -	if (sd[i].prom_name) printf ("%s\n", sd[i].prom_name); -    } -    exit(0); -} - -#else - -void -initSilo () -{ -    return init_sbusdisk(); -} - -char * -disk2PromPath (unsigned char *disk) -{ -    static unsigned char prompath[1024]; -    int diskno = -1, part; - -    if (disk[0] == 'h' && disk[1] == 'd' && disk[2] >= 'a' && disk[2] <= 'z') { -	diskno = disk[2] - 'a'; -	disk += 3; -    } else if (disk[0] == 's' && disk[1] == 'd' && disk[2] >= 'a' && disk[2] <= 'z') { -	if (disk[3] >= 'a' && disk[3] <= 'z') { -	    diskno = (disk[2] - 'a' + 1) * 26 + (disk[3] - 'a'); -	    disk += 4; -	} else { -	    diskno = disk[2] - 'a'; -	    disk += 3; -	} -	if (diskno >= 128) -	    diskno = -1; -	else -	    diskno += hdlen; -    } -    if (diskno == -1) -	part = -1; -    else if (!disk[0]) -	part = 3; -    else { -	part = atoi (disk); -	if (part <= 0 || part > 8) part = -1; -    } -    if (diskno < 0 || part == -1 || -	diskno >= hdlen + sdlen || !hd[diskno].prom_name) { -	return NULL; -    } -    if (!promvers) -	sprintf (prompath, "%s%d)", hd[diskno].prom_name, part ? part - 1 : 2); -    else { -	if (part) -	    sprintf (prompath, "%s:%c", hd[diskno].prom_name, part + 'a' - 1); -	else -	    strcpy (prompath, hd[diskno].prom_name); -    } -    return prompath; -} - -int -hasAliases (void) -{ -    return hasaliases; -} - -char * -promRootName (void) -{ -    return prom_root_name ? prom_root_name : ""; -} - -void -setPromVars (char *linuxAlias, char *bootDevice) -{ -    if (linuxAlias && !*linuxAlias) linuxAlias = NULL; -    if (bootDevice && !*bootDevice) bootDevice = NULL; -    set_prom_vars (linuxAlias, bootDevice); -} - -#endif - -#else -void initSilo() {} -char *disk2PromPath(unsigned char *disk) { return 0; /* NULL */ } -int hasAliases(void) { return 0; } -char *promRootName(void) { return 0; /* NULL */ } -void setPromVars(char *linuxAlias, char *bootDevice) {} -#endif /* __sparc__ */ diff --git a/perl-install/c/smp-dmi.c b/perl-install/c/smp-dmi.c deleted file mode 100644 index 672bc2c35..000000000 --- a/perl-install/c/smp-dmi.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - *	CPU detetion based on DMI decode rev 1.2 - * - *	(C) 2003 Nicolas Planel <nplanel@mandrakesoft.com> - *       - *	Licensed under the GNU Public license. If you want to use it in with - *	another license just ask. - */ - -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stdlib.h> - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; - -static void -dump_raw_data(void *data, unsigned int length) -{ -	unsigned char buffer1[80], buffer2[80], *b1, *b2, c; -	unsigned char *p = data; -	unsigned long column=0; -	unsigned int length_printed = 0; -	const unsigned char maxcolumn = 16; -	while (length_printed < length) { -		b1 = buffer1; -		b2 = buffer2; -		for (column = 0; -		     column < maxcolumn && length_printed < length;  -		     column ++) { -			b1 += sprintf(b1, "%02x ",(unsigned int) *p); -			if (*p < 32 || *p > 126) c = '.'; -			else c = *p; -			b2 += sprintf(b2, "%c", c); -			p++; -			length_printed++; -		} -		/* pad out the line */ -		for (; column < maxcolumn; column++) -		{ -			b1 += sprintf(b1, "   "); -			b2 += sprintf(b2, " "); -		} -		 -		printf("%s\t%s\n", buffer1, buffer2); -	} -} - - - -struct dmi_header -{ -	u8	type; -	u8	length; -	u16	handle; -}; - -static char *dmi_string(struct dmi_header *dm, u8 s) -{ -	u8 *bp=(u8 *)dm; -	if (!s) return ""; -	 -	bp+=dm->length; -	while(s>1) -	{ -		bp+=strlen(bp); -		bp++; -		s--; -	} -	return bp; -} - -static char *dmi_processor_type(u8 code) -{ -	static char *processor_type[]={ -		"", -		"Other", -		"Unknown", -		"Central Processor", -		"Math Processor", -		"DSP Processor", -		"Video Processor" -	}; -	 -	if(code == 0xFF) -		return "Other"; -	 -	if (code > 0xA1) -		return ""; -	return processor_type[code]; -} - -static char *dmi_processor_family(u8 code) -{ -	static char *processor_family[]={ -		"", -		"Other", -		"Unknown", -		"8086", -		"80286", -		"Intel386 processor", -		"Intel486 processor", -		"8087", -		"80287", -		"80387", -		"80487", -		"Pentium processor Family", -		"Pentium Pro processor", -		"Pentium II processor", -		"Pentium processor with MMX technology", -		"Celeron processor", -		"Pentium II Xeon processor", -		"Pentium III processor", -		"M1 Family", -		"M1","M1","M1","M1","M1","M1", /* 13h - 18h */ -		"K5 Family", -		"K5","K5","K5","K5","K5","K5", /* 1Ah - 1Fh */ -		"Power PC Family", -		"Power PC 601", -		"Power PC 603", -		"Power PC 603+", -		"Power PC 604", -	}; -	 -	if(code == 0xFF) -		return "Other"; -	 -	if (code > 0x24) -		return ""; -	return processor_family[code]; -} - -static int dmi_table(int fd, u32 base, int len, int num) -{ -	char *buf=malloc(len); -	struct dmi_header *dm; -	u8 *data; -	int i=0; -	int processor=0; -	 -	if(lseek(fd, (long)base, 0)==-1) -	{ -		perror("dmi: lseek"); -		return; -	} -	if(read(fd, buf, len)!=len) -	{ -		perror("dmi: read"); -		return; -	} -	data = buf; -	while(i<num) -	{ -		u32 u; -		u32 u2; -		dm=(struct dmi_header *)data; -		 -		if((dm->type == 4) && /*"Central Processor"*/(data[5] == 3)) { -			if(/*Processor Manufacturer*/data[7] != 0)  -				processor++; -		} - -		data+=dm->length; -		while(*data || data[1]) -			data++; -		data+=2; -		i++; -	} -	free(buf); -	return processor; -} - -int intelDetectSMP(void) { -  	unsigned char buf[20]; -	int fd=open("/dev/mem", O_RDONLY); -	long fp=0xE0000L; -	int processor=0; -	if(fd==-1) -	{ -		perror("/dev/mem"); -		exit(1); -	} -	if(lseek(fd,fp,0)==-1) -	{ -		perror("seek"); -		exit(1); -	} -	 -	 -	fp -= 16; -	 -	while( fp < 0xFFFFF) -	{ -		fp+=16; -		if(read(fd, buf, 16)!=16) -			perror("read"); -		 -		if(memcmp(buf, "_DMI_", 5)==0) -		{ -			u16 num=buf[13]<<8|buf[12]; -			u16 len=buf[7]<<8|buf[6]; -			u32 base=buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; -			 -			processor=dmi_table(fd, base,len, num); -			break; -		} -	} -	close(fd); -	return (processor > 1); -} diff --git a/perl-install/c/smp-test.c b/perl-install/c/smp-test.c deleted file mode 100644 index f644449b8..000000000 --- a/perl-install/c/smp-test.c +++ /dev/null @@ -1,6 +0,0 @@ -main() { -  if (detectSMP()) -    printf("has smp\n"); -  else -    printf("no smp\n"); -} diff --git a/perl-install/c/smp.c b/perl-install/c/smp.c deleted file mode 100644 index 2438418bb..000000000 --- a/perl-install/c/smp.c +++ /dev/null @@ -1,511 +0,0 @@ -/* -[_Anarchy_(alan@lightning.swansea.uk.linux.org)] you should do one check -   though - if the board seems to be SMP and the CPU in /proc/cpuinfo is non -   intel dont install an SMP kernel - thats a dual pentium board with a cyrix -   or similar single cpu in it -*/ - - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/mman.h> -#include <string.h> -#include <errno.h> - -#ifdef __alpha__ -int alphaDetectSMP(void) -{ -    int issmp = 0; -    FILE *f; -     -    f = fopen("/proc/cpuinfo", "r"); -    if (f) {      -	char buff[1024]; -	 -	while (fgets (buff, 1024, f) != NULL) { -	    if (!strncmp (buff, "cpus detected\t\t: ", 17)) { -		if (strtoul (buff + 17, NULL, 0) > 1) -		    issmp = 1; -		break; -	    } -	} -	fclose(f); -    } else -	return -1; -     -    return issmp; -} -#endif /* __alpha__ */ - -#ifdef __sparc__ -int sparcDetectSMP(void) -{ -    int issmp = 0; -    FILE *f; -     -    f = fopen("/proc/cpuinfo", "r"); -    if (f) {      -	char buff[1024]; -	 -	while (fgets (buff, 1024, f) != NULL) { -	    if (!strncmp (buff, "ncpus probed\t: ", 15)) { -		if (strtoul (buff + 15, NULL, 0) > 1) -		    issmp = 1; -		break; -	    } -	} -	fclose(f); -    } else -	return -1; -     -    return issmp; -} -#endif /* __sparc__ */ - -/* just a placeholder for now - don't have an SMP machine -   need something in place to build - s.benedict */ - -#ifdef __powerpc__ -int ppcDetectSMP(void) -{ -    int issmp = 0; -    FILE *f; -     -    f = fopen("/proc/cpuinfo", "r"); -    if (f) {      -        char buff[1024]; -         -        while (fgets (buff, 1024, f) != NULL) { -            if (!strncmp (buff, "ncpus active\t: ", 15)) { -                if (strtoul (buff + 15, NULL, 0) > 1) -                    issmp = 1; -                break; -            } -        } -        fclose(f); -    } else -        return -1; -     -    return issmp; -} -#endif /* __powerpc__ */ - -#if defined(__i386__) || defined(__x86_64__) -/* - * Copyright (c) 1996, by Steve Passe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - *    notice, this list of conditions and the following disclaimer. - * 2. The name of the developer may NOT be used to endorse or promote products - *    derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - *      $Id$ - */ - -/* - * mptable.c - */ - -#define VMAJOR                  2 -#define VMINOR                  0 -#define VDELTA                  12 - -/* - * this will cause the raw mp table to be dumped to /tmp/mpdump - * -#define RAW_DUMP - */ - -#define MP_SIG                  0x5f504d5f      /* _MP_ */ -#define EXTENDED_PROCESSING_READY -#define OEM_PROCESSING_READY_NOT - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> - -#define LINUX 1 -#if LINUX -typedef unsigned int vm_offset_t; -#else -#include <machine/types.h> -#endif - -/* EBDA is @ 40:0e in real-mode terms */ -#define EBDA_POINTER            0x040e          /* location of EBDA pointer */ - -/* CMOS 'top of mem' is @ 40:13 in real-mode terms */ -#define TOPOFMEM_POINTER        0x0413          /* BIOS: base memory size */ - -#define DEFAULT_TOPOFMEM        0xa0000 - -#define BIOS_BASE               0xf0000 -#define BIOS_BASE2              0xe0000 -#define BIOS_SIZE               0x10000 -#define ONE_KBYTE               1024 - -#define GROPE_AREA1             0x80000 -#define GROPE_AREA2             0x90000 -#define GROPE_SIZE              0x10000 - -/* MP Floating Pointer Structure */ -typedef struct MPFPS { -    char        signature[ 4 ]; -    void*       pap; -    u_char      length; -    u_char      spec_rev; -    u_char      checksum; -    u_char      mpfb1; -    u_char      mpfb2; -    u_char      mpfb3; -    u_char      mpfb4; -    u_char      mpfb5; -} mpfps_t; - -/* MP Configuration Table Header */ -typedef struct MPCTH { -    char        signature[ 4 ]; -    u_short     base_table_length; -    u_char      spec_rev; -    u_char      checksum; -    u_char      oem_id[ 8 ]; -    u_char      product_id[ 12 ]; -    void*       oem_table_pointer; -    u_short     oem_table_size; -    u_short     entry_count; -    void*       apic_address; -    u_short     extended_table_length; -    u_char      extended_table_checksum; -    u_char      reserved; -} mpcth_t; - -typedef struct PROCENTRY { -    u_char      type; -    u_char      apicID; -    u_char      apicVersion; -    u_char      cpuFlags; -    u_long      cpuSignature; -    u_long      featureFlags; -    u_long      reserved1; -    u_long      reserved2; -} ProcEntry; - -#define PROCENTRY_FLAG_EN       0x01 - -static void seekEntry( vm_offset_t addr ); -static void apic_probe( vm_offset_t* paddr, int* where ); -static void readEntry( void* entry, int size ); - -/* global data */ -static int     pfd;            /* physical /dev/mem fd */ -static int     verbose = 0; -static int     grope = 0; - -static int -readType() -{ -    u_char      type; - -    if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) ) { -        perror( "type read" ); -        fprintf( stderr, "\npfd: %d", pfd ); -        fflush( stderr ); -        exit( 1 ); -    } - -    if ( lseek( pfd, -1, SEEK_CUR ) < 0 ) { -        perror( "type seek" ); -        exit( 1 ); -    } - -    return (int)type; -} - -extern int intelDetectSMP(void); - -// old detection -static int intelDetectSMP_mptable(void) -{ -    vm_offset_t paddr; -    int         where; -    mpfps_t     mpfps; -    int		rc = 0; -    int		ncpus = 0; -     -    /* open physical memory for access to MP structures */ -    if ( (pfd = open( "/dev/mem", O_RDONLY )) < 0 ) { -	return 0; -    } - -    /* probe for MP structures */ -    apic_probe( &paddr, &where ); -    if ( where <= 0 ) -	return 0; - -    seekEntry( paddr ); -    readEntry( &mpfps, sizeof( mpfps_t ) ); - -    if (mpfps.mpfb1) -	/* old style */ -	rc = 1; -    else { -	/* go to the config table */ -	mpcth_t     cth; -	int count, i; -	     -	paddr = (vm_offset_t) mpfps.pap; -	seekEntry( paddr ); -	readEntry( &cth, sizeof( cth ) ); -	/* if we don't have any entries, the kernel sure -	   won't be able to set up mp.  Needs at least one entry -	   for smp kernel */ -	if (cth.entry_count <= 1) { -	    close (pfd); -	    return 0; -	} -	count = cth.entry_count; -	for (i = 0; i < count; i++) { -	    if ( readType() == 0 ) { -		ProcEntry   entry; -		readEntry( &entry, sizeof( entry ) ); -		if (entry.cpuFlags & PROCENTRY_FLAG_EN) -		    ncpus++; -	    } -	} -	if (ncpus > 1) -	    rc = 1; -    } - -    close (pfd); -    return rc; -} - -/* - * set PHYSICAL address of MP floating pointer structure - */ -#define NEXT(X)         ((X) += 4) -static void -apic_probe( vm_offset_t* paddr, int* where ) -{ -    /* -     * c rewrite of apic_probe() by Jack F. Vogel -     */ - -    int         x; -    u_short     segment; -    vm_offset_t target; -    u_int       buffer[ BIOS_SIZE / sizeof( int ) ]; - -    if ( verbose ) -        printf( "\n" ); - -    /* search Extended Bios Data Area, if present */ -    if ( verbose ) -        printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER ); -    seekEntry( (vm_offset_t)EBDA_POINTER ); -    readEntry( &segment, 2 ); -    if ( segment ) {                /* search EBDA */ -        target = (vm_offset_t)segment << 4; -        if ( verbose ) -            printf( "found, searching EBDA @ 0x%08x\n", target ); -        seekEntry( target ); -        readEntry( buffer, ONE_KBYTE ); - -        for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) { -            if ( buffer[ x ] == MP_SIG ) { -                *where = 1; -                *paddr = (x * sizeof( unsigned int )) + target; -                return; -            } -        } -    } -    else { -        if ( verbose ) -            printf( "NOT found\n" ); -    } - -    /* read CMOS for real top of mem */ -    seekEntry( (vm_offset_t)TOPOFMEM_POINTER ); -    readEntry( &segment, 2 ); -    --segment;                                          /* less ONE_KBYTE */ -    target = segment * 1024; -    if ( verbose ) -        printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n", -                target, segment ); -    seekEntry( target ); -    readEntry( buffer, ONE_KBYTE ); - -    for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) { -        if ( buffer[ x ] == MP_SIG ) { -            *where = 2; -            *paddr = (x * sizeof( unsigned int )) + target; -            return; -        } -    } - -    /* we don't necessarily believe CMOS, check base of the last 1K of 640K */ -    if ( target != (DEFAULT_TOPOFMEM - 1024)) { -        target = (DEFAULT_TOPOFMEM - 1024); -        if ( verbose ) -            printf( " searching default 'top of mem' @ 0x%08x (%dK)\n", -                    target, (target / 1024) ); -        seekEntry( target ); -        readEntry( buffer, ONE_KBYTE ); - -        for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) { -            if ( buffer[ x ] == MP_SIG ) { -                *where = 3; -                *paddr = (x * sizeof( unsigned int )) + target; -                return; -            } -        } -    } - -    /* search the BIOS */ -    if ( verbose ) -        printf( " searching BIOS @ 0x%08x\n", BIOS_BASE ); -    seekEntry( BIOS_BASE ); -    readEntry( buffer, BIOS_SIZE ); - -    for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) { -        if ( buffer[ x ] == MP_SIG ) { -            *where = 4; -            *paddr = (x * sizeof( unsigned int )) + BIOS_BASE; -            return; -        } -    } - -    /* search the extended BIOS */ -    if ( verbose ) -        printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 ); -    seekEntry( BIOS_BASE2 ); -    readEntry( buffer, BIOS_SIZE ); - -    for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) { -        if ( buffer[ x ] == MP_SIG ) { -            *where = 5; -            *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2; -            return; -        } -    } - -    if ( grope ) { -        /* search additional memory */ -        target = GROPE_AREA1; -        if ( verbose ) -            printf( " groping memory @ 0x%08x\n", target ); -        seekEntry( target ); -        readEntry( buffer, GROPE_SIZE ); - -        for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) { -            if ( buffer[ x ] == MP_SIG ) { -                *where = 6; -                *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1; -                return; -            } -        } - -        target = GROPE_AREA2; -        if ( verbose ) -            printf( " groping memory @ 0x%08x\n", target ); -        seekEntry( target ); -        readEntry( buffer, GROPE_SIZE ); - -        for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) { -            if ( buffer[ x ] == MP_SIG ) { -                *where = 7; -                *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2; -                return; -            } -        } -    } - -    *where = 0; -    *paddr = (vm_offset_t)0; -} - - -/* - * - */ -static void -seekEntry( vm_offset_t addr ) -{ -    if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 ) { -        return; -        perror( "/dev/mem seek" ); -        exit( 1 ); -    } -} - - -/* - * - */ -static void -readEntry( void* entry, int size ) -{ -    if ( read( pfd, entry, size ) != size ) { -        return; -        perror( "readEntry" ); -        exit( 1 ); -    } -} - - -#endif /* __i386__ */ - -int detectSMP(void) -{ -    static int isSMP = -1; - -    if (isSMP != -1) -	return isSMP; - -#ifdef __i386__ -    return isSMP = intelDetectSMP() || intelDetectSMP_mptable(); -#elif __sparc__ -    return isSMP = sparcDetectSMP(); -#elif __alpha__ -    return isSMP = alphaDetectSMP(); -#elif __powerpc__ -    return isSMP = ppcDetectSMP(); -#elif __ia64__ -	/* TODO: Update to check against /proc/pal/cpuX */ -    return isSMP = 1; -#elif __x86_64__ -	return isSMP = intelDetectSMP() || intelDetectSMP_mptable(); -#else -    #error unknown architecture -#endif -} - -#if TEST -int main() { -  if (detectSMP()) -    printf("has smp\n"); -  else -    printf("no smp\n"); -} -#endif diff --git a/perl-install/c/smp.h b/perl-install/c/smp.h deleted file mode 100644 index 3255cc489..000000000 --- a/perl-install/c/smp.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef SMP_H -#define SMP_H - -int detectSMP(void); - -#endif /* SMP_H */ diff --git a/perl-install/c/stuff.pm b/perl-install/c/stuff.pm index 405f896cd..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); @@ -11,7 +11,4 @@ $VERSION = '0.01';  c::stuff->bootstrap($VERSION); -sub from_utf8 { iconv($_[0], "utf-8", standard_charset()) } -sub to_utf8 { iconv($_[0], standard_charset(), "utf-8") } -  1; diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index 2097f0efc..1a148b497 100644..100755 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -5,9 +5,6 @@ print '  #include "perl.h"  #include "XSUB.h" -/* workaround for glibc and kernel header files not in sync */ -#define dev_t dev_t -  #include <ctype.h>  #include <stdlib.h>  #include <stdio.h> @@ -24,6 +21,7 @@ print '  #include <sys/utsname.h>  #include <sys/mount.h>  #undef __USE_MISC +#include <linux/if.h>  #include <linux/wireless.h>  #include <linux/keyboard.h>  #include <linux/kd.h> @@ -33,68 +31,35 @@ print '  #include <linux/cdrom.h>  #include <linux/loop.h>  #include <linux/blkpg.h> +#include <linux/iso_fs.h>  #include <net/if.h>  #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> - -/* for is_ext3 */ -#include <ext2fs/ext2_fs.h> -#include <ext2fs/ext2fs.h> +#include <linux/input.h> +#include <execinfo.h>  // for UPS on USB: +# define HID_MAX_USAGES 1024  #include <linux/hiddev.h>  #include <libldetect.h> -#include <langinfo.h>  #include <string.h> -#include <iconv.h> - -#include <libintl.h>  #define SECTORSIZE 512 -char *prom_getopt(); -void prom_setopt(); -char *prom_getproperty(); -char *disk2PromPath(); -char *promRootName(); - +#include <parted/parted.h>  '; -$ENV{C_DRAKX} && $Config{archname} =~ /i.86/ and print ' +$Config{archname} =~ /i.86/ and print '  char *pcmcia_probe(void);  '; -$ENV{C_RPM} and print ' -#undef Fflush -#undef Mkdir -#undef Stat -#include <rpm/rpmlib.h> -#include <rpm/rpmio.h> - -void rpmError_callback_empty(void) {} - -int rpmError_callback_data; -void rpmError_callback(void) { -  if (rpmErrorCode() != RPMERR_UNLINK && rpmErrorCode() != RPMERR_RMDIR) { -    write(rpmError_callback_data, rpmErrorString(), strlen(rpmErrorString())); -  } -} - -'; - -$ENV{C_DRAKX} and print ' +print ' +/* log_message and log_perror are used in stage1 pcmcia probe */  void log_message(const char * s, ...) {     va_list args;     va_list args_copy; @@ -119,48 +84,68 @@ void log_message(const char * s, ...) {     fclose(logtty);     va_end(args_copy);  } +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; +}  ';  print ' -SV * iconv_(char* s, char* from_charset, char* to_charset) { -  iconv_t cd = iconv_open(to_charset, from_charset); -  char* retval = s; -  if (cd != (iconv_t) (-1)) { -      size_t s_len = strlen(retval); -      /* the maximum expansion when converting happens when converting -	 tscii to utf-8; each tscii char can become up to 4 unicode chars -	 and each one of those unicode chars can be 3 bytes long */ -      char *buf = alloca(4 * 3 * s_len); -      { -	  char *ptr = buf; -	  size_t ptr_len = 4 * 3 * s_len; -	  if ((iconv(cd, &s, &s_len, &ptr, &ptr_len)) != (size_t) (-1)) { -	      *ptr = 0; -	      retval = buf; -	  } -      } -      iconv_close(cd); -  } -  return newSVpv(retval, 0); +int length_of_space_padded(char *str, int len) { +  while (len >= 0 && str[len-1] == \' \') +    --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  '; -$ENV{C_DRAKX} && $Config{archname} =~ /i.86/ and print ' +$Config{archname} =~ /i.86/ and print '  char *  pcmcia_probe()  ';  print ' -char * -dgettext(domainname, msgid) -   char * domainname -   char * msgid -  int  del_partition(hd, part_number)    int hd @@ -204,60 +189,21 @@ is_secure_file(filename)    OUTPUT:    RETVAL -int -is_ext3(device_name) -  char * device_name -  CODE: -  { -    ext2_filsys fs; -    int retval = ext2fs_open (device_name, 0, 0, 0, unix_io_manager, &fs); -    if (retval) { -      RETVAL = 0; -    } else { -      RETVAL = fs->super->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL; -      ext2fs_close(fs);   -    } -  } -  OUTPUT: -  RETVAL - -char * -get_ext2_label(device_name) -  char * device_name -  CODE: -  { -    ext2_filsys fs; -    int retval = ext2fs_open (device_name, 0, 0, 0, unix_io_manager, &fs); -    if (retval) { -      RETVAL = 0; -    } else { -      RETVAL = fs->super->s_volume_name; -      ext2fs_close(fs);   -    } -  } -  OUTPUT: -  RETVAL -  void -setlocale() +init_setlocale()     CODE:     setlocale(LC_ALL, "");     setlocale(LC_NUMERIC, "C"); /* otherwise eval "1.5" returns 1 in fr_FR for example */  char * -bindtextdomain(domainname, dirname) -   char * domainname -   char * dirname - -char * -bind_textdomain_codeset(domainname, codeset) -   char * domainname -   char * codeset +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; @@ -298,32 +244,15 @@ floppy_info(name)    OUTPUT:    RETVAL -unsigned int +NV  total_sectors(fd)    int fd    CODE:    { -    long s; -    RETVAL = ioctl(fd, BLKGETSIZE, &s) == 0 ? s : 0; -  } -  OUTPUT: -  RETVAL - -void -unlimit_core() -  CODE: -  { -    struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY }; -    setrlimit(RLIMIT_CORE, &rlim); -  } - -int -getlimit_core() -  CODE: -  { -    struct rlimit rlim; -    getrlimit(RLIMIT_CORE, &rlim); -    RETVAL = rlim.rlim_cur; +    unsigned long long ll; +    unsigned long l; +    RETVAL = ioctl(fd, BLKGETSIZE64, &ll) == 0 ? ll / 512 :  +             ioctl(fd, BLKGETSIZE, &l) == 0 ? l : 0;    }    OUTPUT:    RETVAL @@ -342,7 +271,7 @@ syslog(priority, mesg)    int priority    char *mesg    CODE: -  syslog(priority, mesg); +  syslog(priority, "%s", mesg);  void  setsid() @@ -355,23 +284,43 @@ void  usleep(microseconds)    unsigned long microseconds -int -detectSMP() + +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:      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%s\t%s\t%s",  -               e->vendor, e->device, e->subvendor, e->subdevice, e->pci_bus, e->pci_device, e->pci_function, -               pci_class2text(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); @@ -385,13 +334,34 @@ usb_probe()      EXTEND(SP, entries.nb);      for (i = 0; i < entries.nb; i++) {        struct pciusb_entry *e = &entries.entries[i]; -      struct usb_class_text class_text = usb_class2text(e->class_); -      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))); +      struct usb_class_text class_text = usb_class2text(e->class_id); +      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); +void +dmi_probe() +  PPCODE: +    //dmidecode_file = "/usr/share/ldetect-lst/dmidecode.Laptop.Dell-Latitude-C810"; +    //dmidecode_file = "../../soft/ldetect-lst/test/dmidecode.Laptop.Sony-Vaio-GRX316MP"; + +    struct dmi_entries entries = dmi_probe(); +    int i; + +    EXTEND(SP, entries.nb); +    for (i = 0; i < entries.nb; i++) { +      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); + +  unsigned int  getpagesize() @@ -408,22 +378,8 @@ get_usb_ups_name(int fd)    RETVAL -  int -hasNetDevice(device) -  char * device -  CODE: -    struct ifreq req; -    int s = socket(AF_INET, SOCK_DGRAM, 0); -    if (s == -1) { RETVAL = 0; return; } - -    strncpy(req.ifr_name, device, IFNAMSIZ); - -    RETVAL = ioctl(s, SIOCGIFFLAGS, &req) == 0; -    close(s); -  OUTPUT: -  RETVAL - +res_init()  int  isNetDeviceWirelessAware(device) @@ -458,6 +414,7 @@ get_netdevices()            if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {                 perror("SIOCGIFCONF"); +               close(s);                 return;            }            if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { @@ -504,6 +461,7 @@ getNetDriver(char* device)                  break;          }      } else { perror("SIOCETHTOOL"); RETVAL = strdup(""); } +    close(s);    OUTPUT:    RETVAL @@ -555,13 +513,69 @@ get_hw_address(const char* ifname)          RETVAL = NULL;          return;      } -    a = ifr.ifr_hwaddr.sa_data; +    a = (unsigned char*)ifr.ifr_hwaddr.sa_data;      asprintf(&res, "%02x:%02x:%02x:%02x:%02x:%02x", a[0],a[1],a[2],a[3],a[4],a[5]);      RETVAL= res;    OUTPUT:    RETVAL +void +strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) +    char *      fmt +    int     sec +    int     min +    int     hour +    int     mday +    int     mon +    int     year +    int     wday +    int     yday +    int     isdst +    CODE: +    {    +        char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst); +        if (buf) { +        ST(0) = sv_2mortal(newSVpv(buf, 0)); +        Safefree(buf); +        } +    } + +#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() @@ -571,160 +585,250 @@ kernel_version()    OUTPUT:    RETVAL -int -prom_open() +void +set_tagged_utf8(s) +   SV *s +   CODE: +   SvUTF8_on(s);  void -prom_close() +get_iso_volume_ids(int fd) +  INIT: +  struct iso_primary_descriptor voldesc; +  PPCODE: +  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))) { +      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("")); +    } +  } -int -prom_getsibling(node) -  int node +'; -int -prom_getchild(node) -  int node +print ' -void -prom_getopt(key) -  char *key -  PPCODE: -  int lenp = 0; -  char *value = NULL; -  value = prom_getopt(key, &lenp); -  EXTEND(sp, 1); -  if (value != NULL) { -    PUSHs(sv_2mortal(newSVpv(value, 0))); +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 { -    PUSHs(&PL_sv_undef); +    PedPartitionFlag flag = string_to_pedpartflag(type); +    if (flag) { +      RETVAL = ped_partition_set_flag(part, flag, 1); +    }    } +  OUTPUT: +  RETVAL -void -prom_setopt(key, value) -  char *key -  char *value -void -prom_getproperty(key) -  char *key -  PPCODE: -  int lenp = 0; -  char *value = NULL; -  value = prom_getproperty(key, &lenp); -  EXTEND(sp, 1); -  if (value != NULL) { -    PUSHs(sv_2mortal(newSVpv(value, lenp))); -  } else { -    PUSHs(&PL_sv_undef); +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 -prom_getstring(key) -  char *key +get_disk_partitions(char * device_path)    PPCODE: -  int lenp = 0; -  char *value = NULL; -  value = prom_getproperty(key, &lenp); -  EXTEND(sp, 1); -  if (value != NULL) { -    PUSHs(sv_2mortal(newSVpv(value, 0))); -  } else { -    PUSHs(&PL_sv_undef); +  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);    } -int -prom_getbool(key) -  char *key - -void -initSilo() - -char * -disk2PromPath(disk) -  unsigned char *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 -hasAliases() - -char * -promRootName() +disk_delete_all(PedDisk* disk) +  CODE: +  RETVAL = 0; +  if (ped_disk_delete_all(disk)) { +    RETVAL = 1; +  } +  OUTPUT: +  RETVAL -void -setPromVars(linuxAlias, bootDevice) -  char *linuxAlias -  char *bootDevice - -SV * -iconv(s, from_charset, to_charset) -  char *s -  char *from_charset -  char *to_charset +int +disk_del_partition(PedDisk* disk, int part_number)    CODE: -  RETVAL = iconv_(s, from_charset, to_charset); +  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 -is_tagged_utf8(s) -   SV *s -   CODE: -   RETVAL = SvUTF8(s); -   OUTPUT: -   RETVAL +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 -void -set_tagged_utf8(s) -   SV *s -   CODE: -   SvUTF8_on(s); +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 -void -upgrade_utf8(s) -   SV *s -   CODE: -   sv_utf8_upgrade(s); +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 -void -unset_tagged_utf8(s) -   SV *s -   CODE: -   SvUTF8_off(s); +#define BACKTRACE_DEPTH				20 +  -char * -standard_charset() +char* +C_backtrace()    CODE: -  RETVAL = nl_langinfo(CODESET); +  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 -'; - -$ENV{C_RPM} and print ' -const char * -rpmErrorString() -void -rpmSetVeryVerbose() -  CODE: -  rpmSetVerbosity(RPMMESS_DEBUG); -void -rpmErrorSetCallback(fd) -  int fd -  CODE: -  rpmError_callback_data = fd; -  rpmErrorSetCallback(rpmError_callback); -int -rpmvercmp(char *a, char *b);  ';  @macros = ( -  [ qw(int S_IFCHR S_IFBLK S_IFIFO KDSKBENT KT_SPEC K_NOSUCHMAP NR_KEYS MAX_NR_KEYMAPS BLKRRPART TIOCSCTTY -       HDIO_GETGEO BLKGETSIZE LOOP_GET_STATUS HIDIOCAPPLICATION -       MS_MGC_VAL MS_RDONLY O_NONBLOCK F_SETFL F_GETFL O_CREAT SECTORSIZE WNOHANG -       VT_ACTIVATE VT_WAITACTIVE VT_GETSTATE CDROM_LOCKDOOR CDROMEJECT CDROM_DRIVE_STATUS CDS_DISC_OK +  [ 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 +       CDROMEJECT CDROMCLOSETRAY CDROM_LOCKDOOR         LOG_WARNING LOG_INFO LOG_LOCAL1 +       LC_COLLATE         ) ],  ); @@ -749,6 +853,5 @@ END  }  print ' -PROTOTYPES: ENABLE +PROTOTYPES: DISABLE  '; - | 
