]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
Updated isys module.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2008 11:06:34 +0000 (11:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2008 11:06:34 +0000 (11:06 +0000)
40 files changed:
src/pomona/Makefile.inc
src/pomona/src/Makefile
src/pomona/src/image.py
src/pomona/src/isys/Makefile
src/pomona/src/isys/cpio.c [deleted file]
src/pomona/src/isys/cpio.h [deleted file]
src/pomona/src/isys/devices.c [new file with mode: 0644]
src/pomona/src/isys/devices.h [new file with mode: 0644]
src/pomona/src/isys/eddsupport.c
src/pomona/src/isys/eddsupport.h
src/pomona/src/isys/ethtool.c [new file with mode: 0644]
src/pomona/src/isys/imount.c
src/pomona/src/isys/imount.h
src/pomona/src/isys/isofs.c
src/pomona/src/isys/isys.c
src/pomona/src/isys/isys.h
src/pomona/src/isys/isys.py
src/pomona/src/isys/lang.c
src/pomona/src/isys/lang.h
src/pomona/src/isys/linkdetect.c [new file with mode: 0644]
src/pomona/src/isys/mount.h [deleted file]
src/pomona/src/isys/mount_clnt.c [deleted file]
src/pomona/src/isys/mount_constants.h [deleted file]
src/pomona/src/isys/mount_svc.c [deleted file]
src/pomona/src/isys/mount_xdr.c [deleted file]
src/pomona/src/isys/net.h [new file with mode: 0644]
src/pomona/src/isys/smp.c
src/pomona/src/isys/smp.h
src/pomona/src/isys/str.c
src/pomona/src/isys/str.h
src/pomona/src/isys/stubs.h
src/pomona/src/isys/sundries.h [deleted file]
src/pomona/src/isys/uncpio.c [deleted file]
src/pomona/src/isys/vio.c
src/pomona/src/isys/wireless.c [new file with mode: 0644]
src/pomona/src/isys/wireless.h [new file with mode: 0644]
src/pomona/src/minihal.py [new file with mode: 0644]
src/pomona/src/pomona
src/pomona/src/tui.py
src/rootfiles/installer/pomona

index 2426ac882b89b78d4db8e46c9d080961d6cfbbf3..cc248c1561a5cb21706ecb810a6720870c90240a 100644 (file)
@@ -28,5 +28,7 @@ INSTALL_PROGRAM = ${INSTALL}
 INSTALL_DATA = ${INSTALL} -m 644
 INSTALLNLSDIR = $(DESTDIR)/usr/share/locale
 
-PYTHONLIBDIR = $(DESTDIR)/lib/$(PSNAME)
-PYTHONINCLUDE= $(DESTDIR)/include/python2.5/
+PYTHONLIBDIR = $(DESTDIR)/usr/lib/$(PSNAME)
+PYTHONINCLUDE= $(DESTDIR)/usr/include/python2.5/
+
+CC = $(CROSS)gcc
index e0a7a202ad17f3ca031aa95bfe81660654bcc634..b3f41d1f912c87a3bbcaa2011e987ffabd820f20 100644 (file)
@@ -20,8 +20,7 @@
 
 include ../Makefile.inc
 
-#SUBDIRS = isys # Don't compile isys at the moment.
-SUBDIRS=
+SUBDIRS = isys
 
 all: subdirs
 
index 17b53c66e1e3d0c56d0679f206a593b193628b4b..20b8fd8947c0b5b86557feb7bfd2d454dc5181bf 100644 (file)
@@ -17,7 +17,6 @@ import os
 import sys
 import isys
 import time
-import kudzu
 import string
 import shutil
 
index 4c0d3c6b5fc33c3547f2eb77d80e14d709ab624e..da70afea5e5f092da13cdf4fabfda0751e6fedd5 100644 (file)
@@ -1,13 +1,14 @@
 include ../../Makefile.inc
 
-CFLAGS +=  -I$(PYTHONINCLUDE) -I..
+CFLAGS +=  -I$(PYTHONINCLUDE) -I$(DESTDIR)/usr/include -I.. -I.
 
-OBJECTS = imount.o smp.o cpio.o uncpio.o \
-          lang.o isofs.o vio.o eddsupport.o str.o
+OBJECTS = devices.o imount.o smp.o linkdetect.o \
+       lang.o isofs.o vio.o eddsupport.o str.o \
+       wireless.o ethtool.o
 
 SOBJECTS = $(patsubst %.o,%.lo,$(OBJECTS))
 SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) isys.c
-LOADLIBES = -lpci -lpopt -lext2fs -lz -lkudzu -lpci
+LOADLIBES = -lpci -lpopt -lext2fs -lz -lpci -lblkid
 PYMODULES = _isys.so
 
 ifeq (.depend,$(wildcard .depend))
@@ -24,7 +25,7 @@ all: $(PYMODULES) libisys.a
        $(CC) -c $(CFLAGS) -fPIC -o $@ $<
 
 _isys.so: isys.lo $(SOBJECTS)
-       gcc -shared -g -fPIC -o $@ isys.lo $(SOBJECTS) $(LOADLIBES) $(LDFLAGS)
+       $(CC) -shared -g -fPIC -o $@ isys.lo $(SOBJECTS) $(LOADLIBES) $(LDFLAGS)
 
 libisys.a: libisys.a($(OBJECTS))
 
diff --git a/src/pomona/src/isys/cpio.c b/src/pomona/src/isys/cpio.c
deleted file mode 100644 (file)
index 008c6b9..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "cpio.h"
-
-int installCpioFile(gzFile fd, char * cpioName, char * outName, int inWin) {
-    struct cpioFileMapping map;
-    int rc;
-    const char * failedFile;
-
-    if (outName) {
-       map.archivePath = cpioName;
-       map.fsPath = outName;
-       map.mapFlags = CPIO_MAP_PATH;
-    }
-
-    rc = myCpioInstallArchive(fd, outName ? &map : NULL, 1, NULL, NULL, 
-                           &failedFile);
-
-    if (rc || access(outName, R_OK)) {
-       return -1;
-    }
-
-    return 0;
-}
diff --git a/src/pomona/src/isys/cpio.h b/src/pomona/src/isys/cpio.h
deleted file mode 100644 (file)
index 1caa4e4..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifndef H_CPIO
-#define H_CPIO
-
-#include <sys/types.h>
-
-#include "stubs.h"
-
-/* Note the CPIO_CHECK_ERRNO bit is set only if errno is valid. These have to
-   be positive numbers or this setting the high bit stuff is a bad idea. */
-#define CPIOERR_CHECK_ERRNO    0x80000000
-
-#define CPIOERR_BAD_MAGIC      (2                      )
-#define CPIOERR_BAD_HEADER     (3                      )
-#define CPIOERR_OPEN_FAILED    (4    | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_CHMOD_FAILED   (5    | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_CHOWN_FAILED   (6    | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_WRITE_FAILED   (7    | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_UTIME_FAILED   (8    | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_UNLINK_FAILED  (9    | CPIOERR_CHECK_ERRNO)
-
-#define CPIOERR_SYMLINK_FAILED (11   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_STAT_FAILED    (12   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_MKDIR_FAILED   (13   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_MKNOD_FAILED   (14   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_MKFIFO_FAILED  (15   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_LINK_FAILED    (16   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_READLINK_FAILED        (17   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_READ_FAILED    (18   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_COPY_FAILED    (19   | CPIOERR_CHECK_ERRNO)
-#define CPIOERR_INTERNAL       (20                     )
-#define CPIOERR_HDR_SIZE       (21                     )
-#define CPIOERR_UNKNOWN_FILETYPE (22                   )
-
-
-/* Don't think this behaves just like standard cpio. It's pretty close, but
-   it has some behaviors which are more to RPM's liking. I tried to document
-   them inline in cpio.c, but I may have missed some. */
-
-#define CPIO_MAP_PATH          (1 << 0)
-#define CPIO_MAP_MODE          (1 << 1)
-#define CPIO_MAP_UID           (1 << 2)
-#define CPIO_MAP_GID           (1 << 3)
-#define CPIO_FOLLOW_SYMLINKS   (1 << 4)  /* only for building */
-
-struct cpioFileMapping {
-    char * archivePath;
-    char * fsPath;
-    mode_t finalMode;
-    uid_t finalUid;
-    gid_t finalGid;
-    int mapFlags;
-};
-
-/* on cpio building, only "file" is filled in */
-struct cpioCallbackInfo {
-    char * file;
-    long fileSize;                     /* total file size */
-    long fileComplete;                 /* amount of file unpacked */
-    long bytesProcessed;               /* bytes in archive read */
-};
-
-typedef void (*cpioCallback)(struct cpioCallbackInfo * filespec, void * data);
-
-/* If no mappings are passed, this installs everything! If one is passed
-   it should be sorted according to cpioFileMapCmp() and only files included
-   in the map are installed. Files are installed relative to the current
-   directory unless a mapping is given which specifies an absolute 
-   directory. The mode mapping is only used for the permission bits, not
-   for the file type. The owner/group mappings are ignored for the nonroot
-   user. If *failedFile is non-NULL on return, it should be free()d. */
-int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings, 
-                      int numMappings, cpioCallback cb, void * cbData,
-                      const char ** failedFile);
-int myCpioFilterArchive(gzFile inStream, gzFile outStream, char ** pattern);
-
-/* This is designed to be qsort/bsearch compatible */
-int myCpioFileMapCmp(const void * a, const void * b);
-
-const char *myCpioStrerror(int rc);
-
-int installCpioFile(gzFile fd, char * cpioName, char * outName, int inWin);
-
-#endif
diff --git a/src/pomona/src/isys/devices.c b/src/pomona/src/isys/devices.c
new file mode 100644 (file)
index 0000000..69a0020
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * devices.c - various hardware probing functionality
+ *
+ * Copyright (C) 2007  Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Bill Nottingham <notting@redhat.com>
+ */
+
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "devices.h"
+
+/* for 'disks', to filter out weird stuff */
+#define MINIMUM_INTERESTING_SIZE       32*1024         /* 32MB */
+
+/* from genhd.h, kernel side */
+#define GENHD_FL_REMOVABLE                      1
+#define GENHD_FL_DRIVERFS                       2
+#define GENHD_FL_MEDIA_CHANGE_NOTIFY            4
+#define GENHD_FL_CD                             8
+#define GENHD_FL_UP                             16
+#define GENHD_FL_SUPPRESS_PARTITION_INFO        32
+#define GENHD_FL_FAIL                           64
+
+
+struct device **getDevices(enum deviceType type) {
+    struct device **ret = NULL;
+    struct device *new;
+    int numdevices = 0;
+    int rc;
+
+    if (type & (DEVICE_DISK | DEVICE_CDROM)) {
+        DIR *dir;
+        struct dirent *ent;
+
+        dir = opendir("/sys/block");
+
+        if (!dir) goto storagedone;
+
+        while ((ent = readdir(dir))) {
+            char path[64];
+            char buf[64];
+            int fd, caps, devtype;
+
+            snprintf(path, 64, "/sys/block/%s/capability", ent->d_name);
+            fd = open(path, O_RDONLY);
+            if (fd == -1)
+                continue;
+            if (read(fd, buf, 64) <= 0) {
+                close(fd);
+                continue;
+            }
+            close(fd);
+            caps = strtol(buf, NULL, 16);
+            if (caps & GENHD_FL_CD)
+                devtype = DEVICE_CDROM;
+            else
+                devtype = DEVICE_DISK;
+            if (!(devtype & type))
+                continue;
+
+            if (devtype == DEVICE_DISK && !(caps & GENHD_FL_REMOVABLE)) {
+                int size;
+
+                snprintf(path, 64, "/sys/block/%s/size", ent->d_name);
+                fd = open(path, O_RDONLY);
+                if (fd == -1)
+                    continue;
+                if (read(fd, buf, 64) <= 0) {
+                    close(fd);
+                    continue;
+                }
+                close(fd);
+                size = atoi(buf);
+                if (size < MINIMUM_INTERESTING_SIZE)
+                    continue;
+            }
+
+            new = calloc(1, sizeof(struct device));
+            new->device = strdup(ent->d_name);
+            /* FIXME */
+            rc = asprintf(&new->description,"Storage device %s",new->device);
+            new->type = devtype;
+            if (caps & GENHD_FL_REMOVABLE) {
+                new->priv.removable = 1;
+            }
+            ret = realloc(ret, (numdevices+2) * sizeof(struct device));
+            ret[numdevices] = new;
+            ret[numdevices+1] = NULL;
+            numdevices++;
+        }
+    }
+storagedone:
+
+    if (type & DEVICE_NETWORK) {
+        DIR *dir;
+        struct dirent *ent;
+
+        dir = opendir("/sys/class/net");
+
+        if (!dir) goto netdone;
+
+        while ((ent = readdir(dir))) {
+            char path[64];
+            int fd, type;
+            char buf[64];
+
+            snprintf(path, 64, "/sys/class/net/%s/type", ent->d_name);
+            fd = open(path, O_RDONLY);
+            if (fd == -1)
+                continue;
+            if (read(fd, buf, 64) <= 0) {
+                close(fd);
+                continue;
+            }
+            close(fd);
+            type = atoi(buf);
+            if (type != 1)
+                continue;
+
+            new = calloc(1, sizeof(struct device));
+            new->device = strdup(ent->d_name);
+            /* FIXME */
+            snprintf(path, 64, "/sys/class/net/%s/address", ent->d_name);
+            fd = open(path, O_RDONLY);
+            if (fd != -1) {
+                if (read(fd, buf, 64) > 0) {
+                    int i;
+                    for (i = (strlen(buf)-1); isspace(buf[i]); i--) buf[i] = '\0';
+                    new->priv.hwaddr = strdup(buf);
+                }
+            }
+
+            if (new->priv.hwaddr)
+               rc = asprintf(&new->description, "Ethernet device %s - %s",
+                             new->device, new->priv.hwaddr);
+            else
+               rc = asprintf(&new->description, "Ethernet device %s", new->device);
+
+            ret = realloc(ret, (numdevices+2) * sizeof(struct device));
+            ret[numdevices] = new;
+            ret[numdevices+1] = NULL;
+            numdevices++;
+        }
+    }
+netdone:
+    return ret;
+}
+
diff --git a/src/pomona/src/isys/devices.h b/src/pomona/src/isys/devices.h
new file mode 100644 (file)
index 0000000..9428a77
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * devices.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DEVICES_H
+#define DEVICES_H
+
+enum deviceType {
+    DEVICE_ANY = ~0,
+    DEVICE_NETWORK = (1 << 0),
+    DEVICE_DISK = (1 << 1),
+    DEVICE_CDROM = (1 << 2)
+};
+
+struct device {
+    char *device;
+    char *description;
+    enum deviceType type;
+    union {
+        char *hwaddr;
+        int removable;
+    } priv;
+};
+
+struct device **getDevices(enum deviceType type);
+
+#endif
index a38f3ce0af8fec9223ce7ccc01c88ef555f4a4a4..ae974c565413897d6853954d06e19be174345101 100644 (file)
@@ -2,17 +2,24 @@
  * eddsupport.c - handling of mapping disk drives in Linux to disk drives
  * according to the BIOS using the edd kernel module
  *
- * Copyright 2004 Dell, Inc., Red Hat, Inc.
+ * Copyright (C) 2004  Dell, Inc.  All rights reserved.
+ * Copyright (C) 2004  Red Hat, Inc.  All rights reserved.
  *
- * Rezwanul_Kabir@Dell.com
- * Jeremy Katz <katzj@redhat.com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This software may be freely redistributed under the terms of the GNU
- * general public license.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
  * 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.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Rezwanul_Kabir@Dell.com
+ *            Jeremy Katz <katzj@redhat.com>
  */
 
 #include <ctype.h>
 #include <sys/types.h>
 #include <linux/types.h>
 
-#include <kudzu/kudzu.h>
-
 
 #include "eddsupport.h"
+#include "devices.h"
 #include "isys.h"
 
-
-
 #define EDD_DIR "/sys/firmware/edd"
 #define SIG_FILE "mbr_signature"
 #define MBRSIG_OFFSET 0x1b8
