]>
Commit | Line | Data |
---|---|---|
d6aaa55d MT |
1 | /* |
2 | * This file is part of the IPCop Firewall. | |
3 | * | |
4 | * IPCop is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * IPCop is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with IPCop; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | * | |
18 | * Copyright 2002: Mark Wormgoor <mark@wormgoor.com> | |
19 | * | |
d6aaa55d MT |
20 | */ |
21 | ||
22 | #include "install.h" | |
23 | ||
24 | int usbuhci = 0; | |
25 | int usbohci = 0; | |
26 | int ehcihcd = 0; | |
27 | ||
28 | int initialize_usb() { | |
10bc6f06 MT |
29 | mysystem("/sbin/modprobe sd_mod"); |
30 | mysystem("/sbin/modprobe sr_mod"); | |
31 | mysystem("/sbin/modprobe usb-storage"); | |
330345c2 | 32 | mysystem("/sbin/modprobe vfat"); |
d6aaa55d MT |
33 | |
34 | if (ehcihcd) { | |
10bc6f06 | 35 | mysystem("/sbin/rmmod ehci-hcd"); |
d6aaa55d MT |
36 | ehcihcd = 0; |
37 | } | |
38 | if (usbohci) { | |
3d6e1202 | 39 | mysystem("/sbin/rmmod ohci-hcd"); |
d6aaa55d MT |
40 | usbohci = 0; |
41 | } | |
42 | if (usbuhci) { | |
3d6e1202 | 43 | mysystem("/sbin/rmmod uhci-hcd"); |
d6aaa55d MT |
44 | usbuhci = 0; |
45 | } | |
46 | ||
10bc6f06 MT |
47 | if (mysystem("/sbin/modprobe ehci-hcd") == 0) |
48 | ehcihcd = 1; | |
3d6e1202 | 49 | if (mysystem("/sbin/modprobe ohci-hcd") == 0) |
10bc6f06 | 50 | usbohci = 1; |
3d6e1202 | 51 | if (mysystem("/sbin/modprobe uhci-hcd") == 0) |
10bc6f06 | 52 | usbuhci = 1; |
d6aaa55d | 53 | |
3d6e1202 | 54 | mysystem("/sbin/modprobe usbhid"); |
d6aaa55d MT |
55 | return 0; |
56 | } | |
57 | ||
58 | int write_usb_modules_conf() { | |
10bc6f06 | 59 | int index; |
d6aaa55d MT |
60 | FILE *handle; |
61 | ||
62 | if (!(handle = fopen("/harddisk/etc/modules.conf", "a"))) | |
63 | return 0; | |
64 | ||
10bc6f06 MT |
65 | index = 0; |
66 | ||
d6aaa55d MT |
67 | #if 0 /* we don't do this yet, because one of the drivers has a problem |
68 | * with it */ | |
69 | if (ehcihcd) { | |
d6aaa55d | 70 | if (index) |
10bc6f06 MT |
71 | fprintf(handle,"alias usb-controller%d ehci-hcd\n",index); |
72 | else | |
73 | fprintf(handle,"alias usb-controller ehci-hcd\n"); | |
d6aaa55d MT |
74 | index++; |
75 | } | |
76 | #endif | |
77 | ||
78 | if (usbohci) { | |
d6aaa55d | 79 | if (index) |
3d6e1202 | 80 | fprintf(handle,"alias usb-controller%d ohci-hcd\n",index); |
10bc6f06 | 81 | else |
3d6e1202 | 82 | fprintf(handle,"alias usb-controller ohci-hcd\n"); |
d6aaa55d MT |
83 | index++; |
84 | } | |
85 | ||
86 | if (usbuhci) { | |
d6aaa55d | 87 | if (index) |
3d6e1202 | 88 | fprintf(handle,"alias usb-controller%d uhci-hcd\n",index); |
10bc6f06 | 89 | else |
3d6e1202 | 90 | fprintf(handle,"alias usb-controller uhci-hcd\n"); |
d6aaa55d MT |
91 | index++; |
92 | } | |
93 | fclose(handle); | |
94 | ||
95 | return 0; | |
96 | } | |
1cdddb12 MT |
97 | |
98 | /* Scans the named partitions and returns true if USB-removable. */ | |
99 | int checkusb(char *device) | |
100 | { | |
101 | FILE *f = NULL; | |
102 | char filename[STRING_SIZE]; | |
103 | char command[STRING_SIZE]; | |
104 | char buffer[STRING_SIZE]; | |
105 | int found = 0; | |
106 | ||
107 | sprintf(command, "udevinfo -a -p /sys/block/%s | grep BUS | sort| uniq >/tmp/usbscan 2>/dev/null", device); | |
108 | system(command); | |
109 | ||
110 | f = fopen("/tmp/usbscan", "r"); | |
111 | while (fgets(buffer, STRING_SIZE, f)) { | |
112 | if (strstr(buffer,"usb")) found=1; | |
113 | } | |
114 | fclose(f); | |
115 | ||
116 | if (found) return 0; | |
117 | else return 1; | |
118 | } |