summaryrefslogtreecommitdiff
path: root/recipes/linux/openzaurus-pxa-2.4.18-rmk7-pxa3-embedix20031107/usb-storage.patch
blob: c9296cf224c9b3c84d7a66e3fb4275c10820392a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
diff -Nur linux-2.4.18/drivers/usb/device/bi/sa1100.c linux-2.4.18-usb-storage/drivers/usb/device/bi/sa1100.c
--- linux-2.4.18/drivers/usb/device/bi/sa1100.c	2003-05-13 13:18:44.000000000 +0400
+++ linux-2.4.18-usb-storage/drivers/usb/device/bi/sa1100.c	2004-03-01 07:20:38.000000000 +0300
@@ -440,6 +440,7 @@
                                         udc_interrupts, *(UDCSR), *(UDCCS0), *(UDCAR));
 
 			usbd_device_event (udc_device, DEVICE_RESET, 0);
+			usbd_device_event (udc_device, DEVICE_ADDRESS_ASSIGNED,0);
 		}
 
 		if (status & UDCSR_SUSIR) {
diff -Nur linux-2.4.18/drivers/usb/device/Config.in linux-2.4.18-usb-storage/drivers/usb/device/Config.in
--- linux-2.4.18/drivers/usb/device/Config.in	2003-05-13 13:18:45.000000000 +0400
+++ linux-2.4.18-usb-storage/drivers/usb/device/Config.in	2003-11-07 05:35:14.000000000 +0300
@@ -34,6 +34,7 @@
    comment 'USB Device functions'
    source drivers/usb/device/net_fd/Config.in
    source drivers/usb/device/serial_fd/Config.in
+   source drivers/usb/device/storage_fd/Config.in
 	
    comment 'USB Device bus interfaces'
    source drivers/usb/device/bi/Config.in
diff -Nur linux-2.4.18/drivers/usb/device/Makefile linux-2.4.18-usb-storage/drivers/usb/device/Makefile
--- linux-2.4.18/drivers/usb/device/Makefile	2003-05-13 13:18:45.000000000 +0400
+++ linux-2.4.18-usb-storage/drivers/usb/device/Makefile	2003-11-07 05:35:01.000000000 +0300
@@ -20,6 +20,7 @@
 
 subdir-$(CONFIG_USBD_NET) += net_fd
 subdir-$(CONFIG_USBD_SERIAL) += serial_fd
+subdir-$(CONFIG_USBD_STORAGE) += storage_fd
 
 #subdir-$(CONFIG_USBD_GENERIC_BUS) += gen_bi
 #subdir-$(CONFIG_USBD_L7205_BUS) += l7205_bi
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/Config.help linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/Config.help
--- linux-2.4.18/drivers/usb/device/storage_fd/Config.help	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/Config.help	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,55 @@
+CONFIG_USBD_STORAGE
+  Enable the generic mass storage function driver. This function is
+  used emulating a Linux block driver.
+
+CONFIG_USBD_STORAGE_VENDORID
+  Optionally specify the mass storage USB Device Vendor ID. The top
+  level Vendor ID will be used if this is not specified.
+
+CONFIG_USBD_STORAGE_PRODUCTID
+  Optionally specify the mass storage USB Device Product ID. The top
+  level Vendor ID will be used if this is not specified.
+
+CONFIG_USBD_STORAGE_OUT_ENDPOINT
+  Specify the preferred OUT (received data) endpoint number. This is a
+  number from 0-15 and must be allowed by the bus interface device.
+
+  Some devices such as the SA-1110 or L7205/L7210 may override this
+  value with a fixed value.
+
+CONFIG_USBD_STORAGE_IN_ENDPOINT
+  Specify the preferred IN (transmit data) endpoint number. This is a
+  number from 0-15 and must be allowed by the bus interface device.
+
+  Some devices such as the SA-1110 or L7205/L7210 may override this
+  value with a fixed value.
+
+CONFIG_USBD_STORAGE_INT_ENDPOINT
+  Specify the preferred INT (interrupt) endpoint number. This is a
+  number from 0-15 and must be allowed by the bus interface device.
+
+  Some devices such as the L7205/L7210 may override this value with a
+  fixed value. Others such as the SA-1110 do not allow an interrupt
+  value.
+
+CONFIG_USBD_STORAGE_OUT_PKTSIZE
+  Specify the maximum packet size for the OUT endpoint. This allowable
+  values are normally 16, 32 and 64. 
+
+  Some devices such as the Linkup L7205/L7210 may override this value
+  with a lower maximum value (such as 32).
+
+CONFIG_USBD_STORAGE_IN_PKTSIZE
+  Specify the maximum packet size for the IN endpoint. This allowable
+  values are normally 16, 32 and 64. 
+
+  Some devices such as the Linkup L7205/L7210 may override this value
+  with a lower maximum value (such as 32).
+
+CONFIG_USBD_STORAGE_INT_PKTSIZE
+  Specify the maximum packet size for the INT endpoint. This allowable
+  values are normally 8 and 16. Some bus interface devices may not
+  support all values.
+
+CONFIG_USBD_STORAGE_DEF_DEVICE_NAME
+  Specify the default block device name to used on mass storage.
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/Config.in linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/Config.in
--- linux-2.4.18/drivers/usb/device/storage_fd/Config.in	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/Config.in	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,29 @@
+#
+#  Generic Mass Storage Function Driver
+#
+# Copyright (c) 2003 Communication Technology Inc.
+# Copyright (C) 2001 Lineo, Inc.
+# Copyright (C) 2001 Hewlett-Packard Co.
+mainmenu_option next_comment
+comment "Mass Storage Function"
+
+dep_tristate '  Mass Storage Function Driver' CONFIG_USBD_STORAGE $CONFIG_USBD
+if [ "$CONFIG_USBD_STORAGE" = "y" -o "$CONFIG_USBD_STORAGE" = "m" ]; then
+   hex     ' Overide VendorID (hex value)' CONFIG_USBD_STORAGE_VENDORID "0000"
+   hex     ' Overide ProductID (hex value)' CONFIG_USBD_STORAGE_PRODUCTID "0000"
+
+   # allow setting of endpoint configurations for some architectures
+   int     '    OUT Endpoint (0-15)' CONFIG_USBD_STORAGE_OUT_ENDPOINT "1"
+   int     '   OUT PacketSize (16, 32, 64)' CONFIG_USBD_STORAGE_OUT_PKTSIZE "64"
+   int     '    IN  Endpoint (0-15)' CONFIG_USBD_STORAGE_IN_ENDPOINT "2"
+   int     '   IN  PacketSize (16, 32, 64)' CONFIG_USBD_STORAGE_IN_PKTSIZE "64"
+
+   if [ ! "$CONFIG_ARCH_SA1100" = "y" -a ! "$CONFIG_ARCH_L7200" = "y" ]; then
+      int  '    INT Endpoint (0-15)' CONFIG_USBD_STORAGE_INT_ENDPOINT "3"
+      int  '   INT PacketSize (8, 16)' CONFIG_USBD_STORAGE_INT_PKTSIZE "16"
+   fi
+
+   string  '   Default Mass Storage device name' CONFIG_USBD_STORAGE_DEF_DEVICE_NAME ""
+fi
+
+endmenu
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/Makefile linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/Makefile
--- linux-2.4.18/drivers/usb/device/storage_fd/Makefile	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/Makefile	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,58 @@
+#
+# SA1100 Function driver for a network USB Device
+#
+# Copyright (C) 2001 Lineo, Inc.
+# Copyright (C) 2001 Hewlett-Packard Co.
+
+
+O_TARGET	:= storage_fd_drv.o
+list-multi	:= storage_fd.o
+
+storage_fd-objs	:= storage-fd.o storageproto.o schedule_task.o # netproto.o crc32.o 
+
+# Object file lists.
+
+obj-y		:=
+obj-m		:=
+obj-n		:=
+obj-		:=
+
+# Each configuration option enables a list of files.
+
+obj-$(CONFIG_USBD_STORAGE)   += storage_fd.o
+
+# Extract lists of the multi-part drivers.
+# The 'int-*' lists are the intermediate files used to build the multi's.
+
+multi-y		:= $(filter $(list-multi), $(obj-y))
+multi-m		:= $(filter $(list-multi), $(obj-m))
+int-y		:= $(sort $(foreach m, $(multi-y), $($(basename $(m))-objs)))
+int-m		:= $(sort $(foreach m, $(multi-m), $($(basename $(m))-objs)))
+
+# Files that are both resident and modular: remove from modular.
+
+obj-m		:= $(filter-out $(obj-y), $(obj-m))
+int-m		:= $(filter-out $(int-y), $(int-m))
+
+# Translate to Rules.make lists.
+
+O_OBJS		:= $(filter-out $(export-objs), $(obj-y))
+OX_OBJS		:= $(filter     $(export-objs), $(obj-y))
+M_OBJS		:= $(sort $(filter-out $(export-objs), $(obj-m)))
+MX_OBJS		:= $(sort $(filter     $(export-objs), $(obj-m)))
+MI_OBJS		:= $(sort $(filter-out $(export-objs), $(int-m)))
+MIX_OBJS	:= $(sort $(filter     $(export-objs), $(int-m)))
+
+# The global Rules.make.
+
+include $(TOPDIR)/Rules.make
+
+# Link rules for multi-part drivers.
+
+storage_fd.o: $(storage_fd-objs)
+	$(LD) -r -o $@ $(storage_fd-objs)
+
+# dependencies:
+
+storage-fd.o: ../usbd.h ../usbd-bus.h ../usbd-func.h
+
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/schedule_task.c linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/schedule_task.c
--- linux-2.4.18/drivers/usb/device/storage_fd/schedule_task.c	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/schedule_task.c	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,230 @@
+/*
+ * linux/drivers/usb/device/storage_fd/schedule_task.c - schedule task library
+ *
+ * Copyright (c) 2003 Lineo Solutions, Inc.
+ *
+ * Written by Shunnosuke kabata
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/******************************************************************************
+** Include File
+******************************************************************************/
+#include <linux/config.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/dcache.h>
+#include <linux/init.h>
+#include <linux/quotaops.h>
+#include <linux/slab.h>
+#include <linux/cache.h>
+#include <linux/swap.h>
+#include <linux/swapctl.h>
+#include <linux/prefetch.h>
+#include <linux/locks.h>
+#include <asm/uaccess.h>
+
+#include "schedule_task.h"
+
+/******************************************************************************
+** Macro Define
+******************************************************************************/
+#define TASK_DESC_NUM   (512)
+
+/******************************************************************************
+** Structure Define
+******************************************************************************/
+
+/**************************************
+** TASK_DESC
+**************************************/
+typedef struct _TASK_DESC{
+    struct _TASK_DESC*  next;
+    SCHEDULE_TASK_FUNC  task_entry;
+    int                 task_param1;
+    int                 task_param2;
+    int                 task_param3;
+    int                 task_param4;
+    int                 task_param5;
+    char*               file;
+    int                 line;
+} TASK_DESC;
+
+/**************************************
+** OS_WRP_TASK_DATA
+**************************************/
+typedef struct{
+    volatile TASK_DESC* read_desc;
+    volatile TASK_DESC* write_desc;
+    TASK_DESC           desc_pool[TASK_DESC_NUM];
+    spinlock_t          spin_lock;
+    struct tq_struct    task_que;
+    unsigned long       use_num;
+    unsigned long       max_num;
+} TASK_DATA;
+
+/******************************************************************************
+** Variable Declaration
+******************************************************************************/
+static TASK_DATA    TaskData;
+
+/******************************************************************************
+** Local Function Prototype
+******************************************************************************/
+static void task_entry(void*);
+
+/******************************************************************************
+** Global Function
+******************************************************************************/
+void schedule_task_init(void)
+{
+    int i;
+    
+    /* 0 clear */
+    memset(&TaskData, 0x00, sizeof(TaskData));
+    
+    /* Read/write pointer initialize */
+    TaskData.read_desc = TaskData.write_desc = &TaskData.desc_pool[0];
+    
+    /* Ling buffer initialize */
+    for(i=0; i<(TASK_DESC_NUM-1); i++){
+        TaskData.desc_pool[i].next = &TaskData.desc_pool[i+1];
+    }
+    TaskData.desc_pool[i].next = &TaskData.desc_pool[0];
+    
+    /* Spin lock initialize */
+    spin_lock_init(&TaskData.spin_lock);
+    
+    /* Task queue initialize */
+    PREPARE_TQUEUE(&TaskData.task_que, task_entry, &TaskData);
+    
+    return;
+}
+
+int schedule_task_register(SCHEDULE_TASK_FUNC entry, int param1, int param2,
+                           int param3, int param4, int param5)
+{
+    unsigned long   flags = 0;
+    
+    spin_lock_irqsave(&TaskData.spin_lock, flags);
+    
+    /* Free descriptor check */
+    if(TaskData.write_desc->next == TaskData.read_desc){
+        printk(KERN_INFO "storage_fd: schedule task no descriptor.\n");
+        spin_unlock_irqrestore(&TaskData.spin_lock, flags);
+        return -1;
+    }
+    
+    /* Descriptor set */
+    TaskData.write_desc->task_entry  = entry;
+    TaskData.write_desc->task_param1 = param1;
+    TaskData.write_desc->task_param2 = param2;
+    TaskData.write_desc->task_param3 = param3;
+    TaskData.write_desc->task_param4 = param4;
+    TaskData.write_desc->task_param5 = param5;
+    
+    /* Pointer update */
+    TaskData.write_desc = TaskData.write_desc->next;
+    
+    /* Statistics set */
+    TaskData.use_num++;
+    if(TaskData.use_num > TaskData.max_num){
+        TaskData.max_num = TaskData.use_num;
+    }
+    
+    spin_unlock_irqrestore(&TaskData.spin_lock, flags);
+    
+    /* Task queue register */
+    schedule_task(&TaskData.task_que);
+    
+    return 0;
+}
+
+void schedule_task_all_unregister(void)
+{
+    unsigned long   flags = 0;
+    
+    spin_lock_irqsave(&TaskData.spin_lock, flags);
+    TaskData.read_desc = TaskData.write_desc;
+    TaskData.use_num = 0;
+    spin_unlock_irqrestore(&TaskData.spin_lock, flags);
+}
+
+ssize_t schedule_task_proc_read(struct file* file, char* buf, size_t count,
+                                loff_t* pos)
+{
+    char    string[1024];
+    int     len = 0;
+
+    len += sprintf(string + len, "Schedule task max num:0x%d\n",
+            TASK_DESC_NUM);
+
+    len += sprintf(string + len, "Schedule task use num:0x%ld\n",
+            TaskData.use_num);
+
+    len += sprintf(string + len, "Schedule task max use num:0x%ld\n",
+            TaskData.max_num);
+    
+    *pos += len;
+    if(len > count){
+        len = -EINVAL;
+    }
+    else
+    if(len > 0 && copy_to_user(buf, string, len)) {
+        len = -EFAULT;
+    }
+
+    return len;
+}
+
+/******************************************************************************
+** Local Function
+******************************************************************************/
+static void task_entry(void* data)
+{
+    int                 cond;
+    unsigned long       flags = 0;
+    volatile TASK_DESC* desc;
+    
+    for(;;){
+        
+        spin_lock_irqsave(&TaskData.spin_lock, flags);
+        desc = TaskData.read_desc;
+        cond = (TaskData.read_desc == TaskData.write_desc);
+        spin_unlock_irqrestore(&TaskData.spin_lock, flags);
+        
+        if(cond) break;
+        
+        /* Task call */
+        desc->task_entry(desc->task_param1, desc->task_param2,
+                      desc->task_param3, desc->task_param4, desc->task_param5);
+        
+        spin_lock_irqsave(&TaskData.spin_lock, flags);
+        
+        /* Pointer update */
+        TaskData.read_desc = TaskData.read_desc->next;
+        
+        /* Statistics set */
+        TaskData.use_num--;
+        
+        spin_unlock_irqrestore(&TaskData.spin_lock, flags);
+    }
+    
+    return;
+}
+
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/schedule_task.h linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/schedule_task.h
--- linux-2.4.18/drivers/usb/device/storage_fd/schedule_task.h	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/schedule_task.h	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,41 @@
+/*
+ * linux/drivers/usb/device/storage_fd/schedule_task.h - schedule task library header
+ *
+ * Copyright (c) 2003 Lineo Solutions, Inc.
+ *
+ * Written by Shunnosuke kabata
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _SCHEDULE_TASK_H_
+#define _SCHEDULE_TASK_H_
+
+/******************************************************************************
+** Macro Define
+******************************************************************************/
+typedef int (*SCHEDULE_TASK_FUNC)(int, int, int, int, int);
+
+/******************************************************************************
+** Global Function Prototype
+******************************************************************************/
+void    schedule_task_init(void);
+int     schedule_task_register(SCHEDULE_TASK_FUNC, int, int, int, int, int);
+void    schedule_task_all_unregister(void);
+ssize_t schedule_task_proc_read(struct file*, char*, size_t, loff_t*);
+
+#endif  /* _SCHEDULE_TASK_H_ */
+
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/storage-fd.c linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/storage-fd.c
--- linux-2.4.18/drivers/usb/device/storage_fd/storage-fd.c	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/storage-fd.c	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,865 @@
+/*
+ * linux/drivers/usb/device/storage_fd/storage-fd.c - mass storage function driver
+ *
+ * Copyright (c) 2003 Lineo Solutions, Inc.
+ *
+ * Written by Shunnosuke kabata
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Based on
+ *
+ * linux/drivers/usbd/net_fd/net-fd.c - network function driver
+ *
+ * Copyright (c) 2000, 2001, 2002 Lineo
+ * Copyright (c) 2001 Hewlett Packard
+ *
+ * By: 
+ *      Stuart Lynne <sl@lineo.com>, 
+ *      Tom Rushworth <tbr@lineo.com>, 
+ *      Bruce Balden <balden@lineo.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 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.
+ *
+ */
+
+/******************************************************************************
+** Include File
+******************************************************************************/
+#include <linux/config.h>
+#include <linux/module.h>
+
+#include "../usbd-export.h"
+#include "../usbd-build.h"
+#include "../usbd-module.h"
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/smp_lock.h>
+#include <linux/ctype.h>
+#include <linux/timer.h>
+#include <linux/string.h>
+#include <linux/atmdev.h>
+#include <linux/pkt_sched.h>
+#include <linux/delay.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <net/arp.h>
+
+#include <linux/autoconf.h>
+
+#include "../usbd.h"
+#include "../usbd-func.h"
+#include "../usbd-bus.h"
+#include "../usbd-inline.h"
+#include "../usbd-arch.h"
+#include "../hotplug.h"
+
+#include "schedule_task.h"
+#include "storageproto.h"
+
+/******************************************************************************
+** Macro Define
+******************************************************************************/
+
+/**************************************
+** Module Information
+**************************************/
+
+MODULE_AUTHOR("Shunnosuke kabata");
+MODULE_DESCRIPTION("USB Device Mass Storage Function");
+USBD_MODULE_INFO("storage_fd 0.1");
+
+/**************************************
+** Configration Check
+**************************************/
+
+#if !defined (CONFIG_USBD_VENDORID) && !defined(CONFIG_USBD_STORAGE_VENDORID)
+#error No Vendor ID
+#endif
+#if !defined (CONFIG_USBD_PRODUCTID) && !defined(CONFIG_USBD_STORAGE_PRODUCTID)
+#error No Product ID
+#endif
+
+#if defined(CONFIG_USBD_STORAGE_VENDORID) && (CONFIG_USBD_STORAGE_VENDORID > 0)
+#undef CONFIG_USBD_VENDORID
+#define CONFIG_USBD_VENDORID    CONFIG_USBD_STORAGE_VENDORID
+#endif
+
+#if defined(CONFIG_USBD_STORAGE_PRODUCTID) && (CONFIG_USBD_STORAGE_PRODUCTID > 0)
+#undef CONFIG_USBD_PRODUCTID
+#define CONFIG_USBD_PRODUCTID   CONFIG_USBD_STORAGE_PRODUCTID
+#endif
+
+#ifndef CONFIG_USBD_MAXPOWER
+#define CONFIG_USBD_MAXPOWER            0
+#endif
+
+#ifndef CONFIG_USBD_MANUFACTURER
+#define CONFIG_USBD_MANUFACTURER        "Sharp"
+#endif
+
+#define MAXTRANSFER                     (512)
+
+#ifndef CONFIG_USBD_VENDORID
+#error "CONFIG_USBD_VENDORID not defined"
+#endif
+
+#ifndef CONFIG_USBD_PRODUCTID
+#error "CONFIG_USBD_PRODUCTID not defined"
+#endif
+
+#ifndef CONFIG_USBD_PRODUCT_NAME
+#define CONFIG_USBD_PRODUCT_NAME        "Linux Mass Storage Driver"
+#endif
+
+#ifndef CONFIG_USBD_SERIAL_NUMBER_STR
+#define CONFIG_USBD_SERIAL_NUMBER_STR   ""
+#endif
+
+/*
+ * USB 2.0 spec does not mention it, but MaxPower is expected to be at least one 
+ * and is tested for in USB configuration tests.
+ */
+
+#ifdef CONFIG_USBD_SELFPOWERED
+#define BMATTRIBUTE BMATTRIBUTE_RESERVED | BMATTRIBUTE_SELF_POWERED
+#define BMAXPOWER   1
+#else
+#define BMATTRIBUTE BMATTRIBUTE_RESERVED
+#define BMAXPOWER   CONFIG_USBD_MAXPOWER
+#endif
+
+/*
+ * setup some default values for pktsizes and endpoint addresses.
+ */
+
+#ifndef CONFIG_USBD_STORAGE_OUT_PKTSIZE
+#define CONFIG_USBD_STORAGE_OUT_PKTSIZE     64
+#endif
+
+#ifndef CONFIG_USBD_STORAGE_IN_PKTSIZE
+#define CONFIG_USBD_STORAGE_IN_PKTSIZE      64
+#endif
+
+#ifndef CONFIG_USBD_STORAGE_INT_PKTSIZE
+#define CONFIG_USBD_STORAGE_INT_PKTSIZE     16
+#endif
+
+#ifndef CONFIG_USBD_STORAGE_OUT_ENDPOINT
+#define CONFIG_USBD_STORAGE_OUT_ENDPOINT    1
+#endif
+
+#ifndef CONFIG_USBD_STORAGE_IN_ENDPOINT
+#define CONFIG_USBD_STORAGE_IN_ENDPOINT     2
+#endif
+
+#ifndef CONFIG_USBD_STORAGE_INT_ENDPOINT
+#define CONFIG_USBD_STORAGE_INT_ENDPOINT    3
+#endif
+
+/*
+ * check for architecture specific endpoint configurations
+ */
+
+#if defined(ABS_OUT_ADDR)
+    //#warning
+    //#warning USING ABS ENDPOINT OUT ADDRESS
+    #undef CONFIG_USBD_STORAGE_OUT_ENDPOINT
+
+    #if ABS_OUT_ADDR > 0
+        #define CONFIG_USBD_STORAGE_OUT_ENDPOINT    ABS_OUT_ADDR
+    #endif
+
+#elif defined(MAX_OUT_ADDR) && defined(CONFIG_USBD_STORAGE_OUT_ENDPOINT) && (CONFIG_USBD_STORAGE_OUT_ENDPOINT > MAX_OUT_ADDR)
+    //#warning
+    //#warning USING DEFAULT ENDPOINT OUT ADDRESS
+    #undef CONFIG_USBD_STORAGE_OUT_ENDPOINT
+    #define CONFIG_USBD_STORAGE_OUT_ENDPOINT        DFL_OUT_ADDR
+
+#endif  /* elif */
+
+#if defined(ABS_IN_ADDR)
+    //#warning
+    //#warning USING ABS ENDPOINT IN ADDRESS
+    #undef CONFIG_USBD_STORAGE_IN_ENDPOINT
+
+    #if ABS_IN_ADDR > 0
+        #define CONFIG_USBD_STORAGE_IN_ENDPOINT     ABS_IN_ADDR
+    #endif
+
+#elif defined(MAX_IN_ADDR) && defined(CONFIG_USBD_STORAGE_IN_ENDPOINT) && (CONFIG_USBD_STORAGE_IN_ENDPOINT > MAX_IN_ADDR)
+    //#warning
+    //#warning USING DEFAULT ENDPOINT IN ADDRESS
+    #undef CONFIG_USBD_STORAGE_IN_ENDPOINT
+    #define CONFIG_USBD_STORAGE_IN_ENDPOINT         DFL_IN_ADDR
+
+#endif  /* elif */
+
+#if defined(ABS_INT_ADDR)
+    //#warning
+    //#warning USING ABS ENDPOINT INT ADDRESS
+    #undef CONFIG_USBD_STORAGE_INT_ENDPOINT
+
+    #if ABS_INT_ADDR
+        #define CONFIG_USBD_STORAGE_INT_ENDPOINT    ABS_INT_ADDR
+    #endif
+
+#elif defined(MAX_INT_ADDR) && defined(CONFIG_USBD_STORAGE_INT_ENDPOINT) && (CONFIG_USBD_STORAGE_INT_ENDPOINT > MAX_INT_ADDR)
+    //#warning
+    //#warning USING DEFAULT ENDPOINT INT ADDRESS
+    #undef CONFIG_USBD_STORAGE_INT_ENDPOINT
+    #define CONFIG_USBD_STORAGE_INT_ENDPOINT        DFL_INT_ADDR
+
+#endif  /* elif */
+
+#if defined(MAX_OUT_PKTSIZE) && defined(CONFIG_USBD_STORAGE_OUT_PKTSIZE) && CONFIG_USBD_STORAGE_OUT_PKTSIZE > MAX_OUT_PKTSIZE
+    //#warning
+    //#warning OVERIDING ENDPOINT OUT PKTSIZE 
+    #undef CONFIG_USBD_STORAGE_OUT_PKTSIZE
+    #define CONFIG_USBD_STORAGE_OUT_PKTSIZE         MAX_OUT_PKTSIZE
+#endif
+
+#if defined(MAX_IN_PKTSIZE) && defined(CONFIG_USBD_STORAGE_IN_PKTSIZE) && CONFIG_USBD_STORAGE_IN_PKTSIZE > MAX_IN_PKTSIZE
+    //#warning
+    //#warning OVERIDING ENDPOINT IN PKTSIZE 
+    #undef CONFIG_USBD_STORAGE_IN_PKTSIZE
+    #define CONFIG_USBD_STORAGE_IN_PKTSIZE          MAX_IN_PKTSIZE
+#endif
+
+#if defined(MAX_INT_PKTSIZE) && defined(CONFIG_USBD_STORAGE_INT_PKTSIZE) && CONFIG_USBD_STORAGE_INT_PKTSIZE > MAX_INT_PKTSIZE
+    //#warning
+    //#warning OVERIDING ENDPOINT INT PKTSIZE
+    #undef CONFIG_USBD_STORAGE_INT_PKTSIZE
+    #define CONFIG_USBD_STORAGE_INT_PKTSIZE         MAX_INT_PKTSIZE
+#endif
+
+/******************************************************************************
+** Variable Declaration
+******************************************************************************/
+
+/**************************************
+** Module Parameters
+**************************************/
+
+static u32  vendor_id;
+static u32  product_id;
+static int  out_pkt_sz = CONFIG_USBD_STORAGE_OUT_PKTSIZE;
+static int  in_pkt_sz  = CONFIG_USBD_STORAGE_IN_PKTSIZE;
+
+MODULE_PARM(vendor_id, "i");
+MODULE_PARM(product_id, "i");
+MODULE_PARM(out_pkt_sz, "i");
+MODULE_PARM(in_pkt_sz, "i");
+
+MODULE_PARM_DESC(vendor_id, "vendor id");
+MODULE_PARM_DESC(product_id, "product id");
+
+/**************************************
+** Mass Storage Configuration
+**************************************/
+
+/*
+ * Data Interface Alternate 1 endpoints
+ */
+static __initdata struct usb_endpoint_description StorageAlt1Endpoints[] = {
+    {
+        bEndpointAddress:CONFIG_USBD_STORAGE_OUT_ENDPOINT,
+        bmAttributes:BULK,
+        wMaxPacketSize:CONFIG_USBD_STORAGE_OUT_PKTSIZE,
+        bInterval:0,
+        direction:OUT,
+        transferSize:MAXTRANSFER,
+    },
+
+    {
+        bEndpointAddress:CONFIG_USBD_STORAGE_IN_ENDPOINT,
+        bmAttributes:BULK,
+        wMaxPacketSize:CONFIG_USBD_STORAGE_IN_PKTSIZE,
+        bInterval:0,
+        direction:IN,
+        transferSize:MAXTRANSFER,
+    },
+
+#if defined(CONFIG_USBD_STORAGE_INT_ENDPOINT) && (CONFIG_USBD_STORAGE_INT_ENDPOINT > 0)
+    {
+        bEndpointAddress:CONFIG_USBD_STORAGE_INT_ENDPOINT,
+        bmAttributes:INTERRUPT,
+        wMaxPacketSize:CONFIG_USBD_STORAGE_INT_PKTSIZE,
+        bInterval:10,
+        direction:IN,
+        transferSize:CONFIG_USBD_STORAGE_INT_PKTSIZE,
+    },
+#endif
+};
+
+
+/*
+ * Data Interface Alternate description(s)
+ */
+static __initdata struct usb_alternate_description StorageAlternateDescriptions[] = {
+    {
+        #if defined(CONFIG_USBD_STORAGE_NO_STRINGS)
+        iInterface:"",
+        #else
+        iInterface:"Mass Storage Interface",
+        #endif
+        bAlternateSetting:0,
+        classes:0,
+        class_list:NULL,
+        endpoints:sizeof (StorageAlt1Endpoints) / sizeof (struct usb_endpoint_description),
+        endpoint_list:StorageAlt1Endpoints,
+    },
+};
+
+/*
+ * Interface description(s)
+ */
+static __initdata struct usb_interface_description StorageInterfaces[] = {
+    {
+        #if defined(CONFIG_USBD_STORAGE_NO_STRINGS)
+        iInterface:"",
+        #else
+        iInterface:"Mass Storage Interface",
+        #endif
+        bInterfaceClass:MASS_STORAGE_CLASS,
+        bInterfaceSubClass:MASS_STORAGE_SUBCLASS_SCSI,
+        bInterfaceProtocol:MASS_STORAGE_PROTO_BULK_ONLY,
+        alternates:sizeof (StorageAlternateDescriptions) / sizeof (struct usb_alternate_description),
+        alternate_list:StorageAlternateDescriptions,
+    },
+};
+
+/******************************************************************************
+** USB Configuration
+******************************************************************************/
+
+/*
+ * Configuration description(s)
+ */
+struct __initdata usb_configuration_description StorageDescription[] = {
+    {
+        #if defined(CONFIG_USBD_STORAGE_NO_STRINGS)
+        iConfiguration:"",
+        #else
+        iConfiguration:"Mass Storage Configuration",
+        #endif
+        bmAttributes:BMATTRIBUTE,
+        bMaxPower:BMAXPOWER,
+        interfaces:sizeof (StorageInterfaces) / sizeof (struct usb_interface_description),
+        interface_list:StorageInterfaces,
+    },
+};
+
+/*
+ * Device Description
+ */
+struct __initdata usb_device_description StorageDeviceDescription = {
+    bDeviceClass:0,
+    bDeviceSubClass:0,  // XXX
+    bDeviceProtocol:0,  // XXX
+    idVendor:CONFIG_USBD_VENDORID,
+    idProduct:CONFIG_USBD_PRODUCTID,
+    iManufacturer:CONFIG_USBD_MANUFACTURER,
+    iProduct:CONFIG_USBD_PRODUCT_NAME,
+    iSerialNumber:CONFIG_USBD_SERIAL_NUMBER_STR,
+};
+
+/**************************************
+** Other Variable
+**************************************/
+static int              storage_exit_flag = 0;
+static pid_t            storage_pid = 0;
+static struct semaphore storage_sem;
+struct timer_list       storage_usb_event_tim;
+
+
+/******************************************************************************
+** Global Function
+******************************************************************************/
+
+void storage_urb_send(struct usb_device_instance* device, void* buffer,
+                      int length)
+{
+    int         port = 0;
+    struct urb* urb;
+
+    if(!(urb = usbd_alloc_urb(device,
+                              device->function_instance_array + port,
+                              CONFIG_USBD_STORAGE_IN_ENDPOINT,
+                              length + 5 + in_pkt_sz))){
+        printk(KERN_INFO "storage_fd: usbd_alloc_urb failed. length '%d'.\n", length);
+        return;
+    }
+
+    if(buffer){
+        memcpy(urb->buffer, buffer, length);
+    }
+    else{
+        memset(urb->buffer, 0x00, length);
+    }
+    urb->actual_length = length;
+
+    if(usbd_send_urb(urb)){
+        printk(KERN_INFO "storage_fd: usbd_send_urb failed.\n");
+        usbd_dealloc_urb(urb);
+        return;
+    }
+
+    return;
+}
+
+/******************************************************************************
+** Local Function
+******************************************************************************/
+
+/**************************************
+** Called when a USB Device is created or destroyed
+**************************************/
+
+static int storage_thread(void *_c)
+{
+    siginfo_t           info;
+    unsigned long       signr;
+    char                buff[32];
+
+    /* current status set */
+    daemonize();
+
+    /* PID set */
+    storage_pid = current->pid;
+
+    /* thread name set */
+    sprintf(current->comm, STORAGE_THREAD_NAME);
+    (current)->nice = 10;
+
+    /* signal register */
+    spin_lock_irq(&current->sigmask_lock);
+    siginitsetinv(&current->blocked,
+                  sigmask(SIGUSR1) | sigmask(SIGHUP) | sigmask(SIGKILL) |
+                  sigmask(SIGSTOP) | sigmask(SIGCONT) | sigmask(SIGTERM) |
+                  sigmask(SIGALRM));
+    recalc_sigpending(current);
+    spin_unlock_irq(&current->sigmask_lock);
+
+    /* media open */
+    schedule_task_register(
+        (SCHEDULE_TASK_FUNC)storageproto_media_status_check, CONTEXT_STORAGE,
+        0, 0, 0, 0);
+
+    /* thread active indicate */
+    sprintf(buff, "%d\n", storage_pid);
+    hotplug("usbdstorage", buff, "active");
+
+    for(;;){
+        set_current_state(TASK_INTERRUPTIBLE);
+
+        if (!signal_pending(current)) {
+            schedule();
+            continue;
+        }
+
+        spin_lock_irq(&current->sigmask_lock);
+        signr = dequeue_signal(&current->blocked, &info);
+        spin_unlock_irq(&current->sigmask_lock);
+
+        switch(signr) {
+        case SIGHUP:
+            /* media signal indicate */
+            schedule_task_register(
+                (SCHEDULE_TASK_FUNC)storageproto_media_status_check, CONTEXT_STORAGE,
+                0, 0, 0, 0);
+
+            DBG_STORAGE_FD(KERN_INFO "storage_fd: signal receive 'SIGHUP'.\n");
+            break;
+
+        default:
+            DBG_STORAGE_FD(KERN_INFO "storage_fd: signal receive '%ld'\n", signr);
+            break;
+        }
+
+        if(storage_exit_flag) break;
+    }
+    /* current status set */
+    current->state = TASK_RUNNING;
+
+    /* PID clear */
+    storage_pid = 0;
+
+    /* thread inactive indicate */
+    hotplug("usbdstorage", buff, "inactive");
+
+    up(&storage_sem);
+
+    return 0;
+}
+
+static void storage_function_init(struct usb_bus_instance* bus,
+                              struct usb_device_instance* device,
+                              struct usb_function_driver* function_driver)
+{
+    /* schedule task init */
+    schedule_task_init();
+
+    /* storage protocol initialize */
+    storageproto_init();
+
+    /* semaphore init */
+    sema_init(&storage_sem, 0);
+
+    /* timer initialize */
+    init_timer(&storage_usb_event_tim);
+
+    /* thread create */
+    storage_pid = kernel_thread(storage_thread, NULL, 0);
+
+    return;
+}
+
+static void storage_function_exit(struct usb_device_instance* device)
+{
+    /* thread kill */
+    storage_exit_flag = 1;
+    kill_proc(storage_pid, SIGKILL, 1);
+    down(&storage_sem);
+
+    /* delete timer */
+    del_timer(&storage_usb_event_tim);
+
+    /* storage protocol exit */
+    storageproto_exit();
+
+    /* schedule task delete */
+    schedule_task_all_unregister();
+
+    return;
+}
+
+
+/**************************************
+** Called to handle USB Events
+**************************************/
+
+static void storage_usb_event_delay_timeout(unsigned long param)
+{
+    /* media signal indicate */
+    schedule_task_register(
+        (SCHEDULE_TASK_FUNC)storageproto_usb_status_check, (int)param,
+        0, 0, 0, 0);
+
+    return;
+}
+
+/*
+ * storage_event - process a device event
+ * @device: usb device 
+ * @event: the event that happened
+ *
+ * Called by the usb device core layer to respond to various USB events.
+ *
+ * This routine IS called at interrupt time. Please use the usual precautions.
+ *
+ */
+void storage_event(struct usb_device_instance* device,
+                   usb_device_event_t event, int data)
+{
+#if 0
+    static struct {
+        usb_device_event_t  event;
+        char*               string;
+    } eventAnal[] = {
+        {DEVICE_UNKNOWN,            "DEVICE_UNKNOWN"},
+        {DEVICE_INIT,               "DEVICE_INIT"},
+        {DEVICE_CREATE,             "DEVICE_CREATE"},
+        {DEVICE_HUB_CONFIGURED,     "DEVICE_HUB_CONFIGURED"},
+        {DEVICE_RESET,              "DEVICE_RESET"},
+        {DEVICE_ADDRESS_ASSIGNED,   "DEVICE_ADDRESS_ASSIGNED"},
+        {DEVICE_CONFIGURED,         "DEVICE_CONFIGURED"},
+        {DEVICE_SET_INTERFACE,      "DEVICE_SET_INTERFACE"},
+        {DEVICE_SET_FEATURE,        "DEVICE_SET_FEATURE"},
+        {DEVICE_CLEAR_FEATURE,      "DEVICE_CLEAR_FEATURE"},
+        {DEVICE_DE_CONFIGURED,      "DEVICE_DE_CONFIGURED"},
+        {DEVICE_BUS_INACTIVE,       "DEVICE_BUS_INACTIVE"},
+        {DEVICE_BUS_ACTIVITY,       "DEVICE_BUS_ACTIVITY"},
+        {DEVICE_POWER_INTERRUPTION, "DEVICE_POWER_INTERRUPTION"},
+        {DEVICE_HUB_RESET,          "DEVICE_HUB_RESET"},
+        {DEVICE_DESTROY,            "DEVICE_DESTROY"},
+        {DEVICE_FUNCTION_PRIVATE,   "DEVICE_FUNCTION_PRIVATE"}
+    };
+    int i;
+
+    for(i=0; i<(sizeof(eventAnal)/sizeof(eventAnal[0])); i++){
+        if(event == eventAnal[i].event){
+            DBG_STORAGE_FD(KERN_INFO "storage_fd: event receive '%s'.\n",
+                eventAnal[i].string);
+            break;
+        }
+    }
+    if(i == (sizeof(eventAnal)/sizeof(eventAnal[0]))){
+        DBG_STORAGE_FD(KERN_INFO "storage_fd: unknown event receive.\n");
+    }
+#endif
+
+    switch(event){
+    case DEVICE_ADDRESS_ASSIGNED:
+        {
+        static int  Is1stCheck = 1;
+        if(Is1stCheck){
+            Is1stCheck = 0;
+
+            /* delay timer set */
+            del_timer(&storage_usb_event_tim);
+            storage_usb_event_tim.expires  = jiffies + ((USB_EVENT_DELAY_TIM * HZ) / 1000);
+            storage_usb_event_tim.data     = USB_DISCONNECT;
+            storage_usb_event_tim.function = storage_usb_event_delay_timeout;
+            add_timer(&storage_usb_event_tim);
+            break;
+        }
+        }
+    case DEVICE_BUS_ACTIVITY:
+        /* delay timer set */
+        del_timer(&storage_usb_event_tim);
+        storage_usb_event_tim.expires  = jiffies + ((USB_EVENT_DELAY_TIM * HZ) / 1000);
+        storage_usb_event_tim.data     = USB_CONNECT;
+        storage_usb_event_tim.function = storage_usb_event_delay_timeout;
+        add_timer(&storage_usb_event_tim);
+        break;
+
+    case DEVICE_BUS_INACTIVE:
+        /* delay timer set */
+        del_timer(&storage_usb_event_tim);
+        storage_usb_event_tim.expires  = jiffies + ((USB_EVENT_DELAY_TIM * HZ) / 1000);
+        storage_usb_event_tim.data     = USB_DISCONNECT;
+        storage_usb_event_tim.function = storage_usb_event_delay_timeout;
+        add_timer(&storage_usb_event_tim);
+        break;
+
+    case DEVICE_RESET:
+        schedule_task_register(
+            (SCHEDULE_TASK_FUNC)storageproto_usb_reset_ind,
+            0, 0, 0, 0, 0);
+        break;
+
+    default:
+        break;
+    }
+
+    return;
+}
+
+/*
+ * storage_recv_setup - called with a control URB 
+ * @urb - pointer to struct urb
+ *
+ * Check if this is a setup packet, process the device request, put results
+ * back into the urb and return zero or non-zero to indicate success (DATA)
+ * or failure (STALL).
+ *
+ * This routine IS called at interrupt time. Please use the usual precautions.
+ *
+ */
+int storage_recv_setup(struct urb* urb)
+{
+    return 0;
+}
+
+/*
+ * storage_recv_urb - called with a received URB 
+ * @urb - pointer to struct urb
+ *
+ * Return non-zero if we failed and urb is still valid (not disposed)
+ *
+ * This routine IS called at interrupt time. Please use the usual precautions.
+ *
+ */
+int storage_recv_urb(struct urb* urb)
+{
+    int                             port = 0;   // XXX compound device
+    struct usb_device_instance*     device;
+    struct usb_function_instance*   function;
+
+    if(!urb || !(device = urb->device) ||
+       !(function = device->function_instance_array + port)){
+        return -EINVAL;
+    }
+
+    if(urb->status != RECV_OK){
+        return -EINVAL;
+    }
+
+    /* URB urb_analysis */
+    schedule_task_register(
+        (SCHEDULE_TASK_FUNC)storageproto_urb_analysis, (int)urb,
+        0, 0, 0, 0);
+
+    return 0;
+}
+
+/*
+ * storage_urb_sent - called to indicate URB transmit finished
+ * @urb: pointer to struct urb
+ * @rc: result
+ *
+ * The usb device core layer will use this to let us know when an URB has
+ * been finished with.
+ *
+ * This routine IS called at interrupt time. Please use the usual precautions.
+ *
+ */
+int storage_urb_sent(struct urb* urb, int rc)
+{
+    int                             port = 0;   // XXX compound device
+    struct usb_device_instance*     device;
+    struct usb_function_instance*   function;
+
+    if(!urb || !(device = urb->device) ||
+       !(function = device->function_instance_array + port)){
+        return -EINVAL;
+    }
+
+    usbd_dealloc_urb (urb);
+
+    return 0;
+}
+
+/**************************************
+** Proc file system
+**************************************/
+
+static ssize_t storage_proc_read(struct file* file, char* buf, size_t count,
+                                 loff_t* pos)
+{
+    int len = 0, ret;
+
+    if(*pos > 0) return 0;
+
+    if((ret = storageproto_proc_read(file, buf + len, count - len, pos)) < 0){
+        return ret;
+    }
+    len += ret;
+
+    if((ret = schedule_task_proc_read(file, buf + len, count - len, pos)) < 0){
+        return ret;
+    }
+    len += ret;
+
+    return len;
+}
+
+static struct file_operations StorageProcOps = {
+    read:storage_proc_read,
+};
+
+/**************************************
+** Module init and exit
+**************************************/
+
+struct usb_function_operations StorageFunctionOps = {
+    event:storage_event,
+    recv_urb:storage_recv_urb,
+    recv_setup:storage_recv_setup,
+    urb_sent:storage_urb_sent,
+    function_init:storage_function_init,
+    function_exit:storage_function_exit,
+};
+
+struct usb_function_driver StorageFunctionDriver = {
+    name:"Mass Storage",
+    ops:&StorageFunctionOps,
+    device_description:&StorageDeviceDescription,
+    configurations:sizeof (StorageDescription) / sizeof (struct usb_configuration_description),
+    configuration_description:StorageDescription,
+    this_module:THIS_MODULE,
+};
+
+/*
+ * net_modinit - module init
+ *
+ */
+static int __init net_modinit(void)
+{
+    struct proc_dir_entry*  proc_entry;
+
+    printk(KERN_INFO "storage_fd: %s (OUT=%d,IN=%d)\n",
+        __usbd_module_info, out_pkt_sz, in_pkt_sz);
+
+    printk(KERN_INFO "storage_fd: vendorID: %x productID: %x\n",
+        CONFIG_USBD_VENDORID, CONFIG_USBD_PRODUCTID);
+
+    // verify pkt sizes not too small
+    if (out_pkt_sz < 3 || in_pkt_sz < 3){
+        printk(KERN_INFO "storage_fd: Rx pkt size %d or Tx pkt size %d too small\n",
+            out_pkt_sz, in_pkt_sz);
+        return (-EINVAL);
+    }
+
+    if(vendor_id){
+        StorageDeviceDescription.idVendor = vendor_id;
+    }
+    if(product_id){
+        StorageDeviceDescription.idProduct = product_id;
+    }
+
+    // register us with the usb device support layer
+    if(usbd_register_function(&StorageFunctionDriver)){
+        printk(KERN_INFO "storage_fd: usbd_register_function failed.\n");
+        return -EINVAL;
+    }
+
+    // create proc entry
+    if ((proc_entry = create_proc_entry("usb-storage", 0, 0)) == NULL) {
+        usbd_deregister_function (&StorageFunctionDriver);
+        printk(KERN_INFO "storage_fd: create_proc_entry failed.\n");
+        return -ENOMEM;
+    }
+    proc_entry->proc_fops = &StorageProcOps;
+
+    return 0;
+}
+
+/*
+ * function_exit - module cleanup
+ *
+ */
+static void __exit net_modexit (void)
+{
+    // de-register us with the usb device support layer
+    usbd_deregister_function (&StorageFunctionDriver);
+
+    // remove proc entry
+    remove_proc_entry("usb-storage", NULL);
+
+    return;
+}
+
+module_init (net_modinit);
+module_exit (net_modexit);
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/storageproto.c linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/storageproto.c
--- linux-2.4.18/drivers/usb/device/storage_fd/storageproto.c	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/storageproto.c	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,1505 @@
+/*
+ * linux/drivers/usb/device/storage_fd/storageproto.c - mass storage protocol library
+ *
+ * Copyright (c) 2003 Lineo Solutions, Inc.
+ *
+ * Written by Shunnosuke kabata
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/******************************************************************************
+** Include File
+******************************************************************************/
+#include <linux/config.h>
+#include <linux/module.h>
+
+#include "../usbd-export.h"
+#include "../usbd-build.h"
+#include "../usbd-module.h"
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/smp_lock.h>
+#include <linux/ctype.h>
+#include <linux/timer.h>
+#include <linux/string.h>
+#include <linux/atmdev.h>
+#include <linux/pkt_sched.h>
+#include <linux/delay.h>
+#include <linux/blkdev.h>
+#include <linux/file.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <net/arp.h>
+
+#include <linux/autoconf.h>
+
+#include "../usbd.h"
+#include "../usbd-func.h"
+#include "../usbd-bus.h"
+#include "../usbd-inline.h"
+#include "../usbd-arch.h"
+#include "../hotplug.h"
+
+#include "schedule_task.h"
+#include "storageproto.h"
+
+/******************************************************************************
+** macro define
+******************************************************************************/
+
+#define DEVICE_BLOCK_SIZE       512
+
+#define BLOCK_BUFFER_SIZE       (1024 * 64)
+
+#define DEF_NUMBER_OF_HEADS     0x10
+#define DEF_SECTORS_PER_TRACK   0x20
+
+/******************************************************************************
+** Structure Define
+******************************************************************************/
+
+typedef struct{
+    unsigned char   scsi_command;
+    unsigned char*  command_name;
+    void            (*scsi_func)(struct usb_device_instance*,
+                                 COMMAND_BLOCK_WRAPPER*);
+} SCSI_ANALYSIS_TBL;
+
+typedef struct{
+    unsigned char   scsi_command;
+    unsigned char*  command_name;
+    void            (*bulkout_func)(struct usb_device_instance*,
+                                    void*, int);
+} SCSI_BULKOUT_ANALYSIS_TBL;
+
+/******************************************************************************
+** Variable Declaration
+******************************************************************************/
+
+/**************************************
+** Module Parameters
+**************************************/
+
+static char*    storage_device = CONFIG_USBD_STORAGE_DEF_DEVICE_NAME;
+MODULE_PARM(storage_device, "s");
+
+/**************************************
+** Device Information
+**************************************/
+
+static struct file*     DeviceFile      = NULL;
+static int              DeviceSize      = 0;
+static int              DeviceBlockSize = DEVICE_BLOCK_SIZE;
+static int              DeviceWrProtect = WR_PROTECT_OFF;
+
+/**************************************
+** Status
+**************************************/
+
+static int  StorageStatus  = STORAGE_IDLE;
+static int  UsbStatus      = USB_DISCONNECT;
+static int  MediaStatus    = MEDIA_EJECT;
+static int  MediaChange    = MEDIA_CHANGE_OFF;
+
+/**************************************
+** Keep Information
+**************************************/
+
+static SCSI_REQUEST_SENSE_DATA  RequestSenseData;
+static COMMAND_BLOCK_WRAPPER    KeepCBW;
+static unsigned long            BulkOutLength = 0;
+static unsigned char            BlockBuffer[BLOCK_BUFFER_SIZE];
+
+/**************************************
+** Statistics
+**************************************/
+static unsigned long    StatMaxBulkInSize  = 0;
+static unsigned long    StatMaxBulkOutSize = 0;
+static unsigned long    StatDevWriteError  = 0;
+static unsigned long    StatDevReadError   = 0;
+static unsigned long    StatDevFlushError  = 0;
+static unsigned long    StatWriteTimout    = 0;
+static unsigned long    StatMaxWriteTime   = 0;
+
+/**************************************
+** Timer
+**************************************/
+static struct timer_list    BulkOutTim;
+static struct timer_list    MediaCheckTim;
+
+/******************************************************************************
+** Local Function
+******************************************************************************/
+
+static void storage_bulkout_timeout(unsigned long param)
+{
+    /* statistics update */
+    StatWriteTimout++;
+    printk(KERN_INFO "storage_fd: write bulk out timeout. length '%ld/%ld'.\n",
+        BulkOutLength, KeepCBW.dCBWDataTransferLength);
+
+    return;
+}
+
+static void media_check_timeout(unsigned long param)
+{
+    /* media check */
+    schedule_task_register(
+        (SCHEDULE_TASK_FUNC)storageproto_media_status_check, CONTEXT_TIMER,
+        0, 0, 0, 0);
+
+    return;
+}
+
+static void request_sense_data_set(unsigned char sense_key, unsigned char asc,
+                                   unsigned char ascq, unsigned long info)
+{
+    /*
+     * set REQUEST SENSE DATA
+     */
+
+    memset(&RequestSenseData, 0x00, sizeof(RequestSenseData));
+
+    RequestSenseData.ErrorCode                    = 0x70;
+    RequestSenseData.Valid                        = (info) ? 1 : 0;
+    RequestSenseData.SenseKey                     = sense_key;
+    memcpy(RequestSenseData.Information, &info, sizeof(info));
+    RequestSenseData.AdditionalSenseLength        = 0x0a;
+    RequestSenseData.AdditionalSenseCode          = asc;
+    RequestSenseData.AdditionalSenseCodeQualifier = ascq;
+
+    return;
+}
+
+static void scsi_inquiry_analysis(struct usb_device_instance* device,
+                                  COMMAND_BLOCK_WRAPPER* cbw)
+{
+    SCSI_INQUIRY_DATA       data;
+    COMMAND_STATUS_WRAPPER  csw;
+    unsigned long           data_len;
+
+    /*
+     * data transport
+     */
+
+    memset(&data, 0x00, sizeof(data));
+
+    data.PeripheralDeviceType = 0x00;
+    data.RMB                  = 1;
+    data.ResponseDataFormat   = 0x01;
+    data.AdditionalLength     = 0x1f;
+    strncpy(data.VendorInformation, CONFIG_USBD_MANUFACTURER,
+            sizeof(data.VendorInformation));
+    strncpy(data.ProductIdentification, CONFIG_USBD_PRODUCT_NAME,
+            sizeof(data.ProductIdentification));
+    strncpy(data.ProductRevisionLevel, PRODUCT_REVISION_LEVEL,
+            sizeof(data.ProductRevisionLevel));
+
+    data_len = sizeof(data);
+    if(cbw->dCBWDataTransferLength < data_len){
+        data_len = cbw->dCBWDataTransferLength;
+    }
+
+    storage_urb_send(device, &data, data_len);
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength - data_len;
+    csw.bCSWStatus      = 0;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_read_format_capacity_analysis(struct usb_device_instance* device,
+                                               COMMAND_BLOCK_WRAPPER* cbw)
+{
+    SCSI_READ_FORMAT_CAPACITY_DATA  data;
+    COMMAND_STATUS_WRAPPER          csw;
+    unsigned long                   block_num, data_len;
+    unsigned short                  block_len;
+
+    /*
+     * data transport
+     */
+
+    block_num = 0xffffffff;
+    block_len = (unsigned short)DeviceBlockSize;
+    block_num = htonl(block_num);
+    block_len = htons(block_len);
+
+    memset(&data, 0x00, sizeof(data));
+
+    data.CapacityListHeader.CapacityListLength =
+        sizeof(data.CurrentMaximumCapacityDescriptor);
+    memcpy(data.CurrentMaximumCapacityDescriptor.NumberofBlocks, &block_num,
+           sizeof(block_num));
+    data.CurrentMaximumCapacityDescriptor.DescriptorCode = 0x03;
+    memcpy(data.CurrentMaximumCapacityDescriptor.BlockLength + 1, &block_len,
+           sizeof(block_len));
+
+    data_len = sizeof(data);
+    if(cbw->dCBWDataTransferLength < data_len){
+        data_len = cbw->dCBWDataTransferLength;
+    }
+
+    storage_urb_send(device, &data, data_len);
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength - data_len;
+    csw.bCSWStatus      = 0;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_read_capacity_analysis(struct usb_device_instance* device,
+                                        COMMAND_BLOCK_WRAPPER* cbw)
+{
+    SCSI_READ_CAPACITY_DATA data;
+    COMMAND_STATUS_WRAPPER  csw;
+    unsigned char           data_len, status = 0;
+
+    if(DeviceFile == NULL){
+        /* 0 clear */
+        memset(&data, 0x00, sizeof(data));
+
+        /* data length set */
+        data_len = cbw->dCBWDataTransferLength;
+
+        /* status set */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+    }
+    else
+    if(MediaChange == MEDIA_CHANGE_ON){
+        /* 0 clear */
+        memset(&data, 0x00, sizeof(data));
+
+        /* data length set */
+        data_len = cbw->dCBWDataTransferLength;
+
+        /* status set */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x06, 0x28, 0x00, 0x00);
+
+        /* media change flag off */
+        MediaChange = MEDIA_CHANGE_OFF;
+    }
+    else{
+        unsigned long   last_lba, block_len;
+
+        /* 0 clear */
+        memset(&data, 0x00, sizeof(data));
+
+        /* data set */
+        last_lba  = (DeviceSize / DeviceBlockSize) - 1;
+        block_len = DeviceBlockSize;
+        last_lba  = htonl(last_lba);
+        block_len = htonl(block_len);
+
+        memcpy(data.LastLogicalBlockAddress, &last_lba, sizeof(last_lba));
+        memcpy(data.BlockLengthInBytes, &block_len, sizeof(block_len));
+
+        /* data length set */
+        data_len = sizeof(data);
+
+        /* status set */
+        status = 0;
+    }
+
+    /*
+     * data transport
+     */
+
+    if(cbw->dCBWDataTransferLength < data_len){
+        data_len = cbw->dCBWDataTransferLength;
+    }
+
+    storage_urb_send(device, &data, data_len);
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength - data_len;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_request_sense_analysis(struct usb_device_instance* device,
+                                        COMMAND_BLOCK_WRAPPER* cbw)
+{
+    COMMAND_STATUS_WRAPPER  csw;
+    unsigned long           data_len;
+
+    /*
+     * data transport
+     */
+
+    data_len = sizeof(RequestSenseData);
+    if(cbw->dCBWDataTransferLength < data_len){
+        data_len = cbw->dCBWDataTransferLength;
+    }
+
+    storage_urb_send(device, &RequestSenseData, data_len);
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength - data_len;
+    csw.bCSWStatus      = 0;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_read_10_analysis(struct usb_device_instance* device,
+                                  COMMAND_BLOCK_WRAPPER* cbw)
+{
+    SCSI_READ_10_COMMAND*   command = (SCSI_READ_10_COMMAND*)cbw->CBWCB;
+    COMMAND_STATUS_WRAPPER  csw;
+    unsigned char           status = 0;
+    unsigned short          len;
+    unsigned long           lba, size, offset;
+
+    memcpy(&lba, command->LogicalBlockAddress, sizeof(lba));
+    memcpy(&len, command->TransferLength, sizeof(len));
+    lba    = ntohl(lba);
+    len    = ntohs(len);
+    offset = lba * DeviceBlockSize;
+    size   = cbw->dCBWDataTransferLength;
+
+    if(DeviceFile == NULL){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+
+        /*
+         * data transport
+         */
+
+        storage_urb_send(device, NULL, size);
+    }
+    else
+    if(MediaChange == MEDIA_CHANGE_ON){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x06, 0x28, 0x00, 0x00);
+
+        /* media change flag off */
+        MediaChange = MEDIA_CHANGE_OFF;
+
+        /*
+         * data transport
+         */
+
+        storage_urb_send(device, NULL, size);
+    }
+    else{
+        unsigned long   count, read_size;
+
+        /*
+         * data transport
+         */
+
+        /* device seek */
+        DeviceFile->f_op->llseek(DeviceFile, offset, 0);
+
+        /* device read */
+        for(count = size; count; count -= read_size){
+            read_size = (count > sizeof(BlockBuffer)) ?
+                            sizeof(BlockBuffer) : count;
+            if(DeviceFile &&
+               DeviceFile->f_op->read(DeviceFile, BlockBuffer, read_size,
+                                      &DeviceFile->f_pos) != read_size){
+
+                /* command fail */
+                status = 1;
+
+                /* error code save REQUEST SENSE */
+                request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+
+                /* statistics update */
+                StatDevReadError++;
+                printk(KERN_INFO "storage_fd: device read error. length '%ld'.\n", read_size);
+            }
+
+            storage_urb_send(device, BlockBuffer, read_size);
+        }
+    }
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength - size;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_mode_sense_analysis(struct usb_device_instance* device,
+                                     COMMAND_BLOCK_WRAPPER* cbw)
+{
+    static READ_WRITE_ERROR_RECOVERY_PAGE           page_01 = {
+        PageCode:0x01,
+        PageLength:0x0A,
+        ReadRetryCount:0x03,
+        WriteRetryCount:0x80,
+    };
+    static FLEXIBLE_DISK_PAGE                       page_05 = {
+        PageCode:0x05,
+        PageLength:0x1E,
+        TransferRate:{0x00, 0xFA},
+        NumberofHeads:0xA0,
+        SectorsperTrack:0x00,
+        DataBytesperSector:{0x02, 0x00},
+        NumberofCylinders:{0x00, 0x00},
+        MotorOnDelay:0x05,
+        MotorOffDelay:0x1E,
+        MediumRotationRate:{0x01, 0x68},
+    };
+    static REMOVABLE_BLOCK_ACCESS_CAPABILITIES_PAGE page_1b = {
+        PageCode:0x1B,
+        PageLength:0x0A,
+        TLUN:0x01,
+    };
+    static TIMER_AND_PROTECT_PAGE                   page_1c = {
+        PageCode:0x1c,
+        PageLength:0x06,
+        InactivityTimeMultiplier:0x0A,
+    };
+
+
+    SCSI_MODE_SENSE_COMMAND*    command = (SCSI_MODE_SENSE_COMMAND*)cbw->CBWCB;
+    SCSI_MODE_SENSE_DATA        data;
+    COMMAND_STATUS_WRAPPER      csw;
+    unsigned char               data_len, status = 0;
+    unsigned short              cylinder, sector;
+    unsigned long               size;
+
+    /*
+     * data transport
+     */
+
+    memset(&data, 0x00, sizeof(data));
+
+    /* set write protect */
+    data.ModeParameterHeader.WP = DeviceWrProtect;
+
+    /* set Flexible Disk Page */
+    if(DeviceFile == NULL){
+        sector   = (unsigned short)DeviceBlockSize;
+        cylinder = 0;
+        sector   = htons(sector);
+        cylinder = htons(cylinder);
+
+        page_05.NumberofHeads      = 0;
+        page_05.SectorsperTrack    = 0;
+        memcpy(page_05.DataBytesperSector, &sector, sizeof(sector));
+        memcpy(page_05.NumberofCylinders, &cylinder, sizeof(cylinder));
+    }
+    else{
+        sector   = (unsigned short)DeviceBlockSize;
+        size     = DEF_NUMBER_OF_HEADS * DEF_SECTORS_PER_TRACK * sector;
+        cylinder = DeviceSize / size;
+        sector   = htons(sector);
+        cylinder = htons(cylinder);
+
+        page_05.NumberofHeads      = DEF_NUMBER_OF_HEADS;
+        page_05.SectorsperTrack    = DEF_SECTORS_PER_TRACK;
+        memcpy(page_05.DataBytesperSector, &sector, sizeof(sector));
+        memcpy(page_05.NumberofCylinders, &cylinder, sizeof(cylinder));
+    }
+
+    if(command->PC == 0 && command->PageCode == 0x01){
+        data_len = sizeof(MODE_PARAMETER_HEADER) + sizeof(page_01);
+        data.ModeParameterHeader.ModeDataLength = data_len - 1;
+        memcpy(&data.ModePages, &page_01, sizeof(page_01));
+    }
+    else
+    if(command->PC == 0 && command->PageCode == 0x05){
+        data_len = sizeof(MODE_PARAMETER_HEADER) + sizeof(page_05);
+        data.ModeParameterHeader.ModeDataLength = data_len - 1;
+        memcpy(&data.ModePages, &page_05, sizeof(page_05));
+    }
+    else
+    if(command->PC == 0 && command->PageCode == 0x1b){
+        data_len = sizeof(MODE_PARAMETER_HEADER) + sizeof(page_1b);
+        data.ModeParameterHeader.ModeDataLength = data_len - 1;
+        memcpy(&data.ModePages, &page_1b, sizeof(page_1b));
+    }
+    else
+    if(command->PC == 0 && command->PageCode == 0x1c){
+        data_len = sizeof(MODE_PARAMETER_HEADER) + sizeof(page_1c);
+        data.ModeParameterHeader.ModeDataLength = data_len - 1;
+        memcpy(&data.ModePages, &page_1c, sizeof(page_1c));
+    }
+    else
+    if(command->PC == 0 && command->PageCode == 0x3f){
+        data_len = sizeof(MODE_PARAMETER_HEADER) + sizeof(MODE_ALL_PAGES);
+        data.ModeParameterHeader.ModeDataLength = data_len - 1;
+        memcpy(&data.ModePages.ModeAllPages.ReadWriteErrorRecoveryPage,
+               &page_01, sizeof(page_01));
+        memcpy(&data.ModePages.ModeAllPages.FlexibleDiskPage,
+               &page_05, sizeof(page_05));
+        memcpy(&data.ModePages.ModeAllPages.RemovableBlockAccessCapabilitiesPage,
+               &page_1b, sizeof(page_1b));
+        memcpy(&data.ModePages.ModeAllPages.TimerAndProtectPage,
+               &page_1c, sizeof(page_1c));
+    }
+    else{
+        /* command fail */
+        status = 1;
+        data_len = cbw->dCBWDataTransferLength;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x05, 0x24, 0x00, 0x00);
+    }
+
+    if(cbw->dCBWDataTransferLength < data_len){
+        data_len = cbw->dCBWDataTransferLength;
+    }
+
+    storage_urb_send(device, &data, data_len);
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength - data_len;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_test_unit_ready_analysis(struct usb_device_instance* device,
+                                          COMMAND_BLOCK_WRAPPER* cbw)
+{
+    COMMAND_STATUS_WRAPPER      csw;
+    unsigned char               status = 0;
+
+    if(DeviceFile == NULL){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+    }
+    else
+    if(MediaChange == MEDIA_CHANGE_ON){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x06, 0x28, 0x00, 0x00);
+
+        /* media change flag off */
+        MediaChange = MEDIA_CHANGE_OFF;
+    }
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_prevent_allow_medium_removal_analysis(struct usb_device_instance* device,
+                                                       COMMAND_BLOCK_WRAPPER* cbw)
+{
+    SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL_COMMAND*  command = (SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL_COMMAND*)cbw->CBWCB;
+    COMMAND_STATUS_WRAPPER                      csw;
+    unsigned char                               status = 0;
+
+    if(command->Prevent){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x05, 0x24, 0x00, 0x00);
+    }
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_start_stop_analysis(struct usb_device_instance* device,
+                                     COMMAND_BLOCK_WRAPPER* cbw)
+{
+    SCSI_START_STOP_COMMAND*    command = (SCSI_START_STOP_COMMAND*)cbw->CBWCB;
+    COMMAND_STATUS_WRAPPER      csw;
+    unsigned char               status = 0;
+
+    if(DeviceFile == NULL){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+    }
+    else
+    if(MediaChange == MEDIA_CHANGE_ON){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x06, 0x28, 0x00, 0x00);
+
+        /* media change flag off */
+        MediaChange = MEDIA_CHANGE_OFF;
+    }
+    else
+    if(command->Start && command->LoEj){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x05, 0x24, 0x00, 0x00);
+    }
+
+    /* device buffer flush */
+    if(DeviceFile && DeviceFile->f_op->ioctl(DeviceFile->f_dentry->d_inode,
+                                             DeviceFile, BLKFLSBUF, 0) != 0){
+        /* statistics update */
+        StatDevFlushError++;
+        printk(KERN_INFO "storage_fd: device flush error.\n");
+    }
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_write_10_analysis(struct usb_device_instance* device,
+                                   COMMAND_BLOCK_WRAPPER* cbw)
+{
+    /* status set */
+    BulkOutLength = 0;
+    StorageStatus = STORAGE_BULKOUT;
+
+    /* timer set */
+    del_timer(&BulkOutTim);
+    BulkOutTim.expires  = jiffies + ((WR_BULKOUT_CHK_TIM * HZ) / 1000);
+    BulkOutTim.data     = 0;
+    BulkOutTim.function = storage_bulkout_timeout;
+    add_timer(&BulkOutTim);
+
+    return;
+}
+
+static void scsi_verify_analysis(struct usb_device_instance* device,
+                                 COMMAND_BLOCK_WRAPPER* cbw)
+{
+    COMMAND_STATUS_WRAPPER      csw;
+    unsigned char               status = 0;
+
+    if(DeviceFile == NULL){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+    }
+    else
+    if(MediaChange == MEDIA_CHANGE_ON){
+        /* command fail */
+        status = 1;
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x06, 0x28, 0x00, 0x00);
+
+        /* media change flag off */
+        MediaChange = MEDIA_CHANGE_OFF;
+    }
+
+    /*
+     * status transport
+     */
+
+    memset(&csw, 0x00, sizeof(csw));
+
+    csw.dCSWSignature   = CSW_SIGNATURE;
+    csw.dCSWTag         = cbw->dCBWTag;
+    csw.dCSWDataResidue = cbw->dCBWDataTransferLength;
+    csw.bCSWStatus      = status;
+
+    storage_urb_send(device, &csw, sizeof(csw));
+
+    return;
+}
+
+static void scsi_unsupport_analysis(struct usb_device_instance* device,
+                                    COMMAND_BLOCK_WRAPPER* cbw)
+{
+    COMMAND_STATUS_WRAPPER csw;
+    unsigned char          data_len = 0;
+
+    if(((cbw->bmCBWFlags & 0x80) == 0x00) && (cbw->dCBWDataTransferLength)){
+        /* BLKOUT */
+
+        /* status set */
+        BulkOutLength = 0;
+        StorageStatus = STORAGE_BULKOUT;
+    }
+    else{
+        /* BLKIN */
+
+        if(cbw->dCBWDataTransferLength){
+            data_len = cbw->dCBWDataTransferLength;
+            storage_urb_send(device, NULL, data_len);
+        }
+
+        /*
+         * status transport
+         */
+
+        memset(&csw, 0x00, sizeof(csw));
+
+        csw.dCSWSignature   = CSW_SIGNATURE;
+        csw.dCSWTag         = cbw->dCBWTag;
+        csw.dCSWDataResidue = cbw->dCBWDataTransferLength - data_len;
+        csw.bCSWStatus      = 0x01;
+        storage_urb_send(device, &csw, sizeof(csw));
+
+    }
+
+    /* error code save REQUEST SENSE */
+    request_sense_data_set(0x05, 0x20, 0x00, 0x00);
+
+    return;
+}
+
+static void scsi_bulkout_write_10_analysis(struct usb_device_instance* device,
+                                           void* buffer, int length)
+{
+    COMMAND_STATUS_WRAPPER  csw;
+    unsigned char           status = 0;
+    unsigned long           buff_used_len, buff_offset;
+    unsigned long           s_tick, e_tick, wr_tick;
+
+    buff_offset = BulkOutLength % sizeof(BlockBuffer);
+
+    memcpy(BlockBuffer + buff_offset, buffer, length);
+    BulkOutLength += length;
+
+    buff_used_len = BulkOutLength % sizeof(BlockBuffer);
+    if(buff_used_len == 0) buff_used_len = sizeof(BlockBuffer);
+
+    /* delete timer */
+    if(BulkOutLength >= KeepCBW.dCBWDataTransferLength){
+        del_timer(&BulkOutTim);
+    }
+
+    if(buff_used_len >= sizeof(BlockBuffer) ||
+       BulkOutLength >= KeepCBW.dCBWDataTransferLength){
+
+        /* buffer full */
+        SCSI_WRITE_10_COMMAND*  command = (SCSI_WRITE_10_COMMAND*)&KeepCBW.CBWCB;
+        unsigned short          len;
+        unsigned long           lba, offset;
+
+        memcpy(&lba, command->LogicalBlockAddress, sizeof(lba));
+        memcpy(&len, command->TransferLength, sizeof(len));
+        lba = ntohl(lba);
+        len = ntohs(len);
+
+        offset = (lba * DeviceBlockSize) +
+                 (sizeof(BlockBuffer) * ((BulkOutLength - 1) / sizeof(BlockBuffer)));
+
+        /* device check */
+        if(DeviceFile &&
+           MediaChange != MEDIA_CHANGE_ON &&
+           DeviceWrProtect != WR_PROTECT_ON){
+
+            /* write before jiffies get */
+            s_tick = jiffies;
+
+            /* device seek */
+            DeviceFile->f_op->llseek(DeviceFile, offset, 0);
+
+            /* device write */
+            if(DeviceFile->f_op->write(DeviceFile, BlockBuffer, buff_used_len,
+                                       &DeviceFile->f_pos) != buff_used_len){
+                /* statistics update */
+                StatDevWriteError++;
+                printk(KERN_INFO "storage_fd: device write error. length '%ld'.\n", buff_used_len);
+            }
+
+            /* write after jiffies get */
+            e_tick = jiffies;
+
+            /* statistics update */
+            wr_tick = e_tick - s_tick;
+            if(wr_tick > StatMaxWriteTime){
+                StatMaxWriteTime = wr_tick;
+            }
+        }
+    }
+
+    if(BulkOutLength >= KeepCBW.dCBWDataTransferLength){
+        if(DeviceFile == NULL){
+            /* command fail */
+            status = 1;
+
+            /* error code save REQUEST SENSE */
+            request_sense_data_set(0x02, 0x3a, 0x00, 0x00);
+        }
+        else
+        if(MediaChange == MEDIA_CHANGE_ON){
+            /* command fail */
+            status = 1;
+
+            /* error code save REQUEST SENSE */
+            request_sense_data_set(0x06, 0x28, 0x00, 0x00);
+
+            /* media change flag off */
+            MediaChange = MEDIA_CHANGE_OFF;
+        }
+        else
+        if(DeviceWrProtect == WR_PROTECT_ON){
+            /* command fail */
+            status = 1;
+
+            /* error code save REQUEST SENSE */
+            request_sense_data_set(0x07, 0x27, 0x00, 0x00);
+
+            /* media change flag off */
+            MediaChange = MEDIA_CHANGE_OFF;
+        }
+
+        /*
+         * status transport
+         */
+
+        memset(&csw, 0x00, sizeof(csw));
+
+        csw.dCSWSignature   = CSW_SIGNATURE;
+        csw.dCSWTag         = KeepCBW.dCBWTag;
+        csw.dCSWDataResidue = KeepCBW.dCBWDataTransferLength - BulkOutLength;
+        csw.bCSWStatus      = status;
+
+        storage_urb_send(device, &csw, sizeof(csw));
+
+        /* status reset */
+        BulkOutLength = 0;
+        StorageStatus = STORAGE_IDLE;
+
+        /* flush before jiffies get */
+        s_tick = jiffies;
+
+        /* device buffer flush */
+        if(DeviceFile && DeviceFile->f_op->ioctl(DeviceFile->f_dentry->d_inode,
+                                                 DeviceFile, BLKFLSBUF, 0) != 0){
+            /* statistics update */
+            StatDevFlushError++;
+            printk(KERN_INFO "storage_fd: device flush error.\n");
+        }
+
+        /* flush after jiffies get */
+        e_tick = jiffies;
+
+        /* statistics update */
+        wr_tick = e_tick - s_tick;
+        if(wr_tick > StatMaxWriteTime){
+            StatMaxWriteTime = wr_tick;
+        }
+
+    }
+
+    return;
+}
+
+static void scsi_bulkout_unsupport_analysis(struct usb_device_instance* device,
+                                            void* buffer, int length)
+{
+    COMMAND_STATUS_WRAPPER  csw;
+
+    BulkOutLength += length;
+
+    if(BulkOutLength >= KeepCBW.dCBWDataTransferLength){
+        /*
+         * status transport
+         */
+
+        memset(&csw, 0x00, sizeof(csw));
+
+        csw.dCSWSignature   = CSW_SIGNATURE;
+        csw.dCSWTag         = KeepCBW.dCBWTag;
+        csw.dCSWDataResidue = KeepCBW.dCBWDataTransferLength - BulkOutLength;
+        csw.bCSWStatus      = 1;
+
+        storage_urb_send(device, &csw, sizeof(csw));
+
+        /* error code save REQUEST SENSE */
+        request_sense_data_set(0x05, 0x20, 0x00, 0x00);
+
+        /* status reset */
+        BulkOutLength = 0;
+        StorageStatus = STORAGE_IDLE;
+    }
+
+    return;
+}
+
+/******************************************************************************
+** Global Function
+******************************************************************************/
+
+static SCSI_ANALYSIS_TBL    ScsiAnalysisTbl[] = {
+    {SCSI_FORMAT_UNT,                   "SCSI_FORMAT_UNT",                   NULL},
+    {SCSI_INQUIRY,                      "SCSI_INQUIRY",                      scsi_inquiry_analysis},
+    {SCSI_START_STOP,                   "SCSI_START_STOP",                   scsi_start_stop_analysis},
+    {SCSI_MODE_SELECT,                  "SCSI_MODE_SELECT",                  NULL},
+    {SCSI_MODE_SENSE,                   "SCSI_MODE_SENSE",                   scsi_mode_sense_analysis},
+    {SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL, "SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL", scsi_prevent_allow_medium_removal_analysis},
+    {SCSI_READ_10,                      "SCSI_READ_10",                      scsi_read_10_analysis},
+    {SCSI_READ_12,                      "SCSI_READ_12",                      NULL},
+    {SCSI_READ_CAPACITY,                "SCSI_READ_CAPACITY",                scsi_read_capacity_analysis},
+    {SCSI_READ_FORMAT_CAPACITY,         "SCSI_READ_FORMAT_CAPACITY",         scsi_read_format_capacity_analysis},
+    {SCSI_REQUEST_SENSE,                "SCSI_REQUEST_SENSE",                scsi_request_sense_analysis},
+    {SCSI_REZERO_UNIT,                  "SCSI_REZERO_UNIT",                  NULL},
+    {SCSI_SEEK_10,                      "SCSI_SEEK_10",                      NULL},
+    {SCSI_SEND_DIAGNOSTIC,              "SCSI_SEND_DIAGNOSTIC",              NULL},
+    {SCSI_TEST_UNIT_READY,              "SCSI_TEST_UNIT_READY",              scsi_test_unit_ready_analysis},
+    {SCSI_VERIFY,                       "SCSI_VERIFY",                       scsi_verify_analysis},
+    {SCSI_WRITE_10,                     "SCSI_WRITE_10",                     scsi_write_10_analysis},
+    {SCSI_WRITE_12,                     "SCSI_WRITE_12",                     NULL},
+    {SCSI_WRITE_AND_VERIFY,             "SCSI_WRITE_AND_VERIFY",             NULL}
+};
+
+static SCSI_BULKOUT_ANALYSIS_TBL    ScsiBlkOutAnalysisTbl[] = {
+    {SCSI_WRITE_10,                     "SCSI_WRITE_10",                     scsi_bulkout_write_10_analysis},
+};
+
+void storageproto_urb_analysis(struct urb* urb)
+{
+    COMMAND_BLOCK_WRAPPER*  cbw = (COMMAND_BLOCK_WRAPPER*)urb->buffer;
+    int                     i;
+
+    /* status BLKOUT check */
+    if(StorageStatus == STORAGE_BULKOUT){
+        for(i = 0;
+            i < sizeof(ScsiBlkOutAnalysisTbl) / sizeof(SCSI_ANALYSIS_TBL);
+            i++){
+            if(ScsiBlkOutAnalysisTbl[i].scsi_command == KeepCBW.CBWCB[0]){
+                if(ScsiBlkOutAnalysisTbl[i].bulkout_func){
+                    ScsiBlkOutAnalysisTbl[i].bulkout_func(urb->device,
+                                                          urb->buffer,
+                                                          urb->actual_length);
+                    goto RETURN_LABEL;
+                }
+                break;
+            }
+        }
+        scsi_bulkout_unsupport_analysis(urb->device, urb->buffer, urb->actual_length);
+        goto RETURN_LABEL;
+    }
+
+    /* signature check */
+    if(cbw->dCBWSignature != CBW_SIGNATURE){
+        printk(KERN_INFO "storage_fd: signature error. '0x%08lx'.\n",
+            cbw->dCBWSignature);
+        goto RETURN_LABEL;
+    }
+
+    /* statistics set */
+    if(cbw->dCBWDataTransferLength){
+        if(((cbw->bmCBWFlags & 0x80) == 0x00) && (cbw->dCBWDataTransferLength)){
+            /* BULK OUT */
+            if(StatMaxBulkOutSize < cbw->dCBWDataTransferLength){
+                StatMaxBulkOutSize = cbw->dCBWDataTransferLength;
+            }
+        }
+        else{
+            /* BULK IN */
+            if(StatMaxBulkInSize < cbw->dCBWDataTransferLength){
+                StatMaxBulkInSize = cbw->dCBWDataTransferLength;
+            }
+        }
+    }
+
+    /* save CBW and set storage status */
+    memcpy(&KeepCBW, cbw, sizeof(KeepCBW));
+
+    /* UFI command analysis */
+    for(i = 0; i < sizeof(ScsiAnalysisTbl) / sizeof(SCSI_ANALYSIS_TBL); i++){
+        if(ScsiAnalysisTbl[i].scsi_command == cbw->CBWCB[0]){
+            if(ScsiAnalysisTbl[i].scsi_func){
+                ScsiAnalysisTbl[i].scsi_func(urb->device, cbw);
+                goto RETURN_LABEL;
+            }
+            break;
+        }
+    }
+
+    scsi_unsupport_analysis(urb->device, cbw);
+    printk(KERN_INFO "storage_fd: SCSI command error. '0x%02x'.\n",
+        cbw->CBWCB[0]);
+    goto RETURN_LABEL;
+
+RETURN_LABEL:
+
+    /* URB free */
+    usbd_recycle_urb(urb);
+
+    return;
+}
+
+int storageproto_device_open_check(void)
+{
+    struct file*    file;
+    struct inode*   inode;
+    kdev_t          dev;
+    int             read_org;
+
+    /* device already open check */
+    if(DeviceFile){
+        storageproto_device_close();
+    }
+
+    /* device open */
+    file = filp_open(storage_device, O_RDWR, 0000);
+    if(IS_ERR(file)){
+        file = filp_open(storage_device, O_RDONLY, 0000);
+        if(IS_ERR(file)){
+            storageproto_device_close();
+            return MEDIA_EJECT;
+        }
+        DeviceWrProtect = WR_PROTECT_ON;
+    }
+
+    file->f_op->llseek(file, 0, 0);
+    if(file->f_op->read(file, (void*)&read_org, sizeof(read_org), &file->f_pos)
+                        != sizeof(read_org)){
+        filp_close(file, NULL);
+        storageproto_device_close();
+        return MEDIA_EJECT;
+    }
+
+    /* struct file pointer save */
+    DeviceFile = file;
+
+    /* device information */
+    inode = file->f_dentry->d_inode;
+    dev = inode->i_rdev;
+
+    if (blk_size[MAJOR(dev)]){
+        DeviceSize = blk_size[MAJOR(dev)][MINOR(dev)] << BLOCK_SIZE_BITS;
+    }
+    else{
+        DeviceSize = INT_MAX << BLOCK_SIZE_BITS;
+    }
+
+    if(blksize_size[MAJOR(dev)] && blksize_size[MAJOR(dev)][MINOR(dev)]){
+        DeviceBlockSize = DEVICE_BLOCK_SIZE;
+    }
+    else{
+        DeviceBlockSize = DEVICE_BLOCK_SIZE;
+    }
+
+    return MEDIA_INSERT;
+}
+
+void storageproto_device_close(void)
+{
+    if(DeviceFile){
+        filp_close(DeviceFile, NULL);
+        DeviceFile      = NULL;
+        DeviceSize      = 0;
+        DeviceBlockSize = DEVICE_BLOCK_SIZE;
+        DeviceWrProtect = WR_PROTECT_OFF;
+    }
+
+    return;
+}
+
+void storageproto_usb_status_check(int status)
+{
+    static int  Is1stCheck = 1;
+
+    /* USB status check */
+    if(Is1stCheck){
+        Is1stCheck = 0;
+    }
+    else{
+        if(UsbStatus == status) goto RETURN_LABEL;
+    }
+
+    /* set status */
+    UsbStatus = status;
+
+    switch(UsbStatus){
+    case USB_CONNECT:
+        /* media status check */
+        storageproto_media_status_check(CONTEXT_SCHEDULE);
+
+        switch(MediaStatus){
+        case MEDIA_EJECT:
+            break;
+
+        case MEDIA_INSERT:
+            hotplug("usbdstorage", storage_device, "umount");
+            break;
+
+        default:
+            break;
+        }
+        hotplug("usbdstorage", storage_device, "connect");
+        break;
+
+    case USB_DISCONNECT:
+        /* device close */
+        storageproto_device_close();
+
+        switch(MediaStatus){
+        case MEDIA_EJECT:
+            break;
+
+        case MEDIA_INSERT:
+            hotplug("usbdstorage", storage_device, "mount");
+            break;
+
+        default:
+            break;
+        }
+        hotplug("usbdstorage", storage_device, "disconnect");
+        break;
+
+    default:
+        break;
+    }
+
+RETURN_LABEL:
+    DBG_STORAGE_FD(KERN_INFO "storage_fd: USB check '%s' '%s' 'file:%p'.\n",
+        (UsbStatus) ? "USB_CONNECT" : "USB_DISCONNECT",
+        (MediaStatus) ? "MEDIA_INSERT" : "MEDIA_EJECT", DeviceFile);
+
+    return;
+}
+
+void storageproto_media_status_check(int call_context)
+{
+    static unsigned long    RetryCount = 0;
+    int status;
+
+    /* media open check */
+    status = storageproto_device_open_check();
+
+    /* media status check retry */
+    if(status == MEDIA_EJECT){
+        switch(call_context){
+        case CONTEXT_STORAGE:
+
+            /* retry counter init */
+            RetryCount = 0;
+
+            /* timer set */
+            del_timer(&MediaCheckTim);
+            MediaCheckTim.expires  = jiffies + ((MEDIA_CHECK_TIM * HZ) / 1000);
+            MediaCheckTim.data     = 0;
+            MediaCheckTim.function = media_check_timeout;
+            add_timer(&MediaCheckTim);
+
+            break;
+
+        case CONTEXT_TIMER:
+
+            /* retry counter update */
+            RetryCount++;
+
+            /* retry counter check */
+            if(RetryCount >= MEDIA_CHECK_RETRY) break;
+
+            /* timer set */
+            del_timer(&MediaCheckTim);
+            MediaCheckTim.expires  = jiffies + ((MEDIA_CHECK_TIM * HZ) / 1000);
+            MediaCheckTim.data     = 0;
+            MediaCheckTim.function = media_check_timeout;
+            add_timer(&MediaCheckTim);
+
+            break;
+
+        default:
+            break;
+        }
+    }
+    else
+    if(status == MEDIA_INSERT){
+        /* delete timer */
+        del_timer(&MediaCheckTim);
+    }
+
+    /* media status check */
+    if(status == MediaStatus){
+        if(UsbStatus == USB_DISCONNECT){
+            storageproto_device_close();
+        }
+        if(MediaStatus == MEDIA_INSERT){
+            if(call_context == CONTEXT_STORAGE || call_context == CONTEXT_TIMER){
+                MediaChange = MEDIA_CHANGE_ON;
+            }
+        }
+        goto RETURN_LABEL;
+    }
+
+    /* set status */
+    MediaStatus = status;
+
+    switch(MediaStatus){
+    case MEDIA_INSERT:
+        /* set status */
+        MediaChange = MEDIA_CHANGE_ON;
+
+        switch(UsbStatus){
+        case USB_DISCONNECT:
+            storageproto_device_close();
+            break;
+
+        case USB_CONNECT:
+            break;
+
+        default:
+            break;
+        }
+        hotplug("usbdstorage", storage_device, "insert");
+        break;
+
+    case MEDIA_EJECT:
+        switch(UsbStatus){
+        case USB_DISCONNECT:
+            storageproto_device_close();
+            break;
+
+        case USB_CONNECT:
+            break;
+
+        default:
+            break;
+        }
+        hotplug("usbdstorage", storage_device, "eject");
+        break;
+
+    default:
+        break;
+    }
+
+RETURN_LABEL:
+    DBG_STORAGE_FD(KERN_INFO "storage_fd: media check. '%s' '%s' 'file:%p' '%s'.\n",
+        (UsbStatus) ? "USB_CONNECT" : "USB_DISCONNECT",
+        (MediaStatus) ? "MEDIA_INSERT" : "MEDIA_EJECT", DeviceFile,
+        (call_context == CONTEXT_SCHEDULE) ? "CONTEXT_SCHEDULE" : 
+        (call_context == CONTEXT_STORAGE)  ? "CONTEXT_STORAGE" : "CONTEXT_TIMER");
+
+    return;
+}
+
+void storageproto_usb_reset_ind(void)
+{
+    /* status reset */
+    BulkOutLength = 0;
+    StorageStatus = STORAGE_IDLE;
+
+    DBG_STORAGE_FD(KERN_INFO "storage_fd: storage protocol reset.\n");
+
+    return;
+}
+
+void storageproto_init(void)
+{
+    /* timer init */
+    init_timer(&BulkOutTim);
+
+    /* timer init */
+    init_timer(&MediaCheckTim);
+
+    return;
+}
+
+void storageproto_exit(void)
+{
+    /* device close */
+    storageproto_device_close();
+
+    /* delete timer */
+    del_timer(&BulkOutTim);
+
+    /* delete timer */
+    del_timer(&MediaCheckTim);
+
+    return;
+}
+
+ssize_t storageproto_proc_read(struct file* file, char* buf, size_t count,
+                               loff_t* pos)
+{
+    char    string[1024];
+    int     len = 0;
+
+    len += sprintf(string + len, "Protocol status:%s\n",
+            (StorageStatus == STORAGE_IDLE)   ? "STORAGE_IDLE" :
+            (StorageStatus == STORAGE_BULKIN) ? "STORAGE_BULKIN" :
+                                                "STORAGE_BULKOUT");
+
+    len += sprintf(string + len, "USB status:%s\n",
+            (UsbStatus == USB_DISCONNECT) ? "USB_DISCONNECT" :
+                                            "USB_CONNECT");
+
+    len += sprintf(string + len, "Media status:%s\n",
+            (MediaStatus == MEDIA_EJECT) ? "MEDIA_EJECT" :
+                                           "MEDIA_INSERT");
+
+    len += sprintf(string + len, "Media chage:%s\n",
+            (MediaChange == MEDIA_CHANGE_OFF) ? "MEDIA_CHANGE_OFF" :
+                                                "MEDIA_CHANGE_ON");
+
+    len += sprintf(string + len, "Device name:%s\n",
+            storage_device);
+
+    len += sprintf(string + len, "Device file descriptor:0x%p\n",
+            DeviceFile);
+
+    len += sprintf(string + len, "Device size:0x%d\n",
+            DeviceSize);
+
+    len += sprintf(string + len, "Device block size:0x%d\n",
+            DeviceBlockSize);
+
+    len += sprintf(string + len, "Device write protect:%s\n",
+            (DeviceWrProtect == WR_PROTECT_OFF) ? "WR_PROTECT_OFF":
+                                                  "WR_PROTECT_ON");
+
+    len += sprintf(string + len, "Bulk in max size:%ld\n",
+            StatMaxBulkInSize);
+
+    len += sprintf(string + len, "Bulk out max size:%ld\n",
+            StatMaxBulkOutSize);
+
+    len += sprintf(string + len, "device write error:%ld\n",
+            StatDevWriteError);
+
+    len += sprintf(string + len, "device read error:%ld\n",
+            StatDevReadError);
+
+    len += sprintf(string + len, "device flush error:%ld\n",
+            StatDevFlushError);
+
+    len += sprintf(string + len, "write data bulk out timout:%ld\n",
+            StatWriteTimout);
+
+    len += sprintf(string + len, "device write max time:%ld msec\n",
+            (StatMaxWriteTime * 1000) / HZ);
+
+    *pos += len;
+    if(len > count){
+        len = -EINVAL;
+    }
+    else
+    if(len > 0 && copy_to_user(buf, string, len)) {
+        len = -EFAULT;
+    }
+
+    return len;
+}
+
diff -Nur linux-2.4.18/drivers/usb/device/storage_fd/storageproto.h linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/storageproto.h
--- linux-2.4.18/drivers/usb/device/storage_fd/storageproto.h	1970-01-01 03:00:00.000000000 +0300
+++ linux-2.4.18-usb-storage/drivers/usb/device/storage_fd/storageproto.h	2003-11-07 05:34:43.000000000 +0300
@@ -0,0 +1,585 @@
+/*
+ * linux/drivers/usb/device/storage_fd/storageproto.h - mass storage protocol library header
+ *
+ * Copyright (c) 2003 Lineo Solutions, Inc.
+ *
+ * Written by Shunnosuke kabata
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _STORAGEPROTO_H_
+#define _STORAGEPROTO_H_
+
+/******************************************************************************
+** Macro Define
+******************************************************************************/
+
+/**************************************
+** Class Code
+**************************************/
+
+/*
+ * Class
+ */
+
+#define MASS_STORAGE_CLASS                  0x08
+
+/*
+ * SubClass
+ */
+
+#define MASS_STORAGE_SUBCLASS_RBC           0x01
+#define MASS_STORAGE_SUBCLASS_SFF8020I      0x02
+#define MASS_STORAGE_SUBCLASS_QIC157        0x03
+#define MASS_STORAGE_SUBCLASS_UFI           0x04
+#define MASS_STORAGE_SUBCLASS_SFF8070I      0x05
+#define MASS_STORAGE_SUBCLASS_SCSI          0x06
+
+/*
+ * Protocol
+ */
+
+#define MASS_STORAGE_PROTO_CBI_WITH_COMP    0x00
+#define MASS_STORAGE_PROTO_CBI_NO_COMP      0x01
+#define MASS_STORAGE_PROTO_BULK_ONLY        0x50
+
+/**************************************
+** SCSI Command
+**************************************/
+
+#define SCSI_FORMAT_UNT                      0x04
+#define SCSI_INQUIRY                         0x12
+#define SCSI_START_STOP                      0x1b
+#define SCSI_MODE_SELECT                     0x55
+#define SCSI_MODE_SENSE                      0x1a
+#define SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL    0x1e
+#define SCSI_READ_10                         0x28
+#define SCSI_READ_12                         0xa8
+#define SCSI_READ_CAPACITY                   0x25
+#define SCSI_READ_FORMAT_CAPACITY            0x23
+#define SCSI_REQUEST_SENSE                   0x03
+#define SCSI_REZERO_UNIT                     0x01
+#define SCSI_SEEK_10                         0x2b
+#define SCSI_SEND_DIAGNOSTIC                 0x1d
+#define SCSI_TEST_UNIT_READY                 0x00
+#define SCSI_VERIFY                          0x2f
+#define SCSI_WRITE_10                        0x2a
+#define SCSI_WRITE_12                        0xaa
+#define SCSI_WRITE_AND_VERIFY                0x2e
+
+/**************************************
+** SCSI Command Parameter
+**************************************/
+
+#define CBW_SIGNATURE           0x43425355  /* USBC */
+#define CSW_SIGNATURE           0x53425355  /* USBS */
+
+#define PRODUCT_REVISION_LEVEL  "1.00"
+
+/**************************************
+** Status
+**************************************/
+
+#define WR_PROTECT_OFF      0
+#define WR_PROTECT_ON       1
+
+#define STORAGE_IDLE        0
+#define STORAGE_BULKIN      1
+#define STORAGE_BULKOUT     2
+
+#define USB_DISCONNECT      0
+#define USB_CONNECT         1
+
+#define MEDIA_EJECT         0
+#define MEDIA_INSERT        1
+
+#define MEDIA_CHANGE_OFF    0
+#define MEDIA_CHANGE_ON     1
+
+/**************************************
+** Mass Storage Thread Name
+**************************************/
+
+#define STORAGE_THREAD_NAME "usbdstorage"
+
+/**************************************
+** Media Signal Delay Time(ms)
+**************************************/
+
+#define USB_EVENT_DELAY_TIM 1000
+
+/**************************************
+** Write Bulk Out Check Time(ms)
+**************************************/
+
+#define WR_BULKOUT_CHK_TIM  1000
+
+/**************************************
+** Media Check Time(ms)
+**************************************/
+
+#define MEDIA_CHECK_TIM     3000
+#define MEDIA_CHECK_RETRY   3
+
+/**************************************
+** Context
+**************************************/
+
+#define CONTEXT_SCHEDULE    0
+#define CONTEXT_STORAGE     1
+#define CONTEXT_TIMER       2
+
+/**************************************
+** Debug Message
+**************************************/
+#if 0
+#define DBG_STORAGE_FD(fmt, args...)    printk(fmt, ##args)
+#else
+#define DBG_STORAGE_FD(fmt, args...)
+#endif
+
+/******************************************************************************
+** Structure Define
+******************************************************************************/
+
+/**************************************
+** Command Block Wrapper / Command Status Wrapper
+**************************************/
+
+/*
+ * Command Block Wrapper
+ */
+typedef struct{
+    unsigned long   dCBWSignature;
+    unsigned long   dCBWTag;
+    unsigned long   dCBWDataTransferLength;
+    unsigned char   bmCBWFlags;
+    unsigned char   bCBWLUN:4,
+                    Reserved:4;
+    unsigned char   bCBWCBLength:5,
+                    Reserved2:3;
+    unsigned char   CBWCB[16];
+} __attribute__((packed)) COMMAND_BLOCK_WRAPPER;
+
+/*
+ * Command Status Wrapper
+ */
+typedef struct{
+    unsigned long   dCSWSignature;
+    unsigned long   dCSWTag;
+    unsigned long   dCSWDataResidue;
+    unsigned char   bCSWStatus;
+} __attribute__((packed)) COMMAND_STATUS_WRAPPER;
+
+/**************************************
+** SCSI Command
+**************************************/
+
+/*
+ * INQUIRY
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   EVPD:1,
+                    Reserved1:4,
+                    LogicalUnitNumber:3;
+    unsigned char   PageCode;
+    unsigned char   Reserved2;
+    unsigned char   AllocationLength;
+    unsigned char   Reserved3;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+} __attribute__((packed)) SCSI_INQUIRY_COMMAND;
+
+typedef struct{
+    unsigned char   PeripheralDeviceType:5,
+                    Reserved1:3;
+    unsigned char   Reserved2:7,
+                    RMB:1;
+    unsigned char   ANSIVersion:3,
+                    ECMAVersion:3,
+                    ISOVersion:2;
+    unsigned char   ResponseDataFormat:4,
+                    Reserved3:4;
+    unsigned char   AdditionalLength;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   VendorInformation[8];
+    unsigned char   ProductIdentification[16];
+    unsigned char   ProductRevisionLevel[4];
+} __attribute__((packed)) SCSI_INQUIRY_DATA;
+
+/*
+ * READ FORMAT CAPACITY
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   Reserved1:5,
+                    LogicalUnitNumber:3;
+    unsigned char   Reserved2;
+    unsigned char   Reserved3;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   AllocationLength[2];
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+} __attribute__((packed)) SCSI_READ_FORMAT_CAPACITY_COMMAND;
+
+typedef struct{
+    struct{
+        unsigned char   Reserved1;
+        unsigned char   Reserved2;
+        unsigned char   Reserved3;
+        unsigned char   CapacityListLength;
+    } __attribute__((packed)) CapacityListHeader;
+    struct{
+        unsigned char   NumberofBlocks[4];
+        unsigned char   DescriptorCode:2,
+                        Reserved1:6;
+        unsigned char   BlockLength[3];
+    } __attribute__((packed)) CurrentMaximumCapacityDescriptor;
+} __attribute__((packed)) SCSI_READ_FORMAT_CAPACITY_DATA;
+
+/*
+ * READ FORMAT CAPACITY
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   RelAdr:1,
+                    Reserved1:4,
+                    LogicalUnitNumber:3;
+    unsigned char   LogicalBlockAddress[4];
+    unsigned char   Reserved2;
+    unsigned char   Reserved3;
+    unsigned char   PMI:1,
+                    Reserved4:7;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+} __attribute__((packed)) SCSI_READ_CAPACITY_COMMAND;
+
+typedef struct{
+    unsigned char   LastLogicalBlockAddress[4];
+    unsigned char   BlockLengthInBytes[4];
+} __attribute__((packed)) SCSI_READ_CAPACITY_DATA;
+
+/*
+ * REQUEST SENSE
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   Reserved1:5,
+                    LogicalUnitNumber:3;
+    unsigned char   Reserved2;
+    unsigned char   Reserved3;
+    unsigned char   AllocationLength;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+    unsigned char   Reserved10;
+} __attribute__((packed)) SCSI_REQUEST_SENSE_COMMAND;
+
+typedef struct{
+    unsigned char   ErrorCode:7,
+                    Valid:1;
+    unsigned char   Reserved1;
+    unsigned char   SenseKey:4,
+                    Reserved2:4;
+    unsigned char   Information[4];
+    unsigned char   AdditionalSenseLength;
+    unsigned char   Reserved3[4];
+    unsigned char   AdditionalSenseCode;
+    unsigned char   AdditionalSenseCodeQualifier;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5[3];
+} __attribute__((packed)) SCSI_REQUEST_SENSE_DATA;
+
+/*
+ * READ(10)
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   RelAdr:1,
+                    Reserved1:2,
+                    FUA:1,
+                    DPO:1,
+                    LogicalUnitNumber:3;
+    unsigned char   LogicalBlockAddress[4];
+    unsigned char   Reserved2;
+    unsigned char   TransferLength[2];
+    unsigned char   Reserved3;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+} __attribute__((packed)) SCSI_READ_10_COMMAND;
+
+/*
+ * MODE SENSE
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   Reserved1:3,
+                    DBD:1,
+                    Reserved2:1,
+                    LogicalUnitNumber:3;
+    unsigned char   PageCode:6,
+                    PC:2;
+    unsigned char   Reserved3;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   ParameterListLength[2];
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+} __attribute__((packed)) SCSI_MODE_SENSE_COMMAND;
+
+typedef struct{
+    unsigned char   ModeDataLength;
+    unsigned char   MediumTypeCode;
+    unsigned char   Reserved1:4,
+                    DPOFUA:1,
+                    Reserved2:2,
+                    WP:1;
+    unsigned char   Reserved3;
+} __attribute__((packed)) MODE_PARAMETER_HEADER;
+
+typedef struct{
+    unsigned char   PageCode:6,
+                    Reserved1:1,
+                    PS:1;
+    unsigned char   PageLength;
+    unsigned char   DCR:1,
+                    Reserved2:1,
+                    PER:1,
+                    Reserved3:1,
+                    RC:1,
+                    Reserved4:1,
+                    Reserved5:1,
+                    AWRE:1;
+    unsigned char   ReadRetryCount;
+    unsigned char   Reserved6[4];
+    unsigned char   WriteRetryCount;
+    unsigned char   Reserved7[3];
+} __attribute__((packed)) READ_WRITE_ERROR_RECOVERY_PAGE;
+
+typedef struct{
+    unsigned char   PageCode:6,
+                    Reserved1:1,
+                    PS:1;
+    unsigned char   PageLength;
+    unsigned char   TransferRate[2];
+    unsigned char   NumberofHeads;
+    unsigned char   SectorsperTrack;
+    unsigned char   DataBytesperSector[2];
+    unsigned char   NumberofCylinders[2];
+    unsigned char   Reserved2[9];
+    unsigned char   MotorOnDelay;
+    unsigned char   MotorOffDelay;
+    unsigned char   Reserved3[7];
+    unsigned char   MediumRotationRate[2];
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+} __attribute__((packed)) FLEXIBLE_DISK_PAGE;
+
+typedef struct{
+    unsigned char   PageCode:6,
+                    Reserved1:1,
+                    PS:1;
+    unsigned char   PageLength;
+    unsigned char   Reserved2:6,
+                    SRFP:1,
+                    SFLP:1;
+    unsigned char   TLUN:3,
+                    Reserved3:3,
+                    SML:1,
+                    NCD:1;
+    unsigned char   Reserved4[8];
+} __attribute__((packed)) REMOVABLE_BLOCK_ACCESS_CAPABILITIES_PAGE;
+
+typedef struct{
+    unsigned char   PageCode:6,
+                    Reserved1:1,
+                    PS:1;
+    unsigned char   PageLength;
+    unsigned char   Reserved2;
+    unsigned char   InactivityTimeMultiplier:4,
+                    Reserved3:4;
+    unsigned char   SWPP:1,
+                    DISP:1,
+                    Reserved4:6;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+} __attribute__((packed)) TIMER_AND_PROTECT_PAGE;
+
+typedef struct{
+    READ_WRITE_ERROR_RECOVERY_PAGE              ReadWriteErrorRecoveryPage;
+    FLEXIBLE_DISK_PAGE                          FlexibleDiskPage;
+    REMOVABLE_BLOCK_ACCESS_CAPABILITIES_PAGE    RemovableBlockAccessCapabilitiesPage;
+    TIMER_AND_PROTECT_PAGE                      TimerAndProtectPage;
+} __attribute__((packed)) MODE_ALL_PAGES;
+
+typedef struct{
+    MODE_PARAMETER_HEADER   ModeParameterHeader;
+    union{
+        READ_WRITE_ERROR_RECOVERY_PAGE              ReadWriteErrorRecoveryPage;
+        FLEXIBLE_DISK_PAGE                          FlexibleDiskPage;
+        REMOVABLE_BLOCK_ACCESS_CAPABILITIES_PAGE    RemovableBlockAccessCapabilitiesPage;
+        TIMER_AND_PROTECT_PAGE                      TimerAndProtectPage;
+        MODE_ALL_PAGES                              ModeAllPages;
+    } __attribute__((packed)) ModePages;
+} __attribute__((packed)) SCSI_MODE_SENSE_DATA;
+
+/*
+ * TEST UNIT READY
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   Reserved1:5,
+                    LogicalUnitNumber:3;
+    unsigned char   Reserved2;
+    unsigned char   Reserved3;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+    unsigned char   Reserved10;
+    unsigned char   Reserved11;
+} __attribute__((packed)) SCSI_TEST_UNIT_READY_COMMAND;
+
+/*
+ * PREVENT-ALLOW MEDIUM REMOVAL
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   Reserved1:5,
+                    LogicalUnitNumber:3;
+    unsigned char   Reserved2;
+    unsigned char   Reserved3;
+    unsigned char   Prevent:1,
+                    Reserved4:7;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+    unsigned char   Reserved10;
+    unsigned char   Reserved11;
+} __attribute__((packed)) SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL_COMMAND;
+
+/*
+ * START-STOP UNIT
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   IMMED:1,
+                    Reserved1:4,
+                    LogicalUnitNumber:3;
+    unsigned char   Reserved2;
+    unsigned char   Reserved3;
+    unsigned char   Start:1,
+                    LoEj:1,
+                    Reserved4:6;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+    unsigned char   Reserved7;
+    unsigned char   Reserved8;
+    unsigned char   Reserved9;
+    unsigned char   Reserved10;
+    unsigned char   Reserved11;
+} __attribute__((packed)) SCSI_START_STOP_COMMAND;
+
+/*
+ * WRITE(10)
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   RelAdr:1,
+                    Reserved1:2,
+                    FUA:1,
+                    DPO:1,
+                    LogicalUnitNumber:3;
+    unsigned char   LogicalBlockAddress[4];
+    unsigned char   Reserved2;
+    unsigned char   TransferLength[2];
+    unsigned char   Reserved3;
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+} __attribute__((packed)) SCSI_WRITE_10_COMMAND;
+
+/*
+ * VERIFY
+ */
+
+typedef struct{
+    unsigned char   OperationCode;
+    unsigned char   RelAdr:1,
+                    ByteChk:1,
+                    Reserved1:1,
+                    Reserved2:1,
+                    DPO:1,
+                    LogicalUnitNumber:3;
+    unsigned char   LogicalBlockAddress[4];
+    unsigned char   Reserved3;
+    unsigned char   VerificationLength[2];
+    unsigned char   Reserved4;
+    unsigned char   Reserved5;
+    unsigned char   Reserved6;
+} __attribute__((packed)) SCSI_VERIFY_COMMAND;
+
+/******************************************************************************
+** Global Function Prototype
+******************************************************************************/
+
+/* storage-fd.c */
+void    storage_urb_send(struct usb_device_instance*, void*, int);
+
+/* storageproto.c */
+void    storageproto_urb_analysis(struct urb*);
+int     storageproto_device_open_check(void);
+void    storageproto_device_close(void);
+void    storageproto_usb_status_check(int);
+void    storageproto_media_status_check(int);
+void    storageproto_usb_reset_ind(void);
+ssize_t storageproto_proc_read(struct file*, char*, size_t, loff_t* pos);
+void    storageproto_init(void);
+void    storageproto_exit(void);
+
+#endif  /* _STORAGEPROTO_H_ */
+