@@ -97,17 +101,13 @@ int probeBiosDisks() {
 
 
 static struct device ** createDiskList(){
-    return probeDevices (CLASS_HD, BUS_UNSPEC, PROBE_ALL);
+    return getDevices (DEVICE_DISK);
 }
 
 static int readDiskSig(char *device, uint32_t *disksig) {
     int fd, rc;
 
-    /* XXX if (devMakeInode(device, "/tmp/biosdev")){
-        return -1;
-    } */ 
-
-    fd = open("/tmp/biosdev", O_RDONLY);
+    fd = open(device, O_RDONLY);
     if (fd < 0) {
 #ifdef STANDALONE 
         fprintf(stderr, "Error opening device %s: %s\n ", device, 
@@ -138,7 +138,6 @@ static int readDiskSig(char *device, uint32_t *disksig) {
     }
 
     close(fd);
-    unlink("/tmp/biosdev");
     return 0;
 }
 
@@ -164,6 +163,7 @@ static int mapBiosDisks(struct device** devices,const char *path) {
 #ifdef STANDALONE
         fprintf(stderr, "Error initializing mbrSigToName table\n");
 #endif
+        closedir(dirHandle);
         return 0;
     }
 
@@ -176,31 +176,33 @@ static int mapBiosDisks(struct device** devices,const char *path) {
         sigFileName = malloc(strlen(path) + strlen(entry->d_name) + 20);
         sprintf(sigFileName, "%s/%s/%s", path, entry->d_name, SIG_FILE);
         if (readMbrSig(sigFileName, &mbrSig) == 0) {
-               
-           for (currentDev = devices, i = 0, foundDisk=NULL; (*currentDev) != NULL && i<2; currentDev++) {
-               if (!(*currentDev)->device)
-                       continue;
-               
-               if ((rc=readDiskSig((*currentDev)->device, &currentSig)) < 0){
-                       if (rc == -ENOMEDIUM)
-                            continue;
-                       return 0;
-               } 
-                       
-
-               if (mbrSig == currentSig){
-                       foundDisk=currentDev;
-                       i++;
-               }
-           }
-
-           if (i==1){
-            if(!addToHashTable(mbrSigToName, (uint32_t)biosNum, 
-                               (*foundDisk)->device))
-                return 0;
-           }
+            for (currentDev = devices, i = 0, foundDisk=NULL;
+                    (*currentDev) != NULL && i<2;
+                    currentDev++) {
+                if (!(*currentDev)->device)
+                    continue;
+
+                if ((rc=readDiskSig((*currentDev)->device, &currentSig)) < 0) {
+                    if (rc == -ENOMEDIUM)
+                        continue;
+                    closedir(dirHandle);
+                    return 0;
+                } 
+
+                if (mbrSig == currentSig) {
+                    foundDisk=currentDev;
+                        i++;
+                }
+            }
+
+            if (i==1) {
+                if(!addToHashTable(mbrSigToName, (uint32_t)biosNum, 
+                               (*foundDisk)->device)) {
+                    closedir(dirHandle);
+                    return 0;
+                }
+            }
         } 
-
     }
     closedir(dirHandle);
     return 1;
index b7a390f43af13ba4afdb198f25fedfe23dbd6534..77fc4c4428720229ec8bc81559dfb48885c5149e 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * eddsupport.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef EDDSUPPORT_H
 #define EDDSUPPORT_H
 
diff --git a/src/pomona/src/isys/ethtool.c b/src/pomona/src/isys/ethtool.c
new file mode 100644 (file)
index 0000000..df65549
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * ethtool.c - setting of basic ethtool options
+ *
+ * Copyright (C) 2003  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Jeremy Katz <katzj@redhat.com>
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <net/if.h>
+
+#include <linux/sockios.h>
+#include "net.h"
+
+static int set_intf_up(struct ifreq ifr, int sock) {
+    if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
+        return (-1);
+    }
+    ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
+    if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
+        fprintf(stderr, "failed to bring up interface %s: %s", ifr.ifr_name,
+                strerror(errno));
+        return -1;
+    }
+    return (0);
+}
+
+int setEthtoolSettings(char * dev, ethtool_speed speed, 
+                       ethtool_duplex duplex) {
+    int sock, err;
+    struct ethtool_cmd ecmd;
+    struct ifreq ifr;
+
+    if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+        perror("Unable to create socket");
+        return -1;
+    }
+
+    /* Setup our control structures. */
+    memset(&ifr, 0, sizeof(ifr));
+    strcpy(ifr.ifr_name, dev);
+
+    if (set_intf_up(ifr, sock) == -1) {
+        fprintf(stderr, "unable to bring up interface %s: %s", dev, 
+                strerror(errno));
+        return -1;
+    }
+
+    ecmd.cmd = ETHTOOL_GSET;
+    ifr.ifr_data = (caddr_t)&ecmd;
+    err = ioctl(sock, SIOCETHTOOL, &ifr);
+    if (err < 0) {
+        perror("Unable to get settings via ethtool.  Not setting");
+        return -1;
+    }
+
+    if (speed != ETHTOOL_SPEED_UNSPEC)
+        ecmd.speed = speed;
+    if (duplex != ETHTOOL_DUPLEX_UNSPEC)
+        ecmd.duplex = duplex;
+    if ((duplex != ETHTOOL_DUPLEX_UNSPEC) || (speed != ETHTOOL_SPEED_UNSPEC))
+        ecmd.autoneg = AUTONEG_DISABLE;
+
+    ecmd.cmd = ETHTOOL_SSET;
+    ifr.ifr_data = (caddr_t)&ecmd;
+    err = ioctl(sock, SIOCETHTOOL, &ifr);
+    if (err < 0) {
+        //        perror("Unable to set settings via ethtool.  Not setting");
+        return -1;
+    }
+
+    return 0;
+}
index d11443e91cf00b6fd5c1ad6a24297a62f5fc0d20..acca4ffa9c44062dc861c3e0db86582ac5ae69d1 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * imount.c
+ *
+ * Copyright (C) 2007, 2008 Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "imount.h"
-#include "sundries.h"
 
 #define _(foo) foo
 
 static int mkdirIfNone(char * directory);
 
-int doPwMount(char * dev, char * where, char * fs, int options, void *data) {
-    char * buf = NULL;
-    int isnfs = 0;
-    char * mount_opt = NULL;
-    long int flag;
-    char * chptr __attribute__ ((unused));
-    
-    if (!strcmp(fs, "nfs")) isnfs = 1;
-
-    /*logMessage(INFO, "mounting %s on %s as type %s", dev, where, fs);*/
+int doPwMount(char *dev, char *where, char *fs, char *options) {
+    int rc, child, status;
+    char *opts = NULL, *device;
 
-    if (mkdirChain(where))
+    if (mkdirChain(where)) {
         return IMOUNT_ERR_ERRNO;
+    }
 
-    flag = MS_MGC_VAL;
-    if (options & IMOUNT_RDONLY)
-        flag |= MS_RDONLY;
-    if (options & IMOUNT_BIND)
-        flag |= MS_BIND;
-    if (options & IMOUNT_REMOUNT)
-        flag |= MS_REMOUNT;
-
-    if (!isnfs && (*dev == '/' || !strcmp(dev, "none"))) {
-        buf = dev;
-    } else if (!isnfs) {
-        buf = alloca(200);
-        strcpy(buf, "/tmp/");
-        strcat(buf, dev);
+    if (strstr(fs, "nfs")) {
+        if (options)
+            rc = asprintf(&opts, "%s,nolock", options);
+        else
+            opts = strdup("nolock");
+        device = strdup(dev);
+    } else {
+        if ((options && strstr(options, "bind") == NULL) && 
+            strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) && *dev != '/')
+           rc = asprintf(&device, "/dev/%s", dev);
+        else
+           device = strdup(dev);
+        if (options)
+            opts = strdup(options);
     }
-    if (!strncmp(fs, "vfat", 4))
-        mount_opt="check=relaxed";
-
-    /*logMessage(INFO, "calling mount(%s, %s, %s, %ld, %p)", buf, where, fs, 
-      flag, mount_opt);*/
-    
-    if (mount(buf, where, fs, flag, mount_opt)) {
-        /*logMessage(ERROR, "mount failed: %s", strerror(errno));*/
-        return IMOUNT_ERR_ERRNO;
+
+
+    if (!(child = fork())) {
+        int fd;
+
+        /* Close off all these filehandles since we don't want errors
+         * spewed to tty1.
+         */
+        fd = open("/dev/tty5", O_RDONLY);
+        close(STDIN_FILENO);
+        dup2(fd, STDIN_FILENO);
+        close(fd);
+
+        fd = open("/dev/tty5", O_WRONLY);
+        close(STDOUT_FILENO);
+        dup2(fd, STDOUT_FILENO);
+        close(STDERR_FILENO);
+        dup2(fd, STDERR_FILENO);
+        close(fd);
+
+        if (opts) {
+            fprintf(stderr, "Running... /bin/mount -n -t %s -o %s %s %s\n",
+                    fs, opts, device, where);
+            rc = execl("/bin/mount",
+                       "/bin/mount", "-n", "-t", fs, "-o", opts, device, where, NULL);
+            exit(1);
+        }
+        else {
+            fprintf(stderr, "Running... /bin/mount -n -t %s %s %s\n",
+                    fs, device, where);
+            rc = execl("/bin/mount", "/bin/mount", "-n", "-t", fs, device, where, NULL);
+            exit(1);
+        }
     }
 
+    waitpid(child, &status, 0);
+
+    free(opts);
+    free(device);
+    if (!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status)))
+       return IMOUNT_ERR_OTHER;
+
     return 0;
 }
 
index 32cfafac0ddbbda148cbc2e02e6f1193101fc424..50ee116008588fb36d105acb8835f382fef637ca 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * imount.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef H_IMOUNT
 #define H_IMOUNT
 
@@ -10,7 +29,7 @@
 #define IMOUNT_BIND    2
 #define IMOUNT_REMOUNT 4
 
-int doPwMount(char * dev, char * where, char * fs, int options, void * data);
+int doPwMount(char *dev, char *where, char *fs, char *options);
 int mkdirChain(char * origChain);
 
 #endif
index 1f954a22532d3da88132b07a5c66c0525cc86a0c..bb5a44adba6b046628afe48f28c5979abdfc50ad 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * isofs.c
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
index e6fa0c10b6f900338712c556aee3e46348d3fa03..dc42c511719a028875c09d6c02bc4a352050700a 100644 (file)
@@ -1,17 +1,42 @@
+/*
+ * isys.c
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <Python.h>
 
 #include <stdio.h>
 #include <dirent.h>
 #include <errno.h>
 #define u32 __u32
-#include <linux/ext2_fs.h>
-#include <linux/ext3_fs.h>
 #include <ext2fs/ext2fs.h>
 #include <fcntl.h>
 #include <popt.h>
 /* Need to tell loop.h what the actual dev_t type is. */
 #undef dev_t
+#if defined(__alpha) || (defined(__sparc__) && defined(__arch64__))
+#define dev_t unsigned int
+#else
+#if defined(__x86_64__)
+#define dev_t unsigned long
+#else
 #define dev_t unsigned short
+#endif
+#endif
 #include <linux/loop.h>
 #undef dev_t
 #define dev_t dev_t
 #include <libintl.h>
 #include <libgen.h>
 #include <linux/major.h>
+#include <linux/raid/md_u.h>
+#include <linux/raid/md_p.h>
 #include <signal.h>
-#include <execinfo.h>
 
-#include "imount.h"
+#include <blkid/blkid.h>
+#include <blkid/blkid_types.h>
+
 #include "isys.h"
+#include "imount.h"
+#include "net.h"
 #include "smp.h"
 #include "lang.h"
+#include "wireless.h"
 #include "eddsupport.h"
 
 #ifndef CDROMEJECT
@@ -50,10 +81,8 @@ static PyObject * doGetOpt(PyObject * s, PyObject * args);
 static PyObject * doRmmod(PyObject * s, PyObject * args);*/
 static PyObject * doMount(PyObject * s, PyObject * args);
 static PyObject * doUMount(PyObject * s, PyObject * args);
-static PyObject * makeDevInode(PyObject * s, PyObject * args);
 static PyObject * smpAvailable(PyObject * s, PyObject * args);
 static PyObject * htAvailable(PyObject * s, PyObject * args);
-static PyObject * doCheckBoot(PyObject * s, PyObject * args);
 static PyObject * doSwapon(PyObject * s, PyObject * args);
 static PyObject * doSwapoff(PyObject * s, PyObject * args);
 static PyObject * doLoSetup(PyObject * s, PyObject * args);
@@ -62,7 +91,7 @@ static PyObject * doLoChangeFd(PyObject * s, PyObject * args);
 static PyObject * doDdFile(PyObject * s, PyObject * args);
 static PyObject * doDevSpaceFree(PyObject * s, PyObject * args);
 static PyObject * doLoadKeymap(PyObject * s, PyObject * args);
-static PyObject * doClobberExt2 (PyObject * s, PyObject * args);
+static PyObject * doClobberExt2(PyObject * s, PyObject * args);
 static PyObject * doReadE2fsLabel(PyObject * s, PyObject * args);
 static PyObject * doExt2Dirty(PyObject * s, PyObject * args);
 static PyObject * doExt2HasJournal(PyObject * s, PyObject * args);
@@ -72,11 +101,13 @@ static PyObject * doisPsudoTTY(PyObject * s, PyObject * args);
 static PyObject * doisVioConsole(PyObject * s);
 static PyObject * doSync(PyObject * s, PyObject * args);
 static PyObject * doisIsoImage(PyObject * s, PyObject * args);
+static PyObject * getFramebufferInfo(PyObject * s, PyObject * args);
 static PyObject * printObject(PyObject * s, PyObject * args);
 static PyObject * py_bind_textdomain_codeset(PyObject * o, PyObject * args);
+static PyObject * isWireless(PyObject * s, PyObject * args);
 static PyObject * doProbeBiosDisks(PyObject * s, PyObject * args);
