]>
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 | * | |
20 | * $Id: usb.c,v 1.9.2.8 2005/12/10 00:18:23 franck78 Exp $ | |
21 | * | |
22 | */ | |
23 | ||
24 | #include "install.h" | |
25 | ||
26 | int usbuhci = 0; | |
27 | int usbohci = 0; | |
28 | int ehcihcd = 0; | |
29 | ||
30 | int initialize_usb() { | |
31 | modprobe("sd_mod"); | |
32 | modprobe("sr_mod"); | |
33 | modprobe("usb-storage"); | |
34 | ||
35 | if (ehcihcd) { | |
36 | rmmod("ehci-hcd"); | |
37 | ehcihcd = 0; | |
38 | } | |
39 | if (usbohci) { | |
40 | rmmod("usb-ohci"); | |
41 | usbohci = 0; | |
42 | } | |
43 | if (usbuhci) { | |
44 | rmmod("usb-uhci"); | |
45 | usbuhci = 0; | |
46 | } | |
47 | ||
48 | if (modprobe("ehci-hcd") == 0) ehcihcd = 1; | |
49 | if (modprobe("usb-ohci") == 0) usbohci = 1; | |
50 | if (modprobe("usb-uhci") == 0) usbuhci = 1; | |
51 | ||
52 | modprobe("hid"); | |
53 | modprobe("keybdev"); | |
54 | return 0; | |
55 | } | |
56 | ||
57 | int write_usb_modules_conf() { | |
58 | int index = 0; | |
59 | FILE *handle; | |
60 | ||
61 | if (!(handle = fopen("/harddisk/etc/modules.conf", "a"))) | |
62 | return 0; | |
63 | ||
64 | #if 0 /* we don't do this yet, because one of the drivers has a problem | |
65 | * with it */ | |
66 | if (ehcihcd) { | |
67 | fprintf(handle,"alias usb-controller"); | |
68 | if (index) | |
69 | fprintf(handle,"%d",index); | |
70 | fprintf(handle," ehci-hcd\n"); | |
71 | index++; | |
72 | } | |
73 | #endif | |
74 | ||
75 | if (usbohci) { | |
76 | fprintf(handle,"alias usb-controller"); | |
77 | if (index) | |
78 | fprintf(handle,"%d",index); | |
79 | fprintf(handle," usb-ohci\n"); | |
80 | index++; | |
81 | } | |
82 | ||
83 | if (usbuhci) { | |
84 | fprintf(handle,"alias usb-controller"); | |
85 | if (index) | |
86 | fprintf(handle,"%d",index); | |
87 | fprintf(handle," usb-uhci\n"); | |
88 | index++; | |
89 | } | |
90 | fclose(handle); | |
91 | ||
92 | return 0; | |
93 | } | |
94 | ||
95 | /* checkusb(). | |
96 | Scans the named partitions and returns true if USB-removable. | |
97 | a bug? in "cat /proc/partitions" with superfloppy scheme device | |
98 | make them appearing always with four 'false' partitions: | |
99 | sda and sda1 sda2 sda3 sda4. | |
100 | No easy way to decide if /dev/sda1 exists or not. | |
101 | */ | |
102 | int checkusb(char *partition) | |
103 | { | |
104 | FILE *f = NULL; | |
105 | char filename[STRING_SIZE]; | |
106 | char buffer[STRING_SIZE]; | |
107 | char *pchar = &buffer[0]; | |
108 | if (!(f = fopen("/proc/partitions", "r"))) | |
109 | return 0; | |
110 | ||
111 | short int major = 0, minor = 0; | |
112 | while (fgets(buffer, STRING_SIZE, f)) { | |
113 | /* look for partition*/ | |
114 | if (strstr (buffer, partition)) { | |
115 | major = atoi (buffer); | |
116 | if (major != 8) break ; /* not scsi */ | |
117 | //get minor | |
118 | while (*pchar != '8') pchar++; | |
119 | minor = atoi (++pchar); | |
120 | break; | |
121 | } | |
122 | } | |
123 | fclose(f); | |
124 | if (major != 8) return 0; /* nothing found */ | |
125 | ||
126 | //now check for usb-storage-MINOR | |
127 | minor >>= 4; // get index from minor | |
128 | sprintf (filename, "/proc/scsi/usb-storage-%d/%d", minor,minor); | |
129 | ||
130 | if (!(f = fopen(filename, "r"))) | |
131 | return 0; | |
132 | int count = 0; | |
133 | while (fgets(buffer, STRING_SIZE, f)) { | |
134 | if (strstr(buffer,"usb-storage")) count++; | |
135 | if (strstr(buffer,"SCSI")) count++; | |
136 | if (strstr(buffer,"Attached: Yes")) count++; | |
137 | } | |
138 | fclose(f); | |
139 | ||
140 | return (count==3 ? 1 : 0); | |
141 | } |