]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/install+setup/install/usb.c
Die IDE/SCSI/SATA/USB-Erkennung erstellt nun schoene Ramdisks :D
[ipfire-2.x.git] / src / install+setup / install / usb.c
index 90bba2caf20ae5c87940bb8abf1a70f714991c9a..57ba56f50effa188b1332bf7bd989b84281ce119 100644 (file)
@@ -17,8 +17,6 @@
  *
  * Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
  * 
- * $Id: usb.c,v 1.9.2.8 2005/12/10 00:18:23 franck78 Exp $
- * 
  */
 
 #include "install.h"
@@ -28,63 +26,68 @@ int usbohci = 0;
 int ehcihcd = 0;
 
 int initialize_usb() {
-    modprobe("sd_mod");
-    modprobe("sr_mod");
-    modprobe("usb-storage");
+    mysystem("/sbin/modprobe sd_mod");
+    mysystem("/sbin/modprobe sr_mod");
+    mysystem("/sbin/modprobe usb-storage");
+    mysystem("/sbin/modprobe vfat");
 
     if (ehcihcd) {
-       rmmod("ehci-hcd");
+       mysystem("/sbin/rmmod ehci-hcd");
        ehcihcd = 0;
     }
     if (usbohci) {
-       rmmod("usb-ohci");
+       mysystem("/sbin/rmmod ohci-hcd");
        usbohci = 0;
     }
     if (usbuhci) {
-       rmmod("usb-uhci");
+       mysystem("/sbin/rmmod uhci-hcd");
        usbuhci = 0;
     }
 
-    if (modprobe("ehci-hcd") == 0) ehcihcd = 1;
-    if (modprobe("usb-ohci") == 0) usbohci = 1;
-    if (modprobe("usb-uhci") == 0) usbuhci = 1;
+    if (mysystem("/sbin/modprobe ehci-hcd") == 0)
+       ehcihcd = 1;
+    if (mysystem("/sbin/modprobe ohci-hcd") == 0)
+       usbohci = 1;
+    if (mysystem("/sbin/modprobe uhci-hcd") == 0)
+       usbuhci = 1;
 
-    modprobe("hid");
-    modprobe("keybdev");
+    mysystem("/sbin/modprobe usbhid");
     return 0;
 }
 
 int write_usb_modules_conf() {
-    int index = 0;
+    int index;
     FILE *handle;
 
     if (!(handle = fopen("/harddisk/etc/modules.conf", "a")))
        return 0;
 
+    index = 0;
+
 #if 0 /* we don't do this yet, because one of the drivers has a problem 
        * with it */
     if (ehcihcd) {
-       fprintf(handle,"alias usb-controller");
        if (index)
-               fprintf(handle,"%d",index);
-       fprintf(handle," ehci-hcd\n");
+               fprintf(handle,"alias usb-controller%d ehci-hcd\n",index);
+       else
+               fprintf(handle,"alias usb-controller ehci-hcd\n");
        index++;
     }
 #endif
 
     if (usbohci) {
-       fprintf(handle,"alias usb-controller");
        if (index)
-               fprintf(handle,"%d",index);
-       fprintf(handle," usb-ohci\n");
+               fprintf(handle,"alias usb-controller%d ohci-hcd\n",index);
+       else
+               fprintf(handle,"alias usb-controller ohci-hcd\n");
        index++;
     }
 
     if (usbuhci) {
-       fprintf(handle,"alias usb-controller");
        if (index)
-               fprintf(handle,"%d",index);
-       fprintf(handle," usb-uhci\n");
+               fprintf(handle,"alias usb-controller%d uhci-hcd\n",index);
+       else
+               fprintf(handle,"alias usb-controller uhci-hcd\n");
        index++;
     }
     fclose(handle);
@@ -92,50 +95,24 @@ int write_usb_modules_conf() {
     return 0;
 }
 
-/* checkusb().
-    Scans the named partitions and returns true if USB-removable.
-    a bug? in "cat /proc/partitions" with superfloppy scheme device
-    make them appearing always with four 'false' partitions:
-    sda and sda1 sda2 sda3 sda4.
-    No easy way to decide if /dev/sda1 exists or not.
-*/
-int checkusb(char *partition)
+/* Scans the named partitions and returns true if USB-removable. */
+int checkusb(char *device)
 {
        FILE *f = NULL;
        char filename[STRING_SIZE];
+       char command[STRING_SIZE];
        char buffer[STRING_SIZE];
-       char *pchar = &buffer[0];
-       if (!(f = fopen("/proc/partitions", "r")))
-               return 0;
-
-       short int major = 0, minor = 0;                 
-       while (fgets(buffer, STRING_SIZE, f))   {
-           /* look for partition*/     
-           if (strstr (buffer, partition)) {
-               major = atoi (buffer);
-               if (major != 8) break ; /* not scsi */
-               //get minor
-               while (*pchar != '8') pchar++;
-               minor = atoi (++pchar);
-               break;
-           }
-       }
-       fclose(f);
-       if (major != 8) return 0; /* nothing found */
+       int found = 0;
        
-       //now check for usb-storage-MINOR
-       minor >>= 4; // get index from minor
-       sprintf (filename, "/proc/scsi/usb-storage-%d/%d", minor,minor);
-
-       if (!(f = fopen(filename, "r")))
-               return 0;
-       int count = 0;
-       while (fgets(buffer, STRING_SIZE, f))   {
-           if (strstr(buffer,"usb-storage")) count++;
-           if (strstr(buffer,"SCSI")) count++;
-           if (strstr(buffer,"Attached: Yes")) count++;
+       sprintf(command, "udevinfo -a -p /sys/block/%s | grep BUS | sort| uniq >/tmp/usbscan 2>/dev/null", device);
+       system(command);
+       
+       f = fopen("/tmp/usbscan", "r");
+       while (fgets(buffer, STRING_SIZE, f)) {
+               if (strstr(buffer,"usb")) found=1;
        }
        fclose(f);
        
-       return (count==3 ? 1 : 0);
+       if (found) return 0;
+               else return 1;
 }