-static PyObject * doGetBiosDisk(PyObject * s, PyObject * args); 
-static PyObject * doSegvHandler(PyObject *s, PyObject *args);
+static PyObject * doGetBiosDisk(PyObject * s, PyObject * args);
+static PyObject * doGetBlkidData(PyObject * s, PyObject * args);
 
 static PyMethodDef isysModuleMethods[] = {
     { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -94,7 +125,6 @@ static PyMethodDef isysModuleMethods[] = {
     { "smpavailable", (PyCFunction) smpAvailable, METH_VARARGS, NULL },
     { "htavailable", (PyCFunction) htAvailable, METH_VARARGS, NULL },
     { "umount", (PyCFunction) doUMount, METH_VARARGS, NULL },
-    { "checkBoot", (PyCFunction) doCheckBoot, METH_VARARGS, NULL },
     { "swapon",  (PyCFunction) doSwapon, METH_VARARGS, NULL },
     { "swapoff",  (PyCFunction) doSwapoff, METH_VARARGS, NULL },
     { "loadKeymap", (PyCFunction) doLoadKeymap, METH_VARARGS, NULL },
@@ -103,11 +133,13 @@ static PyMethodDef isysModuleMethods[] = {
     { "isVioConsole", (PyCFunction) doisVioConsole, METH_NOARGS, NULL},
     { "sync", (PyCFunction) doSync, METH_VARARGS, NULL},
     { "isisoimage", (PyCFunction) doisIsoImage, METH_VARARGS, NULL},
+    { "fbinfo", (PyCFunction) getFramebufferInfo, METH_VARARGS, NULL},
     { "printObject", (PyCFunction) printObject, METH_VARARGS, NULL},
     { "bind_textdomain_codeset", (PyCFunction) py_bind_textdomain_codeset, METH_VARARGS, NULL},
+    { "isWireless", (PyCFunction) isWireless, METH_VARARGS, NULL },
     { "biosDiskProbe", (PyCFunction) doProbeBiosDisks, METH_VARARGS,NULL},
     { "getbiosdisk",(PyCFunction) doGetBiosDisk, METH_VARARGS,NULL},
-    { "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL },
+    { "getblkid", (PyCFunction) doGetBlkidData, METH_VARARGS, NULL },
     { NULL, NULL, 0, NULL }
 } ;
 
@@ -355,25 +387,22 @@ static PyObject * doUMount(PyObject * s, PyObject * args) {
 }
 
 static PyObject * doMount(PyObject * s, PyObject * args) {
-    char * fs, * device, * mntpoint;
+    char *fs, *device, *mntpoint, *flags = NULL;
     int rc;
-    int readOnly = 0;
-    int bindMount = 0;
-    int reMount = 0;
-    int flags = 0;
-
-    if (!PyArg_ParseTuple(args, "sssiii", &fs, &device, &mntpoint,
-                         &readOnly, &bindMount, &reMount)) return NULL;
 
-    if (readOnly) flags |= IMOUNT_RDONLY; 
-    if (bindMount) flags |= IMOUNT_BIND;
-    if (reMount) flags |= IMOUNT_REMOUNT;
+    if (!PyArg_ParseTuple(args, "sss|z", &fs, &device, &mntpoint,
+                         &flags)) return NULL;
 
-    rc = doPwMount(device, mntpoint, fs, flags, NULL);
+    rc = doPwMount(device, mntpoint, fs, flags);
     if (rc == IMOUNT_ERR_ERRNO) 
        PyErr_SetFromErrno(PyExc_SystemError);
-    else if (rc)
-       PyErr_SetString(PyExc_SystemError, "mount failed");
+    else if (rc) {
+        PyObject *tuple = PyTuple_New(2);
+
+        PyTuple_SetItem(tuple, 0, PyInt_FromLong(rc));
+        PyTuple_SetItem(tuple, 1, PyString_FromString("mount failed"));
+        PyErr_SetObject(PyExc_SystemError, tuple);
+    }
 
     if (rc) return NULL;
 
@@ -384,37 +413,6 @@ static PyObject * doMount(PyObject * s, PyObject * args) {
 #define BOOT_SIGNATURE 0xaa55  /* boot signature */
 #define BOOT_SIG_OFFSET        510     /* boot signature offset */
 
-static PyObject * doCheckBoot (PyObject * s, PyObject * args) {
-    char * path;
-    int fd, size;
-    unsigned short magic;
-
-    /* code from LILO */
-    
-    if (!PyArg_ParseTuple(args, "s", &path)) return NULL;
-
-    if ((fd = open (path, O_RDONLY)) == -1) {
-       PyErr_SetFromErrno(PyExc_SystemError);
-       return NULL;
-    }
-
-    if (lseek(fd,(long) BOOT_SIG_OFFSET, 0) < 0) {
-       close (fd);
-       PyErr_SetFromErrno(PyExc_SystemError);
-       return NULL;
-    }
-    
-    if ((size = read(fd,(char *) &magic, 2)) != 2) {
-       close (fd);
-       PyErr_SetFromErrno(PyExc_SystemError);
-       return NULL;
-    }
-
-    close (fd);
-    
-    return Py_BuildValue("i", magic == BOOT_SIGNATURE);
-}
-
 int swapoff(const char * path);
 int swapon(const char * path, int priorty);
 
@@ -680,6 +678,39 @@ static PyObject * doisIsoImage(PyObject * s, PyObject * args) {
     return Py_BuildValue("i", rc);
 }
 
+static PyObject * getFramebufferInfo(PyObject * s, PyObject * args) {
+    int fd;
+    struct fb_var_screeninfo fb;
+
+    fd = open("/dev/fb0", O_RDONLY);
+    if (fd == -1) {
+       Py_INCREF(Py_None);
+       return Py_None;
+    }
+
+    if (ioctl(fd, FBIOGET_VSCREENINFO, &fb)) {
+       close(fd);
+       PyErr_SetFromErrno(PyExc_SystemError);
+       return NULL;
+    }
+
+    close(fd);
+
+    return Py_BuildValue("(iii)", fb.xres, fb.yres, fb.bits_per_pixel);
+}
+
+static PyObject * isWireless(PyObject * s, PyObject * args) {
+    char *dev;
+    int ret;
+
+    if (!PyArg_ParseTuple(args, "s", &dev))
+       return NULL;
+
+    ret = is_wireless_interface(dev);
+
+    return Py_BuildValue("i", ret);
+}
+
 static PyObject * printObject (PyObject * o, PyObject * args) {
     PyObject * obj;
     char buf[256];
@@ -729,23 +760,32 @@ static PyObject * doGetBiosDisk(PyObject * s, PyObject * args) {
     return Py_None;
 }
 
-static PyObject * doSegvHandler(PyObject *s, PyObject *args) {
-    void *array[20];
-    size_t size;
-    char **strings;
-    size_t i;
+static PyObject * doGetBlkidData(PyObject * s, PyObject * args) {
+    char * dev, * key;
+    blkid_cache cache;
+    blkid_dev bdev = NULL;
+    blkid_tag_iterate titer;
+    const char * type, * data;
+
+    if (!PyArg_ParseTuple(args, "ss", &dev, &key)) return NULL;
+
+    blkid_get_cache(&cache, NULL);
+
+    bdev = blkid_get_dev(cache, dev, BLKID_DEV_NORMAL);
+    if (bdev == NULL)
+        goto out;
+    titer = blkid_tag_iterate_begin(bdev);
+    while (blkid_tag_next(titer, &type, &data) >= 0) {
+        if (!strcmp(type, key)) {
+            blkid_tag_iterate_end(titer);
+            return Py_BuildValue("s", data);
+        }
+    }
+    blkid_tag_iterate_end(titer);
 
-    signal(SIGSEGV, SIG_DFL); /* back to default */
-    
-    size = backtrace (array, 20);
-    strings = backtrace_symbols (array, size);
-    
-    printf ("Anaconda received SIGSEGV!.  Backtrace:\n");
-    for (i = 0; i < size; i++)
-        printf ("%s\n", strings[i]);
-     
-    free (strings);
-    exit(1);
+ out:
+    Py_INCREF(Py_None);
+    return Py_None;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4: */
index 303fd27949444a57e16a04ca530e3a2614643e06..9f6a2bba75af5e1ceb6574beee7b0e1615b1a2ef 100644 (file)
@@ -1,10 +1,28 @@
+/*
+ * isys.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef H_ISYS
 #define H_ISYS
 
-#define MIN_RAM                                                32000
+#define MIN_RAM                        32000
 #define EARLY_SWAP_RAM         64000
 
-
 int insmod(char * modName, char * path, char ** args);
 int rmmod(char * modName);
 
index c8ace14f67ee9467b20d2698d061301c581ef621..6b5625ac6ab0802080ef9bccd13e211d50d28147 100644 (file)
@@ -1,18 +1,25 @@
 #
 # isys.py - installer utility functions and glue for C module
 #
-# Matt Wilson <msw@redhat.com>
-# Erik Troan <ewt@redhat.com>
-# Jeremy Katz <katzj@redhat.com>
+# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007  Red Hat, Inc.
+# All rights reserved.
 #
-# Copyright 2001 - 2004 Red Hat, Inc.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
 #
-# This software may be freely redistributed under the terms of the GNU
-# library public license.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU Library Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author(s): Matt Wilson <msw@redhat.com>
+#            Erik Troan <ewt@redhat.com>
+#            Jeremy Katz <katzj@redhat.com>
 #
 
 import _isys
@@ -23,15 +30,16 @@ import socket
 import stat
 import posix
 import sys
-import kudzu
 import inutil
 import warnings
 import resource
 import re
 import struct
+import minihal
 
 import logging
 log = logging.getLogger("pomona")
+import warnings
 
 mountCount = {}
 raidCount = {}
@@ -39,18 +47,16 @@ raidCount = {}
 MIN_RAM = _isys.MIN_RAM
 EARLY_SWAP_RAM = _isys.EARLY_SWAP_RAM
 
-def pathSpaceAvailable(path, fsystem = "ext2"):
-       return _isys.devSpaceFree(path)
-
-def spaceAvailable(device, fsystem = "ext2"):
-       mount(device, "/mnt/space", fstype = fsystem)
-       space = _isys.devSpaceFree("/mnt/space/.")
-       umount("/mnt/space")
-       return space
-
-def fsSpaceAvailable(fsystem):
-       return _isys.devSpaceFree(fsystem)
+## Get the amount of free space available under a directory path.
+# @param path The directory path to check.
+# @return The amount of free space available, in 
+def pathSpaceAvailable(path):
+    return _isys.devSpaceFree(path)
 
+## Set up an already existing device node to be used as a loopback device.
+# @param device The full path to a device node to set up as a loopback device.
+# @param file The file to mount as loopback on device.
+# @param readOnly Should this loopback device be used read-only?
 def losetup(device, file, readOnly = 0):
        if readOnly:
                mode = os.O_RDONLY
@@ -73,6 +79,8 @@ def lochangefd(device, file):
                os.close(loop)
                os.close(targ)
 
+## Disable a previously setup loopback device.
+# @param device The full path to an existing loopback device node.
 def unlosetup(device):
        loop = os.open(device, os.O_RDONLY)
        try:
@@ -82,11 +90,11 @@ def unlosetup(device):
 
 def ddfile(file, megs, pw = None):
        buf = '\x00' * (1024 * 256)
-       
+
        fd = os.open(file, os.O_RDWR | os.O_CREAT)
-       
+
        total = megs * 4            # we write out 1/4 of a meg each time through
-       
+
        if pw:
                (fn, title, text) = pw
                win = fn(title, text, total - 1)
@@ -101,31 +109,57 @@ def ddfile(file, megs, pw = None):
 
        os.close(fd)
 
-def mount(device, location, fstype = "ext2", readOnly = 0, bindMount = 0, remount = 0):
+## Mount a filesystem, similar to the mount system call.
+# @param device The device to mount.  If bindMount is 1, this should be an
+#               already mounted directory.  Otherwise, it should be a device
+#               name.
+# @param location The path to mount device on.
+# @param fstype The filesystem type on device.  This can be disk filesystems
+#               such as vfat or ext3, or pseudo filesystems such as proc or
+#               selinuxfs.
+# @param readOnly Should this filesystem be mounted readonly?
+# @param bindMount Is this a bind mount?  (see the mount(8) man page)
+# @param remount Are we mounting an already mounted filesystem?
+# @return The return value from the mount system call.
+def mount(device, location, fstype = "ext2", readOnly = 0, bindMount = 0, remount = 0, options = "defaults"):
+       flags = None
        location = os.path.normpath(location)
-       
+       opts = string.split(options)
+
        # We don't need to create device nodes for devices that start with '/'
        # (like '/usbdevfs') and also some special fake devices like 'proc'.
        # First try to make a device node and if that fails, assume we can
        # mount without making a device node.  If that still fails, the caller
        # will have to deal with the exception.
        # We note whether or not we created a node so we can clean up later.
-       if device and device != "none" and device[0] != "/":
-               devName = "/dev/%s" % device
-               device = devName
 
        if mountCount.has_key(location) and mountCount[location] > 0:
                mountCount[location] = mountCount[location] + 1
                return
 
-       log.debug("mounting %s --> %s" % (device, location))
-       rc = _isys.mount(fstype, device, location, readOnly, bindMount, remount)
+       if readOnly or bindMount or remount:
+               if readOnly:
+                       opts.append("ro")
+               if bindMount:
+                       opts.append("bind")
+               if remount:
+                       opts.append("remount")
+
+       flags = ",".join(opts)
+
+       log.debug("isys.py:mount()- going to mount %s on %s with options %s" %(device, location, flags))
+       rc = _isys.mount(fstype, device, location, flags)
 
        if not rc:
                mountCount[location] = 1
 
        return rc
 
+## Unmount a filesystem, similar to the umount system call.
+# @param what The directory to be unmounted.  This does not need to be the
+#             absolute path.
+# @param removeDir Should the mount point be removed after being unmounted?
+# @return The return value from the umount system call.
 def umount(what, removeDir = 1):
        what = os.path.normpath(what)
 
@@ -146,35 +180,37 @@ def umount(what, removeDir = 1):
 
        return rc
 
+## Get the SMP status of the system.
+# @return True if this is an SMP system, False otherwise.
 def smpAvailable():
        return _isys.smpavailable()
 
 htavailable = _isys.htavailable
 
-def chroot (path):
-       return os.chroot(path)
-
-def checkBoot (path):
-       return _isys.checkBoot(path)
-
+## Disable swap.
+# @param path The full path of the swap device to disable.
 def swapoff(path):
-       return _isys.swapoff(path)
+       return _isys.swapoff (path)
 
+## Enable swap.
+# @param path The full path of the swap device to enable.
 def swapon(path):
-       return _isys.swapon(path)
-
-def loadFont(): ### DO WE NEED THIS?
-       return _isys.loadFont()
+       return _isys.swapon (path)
 
+## Load a keyboard layout for text mode installs.
+# @param keymap The keyboard layout to load.  This must be one of the values
+#               from rhpl.KeyboardModels.
 def loadKeymap(keymap):
-       return _isys.loadKeymap(keymap)
-
-classMap = { "disk": kudzu.CLASS_HD,
-                                                "cdrom": kudzu.CLASS_CDROM,
-                                                "floppy": kudzu.CLASS_FLOPPY }
+       return _isys.loadKeymap (keymap)
 
 cachedDrives = None
 
+## Clear the drive dict cache.
+# This method clears the drive dict cache.  If the drive state changes (by
+# loading and unloading modules, attaching removable devices, etc.) then this
+# function must be called before any of the *DriveDict or *DriveList functions.
+# If not, those functions will return information that does not reflect the
+# current machine state.
 def flushDriveDict():
        global cachedDrives
        cachedDrives = None
@@ -183,75 +219,141 @@ def driveDict(klassArg):
        import parted
        global cachedDrives
        if cachedDrives is None:
-               devs = kudzu.probe(kudzu.CLASS_HD | kudzu.CLASS_CDROM | \
-                                                                                        kudzu.CLASS_FLOPPY,
-                                  kudzu.BUS_UNSPEC, kudzu.PROBE_SAFE)
                new = {}
-               for dev in devs:
-                       device = dev.device
-                       if device is None: # none devices make no sense
+               for dev in minihal.get_devices_by_type("storage"):
+                       if dev['device'] is None: # none devices make no sense
+                               continue
+
+                       device = dev['device'].replace('/dev/','')
+                       # we can't actually use the sg devices, so ignore them
+                       if device.startswith("sg"):
+                               log.info("ignoring sg device %s" %(device,))
+                               continue
+
+                       # we can't actually use the st devices, so ignore them
+                       if device.startswith("st"):
+                               log.info("ignoring st device %s" %(device,))
+                               continue
+
+                       # we want to ignore md devices as they're not hard disks in our pov
+                       if device.startswith("md"):
                                continue
-                       if dev.deviceclass != classMap["disk"]:
+
+                       if dev['storage.drive_type'] != 'disk':
                                new[device] = dev
                                continue
                        try:
-                               devName = "/dev/%s" % (device,)
-
                                if not mediaPresent(device):
                                        new[device] = dev
                                        continue
 
-                               #if device.startswith("sd"):
-                                       # XXX peddev = parted.PedDevice.get(devName)
-                                       model = peddev.model
-                                       # del peddev
-                               
+                               if device.startswith("sd"):
+                                       peddev = parted.PedDevice.get(dev['device'])
+                                       model = peddev.model
+
+                                       del peddev
                                new[device] = dev
                        except Exception, e:
-                               log.debug("exception checking disk blacklist on %s: %s" % (device, e))
+                               log.debug("exception checking disk blacklist on %s: %s" % \
+                                       (device, e))
                cachedDrives = new
 
        ret = {}
        for key,dev in cachedDrives.items():
-               # XXX these devices should have deviceclass attributes.  Or they
-               # should all be subclasses in a device tree and we should be able
-               # to use isinstance on all of them.  Not both.
-               #if isinstance(dev, block.MultiPath) or isinstance(dev, block.RaidSet):
-               #       if klassArg == "disk":
-               #               ret[key] = dev
-               #el
-               if dev.deviceclass == classMap[klassArg]:
-                       ret[key] = dev.desc
+               if dev['storage.drive_type'] == klassArg:
+                       ret[key] = dev
        return ret
 
+## Get all the hard drives attached to the system.
+# This method queries the drive dict cache for all hard drives.  If the cache
+# is empty, this will cause all disk devices to be probed.  If the status of
+# the devices has changed, flushDriveDict must be called first.
+#
+# @see flushDriveDict
+# @see driveDict
+# @return A dict of all the hard drive descriptions, keyed on device name.
 def hardDriveDict():
-       return driveDict("disk")
+       ret = {}
+       dict = driveDict("disk")
+       for item in dict.keys():
+               try:
+                       ret[item] = dict[item]['description']
+               except AttributeError:
+                       ret[item] = ""
+       return ret
 
-def floppyDriveDict():
-       return driveDict("floppy")
+## Get all the removable drives attached to the system.
+# This method queries the drive dict cache for all removable drives.  If the cache
+# is empty, this will cause all disk devices to be probed.  If the status of
+# the devices has changed, flushDriveDict must be run called first.
+#
+# @see flushDriveDict
+# @see driveDict
+# @return A dict of all the removable drive descriptions, keyed on device name.
+def removableDriveDict():
+       ret = {}
+       dict = driveDict("disk")
+       for item in dict.keys():
+               if dict[item]['storage.removable'] != 0:
+                       try:
+                               ret[item] = dict[item]['description']
+                       except AttributeError:
+                               ret[item] = ""
+       return ret
 
+## Get all CD/DVD drives attached to the system.
+# This method queries the drive dict cache for all hard drives.  If the cache
+# is empty, this will cause all disk devices to be probed.  If the status of
+# the devices has changed, flushDriveDict must be called first.
+#
+# @see flushDriveDict
+# @see driveDict
+# @return A sorted list of all the CD/DVD drives, without any leading /dev/.
 def cdromList():
        list = driveDict("cdrom").keys()
        list.sort()
        return list
 
-def makedev(major, minor):
-       return os.makedev(major, minor)
+## Get all tape drives attached to the system.
+# This method queries the drive dict cache for all hard drives.  If the cache
+# is empty, this will cause all disk devices to be probed.  If the status of
+# the devices has changed, flushDriveDict must be called first.
+#
+# @see flushDriveDict
+# @see driveDict
+# @return A sorted list of all the tape drives, without any leading /dev/.
+def tapeDriveList():
+       list = driveDict("tape").keys()
+       list.sort()
+       return list
+
+## Calculate the broadcast address of a network.
+# @param ip An IPv4 address as a string.
+# @param nm A corresponding netmask as a string.
+# @return A tuple of network address and broadcast address strings.
+def inet_calcNetBroad(ip, nm):
+       (ipaddr,) = struct.unpack('I', socket.inet_pton(socket.AF_INET, ip))
+       ipaddr = socket.ntohl(ipaddr)
+
+       (nmaddr,) = struct.unpack('I', socket.inet_pton(socket.AF_INET, nm))
+       nmaddr = socket.ntohl(nmaddr)
 
-def mknod(pathname, mode, dev):
-       return os.mknod(pathname, mode, dev)
+       netaddr = ipaddr & nmaddr
+       bcaddr = netaddr | (~nmaddr)
 
-def getopt(*args):
-       return apply(_isys.getopt, args)
+       nw = socket.inet_ntop(socket.AF_INET, struct.pack('!I', netaddr))
+       bc = socket.inet_ntop(socket.AF_INET, struct.pack('!I', bcaddr))
+
+       return (nw, bc)
 
 def doProbeBiosDisks():
+       if not iutil.isX86():
+               return None
        return _isys.biosDiskProbe()
 
 def doGetBiosDisk(mbrSig):
        return _isys.getbiosdisk(mbrSig)
 
-handleSegv = _isys.handleSegv
-
 biosdisks = {}
 for d in range(80, 80 + 15):
        disk = doGetBiosDisk("%d" %(d,))
@@ -268,31 +370,31 @@ def compareDrives(first, second):
                elif (one > two):
                        return 1
 
-               if first.startswith("hd"):
-                       type1 = 0
-               elif first.startswith("sd"):
-                       type1 = 1
-               elif first.startswith("xvd"):
-                       type1 = -1
-               else:
-                       type1 = 2
-
-               if second.startswith("hd"):
-                       type2 = 0
-               elif second.startswith("sd"):
-                       type2 = 1
-               elif second.startswith("xvd"):
-                       type2 = -1
-               else:
-                       type2 = 2
+       if first.startswith("hd"):
+               type1 = 0
+       elif first.startswith("sd"):
+               type1 = 1
+       elif (first.startswith("vd") or first.startswith("xvd")):
+               type1 = -1
+       else:
+               type1 = 2
+
+       if second.startswith("hd"):
+               type2 = 0
+       elif second.startswith("sd"):
+               type2 = 1
+       elif (second.startswith("vd") or second.startswith("xvd")):
+               type2 = -1
+       else:
+               type2 = 2
 
-               if (type1 < type2):
-                       return -1
-               elif (type1 > type2):
-                       return 1
-               else:
-                       len1 = len(first)
-                       len2 = len(second)
+       if (type1 < type2):
+               return -1
+       elif (type1 > type2):
+               return 1
+       else:
+               len1 = len(first)
+               len2 = len(second)
 
                if (len1 < len2):
                        return -1
@@ -306,128 +408,45 @@ def compareDrives(first, second):
 
        return 0
 
-def readXFSLabel_int(device):
-       try:
-               fd = os.open(device, os.O_RDONLY)
-       except:
-               return None
-       
-       try:
-               buf = os.read(fd, 128)
-               os.close(fd)
-       except OSError, e:
-               log.debug("error reading xfs label on %s: %s" %(device, e))
-               try:
-                       os.close(fd)
-               except:
-                       pass
-               return None
-       
-       xfslabel = None
-       if len(buf) == 128 and buf[0:4] == "XFSB":
-               xfslabel = string.rstrip(buf[108:120],"\0x00")
-       
-       return xfslabel
-    
-def readXFSLabel(device):
-       label = readXFSLabel_int(device)
-       return label
+def readFSUuid(device):
+       if not os.path.exists(device):
+               device = "/dev/%s" % device
 
-def readSwapLabel_int(device):
-       label = None
-       try:
-               fd = os.open(device, os.O_RDONLY)
-       except:
-               return label
-       
-       pagesize = resource.getpagesize()
-       try:
-               buf = os.read(fd, pagesize)
-               os.close(fd)
-       except OSError, e:
-               log.debug("error reading swap label on %s: %s" %(device, e))
-               try:
-                       os.close(fd)
-               except:
-                       pass
-               return label
-       
-       if ((len(buf) == pagesize) and (buf[pagesize - 10:] == "SWAPSPACE2")):
-               label = string.rstrip(buf[1052:1068], "\0x00")
+       label = _isys.getblkid(device, "UUID")
        return label
 
-def readSwapLabel(device):
-       label = readSwapLabel_int(device)
-       return label
+def readFSLabel(device):
+       if not os.path.exists(device):
+               device = "/dev/%s" % device
 
-def readExt2Label(device):
-       label = _isys.e2fslabel(device)
+       label = _isys.getblkid(device, "LABEL")
        return label
 
-def readReiserFSLabel_int(device):
-       label = None
-       
-       try:
-               fd = os.open(device, os.O_RDONLY)
-       except OSError, e:
-               log.debug("error opening device %s: %s" % (device, e))
-               return label
-
-       # valid block sizes in reiserfs are 512 - 8192, powers of 2
-       # we put 4096 first, since it's the default
-       # reiserfs superblock occupies either the 2nd or 16th block
-       for blksize in (4096, 512, 1024, 2048, 8192):
-               for start in (blksize, (blksize*16)):
+def readFSType(device):
+       if not os.path.exists(device):
+               device = "/dev/%s" % device
+
+       fstype = _isys.getblkid(device, "TYPE")
+       if fstype is None:
+               # FIXME: libblkid doesn't show physical volumes as having a filesystem
+               # so let's sniff for that.(#409321)
+               try:
+                       fd = os.open(device, os.O_RDONLY)
+                       buf = os.read(fd, 2048)
+               except:
+                       return fstype
+               finally:
                        try:
-                               os.lseek(fd, start, 0)
-                               # read 120 bytes to get s_magic and s_label
-                               buf = os.read(fd, 120)
-                               
-                               # see if this block is the superblock
-                               # this reads reiserfs_super_block_v1.s_magic as defined
-                               # in include/reiserfs_fs.h in the reiserfsprogs source
-                               m = string.rstrip(buf[52:61], "\0x00")
-                               if m == "ReIsErFs" or m == "ReIsEr2Fs" or m == "ReIsEr3Fs":
-                                       # this reads reiserfs_super_block.s_label as
-                                       # defined in include/reiserfs_fs.h
-                                       label = string.rstrip(buf[100:116], "\0x00")
-                                       os.close(fd)
-                                       return label
-                       except OSError, e:
-                               # [Error 22] probably means we're trying to read an
-                               # extended partition. 
-                               log.debug("error reading reiserfs label on %s: %s" %(device, e))
-                               
-                               try:
-                                       os.close(fd)
-                               except:
-                                       pass
-                               
-                               return label
-       
-       os.close(fd)
-       return label
+                               os.close(fd)
+                       except:
+                               pass
 
-def readReiserFSLabel(device):
-       label = readReiserFSLabel_int(device)
-       return label
 
-def readFSLabel(device):
-       if not device.startswith("/dev/"):
-               device = "/dev/%s" % device
-       
-       label = readExt2Label(device)
-       if label is None:
-               label = readSwapLabel(device)
-       if label is None:
-               label = readXFSLabel(device)
-       if label is None:
-               label = readReiserFSLabel(device)
-       return label
+       if fstype == "ext4":
+               return "ext4dev"
+       return fstype
 
 def ext2Clobber(device):
-       if not device.startswith("/dev/"):
-               device = "/dev/%s" % device
        _isys.e2fsclobber(device)
 
 def ext2IsDirty(device):
@@ -435,7 +454,7 @@ def ext2IsDirty(device):
        return label
 
 def ext2HasJournal(device):
-       hasjournal = _isys.e2hasjournal(device)
+       hasjournal = _isys.e2hasjournal(device);
        return hasjournal
 
 def ejectCdrom(device):
@@ -446,17 +465,18 @@ def ejectCdrom(device):
                _isys.ejectcdrom(fd)
        except SystemError, e:
                log.warning("error ejecting cdrom (%s): %s" %(device, e))
-       pass
+               pass
 
        os.close(fd)
 
 def driveUsesModule(device, modules):
        """Returns true if a drive is using a prticular module.  Only works
           for SCSI devices right now."""
+
        if not isinstance(modules, ().__class__) and not \
                        isinstance(modules, [].__class__):
                modules = [modules]
-        
+
        if device[:2] == "hd":
                return False
        rc = False
@@ -468,7 +488,7 @@ def driveUsesModule(device, modules):
                        try:
                                # each line has format of:  <device>  <module>
                                (sddev, sdmod) = string.split(l)
-                               
+
                                if sddev == device:
                                        if sdmod in modules:
                                                rc = True
@@ -477,13 +497,15 @@ def driveUsesModule(device, modules):
                                pass
        return rc
 
+## Check if a removable media drive (CD, USB key, etc.) has media present.
+# @param device The basename of the device node.
+# @return True if media is present in device, False otherwise.
 def mediaPresent(device):
        try:
                fd = os.open("/dev/%s" % device, os.O_RDONLY)
        except OSError, (errno, strerror):
                # error 123 = No medium found
                if errno == 123:
-                       log.debug("No medium found on %s" % device)
                        return False
                else:
                        return True
@@ -491,65 +513,123 @@ def mediaPresent(device):
                os.close(fd)
                return True
 
-def vtActivate (num):
+def vtActivate(num):
        _isys.vtActivate (num)
 
 def isPsudoTTY(fd):
-       return _isys.isPsudoTTY(fd)
+       return _isys.isPsudoTTY (fd)
 
+## Flush filesystem buffers.
 def sync():
        return _isys.sync ()
 
+## Determine if a file is an ISO image or not.
+# @param file The full path to a file to check.
+# @return True if ISO image, False otherwise.
 def isIsoImage(file):
        return _isys.isisoimage(file)
 
 def fbinfo():
        return _isys.fbinfo()
 
-def cdRwList():
-       if not os.access("/proc/sys/dev/cdrom/info", os.R_OK): return []
-       
-       f = open("/proc/sys/dev/cdrom/info", "r")
-       lines = f.readlines()
-       f.close()
-       
-       driveList = []
-       finalDict = {}
-       
-       for line in lines:
-               line = string.split(line, ':', 1)
-
-               if (line and line[0] == "drive name"):
-                       line = string.split(line[1])
-                       # no CDROM drives
-                       if not line:  return []
-
-                       for device in line:
-                               if device[0:2] == 'sr':
-                                       device = "scd" + device[2:]
-                                       driveList.append(device)
-                               elif ((line and line[0] == "Can write CD-R") or
-                                       (line and line[0] == "Can write CD-RW")):
-                                       line = string.split(line[1])
-                                       field = 0
-                                       for ability in line:
-                                               if ability == "1":
-                                                       finalDict[driveList[field]] = 1
-                                                       field = field + 1
-
-       l = finalDict.keys()
-       l.sort()
-       return l
-
-def ideCdRwList():
-       newList = []
-       for dev in cdRwList():
-               if dev[0:2] == 'hd': newList.append(dev)
-
-       return newList
-
-
-handleSegv = _isys.handleSegv
+## Determine whether a network device has a link present or not.
+# @param dev The network device to check.
+# @return True if there is a link, False if not or if dev is in an unknown
+#         state.
+def getLinkStatus(dev):
+       if dev == '' or dev is None:
+               return False
+
+       # getLinkStatus returns 1 for link, 0 for no link, -1 for unknown state
+       if _isys.getLinkStatus(dev) == 1:
+               return True
+       else:
+               return False
+
+## Get the MAC address for a network device.
+# @param dev The network device to check.
+# @return The MAC address for dev as a string, or None on error.
+def getMacAddress(dev):
+       return _isys.getMacAddress(dev)
+
+## Determine if a network device is a wireless device.
+# @param dev The network device to check.
+# @return True if dev is a wireless network device, False otherwise.
+def isWireless(dev):
+       return _isys.isWireless(dev)
+
+## Get the IP address for a network device.
+# @param dev The network device to check.
+# @see netlink_interfaces_ip2str
+# @return The IPv4 address for dev, or None on error.
+def getIPAddress(dev):
+       return _isys.getIPAddress(dev)
+
+## Get the correct context for a file from loaded policy.
+# @param fn The filename to query.
+def matchPathContext(fn):
+       return _isys.matchPathContext(fn)
+
+## Set the SELinux file context of a file
+# @param fn The filename to fix.
+# @param con The context to use.
+# @param instroot An optional root filesystem to look under for fn.
+def setFileContext(fn, con, instroot = '/'):
+       if con is not None and os.access("%s/%s" % (instroot, fn), os.F_OK):
+               return (_isys.setFileContext(fn, con, instroot) != 0)
+       return False
+
+## Restore the SELinux file context of a file to its default.
+# @param fn The filename to fix.
+# @param instroot An optional root filesystem to look under for fn.
+def resetFileContext(fn, instroot = '/'):
+       con = matchPathContext(fn)
+       if con:
+               return setFileContext(fn, con, instroot)
+       return False
+
+def prefix2netmask(prefix):
+       return _isys.prefix2netmask(prefix)
+
+def netmask2prefix (netmask):
+       prefix = 0
+
+       while prefix < 33:
+               if (prefix2netmask(prefix) == netmask):
+                       return prefix
+
+               prefix += 1
+
+       return prefix
+
+isPAE = None
+def isPaeAvailable():
+       global isPAE
+       if isPAE is not None:
+               return isPAE
+
+       isPAE = False
+       if not iutil.isX86():
+               return isPAE
+
+       try:
+               f = open("/proc/iomem", "r")
+               lines = f.readlines()
+               for line in lines:
+                       if line[0].isspace():
+                               continue
+                       start = line.split(' ')[0].split('-')[0]
+                       start = long(start, 16)
+
+                       if start > 0x100000000L:
+                               isPAE = True
+                               break
+
+               f.close()
+       except:
+               pass
+
+       return isPAE
 
 printObject = _isys.printObject
 bind_textdomain_codeset = _isys.bind_textdomain_codeset
index f378e9ccff54f91f70ba7323a787226e6819a23e..e16bf3acebf3c81e652f143e55b019773f046c91 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * lang.c
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <alloca.h>
 #include <errno.h>
 #include <fcntl.h>
 #include "lang.h"
 #include "stubs.h"
 
+int isysLoadFont(void) {
+    unsigned char font[65536];
+    struct console_font_op cfo;
+    unsigned short map[E_TABSZ];
+    struct unimapdesc d;
+    struct unimapinit u;
+    struct unipair desc[2048];
+    gzFile stream;
+    int rc;
+
+#if defined (__s390__) || defined (__s390x__)
+    return 0;
+#endif
+    stream = gunzip_open("/etc/screenfont.gz");
+    if (!stream)
+       return -EACCES;
+
+    gunzip_read(stream, &cfo, sizeof(cfo));
+    gunzip_read(stream, font, sizeof(font));
+    gunzip_read(stream, map, sizeof(map));
+    gunzip_read(stream, &d.entry_ct, sizeof(d.entry_ct));
+    d.entries = desc;
+    gunzip_read(stream, desc, d.entry_ct * sizeof(desc[0]));
+    gunzip_close(stream);
+
+    cfo.data = font;
+    cfo.op = KD_FONT_OP_SET;
+
+    rc = ioctl(1, KDFONTOP, &cfo);
+    if (rc) return rc;
+    rc = ioctl(1, PIO_UNIMAPCLR, &u);
+    if (rc) return rc;
+    rc = ioctl(1, PIO_UNIMAP, &d);
+    if (rc) return rc;
+    rc = ioctl(1, PIO_UNISCRNMAP, map);
+    if (rc) return rc;
+    /* activate the font map */
+    fprintf(stderr, "\033(K");
+    return 0;
+}
+
 int isysSetUnicodeKeymap(void) {
     int console;
+
+#if defined (__s390__) || defined (__s390x__)
+    return 0;
+#endif
     console = open("/dev/console", O_RDWR);
     if (console < 0)
        return -EACCES;
@@ -44,6 +108,9 @@ int loadKeymap(gzFile stream) {
     short keymap[NR_KEYS];
     struct stat sb;
 
+#if defined (__s390__) || defined (__s390x__)
+    return 0;
+#endif
     if (isVioConsole())
         return 0;
     if (!access("/proc/xen", R_OK)) /* xen can't load keymaps */
index 3929fdb1c0db58c5a4b606b41941798823755631..a08adbdb0e47b62db372d358b4ceecff58039521 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * lang.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef ISYS_LANG_H
 #define ISYS_LANG_H
 
@@ -18,6 +37,7 @@ struct kmapInfo {
 };
 
 int loadKeymap(gzFile stream);
+int isysLoadFont(void);
 int isysLoadKeymap(char * keymap);
 int isysSetUnicodeKeymap(void);
 
diff --git a/src/pomona/src/isys/linkdetect.c b/src/pomona/src/isys/linkdetect.c
new file mode 100644 (file)
index 0000000..84f77f8
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * linkdetect.c - simple link detection
+ *
+ * pulls code from mii-tool.c in net-toools and ethtool so
+ * that we can do everything that jgarzik says we should check
+ *
+ * Copyright (C) 2002, 2003  Red Hat, Inc.  All rights reserved.
+ * Portions Copyright (C) 2000 David A. Hinds -- dhinds@pcmcia.sourceforge.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Jeremy Katz <katzj@redhat.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <net/if.h>
+
+#include <linux/sockios.h>
+#include <linux/mii.h>
+#include <linux/ethtool.h>
+#include "net.h"
+
+static struct ifreq ifr;
+
+static int mdio_read(int skfd, int location)
+{
+    void *data = &ifr.ifr_data;
+    struct mii_ioctl_data *mii = data;
+    mii->reg_num = location;
+    if (ioctl(skfd, SIOCGMIIREG, &ifr) < 0) {
+#ifdef STANDALONE
+       fprintf(stderr, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name,
+               strerror(errno));
+#endif
+       return -1;
+    }
+    return mii->val_out;
+}
+
+/* we don't need writing right now */
+#if 0
+static void mdio_write(int skfd, int location, int value)
+{
+    struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data;
+    mii->reg_num = location;
+    mii->val_in = value;
+    if (ioctl(skfd, SIOCSMIIREG, &ifr) < 0) {
+#ifdef STANDALONE
+       fprintf(stderr, "SIOCSMIIREG on %s failed: %s\n", ifr.ifr_name,
+               strerror(errno));
+#endif
+    }
+}
+#endif
+
+
+
+static int get_mii_link_status(int sock) {
+    int i, mii_val[32];
+
+    if (ioctl(sock, SIOCGMIIPHY, &ifr) < 0) {
+       if (errno != ENODEV)
+#ifdef STANDALONE
+           fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n",
+                   ifr.ifr_name, strerror(errno));
+#endif
+       return -1;
+    }
+
+    /* Some bits in the BMSR are latched, but we can't rely on being
+       the only reader, so only the current values are meaningful */
+    mdio_read(sock, MII_BMSR);
+    for (i = 0; i < 8; i++)
+       mii_val[i] = mdio_read(sock, i);
+
+    if (mii_val[MII_BMCR] == 0xffff) {
+#ifdef STANDALONE
+       fprintf(stderr, "  No MII transceiver present!.\n");
+#endif
+       return -1;
+    }
+
+    if (mii_val[MII_BMSR] & BMSR_LSTATUS)
+        return 1;
+    else
+        return 0;
+}
+
+static int get_ethtool_link_status(int sock) {
+    struct ethtool_value edata;
+    int rc;
+
+    edata.cmd = ETHTOOL_GLINK;
+    ifr.ifr_data = (caddr_t)&edata;
+    rc = ioctl(sock, SIOCETHTOOL, &ifr);
+    if (rc == 0) {
+        return edata.data;
+    } else if (errno != EOPNOTSUPP) {
+#ifdef STANDALONE
+        fprintf(stderr, "Cannot get link status (%d): %s\n", errno, strerror(errno));
+#endif
+    }
+
+    return -1;
+}
+
+
+
+int get_link_status(char * devname) {
+    int sock, rc;
+
+    if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+#ifdef STANDALONE
+        fprintf(stderr, "Error creating socket: %s\n", strerror(errno));
+#endif
+        return -1;
+    }
+
+    /* Setup our control structures. */
+    memset(&ifr, 0, sizeof(ifr));
+    strcpy(ifr.ifr_name, devname);
+
+    /* check for link with both ethtool and mii registers.  ethtool is
+     * supposed to be the One True Way (tm), but it seems to not work
+     * with much yet :/ */
+
+    rc = get_ethtool_link_status(sock);
+#ifdef STANDALONE
+    printf("ethtool link status of %s is: %d\n", devname, rc);
+#endif
+    if (rc == 1) {
+        close(sock);
+        return 1;
+    }
+
+    rc = get_mii_link_status(sock);
+#ifdef STANDALONE
+    printf("MII link status of %s is: %d\n", devname, rc);
+#endif
+    if (rc == 1) {
+        close(sock);
+        return 1;
+    }
+
+    return 0;
+}
+
+#ifdef STANDALONE
+/* hooray for stupid test programs! */
+int main(int argc, char **argv) {
+    char * dev;
+
+    if (argc >= 2) 
+        dev = argv[1];
+    else
+        dev = strdup("eth0");
+
+    printf("link status of %s is %d\n", dev, get_link_status(dev));
+    return 0;
+}
+#endif
diff --git a/src/pomona/src/isys/mount.h b/src/pomona/src/isys/mount.h
deleted file mode 100644 (file)
index d70ccaf..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Please do not edit this file.
- * It was generated using rpcgen.
- */
-
-#ifndef _MOUNT_H_RPCGEN
-#define _MOUNT_H_RPCGEN
-
-#include <rpc/rpc.h>
-
-#define MNTPATHLEN 1024
-#define MNTNAMLEN 255
-#define FHSIZE 32
-
-typedef char fhandle[FHSIZE];
-#ifdef __cplusplus 
-extern "C" bool_t xdr_fhandle(XDR *, fhandle);
-#elif __STDC__ 
-extern  bool_t xdr_fhandle(XDR *, fhandle);
-#else /* Old Style C */ 
-bool_t xdr_fhandle();
-#endif /* Old Style C */ 
-
-
-struct fhstatus {
-       u_int fhs_status;
-       union {
-               fhandle fhs_fhandle;
-       } fhstatus_u;
-};
-typedef struct fhstatus fhstatus;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_fhstatus(XDR *, fhstatus*);
-#elif __STDC__ 
-extern  bool_t xdr_fhstatus(XDR *, fhstatus*);
-#else /* Old Style C */ 
-bool_t xdr_fhstatus();
-#endif /* Old Style C */ 
-
-
-typedef char *dirpath;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_dirpath(XDR *, dirpath*);
-#elif __STDC__ 
-extern  bool_t xdr_dirpath(XDR *, dirpath*);
-#else /* Old Style C */ 
-bool_t xdr_dirpath();
-#endif /* Old Style C */ 
-
-
-typedef char *name;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_name(XDR *, name*);
-#elif __STDC__ 
-extern  bool_t xdr_name(XDR *, name*);
-#else /* Old Style C */ 
-bool_t xdr_name();
-#endif /* Old Style C */ 
-
-
-typedef struct mountbody *mountlist;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_mountlist(XDR *, mountlist*);
-#elif __STDC__ 
-extern  bool_t xdr_mountlist(XDR *, mountlist*);
-#else /* Old Style C */ 
-bool_t xdr_mountlist();
-#endif /* Old Style C */ 
-
-
-struct mountbody {
-       name ml_hostname;
-       dirpath ml_directory;
-       mountlist ml_next;
-};
-typedef struct mountbody mountbody;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_mountbody(XDR *, mountbody*);
-#elif __STDC__ 
-extern  bool_t xdr_mountbody(XDR *, mountbody*);
-#else /* Old Style C */ 
-bool_t xdr_mountbody();
-#endif /* Old Style C */ 
-
-
-typedef struct groupnode *groups;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_groups(XDR *, groups*);
-#elif __STDC__ 
-extern  bool_t xdr_groups(XDR *, groups*);
-#else /* Old Style C */ 
-bool_t xdr_groups();
-#endif /* Old Style C */ 
-
-
-struct groupnode {
-       name gr_name;
-       groups gr_next;
-};
-typedef struct groupnode groupnode;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_groupnode(XDR *, groupnode*);
-#elif __STDC__ 
-extern  bool_t xdr_groupnode(XDR *, groupnode*);
-#else /* Old Style C */ 
-bool_t xdr_groupnode();
-#endif /* Old Style C */ 
-
-
-typedef struct exportnode *exports;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_exports(XDR *, exports*);
-#elif __STDC__ 
-extern  bool_t xdr_exports(XDR *, exports*);
-#else /* Old Style C */ 
-bool_t xdr_exports();
-#endif /* Old Style C */ 
-
-
-struct exportnode {
-       dirpath ex_dir;
-       groups ex_groups;
-       exports ex_next;
-};
-typedef struct exportnode exportnode;
-#ifdef __cplusplus 
-extern "C" bool_t xdr_exportnode(XDR *, exportnode*);
-#elif __STDC__ 
-extern  bool_t xdr_exportnode(XDR *, exportnode*);
-#else /* Old Style C */ 
-bool_t xdr_exportnode();
-#endif /* Old Style C */ 
-
-
-#define MOUNTPROG ((u_long)100005)
-#define MOUNTVERS ((u_long)1)
-
-#ifdef __cplusplus
-#define MOUNTPROC_NULL ((u_long)0)
-extern "C" void * mountproc_null_1(void *, CLIENT *);
-extern "C" void * mountproc_null_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_MNT ((u_long)1)
-extern "C" fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
-extern "C" fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
-#define MOUNTPROC_DUMP ((u_long)2)
-extern "C" mountlist * mountproc_dump_1(void *, CLIENT *);
-extern "C" mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_UMNT ((u_long)3)
-extern "C" void * mountproc_umnt_1(dirpath *, CLIENT *);
-extern "C" void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
-#define MOUNTPROC_UMNTALL ((u_long)4)
-extern "C" void * mountproc_umntall_1(void *, CLIENT *);
-extern "C" void * mountproc_umntall_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_EXPORT ((u_long)5)
-extern "C" exports * mountproc_export_1(void *, CLIENT *);
-extern "C" exports * mountproc_export_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_EXPORTALL ((u_long)6)
-extern "C" exports * mountproc_exportall_1(void *, CLIENT *);
-extern "C" exports * mountproc_exportall_1_svc(void *, struct svc_req *);
-
-#elif __STDC__
-#define MOUNTPROC_NULL ((u_long)0)
-extern  void * mountproc_null_1(void *, CLIENT *);
-extern  void * mountproc_null_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_MNT ((u_long)1)
-extern  fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
-extern  fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
-#define MOUNTPROC_DUMP ((u_long)2)
-extern  mountlist * mountproc_dump_1(void *, CLIENT *);
-extern  mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_UMNT ((u_long)3)
-extern  void * mountproc_umnt_1(dirpath *, CLIENT *);
-extern  void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
-#define MOUNTPROC_UMNTALL ((u_long)4)
-extern  void * mountproc_umntall_1(void *, CLIENT *);
-extern  void * mountproc_umntall_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_EXPORT ((u_long)5)
-extern  exports * mountproc_export_1(void *, CLIENT *);
-extern  exports * mountproc_export_1_svc(void *, struct svc_req *);
-#define MOUNTPROC_EXPORTALL ((u_long)6)
-extern  exports * mountproc_exportall_1(void *, CLIENT *);
-extern  exports * mountproc_exportall_1_svc(void *, struct svc_req *);
-
-#else /* Old Style C */ 
-#define MOUNTPROC_NULL ((u_long)0)
-extern  void * mountproc_null_1();
-extern  void * mountproc_null_1_svc();
-#define MOUNTPROC_MNT ((u_long)1)
-extern  fhstatus * mountproc_mnt_1();
-extern  fhstatus * mountproc_mnt_1_svc();
-#define MOUNTPROC_DUMP ((u_long)2)
-extern  mountlist * mountproc_dump_1();
-extern  mountlist * mountproc_dump_1_svc();
-#define MOUNTPROC_UMNT ((u_long)3)
-extern  void * mountproc_umnt_1();
-extern  void * mountproc_umnt_1_svc();
-#define MOUNTPROC_UMNTALL ((u_long)4)
-extern  void * mountproc_umntall_1();
-extern  void * mountproc_umntall_1_svc();
-#define MOUNTPROC_EXPORT ((u_long)5)
-extern  exports * mountproc_export_1();
-extern  exports * mountproc_export_1_svc();
-#define MOUNTPROC_EXPORTALL ((u_long)6)
-extern  exports * mountproc_exportall_1();
-extern  exports * mountproc_exportall_1_svc();
-#endif /* Old Style C */ 
-
-#endif /* !_MOUNT_H_RPCGEN */
diff --git a/src/pomona/src/isys/mount_clnt.c b/src/pomona/src/isys/mount_clnt.c
deleted file mode 100644 (file)
index bc6e512..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Please do not edit this file.
- * It was generated using rpcgen.
- */
-
-#include <memory.h> /* for memset */
-#include "mount.h"
-
-/* Default timeout can be changed using clnt_control() */
-static struct timeval TIMEOUT = { 25, 0 };
-
-void *
-mountproc_null_1(void *argp, CLIENT *clnt)
-{
-       static char clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_NULL, xdr_void, argp, xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return ((void *)&clnt_res);
-}
-
-fhstatus *
-mountproc_mnt_1(dirpath *argp, CLIENT *clnt)
-{
-       static fhstatus clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_MNT, xdr_dirpath, argp, xdr_fhstatus, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return (&clnt_res);
-}
-
-mountlist *
-mountproc_dump_1(void *argp, CLIENT *clnt)
-{
-       static mountlist clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_DUMP, xdr_void, argp, xdr_mountlist, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return (&clnt_res);
-}
-
-void *
-mountproc_umnt_1(dirpath *argp, CLIENT *clnt)
-{
-       static char clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_UMNT, xdr_dirpath, argp, xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return ((void *)&clnt_res);
-}
-
-void *
-mountproc_umntall_1(void *argp, CLIENT *clnt)
-{
-       static char clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_UMNTALL, xdr_void, argp, xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return ((void *)&clnt_res);
-}
-
-exports *
-mountproc_export_1(void *argp, CLIENT *clnt)
-{
-       static exports clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_EXPORT, xdr_void, argp, xdr_exports, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return (&clnt_res);
-}
-
-exports *
-mountproc_exportall_1(void *argp, CLIENT *clnt)
-{
-       static exports clnt_res;
-
-       memset((char *)&clnt_res, 0, sizeof(clnt_res));
-       if (clnt_call(clnt, MOUNTPROC_EXPORTALL, xdr_void, argp, xdr_exports, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
-               return (NULL);
-       }
-       return (&clnt_res);
-}
diff --git a/src/pomona/src/isys/mount_constants.h b/src/pomona/src/isys/mount_constants.h
deleted file mode 100644 (file)
index 5f03345..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#define MS_RDONLY       1      /* Mount read-only */
-#define MS_NOSUID       2      /* Ignore suid and sgid bits */
-#define MS_NODEV        4      /* Disallow access to device special files */
-#define MS_NOEXEC       8      /* Disallow program execution */
-#define MS_SYNCHRONOUS 16      /* Writes are synced at once */
-#define MS_REMOUNT     32      /* Alter flags of a mounted FS */
-#define MS_MANDLOCK    64      /* Allow mandatory locks on an FS */
-#define MS_NOATIME     1024    /* Do not update access times. */
-#define MS_NODIRATIME   2048    /* Do not update directory access times */
-/*
- * Magic mount flag number. Has to be or-ed to the flag values.
- */
-#ifndef MS_MGC_VAL
-#define MS_MGC_VAL 0xC0ED0000  /* magic flag number to indicate "new" flags */
-#endif
-#define MS_MGC_MSK 0xffff0000  /* magic flag number mask */
diff --git a/src/pomona/src/isys/mount_svc.c b/src/pomona/src/isys/mount_svc.c
deleted file mode 100644 (file)
index 30be5ca..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Please do not edit this file.
- * It was generated using rpcgen.
- */
-
-#include "mount.h"
-#include <stdio.h>
-#include <stdlib.h>/* getenv, exit */
-#include <rpc/pmap_clnt.h> /* for pmap_unset */
-#include <string.h> /* strcmp */ 
-#include <memory.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#ifdef __STDC__
-#define SIG_PF void(*)(int)
-#endif
-
-static void
-mountprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
-{
-       union {
-               dirpath mountproc_mnt_1_arg;
-               dirpath mountproc_umnt_1_arg;
-       } argument;
-       char *result;
-       xdrproc_t xdr_argument, xdr_result;
-       char *(*local)(char *, struct svc_req *);
-
-       switch (rqstp->rq_proc) {
-       case MOUNTPROC_NULL:
-               xdr_argument = (xdrproc_t) xdr_void;
-               xdr_result = (xdrproc_t) xdr_void;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_null_1_svc;
-               break;
-
-       case MOUNTPROC_MNT:
-               xdr_argument = (xdrproc_t) xdr_dirpath;
-               xdr_result = (xdrproc_t) xdr_fhstatus;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_mnt_1_svc;
-               break;
-
-       case MOUNTPROC_DUMP:
-               xdr_argument = (xdrproc_t) xdr_void;
-               xdr_result = (xdrproc_t) xdr_mountlist;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_dump_1_svc;
-               break;
-
-       case MOUNTPROC_UMNT:
-               xdr_argument = (xdrproc_t) xdr_dirpath;
-               xdr_result = (xdrproc_t) xdr_void;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_umnt_1_svc;
-               break;
-
-       case MOUNTPROC_UMNTALL:
-               xdr_argument = (xdrproc_t) xdr_void;
-               xdr_result = (xdrproc_t) xdr_void;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_umntall_1_svc;
-               break;
-
-       case MOUNTPROC_EXPORT:
-               xdr_argument = (xdrproc_t) xdr_void;
-               xdr_result = (xdrproc_t) xdr_exports;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_export_1_svc;
-               break;
-
-       case MOUNTPROC_EXPORTALL:
-               xdr_argument = (xdrproc_t) xdr_void;
-               xdr_result = (xdrproc_t) xdr_exports;
-               local = (char *(*)(char *, struct svc_req *)) mountproc_exportall_1_svc;
-               break;
-
-       default:
-               svcerr_noproc(transp);
-               return;
-       }
-       (void) memset((char *)&argument, 0, sizeof (argument));
-       if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
-               svcerr_decode(transp);
-               return;
-       }
-       result = (*local)((char *)&argument, rqstp);
-       if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
-               svcerr_systemerr(transp);
-       }
-       if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
-               fprintf(stderr, "unable to free arguments");
-               exit(1);
-       }
-       return;
-}
-
-int
-main(int argc, char **argv)
-{
-       register SVCXPRT *transp;
-
-       (void) pmap_unset(MOUNTPROG, MOUNTVERS);
-
-       transp = svcudp_create(RPC_ANYSOCK);
-       if (transp == NULL) {
-               fprintf(stderr, "cannot create udp service.");
-               exit(1);
-       }
-       if (!svc_register(transp, MOUNTPROG, MOUNTVERS, mountprog_1, IPPROTO_UDP)) {
-               fprintf(stderr, "unable to register (MOUNTPROG, MOUNTVERS, udp).");
-               exit(1);
-       }
-
-       transp = svctcp_create(RPC_ANYSOCK, 0, 0);
-       if (transp == NULL) {
-               fprintf(stderr, "cannot create tcp service.");
-               exit(1);
-       }
-       if (!svc_register(transp, MOUNTPROG, MOUNTVERS, mountprog_1, IPPROTO_TCP)) {
-               fprintf(stderr, "unable to register (MOUNTPROG, MOUNTVERS, tcp).");
-               exit(1);
-       }
-
-       svc_run();
-       fprintf(stderr, "svc_run returned");
-       exit(1);
-       /* NOTREACHED */
-}
diff --git a/src/pomona/src/isys/mount_xdr.c b/src/pomona/src/isys/mount_xdr.c
deleted file mode 100644 (file)
index 542a7ef..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Please do not edit this file.
- * It was generated using rpcgen.
- */
-
-#include "mount.h"
-
-bool_t
-xdr_fhandle(XDR *xdrs, fhandle objp)
-{
-        if (!xdr_opaque(xdrs, objp, FHSIZE)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_fhstatus(XDR *xdrs, fhstatus *objp)
-{
-
-        if (!xdr_u_int(xdrs, &objp->fhs_status)) {
-                return (FALSE);
-        }
-       switch (objp->fhs_status) {
-       case 0:
-                if (!xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle)) {
-                        return (FALSE);
-                }
-               break;
-       default:
-               break;
-       }
-       return (TRUE);
-}
-
-bool_t
-xdr_dirpath(XDR *xdrs, dirpath *objp)
-{
-
-        if (!xdr_string(xdrs, objp, MNTPATHLEN)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_name(XDR *xdrs, name *objp)
-{
-
-        if (!xdr_string(xdrs, objp, MNTNAMLEN)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_mountlist(XDR *xdrs, mountlist *objp)
-{
-
-        if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), (xdrproc_t)xdr_mountbody)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_mountbody(XDR *xdrs, mountbody *objp)
-{
-
-        if (!xdr_name(xdrs, &objp->ml_hostname)) {
-                return (FALSE);
-        }
-        if (!xdr_dirpath(xdrs, &objp->ml_directory)) {
-                return (FALSE);
-        }
-        if (!xdr_mountlist(xdrs, &objp->ml_next)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_groups(XDR *xdrs, groups *objp)
-{
-
-        if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), (xdrproc_t)xdr_groupnode)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_groupnode(XDR *xdrs, groupnode *objp)
-{
-
-        if (!xdr_name(xdrs, &objp->gr_name)) {
-                return (FALSE);
-        }
-        if (!xdr_groups(xdrs, &objp->gr_next)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_exports(XDR *xdrs, exports *objp)
-{
-
-        if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), (xdrproc_t)xdr_exportnode)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
-
-bool_t
-xdr_exportnode(XDR *xdrs, exportnode *objp)
-{
-
-        if (!xdr_dirpath(xdrs, &objp->ex_dir)) {
-                return (FALSE);
-        }
-        if (!xdr_groups(xdrs, &objp->ex_groups)) {
-                return (FALSE);
-        }
-        if (!xdr_exports(xdrs, &objp->ex_next)) {
-                return (FALSE);
-        }
-       return (TRUE);
-}
diff --git a/src/pomona/src/isys/net.h b/src/pomona/src/isys/net.h
new file mode 100644 (file)
index 0000000..4f7e65c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * net.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ISYSNET_H
+#define ISYSNET_H
+
+#include <linux/types.h>
+#include <linux/ethtool.h>
+
+/* type definitions so that the kernel-ish includes can be shared */
+#ifndef uint8_t
+#  define uint8_t       unsigned char
+#endif
+#ifndef uint16_t
+#  define uint16_t      unsigned short int
+#endif
+#ifndef uint32_t
+#  define uint32_t      unsigned int
+#endif
+#ifndef uint64_t
+#  define uint64_t      unsigned long long int
+#endif
+typedef uint64_t u64;
+typedef uint32_t u32;
+typedef uint16_t u16;
+typedef uint8_t u8;
+
+/* returns 1 for link, 0 for no link, -1 for unknown */
+int get_link_status(char *ifname);
+
+typedef enum ethtool_speed_t { ETHTOOL_SPEED_UNSPEC = -1, 
+                               ETHTOOL_SPEED_10 = SPEED_10, 
+                               ETHTOOL_SPEED_100 = SPEED_100,
+                               ETHTOOL_SPEED_1000 = SPEED_1000 } ethtool_speed;
+typedef enum ethtool_duplex_t { ETHTOOL_DUPLEX_UNSPEC = -1, 
+                                ETHTOOL_DUPLEX_HALF = DUPLEX_HALF,
+                                ETHTOOL_DUPLEX_FULL = DUPLEX_FULL } ethtool_duplex;
+
+/* set ethtool settings */
+int setEthtoolSettings(char * dev, ethtool_speed speed, ethtool_duplex duplex);
+
+#endif
index fcf4c47ac52139ec0c9958ffc5b29eeb1dae6055..44f5677330b4ecec1e60a9df3723c2278c6801a3 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * smp.c
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 /*
 [_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
@@ -40,7 +59,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *      $Id: smp.c,v 1.29 2006/06/26 15:01:37 pjones Exp $
+ *      $Id$
  */
 
 /*
@@ -145,9 +164,7 @@ static int     pfd;            /* physical /dev/mem fd */
 static int     verbose = 0;
 static int     grope = 0;
 
-static int
-readType()
-{
+static int readType() {
     u_char      type;
 
     if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) ) {
@@ -169,8 +186,7 @@ readType()
 
 #define MODE_SMP_CHECK 1
 
-static int groupForSMP(int mode)
-{
+static int groupForSMP(int mode) {
     vm_offset_t paddr;
     int         where;
     mpfps_t     mpfps;
@@ -233,8 +249,7 @@ static int groupForSMP(int mode)
  */
 #define NEXT(X)         ((X) += 4)
 static void
-apic_probe( vm_offset_t* paddr, int* where )
-{
+apic_probe( vm_offset_t* paddr, int* where ) {
     /*
      * c rewrite of apic_probe() by Jack F. Vogel
      */
@@ -385,26 +400,20 @@ apic_probe( vm_offset_t* paddr, int* where )
     *paddr = (vm_offset_t)0;
 }
 
-
 /*
  *
  */
-static int
-seekEntry( vm_offset_t addr )
-{
+static int seekEntry( vm_offset_t addr ) {
     if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 ) {
         return 1;
     }
     return 0;
 }
 
-
 /*
  *
  */
-static void
-readEntry( void* entry, int size )
-{
+static void readEntry( void* entry, int size ) {
     if ( read( pfd, entry, size ) != size ) {
         return;
         perror( "readEntry" );
@@ -412,15 +421,13 @@ readEntry( void* entry, int size )
     }
 }
 
-static int intelDetectSMP(void)
-{
+static int intelDetectSMP(void) {
     return groupForSMP(MODE_SMP_CHECK);
 }
 
 /* ---- end mptable mess ---- */
 
-static inline unsigned int cpuid_ebx(int op)
-{
+static inline unsigned int cpuid_ebx(int op) {
     unsigned int eax, ebx;
 
     __asm__("pushl %%ebx; cpuid; movl %%ebx,%1; popl %%ebx"
@@ -432,8 +439,7 @@ static inline unsigned int cpuid_ebx(int op)
 
 /* XXX: rewrite using /proc/cpuinfo info if it there.  Only fall
    back to inline asm if it is not */
-int detectHT(void)
-{
+int detectHT(void) {
     FILE *f;
     int htflag = 0;
     uint32_t ebx = 0;
@@ -472,7 +478,11 @@ int detectSMP(void)
     static int isSMP = -1;
 
     if (isSMP != -1)
-                       return isSMP;
+       return isSMP;
 
-  return isSMP = intelDetectSMP();
+#if defined (__i386__)
+    return isSMP = intelDetectSMP();
+#else
+    #error unknown architecture
+#endif
 }
index e03726826f25d12b56ac03e0d1afd9cd6bfb560f..651fa3335c8d67acd1b544a95d1af7a4cd1ed8f7 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * smp.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef SMP_H
 #define SMP_H
 
index 4508b116d93b02b8d5eda88ad07961e48d2267dd..cf0547391ccc848f0584d7a34e4893b056235dfe 100644 (file)
@@ -1,16 +1,22 @@
 /*
  * str.c - String helper functions that don't need string.h or ctype.h
  *
- * Copyright 2006 Red Hat, Inc.
+ * Copyright (C) 2006  Red Hat, Inc.  All rights reserved.
  *
- * David Cantrell <dcantrell@redhat.com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This software may be freely redistributed under the terms of the GNU
- * general public license.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
  * 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.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): David Cantrell <dcantrell@redhat.com>
  */
 
 #include <stdio.h>
index d5910fe457b0a8507e8dc694ad4c9ede5d3e6db6..d29602153daa3026c3feb427b5981312d0dfb900 100644 (file)
@@ -1,16 +1,22 @@
 /*
  * str.c - String helper functions, the header file
  *
- * Copyright 2006 Red Hat, Inc.
+ * Copyright (C) 2006  Red Hat, Inc.  All rights reserved.
  *
- * David Cantrell <dcantrell@redhat.com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This software may be freely redistributed under the terms of the GNU
- * general public license.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
  * 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.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): David Cantrell <dcantrell@redhat.com>
  */
 
 /* Function prototypes */
index 9e8ee4ce1d540e4b1120680083a64ff867ef0248..40ecb22ac13da1ed5c38fb925ae7b2184603333b 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * stubs.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 /* we use gzlib when linked against dietlibc, but otherwise, we should use
    zlib.  it would make more sense to do the defines in the other direction, 
    but that causes symbol wackiness because both gunzip_open and gzip_open in
diff --git a/src/pomona/src/isys/sundries.h b/src/pomona/src/isys/sundries.h
deleted file mode 100644 (file)
index ee2aeb4..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * sundries.h
- * Support function prototypes.  Functions are in sundries.c.
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#if !defined(bool_t) && !defined(__GLIBC__)
-#include <rpc/types.h>
-#endif
-
-extern int mount_quiet;
-extern int verbose;
-extern int sloppy;
-
-#define streq(s, t)    (strcmp ((s), (t)) == 0)
-
-
-/* String list data structure.  */ 
-typedef struct string_list
-{
-  char *hd;
-  struct string_list *tl;
-} *string_list;
-
-#define car(p) ((p) -> hd)
-#define cdr(p) ((p) -> tl)
-
-string_list cons (char *a, const string_list);
-
-/* Functions in sundries.c that are used in mount.c and umount.c  */ 
-void block_signals (int how);
-char *canonicalize (const char *path);
-char *realpath (const char *path, char *resolved_path);
-void error (const char *fmt, ...);
-int matching_type (const char *type, string_list types);
-string_list parse_list (char *strings);
-void *xmalloc (size_t size);
-char *xstrdup (const char *s);
-char *xstrndup (const char *s, int n);
-char *xstrconcat2 (const char *, const char *);
-char *xstrconcat3 (const char *, const char *, const char *);
-char *xstrconcat4 (const char *, const char *, const char *, const char *);
-
-/* Here is some serious cruft.  */
-#ifdef __GNUC__
-#if __GNUC__ > 2 || (defined(__GNUC_MINOR__) && __GNUC__ == 2 && __GNUC_MINOR__ >= 5)
-void die (int errcode, const char *fmt, ...) __attribute__ ((noreturn));
-#else /* GNUC < 2.5 */
-void volatile die (int errcode, const char *fmt, ...);
-#endif /* GNUC < 2.5 */
-#else /* !__GNUC__ */
-void die (int errcode, const char *fmt, ...);
-#endif /* !__GNUC__ */
-
-/* exit status - bits below are ORed */
-#define EX_USAGE       1       /* incorrect invocation or permission */
-#define EX_SYSERR      2       /* out of memory, cannot fork, ... */
-#define EX_SOFTWARE    4       /* internal mount bug or wrong version */
-#define EX_USER                8       /* user interrupt */
-#define EX_FILEIO      16      /* problems writing, locking, ... mtab/fstab */
-#define EX_FAIL               32       /* mount failure */
-#define EX_SOMEOK      64      /* some mount succeeded */
-
-#define EX_BG         256       /* retry in background (internal only) */
diff --git a/src/pomona/src/isys/uncpio.c b/src/pomona/src/isys/uncpio.c
deleted file mode 100644 (file)
index d27979b..0000000
+++ /dev/null
@@ -1,779 +0,0 @@
-#define HAVE_ALLOCA_H 1
-#define MAJOR_IN_SYSMACROS 1
-
-#if HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-
-#define _(foo) (foo)
-
-#include <errno.h>
-#include <fcntl.h>
-#include <fnmatch.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <utime.h>
-
-#include "cpio.h"
-#include "stubs.h"
-
-#if MAJOR_IN_SYSMACROS 
-#include <sys/sysmacros.h>
-#elif MAJOR_IN_MKDEV 
-#include <sys/mkdev.h>
-#endif
-
-#define CPIO_NEWC_MAGIC        "070701"
-#define CPIO_CRC_MAGIC "070702"
-#define TRAILER                "TRAILER!!!"
-
-/* FIXME: We don't translate between cpio and system mode bits! These
-   should both be the same, but really odd things are going to happen if
-   that's not true! */
-
-/* We need to maintain our oun file pointer to allow padding */
-struct ourfd {
-    gzFile fd;
-    size_t pos;
-};
-
-struct hardLink {
-    struct hardLink * next;
-    char ** files;             /* there are nlink of these, used by install */
-    int * fileMaps;            /* used by build */
-    dev_t dev;
-    ino_t inode;
-    int nlink;                 
-    int linksLeft;
-    int createdPath;
-    struct stat sb;
-};
-
-struct cpioCrcPhysicalHeader {
-    char magic[6];
-    char inode[8];
-    char mode[8];
-    char uid[8];
-    char gid[8];
-    char nlink[8];
-    char mtime[8];
-    char filesize[8];
-    char devMajor[8];
-    char devMinor[8];
-    char rdevMajor[8];
-    char rdevMinor[8];
-    char namesize[8];
-    char checksum[8];                  /* ignored !! */
-};
-
-#define PHYS_HDR_SIZE  110             /* don't depend on sizeof(struct) */
-
-struct cpioHeader {
-    ino_t inode;
-    mode_t mode;
-    uid_t uid;
-    gid_t gid;
-    int nlink;
-    time_t mtime;
-    unsigned long size;
-    dev_t dev, rdev;
-    char * path;
-};
-
-static inline off_t ourread(struct ourfd * thefd, void * buf, size_t size) {
-    off_t i;
-
-    i = gunzip_read(thefd->fd, buf, size);
-    thefd->pos += i;
-    
-    return i;
-}
-
-static inline void padinfd(struct ourfd * fd, int modulo) {
-    int buf[10];
-    int amount;
-    
-    amount = (modulo - fd->pos % modulo) % modulo;
-    ourread(fd, buf, amount);
-}
-
-static inline int padoutfd(struct ourfd * fd, size_t * where, int modulo) {
-    /*static int buf[10] = { '\0', '\0', '\0', '\0', '\0', 
-                          '\0', '\0', '\0', '\0', '\0' };*/
-    int amount;
-    static int buf[512];
-
-    amount = (modulo - *where % modulo) % modulo;
-    *where += amount;
-
-    if (gzip_write(fd->fd, buf, amount) != amount)
-       return CPIOERR_WRITE_FAILED;
-
-    return 0;
-}
-
-static int strntoul(const char * str, char ** endptr, int base, int num) {
-    char * buf, * end;
-    unsigned long ret;
-
-    buf = alloca(num + 1);
-    strncpy(buf, str, num);
-    buf[num] = '\0';
-
-    ret = strtoul(buf, &end, base);
-    if (*end)
-       *endptr = (char *)(str + (end - buf));  /* XXX discards const */
-    else
-       *endptr = "";
-
-    return strtoul(buf, endptr, base);
-}
-
-#define GET_NUM_FIELD(phys, log) \
-       log = strntoul(phys, &end, 16, sizeof(phys)); \
-       if (*end) return CPIOERR_BAD_HEADER;
-#define SET_NUM_FIELD(phys, val, space) \
-       sprintf(space, "%8.8lx", (unsigned long) (val)); \
-       memcpy(phys, space, 8);
-
-static int getNextHeader(struct ourfd * fd, struct cpioHeader * chPtr,
-                        struct cpioCrcPhysicalHeader * physHeaderPtr) {
-    struct cpioCrcPhysicalHeader physHeader;
-    int nameSize;
-    char * end;
-    int major, minor;
-
-    if (ourread(fd, &physHeader, PHYS_HDR_SIZE) != PHYS_HDR_SIZE) 
-       return CPIOERR_READ_FAILED;
-
-    if (physHeaderPtr)
-       memcpy(physHeaderPtr, &physHeader, PHYS_HDR_SIZE);
-
-    if (strncmp(CPIO_CRC_MAGIC, physHeader.magic, strlen(CPIO_CRC_MAGIC)) &&
-       strncmp(CPIO_NEWC_MAGIC, physHeader.magic, strlen(CPIO_NEWC_MAGIC)))
-       return CPIOERR_BAD_MAGIC;
-
-    GET_NUM_FIELD(physHeader.inode, chPtr->inode);
-    GET_NUM_FIELD(physHeader.mode, chPtr->mode);
-    GET_NUM_FIELD(physHeader.uid, chPtr->uid);
-    GET_NUM_FIELD(physHeader.gid, chPtr->gid);
-    GET_NUM_FIELD(physHeader.nlink, chPtr->nlink);
-    GET_NUM_FIELD(physHeader.mtime, chPtr->mtime);
-    GET_NUM_FIELD(physHeader.filesize, chPtr->size);
-
-    GET_NUM_FIELD(physHeader.devMajor, major);
-    GET_NUM_FIELD(physHeader.devMinor, minor);
-    chPtr->dev = makedev(major, minor);
-
-    GET_NUM_FIELD(physHeader.rdevMajor, major);
-    GET_NUM_FIELD(physHeader.rdevMinor, minor);
-    chPtr->rdev = makedev(major, minor);
-
-    GET_NUM_FIELD(physHeader.namesize, nameSize);
-
-    chPtr->path = malloc(nameSize + 1);
-    if (ourread(fd, chPtr->path, nameSize) != nameSize) {
-       free(chPtr->path);
-       return CPIOERR_BAD_HEADER;
-    }
-
-    /* this is unecessary chPtr->path[nameSize] = '\0'; */
-
-    padinfd(fd, 4);
-
-    return 0;
-}
-
-int myCpioFileMapCmp(const void * a, const void * b) {
-    const struct cpioFileMapping * first = a;
-    const struct cpioFileMapping * second = b;
-
-    return (strcmp(first->archivePath, second->archivePath));
-}
-
-/* This could trash files in the path! I'm not sure that's a good thing */
-static int createDirectory(char * path, mode_t perms) {
-    struct stat sb;
-    int dounlink;
-
-    if (!lstat(path, &sb)) {
-       if (S_ISDIR(sb.st_mode)) {
-           return 0;
-       } else if (S_ISLNK(sb.st_mode)) {
-           if (stat(path, &sb)) {
-               if (errno != ENOENT) 
-                   return CPIOERR_STAT_FAILED;
-               dounlink = 1;
-           } else {
-               if (S_ISDIR(sb.st_mode))
-                   return 0;
-               dounlink = 1;
-           }
-       } else {
-           dounlink = 1;
-       }
-
-       if (dounlink && unlink(path)) {
-           return CPIOERR_UNLINK_FAILED;
-       }
-    }
-
-    if (mkdir(path, 000))
-       return CPIOERR_MKDIR_FAILED;
-
-    if (chmod(path, perms))
-       return CPIOERR_CHMOD_FAILED;
-
-    return 0;
-}
-
-static int setInfo(struct cpioHeader * hdr) {
-    int rc = 0;
-    struct utimbuf stamp;
-
-    stamp.actime = hdr->mtime; 
-    stamp.modtime = hdr->mtime;
-
-    if (!S_ISLNK(hdr->mode)) {
-       if (!getuid() && chown(hdr->path, hdr->uid, hdr->gid))
-           rc = CPIOERR_CHOWN_FAILED;
-       if (!rc && chmod(hdr->path, hdr->mode & 07777))
-           rc = CPIOERR_CHMOD_FAILED;
-       if (!rc && utime(hdr->path, &stamp))
-           rc = CPIOERR_UTIME_FAILED;
-    } else {
-#       if ! CHOWN_FOLLOWS_SYMLINK
-           if (!getuid() && !rc && lchown(hdr->path, hdr->uid, hdr->gid))
-               rc = CPIOERR_CHOWN_FAILED;
-#       endif
-    }
-
-    return rc;
-}
-
-static int checkDirectory(char * filename) {
-    static char * lastDir = NULL;
-    static int lastDirLength = 0;
-    static int lastDirAlloced = 0;
-    int length = strlen(filename);
-    char * buf;
-    char * chptr;
-    int rc = 0;
-
-    buf = alloca(length + 1);
-    strcpy(buf, filename);
-
-    for (chptr = buf + length - 1; chptr > buf; chptr--) {
-       if (*chptr == '/') break;
-    }
-
-    if (chptr == buf) return 0;     /* /filename - no directories */
-
-    *chptr = '\0';                  /* buffer is now just directories */
-
-    length = strlen(buf);
-    if (lastDirLength == length && !strcmp(buf, lastDir)) return 0;
-
-    if (lastDirAlloced < (length + 1)) {
-       lastDirAlloced = length + 100;
-       lastDir = realloc(lastDir, lastDirAlloced);
-    }
-
-    strcpy(lastDir, buf);
-    lastDirLength = length;
-
-    for (chptr = buf + 1; *chptr; chptr++) {
-       if (*chptr == '/') {
-           *chptr = '\0';
-           rc = createDirectory(buf, 0755);
-           *chptr = '/';
-           if (rc) return rc;
-       }
-    }
-    rc = createDirectory(buf, 0755);
-
-    return rc;
-}
-
-static int expandRegular(struct ourfd * fd, struct cpioHeader * hdr,
-                        cpioCallback cb, void * cbData) {
-    int out;
-    char buf[8192];
-    int bytesRead;
-    unsigned long left = hdr->size;
-    int rc = 0;
-    struct cpioCallbackInfo cbInfo;
-    struct stat sb;
-
-    if (!lstat(hdr->path, &sb))
-       if (unlink(hdr->path))
-           return CPIOERR_UNLINK_FAILED;
-
-    out = open(hdr->path, O_CREAT | O_WRONLY, 0);
-    if (out < 0) 
-       return CPIOERR_OPEN_FAILED;
-
-    cbInfo.file = hdr->path;
-    cbInfo.fileSize = hdr->size;
-
-    while (left) {
-       bytesRead = ourread(fd, buf, left < sizeof(buf) ? left : sizeof(buf));
-       if (bytesRead <= 0) {
-           rc = CPIOERR_READ_FAILED;
-           break;
-       }
-
-       if (write(out, buf, bytesRead) != bytesRead) {
-           rc = CPIOERR_COPY_FAILED;
-           break;
-       }
-
-       left -= bytesRead;
-
-       /* don't call this with fileSize == fileComplete */
-       if (!rc && cb && left) {
-           cbInfo.fileComplete = hdr->size - left;
-           cbInfo.bytesProcessed = fd->pos;
-           cb(&cbInfo, cbData);
-       }
-    }
-
-    close(out);
-    
-    return rc;
-}
-
-static int expandSymlink(struct ourfd * fd, struct cpioHeader * hdr) {
-    char buf[2048], buf2[2048];
-    struct stat sb;
-    int len;
-
-    if ((hdr->size + 1)> sizeof(buf))
-       return CPIOERR_INTERNAL;
-
-    if (ourread(fd, buf, hdr->size) != hdr->size)
-       return CPIOERR_READ_FAILED;
-
-    buf[hdr->size] = '\0';
-
-    if (!lstat(hdr->path, &sb)) {
-       if (S_ISLNK(sb.st_mode)) {
-           len = readlink(hdr->path, buf2, sizeof(buf2) - 1);
-           if (len > 0) {
-               buf2[len] = '\0';
-               if (!strcmp(buf, buf2)) return 0;
-           }
-       }
-
-       if (unlink(hdr->path))
-           return CPIOERR_UNLINK_FAILED;
-    }
-
-    if (symlink(buf, hdr->path) < 0)
-       return CPIOERR_SYMLINK_FAILED;
-
-    return 0;
-}
-
-static int expandFifo(struct ourfd * fd, struct cpioHeader * hdr) {
-    struct stat sb;
-
-    if (!lstat(hdr->path, &sb)) {
-       if (S_ISFIFO(sb.st_mode)) return 0;
-
-       if (unlink(hdr->path))
-           return CPIOERR_UNLINK_FAILED;
-    }
-
-    if (mkfifo(hdr->path, 0))
-       return CPIOERR_MKFIFO_FAILED;
-
-    return 0; 
-}
-
-static int expandDevice(struct ourfd * fd, struct cpioHeader * hdr) {
-    struct stat sb;
-
-    if (!lstat(hdr->path, &sb)) {
-       if ((S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) && 
-               (sb.st_rdev == hdr->rdev))
-           return 0;
-       if (unlink(hdr->path))
-           return CPIOERR_UNLINK_FAILED;
-    }
-
-    if (mknod(hdr->path, hdr->mode & (~0777), hdr->rdev))
-       return CPIOERR_MKNOD_FAILED;
-    
-    return 0;
-}
-
-static void freeLink(struct hardLink * li) {
-    int i;
-
-    for (i = 0; i < li->nlink; i++) {
-       if (li->files[i]) free(li->files[i]);
-    }
-    free(li->files);
-}
-
-static int createLinks(struct hardLink * li, const char ** failedFile) {
-    int i;
-    struct stat sb;
-
-    for (i = 0; i < li->nlink; i++) {
-       if (i == li->createdPath) continue;
-       if (!li->files[i]) continue;
-
-       if (!lstat(li->files[i], &sb)) {
-           if (unlink(li->files[i])) {
-               *failedFile = strdup(li->files[i]);
-               return CPIOERR_UNLINK_FAILED;
-           }
-       }
-
-       if (link(li->files[li->createdPath], li->files[i])) {
-           *failedFile = strdup(li->files[i]);
-           return CPIOERR_LINK_FAILED;
-       }
-
-       free(li->files[i]);
-       li->files[i] = NULL;
-       li->linksLeft--;
-    }
-
-    return 0;
-}
-
-static int eatBytes(struct ourfd * fd, unsigned long amount) {
-    char buf[4096];
-    unsigned long bite;
-   
-    while (amount) {
-       bite = (amount > sizeof(buf)) ? sizeof(buf) : amount;
-       if (ourread(fd, buf, bite) != bite)
-           return CPIOERR_READ_FAILED;
-       amount -= bite;
-    }
-
-    return 0;
-}
-
-int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings, 
-                      int numMappings, cpioCallback cb, void * cbData,
-                      const char ** failedFile) {
-    struct cpioHeader ch;
-    struct ourfd fd;
-    int rc = 0;
-    int linkNum = 0;
-    struct cpioFileMapping * map = NULL;
-    struct cpioFileMapping needle;
-    mode_t cpioMode;
-    int olderr;
-    struct cpioCallbackInfo cbInfo;
-    struct hardLink * links = NULL;
-    struct hardLink * li = NULL;
-
-    fd.fd = stream;
-    fd.pos = 0;
-
-    *failedFile = NULL;
-
-    do {
-       if ((rc = getNextHeader(&fd, &ch, NULL))) {
-           fprintf(stderr, _("error %d reading header: %s\n"), rc, 
-                   myCpioStrerror(rc));
-           return CPIOERR_BAD_HEADER;
-       }
-
-       if (!strcmp(ch.path, TRAILER)) {
-           free(ch.path);
-           break;
-       }
-
-       if (mappings) {
-           needle.archivePath = ch.path;
-           map = bsearch(&needle, mappings, numMappings, sizeof(needle),
-                         myCpioFileMapCmp);
-       }
-
-       if (mappings && !map) {
-           eatBytes(&fd, ch.size);
-       } else {
-           cpioMode = ch.mode;
-
-           if (map) {
-               if (map->mapFlags & CPIO_MAP_PATH) {
-                   free(ch.path);
-                   ch.path = strdup(map->fsPath);
-               } 
-
-               if (map->mapFlags & CPIO_MAP_MODE)
-                   ch.mode = map->finalMode;
-               if (map->mapFlags & CPIO_MAP_UID)
-                   ch.uid = map->finalUid;
-               if (map->mapFlags & CPIO_MAP_GID)
-                   ch.gid = map->finalGid;
-           }
-
-           /* This won't get hard linked symlinks right, but I can't seem 
-              to create those anyway */
-
-           if (S_ISREG(ch.mode) && ch.nlink > 1) {
-               li = links;
-               for (li = links; li; li = li->next) {
-                   if (li->inode == ch.inode && li->dev == ch.dev) break;
-               }
-
-               if (!li) {
-                   li = malloc(sizeof(*li));
-                   li->inode = ch.inode;
-                   li->dev = ch.dev;
-                   li->nlink = ch.nlink;
-                   li->linksLeft = ch.nlink;
-                   li->createdPath = -1;
-                   li->files = calloc(sizeof(char *), li->nlink);
-                   li->next = links;
-                   links = li;
-               }
-
-               for (linkNum = 0; linkNum < li->nlink; linkNum++)
-                   if (!li->files[linkNum]) break;
-               li->files[linkNum] = strdup(ch.path);
-           }
-               
-           if ((ch.nlink > 1) && S_ISREG(ch.mode) && !ch.size &&
-               li->createdPath == -1) {
-               /* defer file creation */
-           } else if ((ch.nlink > 1) && S_ISREG(ch.mode) && 
-                      (li->createdPath != -1)) {
-               createLinks(li, failedFile);
-
-               /* this only happens for cpio archives which contain
-                  hardlinks w/ the contents of each hardlink being
-                  listed (intead of the data being given just once. This
-                  shouldn't happen, but I've made it happen w/ buggy
-                  code, so what the heck? GNU cpio handles this well fwiw */
-               if (ch.size) eatBytes(&fd, ch.size);
-           } else {
-               rc = checkDirectory(ch.path);
-
-               if (!rc) {
-                   if (S_ISREG(ch.mode))
-                       rc = expandRegular(&fd, &ch, cb, cbData);
-                   else if (S_ISDIR(ch.mode))
-                       rc = createDirectory(ch.path, 000);
-                   else if (S_ISLNK(ch.mode))
-                       rc = expandSymlink(&fd, &ch);
-                   else if (S_ISFIFO(ch.mode))
-                       rc = expandFifo(&fd, &ch);
-                   else if (S_ISCHR(ch.mode) || S_ISBLK(ch.mode))
-                       rc = expandDevice(&fd, &ch);
-                   else if (S_ISSOCK(ch.mode)) {
-                       /* this mimicks cpio but probably isnt' right */
-                       rc = expandFifo(&fd, &ch);
-                   } else {
-                       rc = CPIOERR_INTERNAL;
-                   }
-               }
-
-               if (!rc)
-                   rc = setInfo(&ch);
-
-               if (S_ISREG(ch.mode) && ch.nlink > 1) {
-                   li->createdPath = linkNum;
-                   li->linksLeft--;
-                   rc = createLinks(li, failedFile);
-               }
-           }
-
-           if (rc && !*failedFile) {
-               *failedFile = strdup(ch.path);
-
-               olderr = errno;
-               unlink(ch.path);
-               errno = olderr;
-           }
-       }
-
-       padinfd(&fd, 4);
-
-       if (!rc && cb) {
-           cbInfo.file = ch.path;
-           cbInfo.fileSize = ch.size;
-           cbInfo.fileComplete = ch.size;
-           cbInfo.bytesProcessed = fd.pos;
-           cb(&cbInfo, cbData);
-       }
-
-       free(ch.path);
-    } while (1 && !rc);
-
-    li = links;
-    while (li && !rc) {
-       if (li->linksLeft) {
-           if (li->createdPath == -1)
-               rc = CPIOERR_INTERNAL;
-           else 
-               rc = createLinks(li, failedFile);
-       }
-
-       freeLink(li);
-
-       links = li;
-       li = li->next;
-       free(links);
-       links = li;
-    }
-
-    li = links;
-    /* if an error got us here links will still be eating some memory */
-    while (li) {
-       freeLink(li);
-       links = li;
-       li = li->next;
-       free(links);
-    }
-
-    return rc;
-}
-
-const char * myCpioStrerror(int rc)
-{
-    static char msg[256];
-    char *s;
-    int l, myerrno = errno;
-
-    strcpy(msg, "cpio: ");
-    switch (rc) {
-    default:
-       s = msg + strlen(msg);
-       sprintf(s, _("(error 0x%x)"), rc);
-       s = NULL;
-       break;
-    case CPIOERR_BAD_MAGIC:    s = _("Bad magic");             break;
-    case CPIOERR_BAD_HEADER:   s = _("Bad header");            break;
-
-    case CPIOERR_OPEN_FAILED:  s = "open";     break;
-    case CPIOERR_CHMOD_FAILED: s = "chmod";    break;
-    case CPIOERR_CHOWN_FAILED: s = "chown";    break;
-    case CPIOERR_WRITE_FAILED: s = "write";    break;
-    case CPIOERR_UTIME_FAILED: s = "utime";    break;
-    case CPIOERR_UNLINK_FAILED:        s = "unlink";   break;
-    case CPIOERR_SYMLINK_FAILED: s = "symlink";        break;
-    case CPIOERR_STAT_FAILED:  s = "stat";     break;
-    case CPIOERR_MKDIR_FAILED: s = "mkdir";    break;
-    case CPIOERR_MKNOD_FAILED: s = "mknod";    break;
-    case CPIOERR_MKFIFO_FAILED:        s = "mkfifo";   break;
-    case CPIOERR_LINK_FAILED:  s = "link";     break;
-    case CPIOERR_READLINK_FAILED: s = "readlink";      break;
-    case CPIOERR_READ_FAILED:  s = "read";     break;
-    case CPIOERR_COPY_FAILED:  s = "copy";     break;
-
-    case CPIOERR_INTERNAL:     s = _("Internal error");        break;
-    case CPIOERR_HDR_SIZE:     s = _("Header size too big");   break;
-    case CPIOERR_UNKNOWN_FILETYPE: s = _("Unknown file type"); break;
-    }
-
-    l = sizeof(msg) - strlen(msg) - 1;
-    if (s != NULL) {
-       if (l > 0) strncat(msg, s, l);
-       l -= strlen(s);
-    }
-    if (rc & CPIOERR_CHECK_ERRNO) {
-       s = _(" failed - ");
-       if (l > 0) strncat(msg, s, l);
-       l -= strlen(s);
-       if (l > 0) strncat(msg, strerror(myerrno), l);
-    }
-    return msg;
-}
-
-static int copyFile(struct ourfd * inFd, struct ourfd * outFd, 
-            struct cpioHeader * chp, struct cpioCrcPhysicalHeader * pHdr) {
-    char buf[8192];
-    int amount;
-    size_t size = chp->size;
-
-    amount = strlen(chp->path) + 1;
-    memcpy(pHdr->magic, CPIO_NEWC_MAGIC, sizeof(pHdr->magic));
-
-    gzip_write(outFd->fd, pHdr, PHYS_HDR_SIZE);
-    gzip_write(outFd->fd, chp->path, amount);
-
-    outFd->pos += PHYS_HDR_SIZE + amount;
-
-    padoutfd(outFd, &outFd->pos, 4);
-
-    while (size) {
-       amount = ourread(inFd, buf, size > sizeof(buf) ? sizeof(buf) : size);
-       gzip_write(outFd->fd, buf, amount);
-       size -= amount;
-    }
-
-    outFd->pos += chp->size;
-
-    padoutfd(outFd, &outFd->pos, 4);
-
-    return 0;
-}
-
-int myCpioFilterArchive(gzFile inStream, gzFile outStream, char ** patterns) {
-    struct ourfd inFd, outFd;
-    char ** aPattern;
-    struct cpioHeader ch;
-    int rc;
-    struct cpioCrcPhysicalHeader pHeader;
-
-    inFd.fd = inStream;
-    inFd.pos = 0;
-    outFd.fd = outStream;
-    outFd.pos = 0;
-
-    do {
-       if ((rc = getNextHeader(&inFd, &ch, &pHeader))) {
-           fprintf(stderr, _("error %d reading header: %s\n"), rc, 
-                   myCpioStrerror(rc));
-           return CPIOERR_BAD_HEADER;
-       }
-
-       if (!strcmp(ch.path, TRAILER)) {
-           free(ch.path);
-           break;
-       }
-
-       for (aPattern = patterns; *aPattern; aPattern++)
-           if (!fnmatch(*aPattern, ch.path, FNM_PATHNAME | FNM_PERIOD))
-               break;
-
-       if (!*aPattern)
-           eatBytes(&inFd, ch.size);
-       else
-           copyFile(&inFd, &outFd, &ch, &pHeader);
-
-       padinfd(&inFd, 4);
-
-       free(ch.path);
-    } while (1 && !rc);
-
-    memset(&pHeader, '0', sizeof(pHeader));
-    memcpy(pHeader.magic, CPIO_NEWC_MAGIC, sizeof(pHeader.magic));
-    memcpy(pHeader.nlink, "00000001", 8);
-    memcpy(pHeader.namesize, "0000000b", 8);
-    gzip_write(outFd.fd, &pHeader, PHYS_HDR_SIZE);
-    gzip_write(outFd.fd, "TRAILER!!!", 11);
-
-    outFd.pos += PHYS_HDR_SIZE + 11;
-
-    if ((rc = padoutfd(&outFd, &outFd.pos, 4)))
-       return rc;
-
-    if ((rc = padoutfd(&outFd, &outFd.pos, 512)))
-       return rc;
-
-    return 0;
-}
index 55d09e62d2b2d1c7b438b55c5531b6d714881091..9b06a3eb8c6051b029a68310d1cae826cb14fa27 100644 (file)
@@ -1,10 +1,22 @@
 /*
  * vio.c - probing for vio devices on the iSeries (viocd and viodasd)
  *
- * Jeremy Katz <katzj@redhat.com>
+ * Copyright (C) 2003  Red Hat, Inc.  All rights reserved.
  *
- * Copyright 2003  Red Hat, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Jeremy Katz <katzj@redhat.com>
  */
 
 #include <ctype.h>
@@ -15,8 +27,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <kudzu/kudzu.h>
-
 #if defined(__powerpc__)
 static int readFD (int fd, char **buf)
 {
diff --git a/src/pomona/src/isys/wireless.c b/src/pomona/src/isys/wireless.c
new file mode 100644 (file)
index 0000000..aa13b11
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * wireless.c - wireless card manipulation
+ * Some portions from wireless_tools
+ *    copyright (c) 1997-2003 Jean Tourrilhes <jt@hpl.hp.com>
+ *
+ * Copyright (C) 2004  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Jeremy Katz <katzj@redhat.com>
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <linux/types.h>
+#include <linux/if.h>
+#include <linux/wireless.h>
+
+static struct iwreq get_wreq(char * ifname) {
+    struct iwreq wreq;
+
+    memset(&wreq, 0, sizeof(wreq));
+    strncpy(wreq.ifr_name, ifname, IFNAMSIZ);    
+    return wreq;
+}
+
+static int get_socket() {
+    int sock;
+
+    if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+#ifdef STANDALONE
+        fprintf(stderr, "Error creating socket: %s\n", strerror(errno));
+#endif
+        return -1;
+    }
+
+    return sock;
+}
+
+int is_wireless_interface(char * ifname) {
+    int sock = get_socket();
+    struct iwreq wreq = get_wreq(ifname);
+
+    int rc = ioctl(sock, SIOCGIWNAME, &wreq);
+    close(sock);
+
+    if (rc < 0) {
+        return 0;
+    }
+
+    return 1;
+}
+
+/* set the essid for ifname to essid.  if essid is NULL, do automatically */
+int set_essid(char * ifname, char * essid) {
+    int sock; 
+    struct iwreq wreq;
+
+    memset(&wreq, 0, sizeof (wreq));
+
+    if (strlen(essid) > IW_ESSID_MAX_SIZE) {
+        fprintf(stderr, "essid too long\n");
+        return -1;
+    }
+
+    sock = get_socket();
+    wreq = get_wreq(ifname);
+
+    if (essid) {
+        wreq.u.essid.flags = 1;
+        wreq.u.essid.pointer = (caddr_t) essid;
+        wreq.u.essid.length = strlen(essid) + 1;
+    } else {
+        wreq.u.essid.flags = 0;
+        wreq.u.essid.pointer = (caddr_t) NULL;
+        wreq.u.essid.length = 0;
+    }
+
+    int rc = ioctl(sock, SIOCSIWESSID, &wreq);
+    close(sock);
+
+    if (rc < 0) {
+        fprintf(stderr, "failed to set essid: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+char * get_essid(char * ifname) {
+    int sock; 
+    struct iwreq wreq; 
+
+    memset(&wreq, 0, sizeof (wreq));
+
+    sock = get_socket();
+    wreq = get_wreq(ifname);
+
+    wreq.u.essid.pointer = (caddr_t) malloc(IW_ESSID_MAX_SIZE + 1);
+    wreq.u.essid.length = IW_ESSID_MAX_SIZE + 1;
+    wreq.u.essid.flags = 0;
+    int rc = ioctl(sock, SIOCGIWESSID, &wreq);
+    close(sock);
+
+    if (rc < 0) {
+        fprintf(stderr, "failed to get essid for %s: %s\n", ifname, 
+                strerror(errno));
+        return NULL;
+    }
+
+    return wreq.u.essid.pointer;
+}
+
+/* based off iw_in_key from wireless-tools/iwlib.c */
+static int parse_wep_key(char * in, unsigned char * key) {
+    int len = 0;
+
+    if (!strncmp(in, "s:", 2)) {
+        /* the key is a string */
+        len = strlen(in + 2);
+       memmove(key, in + 2, len);
+    } else {
+        char *buff, *hex, *out, *p;
+
+        /* hexadecimal digits, straight from iwlib.c */
+        buff = malloc(IW_ENCODING_TOKEN_MAX + strlen(in) + 1);
+        if(buff == NULL) {
+            fprintf(stderr, "Malloc failed (string too long ?)\n");
+            return(-1);
+        }
+        /* Preserve original buffers (both in & out) */
+        hex = buff + IW_ENCODING_TOKEN_MAX;
+        strcpy(hex, in);
+        out = buff;
+        /* Parse */
+        p = strtok(hex, "-:;.,");
+        while((p != (char *) NULL) && (len < IW_ENCODING_TOKEN_MAX)) {
+            int temph, templ, count, l;
+
+            /* Get each char separatly (and not by two) so that we don't
+             * get confused by 'enc' (=> '0E'+'0C') and similar */
+            count = sscanf(p, "%1X%1X", &temph, &templ);
+            if(count < 1)
+              return(-1);               /* Error -> non-hex char */
+            /* Fixup odd strings such as '123' is '01'+'23' and not '12'+'03'*/
+            l = strlen(p);
+            if(l % 2)
+              count = 1;
+            /* Put back two chars as one byte */
+            if(count == 2)
+              templ |= temph << 4;
+            else
+              templ = temph;
+            out[len++] = (unsigned char) (templ & 0xFF);
+            /* Check where to get next char from */
+            if(l > count)     /* Token not finished yet */
+              p += count;
+            else
+              p = strtok((char *) NULL, "-:;.,");
+          }
+        memcpy(key, out, len);
+        free(buff);
+    }
+
+    return len;
+}
+
+int set_wep_key(char * ifname, char * key) {
+    int sock; 
+    struct iwreq wreq; 
+    unsigned char thekey[IW_ENCODING_TOKEN_MAX];
+    
+    if (strlen(key) > IW_ENCODING_TOKEN_MAX) {
+        fprintf(stderr, "wep key too long\n");
+        return -1;
+    }
+
+    sock = get_socket();
+    wreq = get_wreq(ifname);
+
+    if (key) {
+        int len = parse_wep_key(key, thekey);
+        if (len > 0) {
+            wreq.u.data.flags = IW_ENCODE_ENABLED;
+            wreq.u.data.length = len;
+            wreq.u.data.pointer = (caddr_t) thekey;
+        }
+    } else {
+        wreq.u.data.flags = IW_ENCODE_DISABLED;
+        wreq.u.data.pointer = (caddr_t) NULL;
+        wreq.u.data.length = 0;
+    }
+
+    int rc = ioctl(sock, SIOCSIWENCODE, &wreq);
+    close(sock);
+
+    if (rc < 0) {
+        fprintf(stderr, "failed to set wep key: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+enum { MODE_AUTO, MODE_ADHOC, MODE_MANAGED, MODE_MASTER, MODE_REPEATER,
+       MODE_SECONDARY, MODE_MONITOR };
+
+int set_managed(char * ifname) {
+    int sock = get_socket();
+    struct iwreq wreq = get_wreq(ifname);
+
+    wreq.u.mode = MODE_MANAGED;
+    int rc = ioctl(sock, SIOCSIWMODE, &wreq);
+    close(sock);
+
+    if (rc < 0) {
+        fprintf(stderr, "failed to set managed mode: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+#ifdef STANDALONE
+int main(int argc, char **argv) {
+    if (argc < 4) {
+        fprintf(stderr, "Usage: %s [interface] [essid] [key]\n", argv[0]);
+        exit(1);
+    }
+
+    if (!is_wireless_interface(argv[1])) {
+        fprintf(stderr, "%s isn't a wireless interface!\n", argv[1]);
+        exit(2);
+    } 
+
+    /*    if (set_essid(argv[1], NULL) < 0) {
+        fprintf(stderr, "Unable to set essid to %s\n", argv[2]);
+        exit(3);
+    }
+    exit(0);*/
+
+    if (set_essid(argv[1], argv[2]) < 0) {
+        fprintf(stderr, "Unable to set essid to %s\n", argv[2]);
+        exit(3);
+    }
+
+    /*    if (set_wep_key(argv[1], NULL) < 0) {
+        fprintf(stderr, "Unable to set wepkey to %s\n", argv[2]);
+        exit(4);
+    }
+    exit(0);*/
+
+    if (set_wep_key(argv[1], argv[3]) < 0) {
+        fprintf(stderr, "Unable to set wepkey to %s\n", argv[2]);
+        exit(4);
+    }
+
+    return 0;
+}
+#endif
diff --git a/src/pomona/src/isys/wireless.h b/src/pomona/src/isys/wireless.h
new file mode 100644 (file)
index 0000000..82cb4d4
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * wireless.h
+ *
+ * Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WIRELESS_H
+#define WIRELESS_H
+
+int is_wireless_interface(char * ifname);
+int set_essid(char * ifname, char * essid);
+char * get_essid(char * ifname);
+int set_wep_key(char * ifname, char * key);
+int set_managed(char * ifname);
+
+#endif
diff --git a/src/pomona/src/minihal.py b/src/pomona/src/minihal.py
new file mode 100644 (file)
index 0000000..c3f7fda
--- /dev/null
@@ -0,0 +1,70 @@
+#
+# minihal.py: Simple wrapper around HAL
+#
+# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author(s): Bill Nottingham <notting@redhat.com>
+#
+
+"""Simple wrapper around HAL"""
+
+import dbus
+
+def get_device(udi):
+       """Retrieve all properties of a particular device (by UDI)"""
+       try:
+               bus = dbus.SystemBus()
+               haldev = dbus.Interface(bus.get_object("org.freedesktop.Hal", udi), "org.freedesktop.Hal.Device")
+               props = haldev.GetAllProperties()
+       except dbus.exceptions.DBusException:
+               return None
+
+       if props.has_key('block.device'):
+               props['device'] = props['block.device'].encode("utf-8")
+       elif props.has_key('linux.device_file'):
+               props['device'] = props['linux.device_file'].encode("utf-8")
+       elif props.has_key('net.interface'):
+               props['device'] = props['net.interface'].encode("utf-8")
+       else:
+               props['device'] = None
+
+       props['description'] = ''
+       if props.has_key('info.product'):
+               if props.has_key('info.vendor'):
+                       props['description'] = '%s %s' % (props['info.vendor'],props['info.product'])
+               else:
+                       props['description'] = props['info.product']
+       else:
+               props['description'] = props['info.udi']
+       if props.has_key('net.originating_device'):
+               pdev = get_device(props['net.originating_device'])
+               props['description'] = pdev['description']
+
+       return props
+
+def get_devices_by_type(type):
+       """Retrieve all devices of a particular type"""
+       ret = []
+       try:
+               bus = dbus.SystemBus()
+               hal = dbus.Interface(bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager"),"org.freedesktop.Hal.Manager")
+       except:
+               return ret
+       for udi in hal.FindDeviceByCapability(type):
+               dev = get_device(udi)
+               if dev:
+                       ret.append(dev)
+       return ret
index e5194419b0255c314fd1345f3368c9f9523b0bc9..5090f0dfc938b98de39804fbab823803eefcf03f 100644 (file)
 ###############################################################################
 
 echo "Running the Pomona Text Installer..."
-sleep 1
+sleep 2
 
 python /usr/lib/pomona/installer.py
 
-clear
-
-reboot
+#reboot
index c96aaec0b620039f2b2e41e5aeddf2028100136e..e1e84ebe929e61638c571ef83341771320a8d966 100644 (file)
@@ -3,7 +3,6 @@ from snack import *
 import sys, os
 import isys
 import parted
-import kudzu
 import signal
 import inutil
 import imputil
index 092cc814f28ba25d2d1c29dc77d0ca461f4613b2..ef89238d9e9e17e1f898682aad279675d50b2496 100644 (file)
@@ -56,7 +56,7 @@ INSTALLER_DIR/usr/lib/pomona/keyboard.pyo
 INSTALLER_DIR/usr/lib/pomona/keyboard_models.py
 #INSTALLER_DIR/usr/lib/pomona/keyboard_models.pyc
 INSTALLER_DIR/usr/lib/pomona/keyboard_models.pyo
-#INSTALLER_DIR/usr/lib/pomona/lang-names
+INSTALLER_DIR/usr/lib/pomona/lang-names
 INSTALLER_DIR/usr/lib/pomona/lang-table
 INSTALLER_DIR/usr/lib/pomona/language.py
 #INSTALLER_DIR/usr/lib/pomona/language.pyc