File: patch-2.4.16

package info (click to toggle)
openmosix 1.5.4-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,988 kB
  • ctags: 1,311
  • sloc: ansic: 6,710; makefile: 292; sh: 266
file content (50377 lines) | stat: -rw-r--r-- 1,288,583 bytes parent folder | download
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
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
38181
38182
38183
38184
38185
38186
38187
38188
38189
38190
38191
38192
38193
38194
38195
38196
38197
38198
38199
38200
38201
38202
38203
38204
38205
38206
38207
38208
38209
38210
38211
38212
38213
38214
38215
38216
38217
38218
38219
38220
38221
38222
38223
38224
38225
38226
38227
38228
38229
38230
38231
38232
38233
38234
38235
38236
38237
38238
38239
38240
38241
38242
38243
38244
38245
38246
38247
38248
38249
38250
38251
38252
38253
38254
38255
38256
38257
38258
38259
38260
38261
38262
38263
38264
38265
38266
38267
38268
38269
38270
38271
38272
38273
38274
38275
38276
38277
38278
38279
38280
38281
38282
38283
38284
38285
38286
38287
38288
38289
38290
38291
38292
38293
38294
38295
38296
38297
38298
38299
38300
38301
38302
38303
38304
38305
38306
38307
38308
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
38325
38326
38327
38328
38329
38330
38331
38332
38333
38334
38335
38336
38337
38338
38339
38340
38341
38342
38343
38344
38345
38346
38347
38348
38349
38350
38351
38352
38353
38354
38355
38356
38357
38358
38359
38360
38361
38362
38363
38364
38365
38366
38367
38368
38369
38370
38371
38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
38401
38402
38403
38404
38405
38406
38407
38408
38409
38410
38411
38412
38413
38414
38415
38416
38417
38418
38419
38420
38421
38422
38423
38424
38425
38426
38427
38428
38429
38430
38431
38432
38433
38434
38435
38436
38437
38438
38439
38440
38441
38442
38443
38444
38445
38446
38447
38448
38449
38450
38451
38452
38453
38454
38455
38456
38457
38458
38459
38460
38461
38462
38463
38464
38465
38466
38467
38468
38469
38470
38471
38472
38473
38474
38475
38476
38477
38478
38479
38480
38481
38482
38483
38484
38485
38486
38487
38488
38489
38490
38491
38492
38493
38494
38495
38496
38497
38498
38499
38500
38501
38502
38503
38504
38505
38506
38507
38508
38509
38510
38511
38512
38513
38514
38515
38516
38517
38518
38519
38520
38521
38522
38523
38524
38525
38526
38527
38528
38529
38530
38531
38532
38533
38534
38535
38536
38537
38538
38539
38540
38541
38542
38543
38544
38545
38546
38547
38548
38549
38550
38551
38552
38553
38554
38555
38556
38557
38558
38559
38560
38561
38562
38563
38564
38565
38566
38567
38568
38569
38570
38571
38572
38573
38574
38575
38576
38577
38578
38579
38580
38581
38582
38583
38584
38585
38586
38587
38588
38589
38590
38591
38592
38593
38594
38595
38596
38597
38598
38599
38600
38601
38602
38603
38604
38605
38606
38607
38608
38609
38610
38611
38612
38613
38614
38615
38616
38617
38618
38619
38620
38621
38622
38623
38624
38625
38626
38627
38628
38629
38630
38631
38632
38633
38634
38635
38636
38637
38638
38639
38640
38641
38642
38643
38644
38645
38646
38647
38648
38649
38650
38651
38652
38653
38654
38655
38656
38657
38658
38659
38660
38661
38662
38663
38664
38665
38666
38667
38668
38669
38670
38671
38672
38673
38674
38675
38676
38677
38678
38679
38680
38681
38682
38683
38684
38685
38686
38687
38688
38689
38690
38691
38692
38693
38694
38695
38696
38697
38698
38699
38700
38701
38702
38703
38704
38705
38706
38707
38708
38709
38710
38711
38712
38713
38714
38715
38716
38717
38718
38719
38720
38721
38722
38723
38724
38725
38726
38727
38728
38729
38730
38731
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
38748
38749
38750
38751
38752
38753
38754
38755
38756
38757
38758
38759
38760
38761
38762
38763
38764
38765
38766
38767
38768
38769
38770
38771
38772
38773
38774
38775
38776
38777
38778
38779
38780
38781
38782
38783
38784
38785
38786
38787
38788
38789
38790
38791
38792
38793
38794
38795
38796
38797
38798
38799
38800
38801
38802
38803
38804
38805
38806
38807
38808
38809
38810
38811
38812
38813
38814
38815
38816
38817
38818
38819
38820
38821
38822
38823
38824
38825
38826
38827
38828
38829
38830
38831
38832
38833
38834
38835
38836
38837
38838
38839
38840
38841
38842
38843
38844
38845
38846
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871
38872
38873
38874
38875
38876
38877
38878
38879
38880
38881
38882
38883
38884
38885
38886
38887
38888
38889
38890
38891
38892
38893
38894
38895
38896
38897
38898
38899
38900
38901
38902
38903
38904
38905
38906
38907
38908
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921
38922
38923
38924
38925
38926
38927
38928
38929
38930
38931
38932
38933
38934
38935
38936
38937
38938
38939
38940
38941
38942
38943
38944
38945
38946
38947
38948
38949
38950
38951
38952
38953
38954
38955
38956
38957
38958
38959
38960
38961
38962
38963
38964
38965
38966
38967
38968
38969
38970
38971
38972
38973
38974
38975
38976
38977
38978
38979
38980
38981
38982
38983
38984
38985
38986
38987
38988
38989
38990
38991
38992
38993
38994
38995
38996
38997
38998
38999
39000
39001
39002
39003
39004
39005
39006
39007
39008
39009
39010
39011
39012
39013
39014
39015
39016
39017
39018
39019
39020
39021
39022
39023
39024
39025
39026
39027
39028
39029
39030
39031
39032
39033
39034
39035
39036
39037
39038
39039
39040
39041
39042
39043
39044
39045
39046
39047
39048
39049
39050
39051
39052
39053
39054
39055
39056
39057
39058
39059
39060
39061
39062
39063
39064
39065
39066
39067
39068
39069
39070
39071
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118
39119
39120
39121
39122
39123
39124
39125
39126
39127
39128
39129
39130
39131
39132
39133
39134
39135
39136
39137
39138
39139
39140
39141
39142
39143
39144
39145
39146
39147
39148
39149
39150
39151
39152
39153
39154
39155
39156
39157
39158
39159
39160
39161
39162
39163
39164
39165
39166
39167
39168
39169
39170
39171
39172
39173
39174
39175
39176
39177
39178
39179
39180
39181
39182
39183
39184
39185
39186
39187
39188
39189
39190
39191
39192
39193
39194
39195
39196
39197
39198
39199
39200
39201
39202
39203
39204
39205
39206
39207
39208
39209
39210
39211
39212
39213
39214
39215
39216
39217
39218
39219
39220
39221
39222
39223
39224
39225
39226
39227
39228
39229
39230
39231
39232
39233
39234
39235
39236
39237
39238
39239
39240
39241
39242
39243
39244
39245
39246
39247
39248
39249
39250
39251
39252
39253
39254
39255
39256
39257
39258
39259
39260
39261
39262
39263
39264
39265
39266
39267
39268
39269
39270
39271
39272
39273
39274
39275
39276
39277
39278
39279
39280
39281
39282
39283
39284
39285
39286
39287
39288
39289
39290
39291
39292
39293
39294
39295
39296
39297
39298
39299
39300
39301
39302
39303
39304
39305
39306
39307
39308
39309
39310
39311
39312
39313
39314
39315
39316
39317
39318
39319
39320
39321
39322
39323
39324
39325
39326
39327
39328
39329
39330
39331
39332
39333
39334
39335
39336
39337
39338
39339
39340
39341
39342
39343
39344
39345
39346
39347
39348
39349
39350
39351
39352
39353
39354
39355
39356
39357
39358
39359
39360
39361
39362
39363
39364
39365
39366
39367
39368
39369
39370
39371
39372
39373
39374
39375
39376
39377
39378
39379
39380
39381
39382
39383
39384
39385
39386
39387
39388
39389
39390
39391
39392
39393
39394
39395
39396
39397
39398
39399
39400
39401
39402
39403
39404
39405
39406
39407
39408
39409
39410
39411
39412
39413
39414
39415
39416
39417
39418
39419
39420
39421
39422
39423
39424
39425
39426
39427
39428
39429
39430
39431
39432
39433
39434
39435
39436
39437
39438
39439
39440
39441
39442
39443
39444
39445
39446
39447
39448
39449
39450
39451
39452
39453
39454
39455
39456
39457
39458
39459
39460
39461
39462
39463
39464
39465
39466
39467
39468
39469
39470
39471
39472
39473
39474
39475
39476
39477
39478
39479
39480
39481
39482
39483
39484
39485
39486
39487
39488
39489
39490
39491
39492
39493
39494
39495
39496
39497
39498
39499
39500
39501
39502
39503
39504
39505
39506
39507
39508
39509
39510
39511
39512
39513
39514
39515
39516
39517
39518
39519
39520
39521
39522
39523
39524
39525
39526
39527
39528
39529
39530
39531
39532
39533
39534
39535
39536
39537
39538
39539
39540
39541
39542
39543
39544
39545
39546
39547
39548
39549
39550
39551
39552
39553
39554
39555
39556
39557
39558
39559
39560
39561
39562
39563
39564
39565
39566
39567
39568
39569
39570
39571
39572
39573
39574
39575
39576
39577
39578
39579
39580
39581
39582
39583
39584
39585
39586
39587
39588
39589
39590
39591
39592
39593
39594
39595
39596
39597
39598
39599
39600
39601
39602
39603
39604
39605
39606
39607
39608
39609
39610
39611
39612
39613
39614
39615
39616
39617
39618
39619
39620
39621
39622
39623
39624
39625
39626
39627
39628
39629
39630
39631
39632
39633
39634
39635
39636
39637
39638
39639
39640
39641
39642
39643
39644
39645
39646
39647
39648
39649
39650
39651
39652
39653
39654
39655
39656
39657
39658
39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
39672
39673
39674
39675
39676
39677
39678
39679
39680
39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
39694
39695
39696
39697
39698
39699
39700
39701
39702
39703
39704
39705
39706
39707
39708
39709
39710
39711
39712
39713
39714
39715
39716
39717
39718
39719
39720
39721
39722
39723
39724
39725
39726
39727
39728
39729
39730
39731
39732
39733
39734
39735
39736
39737
39738
39739
39740
39741
39742
39743
39744
39745
39746
39747
39748
39749
39750
39751
39752
39753
39754
39755
39756
39757
39758
39759
39760
39761
39762
39763
39764
39765
39766
39767
39768
39769
39770
39771
39772
39773
39774
39775
39776
39777
39778
39779
39780
39781
39782
39783
39784
39785
39786
39787
39788
39789
39790
39791
39792
39793
39794
39795
39796
39797
39798
39799
39800
39801
39802
39803
39804
39805
39806
39807
39808
39809
39810
39811
39812
39813
39814
39815
39816
39817
39818
39819
39820
39821
39822
39823
39824
39825
39826
39827
39828
39829
39830
39831
39832
39833
39834
39835
39836
39837
39838
39839
39840
39841
39842
39843
39844
39845
39846
39847
39848
39849
39850
39851
39852
39853
39854
39855
39856
39857
39858
39859
39860
39861
39862
39863
39864
39865
39866
39867
39868
39869
39870
39871
39872
39873
39874
39875
39876
39877
39878
39879
39880
39881
39882
39883
39884
39885
39886
39887
39888
39889
39890
39891
39892
39893
39894
39895
39896
39897
39898
39899
39900
39901
39902
39903
39904
39905
39906
39907
39908
39909
39910
39911
39912
39913
39914
39915
39916
39917
39918
39919
39920
39921
39922
39923
39924
39925
39926
39927
39928
39929
39930
39931
39932
39933
39934
39935
39936
39937
39938
39939
39940
39941
39942
39943
39944
39945
39946
39947
39948
39949
39950
39951
39952
39953
39954
39955
39956
39957
39958
39959
39960
39961
39962
39963
39964
39965
39966
39967
39968
39969
39970
39971
39972
39973
39974
39975
39976
39977
39978
39979
39980
39981
39982
39983
39984
39985
39986
39987
39988
39989
39990
39991
39992
39993
39994
39995
39996
39997
39998
39999
40000
40001
40002
40003
40004
40005
40006
40007
40008
40009
40010
40011
40012
40013
40014
40015
40016
40017
40018
40019
40020
40021
40022
40023
40024
40025
40026
40027
40028
40029
40030
40031
40032
40033
40034
40035
40036
40037
40038
40039
40040
40041
40042
40043
40044
40045
40046
40047
40048
40049
40050
40051
40052
40053
40054
40055
40056
40057
40058
40059
40060
40061
40062
40063
40064
40065
40066
40067
40068
40069
40070
40071
40072
40073
40074
40075
40076
40077
40078
40079
40080
40081
40082
40083
40084
40085
40086
40087
40088
40089
40090
40091
40092
40093
40094
40095
40096
40097
40098
40099
40100
40101
40102
40103
40104
40105
40106
40107
40108
40109
40110
40111
40112
40113
40114
40115
40116
40117
40118
40119
40120
40121
40122
40123
40124
40125
40126
40127
40128
40129
40130
40131
40132
40133
40134
40135
40136
40137
40138
40139
40140
40141
40142
40143
40144
40145
40146
40147
40148
40149
40150
40151
40152
40153
40154
40155
40156
40157
40158
40159
40160
40161
40162
40163
40164
40165
40166
40167
40168
40169
40170
40171
40172
40173
40174
40175
40176
40177
40178
40179
40180
40181
40182
40183
40184
40185
40186
40187
40188
40189
40190
40191
40192
40193
40194
40195
40196
40197
40198
40199
40200
40201
40202
40203
40204
40205
40206
40207
40208
40209
40210
40211
40212
40213
40214
40215
40216
40217
40218
40219
40220
40221
40222
40223
40224
40225
40226
40227
40228
40229
40230
40231
40232
40233
40234
40235
40236
40237
40238
40239
40240
40241
40242
40243
40244
40245
40246
40247
40248
40249
40250
40251
40252
40253
40254
40255
40256
40257
40258
40259
40260
40261
40262
40263
40264
40265
40266
40267
40268
40269
40270
40271
40272
40273
40274
40275
40276
40277
40278
40279
40280
40281
40282
40283
40284
40285
40286
40287
40288
40289
40290
40291
40292
40293
40294
40295
40296
40297
40298
40299
40300
40301
40302
40303
40304
40305
40306
40307
40308
40309
40310
40311
40312
40313
40314
40315
40316
40317
40318
40319
40320
40321
40322
40323
40324
40325
40326
40327
40328
40329
40330
40331
40332
40333
40334
40335
40336
40337
40338
40339
40340
40341
40342
40343
40344
40345
40346
40347
40348
40349
40350
40351
40352
40353
40354
40355
40356
40357
40358
40359
40360
40361
40362
40363
40364
40365
40366
40367
40368
40369
40370
40371
40372
40373
40374
40375
40376
40377
40378
40379
40380
40381
40382
40383
40384
40385
40386
40387
40388
40389
40390
40391
40392
40393
40394
40395
40396
40397
40398
40399
40400
40401
40402
40403
40404
40405
40406
40407
40408
40409
40410
40411
40412
40413
40414
40415
40416
40417
40418
40419
40420
40421
40422
40423
40424
40425
40426
40427
40428
40429
40430
40431
40432
40433
40434
40435
40436
40437
40438
40439
40440
40441
40442
40443
40444
40445
40446
40447
40448
40449
40450
40451
40452
40453
40454
40455
40456
40457
40458
40459
40460
40461
40462
40463
40464
40465
40466
40467
40468
40469
40470
40471
40472
40473
40474
40475
40476
40477
40478
40479
40480
40481
40482
40483
40484
40485
40486
40487
40488
40489
40490
40491
40492
40493
40494
40495
40496
40497
40498
40499
40500
40501
40502
40503
40504
40505
40506
40507
40508
40509
40510
40511
40512
40513
40514
40515
40516
40517
40518
40519
40520
40521
40522
40523
40524
40525
40526
40527
40528
40529
40530
40531
40532
40533
40534
40535
40536
40537
40538
40539
40540
40541
40542
40543
40544
40545
40546
40547
40548
40549
40550
40551
40552
40553
40554
40555
40556
40557
40558
40559
40560
40561
40562
40563
40564
40565
40566
40567
40568
40569
40570
40571
40572
40573
40574
40575
40576
40577
40578
40579
40580
40581
40582
40583
40584
40585
40586
40587
40588
40589
40590
40591
40592
40593
40594
40595
40596
40597
40598
40599
40600
40601
40602
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613
40614
40615
40616
40617
40618
40619
40620
40621
40622
40623
40624
40625
40626
40627
40628
40629
40630
40631
40632
40633
40634
40635
40636
40637
40638
40639
40640
40641
40642
40643
40644
40645
40646
40647
40648
40649
40650
40651
40652
40653
40654
40655
40656
40657
40658
40659
40660
40661
40662
40663
40664
40665
40666
40667
40668
40669
40670
40671
40672
40673
40674
40675
40676
40677
40678
40679
40680
40681
40682
40683
40684
40685
40686
40687
40688
40689
40690
40691
40692
40693
40694
40695
40696
40697
40698
40699
40700
40701
40702
40703
40704
40705
40706
40707
40708
40709
40710
40711
40712
40713
40714
40715
40716
40717
40718
40719
40720
40721
40722
40723
40724
40725
40726
40727
40728
40729
40730
40731
40732
40733
40734
40735
40736
40737
40738
40739
40740
40741
40742
40743
40744
40745
40746
40747
40748
40749
40750
40751
40752
40753
40754
40755
40756
40757
40758
40759
40760
40761
40762
40763
40764
40765
40766
40767
40768
40769
40770
40771
40772
40773
40774
40775
40776
40777
40778
40779
40780
40781
40782
40783
40784
40785
40786
40787
40788
40789
40790
40791
40792
40793
40794
40795
40796
40797
40798
40799
40800
40801
40802
40803
40804
40805
40806
40807
40808
40809
40810
40811
40812
40813
40814
40815
40816
40817
40818
40819
40820
40821
40822
40823
40824
40825
40826
40827
40828
40829
40830
40831
40832
40833
40834
40835
40836
40837
40838
40839
40840
40841
40842
40843
40844
40845
40846
40847
40848
40849
40850
40851
40852
40853
40854
40855
40856
40857
40858
40859
40860
40861
40862
40863
40864
40865
40866
40867
40868
40869
40870
40871
40872
40873
40874
40875
40876
40877
40878
40879
40880
40881
40882
40883
40884
40885
40886
40887
40888
40889
40890
40891
40892
40893
40894
40895
40896
40897
40898
40899
40900
40901
40902
40903
40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
40915
40916
40917
40918
40919
40920
40921
40922
40923
40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
40935
40936
40937
40938
40939
40940
40941
40942
40943
40944
40945
40946
40947
40948
40949
40950
40951
40952
40953
40954
40955
40956
40957
40958
40959
40960
40961
40962
40963
40964
40965
40966
40967
40968
40969
40970
40971
40972
40973
40974
40975
40976
40977
40978
40979
40980
40981
40982
40983
40984
40985
40986
40987
40988
40989
40990
40991
40992
40993
40994
40995
40996
40997
40998
40999
41000
41001
41002
41003
41004
41005
41006
41007
41008
41009
41010
41011
41012
41013
41014
41015
41016
41017
41018
41019
41020
41021
41022
41023
41024
41025
41026
41027
41028
41029
41030
41031
41032
41033
41034
41035
41036
41037
41038
41039
41040
41041
41042
41043
41044
41045
41046
41047
41048
41049
41050
41051
41052
41053
41054
41055
41056
41057
41058
41059
41060
41061
41062
41063
41064
41065
41066
41067
41068
41069
41070
41071
41072
41073
41074
41075
41076
41077
41078
41079
41080
41081
41082
41083
41084
41085
41086
41087
41088
41089
41090
41091
41092
41093
41094
41095
41096
41097
41098
41099
41100
41101
41102
41103
41104
41105
41106
41107
41108
41109
41110
41111
41112
41113
41114
41115
41116
41117
41118
41119
41120
41121
41122
41123
41124
41125
41126
41127
41128
41129
41130
41131
41132
41133
41134
41135
41136
41137
41138
41139
41140
41141
41142
41143
41144
41145
41146
41147
41148
41149
41150
41151
41152
41153
41154
41155
41156
41157
41158
41159
41160
41161
41162
41163
41164
41165
41166
41167
41168
41169
41170
41171
41172
41173
41174
41175
41176
41177
41178
41179
41180
41181
41182
41183
41184
41185
41186
41187
41188
41189
41190
41191
41192
41193
41194
41195
41196
41197
41198
41199
41200
41201
41202
41203
41204
41205
41206
41207
41208
41209
41210
41211
41212
41213
41214
41215
41216
41217
41218
41219
41220
41221
41222
41223
41224
41225
41226
41227
41228
41229
41230
41231
41232
41233
41234
41235
41236
41237
41238
41239
41240
41241
41242
41243
41244
41245
41246
41247
41248
41249
41250
41251
41252
41253
41254
41255
41256
41257
41258
41259
41260
41261
41262
41263
41264
41265
41266
41267
41268
41269
41270
41271
41272
41273
41274
41275
41276
41277
41278
41279
41280
41281
41282
41283
41284
41285
41286
41287
41288
41289
41290
41291
41292
41293
41294
41295
41296
41297
41298
41299
41300
41301
41302
41303
41304
41305
41306
41307
41308
41309
41310
41311
41312
41313
41314
41315
41316
41317
41318
41319
41320
41321
41322
41323
41324
41325
41326
41327
41328
41329
41330
41331
41332
41333
41334
41335
41336
41337
41338
41339
41340
41341
41342
41343
41344
41345
41346
41347
41348
41349
41350
41351
41352
41353
41354
41355
41356
41357
41358
41359
41360
41361
41362
41363
41364
41365
41366
41367
41368
41369
41370
41371
41372
41373
41374
41375
41376
41377
41378
41379
41380
41381
41382
41383
41384
41385
41386
41387
41388
41389
41390
41391
41392
41393
41394
41395
41396
41397
41398
41399
41400
41401
41402
41403
41404
41405
41406
41407
41408
41409
41410
41411
41412
41413
41414
41415
41416
41417
41418
41419
41420
41421
41422
41423
41424
41425
41426
41427
41428
41429
41430
41431
41432
41433
41434
41435
41436
41437
41438
41439
41440
41441
41442
41443
41444
41445
41446
41447
41448
41449
41450
41451
41452
41453
41454
41455
41456
41457
41458
41459
41460
41461
41462
41463
41464
41465
41466
41467
41468
41469
41470
41471
41472
41473
41474
41475
41476
41477
41478
41479
41480
41481
41482
41483
41484
41485
41486
41487
41488
41489
41490
41491
41492
41493
41494
41495
41496
41497
41498
41499
41500
41501
41502
41503
41504
41505
41506
41507
41508
41509
41510
41511
41512
41513
41514
41515
41516
41517
41518
41519
41520
41521
41522
41523
41524
41525
41526
41527
41528
41529
41530
41531
41532
41533
41534
41535
41536
41537
41538
41539
41540
41541
41542
41543
41544
41545
41546
41547
41548
41549
41550
41551
41552
41553
41554
41555
41556
41557
41558
41559
41560
41561
41562
41563
41564
41565
41566
41567
41568
41569
41570
41571
41572
41573
41574
41575
41576
41577
41578
41579
41580
41581
41582
41583
41584
41585
41586
41587
41588
41589
41590
41591
41592
41593
41594
41595
41596
41597
41598
41599
41600
41601
41602
41603
41604
41605
41606
41607
41608
41609
41610
41611
41612
41613
41614
41615
41616
41617
41618
41619
41620
41621
41622
41623
41624
41625
41626
41627
41628
41629
41630
41631
41632
41633
41634
41635
41636
41637
41638
41639
41640
41641
41642
41643
41644
41645
41646
41647
41648
41649
41650
41651
41652
41653
41654
41655
41656
41657
41658
41659
41660
41661
41662
41663
41664
41665
41666
41667
41668
41669
41670
41671
41672
41673
41674
41675
41676
41677
41678
41679
41680
41681
41682
41683
41684
41685
41686
41687
41688
41689
41690
41691
41692
41693
41694
41695
41696
41697
41698
41699
41700
41701
41702
41703
41704
41705
41706
41707
41708
41709
41710
41711
41712
41713
41714
41715
41716
41717
41718
41719
41720
41721
41722
41723
41724
41725
41726
41727
41728
41729
41730
41731
41732
41733
41734
41735
41736
41737
41738
41739
41740
41741
41742
41743
41744
41745
41746
41747
41748
41749
41750
41751
41752
41753
41754
41755
41756
41757
41758
41759
41760
41761
41762
41763
41764
41765
41766
41767
41768
41769
41770
41771
41772
41773
41774
41775
41776
41777
41778
41779
41780
41781
41782
41783
41784
41785
41786
41787
41788
41789
41790
41791
41792
41793
41794
41795
41796
41797
41798
41799
41800
41801
41802
41803
41804
41805
41806
41807
41808
41809
41810
41811
41812
41813
41814
41815
41816
41817
41818
41819
41820
41821
41822
41823
41824
41825
41826
41827
41828
41829
41830
41831
41832
41833
41834
41835
41836
41837
41838
41839
41840
41841
41842
41843
41844
41845
41846
41847
41848
41849
41850
41851
41852
41853
41854
41855
41856
41857
41858
41859
41860
41861
41862
41863
41864
41865
41866
41867
41868
41869
41870
41871
41872
41873
41874
41875
41876
41877
41878
41879
41880
41881
41882
41883
41884
41885
41886
41887
41888
41889
41890
41891
41892
41893
41894
41895
41896
41897
41898
41899
41900
41901
41902
41903
41904
41905
41906
41907
41908
41909
41910
41911
41912
41913
41914
41915
41916
41917
41918
41919
41920
41921
41922
41923
41924
41925
41926
41927
41928
41929
41930
41931
41932
41933
41934
41935
41936
41937
41938
41939
41940
41941
41942
41943
41944
41945
41946
41947
41948
41949
41950
41951
41952
41953
41954
41955
41956
41957
41958
41959
41960
41961
41962
41963
41964
41965
41966
41967
41968
41969
41970
41971
41972
41973
41974
41975
41976
41977
41978
41979
41980
41981
41982
41983
41984
41985
41986
41987
41988
41989
41990
41991
41992
41993
41994
41995
41996
41997
41998
41999
42000
42001
42002
42003
42004
42005
42006
42007
42008
42009
42010
42011
42012
42013
42014
42015
42016
42017
42018
42019
42020
42021
42022
42023
42024
42025
42026
42027
42028
42029
42030
42031
42032
42033
42034
42035
42036
42037
42038
42039
42040
42041
42042
42043
42044
42045
42046
42047
42048
42049
42050
42051
42052
42053
42054
42055
42056
42057
42058
42059
42060
42061
42062
42063
42064
42065
42066
42067
42068
42069
42070
42071
42072
42073
42074
42075
42076
42077
42078
42079
42080
42081
42082
42083
42084
42085
42086
42087
42088
42089
42090
42091
42092
42093
42094
42095
42096
42097
42098
42099
42100
42101
42102
42103
42104
42105
42106
42107
42108
42109
42110
42111
42112
42113
42114
42115
42116
42117
42118
42119
42120
42121
42122
42123
42124
42125
42126
42127
42128
42129
42130
42131
42132
42133
42134
42135
42136
42137
42138
42139
42140
42141
42142
42143
42144
42145
42146
42147
42148
42149
42150
42151
42152
42153
42154
42155
42156
42157
42158
42159
42160
42161
42162
42163
42164
42165
42166
42167
42168
42169
42170
42171
42172
42173
42174
42175
42176
42177
42178
42179
42180
42181
42182
42183
42184
42185
42186
42187
42188
42189
42190
42191
42192
42193
42194
42195
42196
42197
42198
42199
42200
42201
42202
42203
42204
42205
42206
42207
42208
42209
42210
42211
42212
42213
42214
42215
42216
42217
42218
42219
42220
42221
42222
42223
42224
42225
42226
42227
42228
42229
42230
42231
42232
42233
42234
42235
42236
42237
42238
42239
42240
42241
42242
42243
42244
42245
42246
42247
42248
42249
42250
42251
42252
42253
42254
42255
42256
42257
42258
42259
42260
42261
42262
42263
42264
42265
42266
42267
42268
42269
42270
42271
42272
42273
42274
42275
42276
42277
42278
42279
42280
42281
42282
42283
42284
42285
42286
42287
42288
42289
42290
42291
42292
42293
42294
42295
42296
42297
42298
42299
42300
42301
42302
42303
42304
42305
42306
42307
42308
42309
42310
42311
42312
42313
42314
42315
42316
42317
42318
42319
42320
42321
42322
42323
42324
42325
42326
42327
42328
42329
42330
42331
42332
42333
42334
42335
42336
42337
42338
42339
42340
42341
42342
42343
42344
42345
42346
42347
42348
42349
42350
42351
42352
42353
42354
42355
42356
42357
42358
42359
42360
42361
42362
42363
42364
42365
42366
42367
42368
42369
42370
42371
42372
42373
42374
42375
42376
42377
42378
42379
42380
42381
42382
42383
42384
42385
42386
42387
42388
42389
42390
42391
42392
42393
42394
42395
42396
42397
42398
42399
42400
42401
42402
42403
42404
42405
42406
42407
42408
42409
42410
42411
42412
42413
42414
42415
42416
42417
42418
42419
42420
42421
42422
42423
42424
42425
42426
42427
42428
42429
42430
42431
42432
42433
42434
42435
42436
42437
42438
42439
42440
42441
42442
42443
42444
42445
42446
42447
42448
42449
42450
42451
42452
42453
42454
42455
42456
42457
42458
42459
42460
42461
42462
42463
42464
42465
42466
42467
42468
42469
42470
42471
42472
42473
42474
42475
42476
42477
42478
42479
42480
42481
42482
42483
42484
42485
42486
42487
42488
42489
42490
42491
42492
42493
42494
42495
42496
42497
42498
42499
42500
42501
42502
42503
42504
42505
42506
42507
42508
42509
42510
42511
42512
42513
42514
42515
42516
42517
42518
42519
42520
42521
42522
42523
42524
42525
42526
42527
42528
42529
42530
42531
42532
42533
42534
42535
42536
42537
42538
42539
42540
42541
42542
42543
42544
42545
42546
42547
42548
42549
42550
42551
42552
42553
42554
42555
42556
42557
42558
42559
42560
42561
42562
42563
42564
42565
42566
42567
42568
42569
42570
42571
42572
42573
42574
42575
42576
42577
42578
42579
42580
42581
42582
42583
42584
42585
42586
42587
42588
42589
42590
42591
42592
42593
42594
42595
42596
42597
42598
42599
42600
42601
42602
42603
42604
42605
42606
42607
42608
42609
42610
42611
42612
42613
42614
42615
42616
42617
42618
42619
42620
42621
42622
42623
42624
42625
42626
42627
42628
42629
42630
42631
42632
42633
42634
42635
42636
42637
42638
42639
42640
42641
42642
42643
42644
42645
42646
42647
42648
42649
42650
42651
42652
42653
42654
42655
42656
42657
42658
42659
42660
42661
42662
42663
42664
42665
42666
42667
42668
42669
42670
42671
42672
42673
42674
42675
42676
42677
42678
42679
42680
42681
42682
42683
42684
42685
42686
42687
42688
42689
42690
42691
42692
42693
42694
42695
42696
42697
42698
42699
42700
42701
42702
42703
42704
42705
42706
42707
42708
42709
42710
42711
42712
42713
42714
42715
42716
42717
42718
42719
42720
42721
42722
42723
42724
42725
42726
42727
42728
42729
42730
42731
42732
42733
42734
42735
42736
42737
42738
42739
42740
42741
42742
42743
42744
42745
42746
42747
42748
42749
42750
42751
42752
42753
42754
42755
42756
42757
42758
42759
42760
42761
42762
42763
42764
42765
42766
42767
42768
42769
42770
42771
42772
42773
42774
42775
42776
42777
42778
42779
42780
42781
42782
42783
42784
42785
42786
42787
42788
42789
42790
42791
42792
42793
42794
42795
42796
42797
42798
42799
42800
42801
42802
42803
42804
42805
42806
42807
42808
42809
42810
42811
42812
42813
42814
42815
42816
42817
42818
42819
42820
42821
42822
42823
42824
42825
42826
42827
42828
42829
42830
42831
42832
42833
42834
42835
42836
42837
42838
42839
42840
42841
42842
42843
42844
42845
42846
42847
42848
42849
42850
42851
42852
42853
42854
42855
42856
42857
42858
42859
42860
42861
42862
42863
42864
42865
42866
42867
42868
42869
42870
42871
42872
42873
42874
42875
42876
42877
42878
42879
42880
42881
42882
42883
42884
42885
42886
42887
42888
42889
42890
42891
42892
42893
42894
42895
42896
42897
42898
42899
42900
42901
42902
42903
42904
42905
42906
42907
42908
42909
42910
42911
42912
42913
42914
42915
42916
42917
42918
42919
42920
42921
42922
42923
42924
42925
42926
42927
42928
42929
42930
42931
42932
42933
42934
42935
42936
42937
42938
42939
42940
42941
42942
42943
42944
42945
42946
42947
42948
42949
42950
42951
42952
42953
42954
42955
42956
42957
42958
42959
42960
42961
42962
42963
42964
42965
42966
42967
42968
42969
42970
42971
42972
42973
42974
42975
42976
42977
42978
42979
42980
42981
42982
42983
42984
42985
42986
42987
42988
42989
42990
42991
42992
42993
42994
42995
42996
42997
42998
42999
43000
43001
43002
43003
43004
43005
43006
43007
43008
43009
43010
43011
43012
43013
43014
43015
43016
43017
43018
43019
43020
43021
43022
43023
43024
43025
43026
43027
43028
43029
43030
43031
43032
43033
43034
43035
43036
43037
43038
43039
43040
43041
43042
43043
43044
43045
43046
43047
43048
43049
43050
43051
43052
43053
43054
43055
43056
43057
43058
43059
43060
43061
43062
43063
43064
43065
43066
43067
43068
43069
43070
43071
43072
43073
43074
43075
43076
43077
43078
43079
43080
43081
43082
43083
43084
43085
43086
43087
43088
43089
43090
43091
43092
43093
43094
43095
43096
43097
43098
43099
43100
43101
43102
43103
43104
43105
43106
43107
43108
43109
43110
43111
43112
43113
43114
43115
43116
43117
43118
43119
43120
43121
43122
43123
43124
43125
43126
43127
43128
43129
43130
43131
43132
43133
43134
43135
43136
43137
43138
43139
43140
43141
43142
43143
43144
43145
43146
43147
43148
43149
43150
43151
43152
43153
43154
43155
43156
43157
43158
43159
43160
43161
43162
43163
43164
43165
43166
43167
43168
43169
43170
43171
43172
43173
43174
43175
43176
43177
43178
43179
43180
43181
43182
43183
43184
43185
43186
43187
43188
43189
43190
43191
43192
43193
43194
43195
43196
43197
43198
43199
43200
43201
43202
43203
43204
43205
43206
43207
43208
43209
43210
43211
43212
43213
43214
43215
43216
43217
43218
43219
43220
43221
43222
43223
43224
43225
43226
43227
43228
43229
43230
43231
43232
43233
43234
43235
43236
43237
43238
43239
43240
43241
43242
43243
43244
43245
43246
43247
43248
43249
43250
43251
43252
43253
43254
43255
43256
43257
43258
43259
43260
43261
43262
43263
43264
43265
43266
43267
43268
43269
43270
43271
43272
43273
43274
43275
43276
43277
43278
43279
43280
43281
43282
43283
43284
43285
43286
43287
43288
43289
43290
43291
43292
43293
43294
43295
43296
43297
43298
43299
43300
43301
43302
43303
43304
43305
43306
43307
43308
43309
43310
43311
43312
43313
43314
43315
43316
43317
43318
43319
43320
43321
43322
43323
43324
43325
43326
43327
43328
43329
43330
43331
43332
43333
43334
43335
43336
43337
43338
43339
43340
43341
43342
43343
43344
43345
43346
43347
43348
43349
43350
43351
43352
43353
43354
43355
43356
43357
43358
43359
43360
43361
43362
43363
43364
43365
43366
43367
43368
43369
43370
43371
43372
43373
43374
43375
43376
43377
43378
43379
43380
43381
43382
43383
43384
43385
43386
43387
43388
43389
43390
43391
43392
43393
43394
43395
43396
43397
43398
43399
43400
43401
43402
43403
43404
43405
43406
43407
43408
43409
43410
43411
43412
43413
43414
43415
43416
43417
43418
43419
43420
43421
43422
43423
43424
43425
43426
43427
43428
43429
43430
43431
43432
43433
43434
43435
43436
43437
43438
43439
43440
43441
43442
43443
43444
43445
43446
43447
43448
43449
43450
43451
43452
43453
43454
43455
43456
43457
43458
43459
43460
43461
43462
43463
43464
43465
43466
43467
43468
43469
43470
43471
43472
43473
43474
43475
43476
43477
43478
43479
43480
43481
43482
43483
43484
43485
43486
43487
43488
43489
43490
43491
43492
43493
43494
43495
43496
43497
43498
43499
43500
43501
43502
43503
43504
43505
43506
43507
43508
43509
43510
43511
43512
43513
43514
43515
43516
43517
43518
43519
43520
43521
43522
43523
43524
43525
43526
43527
43528
43529
43530
43531
43532
43533
43534
43535
43536
43537
43538
43539
43540
43541
43542
43543
43544
43545
43546
43547
43548
43549
43550
43551
43552
43553
43554
43555
43556
43557
43558
43559
43560
43561
43562
43563
43564
43565
43566
43567
43568
43569
43570
43571
43572
43573
43574
43575
43576
43577
43578
43579
43580
43581
43582
43583
43584
43585
43586
43587
43588
43589
43590
43591
43592
43593
43594
43595
43596
43597
43598
43599
43600
43601
43602
43603
43604
43605
43606
43607
43608
43609
43610
43611
43612
43613
43614
43615
43616
43617
43618
43619
43620
43621
43622
43623
43624
43625
43626
43627
43628
43629
43630
43631
43632
43633
43634
43635
43636
43637
43638
43639
43640
43641
43642
43643
43644
43645
43646
43647
43648
43649
43650
43651
43652
43653
43654
43655
43656
43657
43658
43659
43660
43661
43662
43663
43664
43665
43666
43667
43668
43669
43670
43671
43672
43673
43674
43675
43676
43677
43678
43679
43680
43681
43682
43683
43684
43685
43686
43687
43688
43689
43690
43691
43692
43693
43694
43695
43696
43697
43698
43699
43700
43701
43702
43703
43704
43705
43706
43707
43708
43709
43710
43711
43712
43713
43714
43715
43716
43717
43718
43719
43720
43721
43722
43723
43724
43725
43726
43727
43728
43729
43730
43731
43732
43733
43734
43735
43736
43737
43738
43739
43740
43741
43742
43743
43744
43745
43746
43747
43748
43749
43750
43751
43752
43753
43754
43755
43756
43757
43758
43759
43760
43761
43762
43763
43764
43765
43766
43767
43768
43769
43770
43771
43772
43773
43774
43775
43776
43777
43778
43779
43780
43781
43782
43783
43784
43785
43786
43787
43788
43789
43790
43791
43792
43793
43794
43795
43796
43797
43798
43799
43800
43801
43802
43803
43804
43805
43806
43807
43808
43809
43810
43811
43812
43813
43814
43815
43816
43817
43818
43819
43820
43821
43822
43823
43824
43825
43826
43827
43828
43829
43830
43831
43832
43833
43834
43835
43836
43837
43838
43839
43840
43841
43842
43843
43844
43845
43846
43847
43848
43849
43850
43851
43852
43853
43854
43855
43856
43857
43858
43859
43860
43861
43862
43863
43864
43865
43866
43867
43868
43869
43870
43871
43872
43873
43874
43875
43876
43877
43878
43879
43880
43881
43882
43883
43884
43885
43886
43887
43888
43889
43890
43891
43892
43893
43894
43895
43896
43897
43898
43899
43900
43901
43902
43903
43904
43905
43906
43907
43908
43909
43910
43911
43912
43913
43914
43915
43916
43917
43918
43919
43920
43921
43922
43923
43924
43925
43926
43927
43928
43929
43930
43931
43932
43933
43934
43935
43936
43937
43938
43939
43940
43941
43942
43943
43944
43945
43946
43947
43948
43949
43950
43951
43952
43953
43954
43955
43956
43957
43958
43959
43960
43961
43962
43963
43964
43965
43966
43967
43968
43969
43970
43971
43972
43973
43974
43975
43976
43977
43978
43979
43980
43981
43982
43983
43984
43985
43986
43987
43988
43989
43990
43991
43992
43993
43994
43995
43996
43997
43998
43999
44000
44001
44002
44003
44004
44005
44006
44007
44008
44009
44010
44011
44012
44013
44014
44015
44016
44017
44018
44019
44020
44021
44022
44023
44024
44025
44026
44027
44028
44029
44030
44031
44032
44033
44034
44035
44036
44037
44038
44039
44040
44041
44042
44043
44044
44045
44046
44047
44048
44049
44050
44051
44052
44053
44054
44055
44056
44057
44058
44059
44060
44061
44062
44063
44064
44065
44066
44067
44068
44069
44070
44071
44072
44073
44074
44075
44076
44077
44078
44079
44080
44081
44082
44083
44084
44085
44086
44087
44088
44089
44090
44091
44092
44093
44094
44095
44096
44097
44098
44099
44100
44101
44102
44103
44104
44105
44106
44107
44108
44109
44110
44111
44112
44113
44114
44115
44116
44117
44118
44119
44120
44121
44122
44123
44124
44125
44126
44127
44128
44129
44130
44131
44132
44133
44134
44135
44136
44137
44138
44139
44140
44141
44142
44143
44144
44145
44146
44147
44148
44149
44150
44151
44152
44153
44154
44155
44156
44157
44158
44159
44160
44161
44162
44163
44164
44165
44166
44167
44168
44169
44170
44171
44172
44173
44174
44175
44176
44177
44178
44179
44180
44181
44182
44183
44184
44185
44186
44187
44188
44189
44190
44191
44192
44193
44194
44195
44196
44197
44198
44199
44200
44201
44202
44203
44204
44205
44206
44207
44208
44209
44210
44211
44212
44213
44214
44215
44216
44217
44218
44219
44220
44221
44222
44223
44224
44225
44226
44227
44228
44229
44230
44231
44232
44233
44234
44235
44236
44237
44238
44239
44240
44241
44242
44243
44244
44245
44246
44247
44248
44249
44250
44251
44252
44253
44254
44255
44256
44257
44258
44259
44260
44261
44262
44263
44264
44265
44266
44267
44268
44269
44270
44271
44272
44273
44274
44275
44276
44277
44278
44279
44280
44281
44282
44283
44284
44285
44286
44287
44288
44289
44290
44291
44292
44293
44294
44295
44296
44297
44298
44299
44300
44301
44302
44303
44304
44305
44306
44307
44308
44309
44310
44311
44312
44313
44314
44315
44316
44317
44318
44319
44320
44321
44322
44323
44324
44325
44326
44327
44328
44329
44330
44331
44332
44333
44334
44335
44336
44337
44338
44339
44340
44341
44342
44343
44344
44345
44346
44347
44348
44349
44350
44351
44352
44353
44354
44355
44356
44357
44358
44359
44360
44361
44362
44363
44364
44365
44366
44367
44368
44369
44370
44371
44372
44373
44374
44375
44376
44377
44378
44379
44380
44381
44382
44383
44384
44385
44386
44387
44388
44389
44390
44391
44392
44393
44394
44395
44396
44397
44398
44399
44400
44401
44402
44403
44404
44405
44406
44407
44408
44409
44410
44411
44412
44413
44414
44415
44416
44417
44418
44419
44420
44421
44422
44423
44424
44425
44426
44427
44428
44429
44430
44431
44432
44433
44434
44435
44436
44437
44438
44439
44440
44441
44442
44443
44444
44445
44446
44447
44448
44449
44450
44451
44452
44453
44454
44455
44456
44457
44458
44459
44460
44461
44462
44463
44464
44465
44466
44467
44468
44469
44470
44471
44472
44473
44474
44475
44476
44477
44478
44479
44480
44481
44482
44483
44484
44485
44486
44487
44488
44489
44490
44491
44492
44493
44494
44495
44496
44497
44498
44499
44500
44501
44502
44503
44504
44505
44506
44507
44508
44509
44510
44511
44512
44513
44514
44515
44516
44517
44518
44519
44520
44521
44522
44523
44524
44525
44526
44527
44528
44529
44530
44531
44532
44533
44534
44535
44536
44537
44538
44539
44540
44541
44542
44543
44544
44545
44546
44547
44548
44549
44550
44551
44552
44553
44554
44555
44556
44557
44558
44559
44560
44561
44562
44563
44564
44565
44566
44567
44568
44569
44570
44571
44572
44573
44574
44575
44576
44577
44578
44579
44580
44581
44582
44583
44584
44585
44586
44587
44588
44589
44590
44591
44592
44593
44594
44595
44596
44597
44598
44599
44600
44601
44602
44603
44604
44605
44606
44607
44608
44609
44610
44611
44612
44613
44614
44615
44616
44617
44618
44619
44620
44621
44622
44623
44624
44625
44626
44627
44628
44629
44630
44631
44632
44633
44634
44635
44636
44637
44638
44639
44640
44641
44642
44643
44644
44645
44646
44647
44648
44649
44650
44651
44652
44653
44654
44655
44656
44657
44658
44659
44660
44661
44662
44663
44664
44665
44666
44667
44668
44669
44670
44671
44672
44673
44674
44675
44676
44677
44678
44679
44680
44681
44682
44683
44684
44685
44686
44687
44688
44689
44690
44691
44692
44693
44694
44695
44696
44697
44698
44699
44700
44701
44702
44703
44704
44705
44706
44707
44708
44709
44710
44711
44712
44713
44714
44715
44716
44717
44718
44719
44720
44721
44722
44723
44724
44725
44726
44727
44728
44729
44730
44731
44732
44733
44734
44735
44736
44737
44738
44739
44740
44741
44742
44743
44744
44745
44746
44747
44748
44749
44750
44751
44752
44753
44754
44755
44756
44757
44758
44759
44760
44761
44762
44763
44764
44765
44766
44767
44768
44769
44770
44771
44772
44773
44774
44775
44776
44777
44778
44779
44780
44781
44782
44783
44784
44785
44786
44787
44788
44789
44790
44791
44792
44793
44794
44795
44796
44797
44798
44799
44800
44801
44802
44803
44804
44805
44806
44807
44808
44809
44810
44811
44812
44813
44814
44815
44816
44817
44818
44819
44820
44821
44822
44823
44824
44825
44826
44827
44828
44829
44830
44831
44832
44833
44834
44835
44836
44837
44838
44839
44840
44841
44842
44843
44844
44845
44846
44847
44848
44849
44850
44851
44852
44853
44854
44855
44856
44857
44858
44859
44860
44861
44862
44863
44864
44865
44866
44867
44868
44869
44870
44871
44872
44873
44874
44875
44876
44877
44878
44879
44880
44881
44882
44883
44884
44885
44886
44887
44888
44889
44890
44891
44892
44893
44894
44895
44896
44897
44898
44899
44900
44901
44902
44903
44904
44905
44906
44907
44908
44909
44910
44911
44912
44913
44914
44915
44916
44917
44918
44919
44920
44921
44922
44923
44924
44925
44926
44927
44928
44929
44930
44931
44932
44933
44934
44935
44936
44937
44938
44939
44940
44941
44942
44943
44944
44945
44946
44947
44948
44949
44950
44951
44952
44953
44954
44955
44956
44957
44958
44959
44960
44961
44962
44963
44964
44965
44966
44967
44968
44969
44970
44971
44972
44973
44974
44975
44976
44977
44978
44979
44980
44981
44982
44983
44984
44985
44986
44987
44988
44989
44990
44991
44992
44993
44994
44995
44996
44997
44998
44999
45000
45001
45002
45003
45004
45005
45006
45007
45008
45009
45010
45011
45012
45013
45014
45015
45016
45017
45018
45019
45020
45021
45022
45023
45024
45025
45026
45027
45028
45029
45030
45031
45032
45033
45034
45035
45036
45037
45038
45039
45040
45041
45042
45043
45044
45045
45046
45047
45048
45049
45050
45051
45052
45053
45054
45055
45056
45057
45058
45059
45060
45061
45062
45063
45064
45065
45066
45067
45068
45069
45070
45071
45072
45073
45074
45075
45076
45077
45078
45079
45080
45081
45082
45083
45084
45085
45086
45087
45088
45089
45090
45091
45092
45093
45094
45095
45096
45097
45098
45099
45100
45101
45102
45103
45104
45105
45106
45107
45108
45109
45110
45111
45112
45113
45114
45115
45116
45117
45118
45119
45120
45121
45122
45123
45124
45125
45126
45127
45128
45129
45130
45131
45132
45133
45134
45135
45136
45137
45138
45139
45140
45141
45142
45143
45144
45145
45146
45147
45148
45149
45150
45151
45152
45153
45154
45155
45156
45157
45158
45159
45160
45161
45162
45163
45164
45165
45166
45167
45168
45169
45170
45171
45172
45173
45174
45175
45176
45177
45178
45179
45180
45181
45182
45183
45184
45185
45186
45187
45188
45189
45190
45191
45192
45193
45194
45195
45196
45197
45198
45199
45200
45201
45202
45203
45204
45205
45206
45207
45208
45209
45210
45211
45212
45213
45214
45215
45216
45217
45218
45219
45220
45221
45222
45223
45224
45225
45226
45227
45228
45229
45230
45231
45232
45233
45234
45235
45236
45237
45238
45239
45240
45241
45242
45243
45244
45245
45246
45247
45248
45249
45250
45251
45252
45253
45254
45255
45256
45257
45258
45259
45260
45261
45262
45263
45264
45265
45266
45267
45268
45269
45270
45271
45272
45273
45274
45275
45276
45277
45278
45279
45280
45281
45282
45283
45284
45285
45286
45287
45288
45289
45290
45291
45292
45293
45294
45295
45296
45297
45298
45299
45300
45301
45302
45303
45304
45305
45306
45307
45308
45309
45310
45311
45312
45313
45314
45315
45316
45317
45318
45319
45320
45321
45322
45323
45324
45325
45326
45327
45328
45329
45330
45331
45332
45333
45334
45335
45336
45337
45338
45339
45340
45341
45342
45343
45344
45345
45346
45347
45348
45349
45350
45351
45352
45353
45354
45355
45356
45357
45358
45359
45360
45361
45362
45363
45364
45365
45366
45367
45368
45369
45370
45371
45372
45373
45374
45375
45376
45377
45378
45379
45380
45381
45382
45383
45384
45385
45386
45387
45388
45389
45390
45391
45392
45393
45394
45395
45396
45397
45398
45399
45400
45401
45402
45403
45404
45405
45406
45407
45408
45409
45410
45411
45412
45413
45414
45415
45416
45417
45418
45419
45420
45421
45422
45423
45424
45425
45426
45427
45428
45429
45430
45431
45432
45433
45434
45435
45436
45437
45438
45439
45440
45441
45442
45443
45444
45445
45446
45447
45448
45449
45450
45451
45452
45453
45454
45455
45456
45457
45458
45459
45460
45461
45462
45463
45464
45465
45466
45467
45468
45469
45470
45471
45472
45473
45474
45475
45476
45477
45478
45479
45480
45481
45482
45483
45484
45485
45486
45487
45488
45489
45490
45491
45492
45493
45494
45495
45496
45497
45498
45499
45500
45501
45502
45503
45504
45505
45506
45507
45508
45509
45510
45511
45512
45513
45514
45515
45516
45517
45518
45519
45520
45521
45522
45523
45524
45525
45526
45527
45528
45529
45530
45531
45532
45533
45534
45535
45536
45537
45538
45539
45540
45541
45542
45543
45544
45545
45546
45547
45548
45549
45550
45551
45552
45553
45554
45555
45556
45557
45558
45559
45560
45561
45562
45563
45564
45565
45566
45567
45568
45569
45570
45571
45572
45573
45574
45575
45576
45577
45578
45579
45580
45581
45582
45583
45584
45585
45586
45587
45588
45589
45590
45591
45592
45593
45594
45595
45596
45597
45598
45599
45600
45601
45602
45603
45604
45605
45606
45607
45608
45609
45610
45611
45612
45613
45614
45615
45616
45617
45618
45619
45620
45621
45622
45623
45624
45625
45626
45627
45628
45629
45630
45631
45632
45633
45634
45635
45636
45637
45638
45639
45640
45641
45642
45643
45644
45645
45646
45647
45648
45649
45650
45651
45652
45653
45654
45655
45656
45657
45658
45659
45660
45661
45662
45663
45664
45665
45666
45667
45668
45669
45670
45671
45672
45673
45674
45675
45676
45677
45678
45679
45680
45681
45682
45683
45684
45685
45686
45687
45688
45689
45690
45691
45692
45693
45694
45695
45696
45697
45698
45699
45700
45701
45702
45703
45704
45705
45706
45707
45708
45709
45710
45711
45712
45713
45714
45715
45716
45717
45718
45719
45720
45721
45722
45723
45724
45725
45726
45727
45728
45729
45730
45731
45732
45733
45734
45735
45736
45737
45738
45739
45740
45741
45742
45743
45744
45745
45746
45747
45748
45749
45750
45751
45752
45753
45754
45755
45756
45757
45758
45759
45760
45761
45762
45763
45764
45765
45766
45767
45768
45769
45770
45771
45772
45773
45774
45775
45776
45777
45778
45779
45780
45781
45782
45783
45784
45785
45786
45787
45788
45789
45790
45791
45792
45793
45794
45795
45796
45797
45798
45799
45800
45801
45802
45803
45804
45805
45806
45807
45808
45809
45810
45811
45812
45813
45814
45815
45816
45817
45818
45819
45820
45821
45822
45823
45824
45825
45826
45827
45828
45829
45830
45831
45832
45833
45834
45835
45836
45837
45838
45839
45840
45841
45842
45843
45844
45845
45846
45847
45848
45849
45850
45851
45852
45853
45854
45855
45856
45857
45858
45859
45860
45861
45862
45863
45864
45865
45866
45867
45868
45869
45870
45871
45872
45873
45874
45875
45876
45877
45878
45879
45880
45881
45882
45883
45884
45885
45886
45887
45888
45889
45890
45891
45892
45893
45894
45895
45896
45897
45898
45899
45900
45901
45902
45903
45904
45905
45906
45907
45908
45909
45910
45911
45912
45913
45914
45915
45916
45917
45918
45919
45920
45921
45922
45923
45924
45925
45926
45927
45928
45929
45930
45931
45932
45933
45934
45935
45936
45937
45938
45939
45940
45941
45942
45943
45944
45945
45946
45947
45948
45949
45950
45951
45952
45953
45954
45955
45956
45957
45958
45959
45960
45961
45962
45963
45964
45965
45966
45967
45968
45969
45970
45971
45972
45973
45974
45975
45976
45977
45978
45979
45980
45981
45982
45983
45984
45985
45986
45987
45988
45989
45990
45991
45992
45993
45994
45995
45996
45997
45998
45999
46000
46001
46002
46003
46004
46005
46006
46007
46008
46009
46010
46011
46012
46013
46014
46015
46016
46017
46018
46019
46020
46021
46022
46023
46024
46025
46026
46027
46028
46029
46030
46031
46032
46033
46034
46035
46036
46037
46038
46039
46040
46041
46042
46043
46044
46045
46046
46047
46048
46049
46050
46051
46052
46053
46054
46055
46056
46057
46058
46059
46060
46061
46062
46063
46064
46065
46066
46067
46068
46069
46070
46071
46072
46073
46074
46075
46076
46077
46078
46079
46080
46081
46082
46083
46084
46085
46086
46087
46088
46089
46090
46091
46092
46093
46094
46095
46096
46097
46098
46099
46100
46101
46102
46103
46104
46105
46106
46107
46108
46109
46110
46111
46112
46113
46114
46115
46116
46117
46118
46119
46120
46121
46122
46123
46124
46125
46126
46127
46128
46129
46130
46131
46132
46133
46134
46135
46136
46137
46138
46139
46140
46141
46142
46143
46144
46145
46146
46147
46148
46149
46150
46151
46152
46153
46154
46155
46156
46157
46158
46159
46160
46161
46162
46163
46164
46165
46166
46167
46168
46169
46170
46171
46172
46173
46174
46175
46176
46177
46178
46179
46180
46181
46182
46183
46184
46185
46186
46187
46188
46189
46190
46191
46192
46193
46194
46195
46196
46197
46198
46199
46200
46201
46202
46203
46204
46205
46206
46207
46208
46209
46210
46211
46212
46213
46214
46215
46216
46217
46218
46219
46220
46221
46222
46223
46224
46225
46226
46227
46228
46229
46230
46231
46232
46233
46234
46235
46236
46237
46238
46239
46240
46241
46242
46243
46244
46245
46246
46247
46248
46249
46250
46251
46252
46253
46254
46255
46256
46257
46258
46259
46260
46261
46262
46263
46264
46265
46266
46267
46268
46269
46270
46271
46272
46273
46274
46275
46276
46277
46278
46279
46280
46281
46282
46283
46284
46285
46286
46287
46288
46289
46290
46291
46292
46293
46294
46295
46296
46297
46298
46299
46300
46301
46302
46303
46304
46305
46306
46307
46308
46309
46310
46311
46312
46313
46314
46315
46316
46317
46318
46319
46320
46321
46322
46323
46324
46325
46326
46327
46328
46329
46330
46331
46332
46333
46334
46335
46336
46337
46338
46339
46340
46341
46342
46343
46344
46345
46346
46347
46348
46349
46350
46351
46352
46353
46354
46355
46356
46357
46358
46359
46360
46361
46362
46363
46364
46365
46366
46367
46368
46369
46370
46371
46372
46373
46374
46375
46376
46377
46378
46379
46380
46381
46382
46383
46384
46385
46386
46387
46388
46389
46390
46391
46392
46393
46394
46395
46396
46397
46398
46399
46400
46401
46402
46403
46404
46405
46406
46407
46408
46409
46410
46411
46412
46413
46414
46415
46416
46417
46418
46419
46420
46421
46422
46423
46424
46425
46426
46427
46428
46429
46430
46431
46432
46433
46434
46435
46436
46437
46438
46439
46440
46441
46442
46443
46444
46445
46446
46447
46448
46449
46450
46451
46452
46453
46454
46455
46456
46457
46458
46459
46460
46461
46462
46463
46464
46465
46466
46467
46468
46469
46470
46471
46472
46473
46474
46475
46476
46477
46478
46479
46480
46481
46482
46483
46484
46485
46486
46487
46488
46489
46490
46491
46492
46493
46494
46495
46496
46497
46498
46499
46500
46501
46502
46503
46504
46505
46506
46507
46508
46509
46510
46511
46512
46513
46514
46515
46516
46517
46518
46519
46520
46521
46522
46523
46524
46525
46526
46527
46528
46529
46530
46531
46532
46533
46534
46535
46536
46537
46538
46539
46540
46541
46542
46543
46544
46545
46546
46547
46548
46549
46550
46551
46552
46553
46554
46555
46556
46557
46558
46559
46560
46561
46562
46563
46564
46565
46566
46567
46568
46569
46570
46571
46572
46573
46574
46575
46576
46577
46578
46579
46580
46581
46582
46583
46584
46585
46586
46587
46588
46589
46590
46591
46592
46593
46594
46595
46596
46597
46598
46599
46600
46601
46602
46603
46604
46605
46606
46607
46608
46609
46610
46611
46612
46613
46614
46615
46616
46617
46618
46619
46620
46621
46622
46623
46624
46625
46626
46627
46628
46629
46630
46631
46632
46633
46634
46635
46636
46637
46638
46639
46640
46641
46642
46643
46644
46645
46646
46647
46648
46649
46650
46651
46652
46653
46654
46655
46656
46657
46658
46659
46660
46661
46662
46663
46664
46665
46666
46667
46668
46669
46670
46671
46672
46673
46674
46675
46676
46677
46678
46679
46680
46681
46682
46683
46684
46685
46686
46687
46688
46689
46690
46691
46692
46693
46694
46695
46696
46697
46698
46699
46700
46701
46702
46703
46704
46705
46706
46707
46708
46709
46710
46711
46712
46713
46714
46715
46716
46717
46718
46719
46720
46721
46722
46723
46724
46725
46726
46727
46728
46729
46730
46731
46732
46733
46734
46735
46736
46737
46738
46739
46740
46741
46742
46743
46744
46745
46746
46747
46748
46749
46750
46751
46752
46753
46754
46755
46756
46757
46758
46759
46760
46761
46762
46763
46764
46765
46766
46767
46768
46769
46770
46771
46772
46773
46774
46775
46776
46777
46778
46779
46780
46781
46782
46783
46784
46785
46786
46787
46788
46789
46790
46791
46792
46793
46794
46795
46796
46797
46798
46799
46800
46801
46802
46803
46804
46805
46806
46807
46808
46809
46810
46811
46812
46813
46814
46815
46816
46817
46818
46819
46820
46821
46822
46823
46824
46825
46826
46827
46828
46829
46830
46831
46832
46833
46834
46835
46836
46837
46838
46839
46840
46841
46842
46843
46844
46845
46846
46847
46848
46849
46850
46851
46852
46853
46854
46855
46856
46857
46858
46859
46860
46861
46862
46863
46864
46865
46866
46867
46868
46869
46870
46871
46872
46873
46874
46875
46876
46877
46878
46879
46880
46881
46882
46883
46884
46885
46886
46887
46888
46889
46890
46891
46892
46893
46894
46895
46896
46897
46898
46899
46900
46901
46902
46903
46904
46905
46906
46907
46908
46909
46910
46911
46912
46913
46914
46915
46916
46917
46918
46919
46920
46921
46922
46923
46924
46925
46926
46927
46928
46929
46930
46931
46932
46933
46934
46935
46936
46937
46938
46939
46940
46941
46942
46943
46944
46945
46946
46947
46948
46949
46950
46951
46952
46953
46954
46955
46956
46957
46958
46959
46960
46961
46962
46963
46964
46965
46966
46967
46968
46969
46970
46971
46972
46973
46974
46975
46976
46977
46978
46979
46980
46981
46982
46983
46984
46985
46986
46987
46988
46989
46990
46991
46992
46993
46994
46995
46996
46997
46998
46999
47000
47001
47002
47003
47004
47005
47006
47007
47008
47009
47010
47011
47012
47013
47014
47015
47016
47017
47018
47019
47020
47021
47022
47023
47024
47025
47026
47027
47028
47029
47030
47031
47032
47033
47034
47035
47036
47037
47038
47039
47040
47041
47042
47043
47044
47045
47046
47047
47048
47049
47050
47051
47052
47053
47054
47055
47056
47057
47058
47059
47060
47061
47062
47063
47064
47065
47066
47067
47068
47069
47070
47071
47072
47073
47074
47075
47076
47077
47078
47079
47080
47081
47082
47083
47084
47085
47086
47087
47088
47089
47090
47091
47092
47093
47094
47095
47096
47097
47098
47099
47100
47101
47102
47103
47104
47105
47106
47107
47108
47109
47110
47111
47112
47113
47114
47115
47116
47117
47118
47119
47120
47121
47122
47123
47124
47125
47126
47127
47128
47129
47130
47131
47132
47133
47134
47135
47136
47137
47138
47139
47140
47141
47142
47143
47144
47145
47146
47147
47148
47149
47150
47151
47152
47153
47154
47155
47156
47157
47158
47159
47160
47161
47162
47163
47164
47165
47166
47167
47168
47169
47170
47171
47172
47173
47174
47175
47176
47177
47178
47179
47180
47181
47182
47183
47184
47185
47186
47187
47188
47189
47190
47191
47192
47193
47194
47195
47196
47197
47198
47199
47200
47201
47202
47203
47204
47205
47206
47207
47208
47209
47210
47211
47212
47213
47214
47215
47216
47217
47218
47219
47220
47221
47222
47223
47224
47225
47226
47227
47228
47229
47230
47231
47232
47233
47234
47235
47236
47237
47238
47239
47240
47241
47242
47243
47244
47245
47246
47247
47248
47249
47250
47251
47252
47253
47254
47255
47256
47257
47258
47259
47260
47261
47262
47263
47264
47265
47266
47267
47268
47269
47270
47271
47272
47273
47274
47275
47276
47277
47278
47279
47280
47281
47282
47283
47284
47285
47286
47287
47288
47289
47290
47291
47292
47293
47294
47295
47296
47297
47298
47299
47300
47301
47302
47303
47304
47305
47306
47307
47308
47309
47310
47311
47312
47313
47314
47315
47316
47317
47318
47319
47320
47321
47322
47323
47324
47325
47326
47327
47328
47329
47330
47331
47332
47333
47334
47335
47336
47337
47338
47339
47340
47341
47342
47343
47344
47345
47346
47347
47348
47349
47350
47351
47352
47353
47354
47355
47356
47357
47358
47359
47360
47361
47362
47363
47364
47365
47366
47367
47368
47369
47370
47371
47372
47373
47374
47375
47376
47377
47378
47379
47380
47381
47382
47383
47384
47385
47386
47387
47388
47389
47390
47391
47392
47393
47394
47395
47396
47397
47398
47399
47400
47401
47402
47403
47404
47405
47406
47407
47408
47409
47410
47411
47412
47413
47414
47415
47416
47417
47418
47419
47420
47421
47422
47423
47424
47425
47426
47427
47428
47429
47430
47431
47432
47433
47434
47435
47436
47437
47438
47439
47440
47441
47442
47443
47444
47445
47446
47447
47448
47449
47450
47451
47452
47453
47454
47455
47456
47457
47458
47459
47460
47461
47462
47463
47464
47465
47466
47467
47468
47469
47470
47471
47472
47473
47474
47475
47476
47477
47478
47479
47480
47481
47482
47483
47484
47485
47486
47487
47488
47489
47490
47491
47492
47493
47494
47495
47496
47497
47498
47499
47500
47501
47502
47503
47504
47505
47506
47507
47508
47509
47510
47511
47512
47513
47514
47515
47516
47517
47518
47519
47520
47521
47522
47523
47524
47525
47526
47527
47528
47529
47530
47531
47532
47533
47534
47535
47536
47537
47538
47539
47540
47541
47542
47543
47544
47545
47546
47547
47548
47549
47550
47551
47552
47553
47554
47555
47556
47557
47558
47559
47560
47561
47562
47563
47564
47565
47566
47567
47568
47569
47570
47571
47572
47573
47574
47575
47576
47577
47578
47579
47580
47581
47582
47583
47584
47585
47586
47587
47588
47589
47590
47591
47592
47593
47594
47595
47596
47597
47598
47599
47600
47601
47602
47603
47604
47605
47606
47607
47608
47609
47610
47611
47612
47613
47614
47615
47616
47617
47618
47619
47620
47621
47622
47623
47624
47625
47626
47627
47628
47629
47630
47631
47632
47633
47634
47635
47636
47637
47638
47639
47640
47641
47642
47643
47644
47645
47646
47647
47648
47649
47650
47651
47652
47653
47654
47655
47656
47657
47658
47659
47660
47661
47662
47663
47664
47665
47666
47667
47668
47669
47670
47671
47672
47673
47674
47675
47676
47677
47678
47679
47680
47681
47682
47683
47684
47685
47686
47687
47688
47689
47690
47691
47692
47693
47694
47695
47696
47697
47698
47699
47700
47701
47702
47703
47704
47705
47706
47707
47708
47709
47710
47711
47712
47713
47714
47715
47716
47717
47718
47719
47720
47721
47722
47723
47724
47725
47726
47727
47728
47729
47730
47731
47732
47733
47734
47735
47736
47737
47738
47739
47740
47741
47742
47743
47744
47745
47746
47747
47748
47749
47750
47751
47752
47753
47754
47755
47756
47757
47758
47759
47760
47761
47762
47763
47764
47765
47766
47767
47768
47769
47770
47771
47772
47773
47774
47775
47776
47777
47778
47779
47780
47781
47782
47783
47784
47785
47786
47787
47788
47789
47790
47791
47792
47793
47794
47795
47796
47797
47798
47799
47800
47801
47802
47803
47804
47805
47806
47807
47808
47809
47810
47811
47812
47813
47814
47815
47816
47817
47818
47819
47820
47821
47822
47823
47824
47825
47826
47827
47828
47829
47830
47831
47832
47833
47834
47835
47836
47837
47838
47839
47840
47841
47842
47843
47844
47845
47846
47847
47848
47849
47850
47851
47852
47853
47854
47855
47856
47857
47858
47859
47860
47861
47862
47863
47864
47865
47866
47867
47868
47869
47870
47871
47872
47873
47874
47875
47876
47877
47878
47879
47880
47881
47882
47883
47884
47885
47886
47887
47888
47889
47890
47891
47892
47893
47894
47895
47896
47897
47898
47899
47900
47901
47902
47903
47904
47905
47906
47907
47908
47909
47910
47911
47912
47913
47914
47915
47916
47917
47918
47919
47920
47921
47922
47923
47924
47925
47926
47927
47928
47929
47930
47931
47932
47933
47934
47935
47936
47937
47938
47939
47940
47941
47942
47943
47944
47945
47946
47947
47948
47949
47950
47951
47952
47953
47954
47955
47956
47957
47958
47959
47960
47961
47962
47963
47964
47965
47966
47967
47968
47969
47970
47971
47972
47973
47974
47975
47976
47977
47978
47979
47980
47981
47982
47983
47984
47985
47986
47987
47988
47989
47990
47991
47992
47993
47994
47995
47996
47997
47998
47999
48000
48001
48002
48003
48004
48005
48006
48007
48008
48009
48010
48011
48012
48013
48014
48015
48016
48017
48018
48019
48020
48021
48022
48023
48024
48025
48026
48027
48028
48029
48030
48031
48032
48033
48034
48035
48036
48037
48038
48039
48040
48041
48042
48043
48044
48045
48046
48047
48048
48049
48050
48051
48052
48053
48054
48055
48056
48057
48058
48059
48060
48061
48062
48063
48064
48065
48066
48067
48068
48069
48070
48071
48072
48073
48074
48075
48076
48077
48078
48079
48080
48081
48082
48083
48084
48085
48086
48087
48088
48089
48090
48091
48092
48093
48094
48095
48096
48097
48098
48099
48100
48101
48102
48103
48104
48105
48106
48107
48108
48109
48110
48111
48112
48113
48114
48115
48116
48117
48118
48119
48120
48121
48122
48123
48124
48125
48126
48127
48128
48129
48130
48131
48132
48133
48134
48135
48136
48137
48138
48139
48140
48141
48142
48143
48144
48145
48146
48147
48148
48149
48150
48151
48152
48153
48154
48155
48156
48157
48158
48159
48160
48161
48162
48163
48164
48165
48166
48167
48168
48169
48170
48171
48172
48173
48174
48175
48176
48177
48178
48179
48180
48181
48182
48183
48184
48185
48186
48187
48188
48189
48190
48191
48192
48193
48194
48195
48196
48197
48198
48199
48200
48201
48202
48203
48204
48205
48206
48207
48208
48209
48210
48211
48212
48213
48214
48215
48216
48217
48218
48219
48220
48221
48222
48223
48224
48225
48226
48227
48228
48229
48230
48231
48232
48233
48234
48235
48236
48237
48238
48239
48240
48241
48242
48243
48244
48245
48246
48247
48248
48249
48250
48251
48252
48253
48254
48255
48256
48257
48258
48259
48260
48261
48262
48263
48264
48265
48266
48267
48268
48269
48270
48271
48272
48273
48274
48275
48276
48277
48278
48279
48280
48281
48282
48283
48284
48285
48286
48287
48288
48289
48290
48291
48292
48293
48294
48295
48296
48297
48298
48299
48300
48301
48302
48303
48304
48305
48306
48307
48308
48309
48310
48311
48312
48313
48314
48315
48316
48317
48318
48319
48320
48321
48322
48323
48324
48325
48326
48327
48328
48329
48330
48331
48332
48333
48334
48335
48336
48337
48338
48339
48340
48341
48342
48343
48344
48345
48346
48347
48348
48349
48350
48351
48352
48353
48354
48355
48356
48357
48358
48359
48360
48361
48362
48363
48364
48365
48366
48367
48368
48369
48370
48371
48372
48373
48374
48375
48376
48377
48378
48379
48380
48381
48382
48383
48384
48385
48386
48387
48388
48389
48390
48391
48392
48393
48394
48395
48396
48397
48398
48399
48400
48401
48402
48403
48404
48405
48406
48407
48408
48409
48410
48411
48412
48413
48414
48415
48416
48417
48418
48419
48420
48421
48422
48423
48424
48425
48426
48427
48428
48429
48430
48431
48432
48433
48434
48435
48436
48437
48438
48439
48440
48441
48442
48443
48444
48445
48446
48447
48448
48449
48450
48451
48452
48453
48454
48455
48456
48457
48458
48459
48460
48461
48462
48463
48464
48465
48466
48467
48468
48469
48470
48471
48472
48473
48474
48475
48476
48477
48478
48479
48480
48481
48482
48483
48484
48485
48486
48487
48488
48489
48490
48491
48492
48493
48494
48495
48496
48497
48498
48499
48500
48501
48502
48503
48504
48505
48506
48507
48508
48509
48510
48511
48512
48513
48514
48515
48516
48517
48518
48519
48520
48521
48522
48523
48524
48525
48526
48527
48528
48529
48530
48531
48532
48533
48534
48535
48536
48537
48538
48539
48540
48541
48542
48543
48544
48545
48546
48547
48548
48549
48550
48551
48552
48553
48554
48555
48556
48557
48558
48559
48560
48561
48562
48563
48564
48565
48566
48567
48568
48569
48570
48571
48572
48573
48574
48575
48576
48577
48578
48579
48580
48581
48582
48583
48584
48585
48586
48587
48588
48589
48590
48591
48592
48593
48594
48595
48596
48597
48598
48599
48600
48601
48602
48603
48604
48605
48606
48607
48608
48609
48610
48611
48612
48613
48614
48615
48616
48617
48618
48619
48620
48621
48622
48623
48624
48625
48626
48627
48628
48629
48630
48631
48632
48633
48634
48635
48636
48637
48638
48639
48640
48641
48642
48643
48644
48645
48646
48647
48648
48649
48650
48651
48652
48653
48654
48655
48656
48657
48658
48659
48660
48661
48662
48663
48664
48665
48666
48667
48668
48669
48670
48671
48672
48673
48674
48675
48676
48677
48678
48679
48680
48681
48682
48683
48684
48685
48686
48687
48688
48689
48690
48691
48692
48693
48694
48695
48696
48697
48698
48699
48700
48701
48702
48703
48704
48705
48706
48707
48708
48709
48710
48711
48712
48713
48714
48715
48716
48717
48718
48719
48720
48721
48722
48723
48724
48725
48726
48727
48728
48729
48730
48731
48732
48733
48734
48735
48736
48737
48738
48739
48740
48741
48742
48743
48744
48745
48746
48747
48748
48749
48750
48751
48752
48753
48754
48755
48756
48757
48758
48759
48760
48761
48762
48763
48764
48765
48766
48767
48768
48769
48770
48771
48772
48773
48774
48775
48776
48777
48778
48779
48780
48781
48782
48783
48784
48785
48786
48787
48788
48789
48790
48791
48792
48793
48794
48795
48796
48797
48798
48799
48800
48801
48802
48803
48804
48805
48806
48807
48808
48809
48810
48811
48812
48813
48814
48815
48816
48817
48818
48819
48820
48821
48822
48823
48824
48825
48826
48827
48828
48829
48830
48831
48832
48833
48834
48835
48836
48837
48838
48839
48840
48841
48842
48843
48844
48845
48846
48847
48848
48849
48850
48851
48852
48853
48854
48855
48856
48857
48858
48859
48860
48861
48862
48863
48864
48865
48866
48867
48868
48869
48870
48871
48872
48873
48874
48875
48876
48877
48878
48879
48880
48881
48882
48883
48884
48885
48886
48887
48888
48889
48890
48891
48892
48893
48894
48895
48896
48897
48898
48899
48900
48901
48902
48903
48904
48905
48906
48907
48908
48909
48910
48911
48912
48913
48914
48915
48916
48917
48918
48919
48920
48921
48922
48923
48924
48925
48926
48927
48928
48929
48930
48931
48932
48933
48934
48935
48936
48937
48938
48939
48940
48941
48942
48943
48944
48945
48946
48947
48948
48949
48950
48951
48952
48953
48954
48955
48956
48957
48958
48959
48960
48961
48962
48963
48964
48965
48966
48967
48968
48969
48970
48971
48972
48973
48974
48975
48976
48977
48978
48979
48980
48981
48982
48983
48984
48985
48986
48987
48988
48989
48990
48991
48992
48993
48994
48995
48996
48997
48998
48999
49000
49001
49002
49003
49004
49005
49006
49007
49008
49009
49010
49011
49012
49013
49014
49015
49016
49017
49018
49019
49020
49021
49022
49023
49024
49025
49026
49027
49028
49029
49030
49031
49032
49033
49034
49035
49036
49037
49038
49039
49040
49041
49042
49043
49044
49045
49046
49047
49048
49049
49050
49051
49052
49053
49054
49055
49056
49057
49058
49059
49060
49061
49062
49063
49064
49065
49066
49067
49068
49069
49070
49071
49072
49073
49074
49075
49076
49077
49078
49079
49080
49081
49082
49083
49084
49085
49086
49087
49088
49089
49090
49091
49092
49093
49094
49095
49096
49097
49098
49099
49100
49101
49102
49103
49104
49105
49106
49107
49108
49109
49110
49111
49112
49113
49114
49115
49116
49117
49118
49119
49120
49121
49122
49123
49124
49125
49126
49127
49128
49129
49130
49131
49132
49133
49134
49135
49136
49137
49138
49139
49140
49141
49142
49143
49144
49145
49146
49147
49148
49149
49150
49151
49152
49153
49154
49155
49156
49157
49158
49159
49160
49161
49162
49163
49164
49165
49166
49167
49168
49169
49170
49171
49172
49173
49174
49175
49176
49177
49178
49179
49180
49181
49182
49183
49184
49185
49186
49187
49188
49189
49190
49191
49192
49193
49194
49195
49196
49197
49198
49199
49200
49201
49202
49203
49204
49205
49206
49207
49208
49209
49210
49211
49212
49213
49214
49215
49216
49217
49218
49219
49220
49221
49222
49223
49224
49225
49226
49227
49228
49229
49230
49231
49232
49233
49234
49235
49236
49237
49238
49239
49240
49241
49242
49243
49244
49245
49246
49247
49248
49249
49250
49251
49252
49253
49254
49255
49256
49257
49258
49259
49260
49261
49262
49263
49264
49265
49266
49267
49268
49269
49270
49271
49272
49273
49274
49275
49276
49277
49278
49279
49280
49281
49282
49283
49284
49285
49286
49287
49288
49289
49290
49291
49292
49293
49294
49295
49296
49297
49298
49299
49300
49301
49302
49303
49304
49305
49306
49307
49308
49309
49310
49311
49312
49313
49314
49315
49316
49317
49318
49319
49320
49321
49322
49323
49324
49325
49326
49327
49328
49329
49330
49331
49332
49333
49334
49335
49336
49337
49338
49339
49340
49341
49342
49343
49344
49345
49346
49347
49348
49349
49350
49351
49352
49353
49354
49355
49356
49357
49358
49359
49360
49361
49362
49363
49364
49365
49366
49367
49368
49369
49370
49371
49372
49373
49374
49375
49376
49377
49378
49379
49380
49381
49382
49383
49384
49385
49386
49387
49388
49389
49390
49391
49392
49393
49394
49395
49396
49397
49398
49399
49400
49401
49402
49403
49404
49405
49406
49407
49408
49409
49410
49411
49412
49413
49414
49415
49416
49417
49418
49419
49420
49421
49422
49423
49424
49425
49426
49427
49428
49429
49430
49431
49432
49433
49434
49435
49436
49437
49438
49439
49440
49441
49442
49443
49444
49445
49446
49447
49448
49449
49450
49451
49452
49453
49454
49455
49456
49457
49458
49459
49460
49461
49462
49463
49464
49465
49466
49467
49468
49469
49470
49471
49472
49473
49474
49475
49476
49477
49478
49479
49480
49481
49482
49483
49484
49485
49486
49487
49488
49489
49490
49491
49492
49493
49494
49495
49496
49497
49498
49499
49500
49501
49502
49503
49504
49505
49506
49507
49508
49509
49510
49511
49512
49513
49514
49515
49516
49517
49518
49519
49520
49521
49522
49523
49524
49525
49526
49527
49528
49529
49530
49531
49532
49533
49534
49535
49536
49537
49538
49539
49540
49541
49542
49543
49544
49545
49546
49547
49548
49549
49550
49551
49552
49553
49554
49555
49556
49557
49558
49559
49560
49561
49562
49563
49564
49565
49566
49567
49568
49569
49570
49571
49572
49573
49574
49575
49576
49577
49578
49579
49580
49581
49582
49583
49584
49585
49586
49587
49588
49589
49590
49591
49592
49593
49594
49595
49596
49597
49598
49599
49600
49601
49602
49603
49604
49605
49606
49607
49608
49609
49610
49611
49612
49613
49614
49615
49616
49617
49618
49619
49620
49621
49622
49623
49624
49625
49626
49627
49628
49629
49630
49631
49632
49633
49634
49635
49636
49637
49638
49639
49640
49641
49642
49643
49644
49645
49646
49647
49648
49649
49650
49651
49652
49653
49654
49655
49656
49657
49658
49659
49660
49661
49662
49663
49664
49665
49666
49667
49668
49669
49670
49671
49672
49673
49674
49675
49676
49677
49678
49679
49680
49681
49682
49683
49684
49685
49686
49687
49688
49689
49690
49691
49692
49693
49694
49695
49696
49697
49698
49699
49700
49701
49702
49703
49704
49705
49706
49707
49708
49709
49710
49711
49712
49713
49714
49715
49716
49717
49718
49719
49720
49721
49722
49723
49724
49725
49726
49727
49728
49729
49730
49731
49732
49733
49734
49735
49736
49737
49738
49739
49740
49741
49742
49743
49744
49745
49746
49747
49748
49749
49750
49751
49752
49753
49754
49755
49756
49757
49758
49759
49760
49761
49762
49763
49764
49765
49766
49767
49768
49769
49770
49771
49772
49773
49774
49775
49776
49777
49778
49779
49780
49781
49782
49783
49784
49785
49786
49787
49788
49789
49790
49791
49792
49793
49794
49795
49796
49797
49798
49799
49800
49801
49802
49803
49804
49805
49806
49807
49808
49809
49810
49811
49812
49813
49814
49815
49816
49817
49818
49819
49820
49821
49822
49823
49824
49825
49826
49827
49828
49829
49830
49831
49832
49833
49834
49835
49836
49837
49838
49839
49840
49841
49842
49843
49844
49845
49846
49847
49848
49849
49850
49851
49852
49853
49854
49855
49856
49857
49858
49859
49860
49861
49862
49863
49864
49865
49866
49867
49868
49869
49870
49871
49872
49873
49874
49875
49876
49877
49878
49879
49880
49881
49882
49883
49884
49885
49886
49887
49888
49889
49890
49891
49892
49893
49894
49895
49896
49897
49898
49899
49900
49901
49902
49903
49904
49905
49906
49907
49908
49909
49910
49911
49912
49913
49914
49915
49916
49917
49918
49919
49920
49921
49922
49923
49924
49925
49926
49927
49928
49929
49930
49931
49932
49933
49934
49935
49936
49937
49938
49939
49940
49941
49942
49943
49944
49945
49946
49947
49948
49949
49950
49951
49952
49953
49954
49955
49956
49957
49958
49959
49960
49961
49962
49963
49964
49965
49966
49967
49968
49969
49970
49971
49972
49973
49974
49975
49976
49977
49978
49979
49980
49981
49982
49983
49984
49985
49986
49987
49988
49989
49990
49991
49992
49993
49994
49995
49996
49997
49998
49999
50000
50001
50002
50003
50004
50005
50006
50007
50008
50009
50010
50011
50012
50013
50014
50015
50016
50017
50018
50019
50020
50021
50022
50023
50024
50025
50026
50027
50028
50029
50030
50031
50032
50033
50034
50035
50036
50037
50038
50039
50040
50041
50042
50043
50044
50045
50046
50047
50048
50049
50050
50051
50052
50053
50054
50055
50056
50057
50058
50059
50060
50061
50062
50063
50064
50065
50066
50067
50068
50069
50070
50071
50072
50073
50074
50075
50076
50077
50078
50079
50080
50081
50082
50083
50084
50085
50086
50087
50088
50089
50090
50091
50092
50093
50094
50095
50096
50097
50098
50099
50100
50101
50102
50103
50104
50105
50106
50107
50108
50109
50110
50111
50112
50113
50114
50115
50116
50117
50118
50119
50120
50121
50122
50123
50124
50125
50126
50127
50128
50129
50130
50131
50132
50133
50134
50135
50136
50137
50138
50139
50140
50141
50142
50143
50144
50145
50146
50147
50148
50149
50150
50151
50152
50153
50154
50155
50156
50157
50158
50159
50160
50161
50162
50163
50164
50165
50166
50167
50168
50169
50170
50171
50172
50173
50174
50175
50176
50177
50178
50179
50180
50181
50182
50183
50184
50185
50186
50187
50188
50189
50190
50191
50192
50193
50194
50195
50196
50197
50198
50199
50200
50201
50202
50203
50204
50205
50206
50207
50208
50209
50210
50211
50212
50213
50214
50215
50216
50217
50218
50219
50220
50221
50222
50223
50224
50225
50226
50227
50228
50229
50230
50231
50232
50233
50234
50235
50236
50237
50238
50239
50240
50241
50242
50243
50244
50245
50246
50247
50248
50249
50250
50251
50252
50253
50254
50255
50256
50257
50258
50259
50260
50261
50262
50263
50264
50265
50266
50267
50268
50269
50270
50271
50272
50273
50274
50275
50276
50277
50278
50279
50280
50281
50282
50283
50284
50285
50286
50287
50288
50289
50290
50291
50292
50293
50294
50295
50296
50297
50298
50299
50300
50301
50302
50303
50304
50305
50306
50307
50308
50309
50310
50311
50312
50313
50314
50315
50316
50317
50318
50319
50320
50321
50322
50323
50324
50325
50326
50327
50328
50329
50330
50331
50332
50333
50334
50335
50336
50337
50338
50339
50340
50341
50342
50343
50344
50345
50346
50347
50348
50349
50350
50351
50352
50353
50354
50355
50356
50357
50358
50359
50360
50361
50362
50363
50364
50365
50366
50367
50368
50369
50370
50371
50372
50373
50374
50375
50376
50377
diff -ruN linux-2.4.16/Documentation/Configure.help linux-2.4.16-mosix/Documentation/Configure.help
--- linux-2.4.16/Documentation/Configure.help	Thu Nov 22 20:52:44 2001
+++ linux-2.4.16-mosix/Documentation/Configure.help	Sun Dec 23 13:56:53 2001
@@ -73,6 +73,182 @@
 # 1995-2000 by Axel Boldt and many others and are governed by the GNU
 # General Public License.
 
+Mosix extensions
+CONFIG_MOSIX
+  Say Y to support process migration and automatic load-balancing
+  within a cluster.
+
+Support clusters with a complex network topology
+CONFIG_MOSIX_TOPOLOGY
+  This option is intended for configurations where the network
+  "distance" between the nodes is not uniform, so you require
+  node-dependent fine-tuning (see "man tune").
+
+  If all the nodes in your MOSIX cluster are connected via a simple
+  network and use the same networking hardware (which is the more
+  common case), Say N here (and save kernel-time!).
+
+  Say Y here if not all your MOSIX cluster is connected via a simple
+  network or if some nodes use significantly different networking
+  hardware (if you are not sure whether the difference is significant,
+  compile some MOSIX kernel anyway and compare the results of "tune").
+
+Maximum network-topology complexity to support
+CONFIG_MOSIX_MAXTOPOLOGY
+  In a complex network-toplogy, each node can identify a number of
+  subsets of the other nodes, each set having the same networking
+  hardware, the same processor type (perhaps slower or faster, but
+  of the same type) and the same routing path.
+  The maximum network-complexity is defined as the maximum number of
+  those sets over all the nodes in your cluster.  minimizing this
+  number helps saving kernel time and inter-node communication, so
+  please use only the level of complexity that you actually need.
+
+  IMPORTANT NOTE: even if you prepare different kernels for different
+  nodes, all the nodes in your cluster must have the same value
+  configured here.
+
+  MOSIX allows this value to be in the range of 2-10 (higher values
+  will be truncated and lower values imply no complex topology).
+
+MOSIX kernel debugger
+CONFIG_MOSIX_UDB
+  Say Y to use the MOSIX kernel-debugger:
+  the MOSIX kernel-debugger is provided AS IS and can be entered from the
+  console by pressing <ALT-NumLock>.  It is being used for the
+  development of MOSIX and no claims to reliability are made.
+
+MOSIX diagnostics
+CONFIG_MOSIX_DIAG
+  Say Y to include MOSIX consistency checks.
+  While this adds code to the kernel, it may prevent unexpected
+  occurences when running new versions of MOSIX.
+
+MOSIX debug-code
+CONFIG_MOSIX_DEBUG
+  Say Y to include extensive debugging-messages option in MOSIX
+  (used for MOSIX kernel-development).
+
+Process arrival messages
+CONFIG_MOSIX_WEEEEEEEEE
+  If you say Y to this option, the console will display messages whenever
+  a process arrives: Weeeeeeeee..... for remote (guest) processes and
+  Wooooooooo..... for local processes returning home.
+
+Loopback process-migration testing
+CONFIG_MOSIX_CHEAT_MIGSELF
+  Say Y to allow loopback process "migration" from a node into itself
+  (useful only for MOSIX kernel-debugging).
+
+Level of process-identity disclosure
+CONFIG_MOSIX_DISCLOSURE
+  Determine how much information about processes is disclosed by default
+  when they run as guests on remote nodes:
+  0 = no information
+  1 = only PID (and TGID if different)
+  2 = PID(/TGID), UID, GID
+  3 = PID(/TGID), UID, GID, PGRP, SESSION, COMMAND
+  Processes may modify this default by writing to /proc/self/disclosure.
+
+Prevent the "-mosix" extension on kernel name
+CONFIG_MOSIX_EXTMOSIX
+  Say Y if you want the kernel and module directory to have the "-mosix"
+  extension (to distinguish it from coexistant non-MOSIX kernels of the
+  same kernel version number).
+
+Stricter security on MOSIX ports
+CONFIG_MOSIX_SECUREPORTS
+  The internal kernel TCP/UDP ports used by MOSIX may not be accessed
+  by normal users (and even the Super-User has no real reason to access
+  them).  The question arises whether to allow user-connections to those
+  ports on other (internet) nodes, outside the cluster.
+  If routing schemes allow a MOSIX node to also be accessed from within
+  the MOSIX cluster using an IP address that is not listed in the MOSIX
+  configuration, you must say Y (or risk that a hacking user will mess
+  with the MOSIX internals by connecting to that IP address and one of
+  the MOSIX port numbers).  However, these port numbers, though not
+  listed in "/etc/services", may be in use for other purposes somewhere
+  else on the internet - and this option would prevent accessing them,
+  so if your users require such access, say N and make sure that all the
+  IP addresses by which your nodes can be reached are listed as aliases
+  in the MOSIX configuration.
+
+Direct File-System Access for MOSIX
+CONFIG_MOSIX_DFSA
+  Direct File System Access:
+  DFSA is now ready for Beta-testing.  It can currently only be used
+  by MFS (MOSIX File-System).  You may be interested in this option
+  if you either like experimenting and experiencing the power of DFSA
+  with MFS, or if you are interested in either developing a new
+  file-system, or adapting an existing one to DFSA.
+
+  For the lay user, all you need is to also configure MFS, then run
+  the following commands on each node:
+      mkdir /mfs
+      mount -t mfs cluster /mfs -odfsa=1
+
+  If you are more serious about it, please read "Documentation/DFSA"
+  or run "man dfsa".
+
+MOSIX File-System
+CONFIG_MOSIX_FS
+  The MOSIX File-System (MFS) is now ready for Beta-testing.
+  Along with DFSA, it forms the basis for the next generation
+  of MOSIX, expanding the power of MOSIX beyond CPU-bound tasks
+  into I/O tasks as well.
+
+  On its own, MFS allows processes to access most files (more accurately,
+  all regular files, directories and symbolic-links, but excluding the
+  "/proc" file-system and MFS itself) on all the nodes in the cluster.
+
+  MFS assumes that all users/group-ID's throughout the cluster are
+  equivalent: if this is not the case, you cannot use MFS, so you must
+  say 'N' here, unless you have a sub-cluster where the user/group-ID's
+  are equivalent, in which case you may still choose to configure MFS
+  only in that sub-cluster.
+
+  To use MFS, all you need is to type:
+        mount -t mfs cluster /mfs
+  (the word "cluster" can be changed to suit your taste and the "/mfs"
+  mount-point is only a suggestion, to be used in this discussion).
+  For a permanent solution, enter the following line in "/etc/fstab":
+        cluster    /mfs    mfs    defaults    0 0
+
+  You can now access each node via "/mfs/{node_number}", you may also
+  access the following useful directories:
+
+  /mfs/here     - The current node where your process runs
+  /mfs/home     - Your home node
+  /mfs/magic    - The current node when used by the "creat" system call
+                  (or an "open" with the "O_CREAT" option) - otherwise,
+                  the last node on which an MFS magical file was
+                  successfully created (this is very useful for creating
+                  temporary-files, then immediately unlinking them)
+  /mfs/lastexec - The node on which the process last issued a successful
+                  "execve" system-call.
+  /mfs/selected - The node you selected by either your process itself or
+                  one of its ancesstors (before forking this process),
+                  writing a number into "/proc/self/selected".
+
+  MFS is currently the only file-system that can be used with DFSA.
+  Detailed technical information is available in
+  "Documentation/filesystems/mfs.txt".
+
+Poll/Select exceptions on pipes
+CONFIG_MOSIX_PIPE_EXCEPTIONS
+  This feature is not required for MOSIX-proper, but some user-mode
+  programs like it.  It allows a program to be notified when someone
+  is wishing to read from a pipe.  If you say Y, you may then use:
+  ioctl(pipefd, TCSBRK, arg) to set or clear exception conditions.
+  If (arg & 1), an exception is generated when someone is trying to
+  read the pipe.  If (arg & 2), an exception is generated when the
+  pipe has no more readers.  The default is that pipes never generate
+  any exceptions.  An exception can be returned by the "select" system
+  call and will also cause POLLPRI to be included in the return-value
+  of the "poll" system-call.  You can also get an under-estimate of the
+  number of bytes that processes curretly try to read from the pipe using
+  ioctl(pipefd, TIOCGWINSZ, 0).
+
 Prompt for development and/or incomplete code/drivers
 CONFIG_EXPERIMENTAL
   Some of the various things that Linux supports (such as network
diff -ruN linux-2.4.16/Documentation/DFSA linux-2.4.16-mosix/Documentation/DFSA
--- linux-2.4.16/Documentation/DFSA	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/Documentation/DFSA	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,215 @@
+DFSA - Direct File-System Access:
+
+The first generation of MOSIX has brought about great performance
+improvements in CPU jobs - "number crunchers", but cannot help in the
+case of I/O tasks, which need to communicate with their home-node as
+often as every system-call, and are therefore better off remaining there.
+
+The second generation of MOSIX, includes DFSA, whereby the more common
+system-calls can be (under certain conditions) performed directly on the
+caller's current node, thus increasing the benefit and probability that
+I/O-oriented (or mixed I/O and CPU) tasks will also migrate.
+
+DFSA operates over suitable, cluster-wide shared file-systems that fulfill
+certain requirements.  The only file-system to currently fulfill those
+requirements is the MOSIX File-System (MFS).
+
+To use DFSA without violating access permissions, the permission-scheme
+(user and group ID's) must be identical, or at least compatible throughout
+the MOSIX cluster.
+
+Each partition that is to operate in DFSA mode must be assigned a unique
+DFSA index, currently in the range of 1-8, that must be identical on all
+the nodes in the MOSIX cluster.
+
+To request a particular partition to operate in DFSA mode, mount (or remount)
+it with the "-odfsa={n}" argument  (1 <= n <= 8).
+
+You should do the same on all the nodes in the cluster either at about the
+same time or before MOSIX is configured: failure to assign all DFSA
+mount-points on some of the nodes is not fatal, but may result in serious
+performance degradation, while simultaneous use of the same index for
+different partitions, is likely to cause various faults.
+
+To disassociate a partition from DFSA, run:
+
+mount -o remount {mount-point} -odfsa=0.
+
+You may also designate symbolic-links to operate in DFSA mode: this is
+equivalent to a declaration that the given links are identical on all
+nodes and point to the same partition.  It saves remote processes who use
+those link(s) the need to contact their home node every use in order to
+read those links.  To declare a symbolic-link as identical, type:
+
+echo {symbolic-link} > /proc/mosix/admin/dfsalinks,
+
+where the symbolic-link must be an absolute-pathname, pointing at an existing
+file (or directory or another symbolic-link) on an already-mounted partition
+that is capable of DFSA (but it is not required to be already associated with
+a DFSA index).
+
+To remove a symbolic-link declaration, type:
+
+echo -{symbolic-link} > /proc/mosix/admin/dfsalinks:
+
+If you intend to re-define a declared symbolic link, you must first re-
+move its declaration, then re-declare after the change is made.
+
+To see a list of all currently-declared symbolic links, type:
+
+cat /proc/mosix/admin/dfsalinks.
+
+To cancel all symbolic-link declarations, type:
+
+echo - > /proc/mosix/admin/dfsalinks.
+
+The number of declared symbolic-links is currently limited to 8 and their
+path-name length is limited to 128 characters.
+
+requirements from a complying file-system:
+------------------------------------------
+1) all operations on the file system must be synchronous, in the sense that
+   there is [at most] only one buffer/inode cache throughout the cluster.
+   (on client-server file-systems, this usually means that the whole cache
+   is maintained on the server - however, a sophisticated server may "lend"
+   the cache of particular inodes to particular clients at any given time.
+   on shared-hardware file-systems, this probably requires either a hardware
+   invalidation signal or a new version to be marked on each inode after each
+   modification).
+
+2) The time-stamps on files and between files of the same file-system must be
+   consistent and advancing (unless the clock is deliberately set backwards),
+   regardless from which node modifications are made.
+
+3) The file-system must populate the following two new super-block methods:
+   a) "identify":
+       Given a "dentry", encapsulate identifying information about it into
+       a finite, rather-small structure, in a way that is sufficient to be
+       able to re-establish that open file/directory on another node.
+   b) "reconstruct":
+       Given only a mount-structure ("vfsmnt") and information that was
+       provided by "identify", produce a live new "dentry".
+
+       Also, while not enforced by DFSA itself, in order for the getcwd
+       system-call to work correctly on a shared file-system, regardless
+       of where the call is made from, it is also highly recommended to
+       populate the following new inode-method:
+   c) "checkpath":
+       Given a "dentry", ensure that following its path via the "dcache"
+       will truly reflect its current position on the shared file-system -
+       and if not, make the necessary fixes by adjusting the "dentry" around
+       the directory cache: The "dcache" of shared file-systems cannot be
+       trusted, since processes running on other nodes can move (or remove)
+       a directory at any time.
+
+4) The file-system must ensure that files/directories are not cleared when
+   unlinked, for as long as any process in the cluster still holds them open.
+   There are several possible techniques to achieve this, but given the
+   distributed nature of the file-system, some form of garbage-collection
+   is probably also called upon.
+
+Which system-calls are supported:
+---------------------------------
+The following system-calls are normally supported and usually run directly
+by the process, while any other calls, or hard cases still need to go via
+the home-node:
+
+	read, readv, write, writev, readahead
+	lseek, llseek
+	open, creat, close
+	dup, dup2, fcntl/fcntl64 (F_DUPFD,F_GETFL,F_SETFL)
+	getdents, getdents64, old_readdir
+	fsync, fdatasync
+	chdir, fchdir, getcwd
+	stat, stat64, newstat, lstat, lstat64, newlstat,
+	fstat, fstat64, newfstat
+	access
+	truncate, truncate64, ftruncate, ftruncate64
+	chmod, chown, chown16, lchown, lchown16, fchmod, fchown, fchown16
+	utime, utimes
+	symlink, readlink
+	mkdir, rmdir
+	link, unlink, rename
+
+Examples of hard cases:
+* if not all nodes have the same mounted DFSA partitions, or they do -
+  but with different mount-flags.
+* if the calling process is being traced.
+* if the process has a non-standard root-directory.
+* If the calling process has an emulating personality that causes it
+  to use an alternate root (but this is currently not relevant for the
+  i386 architecture).
+* if the calling process shares either its files or current directory
+  as a result of the "clone" system-call.
+* operations occuring during re-configuration of DFSA on either the
+  home-node or the node where the process runs.
+* operations involving special files (eg. other than regular, directories
+  or symbolic-links)
+* operations on files that were commonly opened and still shared with other
+  related processes.
+* dup2, where the second file-descriptor is an already open non-DFSA file
+  (that requires closing).
+* chdir/fchdir when the previous directory is non-DFSA.
+* link/rename that fail due to an attempt to cross-device link.
+* open/dup/dup2/fcntl(F_DUPFD) that requires an allowable-increase in
+  the maximal file-descriptor index (initially 1023!).
+* When the home-node has pending requests for the process (such as
+  signals, requests for "ps" information, request to migrate or consider
+  migration, etc.)
+* Use of path-names that leave the DFSA partition, as demonstrated by
+  the following example:
+	"/mfs" is a DFSA file-system
+	/mfstmp is a symbolic link to /mfs/2/tmp, and is declared in
+		/proc/mosix/admin/dfsalinks.
+	/mtmp is a symbolic link to /mfstmp, and is declared in
+		/proc/mosix/admin/dfsalinks.
+	/mfs2 is a symbolic link to /mfs/2, but is not declared.
+	on node #2, /fie is a symbolic link to "/tmp/foo".
+  then the following are accepted as simple cases (and identical):
+	/mfs/2/tmp/foo
+	//mfs//2/tmp/foo
+	/./mfs/2/tmp/foo
+	/mfstmp/foo
+	/mtmp/foo
+	/mfs/2/fie
+	mfs/2/tmp/foo  (when in the root directory)
+	
+  but not the following:
+	/tmp/../mfs/tmp/foo
+		(the kernel is not allowed to assume that each node has an
+		 accessible "/tmp" directory!)
+	/mfs/2/../../mfs/2/tmp/foo
+		(the secon ".." steps out of the "/mfs" DFSA partition)
+        /mfs2/tmp/foo
+		(/mfs2 is not declared, hence no assurance was provided
+		that it is identical on all nodes)
+	mfstmp/foo (or mfstmp/foo) when in the root directory
+		(just a difficult case to recognize)
+
+* when the home-node DEPUTY has pending requests for the process (such as
+  signals, requests for "ps" information, request to migrate or consider
+  migration, etc.)
+
+Deviations from normal Linux/Unix/Posix behavior:
+--------------------------------------------------
+It was impossible to maintain 100% compatibility on DFSA file-systems,
+but the deviations are kept to the very minimum:
+
+* A process that received a signal may continue running a few DFSA system-calls
+  before it actually receives and handles the signal.
+  (in contrast, any POSIX process that receives a signal may possibly
+   complete the next system-call, but cannot issue any new ones beyond that).
+
+* Simultaneous mapping and I/O on the same DFSA file creates unpredictable
+  results as follows:
+  1) execution (and library and all other file-mappings) is not always
+     protected against other process(es) modifying the file: either the
+     writing-process or the executing/mapping process may fail to receive the
+     "ETXTBSY" error.
+  2) The "MS_INVALIDATE" flag of "msync" may fail to ensure that previous
+     "write"(s) to a mapped DFSA file are discarded.
+  3) when a process modifies memory that is mapped as "MAP_SHARED" to a DFSA
+     file, but has not yet written it back (using "msync", "munmap", "exec"
+     or "exit"), it is possible that another process that reads that file as
+     it migrates will first see some of the changes but later (as opposed to
+     normal behavior), see the old values (or some of them) again.
diff -ruN linux-2.4.16/Documentation/filesystems/00-INDEX linux-2.4.16-mosix/Documentation/filesystems/00-INDEX
--- linux-2.4.16/Documentation/filesystems/00-INDEX	Wed Jun 20 21:10:27 2001
+++ linux-2.4.16-mosix/Documentation/filesystems/00-INDEX	Sun Dec 23 13:56:53 2001
@@ -22,6 +22,8 @@
 	- info and mount options for the OS/2 HPFS.
 isofs.txt
 	- info and mount options for the ISO 9660 (CDROM) filesystem.
+mfs.txt
+	- info on the Mosix filesystem.
 ncpfs.txt
 	- info on Novell Netware(tm) filesystem using NCP protocol.
 ntfs.txt
diff -ruN linux-2.4.16/Documentation/filesystems/mfs.txt linux-2.4.16-mosix/Documentation/filesystems/mfs.txt
--- linux-2.4.16/Documentation/filesystems/mfs.txt	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/Documentation/filesystems/mfs.txt	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,197 @@
+MFS interface, capabilities and limitations:
+============================================
+To use MFS, configure the "CONFIG_MOSIX_FS" option into the kernel
+then mount it, using:
+	mount -t mfs {any_name} {mount_point} [-o dfsa={n}]
+This gives access to nearly all files throughout the MOSIX cluster,
+with the root of each node available via {mount_point}/{node_number}/.
+Also available as sub-directories are:
+
+/{mount_point}/here/
+	The current node where your process runs
+/{mount_point}/home/
+	Your home node
+/{mount_point}/magic/
+	The current node when used by the "creat" system call (or an "open"
+	with the "O_CREAT" option) - otherwise, the last node on which an MFS
+	magical file was successfully created (this is very useful for creating
+	temporary-files, then immediately unlinking them)
+/{mount_point}/lastexec/
+	The node on which the process last issued a successful "execve"
+	system-call.
+/{mount_point}/selected/
+	The node you selected by either your process itself or as inherited
+	by one of its ancesstors (before forking this process), writing a
+	number into "/proc/self/selected".
+
+You may also wish to have MFS be automatically by entering the following
+line into "/etc/fstab":
+        cluster    /{mount_point}    mfs    defaults    0 0
+or for DFSA use:
+        cluster    /{mount_point}    mfs    dfsa=1      0 0
+
+Once CONFIG_MOSIX_FS is configured in the kernel and MOSIX has been configured
+(See "man setpe"), other nodes can access the node's file-system even without
+the above mount.  To disallow MFS access to this node, write a "1" to
+"/proc/mosix/admin/nomfs" (to re-allow, write a "0").
+
+MFS was designed to also run under DFSA, allowing direct access by processes,
+from wherever they run at each moment, to the node holding the files/directories
+that they require, bypassing their "DEPUTY" in most cases.  This makes it even
+more efficient if the required files are on the same node as the process, in
+which case the process can serve itself without resorting to the network.
+To use MFS with DFSA, make sure that the mount-point is the same on all nodes,
+then mount (or remount) MFS with the "-odfsa={n} flag, where {n} is in the
+range of 1-8 and identical on all nodes in the cluster:
+
+Users and Groups:
+-----------------
+MFS assumes that all user and group ID's throughout the cluster have
+equivalent access rights.  You should not use MFS on clusters with
+heterogenous user/group scheme.  While allowing the Super-User to access
+all files throughout the cluster, this is implied anyway by the security
+requirements of MOSIX (See "man mosix").  If most of your cluster uses the
+same scheme, but some nodes do not, you may either configure MFS only in the
+kernel of those nodes that use the same scheme, or write a "1" to
+"/proc/mosix/admin/nomfs" during node-startup and before MOSIX is configured
+on the other nodes, as well as not mounting MFS there.
+
+Temporary files:
+----------------
+the "here", "magic", "lastexec" and "selected" directories are designed
+to provide easier access to temporary files, so that programs are helped
+to create their temporary files where they run.  With many programs, you
+can make use these directories without recompiling, by using the "TMPDIR"
+environment variable.
+
+The most conservative, but safest thing to do, which can be applied to all
+programs, is to:
+	setenv TMPDIR "/{mount-point}/selected/tmp
+In this case, your shell (or the calling script) should run
+	echo `cat /proc/self/where` > /proc/self/selected
+before calling the program.
+(note that "cp" cannot be used here, since only the shell may modify its
+own "selected", but "echo" works because it is built into most shells)
+
+The next, little less conservative approach, but still safe for programs
+that do not rely on passing file-names to their children as arguments of
+"exec", is to:
+	setenv TMPDIR "/{mount-point}/lastexec/tmp
+       (or "env TMPDIR=/{mount-point}/lastexec/tmp program [args]")
+
+The next, still less conservative, but more powerful approach, can be used
+for programs that create temporary-files, which either create only one MFS file,
+or unlink temporary-files as soon as they are created.  For such programs:
+	setenv TMPDIR "/{mount-point}/magic/tmp
+       (or "env TMPDIR=/{mount-point}/magic/tmp program [args]")
+
+Finally, programs that are locked on any particular node, may use:
+	setenv TMPDIR "/{mount-point}/here/tmp
+       (or "env TMPDIR=/{mount-point}/here/tmp program [args]")
+Please note that this approach is not 100% safe, because even while locked,
+migration back to the home-node may still occur if/when the node where the
+program runs is being shut-down for reboot.
+
+Of course, when designing a new program to run with MFS,
+all the above methods can be freely mixed.
+
+Interpretation of symbolic-links:
+---------------------------------
+The following non-trivial interpretation of symbolic links found within MFS,
+was designed to provide uniformity of access between links created locally
+and via MFS, especially by scripts and "makefile"s that use `pwd` as part
+of symbolic links:
+
+The rule is that when a symbolic link begins with a '/', it refers to the
+root of the file-system's node - not the home-node!
+Similarly, a "/.." (or any combination with ".." that calls for the parent of
+the file-system's root) refers to the file-system's root again, rather than to
+the MFS mount-point.
+
+One of the implications is that a symbolic link is never allowed to cross nodes.
+
+Excluded files:
+---------------
+The following may not be accessed via the MFS file-system:
+* nodes that excluded themselves.
+* special files - other than regular-files, directories or symbolic-links.
+* the "proc" file-system.
+* any subdirectories of the recursive MFS mount-point with the exception
+  of symblic links starting in '/', pointing to the same node, and doing
+  so only once.
+
+Examples:
+assuming that there are 3 nodes in the cluster and on node #2:
+1) MFS is mounted on "/mfs"
+2) "/usr/src/linux_here" is a symbolic link to "/mfs/2/usr/src/linux"
+3) "/usr/src/local_linux" is a symbolic link to "../../mfs/2/usr/src/linux"
+4) "/usr/src/other_linux" is a symbolic link to "/mfs/3/usr/src/linux"
+5) "/usr/src/mfs_linux" is a symbolic link to "/mfs/2/mfs/2/usr/src/linux"
+
+then the following are accessible:
+
+/mfs/2/usr/src/linux
+/mfs/2/etc/hosts
+/mfs/2/mfs
+/mfs/2/usr/src/linux_here
+/usr/src/local_linux
+/usr/src/other_linux
+
+but the following are not (and will result in "Permission denied" error):
+
+/mfs/2/dev/tty6			(special character device)
+/mfs/2/proc/mosix		("proc" file system)
+/mfs/2/mfs/2/tmp	(to prevent infinite recursion and confusing the shell)
+/mfs/2/usr/src/local_linux	(symbolic-link does not start with '/')
+/mfs/2/usr/src/other_linux	(symbolic-link pointing to another node)
+/usr/src/mfs_linux		(symbolic-link pointing to local node twice)
+
+(please note, however, that symbolic-links are still readable
+with "lstat" and "readlink" regardless of their contents)
+
+Garbage Collection:
+-------------------
+When either a client node or part of the network crashes, a garbage-collection
+mechanism will eventually clean up the references to the held-files or
+directories on the serving node(s).  It may take, however, up to an hour
+until the server(s) finally give up the connection, during which the serving
+node(s) will not be able to un-mount the particular file-system(s) involved.
+
+The Super-User may still force an un-mount in 3 ways:
+1) disable MFS by writing a "1" to "/proc/mosix/admin/nomfs".
+2) un-configure MOSIX by running "setpe -off".
+3) write the name of a file or directory to be released to
+   "/proc/mosix/admin/mfskill".  If the given name is of a directory, all
+   files and sub-directories under it will be released as well (with the
+   possible exception of files being actively accessed at that very moment),
+   thus writing '/' releases everything, but is very distruptive to users,
+   so it is better to write the name of the mount-point of the file-system
+   that you wish to un-mount.
+
+Functionality limitations:
+--------------------------
+* Mandatory file-locking is not supported.
+* the F_NOTIFY fcntl option is not supported.
+* Voluntary file-locking only operates among processes of the same home-node
+  (and since it will not be supported by DFSA, it always requires DEPUTY-
+  assitance on the home-node).
+* file-ioctl is currently only supported for the EXT2 file-system.
+* mmap of MFS files only supports private mappings (MAP_PRIVATE).
+  Open files must have read-permission.
+  The actual implementation of "mmap" and "execve" does not use demand-paging,
+  but rather reads in the relevant text/data from the file before proceeding.
+* Every effort was attempted to prevent giving the same inode-number to
+  different files, and in most cases this is the case, but it is not totally
+  possible with only 32 bits inode-numbers and the large potential number of
+  files on numerous nodes and devices within each node.  Priority is given so
+  that files on any particular node do not get the same inode-numbers, but even
+  this cannot be absolutely guaranteed when some of the files are NFS (or other
+  file-systems that use the full 32-bit space for inode numbers).  To identify
+  an inode most accurately, one should use the raw "stat" ("fstat"/"lstat")
+  system-call as provided by the kernel before being filtered by the
+  compatibility library, providing the node-number in the "__unused1" field,
+  the device-number in the "__unused2" field and the local inode-numer in the
+  "__unused3" field (these fields are currently always 0 for non-MFS).
+  In the "stat64"/"lstat64"/"fstat64" system-calls, the node number can be
+  found in "__pad0[2-3]", the device-number in "__pad0[4-5]" and the local
+  inode number in "__pad0[6-9]".
diff -ruN linux-2.4.16/Makefile linux-2.4.16-mosix/Makefile
--- linux-2.4.16/Makefile	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/Makefile	Sun Dec 23 13:56:53 2001
@@ -54,6 +54,11 @@
 
 ifeq (.config,$(wildcard .config))
 include .config
+
+ifdef CONFIG_MOSIX_EXTMOSIX
+EXTRAVERSION := $(EXTRAVERSION)-mosix
+endif
+
 ifeq (.depend,$(wildcard .depend))
 include .depend
 do-it-all:	Version vmlinux
@@ -88,8 +93,13 @@
 
 CPPFLAGS := -D__KERNEL__ -I$(HPATH)
 
+ifdef CONFIG_MOSIX_UDB
+CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
+	  -fno-omit-frame-pointer -fno-strict-aliasing -fno-common
+else
 CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
 	  -fomit-frame-pointer -fno-strict-aliasing -fno-common
+endif
 AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS)
 
 #
@@ -122,7 +132,16 @@
 NETWORKS	=net/network.o
 
 LIBS		=$(TOPDIR)/lib/lib.a
+ifdef CONFIG_MOSIX
+CORE_FILES	+= $(TOPDIR)/mos/mos.o
+SUBDIRS		=mos kernel drivers mm fs net ipc lib
+else
 SUBDIRS		=kernel drivers mm fs net ipc lib
+endif
+ifdef CONFIG_MOSIX_UDB
+CORE_FILES	+= $(TOPDIR)/udb/debugger.o
+SUBDIRS		+= udb
+endif
 
 DRIVERS-n :=
 DRIVERS-y :=
@@ -208,6 +227,11 @@
 	net/khttpd/make_times_h \
 	net/khttpd/times.h \
 	submenu*
+
+CLEAN_FILES += arch/i386/kernel/mosasm.H arch/i386/kernel/offset \
+	mos/auto_syscalls.c mos/mkdefcalls mos/alternate.c \
+	udb/symbols.c udb/symtab vmlinux.symtab
+
 # directories removed with 'make clean'
 CLEAN_DIRS = \
 	modules
@@ -266,6 +290,20 @@
 		$(LIBS) \
 		--end-group \
 		-o vmlinux
+ifdef CONFIG_MOSIX_UDB
+	$(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > vmlinux.symtab
+	udb/symtab < vmlinux.symtab > udb/symbols.c
+	$(CC) -c $(CFLAGS) udb/symbols.c -o udb/symbols.o
+	$(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \
+		--start-group \
+		$(CORE_FILES) \
+		$(DRIVERS) \
+		$(NETWORKS) \
+		$(LIBS) \
+		--end-group \
+		udb/symbols.o \
+		-o vmlinux
+endif
 	$(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
 
 symlinks:
diff -ruN linux-2.4.16/arch/i386/Makefile linux-2.4.16-mosix/arch/i386/Makefile
--- linux-2.4.16/arch/i386/Makefile	Thu Apr 12 22:20:31 2001
+++ linux-2.4.16-mosix/arch/i386/Makefile	Sun Dec 23 13:56:53 2001
@@ -138,6 +138,9 @@
 install: vmlinux
 	@$(MAKEBOOT) BOOTIMAGE=bzImage install
 
+install1:
+	@$(MAKEBOOT) BOOTIMAGE=bzImage install
+
 archclean:
 	@$(MAKEBOOT) clean
 
diff -ruN linux-2.4.16/arch/i386/config.in linux-2.4.16-mosix/arch/i386/config.in
--- linux-2.4.16/arch/i386/config.in	Mon Nov 12 21:58:08 2001
+++ linux-2.4.16-mosix/arch/i386/config.in	Sun Dec 23 13:56:53 2001
@@ -11,6 +11,31 @@
 define_bool CONFIG_UID16 y
 
 mainmenu_option next_comment
+comment 'MOSIX'
+bool 'MOSIX process migration support' CONFIG_MOSIX
+if [ "$CONFIG_MOSIX" = "y" ]; then
+	bool 'Support clusters with a complex network topology' CONFIG_MOSIX_TOPOLOGY
+	if [ "$CONFIG_MOSIX_TOPOLOGY" = "y" ]; then
+	    int  'Maximum network-topology complexity to support (2-10)' CONFIG_MOSIX_MAXTOPOLOGY 4
+	fi
+
+	bool 'MOSIX Kernel Debugger' CONFIG_MOSIX_UDB
+	if [ "$CONFIG_MOSIX_UDB" = "y" ]; then
+		bool 'MOSIX Kernel Debugging Code' CONFIG_MOSIX_DEBUG
+		bool 'Allow migration to self (for easyier testing)' CONFIG_MOSIX_CHEAT_MIGSELF
+		bool 'Process-arrival messages' CONFIG_MOSIX_WEEEEEEEEE
+	fi
+	bool 'MOSIX Kernel Diagnostics' CONFIG_MOSIX_DIAG
+	bool 'Stricter security on MOSIX ports' CONFIG_MOSIX_SECUREPORTS
+	int  'Level of process-identity disclosure (0-3)' CONFIG_MOSIX_DISCLOSURE 1
+	bool 'Create the kernel with a "-mosix" extension' CONFIG_MOSIX_EXTMOSIX
+	bool 'Direct File-System Access' CONFIG_MOSIX_DFSA
+	bool 'MOSIX File-System' CONFIG_MOSIX_FS
+	bool 'Poll/Select exceptions on pipes' CONFIG_MOSIX_PIPE_EXCEPTIONS
+fi
+endmenu
+
+mainmenu_option next_comment
 comment 'Code maturity level options'
 bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL
 endmenu
diff -ruN linux-2.4.16/arch/i386/defconfig linux-2.4.16-mosix/arch/i386/defconfig
--- linux-2.4.16/arch/i386/defconfig	Mon Nov 12 21:59:03 2001
+++ linux-2.4.16-mosix/arch/i386/defconfig	Sun Dec 23 13:56:53 2001
@@ -1,6 +1,26 @@
 #
 # Automatically generated make config: don't edit
 #
+
+#
+# MOSIX options
+#
+
+CONFIG_MOSIX=y
+# CONFIG_MOSIX_TOPOLOGY is not set
+CONFIG_MOSIX_MAXTOPOLOGY=4
+# CONFIG_MOSIX_UDB is not set
+# CONFIG_MOSIX_CHEAT_MIGSELF is not set
+# CONFIG_MOSIX_DEBUG is not set
+# CONFIG_MOSIX_WEEEEEEEEE is not set
+CONFIG_MOSIX_DISCLOSURE=1
+# CONFIG_MOSIX_EXTMOSIX is not set
+CONFIG_MOSIX_DIAG=y
+CONFIG_MOSIX_SECUREPORTS=y
+# CONFIG_MOSIX_DFSA is not set
+# CONFIG_MOSIX_FS is not set
+# CONFIG_MOSIX_PIPE_EXCEPTIONS is not set
+
 CONFIG_X86=y
 CONFIG_ISA=y
 # CONFIG_SBUS is not set
diff -ruN linux-2.4.16/arch/i386/kernel/Makefile linux-2.4.16-mosix/arch/i386/kernel/Makefile
--- linux-2.4.16/arch/i386/kernel/Makefile	Sat Nov 10 00:21:21 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/Makefile	Sun Dec 23 13:56:53 2001
@@ -42,3 +42,14 @@
 obj-$(CONFIG_X86_VISWS_APIC)	+= visws_apic.o
 
 include $(TOPDIR)/Rules.make
+
+ifdef CONFIG_MOSIX
+entry.o: ./mosasm.H
+
+offset: offset.c $(TOPDIR)/include/linux/config.h $(TOPDIR)/include/linux/types.h $(TOPDIR)/include/linux/sched.h $(TOPDIR)/include/linux/signal.h $(TOPDIR)/include/linux/sys.h $(TOPDIR)/include/linux/kernel.h
+	$(HOSTCC) $(HOSTCFLAGS) -D__KERNEL__ -I$(TOPDIR)/include -o offset offset.c
+
+./mosasm.H: offset entry.S
+	./offset < entry.S > mosasm.H
+
+endif
diff -ruN linux-2.4.16/arch/i386/kernel/entry.S linux-2.4.16-mosix/arch/i386/kernel/entry.S
--- linux-2.4.16/arch/i386/kernel/entry.S	Sat Nov  3 03:18:49 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/entry.S	Sun Dec 23 13:56:53 2001
@@ -46,6 +46,10 @@
 #include <asm/segment.h>
 #include <asm/smp.h>
 
+#ifdef CONFIG_MOSIX
+#include "mosasm.H"
+#endif /* CONFIG_MOSIX */
+
 EBX		= 0x00
 ECX		= 0x04
 EDX		= 0x08
@@ -179,10 +183,16 @@
 	pushl %ebx
 	call SYMBOL_NAME(schedule_tail)
 	addl $4, %esp
+#ifdef CONFIG_MOSIX
+ENTRY(ret_from_kickstart)
+	GET_CURRENT(%ebx)
+	jmp	ret_from_sys_call
+#else
 	GET_CURRENT(%ebx)
 	testb $0x02,tsk_ptrace(%ebx)	# PT_TRACESYS
 	jne tracesys_exit
 	jmp	ret_from_sys_call
+#endif /* CONFIG_MOSIX */
 
 /*
  * Return to user mode is not as complex as all this looks,
@@ -197,16 +207,50 @@
 	GET_CURRENT(%ebx)
 	testb $0x02,tsk_ptrace(%ebx)	# PT_TRACESYS
 	jne tracesys
+/* conflict resolution - Qlusters */
+#ifdef CONFIG_MOSIX_UDB
+	pushl %eax
+	call SYMBOL_NAME(sys_call_trace) # display syscalls for debugging
+	popl %eax
+#endif /* CONFIG_MOSIX_UDB */
 	cmpl $(NR_syscalls),%eax
 	jae badsys
+#ifdef CONFIG_MOSIX
+	testl $(DTRACESYS1|DTRACESYS2),DFLAGS(%ebx)
+	jne adjust_trace_before_syscall
+adjusted_trace:
+	testb $DREMOTE,DFLAGS(%ebx)
+	je local_syscall
+on_remote:
+	pushl %eax
+	call *SYMBOL_NAME(remote_sys_call_table)(,%eax,4)
+	addl $4,%esp
+	movl %eax,EAX(%esp)
+	jmp ret_from_sys_call
+local_syscall:
+#endif /* CONFIG_MOSIX */
 	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
 	movl %eax,EAX(%esp)		# save the return value
+#ifdef CONFIG_MOSIX
+	call SYMBOL_NAME(mosix_local_syscall)
+#endif /* CONFIG_MOSIX */
 ENTRY(ret_from_sys_call)
+#ifdef CONFIG_MOSIX
+	testl $(DTRACESYS1|DTRACESYS2),DFLAGS(%ebx)
+	jne adjust_trace_before_syscall
+ret_check_reschedule:
+#endif /* CONFIG_MOSIX */
 	cli				# need_resched and signals atomic test
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
 	jne signal_return
+#ifdef CONFIG_MOSIX
+straight_to_mosix:
+	call SYMBOL_NAME(mosix_pre_usermode_actions)
+	testl %eax,%eax
+	jne ret_from_sys_call
+#endif /* CONFIG_MOSIX */
 restore_all:
 	RESTORE_ALL
 
@@ -218,7 +262,11 @@
 	jne v86_signal_return
 	xorl %edx,%edx
 	call SYMBOL_NAME(do_signal)
+#ifdef CONFIG_MOSIX
+	jmp straight_to_mosix
+#else
 	jmp restore_all
+#endif /* CONFIG_MOSIX */
 
 	ALIGN
 v86_signal_return:
@@ -226,18 +274,41 @@
 	movl %eax,%esp
 	xorl %edx,%edx
 	call SYMBOL_NAME(do_signal)
+#ifdef CONFIG_MOSIX
+	jmp straight_to_mosix
+#else
 	jmp restore_all
+#endif /* CONFIG_MOSIX */
 
 	ALIGN
 tracesys:
 	movl $-ENOSYS,EAX(%esp)
 	call SYMBOL_NAME(syscall_trace)
+#ifdef CONFIG_MOSIX
+adjust_trace_before_syscall:		# only arrive here with DTRACESYS(1|2)
+	testl $DDEPUTY,DFLAGS(%ebx)
+	jne straight_to_mosix		# no mess with signals/syscalls/tracesys
+	testl $DREMOTE,DFLAGS(%ebx)
+	je no_need_to_unsync
+	call wait_for_permission_to_continue
+no_need_to_unsync:
+	testl $DTRACESYS2,DFLAGS(%ebx)
+	jne second_tracesys		# skipping system-call
+	orl $DTRACESYS2,DFLAGS(%ebx)	# next time we skip the system-call
+	movl $-ENOSYS,EAX(%esp)
+	movl ORIG_EAX(%esp),%eax
+	cmpl $(NR_syscalls),%eax
+	jae second_tracesys		# prevent system-call out of range trick
+	jmp adjusted_trace		# now do the system-call
+second_tracesys:			# note: "syscall_trace" clears the flags
+#else
 	movl ORIG_EAX(%esp),%eax
 	cmpl $(NR_syscalls),%eax
 	jae tracesys_exit
 	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
 	movl %eax,EAX(%esp)		# save the return value
 tracesys_exit:
+#endif /* CONFIG_MOSIX */
 	call SYMBOL_NAME(syscall_trace)
 	jmp ret_from_sys_call
 badsys:
@@ -251,7 +322,11 @@
 	movl EFLAGS(%esp),%eax		# mix EFLAGS and CS
 	movb CS(%esp),%al
 	testl $(VM_MASK | 3),%eax	# return to VM86 mode or non-supervisor?
+#ifdef CONFIG_MOSIX
+	jne ret_check_reschedule
+#else
 	jne ret_from_sys_call
+#endif /* CONFIG_MOSIX */
 	jmp restore_all
 
 	ALIGN
@@ -259,6 +334,73 @@
 	call SYMBOL_NAME(schedule)    # test
 	jmp ret_from_sys_call
 
+#ifdef CONFIG_MOSIX
+/*
+ * call_with_regs(caddr_t routine, pt_regs *before, pt_regs *after)
+ * pushes the "before" regs on the stack and calls routine,
+ * then places the possibly-modified registers in "after"
+ * (which may possibly equal "before").
+ * Also, set "current->altregs" to the pushed registers, then restores it.
+ */
+ENTRY(call_with_regs)
+	pushl	%ebx
+	GET_CURRENT(%ebx)
+	pushl	ALTREGS(%ebx)
+	movl	16(%esp),%eax
+	pushl	56(%eax)
+	pushl	52(%eax)
+	pushl	48(%eax)
+	pushl	44(%eax)
+	pushl	40(%eax)
+	pushl	36(%eax)
+	pushl	32(%eax)
+	pushl	28(%eax)
+	pushl	24(%eax)
+	pushl	20(%eax)
+	pushl	16(%eax)
+	pushl	12(%eax)
+	pushl	8(%eax)
+	pushl	4(%eax)
+	pushl	0(%eax)
+	movl	%esp,ALTREGS(%ebx)
+	movl	72(%esp),%eax
+	call	*%eax
+	movl	80(%esp),%edx
+	popl	%ecx
+	movl	%ecx,0(%edx)
+	popl	%ecx
+	movl	%ecx,4(%edx)
+	popl	%ecx
+	movl	%ecx,8(%edx)
+	popl	%ecx
+	movl	%ecx,12(%edx)
+	popl	%ecx
+	movl	%ecx,16(%edx)
+	popl	%ecx
+	movl	%ecx,20(%edx)
+	popl	%ecx
+	movl	%ecx,24(%edx)
+	popl	%ecx
+	movl	%ecx,28(%edx)
+	popl	%ecx
+	movl	%ecx,32(%edx)
+	popl	%ecx
+	movl	%ecx,36(%edx)
+	popl	%ecx
+	movl	%ecx,40(%edx)
+	popl	%ecx
+	movl	%ecx,44(%edx)
+	popl	%ecx
+	movl	%ecx,48(%edx)
+	popl	%ecx
+	movl	%ecx,52(%edx)
+	popl	%ecx
+	movl	%ecx,56(%edx)
+	popl	ALTREGS(%ebx)
+	popl	%ebx
+	ret
+#endif /* CONFIG_MOSIX */
+
 ENTRY(divide_error)
 	pushl $0		# no error code
 	pushl $ SYMBOL_NAME(do_divide_error)
@@ -402,7 +544,11 @@
 	.long SYMBOL_NAME(sys_read)
 	.long SYMBOL_NAME(sys_write)
 	.long SYMBOL_NAME(sys_open)		/* 5 */
+#ifdef CONFIG_MOSIX_DFSA
+	.long SYMBOL_NAME(sys_close_syscall)
+#else
 	.long SYMBOL_NAME(sys_close)
+#endif /* CONFIG_MOSIX_DFSA */
 	.long SYMBOL_NAME(sys_waitpid)
 	.long SYMBOL_NAME(sys_creat)
 	.long SYMBOL_NAME(sys_link)
diff -ruN linux-2.4.16/arch/i386/kernel/i387.c linux-2.4.16-mosix/arch/i386/kernel/i387.c
--- linux-2.4.16/arch/i386/kernel/i387.c	Fri Feb 23 20:09:08 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/i387.c	Sun Dec 23 13:56:53 2001
@@ -520,3 +520,66 @@
 
 	return fpvalid;
 }
+
+#ifdef CONFIG_MOSIX
+
+int
+has_fxsr(void)
+{
+	return(cpu_has_fxsr);
+}
+
+void
+fsave_to_fxsave(union i387_union *from, union i387_union *to)
+{
+	int i;
+	long *fcp, *tcp;
+
+	to->fxsave.cwd = from->fsave.cwd;
+	to->fxsave.swd = from->fsave.swd;
+	to->fxsave.twd = twd_i387_to_fxsr(from->fsave.twd);
+	to->fxsave.fop = from->fxsave.padding[0];
+	to->fxsave.fip = from->fsave.fip;
+	to->fxsave.fcs = from->fsave.fcs;
+	to->fxsave.foo = from->fsave.foo;
+	to->fxsave.mxcsr = from->fxsave.padding[1];
+	to->fxsave.fos = from->fsave.fos;
+	for(fcp = from->fsave.st_space , tcp = to->fxsave.st_space ,
+		i = 0 ; i < 8 ; i++)
+	{
+		*tcp++ = *fcp++;
+		*tcp++ = *fcp++;
+		*tcp = *((unsigned short *)fcp)++;
+		tcp += 2;
+	}
+	memcpy(to->fxsave.xmm_space, from->fxsave.xmm_space,
+						sizeof(from->fxsave.xmm_space));
+}
+
+void
+fxsave_to_fsave(union i387_union *from, union i387_union *to)
+{
+	int i;
+	long *fcp, *tcp;
+
+	to->fsave.cwd = from->fxsave.cwd;
+	to->fsave.swd = from->fxsave.swd;
+	to->fsave.twd = twd_fxsr_to_i387(&from->fxsave);
+	to->fsave.fip = from->fxsave.fip;
+	to->fsave.fcs = from->fxsave.fcs;
+	to->fsave.foo = from->fxsave.foo;
+	to->fsave.fos = from->fxsave.fos;
+	to->fxsave.padding[0] = from->fxsave.fop;
+	to->fxsave.padding[1] = from->fxsave.mxcsr;
+	for(fcp = from->fxsave.st_space , tcp = to->fsave.st_space ,
+		i = 0 ; i < 8 ; i++)
+	{
+		*tcp++ = *fcp++;
+		*tcp++ = *fcp++;
+		*((unsigned short *)tcp)++ = *fcp;
+		fcp += 2;
+	}
+	memcpy(to->fxsave.xmm_space, from->fxsave.xmm_space,
+						sizeof(to->fxsave.xmm_space));
+}
+#endif /* CONFIG_MOSIX */
diff -ruN linux-2.4.16/arch/i386/kernel/ioport.c linux-2.4.16-mosix/arch/i386/kernel/ioport.c
--- linux-2.4.16/arch/i386/kernel/ioport.c	Tue Jul 20 01:22:48 1999
+++ linux-2.4.16-mosix/arch/i386/kernel/ioport.c	Sun Dec 23 13:56:53 2001
@@ -15,6 +15,10 @@
 #include <linux/smp_lock.h>
 #include <linux/stddef.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
 static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
 {
@@ -61,6 +65,10 @@
 		return -EINVAL;
 	if (turn_on && !capable(CAP_SYS_RAWIO))
 		return -EPERM;
+#ifdef CONFIG_MOSIX
+	if(turn_on && !mosix_go_home_for_reason(1, DSTAY_FOR_IOPL))
+		return(-ENOMEM);
+#endif /* CONFIG_MOSIX */
 	/*
 	 * If it's the first ioperm() call in this thread's lifetime, set the
 	 * IO bitmap up. ioperm() is much less timing critical than clone(),
@@ -111,6 +119,11 @@
 		if (!capable(CAP_SYS_RAWIO))
 			return -EPERM;
 	}
+#ifdef CONFIG_MOSIX
+	if(!mosix_go_home_for_reason(1, DSTAY_FOR_IOPL))
+		return(-ENOMEM);
+	regs = mos_to_regs(&current->mosix);
+#endif /* CONFIG_MOSIX */
 	regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12);
 	return 0;
 }
diff -ruN linux-2.4.16/arch/i386/kernel/irq.c linux-2.4.16-mosix/arch/i386/kernel/irq.c
--- linux-2.4.16/arch/i386/kernel/irq.c	Thu Oct 25 22:53:46 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/irq.c	Sun Dec 23 13:56:53 2001
@@ -279,6 +279,10 @@
 		clear_bit(0,&global_irq_lock);
 
 		for (;;) {
+#ifdef CONFIG_MOSIX_UDB
+			extern int nmi_debugger;
+			if(!nmi_debugger)
+#endif /* CONFIG_MOSIX_UDB */
 			if (!--count) {
 				show("wait_on_irq");
 				count = ~0;
diff -ruN linux-2.4.16/arch/i386/kernel/nmi.c linux-2.4.16-mosix/arch/i386/kernel/nmi.c
--- linux-2.4.16/arch/i386/kernel/nmi.c	Fri Sep 21 06:55:24 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/nmi.c	Sun Dec 23 13:56:53 2001
@@ -25,6 +25,9 @@
 #include <asm/mpspec.h>
 
 unsigned int nmi_watchdog = NMI_NONE;
+#ifdef CONFIG_MOSIX_UDB
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX_UDB */
 static unsigned int nmi_hz = HZ;
 unsigned int nmi_perfctr_msr;	/* the MSR to reset in NMI handler */
 extern void show_registers(struct pt_regs *regs);
@@ -268,6 +271,10 @@
 	 */
 	int sum, cpu = smp_processor_id();
 
+#ifdef CONFIG_MOSIX_UDB
+	if(nmi_debugger)
+		return;
+#endif /* CONFIG_MOSIX_UDB */
 	sum = apic_timer_irqs[cpu];
 
 	if (last_irq_sums[cpu] == sum) {
@@ -285,6 +292,10 @@
 			bust_spinlocks(1);
 			printk("NMI Watchdog detected LOCKUP on CPU%d, registers:\n", cpu);
 			show_registers(regs);
+#ifdef CONFIG_MOSIX_UDB
+			mosix_debugger("Watchdog");
+			return;
+#endif /* CONFIG_MOSIX_UDB */
 			printk("console shuts up ...\n");
 			console_silent();
 			spin_unlock(&nmi_print_lock);
diff -ruN linux-2.4.16/arch/i386/kernel/offset.c linux-2.4.16-mosix/arch/i386/kernel/offset.c
--- linux-2.4.16/arch/i386/kernel/offset.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/arch/i386/kernel/offset.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,86 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+/*
+ * Produce an include-file for "entry.S", with:
+ * 1. constant-offsets of some required MOSIX-members of "task_struct"
+ * 2. some bits to test "current->dflags"
+ * 3. a duplicate system-call table (remote_sys_call_table), with all
+ *    system-calls names preceded by a "remote_".
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/sys.h>
+
+struct file;
+#define FILE	struct file
+
+extern int printf(char *, ...);
+extern int fgets(char *, int, FILE *);
+extern int perror(char *);
+extern FILE *stdin;
+
+char line[2048];
+
+int
+main(void)
+{
+	register char *c;
+	register int i;
+	long t, time(long *);
+	char *ctime(long *);
+
+	time(&t);
+	printf("/* Please do not edit -- this file is created automatically */\n");
+	printf("/* %.24s */\n\n", ctime(&t));
+	printf("ALTREGS\t\t= 0x%X\n",
+		(int)&(((struct task_struct *)0)->mosix.altregs));
+	printf("DFLAGS\t\t= 0x%X\n",
+		(int)&(((struct task_struct *)0)->mosix.dflags));
+	printf("DDEPUTY\t\t= 0x%X\n", DDEPUTY);
+	printf("DREMOTE\t\t= 0x%X\n", DREMOTE);
+	printf("DTRACESYS1\t\t= 0x%X\n", DTRACESYS1);
+	printf("DTRACESYS2\t\t= 0x%X\n", DTRACESYS2);
+	printf(".data\n");
+	printf("\nENTRY(remote_sys_call_table)\n");
+	while(fgets(line, 2048, stdin) &&
+		strcmp(line, "ENTRY(sys_call_table)\n"))
+			;
+	for(i = 0 ; i < NR_syscalls && fgets(line, 2048, stdin) ; i++)
+	if(!strncmp(line, "\t.long SYMBOL_NAME(", 19))
+	{
+		for(c = &line[19] ; *c && *c != ')' ; c++);
+		*c = '\0';
+		if(!strcmp(&line[19], "sys_ni_syscall"))
+		{
+			printf("\t.long SYMBOL_NAME(sys_ni_syscall)\n");
+			continue;
+		}
+		printf("\t.long SYMBOL_NAME(remote_%s)\n", &line[19]);
+	}
+	else if(!strcmp(line, "\t.rept NR_syscalls-(.-sys_call_table)/4\n"))
+		printf("\t.rept NR_syscalls-(.-remote_sys_call_table)/4\n");
+	else
+	{
+		printf("%s", line);
+		if(!strncmp(line, "\t.endr", 5))
+			break;
+	}
+	printf(".text\n");
+	return(0);
+}
diff -ruN linux-2.4.16/arch/i386/kernel/process.c linux-2.4.16-mosix/arch/i386/kernel/process.c
--- linux-2.4.16/arch/i386/kernel/process.c	Fri Oct  5 03:42:54 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/process.c	Sun Dec 23 13:56:53 2001
@@ -49,6 +49,10 @@
 
 #include <linux/irq.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
 
 int hlt_counter;
@@ -160,6 +164,14 @@
 /* shamelessly grabbed from lib/vsprintf.c for readability */
 #define is_digit(c)	((c) >= '0' && (c) <= '9')
 #endif
+
+#ifdef CONFIG_MOSIX_UDB
+void set_fastest_reboot(void)
+{
+	reboot_mode = 0x1234;
+}
+#endif /* CONFIG_MOSIX_UDB */
+
 static int __init reboot_setup(char *str)
 {
 	while(1) {
@@ -510,6 +522,43 @@
 	return retval;
 }
 
+#ifdef CONFIG_MOSIX
+/*
+ * Create a thread that starts as kernel, but will eventually run in user-mode:
+ * The slight differences from "kernel_thread" are:
+ * 1) not using CLONE_VM.
+ * 2) adding SIGCHLD to the flags.
+ * 3) leaving space on the stack for the user-registers.
+ */
+int user_thread(int (*fn)(void *), void * arg, unsigned long flags)
+{
+	long retval, d0;
+
+	__asm__ __volatile__(
+		"movl %%esp,%%esi\n\t"
+		"int $0x80\n\t"		/* Linux/i386 system call */
+		"cmpl %%esp,%%esi\n\t"	/* child or parent? */
+		"je 1f\n\t"		/* parent - jump */
+		"subl %7,%%esp\n\t"	/* space for user-registers */
+		/* Load the argument into eax, and push it.  That way, it does
+		 * not matter whether the called function is compiled with
+		 * -mregparm or not.  */
+		"movl %4,%%eax\n\t"
+		"pushl %%eax\n\t"		
+		"call *%5\n\t"		/* call fn */
+		"movl %3,%0\n\t"	/* exit */
+		"int $0x80\n"
+		"1:\t"
+		:"=&a" (retval), "=&S" (d0)
+		:"0" (__NR_clone), "i" (__NR_exit),
+		 "r" (arg), "r" (fn),
+		 "b" (flags | SIGCHLD),
+		 "i" (sizeof(struct pt_regs))
+		: "memory");
+	return retval;
+}
+#endif /* CONFIG_MOSIX */
+
 /*
  * Free current thread data structures etc..
  */
@@ -583,6 +632,10 @@
 
 	childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p)) - 1;
 	struct_cpy(childregs, regs);
+#ifdef CONFIG_MOSIX
+	p->mosix.altregs = (uint32_t *)childregs;
+	p->mosix.deputy_regs = current->mosix.deputy_regs;
+#endif /* CONFIG_MOSIX */
 	childregs->eax = 0;
 	childregs->esp = esp;
 
@@ -734,10 +787,32 @@
 			 */
 			tss->bitmap = INVALID_IO_BITMAP_OFFSET;
 	}
+#ifdef CONFIG_MOSIX
+	if(test_bit(X86_FEATURE_TSC, &boot_cpu_data.x86_capability))
+	{
+		/* REMOTE emulates the RDTSC instruction */
+		if(next_p->mosix.dflags & DREMOTE)
+		{
+			if(!(prev_p->mosix.dflags & DREMOTE))
+				__asm__ __volatile__("movl %%cr4,%%eax\n\t" \
+					"orl $4,%%eax\n\t" \
+					"movl %%eax,%%cr4\n" \
+					: : :"ax");
+		}
+		else if(prev_p->mosix.dflags & DREMOTE)
+			__asm__ __volatile__("movl %%cr4,%%eax\n\t" \
+				"andl $0xfffffffb,%%eax\n\t" \
+				"movl %%eax,%%cr4\n" \
+				: : :"ax");
+	}
+#endif /* CONFIG_MOSIX */
 }
 
 asmlinkage int sys_fork(struct pt_regs regs)
 {
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(BIT_OF_REGISTER(esp));
+#endif /* CONFIG_MOSIX */
 	return do_fork(SIGCHLD, regs.esp, &regs, 0);
 }
 
@@ -745,12 +820,27 @@
 {
 	unsigned long clone_flags;
 	unsigned long newsp;
+#ifdef CONFIG_MOSIX
+	int retval;
+#endif /* CONFIG_MOSIX */
 
 	clone_flags = regs.ebx;
 	newsp = regs.ecx;
 	if (!newsp)
+#ifdef CONFIG_MOSIX
+		mosix_obtain_registers(BIT_OF_REGISTER(esp)) ,
+#endif /* CONFIG_MOSIX */
 		newsp = regs.esp;
+#ifdef CONFIG_MOSIX
+	if((clone_flags & CLONE_VM) && (retval = mosix_pre_clone()))
+		return(retval);
+	retval = do_fork(clone_flags, newsp, &regs, 0);
+	if(clone_flags & CLONE_VM)
+		mosix_post_clone();
+	return(retval);
+#else
 	return do_fork(clone_flags, newsp, &regs, 0);
+#endif /* CONFIG_MOSIX */
 }
 
 /*
@@ -765,7 +855,18 @@
  */
 asmlinkage int sys_vfork(struct pt_regs regs)
 {
+#ifdef CONFIG_MOSIX
+	int retval;
+
+	mosix_obtain_registers(BIT_OF_REGISTER(esp));
+	if((retval = mosix_pre_clone()))
+		return(retval);
+	retval = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, &regs, 0);
+	mosix_post_clone();
+	return(retval);
+#else
 	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, &regs, 0);
+#endif /* CONFIG_MOSIX */
 }
 
 /*
@@ -801,23 +902,50 @@
 	unsigned long ebp, esp, eip;
 	unsigned long stack_page;
 	int count = 0;
+#ifdef CONFIG_MOSIX
+	unsigned long result = 0;
+	if (!p || p == current || LOGICAL_STATE(p) == TASK_RUNNING)
+#else
 	if (!p || p == current || p->state == TASK_RUNNING)
+#endif /* CONFIG_MOSIX */
 		return 0;
 	stack_page = (unsigned long)p;
 	esp = p->thread.esp;
 	if (!stack_page || esp < stack_page || esp > 8188+stack_page)
+#ifdef CONFIG_MOSIX
+		return(result);
+#else
 		return 0;
+#endif /* CONFIG_MOSIX */
 	/* include/asm-i386/system.h:switch_to() pushes ebp last. */
 	ebp = *(unsigned long *) esp;
 	do {
 		if (ebp < stack_page || ebp > 8184+stack_page)
+#ifdef CONFIG_MOSIX
+			return(result);
+#else
 			return 0;
+#endif /* CONFIG_MOSIX */
 		eip = *(unsigned long *) (ebp+4);
 		if (eip < first_sched || eip >= last_sched)
+#ifdef CONFIG_MOSIX
+		{
+			if(!result)
+				return eip;
+		}
+		else
+			result = 0;
+#else
 			return eip;
+#endif /* CONFIG_MOSIX */
 		ebp = *(unsigned long *) ebp;
+#ifdef CONFIG_MOSIX
+	} while (count++ < 64);
+	return(result);
+#else
 	} while (count++ < 16);
 	return 0;
+#endif /* CONFIG_MOSIX */
 }
 #undef last_sched
 #undef first_sched
diff -ruN linux-2.4.16/arch/i386/kernel/ptrace.c linux-2.4.16-mosix/arch/i386/kernel/ptrace.c
--- linux-2.4.16/arch/i386/kernel/ptrace.c	Wed Nov 21 20:42:41 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/ptrace.c	Sun Dec 23 13:56:53 2001
@@ -21,6 +21,10 @@
 #include <asm/i387.h>
 #include <asm/debugreg.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /*
  * does not yet catch signals sent when the child dies.
  * in exit.c or in signal.c.
@@ -44,13 +48,47 @@
  * this routine assumes that all the privileged stacks are in our
  * data space.
  */   
+#ifdef CONFIG_MOSIX
+inline int get_stack_long(struct task_struct *task, int offset)
+#else
 static inline int get_stack_long(struct task_struct *task, int offset)
+#endif /* CONFIG_MOSIX */
 {
 	unsigned char *stack;
 
+#ifdef CONFIG_MOSIX
+	if(task != current)
+		lock_mosix();
+	if(task->mosix.dflags & DDEPUTY)
+	{
+		if(task != current)
+			unlock_mosix();
+		return(request_process(task, NULL, PR_PTRACE_GET_STACK_LONG,
+			offset));
+	}
+	if(task == current)
+		mosix_obtain_registers(ALL_REGISTERS);
+	else
+		task_lock(task);
+	if(!task->thread.saved_esp0)	/* unless in VM86 mode */
+		stack = (char *)(mos_to_regs(&task->mosix) + 1);
+	else
+#endif /* CONFIG_MOSIX */
 	stack = (unsigned char *)task->thread.esp0;
 	stack += offset;
+#ifdef CONFIG_MOSIX
+	{
+		int res = *((int *)stack);
+		if(task != current)
+		{
+			task_unlock(task);
+			unlock_mosix();
+		}
+		return(res);
+	}
+#else
 	return (*((int *)stack));
+#endif /* CONFIG_MOSIX */
 }
 
 /*
@@ -59,14 +97,43 @@
  * this routine assumes that all the privileged stacks are in our
  * data space.
  */
+#ifdef CONFIG_MOSIX
+inline int put_stack_long(struct task_struct *task, int offset,
+#else
 static inline int put_stack_long(struct task_struct *task, int offset,
+#endif /* CONFIG_MOSIX */
 	unsigned long data)
 {
 	unsigned char * stack;
 
+#ifdef CONFIG_MOSIX
+	if(task != current)
+		lock_mosix();
+	if(task->mosix.dflags & DDEPUTY)
+	{
+		if(task != current)
+			unlock_mosix();
+		return(request_process_arg2(task, NULL,
+			PR_PTRACE_PUT_STACK_LONG, offset, data));
+	}
+	if(task == current)
+		mosix_obtain_registers(ALL_REGISTERS);
+	else
+		task_lock(task);
+	if(!task->thread.saved_esp0)	/* unless in VM86 mode */
+		stack = (char *)(mos_to_regs(&task->mosix) + 1);
+	else
+#endif /* CONFIG_MOSIX */
 	stack = (unsigned char *) task->thread.esp0;
 	stack += offset;
 	*(unsigned long *) stack = data;
+#ifdef CONFIG_MOSIX
+	if(task != current)
+	{
+		task_unlock(task);
+		unlock_mosix();
+	}
+#endif /* CONFIG_MOSIX */
 	return 0;
 }
 
@@ -107,6 +174,17 @@
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+void
+ptrace_putregs(unsigned long *data)
+{
+	register int i;
+
+	for (i = 0; i < FRAME_SIZE ; i++)
+		putreg(current, i << 2, data[i]);
+}
+#endif /* CONFIG_MOSIX */
+
 static unsigned long getreg(struct task_struct *child,
 	unsigned long regno)
 {
@@ -147,6 +225,17 @@
 	put_stack_long(child, EFL_OFFSET, tmp);
 }
 
+#ifdef CONFIG_MOSIX
+void
+ptrace_getregs(unsigned long *data)
+{
+	register int i;
+
+	for (i = 0; i < FRAME_SIZE ; i++)
+		data[i] = getreg(current, i << 2);
+}
+#endif /* CONFIG_MOSIX */
+
 asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
 {
 	struct task_struct *child;
@@ -161,6 +250,9 @@
 			goto out;
 		/* set the ptrace bit in the process flags. */
 		current->ptrace |= PT_PTRACED;
+#ifdef CONFIG_MOSIX_DFSA
+		tell_process(current, DREQ_NOTUPTODATE);
+#endif /* CONFIG_MOSIX_DFSA */
 		ret = 0;
 		goto out;
 	}
@@ -210,6 +302,17 @@
 		    addr > sizeof(struct user) - 3)
 			break;
 
+#ifdef CONFIG_MOSIX
+		lock_mosix();
+		if(child->mosix.dflags & DDEPUTY)
+		{
+			unlock_mosix();
+			if(request_process(child, &tmp, PR_PTRACE_PEEKUSER, addr))
+				goto out;
+		}
+		else
+		{
+#endif /* CONFIG_MOSIX */
 		tmp = 0;  /* Default return condition */
 		if(addr < FRAME_SIZE*sizeof(long))
 			tmp = getreg(child, addr);
@@ -219,6 +322,10 @@
 			addr = addr >> 2;
 			tmp = child->thread.debugreg[addr];
 		}
+#ifdef CONFIG_MOSIX
+		unlock_mosix();
+		}
+#endif /* CONFIG_MOSIX */
 		ret = put_user(tmp,(unsigned long *) data);
 		break;
 	}
@@ -265,7 +372,23 @@
 
 			  addr -= (long) &dummy->u_debugreg;
 			  addr = addr >> 2;
+#ifdef CONFIG_MOSIX
+			  lock_mosix();
+			  if(child->mosix.dflags & DDEPUTY)
+			  {
+				unlock_mosix();
+				if(request_process_arg2(child, NULL,
+					PR_PTRACE_POKEUSER, addr, data))
+					goto out;
+			  }
+			  else
+			  {
+#endif /* CONFIG_MOSIX */
 			  child->thread.debugreg[addr] = data;
+#ifdef CONFIG_MOSIX
+			  unlock_mosix();
+			  }
+#endif /* CONFIG_MOSIX */
 			  ret = 0;
 		  }
 		  break;
@@ -282,9 +405,22 @@
 		else
 			child->ptrace &= ~PT_TRACESYS;
 		child->exit_code = data;
+#ifdef CONFIG_MOSIX
+		if(child->mosix.dflags & DDEPUTY)
+		{
+			if(request_process(child, NULL, PR_PTRACE_CONT,
+								request))
+				goto out;
+		}
+		else
+		{
+#endif /* CONFIG_MOSIX */
 	/* make sure the single step bit is not set. */
 		tmp = get_stack_long(child, EFL_OFFSET) & ~TRAP_FLAG;
 		put_stack_long(child, EFL_OFFSET,tmp);
+#ifdef CONFIG_MOSIX
+		}
+#endif /* CONFIG_MOSIX */
 		wake_up_process(child);
 		ret = 0;
 		break;
@@ -299,7 +435,11 @@
 		long tmp;
 
 		ret = 0;
+#ifdef CONFIG_MOSIX
+		if (LOGICAL_STATE(child) == TASK_ZOMBIE) /* already dead */
+#else
 		if (child->state == TASK_ZOMBIE)	/* already dead */
+#endif /* CONFIG_MOSIX */
 			break;
 		child->exit_code = SIGKILL;
 		/* make sure the single step bit is not set. */
@@ -320,8 +460,21 @@
 			/* Spurious delayed TF traps may occur */
 			child->ptrace |= PT_DTRACE;
 		}
+#ifdef CONFIG_MOSIX
+		if(child->mosix.dflags & DDEPUTY)
+		{
+			if(request_process(child, NULL, PR_PTRACE_SINGLE_STEP,
+									0))
+				goto out;
+		}
+		else
+		{
+#endif /* CONFIG_MOSIX */
 		tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG;
 		put_stack_long(child, EFL_OFFSET, tmp);
+#ifdef CONFIG_MOSIX
+		}
+#endif /* CONFIG_MOSIX */
 		child->exit_code = data;
 		/* give it a chance to run. */
 		wake_up_process(child);
@@ -339,26 +492,57 @@
 			ret = -EIO;
 			break;
 		}
+#ifdef CONFIG_MOSIX
+		/* NOTE: even when child does not look like a DEPUTY,
+		 * it could easily become one while we wait for a page
+		 * on __put_user ... therefore, we do this ALWAYS:
+		 */
+		{
+			unsigned long t[FRAME_SIZE];
+
+			if(request_process(child, &t, PR_PTRACE_GETREGS, 0))
+				ret = -EIO;
+			else
+				copy_to_user((void *)data, t, sizeof(t));
+		}
+#else
 		for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
 			__put_user(getreg(child, i),(unsigned long *) data);
 			data += sizeof(long);
 		}
+#endif /* CONFIG_MOSIX */
 		ret = 0;
 		break;
 	}
 
 	case PTRACE_SETREGS: { /* Set all gp regs in the child. */
+#ifndef CONFIG_MOSIX
 		unsigned long tmp;
+#endif /* CONFIG_MOSIX */
 	  	if (!access_ok(VERIFY_READ, (unsigned *)data, FRAME_SIZE*sizeof(long))) {
 			ret = -EIO;
 			break;
 		}
+#ifdef CONFIG_MOSIX
+		/* NOTE: even when child does not look like a DEPUTY,
+		 * it could easily become one while we wait for a page
+		 * on __get_user ... therefore, we do this ALWAYS:
+		 */
+		{
+			unsigned long t[FRAME_SIZE];
+
+			copy_from_user(t, (void *)data, sizeof(t));
+			ret = request_process(child, &t, PR_PTRACE_SETREGS, 0)
+								? -EIO : 0;
+		}
+#else
 		for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
 			__get_user(tmp, (unsigned long *) data);
 			putreg(child, i, tmp);
 			data += sizeof(long);
 		}
 		ret = 0;
+#endif /* CONFIG_MOSIX */
 		break;
 	}
 
@@ -369,6 +553,23 @@
 			break;
 		}
 		ret = 0;
+#ifdef CONFIG_MOSIX
+		/* DEPUTY or NOT - the child-process may become DEPUTY
+		 * while we page-fault on "__copy_to_user",
+		 * so we always do it the long way:
+		 */
+		{
+			struct user_i387_struct f;
+
+			if(request_process(child, &f, PR_PTRACE_GETFPREGS, 0))
+			{
+				ret = -EIO;
+				goto out;
+			}
+			__copy_to_user((void *)data, &f,
+				sizeof(struct user_i387_struct));
+		}
+#else
 		if ( !child->used_math ) {
 			/* Simulate an empty FPU. */
 			set_fpu_cwd(child, 0x037f);
@@ -376,6 +577,7 @@
 			set_fpu_twd(child, 0xffff);
 		}
 		get_fpregs((struct user_i387_struct *)data, child);
+#endif /* CONFIG_MOSIX */
 		break;
 	}
 
@@ -385,9 +587,23 @@
 			ret = -EIO;
 			break;
 		}
+#ifdef CONFIG_MOSIX
+		/* DEPUTY or NOT - the child-process may become DEPUTY
+		 * while we page-fault on "__copy_from_user",
+		 * so we always do it the long way:
+		 */
+		{
+			struct user_i387_struct f;
+
+			__copy_from_user(&f, (void *)data, sizeof(f));
+			ret = request_process(child, &f, PR_PTRACE_SETFPREGS, 0)
+								? -EIO : 0;
+		}
+#else
 		child->used_math = 1;
 		set_fpregs(child, (struct user_i387_struct *)data);
 		ret = 0;
+#endif /* CONFIG_MOSIX */
 		break;
 	}
 
@@ -397,6 +613,24 @@
 			ret = -EIO;
 			break;
 		}
+#ifdef CONFIG_MOSIX
+		ret = 0;
+		/* DEPUTY or NOT - the child-process may become DEPUTY
+		 * while we page-fault on "__copy_to_user",
+		 * so we always do it the long way:
+		 */
+		{
+			struct user_fxsr_struct f;
+
+			if(request_process(child, &f, PR_PTRACE_GETFPXREGS, 0))
+			{
+				ret = -EIO;
+				goto out;
+			}
+			__copy_to_user((void *)data, &f,
+				sizeof(struct user_fxsr_struct));
+		}
+#else
 		if ( !child->used_math ) {
 			/* Simulate an empty FPU. */
 			set_fpu_cwd(child, 0x037f);
@@ -405,6 +639,7 @@
 			set_fpu_mxcsr(child, 0x1f80);
 		}
 		ret = get_fpxregs((struct user_fxsr_struct *)data, child);
+#endif /* CONFIG_MOSIX */
 		break;
 	}
 
@@ -414,8 +649,22 @@
 			ret = -EIO;
 			break;
 		}
+#ifdef CONFIG_MOSIX
+		/* DEPUTY or NOT - the child-process may become DEPUTY
+		 * while we page-fault on "__copy_from_user",
+		 * so we always do it the long way:
+		 */
+		{
+			struct user_fxsr_struct f;
+
+			__copy_from_user(&f, (void *)data, sizeof(f));
+			ret = request_process(child, &f, PR_PTRACE_SETFPXREGS,
+								0) ? -EIO : 0;
+		}
+#else
 		child->used_math = 1;
 		ret = set_fpxregs(child, (struct user_fxsr_struct *)data);
+#endif /* CONFIG_MOSIX */
 		break;
 	}
 
@@ -439,7 +688,174 @@
 	return ret;
 }
 
+#ifdef CONFIG_MOSIX
+/*
+ * The following routines are parts of sys_ptrace performed by the
+ * child process on itself.
+ * Should the relevant code in "sys_ptrace" change, the following routines
+ * must also be modified accordingly.
+ */
+unsigned long
+ptrace_peekuser(long addr)
+{
+	struct user * dummy = NULL;
+	unsigned long tmp;
+
+	tmp = 0;  /* Default return condition */
+	if(addr < FRAME_SIZE*sizeof(long))
+		tmp = getreg(current, addr);
+	if(addr >= (long) &dummy->u_debugreg[0] &&
+	   addr <= (long) &dummy->u_debugreg[7]){
+		addr -= (long) &dummy->u_debugreg[0];
+		addr = addr >> 2;
+		tmp = current->thread.debugreg[addr];
+	};
+	return(tmp);
+}
+
+void
+ptrace_pokeuser(long addr, long data)
+{
+	current->thread.debugreg[addr] = data;
+#define loaddebug(tsk,register) \
+		__asm__("movl %0,%%db" #register  \
+			: /* no output */ \
+			:"r" (tsk->thread.debugreg[register]))
+	/* unlike the original ptrace code, we are doing this for ourselves,
+	 * and there may be no "switch_to" before we go to user-mode again,
+	 * so here we go:
+	 */
+	if(current->thread.debugreg[7])
+	{
+		loaddebug(current, 0);
+		loaddebug(current, 1);
+		loaddebug(current, 2);
+		loaddebug(current, 3);
+		loaddebug(current, 6);
+		loaddebug(current, 7);
+	}
+}
+
+void
+ptrace_cont(int request)
+{
+	unsigned long tmp;
+	struct task_struct *tsk = current;
+
+	tmp = get_stack_long(tsk, EFL_OFFSET) & ~TRAP_FLAG;
+	put_stack_long(tsk, EFL_OFFSET, tmp);
+	if (request == PTRACE_SYSCALL)
+		tsk->ptrace |= PT_TRACESYS;
+	else
+		tsk->ptrace &= ~PT_TRACESYS;
+	if (request == PTRACE_DETACH)
+		tsk->ptrace &= ~PT_PTRACED;
+}
+
+void
+ptrace_single_step(void)
+{
+	unsigned long tmp;
+
+	tmp = get_stack_long(current, EFL_OFFSET) | TRAP_FLAG;
+	put_stack_long(current, EFL_OFFSET, tmp);
+	current->ptrace |= PT_PTRACED | PT_DTRACE;
+#ifdef CONFIG_MOSIX_DFSA
+	tell_process(current, DREQ_NOTUPTODATE);
+#endif /* CONFIG_MOSIX_DFSA */
+}
+
+void
+ptrace_getfpregs(struct user_i387_struct *to)
+{
+	struct task_struct *p = current;
+
+	unlazy_fpu(p);
+	if (!p->used_math)
+	{
+		/* Simulate an empty FPU. */
+		set_fpu_cwd(p, 0x037f);
+		set_fpu_swd(p, 0x0000);
+		set_fpu_twd(p, 0xffff);
+	}
+	get_fpregs(to, p);
+}
+
+void
+ptrace_getfpxregs(struct user_fxsr_struct *to)
+{
+	struct task_struct *p = current;
+
+	unlazy_fpu(p);
+	if (!p->used_math)
+	{
+		/* Simulate an empty FPU. */
+		set_fpu_cwd(p, 0x037f);
+		set_fpu_swd(p, 0x0000);
+		set_fpu_twd(p, 0xffff);
+		set_fpu_mxcsr(p, 0x1f80);
+	}
+	get_fpxregs(to, p);
+}
+
+void
+ptrace_setfpregs(struct user_i387_struct *from)
+{
+	struct task_struct *p = current;
+
+	clear_fpu(p);
+	p->used_math = 1;
+	set_fpregs(p, from);
+}
+
+void
+ptrace_setfpxregs(struct user_fxsr_struct *from)
+{
+	struct task_struct *p = current;
+
+	clear_fpu(p);
+	p->used_math = 1;
+	set_fpxregs(p, from);
+}
+#endif /* CONFIG_MOSIX */
+
+#ifdef CONFIG_MOSIX
+/*
+ * When a process starts a system call in PT_TRACESYS mode, it must run
+ * the full sequence: A=syscall_trace, B=the_system_call, C=syscall_trace.
+ * Since our process can migrate at any of those stages, we maintain 2 flags
+ * that tell us where to resume in the sequence.
+ * In the particular case of DTRACESYS1, the trace was already complete
+ * before the migration.  In the case of DTRACESYS2, the system-call was already
+ * complete before the migration and the code in "entry.S" prevents it from
+ * re-running.
+ */
+asmlinkage void
+syscall_trace(void)
+{
+	extern asmlinkage void do_syscall_trace(void);
+
+	switch(current->mosix.dflags & (DTRACESYS1|DTRACESYS2))
+	{
+		case 0:
+			current->mosix.dflags |= DTRACESYS1;
+			break;
+		case DTRACESYS1:
+			return;
+		case DTRACESYS2:
+		case DTRACESYS1|DTRACESYS2:
+			current->mosix.dflags &= ~(DTRACESYS1|DTRACESYS2);
+	}
+	if(current->mosix.dflags & DREMOTE)
+		mosix_remote_syscall_trace();
+	else
+		do_syscall_trace();
+}
+
+asmlinkage void do_syscall_trace(void)
+#else
 asmlinkage void syscall_trace(void)
+#endif /* CONFIG_MOSIX */
 {
 	if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) !=
 			(PT_PTRACED|PT_TRACESYS))
diff -ruN linux-2.4.16/arch/i386/kernel/signal.c linux-2.4.16-mosix/arch/i386/kernel/signal.c
--- linux-2.4.16/arch/i386/kernel/signal.c	Sat Sep 15 00:15:40 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/signal.c	Sun Dec 23 13:56:53 2001
@@ -24,6 +24,10 @@
 #include <asm/uaccess.h>
 #include <asm/i387.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 #define DEBUG_SIG 0
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
@@ -37,6 +41,29 @@
 	if (from->si_code < 0)
 		return __copy_to_user(to, from, sizeof(siginfo_t));
 	else {
+#ifdef CONFIG_MOSIX
+		/* it is unreasonable to send a separate request per word,
+		 * so find the limit and send them all together.
+		 */
+		int sz = offsetof(struct siginfo, _sifields);
+
+		switch(from->si_code >> 16)
+		{
+			case __SI_FAULT >> 16:
+				sz += sizeof(to->_sifields._sigfault);
+				break;
+			case __SI_CHLD >> 16:
+				sz += sizeof(to->_sifields._sigchld);
+				break;
+			case __SI_MIGRATION >> 16:
+				sz += sizeof(to->_sifields._sigmig);
+				break;
+			default:
+				sz += sizeof(to->_sifields._kill);
+				break;
+		}
+		return(__copy_to_user(to, from, sz));
+#else
 		int err;
 
 		/* If you change siginfo_t structure, please be sure
@@ -62,6 +89,7 @@
 		/* case __SI_RT: This is not generated by the kernel as of now.  */
 		}
 		return err;
+#endif /* CONFIG_MOSIX */
 	}
 }
 
@@ -81,6 +109,10 @@
 	recalc_sigpending(current);
 	spin_unlock_irq(&current->sigmask_lock);
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(
+	   BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip));
+#endif /* CONFIG_MOSIX */
 	regs->eax = -EINTR;
 	while (1) {
 		current->state = TASK_INTERRUPTIBLE;
@@ -110,6 +142,10 @@
 	recalc_sigpending(current);
 	spin_unlock_irq(&current->sigmask_lock);
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(
+	   BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip));
+#endif /* CONFIG_MOSIX */
 	regs->eax = -EINTR;
 	while (1) {
 		current->state = TASK_INTERRUPTIBLE;
@@ -155,6 +191,10 @@
 sys_sigaltstack(const stack_t *uss, stack_t *uoss)
 {
 	struct pt_regs *regs = (struct pt_regs *) &uss;
+
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(BIT_OF_REGISTER(esp));
+#endif /* CONFIG_MOSIX */
 	return do_sigaltstack(uss, uoss, regs->esp);
 }
 
@@ -185,11 +225,19 @@
 	char retcode[8];
 };
 
+#ifdef CONFIG_MOSIX
+int
+#else
 static int
+#endif /* CONFIG_MOSIX */
 restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc, int *peax)
 {
 	unsigned int err = 0;
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(ALL_REGISTERS);
+#endif /* CONFIG_MOSIX */
+
 #define COPY(x)		err |= __get_user(regs->x, &sc->x)
 
 #define COPY_SEG(seg)							\
@@ -249,10 +297,18 @@
 asmlinkage int sys_sigreturn(unsigned long __unused)
 {
 	struct pt_regs *regs = (struct pt_regs *) &__unused;
+#ifdef CONFIG_MOSIX
+	struct sigframe *frame;
+#else
 	struct sigframe *frame = (struct sigframe *)(regs->esp - 8);
+#endif /* CONFIG_MOSIX */
 	sigset_t set;
 	int eax;
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(BIT_OF_REGISTER(esp));
+	frame = (struct sigframe *)(regs->esp - 8);
+#endif /* CONFIG_MOSIX */
 	if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
 		goto badframe;
 	if (__get_user(set.sig[0], &frame->sc.oldmask)
@@ -267,6 +323,14 @@
 	recalc_sigpending(current);
 	spin_unlock_irq(&current->sigmask_lock);
 	
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		if (mosix_deputy_restore_sigcontext(&frame->sc, &eax))
+			goto badframe;
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	if (restore_sigcontext(regs, &frame->sc, &eax))
 		goto badframe;
 	return eax;
@@ -279,11 +343,19 @@
 asmlinkage int sys_rt_sigreturn(unsigned long __unused)
 {
 	struct pt_regs *regs = (struct pt_regs *) &__unused;
+#ifdef CONFIG_MOSIX
+	struct rt_sigframe *frame;
+#else
 	struct rt_sigframe *frame = (struct rt_sigframe *)(regs->esp - 4);
+#endif /* CONFIG_MOSIX */
 	sigset_t set;
 	stack_t st;
 	int eax;
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(BIT_OF_REGISTER(esp));
+	frame = (struct rt_sigframe *)(regs->esp - 4);
+#endif /* CONFIG_MOSIX */
 	if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
 		goto badframe;
 	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
@@ -295,6 +367,14 @@
 	recalc_sigpending(current);
 	spin_unlock_irq(&current->sigmask_lock);
 	
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		if(mosix_deputy_restore_sigcontext(&frame->uc.uc_mcontext,&eax))
+			goto badframe;
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax))
 		goto badframe;
 
@@ -302,6 +382,9 @@
 		goto badframe;
 	/* It is more difficult to avoid calling this function than to
 	   call it and ignore errors.  */
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(BIT_OF_REGISTER(esp));
+#endif /* CONFIG_MOSIX */
 	do_sigaltstack(&st, NULL, regs->esp);
 
 	return eax;
@@ -321,6 +404,9 @@
 {
 	int tmp, err = 0;
 
+#ifdef CONFIG_MOSIX_NO_NEED__ALL_CALLERS_ALREADY_DID
+	mosix_obtain_registers(ALL_REGISTERS);
+#endif /* CONFIG_MOSIX_NO_NEED__ALL_CALLERS_ALREADY_DID */
 	tmp = 0;
 	__asm__("movl %%gs,%0" : "=r"(tmp): "0"(tmp));
 	err |= __put_user(tmp, (unsigned int *)&sc->gs);
@@ -385,12 +471,19 @@
 	return (void *)((esp - frame_size) & -8ul);
 }
 
+#ifdef CONFIG_MOSIX
+void setup_frame(int sig, struct k_sigaction *ka,
+#else
 static void setup_frame(int sig, struct k_sigaction *ka,
+#endif /* CONFIG_MOSIX */
 			sigset_t *set, struct pt_regs * regs)
 {
 	struct sigframe *frame;
 	int err = 0;
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(ALL_REGISTERS);
+#endif /* CONFIG_MOSIX */
 	frame = get_sigframe(ka, regs, sizeof(*frame));
 
 	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
@@ -455,12 +548,19 @@
 	force_sig(SIGSEGV, current);
 }
 
+#ifdef CONFIG_MOSIX
+void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
+#else
 static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
+#endif /* CONFIG_MOSIX */
 			   sigset_t *set, struct pt_regs * regs)
 {
 	struct rt_sigframe *frame;
 	int err = 0;
 
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(ALL_REGISTERS);
+#endif /* CONFIG_MOSIX */
 	frame = get_sigframe(ka, regs, sizeof(*frame));
 
 	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
@@ -538,6 +638,10 @@
 handle_signal(unsigned long sig, struct k_sigaction *ka,
 	      siginfo_t *info, sigset_t *oldset, struct pt_regs * regs)
 {
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(
+	   BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip));
+#endif /* CONFIG_MOSIX */
 	/* Are we from a system call? */
 	if (regs->orig_eax >= 0) {
 		/* If so, check system call restarting.. */
@@ -559,6 +663,11 @@
 	}
 
 	/* Set up the stack frame */
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		mosix_deputy_setup_frame(sig, ka, *info, oldset);
+	else
+#endif /* CONFIG_MOSIX */
 	if (ka->sa.sa_flags & SA_SIGINFO)
 		setup_rt_frame(sig, ka, info, oldset, regs);
 	else
@@ -586,6 +695,11 @@
 	siginfo_t info;
 	struct k_sigaction *ka;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DREMOTE)
+		return(0);
+#endif /* CONFIG_MOSIX */
+
 	/*
 	 * We want the common case to go fast, which
 	 * is why we may in certain cases get here from
@@ -611,6 +725,10 @@
 		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
 			/* Let the debugger run.  */
 			current->exit_code = signr;
+#ifdef CONFIG_MOSIX
+			if(current->mosix.dflags & DDEPUTY)
+				mosix_deputy_rusage(0);
+#endif /* CONFIG_MOSIX */
 			current->state = TASK_STOPPED;
 			notify_parent(current, SIGCHLD);
 			schedule();
@@ -668,6 +786,10 @@
 
 			case SIGSTOP: {
 				struct signal_struct *sig;
+#ifdef CONFIG_MOSIX
+				if(current->mosix.dflags & DDEPUTY)
+					mosix_deputy_rusage(0);
+#endif /* CONFIG_MOSIX */
 				current->state = TASK_STOPPED;
 				current->exit_code = signr;
 				sig = current->p_pptr->sig;
@@ -706,6 +828,10 @@
 	}
 
 	/* Did we come from a system call? */
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(
+	   BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip));
+#endif /* CONFIG_MOSIX */
 	if (regs->orig_eax >= 0) {
 		/* Restart the system call - no handlers present */
 		if (regs->eax == -ERESTARTNOHAND ||
diff -ruN linux-2.4.16/arch/i386/kernel/sys_i386.c linux-2.4.16-mosix/arch/i386/kernel/sys_i386.c
--- linux-2.4.16/arch/i386/kernel/sys_i386.c	Mon Mar 19 22:35:09 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/sys_i386.c	Sun Dec 23 13:56:53 2001
@@ -22,6 +22,10 @@
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * sys_pipe() is the normal C calling standard for creating
  * a pipe. It's not the way Unix traditionally does this, though.
@@ -55,12 +59,20 @@
 			goto out;
 	}
 
+#ifdef CONFIG_MOSIX
+	error = do_mmap_pgoff_down(file, addr, len, prot, flags, pgoff);
+#else
 	down_write(&current->mm->mmap_sem);
 	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 	up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 
 	if (file)
 		fput(file);
+#ifdef CONFIG_MOSIX_DFSA
+	if(file && file_count(file) > 1)
+		dfsa_touch_file(fd);
+#endif /* CONFIG_MOSIX_DFSA */
 out:
 	return error;
 }
diff -ruN linux-2.4.16/arch/i386/kernel/traps.c linux-2.4.16-mosix/arch/i386/kernel/traps.c
--- linux-2.4.16/arch/i386/kernel/traps.c	Sun Sep 30 21:26:08 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/traps.c	Sun Dec 23 13:56:53 2001
@@ -50,6 +50,11 @@
 #include <linux/irq.h>
 #include <linux/module.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#include <asm/processor.h>
+#endif /* CONFIG_MOSIX */
+
 asmlinkage int system_call(void);
 asmlinkage void lcall7(void);
 asmlinkage void lcall27(void);
@@ -248,6 +253,12 @@
 	show_registers(regs);
 	bust_spinlocks(0);
 	spin_unlock_irq(&die_lock);
+#ifdef CONFIG_MOSIX_UDB
+	{
+		extern void mosix_debugger(char *);
+		mosix_debugger("die");
+	}
+#endif /* CONFIG_MOSIX_UDB */
 	do_exit(SIGSEGV);
 }
 
@@ -336,10 +347,16 @@
 }
 
 DO_VM86_ERROR_INFO( 0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->eip)
+#ifndef CONFIG_MOSIX_UDB
 DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
+#endif /* CONFIG_MOSIX_UDB */
 DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
 DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds)
+#ifdef CONFIG_MOSIX
+DO_ERROR_INFO( 6, SIGILL,  "invalid operand", real_invalid_op, ILL_ILLOPN, regs->eip)
+#else
 DO_ERROR_INFO( 6, SIGILL,  "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
+#endif /* CONFIG_MOSIX */
 DO_VM86_ERROR( 7, SIGSEGV, "device not available", device_not_available)
 DO_ERROR( 8, SIGSEGV, "double fault", double_fault)
 DO_ERROR( 9, SIGFPE,  "coprocessor segment overrun", coprocessor_segment_overrun)
@@ -356,6 +373,24 @@
 	if (!(regs->xcs & 3))
 		goto gp_in_kernel;
 
+#ifdef CONFIG_MOSIX
+	if(error_code == 0 && (current->mosix.dflags & DREMOTE))
+	{
+		short code;
+		u64 clk;
+
+		if(!get_user(code, (short *)regs->eip) &&
+			code == 0x310F) /* RDTSC */
+		{
+			clk = mosix_remote_tsc();
+			regs->eax = clk & 0xffffffff;
+			regs->edx = clk >> 32;
+			regs->eip += 2;
+			return;
+		}
+		mosix_go_home(0);
+	}
+#endif /* CONFIG_MOSIX */
 	current->thread.error_code = error_code;
 	current->thread.trap_no = 13;
 	force_sig(SIGSEGV, current);
@@ -452,6 +487,41 @@
 	inb(0x71);		/* dummy */
 }
 
+#ifdef CONFIG_MOSIX_UDB
+asmlinkage void do_int3(struct pt_regs * regs, long error_code)
+{
+	extern int udb_breakpoint(struct pt_regs *regs);
+
+	if (!(regs->eflags & VM_MASK) && (regs->xcs & 3) != 3 &&
+							udb_breakpoint(regs))
+		return;
+	do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
+}
+#endif /* CONFIG_MOSIX_UDB */
+
+#ifdef CONFIG_MOSIX
+static __u32 user_features[NCAPINTS] = USER_MODE_FEATURES;
+
+asmlinkage void
+do_invalid_op(struct pt_regs * regs, long error_code)
+{
+	if((current->mosix.dflags & DREMOTE) && !(regs->eflags & VM_MASK) &&
+							(regs->xcs & 3) == 3)
+	{
+		int i;
+
+		for(i = 0 ; i < NCAPINTS ; i++)
+		if(current->mosix.features[i] & user_features[i] &
+					~boot_cpu_data.x86_capability[i])
+		{
+			mosix_go_home(0);	/* no return if successful */
+			break;
+		}
+	}
+	do_real_invalid_op(regs, error_code);
+}
+#endif /* CONFIG_MOSIX */
+
 /*
  * Our handling of the processor debug registers is non-trivial.
  * We do not clear them on entry and exit from the kernel. Therefore
diff -ruN linux-2.4.16/arch/i386/kernel/vm86.c linux-2.4.16-mosix/arch/i386/kernel/vm86.c
--- linux-2.4.16/arch/i386/kernel/vm86.c	Sat Jul  7 03:05:07 2001
+++ linux-2.4.16-mosix/arch/i386/kernel/vm86.c	Sun Dec 23 13:56:53 2001
@@ -17,6 +17,10 @@
 #include <asm/pgalloc.h>
 #include <asm/io.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /*
  * Known problems:
  *
@@ -69,6 +73,10 @@
 	struct pt_regs *ret;
 	unsigned long tmp;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DREMOTE)
+		panic("remote save_v86");
+#endif /* CONFIG_MOSIX */
 	if (!current->thread.vm86_info) {
 		printk("no vm86_info: BAD\n");
 		do_exit(SIGSEGV);
@@ -83,9 +91,18 @@
 		do_exit(SIGSEGV);
 	}
 	tss = init_tss + smp_processor_id();
+#ifdef CONFIG_MOSIX
+	lock_mosix();	/* ptrace checks saved_esp0 under the mosix-lock */
+#endif /* CONFIG_MOSIX */
 	tss->esp0 = current->thread.esp0 = current->thread.saved_esp0;
 	current->thread.saved_esp0 = 0;
 	ret = KVM86->regs32;
+#ifdef CONFIG_MOSIX
+	unlock_mosix();
+	task_lock(current);
+	current->mosix.stay &= ~DSTAY_FOR_86;
+	task_unlock(current);
+#endif /* CONFIG_MOSIX */
 	return ret;
 }
 
@@ -136,6 +153,13 @@
 	struct task_struct *tsk;
 	int tmp, ret = -EPERM;
 
+#ifdef CONFIG_MOSIX
+	if(!mosix_go_home_for_reason(1, DSTAY_FOR_86))
+	{
+		ret = -ENOMEM;
+		goto out;
+	}
+#endif /* CONFIG_MOSIX */
 	tsk = current;
 	if (tsk->thread.saved_esp0)
 		goto out;
@@ -193,6 +217,13 @@
 	ret = -EFAULT;
 	if (tmp)
 		goto out;
+#ifdef CONFIG_MOSIX
+	if(!mosix_go_home_for_reason(1, DSTAY_FOR_86))
+	{
+		ret = -ENOMEM;
+		goto out;
+	}
+#endif /* CONFIG_MOSIX */
 	info.regs32 = (struct pt_regs *) &subfunction;
 	info.vm86plus.is_vm86pus = 1;
 	tsk->thread.vm86_info = (struct vm86_struct *)v86;
@@ -245,9 +276,15 @@
  * Save old state, set default return value (%eax) to 0
  */
 	info->regs32->eax = 0;
+#ifdef CONFIG_MOSIX
+	lock_mosix();
+#endif /* CONFIG_MOSIX */
 	tsk->thread.saved_esp0 = tsk->thread.esp0;
 	tss = init_tss + smp_processor_id();
 	tss->esp0 = tsk->thread.esp0 = (unsigned long) &info->VM86_TSS_ESP0;
+#ifdef CONFIG_MOSIX
+	unlock_mosix();
+#endif /* CONFIG_MOSIX */
 
 	tsk->thread.screen_bitmap = info->screen_bitmap;
 	if (info->flags & VM86_SCREEN_BITMAP)
@@ -267,6 +304,11 @@
 
 	regs32 = save_v86_state(regs16);
 	regs32->eax = retval;
+#ifdef CONFIG_MOSIX
+	task_lock(current);
+	current->mosix.stay &= ~DSTAY_FOR_86;
+	task_unlock(current);
+#endif /* CONFIG_MOSIX */
 	__asm__ __volatile__("movl %0,%%esp\n\t"
 		"jmp ret_from_sys_call"
 		: : "r" (regs32), "b" (current));
@@ -602,7 +644,11 @@
 	int ret = 0;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if ((p == tsk) && (p->sig)) {
 			ret = 1;
 			break;
diff -ruN linux-2.4.16/arch/i386/lib/usercopy.c linux-2.4.16-mosix/arch/i386/lib/usercopy.c
--- linux-2.4.16/arch/i386/lib/usercopy.c	Fri Nov  9 23:58:02 2001
+++ linux-2.4.16-mosix/arch/i386/lib/usercopy.c	Sun Dec 23 13:56:53 2001
@@ -99,6 +99,11 @@
 __strncpy_from_user(char *dst, const char *src, long count)
 {
 	long res;
+
+#ifdef CONFIG_MOSIX
+	if(USER_IS_REMOTE)
+		return(deputy_strncpy_from_user(dst, (char *)src, count, 0));
+#endif /* CONFIG_MOSIX */
 	__do_strncpy_from_user(dst, src, count, res);
 	return res;
 }
@@ -107,6 +112,11 @@
 strncpy_from_user(char *dst, const char *src, long count)
 {
 	long res = -EFAULT;
+
+#ifdef CONFIG_MOSIX
+	if(USER_IS_REMOTE)
+		return(deputy_strncpy_from_user(dst, (char *)src, count, 1));
+#endif /* CONFIG_MOSIX */
 	if (access_ok(VERIFY_READ, src, 1))
 		__do_strncpy_from_user(dst, src, count, res);
 	return res;
@@ -141,6 +151,10 @@
 unsigned long
 clear_user(void *to, unsigned long n)
 {
+#ifdef CONFIG_MOSIX
+	if (USER_IS_REMOTE)
+		return(deputy_clear_user(to, n, 1));
+#endif /* CONFIG_MOSIX */
 	if (access_ok(VERIFY_WRITE, to, n))
 		__do_clear_user(to, n);
 	return n;
@@ -149,6 +163,10 @@
 unsigned long
 __clear_user(void *to, unsigned long n)
 {
+#ifdef CONFIG_MOSIX
+	if (USER_IS_REMOTE)
+		return(deputy_clear_user(to, n, 0));
+#endif /* CONFIG_MOSIX */
 	__do_clear_user(to, n);
 	return n;
 }
@@ -164,6 +182,10 @@
 	unsigned long mask = -__addr_ok(s);
 	unsigned long res, tmp;
 
+#ifdef CONFIG_MOSIX
+	if(USER_IS_REMOTE)
+		return(deputy_strnlen_user((char *)s, n));
+#endif /* CONFIG_MOSIX */
 	__asm__ __volatile__(
 		"	testl %0, %0\n"
 		"	jz 3f\n"
diff -ruN linux-2.4.16/arch/i386/mm/fault.c linux-2.4.16-mosix/arch/i386/mm/fault.c
--- linux-2.4.16/arch/i386/mm/fault.c	Wed Oct 10 00:13:03 2001
+++ linux-2.4.16-mosix/arch/i386/mm/fault.c	Sun Dec 23 13:56:53 2001
@@ -25,6 +25,10 @@
 #include <asm/pgalloc.h>
 #include <asm/hardirq.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 extern void die(const char *,struct pt_regs *,long);
 
 extern int console_loglevel;
@@ -40,6 +44,10 @@
 	if (!size)
 		return 1;
 
+#ifdef CONFIG_MOSIX
+	if(USER_IS_REMOTE)
+		return(deputy_verify_write((void *)addr, size));
+#endif /* CONFIG_MOSIX */
 	vma = find_vma(current->mm, start);
 	if (!vma)
 		goto bad_area;
@@ -136,6 +144,10 @@
 asmlinkage void do_invalid_op(struct pt_regs *, unsigned long);
 extern unsigned long idt;
 
+#ifdef CONFIG_MOSIX_UDB
+int debug_fixup = 0;
+#endif /* CONFIG_MOSIX_UDB */
+
 /*
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
@@ -263,6 +275,10 @@
 	 */
 	if (regs->eflags & VM_MASK) {
 		unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
+#ifdef CONFIG_MOSIX_DIAG
+		if(!(current->mosix.stay & DSTAY_FOR_86))
+			panic("VM_MASK without STAY");
+#endif /* CONFIG_MOSIX_DIAG */
 		if (bit < 32)
 			tsk->thread.screen_bitmap |= 1 << bit;
 	}
@@ -307,6 +323,10 @@
 	/* Are we prepared to handle this kernel fault?  */
 	if ((fixup = search_exception_table(regs->eip)) != 0) {
 		regs->eip = fixup;
+#ifdef CONFIG_MOSIX_UDB
+		if(debug_fixup)
+			mosix_debugger("fixup");
+#endif /* CONFIG_MOSIX_UDB */
 		return;
 	}
 
diff -ruN linux-2.4.16/drivers/char/Makefile linux-2.4.16-mosix/drivers/char/Makefile
--- linux-2.4.16/drivers/char/Makefile	Sun Nov 11 20:09:32 2001
+++ linux-2.4.16-mosix/drivers/char/Makefile	Sun Dec 23 13:56:53 2001
@@ -137,7 +137,12 @@
   obj-$(CONFIG_PCI) += keyboard.o $(KEYMAP)
 endif
 
+ifdef CONFIG_MOSIX_UDB
+obj-y += sysrq.o
+else
 obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
+endif
+
 obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
 obj-$(CONFIG_ROCKETPORT) += rocket.o
 obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
diff -ruN linux-2.4.16/drivers/char/console.c linux-2.4.16-mosix/drivers/char/console.c
--- linux-2.4.16/drivers/char/console.c	Mon Oct 15 23:00:43 2001
+++ linux-2.4.16-mosix/drivers/char/console.c	Sun Dec 23 13:56:53 2001
@@ -2169,6 +2169,32 @@
 	clear_bit(0, &printing);
 }
 
+#ifdef CONFIG_MOSIX_UDB
+int
+vt_console_read(struct console *co, const char *into, unsigned cnt)
+{
+	extern int keyboard_has_any(void);
+	extern void keyboard_manual_mode(int);
+	extern char keyboard_readch(void);
+	int n = 0;
+
+	keyboard_manual_mode(1);
+	while(!keyboard_has_any());
+	while(cnt--)
+	{
+		((char *)into)[n++] = keyboard_readch();
+		unblank_screen();
+		if(!keyboard_has_any())
+		{
+			keyboard_manual_mode(0);
+			return(n);
+		}
+	}
+	keyboard_manual_mode(0);
+	return(n);
+}
+#endif /* CONFIG_MOSIX_UDB */
+
 static kdev_t vt_console_device(struct console *c)
 {
 	return MKDEV(TTY_MAJOR, c->index ? c->index : fg_console + 1);
@@ -2177,6 +2203,9 @@
 struct console vt_console_driver = {
 	name:		"tty",
 	write:		vt_console_print,
+#ifdef CONFIG_MOSIX_UDB
+	read:		vt_console_read,
+#endif /* CONFIG_MOSIX_UDB */
 	device:		vt_console_device,
 	wait_key:	keyboard_wait_for_keypress,
 	unblank:	unblank_screen,
diff -ruN linux-2.4.16/drivers/char/drm/i810_dma.c linux-2.4.16-mosix/drivers/char/drm/i810_dma.c
--- linux-2.4.16/drivers/char/drm/i810_dma.c	Wed Aug  8 19:42:15 2001
+++ linux-2.4.16-mosix/drivers/char/drm/i810_dma.c	Sun Dec 23 13:56:53 2001
@@ -36,6 +36,10 @@
 #include "i810_drv.h"
 #include <linux/interrupt.h>	/* For task queue support */
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /* in case we don't have a 2.3.99-pre6 kernel or later: */
 #ifndef VM_DONTCOPY
 #define VM_DONTCOPY 0
@@ -181,6 +185,13 @@
 
 	if(buf_priv->currently_mapped == I810_BUF_MAPPED) return -EINVAL;
 
+#ifdef CONFIG_MOSIX
+	if(!mosix_go_home(1))
+	{
+		printk("i810_map_buffer: Cannot map while away!\n");
+		return(-ENOMEM);
+	}
+#endif /* CONFIG_MOSIX */
 	if(VM_DONTCOPY != 0) {
 #if LINUX_VERSION_CODE <= 0x020402
 		down( &current->mm->mmap_sem );
@@ -222,6 +233,13 @@
 	if(VM_DONTCOPY != 0) {
 		if(buf_priv->currently_mapped != I810_BUF_MAPPED)
 			return -EINVAL;
+#ifdef CONFIG_MOSIX
+		{
+			extern asmlinkage long sys_munmap(unsigned long,size_t);
+			retcode = sys_munmap((unsigned long)buf_priv->virtual,
+						(size_t) buf->total);
+		}
+#else
 #if LINUX_VERSION_CODE <= 0x020402
 		down( &current->mm->mmap_sem );
 #else
@@ -240,6 +258,7 @@
 #else
 		up_write( &current->mm->mmap_sem );
 #endif
+#endif /* CONFIG_MOSIX */
 	}
    	buf_priv->currently_mapped = I810_BUF_UNMAPPED;
    	buf_priv->virtual = 0;
diff -ruN linux-2.4.16/drivers/char/keyboard.c linux-2.4.16-mosix/drivers/char/keyboard.c
--- linux-2.4.16/drivers/char/keyboard.c	Tue Sep 18 23:39:51 2001
+++ linux-2.4.16-mosix/drivers/char/keyboard.c	Sun Dec 23 13:56:53 2001
@@ -65,6 +65,61 @@
 EXPORT_SYMBOL(handle_scancode);
 EXPORT_SYMBOL(kbd_ledfunc);
 
+#ifdef CONFIG_MOSIX_UDB
+#define	MANQ	8
+char manq[MANQ];
+static int man_in, man_out;
+static int manual_mode;
+
+void
+keyboard_manual_mode(int x)
+{
+	if(x)
+		manual_mode++;
+	else
+	{
+		if(manual_mode)
+			manual_mode--;
+		man_in = man_out = 0;
+	}
+}
+
+int
+in_manual_mode(void)
+{
+	return(manual_mode);
+}
+
+int
+keyboard_has_any(void)
+{
+	extern void keyboard_like_interrupt(void);
+
+	keyboard_like_interrupt();
+	return(man_in != man_out);
+}
+
+char
+keyboard_readch(void)
+{
+	char c;
+
+	if(man_in == man_out)
+		return('\0');
+	c = manq[man_out];
+	man_out = (man_out + 1) % MANQ;
+	return(c);
+}
+
+void
+keyboard_putch(char ch)
+{
+	manq[man_in++] = ch;
+	man_in %= MANQ;
+}
+
+#endif /* CONFIG_MOSIX_UDB */
+
 extern void ctrl_alt_del(void);
 
 DECLARE_WAIT_QUEUE_HEAD(keypress_wait);
@@ -129,12 +184,19 @@
 	num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose,
 	SAK, decr_console, incr_console, spawn_console, bare_num;
 
+#ifdef CONFIG_MOSIX_UDB
+static void_fn call_udb;
+#endif /* CONFIG_MOSIX_UDB */
+
 static void_fnp spec_fn_table[] = {
 	do_null,	enter,		show_ptregs,	show_mem,
 	show_state,	send_intr,	lastcons,	caps_toggle,
 	num,		hold,		scroll_forw,	scroll_back,
 	boot_it,	caps_on,	compose,	SAK,
 	decr_console,	incr_console,	spawn_console,	bare_num
+#ifdef CONFIG_MOSIX_UDB
+	, call_udb
+#endif /* CONFIG_MOSIX_UDB */
 };
 
 #define SPECIALS_ALLOWED_IN_RAW_MODE (1 << KVAL(K_SAK))
@@ -279,6 +341,9 @@
 	 */
 	if (!rep ||
 	    (vc_kbd_mode(kbd,VC_REPEAT) && tty &&
+#ifdef CONFIG_MOSIX_UDB
+		!manual_mode &&
+#endif /* CONFIG_MOSIX_UDB */
 	     (L_ECHO(tty) || (tty->driver.chars_in_buffer(tty) == 0)))) {
 		u_short keysym;
 		u_char type;
@@ -334,6 +399,13 @@
 
 void put_queue(int ch)
 {
+#ifdef CONFIG_MOSIX_UDB
+	if(manual_mode)
+	{
+		keyboard_putch((char)ch);
+		return;
+	}
+#endif /* CONFIG_MOSIX_UDB */
 	wake_up(&keypress_wait);
 	if (tty) {
 		tty_insert_flip_char(tty, ch, 0);
@@ -814,6 +886,14 @@
 	}
 }
 
+#ifdef CONFIG_MOSIX_UDB
+static void call_udb(void)
+{
+	extern void mosix_debugger(char *);
+	mosix_debugger("Keyboard");
+}
+#endif /* CONFIG_MOSIX_UDB */
+
 /*
  * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
  * or (ii) whatever pattern of lights people want to show using KDSETLED,
@@ -940,5 +1020,8 @@
 	
 	pm_kbd = pm_register(PM_SYS_DEV, PM_SYS_KBC, pm_kbd_request_override);
 
+#ifdef CONFIG_MOSIX_UDB
+	key_maps[2][69] = key_maps[8][69] = K_DEBUGGER|0xf000;
+#endif /* CONFIG_MOSIX_UDB */
 	return 0;
 }
diff -ruN linux-2.4.16/drivers/char/mem.c linux-2.4.16-mosix/drivers/char/mem.c
--- linux-2.4.16/drivers/char/mem.c	Sat Sep 15 00:04:07 2001
+++ linux-2.4.16-mosix/drivers/char/mem.c	Sun Dec 23 13:56:53 2001
@@ -407,6 +407,9 @@
 	left = count;
 
 	/* do we want to be clever? Arbitrary cut-off */
+#ifdef CONFIG_MOSIX
+	if(!(current->mosix.dflags & DDEPUTY))
+#endif /* CONFIG_MOSIX */
 	if (count >= PAGE_SIZE*4) {
 		unsigned long partial;
 
@@ -484,6 +487,62 @@
 	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }
 
+#ifdef CONFIG_MOSIX
+static ssize_t read_fun(struct file * file, char * buf, 
+			 size_t count, loff_t *ppos)
+{
+	unsigned long i, n = 0;
+
+	if (!count)
+		return 0;
+
+	if (!access_ok(VERIFY_WRITE, buf, count))
+		return -EFAULT;
+
+	while(count)
+	{
+		i = (count > 2*PAGE_SIZE ? 2*PAGE_SIZE : count);
+		if(copy_to_user(buf, current, i) < 0)
+			return(EFAULT);
+		buf += i;
+		count -= i;
+		n += i;
+	}
+	return(n);
+}
+
+static ssize_t write_fun(struct file * file, const char * buf, 
+			 size_t count, loff_t *ppos)
+{
+	unsigned long i, n = 0;
+	char *page;
+
+	if (!count)
+		return 0;
+
+	if (!access_ok(VERIFY_READ, buf, count))
+		return -EFAULT;
+
+	if (!(page = (char *)__get_free_page(GFP_KERNEL)))
+		return(-ENOMEM);
+
+	while(count)
+	{
+		i = (count > PAGE_SIZE ? PAGE_SIZE : count);
+		if(copy_from_user(page, (char *)buf, i) < 0)
+		{
+			free_page((long)page);
+			return(EFAULT);
+		}
+		buf += i;
+		count -= i;
+		n += i;
+	}
+	free_page((long)page);
+	return(n);
+}
+#endif /* CONFIG_MOSIX */
+
 #define mmap_kmem	mmap_mem
 #define zero_lseek	null_lseek
 #define full_lseek      null_lseek
@@ -536,6 +595,13 @@
 	write:		write_full,
 };
 
+#ifdef CONFIG_MOSIX
+static struct file_operations fun_fops = {
+	read: read_fun,
+	write: write_fun,
+};
+#endif /* CONFIG_MOSIX */
+
 static int memory_open(struct inode * inode, struct file * filp)
 {
 	switch (MINOR(inode->i_rdev)) {
@@ -565,6 +631,11 @@
 		case 9:
 			filp->f_op = &urandom_fops;
 			break;
+#ifdef CONFIG_MOSIX
+		case 10:
+			filp->f_op = &fun_fops;
+			break;
+#endif /* CONFIG_MOSIX */
 		default:
 			return -ENXIO;
 	}
diff -ruN linux-2.4.16/drivers/char/pc_keyb.c linux-2.4.16-mosix/drivers/char/pc_keyb.c
--- linux-2.4.16/drivers/char/pc_keyb.c	Sat Nov 10 00:01:21 2001
+++ linux-2.4.16-mosix/drivers/char/pc_keyb.c	Sun Dec 23 13:56:53 2001
@@ -525,6 +525,27 @@
 	spin_unlock_irq(&kbd_controller_lock);
 }
 
+
+#ifdef CONFIG_MOSIX_UDB
+void keyboard_like_interrupt(void)
+{
+	unsigned char status;
+	unsigned char scancode;
+
+	status = kbd_read_status();
+	if(!(status & KBD_STAT_OBF))
+		return;
+	status = kbd_read_status();
+	scancode = kbd_read_input();
+
+	if (do_acknowledge(scancode))
+		handle_scancode(scancode, !(scancode & 0x80));
+	if ((status & KBD_STAT_OBF) && do_acknowledge(scancode))
+		handle_scancode(scancode, !(scancode & 0x80));
+	tasklet_schedule(&keyboard_tasklet);
+}
+#endif /* CONFIG_MOSIX_UDB */
+
 /*
  * send_data sends a character to the keyboard and waits
  * for an acknowledge, possibly retrying if asked to. Returns
diff -ruN linux-2.4.16/drivers/char/serial.c linux-2.4.16-mosix/drivers/char/serial.c
--- linux-2.4.16/drivers/char/serial.c	Sat Nov 10 00:12:55 2001
+++ linux-2.4.16-mosix/drivers/char/serial.c	Sun Dec 23 13:56:53 2001
@@ -231,6 +231,10 @@
 #include <asm/irq.h>
 #include <asm/bitops.h>
 
+#ifdef CONFIG_MOSIX_UDB
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX_UDB */
+
 #ifdef CONFIG_MAC_SERIAL
 #define SERIAL_DEV_OFFSET	2
 #else
@@ -818,6 +822,10 @@
 	if (!info)
 		return;
 
+#if defined(CONFIG_MOSIX_UDB) && defined(CONFIG_SERIAL_CONSOLE)
+	if (serial_inp(info, UART_LSR) & (UART_LSR_BI | UART_LSR_FE))
+		mosix_debugger("user request 1");
+#endif /* CONFIG_MOSIX_UDB && CONFIG_SERIAL_CONSOLE */
 #ifdef CONFIG_SERIAL_MULTIPORT	
 	multi = &rs_multiport[irq];
 	if (multi->port_monitor)
@@ -892,7 +900,15 @@
 #endif
 
 	info = IRQ_ports[irq];
+#if defined(CONFIG_MOSIX_UDB) && defined(CONFIG_SERIAL_CONSOLE)
+	if (!info)
+		return;
+	if (serial_inp(info, UART_LSR) & (UART_LSR_BI | UART_LSR_FE))
+		mosix_debugger("user request 2");
+	else if (!info->tty)
+#else
 	if (!info || !info->tty)
+#endif /* CONFIG_MOSIX_UDB */
 		return;
 
 #ifdef CONFIG_SERIAL_MULTIPORT	
@@ -952,6 +968,10 @@
 	info = IRQ_ports[irq];
 	if (!info)
 		return;
+#if defined(CONFIG_MOSIX_UDB) && defined(CONFIG_SERIAL_CONSOLE)
+	if (serial_inp(info, UART_LSR) & (UART_LSR_BI | UART_LSR_FE))
+		mosix_debugger("user request 3");
+#endif /* CONFIG_MOSIX_UDB && CONFIG_SERIAL_CONSOLE */
 	multi = &rs_multiport[irq];
 	if (!multi->port1) {
 		/* Should never happen */
@@ -5854,6 +5874,44 @@
 	return c;
 }
 
+#ifdef CONFIG_MOSIX_UDB
+#ifdef CONFIG_SERIAL_CONSOLE
+static int serial_console_read(struct console *co, const char *into, unsigned cnt)
+{
+	int n = 0;
+	struct serial_state *ser = rs_table + co->index;
+	int lsr;
+	int c;
+	int ier = inb(ser->port + UART_IER);
+
+	outb(0x00, ser->port + UART_IER);
+	while(cnt)
+	{
+		do {
+			lsr = inb(ser->port + UART_LSR);
+		} while (!n && !(lsr & UART_LSR_DR));
+		if(!(lsr & UART_LSR_DR))
+			break;
+		c = inb(ser->port + UART_RX);
+		if(lsr & (UART_LSR_BI | UART_LSR_FE))
+		{
+			mosix_debugger("recursive break");
+			continue;
+		}
+		if (lsr & (UART_LSR_PE | UART_LSR_FE | UART_LSR_OE))
+		{
+			printk("Bad input-char, status=0x%x\n", lsr);
+			continue;
+		}
+		((char *)into)[n++] = c;
+		cnt--;
+	}
+	outb(ier, ser->port + UART_IER);
+	return(n);
+}
+#endif /* CONFIG_SERIAL_CONSOLE */
+#endif /* CONFIG_MOSIX_UDB */
+
 static kdev_t serial_console_device(struct console *c)
 {
 	return MKDEV(TTY_MAJOR, 64 + c->index);
@@ -5993,6 +6051,9 @@
 static struct console sercons = {
 	name:		"ttyS",
 	write:		serial_console_write,
+#ifdef CONFIG_MOSIX_UDB
+	read:		serial_console_read,
+#endif /* CONFIG_MOSIX_UDB */
 	device:		serial_console_device,
 	wait_key:	serial_console_wait_key,
 	setup:		serial_console_setup,
diff -ruN linux-2.4.16/drivers/char/sysrq.c linux-2.4.16-mosix/drivers/char/sysrq.c
--- linux-2.4.16/drivers/char/sysrq.c	Tue Oct  2 18:20:37 2001
+++ linux-2.4.16-mosix/drivers/char/sysrq.c	Sun Dec 23 13:56:53 2001
@@ -162,6 +162,13 @@
 		file_list_unlock();
 		DQUOT_OFF(sb);
 		fsync_dev(sb->s_dev);
+#ifdef CONFIG_MOSIX_UDB
+		if (sb->s_op->write_super && sb->s_dirt)
+			sb->s_op->write_super(sb);
+		if (sb->s_op->put_super)
+			sb->s_op->put_super(sb);
+		fsync_dev(sb->s_dev);
+#endif /* CONFIG_MOSIX_UDB */
 		flags = MS_RDONLY;
 		if (sb->s_op && sb->s_op->remount_fs) {
 			ret = sb->s_op->remount_fs(sb, &flags, NULL);
@@ -288,7 +295,11 @@
 {
 	struct task_struct *p;
 
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if (p->mm) { /* Not swapper nor kernel thread */
 			if (p->pid == 1 && even_init)
 				/* Ugly hack to kill init */
diff -ruN linux-2.4.16/drivers/char/tty_io.c linux-2.4.16-mosix/drivers/char/tty_io.c
--- linux-2.4.16/drivers/char/tty_io.c	Sat Nov  3 03:26:17 2001
+++ linux-2.4.16-mosix/drivers/char/tty_io.c	Sun Dec 23 13:56:53 2001
@@ -497,7 +497,11 @@
 	}
 	
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+ 	for_each_local_task(p) {
+#else
  	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if ((tty->session > 0) && (p->session == tty->session) &&
 		    p->leader) {
 			send_sig(SIGHUP,p,1);
@@ -595,7 +599,11 @@
 	tty->pgrp = -1;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p)
+#else
 	for_each_task(p)
+#endif /* CONFIG_MOSIX */
 	  	if (p->session == current->session)
 			p->tty = NULL;
 	read_unlock(&tasklist_lock);
@@ -1226,7 +1234,11 @@
 		struct task_struct *p;
 
 		read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+		for_each_local_task(p) {
+#else
 		for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 			if (p->tty == tty || (o_tty && p->tty == o_tty))
 				p->tty = NULL;
 		}
@@ -1566,7 +1578,11 @@
 			struct task_struct *p;
 
 			read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+			for_each_local_task(p)
+#else
 			for_each_task(p)
+#endif /* CONFIG_MOSIX */
 				if (p->tty == tty)
 					p->tty = NULL;
 			read_unlock(&tasklist_lock);
@@ -1839,7 +1855,11 @@
 	if (tty->driver.flush_buffer)
 		tty->driver.flush_buffer(tty);
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if ((p->tty == tty) ||
 		    ((session > 0) && (p->session == session))) {
 			send_sig(SIGKILL, p, 1);
diff -ruN linux-2.4.16/drivers/char/vt.c linux-2.4.16-mosix/drivers/char/vt.c
--- linux-2.4.16/drivers/char/vt.c	Fri Nov 16 20:08:28 2001
+++ linux-2.4.16-mosix/drivers/char/vt.c	Sun Dec 23 13:56:53 2001
@@ -221,6 +221,10 @@
 			key_map[0] = U(K_ALLOCATED);
 			for (j = 1; j < NR_KEYS; j++)
 				key_map[j] = U(K_HOLE);
+#ifdef CONFIG_MOSIX_UDB
+			if(s == 2 || s == 8)
+				key_map[69] = K_DEBUGGER|0xf000;
+#endif /* CONFIG_MOSIX_UDB */
 			keymap_count++;
 		}
 		ov = U(key_map[i]);
@@ -232,6 +236,10 @@
 		if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN))
 			return -EPERM;
 		key_map[i] = U(v);
+#ifdef CONFIG_MOSIX_UDB
+		if(i == 69 && (s == 2 || s == 8))
+			key_map[i] = K_DEBUGGER|0xf000;
+#endif /* CONFIG_MOSIX_UDB */
 		if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT))
 			compute_shiftstate();
 		break;
diff -ruN linux-2.4.16/drivers/scsi/cpqfcTSworker.c linux-2.4.16-mosix/drivers/scsi/cpqfcTSworker.c
--- linux-2.4.16/drivers/scsi/cpqfcTSworker.c	Thu Oct 25 22:53:50 2001
+++ linux-2.4.16-mosix/drivers/scsi/cpqfcTSworker.c	Sun Dec 23 13:56:53 2001
@@ -193,6 +193,9 @@
   { 
     current->fs = fs;
     atomic_inc(&fs->count);
+#ifdef CONFIG_MOSIX
+    atomic_inc(&fs->users);
+#endif /* CONFIG_MOSIX */
   }
 
   siginitsetinv(&current->blocked, SHUTDOWN_SIGS);
diff -ruN linux-2.4.16/drivers/sgi/char/graphics.c linux-2.4.16-mosix/drivers/sgi/char/graphics.c
--- linux-2.4.16/drivers/sgi/char/graphics.c	Thu Oct 11 18:43:30 2001
+++ linux-2.4.16-mosix/drivers/sgi/char/graphics.c	Sun Dec 23 13:56:53 2001
@@ -152,11 +152,17 @@
 		 * sgi_graphics_mmap
 		 */
 		disable_gconsole ();
+#ifdef CONFIG_MOSIX
+		r = do_mmap_down (file, (unsigned long)vaddr,
+			     cards[board].g_regs_size, PROT_READ|PROT_WRITE,
+			     MAP_FIXED|MAP_PRIVATE, 0);
+#else
 		down_write(&current->mm->mmap_sem);
 		r = do_mmap (file, (unsigned long)vaddr,
 			     cards[board].g_regs_size, PROT_READ|PROT_WRITE,
 			     MAP_FIXED|MAP_PRIVATE, 0);
 		up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 		if (r)
 			return r;
 	}
diff -ruN linux-2.4.16/drivers/sgi/char/shmiq.c linux-2.4.16-mosix/drivers/sgi/char/shmiq.c
--- linux-2.4.16/drivers/sgi/char/shmiq.c	Mon Aug 27 18:56:31 2001
+++ linux-2.4.16-mosix/drivers/sgi/char/shmiq.c	Sun Dec 23 13:56:53 2001
@@ -285,11 +285,16 @@
 			s = req.arg * sizeof (struct shmqevent) +
 			    sizeof (struct sharedMemoryInputQueue);
 			v = sys_munmap (vaddr, s);
+#ifdef CONFIG_MOSIX
+			do_mmap_down(filp, vaddr, s, PROT_READ | PROT_WRITE,
+			        MAP_PRIVATE|MAP_FIXED, 0);
+#else
 			down_write(&current->mm->mmap_sem);
 			do_munmap(current->mm, vaddr, s);
 			do_mmap(filp, vaddr, s, PROT_READ | PROT_WRITE,
 			        MAP_PRIVATE|MAP_FIXED, 0);
 			up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 			shmiqs[minor].events = req.arg;
 			shmiqs[minor].mapped = 1;
 
diff -ruN linux-2.4.16/drivers/usb/storage/usb.c linux-2.4.16-mosix/drivers/usb/storage/usb.c
--- linux-2.4.16/drivers/usb/storage/usb.c	Sun Nov 11 20:01:32 2001
+++ linux-2.4.16-mosix/drivers/usb/storage/usb.c	Sun Dec 23 13:56:53 2001
@@ -317,6 +317,9 @@
 	exit_files(current);
 	current->files = init_task.files;
 	atomic_inc(&current->files->count);
+#ifdef CONFIG_MOSIX_DFSA
+	atomic_inc(&current->files->users);
+#endif /* CONFIG_MOSIX_DFSA */
 	daemonize();
 
 	/* set our name for identification purposes */
diff -ruN linux-2.4.16/fs/Makefile linux-2.4.16-mosix/fs/Makefile
--- linux-2.4.16/fs/Makefile	Mon Nov 12 19:34:16 2001
+++ linux-2.4.16-mosix/fs/Makefile	Sun Dec 23 13:56:53 2001
@@ -67,6 +67,9 @@
 subdir-$(CONFIG_REISERFS_FS)	+= reiserfs
 subdir-$(CONFIG_DEVPTS_FS)	+= devpts
 subdir-$(CONFIG_SUN_OPENPROMFS)	+= openpromfs
+ifdef CONFIG_MOSIX
+subdir-$(CONFIG_MOSIX_FS)	+= mfs
+endif
 
 
 obj-$(CONFIG_BINFMT_AOUT)	+= binfmt_aout.o
diff -ruN linux-2.4.16/fs/binfmt_aout.c linux-2.4.16-mosix/fs/binfmt_aout.c
--- linux-2.4.16/fs/binfmt_aout.c	Sat Nov  3 03:39:20 2001
+++ linux-2.4.16-mosix/fs/binfmt_aout.c	Sun Dec 23 13:56:53 2001
@@ -29,6 +29,10 @@
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs);
 static int load_aout_library(struct file*);
 static int aout_core_dump(long signr, struct pt_regs * regs, struct file *file);
@@ -108,6 +112,14 @@
 	dump.u_ar0 = (void *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump)));
 #endif
 	dump.signal = signr;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		if(mosix_deputy_dump_thread(&dump))
+			goto end_coredump;
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	dump_thread(regs, &dump);
 
 /* If the size of the dump file exceeds the rlimit, then see what would happen
@@ -189,7 +201,11 @@
  * memory and creates the pointer tables from them, and puts their
  * addresses on the "stack", returning the new stack pointer value.
  */
+#ifdef CONFIG_MOSIX
+unsigned long * create_aout_tables(char * p, struct linux_binprm * bprm)
+#else
 static unsigned long * create_aout_tables(char * p, struct linux_binprm * bprm)
+#endif /* CONFIG_MOSIX */
 {
 	char **argv, **envp;
 	unsigned long * sp;
@@ -258,6 +274,9 @@
 	unsigned long fd_offset;
 	unsigned long rlim;
 	int retval;
+#ifdef CONFIG_MOSIX
+	unsigned long start_stack;
+#endif /* CONFIG_MOSIX */
 
 	ex = *((struct exec *) bprm->buf);		/* exec-header */
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
@@ -296,6 +315,12 @@
 	set_personality(PER_LINUX);
 #endif
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		mosix_deputy_init_aout_mm(&ex);
+	else
+	{
+#endif /* CONFIG_MOSIX */
 	current->mm->end_code = ex.a_text +
 		(current->mm->start_code = N_TXTADDR(ex));
 	current->mm->end_data = ex.a_data +
@@ -305,6 +330,9 @@
 
 	current->mm->rss = 0;
 	current->mm->mmap = NULL;
+#ifdef CONFIG_MOSIX
+	}
+#endif /* CONFIG_MOSIX */
 	compute_creds(bprm);
  	current->flags &= ~PF_FORKNOEXEC;
 #ifdef __sparc__
@@ -349,6 +377,9 @@
 			return error;
 		}
 			 
+#if defined(CONFIG_MOSIX) && !defined(__i386__)
+#error On platforms where "flush_icache_range" is non-empty, code must be adjusted
+#endif /* CONFIG_MOSIX */
 		flush_icache_range(text_addr, text_addr+ex.a_text+ex.a_data);
 	} else {
 		static unsigned long error_time, error_time2;
@@ -379,24 +410,38 @@
 			goto beyond_if;
 		}
 
+#ifdef CONFIG_MOSIX
+		error = do_mmap_down(bprm->file, N_TXTADDR(ex), ex.a_text,
+			PROT_READ | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
+			fd_offset);
+#else
 		down_write(&current->mm->mmap_sem);
 		error = do_mmap(bprm->file, N_TXTADDR(ex), ex.a_text,
 			PROT_READ | PROT_EXEC,
 			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
 			fd_offset);
 		up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 
 		if (error != N_TXTADDR(ex)) {
 			send_sig(SIGKILL, current, 0);
 			return error;
 		}
 
+#ifdef CONFIG_MOSIX
+ 		error = do_mmap_down(bprm->file, N_DATADDR(ex), ex.a_data,
+				PROT_READ | PROT_WRITE | PROT_EXEC,
+				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
+				fd_offset + ex.a_text);
+#else
 		down_write(&current->mm->mmap_sem);
  		error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
 				PROT_READ | PROT_WRITE | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
 				fd_offset + ex.a_text);
 		up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 		if (error != N_DATADDR(ex)) {
 			send_sig(SIGKILL, current, 0);
 			return error;
@@ -405,8 +450,27 @@
 beyond_if:
 	set_binfmt(&aout_format);
 
+#ifdef CONFIG_MOSIX
+	/* if DEPUTY, the REMOTE already did "set_brk" in aout_remote_init_mm */
+	if(!(current->mosix.dflags & DDEPUTY))
+#endif /* CONFIG_MOSIX */
 	set_brk(current->mm->start_brk, current->mm->brk);
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		retval = mosix_deputy_setup_args(SETUP_ARGS_AS_AOUT,
+								&start_stack);
+		if(retval < 0)
+		{
+			send_sig(SIGKILL, current, 0);
+			return(retval);
+		}
+		mosix_obtain_registers(START_THREAD_REGS);
+	}
+	else
+	{
+#endif /* CONFIG_MOSIX */
 	retval = setup_arg_pages(bprm); 
 	if (retval < 0) { 
 		/* Someone check-me: is this error path enough? */ 
@@ -414,17 +478,46 @@
 		return retval;
 	}
 
+#ifdef CONFIG_MOSIX
+	start_stack =
+#endif /* CONFIG_MOSIX */
 	current->mm->start_stack =
 		(unsigned long) create_aout_tables((char *) bprm->p, bprm);
+#ifdef CONFIG_MOSIX
+	}
+#endif /* CONFIG_MOSIX */
 #ifdef __alpha__
 	regs->gp = ex.a_gpvalue;
 #endif
+#ifdef CONFIG_MOSIX
+	start_thread(regs, ex.a_entry, start_stack);
+#else
 	start_thread(regs, ex.a_entry, current->mm->start_stack);
+#endif /* CONFIG_MOSIX */
 	if (current->ptrace & PT_PTRACED)
 		send_sig(SIGTRAP, current, 0);
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+void
+aout_remote_init_mm(struct exec *ex)
+{
+	register struct task_struct *p = current;
+
+	/* in principle we should first check for the "PER_LINUX" personality */
+	/* but then which LINUX does not have it??? */
+
+	p->mm->end_code = ex->a_text + (p->mm->start_code = N_TXTADDR(*ex));
+	p->mm->end_data = ex->a_data + (p->mm->start_data = N_DATADDR(*ex));
+	p->mm->brk = ex->a_bss + (p->mm->start_brk = N_BSSADDR(*ex));
+
+	p->mm->rss = 0;
+	p->mm->mmap = NULL;
+	set_brk(p->mm->start_brk, current->mm->brk);
+}
+#endif /* CONFIG_MOSIX */
+
 static int load_aout_library(struct file *file)
 {
 	struct inode * inode;
@@ -478,12 +571,19 @@
 		goto out;
 	}
 	/* Now use mmap to map the library into memory. */
+#ifdef CONFIG_MOSIX
+	error = do_mmap_down(file, start_addr, ex.a_text + ex.a_data,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
+			N_TXTOFF(ex));
+#else
 	down_write(&current->mm->mmap_sem);
 	error = do_mmap(file, start_addr, ex.a_text + ex.a_data,
 			PROT_READ | PROT_WRITE | PROT_EXEC,
 			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
 			N_TXTOFF(ex));
 	up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 	retval = error;
 	if (error != start_addr)
 		goto out;
diff -ruN linux-2.4.16/fs/binfmt_elf.c linux-2.4.16-mosix/fs/binfmt_elf.c
--- linux-2.4.16/fs/binfmt_elf.c	Sun Oct 21 04:16:59 2001
+++ linux-2.4.16-mosix/fs/binfmt_elf.c	Sun Dec 23 13:56:53 2001
@@ -42,6 +42,10 @@
 
 #include <linux/elf.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs);
 static int load_elf_library(struct file*);
 static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int);
@@ -111,7 +115,12 @@
 		  struct elfhdr * exec,
 		  unsigned long load_addr,
 		  unsigned long load_bias,
+#ifdef CONFIG_MOSIX
+		  unsigned long interp_load_addr, int ibcs,
+		  struct elf_tables_extras *extras)
+#else
 		  unsigned long interp_load_addr, int ibcs)
+#endif /* CONFIG_MOSIX */
 {
 	elf_caddr_t *argv;
 	elf_caddr_t *envp;
@@ -128,8 +137,13 @@
 	 * merely difficult.
 	 */
 
+#ifdef CONFIG_MOSIX
+	hwcap = extras->hwcap;
+	k_platform = extras->platform;
+#else
 	hwcap = ELF_HWCAP;
 	k_platform = ELF_PLATFORM;
+#endif /* CONFIG_MOSIX */
 
 	if (k_platform) {
 		platform_len = strlen(k_platform) + 1;
@@ -176,10 +190,17 @@
 	NEW_AUX_ENT( 6, AT_BASE, interp_load_addr);
 	NEW_AUX_ENT( 7, AT_FLAGS, 0);
 	NEW_AUX_ENT( 8, AT_ENTRY, load_bias + exec->e_entry);
+#ifdef CONFIG_MOSIX
+	NEW_AUX_ENT(9, AT_UID, (elf_addr_t) extras->uid);
+	NEW_AUX_ENT(10, AT_EUID, (elf_addr_t) extras->euid);
+	NEW_AUX_ENT(11, AT_GID, (elf_addr_t) extras->gid);
+	NEW_AUX_ENT(12, AT_EGID, (elf_addr_t) extras->egid);
+#else
 	NEW_AUX_ENT( 9, AT_UID, (elf_addr_t) current->uid);
 	NEW_AUX_ENT(10, AT_EUID, (elf_addr_t) current->euid);
 	NEW_AUX_ENT(11, AT_GID, (elf_addr_t) current->gid);
 	NEW_AUX_ENT(12, AT_EGID, (elf_addr_t) current->egid);
+#endif /* CONFIG_MOSIX */
 #ifdef ARCH_DLINFO
 	/* 
 	 * ARCH_DLINFO must come last so platform specific code can enforce
@@ -228,11 +249,17 @@
 {
 	unsigned long map_addr;
 
+#ifdef CONFIG_MOSIX
+	map_addr = do_mmap_down(filep, ELF_PAGESTART(addr),
+			eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot,
+			type, eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
+#else
 	down_write(&current->mm->mmap_sem);
 	map_addr = do_mmap(filep, ELF_PAGESTART(addr),
 			   eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, type,
 			   eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
 	up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 	return(map_addr);
 }
 
@@ -361,10 +388,23 @@
 	loff_t offset;
 	int retval;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		mosix_deputy_fix_elf_aout_interp(interp_ex->a_bss,
+					interp_ex->a_data, interp_ex->a_text);
+	else
+#endif /* CONFIG_MOSIX */
 	current->mm->end_code = interp_ex->a_text;
 	text_data = interp_ex->a_text + interp_ex->a_data;
+#ifdef CONFIG_MOSIX
+	if(!current->mosix.dflags & DDEPUTY)
+	{
+#endif /* CONFIG_MOSIX */
 	current->mm->end_data = text_data;
 	current->mm->brk = interp_ex->a_bss + text_data;
+#ifdef CONFIG_MOSIX
+	}
+#endif /* CONFIG_MOSIX */
 
 	switch (N_MAGIC(*interp_ex)) {
 	case OMAGIC:
@@ -387,6 +427,12 @@
 	retval = interpreter->f_op->read(interpreter, addr, text_data, &offset);
 	if (retval < 0)
 		goto out;
+#ifdef CONFIG_MOSIX
+#ifndef __i386__
+On platforms where "flush_icache_range" is non-empty,
+it has to distributed and run REMOTELY.
+#endif /* __i386__ */
+#endif /* CONFIG_MOSIX */
 	flush_icache_range((unsigned long)addr,
 	                   (unsigned long)addr + text_data);
 
@@ -428,6 +474,9 @@
 	struct elfhdr interp_elf_ex;
   	struct exec interp_ex;
 	char passed_fileno[6];
+#ifdef CONFIG_MOSIX
+	struct elf_tables_extras extras;
+#endif /* CONFIG_MOSIX */
 	
 	/* Get the exec-header */
 	elf_ex = *((struct elfhdr *) bprm->buf);
@@ -513,6 +562,9 @@
 				struct fs_struct *old_fs = current->fs, *new_fs;
 				get_exec_domain(old_domain);
 				atomic_inc(&old_fs->count);
+#ifdef CONFIG_MOSIX_DFSA
+				atomic_inc(&old_fs->users);
+#endif /* CONFIG_MOSIX_DFSA */
 
 				set_personality(PER_SVR4);
 				interpreter = open_exec(elf_interpreter);
@@ -523,7 +575,11 @@
 				current->exec_domain = old_domain;
 				current->fs = old_fs;
 				put_exec_domain(new_domain);
+#ifdef CONFIG_MOSIX_DFSA
+				put_used_fs_struct(new_fs);
+#else
 				put_fs_struct(new_fs);
+#endif /* CONFIG_MOSIX_DFSA */
 			} else
 #endif
 			{
@@ -595,6 +651,22 @@
 		goto out_free_dentry;
 
 	/* OK, This is the point of no return */
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		current->flags &= ~PF_FORKNOEXEC;
+		elf_entry = (unsigned long) elf_ex.e_entry;
+		SET_PERSONALITY(elf_ex, ibcs2_interpreter);
+		mosix_deputy_setup_args(SETUP_ARGS_AS_ELF, NULL);
+		if(IS_ERR((const unsigned *)bprm->p))
+		{
+			send_sig(SIGKILL, current, 0);
+			return(0);	/* too late for error */
+		}
+	}
+	else
+	{
+#endif /* CONFIG_MOSIX */
 	current->mm->start_data = 0;
 	current->mm->end_data = 0;
 	current->mm->end_code = 0;
@@ -611,6 +683,9 @@
 	current->mm->rss = 0;
 	setup_arg_pages(bprm); /* XXX: check error */
 	current->mm->start_stack = bprm->p;
+#ifdef CONFIG_MOSIX
+	}
+#endif /* CONFIG_MOSIX */
 
 	/* Now we do a little grungy work by mmaping the ELF image into
 	   the correct location in memory.  At this point, we assume that
@@ -724,6 +799,26 @@
 
 	compute_creds(bprm);
 	current->flags &= ~PF_FORKNOEXEC;
+#ifdef CONFIG_MOSIX
+	extras.uid = current->uid;
+	extras.euid = current->euid;
+	extras.gid = current->gid;
+	extras.egid = current->egid;
+	extras.hwcap = ELF_HWCAP;
+	memcpy(extras.platform, ELF_PLATFORM, sizeof(extras.platform));
+	extras.platform[sizeof(extras.platform)-1] = '\0';
+	if(current->mosix.dflags & DDEPUTY)
+	    bprm->p = mosix_deputy_elf_setup((char *)bprm->p,
+		bprm->argc, bprm->envc, &elf_ex,
+		load_addr, load_bias, interp_load_addr,
+		(interpreter_type == INTERPRETER_AOUT ? 0 : 1),
+		interpreter_type == INTERPRETER_AOUT ?
+			strlen(passed_fileno) + 1 : 0,
+		elf_brk, end_code, start_code, start_data, end_data, elf_bss,
+		current->personality, &extras);
+	if(!(current->mosix.dflags & DDEPUTY))	/* must check again! */
+	{
+#endif /* CONFIG_MOSIX */
 	bprm->p = (unsigned long)
 	  create_elf_tables((char *)bprm->p,
 			bprm->argc,
@@ -731,7 +826,12 @@
 			&elf_ex,
 			load_addr, load_bias,
 			interp_load_addr,
+#ifdef CONFIG_MOSIX
+			(interpreter_type == INTERPRETER_AOUT ? 0 : 1),
+								&extras);
+#else
 			(interpreter_type == INTERPRETER_AOUT ? 0 : 1));
+#endif /* CONFIG_MOSIX */
 	/* N.B. passed_fileno might not be initialized? */
 	if (interpreter_type == INTERPRETER_AOUT)
 		current->mm->arg_start += strlen(passed_fileno) + 1;
@@ -765,11 +865,21 @@
 		   Since we do not have the power to recompile these, we
 		   emulate the SVr4 behavior.  Sigh.  */
 		/* N.B. Shouldn't the size here be PAGE_SIZE?? */
+#ifdef CONFIG_MOSIX
+		error = do_mmap_down(NULL, 0, 4096, PROT_READ | PROT_EXEC,
+				MAP_FIXED | MAP_PRIVATE, 0);
+#else
 		down_write(&current->mm->mmap_sem);
 		error = do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE, 0);
 		up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
+	}
+
+#ifdef CONFIG_MOSIX
 	}
+	mosix_obtain_registers(START_THREAD_REGS|ELF_PLAT_INIT_REGS);
+#endif /* CONFIG_MOSIX */
 
 #ifdef ELF_PLAT_INIT
 	/*
@@ -802,6 +912,69 @@
 	goto out;
 }
 
+#ifdef CONFIG_MOSIX
+/*
+ * the following routine is the remote portion of part of "do_load_elf_binary"
+ * and must be updated with changes to the former.
+ */
+unsigned long
+elf_remote_setup(char *p, int argc, int envc, struct elfhdr *exec,
+	unsigned long load_addr, unsigned long load_bias,
+	unsigned long interp_load_addr, int ibcs, int add_arg_start,
+	unsigned long elf_brk, unsigned long end_code, unsigned long start_code,
+	unsigned long start_data, unsigned long end_data, unsigned long elf_bss,
+	unsigned long personality, struct elf_tables_extras *extras)
+{
+	unsigned long ret;
+	struct exec_domain *new_domain = lookup_exec_domain(personality);
+
+	if(!new_domain)
+		mosix_go_home(2);	/* never returns */
+
+	if (current->exec_domain && current->exec_domain->module)
+		__MOD_DEC_USE_COUNT(current->exec_domain->module);
+	current->exec_domain = new_domain;
+	if (new_domain->module)
+		__MOD_INC_USE_COUNT(new_domain->module);
+	ret = (unsigned long)create_elf_tables(p, argc, envc, exec, load_addr,
+		load_bias, interp_load_addr, ibcs, extras);
+	current->mm->arg_start += add_arg_start;
+	current->mm->start_brk = current->mm->brk = elf_brk;
+	current->mm->end_code = end_code;
+	current->mm->start_code = start_code;
+	current->mm->start_data = start_data;
+	current->mm->end_data = end_data;
+	current->mm->start_stack = (unsigned long)p;
+
+	/* Calling set_brk effectively mmaps the pages that we need for the bss and break
+	   sections */
+	set_brk(elf_bss, elf_brk);
+
+	padzero(elf_bss);
+
+#if 0
+	printk("(start_brk) %x\n" , current->mm->start_brk);
+	printk("(end_code) %x\n" , current->mm->end_code);
+	printk("(start_code) %x\n" , current->mm->start_code);
+	printk("(end_data) %x\n" , current->mm->end_data);
+	printk("(start_stack) %x\n" , current->mm->start_stack);
+	printk("(brk) %x\n" , current->mm->brk);
+#endif
+
+	if ( personality == PER_SVR4 )
+	{
+		/* Why this, you ask???  Well SVr4 maps page 0 as read-only,
+		   and some applications "depend" upon this behavior.
+		   Since we do not have the power to recompile these, we
+		   emulate the SVr4 behavior.  Sigh.  */
+		/* N.B. Shouldn't the size here be PAGE_SIZE?? */
+		do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC,
+				MAP_FIXED | MAP_PRIVATE, 0);
+	}
+	return(ret);
+}
+#endif /* CONFIG_MOSIX */
+
 /* This is really simpleminded and specialized - we are loading an
    a.out library that is given an ELF header. */
 
@@ -848,6 +1021,16 @@
 	while (elf_phdata->p_type != PT_LOAD) elf_phdata++;
 
 	/* Now use mmap to map the library into memory. */
+#ifdef CONFIG_MOSIX
+	error = do_mmap_down(file,
+			ELF_PAGESTART(elf_phdata->p_vaddr),
+			(elf_phdata->p_filesz +
+			 ELF_PAGEOFFSET(elf_phdata->p_vaddr)),
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
+			(elf_phdata->p_offset -
+			 ELF_PAGEOFFSET(elf_phdata->p_vaddr)));
+#else
 	down_write(&current->mm->mmap_sem);
 	error = do_mmap(file,
 			ELF_PAGESTART(elf_phdata->p_vaddr),
@@ -858,6 +1041,7 @@
 			(elf_phdata->p_offset -
 			 ELF_PAGEOFFSET(elf_phdata->p_vaddr)));
 	up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 	if (error != ELF_PAGESTART(elf_phdata->p_vaddr))
 		goto out_free_ph;
 
@@ -937,6 +1121,14 @@
 
 #define roundup(x, y)  ((((x)+((y)-1))/(y))*(y))
 
+#ifdef CONFIG_MOSIX
+int
+elf_maydump(struct vm_area_struct *vma)
+{
+	return(maydump(vma));
+}
+#endif /* CONFIG_MOSIX */
+
 /* An ELF note in memory */
 struct memelfnote
 {
@@ -1031,7 +1223,38 @@
 	struct elf_prstatus prstatus;	/* NT_PRSTATUS */
 	elf_fpregset_t fpu;		/* NT_PRFPREG */
 	struct elf_prpsinfo psinfo;	/* NT_PRPSINFO */
+#ifdef CONFIG_MOSIX
+	struct vmalist *vmas = NULL, *rvma;
+	unsigned long arg_start, arg_end;
+#endif /* CONFIG_MOSIX */
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		segs = 0;
+		mosix_deputy_rusage(0);
+		if((i=mosix_deputy_list_vmas(&vmas, &arg_start, &arg_end)) < 0)
+		{
+			MOD_DEC_USE_COUNT;
+			return(0);
+		}
+		for(rvma = vmas ; i-- > 0 ; rvma++)
+		{
+			if(rvma->maydump)
+			{
+				int sz = rvma->vmend - rvma->vmstart;
+
+				if (size+sz >= limit)
+					break;
+				else
+					size += sz;
+			}
+			segs++;
+		}
+		vma = NULL;	/* to satisfy the silly compiler */
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	segs = current->mm->map_count;
 
 #ifdef DEBUG
@@ -1100,6 +1323,9 @@
 	 * This transfers the registers from regs into the standard
 	 * coredump arrangement, whatever that is.
 	 */
+#ifdef CONFIG_MOSIX
+	mosix_obtain_registers(ALL_REGISTERS);
+#endif /* CONFIG_MOSIX */
 #ifdef ELF_CORE_COPY_REGS
 	ELF_CORE_COPY_REGS(prstatus.pr_reg, regs)
 #else
@@ -1121,7 +1347,12 @@
 	notes[1].type = NT_PRPSINFO;
 	notes[1].datasz = sizeof(psinfo);
 	notes[1].data = &psinfo;
+#ifdef CONFIG_MOSIX
+	i = LOGICAL_STATE(current);
+	i = i ? ffz(~i) + 1 : 0;
+#else
 	i = current->state ? ffz(~current->state) + 1 : 0;
+#endif /* CONFIG_MOSIX */
 	psinfo.pr_state = i;
 	psinfo.pr_sname = (i < 0 || i > 5) ? '.' : "RSDZTD"[i];
 	psinfo.pr_zomb = psinfo.pr_sname == 'Z';
@@ -1134,11 +1365,23 @@
 
 		set_fs(fs);
 
+#ifdef CONFIG_MOSIX
+		if(current->mosix.dflags & DDEPUTY)
+			len = arg_end - arg_start;
+		else
+#endif /* CONFIG_MOSIX */
 		len = current->mm->arg_end - current->mm->arg_start;
 		if (len >= ELF_PRARGSZ)
 			len = ELF_PRARGSZ-1;
+#ifdef CONFIG_MOSIX
 		copy_from_user(&psinfo.pr_psargs,
+			(current->mosix.dflags & DDEPUTY) ?
+			   (const char *)arg_start :
 			      (const char *)current->mm->arg_start, len);
+#else
+		copy_from_user(&psinfo.pr_psargs,
+			      (const char *)current->mm->arg_start, len);
+#endif /* CONFIG_MOSIX */
 		for(i = 0; i < len; i++)
 			if (psinfo.pr_psargs[i] == 0)
 				psinfo.pr_psargs[i] = ' ';
@@ -1154,6 +1397,11 @@
 	notes[2].data = current;
 
 	/* Try to dump the FPU. */
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		prstatus.pr_fpvalid = mosix_deputy_dump_fpu(&fpu);
+	else
+#endif /* CONFIG_MOSIX */
 	prstatus.pr_fpvalid = dump_fpu (regs, &fpu);
 	if (!prstatus.pr_fpvalid)
 	{
@@ -1192,6 +1440,30 @@
 	dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
 
 	/* Write program headers for segments dump */
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	for(rvma = vmas , i = 0 ; i < segs ; rvma++ , i++) {
+		struct elf_phdr phdr;
+		size_t sz;
+
+		sz = rvma->vmend - rvma->vmstart;
+
+		phdr.p_type = PT_LOAD;
+		phdr.p_offset = offset;
+		phdr.p_vaddr = rvma->vmstart;
+		phdr.p_paddr = 0;
+		phdr.p_filesz = rvma->maydump ? sz : 0;
+		phdr.p_memsz = sz;
+		offset += phdr.p_filesz;
+		phdr.p_flags = (rvma->vmflags & VM_READ) ? PF_R : 0;
+		if (rvma->vmflags & VM_WRITE) phdr.p_flags |= PF_W;
+		if (rvma->vmflags & VM_EXEC) phdr.p_flags |= PF_X;
+		phdr.p_align = ELF_EXEC_PAGESIZE;
+
+		DUMP_WRITE(&phdr, sizeof(phdr));
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
 		struct elf_phdr phdr;
 		size_t sz;
@@ -1221,6 +1493,23 @@
 
 	DUMP_SEEK(dataoff);
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		for(i = 0 , rvma = vmas ; i < segs ; rvma++ , i++)
+		if(rvma->maydump)
+		{
+			unsigned long addr = rvma->vmstart;
+			unsigned long len = rvma->vmend - rvma->vmstart;
+
+#ifdef DEBUG
+			printk("elf_core_dump: writing %08lx %lx\n", addr, len);
+#endif
+			DUMP_WRITE((void *)addr, len);
+		}
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
 		unsigned long addr;
 
@@ -1259,6 +1548,10 @@
 	}
 
  end_coredump:
+#ifdef CONFIG_MOSIX
+	if(vmas)
+		kfree(vmas);
+#endif /* CONFIG_MOSIX */
 	set_fs(fs);
 	return has_dumped;
 }
diff -ruN linux-2.4.16/fs/buffer.c linux-2.4.16-mosix/fs/buffer.c
--- linux-2.4.16/fs/buffer.c	Thu Nov 22 00:40:17 2001
+++ linux-2.4.16-mosix/fs/buffer.c	Sun Dec 23 13:56:53 2001
@@ -53,6 +53,10 @@
 #include <asm/bitops.h>
 #include <asm/mmu_context.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 #define MAX_BUF_PER_PAGE (PAGE_CACHE_SIZE / 512)
 #define NR_RESERVED (10*MAX_BUF_PER_PAGE)
 #define MAX_UNUSED_BUFFERS NR_RESERVED+20 /* don't ever have more than this 
@@ -403,6 +407,9 @@
 	struct inode * inode;
 	int err;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	err = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -435,6 +442,9 @@
 	struct inode * inode;
 	int err;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	err = -EBADF;
 	file = fget(fd);
 	if (!file)
diff -ruN linux-2.4.16/fs/dcache.c linux-2.4.16-mosix/fs/dcache.c
--- linux-2.4.16/fs/dcache.c	Thu Oct  4 07:57:36 2001
+++ linux-2.4.16-mosix/fs/dcache.c	Sun Dec 23 13:56:53 2001
@@ -26,6 +26,10 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/smp_lock.h>
+#endif /* CONFIG_MOSIX */
+
 #define DCACHE_PARANOIA 1
 /* #define DCACHE_DEBUG 1 */
 
@@ -834,6 +838,11 @@
 void d_rehash(struct dentry * entry)
 {
 	struct list_head *list = d_hash(entry->d_parent, entry->d_name.hash);
+
+#ifdef CONFIG_MOSIX_FS
+	if(entry->d_flags & DCACHE_NO_CACHE)
+		return;
+#endif /* CONFIG_MOSIX_FS */
 	if (!list_empty(&entry->d_hash)) BUG();
 	spin_lock(&dcache_lock);
 	list_add(&entry->d_hash, list);
@@ -906,6 +915,9 @@
 	spin_lock(&dcache_lock);
 	/* Move the dentry to the target hash queue */
 	list_del(&dentry->d_hash);
+#ifdef CONFIG_MOSIX_FS
+	if(!(dentry->d_flags & DCACHE_NO_CACHE))
+#endif /* CONFIG_MOSIX_FS */
 	list_add(&dentry->d_hash, &target->d_hash);
 
 	/* Unhash the target: dput() will then get rid of it */
@@ -951,6 +963,9 @@
 
 	*--end = '\0';
 	buflen--;
+#ifdef CONFIG_MOSIX_FS
+	if (!(dentry->d_flags & DCACHE_NO_CACHE))
+#endif /* CONFIG_MOSIX_FS */
 	if (!IS_ROOT(dentry) && list_empty(&dentry->d_hash)) {
 		buflen -= 10;
 		end -= 10;
@@ -1022,19 +1037,40 @@
 	char *page = (char *) __get_free_page(GFP_USER);
 
 	if (!page)
+#ifdef CONFIG_MOSIX_DFSA
+		return ((current->mosix.dflags & DREMOTE) ?
+							-EDOITATHOME : -ENOMEM);
+#else
 		return -ENOMEM;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	read_lock(&current->fs->lock);
+#ifdef CONFIG_MOSIX_DFSA
+	if(!current->fs->pwd)	/* we are REMOTE and not on a DFSA FS! */
+	{
+		read_unlock(&current->fs->lock);
+		return(-EDOITATHOME);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	pwdmnt = mntget(current->fs->pwdmnt);
 	pwd = dget(current->fs->pwd);
 	rootmnt = mntget(current->fs->rootmnt);
 	root = dget(current->fs->root);
 	read_unlock(&current->fs->lock);
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	if(pwd->d_inode->i_op && pwd->d_inode->i_op->check_path)
+		pwd->d_inode->i_op->check_path(pwd);
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 
 	error = -ENOENT;
 	/* Has the current directory has been unlinked? */
 	spin_lock(&dcache_lock);
+#ifdef CONFIG_MOSIX_FS
+	if (pwd->d_parent == pwd || !list_empty(&pwd->d_hash) ||
+					(pwd->d_flags & DCACHE_NO_CACHE)) {
+#else
 	if (pwd->d_parent == pwd || !list_empty(&pwd->d_hash)) {
+#endif /* CONFIG_MOSIX_FS */
 		unsigned long len;
 		char * cwd;
 
diff -ruN linux-2.4.16/fs/dnotify.c linux-2.4.16-mosix/fs/dnotify.c
--- linux-2.4.16/fs/dnotify.c	Wed Nov  8 09:27:57 2000
+++ linux-2.4.16-mosix/fs/dnotify.c	Sun Dec 23 13:56:53 2001
@@ -20,6 +20,10 @@
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
 extern void send_sigio(struct fown_struct *fown, int fd, int band);
 
 int dir_notify_enable = 1;
@@ -51,6 +55,10 @@
 	inode = filp->f_dentry->d_inode;
 	if (!S_ISDIR(inode->i_mode))
 		return -ENOTDIR;
+#ifdef CONFIG_MOSIX_FS
+	if(inode->i_sb->s_magic == MFS_SUPER_MAGIC)
+		return(-EPERM);
+#endif /* CONFIG_MOSIX_FS */
 	if (!turning_off) {
 		dn = kmem_cache_alloc(dn_cache, SLAB_KERNEL);
 		if (dn == NULL)
diff -ruN linux-2.4.16/fs/exec.c linux-2.4.16-mosix/fs/exec.c
--- linux-2.4.16/fs/exec.c	Sat Nov  3 03:39:20 2001
+++ linux-2.4.16-mosix/fs/exec.c	Sun Dec 23 13:56:53 2001
@@ -47,6 +47,12 @@
 #endif
 
 int core_uses_pid;
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
 
 static struct linux_binfmt *formats;
 static rwlock_t binfmt_lock = RW_LOCK_UNLOCKED;
@@ -125,6 +131,9 @@
 	if (IS_ERR(file))
 		goto out;
 
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dflags &= ~DSTATSDOWN;	/* NOT a DFSA system-call */
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -ENOEXEC;
 	if(file->f_op && file->f_op->read) {
 		struct linux_binfmt * fmt;
@@ -343,7 +352,16 @@
 	struct file *file;
 	int err = 0;
 
+#ifdef CONFIG_MOSIX_FS
+	/* if file is MFS, we need to complete in order to perform the "open"
+	 * method of dentry_open (which is NULL on MFS itself) */
+	nd.express_function = EF_OPEN;
+	nd.complete_args.ints.i1 = O_RDONLY+1;
+	nd.complete_args.ints.i2 = 0;
+	if (path_init(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE|LOOKUP_COMPLETE, &nd))
+#else
 	if (path_init(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd))
+#endif /* CONFIG_MOSIX_FS */
 		err = path_walk(name, &nd);
 	file = ERR_PTR(err);
 	if (!err) {
@@ -390,7 +408,11 @@
 	return result;
 }
 
+#ifdef CONFIG_MOSIX
+int exec_mmap(void)
+#else
 static int exec_mmap(void)
+#endif /* CONFIG_MOSIX */
 {
 	struct mm_struct * mm, * old_mm;
 
@@ -398,6 +420,9 @@
 	if (old_mm && atomic_read(&old_mm->mm_users) == 1) {
 		mm_release();
 		exit_mmap(old_mm);
+#ifdef CONFIG_MOSIX
+		mosix_exec_mmap(NULL);
+#endif /* CONFIG_MOSIX */
 		return 0;
 	}
 
@@ -423,6 +448,9 @@
 		task_unlock(current);
 		activate_mm(active_mm, mm);
 		mm_release();
+#ifdef CONFIG_MOSIX
+		mosix_exec_mmap(old_mm);
+#endif /* CONFIG_MOSIX */
 		if (old_mm) {
 			if (active_mm != old_mm) BUG();
 			mmput(old_mm);
@@ -544,6 +572,13 @@
 	/* 
 	 * Release all of the old mmap stuff
 	 */
+#ifdef CONFIG_MOSIX
+	if(!(current->mosix.dflags & DDEPUTY))
+		mosix_clear_statistics();
+	if(current->mosix.dflags & DDEPUTY)
+		retval = mosix_deputy_exec_mmap(bprm->filename);
+	else
+#endif /* CONFIG_MOSIX */
 	retval = exec_mmap();
 	if (retval) goto mmap_failed;
 
@@ -553,7 +588,11 @@
 	current->sas_ss_sp = current->sas_ss_size = 0;
 
 	if (current->euid == current->uid && current->egid == current->gid)
+#ifdef CONFIG_MOSIX
+		set_me_dumpable(1);
+#else
 		current->mm->dumpable = 1;
+#endif /* CONFIG_MOSIX */
 	name = bprm->filename;
 	for (i=0; (ch = *(name++)) != '\0';) {
 		if (ch == '/')
@@ -563,6 +602,9 @@
 				current->comm[i++] = ch;
 	}
 	current->comm[i] = '\0';
+#ifdef CONFIG_MOSIX
+	tell_process(current, DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
 
 	flush_thread();
 
@@ -570,7 +612,11 @@
 
 	if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || 
 	    permission(bprm->file->f_dentry->d_inode,MAY_READ))
+#ifdef CONFIG_MOSIX
+		set_me_dumpable(0);
+#else
 		current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 
 	/* An exec changes our domain. We are no longer part of the thread
 	   group */
@@ -692,12 +738,21 @@
 
 	if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
 	    !cap_issubset(new_permitted, current->cap_permitted)) {
+#ifdef CONFIG_MOSIX
+                set_me_dumpable(0);
+#else
                 current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 		
 		lock_kernel();
 		if (must_not_trace_exec(current)
+#ifdef CONFIG_MOSIX_DFSA
+		    || atomic_read(&current->fs->users) > 1
+		    || atomic_read(&current->files->users) > 1
+#else
 		    || atomic_read(&current->fs->count) > 1
 		    || atomic_read(&current->files->count) > 1
+#endif /* CONFIG_MOSIX_DFSA */
 		    || atomic_read(&current->sig->count) > 1) {
 			if(!capable(CAP_SETUID)) {
 				bprm->e_uid = current->uid;
@@ -723,6 +778,12 @@
 	
         /* AUD: Audit candidate if current->cap_effective is set */
 
+#ifdef CONFIG_MOSIX
+	tell_process(current, DREQ_CAPCNG|DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
         current->suid = current->euid = current->fsuid = bprm->e_uid;
         current->sgid = current->egid = current->fsgid = bprm->e_gid;
 
@@ -874,6 +935,19 @@
 	bprm.sh_bang = 0;
 	bprm.loader = 0;
 	bprm.exec = 0;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		mosix_deputy_count_args(argv, envp, &bprm.argc, &bprm.envc);
+		if(bprm.argc < 0 || bprm.envc < 0)
+		{
+			allow_write_access(file);
+			fput(file);
+			return(bprm.argc < 0 ? bprm.argc : bprm.envc);
+		}
+		goto counted;
+	}
+#endif /* CONFIG_MOSIX */
 	if ((bprm.argc = count(argv, bprm.p / sizeof(void *))) < 0) {
 		allow_write_access(file);
 		fput(file);
@@ -885,8 +959,19 @@
 		fput(file);
 		return bprm.envc;
 	}
+#ifdef CONFIG_MOSIX
+	counted:
+#endif /* CONFIG_MOSIX */
 
 	retval = prepare_binprm(&bprm);
+#ifdef CONFIG_MOSIX
+	current->mosix.inexec = &bprm;
+	if((current->mosix.dflags & DDEPUTY) && retval >= 0)
+		retval = mosix_deputy_bring_strings(&bprm, (char *)regs->ebx,
+								envp, argv);
+	else
+	{
+#endif /* CONFIG_MOSIX */
 	if (retval < 0) 
 		goto out; 
 
@@ -900,15 +985,35 @@
 		goto out; 
 
 	retval = copy_strings(bprm.argc, argv, &bprm);
+#ifdef CONFIG_MOSIX
+	}
+#endif /* CONFIG_MOSIX */
 	if (retval < 0) 
 		goto out; 
 
 	retval = search_binary_handler(&bprm,regs);
+#ifdef CONFIG_MOSIX
+	current->mosix.inexec = NULL;
+	if(retval >= 0)
+	{
+		mosix_decay_exec();
+		current->mosix.sigmig = 0;
+#ifdef CONFIG_MOSIX_FS
+		current->mosix.lastexec = current->mosix.whereami ? : PE;
+#ifdef CONFIG_MOSIX_DFSA
+		current->mosix.dupdates |= DFSA_UPDSEL;
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
+	}
+#endif /* CONFIG_MOSIX */
 	if (retval >= 0)
 		/* execve success */
 		return retval;
 
 out:
+#ifdef CONFIG_MOSIX
+	current->mosix.inexec = NULL;
+#endif /* CONFIG_MOSIX */
 	/* Something went wrong, return the inode and free the argument pages*/
 	allow_write_access(bprm.file);
 	if (bprm.file)
@@ -945,15 +1050,28 @@
 	binfmt = current->binfmt;
 	if (!binfmt || !binfmt->core_dump)
 		goto fail;
+#ifdef CONFIG_MOSIX
+	if(!i_am_dumpable())
+#else
 	if (!current->mm->dumpable)
+#endif /* CONFIG_MOSIX */
 		goto fail;
+#ifdef CONFIG_MOSIX
+	set_me_dumpable(0);
+#else
 	current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 	if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
 		goto fail;
 
 	memcpy(corename,"core.", 5);
 	corename[4] = '\0';
+#ifdef CONFIG_MOSIX
+ 	if (core_uses_pid ||
+		(current->mm && atomic_read(&current->mm->mm_realusers) != 1))
+#else
  	if (core_uses_pid || atomic_read(&current->mm->mm_users) != 1)
+#endif /* CONFIG_MOSIX */
  		sprintf(&corename[4], ".%d", current->pid);
 	file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW, 0600);
 	if (IS_ERR(file))
@@ -973,8 +1091,16 @@
 	if (do_truncate(file->f_dentry, 0) != 0)
 		goto close_fail;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		mosix_deputy_rusage(0);
+	else
+#endif /* CONFIG_MOSIX */
 	down_read(&current->mm->mmap_sem);
 	retval = binfmt->core_dump(signr, regs, file);
+#ifdef CONFIG_MOSIX
+	if(!(current->mosix.dflags & DDEPUTY))
+#endif /* CONFIG_MOSIX */
 	up_read(&current->mm->mmap_sem);
 
 close_fail:
@@ -983,3 +1109,43 @@
 	unlock_kernel();
 	return retval;
 }
+
+#ifdef CONFIG_MOSIX
+/*
+ * The following routines are performed on the REMOTE side
+ * and must be updated whenever the corresponding original-code
+ * is modified:
+ */
+
+void
+execve_remote_counts(char **argv, char **envp, int *argc, int *envc)
+{
+/* the following definition must match the value
+ * of bprm.p at the beginning of do_execve():
+ * (otherwise, this constant needs to be passed as argument)
+ */
+#define BPRM_P_AS_SIZE (PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *))
+	if ((*argc = count(argv, BPRM_P_AS_SIZE / sizeof(void *))) < 0)
+		return;
+	if ((*envc = count(envp, BPRM_P_AS_SIZE / sizeof(void *))) < 0)
+		return;
+}
+
+int
+execve_remote_bring_strings(struct linux_binprm *bprm, char **envp, char **argv)
+{
+	int retval;
+	char *filename = getname(bprm->filename);
+
+	if(IS_ERR(filename))
+		return((int)filename);
+	retval = copy_strings_kernel(1, &filename, bprm);
+	putname(filename);
+	if(retval < 0)
+		return(retval);
+	bprm->exec = bprm->p;
+	if((retval = copy_strings(bprm->envc, envp, bprm)) < 0)
+		return(retval);
+	return(copy_strings(bprm->argc, argv, bprm));
+}
+#endif /* CONFIG_MOSIX */
diff -ruN linux-2.4.16/fs/fcntl.c linux-2.4.16-mosix/fs/fcntl.c
--- linux-2.4.16/fs/fcntl.c	Mon Sep 17 23:16:30 2001
+++ linux-2.4.16-mosix/fs/fcntl.c	Sun Dec 23 13:56:53 2001
@@ -16,6 +16,10 @@
 #include <asm/siginfo.h>
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 extern int sock_fcntl (struct file *, unsigned int cmd, unsigned long arg);
 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
 extern int fcntl_getlease(struct file *filp);
@@ -81,6 +85,13 @@
 			files->max_fdset, start);
 	}
 	
+#ifdef CONFIG_MOSIX_DFSA
+	if((current->mosix.dflags & DREMOTE) && newfd >= files->max_fds)
+	{
+		error = -EDOITATHOME;
+		goto out;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -EMFILE;
 	if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
 		goto out;
@@ -137,12 +148,24 @@
 	struct file * file, *tofree;
 	struct files_struct * files = current->files;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(oldfd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	write_lock(&files->file_lock);
 	if (!(file = fcheck(oldfd)))
 		goto out_unlock;
 	err = newfd;
 	if (newfd == oldfd)
 		goto out_unlock;
+#ifdef CONFIG_MOSIX_DFSA
+	if((current->mosix.dflags & DREMOTE) &&
+		(newfd >= files->max_fdset || newfd >= files->max_fds ||
+		(!files->fd[newfd] && FD_ISSET(newfd, files->open_fds))))
+	{
+		err = -EDOITATHOME;
+		goto out_unlock;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	err = -EBADF;
 	if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
 		goto out_unlock;
@@ -169,6 +192,11 @@
 	FD_SET(newfd, files->open_fds);
 	FD_CLR(newfd, files->close_on_exec);
 	write_unlock(&files->file_lock);
+#ifdef CONFIG_MOSIX_DFSA
+	if(tofree)
+		dfsa_close_file(newfd);
+	dfsa_open_file(newfd);
+#endif /* CONFIG_MOSIX_DFSA */
 
 	if (tofree)
 		filp_close(tofree, files);
@@ -190,6 +218,9 @@
 	int ret = -EBADF;
 	struct file * file = fget(fildes);
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fildes, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	if (file)
 		ret = dupfd(file, 0);
 	return ret;
@@ -206,6 +237,16 @@
 	 * In the case of an append-only file, O_APPEND
 	 * cannot be cleared
 	 */
+#ifdef CONFIG_MOSIX_FS
+	if(!(arg & O_APPEND))
+	/* no way to guess the IS_APPEND status on MFS - need to look */
+	{
+		struct inode_operations *iops = filp->f_dentry->d_inode->i_op;
+
+		if (iops && iops->revalidate)
+			iops->revalidate(filp->f_dentry);
+	}
+#endif /* CONFIG_MOSIX_FS */
 	if (!(arg & O_APPEND) && IS_APPEND(inode))
 		return -EPERM;
 
@@ -251,6 +292,18 @@
 {
 	long err = -EINVAL;
 
+#ifdef CONFIG_MOSIX_DFSA
+	switch(cmd)
+	{
+		case F_GETFL:
+			dfsa_syscall_on_file(fd, 0);
+			break;
+		case F_DUPFD:
+		case F_SETFL:
+			dfsa_syscall_on_file(fd, 1);
+			break;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	switch (cmd) {
 		case F_DUPFD:
 			if (arg < NR_OPEN) {
@@ -438,7 +491,11 @@
 		send_sigio_to_task(p, fown, fd, band);
 		goto out;
 	}
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		int match = p->pid;
 		if (pid < 0)
 			match = -p->pgrp;
diff -ruN linux-2.4.16/fs/file.c linux-2.4.16-mosix/fs/file.c
--- linux-2.4.16/fs/file.c	Fri Feb  9 21:29:44 2001
+++ linux-2.4.16-mosix/fs/file.c	Sun Dec 23 13:56:53 2001
@@ -14,6 +14,9 @@
 
 #include <asm/bitops.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
 
 /*
  * Allocate an fd array, using kmalloc or vmalloc.
@@ -98,6 +101,10 @@
 		struct file **old_fds;
 		int i;
 		
+#ifdef CONFIG_MOSIX_DFSA
+		if(files == current->files)
+			current->mosix.dupdates |= DFSA_UPDMAX;
+#endif /* CONFIG_MOSIX_DFSA */
 		old_fds = xchg(&files->fd, new_fds);
 		i = xchg(&files->max_fds, nfds);
 
@@ -164,6 +171,9 @@
 int expand_fdset(struct files_struct *files, int nr)
 {
 	fd_set *new_openset = 0, *new_execset = 0;
+#ifdef CONFIG_MOSIX_DFSA
+	fd_set *new_closed = 0, *new_opened = 0, *new_modified = 0;
+#endif /* CONFIG_MOSIX_DFSA */
 	int error, nfds = 0;
 
 	error = -EMFILE;
@@ -187,8 +197,18 @@
 	error = -ENOMEM;
 	new_openset = alloc_fdset(nfds);
 	new_execset = alloc_fdset(nfds);
+#ifdef CONFIG_MOSIX_DFSA
+	new_closed = alloc_fdset(nfds);
+	new_opened = alloc_fdset(nfds);
+	new_modified = alloc_fdset(nfds);
+#endif /* CONFIG_MOSIX_DFSA */
 	write_lock(&files->file_lock);
+#ifdef CONFIG_MOSIX_DFSA
+	if (!new_openset || !new_execset ||
+				!new_closed || !new_opened || !new_modified)
+#else
 	if (!new_openset || !new_execset)
+#endif /* CONFIG_MOSIX_DFSA */
 		goto out;
 
 	error = 0;
@@ -198,6 +218,10 @@
 		int i = files->max_fdset / (sizeof(unsigned long) * 8);
 		int count = (nfds - files->max_fdset) / 8;
 		
+#ifdef CONFIG_MOSIX_DFSA
+		if(files == current->files)
+			current->mosix.dupdates |= DFSA_UPDMAX;
+#endif /* CONFIG_MOSIX_DFSA */
 		/* 
 		 * Don't copy the entire array if the current fdset is
 		 * not yet initialised.  
@@ -207,14 +231,32 @@
 			memcpy (new_execset, files->close_on_exec, files->max_fdset/8);
 			memset (&new_openset->fds_bits[i], 0, count);
 			memset (&new_execset->fds_bits[i], 0, count);
+#ifdef CONFIG_MOSIX_DFSA
+			memcpy (new_closed, files->closed, files->max_fdset/8);
+			memcpy (new_opened, files->opened, files->max_fdset/8);
+			memcpy (new_modified, files->modified, files->max_fdset/8);
+			memset (&new_closed->fds_bits[i], 0, count);
+			memset (&new_opened->fds_bits[i], 0, count);
+			memset (&new_modified->fds_bits[i], 0, count);
+#endif /* CONFIG_MOSIX_DFSA */
 		}
 		
 		nfds = xchg(&files->max_fdset, nfds);
 		new_openset = xchg(&files->open_fds, new_openset);
 		new_execset = xchg(&files->close_on_exec, new_execset);
+#ifdef CONFIG_MOSIX_DFSA
+		new_closed = xchg(&files->closed, new_closed);
+		new_opened = xchg(&files->opened, new_opened);
+		new_modified = xchg(&files->modified, new_modified);
+#endif /* CONFIG_MOSIX_DFSA */
 		write_unlock(&files->file_lock);
 		free_fdset (new_openset, nfds);
 		free_fdset (new_execset, nfds);
+#ifdef CONFIG_MOSIX_DFSA
+		free_fdset (files->closed, nfds);
+		free_fdset (files->opened, nfds);
+		free_fdset (files->modified, nfds);
+#endif /* CONFIG_MOSIX_DFSA */
 		write_lock(&files->file_lock);
 		return 0;
 	} 
@@ -226,6 +268,14 @@
 		free_fdset(new_openset, nfds);
 	if (new_execset)
 		free_fdset(new_execset, nfds);
+#ifdef CONFIG_MOSIX_DFSA
+	if (new_closed)
+		free_fdset(new_closed, nfds);
+	if (new_opened)
+		free_fdset(new_opened, nfds);
+	if (new_modified)
+		free_fdset(new_modified, nfds);
+#endif /* CONFIG_MOSIX_DFSA */
 	write_lock(&files->file_lock);
 	return error;
 }
diff -ruN linux-2.4.16/fs/file_table.c linux-2.4.16-mosix/fs/file_table.c
--- linux-2.4.16/fs/file_table.c	Mon Sep 17 23:16:30 2001
+++ linux-2.4.16-mosix/fs/file_table.c	Sun Dec 23 13:56:53 2001
@@ -58,7 +58,12 @@
 	/*
 	 * Allocate a new one if we're below the limit.
 	 */
+#ifdef CONFIG_MOSIX_FS
+	if (files_stat.nr_files < files_stat.max_files ||
+		(current->mosix.dirty_bits & MFSARG_EMPTYF_PRI)) {
+#else
 	if (files_stat.nr_files < files_stat.max_files) {
+#endif /* CONFIG_MOSIX_FS */
 		file_list_unlock();
 		f = kmem_cache_alloc(filp_cachep, SLAB_KERNEL);
 		file_list_lock();
@@ -113,6 +118,9 @@
 			file->f_op->release(inode, file);
 		fops_put(file->f_op);
 		if (file->f_mode & FMODE_WRITE)
+#ifdef CONFIG_MOSIX
+		if (!(file->f_flags & O_NOWRITEACCESS))
+#endif /* CONFIG_MOSIX */
 			put_write_access(inode);
 		file_list_lock();
 		file->f_dentry = NULL;
diff -ruN linux-2.4.16/fs/inode.c linux-2.4.16-mosix/fs/inode.c
--- linux-2.4.16/fs/inode.c	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/fs/inode.c	Sun Dec 23 13:56:53 2001
@@ -18,6 +18,11 @@
 #include <linux/prefetch.h>
 #include <linux/locks.h>
 
+#ifdef CONFIG_MOSIX
+spinlock_t unique_gen_lock = SPIN_LOCK_UNLOCKED;
+unsigned long long unique_generator;
+#endif /* CONFIG_MOSIX */
+
 /*
  * New inode.c implementation.
  *
@@ -787,6 +792,9 @@
 	inode->i_data.host = inode;
 	inode->i_data.gfp_mask = GFP_HIGHUSER;
 	inode->i_mapping = &inode->i_data;
+#ifdef CONFIG_MOSIX
+	VMODIFIED(inode);
+#endif /* CONFIG_MOSIX */
 }
 
 /**
@@ -822,6 +830,9 @@
 		inode->i_flags = 0;
 		atomic_set(&inode->i_count, 1);
 		inode->i_state = 0;
+#ifdef CONFIG_MOSIX
+		VMODIFIED(inode);
+#endif /* CONFIG_MOSIX */
 		spin_unlock(&inode_lock);
 		clean_inode(inode);
 	}
@@ -856,6 +867,9 @@
 			inode->i_flags = 0;
 			atomic_set(&inode->i_count, 1);
 			inode->i_state = I_LOCK;
+#ifdef CONFIG_MOSIX
+			VMODIFIED(inode);
+#endif /* CONFIG_MOSIX */
 			spin_unlock(&inode_lock);
 
 			clean_inode(inode);
diff -ruN linux-2.4.16/fs/ioctl.c linux-2.4.16-mosix/fs/ioctl.c
--- linux-2.4.16/fs/ioctl.c	Fri Feb  9 21:29:44 2001
+++ linux-2.4.16-mosix/fs/ioctl.c	Sun Dec 23 13:56:53 2001
@@ -11,6 +11,10 @@
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
 {
 	int error;
@@ -51,6 +55,9 @@
 	struct file * filp;
 	unsigned int flag;
 	int on, error = -EBADF;
+#ifdef CONFIG_MOSIX_DFSA
+	int flags_changed = 0;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	filp = fget(fd);
 	if (!filp)
@@ -79,6 +86,9 @@
 				filp->f_flags |= flag;
 			else
 				filp->f_flags &= ~flag;
+#ifdef CONFIG_MOSIX_DFSA
+			flags_changed = 1;
+#endif /* CONFIG_MOSIX_DFSA */
 			break;
 
 		case FIOASYNC:
@@ -99,6 +109,9 @@
 				filp->f_flags |= FASYNC;
 			else
 				filp->f_flags &= ~FASYNC;
+#ifdef CONFIG_MOSIX_DFSA
+			flags_changed = 1;
+#endif /* CONFIG_MOSIX_DFSA */
 			break;
 
 		default:
@@ -110,6 +123,10 @@
 	}
 	unlock_kernel();
 	fput(filp);
+#ifdef CONFIG_MOSIX_DFSA
+	if(flags_changed)
+		dfsa_touch_file(fd);
+#endif /* CONFIG_MOSIX_DFSA */
 
 out:
 	return error;
diff -ruN linux-2.4.16/fs/lockd/svc.c linux-2.4.16-mosix/fs/lockd/svc.c
--- linux-2.4.16/fs/lockd/svc.c	Sun Oct 21 19:32:33 2001
+++ linux-2.4.16-mosix/fs/lockd/svc.c	Sun Dec 23 13:56:53 2001
@@ -304,6 +304,9 @@
 	 * Wait for the lockd process to exit, but since we're holding
 	 * the lockd semaphore, we can't wait around forever ...
 	 */
+#ifdef CONFIG_MOSIX
+	current->mosix.ignoreoldsigs = 1;
+#endif /* CONFIG_MOSIX */
 	current->sigpending = 0;
 	interruptible_sleep_on_timeout(&lockd_exit, HZ);
 	if (nlmsvc_pid) {
diff -ruN linux-2.4.16/fs/mfs/Makefile linux-2.4.16-mosix/fs/mfs/Makefile
--- linux-2.4.16/fs/mfs/Makefile	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/Makefile	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,8 @@
+#
+# Makefile for the Linux MOSIX mfs filesystem routines.
+#
+
+O_TARGET := mfs.o
+obj-y    := file.o convert.o complete.o server.o client.o scontact.o ccontact.o socket.o count.o
+
+include $(TOPDIR)/Rules.make
diff -ruN linux-2.4.16/fs/mfs/ccontact.c linux-2.4.16-mosix/fs/mfs/ccontact.c
--- linux-2.4.16/fs/mfs/ccontact.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/ccontact.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,325 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/config.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/slab.h>
+#include <linux/mfs.h>
+#include <linux/mfs_socket.h>
+
+spinlock_t mfs_client_lock = SPIN_LOCK_UNLOCKED;
+
+#define MFS_CLIENT_OPTCONS	50
+#define	MFS_MAX_HOGGING_A_NODE	8
+
+struct mfs_client_contact
+{
+	struct mfs_client_contact *next;
+	int to;
+	struct socket *sock;
+	int serial;
+	int has_mh;
+	struct mfs_message_header mh;
+} *mfs_busy_clients, *mfs_connected_clients, *mfs_closing_clients;
+
+int mfs_client_serial;
+
+DECLARE_WAIT_QUEUE_HEAD(wait_for_busy_contact);
+int waiting_for_busy_contact;
+
+int
+mfs_client_send(struct mfs_client_contact *s, int type, void *header, int hdln,
+			void *dat1, int len1, void *dat2, int len2)
+{
+	return(mfs_send(s->sock, 0, s->serial,
+				type, header, hdln, dat1, len1, dat2, len2));
+}
+
+int
+mfs_client_receive(struct mfs_client_contact *s,
+					void **header, void **dat1, void **dat2)
+{
+	if(s->has_mh)
+	{
+		s->has_mh = 0;
+if(mfs_debug > 1)
+printk("mfs_client_receive: continuing with serial %d, type %d (%d/%d/%d)\n",
+s->mh.serial, s->mh.type, s->mh.hdsz, s->mh.dat1sz, s->mh.dat2sz);
+		return(mfs_receive(s->sock, MFS_MUST_MATCH, &s->serial, &s->mh,
+							header, dat1, dat2));
+	}
+	else
+		return(mfs_receive(s->sock, MFS_SKIP_OTHERS, &s->serial, NULL,
+							header, dat1, dat2));
+}
+
+int
+mfs_client_contact_has_data(struct mfs_client_contact *con)
+{
+	return(mfs_socket_has_data(con->sock));
+}
+
+void
+delayed_close_client(struct mfs_client_contact *con)
+{
+	mfs_send(con->sock, 1, 0, MFS_CLOSE, NULL, 0, NULL, 0, NULL,0);
+	spin_lock(&mfs_client_lock);
+	con->next = mfs_closing_clients;
+	mfs_closing_clients = con;
+	spin_unlock(&mfs_client_lock);
+}
+
+void
+mfs_client_check_closed(struct mfs_client_contact **head)
+{
+	struct mfs_client_contact *c, *prev, *next;
+	struct mfs_client_contact *dispose = NULL;
+
+	spin_lock(&mfs_client_lock);
+	for(prev = NULL, c = *head ; c ; c = next)
+	{
+		next = c->next;
+		if(mfs_socket_is_closed(c->sock))
+		{
+			if(prev)
+				prev->next = next;
+			else
+				*head = next;
+			c->next = dispose;
+			dispose = c;
+		}
+		else
+			prev = c;
+	}
+	spin_unlock(&mfs_client_lock);
+	for(; dispose ; dispose = next)
+	{
+		next = dispose->next;
+		mfs_close_socket(dispose->sock);
+		kfree(dispose);
+	}
+}
+
+void
+mfs_release_contact(struct mfs_client_contact *con)
+{
+	struct mfs_client_contact *s, *prev;
+	int bcnt = 0, pcnt = 0, tcnt = 0;
+	int pe = con->to;
+	int found = 0;
+
+	spin_lock(&mfs_client_lock);
+	for(prev = NULL , s = mfs_busy_clients ; s ; )
+	{
+		tcnt++;
+		if(s == con)
+		{
+			s = s->next;
+			if(prev)
+				prev->next = s;
+			else
+				mfs_busy_clients = s;
+			found = 1;
+		}
+		else
+		{
+			if(s->to == pe && ++bcnt >= MFS_MAX_HOGGING_A_NODE &&
+									found)
+				break;
+			prev = s;
+			s = s->next;
+		}
+	}
+	if(!found)
+		printk("mfs_release_contact: not listed!\n");
+	if((pcnt = bcnt) < MFS_MAX_HOGGING_A_NODE)
+	for(s = mfs_connected_clients ; s ; s = s->next)
+	{
+		tcnt++;
+		if(s->to == pe && ++pcnt == MFS_MAX_HOGGING_A_NODE)
+			break;
+	}
+	if((tcnt >= MFS_CLIENT_OPTCONS && pcnt) ||
+						pcnt >= MFS_MAX_HOGGING_A_NODE)
+	{
+		spin_unlock(&mfs_client_lock);
+		delayed_close_client(con);
+		if(bcnt >= MFS_MAX_HOGGING_A_NODE)
+			return;
+		spin_lock(&mfs_client_lock);
+	}
+	else
+	{
+		con->next = mfs_connected_clients;
+		mfs_connected_clients = con;
+	}
+	if(waiting_for_busy_contact == pe ||
+		waiting_for_busy_contact == MFS_UNKNOWN_PE)
+	{
+		waiting_for_busy_contact = 0;
+		wake_up(&wait_for_busy_contact);
+	}
+	spin_unlock(&mfs_client_lock);
+}
+
+static inline int
+node_is_hogged(int pe)
+{
+	int n = 0;
+	struct mfs_client_contact *s;
+
+	for(s = mfs_busy_clients ; s ; s = s->next)
+	if(s->to == pe && ++n == MFS_MAX_HOGGING_A_NODE)
+		return(1);
+	return(0);
+}
+
+struct mfs_client_contact *
+mfs_new_request(int pe, int type, void *header, int hdln, void *dat1, int len1,
+							void *dat2, int len2)
+{
+	struct mfs_client_contact *s, *prev, *prevprev, *con;
+	int tried_a_new = 0;
+	int cnt;
+	DECLARE_WAITQUEUE(wait, current);
+
+	if(pe == MFS_BAD_PE)
+		return(ERR_PTR(-ESTALE));
+	spin_lock(&mfs_client_lock);
+	for(prev = prevprev = NULL , cnt = 0 , s = mfs_connected_clients ; s ;
+					prevprev = prev, prev = s , s = s->next)
+	if(s->to == pe)
+		break;
+	else
+		cnt++;
+	if(s)
+	{
+		found_a_connected:
+		if(prev)
+			prev->next = s->next;
+		else
+			mfs_connected_clients = s->next;
+		try_it:
+		con = s;
+		con->to = pe;
+		con->next = mfs_busy_clients;
+		mfs_busy_clients = con;
+		con->serial = ++mfs_client_serial;
+		spin_unlock(&mfs_client_lock);
+		if(!mfs_send(con->sock, 1, con->serial, type, header, hdln,
+						dat1, len1, dat2, len2) &&
+			mfs_receive(con->sock, MFS_JUST_HEADER, &con->serial,
+					&con->mh, NULL, NULL, NULL) >= 0)
+		{
+			con->has_mh = 1;
+if(mfs_debug > 1)
+printk("mfs_new_request: first reply will be serial %d, type %d (%d/%d/%d)\n",
+con->mh.serial, con->mh.type, con->mh.hdsz, con->mh.dat1sz, con->mh.dat2sz);
+			return(con);
+		}
+		spin_lock(&mfs_client_lock);
+		for(prev = NULL , s = mfs_busy_clients ; s && s != con ;
+							prev = s , s = s->next)
+			;
+		if(s)
+		{
+			if(prev)
+				prev->next = s->next;
+			else
+				mfs_busy_clients = s->next;
+			if(waiting_for_busy_contact == pe ||
+				waiting_for_busy_contact == MFS_UNKNOWN_PE)
+			{
+				waiting_for_busy_contact = 0;
+				wake_up(&wait_for_busy_contact);
+			}
+			spin_unlock(&mfs_client_lock);
+			mfs_close_socket(s->sock);
+			kfree(s);
+			spin_lock(&mfs_client_lock);
+		}
+		else
+			printk("mfs_new_request: contact disappeared!\n");
+	}
+	else if(cnt >= MFS_CLIENT_OPTCONS)
+	{
+		/* trim out the last one (also last used) */
+		prevprev->next = NULL;
+		spin_unlock(&mfs_client_lock);
+		delayed_close_client(prev);
+		mfs_client_check_closed(&mfs_closing_clients);
+		spin_lock(&mfs_client_lock);
+	}
+	if(tried_a_new || !PE)
+	{
+		spin_unlock(&mfs_client_lock);
+		return(ERR_PTR(-EREMOTE));
+	}
+	if(node_is_hogged(pe))
+	{
+		add_wait_queue(&wait_for_busy_contact, &wait);
+		while(1)
+		{
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			if(waiting_for_busy_contact &&
+				waiting_for_busy_contact != pe)
+				waiting_for_busy_contact = MFS_UNKNOWN_PE;
+			else
+				waiting_for_busy_contact = pe;
+			if(!node_is_hogged(pe))
+				break;
+			spin_unlock(&mfs_client_lock);
+			if(!PE)
+			{
+				remove_wait_queue(&wait_for_busy_contact, &wait);
+				set_current_state(TASK_RUNNING);
+				return(NULL);
+			}
+			schedule_timeout(HZ);
+			spin_lock(&mfs_client_lock);
+			for(prev = NULL , s = mfs_connected_clients ; s ;
+							prev = s , s = s->next)
+			if(s->to == pe)
+			{
+				remove_wait_queue(&wait_for_busy_contact,&wait);
+				set_current_state(TASK_RUNNING);
+				goto found_a_connected;
+			}
+		}
+		remove_wait_queue(&wait_for_busy_contact, &wait);
+		set_current_state(TASK_RUNNING);
+	}
+	spin_unlock(&mfs_client_lock);
+	tried_a_new++;
+	if(!(s = (struct mfs_client_contact *)kmalloc(sizeof(*s), GFP_KERNEL)))
+		return(ERR_PTR(-ENOMEM));
+	s->sock = mfs_connect_to(pe);
+	s->has_mh = 0;
+	if(!IS_ERR(s->sock))
+	{
+		spin_lock(&mfs_client_lock);
+		goto try_it;
+	}
+	con = (struct mfs_client_contact *)s->sock;
+	kfree(s);
+	return(con);
+}
+
+void
+mfs_monitor_client_contacts(void)
+{
+	mfs_client_check_closed(&mfs_connected_clients);
+	mfs_client_check_closed(&mfs_closing_clients);
+}
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/client.c linux-2.4.16-mosix/fs/mfs/client.c
--- linux-2.4.16/fs/mfs/client.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/client.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,665 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <asm/uaccess.h>
+#include <linux/slab.h>
+#include <linux/mfs.h>
+
+void
+pack_credits(struct mfs_cred *cred)
+{
+	register struct task_struct *p = current;
+	register int i;
+
+	cred->uid = p->uid;
+	cred->euid = p->euid;
+	cred->sgid = p->sgid;
+	cred->fsuid = p->fsuid;
+	cred->gid = p->gid;
+	cred->egid = p->egid;
+	cred->sgid = p->sgid;
+	cred->fsgid = p->fsgid;
+	cred->ngroups = p->ngroups;
+	for(i = cred->ngroups-1 ; i >= 0 ; i--)
+		cred->groups[i] = p->groups[i];
+	cred->caps = p->cap_effective;
+	cred->whereami = current->mosix.whereami ? : PE;
+	cred->deppe = current->mosix.deppe ? : PE;
+}
+
+inline void
+mfs_file_up_to_date(struct file *filp)
+{
+	struct dentry *dp;
+	struct mfs_dinfo *i;
+
+	if((dp = filp->f_dentry) && (i = (struct mfs_dinfo *)dp->d_fsdata))
+		i->latest = jiffies;
+}
+
+int
+mfs_client_attach_handle(int pe, mfs_handle_t handle)
+{
+	struct mfs_request_attach_handle s;
+	struct mfs_reply_attach_handle *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	s.handle = handle;
+	con = mfs_new_request(pe, MFS_REQUEST_ATTACH_HANDLE, &s, sizeof(s),
+							NULL, 0, NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_ATTACH_HANDLE)
+		err = r->result;
+	else if(err >= 0)
+	{
+		printk("mfs_client_attach_handle: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+int
+mfs_client_touch_handle(int pe, mfs_handle_t handle)
+{
+	struct mfs_request_touch_handle s;
+	struct mfs_reply_touch_handle *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	s.handle = handle;
+	con = mfs_new_request(pe, MFS_REQUEST_TOUCH_HANDLE, &s, sizeof(s),
+							NULL, 0, NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_TOUCH_HANDLE)
+		err = r->result;
+	else if(err >= 0)
+	{
+		printk("mfs_client_touch_handle: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+void
+mfs_client_dispose_handle(int pe, mfs_handle_t handle)
+{
+	struct mfs_request_dispose_handle s;
+	struct mfs_client_contact *con;
+	void *r;
+
+	s.handle = handle;
+	con = mfs_new_request(pe, MFS_REQUEST_DISPOSE_HANDLE, &s, sizeof(s),
+							NULL, 0, NULL, 0);
+	if(IS_ERR(con))
+		return;
+	mfs_client_receive(con, &r, NULL, NULL);
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+}
+
+int
+mfs_client_llseek(int pe, mfs_handle_t handle, struct file *filp, loff_t offset,
+								int origin)
+{
+	struct mfs_request_llseek s;
+	struct mfs_reply_llseek *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.file = *filp;
+	s.offset = offset;
+	s.origin = origin;
+	con = mfs_new_request(pe, MFS_REQUEST_LLSEEK, &s, sizeof(s), NULL, 0,
+								NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_LLSEEK)
+	{
+		cp_file_fields(filp, &r->file);
+		err = r->result;
+		if(err >= 0)
+			mfs_file_up_to_date(filp);
+	}
+	else if(err >= 0)
+	{
+		printk("mfs_client_llseek: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+ssize_t
+mfs_client_read(int pe, mfs_handle_t handle, struct file *filp, char *buf,
+						size_t count, loff_t *ppos)
+{
+	struct mfs_request_read s;
+	struct mfs_reply_read *r;
+	struct mfs_client_contact *con;
+	void *data;
+	int err;
+	ssize_t i, result = 0;
+	int user_err = 0;
+	int done = 0;
+
+	if((int)count < 0)
+		return(-EINVAL);
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.file = *filp;
+	s.count = count;
+	s.pos = *ppos;
+	con = mfs_new_request(pe, MFS_REQUEST_READ, &s, sizeof(s), NULL, 0,
+								NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	while(!done)
+	{
+		err = mfs_client_receive(con, (void **)&r, &data, NULL);
+		if(err < 0)
+		{
+			result = err;
+			break;
+		}
+		switch(err)
+		{
+			case MFS_INTERIM_DATA:
+				i = ((struct mfs_interim_data *)r)->count;
+				if(!user_err && copy_to_user(buf, data, i))
+					user_err = -EFAULT;
+				else
+					buf += i;
+				/* do not exit: it is always the server
+				 * that should close the connection
+				 */
+				break;
+			case MFS_REPLY_READ:
+				done = 1;
+				if(!user_err && r->datalen &&
+					copy_to_user(buf, data, r->datalen))
+					user_err = -EFAULT;
+				cp_file_fields(filp, &r->file);
+				*ppos = r->ppos;
+				result = r->result;
+				if(result >= 0)
+					mfs_file_up_to_date(filp);
+				break;
+			default:
+				printk("mfs_client_read: unexpected reply %d\n",
+									err);
+				result = -EINVAL;
+				done = 1;
+				break;
+				
+		}
+		if(r)
+			kfree(r);
+	}
+	mfs_release_contact(con);
+	return(user_err ? : result);
+}
+
+ssize_t
+mfs_client_write(int pe, mfs_handle_t handle, struct file *filp, char *buf,
+					size_t count, loff_t *ppos, long flim)
+{
+	struct mfs_request_write s;
+	struct mfs_interim_data i;
+	struct mfs_reply_write *r;
+	struct mfs_client_contact *con;
+	void *data;
+	int err;
+	ssize_t result = 0;
+	int user_err = 0;
+	size_t max, sent, cnt;
+	char smallbuf[4];
+	char *tbuf = NULL;	/* NULL just because bad compiler complains */
+
+	if(count == 0)
+		return(0);
+	if((int)count < 0)
+		return(-EINVAL);
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.file = *filp;
+	s.count = count;
+	s.pos = *ppos;
+	s.flim = flim;
+	for(max = count > 16384 ? 16384 : count ; max > sizeof(smallbuf) ;
+								max >>= 1)
+	if((tbuf = (char *)kmalloc(max, GFP_KERNEL)))
+		break;
+	if(max <= sizeof(smallbuf))
+	{
+		tbuf = smallbuf;
+		max = sizeof(smallbuf);
+	}
+	s.datalen = sent = count < max ? count : max;
+	if(copy_from_user(tbuf, buf, sent))
+	{
+		user_err = -EFAULT;
+		goto free_buf;
+	}
+	buf += sent;
+	con = mfs_new_request(pe, MFS_REQUEST_WRITE, &s, sizeof(s), tbuf, sent,
+								NULL, 0);
+	if(IS_ERR(con))
+	{
+		result = (int)con;
+		goto free_buf;
+	}
+	while(sent < count)
+	{
+		if(mfs_client_contact_has_data(con))
+			break;
+		cnt = count - sent;
+		if(cnt > max)
+			cnt = max;
+		if(user_err || copy_from_user(tbuf, buf, cnt))
+		{
+			user_err = -EFAULT;
+			mfs_client_send(con, MFS_STOP, NULL, 0,
+					NULL, 0, NULL, 0);
+			break;	/* let the server quit first */
+		}
+		i.count = cnt;
+		if((err = mfs_client_send(con, MFS_INTERIM_DATA,
+			&i, sizeof(i), (void *)tbuf, cnt,
+			NULL, 0)))
+		{
+			result = err;
+			break;
+		}
+		buf += cnt;
+		sent += cnt;
+	}
+	err = mfs_client_receive(con, (void **)&r, &data, NULL);
+	if(err == MFS_CONTINUE)
+		err = mfs_client_receive(con, (void **)&r, &data, NULL);
+	if(err == MFS_REPLY_WRITE)
+	{
+		cp_file_fields(filp, &r->file);
+		*ppos = r->ppos;
+		result = r->result;
+		if(result >= 0)
+			mfs_file_up_to_date(filp);
+		if(r->hadsigxfsz)
+			send_sig(SIGXFSZ, current, 0);
+	}
+	else if(err < 0)
+		result = err;
+	else
+	{
+		printk("mfs_client_write: unexpected reply %d\n", err);
+		result = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	free_buf:
+	if(max != sizeof(smallbuf))
+		kfree(tbuf);
+	return(user_err ? : result);
+}
+
+int
+mfs_client_readdir_transfer(void *d, int len, void *dirent, filldir_t filldir)
+{
+	ino_t ino;
+	loff_t off;
+	unsigned int type;
+	short namelen;
+	int err;
+
+	while(len)
+	{
+		len -= sizeof(ino)+sizeof(off)+sizeof(type)+sizeof(namelen);
+		if(len < 0)
+			return(-EINVAL);
+		ino = *((ino_t *)d)++;
+		off = *((loff_t *)d)++;
+		type = *((unsigned int *)d)++;
+		namelen = *((short *)d)++;
+		if(len < namelen)
+			return(-EINVAL);
+		len -= namelen;
+		if((err = filldir(dirent, (const char *)d, namelen, off, ino,
+									type)))
+			return(err);
+		d += namelen;
+	}
+	return(0);
+}
+
+int
+mfs_client_readdir(int pe, mfs_handle_t handle, struct file *filp, void *dirent,
+	filldir_t filldir, int policy, int maxbytes, int *packets, int *bytes)
+{
+	struct mfs_request_readdir s;
+	struct mfs_reply_readdir *r;
+	struct mfs_interim_readdir ri;
+	struct mfs_client_contact *con;
+	void *data;
+	ssize_t i;
+	int result = 0;
+	int done = 0;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.file = *filp;
+	s.policy = policy;
+	s.maxbytes = maxbytes;
+	*packets = *bytes = 0;
+	con = mfs_new_request(pe, MFS_REQUEST_READDIR, &s, sizeof(s), NULL, 0,
+								NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	while(!done && (result =
+		mfs_client_receive(con, (void **)&r, &data, NULL)) >= 0)
+	{
+		switch(result)
+		{
+			case MFS_INTERIM_DATA:
+				i = ((struct mfs_interim_data *)r)->count;
+				(*packets)++;
+				(*bytes) += i;
+				ri.error = mfs_client_readdir_transfer(data, i,
+							dirent, filldir);
+				if((result = mfs_client_send(con,
+					MFS_INTERIM_READDIR, &ri, sizeof(ri),
+					NULL, 0, NULL, 0)))
+					done = 1;
+				break;
+			case MFS_REPLY_READDIR:
+				done = 1;
+				(*bytes) += r->datalen;
+				if(!r->datalen ||
+					!(result = mfs_client_readdir_transfer(
+					data, r->datalen, dirent, filldir)))
+					result = r->result;
+				cp_file_fields(filp, &r->file);
+				if(result >= 0)
+					mfs_file_up_to_date(filp);
+				break;
+			default:
+				printk("mfs_client_readdir: unexpected reply %d\n", result);
+				result = -EINVAL;
+				done = 1;
+				break;
+		}
+		if(r)
+			kfree(r);
+	}
+	mfs_release_contact(con);
+	return(result);
+}
+
+int
+mfs_client_ioctl(int pe, mfs_handle_t handle, struct file *filp,
+		unsigned int cmd, unsigned long arg, int size, int *data)
+{
+	struct mfs_request_ioctl s;
+	struct mfs_reply_ioctl *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.file = *filp;
+	s.cmd = cmd;
+	s.arg = arg;
+	s.data = *data;
+	s.size = size;
+	con = mfs_new_request(pe, MFS_REQUEST_IOCTL, &s, sizeof(s), NULL, 0,
+								NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_IOCTL)
+	{
+		cp_file_fields(filp, &r->file);
+		if(size < 0)
+			*data = r->data;
+		err = r->result;
+		if(err >= 0)
+			mfs_file_up_to_date(filp);
+	}
+	else if(err >= 0)
+	{
+		printk("mfs_client_ioctl: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+int
+mfs_client_fsync(int pe, mfs_handle_t handle, struct file *filp, int datasync)
+{
+	struct mfs_request_fsync s;
+	struct mfs_reply_fsync *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.file = *filp;
+	s.datasync = datasync;
+	con = mfs_new_request(pe, MFS_REQUEST_FSYNC, &s, sizeof(s), NULL, 0,
+								NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_FSYNC)
+	{
+		cp_file_fields(filp, &r->file);
+		err = r->result;
+		if(err >= 0)
+			mfs_file_up_to_date(filp);
+	}
+	else if(err >= 0)
+	{
+		printk("mfs_client_fsync: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+int
+mfs_client_revalidate(int pe, mfs_handle_t handle, struct subinode *iinfo)
+{
+	struct mfs_request_revalidate s;
+	struct mfs_reply_revalidate *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	con = mfs_new_request(pe, MFS_REQUEST_REVALIDATE, &s, sizeof(s),
+							NULL, 0, NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_REVALIDATE)
+	{
+		*iinfo = r->iinfo;
+		err = r->result;
+	}
+	else if(err >= 0)
+	{
+		printk("mfs_client_revalidate: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+int
+mfs_client_express_lookup(int pe, mfs_handle_t *handle, char *name,
+	unsigned int follow, struct subinode *iinfo, char **newname,
+	struct mfs_completion *complete)
+{
+	struct mfs_request_express s;
+	struct mfs_reply_express *r;
+	struct mfs_client_contact *con;
+	int err;
+	void *name_back, *more_data;
+
+	*newname = NULL;
+	pack_credits(&s.cred);
+	s.handle = *handle;
+	s.namelen = strlen(name) + 1;
+	s.follow = follow;
+	s.link_count = current->link_count;
+	s.total_link_count = current->total_link_count;
+	s.complete = *complete;
+	con = mfs_new_request(pe, MFS_REQUEST_EXPRESS, &s, sizeof(s),
+				(void *)name, s.namelen,
+				s.complete.more_data, s.complete.more_data_len);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, &name_back, &more_data);
+	if(err == MFS_REPLY_EXPRESS)
+	{
+		*handle = r->handle;
+		*iinfo = r->iinfo;
+		*complete = r->complete;
+		err = r->result;
+		if(!err)
+		{
+			if(!r->namelen)
+				*newname = NULL;
+			else if((*newname = kmalloc(r->namelen, GFP_KERNEL)))
+				memcpy(*newname, name_back, r->namelen);
+			else
+				err = -ENOMEM;
+		}
+		if(complete->more_data)
+		{
+			if((complete->more_data =
+				kmalloc(complete->more_data_len, GFP_KERNEL)))
+				memcpy(complete->more_data, more_data,
+						complete->more_data_len);
+			else
+			{
+				if(!err)
+					err = -ENOMEM;
+				if(*newname)
+				{
+					kfree(*newname);
+					*newname = NULL;
+				}
+			}
+		}
+	}
+	else if(err >= 0)
+	{
+		printk("mfs_client_express_lookup: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+char *
+mfs_client_check_path(int pe, mfs_handle_t handle)
+{
+	struct mfs_request_checkpath s;
+	struct mfs_reply_checkpath *r;
+	char *path;
+	char *copy = NULL;
+	struct mfs_client_contact *con;
+	int err;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	con = mfs_new_request(pe, MFS_REQUEST_CHECKPATH, &s, sizeof(s), NULL, 0,
+								NULL, 0);
+	if(IS_ERR(con))
+		return(NULL);
+	err = mfs_client_receive(con, (void **)&r, (void *)&path, NULL);
+	if(err == MFS_REPLY_CHECKPATH)
+	{
+		if(r->namelen && (copy = kmalloc(r->namelen, GFP_KERNEL)))
+			memcpy(copy, path, r->namelen);
+	}
+	else if(err >= 0)
+	{
+		printk("mfs_client_check_path: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(copy);
+}
+
+int
+mfs_client_setattr(int pe, mfs_handle_t handle, struct iattr *iattr)
+{
+	struct mfs_request_setattr s;
+	struct mfs_reply_setattr *r;
+	struct mfs_client_contact *con;
+	int err;
+
+	pack_credits(&s.cred);
+	s.handle = handle;
+	s.attr = *iattr;
+	con = mfs_new_request(pe, MFS_REQUEST_SETATTR, &s, sizeof(s),
+							NULL, 0, NULL, 0);
+	if(IS_ERR(con))
+		return((int)con);
+	err = mfs_client_receive(con, (void **)&r, NULL, NULL);
+	if(err == MFS_REPLY_SETATTR)
+		err = r->result;
+	else if(err >= 0)
+	{
+		printk("mfs_client_setattr: unexpected reply %d\n", err);
+		err = -EINVAL;
+	}
+	if(r)
+		kfree(r);
+	mfs_release_contact(con);
+	return(err);
+}
+
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/complete.c linux-2.4.16-mosix/fs/mfs/complete.c
--- linux-2.4.16/fs/mfs/complete.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/complete.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,731 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <asm/uaccess.h>
+#include <linux/slab.h>
+#include <linux/mfs.h>
+#include <linux/utime.h>
+#include <linux/smp_lock.h>
+#include <linux/quotaops.h>
+
+extern struct dentry *lookup_create(struct nameidata *, int);
+extern int chown_common(struct dentry *, uid_t, gid_t);
+
+#define	MAX_READLINK	10240
+
+void
+mfs_prepare_other(struct mfs_completion *c, struct nameidata *ond)
+{
+	struct dentry *other = ond->dentry;
+	struct mfs_dinfo *info;
+
+	if(other->d_sb != mfs_super ||
+		!(info = (struct mfs_dinfo *)other->d_fsdata))
+		c->other_pe = 0;
+	else
+	{
+		c->other_pe = info->pe;
+		c->other = info->handle;
+		if(atomic_read(&other->d_count) > 1)
+			c->dispose_other = 0;
+		else
+		{
+			kfree(info);
+			other->d_fsdata = NULL;
+			c->dispose_other = 1;
+		}
+	}
+}
+
+void
+mfs_prepare_utime(struct mfs_completion *c, time_t *pa, time_t *pm)
+{
+	if(get_user(c->args.times.a, pa) || get_user(c->args.times.m, pm))
+	{
+		c->needed = 0;
+		c->error = -EFAULT;
+	}
+}
+
+void
+mfs_prepare_completion(struct mfs_completion *c, struct nameidata *nd)
+{
+	struct dentry *base = nd->dentry;
+	struct utimbuf *ut;
+	struct timeval *uts;
+	struct mfs_dinfo *info;
+
+	c->done = 0;
+	c->other_pe = 0;
+	c->dispose_other = 0;
+	c->more_data = NULL;
+	c->more_data_len = 0;
+	c->error = 0;
+	c->ro = mfs_is_ro;
+#ifdef CONFIG_MOSIX_DIAG
+	if(nd->mnt->mnt_sb != mfs_super)
+		panic("mfs_prepare_completion: bad base\n");
+#endif /* CONFIG_MOSIX_DIAG */
+	c->dispose_base = 0;
+	if((info = (struct mfs_dinfo *)base->d_fsdata))
+	{
+		c->base_pe = info->pe;
+		c->base = info->handle;
+		if(atomic_read(&base->d_count) == 1)
+		{
+			kfree(info);
+			base->d_fsdata = NULL;
+			c->dispose_base = 1;
+		}
+	}
+	else
+	{
+		c->base_pe = 0;
+		c->base = MFS_ROOT_INO;
+	}
+	if(!(c->needed = ((nd->flags & LOOKUP_COMPLETE) != 0)))
+		return;
+	c->args = nd->complete_args;
+	switch(c->func = nd->express_function)
+	{
+		case EF_OPEN:
+		case EF_ACCESS:
+		case EF_UNLINK:
+		case EF_MKDIR:
+		case EF_RMDIR:
+		case EF_TRUNCATE:
+		case EF_CHOWN:
+		case EF_CHMOD:
+		case EF_MKNOD:
+			return;
+		case EF_RENAME:
+			if(nd->complete_args.oldnd->last_type == LAST_NORM)
+			{
+				c->more_data = (char *)
+					nd->complete_args.oldnd->last.name;
+				c->more_data_len = strlen(c->more_data)+1;
+			}
+			/* fall through */
+		case EF_LINK:
+			mfs_prepare_other(c, nd->complete_args.oldnd);
+			return;
+		case EF_SYMLINK:
+			c->more_data = nd->complete_parg;
+			c->more_data_len = strlen(c->more_data)+1;
+			return;
+		case EF_READLINK:
+			if(c->args.buffer.bufsiz > MAX_READLINK)
+				c->args.buffer.bufsiz = MAX_READLINK;
+			return;
+		case EF_UTIME:
+			ut = (struct utimbuf *)nd->complete_parg;
+			if(ut)
+				mfs_prepare_utime(c, &ut->actime, &ut->modtime);
+			else
+				c->other_pe = 1;
+			return;
+		case EF_UTIMES:
+			uts = (struct timeval *)nd->complete_parg;
+			if(uts)
+				mfs_prepare_utime(c, &uts[0].tv_sec,
+								&uts[1].tv_sec);
+			else
+				c->other_pe = 1;
+			return;
+		case EF_STAT:
+			nd->complete_parg = NULL;
+			return;
+		default:
+			c->needed = 0;
+			return;
+	}
+}
+
+int
+mfs_low_complete_link(struct mfs_completion *c, struct nameidata *nd)
+{
+	struct nameidata ond;
+	int err;
+	struct dentry *new_dentry;
+
+	if(c->other_pe != MFS_PE)
+		return(-EXDEV);
+	if((err = mfs_to_local(c->other, &ond)))
+		return(err);
+	err = -EXDEV;
+	if(ond.mnt != nd->mnt)
+		goto out;
+	new_dentry = lookup_create(nd, 0);
+	if(IS_ERR(new_dentry))
+		err = PTR_ERR(new_dentry);
+	else
+	{
+		err = vfs_link(ond.dentry, nd->dentry->d_inode, new_dentry);
+		dput(new_dentry);
+	}
+	up(&nd->dentry->d_inode->i_sem);
+	out:
+	mfs_lput(ond.dentry, ond.mnt);
+	return(err);
+}
+
+int
+mfs_low_complete_unlink(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct dentry *dentry;
+
+	if(nd->last_type != LAST_NORM)
+		return(-EISDIR);
+	down(&nd->dentry->d_inode->i_sem);
+	dentry = lookup_hash(&nd->last, nd->dentry);
+	if(IS_ERR(dentry))
+		err = PTR_ERR(dentry);
+	else
+	{
+		if(!dentry->d_inode)
+			err = -ENOENT;
+		else if(nd->last.name[nd->last.len])
+			err = S_ISDIR(dentry->d_inode->i_mode) ?
+							-EISDIR : -ENOTDIR;
+		else
+			err = vfs_unlink(nd->dentry->d_inode, dentry);
+		dput(dentry);
+	}
+	up(&nd->dentry->d_inode->i_sem);
+	return(err);
+}
+
+int
+mfs_low_complete_symlink(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct dentry *dentry;
+
+	dentry = lookup_create(nd, 0);
+	if(IS_ERR(dentry))
+		err = PTR_ERR(dentry);
+	else
+	{
+		err = vfs_symlink(nd->dentry->d_inode, dentry, c->more_data);
+		dput(dentry);
+	}
+	up(&nd->dentry->d_inode->i_sem);
+	return(err);
+}
+
+int
+mfs_low_complete_mkdir(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct dentry *dentry;
+
+	dentry = lookup_create(nd, 1);
+	if(IS_ERR(dentry))
+		err = PTR_ERR(dentry);
+	else
+	{
+		err = vfs_mkdir(nd->dentry->d_inode, dentry, c->args.ints.i1);
+		dput(dentry);
+	}
+	up(&nd->dentry->d_inode->i_sem);
+	return(err);
+}
+
+int
+mfs_low_complete_mknod(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct dentry *dentry;
+	int mode = c->args.ints.i1;
+
+	dentry = lookup_create(nd, 1);
+	if(IS_ERR(dentry))
+		err = PTR_ERR(dentry);
+	else
+	{
+		switch(mode & S_IFMT)
+		{
+			case 0:
+			case S_IFREG:
+				err = vfs_create(nd->dentry->d_inode, dentry,
+									mode);
+				break;
+			case S_IFCHR:
+			case S_IFBLK:
+			case S_IFIFO:
+			case S_IFSOCK:
+			case S_IFDIR:
+				err = -EPERM;
+				break;
+			default:
+				err = -EINVAL;
+				break;
+		}
+		dput(dentry);
+	}
+	up(&nd->dentry->d_inode->i_sem);
+	return(err);
+}
+
+int
+mfs_low_complete_rmdir(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct dentry *dentry;
+
+	switch(nd->last_type)
+	{
+		case LAST_NORM:
+			break;
+		case LAST_DOTDOT:
+			return(-ENOTEMPTY);
+		default:
+			return(-EBUSY);
+	}
+	down(&nd->dentry->d_inode->i_sem);
+	dentry = lookup_hash(&nd->last, nd->dentry);
+	if(IS_ERR(dentry))
+		err = PTR_ERR(dentry);
+	else
+	{
+		err = vfs_rmdir(nd->dentry->d_inode, dentry);
+		dput(dentry);
+	}
+	up(&nd->dentry->d_inode->i_sem);
+	return(err);
+}
+
+int
+mfs_low_complete_rename(struct mfs_completion *c, struct nameidata *newnd)
+{
+	struct nameidata ond;
+	int err;
+	struct dentry *old_dir, *new_dir;
+	struct dentry *old_dentry, *new_dentry;
+
+	if(c->other_pe != MFS_PE)
+		return(-EXDEV);
+	if((err = mfs_to_local(c->other, &ond)))
+		return(err);
+	if(c->more_data_len)
+	{
+		unsigned int hash = init_name_hash();
+		const unsigned char *n;
+
+		ond.last_type = LAST_NORM;
+		ond.last.name = c->more_data;
+		ond.last.len = strlen(c->more_data);
+		for(n = ond.last.name ; *n && *n != '/' ; n++)
+			hash = partial_name_hash(*n, hash);
+		ond.last.hash = end_name_hash(hash);
+	}
+	err = -EXDEV;
+	if(ond.mnt != newnd->mnt)
+		goto out;
+	err = -EBUSY;
+	if (ond.last_type != LAST_NORM || newnd->last_type != LAST_NORM)
+		goto out;
+	old_dir = ond.dentry;
+	new_dir = newnd->dentry;
+	double_lock(new_dir, old_dir);
+
+	old_dentry = lookup_hash(&ond.last, old_dir);
+	err = PTR_ERR(old_dentry);
+	if (IS_ERR(old_dentry))
+		goto out1;
+	/* source must exist */
+	err = -ENOENT;
+	if (!old_dentry->d_inode)
+		goto out2;
+	/* unless the source is a directory trailing slashes give -ENOTDIR */
+	if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
+		err = -ENOTDIR;
+		if (ond.last.name[ond.last.len])
+			goto out2;
+		if (newnd->last.name[newnd->last.len])
+			goto out2;
+	}
+	new_dentry = lookup_hash(&newnd->last, new_dir);
+	err = PTR_ERR(new_dentry);
+	if (IS_ERR(new_dentry))
+		goto out2;
+
+	lock_kernel();
+	err = vfs_rename(old_dir->d_inode, old_dentry, new_dir->d_inode,
+								new_dentry);
+	unlock_kernel();
+
+	dput(new_dentry);
+	out2:
+	dput(old_dentry);
+	out1:
+	double_up(&new_dir->d_inode->i_sem, &old_dir->d_inode->i_sem);
+	out:
+	mfs_lput(ond.dentry, ond.mnt);
+	return(err);
+}
+
+int
+mfs_low_complete_readlink(struct mfs_completion *c, struct nameidata *nd)
+{
+	char *buf;
+	mm_segment_t old_fs = get_fs();
+	int err;
+	struct inode *ip = nd->dentry->d_inode;
+	int sz = c->args.buffer.bufsiz;
+
+	if(!ip)
+		return(-ENOENT);
+	if(!ip->i_op || !ip->i_op->readlink)
+		return(-EINVAL);
+	if(ip->i_op && ip->i_op->revalidate &&
+		(err = ip->i_op->revalidate(nd->dentry)))
+		return(err);
+	if(!(buf = kmalloc(sz, GFP_KERNEL)))
+		return(-ENOMEM);
+	UPDATE_ATIME(ip);
+	set_fs(KERNEL_DS);
+	if(!ip->i_op || !ip->i_op->readlink)
+		err = -EINVAL;
+	else
+		err = ip->i_op->readlink(nd->dentry, buf, sz);
+	set_fs(old_fs);
+	if(err > 0)
+	{
+		c->more_data = buf;
+		c->more_data_len = err;
+	}
+	else
+		kfree(buf);
+	return(err);
+}
+
+int
+mfs_low_complete_truncate(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct inode *ip = nd->dentry->d_inode;
+
+	if(!S_ISREG(ip->i_mode))
+		return(-EACCES);
+	if((err = permission(ip, MAY_WRITE)))
+		return(err);
+	if(IS_RDONLY(ip))
+		return(-EROFS);
+	if(IS_IMMUTABLE(ip) || IS_APPEND(ip))
+		return(-EPERM);
+	if((err = get_write_access(ip)))
+		return(err);
+	if(!(err = locks_verify_truncate(ip, NULL, c->args.len)))
+	{
+		DQUOT_INIT(ip);
+		err = do_truncate(nd->dentry, c->args.len);
+	}
+	put_write_access(ip);
+	return(err);
+}
+
+int
+mfs_low_complete_utime(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct iattr newattrs;
+	struct inode *ip = nd->dentry->d_inode;
+
+	if(IS_RDONLY(ip))
+		return(-EROFS);
+	newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
+	if(c->other_pe)
+	{
+		if((err = permission(ip, MAY_WRITE)))
+			return(err);
+	}
+	else
+	{
+		newattrs.ia_atime = c->args.times.a;
+		newattrs.ia_mtime = c->args.times.m;
+		newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
+	}
+	return(notify_change(nd->dentry, &newattrs));
+}
+
+int
+mfs_low_complete_chmod(struct mfs_completion *c, struct nameidata *nd)
+{
+	struct iattr newattrs;
+	mode_t mode = c->args.mode;
+	struct inode *ip = nd->dentry->d_inode;
+
+	if(IS_RDONLY(ip))
+		return(-EROFS);
+	if(IS_IMMUTABLE(ip) || IS_APPEND(ip))
+		return(-EPERM);
+	if (mode == (mode_t) -1)
+		mode = ip->i_mode;
+	newattrs.ia_mode = (mode & S_IALLUGO) | (ip->i_mode & ~S_IALLUGO);
+	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
+	return(notify_change(nd->dentry, &newattrs));
+}
+
+int
+mfs_low_complete_stat(struct mfs_completion *c, struct nameidata *nd)
+{
+	int err;
+	struct inode *ip = nd->dentry->d_inode;
+
+	if (ip->i_op && ip->i_op->revalidate &&
+		(err = ip->i_op->revalidate(nd->dentry)))
+		return(err);
+	if(!(c->more_data = kmalloc(sizeof(struct subinode), GFP_KERNEL)))
+		return(-ENOMEM);
+	c->more_data_len = sizeof(struct subinode);
+	ip = nd->dentry->d_inode;
+	mfs_ip_to_subip((struct subinode *)c->more_data, ip);
+	((struct subinode *)c->more_data)->si_ino = global_inum(ip);
+	return(0);
+}
+
+mfs_handle_t
+mfs_low_complete(struct mfs_completion *c, struct nameidata *nd)
+{
+	mfs_handle_t result;
+
+	if(!c->needed)
+		goto export;
+	c->error = 0;
+	c->done = 1;
+	if(c->ro)
+		current->mosix.dirty_bits |= MFSARG_RONLY;
+	switch(c->func)
+	{
+		case EF_OPEN:
+			c->error = open_namei(NULL, c->args.ints.i1,
+							c->args.ints.i2, nd);
+			break;
+		case EF_ACCESS:
+			c->error = permission(nd->dentry->d_inode,
+							c->args.ints.i1);
+			break;
+		case EF_LINK:
+			c->error = mfs_low_complete_link(c, nd);
+			break;
+		case EF_UNLINK:
+			c->error = mfs_low_complete_unlink(c, nd);
+			break;
+		case EF_SYMLINK:
+			c->error = mfs_low_complete_symlink(c, nd);
+			c->more_data = NULL;
+			c->more_data_len = 0;
+			break;
+		case EF_MKDIR:
+			c->error = mfs_low_complete_mkdir(c, nd);
+			break;
+		case EF_MKNOD:
+			c->error = mfs_low_complete_mknod(c, nd);
+			break;
+		case EF_RMDIR:
+			c->error = mfs_low_complete_rmdir(c, nd);
+			break;
+		case EF_RENAME:
+			c->error = mfs_low_complete_rename(c, nd);
+			c->more_data = NULL;
+			c->more_data_len = 0;
+			break;
+		case EF_READLINK:
+			c->error = mfs_low_complete_readlink(c, nd);
+			break;
+		case EF_TRUNCATE:
+			c->error = mfs_low_complete_truncate(c, nd);
+			break;
+		case EF_UTIME:
+		case EF_UTIMES:
+			c->error = mfs_low_complete_utime(c, nd);
+			break;
+		case EF_CHMOD:
+			c->error = mfs_low_complete_chmod(c, nd);
+			break;
+		case EF_CHOWN:
+			c->error = chown_common(nd->dentry, c->args.ids.uid,
+							c->args.ids.gid);
+			break;
+		case EF_STAT:
+			c->error = mfs_low_complete_stat(c, nd);
+			break;
+		default:
+			c->done = 0;
+			break;
+	}
+	current->mosix.dirty_bits &= ~MFSARG_RONLY;
+	if(c->dispose_other && c->other_pe == MFS_PE)
+	{
+		c->dispose_other = 0;
+		mfs_low_dispose_handle(c->other);
+	}
+	if(c->dispose_base && c->base_pe == MFS_PE)
+	{
+		c->dispose_base = 0;
+		mfs_low_dispose_handle(c->base);
+	}	
+	if(c->done && (c->func != EF_OPEN || c->error))
+		return(0);
+	export:
+	if(!(result = local_to_mfs(nd)))
+	{
+		if(c->more_data)
+		{
+			kfree(c->more_data);
+			c->more_data = NULL;
+			c->more_data_len = 0;
+		}
+		c->error = -ENOMEM;
+		path_release(nd);
+		if(c->needed)
+			c->done = 1;
+	}
+	return(result);
+}
+
+void
+mfs_low_complete_error(struct mfs_completion *c, int err)
+{
+	if(c->dispose_base && c->base_pe == MFS_PE)
+	{
+		c->dispose_base = 0;
+		mfs_low_dispose_handle(c->base);
+	}
+	if(c->dispose_other && c->other_pe == MFS_PE)
+	{
+		c->dispose_other = 0;
+		mfs_low_dispose_handle(c->other);
+	}
+	c->error = err;
+	c->more_data = NULL;	/* in case of EF_SYMLINK */
+	c->more_data_len = 0;
+	if(c->needed)
+		c->done = 1;
+}
+
+int
+mfs_check_completion(struct mfs_completion *c, struct nameidata *nd)
+{
+	struct inode *inode;
+	struct subinode *subip;
+
+	if(c->dispose_other)
+		mfs_dispose_handle(c->other_pe, c->other);
+	if(c->dispose_base)
+		mfs_dispose_handle(c->base_pe, c->base);
+	if(!c->done)
+		return(0);
+	nd->complete_flags |= COMPLETE_DONE;
+	if(c->error && (c->func != EF_READLINK || c->error < 0))
+		return(1);
+	switch(c->func)
+	{
+		case EF_OPEN:
+			return(0);
+		case EF_STAT:
+			nd->complete_parg = NULL;
+			if(!(subip = (struct subinode *)c->more_data))
+			{
+				if(!c->error)
+					c->error = -ENOMEM;
+				return(1);
+			}
+			if((inode = (struct inode *)
+				    kmalloc(sizeof(struct inode), GFP_KERNEL)))
+			{
+				path_release(nd);
+				mfs_subip_to_ip(inode, subip);
+				inode->i_ino =
+				    ((struct subinode *)c->more_data)->si_ino;
+				inode->i_dev = mfs_super->s_dev;
+				inode->u.mfs_i.pe = c->other_pe;
+				nd->complete_parg = inode;
+				/* the caller must later kfree this! */
+			}
+			else if(!c->error)
+				c->error = -ENOMEM;
+			kfree(subip);
+			return(1);
+		case EF_READLINK:
+			if(c->more_data)
+			{
+				if(c->error >= 0 &&
+					copy_to_user((void *)c->args.buffer.buf,
+					c->more_data, c->more_data_len))
+					c->error = -EFAULT;
+				kfree(c->more_data);
+				path_release(nd);
+			}
+			else if(c->error >= 0)
+				c->error = -ENOMEM;
+			return(1);
+		default:
+			path_release(nd);
+		case 0:
+			return(1);
+	}
+}
+
+int
+mfs_link_complete(struct mfs_completion *c, int pe, struct nameidata *nd)
+{
+	int result;
+	char node[6];
+	int len, copy;
+	struct inode *ip;
+
+	if(c->dispose_other)
+		mfs_dispose_handle(c->other_pe, c->other);
+	if(c->dispose_base)
+		mfs_dispose_handle(c->base_pe, c->base);
+	if(!c->needed)
+		return(-EPERM);
+	nd->complete_flags |= COMPLETE_DONE;
+	switch(c->func)
+	{
+		case EF_READLINK:
+			sprintf(node, "%d", pe);
+			len = strlen(node);
+			result = copy = min(len, c->args.buffer.bufsiz);
+			if(copy_to_user((void *)c->args.buffer.buf, node, copy))
+				return(-EFAULT);
+			break;
+		case EF_STAT:
+			if(!(ip = (struct inode *)
+				    kmalloc(sizeof(*ip), GFP_KERNEL)))
+				return(-ENOMEM);
+			nd->complete_parg = ip;
+			memset(ip, 0, sizeof(*ip));
+			ip->i_dev = mfs_super->s_dev;
+			ip->i_ino = pe;
+			ip->u.mfs_i.pe = pe;
+			ip->i_mode = S_IFLNK | 0555;
+			ip->i_nlink = 1;
+			for(len = pe ; len ; len /= 10)
+				ip->i_size++;
+			ip->i_version = pe;
+			result = 0;
+			break;
+		default:
+			return(-EPERM);
+	}
+	path_release(nd);
+	return(result);
+}
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/convert.c linux-2.4.16-mosix/fs/mfs/convert.c
--- linux-2.4.16/fs/mfs/convert.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/convert.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,629 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mosix.h>
+#include <linux/slab.h>
+#include <linux/mfs.h>
+#include <asm/uaccess.h>
+
+static struct semaphore mfsc_sem = __MUTEX_INITIALIZER(mfsc_sem);
+
+mfs_handle_t mfs_unique;
+struct dentry *mfs_root;
+struct vfsmount *mfs_mnt;
+ino_t mfs_root_ino;
+dev_t mfs_root_dev;
+int mfs_root_usage;
+
+#define	MFS_HASHES	64
+struct mfs_map
+{
+	struct list_head llist;
+	struct list_head glist;
+	mfs_handle_t handle;
+	struct dentry *l;
+	struct vfsmount *mnt;
+	int dcount;	/* inc: local_to_mfs ; dec: mfs_put_handle */
+	int usecount;	/* inc: mfs_to_local ; dec: mfs_lput */
+	unsigned long latest;
+};
+
+static struct list_head lhash[MFS_HASHES], ghash[MFS_HASHES];
+
+static inline int
+hash_dentry(struct dentry *d)
+{
+	return(((((unsigned int)d) >> 8) + (((unsigned int)d) >> 14) +
+		(((unsigned int)d) >> 20)) % MFS_HASHES);
+}
+
+static inline int
+hash_handle(mfs_handle_t l)
+{
+	unsigned int h = l;
+
+	return((h+(h>>6)+(h>>12)+(h>>18)+(h>>24)) % MFS_HASHES);
+}
+
+int
+mfs_conversion_init(void)
+{
+	int i;
+
+	if(!mfs_unique)
+	{
+		mfs_root = dget(current->fs->root);
+		mfs_mnt = mntget(current->fs->rootmnt);
+		mfs_root_ino = mfs_root->d_inode->i_ino;
+		mfs_root_dev = mfs_root->d_inode->i_dev;
+		mfs_unique = ((mfs_handle_t) CURRENT_TIME) << 31;
+		if(mfs_unique <= MFS_ROOT_INO)	/* 0 time? */
+			mfs_unique = MFS_ROOT_INO + 1;
+		for(i = 0 ; i < MFS_HASHES ; i++)
+		{
+			INIT_LIST_HEAD(&lhash[i]);
+			INIT_LIST_HEAD(&ghash[i]);
+		}
+	}
+	return(0);
+}
+
+void
+mfs_put(struct mfs_map *m, int putuse)
+{
+	struct list_head *x, *nex, *prv;
+
+	if(putuse)
+		m->usecount--;
+	else
+		m->dcount--;
+	if(m->usecount > 0 || m->dcount > 0)
+		return;
+	x = &m->llist;
+	nex = x->next;
+	prv = x->prev;
+	nex->prev = prv;
+	prv->next = nex;
+	x = &m->glist;
+	nex = x->next;
+	prv = x->prev;
+	nex->prev = prv;
+	prv->next = nex;
+	dput(m->l);
+	mntput(m->mnt);
+	kfree(m);
+}
+
+void
+mfs_change_root(struct dentry *from, struct vfsmount *frommnt,
+				struct dentry *to, struct vfsmount *tomnt)
+{
+	int h;
+	struct list_head *head, *x;
+	struct mfs_map *m, *new = NULL;
+	int new_root_usage = 0;
+
+	down(&mfsc_sem);
+	if(from != mfs_root || frommnt != mfs_mnt ||
+					(to == from && tomnt == frommnt))
+		goto out;
+	if(mfs_root_usage && !(new = (struct mfs_map *)
+			kmalloc(sizeof (struct mfs_map), GFP_KERNEL)))
+	{
+		printk("MFS root failed to change (ENOMEM)!\n");
+		goto out;
+	}
+
+	/* is the new root listed? (if so, and no external refs, remove it) */
+	head = &lhash[hash_dentry(to)];
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, llist));
+		if(m->l == to && m->mnt == tomnt)
+		{
+			new_root_usage = m->dcount;
+			m->dcount = 1;
+			mfs_put(m, 0);
+			break;
+		}
+	}
+
+	if(mfs_root_usage)
+	{
+		/* someone is actively using the old root,
+		 * so we must set it up as a normal hashed entry */
+		new->l = dget(from);
+		new->mnt = mntget(frommnt);
+		new->dcount = 0;
+		new->usecount = mfs_root_usage;
+		new->handle = mfs_unique++;
+		new->latest = jiffies;
+		h = hash_dentry(from);
+		new->llist.next = lhash[h].next;
+		lhash[h].next->prev = &new->llist;
+		new->llist.prev = &lhash[h];
+		lhash[h].next = &new->llist;
+		h = hash_handle(new->handle);
+		new->glist.next = ghash[h].next;
+		ghash[h].next->prev = &new->glist;
+		new->glist.prev = &ghash[h];
+		ghash[h].next = &new->glist;
+		new = NULL;
+	}
+	dget(to);
+	mntget(tomnt);
+	mfs_root = to;
+	mfs_mnt = tomnt;
+	mfs_root_ino = to->d_inode->i_ino;
+	mfs_root_dev = to->d_inode->i_dev;
+	mfs_root_usage = new_root_usage;
+	dput(from);
+	mntput(frommnt);
+	if(new)
+		kfree(new);
+	out:
+	up(&mfsc_sem);
+}
+
+mfs_handle_t
+local_to_mfs(struct nameidata *local)
+{
+	struct dentry *dp = local->dentry;
+	struct vfsmount *mnt = local->mnt;
+	int h = hash_dentry(dp);
+	struct list_head *head = &lhash[h], *x;
+	struct mfs_map *m;
+
+	down(&mfsc_sem);
+	if(dp == mfs_root && mnt == mfs_mnt)
+	{
+		up(&mfsc_sem);
+		return(MFS_PE);
+	}
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, llist));
+		if(m->l == dp && mnt == mnt)
+		{
+			m->dcount++;
+			up(&mfsc_sem);
+			return(m->handle);
+		}
+	}
+	if(!(m = (struct mfs_map *)kmalloc(sizeof (struct mfs_map),GFP_KERNEL)))
+	{
+		up(&mfsc_sem);
+		return(0);
+	}
+	m->l = dget(dp);
+	m->mnt = mntget(mnt);
+	m->dcount = 1;
+	m->usecount = 0;
+	m->handle = mfs_unique++;
+	m->llist.next = lhash[h].next;
+	lhash[h].next->prev = &m->llist;
+	m->llist.prev = &lhash[h];
+	lhash[h].next = &m->llist;
+	h = hash_handle(m->handle);
+	m->glist.next = ghash[h].next;
+	ghash[h].next->prev = &m->glist;
+	m->glist.prev = &ghash[h];
+	ghash[h].next = &m->glist;
+	m->latest = jiffies;
+	up(&mfsc_sem);
+	return(m->handle);
+}
+
+int
+mfs_to_local(mfs_handle_t handle, struct nameidata *local)
+{
+	struct list_head *head, *x, *nex, *prv;
+	struct mfs_map *m;
+
+	down(&mfsc_sem);
+	if(handle == MFS_PE)
+	{
+		its_the_root:
+		mfs_root_usage++;
+		local->dentry = mfs_root;
+		local->mnt = mfs_mnt;
+		up(&mfsc_sem);
+		return(0);
+	}
+	if(handle < MFS_ROOT_INO)
+	{
+		up(&mfsc_sem);
+		return(-EINVAL);
+	}
+	head = &ghash[hash_handle(handle)];
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, glist));
+		if(m->handle == handle)
+		{
+			local->dentry = m->l;
+			local->mnt = m->mnt;
+			if(m->l == mfs_root && m->mnt == mfs_mnt)
+				/* very rare, but possible after root change */
+				goto its_the_root;
+			m->usecount++;
+			/* move to head of queues: */
+			if(x != head->next)
+			{
+				nex = x->next;
+				prv = x->prev;
+				nex->prev = prv;
+				prv->next = nex;
+				x->next = head->next;
+				x->prev = head;
+				x->next->prev = x;
+				head->next = x;
+			}
+			head = &lhash[hash_dentry(local->dentry)];
+			x = &m->llist;
+			if(x != head->next)
+			{
+				nex = x->next;
+				prv = x->prev;
+				nex->prev = prv;
+				prv->next = nex;
+				x->next = head->next;
+				x->prev = head;
+				x->next->prev = x;
+				head->next = x;
+			}
+			m->latest = jiffies;
+			up(&mfsc_sem);
+			return(0);
+		}
+	}
+	up(&mfsc_sem);
+	printk("MFS: Handle %016LX not found (obsolete)\n", handle);
+	return(-ESTALE);
+}
+
+void
+mfs_lput(struct dentry *dp, struct vfsmount *mnt)
+{
+	struct list_head *head, *x;
+	struct mfs_map *m;
+
+	down(&mfsc_sem);
+	if(dp == mfs_root && mnt == mfs_mnt)
+	{
+		mfs_root_usage--;
+		up(&mfsc_sem);
+		return;
+	}
+	head = &lhash[hash_dentry(dp)];
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, llist));
+		if(m->l == dp && m->mnt == mnt)
+		{
+			mfs_put(m, 1);
+			up(&mfsc_sem);
+			return;
+		}
+	}
+	up(&mfsc_sem);
+	printk("mfs_lput: no handle!\n");
+}
+
+int
+mfs_get_handle(mfs_handle_t handle)
+{
+	int h = hash_handle(handle);
+	struct list_head *head = &ghash[h], *x;
+	struct mfs_map *m;
+
+	if(handle < MFS_ROOT_INO)
+		return(0);
+	down(&mfsc_sem);
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, glist));
+		if(m->handle == handle)
+		{
+			m->dcount++;
+			m->latest = jiffies;
+			up(&mfsc_sem);
+			return(0);
+		}
+	}
+	up(&mfsc_sem);
+	printk("MFS: Handle %016LX not found (obsolete) when duplicated\n",
+									handle);
+	return(-ESTALE);
+}
+
+int
+mfs_access_handle(mfs_handle_t handle)
+{
+	int h = hash_handle(handle);
+	struct list_head *head = &ghash[h], *x;
+	struct mfs_map *m;
+
+	if(handle < MFS_ROOT_INO)
+		return(0);
+	down(&mfsc_sem);
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, glist));
+		if(m->handle == handle)
+		{
+			m->latest = jiffies;
+			up(&mfsc_sem);
+			return(0);
+		}
+	}
+	up(&mfsc_sem);
+	printk("MFS: Handle %016LX not found (obsolete) when claimed\n",
+									handle);
+	return(-ESTALE);
+}
+
+void
+mfs_put_handle(mfs_handle_t handle)
+{
+	int h = hash_handle(handle);
+	struct list_head *head = &ghash[h], *x;
+	struct mfs_map *m;
+
+	if(handle < MFS_ROOT_INO)
+		return;
+	down(&mfsc_sem);
+	for(x = head->next ; x != head ; x = x->next)
+	{
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, glist));
+		if(m->handle == handle)
+		{
+			mfs_put(m, 0);
+			up(&mfsc_sem);
+			return;
+		}
+	}
+	up(&mfsc_sem);
+	printk("MFS: Handle %016LX not found (obsolete) when released\n",
+									handle);
+}
+
+int
+mfs_try_to_cleanup(int force)
+{
+	int h;
+	struct mfs_map *m;
+	struct list_head *next;
+
+	if(!mfs_unique)
+		return(0);
+	down(&mfsc_sem);
+	if(force != 2)
+	for(h = 0 ; h < MFS_HASHES ; h++)
+	while(lhash[h].next != &lhash[h])
+	{
+		m = (struct mfs_map *)((char *)lhash[h].next -
+					offsetof(struct mfs_map, llist));
+		if(!force || m->usecount)
+		{
+			busy:
+			up(&mfsc_sem);
+			return(-EBUSY);
+		}
+	}
+	for(h = 0 ; h < MFS_HASHES ; h++)
+	for(next = lhash[h].next ; next != &lhash[h] ; )
+	{
+		m = (struct mfs_map *)((char *)next -
+					offsetof(struct mfs_map, llist));
+		next = next->next;
+		if(m->usecount)
+		{
+			if(force == 2)
+				m->dcount = 0;
+			else
+				goto busy;
+		}
+		else
+		{
+			m->dcount = 1;
+			mfs_put(m, 0);
+		}
+	}
+	up(&mfsc_sem);
+	return(0);
+}
+
+void
+mfs_throw_garbage(void)
+{
+	int h;
+	struct mfs_map *m;
+	struct list_head *next;
+	int n = 0;
+
+	down(&mfsc_sem);
+	for(h = 0 ; h < MFS_HASHES ; h++)
+	for(next = lhash[h].next ; next != &lhash[h] ; )
+	{
+		m = (struct mfs_map *)((char *)lhash[h].next -
+					offsetof(struct mfs_map, llist));
+		next = next->next;
+		if(!m->usecount &&
+			time_after(jiffies, m->latest + MFS_GARBAGE_TIME))
+		{
+			m->dcount = 1;
+			mfs_put(m, 0);
+			n++;
+		}
+	}
+	up(&mfsc_sem);
+	if(n)
+		printk("MFS: Disposed of %d unclaimed entr%s\n", n,
+							n > 1 ? "ies" : "y");
+}
+
+/* why is this not in dcache.c? */
+int
+is_descendant(struct dentry *dp, struct vfsmount *mnt, struct dentry *pdp,
+							struct vfsmount *pmnt)
+{
+	spin_lock(&dcache_lock);
+	while(1)
+	{
+		if(dp == pdp && mnt == pmnt)
+		{
+			spin_unlock(&dcache_lock);
+			return(1);
+		}
+		if(dp == mnt->mnt_root)
+		{
+			struct vfsmount *xmnt = mnt->mnt_parent;
+
+			if(xmnt == mnt)
+				break;
+			dp = mnt->mnt_mountpoint;
+			mnt = xmnt;
+		}
+		else
+			dp = dp->d_parent;
+	}
+	spin_unlock(&dcache_lock);
+	return(0);
+}
+
+int
+mfs_kill(char *filename)
+{
+	int h;
+	struct mfs_map *m;
+	struct list_head *next;
+	int n = 0;
+	int error;
+	mm_segment_t old_fs;
+	struct nameidata nd;
+
+	old_fs = set_fs(KERNEL_DS);
+	error = 0;
+	if(path_init(filename, LOOKUP_POSITIVE, &nd))
+		error = path_walk(filename, &nd);
+	set_fs(old_fs);
+	if(error)
+		return(error);
+	down(&mfsc_sem);
+	for(h = 0 ; h < MFS_HASHES ; h++)
+	for(next = lhash[h].next ; next != &lhash[h] ; )
+	{
+		m = (struct mfs_map *)((char *)lhash[h].next -
+					offsetof(struct mfs_map, llist));
+		next = next->next;
+		if(is_descendant(m->l, m->mnt, nd.dentry, nd.mnt))
+		{
+			m->dcount = 1;
+			mfs_put(m, 0);
+			n++;
+		}
+	}
+	up(&mfsc_sem);
+	if(n)
+		printk("MFS_KILL: Killed %d entr%s\n", n, n > 1 ? "ies" : "y");
+	path_release(&nd);
+	return(0);
+}
+
+/* JUST FOR DEBUGGING: */
+void
+mfs_print_latest(unsigned long when)
+{
+	int diff = (when - jiffies) / HZ;
+
+	printk(", age=");
+	if(diff < 0 || diff > 24*3600)
+		printk("%ld", when);
+	else if(diff == 0)
+		printk("in %ld ticks", when - jiffies);
+	else if(diff < 6000)
+		printk("%d seconds", diff);
+	else if(diff < 3600)
+		printk("%d:%02d minutes", diff/60, diff % 60);
+	else
+		printk("%d:%02d:%02d hours", diff/3600, (diff % 3600) / 60,
+								diff % 60);
+}
+
+int
+dump_mfsc(void)
+{
+	register int h;
+	struct list_head *head, *x;
+	struct mfs_map *m;
+	int cnt = 0;
+
+	for(h = 0 ; h < MFS_HASHES ; h++)
+	for(head = &lhash[h] , x = head->next ; x != head ; x = x->next)
+	{
+		cnt++;
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, llist));
+		printk("%d: handle=%016LX, l=%x, ip=%x, count=%d, use=%d",
+			h, m->handle,
+			(int)m->l, (int)m->l->d_inode, m->dcount, m->usecount);
+		if(m->l->d_inode)
+			printk("\n        dev=%d/%d, ino=%ld, mode=0%o",
+				MAJOR(m->l->d_inode->i_dev),
+				MINOR(m->l->d_inode->i_dev),
+				m->l->d_inode->i_ino, m->l->d_inode->i_mode);
+		mfs_print_latest(m->latest);
+		printk("\n");
+	}
+	return(cnt);
+}
+
+int
+dump_mfsc2(void)
+{
+	register int h;
+	struct list_head *head, *x;
+	struct mfs_map *m;
+	int cnt = 0;
+
+	for(h = 0 ; h < MFS_HASHES ; h++)
+	for(head = &ghash[h] , x = head->next ; x != head ; x = x->next)
+	{
+		cnt++;
+		m = (struct mfs_map *)((char *)x -
+					offsetof(struct mfs_map, glist));
+		printk("%d: handle=%016LX, l=%x, ip=%x, count=%d, use=%d",
+			h, m->handle,
+			(int)m->l, (int)m->l->d_inode, m->dcount, m->usecount);
+		if(m->l->d_inode)
+			printk("\n        dev=%d/%d, ino=%ld, mode=0%o",
+				MAJOR(m->l->d_inode->i_dev),
+				MINOR(m->l->d_inode->i_dev),
+				m->l->d_inode->i_ino, m->l->d_inode->i_mode);
+		mfs_print_latest(m->latest);
+		printk("\n");
+	}
+	return(cnt);
+}
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/count.c linux-2.4.16-mosix/fs/mfs/count.c
--- linux-2.4.16/fs/mfs/count.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/count.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,282 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+
+#include <linux/sched.h>
+#if defined(CONFIG_MOSIX_FS) && defined(CONFIG_MOSIX_DFSA)
+#include <linux/mosctl.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/mfs.h>
+#include <linux/mfs_socket.h>
+#include <mos/defs.h>
+#include <linux/mosix.h>
+
+#define	weight(_c,_i,_o)	((_c)*2048+(_i)+(_o))
+#define	threshold		0xffe00000
+
+#define DEBUG_MFSCOUNT
+#ifdef DEBUG_MFSCOUNT
+int debug_mfscount;
+
+void do_dump_mfscount(struct task_struct *p)
+{
+	int i;
+	struct mfs_stats *s = p->mosix.mfs_stats;
+
+	if(!s || !s->nnodes)
+	{
+		printk("%s MFS Statistics for %d(%s)\n", s ? "Empty" : "No",
+							p->pid, p->comm);
+		return;
+	}
+	for(i = 0 ; i < s->nnodes ; i++)
+	printk("%d: node #%d, conns=%d, inbytes=%d, outbytes=%d\n", i,
+		s->nodes[i], (int)s->conns[i], (int)s->inbytes[i],
+		(int)s->outbytes[i]);
+}
+#endif /* DEBUG_MFSCOUNT */
+
+void
+mfs_count(int w, int inbytes, int outbytes)
+{
+	struct task_struct *p = current;
+	struct mfs_stats *s = p->mosix.mfs_stats;
+	register int i;
+	int64_t prev, worst = 0, best = 0;
+	int victim = -1;
+	long new_weight;
+
+	if(!mfs_is_dfsa || !(p->mosix.dflags & (DREMOTE|DSTATSDOWN)))
+		return;
+#ifdef DEBUG_MFSCOUNT
+	if(debug_mfscount > 1)
+		printk("mfs_count(%d,%d,%d): ", w, inbytes, outbytes);
+#endif /* DEBUG_MFSCOUNT */
+	if(w == 0 || w > MOSIX_MAX)
+		return;
+	if(!s)
+	{
+		if(!(s = kmalloc(sizeof(struct mfs_stats), GFP_KERNEL)))
+			return;
+		p->mosix.mfs_stats = s;
+		s->nnodes = 0;
+	}
+	new_weight = weight(1, inbytes, outbytes);
+	for(i = (s->hint < s->nnodes && s->nodes[s->hint] == w) ? s->hint :
+						s->nnodes - 1 ; i >= 0 ; i--)
+	{
+		prev = weight(s->conns[i], s->inbytes[i], s->outbytes[i]);
+		if(s->nodes[i] == w)
+		{
+			s->conns[i]++;
+			s->inbytes[i] += inbytes;
+			s->outbytes[i] += outbytes;
+			s->hint = i;
+			if(w != PE &&
+				(((((long)prev)+new_weight)^prev) & threshold))
+				mosix_add_to_whereto(p, MFSBALANCE);
+#ifdef DEBUG_MFSCOUNT
+			if(debug_mfscount)
+			{
+				printk("Successfully added <%d,%d> to %d\n",
+					inbytes, outbytes, w);
+				if(debug_mfscount > 2)
+					do_dump_mfscount(p);
+			}
+#endif /* DEBUG_MFSCOUNT */
+			return;
+		}
+		if(victim == -1)
+		{
+			best = worst = prev;
+			victim = i;
+		}
+		else
+		{
+			if(prev > best)
+				best = prev;
+			if(prev < worst)
+			{
+				worst = prev;
+				victim = i;
+			}
+		}
+	}
+	if((i = s->nnodes) < MAX_MFS_STATNODES)
+	{
+		s->nnodes++;
+		s->nodes[i] = w;
+		s->conns[i] = 1;
+		s->inbytes[i] = inbytes;
+		s->outbytes[i] = outbytes;
+		s->hint = i;
+#ifdef DEBUG_MFSCOUNT
+		if(debug_mfscount)
+		{
+			printk("New MFS stats (%d,%d) for %d\n",
+				inbytes, outbytes, w);
+			if(debug_mfscount > 2)
+				do_dump_mfscount(p);
+		}
+#endif /* DEBUG_MFSCOUNT */
+		return;
+	}
+	i = victim;
+	if(--s->conns[i] <= 0 || (s->inbytes[i] -= inbytes) <= 0 ||
+		(s->outbytes[i] -= outbytes) <= 0)
+	{
+		if(victim == --s->nnodes)
+		{
+#ifdef DEBUG_MFSCOUNT
+			if(debug_mfscount)
+			{
+				printk("Anulled victim=%d\n", s->nodes[i]);
+				if(debug_mfscount > 2)
+					do_dump_mfscount(p);
+			}
+#endif /* DEBUG_MFSCOUNT */
+			return;
+		}
+		victim = s->nnodes;
+		s->nodes[i] = s->nodes[victim];
+		s->conns[i] = s->conns[victim];
+		s->inbytes[i] = s->inbytes[victim];
+		s->outbytes[i] = s->outbytes[victim];
+		if(s->hint == victim)
+			s->hint = i;
+#ifdef DEBUG_MFSCOUNT
+		if(debug_mfscount)
+		{
+			printk("Anulled/replaced a victim\n");
+			if(debug_mfscount > 2)
+				do_dump_mfscount(p);
+		}
+#endif /* DEBUG_MFSCOUNT */
+	}
+#ifdef DEBUG_MFSCOUNT
+	else if(debug_mfscount)
+	{
+		printk("Reduced victim=%d by <%d,%d>\n", s->nodes[i],
+							inbytes, outbytes);
+		if(debug_mfscount > 2)
+			do_dump_mfscount(p);
+	}
+#endif /* DEBUG_MFSCOUNT */
+	return;
+}
+
+int
+mfs_add_stats(struct mfs_stats *add, struct mfs_stats *to, struct mosix_task *m)
+{
+	register int i, j;
+	int64_t prev, worst = 0;
+	int victim = -1;
+#if MAX_MFS_STATNODES > BITS_PER_LONG
+#error unsigned long is not enough
+#else
+	unsigned long bit, done = 0;
+#endif /* MAX_MFS_STATNODES > BITS_PER_LONG */
+	int node;
+	int ret = 0;
+
+	if(!add || !add->nnodes)
+		return(0);
+	if(!to)
+	{
+		if(!to && (!m || !(to = m->mfs_stats =
+				kmalloc(sizeof(struct mfs_stats), GFP_KERNEL))))
+			return(0);
+		*to = *add;
+		for(i = to->nnodes-1 ; i >= 0 ; i--)
+		if(weight(to->conns[i], to->inbytes[i], to->outbytes[i]) &
+								threshold)
+			return(1);
+		return(0);
+	}
+	for(i = 0 ; i < to->nnodes ; i++)
+	{
+		node = to->nodes[i];
+		for(j = 0 ; j < add->nnodes ; j++)
+		if(add->nodes[j] == node)
+		{
+			prev = weight(to->conns[i], to->inbytes[i],
+							to->outbytes[i]);
+			to->conns[i] += add->conns[i];
+			to->inbytes[i] += add->inbytes[i];
+			to->outbytes[i] += add->outbytes[i];
+			if(!ret && node != PE &&
+				(weight(to->conns[i], to->inbytes[i],
+					to->outbytes[i]) ^ prev) & threshold)
+				ret = 1;
+			done |= (1 << (j-1));
+			break;
+		}
+	}
+	for(bit = 1 , j = 0 ; j < add->nnodes ; j++ , bit <<= 1)
+	if(!(done & bit))
+	{
+		if(to->nnodes < MAX_MFS_STATNODES)
+		{
+			i = to->nnodes++;
+			to->nodes[i] = add->nodes[j];
+			to->conns[i] = add->conns[j];
+			to->inbytes[i] = add->inbytes[j];
+			to->outbytes[i] = add->outbytes[j];
+			if(!ret && (weight(to->conns[i], to->inbytes[i],
+				to->outbytes[i]) & threshold))
+				ret = 1;
+			continue;
+		}
+		for(i = 0 ; i < MAX_MFS_STATNODES ; i++)
+		{
+			prev = weight(add->conns[i], add->inbytes[i],
+							add->outbytes[i]);
+			if(i == 0 || prev < worst)
+			{
+				victim = i;
+				worst = prev;
+			}
+		}
+		if(!ret && (weight(add->conns[i], add->inbytes[i],
+						add->outbytes[i]) & threshold))
+			ret = 1;
+		to->nodes[victim] = add->nodes[i];
+		to->conns[victim] = add->conns[i];
+		to->inbytes[victim] = add->inbytes[i];
+		to->outbytes[victim] = add->outbytes[i];
+	}
+	return(ret);
+}
+
+#ifdef DEBUG_MFSCOUNT
+void
+dump_mfscount(int pid)
+{
+	struct task_struct *p;
+
+	if(!pid)
+		p = current;
+	else
+		p = find_any_task_by_pid(pid);
+	if(p)
+		do_dump_mfscount(p);
+	else
+		printk("No Such Task (%d)\n", pid);
+}
+#endif /* DEBUG_MFSCOUNT */
+
+#endif /* CONFIG_MOSIX_FS && CONFIG_MOSIX_DFSA */
diff -ruN linux-2.4.16/fs/mfs/file.c linux-2.4.16-mosix/fs/mfs/file.c
--- linux-2.4.16/fs/mfs/file.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/file.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1868 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mosix.h>
+#include <linux/mosctl.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/mfs.h>
+#include <linux/mfs_socket.h>
+#include <linux/locks.h>
+#include <linux/module.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <linux/dcache.h>
+#include <linux/quotaops.h>
+#include <linux/ext2_fs.h>
+#include <linux/file.h>
+
+int MFS_PE;
+int mfs_is_mounted;
+char mfs_is_ro;
+#ifdef CONFIG_MOSIX_DFSA
+char mfs_is_dfsa;
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_DEBUG
+int mfs_loopback_test = 0;
+#else
+#define	mfs_loopback_test	0
+#endif /* CONFIG_MOSIX_DEBUG */
+int mfs_debug;
+struct super_block *mfs_super;
+extern int may_create(struct inode *, struct dentry *);
+
+#define	AN_IMPOSSIBLE_ERROR	(-ECHILD)	/* cannot occur in FS context */
+
+ino_t
+global_inum(struct inode *ip)
+{
+	dev_t dev = ip->i_dev;
+	ino_t mask = (MFS_PE << 16) ^ (MAJOR(dev) << 16) ^ (MINOR(dev) << 24);
+	ino_t result = ip->i_ino ^ mask;
+
+	if(ip->i_ino == mfs_root_ino && dev == mfs_root_dev)
+		return(MFS_PE);
+	if(((unsigned long)result) <= MFS_ROOT_INO)
+		result ^= 0x80800000;
+	return(result);
+}
+
+inline void
+mfs_get_handling(struct dentry *dp, int *where, mfs_handle_t *handle)
+{
+	struct mfs_dinfo *p = (struct mfs_dinfo *)dp->d_fsdata;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!p)
+		panic("mfs_get_handling: no handle\n");
+#endif /* CONFIG_MOSIX_DIAG */
+	*where = p->pe;
+	*handle = p->handle;
+}
+
+inline int
+mfs_is_last_use(struct dentry *dp, int *where, mfs_handle_t *handle)
+{
+	if(dp->d_fsdata)
+	{
+		*where = ((struct mfs_dinfo *)dp->d_fsdata)->pe;
+		*handle = ((struct mfs_dinfo *)dp->d_fsdata)->handle;
+		if(atomic_read(&dp->d_count) > 1)
+			return(0);
+		kfree(dp->d_fsdata);
+		dp->d_fsdata = NULL;
+		return(1);
+	}
+	else
+	{
+		*where = 0;
+		*handle = MFS_ROOT_INO;
+		return(0);
+	}
+}
+
+inline int
+mfs_low_attach_handle(mfs_handle_t handle)
+{
+	if(handle > MFS_ROOT_INO)	/* do not waste time on root */
+		return(mfs_get_handle(handle));
+	return(0);
+}
+
+inline int
+mfs_attach_handle(int pe, mfs_handle_t handle)
+{
+	if(handle <= MFS_ROOT_INO)
+		return(0);
+	mfs_count_attach_handle(pe);
+	if(pe == MFS_PE && !mfs_loopback_test)
+		return(mfs_low_attach_handle(handle));
+	else if(pe)
+		return(mfs_client_attach_handle(pe, handle));
+	return(0);
+}
+
+inline int
+mfs_low_touch_handle(mfs_handle_t handle)
+{
+	if(handle > MFS_ROOT_INO)	/* do not waste time on root */
+		return(mfs_access_handle(handle));
+	return(0);
+}
+
+inline int
+mfs_touch_handle(int pe, mfs_handle_t handle)
+{
+	if(handle <= MFS_ROOT_INO)
+		return(0);
+	mfs_count_touch_handle(pe);
+	if(pe == MFS_PE && !mfs_loopback_test)
+		return(mfs_low_touch_handle(handle));
+	else if(pe)
+		return(mfs_client_touch_handle(pe, handle));
+	return(0);
+}
+
+inline void
+mfs_low_dispose_handle(mfs_handle_t handle)
+{
+	if(handle > MFS_ROOT_INO)	/* do not waste time on root */
+		mfs_put_handle(handle);
+}
+
+inline void
+mfs_dispose_handle(int pe, mfs_handle_t handle)
+{
+	if(handle <= MFS_ROOT_INO)
+		return;
+	mfs_count_dispose_handle(pe);
+	if(pe == MFS_PE && !mfs_loopback_test)
+		mfs_low_dispose_handle(handle);
+	else if(pe)
+		mfs_client_dispose_handle(pe, handle);
+}
+
+extern struct file_operations mfs_file_file_operations;
+extern struct file_operations mfs_symlink_file_operations;
+extern struct file_operations mfs_dir_file_operations;
+extern struct inode_operations mfs_file_inode_operations;
+extern struct inode_operations mfs_symlink_inode_operations;
+extern struct inode_operations mfs_dir_inode_operations;
+extern struct dentry_operations mfs_dentry_operations;
+
+void
+mfs_ip_to_subip(struct subinode *subip, struct inode *ip)
+{
+	subip->si_mode = ip->i_mode;
+	subip->si_nlink = ip->i_nlink;
+	subip->si_iuid = ip->i_uid;
+	subip->si_gid = ip->i_gid;
+	subip->si_rdev = ip->i_rdev;
+	subip->si_size = ip->i_size;
+	subip->si_atime = ip->i_atime;
+	subip->si_ctime = ip->i_ctime;
+	subip->si_mtime = ip->i_mtime;
+	subip->si_blksize = ip->i_blksize;
+	subip->si_blocks = ip->i_blocks;
+	subip->si_origino = ip->i_ino;
+	subip->si_origdev = ip->i_dev;
+}
+
+void
+mfs_subip_to_ip(struct inode *ip, struct subinode *subip)
+{
+	ip->i_mode = subip->si_mode;
+	ip->i_nlink = subip->si_nlink;
+	ip->i_uid = subip->si_iuid;
+	ip->i_gid = subip->si_gid;
+	ip->i_rdev = subip->si_rdev;
+	ip->i_size = subip->si_size;
+	ip->i_atime = subip->si_atime;
+	ip->i_ctime = subip->si_ctime;
+	ip->i_mtime = subip->si_mtime;
+	ip->i_blksize = subip->si_blksize;
+	ip->i_blocks = subip->si_blocks;
+	ip->i_version = subip->si_origino;
+	ip->i_generation = subip->si_origdev;
+	ip->i_sb = mfs_super;
+	switch(ip->i_mode & S_IFMT)
+	{
+		case S_IFREG:
+			ip->i_op = &mfs_file_inode_operations;
+			ip->i_fop = &mfs_file_file_operations;
+			break;
+		case S_IFLNK:
+			ip->i_op = &mfs_symlink_inode_operations;
+			ip->i_fop = &mfs_symlink_file_operations;
+			break;
+		case S_IFDIR:
+			ip->i_op = &mfs_dir_inode_operations;
+			ip->i_fop = &mfs_dir_file_operations;
+			break;
+		default:
+			printk("MFS: inum %d of bad mode (0%o)\n",
+						(int)ip->i_ino, ip->i_mode);
+			make_bad_inode(ip);
+			break;
+	}
+}
+
+void
+cp_file_fields(struct file *filto, struct file *filfrom)
+{
+	filto->f_mode = filfrom->f_mode;
+	filto->f_pos = filfrom->f_pos;
+	filto->f_owner = filfrom->f_owner;
+	filto->f_reada = filfrom->f_reada;
+	filto->f_ramax = filfrom->f_ramax;
+	filto->f_raend = filfrom->f_raend;
+	filto->f_ralen = filfrom->f_ralen;
+	filto->f_rawin = filfrom->f_rawin;
+/* the following two fields are not actually currently in use!
+	filto->f_uid = filfrom->f_uid;
+	filto->f_gid = filfrom->f_gid;
+*/
+	filto->f_error = filfrom->f_error;
+	filto->f_version = filfrom->f_version;
+	filto->private_data = filfrom->private_data;
+}
+
+int
+prepare_dummy_file(mfs_handle_t handle, struct file *dummy, struct file *filp)
+{
+	struct nameidata nd;
+	int err;
+
+	if((err = mfs_to_local(handle, &nd)))
+		return(err);
+	if(nd.dentry->d_inode && nd.dentry->d_inode->i_op)
+		dummy->f_op = nd.dentry->d_inode->i_fop;
+	else
+		dummy->f_op = NULL;
+	dummy->f_dentry = nd.dentry;
+	dummy->f_vfsmnt = nd.mnt;
+	dummy->f_flags = filp->f_flags & (O_LARGEFILE|O_SYNC);
+	dummy->f_iobuf = NULL;
+	dummy->f_iobuf_lock = 0;
+	atomic_set(&dummy->f_count, 1);
+	cp_file_fields(dummy, filp);
+	return(0);
+}
+
+void
+collect_dummy_file(struct file *dummy, struct file *filp)
+{
+	mfs_lput(dummy->f_dentry, dummy->f_vfsmnt);
+	cp_file_fields(filp, dummy);
+}
+
+loff_t
+mfs_dir_llseek(struct file *filp, loff_t offset, int origin)
+{
+	int where;
+	mfs_handle_t handle;
+
+	mfs_get_handling(filp->f_dentry, &where, &handle);
+	mfs_count_llseek(where);
+	if(where != MFS_PE || mfs_loopback_test)
+		return(mfs_client_llseek(where, handle, filp, offset, origin));
+	return(mfs_low_llseek(handle, filp, offset, origin));
+}
+
+loff_t
+mfs_file_llseek(struct file *filp, loff_t offset, int origin)
+{
+	uint64_t newoff;
+
+	switch(origin)
+	{
+		case 0:
+			newoff = offset;
+			break;
+		case 1:
+			newoff = offset + filp->f_pos;
+			break;
+		default:
+			goto must_call;
+	}
+	if(!(newoff >> 32))
+	{
+		if(newoff != filp->f_pos)
+		{
+			lock_kernel();
+			filp->f_pos = newoff;
+			filp->f_reada = 0;
+			filp->f_version = ++event;
+			unlock_kernel();
+		}
+		return(newoff);
+	}
+
+	must_call:
+	return(mfs_dir_llseek(filp, offset, origin));
+}
+
+loff_t
+mfs_low_llseek(mfs_handle_t handle, struct file *filp, loff_t offset,
+								int origin)
+{
+	loff_t ret;
+	struct file dummy;
+	extern loff_t llseek(struct file *, loff_t, int);
+
+	if((ret = prepare_dummy_file(handle, &dummy, filp)))
+		return(ret);
+	lock_kernel();
+	ret = llseek(&dummy, offset, origin);
+	unlock_kernel();
+	collect_dummy_file(&dummy, filp);
+	return(ret);
+}
+
+ssize_t
+mfs_read(struct file *filp, char *buf, size_t count, loff_t *ppos)
+{
+	int where;
+	mfs_handle_t handle;
+
+	if(!(filp->f_mode & FMODE_READ))
+		return(-EBADF);
+	mfs_get_handling(filp->f_dentry, &where, &handle);
+	mfs_count_read(where, count);
+	if(where != MFS_PE || mfs_loopback_test)
+		return(mfs_client_read(where, handle, filp, buf, count, ppos));
+	return(mfs_low_read(handle, filp, buf, count, ppos));
+}
+
+ssize_t
+mfs_low_read(mfs_handle_t handle, struct file *filp, char *buf, size_t count,
+								loff_t *ppos)
+{
+	loff_t ret;
+	struct file *dummy;
+	struct file_operations *fops;
+	loff_t mppos;
+
+	current->mosix.dirty_bits |= MFSARG_EMPTYF_PRI;
+	dummy = get_empty_filp();
+	current->mosix.dirty_bits &= ~MFSARG_EMPTYF_PRI;
+	if(!dummy)
+		return(-ENFILE);
+
+	if((ret = prepare_dummy_file(handle, dummy, filp)))
+	{
+		put_filp(dummy);
+		return(ret);
+	}
+	dget(dummy->f_dentry);
+	mntget(dummy->f_vfsmnt);
+	fops = dummy->f_dentry->d_inode->i_fop;
+	mppos = *ppos;
+#ifdef ONE_DAY_S_FILES_WILL_BE_USED_FOR_RDONLY_FILES
+	if(ip->i_sb)
+		file_move(dummy, &ip->i_sb->s_files);
+#endif /* ONE_DAY_S_FILES_WILL_BE_USED_FOR_RDONLY_FILES */
+	if(!fops || !fops->read)
+		ret = -EINVAL;
+	else
+		ret = fops->read(dummy, buf, count, &mppos);
+	collect_dummy_file(dummy, filp);
+	*ppos = mppos;
+	dummy->f_mode &= ~FMODE_WRITE;
+	fput(dummy);
+	return(ret);
+}
+
+ssize_t
+mfs_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
+{
+	int where;
+	mfs_handle_t handle;
+	int flim = current->rlim[RLIMIT_FSIZE].rlim_cur;
+
+	if(!(filp->f_mode & FMODE_WRITE))
+		return(-EBADF);
+	mfs_get_handling(filp->f_dentry, &where, &handle);
+	mfs_count_write(where, count);
+	if(where != MFS_PE || mfs_loopback_test)
+		return(mfs_client_write(where, handle, filp, (char *)buf, count,
+								ppos, flim));
+	return(mfs_low_write(handle, filp, (char *)buf, count, ppos, flim));
+}
+
+ssize_t
+mfs_low_write(mfs_handle_t handle, struct file *filp, char *buf, size_t count,
+							loff_t *ppos, long flim)
+{
+	loff_t ret;
+	struct file *dummy;
+	struct file_operations *fops;
+	struct super_block *sb;
+	struct inode *ip;
+	loff_t mppos;
+
+	/* unlike other functions, we need to allocate a dummy "file"
+	 * in the proper way, because NFS files could live even after
+	 * we exit */
+	current->mosix.dirty_bits |= MFSARG_EMPTYF_PRI;
+	dummy = get_empty_filp();
+	current->mosix.dirty_bits &= ~MFSARG_EMPTYF_PRI;
+	if(!dummy)
+		return(-ENFILE);
+	
+	if((ret = prepare_dummy_file(handle, dummy, filp)))
+	{
+		put_filp(dummy);
+		return(ret);
+	}
+	dget(dummy->f_dentry);
+	mntget(dummy->f_vfsmnt);
+	current->rlim[RLIMIT_FSIZE].rlim_cur = flim;
+	ip = dummy->f_dentry->d_inode;
+	sb = ip->i_sb;
+	fops = ip->i_fop;
+	mppos = *ppos;
+	if(filp->f_flags & O_APPEND)
+		mppos = ip->i_size;
+	if(sb)
+		file_move(dummy, &sb->s_files);
+	if(get_write_access(ip))
+		dummy->f_flags |= O_NOWRITEACCESS;
+	if((ret = locks_verify_area(FLOCK_VERIFY_WRITE, ip, NULL, mppos,count)))
+		;
+	else if(sb && (sb->s_flags & MS_RDONLY))
+		ret = -EROFS;
+	else if(!fops || !fops->write)
+		ret = -EINVAL;
+	else
+		ret = fops->write(dummy, buf, count, &mppos);
+	collect_dummy_file(dummy, filp);
+	*ppos = mppos;
+	fput(dummy);
+	return(ret);
+}
+
+int
+mfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+	int where;
+	mfs_handle_t handle;
+	struct task_struct *p = current;
+	int policy;
+	int packets, bytes;
+	int result;
+
+	switch(p->mosix.dirty_bits &
+		(MFSARG_GETDENTS|MFSARG_GETDENTS64|MFSARG_OLDREADDIR))
+	{
+		case MFSARG_GETDENTS:
+			policy = MFS_READDIR_GETDENTS;
+			break;
+		case MFSARG_GETDENTS64:
+			policy = MFS_READDIR_GETDENTS64;
+			break;
+		case MFSARG_OLDREADDIR:
+			policy = MFS_READDIR_JUSTONE;
+			break;
+		default:
+			policy = MFS_READDIR_UNKNOWN;
+			break;
+	}
+	mfs_get_handling(filp->f_dentry, &where, &handle);
+	if(where != MFS_PE || mfs_loopback_test)
+		result = mfs_client_readdir(where, handle, filp, dirent,
+			filldir, policy, p->mosix.dirty_arg, &packets, &bytes);
+	else
+		result = mfs_low_readdir(handle, filp, dirent, filldir,
+							&packets, &bytes);
+	mfs_count_readdir(where, packets, bytes);
+	return(result);
+}
+
+struct mfs_local_readdir_callback
+{
+	filldir_t realfilldir;
+	void *realdirent;
+	struct dentry *parent;
+	struct vfsmount *pmnt;
+	int packets, bytes, inbytes;
+};
+
+int
+mfs_local_filldir(void *__cb, const char *name, int namelen, loff_t offset,
+						ino_t ino, unsigned int type)
+{
+	struct mfs_local_readdir_callback *cb = __cb;
+	struct inode ji;
+	struct inode *ri;
+	int b = sizeof(ino_t) + sizeof(loff_t) + sizeof(namelen) +
+						strnlen(name, namelen) + 1;
+
+	cb->bytes += b;
+	if((cb->inbytes += b) > MFS_MAXBLOCK)
+	{
+		cb->packets++;
+		cb->inbytes = b;
+	}
+	ji.i_ino = ino;
+	ji.i_dev = cb->parent->d_inode->i_dev;
+	/* to present a single, flat filesystem, we must adjust in case the
+	 * son falls outside the parent's file-system. */
+	if(namelen == 1 && name[0] == '.')
+		;	/* nothing */
+	else if(namelen == 2 && name[0] == '.' && name[1] == '.')
+	{
+		if(cb->parent == cb->pmnt->mnt_root)
+		{
+			ri = cb->pmnt->mnt_mountpoint->d_inode;
+			ji.i_ino = ri->i_ino;
+			ji.i_dev = ri->i_dev;
+		}
+	}
+	else
+	{
+		struct list_head *p;
+		struct vfsmount *m;
+
+		spin_lock(&dcache_lock);
+		for(p = cb->pmnt->mnt_mounts.next ; p != &cb->pmnt->mnt_mounts ;
+			p = p->next)
+		{
+			m = list_entry(p, struct vfsmount, mnt_child);
+			if(m->mnt_mountpoint->d_inode->i_ino == ji.i_ino)
+			{
+				struct inode *mroot = m->mnt_root->d_inode;
+
+				ji.i_dev = mroot->i_dev;
+				ji.i_ino = mroot->i_ino;
+				break;
+			}
+		}
+		spin_unlock(&dcache_lock);
+	}
+	return(cb->realfilldir(cb->realdirent, name, namelen, offset,
+						global_inum(&ji), type));
+}
+
+int
+mfs_low_readdir(mfs_handle_t handle, struct file *filp, void *dirent,
+				filldir_t filldir, int *packets, int *bytes)
+{
+	int ret;
+	struct file_operations *fops;
+	struct file dummy;
+	struct mfs_local_readdir_callback lrb;
+
+	if((ret = prepare_dummy_file(handle, &dummy, filp)))
+		return(ret);
+	fops = dummy.f_dentry->d_inode->i_fop;
+	lrb.realfilldir = filldir;
+	lrb.realdirent = dirent;
+	lrb.parent = dummy.f_dentry;
+	lrb.pmnt = dummy.f_vfsmnt;
+	lrb.packets = lrb.bytes = lrb.inbytes = 0;
+	ret = vfs_readdir(&dummy, mfs_local_filldir, (void *)&lrb);
+	collect_dummy_file(&dummy, filp);
+	*packets = lrb.packets;
+	*bytes = lrb.bytes;
+	return(ret);
+}
+
+int
+mfs_ioctl(struct inode *ip, struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	int where;
+	mfs_handle_t handle;
+	int size;
+	int data;
+	int ret;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(ip != filp->f_dentry->d_inode)
+	{
+		mosix_panic("mfs_ioctl: not same");
+		return(-EINVAL);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	/* currently supporting only EXT2 ioctls: the following others
+	 * are possible candidates (later): ncpfs, smbfs, umsdos */
+	switch(cmd)
+	{
+		case EXT2_IOC_GETFLAGS:
+		case EXT2_IOC_GETVERSION:
+			size = -(int)sizeof(int);
+			break;
+		case EXT2_IOC_SETFLAGS:
+		case EXT2_IOC_SETVERSION:
+			size = sizeof(int);
+			break;
+		default:
+			return(-EPERM);
+	}
+	if(size > 0 && copy_from_user((void *)&data, (void *)arg, size))
+		return(-EFAULT);
+	mfs_get_handling(filp->f_dentry, &where, &handle);
+	mfs_count_ioctl(where);
+	if(where != MFS_PE || mfs_loopback_test)
+		ret = mfs_client_ioctl(where, handle, filp, cmd, arg, size,
+									&data);
+	else
+		ret = mfs_low_ioctl(handle, filp, cmd, arg, size, &data);
+	if(!ret && size < 0 && copy_to_user((void *)arg, (void *)&data, -size))
+		ret = -EFAULT;
+	return(ret);
+}
+
+int
+mfs_low_ioctl(mfs_handle_t handle, struct file *filp, unsigned int cmd,
+					unsigned long arg, int size, int *data)
+{
+	int ret;
+	struct file_operations *fops;
+	struct file dummy;
+	mm_segment_t old_fs;
+
+	if((ret = prepare_dummy_file(handle, &dummy, filp)))
+		return(ret);
+	fops = dummy.f_dentry->d_inode->i_fop;
+	if(!fops || !fops->ioctl)
+		ret = -ENOTTY;
+	else
+	{
+		if(size)
+			old_fs = set_fs(KERNEL_DS);
+		lock_kernel();
+		ret = fops->ioctl(dummy.f_dentry->d_inode, &dummy, cmd,
+			size ? (unsigned long)data : arg);
+		unlock_kernel();
+		if(size)
+			set_fs(old_fs);
+	}
+	collect_dummy_file(&dummy, filp);
+	return(ret);
+}
+
+int
+mfs_mmap(struct file *f, struct vm_area_struct *x)
+{
+	/* cannot be reached: just a place-holder */
+	/* some code (including "binfmt_elf.c") check for the existance of this
+	 * routine, but "do_mmap" will detect that there are no a_ops
+	 * and convert it to a file-read
+	 */
+	panic("mfs_mmap");
+	return(-ENOSYS);
+}
+
+int
+mfs_fsync(struct file *filp, struct dentry *dp, int datasync)
+{
+	int where;
+	mfs_handle_t handle;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(dp != filp->f_dentry)
+		mosix_panic("mfs_fsync: not same");
+#endif /* CONFIG_MOSIX_DIAG */
+	mfs_get_handling(dp, &where, &handle);
+	mfs_count_fsync(where);
+	if(where != MFS_PE || mfs_loopback_test)
+		return(mfs_client_fsync(where, handle, filp, datasync));
+	return(mfs_low_fsync(handle, filp, datasync));
+}
+
+int
+mfs_low_fsync(mfs_handle_t handle, struct file *filp, int datasync)
+{
+	int ret;
+	struct file_operations *fops;
+	struct file dummy;
+
+	if((ret = prepare_dummy_file(handle, &dummy, filp)))
+		return(ret);
+	fops = dummy.f_dentry->d_inode->i_fop;
+	down(&dummy.f_dentry->d_inode->i_sem);
+	if(!fops || !fops->fsync)
+		ret = -EINVAL;
+	else
+		ret = fops->fsync(&dummy, dummy.f_dentry, datasync);
+	up(&dummy.f_dentry->d_inode->i_sem);
+	collect_dummy_file(&dummy, filp);
+	return(ret);
+}
+
+static struct file_operations mfs_file_file_operations =
+{
+	llseek:		mfs_file_llseek,
+	read:		mfs_read,
+	write:		mfs_write,
+	ioctl:		mfs_ioctl,
+	mmap:		mfs_mmap,
+	fsync:		mfs_fsync,
+};
+
+static struct file_operations mfs_symlink_file_operations =
+{
+	ioctl:		mfs_ioctl,
+};
+
+static struct file_operations mfs_dir_file_operations =
+{
+	llseek:		mfs_dir_llseek,
+	read:		mfs_read,
+	readdir:	mfs_readdir,
+	ioctl:		mfs_ioctl,
+	fsync:		mfs_fsync,
+};
+
+struct mfs_iphand
+{
+	int pe;
+	mfs_handle_t handle;
+};
+
+int
+compare_mfs_ip(struct inode *ip, unsigned long ig1, void *arg)
+{
+	int pe = ((struct mfs_iphand *)arg)->pe;
+
+	return(!pe || (ip->u.mfs_i.pe == pe &&
+		ip->u.mfs_i.handle == ((struct mfs_iphand *)arg)->handle));
+}
+
+struct inode *mfs_iget(unsigned long ino, int pe, mfs_handle_t handle)
+{
+	struct mfs_iphand h;
+
+	h.pe = pe;
+	h.handle = handle;
+	current->mosix.iget_mfs_pe = pe;
+	current->mosix.iget_mfs_handle = handle;
+	return(iget4(mfs_super, ino, compare_mfs_ip, &h));
+}
+
+int
+mfs_revalidate(struct dentry *dentry)
+{
+	int where;
+	mfs_handle_t handle;
+	int ret;
+	struct subinode iinfo;
+	struct inode *ip = dentry->d_inode;
+
+	mfs_get_handling(dentry, &where, &handle);
+	mfs_ip_to_subip(&iinfo, ip);
+	mfs_count_revalidate(where);
+	if(where != MFS_PE || mfs_loopback_test)
+		ret = mfs_client_revalidate(where, handle, &iinfo);
+	else
+		ret = mfs_low_revalidate(handle, &iinfo);
+	if(!ret)
+		mfs_subip_to_ip(ip, &iinfo);
+	return(ret);
+}
+
+int
+mfs_low_revalidate(mfs_handle_t handle, struct subinode *iinfo)
+{
+	struct inode *lip;
+	int ret;
+	struct nameidata nd;
+
+	if((ret = mfs_to_local(handle, &nd)))
+		return(ret);
+	lip = nd.dentry->d_inode;
+	if(!lip || !lip->i_op || !lip->i_op->revalidate)
+		ret = 0;
+	else
+		ret = lip->i_op->revalidate(nd.dentry);
+	if(!ret)
+		mfs_ip_to_subip(iinfo, lip);
+	mfs_lput(nd.dentry, nd.mnt);
+	return(ret);
+}
+
+int
+mfs_setattr(struct dentry *dentry, struct iattr *attr)
+{
+	int where;
+	mfs_handle_t handle;
+
+	if(mfs_is_ro)
+		return(-EROFS);
+	if(!dentry->d_fsdata) /* someone trying to fiddle with the MFS root */
+		return(-EPERM);
+	mfs_get_handling(dentry, &where, &handle);
+	mfs_count_setattr(where);
+	if(where != MFS_PE || mfs_loopback_test)
+		return(mfs_client_setattr(where, handle, attr));
+	return(mfs_low_setattr(handle, attr));
+}
+
+int
+mfs_low_setattr(mfs_handle_t handle, struct iattr *attr)
+{
+	struct nameidata nd;
+	struct inode *ip;
+	int ret;
+	int wa = 0;
+
+	if((ret = mfs_to_local(handle, &nd)))
+		return(ret);
+	ret = -EINVAL;
+	if(!(ip = nd.dentry->d_inode))
+		goto out;
+	if(attr->ia_valid & ATTR_SIZE)
+	{
+		/* this must be ftruncate: */
+
+		if((ret = get_write_access(ip)))
+			goto out;
+		wa = 1;
+		ret = -EISDIR;
+		if(S_ISDIR(ip->i_mode))
+			goto out;
+		ret = -EINVAL;
+		if(!S_ISREG(ip->i_mode))
+			goto out;
+		ret = -EPERM;
+		if(IS_APPEND(ip))
+			goto out;
+		if((ret = locks_verify_truncate(ip, NULL, attr->ia_size)))
+			goto out;
+		down(&ip->i_sem);
+	}
+	ret = notify_change(nd.dentry, attr);
+	if(attr->ia_valid & ATTR_SIZE)
+		up(&ip->i_sem);
+	out:
+	if(wa)
+		put_write_access(ip);
+	mfs_lput(nd.dentry, nd.mnt);
+	return(ret);
+}
+
+int
+mfs_root_name_to_ino(char *name, int len)
+{
+	int node = 0;
+
+	if(*name >= '0' && *name <= '9')
+	while(len && node <= MOSIX_MAX && *name >= '0' && *name <= '9')
+	{
+		node = node * 10 + (*name - '0');
+		name++;
+		len--;
+	}
+	else if(len)
+	switch(*name)
+	{
+		case 'h':
+			if(len != 4 || name[3] != 'e')
+				return(0);
+			if(name[1] == 'e' && name[2] == 'r')
+				return(current->mosix.whereami ? : PE);
+			if(name[1] == 'o' && name[2] == 'm')
+				return(current->mosix.deppe ? : PE);
+			break;
+		case 'l':
+			if(len == 8 && !memcmp(&name[1], "astexec", 7))
+				return(current->mosix.lastexec ? :
+					(current->mosix.deppe ? : PE));
+			break;
+		case 'm':
+			if(len == 5 && !memcmp(&name[1], "agic", 4))
+				return(current->mosix.lastmagic ? :
+					(current->mosix.deppe ? : PE));
+		case 's':
+			if(len == 8 && !memcmp(&name[1], "elected", 7))
+				return(current->mosix.selected ? :
+					(current->mosix.deppe ? : PE));
+	}
+	if(len || !mos_to_net(node, NULL))
+		node = 0;
+	return(node);
+}
+
+static void
+fill_last_component(char *nam, struct nameidata *nd)
+{
+	char *start = nam, *end;
+
+	while(*nam)
+		nam++;
+	end = nam;
+	for(nam-- ; *nam == '/' && nam > start ; nam--)
+		;
+	while(nam > start && *(nam-1) != '/')
+		nam--;
+	nd->last.name = nam;
+	nd->last.len = end - nam + 1;
+	nd->last_type = LAST_NORM;
+	switch(*nam)
+	{
+		case '/':
+		case '\0':
+			nd->last_type = LAST_ROOT;
+			break;
+		case '.':
+			switch(*(nam+1))
+			{
+				case '.':
+					if(*(nam+2) == '/' || *(nam+2) == '\0')
+						nd->last_type = LAST_DOTDOT;
+					break;
+				case '/':
+				case '\0':
+					nd->last_type = LAST_DOT;
+					return;
+			}
+			break;
+	}
+}
+
+int
+mfs_express_lookup(struct nameidata *nd, char **name)
+{
+	char *nam = *name;
+	struct vfsmount *mnt;
+	int pe;
+	mfs_handle_t handle;
+	struct subinode iinfo;
+	struct inode *ip;
+	struct qstr qnam;
+	char *newname = NULL;
+	struct mfs_completion complete;
+	struct dentry *result;
+	int err;
+	int magic = 0;
+	int link = 0;
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int flags = nd->flags & ~(LOOKUP_COMPLETE|LOOKUP_STAYFS);
+#else
+	unsigned int flags = nd->flags & ~LOOKUP_COMPLETE;
+#endif /* CONFIG_MOSIX_DFSA */
+
+	mfs_prepare_completion(&complete, nd);
+	if(complete.error < 0)
+	{
+		mfs_check_completion(&complete, nd);
+		return(complete.error);
+	}
+	pe = complete.base_pe;
+	handle = complete.base;
+	*name = NULL;
+	while(*nam)
+	{
+		if(pe == 0)
+		{
+			char *c;
+
+			if(*nam == '.')
+			switch(*(nam+1))
+			{
+				case '\0':
+					nam++;
+					continue;
+				case '/':
+					nam += 2;
+					while(*nam == '/')
+						nam++;
+					continue;
+				case '.':
+					if(*(nam+2) == '\0' || *(nam+2) == '/')
+						goto name_leads_back;
+					break;
+			}
+			for(c = nam ; *c && *c != '/' ; c++)
+				;
+			pe = mfs_root_name_to_ino(nam, c - nam);
+			handle = pe;
+			if(!pe)
+			{
+				mfs_check_completion(&complete, nd);
+#ifdef CONFIG_MOSIX_DFSA
+				if(current->mosix.dflags & DREMOTE)
+					return(-EDOITATHOME);
+#endif /* CONFIG_MOSIX_DFSA */
+				return(-ENOENT);
+			}
+			if(nam[0] == 'm')
+				magic = 1;
+			link = (nam[0] >= 'a');
+			while(*c == '/')
+				c++;
+			nam = c;
+		}
+		if(flags & LOOKUP_MFS)
+		{
+			/* server may only access the MFS root itself or reach
+			 * back to the node's root via the correct link */
+			mfs_check_completion(&complete, nd);
+			if(pe != MFS_PE || !(flags & LOOKUP_MFS_MFS))
+				return(-EACCES);
+			nd->flags &= ~LOOKUP_MFS_MFS;
+			dput(nd->dentry);
+			mntput(nd->mnt);
+			nd->dentry = dget(mfs_root);
+			nd->mnt = mntget(mfs_mnt);
+			if(*nam)
+				*name = nam;
+			return(0);
+		}
+		if(!*nam && (nd->flags & LOOKUP_PARENT))
+		{
+			mfs_check_completion(&complete, nd);
+			return(-EPERM);
+		}
+		if(pe && !*nam && link && !(nd->flags & LOOKUP_FOLLOW))
+			return(mfs_link_complete(&complete, pe, nd));
+		mfs_count_express(pe, complete.more_data_len);
+		if(pe != MFS_PE || mfs_loopback_test)
+			err = mfs_client_express_lookup(pe, &handle, nam,
+					flags, &iinfo, &newname, &complete);
+		else
+			err = mfs_low_express_lookup(&handle, nam, flags,
+					current->link_count,
+					current->total_link_count, &iinfo,
+					&newname, &complete);
+#if 0
+printk("mfs_express_lookup: nam=<%s>, newname=%x", nam, newname);
+if(newname)printk("<%s>\n", newname);else printk("\n");
+#endif
+
+		if(err == AN_IMPOSSIBLE_ERROR && iinfo.si_count)
+		{
+			pe = magic = 0;
+#if 0
+printk("mfs_express_lookup: skipping from <%s> to ", nam);
+#endif
+			nam += iinfo.si_count - 1;
+#if 0
+printk("<%s>\n", nam);
+#endif
+			if(!*nam && (nd->flags & LOOKUP_PARENT))
+			{
+				mfs_check_completion(&complete, nd);
+				return(-EPERM);
+			}
+			dput(nd->dentry);
+			nd->dentry = dget(mfs_super->s_root);
+		}
+		else if(IS_ERR((const void *)err))
+		{
+			mfs_check_completion(&complete, nd);
+			return(err);
+		}
+		else
+		{
+			if(nd->flags & LOOKUP_PARENT)
+				fill_last_component(nam, nd);
+			break;
+		}
+	}
+	if(pe == 0)
+	{
+		mfs_check_completion(&complete, nd);
+		return(0);
+	}
+	if(mfs_check_completion(&complete, nd))
+	{
+		if(newname)
+			kfree(newname);
+		return(complete.error);
+	}
+	if(newname)
+	{
+		qnam.name = newname;
+		qnam.len = strlen(newname);
+	}
+	else	/* can still function - except 'getcwd' */
+	{
+		qnam.name = "__removed__";
+		qnam.len = 11;
+	}
+	result = d_alloc(mfs_super->s_root, &qnam);
+	if(newname)
+		kfree(newname);
+	if(!result)
+	{
+		mfs_dispose_handle(pe, handle);
+		return(-ENOMEM);
+	}
+	if(!(result->d_fsdata = kmalloc(sizeof(struct mfs_dinfo), GFP_KERNEL)))
+	{
+		dput(result);
+		mfs_dispose_handle(pe, handle);
+		return(-ENOMEM);
+	}
+	result->d_flags |= DCACHE_NO_CACHE;
+	result->d_op = &mfs_dentry_operations;
+	((struct mfs_dinfo *)result->d_fsdata)->pe = pe;
+	((struct mfs_dinfo *)result->d_fsdata)->handle = handle;
+	((struct mfs_dinfo *)result->d_fsdata)->latest = jiffies;
+	if(iinfo.si_ino)
+	{
+		ip = mfs_iget(iinfo.si_ino, pe, handle);
+		if(!ip)
+		{
+			dput(result);
+			return(-EACCES);
+		}
+		mfs_subip_to_ip(ip, &iinfo);
+		d_add(result, ip);
+	}
+	else
+		d_add(result, NULL);
+	if(magic && (nd->complete_flags & COMPLETE_DONE))
+		nd->complete_flags |= COMPLETE_MAGICAL;
+	dput(nd->dentry);
+	nd->dentry = result;
+	return(0);
+
+	name_leads_back:
+#ifdef CONFIG_MOSIX_DIAG
+	if(complete.done)
+		printk("OOPS: compete->done in name_leads_back!\n");
+#endif /* CONFIG_MOSIX_DIAG */
+	mfs_check_completion(&complete, nd);
+#ifdef CONFIG_MOSIX_DFSA
+	if(nd->flags & LOOKUP_STAYFS)
+	{
+		if(current->mosix.dflags & DREMOTE)
+			return(-EDOITATHOME);
+		nd->flags &= ~LOOKUP_STAYFS;
+		current->mosix.dflags &= ~DSTATSDOWN;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	for(nam += 2 ; *nam == '/' ; nam++)
+		;
+#if 0
+printk("name leads back, left=../<%s>\n", nam);
+#endif
+	if(*nam)
+		*name = nam;
+	else if(nd->flags & LOOKUP_PARENT)
+		return(-EPERM);
+	dput(nd->dentry);
+	mnt = nd->mnt;
+	nd->mnt = mntget(mnt->mnt_parent);
+	nd->dentry = dget(mnt->mnt_mountpoint->d_parent);
+	mntput(mnt);
+	return(0);
+}
+
+char *
+mfs_full_name(struct dentry *of, struct vfsmount *on)
+{
+	char *a, *b;
+	char *page = (char *)kmalloc(PAGE_SIZE, GFP_KERNEL);
+	int x;
+
+	if(!page)
+		return(NULL);
+	if(of == mfs_root && on == mfs_mnt)
+	{
+		a = &page[PAGE_SIZE-1];
+		*a = '\0';
+	}
+	else
+	{
+		spin_lock(&dcache_lock);
+		a = __d_path(of, on, mfs_root, mfs_mnt, page, PAGE_SIZE);
+		spin_unlock(&dcache_lock);
+	}
+	for(x = MFS_PE ; x ; x /= 10)
+	{
+		if(a == page)
+		{
+			kfree(page);
+			return(NULL);
+		}
+		*(--a) = x % 10 + '0';
+	}
+	if(a != page)
+	{
+		for(b = page ; *a ; )
+			*b++ = *a++;
+		*b = '\0';
+		a = page;
+	}
+	return(a);
+}
+
+int
+mfs_low_express_lookup(mfs_handle_t *handlep, char *name, unsigned int flags,
+	int link_count, int total_link_count, struct subinode *iinfo,
+	char **newname, struct mfs_completion *complete)
+{
+	struct inode *ip;
+	struct nameidata nd;
+	int error;
+
+	iinfo->si_count = 0;
+	*newname = NULL;
+	if((error = mfs_to_local(*handlep, &nd)))
+	{
+		mfs_low_complete_error(complete, error);
+		return(error);
+	}
+#if 0
+ip = nd.dentry->d_inode;
+printk("mfs_low_express_lookup, original ino=%x/%d, d_count=%d\n", ip->i_dev, ip->i_ino, atomic_read(&nd.dentry->d_count));
+#endif
+	nd.flags = (flags | LOOKUP_MFS) & ~LOOKUP_MFS_MFS;
+	nd.last_type = LAST_ROOT;
+	nd.name_left = NULL;
+	nd.complete_flags = 0;
+	dget(nd.dentry);
+	mntget(nd.mnt);
+	mfs_lput(nd.dentry, nd.mnt);
+	current->link_count = link_count;
+	current->total_link_count = total_link_count;
+	error = path_walk(name, &nd);
+	if(nd.name_left)	/* "/.." */
+	{
+		iinfo->si_count = (nd.name_left - name) + 1;
+#if 0
+printk("mfs_low_express_lookup: name_left %x<%s>, orig_name=%x<%s>, skip_factor=%d\n", nd.name_left, nd.name_left, name, name, iinfo->si_count);
+#endif
+		return(AN_IMPOSSIBLE_ERROR);
+	}
+	if(error)
+	{
+		mfs_low_complete_error(complete, error);
+		return(error);
+	}
+	if((*handlep = mfs_low_complete(complete, &nd)))
+	{
+		/* need information back */
+		if((ip = nd.dentry->d_inode))
+		{
+			iinfo->si_ino = global_inum(ip);
+			mfs_ip_to_subip(iinfo, ip);
+		}
+		else
+			iinfo->si_ino = 0;
+		*newname = mfs_full_name(nd.dentry, nd.mnt);
+#if 0
+printk("mfs_low_express_lookup: dev=%x, ip=%d, name=<%s>, newname=%x", ip ? ip->i_dev : 0, ip ? ip->i_ino : 0, name, *newname);
+if(*newname)printk("<%s>", *newname);printk("\n");
+#endif
+	}
+	else
+	{
+#if 0
+printk("mfs_low_express_lookup(%s): all resolved, err=%d", name, complete->error);
+if(nd.dentry->d_inode)printk(", dev=%x, ino=%d\n", nd.dentry->d_inode->i_dev, nd.dentry->d_inode->i_ino);
+printk("\n");
+#endif
+		*handlep = 0;
+	}
+#if 0
+ip = nd.dentry->d_inode; printk("before path release, ");
+if(ip)printk("ino=%x/%d, ", ip->i_dev, ip->i_ino);
+printk("d_count=%d\n", atomic_read(&nd.dentry->d_count));
+#endif 
+	if(!IS_ERR((const void *)complete->error))
+		path_release(&nd);
+	return(complete->error);
+}
+
+void
+mfs_check_path(struct dentry *dp)
+{
+	int where;
+	mfs_handle_t handle;
+	char *name;
+	int len;
+
+	if(dp == mfs_super->s_root)
+		return;
+	if(dp->d_parent != mfs_super->s_root)
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		printk("mfs_check_path: not son of root\n");
+#endif /* CONFIG_MOSIX_DIAG */
+		return;
+	}
+	mfs_get_handling(dp, &where, &handle);
+	if(where != MFS_PE || mfs_loopback_test)
+		name = mfs_client_check_path(where, handle);
+	else
+		name = mfs_low_check_path(handle);
+	mfs_count_check_path(where, name ? strlen(name)+1 : 0);
+	if(!name || !strcmp(name, dp->d_name.name))
+		return;
+
+	len = strlen(name);
+	if(len <= dp->d_name.len)
+	{
+		dp->d_name.len = len;
+		strcpy((char *)dp->d_name.name, name);
+		kfree(name);
+	}
+	else
+	{
+		if(dname_external(dp))
+			kfree(dp->d_name.name);
+		dp->d_name.name = name;
+		dp->d_name.len = len;
+	}
+}
+
+char *
+mfs_low_check_path(mfs_handle_t handle)
+{
+	struct nameidata nd;
+	char *ret;
+
+	if(mfs_to_local(handle, &nd))
+		return(NULL);
+	ret = mfs_full_name(nd.dentry, nd.mnt);
+	mfs_lput(nd.dentry, nd.mnt);
+	return(ret);
+}
+
+struct inode_operations mfs_file_inode_operations = {
+        revalidate:	mfs_revalidate,
+	setattr:	mfs_setattr,
+	check_path:	mfs_check_path,
+};
+
+struct inode_operations mfs_symlink_inode_operations = {
+        revalidate:	mfs_revalidate,
+	setattr:	mfs_setattr,
+	check_path:	mfs_check_path,
+};
+
+struct inode_operations mfs_dir_inode_operations = {
+        revalidate:	mfs_revalidate,
+	setattr:	mfs_setattr,
+	express_lookup:	mfs_express_lookup,
+	check_path:	mfs_check_path,
+};
+
+int
+mfs_root_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+	int first, last;
+
+	if(filp->f_pos == 0)
+	{
+		if(filldir(dirent, ".", 1, 0,
+				filp->f_dentry->d_inode->i_ino, DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 1;
+	}
+	if(filp->f_pos == 1)
+	{
+		if(filldir(dirent, "..", 2, 1,
+				filp->f_dentry->d_inode->i_ino, DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 2;
+	}
+	if(filp->f_pos == 2)
+	{
+		if(filldir(dirent, "here", 4, 2,
+				mfs_root_name_to_ino("here", 4), DT_DIR))
+			return(0);
+		filp->f_pos = 3;
+	}
+	if(filp->f_pos == 3)
+	{
+		if(filldir(dirent, "home", 4, 3,
+				mfs_root_name_to_ino("home", 4), DT_DIR))
+			return(0);
+		filp->f_pos = 4;
+	}
+	if(filp->f_pos == 4)
+	{
+		if(filldir(dirent, "lastexec", 8, 4,
+				mfs_root_name_to_ino("lastexec", 8), DT_DIR))
+			return(0);
+		filp->f_pos = 5;
+	}
+	if(filp->f_pos == 5)
+	{
+		if(filldir(dirent, "magic", 5, 5,
+				mfs_root_name_to_ino("magic", 5), DT_DIR))
+			return(0);
+		filp->f_pos = 6;
+	}
+	if(filp->f_pos == 6)
+	{
+		if(filldir(dirent, "selected", 8, 6,
+				mfs_root_name_to_ino("selected", 8), DT_DIR))
+			return(0);
+		filp->f_pos = 7;
+	}
+	if(filp->f_pos < 7 || filp->f_pos >= 7 + MOSIX_MAX)
+		return(0);
+	while(scan_mosix_nodes(filp->f_pos - 6, &first, &last))
+	while(first <= last)
+	{
+		char node[6];
+		int n = first;
+		char *c;
+
+		c = &node[5];
+		*c = '\0';
+		while(n)
+		{
+			c--;
+			*c = n % 10 + '0';
+			n /= 10;
+		}
+		if(filldir(dirent, c, sizeof(node) - 1 - (c - node),
+			first + 6, first, DT_DIR))
+				return(0);
+		filp->f_pos = ++first + 6;
+	}
+	return(0);
+}
+
+static struct file_operations mfs_root_file_operations =
+{
+	readdir:	mfs_root_readdir,
+};
+
+int
+mfs_root_revalidate(struct dentry *dp)
+{
+	struct inode *ip = dp->d_inode;
+
+	ip->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
+	ip->i_nlink = 1;
+	ip->i_uid = 0;
+	ip->i_gid = 0;
+	ip->i_rdev = 0;
+	ip->i_size = 0;
+	ip->i_atime = 0;
+	ip->i_ctime = 0;
+	ip->i_mtime = 0;
+	ip->i_blksize = 1024;
+	ip->i_blocks = 0;
+	return(0);
+}
+
+struct dentry *
+mfs_root_lookup(struct inode *dir, struct dentry *dentry)
+{
+	struct mfs_dinfo *info;
+	struct inode *inode = NULL;
+	int node;
+
+	if(!(node = mfs_root_name_to_ino((char *)dentry->d_name.name,
+							dentry->d_name.len)))
+	{
+#ifdef CONFIG_MOSIX_DFSA
+		if(current->mosix.dflags & DREMOTE)
+			return(ERR_PTR(-EDOITATHOME));
+#endif /* CONFIG_MOSIX_DFSA */
+		return(ERR_PTR(-EACCES));
+	}
+	if(!(info = (struct mfs_dinfo *)kmalloc(sizeof(struct mfs_dinfo),
+								GFP_KERNEL)))
+		return(ERR_PTR(-ENOMEM));
+	info->pe = node;
+	info->handle = node;
+	info->latest = jiffies;
+	dentry->d_flags |= DCACHE_NO_CACHE;
+	dentry->d_op = &mfs_dentry_operations;
+	dentry->d_fsdata = info;
+	inode = mfs_iget(node, node, node);
+	if(!inode)
+		return(ERR_PTR(-ENOMEM));
+	d_add(dentry, inode);
+	return(NULL);
+}
+
+/* note: most of the following functions are actually required, even though
+ * not really permitted on the MFS root itself, because the MFS root is
+ * technically the parent of all MFS nodes.
+ */
+struct inode_operations mfs_root_inode_operations = {
+	revalidate:	mfs_root_revalidate,
+	setattr:	mfs_setattr,
+	express_lookup:	mfs_express_lookup,
+};
+
+void
+mfs_read_inode(struct inode * inode)
+{
+	unsigned long ino = inode->i_ino;
+	struct subinode iinfo;
+	int err;
+
+	if(ino == MFS_ROOT_INO)
+	{
+		inode->i_mode = S_IFDIR | S_IXUGO | S_IRUGO | S_IWUGO;
+		inode->i_op = &mfs_root_inode_operations;
+		inode->i_fop = &mfs_root_file_operations;
+		inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
+		inode->i_blocks = 0;
+		inode->i_blksize = 1024;
+		inode->i_uid = 0;
+		inode->i_gid = 0;
+		inode->i_nlink = 1;
+		inode->i_size = 0;
+		inode->i_generation = 0;
+		inode->i_version = 0;
+		return;
+	}
+	inode->u.mfs_i.pe = current->mosix.iget_mfs_pe;
+	inode->u.mfs_i.handle = current->mosix.iget_mfs_handle;
+	if(ino < MFS_ROOT_INO)
+	{
+		mfs_count_revalidate(ino);
+		if(ino != MFS_PE || mfs_loopback_test)
+			err = mfs_client_revalidate(ino, ino, &iinfo);
+		else
+			err = mfs_low_revalidate(MFS_PE, &iinfo);
+		if(err)		/* just guess */
+		{
+			inode->i_mode = S_IFDIR | S_IXUGO | S_IRUGO;
+			inode->i_op = &mfs_dir_inode_operations;
+			inode->i_mtime = inode->i_atime = inode->i_ctime =
+								CURRENT_TIME;
+			inode->i_blocks = 0;
+			inode->i_blksize = 1024;
+			inode->i_uid = 0;
+			inode->i_gid = 0;
+			inode->i_nlink = 1;
+			inode->i_size = 0;
+		}
+		else
+			mfs_subip_to_ip(inode, &iinfo);
+	}
+}
+
+int
+mfs_statfs(struct super_block *sb, struct statfs *buf)
+{
+	buf->f_type = MFS_SUPER_MAGIC;
+	buf->f_bsize = PAGE_SIZE/sizeof(long);
+	buf->f_namelen = NAME_MAX;
+	/* all the rest are 0 */
+	return(0);
+}
+
+void
+mfs_put_super(struct super_block *sb)
+{
+	mfs_is_mounted = 0;
+	mfs_super = NULL;
+}
+
+#ifdef CONFIG_MOSIX_DFSA
+struct mfs_ident	/* used in mfs_identify/mfs_reconstruct */
+{
+	int pe;
+	mfs_handle_t handle;
+	ino_t ino;
+	mode_t mode;
+};
+
+int
+mfs_identify(struct dentry *dentry, void *into)
+{
+	struct mfs_ident *i = into;
+	struct mfs_dinfo *p = (struct mfs_dinfo *)dentry->d_fsdata;
+
+	if(sizeof(struct mfs_ident) > MAX_IDENT_RECORD_LEN)
+		panic("mfs_identify: insufficient\n");
+	if(p)
+	{
+		i->pe = p->pe;
+		i->handle = p->handle;
+	}
+	else
+	{
+		i->pe = 0;
+		i->handle = 0;
+	}
+	i->ino = dentry->d_inode->i_ino;
+	i->mode = dentry->d_inode->i_mode;
+	return(sizeof(struct mfs_ident));
+}
+
+struct dentry *
+mfs_reconstruct(struct vfsmount *mnt, void *info, int infolen)
+{
+	struct mfs_ident *i = (struct mfs_ident *)info;
+	struct dentry *dp;
+	struct inode *ip;
+	struct qstr qname;
+
+	if(mnt->mnt_sb != mfs_super || infolen != sizeof(struct mfs_ident))
+	{
+		printk("mfs_reconstruct: improper data\n");
+		return(NULL);
+	}
+	if(!i->pe)
+		return(i->handle ? NULL : dget(mfs_super->s_root));
+	qname.name = "yet_unknown";
+	qname.len = 11;
+	if(!(dp = d_alloc(mfs_super->s_root, &qname)))
+		return(NULL);
+	if(!(dp->d_fsdata = kmalloc(sizeof(struct mfs_dinfo), GFP_KERNEL)))
+	{
+		dput(dp);
+		return(NULL);
+	}
+	dp->d_flags |= DCACHE_NO_CACHE;
+	dp->d_op = &mfs_dentry_operations;
+	((struct mfs_dinfo *)dp->d_fsdata)->pe = i->pe;
+	((struct mfs_dinfo *)dp->d_fsdata)->handle = i->handle;
+	((struct mfs_dinfo *)dp->d_fsdata)->latest = jiffies;
+	ip = mfs_iget(i->ino, i->pe, i->handle);
+	if(!ip)
+	{
+		kfree(dp->d_fsdata);
+		dp->d_fsdata = NULL;
+		dput(dp);
+		return(NULL);
+	}
+	ip->i_mode = i->mode;
+	switch(i->mode & S_IFMT)
+	{
+		case S_IFREG:
+			ip->i_op = &mfs_file_inode_operations;
+			ip->i_fop = &mfs_file_file_operations;
+			break;
+		case S_IFLNK:
+			ip->i_op = &mfs_symlink_inode_operations;
+			ip->i_fop = &mfs_symlink_file_operations;
+			break;
+		case S_IFDIR:
+			ip->i_op = &mfs_dir_inode_operations;
+			ip->i_fop = &mfs_dir_file_operations;
+			break;
+		default:
+			printk("mfs_reconstruct: inum %d of bad mode (0%o)\n",
+						(int)ip->i_ino, ip->i_mode);
+			make_bad_inode(ip);
+			break;
+	}
+	d_add(dp, ip);
+	if(mfs_attach_handle(i->pe, i->handle))
+	{
+		kfree(dp->d_fsdata);
+		dp->d_fsdata = NULL;
+		dput(dp);
+		return(NULL);
+	}
+	return(dp);
+}
+
+void
+mfs_dfsa_changed(struct vfsmount *mnt, int new)
+{
+	mfs_is_dfsa = (new != 0);
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
+struct super_operations mfs_sops =
+{
+	read_inode:		mfs_read_inode,
+	put_inode:		force_delete,
+	put_super:		mfs_put_super,
+	statfs:			mfs_statfs,
+#ifdef CONFIG_MOSIX_DFSA
+	identify:		mfs_identify,
+	reconstruct:		mfs_reconstruct,
+	dfsa_changed:		mfs_dfsa_changed,
+#endif /* CONFIG_MOSIX_DFSA */
+};
+
+int
+mfs_dentry_compare(struct dentry *d, struct qstr *a, struct qstr *b)
+{
+	/* since MFS uses no hashing/caching, we should never reach here! */
+	printk("mfs_dentry_compare! (<%s>, <%s>)\n", a->name, b->name);
+	return(1);
+}
+
+void
+mfs_dentry_release(struct dentry *dp)
+{
+	int where;
+	mfs_handle_t handle;
+
+	if(dp->d_fsdata)
+	{
+		where = ((struct mfs_dinfo *)dp->d_fsdata)->pe;
+		handle = ((struct mfs_dinfo *)dp->d_fsdata)->handle;
+		kfree(dp->d_fsdata);
+		dp->d_fsdata = NULL;
+		mfs_dispose_handle(where, handle);
+	}
+}
+
+struct dentry_operations mfs_dentry_operations =
+{
+	d_compare:		mfs_dentry_compare,
+	d_release:		mfs_dentry_release,
+};
+
+struct super_block *
+mfs_read_super(struct super_block *s, void *data, int silent)
+{
+	struct inode * root_inode;
+	struct super_block *ret = s;
+
+	if(mfs_is_mounted)
+	{
+		printk("MFS already mounted!\n");
+		return(NULL);
+	}
+	if(!PE)
+		printk("WARNING: MFS mounting is ineffective until MOSIX is configured.\n");
+	mfs_is_mounted = 1;
+	mfs_is_ro = (s->s_flags & MS_RDONLY);
+	mfs_super = s;
+	s->s_blocksize = 1024;
+	s->s_blocksize_bits = 10;
+	s->s_magic = MFS_SUPER_MAGIC;
+	s->s_op = &mfs_sops;
+	root_inode = iget(s, MFS_ROOT_INO);
+	if (!root_inode || !(s->s_root = d_alloc_root(root_inode)))
+	{
+		printk("Failed initializing MOSIX file-system.\n");
+		iput(root_inode);
+		mfs_is_mounted = 0;
+		ret = NULL;
+	}
+	else
+		s->s_root->d_op = &mfs_dentry_operations;
+	s->s_maxbytes = ~0LL;
+	return(ret);
+}
+
+void
+mfs_change_pe(void)
+{
+	lock_mosix();
+	if(MFS_PE == ((PE && !mosadmin_mode_nomfs) ? PE : MFS_UNKNOWN_PE))
+	{
+		unlock_mosix();
+		return;
+	}
+	unlock_mosix();
+	if(mfs_try_to_cleanup(0))
+	{
+		printk("WARNING: Due to the MOSIX configuration-change, all MFS files and\n");
+		printk("directories previously opened on this node will become inaccessible!\n");
+		mfs_try_to_cleanup(2);
+	}
+	lock_mosix();
+	MFS_PE = (PE && !mosadmin_mode_nomfs) ? PE : MFS_UNKNOWN_PE;
+	unlock_mosix();
+}
+
+DECLARE_FSTYPE(mfs_fs_type, "mfs", mfs_read_super, 0);
+
+int
+init_mfs(void)
+{
+	int err;
+
+	MFS_PE = (PE && !mosadmin_mode_nomfs) ? PE : MFS_UNKNOWN_PE;
+	if((err = register_filesystem(&mfs_fs_type)))
+		return(err);
+	mfs_conversion_init();
+	mfs_make_servers();
+	return(0);
+}
+
+int
+mfs_walk_init_root(struct nameidata *nd)
+{
+	int ret;
+
+	lock_kernel();
+	if(mfs_root)
+	{
+		nd->dentry = dget(mfs_root);
+		nd->mnt = mntget(mfs_mnt);
+		ret = 1;
+	}
+	else
+		ret = 0;
+	unlock_kernel();
+	return(ret);
+}
+
+int
+is_mfs_root(struct nameidata *nd)
+{
+	return(nd->dentry == mfs_root && nd->mnt == mfs_mnt);
+}
+
+void
+mfs_report_used(void)
+{
+	struct dentry *root;
+	struct dentry *dp;
+	struct list_head *next;
+	unsigned long timo = jiffies + 10 * HZ;
+	struct mfs_dinfo *i;
+	
+	loop:
+	if(!mfs_super)
+		return;
+	root = mfs_super->s_root;
+	dget(root);
+	for(next = root->d_subdirs.next ; next != &root->d_subdirs &&
+				time_before(jiffies, timo) ; next = next->next)
+	{
+		dp = list_entry(next, struct dentry, d_child);
+		if((i = dp->d_fsdata) &&
+			time_before(i->latest + MFS_REPORT_TIME, jiffies))
+		{
+			dget(dp);
+			i->latest = jiffies;
+			if(mfs_touch_handle(i->pe, i->handle))
+				i->pe = MFS_BAD_PE;
+			dput(dp);
+			goto loop;
+		}
+	}
+	dput(root);
+}
+
+int
+mfs_client_daemon(void *nothing)
+{
+	struct task_struct *p = current;
+
+	lock_kernel();
+	common_daemon_setup("mfs_gc", 0);
+	while(1)
+	{
+		mfs_report_used();
+		mfs_monitor_client_contacts();
+		p->state = TASK_INTERRUPTIBLE;
+		schedule_timeout(20 * HZ);
+		flush_signals(p);
+	}
+}
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/scontact.c linux-2.4.16-mosix/fs/mfs/scontact.c
--- linux-2.4.16/fs/mfs/scontact.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/scontact.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,517 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/mfs.h>
+#include <linux/mfs_socket.h>
+#include <mos/routines.h>
+
+#define	MFS_MINSERVERS	2
+#define	MFS_MAXDEDICATED 6
+#define	MFS_MAXSERVERS	14
+#define	MFS_CONTACT_KEEPALIVE (60*HZ)
+#define	MFS_MAXQ	100	/* do not increase - leave space under 128 */
+
+spinlock_t mfs_servq_lock = SPIN_LOCK_UNLOCKED;
+
+struct task_struct *mfs_main_server_task;
+int n_mfs_servers;
+int mfs_total_services;
+
+struct mfs_server_contact
+{
+	struct mfs_server_contact *next;
+	struct socket *sock;
+	int caller;
+	int serial;
+	unsigned long last_use;
+};
+
+/* service queue: */
+struct mfs_server_contact *queued_services;
+struct mfs_server_contact *last_queued_service;
+int mfs_qlen;
+
+/* past connections that are still kept open: */
+struct mfs_server_contact *mfs_idle_connections;
+
+/* servers waiting: */
+DECLARE_WAIT_QUEUE_HEAD(wait_to_serve_mfs);
+atomic_t waiting_to_serve_mfs = ATOMIC_INIT(0);
+int mfs_idle_servers;
+
+/* main server waiting: */
+DECLARE_WAIT_QUEUE_HEAD(wait_for_mfs_calls);
+volatile int waiting_for_mfs_calls;
+volatile int mfs_has_new_calls;
+
+int
+mfs_server_send(struct mfs_server_contact *s, int type, void *header, int hdln,
+			void *dat1, int len1, void *dat2, int len2)
+{
+	return(mfs_send(s->sock, 0, s->serial, type,
+					header, hdln, dat1, len1, dat2, len2));
+}
+
+int
+mfs_server_receive(struct mfs_server_contact *s,
+					void **header, void **dat1, void **dat2)
+{
+	return(mfs_receive(s->sock, MFS_MUST_MATCH, &s->serial, NULL,
+							header, dat1, dat2));
+}
+
+void
+mfs_serve1(struct mfs_server_contact *s)
+{
+	int type, more, changed;
+	void *header;
+	void *dat1;
+	void *dat2;
+	static int n_dedicated;
+
+	mfs_set_main_ownership(s->sock, 0);
+	again:
+	type = mfs_receive(s->sock, MFS_FIRST_RECEIVE, &s->serial, NULL,
+							&header, &dat1, &dat2);
+	if(type == MFS_CLOSE || type < MFS_NONE)
+	{
+		mfs_close_socket(s->sock);
+if(mfs_debug > 1)
+printk("mfs_serve1: closing socket %x by client request!\n", (int)s->sock);
+		s->sock = NULL;
+	}
+	else
+		mfs_serve(s, type, header, dat1, dat2);
+	if(header)
+		kfree(header);
+	if(!s->sock)
+		return;
+	spin_lock(&mfs_servq_lock);
+	more = 1 + (n_dedicated < MFS_MAXDEDICATED);
+	if(more == 2)
+		n_dedicated++;
+	spin_unlock(&mfs_servq_lock);
+	changed = mfs_set_main_ownership(s->sock, more);
+	if(more == 2)
+	{
+		spin_lock(&mfs_servq_lock);
+		n_dedicated--;
+		spin_unlock(&mfs_servq_lock);
+	}
+	if(!changed)
+	{
+		if(mfs_debug)
+			printk("mfs_serv1: serving in chain!\n");
+		goto again;
+	}
+}
+
+/* trim_idle_connections must be called with mfs_servq_lock! */
+void
+trim_idle_connections(void)
+{
+#define	HOGS_CONSIDERED	10
+	struct mfs_server_contact *s, *prev, *next, *dispose = NULL;
+	int nhogs = 0;
+	int hogpe[HOGS_CONSIDERED];
+	int hogs[HOGS_CONSIDERED];
+	int i, caller, least, leastval, penalty, bar;
+	int disposed = 0;
+
+	/* compile the hog-table */
+	for(prev = NULL, s = mfs_idle_connections ; s ; prev = s , s = s->next)
+	{
+		caller = s->caller;
+		for(i = 0 ; i < nhogs ; i++)
+		if(hogpe[i] == caller)
+		{
+			hogs[i]++;
+			goto next_connection;
+		}
+		if(i < HOGS_CONSIDERED)
+		{
+			hogpe[i] = caller;
+			hogs[i] = 1;
+			nhogs++;
+			goto next_connection;
+		}
+		leastval = 10000000;
+		least = 0;
+		for(i = 0 ; i < HOGS_CONSIDERED ; i++)
+		if(hogs[i] < leastval)
+		{
+			least = i;
+			leastval = hogs[i];
+		}
+		hogpe[least] = caller;
+		hogs[least] = 1;
+		next_connection:;
+	}
+	/* calculate penalties, store in the "serial" field (unused for idle) */
+	/* penalty increases for old sockets and for hogs */
+	for(s = mfs_idle_connections ; s ; s = s->next)
+	{
+		penalty = abs((long)jiffies - (long)(s->last_use));
+		if(penalty > 2*MFS_CONTACT_KEEPALIVE)	/* avoid overflow */
+			penalty = 2*MFS_CONTACT_KEEPALIVE;
+		penalty = mfs_total_services * penalty / MFS_CONTACT_KEEPALIVE; 
+		caller = s->caller;
+		for(i = 0 ; i < nhogs ; i++)
+		if(hogpe[i] == caller)
+		{
+			penalty *= hogs[i];
+			break;
+		}
+		s->serial = penalty;
+	}
+	/* collect old sockets, more aggressively as services are exhausted */
+	for(bar = MFS_MAXQ/2 ;
+		mfs_idle_connections && mfs_total_services - disposed > MFS_MAXQ
+							; bar = bar * 2 / 3)
+	for(prev = NULL, s = mfs_idle_connections ; s ; )
+	if(s->serial >= bar)
+	{
+		next = s->next;
+		if(prev)
+			prev->next = next;
+		else
+			mfs_idle_connections = next;
+if(mfs_debug)
+printk("trim_idle_connections: penalty=%d, closing socket %x\n", s->serial,
+(int)s->sock);
+		s->next = dispose;
+		dispose = s;
+		disposed++;
+		s = next;
+	}
+	else
+	{
+		prev = s;
+		s = s->next;
+	}
+	/* dispose of those sockets */
+	mfs_total_services -= disposed;
+	spin_unlock(&mfs_servq_lock);
+	for(; dispose ; dispose = next)
+	{
+		next = dispose->next;
+		mfs_close_socket(dispose->sock);
+		kfree(dispose);
+	}
+	spin_lock(&mfs_servq_lock);
+}
+
+void
+mfs_recycle_service(struct mfs_server_contact *s)
+{
+	spin_lock(&mfs_servq_lock);
+	if(!s->sock)
+	{
+		mfs_total_services--;
+		spin_unlock(&mfs_servq_lock);
+		kfree(s);
+		return;
+	}
+	if(mfs_total_services >= MFS_MAXQ)
+		trim_idle_connections();
+	if(mfs_total_services < MFS_MAXQ)
+	{
+		s->last_use = jiffies;
+		s->next = mfs_idle_connections;
+		mfs_idle_connections = s;
+		spin_unlock(&mfs_servq_lock);
+		return;
+	}
+if(mfs_debug)
+printk("mfs_recycle_service: closing socket %x (too many connections already)\n", (int)s->sock);
+	mfs_total_services--;
+	spin_unlock(&mfs_servq_lock);
+	mfs_close_socket(s->sock);
+	kfree(s);
+}
+
+int
+mfs_server(void *nothing)
+{
+	struct mfs_server_contact *s;
+	struct task_struct *p = current;
+	extern struct task_struct *child_reaper;
+
+	strcpy(p->comm, "mfs_server");
+	p->exit_signal = SIGCHLD;
+	p->p_opptr = child_reaper;
+	write_lock_irq(&tasklist_lock);
+	REMOVE_LINKS(p);
+	p->p_pptr = p->p_opptr;
+	SET_LINKS(p);
+	p->fs->umask = 0;
+	write_unlock_irq(&tasklist_lock);
+	set_fs(KERNEL_DS);	/* all server I/O always to kernel */
+	spin_lock(&mfs_servq_lock);
+	mfs_idle_servers--;
+	while(1)
+	{
+		while((s = queued_services))
+		{
+			mfs_qlen--;
+			if(!(queued_services = s->next))
+				last_queued_service = NULL;
+			spin_unlock(&mfs_servq_lock);
+			mfs_serve1(s);
+			mfs_recycle_service(s);
+			spin_lock(&mfs_servq_lock);
+		}
+		if(n_mfs_servers > MFS_MINSERVERS || MFS_PE == MFS_UNKNOWN_PE)
+		{
+			n_mfs_servers--;
+			spin_unlock(&mfs_servq_lock);
+			return(0);		/* and exit */
+		}
+		mfs_idle_servers++;
+		atomic_inc(&waiting_to_serve_mfs);
+		spin_unlock(&mfs_servq_lock);
+		interruptible_sleep_on(&wait_to_serve_mfs);
+		if(p->sigpending)
+		{
+			spin_lock_irq(&p->sigmask_lock);
+			flush_signals(p);
+			spin_unlock_irq(&p->sigmask_lock);
+		}
+		spin_lock(&mfs_servq_lock);
+		atomic_dec(&waiting_to_serve_mfs);
+		mfs_idle_servers--;
+	}
+}
+
+void
+mfs_new_request_arrived(void)
+{
+if(mfs_debug > 1)
+printk("mfs_new_request_arrived!\n");
+	mfs_has_new_calls = 1;
+	if(waiting_for_mfs_calls)
+		wake_up_interruptible(&wait_for_mfs_calls);
+}
+
+/* mfs_add_to_queue must be called with mfs_servq_lock! */
+static inline void
+mfs_add_to_queue(struct mfs_server_contact *s)
+{
+	s->next = NULL;
+	mfs_qlen++;
+	if(last_queued_service)
+		last_queued_service->next = s;
+	else
+		queued_services = s;
+	last_queued_service = s;
+	if(atomic_read(&waiting_to_serve_mfs))
+		wake_up_interruptible(&wait_to_serve_mfs);
+}
+
+int
+mfs_main_server(void *nothing)
+{
+	register struct task_struct *p = current;
+	struct socket *mainsock = NULL, *sock;
+	struct mfs_server_contact *s, *prev, *next, *dispose = NULL;
+	int caller;
+	unsigned long last_trim = 0;
+	int client_pid = 0;
+	int success;
+	DECLARE_WAITQUEUE(wait, p);
+
+	mfs_main_server_task = p;
+	common_daemon_setup("mfs_main_server", 1);
+	while(client_pid <= 0 || !mainsock)
+	{
+		if(client_pid <= 0)
+			client_pid = kernel_thread(mfs_client_daemon, NULL, 0);
+		if(!mainsock)
+			mainsock = mfs_open_main_socket();
+		if(client_pid > 0 && mainsock)
+			break;
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(MFS_CONTACT_KEEPALIVE / 3);
+		spin_lock_irq(&p->sigmask_lock);
+		flush_signals(p);
+		spin_unlock_irq(&p->sigmask_lock);
+	}
+	mainloop:
+	spin_lock(&mfs_servq_lock);
+	if(MFS_PE != MFS_UNKNOWN_PE)
+	while(n_mfs_servers < MFS_MINSERVERS)
+	{
+		n_mfs_servers++;
+		mfs_idle_servers++;
+		spin_unlock(&mfs_servq_lock);
+		success = (kernel_thread(mfs_server, NULL, 0) >= 0);
+		spin_lock(&mfs_servq_lock);
+		if(!success)
+		{
+			n_mfs_servers--;
+			mfs_idle_servers--;
+			break;
+		}
+	}
+	if(mfs_has_new_calls)
+	{
+		spin_unlock(&mfs_servq_lock);
+		mfs_has_new_calls = 0;
+		while((sock = mfs_new_connection(mainsock, &caller)))
+		if(MFS_PE == MFS_UNKNOWN_PE)
+			mfs_close_socket(sock);
+		else
+		{
+if(mfs_debug)
+printk("mfs_main_server: new connection=%x (mainsock=%x)\n", (int)sock, (int)mainsock);
+			if((s = (struct mfs_server_contact *)kmalloc(
+				sizeof(struct mfs_server_contact), GFP_KERNEL)))
+			{
+				spin_lock(&mfs_servq_lock);
+				mfs_total_services++;
+				s->sock = sock;
+				s->caller = caller;
+				mfs_add_to_queue(s);
+				spin_unlock(&mfs_servq_lock);
+			}
+			else
+				mfs_close_socket(sock);
+		}
+		spin_lock(&mfs_servq_lock);
+		for(prev = NULL, s = mfs_idle_connections ; s ; )
+		if(MFS_PE == MFS_UNKNOWN_PE || mfs_socket_has_data(s->sock))
+		{
+			next = s->next;
+			if(prev)
+				prev->next = next;
+			else
+				mfs_idle_connections = next;
+			if(MFS_PE == MFS_UNKNOWN_PE)
+			{
+				s->next = dispose;
+				dispose = s;
+				mfs_total_services--;
+			}
+			else
+			{
+if(mfs_debug)
+printk("mfs_main_server: new request on old sock (%x)\n", (int)s->sock);
+				mfs_add_to_queue(s);
+			}
+			s = next;
+		}
+		else
+		{
+			prev = s;
+			s = s->next;
+		}
+		while(mfs_qlen > mfs_idle_servers &&
+			n_mfs_servers < MFS_MAXSERVERS &&
+			MFS_PE != MFS_UNKNOWN_PE)
+		{
+if(mfs_debug > 1)printk("mfs_main_server adding a server\n");
+			n_mfs_servers++;
+			mfs_idle_servers++;
+			spin_unlock(&mfs_servq_lock);
+			success = (kernel_thread(mfs_server, NULL, 0) >= 0);
+			spin_lock(&mfs_servq_lock);
+			if(!success)
+			{
+				n_mfs_servers--;
+				mfs_idle_servers--;
+				if(!n_mfs_servers)
+				{
+					/* too bad - just shut all down */
+					while((s = queued_services))
+					{
+						queued_services = s->next;
+						mfs_qlen--;
+						mfs_total_services--;
+						spin_unlock(&mfs_servq_lock);
+						mfs_close_socket(s->sock);
+						kfree(s);
+						spin_lock(&mfs_servq_lock);
+					}
+				}
+				break;
+			}
+		}
+	}
+	if(abs((long)jiffies - (long)last_trim) > HZ)
+	{
+		for(prev = NULL, s = mfs_idle_connections ; s ; )
+		if(abs((long)jiffies - (long)(s->last_use)) >=
+							MFS_CONTACT_KEEPALIVE)
+		{
+			next = s->next;
+			if(prev)
+				prev->next = next;
+			else
+				mfs_idle_connections = next;
+			if(mfs_socket_has_data(s->sock))
+				mfs_add_to_queue(s);
+			else
+			{
+if(mfs_debug > 1)
+printk("mfs_main_server: closing old socket %x\n", (int)s->sock);
+				s->next = dispose;
+				dispose = s;
+				mfs_total_services--;
+			}
+			s = next;
+		}
+		else
+		{
+			prev = s;
+			s = s->next;
+		}
+	}
+	spin_unlock(&mfs_servq_lock);
+	last_trim = jiffies;
+	for(; dispose ; dispose = next)
+	{
+		next = dispose->next;
+		mfs_close_socket(dispose->sock);
+		kfree(dispose);
+	}
+	if(!mfs_has_new_calls)
+	{
+		add_wait_queue(&wait_for_mfs_calls, &wait);
+		set_current_state(TASK_INTERRUPTIBLE);
+		waiting_for_mfs_calls = 1;
+		if(!mfs_has_new_calls)
+			schedule_timeout(MFS_CONTACT_KEEPALIVE / 3);
+		waiting_for_mfs_calls = 0;
+		remove_wait_queue(&wait_for_mfs_calls, &wait);
+		set_current_state(TASK_RUNNING);
+	}
+	spin_lock_irq(&p->sigmask_lock);
+	flush_signals(p);
+	spin_unlock_irq(&p->sigmask_lock);
+	mfs_throw_garbage();
+	goto mainloop;
+}
+
+void
+mfs_make_servers(void)
+{
+	kernel_thread(mfs_main_server, NULL, 0);
+}
+
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/server.c linux-2.4.16-mosix/fs/mfs/server.c
--- linux-2.4.16/fs/mfs/server.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/server.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,471 @@
+/* Additional changes by Moshe Bar
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/slab.h>
+#include <linux/mfs.h>
+#include <linux/dirent.h>
+
+void
+unpack_credits(struct mfs_cred *cred)
+{
+	register struct task_struct *p = current;
+	register int i;
+
+	p->uid = cred->uid;
+	p->euid = cred->euid;
+	p->sgid = cred->sgid;
+	p->fsuid = cred->fsuid;
+	p->gid = cred->gid;
+	p->egid = cred->egid;
+	p->sgid = cred->sgid;
+	p->fsgid = cred->fsgid;
+	p->ngroups = cred->ngroups;
+	for(i = cred->ngroups-1 ; i >= 0 ; i--)
+		p->groups[i] = cred->groups[i];
+	p->cap_effective = (p->cap_effective & ~REMOTE_CAPS) |
+						(cred->caps & REMOTE_CAPS);
+	p->mosix.whereami = cred->whereami;
+	p->mosix.deppe = cred->deppe;
+}
+
+void
+mfs_serve_attach(struct mfs_server_contact *con,
+					struct mfs_request_attach_handle *s)
+{
+	struct mfs_reply_attach_handle r;
+
+	r.result = mfs_low_attach_handle(s->handle);
+	mfs_server_send(con, MFS_REPLY_ATTACH_HANDLE, &r, sizeof(r), NULL, 0,
+								NULL, 0);
+}
+
+void
+mfs_serve_touch(struct mfs_server_contact *con,
+					struct mfs_request_touch_handle *s)
+{
+	struct mfs_reply_touch_handle r;
+
+	r.result = mfs_low_touch_handle(s->handle);
+	mfs_server_send(con, MFS_REPLY_TOUCH_HANDLE, &r, sizeof(r), NULL, 0,
+								NULL, 0);
+}
+
+void
+mfs_serve_llseek(struct mfs_server_contact *con, struct mfs_request_llseek *s)
+{
+	struct mfs_reply_llseek r;
+
+	unpack_credits(&s->cred);
+	r.result = mfs_low_llseek(s->handle, &s->file, s->offset, s->origin);
+	r.file = s->file;
+	mfs_server_send(con, MFS_REPLY_LLSEEK, &r, sizeof(r), NULL, 0, NULL, 0);
+}
+
+void
+mfs_serve_read(struct mfs_server_contact *con, struct mfs_request_read *s)
+{
+	struct mfs_reply_read r;
+	int n;
+	size_t count = s->count;
+	size_t cnt, sent = 0;
+	char *buf = NULL;
+	int ret = 0;
+	size_t max;
+	char smallbuf[4];
+	struct mfs_interim_data d;
+
+	for(max = s->count > 16384 ? 16384 : s->count ; max > sizeof(smallbuf) ;
+								max >>= 1)
+	if((buf = (char *)kmalloc(max, GFP_KERNEL)))
+		break;
+	if(max <= sizeof(smallbuf))
+	{
+		buf = smallbuf;
+		max = sizeof(smallbuf);
+	}
+	unpack_credits(&s->cred);
+	while(count > 0)
+	{
+		cnt = count;
+		if(cnt > max)
+			cnt = max;
+		n = mfs_low_read(s->handle, &s->file, buf, cnt, &s->pos);
+		if(n < cnt || cnt == count)
+		{
+			if(n < 0)
+				ret = n;
+			else
+				ret += n;
+			break;
+		}
+		ret += cnt;
+		d.count = cnt;
+		if(mfs_server_send(con, MFS_INTERIM_DATA, (void *)&d, sizeof(d),
+			(void *)buf, cnt, NULL, 0))
+			goto free_buf;
+		sent += cnt;
+		count -= cnt;
+	}
+	r.file = s->file;
+	r.ppos = s->pos;
+	r.result = ret;
+	r.datalen = (ret > 0 && ret > sent) ? ret - sent : 0;
+	mfs_server_send(con, MFS_REPLY_READ, &r, sizeof(r),
+				r.datalen ? buf : NULL, r.datalen, NULL, 0);
+	free_buf:
+	if(max != sizeof(smallbuf))
+		kfree(buf);
+}
+
+void
+mfs_serve_write(struct mfs_server_contact *con, struct mfs_request_write *s,
+								void *buf)
+{
+	struct mfs_reply_write r;
+	struct mfs_interim_data *i = NULL;
+	ssize_t n;
+	size_t count = s->count;
+	size_t cnt;
+	struct task_struct *p = current;
+
+	unpack_credits(&s->cred);
+	if(signal_pending(p))
+	{
+		spin_lock_irq(&p->sigmask_lock);
+		flush_signals(p);
+		spin_unlock_irq(&p->sigmask_lock);
+	}
+	cnt = s->datalen;
+	if(cnt < count)
+		mfs_server_send(con, MFS_CONTINUE, NULL, 0, NULL, 0, NULL, 0);
+	r.result = mfs_low_write(s->handle, &s->file, buf, cnt,&s->pos,s->flim);
+	/* in Linux, an append-"write", once started is not broken even if
+	 * another process interfered */
+	s->file.f_flags &= ~O_APPEND;
+	if(r.result == cnt)
+	while(r.result < count)
+	{
+		if(i)
+			kfree(i);
+		if((n = mfs_server_receive(con, (void **)&i, &buf, NULL)) < 0)
+			return;
+		if(n == MFS_STOP)
+		{
+			r.result = -EFAULT;
+			break;
+		}
+		if(n != MFS_INTERIM_DATA)
+		{
+			printk("mfs_serve_write: unexpected type: %d\n", n);
+			if(i)
+				kfree(i);
+			return;
+		}
+		n = mfs_low_write(s->handle, &s->file, buf, i->count, &s->pos,
+								s->flim);
+		r.result += n;
+		if(n < i->count)
+		{
+			if(n < 0)
+				r.result = n;
+			break;
+		}
+	}
+	if(i)
+		kfree(i);
+	r.file = s->file;
+	r.ppos = s->pos;
+	if(sigismember(&p->pending.signal, SIGXFSZ))
+	{
+		spin_lock_irq(&p->sigmask_lock);
+		flush_signals(p);
+		spin_unlock_irq(&p->sigmask_lock);
+		r.hadsigxfsz = 1;
+	}
+	else
+		r.hadsigxfsz = 0;
+	current->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
+	mfs_server_send(con, MFS_REPLY_WRITE, &r, sizeof(r), NULL, 0, NULL, 0);
+}
+
+struct mfs_serve_readdir_callback
+{
+	struct mfs_server_contact *con;
+	void *buf, *bufp;
+	int buflen;
+	int policy;
+	int maxbytes;
+};
+
+int
+mfs_serve_flush_dirs(struct mfs_serve_readdir_callback *cb)
+{
+	struct mfs_interim_data i;
+	struct mfs_interim_readdir *ri;
+	int t, err;
+
+	i.count = cb->bufp - cb->buf;
+	if(i.count == 0)
+		return(0);
+	if(mfs_server_send(cb->con, MFS_INTERIM_DATA, (void *)&i, sizeof(i),
+						cb->buf, i.count, NULL, 0))
+		return(-EINVAL);
+	t = mfs_server_receive(cb->con, (void **)&ri, NULL, NULL);
+	if(t == MFS_INTERIM_READDIR)
+		err = ri->error;
+	else
+		err = -EINVAL;
+	if(ri)
+		kfree(ri);
+	if(err)
+		return(err);
+	cb->bufp = cb->buf;
+	return(0);
+}
+
+int
+mfs_serve_filldir(void *__cb, const char *name, int namelen, loff_t offset,
+						ino_t ino, unsigned int type)
+{
+	struct mfs_serve_readdir_callback *cb = __cb;
+	int reclen;
+	int err;
+
+	switch(cb->policy)
+	{
+		case MFS_READDIR_JUSTONE:
+			if(!cb->maxbytes)
+				return(-EINVAL);
+			cb->maxbytes = 0;
+			break;
+		case MFS_READDIR_GETDENTS:
+			reclen = (offsetof(struct dirent, d_name[0]) + namelen +
+				1 + sizeof(long)-1) & ~(sizeof(long)-1);
+			if(reclen > cb->maxbytes)
+				return(-EINVAL);
+			cb->maxbytes -= reclen;
+			break;
+		case MFS_READDIR_GETDENTS64:
+			reclen = (offsetof(struct dirent64, d_name[0]) +
+				namelen + 1 + sizeof(u64)-1) & ~(sizeof(u64)-1);
+			if(reclen > cb->maxbytes)
+				return(-EINVAL);
+			cb->maxbytes -= reclen;
+			break;
+	}
+	reclen = sizeof(ino_t) + sizeof(loff_t) + sizeof(unsigned int) +
+						sizeof(short) + namelen;
+	if(reclen > cb->buflen - (cb->bufp - cb->buf))
+	{
+		if(cb->bufp == cb->buf || (cb->policy != MFS_READDIR_GETDENTS
+				&& cb->policy != MFS_READDIR_GETDENTS64))
+		{
+			/* should not happen - we allocated at least dirent64 */
+			printk("mfs_serve_filldir: buffer not sufficient\n");
+			return(-EINVAL);
+		}
+		if((err = mfs_serve_flush_dirs(cb)))
+			return(err);
+	}
+	*((ino_t *)cb->bufp)++ = ino;
+	*((loff_t *)cb->bufp)++ = offset;
+	*((unsigned int *)cb->bufp)++ = type;
+	*((short *)cb->bufp)++ = namelen;
+	memcpy(cb->bufp, (void *)name, namelen);
+	cb->bufp += namelen;
+	if(cb->policy == MFS_READDIR_UNKNOWN)
+		return(mfs_serve_flush_dirs(cb));
+	else
+		return(0);
+}
+
+void
+mfs_serve_readdir(struct mfs_server_contact *con, struct mfs_request_readdir *s)
+{
+	struct mfs_reply_readdir r;
+	int ret = 0;
+	struct mfs_serve_readdir_callback cb;
+	int multi = (s->policy == MFS_READDIR_GETDENTS ||
+					s->policy == MFS_READDIR_GETDENTS64);
+	int duma, dumb;
+
+	for(cb.buflen = multi ? 16384 : sizeof(struct dirent64) ;
+		cb.buflen >= sizeof(struct dirent64) ; cb.buflen >>= 1)
+	if((cb.buf = (char *)kmalloc(cb.buflen, GFP_KERNEL)))
+		break;
+	cb.bufp = cb.buf;
+	cb.policy = s->policy;
+	cb.maxbytes = multi ? s->maxbytes : 1;
+	cb.con = con;
+	unpack_credits(&s->cred);
+	if(cb.buflen < sizeof(struct dirent64))
+		ret = -ENOMEM;
+	else
+		ret = mfs_low_readdir(s->handle, &s->file, (void *)&cb, 
+					mfs_serve_filldir, &duma, &dumb);
+	r.file = s->file;
+	r.result = ret;
+	r.datalen = cb.bufp - cb.buf;
+	mfs_server_send(con, MFS_REPLY_READDIR, &r, sizeof(r),
+				r.datalen ? cb.buf : NULL, r.datalen, NULL, 0);
+	if(cb.buflen >= sizeof(struct dirent64))
+		kfree(cb.buf);
+}
+
+void
+mfs_serve_ioctl(struct mfs_server_contact *con, struct mfs_request_ioctl *s)
+{
+	struct mfs_reply_ioctl r;
+
+	unpack_credits(&s->cred);
+	r.result = mfs_low_ioctl(s->handle, &s->file, s->cmd, s->arg, s->size,
+								&s->data);
+	r.file = s->file;
+	r.data = s->data;
+	mfs_server_send(con, MFS_REPLY_IOCTL, &r, sizeof(r), NULL, 0, NULL, 0);
+}
+
+void
+mfs_serve_fsync(struct mfs_server_contact *con, struct mfs_request_fsync *s)
+{
+	struct mfs_reply_fsync r;
+
+	unpack_credits(&s->cred);
+	r.result = mfs_low_fsync(s->handle, &s->file, s->datasync);
+	r.file = s->file;
+	mfs_server_send(con, MFS_REPLY_FSYNC, &r, sizeof(r), NULL, 0, NULL, 0);
+}
+
+void
+mfs_serve_revalidate(struct mfs_server_contact *con,
+					struct mfs_request_revalidate *s)
+{
+	struct mfs_reply_revalidate r;
+
+	unpack_credits(&s->cred);
+	r.result = mfs_low_revalidate(s->handle, &r.iinfo);
+	mfs_server_send(con, MFS_REPLY_REVALIDATE, &r, sizeof(r), NULL, 0, NULL, 0);
+}
+
+void
+mfs_serve_express(struct mfs_server_contact *con, struct mfs_request_express *s,
+						char *name, void *more_data)
+{
+	struct mfs_reply_express r;
+	char *newname;
+
+	unpack_credits(&s->cred);
+	r.handle = s->handle;
+	r.complete = s->complete;
+	if(r.complete.more_data)
+		r.complete.more_data = more_data;
+	r.result = mfs_low_express_lookup(&r.handle, name, s->follow,
+			s->link_count, s->total_link_count, &r.iinfo,
+			&newname, &r.complete);
+	r.namelen = (r.result || !newname) ? 0 : strlen(newname) + 1;
+	mfs_server_send(con, MFS_REPLY_EXPRESS, &r, sizeof(r),
+				r.namelen ? (void *)newname : NULL, r.namelen,
+				r.complete.more_data, r.complete.more_data_len);
+	if(r.namelen)
+		kfree(newname);
+	if(r.complete.more_data)
+		kfree(r.complete.more_data);
+}
+
+void
+mfs_serve_checkpath(struct mfs_server_contact *con,
+						struct mfs_request_checkpath *s)
+{
+	struct mfs_reply_checkpath r;
+	char *path;
+
+	unpack_credits(&s->cred);
+	path = mfs_low_check_path(s->handle);
+	r.namelen = path ? strlen(path)+1 : 0;
+	mfs_server_send(con, MFS_REPLY_CHECKPATH, &r, sizeof(r),
+		r.namelen ? (void *)path : NULL, r.namelen, NULL, 0);
+	if(path)
+		kfree(path);
+}
+
+void
+mfs_serve_setattr(struct mfs_server_contact *con, struct mfs_request_setattr *s)
+{
+	struct mfs_reply_setattr r;
+
+	unpack_credits(&s->cred);
+	r.result = mfs_low_setattr(s->handle, &s->attr);
+	mfs_server_send(con, MFS_REPLY_SETATTR, &r, sizeof(r), NULL, 0,
+								NULL, 0);
+}
+
+void
+mfs_serve(struct mfs_server_contact *con, int type, void *header, void *dat1,
+								void *dat2)
+{
+	switch(type)
+	{
+	case MFS_REQUEST_ATTACH_HANDLE:
+		mfs_serve_attach(con,
+				(struct mfs_request_attach_handle *)header);
+		break;
+	case MFS_REQUEST_TOUCH_HANDLE:
+		mfs_serve_touch(con,(struct mfs_request_touch_handle *)header);
+		break;
+	case MFS_REQUEST_DISPOSE_HANDLE:
+		mfs_low_dispose_handle(
+			((struct mfs_request_dispose_handle *)header)->handle);
+		mfs_server_send(con, MFS_CONTINUE, NULL, 0, NULL, 0, NULL,0);
+		break;
+	case MFS_REQUEST_LLSEEK:
+		mfs_serve_llseek(con, (struct mfs_request_llseek *)header);
+		break;
+	case MFS_REQUEST_READ:
+		mfs_serve_read(con, (struct mfs_request_read *)header);
+		break;
+	case MFS_REQUEST_WRITE:
+		mfs_serve_write(con, (struct mfs_request_write *)header, dat1);
+		break;
+	case MFS_REQUEST_READDIR:
+		mfs_serve_readdir(con, (struct mfs_request_readdir *)header);
+		break;
+	case MFS_REQUEST_IOCTL:
+		mfs_serve_ioctl(con, (struct mfs_request_ioctl *)header);
+		break;
+	case MFS_REQUEST_FSYNC:
+		mfs_serve_fsync(con, (struct mfs_request_fsync *)header);
+		break;
+	case MFS_REQUEST_REVALIDATE:
+		mfs_serve_revalidate(con,
+				(struct mfs_request_revalidate *)header);
+		break;
+	case MFS_REQUEST_EXPRESS:
+		mfs_serve_express(con, (struct mfs_request_express *)header,
+							(char *)dat1, dat2);
+		break;
+	case MFS_REQUEST_CHECKPATH:
+		mfs_serve_checkpath(con,
+					(struct mfs_request_checkpath *)header);
+		break;
+	case MFS_REQUEST_SETATTR:
+		mfs_serve_setattr(con, (struct mfs_request_setattr *)header);
+		break;
+	default:
+		printk("mfs_serve: type %d unimplemented\n", type);
+	}
+}
+
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/mfs/socket.c linux-2.4.16-mosix/fs/mfs/socket.c
--- linux-2.4.16/fs/mfs/socket.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/fs/mfs/socket.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,534 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ * used code by Oren Laadan.
+ */
+
+#include <linux/sched.h>
+#ifdef CONFIG_MOSIX_FS
+#include <net/tcp.h>
+#include <linux/mosix.h>
+#include <linux/slab.h>
+#include <linux/mfs.h>
+#include <linux/mfs_socket.h>
+#include <linux/poll.h>
+#include <mos/routines.h>
+#include <mos/protocol.h>
+
+/* meanwhile, we assume MOSIX uses only IPv4 addresses */
+/* when MOSIX can use IPv6, this file must also be upgraded */
+
+#ifdef CONFIG_MOSIX_UDB
+#define	MFS_CONNECT_TIMO	(100*HZ)
+#define	MFS_RECEIVE_TIMO	(100*HZ)
+#else
+#define	MFS_CONNECT_TIMO	(10*HZ)
+#define	MFS_RECEIVE_TIMO	(10*HZ)
+#endif /* CONFIG_MOSIX_UDB */
+
+int
+mfs_common_socket_setup(struct socket *sock)
+{
+	mm_segment_t oldfs = get_fs();
+	int error = 0;
+	int val;
+
+	set_fs(KERNEL_DS);
+	val = 32768+1024;
+	sock_setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&val, sizeof(val));
+	sock_setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&val, sizeof(val));
+	val = MOSIX_CONNECTION_KEEPALIVE_INTERVAL;
+	sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL,
+						(char *) &val, sizeof(val));
+	val = MOSIX_CONNECTION_KEEPALIVE_MAXTRIES;
+	sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT,
+						(char *) &val, sizeof(val));
+	val = MOSIX_CONNECTION_KEEPALIVE_TOTAL;
+	sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE,
+						(char *) &val, sizeof(val));
+	val = 1;
+	sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+						(char *)&val, sizeof(val));
+	error = sock_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
+						(char *)&val, sizeof(val));
+	set_fs(oldfs);
+	set_bit(SOCK_INTER_MOSIX, &sock->flags);
+	return(error);
+}
+
+struct socket *
+mfs_open_main_socket(void)
+{
+	struct socket *sock;
+	struct sockaddr_in addr;
+
+	deeper_sleep();
+
+	memset(&addr, 0, sizeof(struct sockaddr_in));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_port = MFS_MAIN_PORT;
+	if(sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &sock))
+		goto failed;
+
+	if(mfs_common_socket_setup(sock))
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		printk("setup failed on MFS main socket\n");
+#endif /* CONFIG_MOSIX_DEBUG */
+		goto failed;
+	}
+
+	if(sock->ops->bind(sock, (struct sockaddr *)&addr, sizeof(addr)))
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		printk("bind failed on MFS main socket\n");
+#endif /* CONFIG_MOSIX_DEBUG */
+		goto failed;
+	}
+	if(sock->ops->listen(sock, SOMAXCONN))
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		printk("listen failed on MFS main socket\n");
+#endif /* CONFIG_MOSIX_DEBUG */
+		goto failed;
+	}
+
+	lighter_sleep();
+	spin_lock_irq(&skown_lock);
+	sock->sk->owner = mfs_main_server_task;
+	spin_unlock_irq(&skown_lock);
+	return(sock);
+
+failed:
+	lighter_sleep();
+	if (sock)
+		sock_release(sock);
+	return(NULL);
+}
+
+struct socket *
+mfs_new_connection(struct socket *parent, int *caller)
+{
+	struct socket *sock;
+	struct mosix_addr mosaddr;
+	int val = sizeof(mosaddr.saddr);
+
+	if(!(parent->ops->poll(NULL, parent, NULL) & POLLIN))
+		return(NULL);
+	if (!(sock = sock_alloc()))
+		return(NULL);
+	sock->type = parent->type;
+	sock->ops = parent->ops;
+	if(sock->ops->accept(parent, sock, O_NONBLOCK))
+		goto failed;
+	if (sock->ops->getname(sock, &mosaddr.saddr, &val, 1))
+		goto failed;
+	if(!(*caller = net_to_mos(&mosaddr)))
+	{
+		comm_report_violation("MFS", &mosaddr.saddr);
+		goto failed;
+	}
+	if(mfs_common_socket_setup(sock))
+		goto failed;
+	spin_lock_irq(&skown_lock);
+	sock->sk->owner = mfs_main_server_task;
+	spin_unlock_irq(&skown_lock);
+	return(sock);
+	failed:
+	sock_release(sock);
+	return(NULL);
+}
+
+struct socket *
+mfs_connect_to(int to)
+{
+	struct task_struct *p = current;
+	int error;
+	struct socket *sock = NULL;
+	struct sockaddr addr;
+	unsigned long timo = MFS_CONNECT_TIMO;
+	DECLARE_WAITQUEUE(wait, p);
+
+	deeper_sleep();
+	if(!mos_to_net(to, &addr))
+	{
+		error = -EREMOTE;
+		goto failed;
+	}
+	((struct sockaddr_in *)&addr)->sin_port = MFS_MAIN_PORT;
+	if((error = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &sock)))
+		goto failed;
+	if((error = mfs_common_socket_setup(sock)))
+		goto failed;
+	sock->ops->connect(sock, &addr, sizeof(addr), O_NONBLOCK);
+	add_wait_queue(sock->sk->sleep, &wait);
+	while (sock->state != SS_CONNECTED)
+	{
+		set_current_state(TASK_INTERRUPTIBLE);
+		error = sock->ops->connect(sock, &addr, sizeof(addr),
+								O_NONBLOCK);
+		if (error != -EALREADY || (error = sock_error(sock->sk)))
+			break;
+		timo = schedule_timeout(timo);
+		if (timo <= 0)
+		{
+			error = -EAGAIN;
+			break;
+		}
+	}
+	remove_wait_queue(sock->sk->sleep, &wait);
+	set_current_state(TASK_RUNNING);
+
+	if (error)
+		goto failed;
+	if (sock->sk->err)
+	{
+		error = sock_error(sock->sk);	/* cleans error.. */
+		goto failed;
+	}
+	lighter_sleep();
+if(mfs_debug)
+printk("%s-mfs_connect_to %d: success\n", desc_mostask(NULL), to);
+	return (sock);
+
+failed:
+	lighter_sleep();
+	if (sock)
+		sock_release(sock);
+	return (ERR_PTR(error));
+}
+
+inline int
+mfs_socket_has_data(struct socket *sock)
+{
+	return((sock->ops->poll(NULL, sock, 0) &
+				(POLLRDNORM|POLLIN|POLLHUP|POLLERR)) != 0);
+}
+
+/*
+ * "mfs_socket_is_closed" is only called by the client on inactive sockets:
+ * we never expect server-initiated data, so POLLIN implies a closed socket.
+ */
+int
+mfs_socket_is_closed(struct socket *sock)
+{
+if(mfs_debug > 1)printk("socket_is_closed(%x): poll=0x%x\n", (int)sock, sock->ops->poll(NULL, sock, NULL));
+	return((sock->ops->poll(NULL, sock, NULL) &
+						(POLLHUP|POLLERR|POLLIN)) != 0);
+}
+
+int
+mfs_send(struct socket *sock, int first, int serial, int type,
+	void *header, int hdsz, void *dat1, int dat1sz, void *dat2, int dat2sz)
+{
+	struct mfs_message_header hd;
+	struct iovec iov[5];
+	struct msghdr msg = { NULL, 0, iov, 0, NULL, 0, MSG_NOSIGNAL };
+	mm_segment_t oldfs;
+	int niov = 1;
+	int size = 0;
+	int error = -ENOMEM;
+
+	hd.serial = serial;
+	hd.first = first;
+	hd.version = MFS_VERSION;
+	hd.caller = PE;
+	hd.type = type;
+	hd.hdsz = hdsz;
+	hd.dat1sz = dat1sz;
+	hd.dat2sz = dat2sz;
+	iov[0].iov_base = &hd;
+	iov[0].iov_len = sizeof(hd);
+	if(hdsz)
+	{
+		iov[1].iov_base = header;
+		iov[1].iov_len = hdsz;
+		niov++;
+	}
+	if(dat1sz)
+	{
+		iov[niov].iov_base = dat1;
+		iov[niov++].iov_len = dat1sz;
+	}
+	if(dat2sz)
+	{
+		iov[niov].iov_base = dat2;
+		iov[niov++].iov_len = dat2sz;
+	}
+	size = sizeof(hd) + hdsz + dat1sz + dat2sz;
+	msg.msg_iovlen = niov;
+
+	deeper_sleep();
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	error = sock->ops->sendmsg(sock, &msg, size, 0);
+if(mfs_debug)
+printk("%s-mfs_send, type=%d, serial=%d, size=%d/%d/%d, err=%d\n", desc_mostask(NULL), type, serial, hdsz, dat1sz, dat2sz, error);
+	set_fs(oldfs);
+	lighter_sleep();
+
+	return (error < 0 ? error : 0);
+}
+
+int
+mfs_do_receive(struct socket *sock, void *base, int len)
+{
+	struct task_struct *p = current;
+	int n = 0;
+	struct iovec iov;
+	struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0,
+				MSG_NOSIGNAL | MSG_DONTWAIT};
+	int done = 0;
+	unsigned long timo = MFS_RECEIVE_TIMO;
+	DECLARE_WAITQUEUE(wait, p);
+
+	add_wait_queue(sock->sk->sleep, &wait);
+	while(done < len)
+	{
+		set_current_state(TASK_INTERRUPTIBLE);
+		p->mosix.ignoreoldsigs = 1;
+		p->sigpending = 0;
+		if(!mfs_socket_has_data(sock))
+		{
+			if(timo <= 0)
+			{
+				len = -EPIPE;
+				break;
+			}
+if(mfs_debug)printk("mfs_do_receive: timo before=%ld\n", timo);
+			timo = schedule_timeout(timo);
+if(mfs_debug)printk("mfs_do_receive: timo after=%ld\n", timo);
+			continue;
+		}
+		iov.iov_base = (void *)((char *)base + done);
+		iov.iov_len = len - done;
+		msg.msg_iov = &iov;
+		msg.msg_iovlen = 1;
+if(mfs_debug > 2)printk("%s-mfs_do_receive: looking for %d-%d\n", desc_mostask(NULL), len, done);
+		n = sock->ops->recvmsg(sock, &msg, len-done, msg.msg_flags, 0);
+if(mfs_debug > 2)printk("%s-mfs_do_receive: got %d of %d-%d\n", desc_mostask(NULL), n, len, done);
+		if (n == -EAGAIN || n == -ERESTARTSYS || n == -EINTR)
+			continue;
+		if(n <= 0)
+		{
+			len = n < 0 ? n : ECONNRESET;
+			break;
+		}
+		done += n;
+	}
+	remove_wait_queue(sock->sk->sleep, &wait);
+	set_current_state(TASK_RUNNING);
+	recalc_sigpending(p);
+	return (len);
+}
+
+int
+mfs_receive(struct socket *sock, int policy, int *serial,
+		struct mfs_message_header *preread_header,
+					void **header, void **dat1, void **dat2)
+{
+	struct mfs_message_header hd;
+	void *contents = NULL;
+	int tlen;
+	mm_segment_t oldfs;
+	int error;
+	int need_another;
+
+if(mfs_debug > 1)
+printk("%s-mfs_receive, policy=%d\n", desc_mostask(NULL), policy);
+	deeper_sleep();
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	next_message:
+	need_another = 0;
+
+	if(preread_header && policy != MFS_JUST_HEADER)
+	{
+		hd = *preread_header;
+		preread_header = NULL;
+		error = 0;
+	}
+	else if ((error = mfs_do_receive(sock, &hd, sizeof(hd))) != sizeof(hd))
+	{
+if(mfs_debug)
+printk("%s-mfs_receive: asked for header(%d), got %d\n", desc_mostask(NULL), sizeof(hd), error);
+		if (error >= 0)
+			error = -EPIPE;
+		goto failed;
+	}
+if(mfs_debug)
+printk("%s-mfs_do_receive: asked and got header: ", desc_mostask(NULL));
+if(mfs_debug)
+printk("version=%d, first=%d, caller=%d, serial=%d, type=%d, size=%d/%d/%d\n", hd.version,hd.first, hd.caller, hd.serial, hd.type, hd.hdsz, hd.dat1sz, hd.dat2sz);
+	if(hd.version != MFS_VERSION)
+	{
+		static int limit;
+
+		if(limit++ < 5)
+		{
+			printk("MFS received request from wrong version:\n");
+			printk("Mine is %d, theirs (%d) is %d\n", MFS_VERSION,
+							hd.caller, hd.version);
+			error = -EINVAL;
+			goto failed;
+		}
+	}
+	error = 0;
+	switch(policy)
+	{
+		case MFS_JUST_HEADER:
+			if(hd.serial != *serial)
+			{
+				need_another = 1;
+				break;
+			}
+			*preread_header = hd;
+			goto done;
+		case MFS_SKIP_OTHERS:
+			if(hd.serial != *serial)
+				need_another = 1;
+			break;
+		case MFS_MUST_MATCH:
+			if(hd.first || hd.serial != *serial)
+			{
+				error = -EPIPE;
+				goto failed;
+			}
+			break;
+		case MFS_FIRST_RECEIVE:
+			if(hd.first)
+				*serial = hd.serial;
+			else
+			{
+				error = -EPIPE;
+				goto failed;
+			}
+			break;
+	}
+	tlen = hd.hdsz + hd.dat1sz + hd.dat2sz;
+
+	if (tlen)
+	{
+		if(!(contents = kmalloc(tlen, GFP_KERNEL)))
+		{
+			error = -ENOMEM;
+			goto failed;
+		}
+		if ((error = mfs_do_receive(sock, contents, tlen)) != tlen) {
+if(mfs_debug)
+printk("%s-mfs_receive: asked for body(%d), got %d\n", desc_mostask(NULL), tlen, error);
+			if (error >= 0)
+				error = -EFAULT;
+			goto failed;
+		}
+if(mfs_debug>1)
+printk("%s-mfs_receive: asked and got body(%d)\n", desc_mostask(NULL), tlen);
+	}
+	error = 0;
+
+done:
+failed:
+	lighter_sleep();
+	set_fs(oldfs);
+	if(error)
+	{
+		if(contents)
+			kfree(contents);
+		if(header)
+			*header = NULL;
+		if(dat1)
+			*dat1 = NULL;
+		if(dat2)
+			*dat2 = NULL;
+if(mfs_debug)
+printk("%s-mfs_receive: error=%d\n", desc_mostask(NULL), error);
+		return(error);
+	}
+	else if(need_another)
+	{
+		need_another = 0;
+if(mfs_debug)
+printk("%s-mfs_receive: need another!\n", desc_mostask(NULL));
+		if(contents)
+		{
+			kfree(contents);
+			contents = NULL;
+		}
+		goto next_message;
+	}
+	if(header)
+		*header = contents;
+	if(dat1)
+		*dat1 = (void *)(((char *)contents) + hd.hdsz);
+	if(dat2)
+		*dat2 = (void *)(((char *)contents) + hd.hdsz + hd.dat1sz);
+	return(hd.type);
+}
+
+int
+mfs_set_main_ownership(struct socket *sock, int main)
+{
+	int timo = HZ;
+
+	spin_lock_irq(&skown_lock);
+	if(!main)
+	{
+		sock->sk->owner = NULL;
+		spin_unlock_irq(&skown_lock);
+		return(1);
+	}
+	sock->sk->owner = current;
+	set_bit(SOCK_WAIT_MFSDATA, &sock->flags);
+	spin_unlock_irq(&skown_lock);
+	while(1)
+	{
+		current->state = TASK_INTERRUPTIBLE;
+		if(sock->ops->poll(NULL, sock, 0) & POLLIN)
+		{
+			spin_lock_irq(&skown_lock);
+			clear_bit(SOCK_WAIT_MFSDATA, &sock->flags);
+			sock->sk->owner = NULL;
+			spin_unlock_irq(&skown_lock);
+			current->state = TASK_RUNNING;
+			return(0);
+		}
+		if(main == 1 || timo <= 0)
+		{
+			spin_lock_irq(&skown_lock);
+			clear_bit(SOCK_WAIT_MFSDATA, &sock->flags);
+			sock->sk->owner = NULL;
+			current->state = TASK_RUNNING;
+			spin_unlock_irq(&skown_lock);
+			sock->sk->owner = mfs_main_server_task;
+			mfs_new_request_arrived();
+			return(1);
+		}
+		timo = schedule_timeout(timo);
+	}
+}
+
+void
+mfs_close_socket(struct socket *sock)
+{
+	spin_lock_irq(&skown_lock);
+	if(sock->sk)
+		sock->sk->owner = NULL;
+	clear_bit(SOCK_INTER_MOSIX, &sock->flags);
+	spin_unlock_irq(&skown_lock);
+	if(sock->ops)
+		sock->ops->shutdown(sock, 2);
+	sock_release(sock);
+}
+
+#endif /* CONFIG_MOSIX_FS */
diff -ruN linux-2.4.16/fs/namei.c linux-2.4.16-mosix/fs/namei.c
--- linux-2.4.16/fs/namei.c	Wed Oct 17 23:46:29 2001
+++ linux-2.4.16-mosix/fs/namei.c	Sun Dec 23 13:56:53 2001
@@ -26,6 +26,15 @@
 #include <asm/namei.h>
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#include <linux/proc_fs.h>
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#define	replaced_name	name_left
+#endif /* CONFIG_MOSIX_DFSA */
+
 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
 
 /* [Feb-1997 T. Schoebel-Theuer]
@@ -237,6 +246,7 @@
 	spin_unlock(&arbitration_lock);
 	return 0;
 }
+
 int deny_write_access(struct file * file)
 {
 	spin_lock(&arbitration_lock);
@@ -324,6 +334,25 @@
 	return result;
 }
 
+#ifdef CONFIG_MOSIX_DFSA
+static inline int
+dfsa_crossed(struct nameidata *nd, struct vfsmount *prevmnt)
+{
+	if(nd->flags & LOOKUP_STAYFS)
+	{
+		mntput(prevmnt);
+		if(nd->mnt != prevmnt)
+		{
+			if(current->mosix.dflags & DREMOTE)
+				return(-EDOITATHOME);
+			nd->flags &= ~LOOKUP_STAYFS;
+			current->mosix.dflags &= ~DSTATSDOWN;
+		}
+	}
+	return(0);
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * This limits recursive symlink follows to 8, while
  * limiting consecutive symlinks to 40.
@@ -436,6 +465,15 @@
 	}
 }
 
+#ifdef CONFIG_MOSIX_FS
+static inline int
+unacceptable_mfs_fs(unsigned long magic)
+{
+	return(magic == PROC_SUPER_MAGIC || magic == 0x42494e4d);
+						  /* (BINMisc) */
+}
+#endif /* CONFIG_MOSIX_FS */
+
 /*
  * Name resolution.
  *
@@ -450,7 +488,29 @@
 	struct inode *inode;
 	int err;
 	unsigned int lookup_flags = nd->flags;
-
+#ifdef CONFIG_MOSIX_DFSA
+	struct vfsmount *prevmnt = NULL;
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	char *orig_part = NULL, *orig_ref = NULL, *tmpname;
+	int flattings = 0;
+	char *free_me = NULL;
+#endif /* CONFIG_MOSIX_FS */
+
+#ifdef CONFIG_MOSIX_DFSA
+	/* an early error in path_init? (callers did not error-check there!) */
+	if(nd->flags & LOOKUP_DOITATHOME)
+	{
+		path_release(nd);
+		return(-EDOITATHOME);
+	}
+	if(nd->flags & LOOKUP_REPLACENAME)
+	{
+		nd->flags &= ~LOOKUP_REPLACENAME;
+		name = nd->replaced_name;
+		nd->replaced_name = NULL;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	while (*name=='/')
 		name++;
 	if (!*name)
@@ -458,7 +518,12 @@
 
 	inode = nd->dentry->d_inode;
 	if (current->link_count)
+#ifdef CONFIG_MOSIX_FS
+		lookup_flags = LOOKUP_FOLLOW |
+			(nd->flags & (LOOKUP_MFS|LOOKUP_MFS_MFS));
+#else
 		lookup_flags = LOOKUP_FOLLOW;
+#endif /* CONFIG_MOSIX_FS */
 
 	/* At this point we know we have a real path component. */
 	for(;;) {
@@ -466,6 +531,47 @@
 		struct qstr this;
 		unsigned int c;
 
+#ifdef CONFIG_MOSIX_FS
+		/* have we consumed the whole link and can continue
+		 * with the original name?
+		 */
+		if(orig_part && name >= orig_part)
+		{
+			name = orig_ref + (name - orig_part);
+			orig_part = orig_ref = NULL;
+			if(free_me)
+			{
+				kfree(free_me);
+				free_me = NULL;
+			}
+			flattings = 0;	/* real progress made */
+			nd->flags &= ~LOOKUP_MFS_MFS;
+		}
+		if(inode->i_op->express_lookup)
+		{
+			if(current->link_count)
+			/* flatten the path by passing it back to top-level,
+			 * so all is included in the same express_lookup */
+			{
+				if(!(nd->name_left =
+					kmalloc(strlen(name)+1, GFP_KERNEL)))
+				{
+					err = -ENOMEM;
+					break;
+				}
+				strcpy(nd->name_left, name);
+				return(0);
+			}
+			err = inode->i_op->express_lookup(nd, (char **)&name);
+			if(IS_ERR((const void *)err))
+				break;
+			if(!name)
+				goto return_err; /*trick: err can be positive*/
+			inode = nd->dentry->d_inode;
+			continue;
+		}
+#endif /* CONFIG_MOSIX_FS */
+
 		err = permission(inode, MAY_EXEC);
 		dentry = ERR_PTR(err);
  		if (err)
@@ -501,7 +607,25 @@
 			case 2:	
 				if (this.name[1] != '.')
 					break;
+#ifdef CONFIG_MOSIX_FS
+				if((nd->flags & LOOKUP_MFS) &&
+					!current->link_count && !orig_ref &&
+					is_mfs_root(nd))
+				{
+					nd->name_left = (char *)name;
+					path_release(nd);
+					goto return_base;
+				}
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+				if(nd->flags & LOOKUP_STAYFS)
+					prevmnt = mntget(nd->mnt);
+#endif /* CONFIG_MOSIX_DFSA */
 				follow_dotdot(nd);
+#ifdef CONFIG_MOSIX_DFSA
+				if((err = dfsa_crossed(nd, prevmnt)))
+					break;
+#endif /* CONFIG_MOSIX_DFSA */
 				inode = nd->dentry->d_inode;
 				/* fallthrough */
 			case 1:
@@ -525,8 +649,16 @@
 				break;
 		}
 		/* Check mountpoints.. */
+#ifdef CONFIG_MOSIX_DFSA
+		if(nd->flags & LOOKUP_STAYFS)
+			prevmnt = mntget(nd->mnt);
+#endif /* CONFIG_MOSIX_DFSA */
 		while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry))
 			;
+#ifdef CONFIG_MOSIX_DFSA
+		if((err = dfsa_crossed(nd, prevmnt)))
+			break;
+#endif /* CONFIG_MOSIX_DFSA */
 
 		err = -ENOENT;
 		inode = dentry->d_inode;
@@ -543,6 +675,43 @@
 				goto return_err;
 			err = -ENOENT;
 			inode = nd->dentry->d_inode;
+#ifdef CONFIG_MOSIX_FS
+			if(nd->name_left)
+			{
+				int l = strlen(nd->name_left);
+
+				err = -ELOOP;
+				if(flattings++ > 8)
+				{
+					kfree(nd->name_left);
+					nd->name_left = NULL;
+					break;
+				}
+				err = -ENOMEM;
+				if(!(tmpname = kmalloc(l + strlen(name) + 2,
+								GFP_KERNEL)))
+				{
+					kfree(nd->name_left);
+					nd->name_left = NULL;
+					break;
+				}
+				sprintf(tmpname, "%s/%s", nd->name_left, name);
+				kfree(nd->name_left);
+				if(current->link_count)
+				{
+					nd->name_left = tmpname;
+					return(0);
+				}
+				if(free_me)
+					kfree(free_me);
+				free_me = tmpname;
+				nd->name_left = NULL;
+				orig_part = tmpname + l + 1;
+				orig_ref = (char *)name;
+				name = tmpname;
+				continue;
+			}
+#endif /* CONFIG_MOSIX_FS */
 			if (!inode)
 				break;
 			err = -ENOTDIR; 
@@ -553,8 +722,19 @@
 			nd->dentry = dentry;
 		}
 		err = -ENOTDIR; 
+#ifdef CONFIG_MOSIX_FS
+		if (!inode->i_op->express_lookup)
+#endif /* CONFIG_MOSIX_FS */
 		if (!inode->i_op->lookup)
 			break;
+#ifdef CONFIG_MOSIX_FS
+		if(lookup_flags & LOOKUP_MFS)
+		{
+			err = -EACCES;
+			if(unacceptable_mfs_fs(nd->mnt->mnt_sb->s_magic))
+				break;
+		}
+#endif /* CONFIG_MOSIX_FS */
 		continue;
 		/* here ends the main loop */
 
@@ -569,7 +749,25 @@
 			case 2:	
 				if (this.name[1] != '.')
 					break;
+#ifdef CONFIG_MOSIX_FS
+				if((nd->flags & LOOKUP_MFS) &&
+					!current->link_count && !orig_ref &&
+					is_mfs_root(nd))
+				{
+					nd->name_left = (char *)name;
+					path_release(nd);
+					goto return_base;
+				}
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+				if(nd->flags & LOOKUP_STAYFS)
+					prevmnt = mntget(nd->mnt);
+#endif /* CONFIG_MOSIX_DFSA */
 				follow_dotdot(nd);
+#ifdef CONFIG_MOSIX_DFSA
+				if((err = dfsa_crossed(nd, prevmnt)))
+					break;
+#endif /* CONFIG_MOSIX_DFSA */
 				inode = nd->dentry->d_inode;
 				/* fallthrough */
 			case 1:
@@ -587,8 +785,16 @@
 			if (IS_ERR(dentry))
 				break;
 		}
+#ifdef CONFIG_MOSIX_DFSA
+		if(nd->flags & LOOKUP_STAYFS)
+			prevmnt = mntget(nd->mnt);
+#endif /* CONFIG_MOSIX_DFSA */
 		while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry))
 			;
+#ifdef CONFIG_MOSIX_DFSA
+		if((err = dfsa_crossed(nd, prevmnt)))
+			break;
+#endif /* CONFIG_MOSIX_DFSA */
 		inode = dentry->d_inode;
 		if ((lookup_flags & LOOKUP_FOLLOW)
 		    && inode && inode->i_op && inode->i_op->follow_link) {
@@ -597,6 +803,29 @@
 			if (err)
 				goto return_err;
 			inode = nd->dentry->d_inode;
+#ifdef CONFIG_MOSIX_FS
+			if(nd->name_left)
+			{
+				err = -ELOOP;
+				if(flattings++ > 8)
+				{
+					kfree(nd->name_left);
+					nd->name_left = NULL;
+					break;
+				}
+				err = -ENOMEM;
+				if(free_me)
+					kfree(free_me);
+				if(current->link_count)
+					return(0);
+				orig_ref = (char *)name;
+				name = free_me = nd->name_left;
+				nd->name_left = NULL;
+				lookup_flags = nd->flags;
+				orig_part = NULL;
+				continue;
+			}
+#endif /* CONFIG_MOSIX_FS */
 		} else {
 			dput(nd->dentry);
 			nd->dentry = dentry;
@@ -606,9 +835,26 @@
 			goto no_inode;
 		if (lookup_flags & LOOKUP_DIRECTORY) {
 			err = -ENOTDIR; 
+#ifdef CONFIG_MOSIX_FS
+			if (!inode->i_op || (!inode->i_op->lookup &&
+						!inode->i_op->express_lookup))
+#else
 			if (!inode->i_op || !inode->i_op->lookup)
+#endif /* CONFIG_MOSIX_FS */
 				break;
 		}
+#ifdef CONFIG_MOSIX_FS
+		if(lookup_flags & LOOKUP_MFS)
+		{
+			umode_t mod = inode->i_mode & S_IFMT;
+
+			err = -EACCES;
+			if(mod != S_IFREG && mod != S_IFDIR && mod != S_IFLNK)
+				break;
+			if(unacceptable_mfs_fs(nd->mnt->mnt_sb->s_magic))
+				break;
+		}
+#endif /* CONFIG_MOSIX_FS */
 		goto return_base;
 no_inode:
 		err = -ENOENT;
@@ -625,6 +871,10 @@
 		else if (this.len == 2 && this.name[1] == '.')
 			nd->last_type = LAST_DOTDOT;
 return_base:
+#ifdef CONFIG_MOSIX_FS
+		if(free_me)
+			kfree(free_me);
+#endif /* CONFIG_MOSIX_FS */
 		return 0;
 out_dput:
 		dput(dentry);
@@ -632,6 +882,10 @@
 	}
 	path_release(nd);
 return_err:
+#ifdef CONFIG_MOSIX_FS
+	if(free_me)
+		kfree(free_me);
+#endif /* CONFIG_MOSIX_FS */
 	return err;
 }
 
@@ -701,12 +955,53 @@
 		dput(olddentry);
 		mntput(oldmnt);
 	}
+#ifdef CONFIG_MOSIX_DFSA
+	tell_process(current, DREQ_NOTUPTODATE);
+#endif /* CONFIG_MOSIX_DFSA */
 }
 
 /* SMP-safe */
 static inline int
 walk_init_root(const char *name, struct nameidata *nd)
 {
+#ifdef CONFIG_MOSIX_DFSA
+	if(nd->flags & LOOKUP_STAYFS)
+	{
+		struct task_struct *p = current;
+
+		if(current->fs->altroot)
+		{
+			p->mosix.dflags &= ~DSTATSDOWN;
+			nd->flags &= ~LOOKUP_STAYFS;
+		}
+		else if(p->mosix.dflags & DDEPUTY)
+			nd->flags &= ~LOOKUP_STAYFS;
+		else if(((p->mosix.dflags & DREMOTE) || CAN_DFSA(p)) &&
+			name_starts_in_dfsa((char **)&name, nd))
+		{
+			if(!(p->mosix.dflags & DREMOTE) && !p->link_count)
+				p->mosix.dflags |= DSTATSDOWN;
+			if(!*name)
+				return(0);
+			nd->flags |= LOOKUP_REPLACENAME;
+			nd->replaced_name = (char *)name;
+			return(1);
+		}
+		else if(p->mosix.dflags & DREMOTE)
+		{
+			nd->flags |= LOOKUP_DOITATHOME;
+			nd->mnt = NULL;
+			nd->dentry = NULL;
+			return(1);
+		}
+		else
+			p->mosix.dflags &= ~DSTATSDOWN;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	if(nd->flags & LOOKUP_MFS)
+		return(mfs_walk_init_root(nd));
+#endif /* CONFIG_MOSIX_FS */
 	read_lock(&current->fs->lock);
 	if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
 		nd->mnt = mntget(current->fs->altrootmnt);
@@ -727,12 +1022,48 @@
 {
 	nd->last_type = LAST_ROOT; /* if there are only slashes... */
 	nd->flags = flags;
+#ifdef CONFIG_MOSIX_FS
+	nd->name_left = NULL;
+	nd->complete_flags = 0;
+#ifdef CONFIG_MOSIX_DIAG
+	if(flags & LOOKUP_MFS)
+		panic("MFS should have own path_init!");
+#endif /* CONFIG_MOSIX_DIAG */
+#endif /* CONFIG_MOSIX_FS */
 	if (*name=='/')
 		return walk_init_root(name,nd);
 	read_lock(&current->fs->lock);
 	nd->mnt = mntget(current->fs->pwdmnt);
 	nd->dentry = dget(current->fs->pwd);
 	read_unlock(&current->fs->lock);
+#ifdef CONFIG_MOSIX_DFSA
+	if(!nd->dentry)	/* possible on REMOTE! */
+	{
+		nd->flags |= LOOKUP_DOITATHOME;
+		return(1);
+	}
+
+	if(nd->flags & LOOKUP_STAYFS)
+	{
+		struct task_struct *p = current;
+
+		if(p->mosix.dflags & DDEPUTY)
+			nd->flags &= ~LOOKUP_STAYFS;
+		else if(((p->mosix.dflags & DREMOTE) || CAN_DFSA(p)) &&
+								within_dfsa(nd))
+		{
+			if(!(p->mosix.dflags & DREMOTE))
+				p->mosix.dflags |= DSTATSDOWN;
+		}
+		else
+		{
+			if(p->mosix.dflags & DREMOTE)
+				nd->flags |= LOOKUP_DOITATHOME;
+			else
+				p->mosix.dflags &= ~DSTATSDOWN;
+		}
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	return 1;
 }
 
@@ -832,6 +1163,10 @@
 			err = path_walk(tmp, nd);
 		putname(tmp);
 	}
+#ifdef CONFIG_MOSIX_FS
+	else
+		nd->complete_flags = 0;
+#endif /* CONFIG_MOSIX_FS */
 	return err;
 }
 
@@ -898,7 +1233,11 @@
  *  3. We should have write and exec permissions on dir
  *  4. We can't do it if dir is immutable (done in permission())
  */
+#ifdef CONFIG_MOSIX_FS
+inline int may_create(struct inode *dir, struct dentry *child) {
+#else
 static inline int may_create(struct inode *dir, struct dentry *child) {
+#endif /* CONFIG_MOSIX_FS */
 	if (child->d_inode)
 		return -EEXIST;
 	if (IS_DEADDIR(dir))
@@ -976,17 +1315,46 @@
 	struct dentry *dentry;
 	struct dentry *dir;
 	int count = 0;
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	unsigned int more_flags = 0;
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 
 	acc_mode = ACC_MODE(flag);
+#ifdef CONFIG_MOSIX_FS
+	if(!pathname)	/* special argument to skip path-search */
+	{
+		if(flag & O_CREAT)
+			goto low_create;
+		else
+			goto low_nocreate;
+	}
+	nd->express_function = EF_OPEN;
+	nd->complete_args.ints.i1 = flag;
+	nd->complete_args.ints.i2 = mode & ~current->fs->umask;
+	more_flags |= LOOKUP_COMPLETE;
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+	if(current->mosix.dirty_bits & FILP_OPEN_SYSCALL)
+		more_flags |= LOOKUP_STAYFS;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	/*
 	 * The simplest case - just a plain lookup.
 	 */
 	if (!(flag & O_CREAT)) {
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+		if (path_init(pathname, lookup_flags(flag)|more_flags, nd))
+#else
 		if (path_init(pathname, lookup_flags(flag), nd))
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 			error = path_walk(pathname, nd);
 		if (error)
 			return error;
+#ifdef CONFIG_MOSIX_FS
+		if(nd->complete_flags & COMPLETE_DONE)
+			return(0);
+		low_nocreate:
+#endif /* CONFIG_MOSIX_FS */
 		dentry = nd->dentry;
 		goto ok;
 	}
@@ -994,10 +1362,19 @@
 	/*
 	 * Create - we need to know the parent.
 	 */
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	if (path_init(pathname, LOOKUP_PARENT|more_flags, nd))
+#else
 	if (path_init(pathname, LOOKUP_PARENT, nd))
+#endif /* CONFIG_MOSIX_FS */
 		error = path_walk(pathname, nd);
 	if (error)
 		return error;
+#ifdef CONFIG_MOSIX_FS
+	if(nd->complete_flags & COMPLETE_DONE)
+		return(0);
+	low_create:
+#endif /* CONFIG_MOSIX_FS */
 
 	/*
 	 * We have the parent and last component. First of all, check
@@ -1186,7 +1563,11 @@
 }
 
 /* SMP-safe */
+#ifdef CONFIG_MOSIX_FS
+struct dentry *lookup_create(struct nameidata *nd, int is_dir)
+#else
 static struct dentry *lookup_create(struct nameidata *nd, int is_dir)
+#endif /* CONFIG_MOSIX_FS */
 {
 	struct dentry *dentry;
 
@@ -1247,8 +1628,18 @@
 	if (IS_ERR(tmp))
 		return PTR_ERR(tmp);
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_MKNOD;
+	nd.complete_args.ints.i1 = mode & ~current->fs->umask;
+	if (path_init(tmp, LOOKUP_COMPLETE|LOOKUP_PARENT, &nd))
+#else
 	if (path_init(tmp, LOOKUP_PARENT, &nd))
+#endif /* CONFIG_MOSIX_FS */
 		error = path_walk(tmp, &nd);
+#ifdef CONFIG_MOSIX_FS
+	if(nd.complete_flags & COMPLETE_DONE)
+		goto out;
+#endif /* CONFIG_MOSIX_FS */
 	if (error)
 		goto out;
 	dentry = lookup_create(&nd, 0);
@@ -1316,10 +1707,25 @@
 		struct dentry *dentry;
 		struct nameidata nd;
 
+#ifdef CONFIG_MOSIX_FS
+		nd.express_function = EF_MKDIR;
+		nd.complete_args.ints.i1 = mode & ~current->fs->umask;
+		if (path_init(tmp, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS,
+									&nd))
+#else
+#ifdef CONFIG_MOSIX_DFSA
+		if (path_init(tmp, LOOKUP_PARENT|LOOKUP_STAYFS, &nd))
+#else
 		if (path_init(tmp, LOOKUP_PARENT, &nd))
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 			error = path_walk(tmp, &nd);
 		if (error)
 			goto out;
+#ifdef CONFIG_MOSIX_FS
+		if(nd.complete_flags & COMPLETE_DONE)
+			goto out;
+#endif /* CONFIG_MOSIX_FS */
 		dentry = lookup_create(&nd, 1);
 		error = PTR_ERR(dentry);
 		if (!IS_ERR(dentry)) {
@@ -1411,10 +1817,23 @@
 	if(IS_ERR(name))
 		return PTR_ERR(name);
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_RMDIR;
+	if (path_init(name, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS, &nd))
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	if (path_init(name, LOOKUP_PARENT|LOOKUP_STAYFS, &nd))
+#else
 	if (path_init(name, LOOKUP_PARENT, &nd))
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 		error = path_walk(name, &nd);
 	if (error)
 		goto exit;
+#ifdef CONFIG_MOSIX_FS
+	if(nd.complete_flags & COMPLETE_DONE)
+		goto exit;
+#endif /* CONFIG_MOSIX_FS */
 
 	switch(nd.last_type) {
 		case LAST_DOTDOT:
@@ -1480,10 +1899,23 @@
 	if(IS_ERR(name))
 		return PTR_ERR(name);
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_UNLINK;
+	if (path_init(name, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS, &nd))
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	if (path_init(name, LOOKUP_PARENT|LOOKUP_STAYFS, &nd))
+#else
 	if (path_init(name, LOOKUP_PARENT, &nd))
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 		error = path_walk(name, &nd);
 	if (error)
 		goto exit;
+#ifdef CONFIG_MOSIX_FS
+	if(nd.complete_flags & COMPLETE_DONE)
+		goto exit;
+#endif /* CONFIG_MOSIX_FS */
 	error = -EISDIR;
 	if (nd.last_type != LAST_NORM)
 		goto exit1;
@@ -1552,10 +1984,25 @@
 		struct dentry *dentry;
 		struct nameidata nd;
 
+#ifdef CONFIG_MOSIX_FS
+		nd.express_function = EF_SYMLINK;
+		nd.complete_parg = from;
+		if (path_init(to, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS,
+									&nd))
+#else
+#ifdef CONFIG_MOSIX_DFSA
+		if (path_init(to, LOOKUP_PARENT|LOOKUP_STAYFS, &nd))
+#else
 		if (path_init(to, LOOKUP_PARENT, &nd))
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 			error = path_walk(to, &nd);
 		if (error)
 			goto out;
+#ifdef CONFIG_MOSIX_FS
+		if(nd.complete_flags & COMPLETE_DONE)
+			goto out;
+#endif /* CONFIG_MOSIX_FS */
 		dentry = lookup_create(&nd, 0);
 		error = PTR_ERR(dentry);
 		if (!IS_ERR(dentry)) {
@@ -1634,16 +2081,40 @@
 	if (!IS_ERR(to)) {
 		struct dentry *new_dentry;
 		struct nameidata nd, old_nd;
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+		unsigned int more_flags = 0;
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 
 		error = 0;
+#ifdef CONFIG_MOSIX_DFSA
+		if (path_init(from, LOOKUP_POSITIVE|LOOKUP_STAYFS, &old_nd))
+#else
 		if (path_init(from, LOOKUP_POSITIVE, &old_nd))
+#endif /* CONFIG_MOSIX_DFSA */
 			error = path_walk(from, &old_nd);
 		if (error)
 			goto exit;
+#ifdef CONFIG_MOSIX_DFSA
+		if(current->mosix.dflags & (DREMOTE|DSTATSDOWN))
+			more_flags |= LOOKUP_STAYFS;
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+		nd.express_function = EF_LINK;
+		nd.complete_args.oldnd = &old_nd;
+		more_flags |= LOOKUP_COMPLETE;
+#endif /* CONFIG_MOSIX_FS */
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+		if (path_init(to, LOOKUP_PARENT|more_flags, &nd))
+#else
 		if (path_init(to, LOOKUP_PARENT, &nd))
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 			error = path_walk(to, &nd);
 		if (error)
 			goto out;
+#ifdef CONFIG_MOSIX_FS
+		if(nd.complete_flags & COMPLETE_DONE)
+			goto out;
+#endif /* CONFIG_MOSIX_FS */
 		error = -EXDEV;
 		if (old_nd.mnt != nd.mnt)
 			goto out_release;
@@ -1840,15 +2311,39 @@
 	struct dentry * old_dir, * new_dir;
 	struct dentry * old_dentry, *new_dentry;
 	struct nameidata oldnd, newnd;
-
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	unsigned int more_flags = 0;
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
+
+#ifdef CONFIG_MOSIX_DFSA
+	if (path_init(oldname, LOOKUP_PARENT|LOOKUP_STAYFS, &oldnd))
+#else
 	if (path_init(oldname, LOOKUP_PARENT, &oldnd))
+#endif /* CONFIG_MOSIX_DFSA */
 		error = path_walk(oldname, &oldnd);
 
 	if (error)
 		goto exit;
 
+#ifdef CONFIG_MOSIX_DFSA
+	if(current->mosix.dflags & (DREMOTE|DSTATSDOWN))
+		more_flags |= LOOKUP_STAYFS;
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	newnd.express_function = EF_RENAME;
+	newnd.complete_args.oldnd = &oldnd;
+	more_flags |= LOOKUP_COMPLETE;
+#endif /* CONFIG_MOSIX_FS */
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	if (path_init(newname, LOOKUP_PARENT|more_flags, &newnd))
+#else
 	if (path_init(newname, LOOKUP_PARENT, &newnd))
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 		error = path_walk(newname, &newnd);
+#ifdef CONFIG_MOSIX_FS
+	if(newnd.complete_flags & COMPLETE_DONE)
+		goto exit1;
+#endif /* CONFIG_MOSIX_FS */
 	if (error)
 		goto exit1;
 
@@ -1955,8 +2450,16 @@
 		if (!walk_init_root(link, nd))
 			/* weird __emul_prefix() stuff did it */
 			goto out;
+#ifdef CONFIG_MOSIX_FS
+		if(nd->flags & LOOKUP_MFS)
+			nd->flags |= LOOKUP_MFS_MFS;
+#endif /* CONFIG_MOSIX_FS */
 	}
 	res = link_path_walk(link, nd);
+#ifdef CONFIG_MOSIX_FS
+	if(!nd->name_left)
+		nd->flags &= ~LOOKUP_MFS_MFS;
+#endif /* CONFIG_MOSIX_FS */
 out:
 	if (current->link_count || res || nd->last_type!=LAST_NORM)
 		return res;
diff -ruN linux-2.4.16/fs/namespace.c linux-2.4.16-mosix/fs/namespace.c
--- linux-2.4.16/fs/namespace.c	Sun Nov 11 21:23:14 2001
+++ linux-2.4.16-mosix/fs/namespace.c	Sun Dec 23 14:58:53 2001
@@ -24,13 +24,24 @@
 #include <linux/nfs_mount.h>
 #include <linux/seq_file.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/file.h>
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
 struct vfsmount *do_kern_mount(char *type, int flags, char *name, void *data);
 int do_remount_sb(struct super_block *sb, int flags, void * data);
 void kill_super(struct super_block *sb);
 
 static struct list_head *mount_hashtable;
 static int hash_mask, hash_bits;
-static kmem_cache_t *mnt_cache; 
+static kmem_cache_t *mnt_cache;
 
 static LIST_HEAD(vfsmntlist);
 static DECLARE_MUTEX(mount_sem);
@@ -48,7 +59,7 @@
 
 struct vfsmount *alloc_vfsmnt(void)
 {
-	struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL); 
+	struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL);
 	if (mnt) {
 		memset(mnt, 0, sizeof(struct vfsmount));
 		atomic_set(&mnt->mnt_count,1);
@@ -237,6 +248,10 @@
 	}
 	seq_puts(m, ",addr=");
 	mangle(m, nfss->hostname);
+#ifdef CONFIG_MOSIX_DFSA
+	if (mnt->mnt_dfsa)
+		seq_printf(m, ",dfsa=%d", mnt->mnt_dfsa);
+#endif /* CONFIG_MOSIX_DFSA */
 }
 
 static int show_vfsmnt(struct seq_file *m, void *v)
@@ -376,7 +391,16 @@
 		return retval;
 	}
 
+#ifdef CONFIG_MOSIX_DFSA
+	down_half_interruptible(&mount_sem);
+	if((retval = dfsa_setmnt(mnt, 0, 0)))
+	{
+		up(&mount_sem);
+		return(retval);
+	}
+#else
 	down(&mount_sem);
+#endif /* CONFIG_MOSIX_DFSA */
 	spin_lock(&dcache_lock);
 
 	if (atomic_read(&sb->s_active) == 1) {
@@ -441,9 +465,9 @@
 }
 
 /*
- *	The 2.0 compatible umount. No flags. 
+ *	The 2.0 compatible umount. No flags.
  */
- 
+
 asmlinkage long sys_oldumount(char * name)
 {
 	return sys_umount(name,0);
@@ -553,7 +577,11 @@
 	if (err)
 		return err;
 
+#ifdef CONFIG_MOSIX
+	down_half_interruptible(&mount_sem);
+#else
 	down(&mount_sem);
+#endif /* CONFIG_MOSIX */
 	err = -EINVAL;
 	if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
 		err = -ENOMEM;
@@ -586,6 +614,9 @@
 {
 	int err;
 	struct super_block * sb = nd->mnt->mnt_sb;
+#ifdef CONFIG_MOSIX_DFSA
+	int odfsa = 0, new_dfsa, cng_dfsa;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -596,11 +627,33 @@
 	if (nd->dentry != nd->mnt->mnt_root)
 		return -EINVAL;
 
+#ifdef CONFIG_MOSIX_DFSA
+	if((cng_dfsa = dfsa_option(data, &new_dfsa)))
+	{
+		down_half_interruptible(&mount_sem);
+		odfsa = nd->mnt->mnt_dfsa;
+		nd->mnt->mnt_dfsa = new_dfsa;
+		err = dfsa_setmnt(nd->mnt, new_dfsa, flags);
+		up(&mount_sem);
+		if(err)
+			return(err);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	down_write(&sb->s_umount);
 	err = do_remount_sb(sb, flags, data);
 	if (!err)
 		nd->mnt->mnt_flags=mnt_flags;
 	up_write(&sb->s_umount);
+#ifdef CONFIG_MOSIX_DFSA
+	if(err && cng_dfsa)
+	{
+		/* undo - unless someone else played with mount meanwhile */
+		down_half_interruptible(&mount_sem);
+		if(nd->mnt->mnt_dfsa == new_dfsa)
+			dfsa_setmnt(nd->mnt, odfsa, nd->mnt->mnt_sb->s_flags);
+		up(&mount_sem);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
 	return err;
 }
 
@@ -613,7 +666,11 @@
 	if (IS_ERR(mnt))
 		goto out;
 
+#ifdef CONFIG_MOSIX_DFSA
+	down_half_interruptible(&mount_sem);
+#else
 	down(&mount_sem);
+#endif /* CONFIG_MOSIX_DFSA */
 	/* Something was mounted here while we slept */
 	while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
 		;
@@ -640,7 +697,7 @@
 	int i;
 	unsigned long page;
 	unsigned long size;
-	
+
 	*where = 0;
 	if (!data)
 		return 0;
@@ -659,7 +716,7 @@
 
 	i = size - copy_from_user((void *)page, data, size);
 	if (!i) {
-		free_page(page); 
+		free_page(page);
 		return -EFAULT;
 	}
 	if (i != PAGE_SIZE)
@@ -688,6 +745,9 @@
 	struct nameidata nd;
 	int retval = 0;
 	int mnt_flags = 0;
+#ifdef CONFIG_MOSIX_DFSA
+	int dfsa_opt;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	/* Discard magic */
 	if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
@@ -723,6 +783,22 @@
 	else
 		retval = do_add_mount(&nd, type_page, flags, mnt_flags,
 				      dev_name, data_page);
+#ifdef CONFIG_MOSIX_DFSA
+	down_half_interruptible(&mount_sem);
+	if(!retval && dfsa_option((char *)data_page, &dfsa_opt) &&
+		d_mountpoint(nd.dentry) && follow_down(&nd.mnt, &nd.dentry)
+		&& (nd.mnt->mnt_dfsa = dfsa_opt) &&
+			dfsa_setmnt(nd.mnt, dfsa_opt, flags))
+	{
+		/* too late to undo the mount - all we can do is complain: */
+		nd.mnt->mnt_dfsa = 0;
+		printk("Mount succeeded, but DFSA option failed: "
+			"if you can fix the problem, run:\n");
+		printk("'mount -o remount,dfsa=%d %s %s'\n", dfsa_opt,
+			dev_name, dir_name);
+	}
+	up(&mount_sem);
+#endif /* CONFIG_MOSIX_DFSA */
 	path_release(&nd);
 	return retval;
 }
@@ -774,7 +850,12 @@
 	struct fs_struct *fs;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	/* DFSA is disabled, so no REMOTE roots (and no cwd's away) */
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		task_lock(p);
 		fs = p->fs;
 		if (fs) {
@@ -791,6 +872,32 @@
 	read_unlock(&tasklist_lock);
 }
 
+#ifdef CONFIG_MOSIX_DFSA
+void
+restore_dfsa_mounts(void)
+{
+	struct list_head *p;
+	int told = 0;
+
+	for (p = vfsmntlist.next; p != &vfsmntlist; p = p->next)
+	{
+		struct vfsmount *tmp = list_entry(p, struct vfsmount, mnt_list);
+
+		if(tmp->mnt_dfsa &&
+			dfsa_setmnt(tmp, tmp->mnt_dfsa, tmp->mnt_sb->s_flags))
+		{
+			if(!told++)
+			printk("One or more partitions failed to restore DFSA"
+				" status after pivot_root.\n"
+				"If you can fix the problem, please remount "
+				"the affected partition(s) with the appropriate"
+				" dfsa= option\n");
+			tmp->mnt_dfsa = 0;
+		}
+	}
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * Moves the current root to put_root, and sets root/cwd of all processes
  * which had them on the old root to new_root.
@@ -814,6 +921,10 @@
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
+#ifdef CONFIG_MOSIX_DFSA
+	if((error = disable_dfsa()))
+		return(error);
+#endif /* CONFIG_MOSIX_DFSA */
 	lock_kernel();
 
 	name = getname(new_root);
@@ -845,7 +956,11 @@
 	user_nd.mnt = mntget(current->fs->rootmnt);
 	user_nd.dentry = dget(current->fs->root);
 	read_unlock(&current->fs->lock);
+#ifdef CONFIG_MOSIX_DFSA
+	down_half_interruptible(&mount_sem);
+#else
 	down(&mount_sem);
+#endif /* CONFIG_MOSIX_DFSA */
 	down(&old_nd.dentry->d_inode->i_zombie);
 	error = -EINVAL;
 	if (!check_mnt(user_nd.mnt))
@@ -857,6 +972,15 @@
 		goto out2;
 	if (d_unhashed(old_nd.dentry) && !IS_ROOT(old_nd.dentry))
 		goto out2;
+#ifdef CONFIG_MOSIX_FS
+	if(new_nd.dentry->d_inode->i_sb->s_magic == MFS_SUPER_MAGIC ||
+		old_nd.dentry->d_inode->i_sb->s_magic == MFS_SUPER_MAGIC)
+	{
+		/* MFS does not support mounts (which are otherwise ignored) */
+		error = -EINVAL;
+		goto out2;
+	}
+#endif /* CONFIG_MOSIX_FS */
 	error = -EBUSY;
 	if (new_nd.mnt == user_nd.mnt || old_nd.mnt == user_nd.mnt)
 		goto out2; /* loop */
@@ -884,6 +1008,9 @@
 	attach_mnt(user_nd.mnt, &old_nd);
 	attach_mnt(new_nd.mnt, &root_parent);
 	spin_unlock(&dcache_lock);
+#ifdef CONFIG_MOSIX_FS
+	mfs_change_root(user_nd.dentry, user_nd.mnt, new_nd.dentry, new_nd.mnt);
+#endif /* CONFIG_MOSIX_FS */
 	chroot_fs_refs(&user_nd, &new_nd);
 	error = 0;
 	path_release(&root_parent);
@@ -897,6 +1024,10 @@
 	path_release(&new_nd);
 out0:
 	unlock_kernel();
+#ifdef CONFIG_MOSIX_DFSA
+	enable_dfsa();
+	restore_dfsa_mounts();
+#endif /* CONFIG_MOSIX_DFSA */
 	return error;
 out3:
 	spin_unlock(&dcache_lock);
@@ -1042,7 +1173,7 @@
 	mount_root();
 #if 1
 	shrink_dcache();
-	printk("change_root: old root has d_count=%d\n", 
+	printk("change_root: old root has d_count=%d\n",
 	       atomic_read(&old_rootmnt->mnt_root->d_count));
 #endif
 	mount_devfs_fs ();
@@ -1074,7 +1205,7 @@
 		} else {
 			printk("okay\n");
 			error = 0;
-		}			
+		}
 		kfree(new_devname);
 		return error;
 	}
diff -ruN linux-2.4.16/fs/nfsd/auth.c linux-2.4.16-mosix/fs/nfsd/auth.c
--- linux-2.4.16/fs/nfsd/auth.c	Mon Jul 24 09:04:10 2000
+++ linux-2.4.16-mosix/fs/nfsd/auth.c	Sun Dec 23 13:56:53 2001
@@ -9,6 +9,9 @@
 #include <linux/sunrpc/svc.h>
 #include <linux/sunrpc/svcauth.h>
 #include <linux/nfsd/nfsd.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
 
 #define	CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
 void
@@ -20,6 +23,9 @@
 	if (rqstp->rq_userset)
 		return;
 
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	if (exp->ex_flags & NFSEXP_ALLSQUASH) {
 		cred->cr_uid = exp->ex_anon_uid;
 		cred->cr_gid = exp->ex_anon_gid;
diff -ruN linux-2.4.16/fs/nfsd/export.c linux-2.4.16-mosix/fs/nfsd/export.c
--- linux-2.4.16/fs/nfsd/export.c	Thu Oct  4 07:57:36 2001
+++ linux-2.4.16-mosix/fs/nfsd/export.c	Sun Dec 23 13:56:53 2001
@@ -463,6 +463,9 @@
 		return 0;
 	}
 
+#ifdef CONFIG_MOSIX
+	current->mosix.ignoreoldsigs = 1;
+#endif /* CONFIG_MOSIX */
 	current->sigpending = 0;
 	want_lock++;
 	while (hash_count || hash_lock) {
diff -ruN linux-2.4.16/fs/nfsd/vfs.c linux-2.4.16-mosix/fs/nfsd/vfs.c
--- linux-2.4.16/fs/nfsd/vfs.c	Fri Oct  5 21:23:53 2001
+++ linux-2.4.16-mosix/fs/nfsd/vfs.c	Sun Dec 23 13:56:53 2001
@@ -45,6 +45,10 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
 #define NFSDDBG_FACILITY		NFSDDBG_FILEOP
 #define NFSD_PARANOIA
 
@@ -108,6 +112,13 @@
 	dparent = fhp->fh_dentry;
 	exp  = fhp->fh_export;
 
+#ifdef CONFIG_MOSIX_FS
+	if(dparent->d_sb->s_magic == MFS_SUPER_MAGIC)
+	{
+		err = -EPERM;
+		goto out;
+	}
+#endif /* CONFIG_MOSIX_FS */
 	err = nfserr_acces;
 
 	/* Lookup the name, but don't follow links */
@@ -510,6 +521,9 @@
 		filp->f_op->release(inode, filp);
 	fops_put(filp->f_op);
 	if (filp->f_mode & FMODE_WRITE)
+#ifdef CONFIG_MOSIX
+	if (!(filp->f_flags & O_NOWRITEACCESS))
+#endif /* CONFIG_MOSIX */
 		put_write_access(inode);
 }
 
diff -ruN linux-2.4.16/fs/open.c linux-2.4.16-mosix/fs/open.c
--- linux-2.4.16/fs/open.c	Fri Oct 12 22:48:42 2001
+++ linux-2.4.16-mosix/fs/open.c	Sun Dec 23 13:56:53 2001
@@ -20,6 +20,12 @@
 
 #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#include <linux/mosix.h>
+#include <mos/debug.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 int vfs_statfs(struct super_block *sb, struct statfs *buf)
 {
 	int retval = -ENODEV;
@@ -99,7 +105,21 @@
 	if (length < 0)	/* sorry, but loff_t says... */
 		goto out;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_TRUNCATE;
+	nd.complete_args.len = length;
+	error = __user_walk(path, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS|
+							LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(path,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(path, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (error)
 		goto out;
 	inode = nd.dentry->d_inode;
@@ -165,6 +185,9 @@
 	error = -EINVAL;
 	if (length < 0)
 		goto out;
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -236,7 +259,21 @@
 	struct inode * inode;
 	struct iattr newattrs;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_UTIME;
+	nd.complete_parg = times;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (error)
 		goto out;
 	inode = nd.dentry->d_inode;
@@ -280,7 +317,21 @@
 	struct inode * inode;
 	struct iattr newattrs;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_UTIMES;
+	nd.complete_parg = utimes;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS| LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS , &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 
 	if (error)
 		goto out;
@@ -339,7 +390,22 @@
 	else
 		current->cap_effective = current->cap_permitted;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_ACCESS;
+	nd.complete_args.ints.i1 = mode;
+	res = __user_walk(filename,
+		LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_COMPLETE|LOOKUP_STAYFS,
+									&nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(res);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	res = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	res = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!res) {
 		res = permission(nd.dentry->d_inode, mode);
 		/* SuS v2 requires we report a read only fs too */
@@ -352,6 +418,11 @@
 	current->fsuid = old_fsuid;
 	current->fsgid = old_fsgid;
 	current->cap_effective = old_cap;
+#ifdef CONFIG_MOSIX_DFSA
+	/* a bit paranoid, for the rare case when we slept interruptibly
+	 * during "permission" and the temporary fs[ug]id passed across: */
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	return res;
 }
@@ -368,7 +439,12 @@
 		goto out;
 
 	error = 0;
+#ifdef CONFIG_MOSIX_DFSA
+	if (path_init(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY|
+							LOOKUP_STAYFS, &nd))
+#else
 	if (path_init(name,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd))
+#endif /* CONFIG_MOSIX_DFSA */
 		error = path_walk(name, &nd);
 	putname(name);
 	if (error)
@@ -394,6 +470,9 @@
 	struct vfsmount *mnt;
 	int error;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -459,6 +538,9 @@
 	int err = -EBADF;
 	struct iattr newattrs;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	file = fget(fd);
 	if (!file)
 		goto out;
@@ -491,7 +573,21 @@
 	int error;
 	struct iattr newattrs;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_CHMOD;
+	nd.complete_args.mode = mode;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (error)
 		goto out;
 	inode = nd.dentry->d_inode;
@@ -516,7 +612,11 @@
 	return error;
 }
 
+#ifdef CONFIG_MOSIX_FS
+int chown_common(struct dentry * dentry, uid_t user, gid_t group)
+#else
 static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
+#endif /* CONFIG_MOSIX_FS */
 {
 	struct inode * inode;
 	int error;
@@ -581,7 +681,22 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_CHOWN;
+	nd.complete_args.ids.uid = user;
+	nd.complete_args.ids.gid = group;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = chown_common(nd.dentry, user, group);
 		path_release(&nd);
@@ -594,7 +709,21 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_CHOWN;
+	nd.complete_args.ids.uid = user;
+	nd.complete_args.ids.gid = group;
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk_link(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = chown_common(nd.dentry, user, group);
 		path_release(&nd);
@@ -608,6 +737,9 @@
 	struct file * file;
 	int error = -EBADF;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	file = fget(fd);
 	if (file) {
 		error = chown_common(file->f_dentry, user, group);
@@ -634,6 +766,9 @@
 {
 	int namei_flags, error;
 	struct nameidata nd;
+#ifdef CONFIG_MOSIX_FS
+	int old_magic = current->mosix.lastmagic;
+#endif /* CONFIG_MOSIX_FS */
 
 	namei_flags = flags;
 	if ((namei_flags+1) & O_ACCMODE)
@@ -641,9 +776,31 @@
 	if (namei_flags & O_TRUNC)
 		namei_flags |= 2;
 
+#ifdef CONFIG_MOSIX_FS
+	if(flags & O_CREAT)
+		current->mosix.lastmagic = current->mosix.whereami ? : PE;
+#endif /* CONFIG_MOSIX_FS */
 	error = open_namei(filename, namei_flags, mode, &nd);
+#ifdef CONFIG_MOSIX_FS
+	if(!(nd.complete_flags & COMPLETE_MAGICAL))
+		current->mosix.lastmagic = old_magic;
+#endif /* CONFIG_MOSIX_FS */
 	if (!error)
+#ifdef CONFIG_MOSIX_FS
+	{
+		struct file *newf = dentry_open(nd.dentry, nd.mnt, flags);
+
+		if(IS_ERR(newf))
+			current->mosix.lastmagic = old_magic;
+#ifdef CONFIG_MOSIX_DFSA
+		else if(current->mosix.lastmagic != old_magic)
+			current->mosix.dupdates |= DFSA_UPDSEL;
+#endif /* CONFIG_MOSIX_DFSA */
+		return(newf);
+	}
+#else
 		return dentry_open(nd.dentry, nd.mnt, flags);
+#endif /* CONFIG_MOSIX_FS */
 
 	return ERR_PTR(error);
 }
@@ -735,6 +892,11 @@
 
 	/* Do we need to expand the fdset array? */
 	if (fd >= files->max_fdset) {
+#ifdef CONFIG_MOSIX_DFSA
+		if(current->mosix.dflags & DREMOTE)
+			error = -EDOITATHOME;
+		else
+#endif /* CONFIG_MOSIX_DFSA */
 		error = expand_fdset(files, fd);
 		if (!error) {
 			error = -EMFILE;
@@ -747,6 +909,11 @@
 	 * Check whether we need to expand the fd array.
 	 */
 	if (fd >= files->max_fds) {
+#ifdef CONFIG_MOSIX_DFSA
+		if(current->mosix.dflags & DREMOTE)
+			error = -EDOITATHOME;
+		else
+#endif /* CONFIG_MOSIX_DFSA */
 		error = expand_fd_array(files, fd);
 		if (!error) {
 			error = -EMFILE;
@@ -785,10 +952,46 @@
 	if (!IS_ERR(tmp)) {
 		fd = get_unused_fd();
 		if (fd >= 0) {
+#ifdef CONFIG_MOSIX_DFSA
+			struct file * f;
+			mode_t imode;
+
+			current->mosix.dirty_bits |= FILP_OPEN_SYSCALL;
+			f = filp_open(tmp, flags, mode);
+			current->mosix.dirty_bits &= ~FILP_OPEN_SYSCALL;
+#else
 			struct file *f = filp_open(tmp, flags, mode);
+#endif /* CONFIG_MOSIX_DFSA */
 			error = PTR_ERR(f);
 			if (IS_ERR(f))
 				goto out_error;
+#ifdef CONFIG_MOSIX_DFSA
+			imode = f->f_dentry->d_inode->i_mode;
+			if(!S_ISREG(imode) && !S_ISDIR(imode))
+			{
+				if(current->mosix.dflags & DREMOTE)
+				{
+#ifdef CONFIG_MOSIX_DEBUG
+					if(ds_debug & DSDEB_DFSA)
+					printk("%d(%s)-File <%s> Did not open, "
+						"mode=%d\n", current->pid,
+						current->comm, tmp, imode);
+#endif /* CONFIG_MOSIX_DEBUG */
+					filp_close(f, NULL);
+					error = -EDOITATHOME;
+					goto out_error;
+				}
+				current->mosix.dflags &= ~DSTATSDOWN;
+			}
+#ifdef CONFIG_MOSIX_DEBUG
+			if((current->mosix.dflags & DREMOTE) &&
+							(ds_debug & DSDEB_DFSA))
+				printk("%d(%s)-Opened <%s> Remotely, fd=%d, "
+					"ino=%ld\n", current->pid,
+					current->comm, tmp, (int)fd,
+					f->f_dentry->d_inode->i_ino);
+#endif /* CONFIG_MOSIX_DEBUG */
+#endif /* CONFIG_MOSIX_DFSA */
 			fd_install(fd, f);
 		}
 out:
@@ -799,6 +1002,10 @@
 out_error:
 	put_unused_fd(fd);
 	fd = error;
+#ifdef CONFIG_MOSIX_DFSA
+	if(error == -ETXTBSY && (current->mosix.dflags & DREMOTE))
+		error = -EDOITATHOME;
+#endif /* CONFIG_MOSIX_DFSA */
 	goto out;
 }
 
@@ -859,6 +1066,9 @@
 	FD_CLR(fd, files->close_on_exec);
 	__put_unused_fd(files, fd);
 	write_unlock(&files->file_lock);
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_close_file(fd);
+#endif /* CONFIG_MOSIX_DFSA */
 	return filp_close(filp, files);
 
 out_unlock:
@@ -866,6 +1076,35 @@
 	return -EBADF;
 }
 
+#ifdef CONFIG_MOSIX_DFSA
+/*
+ * almost like "sys_close", except for raising DSTATSDOWN in the right
+ * circumstances, which we cannot do this in "sys_close" itself only
+ * because it can be called from other system-calls.
+ * [wish they all called "do_close" instead!]
+ */
+asmlinkage long sys_close_syscall(unsigned int fd)
+{
+	register struct task_struct *p = current;
+
+	if((p->mosix.dflags & (DDEPUTY|DREMOTE)) || !CAN_DFSA(p))
+		goto call_sys;
+
+	/* no locking of "&p->files->file_lock" is needed because CAN_DFSA
+	 * included checking that no clones are sharing our files! */
+	if (fd >= p->files->max_fds)
+	/* if we were to run remotely, we could also "close" a bad file there!*/
+	{
+		p->mosix.dflags |= DSTATSDOWN;
+		return(-EBADF);
+	}
+	if(can_dfsa_file(fd))	/* and we already know CAN_DFSA(p) is true */
+		p->mosix.dflags |= DSTATSDOWN;
+	call_sys:
+	return(sys_close(fd));
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * This routine simulates a hangup on the tty, to arrange that users
  * are given clean terminals at login time.
diff -ruN linux-2.4.16/fs/pipe.c linux-2.4.16-mosix/fs/pipe.c
--- linux-2.4.16/fs/pipe.c	Sat Sep 29 03:03:48 2001
+++ linux-2.4.16-mosix/fs/pipe.c	Sun Dec 23 13:56:53 2001
@@ -69,8 +69,24 @@
 			goto out;
 
 		for (;;) {
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+			unsigned long bytes, prev;
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 			PIPE_WAITING_READERS(*inode)++;
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+			bytes = count;
+			if(bytes > PIPE_BUF)
+				bytes = PIPE_BUF;
+			prev = PIPE_READING_BYTES(*inode);
+			PIPE_READING_BYTES(*inode) += bytes;
+			if (!prev && (PIPE_EXCEPTIONS(*inode) &
+							PIPE_EXCEPTION_INPUT))
+				wake_up_interruptible(PIPE_WAIT(*inode));
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 			pipe_wait(inode);
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+			PIPE_READING_BYTES(*inode) -= bytes;
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 			PIPE_WAITING_READERS(*inode)--;
 			ret = -ERESTARTSYS;
 			if (signal_pending(current))
@@ -264,6 +280,22 @@
 	return -EBADF;
 }
 
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+static inline int
+set_pipe_exceptions(struct inode *ip, unsigned long val)
+{
+	int oval = PIPE_EXCEPTIONS(*ip);
+
+	PIPE_EXCEPTIONS(*ip) = val;
+	if(val & ~(PIPE_EXCEPTION_INPUT|PIPE_EXCEPTION_NOINPUT))
+		return(-EINVAL);
+	if(((val & PIPE_EXCEPTION_INPUT & ~oval) && PIPE_READING_BYTES(*ip))
+	    || ((val & PIPE_EXCEPTION_NOINPUT & ~oval) && !PIPE_READERS(*ip)))
+		wake_up_interruptible(PIPE_WAIT(*ip));
+	return(0);
+}
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
+
 static int
 pipe_ioctl(struct inode *pino, struct file *filp,
 	   unsigned int cmd, unsigned long arg)
@@ -271,6 +303,12 @@
 	switch (cmd) {
 		case FIONREAD:
 			return put_user(PIPE_LEN(*pino), (int *)arg);
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+		case TCSBRK:
+			return(set_pipe_exceptions(pino, arg));
+		case TIOCGWINSZ:
+			return(PIPE_READING_BYTES(*pino));
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 		default:
 			return -EINVAL;
 	}
@@ -293,6 +331,13 @@
 		mask |= POLLHUP;
 	if (!PIPE_READERS(*inode))
 		mask |= POLLERR;
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+	if (((PIPE_EXCEPTIONS(*inode) & PIPE_EXCEPTION_INPUT) &&
+		PIPE_READING_BYTES(*inode)) ||
+	    ((PIPE_EXCEPTIONS(*inode) & PIPE_EXCEPTION_NOINPUT) &&
+		!PIPE_READERS(*inode)))
+		mask |= POLLPRI;
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 
 	return mask;
 }
@@ -458,6 +503,9 @@
 	PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0;
 	PIPE_WAITING_READERS(*inode) = PIPE_WAITING_WRITERS(*inode) = 0;
 	PIPE_RCOUNTER(*inode) = PIPE_WCOUNTER(*inode) = 1;
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+	PIPE_READING_BYTES(*inode) = PIPE_EXCEPTIONS(*inode) = 0;
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 
 	return inode;
 fail_page:
diff -ruN linux-2.4.16/fs/proc/array.c linux-2.4.16-mosix/fs/proc/array.c
--- linux-2.4.16/fs/proc/array.c	Thu Oct 11 18:00:01 2001
+++ linux-2.4.16-mosix/fs/proc/array.c	Sun Dec 23 13:56:53 2001
@@ -76,6 +76,13 @@
 #include <asm/io.h>
 #include <asm/processor.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#include <linux/ptrace.h>
+#include <linux/smp_lock.h>
+#include <linux/file.h>
+#endif /* CONFIG_MOSIX */
+
 /* Gcc optimizes away "strlen(x)" for constant x */
 #define ADDBUF(buffer, string) \
 do { memcpy(buffer, string, strlen(string)); \
@@ -130,7 +137,11 @@
 
 static inline const char * get_task_state(struct task_struct *tsk)
 {
+#ifdef CONFIG_MOSIX
+	unsigned int state = LOGICAL_STATE(tsk) & (TASK_RUNNING |
+#else
 	unsigned int state = tsk->state & (TASK_RUNNING |
+#endif /* CONFIG_MOSIX */
 					   TASK_INTERRUPTIBLE |
 					   TASK_UNINTERRUPTIBLE |
 					   TASK_ZOMBIE |
@@ -176,7 +187,11 @@
 	return buffer;
 }
 
+#ifdef CONFIG_MOSIX
+inline char * task_mem(struct mm_struct *mm, char *buffer)
+#else
 static inline char * task_mem(struct mm_struct *mm, char *buffer)
+#endif /* CONFIG_MOSIX */
 {
 	struct vm_area_struct * vma;
 	unsigned long data = 0, stack = 0;
@@ -274,10 +289,18 @@
 {
 	char * orig = buffer;
 	struct mm_struct *mm;
+#ifdef CONFIG_MOSIX
+	int should_ask = 0;
+#endif /* CONFIG_MOSIX */
 
 	buffer = task_name(task, buffer);
 	buffer = task_state(task, buffer);
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if((should_ask = SHOULD_ASK_PROCESS(task)))
+		mm = NULL;
+	else
+#endif /* CONFIG_MOSIX */
 	mm = task->mm;
 	if(mm)
 		atomic_inc(&mm->mm_users);
@@ -286,6 +309,10 @@
 		buffer = task_mem(mm, buffer);
 		mmput(mm);
 	}
+#ifdef CONFIG_MOSIX
+	else if(should_ask)
+		buffer = request_process_to_buf(task,buffer,PR_PROCFS_TASK_MEM);
+#endif /* CONFIG_MOSIX */
 	buffer = task_sig(task, buffer);
 	buffer = task_cap(task, buffer);
 #if defined(CONFIG_ARCH_S390)
@@ -294,10 +321,126 @@
 	return buffer - orig;
 }
 
+#ifdef CONFIG_MOSIX
+
+int proc_pid_where(struct task_struct *task, char *buffer)
+{
+	task_lock(task);
+	sprintf(buffer, "%d\n", (task->mosix.stay & DSTAY_ITS_DAEMON) ? 0 :
+							task->mosix.whereami);
+	task_unlock(task);
+	return (strlen(buffer));
+}
+
+int proc_pid_lock(struct task_struct *task, char *buffer)
+{
+	sprintf(buffer, "%d\n", (task->mosix.stay & DNOMIGRATE) ? 1 : 0);
+	return(3);	/* == strlen(buffer) */
+}
+
+int proc_pid_disclosure(struct task_struct *task, char *buffer)
+{
+	sprintf(buffer, "%d\n", task->mosix.disclosure);
+	return(strlen(buffer));
+}
+
+char *mosix_stay_string[] = {
+	"monkey",	"mmap_dev",	"VM86_mode",	"daemon",
+	"priv_inst",	"mem_lock",	"clone_vm",	"rt_sched",
+	"direct_io",	"init_proc",	"kiobuf",	NULL,
+	NULL,		NULL,		NULL,		NULL,
+	NULL,		NULL,		NULL,		NULL,
+	NULL,		NULL,		NULL,		NULL,
+	"extern_1",	"extern_2",	"extern_3",	"extern_4",
+	NULL,		NULL,		NULL,		"user_lock"
+};
+
+int proc_pid_cantmove(struct task_struct *task, char *buffer)
+{
+	typeof (task->mosix.stay) i;
+	int j;
+
+	for (buffer[0] = '\0' , j = 0 , i = 1 ; i ; i <<= 1 , j++)
+	if (task->mosix.stay & DSTAY & i)
+	{
+		if(buffer[0])
+			strcat(buffer, ", ");
+		strcat(buffer, mosix_stay_string[j] ? : "unrecognized");
+	}
+	if(buffer[0])
+		strcat(buffer, "\n");
+	return(strlen(buffer));
+}
+
+int proc_pid_nmigs(struct task_struct *task, char *buffer)
+{
+	task_lock(task);
+	sprintf(buffer, "%d\n", task->mosix.nmigs);
+	task_unlock(task);
+	return(strlen(buffer));
+}
+
+int proc_pid_sigmig(struct task_struct *task, char * buffer)
+{
+	sprintf(buffer, "%d\n", task->mosix.sigmig);
+	return(strlen(buffer));
+}
+
+#ifdef CONFIG_MOSIX_FS
+int proc_pid_selected(struct task_struct *task, char *buffer)
+{
+	sprintf(buffer, "%d\n", task->mosix.selected);
+	return(strlen(buffer));
+}
+#endif /* CONFIG_MOSIX_FS */
+
+void
+proc_get_stat_parts(struct task_struct *task, struct mm_struct *mm,
+					struct proc_remote_stat_parts *t)
+{
+	if (mm)
+	{
+		struct vm_area_struct *vma;
+
+		t->vsize = 0;
+		down_read(&mm->mmap_sem);
+		vma = mm->mmap;
+		while (vma) {
+			t->vsize += vma->vm_end - vma->vm_start;
+			vma = vma->vm_next;
+		}
+		t->rss = mm->rss;
+		t->start_code = mm->start_code;
+		t->end_code = mm->end_code;
+		t->start_stack = mm->start_stack;
+		up_read(&mm->mmap_sem);
+		if(task == current && (task->mosix.dflags & DREMOTE))
+		/* just in case EIP and/or ESP are held by DEPUTY: */
+			mosix_obtain_registers(
+				BIT_OF_REGISTER(eip)|BIT_OF_REGISTER(esp));
+		t->eip = KSTK_EIP(task);
+		t->esp = KSTK_ESP(task);
+	}
+	else
+		memset(t, 0, sizeof(*t));
+	t->priority = task->counter;
+	t->priority = 20 - (t->priority * 10 + DEF_COUNTER / 2) / DEF_COUNTER;
+	t->processor = task->processor;
+	if(task->mosix.dflags & DREMOTE)
+		t->processor += 32*PE;
+}
+#endif /* CONFIG_MOSIX */
+
 int proc_pid_stat(struct task_struct *task, char * buffer)
 {
+#ifdef CONFIG_MOSIX
+	unsigned long wchan;
+	long nice;
+	struct proc_remote_stat_parts rinfo;
+#else
 	unsigned long vsize, eip, esp, wchan;
 	long priority, nice;
+#endif /* CONFIG_MOSIX */
 	int tty_pgrp = -1, tty_nr = 0;
 	sigset_t sigign, sigcatch;
 	char state;
@@ -306,8 +449,36 @@
 	struct mm_struct *mm;
 
 	state = *get_task_state(task);
+#ifndef CONFIG_MOSIX
 	vsize = eip = esp = 0;
+#endif /* CONFIG_MOSIX */
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if (task->tty) {
+		tty_pgrp = task->tty->pgrp;
+		tty_nr = kdev_t_to_nr(task->tty->device);
+	}
+	if(SHOULD_ASK_PROCESS(task))
+	{
+		task_unlock(task);
+		if(request_process(task, &rinfo, PR_PROCFS_GET_STAT_PARTS, 0)<0)
+			memset((caddr_t)&rinfo, 0, sizeof(rinfo));
+		mm = NULL;
+	}
+	else
+	{
+		mm = task->mm;
+		if(mm)
+			atomic_inc(&mm->mm_users);
+		task_unlock(task);
+		proc_get_stat_parts(task, mm, &rinfo);
+	}
+	/* the following test has nothing to do with MOSIX - just security! */
+	if ((current->fsuid != task->euid ||
+	    !cap_issubset(task->cap_permitted, current->cap_permitted)) &&
+	    !capable(CAP_DAC_OVERRIDE))
+		rinfo.eip = rinfo.esp = 0;
+#else
 	mm = task->mm;
 	if(mm)
 		atomic_inc(&mm->mm_users);
@@ -328,6 +499,7 @@
 		esp = KSTK_ESP(task);
 		up_read(&mm->mmap_sem);
 	}
+#endif /* CONFIG_MOSIX */
 
 	wchan = get_wchan(task);
 
@@ -335,8 +507,10 @@
 
 	/* scale priority and nice values from timeslices to -20..20 */
 	/* to make it look like a "normal" Unix priority/nice value  */
+#ifndef CONFIG_MOSIX
 	priority = task->counter;
 	priority = 20 - (priority * 10 + DEF_COUNTER / 2) / DEF_COUNTER;
+#endif /* CONFIG_MOSIX */
 	nice = task->nice;
 
 	read_lock(&tasklist_lock);
@@ -362,19 +536,36 @@
 		task->times.tms_stime,
 		task->times.tms_cutime,
 		task->times.tms_cstime,
+#ifdef CONFIG_MOSIX
+		rinfo.priority,
+#else
 		priority,
+#endif /* CONFIG_MOSIX */
 		nice,
 		0UL /* removed */,
 		task->it_real_value,
 		task->start_time,
+#ifdef CONFIG_MOSIX
+		rinfo.vsize,
+		rinfo.rss,
+#else
 		vsize,
 		mm ? mm->rss : 0, /* you might want to shift this left 3 */
+#endif /* CONFIG_MOSIX */
 		task->rlim[RLIMIT_RSS].rlim_cur,
+#ifdef CONFIG_MOSIX
+		rinfo.start_code,
+		rinfo.end_code,
+		rinfo.start_stack,
+		rinfo.esp,
+		rinfo.eip,
+#else
 		mm ? mm->start_code : 0,
 		mm ? mm->end_code : 0,
 		mm ? mm->start_stack : 0,
 		esp,
 		eip,
+#endif /* CONFIG_MOSIX */
 		/* The signal information here is obsolete.
 		 * It must be decimal for Linux 2.0 compatibility.
 		 * Use /proc/#/status for real-time signals.
@@ -387,7 +578,11 @@
 		task->nswap,
 		task->cnswap,
 		task->exit_signal,
+#ifdef CONFIG_MOSIX
+		(int)rinfo.processor);
+#else
 		task->processor);
+#endif /* CONFIG_MOSIX */
 	if(mm)
 		mmput(mm);
 	return res;
@@ -472,12 +667,24 @@
 {
 	struct mm_struct *mm;
 	int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0;
+#ifdef CONFIG_MOSIX
+	int should_ask = 0;
+#endif /* CONFIG_MOSIX */
 
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if((should_ask = SHOULD_ASK_PROCESS(task)))
+		mm = NULL;
+	else
+#endif /* CONFIG_MOSIX */
 	mm = task->mm;
 	if(mm)
 		atomic_inc(&mm->mm_users);
 	task_unlock(task);
+#ifdef CONFIG_MOSIX
+	if(should_ask)
+		return(request_process(task, buffer, PR_PROCFS_GET_STATM, 0));
+#endif /* CONFIG_MOSIX */
 	if (mm) {
 		struct vm_area_struct * vma;
 		down_read(&mm->mmap_sem);
@@ -538,6 +745,46 @@
 #define MAPS_LINE_FORMAT	(sizeof(void*) == 4 ? MAPS_LINE_FORMAT4 : MAPS_LINE_FORMAT8)
 #define MAPS_LINE_MAX	(sizeof(void*) == 4 ?  MAPS_LINE_MAX4 :  MAPS_LINE_MAX8)
 
+#ifdef CONFIG_MOSIX
+int
+proc_list_maps(struct vmamaps *maps, int start)
+{
+	struct mm_struct *mm;
+	struct vm_area_struct *map;
+	int i;
+
+	if(!(mm = current->mm))
+		return(0);
+	down_read(&mm->mmap_sem);
+	map = mm->mmap;
+	while(map && start-- > 0)
+		map = map->vm_next;
+	for(i = 0 ; map && i < PAGE_SIZE / sizeof(struct vmamaps) ; i++)
+	{
+		maps->vmstart = map->vm_start;
+		maps->vmend = map->vm_end;
+		maps->vmflags = map->vm_flags;
+		maps->vmpgoff = map->vm_pgoff;
+		maps->fp = map->vm_file ? home_file(map->vm_file) : 0;
+		maps++;
+		map = map->vm_next;
+	}
+	up_read(&mm->mmap_sem);
+	return (i * sizeof(struct vmamaps));
+}
+
+void
+ref_mapped_files(struct vmamaps *maps, int len)
+{
+	int i;
+	struct file *fp;
+
+	for(i = 0 ; i < len / sizeof(struct vmamaps) ; i++)
+	if((fp = maps[i].fp))
+		get_file(fp);
+}
+#endif /* CONFIG_MOSIX */
+
 static int proc_pid_maps_get_line (char *buf, struct vm_area_struct *map)
 {
 	/* produce the next line */
@@ -595,6 +842,12 @@
 	char *tmp, *kbuf;
 	long retval;
 	int off, lineno, loff;
+#ifdef CONFIG_MOSIX
+	int should_ask = 0;
+	int nrmaps = 0, ind = 0;
+	struct vmamaps *rmaps = NULL;
+	struct vm_area_struct rvma;
+#endif /* CONFIG_MOSIX */
 
 	/* reject calls with out of range parameters immediately */
 	retval = 0;
@@ -616,16 +869,42 @@
 		goto out_free1;
 
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if((should_ask = SHOULD_ASK_PROCESS(task)))
+		mm = NULL;
+	else
+#endif /* CONFIG_MOSIX */
 	mm = task->mm;
 	if (mm)
 		atomic_inc(&mm->mm_users);
 	task_unlock(task);
+#ifdef CONFIG_MOSIX
+	if(should_ask)
+	{
+		retval = -ENOMEM;
+		if(!(rmaps = (struct vmamaps *)__get_free_page(GFP_KERNEL)))
+			goto out_free2;
+		ind = off / PAGE_SIZE;
+		retval = request_process(task, rmaps, PR_PROCFS_MAP_INFO, ind);
+		nrmaps = 0;
+		if(retval <= 0)
+			goto out_free2;
+		ind = -ind;
+		nrmaps = retval / sizeof(struct vmamaps);
+		retval = 0;
+		map = &rvma;
+		goto begin;
+	}
+#endif /* CONFIG_MOSIX */
 	retval = 0;
 	if (!mm)
 		goto out_free2;
 
 	down_read(&mm->mmap_sem);
 	map = mm->mmap;
+#ifdef CONFIG_MOSIX
+	begin:
+#endif /* CONFIG_MOSIX */
 	lineno = 0;
 	loff = 0;
 	if (count > PAGE_SIZE)
@@ -636,6 +915,16 @@
 			off -= PAGE_SIZE;
 			goto next;
 		}
+#ifdef CONFIG_MOSIX
+		if(should_ask)
+		{
+			rvma.vm_start = rmaps[ind].vmstart;
+			rvma.vm_end = rmaps[ind].vmend;
+			rvma.vm_flags = rmaps[ind].vmflags;
+			rvma.vm_pgoff = rmaps[ind].vmpgoff;
+			rvma.vm_file = rmaps[ind].fp;
+		}
+#endif /* CONFIG_MOSIX */
 		len = proc_pid_maps_get_line(tmp, map);
 		len -= off;
 		if (len > 0) {
@@ -656,10 +945,25 @@
 		if (retval >= count)
 			break;
 		if (loff) BUG();
+#ifdef CONFIG_MOSIX
+		if(should_ask)
+		{
+			if(++ind >= nrmaps)
+				map = NULL;
+		}
+		else
+#endif /* CONFIG_MOSIX */
 		map = map->vm_next;
 	}
+#ifdef CONFIG_MOSIX
+	if(mm)
+	{
+#endif /* CONFIG_MOSIX */
 	up_read(&mm->mmap_sem);
 	mmput(mm);
+#ifdef CONFIG_MOSIX
+	}
+#endif /* CONFIG_MOSIX */
 
 	if (retval > count) BUG();
 	if (copy_to_user(buf, kbuf, retval))
@@ -672,6 +976,15 @@
 out_free1:
 	free_page((unsigned long)kbuf);
 out:
+#ifdef CONFIG_MOSIX
+	if(rmaps)
+	{
+		for(ind = 0 ; ind < nrmaps ; ind++)
+		if(rmaps[ind].fp)
+			fput(rmaps[ind].fp);
+		free_page((unsigned long)rmaps);
+	}
+#endif /* CONFIG_MOSIX */
 	return retval;
 }
 
@@ -680,6 +993,10 @@
 {
 	int i, len;
 
+#ifdef CONFIG_MOSIX
+	if(SHOULD_ASK_PROCESS(task))
+		request_process(task, buffer, PR_PROCFS_UPDATE_TIMES, 0);
+#endif /* CONFIG_MOSIX */
 	len = sprintf(buffer,
 		"cpu  %lu %lu\n",
 		task->times.tms_utime,
@@ -690,6 +1007,10 @@
 			i,
 			task->per_cpu_utime[cpu_logical_map(i)],
 			task->per_cpu_stime[cpu_logical_map(i)]);
+#ifdef CONFIG_MOSIX
+	if(task->mosix.nmigs)
+		len += sprintf(buffer, "TIMES ON REMOTE MOSIX NODES NOT LISTED\n");
+#endif /* CONFIG_MOSIX */
 
 	return len;
 }
diff -ruN linux-2.4.16/fs/proc/base.c linux-2.4.16-mosix/fs/proc/base.c
--- linux-2.4.16/fs/proc/base.c	Thu Oct 11 08:42:47 2001
+++ linux-2.4.16-mosix/fs/proc/base.c	Sun Dec 23 13:56:53 2001
@@ -24,6 +24,11 @@
 #include <linux/file.h>
 #include <linux/string.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#include <linux/smp_lock.h>
+#endif /* CONFIG_MOSIX */
+
 /*
  * For hysterical raisins we keep the same inumbers as in the old procfs.
  * Feel free to change the macro below - just keep the range distinct from
@@ -39,6 +44,17 @@
 int proc_pid_status(struct task_struct*,char*);
 int proc_pid_statm(struct task_struct*,char*);
 int proc_pid_cpu(struct task_struct*,char*);
+#ifdef CONFIG_MOSIX
+int proc_pid_where(struct task_struct*,char*);
+int proc_pid_nmigs(struct task_struct*,char*);
+int proc_pid_cantmove(struct task_struct*,char*);
+int proc_pid_lock(struct task_struct*,char*);
+int proc_pid_sigmig(struct task_struct*,char*);
+int proc_pid_disclosure(struct task_struct*,char*);
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_FS
+int proc_pid_selected(struct task_struct*,char*);
+#endif /* CONFIG_MOSIX_FS */
 
 static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
 {
@@ -50,6 +66,32 @@
 	return -ENOENT;
 }
 
+#ifdef CONFIG_MOSIX
+struct file *
+first_executable(void)
+{
+	struct mm_struct *mm = current->mm;
+	register struct vm_area_struct *vma;
+	struct file *f = NULL;
+
+	if(!mm)
+		return(NULL);
+	down_read(&mm->mmap_sem);
+	for(vma = current->mm->mmap ; vma ; vma = vma->vm_next)
+	if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
+	{
+		f = vma->vm_file;
+		if(current->mosix.dflags & DREMOTE)
+			f = home_file(f);
+		else
+			get_file(f);
+		break;
+	}
+	up_read(&mm->mmap_sem);
+	return(f);
+}
+#endif /* CONFIG_MOSIX */
+
 static int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
 {
 	struct mm_struct * mm;
@@ -58,6 +100,24 @@
 	struct task_struct *task = inode->u.proc_i.task;
 
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if(SHOULD_ASK_PROCESS(task))
+	{
+		struct file *f;
+
+		task_unlock(task);
+		f = (struct file *)request_process(task, &f,
+							PR_PROCFS_GET_EXE, 0);
+		if(f && !IS_ERR(f))
+		{
+			*mnt = mntget(f->f_vfsmnt);
+			*dentry = dget(f->f_dentry);
+			result = 0;
+			fput(f);
+		}
+		goto out;
+	}
+#endif /* CONFIG_MOSIX */
 	mm = task->mm;
 	if (mm)
 		atomic_inc(&mm->mm_users);
@@ -86,6 +146,12 @@
 {
 	struct fs_struct *fs;
 	int result = -ENOENT;
+#ifdef CONFIG_MOSIX_DFSA
+	struct task_struct *p = inode->u.proc_i.task;
+
+	if(SHOULD_ASK_PROCESS(p))
+		request_process(p, NULL, PR_DFSA_SYNCHRONIZE, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	task_lock(inode->u.proc_i.task);
 	fs = inode->u.proc_i.task->fs;
 	if(fs)
@@ -122,11 +188,22 @@
 	return result;
 }
 
+#ifdef CONFIG_MOSIX
+int proc_pid_environ(struct task_struct *task, char * buffer)
+#else
 static int proc_pid_environ(struct task_struct *task, char * buffer)
+#endif /* CONFIG_MOSIX */
 {
 	struct mm_struct *mm;
 	int res = 0;
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if(SHOULD_ASK_PROCESS(task))
+	{
+		task_unlock(task);
+		return(request_process(task, buffer, PR_PROCFS_GET_ENV, 0));
+	}
+#endif /* CONFIG_MOSIX */
 	mm = task->mm;
 	if (mm)
 		atomic_inc(&mm->mm_users);
@@ -141,11 +218,22 @@
 	return res;
 }
 
+#ifdef CONFIG_MOSIX
+int proc_pid_cmdline(struct task_struct *task, char * buffer)
+#else
 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
+#endif /* CONFIG_MOSIX */
 {
 	struct mm_struct *mm;
 	int res = 0;
 	task_lock(task);
+#ifdef CONFIG_MOSIX
+	if(SHOULD_ASK_PROCESS(task))
+	{
+		task_unlock(task);
+		return(request_process(task, buffer, PR_PROCFS_GET_ARG, 0));
+	}
+#endif /* CONFIG_MOSIX */
 	mm = task->mm;
 	if (mm)
 		atomic_inc(&mm->mm_users);
@@ -196,6 +284,10 @@
 	our_vfsmnt = mntget(current->fs->rootmnt);
 	base = dget(current->fs->root);
 	read_unlock(&current->fs->lock);
+#ifdef CONFIG_MOSIX
+	if(!root)	/* hope it will be fixed by 2.4.0 */
+		return(-ENOENT);
+#endif /* CONFIG_MOSIX */
 
 	spin_lock(&dcache_lock);
 	de = root;
@@ -286,8 +378,14 @@
 	read:		proc_info_read,
 };
 
+#ifdef CONFIG_MOSIX
+#define MAY_PTRACE(p) \
+(p==current||(p->p_pptr==current&&(p->ptrace & PT_PTRACED) && \
+					LOGICAL_STATE(p) == TASK_STOPPED))
+#else
 #define MAY_PTRACE(p) \
 (p==current||(p->p_pptr==current&&(p->ptrace & PT_PTRACED)&&p->state==TASK_STOPPED))
+#endif /* CONFIG_MOSIX */
 
 
 static int mem_open(struct inode* inode, struct file* file)
@@ -318,10 +416,15 @@
 	if (mm)
 		atomic_inc(&mm->mm_users);
 	task_unlock(task);
+#ifndef CONFIG_MOSIX
 	if (!mm)
 		return 0;
+#endif /* CONFIG_MOSIX */
 
 	if (file->private_data != (void*)((long)current->self_exec_id) ) {
+#ifdef CONFIG_MOSIX
+		if(mm)
+#endif /* CONFIG_MOSIX */
 		mmput(mm);
 		return -EIO;
 	}
@@ -347,6 +450,9 @@
 		count -= retval;
 	}
 	*ppos = src;
+#ifdef CONFIG_MOSIX
+	if(mm)
+#endif /* CONFIG_MOSIX */
 	mmput(mm);
 	free_page((unsigned long) page);
 	return copied;
@@ -497,6 +603,20 @@
 	PROC_PID_STATM,
 	PROC_PID_MAPS,
 	PROC_PID_CPU,
+#ifdef CONFIG_MOSIX
+	PROC_PID_WHERE,
+	PROC_PID_MIGRATE,
+	PROC_PID_GOTO,
+	PROC_PID_LOCK,
+	PROC_PID_NMIGS,
+	PROC_PID_CANTMOVE,
+	PROC_PID_SIGMIG,
+	PROC_PID_DISCLOSURE,
+#ifdef CONFIG_MOSIX_FS
+	PROC_PID_SELECTED,
+#endif /* CONFIG_MOSIX_FS */
+	PROC_PID_MOSIX_START = PROC_MOSIX_USE_START,
+#endif /* CONFIG_MOSIX */
 	PROC_PID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
 };
 
@@ -516,6 +636,19 @@
   E(PROC_PID_CWD,	"cwd",		S_IFLNK|S_IRWXUGO),
   E(PROC_PID_ROOT,	"root",		S_IFLNK|S_IRWXUGO),
   E(PROC_PID_EXE,	"exe",		S_IFLNK|S_IRWXUGO),
+#ifdef CONFIG_MOSIX
+  E(PROC_PID_WHERE,	"where",	S_IFREG|S_IRUGO),
+  E(PROC_PID_MIGRATE,	"migrate",	S_IFREG|S_IWUSR),
+  E(PROC_PID_GOTO,	"goto",		S_IFREG|S_IWUGO),
+  E(PROC_PID_LOCK,	"lock",		S_IFREG|S_IRUGO|S_IWUSR),
+  E(PROC_PID_NMIGS,	"nmigs",	S_IFREG|S_IRUGO),
+  E(PROC_PID_CANTMOVE,	"cantmove",	S_IFREG|S_IRUGO),
+  E(PROC_PID_SIGMIG,	"sigmig",	S_IFREG|S_IRUGO|S_IWUSR),
+  E(PROC_PID_DISCLOSURE,"disclosure",	S_IFREG|S_IRUGO|S_IWUSR),
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_FS
+  E(PROC_PID_SELECTED,	"selected",	S_IFREG|S_IRUGO|S_IWUSR),
+#endif /* CONFIG_MOSIX_FS */
   {0,0,NULL,0}
 };
 #undef E
@@ -546,6 +679,10 @@
 				goto out;
 			filp->f_pos++;
 		default:
+#ifdef CONFIG_MOSIX_DFSA
+			if(SHOULD_ASK_PROCESS(p))
+				request_process(p, NULL, PR_DFSA_SYNCHRONIZE,0);
+#endif /* CONFIG_MOSIX_DFSA */
 			task_lock(p);
 			files = p->files;
 			if (files)
@@ -622,7 +759,11 @@
 
 /* building an inode */
 
+#ifdef CONFIG_MOSIX
+int task_dumpable(struct task_struct *task)
+#else
 static int task_dumpable(struct task_struct *task)
+#endif /* CONFIG_MOSIX */
 {
 	int dumpable = 0;
 	struct mm_struct *mm;
@@ -631,6 +772,11 @@
 	mm = task->mm;
 	if (mm)
 		dumpable = mm->dumpable;
+#ifdef CONFIG_MOSIX
+	else if((current->mosix.dflags & (DDEPUTY|DDUMPABLE)) ==
+							(DDEPUTY|DDUMPABLE))
+		dumpable = 1;
+#endif /* CONFIG_MOSIX */
 	task_unlock(task);
 	return dumpable;
 }
@@ -747,6 +893,10 @@
 	inode = proc_pid_make_inode(dir->i_sb, task, PROC_PID_FD_DIR+fd);
 	if (!inode)
 		goto out;
+#ifdef CONFIG_MOSIX_DFSA
+	if(SHOULD_ASK_PROCESS(task))
+		request_process(task, NULL, PR_DFSA_SYNCHRONIZE,0);
+#endif /* CONFIG_MOSIX_DFSA */
 	task_lock(task);
 	files = task->files;
 	if (files)
@@ -795,6 +945,52 @@
 	permission:	proc_permission,
 };
 
+#ifdef CONFIG_MOSIX
+static int
+proc_pid_writeonly(struct task_struct *doesnt_matter, char *buf)
+{
+	return(-EPERM);
+}
+
+static ssize_t
+proc_mosix_write(struct file *file, const char *buf, size_t cnt, loff_t *ppos)
+{
+	struct inode * inode = file->f_dentry->d_inode;
+	ssize_t result = -EPERM;
+	struct task_struct *task = inode->u.proc_i.task;
+
+	switch(inode->i_ino & 0xffff)
+	{
+	    case PROC_PID_MIGRATE:
+		result = proc_mosix_pid_set_migrate(file, task, buf, cnt);
+		break;
+	    case PROC_PID_GOTO:
+		result = proc_mosix_pid_set_goto(file, task, buf, cnt);
+		break;
+	    case PROC_PID_LOCK:
+		result = proc_mosix_pid_set_lock(file, task, buf, cnt);
+		break;
+	    case PROC_PID_SIGMIG:
+		result = proc_mosix_pid_set_sigmig(file, task, buf, cnt);
+		break;
+	    case PROC_PID_DISCLOSURE:
+		result = proc_mosix_pid_set_disclosure(file, task, buf, cnt);
+		break;
+#ifdef CONFIG_MOSIX_FS
+	    case PROC_PID_SELECTED:
+		result = proc_mosix_pid_set_selected(file, task, buf, cnt);
+		break;
+#endif /* CONFIG_MOSIX_FS */
+	}
+	return(result);
+}
+
+static struct file_operations proc_mosix_file_operations = {
+	read: proc_info_read,
+	write: proc_mosix_write,
+};
+#endif /* CONFIG_MOSIX */
+
 static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
 {
 	struct inode *inode;
@@ -875,6 +1071,46 @@
 			inode->i_op = &proc_mem_inode_operations;
 			inode->i_fop = &proc_mem_operations;
 			break;
+#ifdef CONFIG_MOSIX
+		case PROC_PID_WHERE:
+			inode->i_fop = &proc_info_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_where;
+			break;
+		case PROC_PID_NMIGS:
+			inode->i_fop = &proc_info_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_nmigs;
+			break;
+		case PROC_PID_CANTMOVE:
+			inode->i_fop = &proc_info_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_cantmove;
+			break;
+		case PROC_PID_MIGRATE:
+			inode->i_fop = &proc_mosix_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_writeonly;
+			break;
+		case PROC_PID_GOTO:
+			inode->i_fop = &proc_mosix_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_writeonly;
+			break;
+		case PROC_PID_LOCK:
+			inode->i_fop = &proc_mosix_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_lock;
+			break;
+		case PROC_PID_SIGMIG:
+			inode->i_fop = &proc_mosix_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_sigmig;
+			break;
+		case PROC_PID_DISCLOSURE:
+			inode->i_fop = &proc_mosix_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_disclosure;
+			break;
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_FS
+		case PROC_PID_SELECTED:
+			inode->i_fop = &proc_mosix_file_operations;
+			inode->u.proc_i.op.proc_read = proc_pid_selected;
+			break;
+#endif /* CONFIG_MOSIX_FS */
 		default:
 			printk("procfs: impossible type (%d)",p->type);
 			iput(inode);
@@ -989,6 +1225,14 @@
 {
 	if (inode->u.proc_i.file)
 		fput(inode->u.proc_i.file);
+#ifdef CONFIG_MOSIX
+	{
+		int ino = inode->i_ino & 0xffff;
+
+		if(ino >= PROC_PID_MOSIX_START && ino < PROC_PID_FD_DIR)
+			return;
+	}
+#endif /* CONFIG_MOSIX */
 	if (inode->u.proc_i.task)
 		free_task_struct(inode->u.proc_i.task);
 }
@@ -1008,7 +1252,11 @@
 
 	index--;
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		int pid = p->pid;
 		if (!pid)
 			continue;
diff -ruN linux-2.4.16/fs/proc/generic.c linux-2.4.16-mosix/fs/proc/generic.c
--- linux-2.4.16/fs/proc/generic.c	Fri Sep  7 20:53:59 2001
+++ linux-2.4.16-mosix/fs/proc/generic.c	Sun Dec 23 13:56:53 2001
@@ -356,7 +356,11 @@
 	lookup:		proc_lookup,
 };
 
+#ifdef CONFIG_MOSIX
+int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
+#else
 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
+#endif /* CONFIG_MOSIX */
 {
 	int	i;
 	
diff -ruN linux-2.4.16/fs/proc/inode.c linux-2.4.16-mosix/fs/proc/inode.c
--- linux-2.4.16/fs/proc/inode.c	Sat Nov 17 21:24:32 2001
+++ linux-2.4.16-mosix/fs/proc/inode.c	Sun Dec 23 13:56:53 2001
@@ -194,7 +194,11 @@
 	 * Fixup the root inode's nlink value
 	 */
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) if (p->pid) root_inode->i_nlink++;
+#else
 	for_each_task(p) if (p->pid) root_inode->i_nlink++;
+#endif /* CONFIG_MOSIX */
 	read_unlock(&tasklist_lock);
 	s->s_root = d_alloc_root(root_inode);
 	if (!s->s_root)
diff -ruN linux-2.4.16/fs/proc/root.c linux-2.4.16-mosix/fs/proc/root.c
--- linux-2.4.16/fs/proc/root.c	Sun Oct 21 04:14:42 2001
+++ linux-2.4.16-mosix/fs/proc/root.c	Sun Dec 23 13:56:53 2001
@@ -17,7 +17,14 @@
 #include <linux/module.h>
 #include <asm/bitops.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 struct proc_dir_entry *proc_net, *proc_bus, *proc_root_fs, *proc_root_driver;
+#ifdef CONFIG_MOSIX
+struct proc_dir_entry *proc_mosix;
+#endif /* CONFIG_MOSIX */
 
 #ifdef CONFIG_SYSCTL
 struct proc_dir_entry *proc_sys_root;
@@ -48,6 +55,10 @@
 	proc_mkdir("sys/fs", 0);
 	proc_mkdir("sys/fs/binfmt_misc", 0);
 #endif
+#ifdef CONFIG_MOSIX
+	proc_mosix = proc_mkdir("mosix", 0);
+	mosix_proc_init();
+#endif /* CONFIG_MOSIX */
 	proc_root_fs = proc_mkdir("fs", 0);
 	proc_root_driver = proc_mkdir("driver", 0);
 #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
@@ -70,6 +81,9 @@
 		int nlink = proc_root.nlink;
 
 		nlink += nr_threads;
+#ifdef CONFIG_MOSIX
+		nlink -= count_guests();
+#endif /* CONFIG_MOSIX */
 
 		dir->i_nlink = nlink;
 	}
diff -ruN linux-2.4.16/fs/read_write.c linux-2.4.16-mosix/fs/read_write.c
--- linux-2.4.16/fs/read_write.c	Sun Aug  5 23:12:41 2001
+++ linux-2.4.16-mosix/fs/read_write.c	Sun Dec 23 13:56:53 2001
@@ -14,6 +14,10 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 struct file_operations generic_ro_fops = {
 	llseek:		generic_file_llseek,
 	read:		generic_file_read,
@@ -76,7 +80,11 @@
 	return retval;
 }
 
+#ifdef CONFIG_MOSIX_FS
+inline loff_t llseek(struct file *file, loff_t offset, int origin)
+#else
 static inline loff_t llseek(struct file *file, loff_t offset, int origin)
+#endif /* CONFIG_MOSIX_FS */
 {
 	loff_t (*fn)(struct file *, loff_t, int);
 	loff_t retval;
@@ -95,6 +103,9 @@
 	off_t retval;
 	struct file * file;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	retval = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -120,6 +131,9 @@
 	struct file * file;
 	loff_t offset;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	retval = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -149,6 +163,9 @@
 	ssize_t ret;
 	struct file * file;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	ret = -EBADF;
 	file = fget(fd);
 	if (file) {
@@ -175,6 +192,9 @@
 	ssize_t ret;
 	struct file * file;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	ret = -EBADF;
 	file = fget(fd);
 	if (file) {
@@ -307,6 +327,9 @@
 	ssize_t ret;
 
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	ret = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -327,6 +350,9 @@
 	ssize_t ret;
 
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	ret = -EBADF;
 	file = fget(fd);
 	if (!file)
diff -ruN linux-2.4.16/fs/readdir.c linux-2.4.16-mosix/fs/readdir.c
--- linux-2.4.16/fs/readdir.c	Mon Aug 13 00:59:08 2001
+++ linux-2.4.16-mosix/fs/readdir.c	Sun Dec 23 13:56:53 2001
@@ -5,6 +5,10 @@
  */
 
 #include <linux/sched.h>
+#ifdef CONFIG_MOSIX
+#include <linux/stddef.h>
+#include <linux/dirent.h>
+#endif /* CONFIG_MOSIX */
 #include <linux/mm.h>
 #include <linux/errno.h>
 #include <linux/stat.h>
@@ -13,6 +17,10 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 int vfs_readdir(struct file *file, filldir_t filler, void *buf)
 {
 	struct inode *inode = file->f_dentry->d_inode;
@@ -132,11 +140,30 @@
 		return -EINVAL;
 	buf->count++;
 	dirent = buf->dirent;
+#ifdef CONFIG_MOSIX
+	{
+		union
+		{
+			struct old_linux_dirent o;
+			struct dirent d;
+		} u;
+
+		u.o.d_ino = ino;
+		u.o.d_offset = offset;
+		u.o.d_namlen = namlen;
+		memcpy(u.d.d_name, name, namlen);
+		u.d.d_name[namlen] = '\0';
+		copy_to_user(dirent, &u,
+			offsetof(struct old_linux_dirent, d_name[0]) +
+				namlen + 1);
+	}
+#else
 	put_user(ino, &dirent->d_ino);
 	put_user(offset, &dirent->d_offset);
 	put_user(namlen, &dirent->d_namlen);
 	copy_to_user(dirent->d_name, name, namlen);
 	put_user(0, dirent->d_name + namlen);
+#endif /* CONFIG_MOSIX */
 	return 0;
 }
 
@@ -146,6 +173,9 @@
 	struct file * file;
 	struct readdir_callback buf;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -154,7 +184,13 @@
 	buf.count = 0;
 	buf.dirent = dirent;
 
+#ifdef CONFIG_MOSIX_FS
+	current->mosix.dirty_bits |= MFSARG_OLDREADDIR;
+#endif /* CONFIG_MOSIX_FS */
 	error = vfs_readdir(file, fillonedir, &buf);
+#ifdef CONFIG_MOSIX_FS
+	current->mosix.dirty_bits &= ~MFSARG_OLDREADDIR;
+#endif /* CONFIG_MOSIX_FS */
 	if (error >= 0)
 		error = buf.count;
 
@@ -189,6 +225,9 @@
 	struct linux_dirent * dirent;
 	struct getdents_callback * buf = (struct getdents_callback *) __buf;
 	int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
+#ifdef CONFIG_MOSIX
+	struct dirent d;
+#endif /* CONFIG_MOSIX */
 
 	buf->error = -EINVAL;	/* only used if we fail.. */
 	if (reclen > buf->count)
@@ -199,9 +238,24 @@
 	dirent = buf->current_dir;
 	buf->previous = dirent;
 	put_user(ino, &dirent->d_ino);
+#ifdef CONFIG_MOSIX
+/* access to remote-data is much faster in one block */
+	d.d_reclen = reclen;
+	memcpy(d.d_name, name, namlen);
+	d.d_name[namlen] = '\0';
+/* NOTICE:
+We take great liberty to fill the potential round-up byte(s)
+that are not filled by standard Linux.
+SORRY - performance would be horrible otherwise with all the fragmentation.
+*/
+
+	copy_to_user(&dirent->d_reclen, &d.d_reclen,
+				reclen - offsetof(struct dirent, d_reclen));
+#else
 	put_user(reclen, &dirent->d_reclen);
 	copy_to_user(dirent->d_name, name, namlen);
 	put_user(0, dirent->d_name + namlen);
+#endif /* CONFIG_MOSIX */
 	((char *) dirent) += reclen;
 	buf->current_dir = dirent;
 	buf->count -= reclen;
@@ -215,6 +269,9 @@
 	struct getdents_callback buf;
 	int error;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -225,7 +282,14 @@
 	buf.count = count;
 	buf.error = 0;
 
+#ifdef CONFIG_MOSIX_FS
+	current->mosix.dirty_bits |= MFSARG_GETDENTS;
+	current->mosix.dirty_arg = count;
+#endif /* CONFIG_MOSIX_FS */
 	error = vfs_readdir(file, filldir, &buf);
+#ifdef CONFIG_MOSIX_FS
+	current->mosix.dirty_bits &= ~MFSARG_GETDENTS;
+#endif /* CONFIG_MOSIX_FS */
 	if (error < 0)
 		goto out_putf;
 	error = buf.error;
@@ -298,6 +362,9 @@
 	struct getdents_callback64 buf;
 	int error;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -308,7 +375,14 @@
 	buf.count = count;
 	buf.error = 0;
 
+#ifdef CONFIG_MOSIX_FS
+	current->mosix.dirty_bits |= MFSARG_GETDENTS64;
+	current->mosix.dirty_arg = count;
+#endif /* CONFIG_MOSIX_FS */
 	error = vfs_readdir(file, filldir64, &buf);
+#ifdef CONFIG_MOSIX_FS
+	current->mosix.dirty_bits &= ~MFSARG_GETDENTS64;
+#endif /* CONFIG_MOSIX_FS */
 	if (error < 0)
 		goto out_putf;
 	error = buf.error;
diff -ruN linux-2.4.16/fs/stat.c linux-2.4.16-mosix/fs/stat.c
--- linux-2.4.16/fs/stat.c	Fri Sep 14 02:04:43 2001
+++ linux-2.4.16-mosix/fs/stat.c	Sun Dec 23 13:56:53 2001
@@ -13,6 +13,14 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#include <linux/slab.h>
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * Revalidate the inode. This is required for proper NFS attribute caching.
  */
@@ -123,6 +131,14 @@
 		tmp.st_blocks = inode->i_blocks;
 		tmp.st_blksize = inode->i_blksize;
 	}
+#ifdef CONFIG_MOSIX_FS
+	if(inode->i_sb && inode->i_sb->s_magic == MFS_SUPER_MAGIC)
+	{
+		tmp.__unused1 = inode->u.mfs_i.pe;
+		tmp.__unused2 = inode->i_generation;
+		tmp.__unused3 = inode->i_version;
+	}
+#endif /* CONFIG_MOSIX_FS */
 	return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
 }
 
@@ -137,7 +153,28 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_STAT;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+	{
+		if(nd.complete_parg)
+		{
+			error = cp_old_stat((struct inode *)nd.complete_parg,
+								statbuf);
+			kfree(nd.complete_parg);
+		}
+		return(error);
+	}
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW| LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = do_revalidate(nd.dentry);
 		if (!error)
@@ -153,7 +190,28 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_STAT;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+	{
+		if(nd.complete_parg)
+		{
+			error = cp_new_stat((struct inode *)nd.complete_parg,
+								statbuf);
+			kfree(nd.complete_parg);
+		}
+		return(error);
+	}
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = do_revalidate(nd.dentry);
 		if (!error)
@@ -174,7 +232,27 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_STAT;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS|
+							LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+	{
+		if(nd.complete_parg)
+		{
+			error = cp_old_stat((struct inode *)nd.complete_parg,
+								statbuf);
+			kfree(nd.complete_parg);
+		}
+		return(error);
+	}
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk_link(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = do_revalidate(nd.dentry);
 		if (!error)
@@ -191,7 +269,27 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_STAT;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS|
+							LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+	{
+		if(nd.complete_parg)
+		{
+			error = cp_new_stat((struct inode *)nd.complete_parg,
+								statbuf);
+			kfree(nd.complete_parg);
+		}
+		return(error);
+	}
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk_link(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = do_revalidate(nd.dentry);
 		if (!error)
@@ -212,6 +310,9 @@
 	struct file * f;
 	int err = -EBADF;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	f = fget(fd);
 	if (f) {
 		struct dentry * dentry = f->f_dentry;
@@ -231,6 +332,9 @@
 	struct file * f;
 	int err = -EBADF;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	f = fget(fd);
 	if (f) {
 		struct dentry * dentry = f->f_dentry;
@@ -251,7 +355,21 @@
 	if (bufsiz <= 0)
 		return -EINVAL;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_READLINK;
+	nd.complete_args.buffer.buf = buf;
+	nd.complete_args.buffer.bufsiz = bufsiz;
+	error = __user_walk(path, LOOKUP_POSITIVE|LOOKUP_STAYFS|LOOKUP_COMPLETE,
+									&nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+		return(error);
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(path, LOOKUP_POSITIVE|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk_link(path, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		struct inode * inode = nd.dentry->d_inode;
 
@@ -326,6 +444,14 @@
 		tmp.st_blocks = inode->i_blocks;
 		tmp.st_blksize = inode->i_blksize;
 	}
+#ifdef CONFIG_MOSIX_FS
+	if(inode->i_sb && inode->i_sb->s_magic == MFS_SUPER_MAGIC)
+	{
+		STAT64_NODE(tmp) = inode->u.mfs_i.pe;
+		STAT64_ORIGDEV(tmp) = inode->i_generation;
+		STAT64_ORIGINO(tmp) = inode->i_version;
+	}
+#endif /* CONFIG_MOSIX_FS */
 	return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
 }
 
@@ -334,7 +460,28 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_STAT;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW|
+					LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+	{
+		if(nd.complete_parg)
+		{
+			error = cp_new_stat64((struct inode *)nd.complete_parg,
+								statbuf);
+			kfree(nd.complete_parg);
+		}
+		return(error);
+	}
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename,
+			LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = do_revalidate(nd.dentry);
 		if (!error)
@@ -349,7 +496,27 @@
 	struct nameidata nd;
 	int error;
 
+#ifdef CONFIG_MOSIX_FS
+	nd.express_function = EF_STAT;
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS|
+							LOOKUP_COMPLETE, &nd);
+	if(nd.complete_flags & COMPLETE_DONE)
+	{
+		if(nd.complete_parg)
+		{
+			error = cp_new_stat64((struct inode *)nd.complete_parg,
+								statbuf);
+			kfree(nd.complete_parg);
+		}
+		return(error);
+	}
+#else
+#ifdef CONFIG_MOSIX_DFSA
+	error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS, &nd);
+#else
 	error = user_path_walk_link(filename, &nd);
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX_FS */
 	if (!error) {
 		error = do_revalidate(nd.dentry);
 		if (!error)
@@ -364,6 +531,9 @@
 	struct file * f;
 	int err = -EBADF;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_syscall_on_file(fd, 0);
+#endif /* CONFIG_MOSIX_DFSA */
 	f = fget(fd);
 	if (f) {
 		struct dentry * dentry = f->f_dentry;
diff -ruN linux-2.4.16/fs/super.c linux-2.4.16-mosix/fs/super.c
--- linux-2.4.16/fs/super.c	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/fs/super.c	Sun Dec 23 13:56:53 2001
@@ -495,7 +495,11 @@
 {
 	int i;
 
+#ifdef CONFIG_MOSIX_FS
+	for (i = 1; i < 255; i++) {
+#else
 	for (i = 1; i < 256; i++) {
+#endif /* CONFIG_MOSIX_FS */
 		if (!test_and_set_bit(i,unnamed_dev_in_use))
 			return MKDEV(UNNAMED_MAJOR, i);
 	}
@@ -506,6 +510,10 @@
 {
 	if (!dev || MAJOR(dev) != UNNAMED_MAJOR)
 		return;
+#ifdef CONFIG_MOSIX_FS
+	if(MINOR(dev) == 255)
+		return;
+#endif /* CONFIG_MOSIX_FS */
 	if (test_and_clear_bit(MINOR(dev), unnamed_dev_in_use))
 		return;
 	printk("VFS: put_unnamed_dev: freeing unused device %s\n",
@@ -644,6 +652,12 @@
 {
 	kdev_t dev;
 	int error = -EMFILE;
+
+#ifdef CONFIG_MOSIX_FS
+	if(!strcmp(fs_type->name, "mfs"))
+		dev = MKDEV(UNNAMED_MAJOR, 255);
+	else
+#endif /* CONFIG_MOSIX_FS */
 	dev = get_unnamed_dev();
 	if (dev) {
 		struct super_block * sb;
diff -ruN linux-2.4.16/fs/umsdos/ioctl.c linux-2.4.16-mosix/fs/umsdos/ioctl.c
--- linux-2.4.16/fs/umsdos/ioctl.c	Tue Aug 28 18:16:07 2001
+++ linux-2.4.16-mosix/fs/umsdos/ioctl.c	Sun Dec 23 13:56:53 2001
@@ -15,6 +15,10 @@
 #include <linux/msdos_fs.h>
 #include <linux/umsdos_fs.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 struct UMSDOS_DIR_ONCE {
 	struct dirent *ent;
 	int count;
@@ -209,6 +213,20 @@
 		}
 		/* update the original f_pos */
 		filp->f_pos = pos;
+#ifdef CONFIG_MOSIX_DFSA
+		{
+			struct files_struct *files = current->files;
+			register int i;
+
+			if(atomic_read(&files->count) == 1)
+			for(i = 0 ; i < files->max_fds ; i++)
+			if(files->fd[i] == filp)
+			{
+				dfsa_touch_file(i);
+				break;
+			}
+		}
+#endif /* CONFIG_MOSIX_DFSA */
 	read_dput:
 		d_drop(demd);
 		dput(demd);
diff -ruN linux-2.4.16/include/asm-generic/smplock.h linux-2.4.16-mosix/include/asm-generic/smplock.h
--- linux-2.4.16/include/asm-generic/smplock.h	Thu Mar 23 22:50:09 2000
+++ linux-2.4.16-mosix/include/asm-generic/smplock.h	Sun Dec 23 13:56:53 2001
@@ -49,3 +49,24 @@
 	if (--current->lock_depth < 0)
 		spin_unlock(&kernel_flag);
 }
+
+#ifdef CONFIG_MOSIX
+
+/* the big MOSIX lock resembles the big kernel lock in the way it is
+ * allowed to be locked multiple times.  It is not allowed, however,
+ * to remain locked when entering "schedule".
+ */
+extern spinlock_t mosix_flag;
+
+extern __inline__ void lock_mosix(void)
+{
+	if (!++current->mosix.lock_depth)
+		spin_lock(&mosix_flag);
+}
+
+extern __inline__ void unlock_mosix(void)
+{
+	if (--current->mosix.lock_depth < 0)
+		spin_unlock(&mosix_flag);
+}
+#endif /* CONFIG_MOSIX */
diff -ruN linux-2.4.16/include/asm-i386/a.out.h linux-2.4.16-mosix/include/asm-i386/a.out.h
--- linux-2.4.16/include/asm-i386/a.out.h	Fri Jun 16 21:33:06 1995
+++ linux-2.4.16-mosix/include/asm-i386/a.out.h	Sun Dec 23 13:56:53 2001
@@ -21,6 +21,9 @@
 
 #define STACK_TOP	TASK_SIZE
 
+#ifdef CONFIG_MOSIX
+void aout_remote_init_mm(struct exec *);
+#endif /* CONFIG_MOSIX */
 #endif
 
 #endif /* __A_OUT_GNU_H__ */
diff -ruN linux-2.4.16/include/asm-i386/checksum.h linux-2.4.16-mosix/include/asm-i386/checksum.h
--- linux-2.4.16/include/asm-i386/checksum.h	Thu Jul 26 23:41:22 2001
+++ linux-2.4.16-mosix/include/asm-i386/checksum.h	Sun Dec 23 13:56:53 2001
@@ -1,6 +1,13 @@
 #ifndef _I386_CHECKSUM_H
 #define _I386_CHECKSUM_H
 
+#ifndef CONFIG_MOSIX
+#include <linux/config.h>
+#endif /* CONFIG_MOSIX */
+
+#ifdef CONFIG_MOSIX
+#include <asm/uaccess.h>
+#endif /* CONFIG_MOSIX */
 
 /*
  * computes the checksum of a memory block at buff, length len,
@@ -38,13 +45,29 @@
 unsigned int csum_partial_copy_nocheck ( const char *src, char *dst,
 					int len, int sum)
 {
+#ifdef CONFIG_MOSIX
+	if(!segment_eq(get_fs(), KERNEL_DS) &&
+		(((unsigned long)src) < PAGE_OFFSET ||
+		((unsigned long)dst) < PAGE_OFFSET))
+		panic("csum_partial_copy_nocheck, src=%x,dst=%x",(int)src,(int)dst);
+#endif /* CONFIG_MOSIX */
 	return csum_partial_copy_generic ( src, dst, len, sum, NULL, NULL);
 }
 
+#ifdef CONFIG_MOSIX
+extern unsigned int deputy_csum_partial_copy_from_user(const char *, char *, int, int, int *);
+extern unsigned int deputy_csum_partial_copy_to_user(const char *, char *, int, int, int *);
+#endif /* CONFIG_MOSIX */
+
 static __inline__
 unsigned int csum_partial_copy_from_user ( const char *src, char *dst,
 						int len, int sum, int *err_ptr)
 {
+#ifdef CONFIG_MOSIX
+	if(memory_not_here(len, FROM_USER))
+		return(deputy_csum_partial_copy_from_user(src, dst, len,
+								sum, err_ptr));
+#endif /* CONFIG_MOSIX */
 	return csum_partial_copy_generic ( src, dst, len, sum, err_ptr, NULL);
 }
 
@@ -185,6 +208,11 @@
 static __inline__ unsigned int csum_and_copy_to_user (const char *src, char *dst,
 				    int len, int sum, int *err_ptr)
 {
+#ifdef CONFIG_MOSIX
+	if(memory_not_here(len, FROM_USER))
+		return(deputy_csum_partial_copy_to_user(src, dst, len,
+								sum, err_ptr));
+#endif /* CONFIG_MOSIX */
 	if (access_ok(VERIFY_WRITE, dst, len))
 		return csum_partial_copy_generic(src, dst, len, sum, NULL, err_ptr);
 
diff -ruN linux-2.4.16/include/asm-i386/cpufeature.h linux-2.4.16-mosix/include/asm-i386/cpufeature.h
--- linux-2.4.16/include/asm-i386/cpufeature.h	Mon Nov 13 07:55:50 2000
+++ linux-2.4.16-mosix/include/asm-i386/cpufeature.h	Sun Dec 23 13:56:53 2001
@@ -63,6 +63,22 @@
 #define X86_FEATURE_CYRIX_ARR	(3*32+ 2) /* Cyrix ARRs (= MTRRs) */
 #define X86_FEATURE_CENTAUR_MCR	(3*32+ 3) /* Centaur MCRs (= MTRRs) */
 
+#ifdef CONFIG_MOSIX
+#define	FBIT(feature)	(1 << ((feature) % 32))
+#define	USER_MODE_FEATURES0	(FBIT(X86_FEATURE_TSC)|FBIT(X86_FEATURE_CX8)|\
+				FBIT(X86_FEATURE_SEP)|FBIT(X86_FEATURE_CMOV)|\
+				FBIT(X86_FEATURE_MMX)|FBIT(X86_FEATURE_CLFLSH)|\
+				FBIT(X86_FEATURE_FXSR)|FBIT(X86_FEATURE_XMM)|\
+				FBIT(X86_FEATURE_XMM2))
+#define	USER_MODE_FEATURES1	(FBIT(X86_FEATURE_SYSCALL)|\
+				FBIT(X86_FEATURE_MMXEXT)|FBIT(X86_FEATURE_LM)|\
+				FBIT(X86_FEATURE_3DNOWEXT)|\
+				FBIT(X86_FEATURE_3DNOW))
+#define	USER_MODE_FEATURES2	0
+#define	USER_MODE_FEATURES3	(FBIT(X86_FEATURE_CXMMX))
+#define	USER_MODE_FEATURES	{ USER_MODE_FEATURES0, USER_MODE_FEATURES1, \
+				USER_MODE_FEATURES2, USER_MODE_FEATURES3 }
+#endif /* CONFIG_MOSIX */
 #endif /* __ASM_I386_CPUFEATURE_H */
 
 /* 
diff -ruN linux-2.4.16/include/asm-i386/elf.h linux-2.4.16-mosix/include/asm-i386/elf.h
--- linux-2.4.16/include/asm-i386/elf.h	Thu Nov 22 21:48:29 2001
+++ linux-2.4.16-mosix/include/asm-i386/elf.h	Sun Dec 23 13:56:53 2001
@@ -41,6 +41,12 @@
    We might as well make sure everything else is cleared too (except for %esp),
    just to make things more deterministic.
  */
+#ifdef CONFIG_MOSIX
+#define	ELF_PLAT_INIT_REGS	(BIT_OF_REGISTER(ebx)|BIT_OF_REGISTER(ecx)|\
+				 BIT_OF_REGISTER(edx)|BIT_OF_REGISTER(esi)|\
+				 BIT_OF_REGISTER(edi)|BIT_OF_REGISTER(ebp)|\
+				 BIT_OF_REGISTER(eax))
+#endif /* CONFIG_MOSIX */
 #define ELF_PLAT_INIT(_r)	do { \
 	_r->ebx = 0; _r->ecx = 0; _r->edx = 0; \
 	_r->esi = 0; _r->edi = 0; _r->ebp = 0; \
diff -ruN linux-2.4.16/include/asm-i386/fcntl.h linux-2.4.16-mosix/include/asm-i386/fcntl.h
--- linux-2.4.16/include/asm-i386/fcntl.h	Mon Sep 17 23:16:30 2001
+++ linux-2.4.16-mosix/include/asm-i386/fcntl.h	Sun Dec 23 13:56:53 2001
@@ -21,6 +21,10 @@
 #define O_DIRECTORY	0200000	/* must be a directory */
 #define O_NOFOLLOW	0400000 /* don't follow links */
 
+#ifdef CONFIG_MOSIX
+#define	O_NOWRITEACCESS	01000000 /* do not put_write_access() */
+#endif /* CONFIG_MOSIX */
+
 #define F_DUPFD		0	/* dup */
 #define F_GETFD		1	/* get close_on_exec */
 #define F_SETFD		2	/* set/clear close_on_exec */
diff -ruN linux-2.4.16/include/asm-i386/i387.h linux-2.4.16-mosix/include/asm-i386/i387.h
--- linux-2.4.16/include/asm-i386/i387.h	Thu Nov 22 21:48:58 2001
+++ linux-2.4.16-mosix/include/asm-i386/i387.h	Sun Dec 23 13:56:53 2001
@@ -85,4 +85,10 @@
 extern int dump_extended_fpu( struct pt_regs *regs,
 			      struct user_fxsr_struct *fpu );
 
+#ifdef CONFIG_MOSIX
+extern int has_fxsr(void);
+extern void fsave_to_fxsave(union i387_union *, union i387_union *);
+extern void fxsave_to_fsave(union i387_union *, union i387_union *);
+#endif /* CONFIG_MOSIX */
+
 #endif /* __ASM_I386_I387_H */
diff -ruN linux-2.4.16/include/asm-i386/processor.h linux-2.4.16-mosix/include/asm-i386/processor.h
--- linux-2.4.16/include/asm-i386/processor.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/asm-i386/processor.h	Sun Dec 23 13:56:53 2001
@@ -420,6 +420,12 @@
 	regs->esp = new_esp;					\
 } while (0)
 
+#ifdef CONFIG_MOSIX
+#define START_THREAD_REGS (BIT_OF_REGISTER(xds)|BIT_OF_REGISTER(xes)|\
+			   BIT_OF_REGISTER(xss)|BIT_OF_REGISTER(xcs)|\
+			   BIT_OF_REGISTER(eip)|BIT_OF_REGISTER(esp))
+#endif /* CONFIG_MOSIX */
+
 /* Forward declaration, a strange C thing */
 struct task_struct;
 struct mm_struct;
@@ -430,6 +436,9 @@
  * create a kernel thread without removing it from tasklists
  */
 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
+#ifdef CONFIG_MOSIX
+extern int user_thread(int (*fn)(void *), void * arg, unsigned long flags);
+#endif /* CONFIG_MOSIX */
 
 /* Copy and release all segment info associated with a VM */
 extern void copy_segments(struct task_struct *p, struct mm_struct * mm);
@@ -444,8 +453,13 @@
 }
 
 unsigned long get_wchan(struct task_struct *p);
+#ifdef CONFIG_MOSIX
+#define	KSTK_EIP(tsk)	(mos_to_regs(&(tsk)->mosix)->eip)
+#define	KSTK_ESP(tsk)	(mos_to_regs(&(tsk)->mosix)->esp)
+#else
 #define KSTK_EIP(tsk)	(((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
 #define KSTK_ESP(tsk)	(((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
+#endif /* CONFIG_MOSIX */
 
 #define THREAD_SIZE (2*PAGE_SIZE)
 #define alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
diff -ruN linux-2.4.16/include/asm-i386/semaphore.h linux-2.4.16-mosix/include/asm-i386/semaphore.h
--- linux-2.4.16/include/asm-i386/semaphore.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/asm-i386/semaphore.h	Sun Dec 23 13:56:53 2001
@@ -159,6 +159,11 @@
 	return result;
 }
 
+#ifdef CONFIG_MOSIX
+/* do not be interrupted by signals, but still respond to MOSIX requests */
+extern void down_half_interruptible(struct semaphore *);
+#endif /* CONFIG_MOSIX */
+
 /*
  * Non-blockingly attempt to down() a semaphore.
  * Returns zero if we acquired it
diff -ruN linux-2.4.16/include/asm-i386/siginfo.h linux-2.4.16-mosix/include/asm-i386/siginfo.h
--- linux-2.4.16/include/asm-i386/siginfo.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/asm-i386/siginfo.h	Sun Dec 23 13:56:53 2001
@@ -59,6 +59,12 @@
 			int _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
 			int _fd;
 		} _sigpoll;
+#ifdef CONFIG_MOSIX
+		struct {
+			int _newplace;
+			int _reason;
+		} _sigmig;
+#endif /* CONFIG_MOSIX */
 	} _sifields;
 } siginfo_t;
 
@@ -76,6 +82,10 @@
 #define si_addr		_sifields._sigfault._addr
 #define si_band		_sifields._sigpoll._band
 #define si_fd		_sifields._sigpoll._fd
+#ifdef CONFIG_MOSIX
+#define	si_newplace	_sifields._sigmig._newplace
+#define	si_reason	_sifields._sigmig._reason
+#endif /* CONFIG_MOSIX */
 
 #ifdef __KERNEL__
 #define __SI_MASK	0xffff0000
@@ -85,6 +95,9 @@
 #define __SI_FAULT	(3 << 16)
 #define __SI_CHLD	(4 << 16)
 #define __SI_RT		(5 << 16)
+#ifdef CONFIG_MOSIX
+#define	__SI_MIGRATION	(6 << 16)
+#endif /* CONFIG_MOSIX */
 #define __SI_CODE(T,N)	((T) << 16 | ((N) & 0xffff))
 #else
 #define __SI_KILL	0
@@ -107,6 +120,9 @@
 #define SI_MESGQ	-3		/* sent by real time mesq state change */
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
+#ifdef CONFIG_MOSIX
+#define	SI_MIGRATION	0x100	/* sent by migration */
+#endif /* CONFIG_MOSIX */
 
 #define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
 #define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
@@ -181,6 +197,10 @@
 #define POLL_HUP	(__SI_POLL|6)	/* device disconnected */
 #define NSIGPOLL	6
 
+#ifdef CONFIG_MOSIX
+#define	SI_MIGRATED	(__SI_MIGRATION|1)	/* process migrated */
+#endif /* CONFIG_MOSIX */
+
 /*
  * sigevent definitions
  * 
diff -ruN linux-2.4.16/include/asm-i386/smplock.h linux-2.4.16-mosix/include/asm-i386/smplock.h
--- linux-2.4.16/include/asm-i386/smplock.h	Thu Nov 22 21:46:20 2001
+++ linux-2.4.16-mosix/include/asm-i386/smplock.h	Sun Dec 23 13:56:53 2001
@@ -73,3 +73,26 @@
 		 "=m" (current->lock_depth));
 #endif
 }
+
+#ifdef CONFIG_MOSIX
+
+/* the big MOSIX lock resembles the big kernel lock in the way it is
+ * allowed to be locked multiple times.  It is not allowed, however,
+ * to remain locked when entering "schedule".
+ */
+extern spinlock_t mosix_flag;
+
+extern __inline__ void lock_mosix(void)
+{
+	if (!++current->mosix.lock_depth)
+		spin_lock(&mosix_flag);
+}
+
+extern __inline__ void unlock_mosix(void)
+{
+	if (current->mosix.lock_depth < 0)
+		BUG();
+	if (--current->mosix.lock_depth < 0)
+		spin_unlock(&mosix_flag);
+}
+#endif /* CONFIG_MOSIX */
diff -ruN linux-2.4.16/include/asm-i386/spinlock.h linux-2.4.16-mosix/include/asm-i386/spinlock.h
--- linux-2.4.16/include/asm-i386/spinlock.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/asm-i386/spinlock.h	Sun Dec 23 13:56:53 2001
@@ -209,4 +209,8 @@
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+#define can_read_lock(rw)	((rw)->lock > 0)
+#endif /* CONFIG_MOSIX */
+
 #endif /* __ASM_SPINLOCK_H */
diff -ruN linux-2.4.16/include/asm-i386/stat.h linux-2.4.16-mosix/include/asm-i386/stat.h
--- linux-2.4.16/include/asm-i386/stat.h	Wed Aug  2 00:08:00 2000
+++ linux-2.4.16-mosix/include/asm-i386/stat.h	Sun Dec 23 13:56:53 2001
@@ -75,4 +75,12 @@
 	unsigned long long	st_ino;
 };
 
+#ifdef CONFIG_MOSIX_FS
+
+/* more information about MFS: */
+#define STAT64_NODE(_x)		(*((short *)(&(_x).__pad0[2])))
+#define STAT64_ORIGDEV(_x)	(*((short *)(&(_x).__pad0[4])))
+#define STAT64_ORIGINO(_x)	(*((unsigned long *)(&(_x).__pad0[6])))
+
+#endif /* CONFIG_MOSIX_FS */
 #endif
diff -ruN linux-2.4.16/include/asm-i386/uaccess.h linux-2.4.16-mosix/include/asm-i386/uaccess.h
--- linux-2.4.16/include/asm-i386/uaccess.h	Thu Nov 22 21:46:20 2001
+++ linux-2.4.16-mosix/include/asm-i386/uaccess.h	Sun Dec 23 13:56:53 2001
@@ -32,6 +32,74 @@
 
 #define segment_eq(a,b)	((a).seg == (b).seg)
 
+#ifdef CONFIG_MOSIX
+
+enum { FROM_USER, TO_USER };
+
+#define	COPY_COUNTER_MULTIPLIER	1024
+#define	COPY_COUNTER_SHIFT	10
+
+static inline void
+mosix_local_statistic(int __nb, int __dir)
+{
+	extern void cause_link_error_by_routine_that_does_not_exist(void);
+
+	if(__dir == TO_USER)
+	{
+#ifdef CONFIG_MOSIX_DFSA
+		if(current->mosix.dflags & DSTATSDOWN)
+			return;
+#endif /* CONFIG_MOSIX_DFSA */
+		current->mosix.ncopyouts += COPY_COUNTER_MULTIPLIER;
+		current->mosix.copyoutbytes += __nb;
+	}
+	else if(__dir == FROM_USER)
+	{
+#ifdef CONFIG_MOSIX_DFSA
+		if(current->mosix.dflags & DSTATSDOWN)
+		{
+			current->mosix.copy_ins++;
+			current->mosix.bytes_in += __nb;
+		}
+		else
+#endif /* CONFIG_MOSIX_DFSA */
+		{
+			current->mosix.ncopyins += COPY_COUNTER_MULTIPLIER;
+			current->mosix.copyinbytes += __nb;
+		}
+	}
+	else	/* impossible */
+		cause_link_error_by_routine_that_does_not_exist();
+}
+
+#define	USER_IS_REMOTE	((current->mosix.dflags & DDEPUTY) && \
+			 segment_eq(get_fs(), USER_DS))
+
+static inline int
+memory_not_here(int bytes, int direction)
+{
+	if(segment_eq(get_fs(), KERNEL_DS))
+		return(0);
+	switch(current->mosix.dflags & (DDEPUTY|DREMOTE))
+	{
+		case DDEPUTY:
+			return(1);
+		default:
+			mosix_local_statistic(bytes, direction);
+			/* fall thru */
+		case DREMOTE:
+			return(0);
+	}
+}
+
+extern unsigned long deputy_copy_from_user(void *, void *, unsigned long, int);
+extern unsigned long deputy_copy_to_user(void *, void *, unsigned long, int);
+extern unsigned long deputy_clear_user(void *, int, int);
+extern long deputy_strncpy_from_user(char *, char *, int, int);
+extern long deputy_strnlen_user(char *, long);
+extern int deputy_verify_write(void *, unsigned long);
+#endif /* CONFIG_MOSIX */
+
 extern int __verify_write(const void *, unsigned long);
 
 #define __addr_ok(addr) ((unsigned long)(addr) < (current->addr_limit.seg))
@@ -112,6 +180,23 @@
 		:"0" (ptr))
 
 /* Careful: we have to cast the result to the type of the pointer for sign reasons */
+#ifdef CONFIG_MOSIX
+#define get_user(x,ptr)							\
+({	int __ret_gu,__val_gu;						\
+	if(memory_not_here(sizeof(*(ptr)),FROM_USER))			\
+		__ret_gu = deputy_copy_from_user((void *)&__val_gu,	\
+			(void *)ptr, sizeof(*(ptr)), 1);		\
+	else								\
+	switch(sizeof (*(ptr))) {					\
+	case 1:  __get_user_x(1,__ret_gu,__val_gu,ptr); break;		\
+	case 2:  __get_user_x(2,__ret_gu,__val_gu,ptr); break;		\
+	case 4:  __get_user_x(4,__ret_gu,__val_gu,ptr); break;		\
+	default: __get_user_x(X,__ret_gu,__val_gu,ptr); break;		\
+	}								\
+	(x) = (__typeof__(*(ptr)))__val_gu;				\
+	__ret_gu;							\
+})
+#else
 #define get_user(x,ptr)							\
 ({	int __ret_gu,__val_gu;						\
 	switch(sizeof (*(ptr))) {					\
@@ -123,6 +208,7 @@
 	(x) = (__typeof__(*(ptr)))__val_gu;				\
 	__ret_gu;							\
 })
+#endif /* CONFIG_MOSIX */
 
 extern void __put_user_1(void);
 extern void __put_user_2(void);
@@ -131,6 +217,34 @@
 
 extern void __put_user_bad(void);
 
+#ifdef CONFIG_MOSIX
+#define put_user(x,ptr)							\
+({	int __ret_pu;							\
+	if(memory_not_here(sizeof(*(ptr)),TO_USER)) {			\
+		__typeof__(*(ptr)) __val_pu = (__typeof__(*ptr)) x;	\
+		__ret_pu = deputy_copy_to_user((void *)ptr,		\
+			(void *)&__val_pu, sizeof(*(ptr)), 1); }	\
+	else								\
+		__ret_pu =						\
+  __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)));	\
+	__ret_pu;							\
+})
+
+#define __get_user(x,ptr) \
+	(memory_not_here(sizeof(*(ptr)),FROM_USER) ?			\
+		({ int __ret_gu,__val_gu;				\
+		__ret_gu = deputy_copy_from_user((void *)&__val_gu,	\
+			(void *)(ptr), sizeof(*(ptr)), 0);		\
+		(x) = (__typeof__(*(ptr)))__val_gu;			\
+		__ret_gu; })						\
+	: __get_user_nocheck((x),(ptr),sizeof(*(ptr))))
+#define __put_user(x,ptr) \
+	(memory_not_here(sizeof(*ptr),TO_USER) ? ({			\
+		__typeof__(*(ptr)) __val_pu = (__typeof__(*ptr)) x;	\
+		deputy_copy_to_user((void *)(ptr),			\
+			(void *)&__val_pu, sizeof(*(ptr)), 0); })	\
+	: __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr))))
+#else
 #define put_user(x,ptr)							\
   __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
 
@@ -138,6 +252,7 @@
   __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
 #define __put_user(x,ptr) \
   __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
+#endif /* CONFIG_MOSIX */
 
 #define __put_user_nocheck(x,ptr,size)			\
 ({							\
@@ -576,6 +691,35 @@
 	return n;
 }
 
+#ifdef CONFIG_MOSIX
+#define copy_to_user(to,from,n)				\
+	(memory_not_here((n),TO_USER) ?			\
+		deputy_copy_to_user((to),(void *)(from),(n),1) : \
+	 __builtin_constant_p(n) ?			\
+	 __constant_copy_to_user((to),(from),(n)) :	\
+	 __generic_copy_to_user((to),(from),(n)))
+
+#define copy_from_user(to,from,n)			\
+	(memory_not_here((n),FROM_USER) ?		\
+		deputy_copy_from_user((to),(void *)(from),(n),1) : \
+	 __builtin_constant_p(n) ?			\
+	 __constant_copy_from_user((to),(from),(n)) :	\
+	 __generic_copy_from_user((to),(from),(n)))
+
+#define __copy_to_user(to,from,n)			\
+	 (memory_not_here((n),TO_USER) ?		\
+		deputy_copy_to_user((to),(void *)(from),(n),0) : \
+	 __builtin_constant_p(n) ?			\
+	 __constant_copy_to_user_nocheck((to),(from),(n)) :	\
+	 __generic_copy_to_user_nocheck((to),(from),(n)))
+
+#define __copy_from_user(to,from,n)			\
+	 (memory_not_here((n),FROM_USER) ?		\
+		deputy_copy_from_user((to),(void *)(from),(n),0) : \
+	 __builtin_constant_p(n) ?			\
+	 __constant_copy_from_user_nocheck((to),(from),(n)) :	\
+	 __generic_copy_from_user_nocheck((to),(from),(n)))
+#else
 #define copy_to_user(to,from,n)				\
 	(__builtin_constant_p(n) ?			\
 	 __constant_copy_to_user((to),(from),(n)) :	\
@@ -595,6 +739,7 @@
 	(__builtin_constant_p(n) ?			\
 	 __constant_copy_from_user_nocheck((to),(from),(n)) :	\
 	 __generic_copy_from_user_nocheck((to),(from),(n)))
+#endif /* CONFIG_MOSIX */
 
 long strncpy_from_user(char *dst, const char *src, long count);
 long __strncpy_from_user(char *dst, const char *src, long count);
diff -ruN linux-2.4.16/include/linux/binfmts.h linux-2.4.16-mosix/include/linux/binfmts.h
--- linux-2.4.16/include/linux/binfmts.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/binfmts.h	Sun Dec 23 13:56:53 2001
@@ -65,5 +65,12 @@
 #define change_ldt(a,b) setup_arg_pages(a,b)
 #endif
 
+#ifdef CONFIG_MOSIX
+extern void execve_remote_counts(char **, char **, int *, int *);
+extern int execve_remote_bring_strings(struct linux_binprm *, char **, char **);
+extern unsigned long *create_aout_tables(char *, struct linux_binprm *);
+extern int exec_mmap(void);
+#endif /* CONFIG_MOSIX */
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_BINFMTS_H */
diff -ruN linux-2.4.16/include/linux/capability.h linux-2.4.16-mosix/include/linux/capability.h
--- linux-2.4.16/include/linux/capability.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/capability.h	Sun Dec 23 13:56:53 2001
@@ -348,6 +348,11 @@
 
 #define cap_is_fs_cap(c)     (CAP_TO_MASK(c) & CAP_FS_MASK)
 
+#ifdef CONFIG_MOSIX
+#define	REMOTE_CAPS	(CAP_FS_MASK | CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | \
+						CAP_TO_MASK(CAP_SYS_RESOURCE))
+#endif /* CONFIG_MOSIX */
+
 #endif /* __KERNEL__ */
 
 #endif /* !_LINUX_CAPABILITY_H */
diff -ruN linux-2.4.16/include/linux/completion.h linux-2.4.16-mosix/include/linux/completion.h
--- linux-2.4.16/include/linux/completion.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/completion.h	Sun Dec 23 13:56:53 2001
@@ -28,6 +28,9 @@
 }
 
 extern void FASTCALL(wait_for_completion(struct completion *));
+#ifdef CONFIG_MOSIX
+extern void FASTCALL(wait_for_completion_half_interruptible(struct completion *));
+#endif /* CONFIG_MOSIX */
 extern void FASTCALL(complete(struct completion *));
 
 #define INIT_COMPLETION(x)	((x).done = 0)
diff -ruN linux-2.4.16/include/linux/dcache.h linux-2.4.16-mosix/include/linux/dcache.h
--- linux-2.4.16/include/linux/dcache.h	Thu Nov 22 21:46:18 2001
+++ linux-2.4.16-mosix/include/linux/dcache.h	Sun Dec 23 13:56:53 2001
@@ -124,6 +124,10 @@
 					 */
 #define DCACHE_REFERENCED	0x0008  /* Recently used, don't discard. */
 
+#ifdef CONFIG_MOSIX_FS
+#define	DCACHE_NO_CACHE	      0x0010	/* do not hash, do not cache */
+#endif /* CONFIG_MOSIX_FS */
+
 extern spinlock_t dcache_lock;
 
 /**
diff -ruN linux-2.4.16/include/linux/dfsa_interface.h linux-2.4.16-mosix/include/linux/dfsa_interface.h
--- linux-2.4.16/include/linux/dfsa_interface.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/dfsa_interface.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+/* DFSA definitions and functions required anywhere outside of MOSIX */
+#ifndef _MOS_DFSA_INTERFACE_H
+#define _MOS_DFSA_INTERFACE_H
+
+#ifdef CONFIG_MOSIX_DFSA
+
+/* update flags (dupdates): */
+
+#define	DFSA_UPDCRED	1	/* need to update credentials */
+#define	DFSA_UPDTABLE	2	/* need to update DFSA table */
+#define	DFSA_UPDCDIR	4	/* need to update current-directory */
+#define	DFSA_UPDMAX	8	/* need to update "max_fdset" */
+#define	DFSA_UPDCLOSE	16	/* need to update closed files */
+#define	DFSA_UPDOPEN	32	/* need to update opened files */
+#define	DFSA_UPDMODS	64	/* need to update modified files */
+#define	DFSA_UPDUSED	128	/* need to update the "used" bits */
+#define	DFSA_UPDSEL	256	/* need to update MFS node-selections */
+#define	DFSA_UPDUMASK	512	/* need to update umask */
+
+#define	DFSA_UPDATE	(DFSA_UPDCRED|DFSA_UPDTABLE|DFSA_UPDCDIR|DFSA_UPDMAX|\
+			 DFSA_UPDCLOSE|DFSA_UPDOPEN|DFSA_UPDMODS|DFSA_UPDUSED|\
+			 DFSA_UPDSEL|DFSA_UPDUMASK)
+
+#define CAN_DFSA(p)	((p)->fs && atomic_read(&(p)->fs->users) == 1 && \
+			!(p)->fs->altroot && \
+			(p)->files && atomic_read(&(p)->files->users) == 1 && \
+			(p)->fs->root == init_task.fs->root && \
+			(p)->fs->rootmnt == init_task.fs->rootmnt && \
+			!((p)->ptrace) && !(p->flags & PF_EXITING))
+
+/* adjust the following if any file-system requires more identifying bytes: */
+#define	MAX_IDENT_RECORD_LEN	20
+
+struct vfsmount;
+struct dentry;
+struct nameidata;
+struct file;
+
+void dfsa_init(void);
+int dfsa_setmnt(struct vfsmount *, int, unsigned long);
+int dfsa_option(char *, int *);
+void dfsa_close_file(int);
+void dfsa_open_file(int);
+void dfsa_touch_file(int);
+void dfsa_is_not_up_to_date(void);
+void dfsa_pwd_changed(void);
+int can_dfsa_file(int);
+void dfsa_syscall_on_file(int, int);
+int name_starts_in_dfsa(char **, struct nameidata *);
+int within_dfsa(struct nameidata *);
+int dfsa_optimized_read(struct file *, loff_t, unsigned long, unsigned long);
+int disable_dfsa(void);
+void enable_dfsa(void);
+
+#endif /* CONFIG_MOSIX_DFSA */
+#endif
diff -ruN linux-2.4.16/include/linux/elf.h linux-2.4.16-mosix/include/linux/elf.h
--- linux-2.4.16/include/linux/elf.h	Thu Nov 22 21:48:29 2001
+++ linux-2.4.16-mosix/include/linux/elf.h	Sun Dec 23 13:56:53 2001
@@ -607,5 +607,18 @@
 
 #endif
 
+#ifdef CONFIG_MOSIX
+#ifdef __KERNEL__
+struct elf_tables_extras
+{
+	int uid, euid, gid, egid;
+	long hwcap;
+	char platform[8];
+};
+
+extern unsigned long elf_remote_setup(char *, int, int, struct elfhdr *, unsigned long, unsigned long, unsigned long, int, int, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, struct elf_tables_extras *);
+extern int elf_maydump(struct vm_area_struct *);
+#endif /*__KERNEL__*/
+#endif /* CONFIG_MOSIX */
 
 #endif /* _LINUX_ELF_H */
diff -ruN linux-2.4.16/include/linux/errno.h linux-2.4.16-mosix/include/linux/errno.h
--- linux-2.4.16/include/linux/errno.h	Sat Feb 10 00:46:13 2001
+++ linux-2.4.16-mosix/include/linux/errno.h	Sun Dec 23 13:56:53 2001
@@ -21,6 +21,10 @@
 #define EBADTYPE	527	/* Type not supported by server */
 #define EJUKEBOX	528	/* Request initiated, but will not complete before timeout */
 
+#ifdef CONFIG_MOSIX
+#define	EDOITATHOME	550
+#endif /* CONFIG_MOSIX */
+
 #endif
 
 #endif
diff -ruN linux-2.4.16/include/linux/file.h linux-2.4.16-mosix/include/linux/file.h
--- linux-2.4.16/include/linux/file.h	Wed Aug 23 21:22:26 2000
+++ linux-2.4.16-mosix/include/linux/file.h	Sun Dec 23 13:56:53 2001
@@ -5,6 +5,10 @@
 #ifndef __LINUX_FILE_H
 #define __LINUX_FILE_H
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 extern void FASTCALL(fput(struct file *));
 extern struct file * FASTCALL(fget(unsigned int fd));
  
@@ -93,6 +97,9 @@
 		BUG();
 	files->fd[fd] = file;
 	write_unlock(&files->file_lock);
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_open_file(fd);
+#endif /* CONFIG_MOSIX_DFSA */
 }
 
 void put_files_struct(struct files_struct *fs);
diff -ruN linux-2.4.16/include/linux/fs.h linux-2.4.16-mosix/include/linux/fs.h
--- linux-2.4.16/include/linux/fs.h	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/include/linux/fs.h	Sun Dec 23 13:56:53 2001
@@ -150,7 +150,12 @@
  */
 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
 
+#if defined(CONFIG_MOSIX_FS) && defined(__KERNEL__)
+#define IS_RDONLY(inode) (((inode)->i_sb->s_flags & MS_RDONLY) || \
+				(current->mosix.dirty_bits & MFSARG_RONLY))
+#else
 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
+#endif /* CONFIG_MOSIX_FS && __KERNEL__ */
 #define IS_SYNC(inode)		(__IS_FLG(inode, MS_SYNCHRONOUS) || ((inode)->i_flags & S_SYNC))
 #define IS_MANDLOCK(inode)	__IS_FLG(inode, MS_MANDLOCK)
 
@@ -315,6 +320,12 @@
 #include <linux/usbdev_fs_i.h>
 #include <linux/jffs2_fs_i.h>
 #include <linux/cramfs_fs_sb.h>
+#ifdef CONFIG_MOSIX
+#include <linux/remote_fs_i.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs_fs_i.h>
+#endif /* CONFIG_MOSIX_FS */
+#endif /* CONFIG_MOSIX */
 
 /*
  * Attribute flags.  These should be or-ed together to figure out what
@@ -506,7 +517,16 @@
 		struct usbdev_inode_info        usbdev_i;
 		struct jffs2_inode_info		jffs2_i;
 		void				*generic_ip;
+#ifdef CONFIG_MOSIX
+		struct remote_inode_info	remote_i;
+#ifdef CONFIG_MOSIX_FS
+		struct mfs_inode_info		mfs_i;
+#endif /* CONFIG_MOSIX_FS */
+#endif /* CONFIG_MOSIX */
 	} u;
+#ifdef CONFIG_MOSIX
+	uint64_t		i_unique;
+#endif /* CONFIG_MOSIX */
 };
 
 struct fown_struct {
@@ -643,6 +663,45 @@
 	struct qstr last;
 	unsigned int flags;
 	int last_type;
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	char *name_left;
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_FS
+	unsigned short express_function;
+	union complete_args
+	{
+		struct
+		{
+			int i1;
+			int i2;
+		} ints;
+		struct
+		{
+			time_t a;
+			time_t m;
+		} times;
+		struct
+		{
+			uid_t uid;
+			gid_t gid;
+		} ids;
+		struct
+		{
+			int mode;
+			dev_t dev;
+		} mknod;
+		mode_t mode;
+		loff_t len;
+		struct
+		{
+			char *buf;
+			int bufsiz;
+		} buffer;
+		struct nameidata *oldnd;
+	} complete_args;
+	void *complete_parg;
+	unsigned int complete_flags;
+#endif /* CONFIG_MOSIX_FS */
 };
 
 #define DQUOT_USR_ENABLED	0x01		/* User diskquotas enabled */
@@ -852,6 +911,12 @@
 	int (*revalidate) (struct dentry *);
 	int (*setattr) (struct dentry *, struct iattr *);
 	int (*getattr) (struct dentry *, struct iattr *);
+#ifdef CONFIG_MOSIX_FS
+	int (*express_lookup) (struct nameidata *, char **);
+#endif /* CONFIG_MOSIX_FS */
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	void (*check_path) (struct dentry *);
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 };
 
 /*
@@ -905,6 +970,11 @@
 	 */
 	struct dentry * (*fh_to_dentry)(struct super_block *sb, __u32 *fh, int len, int fhtype, int parent);
 	int (*dentry_to_fh)(struct dentry *, __u32 *fh, int *lenp, int need_parent);
+#ifdef CONFIG_MOSIX_DFSA
+	int (*identify) (struct dentry *, void *);
+	struct dentry * (*reconstruct) (struct vfsmount *, void *, int);
+	void (*dfsa_changed) (struct vfsmount *, int);
+#endif /* CONFIG_MOSIX_DFSA */
 };
 
 /* Inode state bits.. */
@@ -1274,6 +1344,46 @@
 #define LOOKUP_POSITIVE		(8)
 #define LOOKUP_PARENT		(16)
 #define LOOKUP_NOALT		(32)
+
+#ifdef CONFIG_MOSIX_DFSA
+#define	LOOKUP_STAYFS		(64)
+#define	LOOKUP_DOITATHOME	(128)
+#define	LOOKUP_REPLACENAME	(256)
+#else
+#define	LOOKUP_STAYFS		(0)
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+#define	LOOKUP_MFS		(512)
+#define	LOOKUP_COMPLETE		(1024)
+#define	LOOKUP_MFS_MFS		(2048)
+
+/* complete_flags: */
+#define	COMPLETE_DONE		1
+#define	COMPLETE_MAGICAL	2
+
+/* express functions: */
+enum express_functions
+{
+	EF_OPEN = 1,
+	EF_ACCESS,
+	EF_LINK,
+	EF_UNLINK,
+	EF_SYMLINK,
+	EF_MKDIR,
+	EF_RMDIR,
+	EF_RENAME,
+	EF_READLINK,
+	EF_TRUNCATE,
+	EF_UTIME,
+	EF_UTIMES,
+	EF_CHMOD,
+	EF_CHOWN,
+	EF_STAT,
+	EF_MKNOD,
+};
+
+#endif /* CONFIG_MOSIX_FS */
+
 /*
  * Type of the last component on LOOKUP_PARENT
  */
@@ -1579,6 +1689,16 @@
 	dput(d2);
 }
 
+#ifdef CONFIG_MOSIX
+extern spinlock_t unique_gen_lock;
+extern uint64_t unique_generator;
+#define	VMODIFIED(_ip)	do { \
+				spin_lock(&unique_gen_lock); \
+				_ip->i_unique = ++unique_generator; \
+				spin_unlock(&unique_gen_lock); \
+			} while(0)
+#endif /* CONFIG_MOSIX */
+
 #endif /* __KERNEL__ */
 
 #endif /* _LINUX_FS_H */
diff -ruN linux-2.4.16/include/linux/fs_struct.h linux-2.4.16-mosix/include/linux/fs_struct.h
--- linux-2.4.16/include/linux/fs_struct.h	Sat Jul 14 01:10:44 2001
+++ linux-2.4.16-mosix/include/linux/fs_struct.h	Sun Dec 23 13:56:53 2001
@@ -2,12 +2,24 @@
 #define _LINUX_FS_STRUCT_H
 #ifdef __KERNEL__
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 struct fs_struct {
 	atomic_t count;
 	rwlock_t lock;
 	int umask;
 	struct dentry * root, * pwd, * altroot;
 	struct vfsmount * rootmnt, * pwdmnt, * altrootmnt;
+#ifdef CONFIG_MOSIX_DFSA
+	atomic_t users;
+	short count_dropped_to_one;
+	short pwd_changed;
+#define	INIT_FS_DFSA	, ATOMIC_INIT(1), 0, 0
+#else
+#define	INIT_FS_DFSA
+#endif /* CONFIG_MOSIX_DFSA */
 };
 
 #define INIT_FS { \
@@ -15,6 +27,7 @@
 	RW_LOCK_UNLOCKED, \
 	0022, \
 	NULL, NULL, NULL, NULL, NULL, NULL \
+	INIT_FS_DFSA \
 }
 
 extern void exit_fs(struct task_struct *);
@@ -41,6 +54,9 @@
 		dput(old_root);
 		mntput(old_rootmnt);
 	}
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_is_not_up_to_date();
+#endif /* CONFIG_MOSIX_DFSA */
 }
 
 /*
@@ -60,6 +76,10 @@
 	fs->pwdmnt = mntget(mnt);
 	fs->pwd = dget(dentry);
 	write_unlock(&fs->lock);
+#ifdef CONFIG_MOSIX_DFSA
+	if(fs->pwdmnt != old_pwdmnt || fs->pwd != old_pwd)
+		dfsa_pwd_changed();
+#endif /* CONFIG_MOSIX_DFSA */
 	if (old_pwd) {
 		dput(old_pwd);
 		mntput(old_pwdmnt);
@@ -68,6 +88,9 @@
 
 struct fs_struct *copy_fs_struct(struct fs_struct *old);
 void put_fs_struct(struct fs_struct *fs);
+#ifdef CONFIG_MOSIX_DFSA
+void put_used_fs_struct(struct fs_struct *fs);
+#endif /* CONFIG_MOSIX_DFSA */
 
 #endif
 #endif
diff -ruN linux-2.4.16/include/linux/iobuf.h linux-2.4.16-mosix/include/linux/iobuf.h
--- linux-2.4.16/include/linux/iobuf.h	Thu Nov 22 21:46:26 2001
+++ linux-2.4.16-mosix/include/linux/iobuf.h	Sun Dec 23 13:56:53 2001
@@ -56,6 +56,9 @@
 	int		errno;		/* Status of completed IO */
 	void		(*end_io) (struct kiobuf *); /* Completion callback */
 	wait_queue_head_t wait_queue;
+#ifdef CONFIG_MOSIX
+	struct mm_struct *mm;
+#endif /* CONFIG_MOSIX */
 };
 
 
diff -ruN linux-2.4.16/include/linux/keyboard.h linux-2.4.16-mosix/include/linux/keyboard.h
--- linux-2.4.16/include/linux/keyboard.h	Thu Nov 22 21:47:07 2001
+++ linux-2.4.16-mosix/include/linux/keyboard.h	Sun Dec 23 13:56:53 2001
@@ -329,6 +329,10 @@
 #define K_SPAWNCONSOLE	K(KT_SPEC,18)
 #define K_BARENUMLOCK	K(KT_SPEC,19)
 
+#ifdef CONFIG_MOSIX_UDB
+#define	K_DEBUGGER	K(KT_SPEC,20)
+#endif /* CONFIG_MOSIX_UDB */
+
 #define K_ALLOCATED	K(KT_SPEC,126) /* dynamically allocated keymap */
 #define K_NOSUCHMAP	K(KT_SPEC,127) /* returned by KDGKBENT */
 
diff -ruN linux-2.4.16/include/linux/linkage.h linux-2.4.16-mosix/include/linux/linkage.h
--- linux-2.4.16/include/linux/linkage.h	Mon Dec 11 22:49:54 2000
+++ linux-2.4.16-mosix/include/linux/linkage.h	Sun Dec 23 13:56:53 2001
@@ -10,7 +10,13 @@
 #endif
 
 #if defined __i386__
+#if defined(CONFIG_MOSIX)
+/* there is a bug in egcs-2.91.66 using "regparm(0)" */
+/* it often crashes the compiler on some MOSIX files */
+#define asmlinkage CPP_ASMLINKAGE
+#else
 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
+#endif /* CONFIG_MOSIX */
 #elif defined __ia64__
 #define asmlinkage CPP_ASMLINKAGE __attribute__((syscall_linkage))
 #else
diff -ruN linux-2.4.16/include/linux/mfs.h linux-2.4.16-mosix/include/linux/mfs.h
--- linux-2.4.16/include/linux/mfs.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/mfs.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,465 @@
+#ifndef _MFS_H
+#define _MFS_H
+
+#include <linux/mfs_fs_i.h>
+
+#define	MFS_VERSION	2
+
+#define	MFS_GARBAGE_TIME (2700*HZ)
+#define	MFS_REPORT_TIME	(MFS_GARBAGE_TIME/3)
+
+#define	MFS_MAXBLOCK	16384
+
+struct mfs_server_contact;
+struct mfs_client_contact;
+
+struct mfs_completion
+{
+	unsigned char needed;
+	unsigned char done;
+	unsigned char func;
+	unsigned char ro;
+	int base_pe;
+	mfs_handle_t base;
+	mfs_handle_t dispose_base;
+	int other_pe;
+	mfs_handle_t other;
+	mfs_handle_t dispose_other;
+	union complete_args args;
+	void *more_data;
+	int more_data_len;
+	int error;
+};
+
+struct subinode
+{
+	unsigned long		si_ino;
+	unsigned int		si_count;
+	umode_t			si_mode;
+	nlink_t			si_nlink;
+	uid_t			si_iuid;
+	gid_t			si_gid;
+	kdev_t			si_rdev;
+	loff_t			si_size;
+	time_t			si_atime;
+	time_t			si_mtime;
+	time_t			si_ctime;
+	unsigned long		si_blksize;
+	unsigned long		si_blocks;
+	unsigned long		si_origino;
+	kdev_t			si_origdev;
+};
+
+struct mfs_dinfo
+{
+	int pe;
+	mfs_handle_t handle;
+	unsigned long latest;
+};
+
+extern int init_mfs(void);
+extern void mfs_change_pe(void);
+extern void mfs_change_root(struct dentry *, struct vfsmount *, struct dentry *, struct vfsmount *);
+extern int is_mfs_root(struct nameidata *);
+extern int mfs_walk_init_root(struct nameidata *);
+extern void mfs_ip_to_subip(struct subinode *, struct inode *);
+extern void mfs_subip_to_ip(struct inode *, struct subinode *);
+extern int mfs_conversion_init(void);
+extern mfs_handle_t local_to_mfs(struct nameidata *);
+extern int mfs_to_local(mfs_handle_t, struct nameidata *);
+extern int mfs_get_handle(mfs_handle_t handle);
+extern void mfs_put_handle(mfs_handle_t handle);
+extern int mfs_access_handle(mfs_handle_t handle);
+extern void mfs_lput(struct dentry *, struct vfsmount *);
+extern int mfs_try_to_cleanup(int);
+extern int mfs_attach_handle(int, mfs_handle_t);
+extern void mfs_dispose_handle(int, mfs_handle_t);
+extern int mfs_touch_handle(int, mfs_handle_t);
+extern ino_t global_inum(struct inode *);
+extern void cp_file_fields(struct file *, struct file *);
+
+extern loff_t mfs_low_llseek(mfs_handle_t, struct file *, loff_t, int);
+extern ssize_t mfs_low_read(mfs_handle_t, struct file *, char *, size_t, loff_t *);
+extern ssize_t mfs_low_write(mfs_handle_t, struct file *, char *, size_t, loff_t *, long);
+extern int mfs_low_readdir(mfs_handle_t, struct file *, void *, filldir_t, int *, int *);
+extern int mfs_low_ioctl(mfs_handle_t, struct file *, unsigned int, unsigned long, int, int *);
+extern int mfs_low_open(mfs_handle_t, struct file *);
+extern int mfs_low_fsync(mfs_handle_t, struct file *, int);
+extern int mfs_low_attach_handle(mfs_handle_t);
+extern int mfs_low_touch_handle(mfs_handle_t);
+extern void mfs_low_dispose_handle(mfs_handle_t);
+extern int mfs_low_revalidate(mfs_handle_t, struct subinode *);
+extern int mfs_low_express_lookup(mfs_handle_t *, char *, unsigned int, int, int, struct subinode *, char **, struct mfs_completion *);
+extern int mfs_low_setattr(mfs_handle_t, struct iattr *);
+extern char *mfs_low_check_path(mfs_handle_t);
+
+extern void mfs_prepare_completion(struct mfs_completion *, struct nameidata *);
+extern int mfs_check_completion(struct mfs_completion *, struct nameidata *);
+extern mfs_handle_t mfs_low_complete(struct mfs_completion *, struct nameidata *);
+extern void mfs_low_complete_error(struct mfs_completion *, int);
+extern int mfs_link_complete(struct mfs_completion *, int, struct nameidata *);
+
+extern struct dentry *mfs_root;
+extern struct vfsmount *mfs_mnt;
+extern ino_t mfs_root_ino;
+extern dev_t mfs_root_dev;
+extern struct super_block *mfs_super;
+extern int MFS_PE;
+extern int mfs_debug;
+extern char mfs_is_ro;
+#ifdef CONFIG_MOSIX_DFSA
+extern char mfs_is_dfsa;
+#endif /* CONFIG_MOSIX_DFSA */
+
+#define	MFS_SUPER_MAGIC	235466776
+#define	MFS_BAD_PE	65536
+#define	MFS_UNKNOWN_PE	65537
+#define	MFS_ROOT_INO	65538
+
+/* protocols: */
+
+enum
+{
+	MFS_NONE = 0,
+	MFS_CLOSE,
+	MFS_CONTINUE,
+	MFS_STOP,
+	MFS_INTERIM_DATA,
+	MFS_REQUEST_LLSEEK,
+	MFS_REPLY_LLSEEK,
+	MFS_REQUEST_READ,
+	MFS_REPLY_READ,
+	MFS_REQUEST_WRITE,
+	MFS_REPLY_WRITE,
+	MFS_REQUEST_READDIR,
+	MFS_INTERIM_READDIR,
+	MFS_REPLY_READDIR,
+	MFS_REQUEST_IOCTL,
+	MFS_REPLY_IOCTL,
+	MFS_REQUEST_FSYNC,
+	MFS_REPLY_FSYNC,
+	MFS_REQUEST_REVALIDATE,
+	MFS_REPLY_REVALIDATE,
+	MFS_REQUEST_EXPRESS,
+	MFS_REPLY_EXPRESS,
+	MFS_REQUEST_CHECKPATH,
+	MFS_REPLY_CHECKPATH,
+	MFS_REQUEST_SETATTR,
+	MFS_REPLY_SETATTR,
+	MFS_REQUEST_ATTACH_HANDLE,
+	MFS_REPLY_ATTACH_HANDLE,
+	MFS_REQUEST_TOUCH_HANDLE,
+	MFS_REPLY_TOUCH_HANDLE,
+	MFS_REQUEST_DISPOSE_HANDLE,
+};
+
+struct mfs_cred
+{
+	uid_t uid, euid, suid, fsuid;
+	gid_t gid, egid, sgid, fsgid;
+	int ngroups;
+	gid_t groups[NGROUPS];
+	kernel_cap_t caps;
+	int whereami;
+	int deppe;
+};
+
+struct mfs_request_llseek
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+	loff_t offset;
+	int origin;
+};
+
+struct mfs_reply_llseek
+{
+	struct file file;
+	int result;
+};
+
+struct mfs_request_read
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+	size_t count;
+	loff_t pos;
+};
+
+struct mfs_interim_data
+{
+	size_t count;
+};
+
+struct mfs_reply_read
+{
+	struct file file;
+	loff_t ppos;
+	ssize_t result;
+	size_t datalen;
+};
+
+struct mfs_request_write
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+	size_t count;
+	loff_t pos;
+	size_t datalen;
+	long flim;
+};
+
+struct mfs_reply_write
+{
+	struct file file;
+	loff_t ppos;
+	ssize_t result;
+	int hadsigxfsz;
+};
+
+struct mfs_request_readdir
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+	int policy;
+	int maxbytes;
+};
+
+#define	MFS_READDIR_UNKNOWN	0
+#define	MFS_READDIR_JUSTONE	1
+#define	MFS_READDIR_GETDENTS	2
+#define	MFS_READDIR_GETDENTS64	3
+
+struct mfs_interim_readdir
+{
+	int error;
+};
+
+struct mfs_reply_readdir
+{
+	struct file file;
+	int result;
+	int datalen;
+};
+
+struct mfs_request_ioctl
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+	unsigned int cmd;
+	unsigned long arg;
+	int data;
+	int size;
+};
+
+struct mfs_reply_ioctl
+{
+	struct file file;
+	int data;
+	int result;
+};
+
+struct mfs_request_open
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+};
+
+struct mfs_reply_open
+{
+	struct file file;
+	int result;
+};
+
+struct mfs_request_fsync
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct file file;
+	int datasync;
+};
+
+struct mfs_reply_fsync
+{
+	struct file file;
+	int result;
+};
+
+struct mfs_request_revalidate
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+};
+
+struct mfs_reply_revalidate
+{
+	struct subinode iinfo;
+	int result;
+};
+
+struct mfs_request_express
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	int namelen;
+	unsigned int follow;
+	int link_count;
+	int total_link_count;
+	struct mfs_completion complete;
+};
+
+struct mfs_reply_express
+{
+	mfs_handle_t handle;
+	struct subinode iinfo;
+	int namelen;
+	struct mfs_completion complete;
+	int result;
+};
+
+struct mfs_request_checkpath
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+};
+
+struct mfs_reply_checkpath
+{
+	int namelen;
+};
+
+struct mfs_request_setattr
+{
+	struct mfs_cred cred;
+	mfs_handle_t handle;
+	struct iattr attr;
+};
+
+struct mfs_reply_setattr
+{
+	int result;
+};
+
+struct mfs_request_attach_handle
+{
+	mfs_handle_t handle;
+};
+
+struct mfs_reply_attach_handle
+{
+	int result;
+};
+
+struct mfs_request_touch_handle
+{
+	mfs_handle_t handle;
+};
+
+struct mfs_reply_touch_handle
+{
+	int result;
+};
+
+struct mfs_request_dispose_handle
+{
+	mfs_handle_t handle;
+};
+
+struct mfs_server_contact *mfs_alloc_service(void);
+void mfs_release_contact(struct mfs_client_contact *);
+int mfs_client_contact_has_data(struct mfs_client_contact *);
+void mfs_end_serve(struct mfs_server_contact *);
+int mfs_server_send(struct mfs_server_contact *, int, void *, int, void *, int, void *, int);
+int mfs_client_send(struct mfs_client_contact *, int, void *, int, void *, int, void *, int);
+int mfs_server_receive(struct mfs_server_contact *, void **, void **, void **);
+int mfs_client_receive(struct mfs_client_contact *, void **, void **, void **);
+struct mfs_client_contact *mfs_new_request(int, int, void *, int, void *, int, void *, int);
+void mfs_make_servers(void);
+void mfs_new_request_arrived(void);
+void mfs_serve(struct mfs_server_contact *, int, void *, void *, void *);
+
+int mfs_client_attach_handle(int, mfs_handle_t);
+void mfs_client_dispose_handle(int, mfs_handle_t);
+int mfs_client_touch_handle(int, mfs_handle_t);
+int mfs_client_llseek(int, mfs_handle_t, struct file *, loff_t, int);
+ssize_t mfs_client_read(int, mfs_handle_t, struct file *, char *, size_t, loff_t *);
+ssize_t mfs_client_write(int, mfs_handle_t, struct file *, char *, size_t, loff_t *, long);
+int mfs_client_readdir(int, mfs_handle_t, struct file *, void *, filldir_t, int, int, int *, int *);
+int mfs_client_ioctl(int, mfs_handle_t, struct file *, unsigned int, unsigned long, int, int *);
+int mfs_client_open(int, mfs_handle_t, struct file *);
+int mfs_client_fsync(int, mfs_handle_t, struct file *, int);
+int mfs_client_revalidate(int, mfs_handle_t, struct subinode *);
+int mfs_client_express_lookup(int, mfs_handle_t *, char *, unsigned int, struct subinode *, char **, struct mfs_completion *);
+char *mfs_client_check_path(int, mfs_handle_t);
+int mfs_client_setattr(int, mfs_handle_t, struct iattr *);
+void mfs_throw_garbage(void);
+int mfs_client_daemon(void *);
+int mfs_kill(char *);
+void mfs_tuneinfo(char *);
+#ifdef CONFIG_MOSIX_DFSA
+int mfs_add_stats(struct mfs_stats *, struct mfs_stats *, struct mosix_task *);
+#else
+static inline int mfs_add_stats(struct mfs_stats *x, struct mfs_stats *y, struct mosix_task *z)
+{
+	return(0);
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
+extern struct task_struct *mfs_main_server_task;
+
+static inline int
+file_is_mfs(struct file *file)
+{
+	struct dentry *dp;
+	struct inode *ip;
+	struct super_block *sb;
+
+	return(file && (dp = file->f_dentry) && (ip = dp->d_inode) &&
+		(sb = ip->i_sb) && sb->s_magic == MFS_SUPER_MAGIC);
+}
+
+/* statistic collection: */
+
+#ifdef CONFIG_MOSIX_DFSA
+extern void mfs_count(int, int, int);
+
+#define	mfs_count_attach_handle(w)	mfs_count(w, 0, 0)
+#define	mfs_count_touch_handle(w)	mfs_count(w, 0, 0)
+#define	mfs_count_dispose_handle(w)	mfs_count(w, 0, 0)
+#define	mfs_count_llseek(w)		mfs_count(w, 0, 0)
+#define	mfs_count_read(w,n)		mfs_count(w, n, 0)
+#define	mfs_count_write(w,n)		mfs_count(w, 0, n)
+#define	mfs_count_readdir(w,p,b)	mfs_count(w, b, (p) * sizeof(int))
+#define	mfs_count_ioctl(w)		mfs_count(w, 0, 0)
+#define	mfs_count_open(w)		mfs_count(w, 0, 0)
+#define	mfs_count_fsync(w)		mfs_count(w, 0, 0)
+#define	mfs_count_setattr(w)		mfs_count(w, 0, 0)
+#define	mfs_count_revalidate(w)		mfs_count(w, 0, 0)
+#define	mfs_count_express(w,l) 		mfs_count(w, 0, l)
+#define	mfs_count_check_path(w,l)	mfs_count(w, 0, l)
+#define	mfs_count_notify_change(w)	mfs_count(w, 0, 0)
+#else
+#define	mfs_count_attach_handle(w)	do {} while(0)
+#define	mfs_count_touch_handle(w)	do {} while(0)
+#define	mfs_count_dispose_handle(w)	do {} while(0)
+#define	mfs_count_llseek(w)		do {} while(0)
+#define	mfs_count_read(w,n)		do {} while(0)
+#define	mfs_count_write(w,n)		do {} while(0)
+#define	mfs_count_readdir(w,p,b)	do {} while(0)
+#define	mfs_count_ioctl(w)		do {} while(0)
+#define	mfs_count_open(w)		do {} while(0)
+#define	mfs_count_fsync(w)		do {} while(0)
+#define	mfs_count_setattr(w)		do {} while(0)
+#define	mfs_count_revalidate(w)		do {} while(0)
+#define	mfs_count_express(w,l)	do {} while(0)
+#define	mfs_count_check_path(w,l)	do {} while(0)
+#define	mfs_count_notify_change(w)	do {} while(0)
+#endif /* CONFIG_MOSIX_DFSA */
+
+#endif /* _MFS_H */
diff -ruN linux-2.4.16/include/linux/mfs_fs_i.h linux-2.4.16-mosix/include/linux/mfs_fs_i.h
--- linux-2.4.16/include/linux/mfs_fs_i.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/mfs_fs_i.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#ifndef _LINUX_MFS_FS_I_H
+#define _LINUX_MFS_FS_I_H
+#ifdef CONFIG_MOSIX
+
+typedef unsigned long long mfs_handle_t;
+
+struct mfs_inode_info
+{
+	int pe;
+	mfs_handle_t handle;
+};
+
+#endif /* CONFIG_MOSIX */
+#endif
diff -ruN linux-2.4.16/include/linux/mfs_socket.h linux-2.4.16-mosix/include/linux/mfs_socket.h
--- linux-2.4.16/include/linux/mfs_socket.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/mfs_socket.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,40 @@
+#ifndef _MFS_SOCKET_H
+#define _MFS_SOCKET_H
+
+struct socket;
+
+struct mfs_message_header
+{
+	char version;
+	char first;
+	short hdsz;
+	int caller;
+	int serial;
+	int type;
+	int dat1sz;
+	int dat2sz;
+};
+
+struct socket *mfs_open_main_socket(void);
+struct socket *mfs_new_connection(struct socket *, int *);
+struct socket *mfs_connect_to(int);
+int mfs_socket_has_data(struct socket *);
+int mfs_socket_is_closed(struct socket *);
+int mfs_send(struct socket *, int, int, int, void *, int, void *, int, void *, int);
+int mfs_receive(struct socket *, int, int *, struct mfs_message_header *, void **, void **, void **);
+int mfs_set_main_ownership(struct socket *, int);
+void mfs_close_socket(struct socket *);
+void mfs_monitor_client_contacts(void);
+
+/* 2nd parameter of mfs_receive: */
+enum
+{
+	MFS_FIRST_RECEIVE,	/* obtain serial */
+	MFS_MUST_MATCH,		/* fail if serial does not match */
+	MFS_SKIP_OTHERS,	/* skip packet if serial does not match */
+	MFS_JUST_HEADER		/* preliminary header check */
+};
+
+#define	MFS_MAIN_PORT	0xD302
+
+#endif /* _MFS__SOCKET_H */
diff -ruN linux-2.4.16/include/linux/mm.h linux-2.4.16-mosix/include/linux/mm.h
--- linux-2.4.16/include/linux/mm.h	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/include/linux/mm.h	Sun Dec 23 13:56:53 2001
@@ -165,6 +165,10 @@
 	void *virtual;			/* Kernel virtual address (NULL if
 					   not kmapped, ie. highmem) */
 	struct zone_struct *zone;	/* Memory zone we are in. */
+#ifdef CONFIG_MOSIX
+	char young;
+	unsigned long last_young;
+#endif /* CONFIG_MOSIX */
 } mem_map_t;
 
 /*
@@ -506,6 +510,48 @@
 		return 0;
 }
 
+#ifdef CONFIG_MOSIX
+static inline unsigned long
+do_mmap_pgoff_down(struct file *file, unsigned long addr, unsigned long len,
+	unsigned long prot, unsigned long flag, unsigned long pgoff)
+{
+	int initially_local = !(current->mosix.dflags & DDEPUTY);
+	struct mm_struct *mm = current->mm;
+	unsigned long result;
+
+	if(initially_local)
+	{
+		down_write(&mm->mmap_sem);
+#ifdef CONFIG_MOSIX_FS
+		current->mosix.dirty_bits |= MMAP_MMDOWNED;
+#endif /* CONFIG_MOSIX_FS */
+	}
+	result = do_mmap_pgoff(file, addr, len, prot, flag, pgoff);
+	if(initially_local)
+	{
+		up_write(&mm->mmap_sem);
+#ifdef CONFIG_MOSIX_FS
+		current->mosix.dirty_bits &= ~MMAP_MMDOWNED;
+#endif /* CONFIG_MOSIX_FS */
+	}
+	return(result);
+}
+
+static inline unsigned long do_mmap_down(struct file *file, unsigned long addr,
+	unsigned long len, unsigned long prot,
+	unsigned long flag, unsigned long offset)
+{
+	unsigned long ret = -EINVAL;
+	if ((offset + PAGE_ALIGN(len)) < offset)
+		goto out;
+	if (!(offset & ~PAGE_MASK))
+		ret = do_mmap_pgoff_down(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
+out:
+	return ret;
+}
+
+#endif /* CONFIG_MOSIX */
+
 struct zone_t;
 /* filemap.c */
 extern void remove_inode_page(struct page *);
diff -ruN linux-2.4.16/include/linux/mosctl.h linux-2.4.16-mosix/include/linux/mosctl.h
--- linux-2.4.16/include/linux/mosctl.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/mosctl.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan.
+ */
+#ifndef _LINUX_MOSCTL_H
+#define _LINUX_MOSCTL_H
+
+#ifdef __KERNEL__
+#include <linux/socket.h>
+#else
+#include <sys/socket.h>
+#endif /*__KERNEL__*/
+
+#include <mos/mosctl.h>
+
+/* configuration */
+
+#define MOSIX_MAX	65535
+#define MAX_MOSNET_ENTS	256
+
+struct mosixnet
+{
+	int base;
+	struct sockaddr saddr;
+	int cnt;
+};
+
+
+#endif
diff -ruN linux-2.4.16/include/linux/mosix.h linux-2.4.16-mosix/include/linux/mosix.h
--- linux-2.4.16/include/linux/mosix.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/mosix.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#ifndef _LINUX_MOSIX_H
+#define _LINUX_MOSIX_H
+
+#ifdef CONFIG_MOSIX
+
+#ifdef __KERNEL__
+
+#include <linux/sched.h>
+#include <linux/user.h>
+#include <linux/elf.h>
+#include <mos/defs.h>
+#include <mos/request.h>
+
+/* operations on DEPUTY's data-base of REMOTE files: */
+
+extern int mosix_register_a_file(struct file *, int);
+extern void mosix_undo_last_file_registration(struct file *, int);
+extern int mosix_rebuild_file_list(void);
+extern void mosix_update_remote_files(void);
+
+struct vmalist
+{
+	unsigned int vmstart;
+	unsigned int vmend;
+	unsigned short vmflags;
+	short	maydump;
+};
+
+struct vmamaps
+{
+	unsigned long vmstart, vmend, vmflags, vmpgoff;
+	struct file *fp;
+};
+
+extern void init_mosix(void);
+extern void wake_up_mosix(struct task_struct *);
+extern int mosix_wakeable(struct task_struct *);
+extern int mosix_go_home(int);
+extern int mosix_go_home_for_reason(int, int);
+extern int mosix_send_back_home(struct task_struct *);
+extern int mosix_need_while_asleep(void);
+extern void mosix_run_while_asleep(void);
+extern void mosix_pre_usermode_functions(void);
+extern int stay_me_and_my_clones(uint32_t);
+extern void unstay_mm(struct mm_struct *);
+extern void mosix_inform_remote_of_nice(void);
+extern void mosix_snap_load(int);
+extern void mosix_clear_statistics(void);
+extern int mosix_fork_init_fields(struct task_struct *);
+extern void mosix_fork_free_fields(struct task_struct *);
+extern void mosix_exit(void);
+extern void mosix_very_exit(void);
+extern void mosix_obtain_registers(unsigned long);
+extern void mosix_bring_monkey_users_back(struct inode *);
+extern void mosix_no_longer_monkey(struct inode *);
+extern void mosix_check_for_freedom_to_move(void);
+extern int mosix_pre_clone(void);
+extern void mosix_post_clone(void);
+extern void mosix_remote_syscall_trace(void);
+extern u64 mosix_remote_tsc(void);
+extern int mosix_forkmigrate(void);
+extern int mosix_deputy_fork(struct task_struct *, int, unsigned long);
+extern void mosix_exit_mm(struct task_struct *);
+extern void mosix_exec_mmap(struct mm_struct *);
+extern void mosix_deputy_rusage(int);
+extern int mosix_deputy_personality(unsigned long);
+extern void mosix_deputy_count_args(char **, char**, int *, int *);
+extern int mosix_deputy_bring_strings(struct linux_binprm *, char *, char **, char **);
+extern int mosix_deputy_setup_args(int, unsigned long *);
+extern int mosix_deputy_exec_mmap(char *);
+extern int mosix_deputy_dump_thread(struct user *);
+extern void mosix_deputy_init_aout_mm(struct exec *);
+extern unsigned long mosix_deputy_elf_setup(char *, int, int, struct elfhdr *, unsigned long, unsigned long, unsigned long, int, int, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, struct elf_tables_extras *);
+extern void mosix_deputy_fix_elf_aout_interp(unsigned, unsigned, unsigned);
+extern int mosix_deputy_list_vmas(struct vmalist **, unsigned long *, unsigned long *);
+extern long mosix_deputy_brk(unsigned long, unsigned long);
+
+extern void mosix_notify_urgent(struct socket *);
+extern void mosix_notify_receive(struct socket *);
+
+extern void mosix_proc_init(void);
+extern int mosix_proc_get_remote_array(char *, int, int);
+extern int mosix_proc_get_node_array(char *, int, int);
+
+extern void mosix_decay_exec(void);
+extern void mosix_add_to_whereto(struct task_struct *, int);
+extern void mosix_do_add_to_whereto(struct task_struct *, int);
+
+struct sockaddr;
+extern int reserved_mosix_address(struct sockaddr *);
+extern void comm_report_violation(char *, struct sockaddr *);
+
+void init_guest_user_struct(void);
+extern int get_free_guest_slots(void);
+extern int count_guests(void);
+
+/* argument of mosix_deputy_setup_args: */
+#define	SETUP_ARGS_PLAIN	0	
+#define	SETUP_ARGS_AS_AOUT	1
+#define	SETUP_ARGS_AS_ELF	2
+#define	SETUP_ARGS_NOTYET	3
+
+extern int mosix_deputy_restore_sigcontext(struct sigcontext *, int *);
+extern void mosix_deputy_setup_frame(unsigned long, struct k_sigaction *, siginfo_t, sigset_t *);
+extern unsigned long mosix_deputy_mmap(struct file *, unsigned long, int, unsigned long, unsigned long, unsigned long, off_t, nopage_t);
+extern int deputy_munmap(unsigned long, size_t);
+extern int deputy_mprotect(unsigned long, size_t, unsigned long);
+extern void mosix_deputy_rlimit(int, struct rlimit);
+extern int mosix_deputy_dump_fpu(struct user_i387_struct *);
+extern int mosix_sync_caps(kernel_cap_t);
+
+#define	ALL_REGISTERS	0x7fff	/* as many as in struct pt_regs */
+#define	BIT_OF_REGISTER(_which) \
+	(1 << (((int)&(((struct pt_regs *)0)->_which)) / sizeof(int)))
+
+/*
+ * meaning of signals on REMOTE
+ */
+
+#define	FATAL_SIGSEGV		SIGINT
+#define	REMOTE_FILE_RELEASED	SIGQUIT
+
+/* other signals that can occur on REMOTE:
+ * SIGKILL, SIGSEGV, SIGPROF, SIGVTALRM, SIGFPE, SIGBUS, SIGIOT, SIGILL,
+ * SIGXCPU, SIGXFSZ, SIGPROF, SIGTRQAP, SIGPWR (a tricky one).
+ * SIGTERM requires the process to migrate back.
+ */
+
+#define	MOSIX_PRIORITY		(100)
+#define	MOSIX_ASLEEP_PRIORITY	(MOSIX_PRIORITY * 3 / 10)
+#define	MOSIX_DEPUTY_PRIORITY	(MOSIX_PRIORITY * 1 / 10)
+#define	MOSIX_RESPOND_PRIORITY	(MOSIX_PRIORITY * 6 / 10)
+
+#define	PROC_MOSIX_USE_START	1024	/* coordinate with proc/fs/base.c */
+
+#if defined(CONFIG_MOSIX_DIAG) && defined(CONFIG_SMP)
+#define KERNEL_LOCKED	do{if(current->lock_depth == -1)panic("not locked %d of " __FILE__, __LINE__);}while(0)
+#define MOSIX_LOCKED	do{if(current->mosix.lock_depth == -1)panic("not locked %d of " __FILE__, __LINE__);}while(0)
+#else
+#define	KERNEL_LOCKED	do {} while(0)
+#define	MOSIX_LOCKED	do {} while(0)
+#endif /* CONFIG_MOSIX_DIAG */
+
+#define	mos_to_contact(m) ((struct socket *)((m)->contact))
+#define	mos_to_waitp(m)	((wait_queue_head_t *)(&(m)->wait_dist))
+#define mos_to_regs(m)	((struct pt_regs *)((m)->altregs))
+
+struct proc_dir_entry;
+extern struct proc_dir_entry *proc_mosix;
+typedef ssize_t (proc_mosix_pid_writer)(struct file *, struct task_struct *, const char *, size_t);
+extern proc_mosix_pid_writer proc_mosix_pid_set_migrate;
+extern proc_mosix_pid_writer proc_mosix_pid_set_goto;
+extern proc_mosix_pid_writer proc_mosix_pid_set_lock;
+extern proc_mosix_pid_writer proc_mosix_pid_set_sigmig;
+extern proc_mosix_pid_writer proc_mosix_pid_set_disclosure;
+#ifdef CONFIG_MOSIX_FS
+extern proc_mosix_pid_writer proc_mosix_pid_set_selected;
+#endif /* CONFIG_MOSIX_FS */
+
+#ifdef CONFIG_MOSIX_UDB
+extern void udbinit(void);
+extern int udb_booting;
+extern int nmi_debugger;
+#endif /* CONFIG_MOSIX_UDB */
+
+#endif /*__KERNEL__*/
+
+#endif /* CONFIG_MOSIX */
+
+#endif
diff -ruN linux-2.4.16/include/linux/mount.h linux-2.4.16-mosix/include/linux/mount.h
--- linux-2.4.16/include/linux/mount.h	Fri Oct  5 22:05:55 2001
+++ linux-2.4.16-mosix/include/linux/mount.h	Sun Dec 23 13:56:53 2001
@@ -29,6 +29,11 @@
 	int mnt_flags;
 	char *mnt_devname;		/* Name of device e.g. /dev/dsk/hda1 */
 	struct list_head mnt_list;
+#ifdef CONFIG_MOSIX_DFSA
+	short mnt_dfsa;		/* what should be */
+	short mnt_dfsano;	/* what is */
+	short mnt_dfsaprev;	/* what was */
+#endif /* CONFIG_MOSIX_DFSA */
 };
 
 static inline struct vfsmount *mntget(struct vfsmount *mnt)
diff -ruN linux-2.4.16/include/linux/net.h linux-2.4.16-mosix/include/linux/net.h
--- linux-2.4.16/include/linux/net.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/net.h	Sun Dec 23 13:56:53 2001
@@ -62,6 +62,12 @@
 #define SOCK_ASYNC_WAITDATA	1
 #define SOCK_NOSPACE		2
 
+#ifdef CONFIG_MOSIX
+#define SOCK_INTER_MOSIX	3	/* used internally in kernel-mode */
+#define	SOCK_WAIT_MFSDATA	4	/* waiting for MFS data */
+#define	SOCK_OOB_IN		5	/* OOB received on MOSIX socket */
+#endif /* CONFIG_MOSIX */
+
 struct socket
 {
 	socket_state		state;
diff -ruN linux-2.4.16/include/linux/personality.h linux-2.4.16-mosix/include/linux/personality.h
--- linux-2.4.16/include/linux/personality.h	Mon Sep 10 23:04:33 2001
+++ linux-2.4.16-mosix/include/linux/personality.h	Sun Dec 23 13:56:53 2001
@@ -123,4 +123,8 @@
 		__MOD_DEC_USE_COUNT(ep->module);	\
 } while (0)
 
+#ifdef CONFIG_MOSIX
+extern struct exec_domain *lookup_exec_domain(unsigned long);
+#endif /* CONFIG_MOSIX */
+
 #endif /* _LINUX_PERSONALITY_H */
diff -ruN linux-2.4.16/include/linux/pipe_fs_i.h linux-2.4.16-mosix/include/linux/pipe_fs_i.h
--- linux-2.4.16/include/linux/pipe_fs_i.h	Thu Apr 26 00:18:23 2001
+++ linux-2.4.16-mosix/include/linux/pipe_fs_i.h	Sun Dec 23 13:56:53 2001
@@ -9,6 +9,10 @@
 	unsigned int start;
 	unsigned int readers;
 	unsigned int writers;
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+	unsigned int exceptions;
+	unsigned long reading_bytes;
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
 	unsigned int waiting_readers;
 	unsigned int waiting_writers;
 	unsigned int r_counter;
@@ -38,6 +42,14 @@
 #define PIPE_MAX_RCHUNK(inode)	(PIPE_SIZE - PIPE_START(inode))
 #define PIPE_MAX_WCHUNK(inode)	(PIPE_SIZE - PIPE_END(inode))
 
+#ifdef CONFIG_MOSIX_PIPE_EXCEPTIONS
+#define	PIPE_EXCEPTIONS(inode)	((inode).i_pipe->exceptions)
+#define	PIPE_READING_BYTES(inode)	((inode).i_pipe->reading_bytes)
+
+#define	PIPE_EXCEPTION_INPUT	1
+#define	PIPE_EXCEPTION_NOINPUT	2
+#endif /* CONFIG_MOSIX_PIPE_EXCEPTIONS */
+
 /* Drop the inode semaphore and wait for a pipe event, atomically */
 void pipe_wait(struct inode * inode);
 
diff -ruN linux-2.4.16/include/linux/proc_fs.h linux-2.4.16-mosix/include/linux/proc_fs.h
--- linux-2.4.16/include/linux/proc_fs.h	Thu Nov 22 21:46:23 2001
+++ linux-2.4.16-mosix/include/linux/proc_fs.h	Sun Dec 23 13:56:53 2001
@@ -90,6 +90,9 @@
 void proc_pid_delete_inode(struct inode *inode);
 int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
 
+#ifdef CONFIG_MOSIX
+extern int proc_register(struct proc_dir_entry *, struct proc_dir_entry *);
+#endif /* CONFIG_MOSIX */
 extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
 						struct proc_dir_entry *parent);
 extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
diff -ruN linux-2.4.16/include/linux/remote_fs_i.h linux-2.4.16-mosix/include/linux/remote_fs_i.h
--- linux-2.4.16/include/linux/remote_fs_i.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/linux/remote_fs_i.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#ifndef _LINUX_REMOTE_FS_I_H
+#define _LINUX_REMOTE_FS_I_H
+#ifdef CONFIG_MOSIX
+
+struct vm_area_struct;
+typedef struct page * (*nopage_t)(struct vm_area_struct *, unsigned long, int);
+
+struct remote_inode_info
+{
+	int origin;			/* node of origin */
+	struct dentry *dp;		/* dentry pointer on origin */
+	uint64_t unique;		/* unique version on origin */
+	nopage_t nopage;		/* nopage routine */
+};
+
+#define	home_file(f)	(*((struct file **)(&(f)->f_pos)))
+
+#endif /* CONFIG_MOSIX */
+#endif
diff -ruN linux-2.4.16/include/linux/sched.h linux-2.4.16-mosix/include/linux/sched.h
--- linux-2.4.16/include/linux/sched.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/sched.h	Sun Dec 23 15:34:36 2001
@@ -29,6 +29,12 @@
 
 struct exec_domain;
 
+#ifdef CONFIG_MOSIX
+#include <mos/mosixtask.h>
+#else
+#define MOSIX_INIT_TASK(tsk)
+#endif /* CONFIG_MOSIX */
+
 /*
  * cloning flags:
  */
@@ -88,6 +94,9 @@
 #define TASK_UNINTERRUPTIBLE	2
 #define TASK_ZOMBIE		4
 #define TASK_STOPPED		8
+#ifdef CONFIG_MOSIX
+#define	TASK_SAME		16
+#endif /* CONFIG_MOSIX */
 
 #define __set_task_state(tsk, state_value)		\
 	do { (tsk)->state = (state_value); } while (0)
@@ -181,6 +190,25 @@
 	fd_set close_on_exec_init;
 	fd_set open_fds_init;
 	struct file * fd_array[NR_OPEN_DEFAULT];
+#ifdef CONFIG_MOSIX_DFSA
+	atomic_t users;		/* the real count, excluding /proc grabs */
+	int count_dropped_to_one;
+	int maxclosed;
+	fd_set *closed;
+	fd_set closed_fds_init;
+	int maxopened;
+	fd_set *opened;
+	fd_set opened_fds_init;
+	int maxmod;
+	fd_set *modified;
+	fd_set modified_fds_init;
+#define	INIT_FILES_DFSA , users : ATOMIC_INIT(1), \
+			  closed: &init_files.closed_fds_init, \
+			  opened: &init_files.opened_fds_init, \
+			  modified: &init_files.modified_fds_init,
+#else
+#define	INIT_FILES_DFSA
+#endif /* CONFIG_MOSIX_DFSA */
 };
 
 #define INIT_FILES \
@@ -196,6 +224,7 @@
 	close_on_exec_init: { { 0, } }, 		\
 	open_fds_init:	{ { 0, } }, 			\
 	fd_array:	{ NULL, } 			\
+	INIT_FILES_DFSA					\
 }
 
 /* Maximum number of active map areas.. This is a random (large) number */
@@ -229,6 +258,20 @@
 
 	/* Architecture-specific MM context */
 	mm_context_t context;
+#ifdef CONFIG_MOSIX
+	atomic_t mm_kiocount;
+	atomic_t mm_realusers;
+	unsigned long last_memsort;
+	int used, unused, swapped;	/* break-down of memory pages */
+	int private_unused;		/* unused but not active/inactive */
+/*
+	int private_unused;
+*/
+	int mark;
+#define	INIT_MM_MOSIX	mm_kiocount: ATOMIC_INIT(0), mm_realusers: ATOMIC_INIT(1),
+#else
+#define	INIT_MM_MOSIX
+#endif /* CONFIG_MOSIX */
 };
 
 extern int mmlist_nr;
@@ -242,6 +285,7 @@
 	mmap_sem:	__RWSEM_INITIALIZER(name.mmap_sem), \
 	page_table_lock: SPIN_LOCK_UNLOCKED, 		\
 	mmlist:		LIST_HEAD_INIT(name.mmlist),	\
+	INIT_MM_MOSIX					\
 }
 
 struct signal_struct {
@@ -340,9 +384,9 @@
 	pid_t tgid;
 	/* boolean value for session group leader */
 	int leader;
-	/* 
+	/*
 	 * pointers to (original) parent process, youngest child, younger sibling,
-	 * older sibling, respectively.  (p->father can be replaced with 
+	 * older sibling, respectively.  (p->father can be replaced with
 	 * p->p_pptr->pid)
 	 */
 	struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
@@ -401,13 +445,15 @@
 	int (*notifier)(void *priv);
 	void *notifier_data;
 	sigset_t *notifier_mask;
-	
+
 /* Thread group tracking */
    	u32 parent_exec_id;
    	u32 self_exec_id;
 /* Protection of (de-)allocation: mm, files, fs, tty */
 	spinlock_t alloc_lock;
-
+#ifdef CONFIG_MOSIX
+	struct mosix_task mosix;
+#endif /* CONFIG_MOSIX */
 /* journalling filesystem info */
 	void *journal_info;
 };
@@ -500,6 +546,7 @@
     blocked:		{{0}},						\
     alloc_lock:		SPIN_LOCK_UNLOCKED,				\
     journal_info:	NULL,						\
+MOSIX_INIT_TASK(tsk)                            \
 }
 
 
@@ -546,9 +593,23 @@
 
 	for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
 		;
+#ifdef CONFIG_MOSIX
+	if(p && (p->mosix.dflags & DREMOTE))
+		p = NULL;
+#endif /* CONFIG_MOSIX */
+	return p;
+}
+
+#ifdef CONFIG_MOSIX
+static inline struct task_struct *find_any_task_by_pid(int pid)
+{
+	struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
 
+	for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
+		;
 	return p;
 }
+#endif /* CONFIG_MOSIX */
 
 #define task_has_cpu(tsk) ((tsk)->cpus_runnable != ~0UL)
 
@@ -669,6 +730,14 @@
 
 static inline void recalc_sigpending(struct task_struct *t)
 {
+#ifdef CONFIG_MOSIX
+	t->mosix.ignoreoldsigs = 0;
+	if(t->mosix.dflags & DHEAVYSLEEP)
+		t->sigpending = 0;
+	else if(t->mosix.dflags & DFAKESIGNAL)
+		t->sigpending = 1;
+	else
+#endif /* CONFIG_MOSIX */
 	t->sigpending = has_pending_signals(&t->pending.signal, &t->blocked);
 }
 
@@ -701,12 +770,12 @@
  * fsuser(). This is done, along with moving fsuser() checks to be
  * last.
  *
- * These will be removed, but in the mean time, when the SECURE_NOROOT 
+ * These will be removed, but in the mean time, when the SECURE_NOROOT
  * flag is set, uids don't grant privilege.
  */
 static inline int suser(void)
 {
-	if (!issecure(SECURE_NOROOT) && current->euid == 0) { 
+	if (!issecure(SECURE_NOROOT) && current->euid == 0) {
 		current->flags |= PF_SUPERPRIV;
 		return 1;
 	}
@@ -723,7 +792,7 @@
 }
 
 /*
- * capable() checks for a particular capability.  
+ * capable() checks for a particular capability.
  * New privilege checks should use this interface, rather than suser() or
  * fsuser(). See include/linux/capability.h for defined capabilities.
  */
@@ -835,7 +904,7 @@
 	current->state = TASK_RUNNING;					\
 	remove_wait_queue(&wq, &__wait);				\
 } while (0)
-	
+
 #define wait_event_interruptible(wq, condition)				\
 ({									\
 	int __ret = 0;							\
@@ -872,10 +941,37 @@
 #define next_thread(p) \
 	list_entry((p)->thread_group.next, struct task_struct, thread_group)
 
+#ifdef CONFIG_MOSIX
+#define for_each_local_task(p) \
+	for (p = &init_task ; (p = p->next_task) != &init_task ; ) \
+	if(!(p->mosix.dflags & DREMOTE))
+
+static inline long
+LOGICAL_STATE(struct task_struct *p)
+{
+	int result;
+	unsigned long flags;
+
+	read_lock_irqsave(&p->mosix.state_lock, flags);
+	result = (p->mosix.bstate == TASK_SAME) ? p->state : p->mosix.bstate;
+	read_unlock_irqrestore(&p->mosix.state_lock, flags);
+	return(result);
+}
+
+extern void run_on(struct task_struct *);
+extern void run_off(struct task_struct *);
+
+#define	need_interim_while_asleep()	mosix_need_while_asleep()
+#define	run_interim_while_asleep()	mosix_run_while_asleep()
+#endif /* CONFIG_MOSIX */
+
 static inline void del_from_runqueue(struct task_struct * p)
 {
 	nr_running--;
 	p->sleep_time = jiffies;
+#ifdef CONFIG_MOSIX
+	run_off(p);
+#endif /* CONFIG_MOSIX */
 	list_del(&p->run_list);
 	p->run_list.next = NULL;
 }
@@ -914,6 +1010,11 @@
 	char *res;
 	struct vfsmount *rootmnt;
 	struct dentry *root;
+#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS)
+	if(dentry->d_inode && dentry->d_inode->i_op &&
+		dentry->d_inode->i_op->check_path)
+		dentry->d_inode->i_op->check_path(dentry);
+#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */
 	read_lock(&current->fs->lock);
 	rootmnt = mntget(current->fs->rootmnt);
 	root = dget(current->fs->root);
diff -ruN linux-2.4.16/include/linux/smp_lock.h linux-2.4.16-mosix/include/linux/smp_lock.h
--- linux-2.4.16/include/linux/smp_lock.h	Thu Nov 22 21:46:27 2001
+++ linux-2.4.16-mosix/include/linux/smp_lock.h	Sun Dec 23 13:56:53 2001
@@ -11,6 +11,11 @@
 #define reacquire_kernel_lock(task)		do { } while(0)
 #define kernel_locked() 1
 
+#ifdef CONFIG_MOSIX
+#define	lock_mosix()				do {} while(0)
+#define	unlock_mosix()				do {} while(0)
+#endif /* CONFIG_MOSIX */
+
 #else
 
 #include <asm/smplock.h>
diff -ruN linux-2.4.16/include/linux/spinlock.h linux-2.4.16-mosix/include/linux/spinlock.h
--- linux-2.4.16/include/linux/spinlock.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/spinlock.h	Sun Dec 23 13:56:53 2001
@@ -130,6 +130,10 @@
 #define write_lock(lock)	(void)(lock) /* Not "unused variable". */
 #define write_unlock(lock)	do { } while(0)
 
+#ifdef CONFIG_MOSIX
+#define	can_read_lock(rw)	(1)
+#endif /* CONFIG_MOSIX */
+
 #endif /* !SMP */
 
 /* "lock on reference count zero" */
diff -ruN linux-2.4.16/include/linux/wait.h linux-2.4.16-mosix/include/linux/wait.h
--- linux-2.4.16/include/linux/wait.h	Thu Nov 22 21:46:19 2001
+++ linux-2.4.16-mosix/include/linux/wait.h	Sun Dec 23 13:56:53 2001
@@ -190,6 +190,21 @@
 	return !list_empty(&q->task_list);
 }
 
+#ifdef CONFIG_MOSIX
+#if BITS_PER_LONG == 32
+#define	KERNEL_ADDRESS_BIT	0x80000000
+#else
+#error please fill in: use a bit that is always set in kernel addresses.
+#endif
+#define	IN_MOSIX_CONTEXT(p)	(!(((unsigned long) (p)) & KERNEL_ADDRESS_BIT))
+#define	MOSIX_CONTEXT(p)	((struct task_struct *)\
+				(((unsigned long) (p)) & ~KERNEL_ADDRESS_BIT))
+#define	NORMAL_CONTEXT(p)	((struct task_struct *)\
+				(((unsigned long) (p)) | KERNEL_ADDRESS_BIT))
+
+extern void adjust_task_mosix_context(struct task_struct **);
+#endif /* CONFIG_MOSIX */
+
 static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
 {
 #if WAITQUEUE_DEBUG
@@ -200,6 +215,9 @@
 	if (!head->task_list.next || !head->task_list.prev)
 		WQ_BUG();
 #endif
+#ifdef CONFIG_MOSIX
+	adjust_task_mosix_context(&new->task);
+#endif /* CONFIG_MOSIX */
 	list_add(&new->task_list, &head->task_list);
 }
 
@@ -217,6 +235,9 @@
 	if (!head->task_list.next || !head->task_list.prev)
 		WQ_BUG();
 #endif
+#ifdef CONFIG_MOSIX
+	adjust_task_mosix_context(&new->task);
+#endif /* CONFIG_MOSIX */
 	list_add_tail(&new->task_list, &head->task_list);
 }
 
diff -ruN linux-2.4.16/include/mos/balance.h linux-2.4.16-mosix/include/mos/balance.h
--- linux-2.4.16/include/mos/balance.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/balance.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#ifndef _MOSIX_BALANCE_H
+#define _MOSIX_BALANCE_H
+
+#ifdef __KERNEL__
+
+/* various tuning definitions: */
+#define	MAXKNOWNUP		45
+#define INFO_WIN		8
+#define	BALANCING_TIMEOUT	10
+
+struct loadinfo {
+	unsigned short pe;
+	unsigned short speed;	/* in SMP: of each CPU (not the total) */
+	unsigned long load;
+	unsigned short ncpus;
+	unsigned short util;	/* in SMP: max=MF*smp_num_cpus */
+	unsigned short status;
+	unsigned short free_slots;
+	unsigned int mem;
+	unsigned int rmem;
+	unsigned int tmem;
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	struct opcost costs[MAX_MOSIX_TOPOLOGY];
+	struct mfs_cost mfscosts[MAX_MOSIX_TOPOLOGY];
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+#ifdef CONFIG_MOSIX_RESEARCH
+        unsigned int rio;   /* read io  */
+        unsigned int wio;   /* write io */
+#endif /* CONFIG_MOSIX_REASEARCH */
+};
+
+struct miginfo {
+	int aload;
+	unsigned long pages;
+};
+
+struct infomsg {
+	long version;
+	int topology;
+	int serialno;
+	struct loadinfo load;
+};
+
+
+/* following is a multiple to be used for statistical values - primarily the
+ * number of system-calls.  Statistical values are counted in chunks of
+ * EVENT_COUNTER_VALUE, rather than simply 1, for the following two reasons:
+ * 1) to prevent being lost by decaying
+ * 2) making the contribution of a system-call to "iocounter" reflect its
+ *    impact, which is considerably more relative to 1-byte of I/O:
+ *    "iocounter" need not be accurate since it is only used to trigger
+ *    considerations for IOBALANCE migrations, but it is good to maintain
+ *    a power of 2 to prevent multiplications in "iocounter" computations.
+ */
+#define	EVENT_COUNTER_VALUE	1024
+#define	EVENT_COUNTER_SHIFT	10
+
+/* MDP constants: */
+#define	KEEP_FREE_PORTION	16	/* 1/16 of memory */
+#define	MAX_PAGES_TO_KEEP_FREE	(0x600000/PAGE_SIZE)	/* but no more than 6MB */
+#define	MIN_EXPECTED_PROC_SIZE	(0x80000/PAGE_SIZE)	/* when freeing memory, at least this */
+#define	MIN_MCHOOSE_AGAIN	1000000	/* youngest (RT) to mconsider */
+#define	MAX_MCHOOSE_AGAIN	4000000	/* no elder-advantage beyond this */
+#define	UTIL_TOLLERANCE		8/10	/* under this, sure trashing */
+#define	OLD_SECONDS		60	/* making an untouched page old */
+
+extern struct loadinfo loadinfo[INFO_WIN];
+
+extern int export_load;		/* load reported to other processors */
+extern int stable_export;	/* machine dependent stabilizing factor */
+extern unsigned acpuse;		/* accumulated cpu utilization */
+extern unsigned coming_in;	/* number of arriving processes */
+extern unsigned came_lately4;	/* processes that arrived lately (*4) */
+extern unsigned load_left;	/* load of processes that just left */
+extern int standard_speed;	/* yardstick */
+#ifdef CONFIG_MOSIX_RESEARCH
+extern unsigned int io_read_rate; /* the current read rate from block devices */
+extern unsigned int io_write_rate; /* the current write rate from block devices */ 
+#endif /* CONFIG_MOSIX_RESEARCH */
+extern struct opcost deputy_here[MAX_MOSIX_TOPOLOGY]; /* DEPUTY I/O overheads here */
+extern struct opcost remote_here_adjusted[MAX_MOSIX_TOPOLOGY];
+#ifndef CONFIG_MOSIX_TOPOLOGY
+extern struct opcost remote_here;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+extern unsigned load_ticks;
+
+extern int pages_to_keep_free;	/* # of pages to attempt to keep free */
+extern int latest_free_mem;	/* in pages */
+
+extern rwlock_t loadinfo_lock;
+
+#define	BUMP_HEAD do { register struct mosix_task *m = &current->mosix; \
+			unsigned long oldcounter; int dobal; \
+			lock_mosix(); \
+			oldcounter = m->iocounter
+
+#define	BUMP_TAIL dobal = ((m->iocounter ^ oldcounter) & 0xfff00000) != 0; \
+			unlock_mosix(); \
+			if(dobal) { mosix_add_to_whereto(current, IOBALANCE); \
+				m->iocounter = 0; } \
+			} while(0)
+
+#define bump_statistics(s) BUMP_HEAD; \
+	m->s += EVENT_COUNTER_VALUE; \
+	m->iocounter += EVENT_COUNTER_VALUE; \
+	BUMP_TAIL
+#define	bump_statistic_amount(type,b) BUMP_HEAD; \
+	m->n##type##s += COPY_COUNTER_MULTIPLIER; \
+	m->type##bytes += b; \
+	m->iocounter += COPY_COUNTER_MULTIPLIER + b; \
+	BUMP_TAIL
+
+#define	bump_copyout(_n)	bump_statistic_amount(copyout,_n)
+#define	bump_copyin(_n)		bump_statistic_amount(copyin,_n)
+#define	bump_syscalls()		bump_statistics(nsyscalls)
+#define	bump_demandpages()	bump_statistics(ndemandpages)
+
+#endif /*__KERNEL__*/
+
+#endif
diff -ruN linux-2.4.16/include/mos/comm.h linux-2.4.16-mosix/include/mos/comm.h
--- linux-2.4.16/include/mos/comm.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/comm.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan, Amnon Shiloh.
+ */
+
+/* interfacing the MOSIX communication package: */
+
+#ifndef _MOS_COMM_H
+#define _MOS_COMM_H
+
+#ifdef __KERNEL__
+
+struct mosix_link;			/* defined in mos/comm.c */
+struct mosix_addr;			/* defined in include/mos/protocol.h */
+struct mosix_task;
+typedef struct mosix_link mosix_link;
+typedef struct mosix_addr mosix_addr;
+
+/*
+ * values for mos# (e.g. in comm_open)
+ * 1..65535	-> valid mos# (mig)
+ * -1..-65535	-> valid mos# (info)
+ */
+
+#define COMM_TOADDR	(70001)
+#define COMM_ACCEPT	(70002)
+#define COMM_MIGD	(70003)
+#define COMM_INFO	(70004)
+#define	COMM_LOOSE	(70005)
+
+/*
+ * message flags:
+ * lower 16 bits used for message types (see mos/protocol.h)
+ * next 8 bits used for message flags (see below)
+ * upper 8 bits used for mosix logging
+ */
+#define COMM_MFREGS	0x00800000
+#define COMM_MFDATA	0x00400000
+#define COMM_MFIDENT	0x00100000
+#ifdef CONFIG_MOSIX_DFSA
+#define	COMM_MFDFSA	0x00080000
+#define	COMM_MFNODFSA	0x00040000
+#define	COMM_MFDFSAOPTS	(COMM_MFDFSA|COMM_MFNODFSA)
+#endif /* CONFIG_MOSIX_DFSA */
+
+#define COMM_MFOPTIONS	0x00ff0000
+#define	COMM_MFHEADOPTS	(COMM_MFREGS|COMM_MFIDENT)
+
+#define	COMM_ZEROCOPYOK	0x40000000
+
+/*
+ * other flags
+ */
+#define COMM_ALLDATA	(-1)	/* copy/flush all available data */
+
+
+/*
+ * message format
+ */
+struct comm_header {
+	unsigned short olen;
+	unsigned short hlen;
+	int type;
+	int dlen;
+	int regs;
+	int dfsalen;
+};
+
+#define COMM_HLEN	(sizeof(struct comm_header))
+
+/*
+ * exported data
+ */
+extern int comm_type;
+extern unsigned long comm_remote_timo;
+extern unsigned long comm_connect_timo;
+extern unsigned long comm_reconn_timo;
+
+/*
+ * communication module interface
+ */
+
+extern void comm_startup(void);
+extern mosix_link *comm_open(int, mosix_addr *, unsigned long);
+extern mosix_link *comm_use(struct task_struct *, mosix_link *);
+extern void comm_close(mosix_link *);
+extern int comm_accept(mosix_link *,mosix_link **, mosix_addr *,unsigned long);
+extern int comm_send(int, void *, int, void *, int, int);
+extern int comm_recv(void **, int *);
+extern int comm_recvdata(void **);
+extern int comm_copydata(void *, int, int);
+extern int comm_hidedata(void);
+extern void comm_flushdata(int);
+extern void comm_free(void *);
+extern int comm_peek(void);
+extern int comm_wait(void);
+extern int comm_send_urgent(void);
+extern int comm_test_urgent(void);
+extern void comm_take_urgent(void);
+extern int comm_sendto(int, void *, int, mosix_link *, mosix_addr *);
+extern int comm_recvfrom(void *,int, mosix_link *, mosix_addr *, unsigned long);
+extern int comm_recvfrompe(void *,int, mosix_link *, int *, unsigned long);
+extern int net_to_mos(mosix_addr *);
+
+extern inline void comm_invalidate_address(mosix_addr *);
+extern void comm_migration_mode(int);
+extern int comm_getpeer(mosix_link *);
+extern void comm_init_linkpool(void);
+extern void comm_free_linkpool(void);
+extern mosix_link *comm_borrow_linkpool(void);
+extern void comm_return_linkpool(mosix_link *);
+extern void comm_age_linkpool(void);
+extern void rinode_flush_files(int);
+
+extern spinlock_t skown_lock;
+
+#endif /* __KERNEL__ */
+
+#endif
diff -ruN linux-2.4.16/include/mos/debug.h linux-2.4.16-mosix/include/mos/debug.h
--- linux-2.4.16/include/mos/debug.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/debug.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Oren Laadan.
+ */
+
+#ifndef _MOS_DEBUG_H
+#define _MOS_DEBUG_H
+
+#ifdef CONFIG_MOSIX_DEBUG
+
+extern unsigned long ds_debug;
+
+#define DSDEB_ERROR	0x00000001
+#ifdef CONFIG_MOSIX_DFSA
+#define	DSDEB_DFSA	0x00000002
+#endif /* CONFIG_MOSIX_DFSA */
+#define DSDEB_MIG	0x00000010
+#define	DSDEB_EXPEL	0x00000020
+#define	DSDEB_HOLD	0x00000040
+#define	DSDEB_MIGSTAGE	0x00000080
+#define DSDEB_WHERETO	0x00000100
+#define DSDEB_INFO	0x00000200
+#define DSDEB_PROC	0x00000400
+#define	DSDEB_CACHE	0x00000800
+#define	DSDEB_CACHESTOP 0x00001000
+#define DSDEB_CONFIG	0x00002000
+#define	DSDEB_LOAD	0x00004000
+#define	DSDEB_CONSIDER	0x00008000
+#define	DSDEB_LOADS	0x00010000
+#define	DSDEB_ANCESSTOR	0x00020000
+#define	DSDEB_DECAY	0x00040000
+#define	DSDEB_MEM	0x00080000
+#define	DSDEB_NOTCACHED	0x00100000
+#define	DSDEB_SUPERMEM	0x00200000
+
+#define DSDEB_COMMOPEN	0x00400000
+#define DSDEB_COMMACPT	0x00800000
+#define DSDEB_COMMFLAGS	0x01000000
+#define DSDEB_COMMRECV	0x02000000
+#define DSDEB_COMMSEND	0x04000000
+#define DSDEB_COMMADDR	0x08000000
+#define	DSDEB_COMMDORECV 0x10000000
+#define	DSDEB_COMMDOSEND 0x20000000
+#define	DSDEB_DEBUGSEND	0x40000000
+
+
+#define DSDEB_COMM	(DSDEB_COMMOPEN|DSDEB_COMMACPT|DSDEB_COMMFLAGS|	\
+			 DSDEB_COMMRECV|DSDEB_COMMSEND|DSDEB_COMMADDR)
+
+#endif /* CONFIG_MOSIX_DEBUG */
+
+#ifdef CONFIG_MOSIX_UDB
+extern void mosix_debugger(char *);
+#define mosix_panic	mosix_debugger
+#else
+#define mosix_panic	panic
+#endif /* CONFIG_MOSIX_UDB */
+#endif
diff -ruN linux-2.4.16/include/mos/defs.h linux-2.4.16-mosix/include/mos/defs.h
--- linux-2.4.16/include/mos/defs.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/defs.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+/* all manners of independent variables and definitions required by the
+ * MOSIX package and possibly also by the MOSIX module itself:
+ */
+
+#ifndef _MOS_DEFS_H
+#define _MOS_DEFS_H
+
+extern int mosix_running;
+extern int active_cpus;
+
+extern spinlock_t whereto_lock;
+
+extern struct task_struct *mig_proc;
+extern int mig_daemon_active;
+extern struct task_struct *info_proc;
+extern int info_daemon_active;
+
+extern int slow_alpha, fast_alpha;	/* units over DECAY_QUOTIENT */
+extern int decay_interval;	/* in seconds */
+extern int mosadmin_gateways;	/* number of network segments (gateways) */
+extern int mosadmin_mode_stay;	/* no automatic migration out */
+extern int mosadmin_mode_lstay;	/* same just for local processes */
+extern int mosadmin_mode_block;	/* do not accept guests */
+extern int mosadmin_mode_quiet;	/* stop the load-chat (obsolete) */
+extern int mosadmin_mode_nomfs;	/* disallow MFS access to this node */
+extern char bootexpel, expel_progress;
+extern int latest_free_mem;
+
+extern struct task_struct *chosen_for_balance;
+extern struct task_struct *chosen_for_mdp;
+
+#define	STD_SPD		10000	  /* speed units of a standard processor */
+extern int cpuspeed;		  /* this node's relative processor speed */
+extern int standard_speed;	  /* if sysadmin changes standard-processor */
+extern int PE;			/* MOSIX number for this processor */
+extern int NPE;			/* number of configured MOSIX nodes */
+extern int MAXPE;		/* maximum MOSIX number in the cluster */
+
+#ifdef CONFIG_MOSIX_TOPOLOGY
+#if CONFIG_MOSIX_MAXTOPOLOGY > 10
+#warning MAXIMUM TOPOLOGY too big -- truncated to 10
+#define	MAX_MOSIX_TOPOLOGY	10
+#elif CONFIG_MOSIX_MAXTOPOLOGY < 2
+#warning MAXIMUM TOPOLOGY < 2 -- so why use it at all?
+#define	MAX_MOSIX_TOPOLOGY	1
+#else
+#define	MAX_MOSIX_TOPOLOGY	CONFIG_MOSIX_MAXTOPOLOGY
+#endif /* CONFIG_MOSIX_MAXTOPOLOGY */
+#else
+#define	MAX_MOSIX_TOPOLOGY	1
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+
+extern struct mosix_cost
+{
+	int PAGE_D, PAGE_R;
+	int SYSCALL_D, SYSCALL_R;
+	int COPYOUT_BASE_D, COPYOUT_PER_KB_D;
+	int COPYOUT_BASE_R, COPYOUT_PER_KB_R;
+	int COPYIN_BASE_D, COPYIN_PER_KB_D;
+	int COPYIN_BASE_R, COPYIN_PER_KB_R;
+	int MIGRATION_BASIC, MIGRATION_PER_PAGE;
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	int first, last;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+} mosix_cost[MAX_MOSIX_TOPOLOGY];
+
+extern struct mfs_cost
+{
+	int MFS_CONN_S, MFS_CONN_C;
+	int MFS_INKB_S, MFS_INKB_C;
+	int MFS_OUTKB_S, MFS_OUTKB_C;
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	int first, last;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+} mfs_cost[MAX_MOSIX_TOPOLOGY];
+
+extern struct opcost deputy_here[MAX_MOSIX_TOPOLOGY];
+
+#ifdef CONFIG_MOSIX_FS
+#define	MAX_MFS_STATNODES	10
+
+struct mfs_stats
+{
+	int nnodes;
+	unsigned short hint;
+	unsigned short nodes[MAX_MFS_STATNODES];
+	int64_t conns[MAX_MFS_STATNODES];
+	int64_t inbytes[MAX_MFS_STATNODES];
+	int64_t outbytes[MAX_MFS_STATNODES];
+};
+#else
+#define	MAX_MFS_STATNODES	0
+#endif /* CONFIG_MOSIX_FS */
+
+/* node-disconnection timeout: */
+#ifdef CONFIG_MOSIX_UDB
+#define	MOSIX_CONNECTION_KEEPALIVE_INTERVAL	60
+#define	MOSIX_CONNECTION_KEEPALIVE_MAXTRIES	10
+#define	MOSIX_CONNECTION_KEEPALIVE_TOTAL	600
+#else
+#define	MOSIX_CONNECTION_KEEPALIVE_INTERVAL	30
+#define	MOSIX_CONNECTION_KEEPALIVE_MAXTRIES	6
+#define	MOSIX_CONNECTION_KEEPALIVE_TOTAL	180
+#endif /* CONFIG_MOSIX_UDB */
+
+/* default slow decay brings process-statistics down to 10% in 3 minutes */
+/* default fast decay brings process-statistics down to 10% in 1 minute */
+
+#define	DEFAULT_DECAY_INTERVAL	2		/* seconds */
+#define	DEFAULT_SLOW_ALPHA	(DECAY_QUOTIENT * 975 / 1000)
+#define	DEFAULT_FAST_ALPHA	(DECAY_QUOTIENT * 926 / 1000)
+
+#define	MF	100		/* MOSIX frequency */
+
+#define	MILLION		1000000
+#define	DMILLION	1000000.0
+
+#endif
diff -ruN linux-2.4.16/include/mos/dfsa.h linux-2.4.16-mosix/include/mos/dfsa.h
--- linux-2.4.16/include/mos/dfsa.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/dfsa.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#ifndef _MOS_DFSA_H
+#define _MOS_DFSA_H
+
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/mount.h>
+#include <linux/dfsa_interface.h>
+
+#ifdef CONFIG_MOSIX_DFSA
+
+#define	MAXDFSAFS	8
+#define	MAXDFSALINKS	8
+#define	MAXDFSALINKLEN	128
+
+struct dfsatab
+{
+	unsigned short len;
+	char ndefs;
+	struct dfsdef
+	{
+		char defno;	/* mount=1-MAXDFSAFS, symlink>MAXDFSAFS */
+		char mounted;
+		short offset;
+	} dfsdef[0];
+};
+
+/* update flags (dupdates): */
+
+int dfsa_addlink(char *);
+int dfsa_dellink(char *);
+int dfsa_clearlinks(void);
+char *dfsa_showlinks(void);
+void dfsa_adapt(struct dfsatab *);
+int dfsa_sync(int);
+void dfsa_everyone_was_updated(void);
+void clear_dfsasync(void);
+void remote_clear_dfsa(void);
+void dfsa_tinit(void); 
+void deputy_resync_dfsa(void);
+char *deputy_pack_dfsa_changes(int *);
+void remote_unpack_dfsa_changes(char *);
+char *remote_pack_dfsa_changes(int *);
+void deputy_unpack_dfsa_changes(char *);
+void dfsa_check_comm_send(int *, char **, int *);
+void dfsa_comm_recv(int, char *);
+int enter_remote_dfsa_mode(void);
+void leave_remote_dfsa_mode(void);
+void dfsa_exit(void);
+
+#endif
+#endif
diff -ruN linux-2.4.16/include/mos/dscosts.h linux-2.4.16-mosix/include/mos/dscosts.h
--- linux-2.4.16/include/mos/dscosts.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/dscosts.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,24 @@
+/* dscosts.h -- MOSIX */
+/* cost of remote operations (microseconds) */
+
+/* measuring date: Mon Apr 30 20:08:13 IDT 2001 */
+/* between two Pentium-III/1GHz over Ethernet-100 */
+
+#define	PAGE_COST_D	81
+#define	PAGE_COST_R	150
+
+#define	SYSCALL_COST_D	39
+#define	SYSCALL_COST_R	38
+
+#define	COPYOUT_COST_BASE_D	0
+#define	COPYOUT_COST_PER_KB_D	11
+#define	COPYOUT_COST_BASE_R	0
+#define	COPYOUT_COST_PER_KB_R	18
+
+#define	COPYIN_COST_BASE_D	0
+#define	COPYIN_COST_PER_KB_D	18
+#define	COPYIN_COST_BASE_R	0
+#define	COPYIN_COST_PER_KB_R	12
+
+#define	MIGRATION_COST_BASIC	8141
+#define	MIGRATION_COST_PER_PAGE	351
diff -ruN linux-2.4.16/include/mos/log.h linux-2.4.16-mosix/include/mos/log.h
--- linux-2.4.16/include/mos/log.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/log.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan.
+ */
+
+#ifndef _MOS_LOG_H
+#define _MOS_LOG_H
+
+
+#define MOSIX_LOG_LEN		30
+#define MOSIX_LOG_POS(x)	(x)[MOSIX_LOG_LEN]
+
+#define MOSIX_LOG_SENDTYPE	1
+#define MOSIX_LOG_RECVTYPE	2
+#define MOSIX_LOG_RECEIVE	3
+#define MOSIX_LOG_SENDHDR	4
+#define MOSIX_LOG_RECVHDR	5
+#define MOSIX_LOG_SENDDATA	6
+#define MOSIX_LOG_RECVDATA	7
+#define MOSIX_LOG_SENDURG	8
+#define MOSIX_LOG_RECVURG	9
+#define MOSIX_LOG_RETURNVAL	10
+
+
+#ifdef CONFIG_MOSIX_DEBUG
+void add_mosix_log(struct task_struct *, int, int);
+#else
+#define add_mosix_log(x,y,z)	do {} while (0)
+#endif /* CONFIG_MOSIX_DEBUG */
+
+
+#define add_mosix_log_hdr(p, type, hlen, olen) \
+	add_mosix_log((p), (type), \
+		( ((hlen) & 0xffff) + (((olen) & 0xff) << 16) ) & 0x00ffffff)
+
+#define add_mosix_log_ret(p, err) \
+	add_mosix_log((p), MOSIX_LOG_RETURNVAL, (-(err)) & 0x00ffffff)
+
+#endif /* _MOSIX_LOG_H */
diff -ruN linux-2.4.16/include/mos/mfscosts.h linux-2.4.16-mosix/include/mos/mfscosts.h
--- linux-2.4.16/include/mos/mfscosts.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/mfscosts.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,14 @@
+/* mfscosts.h -- MOSIX */
+/* cost of MFS operations (microseconds) */
+
+/* measuring date: Mon Apr 30 20:12:28 IDT 2001 */
+/* between two Pentium-III/1GHz over Ethernet-100 */
+
+#define MFS_COST_CONN_S 36
+#define MFS_COST_CONN_C 40
+
+#define MFS_COST_INKB_S 14
+#define MFS_COST_INKB_C 19
+
+#define MFS_COST_OUTKB_S 88
+#define MFS_COST_OUTKB_C 56
diff -ruN linux-2.4.16/include/mos/mosctl.h linux-2.4.16-mosix/include/mos/mosctl.h
--- linux-2.4.16/include/mos/mosctl.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/mosctl.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan, Amnon Shiloh.
+ */
+
+#ifndef _MOS_MOSCTL_H
+#define _MOS_MOSCTL_H
+
+/*
+ * MOSIX API
+ */
+
+/* migration requests via /proc/nnnnn/goto */
+
+#define DM_GOBACKHOME    0       /* just go back home */
+#define DM_BALANCE       (-1)    /* perform load balancing */
+
+
+/* constants for status report (/proc/mosix/nodes/nnn/status) */
+
+#define	DS_MOSIX_DEF	0x001
+#define DS_MOSIX_UP     0x002
+#define DS_STAY         0x004
+#define DS_LSTAY        0x008
+#define DS_BLOCK        0x010
+#define DS_QUIET        0x020
+#define DS_NOMFS        0x040
+
+
+/* constants for statictics decay */
+
+#define DADV_CPU        1       /* a pure CPU task */
+#define DADV_NOCPU      2       /* a non-computational task */
+#define DADV_NODECAY    3       /* task of a uniform mix of rapid changes */
+#define DADV_SLOWDECAY  4       /* task may change its nature over long run */
+#define DADV_FASTDECAY  5       /* task changes its nature frequently */
+#define DADV_OWNDECAY   6       /* task defined its own decay policy */
+
+#define DADV_POLICY     0x00F   /* policy mask */
+
+#define DADV_CLEAR      0x010   /* clear statistics: nature is changing */
+#define DADV_INHERIT    0x020   /* children of same nature */
+#define DADV_EXEC       0x040   /* maintain advice after exec */
+#define DADV_EXECONCE   0x080   /* maintain advice after only the next exec */
+#define DADV_NOINHERIT  0x100   /* cancel inheritance */
+#define DADV_NOEXEC     0x200   /* cancel advice on exec */
+#define DADV_NOEXECONCE 0x400   /* cancel DADV_EXECONCE */
+#define DADV_ENQUIRE    0x1000  /* enquire decay policy */
+
+#define DADV_DEFAULT    DADV_SLOWDECAY
+
+#define DECAY_QUOTIENT  1000    /* quotient for the "decay" argument */
+
+
+/* load information */
+
+struct mosix_info {
+        unsigned long load;
+        unsigned short speed;
+        unsigned short ncpus;
+        unsigned short util;
+        unsigned short status;
+        unsigned int mem;
+        unsigned int rmem;
+        unsigned int tmem;
+#ifdef CONFIG_MOSIX_RESEARCH
+        unsigned int rio;   /* read io  */
+        unsigned int wio;   /* write io */
+#endif /* CONFIG_MOSIX_REASEARCH */
+};
+
+#endif
diff -ruN linux-2.4.16/include/mos/mosixtask.h linux-2.4.16-mosix/include/mos/mosixtask.h
--- linux-2.4.16/include/mos/mosixtask.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/mosixtask.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#ifndef _LINUX_MOSIXTASK_H
+#define _LINUX_MOSIXTASK_H
+
+#include <mos/defs.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+
+typedef long long now_t;
+#ifdef CONFIG_MOSIX_DFSA
+struct dfsatab;
+#endif /* CONFIG_MOSIX_DFSA */
+
+#ifdef CONFIG_MOSIX_FS
+struct dentry;
+struct mfs_stats;
+#endif /* CONFIG_MOSIX_FS */
+
+struct opcost
+{
+	int page, syscall, out, outkb, in, inkb;
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	int first, last;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+};
+
+struct mosix_task
+{
+	volatile uint32_t dflags;	/* distributed (MOSIX) flags */
+	atomic_t dreqs;			/* bits that others may request */
+	/* following chars/bits should be in dflags, but modified within
+	 * interrupt code... if only the compiler generated single-instruction
+	 * codes for "|=" and "&=~" (but it doesn't) */
+	volatile char commpri;		/* prioririty for MOSIX communication */
+	volatile char ignoreoldsigs;	/* deliberately cleared ->sigpending */
+	volatile char catchme;		/* catch for debugging */
+
+	char hsleep_count;		/* count on DHEAVYSLEEP */
+	volatile int whereto;		/* migration request */
+	int lock_depth;			/* of the mosix_flag */
+	volatile uint32_t stay;		/* reasons why process must stay */
+	struct prequest *prequest;	/* requests to this task */
+	int whereami;			/* where the process is */
+	int deppe;			/* where the process came from */
+	volatile long bstate;		/* backed-up state while in MOSIX */
+	rwlock_t state_lock;		/* changes of bstate */
+	kernel_cap_t remote_caps;	/* effective capabilities on REMOTE */
+	struct held_files
+	{
+		struct file *f;		/* a file in use */
+		char denywrite;		/* whether holding i_writecount down */
+	} *held_files;			/* files held by remote VM */
+	int held_allocated;		/* # of entries in "held_inodes" */
+	struct mosix_link *contact;	/* DEPUTY <==> REMOTE connection */
+	struct task_struct *ancesstor;	/* nearest ancesstor when dependent */
+	uint32_t deputytime;		/* ticks spent on DEPUTY */
+	long last_sigxcpu;		/* last [prof] time SIGXCPU was sent */
+	int64_t passedtime;		/* time already passed to DEPUTY */
+	int64_t uttime;		/* time to add(REMOTE)/subtract(LOCAL) to/from
+				 * times->tms_utime for statistic purposes */
+	int64_t dctime;		/* decayed user-time (ms) */
+	int64_t cutime;		/* cummulative dependent-child user-time (ms) */
+	int64_t pagetime;	/* time waiting for free pages (ms) */
+	int64_t ndemandpages;	/* statistical # of demand pages */
+	int64_t nsyscalls;	/* statistical # of of syscalls */
+	int64_t ncopyouts;	/* statistical # of copying kernel to user */
+	int64_t copyoutbytes;	/* statsitical # of bytes to user */
+	int64_t ncopyins;	/* statistical # of copying user to kernel */
+	int64_t copyinbytes;	/* statistical # of bytes from user */
+	uint32_t iocounter;	/* combintaion of above statistics */
+	struct opcost depcost[MAX_MOSIX_TOPOLOGY]; /* costs on DEPUTY */
+	int depspeed;		/* speed of DEPUTY */
+	int64_t last_consider;	/* user time since last considered migration */
+	now_t last_mconsider;	/* when last selected for memory-balancing */
+	unsigned short decsecs;	/* seconds within decay cycle */
+	unsigned short deccycle;/* length of decay cycle in seconds */
+	short decay;		/* decay factor (out of DECAY_QUOTIENT) */
+	unsigned char dpolicy;	/* statistic-collection policy */
+	char disclosure;	/* level of disclosure */
+	uint32_t asig;		/* signals arriving on REMOTE */
+	siginfo_t *forced_sigs;	/* REMOTE forced signals */
+	int nforced_sigs;	/* # of REMOTE forced signals */
+	int pages_i_bring;	/* # if pages still to be brought */
+	int rpagecredit;	/* # of expected remote page-faults */
+	int rfreepages;		/* # of mapped-pages to bring without penalty */
+	int page_allocs;	/* page allocation requests decaying counter */
+	short ran;		/* ticks running during last second */
+	unsigned short runstart;/* "load_ticks" (+1) since running */
+	int nmigs;		/* number of [successful] migrations - ever */
+	int load;		/* estimated contribution to load */
+	int sonpid;		/* pid of son in remote-fork */
+	int loadhere;		/* original local load */
+	int migpages;		/* # of migrating pages */
+	void *inexec;		/* structure while in "exec" */
+	wait_queue_head_t wait_dist;/* misc. wait for process */
+	unsigned long exit_mem;	/* memory on REMOTE when exited */
+	unsigned short deputy_regs; /* bit map of regs in charge of DEPUTY */
+	unsigned short pass_regs; /* bit map of regs to pass */
+	__u32 features[NCAPINTS]; /* CPU features on original node */
+	short mypid;		/* original PID */
+	short sigmig;		/* signal to receive on migration */
+	uint32_t *altregs;	/* place of registers when not on stack-top */
+	void *mosix_log;
+	struct data_cache *ucache;
+	char *ps;		/* common "ps" information */
+	int memused, memunused, memswapped;	/* memory split-up */
+	struct depinfo
+	{
+		pid_t pgrp;
+		pid_t session;
+		char comm[16];
+		pid_t tgid;
+	} depinfo;
+	unsigned int dirty_bits;	/* hidden bit-args to Linux routines */
+	unsigned int dirty_arg;		/* hidden argument to Linux routines */
+#ifdef CONFIG_MOSIX_DFSA
+	int copy_ins;
+	int bytes_in;
+	uint32_t dupdates;
+	struct dfsatab *ttab;
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	int iget_mfs_pe;
+	unsigned long long iget_mfs_handle;
+	int selected;
+	int lastexec;
+	int lastmagic;
+	struct mfs_stats *mfs_stats;
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DIAG
+	int mig_page_count;
+#endif /* CONFIG_MOSIX_DIAG */
+};
+
+#ifdef CONFIG_MOSIX_DFSA
+#define	DFSA_INIT_TASK	/* All fields are 0, nothing to declare */
+#else
+#define DFSA_INIT_TASK
+#endif /* CONFIG_MOSIX_DFSA */
+
+#ifdef CONFIG_MOSIX_FS
+#define	MFS_INIT_TASK	/* All fields are 0, nothing to declare */
+#else
+#define	MFS_INIT_TASK
+#endif /* CONFIG_MOSIX_FS */
+
+/* only non-zero fields are mentioned: */
+#define MOSIX_INIT_TASK(tsk) mosix: { \
+	dreqs:		ATOMIC_INIT(0),		\
+	lock_depth:  	-1,			\
+	bstate:		TASK_SAME, 		\
+	wait_dist: 	__WAIT_QUEUE_HEAD_INITIALIZER(tsk.mosix.wait_dist), \
+	state_lock:	RW_LOCK_UNLOCKED,	\
+	disclosure:	CONFIG_MOSIX_DISCLOSURE \
+	DFSA_INIT_TASK \
+	MFS_INIT_TASK \
+}
+
+/*
+ * distributed flags (dflags) that are set only by the process itself,
+ * (but may be read by others):
+ * the following locks (in correct order of locking) are required to
+ * modify those bits:
+ *
+ * DINSCHED:		runqueue_lock
+ * DHEAVYSLEEP:		runqueue_lock
+ * DREMOTEDFSA:		runqueue_lock
+ * DPASSING:		runqueue_lock
+ * DINCOMING:		runqueue_lock
+ * DDEPUTY:		lock_mosix, tasklist_lock, runqueue_lock, task_lock
+ * DFINISHED:		lock_mosix, runqueue_lock, task_lock
+ * DPAGEIN:		runqueue_lock
+ * DSENTURGENT:		runqueue_lock
+ * DFAKESIGNAL:		sometimes sigmask_lock 
+ */
+#define DDEPUTY		0x00000001	/* process is a DEPUTY stub */
+#define DREMOTE		0x00000002	/* process is running remotely */
+#define	DINSCHED	0x00000004	/* MOSIX task within "schedule" */
+#define DSYNC		0x00000008	/* remote process is synced and waits */
+#define DPSYNC		DSYNC		/* deputy must tell us to continue */
+#define DNESTED		0x00000010	/* nested requests from remote */
+#define	DSENTURGENT	0x00000020	/* REMOTE has already sent OOB */
+#define DINCOMING	0x00000040	/* process coming here */
+#define DPASSING	0x00000080	/* process is in migration */
+#define DPAGEIN		0x00000100	/* in pagein, considered running */
+#define DFINISHED	0x00000200	/* wants to become zombie */
+#define	DREMOTEDAEMON	0x00000400	/* set DREMOTE on "fork" */
+#define	DFAKESIGNAL	0x00000800	/* produce a fake signal */
+#define	DHEAVYSLEEP	0x00001000	/* prevent signals/events when asleep */
+#define	DTRACESYS1	0x00002000	/* PT_TRACESYS done before syscall */
+#define	DTRACESYS2	0x00004000	/* syscall done before 2nd PT_TRACESYS*/
+#define	DMUSTBEBACK	0x00008000	/* MUST arrive back home */
+#define	DDUMPABLE	0x00010000	/* copy of dumpable when DEPUTY */
+#define	DDELAYHELD	0x00020000	/* rebuild held_files later */
+#ifdef CONFIG_MOSIX_DFSA
+#define	DSTATSDOWN	0x00800000	/* turn off local system-call stats */
+#define	DREMOTEDFSA	0x01000000	/* on REMOTE: within a DFSA syscall */
+#endif /* CONFIG_MOSIX_DFSA */
+
+/*
+ * bits in "dreqs" (anything that others can set):
+ */
+
+#define DREQ_NICECNG		0x00000001	/* priority changed */
+#define	DREQ_UPDOVERHEADS	0x00000002	/* update overheads */
+#define	DREQ_HOMEWAKE		0x00000004	/* wake when arrived home */
+#define	DREQ_CHECKCONF		0x00000008	/* check MOSIX configuration */
+#define	DREQ_CHECKSTAY		0x00000010	/* check whether still stay */
+#define	DREQ_URGENT		0x00000020	/* something urgent (R=>D) */
+#define	DREQ_CAPCNG		0x00000040	/* capabilities changed */
+#define	DREQ_INFOCNG		0x00000080	/* disclosed info changed */
+#define	DREQ_FILEUNMAP		0x00000100	/* file(s) were unmapped */
+#ifdef CONFIG_MOSIX_DFSA
+#define	DREQ_NOTUPTODATE	0x10000000	/* send it all again */
+#define	DREQ_DFSASYNC		0x20000000	/* DFSA world changed */
+#define	DREQ_EXITDFSA		0x40000000	/* call DEPUTY ASAP */
+#else
+#define	DREQ_DFSASYNC		0
+#define	DREQ_EXITDFSA		0
+#endif /* CONFIG_MOSIX_DFSA */
+
+#define	tell_process(p,what)	atomic_set_mask(what,&(p)->mosix.dreqs)
+#define	process_ack(p,what)	atomic_clear_mask(what,&((p)->mosix.dreqs))
+#define	process_told(p,what)	(atomic_read(&((p)->mosix.dreqs)) & (what))
+
+/*
+ * reasons to stay:
+ */
+
+#define DSTAY_FOR_MONKEY 0x00000001	/* using monkey vnode */
+#define DSTAY_FOR_DEV	 0x00000002	/* mapping a device */
+#define DSTAY_FOR_86	 0x00000004	/* running in 86 mode */
+#define DSTAY_ITS_DAEMON 0x00000008	/* daemon process */
+#define DSTAY_FOR_PRIV	 0x00000010	/* privilleged inst. access (in/out) */
+#define DSTAY_FOR_MLOCK	 0x00000020	/* has locked memory */
+#define DSTAY_FOR_CLONE	 0x00000040	/* shared VM */
+#define DSTAY_FOR_RT	 0x00000080	/* Real-Time scheduling */
+#define	DSTAY_FOR_IOPL	0x00000100	/* direct I/O permission */
+#define	DSTAY_ITS_INIT	0x00000200	/* init process */
+#define	DSTAY_FOR_KIOBUF 0x00000400	/* using kiobuf */
+#define	DSTAY_OTHER1	0x01000000	/* external reason for stay (1) */
+#define	DSTAY_OTHER2	0x02000000	/* external reason for stay (2) */
+#define	DSTAY_OTHER3	0x04000000	/* external reason for stay (3) */
+#define	DSTAY_OTHER4	0x08000000	/* external reason for stay (4) */
+#define DNOMIGRATE	0x80000000	/* user requested no auto-migrations */
+
+#define DSTAY   (~DNOMIGRATE)
+#define	DSTAY_PER_MM	(DSTAY_FOR_MONKEY|DSTAY_FOR_DEV|DSTAY_FOR_MLOCK|DSTAY_FOR_KIOBUF)
+
+/*
+ * where to go (whereto)
+ */
+#define GOBACKHOME	(-1)	/* just go back home */
+#define BALANCE		(-2)	/* perform load balancing */
+#define IOBALANCE	(-3)	/* perform load balancing for I/O */
+#define MEMBALANCE	(-4)	/* perform balancing for memory */
+#define	MFSBALANCE	(-5)	/* must go back home */
+#define	MUSTGOHOME	(-6)	/* must go back home */
+
+#define	evaluate_pending_signals_in_mosix_context() do { \
+	struct task_struct *p = current; \
+	unsigned long flags; \
+	spin_lock_irqsave(&p->sigmask_lock,flags);\
+	if(p->mosix.ignoreoldsigs) \
+		p->sigpending = (p->mosix.dflags & (DFAKESIGNAL|DHEAVYSLEEP)) == DFAKESIGNAL; \
+	else recalc_sigpending(p); \
+	spin_unlock_irqrestore(&p->sigmask_lock,flags); \
+	} while(0)
+
+#define	deeper_sleep() do { \
+	struct task_struct *p = current; \
+	if(!p->mosix.hsleep_count++) { \
+		unsigned long flags; \
+		spin_lock_irq(&runqueue_lock); \
+		p->mosix.dflags |= DHEAVYSLEEP; \
+		spin_unlock_irq(&runqueue_lock); \
+		spin_lock_irqsave(&p->sigmask_lock,flags); \
+		p->sigpending = 0; \
+		spin_unlock_irqrestore(&p->sigmask_lock,flags); \
+	} } while(0)
+
+#define	lighter_sleep() do { \
+	struct task_struct *p = current; \
+	if(!--p->mosix.hsleep_count) { \
+		spin_lock_irq(&runqueue_lock); \
+		p->mosix.dflags &= ~DHEAVYSLEEP; \
+		spin_unlock_irq(&runqueue_lock); \
+		evaluate_pending_signals_in_mosix_context(); \
+	} } while(0)
+
+#define	set_me_dumpable(on) do { \
+		if(current->mm) current->mm->dumpable = (on); \
+		else if((on)) current->mosix.dflags |= DDUMPABLE; \
+		else current->mosix.dflags &= ~DDUMPABLE; \
+	} while(0)
+
+#define	i_am_dumpable()	((current->mosix.dflags & DDEPUTY) ? \
+	(current->mosix.dflags & DDUMPABLE) != 0 : \
+	current->mm ? current->mm->dumpable : 0)
+
+/* dirty parameters: */
+/* sorry we are not allowed to add parameters to standard Linux routines */
+/* because they can be called by who knows what - even modules, so instead: */
+#define	MMAP_MMDOWNED		0x01	/* MM was downed prior to mmap() */
+#define	MMAP_MAYSHARE		0x02	/* ornament with VM_MAYSHARE */
+#define	MAPS_NOUSER		0x04	/* do not copy maps to user */
+#ifdef CONFIG_MOSIX_FS
+#define	MFSARG_OLDREADDIR	0x08	/* this is "old_readdir" calling */
+#define	MFSARG_GETDENTS		0x10	/* this is "getdents" calling */
+#define	MFSARG_GETDENTS64	0x20	/* this is "getdents" calling */
+#define	MFSARG_EMPTYF_PRI	0x40	/* obtain empty file even beyond limit*/
+#define	MFSARG_RONLY		0x80	/* no write-permission on anything */
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+#define	FILP_OPEN_SYSCALL	0x100	/* filp_open called from sys_open */
+#endif /* CONFIG_MOSIX_DFSA */
+
+#endif
diff -ruN linux-2.4.16/include/mos/protocol.h linux-2.4.16-mosix/include/mos/protocol.h
--- linux-2.4.16/include/mos/protocol.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/protocol.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,559 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Oren Laadan.
+ */
+#ifndef _MOS_PROTOCOL_H
+#define _MOS_PROTOCOL_H
+#ifdef CONFIG_MOSIX
+#ifdef __KERNEL__
+
+#include <linux/signal.h>
+#include <linux/resource.h>
+#include <linux/elf.h>
+
+#define	EDIST	EDOM	/* MOSIX general error-code, that is otherwise */
+			/* rarely-if-ever returned by kernel */
+
+struct mosix_addr {
+	struct sockaddr saddr;
+};
+
+
+/* structures passed between DEPUTY and REMOTE: */
+
+struct mig_request_h
+{
+	long version;
+	short reason;
+	short topology;
+	int personality;
+	int wp_works_ok;
+	int pages_sent;
+	int request_type;
+	int has_dfsa;
+};
+
+enum contact_type
+{
+	FROM_DEPUTY, DEPUTY_PROBE, FROM_REMOTE
+};
+
+struct please_migrate_h
+{
+	int reason;
+	int to;
+	struct mosix_addr ma;
+};
+
+struct mmap_parameters_h
+{
+	unsigned long addr;
+	int fixed;
+	unsigned long len;
+	unsigned long flags;
+	unsigned long pgoff;
+	int origin;
+	struct file *fp;
+	struct dentry *dp;
+	uint64_t uniq;
+	off_t isize;
+	nopage_t nopage;
+};
+
+struct brk_parameters_h
+{
+	unsigned long addr;
+	unsigned long len;
+};
+
+struct munmap_parameters_h
+{
+	unsigned long addr;
+	size_t len;
+};
+
+struct mprotect_parameters_h
+{
+	unsigned long addr;
+	size_t len;
+	unsigned long prot;
+};
+
+struct setupframe_parameters_h
+{
+	unsigned long sig;
+	unsigned long flags;
+	__sighandler_t handler;
+	void (*restorer)(void);
+	sigset_t set;
+	struct siginfo info;
+	unsigned long ss_sp;
+	size_t ss_size;
+};
+
+struct restore_sigcontext_ret_h
+{
+	int result;
+	int eax;
+};
+
+struct prequest_h
+{
+	char command;
+	int param;
+	int param2;
+	int len;
+};
+
+struct prequest_reply_h
+{
+	int reply;
+	int error;
+	int datalen;
+};
+
+struct user_copy_h
+{
+	void *addr;
+	unsigned int size;
+	char verify;
+};
+
+struct strnlen_user_h
+{
+	char *addr;
+	long len;
+};
+
+struct user_csum_copy_h
+{
+	void *addr;
+	unsigned int len;
+	int sum;
+};
+
+struct user_csum_copy_ret_h
+{
+	unsigned int newsum;
+	unsigned int error;
+};
+
+struct asig_h
+{
+	unsigned int sigs;
+	int nforced;
+};
+
+struct syscall_h
+{
+	int n;
+	unsigned int args[6];
+	int simple_data_type;
+	unsigned long simple_data_addr;
+	int simple_data_len;
+	int simple_data_actual;
+};
+
+struct syscall_ret_h
+{
+	long ret;
+	unsigned long deputytime;
+	unsigned long simple_data_addr;
+	int simple_data_len;	/* -1 = complex data */
+};
+
+struct bring_page_h
+{
+	struct file *fp;
+	unsigned long offset;
+	nopage_t nopage;
+};
+
+struct page_ret_h
+{
+	int ret;
+	unsigned long deputytime;
+};
+
+struct rlimit_h
+{
+	int resource;
+	struct rlimit limit;
+};
+
+struct execve_counts_h
+{
+	char **argp;
+	char **envp;
+};
+
+struct execve_counts_ret_h
+{
+	int argc;
+	int envc;
+};
+
+struct execve_bring_strings_h
+{
+	unsigned long p;
+	char *filename;
+	char **envp;
+	int envc;
+	char **argp;
+	int argc;
+};
+
+struct execve_bring_strings_ret_h
+{
+	unsigned long p;
+	unsigned long exec;
+	int pgno;
+	int len;
+	int result;
+};
+
+struct execve_more_strings_h
+{
+	int pgno;
+	int len;
+};
+
+struct execve_setup_args_h
+{
+	int create;
+	int pgno;
+	int len;
+	int how;
+	int p;
+	int loader;
+	int exec;
+	int argc;
+	int envc;
+	unsigned long personality;
+};
+
+struct execve_setup_args_ret_h
+{
+	unsigned long p;
+	unsigned long loader;
+	unsigned long exec;
+	int reply;
+	unsigned long start_stack;
+};
+
+struct execve_exec_mmap_ret_h
+{
+	int result;
+	char comm[16];
+};
+
+struct execve_elf_setup_h
+{
+	char *p;
+	int argc;
+	int envc;
+	int hasexec;
+	unsigned long exec_e_phoff;
+	unsigned long exec_e_phnum;
+	unsigned long exec_e_entry;
+	unsigned long addr;
+	unsigned long load_bias;
+	unsigned long interp_load_addr;
+	int ibcs;
+	struct elf_tables_extras extras;
+	int add_arg_start;
+	unsigned long elf_brk;
+	unsigned long end_code;
+	unsigned long start_code;
+	unsigned long start_data;
+	unsigned long end_data;
+	unsigned long elf_bss;
+	unsigned long personality;
+};
+
+struct execve_fix_elf_aout_h
+{
+	unsigned bss;
+	unsigned data;
+	unsigned text;
+};
+
+struct list_vmas_ret_h
+{
+	int n;
+	unsigned long argstart;
+	unsigned long argend;
+};
+
+struct fork_h
+{
+	unsigned long usp;
+	int do_forkmigrate;
+	int pid;
+};
+
+struct mm_stats_h
+{
+	unsigned long start_code, end_code, start_data, end_data;
+	unsigned long start_brk, brk, start_stack;
+	unsigned long arg_start, arg_end, env_start, env_end;
+};
+
+struct disclosure_h
+{
+	uid_t uid;
+	gid_t gid;
+	pid_t pgrp;
+	pid_t session;
+	char disclosure;
+	char comm[16];
+	pid_t tgid;
+};
+
+struct mig_misc_h
+{
+	unsigned long ptrace;
+	unsigned long dflags;
+	long debugreg[8];
+	long nice;
+	kernel_cap_t caps;
+	unsigned long it_prof_value, it_prof_incr, it_virt_value, it_virt_incr;
+	struct pt_regs regs;
+	struct rlimit rlim_cpu, rlim_data, rlim_stack, rlim_rss, rlim_as;
+#ifdef CONFIG_MOSIX_DFSA
+	struct rlimit rlim_nofile, rlim_fsz;
+#endif /* CONFIG_MOSIX_DFSA */
+	char stay;
+	unsigned short deppe;
+	unsigned short deputy_regs;
+	u64 passedtime;
+	u16 deccycle;
+	s16 decay;
+	u8 dpolicy;
+	pid_t mypid;
+	struct asig_h asig;
+	struct disclosure_h info;
+	int nmigs;
+	int pagecredit;
+	int lastxcpu;
+	__u32 features[NCAPINTS];
+	u64 tscval;
+	struct opcost depcost[MAX_MOSIX_TOPOLOGY];
+	int depspeed;
+};
+
+struct decay_h
+{
+	int policy;
+	int deccycle;
+	int decay;
+};
+
+struct aload_h
+{
+	int aload;
+	int freepages;
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	struct mfs_cost mfscosts[MAX_MOSIX_TOPOLOGY];
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+};
+
+#ifdef CONFIG_MOSIX_DFSA
+struct read_yourself_h
+{
+	int dfsano;
+	loff_t off;
+	unsigned long addr;
+	unsigned long len;
+	int infolen;
+};
+#endif /* CONFIG_MOSIX_DFSA */
+
+/* COMMAND CLASSES: */
+
+#define	DEP_FLG	0x100
+#define	MIG_FLG	0x200
+#define	REPLY	0x400
+#define	ANYTIME	0x800
+#define	USERMODE 0x1000
+#ifdef CONFIG_MOSIX_DFSA
+#define	DFSA_NOUPDATE	0x2000
+#else
+#define	DFSA_NOUPDATE	0
+#endif /* CONFIG_MOSIX_DFSA */
+
+/* COMMANDS: */
+
+#define	DEP_USERMODE		(DEP_FLG|0x00)
+#define	DEP_SYNC		(DEP_FLG|0x01)
+#define	DEP_NOTHING		(DEP_FLG|0x02)
+#define	DEP_MMAP		(DEP_FLG|0x03)
+#define	DEP_MUNMAP		(DEP_FLG|0x04)
+#define	DEP_LISTHOLD		(DEP_FLG|0x05)
+#define	DEP_SETUPFRAME		(DEP_FLG|0x06)
+#define	DEP_NICE		(DEP_FLG|0x07)
+#define	DEP_CPAS		(DEP_FLG|0x08)
+#define	DEP_RESTORESIGCONTEXT	(DEP_FLG|0x09)
+#define	DEP_PREQUEST		(DEP_FLG|0x10)
+#define	DEP_COPY_FROM_USER	(DEP_FLG|0x11)
+#define	DEP_COPY_TO_USER	(DEP_FLG|0x12)
+#define	DEP_CLEAR_USER		(DEP_FLG|0x13)
+#define	DEP_STRNCPY_FROM_USER	(DEP_FLG|0x14)
+#define	DEP_STRNLEN_USER	(DEP_FLG|0x15)
+#define	DEP_VERIFY_WRITE	(DEP_FLG|0x16)
+#define	DEP_RLIMIT		(DEP_FLG|0x17)
+#define	DEP_TAKEURGENT		(DEP_FLG|0x18)
+#define	DEP_RUSAGE		(DEP_FLG|0x19)
+#define	DEP_EXECVE_COUNTS	(DEP_FLG|0x20)
+#define	DEP_BRING_STRINGS	(DEP_FLG|0x21)
+#define	DEP_SETUP_ARGS		(DEP_FLG|0x22)
+#define	DEP_EXEC_MMAP		(DEP_FLG|0x23)
+#define	DEP_DUMP_THREAD		(DEP_FLG|0x24)
+#define	DEP_INIT_AOUT_MM	(DEP_FLG|0x25)
+#define	DEP_ELF_SETUP		(DEP_FLG|0x26)
+#define	DEP_FIX_ELF_AOUT	(DEP_FLG|0x27)
+#define	DEP_LIST_VMAS		(DEP_FLG|0x28)
+#define	DEP_PLEASE_FORK		(DEP_FLG|0x29)
+#define DEP_CONSIDER		(DEP_FLG|0x30)
+#define	DEP_PERSONALITY		(DEP_FLG|0x31)
+#define	DEP_BRING_ME_REGS	(DEP_FLG|0x32)
+#define	DEP_CSUM_COPY_FROM_USER	(DEP_FLG|0x33)
+#define	DEP_DUMP_FPU		(DEP_FLG|0x34)
+#define	DEP_COME_BACK		(DEP_FLG|0x35)
+#define DEP_PLEASE_MIGRATE	(DEP_FLG|0x36)
+#define	DEP_CACHE_READ_DATA	(DEP_FLG|0x37)
+#define	DEP_DATA_TO_USER	(DEP_FLG|0x38)
+#define	DEP_UPDATE_DECAY	(DEP_FLG|0x39)
+#define	DEP_UPDATE_LOCK		(DEP_FLG|0x40)
+#define	DEP_PSINFO		(DEP_FLG|0x41)
+#define	DEP_OPCOSTS		(DEP_FLG|0x42)
+#define	DEP_MPROTECT		(DEP_FLG|0x43)
+#define	DEP_BRK			(DEP_FLG|0x44)
+#define	DEP_CAPS		(DEP_FLG|0x45)
+#define	DEP_INFO		(DEP_FLG|0x46)
+#ifdef CONFIG_MOSIX_DFSA
+#define	DEP_DFSA_CHANGES	(DEP_FLG|0x80)
+#define	DEP_DFSA_CLEAR		(DEP_FLG|0x81)
+#define	DEP_READ_YOURSELF	(DEP_FLG|0x82)
+#endif /* CONFIG_MOSIX_DFSA */
+
+#define	REM_NOTHING		(ANYTIME|0x01)
+#define	REM_PAGE		(ANYTIME|DFSA_NOUPDATE|0x02)
+#define	REM_MORESTRINGS		(ANYTIME|0x03)
+#define	REM_BRING_ME_REGS	(ANYTIME|0x04)
+#define	REM_GETALOAD		(ANYTIME|0x05)
+#define	REM_GETTSC		(ANYTIME|0x06)
+
+#define	REM_NULLMSG		0x01
+#define	REM_ASIG		0x02
+#define	REM_SYSCALL_TRACE	0x03
+#define	REM_SYSCALL		0x04
+#define REM_BRING_ME_HOME	0x05
+#define	REM_BRING_ME_TO		0x06
+#define	REM_CONSIDERING		0x07
+#define	REM_MUST_COME_HOME	0x08
+#define	REM_CONNECT_TO		0x09
+
+#define MIG_REQUEST		(MIG_FLG|0x01)
+
+#define	MIG_MM_STATS		(MIG_FLG|0x10)
+#define	MIG_MM_AREA		(MIG_FLG|0x11)
+#define	MIG_PAGE		(MIG_FLG|0x12)
+#define	MIG_FP			(MIG_FLG|0x13)
+#define	MIG_XFP			(MIG_FLG|0x14)
+#define	MIG_LDT			(MIG_FLG|0x15)
+#define	MIG_MISC		(MIG_FLG|0x16)
+#define	MIG_NOT_COMING		(MIG_FLG|0x17)
+
+/* routines on the DEPUTY side of the protocol: */
+
+extern int deputy_request(int, void *, int, void *, int, int, void **, int);
+extern int deputy_wait(int, void **, int *);
+extern int deputy_reply(int, void *, int, void *, int, int, int);
+extern int deputy_handle_interim_request(int, void *, int);
+extern void deputy_syscall(struct syscall_h *, int);
+extern void deputy_rusage(int);
+extern void deputy_add_rusage(struct rusage *);
+extern void deputy_analyse_remote_signals(struct asig_h *);
+extern int deputy_bring_page(struct bring_page_h *);
+extern int deputy_tsc(void);
+extern int deputy_more_strings(struct execve_more_strings_h *);
+extern int deputy_bring_me_regs(unsigned long *);
+extern void deputy_inform_remote_of_overheads(void);
+
+/* routines on the REMOTE side of the protocol: */
+
+extern int remote_request(int, void *, int, void *, int, int, void **, int);
+extern void wait_for_permission_to_continue(void);
+extern int remote_deputy_has_something_for_us(struct task_struct *);
+extern void inform_deputy_of_urgent(void);
+extern void transfer_signals_to_deputy(unsigned int, siginfo_t *, int);
+extern void absorb_deptime(unsigned long);
+extern int remote_rusage(int *);
+extern int remote_execve_counts(struct execve_counts_h *);
+extern int remote_bring_strings(struct execve_bring_strings_h *);
+extern int remote_setup_args(struct execve_setup_args_h *);
+extern int remote_exec_mmap(void);
+extern int remote_urgent(void);
+extern int remote_readpage(struct file *, struct page *);
+extern int remote_dump_thread(void);
+extern int remote_init_aout_mm(struct exec *);
+extern int remote_elf_setup(struct execve_elf_setup_h *);
+extern int remote_fix_elf_aout(struct execve_fix_elf_aout_h *);
+extern int remote_list_vmas(void);
+extern int remote_fork(struct fork_h *);
+extern int remote_personality(unsigned long *);
+extern int remote_prequest(struct prequest_h *);
+extern int remote_mmap(struct mmap_parameters_h *, int);
+extern int remote_brk(struct brk_parameters_h *);
+extern int remote_munmap(struct munmap_parameters_h *);
+extern int remote_mprotect(struct mprotect_parameters_h *);
+extern int remote_come_back(void *);
+extern int remote_goto_remote(void *);
+extern int remote_copy_from_user(struct user_copy_h *);
+extern int remote_copy_to_user(struct user_copy_h *);
+extern int remote_data_to_user(struct user_copy_h *);
+extern int remote_clear_user(struct user_copy_h *);
+extern int remote_strncpy_from_user(struct user_copy_h *);
+extern int remote_strnlen_user(struct strnlen_user_h *);
+extern int remote_verify_write(struct user_copy_h *);
+extern int remote_csum_copy_from_user(struct user_csum_copy_h *);
+extern int remote_csum_copy_to_user(struct user_csum_copy_h *);
+extern int remote_report_files(void);
+extern int remote_setup_frame(struct setupframe_parameters_h *);
+extern int remote_nice(long *);
+extern int remote_caps(kernel_cap_t *);
+extern int remote_depcosts(void *);
+extern int remote_restore_sigcontext(struct sigcontext **);
+extern int remote_bring_me_regs(unsigned long *);
+extern int remote_dump_fpu(void);
+extern int remote_consider(int *);
+extern int remote_setdecay(struct decay_h *);
+extern int remote_set_lock(int *);
+extern int remote_psinfo(void);
+#ifdef CONFIG_MOSIX_DFSA
+extern int remote_receive_dfsachanges(int *);
+extern int remote_read_yourself(struct read_yourself_h *);
+#endif /* CONFIG_MOSIX_DFSA */
+extern int remote_rlimit(struct rlimit_h *);
+extern int remote_updinfo(struct disclosure_h *);
+extern void remote_do_updinfo(struct disclosure_h *);
+extern void remote_fill_rusage(struct rusage *, int);
+
+/* routines used by both sides of the protocol: */
+
+extern unsigned int which_regs_to_send(void);
+extern void regs_were_sent(void);
+
+#endif /*__KERNEL__*/
+#endif /* CONFIG_MOSIX */
+#endif
diff -ruN linux-2.4.16/include/mos/request.h linux-2.4.16-mosix/include/mos/request.h
--- linux-2.4.16/include/mos/request.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/request.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#ifndef _MOS_REQUEST_H
+#define _MOS_REQUEST_H
+#ifdef CONFIG_MOSIX
+
+struct prequest
+{
+	struct prequest *rnext;		/* next in request chain */
+	struct prequest *cnext;		/* caller chain */
+	volatile char rflags;		/* coordination flags - see below */
+	char command;			/* ... */
+	int param;			/* optional parameter */
+	int param2;			/* optional parameter */
+	caddr_t ereply;		 	/* extended reply address */
+	int len;			/* optional extended reply length */
+	long reply;			/* reply, if only one longword */
+	wait_queue_head_t waitq;	/* who is waiting for the reply */
+};
+
+/* flags: */
+
+#define PR_WAITING	1       /* caller still waiting for the request */
+#define PR_DONE	 	2	/* request complete */
+#define PR_ERROR	4	/* request failed, reply contains errno */
+
+/* commands: */
+
+enum
+{
+PR_PROCFS_TASK_MEM = 1,
+PR_PROCFS_GET_ENV,
+PR_PROCFS_GET_ARG,
+PR_PROCFS_GET_STAT_PARTS,
+PR_PROCFS_GET_STATM,
+PR_PROCFS_MAP_INFO,
+PR_PROCFS_MEM_READ,
+PR_PROCFS_MEM_WRITE,
+PR_PROCFS_UPDATE_TIMES,
+PR_PROCFS_GET_EXE,
+PR_PTRACE_GET_STACK_LONG,
+PR_PTRACE_PUT_STACK_LONG,
+PR_PTRACE_GETREGS,
+PR_PTRACE_SETREGS,
+PR_PTRACE_PEEKUSER,
+PR_PTRACE_POKEUSER,
+PR_PTRACE_CONT,
+PR_PTRACE_SINGLE_STEP,
+PR_PTRACE_GETFPREGS,
+PR_PTRACE_SETFPREGS,
+PR_PTRACE_GETFPXREGS,
+PR_PTRACE_SETFPXREGS,
+PR_PTRACE_NOT_TRACED,
+#ifdef CONFIG_MOSIX_DFSA
+PR_DFSA_SYNCHRONIZE,
+#endif /* CONFIG_MOSIX_DFSA */
+};
+
+#define	SHOULD_ASK_PROCESS(p)	(p && (p->mosix.dflags & DDEPUTY) && (p != current || !(p->mosix.dflags & DINSCHED)))
+
+extern int request_process_arg2(struct task_struct *, void *, int, int, int);
+#define request_process(_t, _b, _c, _a) request_process_arg2(_t, _b, _c, _a, 0)
+extern char *request_process_to_buf_arg(struct task_struct *, char *, int, int);
+#define request_process_to_buf(_p,_b,_c) request_process_to_buf_arg(_p,_b,_c,0)
+
+extern char *fill_common_ps_info(int *);
+extern int pick_ps(struct task_struct *, struct prequest *);
+extern void store_common_ps_info(void);
+extern void stop_storing_common_ps_info(void);
+extern void process_requests(void);
+extern void discard_requests(void);
+extern void process_only_easy_requests(void);
+
+struct proc_remote_stat_parts
+{
+	unsigned long vsize, eip, esp;
+	long priority;
+	unsigned long rss, start_code, end_code, start_stack;
+	long processor;
+};
+
+/* routines in other parts of the kernel that are called by MOSIX: */
+
+extern int proc_pid_environ(struct task_struct *, char *);
+extern int proc_pid_cmdline(struct task_struct *, char *);
+extern char *task_mem(struct mm_struct *, char *);
+extern void proc_get_stat_parts(struct task_struct *, struct mm_struct *, struct proc_remote_stat_parts *);
+extern int proc_pid_statm(struct task_struct *, char *);
+struct vmamaps;
+extern int proc_list_maps(struct vmamaps *, int);
+extern void ref_mapped_files(struct vmamaps *, int);
+extern int get_stack_long(struct task_struct *, int);
+extern int put_stack_long(struct task_struct *, int, unsigned long);
+extern void ptrace_putregs(unsigned long *);
+extern void ptrace_getregs(unsigned long *);
+extern unsigned long ptrace_peekuser(long);
+extern void ptrace_pokeuser(long, long);
+extern void ptrace_cont(int);
+extern void ptrace_single_step(void);
+struct user_i387_struct;
+extern void ptrace_getfpregs(struct user_i387_struct *);
+extern void ptrace_setfpregs(struct user_i387_struct *);
+struct user_fxsr_struct;
+extern void ptrace_getfpxregs(struct user_fxsr_struct *);
+extern void ptrace_setfpxregs(struct user_fxsr_struct *);
+extern struct file *first_executable(void); 
+
+#endif /* CONFIG_MOSIX */
+#endif
diff -ruN linux-2.4.16/include/mos/routines.h linux-2.4.16-mosix/include/mos/routines.h
--- linux-2.4.16/include/mos/routines.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/routines.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#ifndef _MOS_ROUTINES_H
+#define _MOS_ROUTINES_H
+#ifdef CONFIG_MOSIX
+
+#include <linux/stddef.h>
+
+/*
+ * a collection of routines in mos/?*.c that are neither:
+ * 1) used by the rest of the kernel	 --> include/linux/mosix.h
+ * 2) in the communication package	 --> include/mos/comm.h
+ * 3) part of the DEPUTY/REMOTE protocol --> include/mos/protocol.h
+ * 4) related to prequests		 --> include/mos/request.h
+ * 5) related to DFSA			 --> include/mos/dfsa.h
+ */
+
+struct task_struct;
+struct mosixnet;
+
+/* task management: */
+
+extern int remote_need_while_asleep(struct task_struct *);
+extern int other_needs_while_asleep(void);
+extern void remote_run_while_asleep(void);
+extern void deputy_run_while_asleep(void);
+extern int remote_pre_usermode_actions(void);
+extern int local_pre_usermode_actions(void);
+extern void per_task_ack_mosix_state(void);
+extern char *desc_mostask(struct mosix_task *);
+extern void mosix_do_add_to_whereto(struct task_struct *, int);
+extern void common_daemon_setup(char *, int);
+extern void neutralize_my_load(int);
+extern void wait_for_mosix_configuration(int *);
+extern int obtain_mm(void);
+extern void sync_caps(void);
+
+/* load balancing: */
+
+extern void mosix_load_init(void);
+extern void load_balance(void);
+extern void mosix_clear_statistics(void);
+struct sonstats;
+extern void consider(int, struct sonstats *);
+extern int send_local_aload(int);
+extern int send_with_miginfo(int, void *, int);
+extern void mosix_local_syscall(void);
+extern void release_migrations(int);
+extern void changed_my_mind_and_staying(void);
+extern int balance_commit_mig(int, int);
+extern void info_someone_came_in(void);
+extern void end_coming_in(int);
+extern void add_statistics_to_ancesstor(struct task_struct *, struct task_struct *);
+extern void info_update_costs(void);
+extern void info_update_mfscosts(void);
+extern void load_balance(void);
+extern void memory_balance(void);
+extern void age_balancing(void);
+extern void unchoose_me(void);
+
+/* memory: */
+
+extern void init_mdp(void);
+extern void compute_freemem(void);
+extern int export_mem(void);
+extern int memory_badly_required(void);
+extern int memory_relief_quality(struct task_struct *, int);
+extern void memory_balance(void);
+
+/* information dissemination: */
+
+extern void init_mosconfig(void);
+extern int mosix_info_daemon(void *); 
+extern void info_init(void);
+extern void info_startup(void);
+extern void info_reconfig(void);
+struct mosix_info;
+struct loadinfo;
+extern int balance_get_load(int, struct loadinfo *);
+extern int balance_get_infos(int, int, struct mosix_info *, int);
+extern int balance_get_info(int, struct mosix_info *);
+extern void mosinfo_update_gateways(void);
+extern void this_machine_is_favourite(int);
+extern int mosix_mem_daemon(void *); 
+
+/* migration: */
+
+struct mig_request_h;
+extern int mosix_mig_daemon(void *);
+extern int passto(int, int);
+extern int mosix_do_send_back_home(struct task_struct *);
+extern int mosix_do_go_home(int);
+extern void follow_whereto(void);
+extern int mig_migrate(int);
+extern void mig_set_lock(int);
+extern int count_migrating_pages(void);
+extern void kickstart(void);
+extern int run_over_dirty_pages(int (*func)(unsigned long, int), int);
+extern void deputy_startup(void);
+extern int mig_send_request(int, int);
+extern int mig_recv_request(struct mig_request_h **);
+extern int mig_do_send(void);
+extern int mig_do_receive(void);
+
+/* deputy: */
+
+extern void deputy_main_loop(void);
+extern void undeputy(struct task_struct *);
+extern void deputy_async_requests(void);
+extern void mosix_clear_all_held_files(struct task_struct *);
+extern int fork_mosix_remote_files(struct task_struct *);
+extern void coordinate(int, int);
+extern long call_with_regs(void *, struct pt_regs *, struct pt_regs *);
+extern int task_maps_ip(struct task_struct *, struct inode *);
+extern void deputy_communication_failed(void);
+extern void deputy_die_on_communication(void) ATTRIB_NORET;
+
+/* remote: */
+
+extern int remote_wait(int, void **, int *);
+extern void wait_for_permission_to_continue(void);
+extern int remote_request(int, void *, int, void *, int, int, void **, int);
+extern long remote_standard_system_call(int, struct pt_regs *);
+extern struct file *get_remote_file(int, struct file *, struct dentry *, unsigned long long, off_t, nopage_t);
+extern void remote_disappear(void) __attribute__((noreturn));
+
+/* data cache: */
+
+struct syscall_h;
+struct syscall_ret_h;
+extern int copy_from_cache(char *, unsigned long, int, int *);
+extern int copy_to_cache(unsigned long, char *, int, int *);
+extern int zero_cache(char *, int, int *);
+extern int strlen_cache(char *, int *);
+extern int all_in_cache(unsigned long, unsigned int, int);
+extern int any_in_cache(unsigned long, unsigned int);
+extern int alloc_ucache(void);
+extern void free_ucache(void);
+extern void flush_ucache(void);
+extern void flush_read_cache(void);
+extern int ucache_ok(unsigned long, unsigned long, int);
+extern int remote_unpack_read_cache_data(struct syscall_ret_h *);
+extern void set_read_region(unsigned long, unsigned int);
+extern void set_write_region(unsigned long, unsigned int);
+extern char *construct_ucache_envelope(int *, int *, struct syscall_h *, char **);
+extern int open_ucache_envelope(struct syscall_h *);
+extern char *deputy_pack_read_cache_data(int *, struct syscall_ret_h *, char **);
+
+/* configuration: */
+
+extern int count_mosix_nodes(void); 
+extern int nth_node(int);
+extern int mos_to_ascii(int, char *, int);
+extern int mos_to_net(int, void *);
+extern int mymos_to_net(void *);
+extern int mosix_config_get_table(struct mosixnet **, int, int);
+extern int mosix_config_set_table(struct mosixnet *, int, int);
+extern int mosix_config_get_pe(void);
+extern int mosix_config_set_pe(int);
+extern int mosix_config_get_tentative_pe(void);
+extern int mosix_config_get_limit(void);
+extern int count_mosix_nodes(void);
+extern int config_get_status(int);
+extern int config_set_status(int);
+extern int i_am_in_a_wrong_place(void);
+extern void done_checking_conf(void);
+#ifdef CONFIG_MOSIX_FS
+extern int scan_mosix_nodes(int, int *, int *);
+#endif /* CONFIG_MOSIX_FS */
+
+/* statistics decay: */
+
+extern int decay_inherit(int);
+extern int decay_exec(int);
+extern int decay_execonce(int);
+extern int decay_set(int, int, int);
+extern int decay_get(int);
+extern void decay_clear(void);
+extern void deputy_update_remote_decay(void);
+extern void do_decay(void);
+extern void inc_decays(void);
+extern now_t time_now(void);
+#define	time_since(_when_)	(time_now() - (_when_))
+
+/* MOSIX administration: */
+
+extern int admin_get_mode(int);
+extern int admin_set_mode(int, int);
+extern int expel(int);
+extern int bring(void);
+extern void proc_update_costs(void);
+extern int my_mosix_status(void);
+extern void set_my_cpuspeed(void);
+
+/* debugging: */
+
+#ifdef CONFIG_MOSIX_DEBUG
+extern void init_mosix_log(struct task_struct *);
+extern void clear_mosix_log(struct task_struct *);
+#else
+#define	init_mosix_log(m)	do {} while(0)
+#define	clear_mosix_log(m)	do {} while(0)
+#endif /* CONFIG_MOSIX_DEBUG */
+
+/* macros: */
+
+#define	MOSIX_TO_TASK(m) ((struct task_struct *)(((char *)m)-offsetof(struct task_struct,mosix)))
+
+#ifdef CONFIG_MOSIX_DFSA
+#define	URGENT_REMOTE_CONDITIONS(p)	((p)->mosix.whereto || \
+					process_told((p), DREQ_DFSASYNC))
+#else
+#define	URGENT_REMOTE_CONDITIONS(m)	((p)->mosix.whereto)
+#endif /* CONFIG_MOSIX_DFSA */
+#endif /* CONFIG_MOSIX */
+
+#if MILLION % HZ
+#define ticks_to_ms(ticks)	(((int64_t)(ticks)) * MILLION / HZ)
+#define	ms_to_ticks(ms)		((ms) * HZ / MILLION)
+#else
+#define ticks_to_ms(ticks)	(((int64_t)(ticks)) * (MILLION / HZ))
+#define	ms_to_ticks(ms)		((ms) / (MILLION/HZ))
+#endif
+
+#endif
diff -ruN linux-2.4.16/include/mos/version.h linux-2.4.16-mosix/include/mos/version.h
--- linux-2.4.16/include/mos/version.h	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/include/mos/version.h	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Oren Laadan.
+ */
+
+#ifndef _MOS_VERSION_H
+#define _MOS_VERSION_H
+
+/* The following are the EXTERNAL MOSIX versions, used to enforce compatibility
+ * between different MOSIX nodes when migrating and exchanging information -
+ * as opposed to the later INTERNAL kernel version, being used for reference
+ */
+#define MOSIX_MIGRATION_VERSION	0x000036L
+#define MOSIX_BALANCE_VERSION	0x000030L
+
+#define MOSIX_KERNEL_VERSION	 10502	/* version 1.5.2 */
+
+#define MOSIX_VERSION_PARTS(x) (x)/10000, ((x)%10000)/100, (x)%100
+	
+#endif /* _MOS_VERSION_H */
diff -ruN linux-2.4.16/include/net/sock.h linux-2.4.16-mosix/include/net/sock.h
--- linux-2.4.16/include/net/sock.h	Thu Nov 22 21:47:15 2001
+++ linux-2.4.16-mosix/include/net/sock.h	Sun Dec 23 13:56:53 2001
@@ -546,6 +546,9 @@
 	/* Hole of 3 bytes. Try to pack. */
 	int			route_caps;
 	int			proc;
+#ifdef CONFIG_MOSIX
+	struct task_struct	*owner;
+#endif /* CONFIG_MOSIX */
 	unsigned long	        lingertime;
 
 	int			hashent;
diff -ruN linux-2.4.16/init/main.c linux-2.4.16-mosix/init/main.c
--- linux-2.4.16/init/main.c	Sat Nov 10 00:15:00 2001
+++ linux-2.4.16-mosix/init/main.c	Sun Dec 23 13:56:53 2001
@@ -69,6 +69,10 @@
 #include <asm/smp.h>
 #endif
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /*
  * Versions of gcc older than that listed below may actually compile
  * and link okay, but the end product can have subtle run time bugs.
@@ -550,6 +554,9 @@
  */
 	lock_kernel();
 	printk(linux_banner);
+#ifdef CONFIG_MOSIX_UDB
+	udbinit();
+#endif /* CONFIG_MOSIX_UDB */
 	setup_arch(&command_line);
 	printk("Kernel command line: %s\n", saved_command_line);
 	parse_options(command_line);
@@ -807,6 +814,9 @@
 	 * initmem segments and start the user-mode stuff..
 	 */
 	free_initmem();
+#ifdef CONFIG_MOSIX
+	init_mosix();
+#endif /* CONFIG_MOSIX */
 	unlock_kernel();
 
 	if (open("/dev/console", O_RDWR, 0) < 0)
diff -ruN linux-2.4.16/ipc/shm.c linux-2.4.16-mosix/ipc/shm.c
--- linux-2.4.16/ipc/shm.c	Wed Oct 17 23:16:39 2001
+++ linux-2.4.16-mosix/ipc/shm.c	Sun Dec 23 13:56:53 2001
@@ -621,9 +621,13 @@
 	shp->shm_nattch++;
 	shm_unlock(shmid);
 
+#ifdef CONFIG_MOSIX
+	user_addr = (void *) do_mmap_down (file, addr, file->f_dentry->d_inode->i_size, prot, flags, 0);
+#else
 	down_write(&current->mm->mmap_sem);
 	user_addr = (void *) do_mmap (file, addr, file->f_dentry->d_inode->i_size, prot, flags, 0);
 	up_write(&current->mm->mmap_sem);
+#endif /* CONFIG_MOSIX */
 
 	down (&shm_ids.sem);
 	if(!(shp = shm_lock(shmid)))
@@ -652,6 +656,10 @@
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *shmd, *shmdnext;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		return(0);
+#endif /* CONFIG_MOSIX */
 	down_write(&mm->mmap_sem);
 	for (shmd = mm->mmap; shmd; shmd = shmdnext) {
 		shmdnext = shmd->vm_next;
diff -ruN linux-2.4.16/kernel/acct.c linux-2.4.16-mosix/kernel/acct.c
--- linux-2.4.16/kernel/acct.c	Mon Mar 19 22:35:08 2001
+++ linux-2.4.16-mosix/kernel/acct.c	Sun Dec 23 13:56:53 2001
@@ -57,6 +57,9 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
 /*
  * These constants control the amount of freespace that suspend and
  * resume the process accounting system, and the time delay between
@@ -203,6 +206,10 @@
 	}
 	unlock_kernel();
 	if (old_acct) {
+#ifdef CONFIG_MOSIX
+		if(current->mosix.dflags & DDEPUTY)
+			mosix_deputy_rusage(2);
+#endif /* CONFIG_MOSIX */
 		do_acct_process(0,old_acct);
 		filp_close(old_acct, NULL);
 	}
@@ -278,6 +285,10 @@
 	mm_segment_t fs;
 	unsigned long vsize;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DREMOTE)
+		return;
+#endif /* CONFIG_MOSIX */
 	/*
 	 * First check to see if there is enough free_space to continue
 	 * the process accounting system.
@@ -323,6 +334,10 @@
 		}
 		up_read(&current->mm->mmap_sem);
 	}
+#ifdef CONFIG_MOSIX
+	else	/* were we a DEPUTY?  otherwise, "mosix.exit_mem" is 0 anyway */
+		vsize = current->mosix.exit_mem;
+#endif /* CONFIG_MOSIX */
 	vsize = vsize / 1024;
 	ac.ac_mem = encode_comp_t(vsize);
 	ac.ac_io = encode_comp_t(0 /* current->io_usage */);	/* %% */
diff -ruN linux-2.4.16/kernel/capability.c linux-2.4.16-mosix/kernel/capability.c
--- linux-2.4.16/kernel/capability.c	Sat Jun 24 07:06:37 2000
+++ linux-2.4.16-mosix/kernel/capability.c	Sun Dec 23 13:56:53 2001
@@ -7,6 +7,9 @@
 
 #include <linux/mm.h>
 #include <asm/uaccess.h>
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
 
 kernel_cap_t cap_bset = CAP_INIT_EFF_SET;
 
@@ -85,7 +88,11 @@
 
      /* FIXME: do we need to have a write lock here..? */
      read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+     for_each_local_task(target) {
+#else
      for_each_task(target) {
+#endif /* CONFIG_MOSIX */
              if (target->pgrp != pgrp)
                      continue;
              target->cap_effective   = *effective;
@@ -106,7 +113,11 @@
      /* FIXME: do we need to have a write lock here..? */
      read_lock(&tasklist_lock);
      /* ALL means everyone other than self or 'init' */
+#ifdef CONFIG_MOSIX
+     for_each_local_task(target) {
+#else
      for_each_task(target) {
+#endif /* CONFIG_MOSIX */
              if (target == current || target->pid == 1)
                      continue;
              target->cap_effective   = *effective;
@@ -212,5 +223,8 @@
      }
 spin_out:
      spin_unlock(&task_capability_lock);
+#ifdef CONFIG_MOSIX
+     mosix_sync_caps(effective);
+#endif /* CONFIG_MOSIX */
      return error;
 }
diff -ruN linux-2.4.16/kernel/exec_domain.c linux-2.4.16-mosix/kernel/exec_domain.c
--- linux-2.4.16/kernel/exec_domain.c	Sun Nov 11 20:20:21 2001
+++ linux-2.4.16-mosix/kernel/exec_domain.c	Sun Dec 23 13:56:53 2001
@@ -16,6 +16,10 @@
 #include <linux/sched.h>
 #include <linux/sysctl.h>
 #include <linux/types.h>
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#include <asm/namei.h>
+#endif /* CONFIG_MOSIX */
 
 
 static void default_handler(int, struct pt_regs *);
@@ -73,7 +77,11 @@
 		send_sig(SIGSEGV, current, 1);
 }
 
+#ifdef CONFIG_MOSIX
+struct exec_domain *
+#else
 static struct exec_domain *
+#endif /* CONFIG_MOSIX */
 lookup_exec_domain(u_long personality)
 {
 	struct exec_domain *	ep;
@@ -169,7 +177,11 @@
 		return 0;
 	}
 
+#ifdef CONFIG_MOSIX_DFSA
+	if (atomic_read(&current->fs->users) != 1) {
+#else
 	if (atomic_read(&current->fs->count) != 1) {
+#endif /* CONFIG_MOSIX_DFSA */
 		struct fs_struct *fsp, *ofsp;
 
 		fsp = copy_fs_struct(current->fs);
@@ -183,7 +195,11 @@
 		current->fs = fsp;
 		task_unlock(current);
 
+#ifdef CONFIG_MOSIX_DFSA
+		put_used_fs_struct(ofsp);
+#else
 		put_fs_struct(ofsp);
+#endif /* CONFIG_MOSIX_DFSA */
 	}
 
 	/*
@@ -191,6 +207,37 @@
 	 * current->fs.
 	 */
 
+#ifdef CONFIG_MOSIX
+	if((current->mosix.dflags & DDEPUTY) &&
+		personality != current->personality &&
+		mosix_deputy_personality(personality))
+	{
+		if(!current->mosix.inexec)
+			mosix_go_home(1);
+		if(current->mosix.dflags & DDEPUTY)
+		{
+			put_exec_domain(ep);
+			printk("%d(%s)-killed because it could not go back home"
+				"and\nits new personality (%ld) is not"
+				" supported where it ran (%d)\n", current->pid,
+				current->comm, personality,
+				current->mosix.whereami);
+			send_sig(SIGKILL, current, 1);
+			return(-EINVAL);
+		}
+	}
+	else if(current->mosix.dflags & DREMOTE)
+	{
+		unsigned long prev = current->personality;
+
+		current->personality = personality;
+		if(__emul_prefix())
+		{
+			current->personality = prev;
+			return(-EINVAL);
+		}
+	}
+#endif /* CONFIG_MOSIX */
 	current->personality = personality;
 	oep = current->exec_domain;
 	current->exec_domain = ep;
diff -ruN linux-2.4.16/kernel/exit.c linux-2.4.16-mosix/kernel/exit.c
--- linux-2.4.16/kernel/exit.c	Thu Nov 22 00:42:27 2001
+++ linux-2.4.16-mosix/kernel/exit.c	Sun Dec 23 13:56:53 2001
@@ -15,6 +15,9 @@
 #ifdef CONFIG_BSD_PROCESS_ACCT
 #include <linux/acct.h>
 #endif
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -84,7 +87,11 @@
 
 	fallback = -1;
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
  		if (p->session <= 0)
  			continue;
 		if (p->pgrp == pgrp) {
@@ -111,9 +118,17 @@
 	struct task_struct *p;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if ((p == ignored_task) || (p->pgrp != pgrp) ||
+#ifdef CONFIG_MOSIX
+		    (LOGICAL_STATE(p) == TASK_ZOMBIE) ||
+#else
 		    (p->state == TASK_ZOMBIE) ||
+#endif /* CONFIG_MOSIX */
 		    (p->p_pptr->pid == 1))
 			continue;
 		if ((p->p_pptr->pgrp != pgrp) &&
@@ -137,10 +152,18 @@
 	struct task_struct * p;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if (p->pgrp != pgrp)
 			continue;
+#ifdef CONFIG_MOSIX
+		if (LOGICAL_STATE(p) != TASK_STOPPED)
+#else
 		if (p->state != TASK_STOPPED)
+#endif /* CONFIG_MOSIX */
 			continue;
 		retval = 1;
 		break;
@@ -171,7 +194,11 @@
 	read_unlock(&tasklist_lock);
 }
 
+#ifdef CONFIG_MOSIX_DFSA
+void close_files(struct files_struct * files)
+#else
 static inline void close_files(struct files_struct * files)
+#endif /* CONFIG_MOSIX_DFSA */
 {
 	int i, j;
 
@@ -206,6 +233,11 @@
 		if (files->max_fdset > __FD_SETSIZE) {
 			free_fdset(files->open_fds, files->max_fdset);
 			free_fdset(files->close_on_exec, files->max_fdset);
+#ifdef CONFIG_MOSIX_DFSA
+			free_fdset(files->closed, files->max_fdset);
+			free_fdset(files->opened, files->max_fdset);
+			free_fdset(files->modified, files->max_fdset);
+#endif /* CONFIG_MOSIX_DFSA */
 		}
 		kmem_cache_free(files_cachep, files);
 	}
@@ -219,6 +251,11 @@
 		task_lock(tsk);
 		tsk->files = NULL;
 		task_unlock(tsk);
+#ifdef CONFIG_MOSIX_DFSA
+		atomic_dec(&files->users);
+		if(atomic_read(&files->users) == 1)
+			files->count_dropped_to_one = 1;
+#endif /* CONFIG_MOSIX_DFSA */
 		put_files_struct(files);
 	}
 }
@@ -249,6 +286,17 @@
 	__put_fs_struct(fs);
 }
 
+#ifdef CONFIG_MOSIX_DFSA
+inline void
+put_used_fs_struct(struct fs_struct *fs)
+{
+	atomic_dec(&fs->users);
+	if(atomic_read(&fs->users) == 1)
+		fs->count_dropped_to_one = 1;
+	__put_fs_struct(fs);
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
 static inline void __exit_fs(struct task_struct *tsk)
 {
 	struct fs_struct * fs = tsk->fs;
@@ -257,7 +305,11 @@
 		task_lock(tsk);
 		tsk->fs = NULL;
 		task_unlock(tsk);
+#ifdef CONFIG_MOSIX_DFSA
+		put_used_fs_struct(fs);
+#else
 		__put_fs_struct(fs);
+#endif /* CONFIG_MOSIX_DFSA */
 	}
 }
 
@@ -301,6 +353,9 @@
 	struct mm_struct * mm = tsk->mm;
 
 	mm_release();
+#ifdef CONFIG_MOSIX
+	mosix_exit_mm(tsk);
+#endif /* CONFIG_MOSIX */
 	if (mm) {
 		atomic_inc(&mm->mm_count);
 		if (mm != tsk->active_mm) BUG();
@@ -327,6 +382,14 @@
 	struct task_struct * p, *t;
 
 	forget_original_parent(current);
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DREMOTE)
+	{
+		current->state = TASK_ZOMBIE;
+		notify_parent(current, SIGCHLD);
+		return;
+	}
+#endif /* CONFIG_MOSIX */
 	/*
 	 * Check to see if any process groups have become orphaned
 	 * as a result of our exiting, and if they have any stopped
@@ -380,10 +443,24 @@
 	 */
 
 	write_lock_irq(&tasklist_lock);
+#ifndef CONFIG_MOSIX
 	current->state = TASK_ZOMBIE;
 	do_notify_parent(current, current->exit_signal);
+#endif /* CONFIG_MOSIX */
 	while (current->p_cptr != NULL) {
 		p = current->p_cptr;
+#ifdef CONFIG_MOSIX
+		if(p->ptrace && (p->mosix.dflags & DDEPUTY))
+		{
+			get_task_struct(p);
+			write_unlock_irq(&tasklist_lock);
+			request_process(p, NULL, PR_PTRACE_NOT_TRACED, 0);
+			p->ptrace = 0;
+			free_task_struct(p);
+			write_lock_irq(&tasklist_lock);
+			continue;
+		}
+#endif /* CONFIG_MOSIX */
 		current->p_cptr = p->p_osptr;
 		p->p_ysptr = NULL;
 		p->ptrace = 0;
@@ -393,7 +470,11 @@
 		if (p->p_osptr)
 			p->p_osptr->p_ysptr = p;
 		p->p_pptr->p_cptr = p;
+#ifdef CONFIG_MOSIX
+		if (LOGICAL_STATE(p) == TASK_ZOMBIE)
+#else
 		if (p->state == TASK_ZOMBIE)
+#endif /* CONFIG_MOSIX */
 			do_notify_parent(p, p->exit_signal);
 		/*
 		 * process group orphan check
@@ -413,6 +494,10 @@
 			write_lock_irq(&tasklist_lock);
 		}
 	}
+#ifdef CONFIG_MOSIX
+	current->state = TASK_ZOMBIE;
+	do_notify_parent(current, current->exit_signal);
+#endif /* CONFIG_MOSIX */
 	write_unlock_irq(&tasklist_lock);
 }
 
@@ -430,6 +515,9 @@
 	del_timer_sync(&tsk->real_timer);
 
 fake_volatile:
+#ifdef CONFIG_MOSIX
+	mosix_exit();
+#endif /* CONFIG_MOSIX */
 #ifdef CONFIG_BSD_PROCESS_ACCT
 	acct_process(code);
 #endif
@@ -440,6 +528,9 @@
 	__exit_files(tsk);
 	__exit_fs(tsk);
 	exit_sighand(tsk);
+#ifdef CONFIG_MOSIX
+	mosix_very_exit();
+#endif /* CONFIG_MOSIX */
 	exit_thread();
 
 	if (current->leader)
@@ -519,7 +610,11 @@
 			    && !(options & __WALL))
 				continue;
 			flag = 1;
+#ifdef CONFIG_MOSIX
+			switch (LOGICAL_STATE(p)) {
+#else
 			switch (p->state) {
+#endif /* CONFIG_MOSIX */
 			case TASK_STOPPED:
 				if (!p->exit_code)
 					continue;
diff -ruN linux-2.4.16/kernel/fork.c linux-2.4.16-mosix/kernel/fork.c
--- linux-2.4.16/kernel/fork.c	Wed Nov 21 20:18:42 2001
+++ linux-2.4.16-mosix/kernel/fork.c	Sun Dec 23 13:56:53 2001
@@ -26,6 +26,10 @@
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /* The idle threads do not count.. */
 int nr_threads;
 int nr_running;
@@ -74,8 +78,14 @@
 	 */
 	max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) / 8;
 
+#ifdef CONFIG_MOSIX
+	/* 1/6th of "max_threads" goes for guest tasks */
+	init_task.rlim[RLIMIT_NPROC].rlim_cur = max_threads/3;
+	init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/3;
+#else
 	init_task.rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
 	init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
+#endif
 }
 
 /* Protects next_safe and last_pid. */
@@ -125,6 +135,16 @@
 	return last_pid;
 }
 
+#ifdef CONFIG_MOSIX
+/* NOTE: "dup_mmap" is called beyond the point of no migration:
+ * this means we are no longer allowed to sleep interruptibly here without
+ * taking special measures to prevent migration (such as raising a new flag
+ * in "current->mosix.stay"),
+ * Fortunately, vm_ops->open(tmp) is rarely non-NULL and even then, it never
+ * sleeps interruptibly.  BUT if it ever does, then we must take such measures
+ * to prevent migration here.
+ */
+#endif /* CONFIG_MOSIX */
 static inline int dup_mmap(struct mm_struct * mm)
 {
 	struct vm_area_struct * mpnt, *tmp, **pprev;
@@ -215,6 +235,13 @@
 static struct mm_struct * mm_init(struct mm_struct * mm)
 {
 	atomic_set(&mm->mm_users, 1);
+#ifdef CONFIG_MOSIX
+	atomic_set(&mm->mm_realusers, 1);
+	atomic_set(&mm->mm_kiocount, 0);
+	mm->last_memsort = 0;
+	mm->used = mm->unused = mm->swapped = mm->private_unused = 0;
+	mm->mark = 0;
+#endif /* CONFIG_MOSIX */
 	atomic_set(&mm->mm_count, 1);
 	init_rwsem(&mm->mmap_sem);
 	mm->page_table_lock = SPIN_LOCK_UNLOCKED;
@@ -319,6 +346,9 @@
 
 	if (clone_flags & CLONE_VM) {
 		atomic_inc(&oldmm->mm_users);
+#ifdef CONFIG_MOSIX
+		atomic_inc(&oldmm->mm_realusers);
+#endif /* CONFIG_MOSIX */
 		mm = oldmm;
 		goto good_mm;
 	}
@@ -347,6 +377,9 @@
 
 	if (init_new_context(tsk,mm))
 		goto free_pt;
+#ifdef CONFIG_MOSIX
+	tsk->mosix.stay &= ~DSTAY_FOR_CLONE;
+#endif /* CONFIG_MOSIX */
 
 good_mm:
 	tsk->mm = mm;
@@ -365,13 +398,28 @@
 	/* We don't need to lock fs - think why ;-) */
 	if (fs) {
 		atomic_set(&fs->count, 1);
+#ifdef CONFIG_MOSIX_DFSA
+		atomic_set(&fs->users, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 		fs->lock = RW_LOCK_UNLOCKED;
 		fs->umask = old->umask;
 		read_lock(&old->lock);
 		fs->rootmnt = mntget(old->rootmnt);
 		fs->root = dget(old->root);
+#ifdef CONFIG_MOSIX
+		if(current->mosix.dflags & (DREMOTEDAEMON|DREMOTE))
+		{
+			fs->pwdmnt = NULL;
+			fs->pwd = NULL;
+		}
+		else
+		{
+#endif /* CONFIG_MOSIX */
 		fs->pwdmnt = mntget(old->pwdmnt);
 		fs->pwd = dget(old->pwd);
+#ifdef CONFIG_MOSIX
+		}
+#endif /* CONFIG_MOSIX */
 		if (old->altroot) {
 			fs->altrootmnt = mntget(old->altrootmnt);
 			fs->altroot = dget(old->altroot);
@@ -393,6 +441,9 @@
 {
 	if (clone_flags & CLONE_FS) {
 		atomic_inc(&current->fs->count);
+#ifdef CONFIG_MOSIX_DFSA
+		atomic_inc(&current->fs->users);
+#endif /* CONFIG_MOSIX_DFSA */
 		return 0;
 	}
 	tsk->fs = __copy_fs_struct(current->fs);
@@ -429,6 +480,9 @@
 
 	if (clone_flags & CLONE_FILES) {
 		atomic_inc(&oldf->count);
+#ifdef CONFIG_MOSIX_DFSA
+		atomic_inc(&oldf->users);
+#endif /* CONFIG_MOSIX_DFSA */
 		goto out;
 	}
 
@@ -439,6 +493,9 @@
 		goto out;
 
 	atomic_set(&newf->count, 1);
+#ifdef CONFIG_MOSIX_DFSA
+	atomic_set(&newf->users, 1);
+#endif /* CONFIG_MOSIX_DFSA */
 
 	newf->file_lock	    = RW_LOCK_UNLOCKED;
 	newf->next_fd	    = 0;
@@ -447,6 +504,15 @@
 	newf->close_on_exec = &newf->close_on_exec_init;
 	newf->open_fds	    = &newf->open_fds_init;
 	newf->fd	    = &newf->fd_array[0];
+#ifdef CONFIG_MOSIX_DFSA
+	newf->closed	    = &newf->closed_fds_init;
+	newf->opened        = &newf->opened_fds_init;
+	newf->modified	    = &newf->modified_fds_init;
+	newf->maxclosed	    = 0;
+	newf->maxopened     = 0;
+	newf->maxmod	    = 0;
+	newf->count_dropped_to_one = 0;
+#endif /* CONFIG_MOSIX_DFSA */
 
 	/* We don't yet have the oldf readlock, but even if the old
            fdset gets grown now, we'll only copy up to "size" fds */
@@ -486,6 +552,11 @@
 
 	memcpy(newf->open_fds->fds_bits, oldf->open_fds->fds_bits, open_files/8);
 	memcpy(newf->close_on_exec->fds_bits, oldf->close_on_exec->fds_bits, open_files/8);
+#ifdef CONFIG_MOSIX_DFSA
+	memcpy(newf->closed->fds_bits, oldf->closed->fds_bits, open_files/8);
+	memcpy(newf->opened->fds_bits, oldf->opened->fds_bits, open_files/8);
+	memcpy(newf->modified->fds_bits, oldf->modified->fds_bits, open_files/8);
+#endif /* CONFIG_MOSIX_DFSA */
 
 	for (i = open_files; i != 0; i--) {
 		struct file *f = *old_fds++;
@@ -507,6 +578,11 @@
 		
 		memset(&newf->open_fds->fds_bits[start], 0, left);
 		memset(&newf->close_on_exec->fds_bits[start], 0, left);
+#ifdef CONFIG_MOSIX_DFSA
+		memset(&newf->closed->fds_bits[start], 0, left);
+		memset(&newf->opened->fds_bits[start], 0, left);
+		memset(&newf->modified->fds_bits[start], 0, left);
+#endif /* CONFIG_MOSIX_DFSA */
 	}
 
 	tsk->files = newf;
@@ -517,6 +593,11 @@
 out_release:
 	free_fdset (newf->close_on_exec, newf->max_fdset);
 	free_fdset (newf->open_fds, newf->max_fdset);
+#ifdef CONFIG_MOSIX_DFSA
+	free_fdset (newf->closed, newf->max_fdset);
+	free_fdset (newf->opened, newf->max_fdset);
+	free_fdset (newf->modified, newf->max_fdset);
+#endif /* CONFIG_MOSIX_DFSA */
 	kmem_cache_free(files_cachep, newf);
 	goto out;
 }
@@ -565,6 +646,9 @@
 	int retval;
 	struct task_struct *p;
 	struct completion vfork;
+#ifdef CONFIG_MOSIX
+	int migrated = 0;
+#endif /* CONFIG_MOSIX */
 
 	retval = -EPERM;
 
@@ -576,6 +660,11 @@
 		if (current->pid)
 			goto fork_out;
 	}
+#ifdef CONFIG_MOSIX
+	if(!(current->mosix.stay ||
+		(current->mosix.dflags & (DDEPUTY|DREMOTE|DREMOTEDAEMON))))
+		migrated = mosix_forkmigrate();
+#endif /* CONFIG_MOSIX */
 
 	retval = -ENOMEM;
 	p = alloc_task_struct();
@@ -652,6 +741,10 @@
 	INIT_LIST_HEAD(&p->local_pages);
 
 	retval = -ENOMEM;
+#ifdef CONFIG_MOSIX
+	if(mosix_fork_init_fields(p))
+		goto bad_fork_cleanup;
+#endif /* CONFIG_MOSIX */
 	/* copy all the process information */
 	if (copy_files(clone_flags, p))
 		goto bad_fork_cleanup;
@@ -659,6 +752,12 @@
 		goto bad_fork_cleanup_files;
 	if (copy_sighand(clone_flags, p))
 		goto bad_fork_cleanup_fs;
+#ifdef CONFIG_MOSIX
+	if((current->mosix.dflags & DDEPUTY) &&
+		(retval = mosix_deputy_fork(p, migrated, stack_start)))
+		goto bad_fork_cleanup_sighand;
+	/* No migrations allowed beyond this point! */
+#endif /* CONFIG_MOSIX */
 	if (copy_mm(clone_flags, p))
 		goto bad_fork_cleanup_sighand;
 	retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
@@ -703,6 +802,14 @@
 	/* CLONE_PARENT and CLONE_THREAD re-use the old parent */
 	p->p_opptr = current->p_opptr;
 	p->p_pptr = current->p_pptr;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & (DREMOTE|DREMOTEDAEMON))
+	{
+		extern struct task_struct *child_reaper;
+		p->p_pptr = p->p_opptr = child_reaper;
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	if (!(clone_flags & (CLONE_PARENT | CLONE_THREAD))) {
 		p->p_opptr = current;
 		if (!(p->ptrace & PT_PTRACED))
@@ -720,12 +827,19 @@
 	write_unlock_irq(&tasklist_lock);
 
 	if (p->ptrace & PT_PTRACED)
+#ifdef CONFIG_MOSIX
+	if(!(p->mosix.dflags & DREMOTE))
+#endif /* CONFIG_MOSIX */
 		send_sig(SIGSTOP, p, 1);
 
 	wake_up_process(p);		/* do this last */
 	++total_forks;
 	if (clone_flags & CLONE_VFORK)
+#ifdef CONFIG_MOSIX
+		wait_for_completion_half_interruptible(&vfork);
+#else
 		wait_for_completion(&vfork);
+#endif /* CONFIG_MOSIX */
 
 fork_out:
 	return retval;
@@ -739,6 +853,9 @@
 bad_fork_cleanup_files:
 	exit_files(p); /* blocking */
 bad_fork_cleanup:
+#ifdef CONFIG_MOSIX
+	mosix_fork_free_fields(p);
+#endif /* CONFIG_MOSIX */
 	put_exec_domain(p->exec_domain);
 	if (p->binfmt && p->binfmt->module)
 		__MOD_DEC_USE_COUNT(p->binfmt->module);
diff -ruN linux-2.4.16/kernel/module.c linux-2.4.16-mosix/kernel/module.c
--- linux-2.4.16/kernel/module.c	Sun Nov 11 21:23:14 2001
+++ linux-2.4.16-mosix/kernel/module.c	Sun Dec 23 13:56:53 2001
@@ -1066,6 +1066,15 @@
 	}
 	spin_unlock_irqrestore(&modlist_lock, flags);
 
+#ifdef CONFIG_MOSIX_UDB
+	/* And from the udb symbols list */
+	{
+		extern void udb_proc_rmmod(char *name, struct module *);
+		
+		udb_proc_rmmod((char *)mod->name, mod);
+	}
+#endif /* CONFIG_MOSIX_UDB */
+
 	/* And free the memory.  */
 
 	module_unmap(mod);
diff -ruN linux-2.4.16/kernel/panic.c linux-2.4.16-mosix/kernel/panic.c
--- linux-2.4.16/kernel/panic.c	Sun Sep 30 21:26:08 2001
+++ linux-2.4.16-mosix/kernel/panic.c	Sun Dec 23 13:56:53 2001
@@ -97,6 +97,12 @@
 	sti();
 	for(;;) {
 		CHECK_EMERGENCY_SYNC
+#ifdef CONFIG_MOSIX_UDB
+	{
+		extern void mosix_debugger(char *);
+		mosix_debugger("panic");
+	}
+#endif /* CONFIG_MOSIX_UDB */
 	}
 }
 
diff -ruN linux-2.4.16/kernel/ptrace.c linux-2.4.16-mosix/kernel/ptrace.c
--- linux-2.4.16/kernel/ptrace.c	Thu Nov 22 00:43:01 2001
+++ linux-2.4.16-mosix/kernel/ptrace.c	Sun Dec 23 13:56:53 2001
@@ -52,6 +52,10 @@
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+#include <mos/request.h>
+#endif /* CONFIG_MOSIX */
+
 int ptrace_attach(struct task_struct *task)
 {
 	task_lock(task);
@@ -59,6 +63,9 @@
 		goto bad;
 	if (task == current)
 		goto bad;
+#ifdef CONFIG_MOSIX
+	if(!(task->mosix.dflags & DDEPUTY))
+#endif /* CONFIG_MOSIX */
 	if (!task->mm)
 		goto bad;
 	if(((current->uid != task->euid) ||
@@ -70,7 +77,12 @@
  	    (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
 		goto bad;
 	rmb();
+#ifdef CONFIG_MOSIX
+	if (!(task->mm ? task->mm->dumpable : (task->mosix.dflags & DDUMPABLE))
+		&& !capable(CAP_SYS_PTRACE))
+#else
 	if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE))
+#endif /* CONFIG_MOSIX */
 		goto bad;
 	/* the same process cannot be attached many times */
 	if (task->ptrace & PT_PTRACED)
@@ -81,6 +93,9 @@
 	if (capable(CAP_SYS_PTRACE))
 		task->ptrace |= PT_PTRACE_CAP;
 	task_unlock(task);
+#ifdef CONFIG_MOSIX_DFSA
+	tell_process(task, DREQ_NOTUPTODATE);
+#endif /* CONFIG_MOSIX_DFSA */
 
 	write_lock_irq(&tasklist_lock);
 	if (task->p_pptr != current) {
@@ -104,6 +119,14 @@
 		return	-EIO;
 
 	/* Architecture-specific hardware disable .. */
+#ifdef CONFIG_MOSIX
+	if(child->mosix.dflags & DDEPUTY)
+	{
+		if(request_process(child, NULL, PR_PTRACE_CONT, PTRACE_DETACH))
+			return(-ESRCH);
+	}
+	else
+#endif /* CONFIG_MOSIX */
 	ptrace_disable(child);
 
 	/* .. re-parent .. */
@@ -235,6 +258,12 @@
 	struct mm_struct *mm;
 	struct vm_area_struct * vma;
 
+#ifdef CONFIG_MOSIX
+	if(tsk != current || (tsk->mosix.dflags & DDEPUTY))
+		return(request_process_arg2(tsk, buf,
+			write ? PR_PROCFS_MEM_WRITE : PR_PROCFS_MEM_READ,
+			(long)addr, len));
+#endif /* CONFIG_MOSIX */
 	/* Worry about races with exit() */
 	task_lock(tsk);
 	mm = tsk->mm;
diff -ruN linux-2.4.16/kernel/sched.c linux-2.4.16-mosix/kernel/sched.c
--- linux-2.4.16/kernel/sched.c	Thu Nov 22 02:25:48 2001
+++ linux-2.4.16-mosix/kernel/sched.c	Sun Dec 23 15:48:54 2001
@@ -37,6 +37,10 @@
 extern void tqueue_bh(void);
 extern void immediate_bh(void);
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /*
  * scheduler variables
  */
@@ -75,7 +79,7 @@
  *	Init task must be ok at boot for the ix86 as we will check its signals
  *	via the SMP irq return path.
  */
- 
+
 struct task_struct * init_tasks[NR_CPUS] = {&init_task, };
 
 /*
@@ -92,7 +96,11 @@
 spinlock_t runqueue_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;  /* inner */
 rwlock_t tasklist_lock __cacheline_aligned = RW_LOCK_UNLOCKED;	/* outer */
 
+#ifdef CONFIG_MOSIX
+LIST_HEAD(runqueue_head);
+#else
 static LIST_HEAD(runqueue_head);
+#endif /* CONFIG_MOSIX */
 
 /*
  * We align per-CPU scheduling data on cacheline boundaries,
@@ -166,9 +174,19 @@
 		 * over..
 		 */
 		weight = p->counter;
+#ifdef CONFIG_MOSIX
+		/* give a generous advantage to processes in MOSIX context: */
+		/* (they do not hog the CPU anyway) */
+		if (p->mosix.dflags & DINSCHED)
+			weight += MOSIX_ASLEEP_PRIORITY;
+		if (p->mosix.dflags & DDEPUTY)
+			weight += MOSIX_DEPUTY_PRIORITY;
+		if (p->mosix.commpri)
+			weight += MOSIX_RESPOND_PRIORITY;
+#endif /* CONFIG_MOSIX */
 		if (!weight)
 			goto out;
-			
+
 #ifdef CONFIG_SMP
 		/* Give a largish advantage to the same processor...   */
 		/* (this is equivalent to penalizing other processors) */
@@ -288,7 +306,7 @@
 			smp_send_reschedule(tsk->processor);
 	}
 	return;
-		
+
 
 #else /* UP */
 	int this_cpu = smp_processor_id();
@@ -311,6 +329,9 @@
 {
 	list_add(&p->run_list, &runqueue_head);
 	nr_running++;
+#ifdef CONFIG_MOSIX
+	run_on(p);
+#endif /* CONFIG_MOSIX */
 }
 
 static inline void move_last_runqueue(struct task_struct * p)
@@ -337,12 +358,35 @@
 {
 	unsigned long flags;
 	int success = 0;
+#ifdef CONFIG_MOSIX
+	struct task_struct *origp = p;
+#endif /* CONFIG_MOSIX */
 
 	/*
 	 * We want the common case fall through straight, thus the goto.
 	 */
 	spin_lock_irqsave(&runqueue_lock, flags);
+#ifdef CONFIG_MOSIX
+	p = NORMAL_CONTEXT(p);
+	write_lock(&p->mosix.state_lock);
+	if(origp != p)
+	{
+		if(p->mosix.bstate != TASK_SAME)
+			p->state = TASK_RUNNING;
+	}
+	else if(p->mosix.bstate == TASK_SAME)
+		p->state = TASK_RUNNING;
+	else
+	{
+		p->mosix.bstate = TASK_RUNNING;
+		success = 1;
+		write_unlock(&p->mosix.state_lock);
+		goto out;
+	}
+	write_unlock(&p->mosix.state_lock);
+#else
 	p->state = TASK_RUNNING;
+#endif /* CONFIG_MOSIX */
 	if (task_on_runqueue(p))
 		goto out;
 	add_to_runqueue(p);
@@ -359,6 +403,30 @@
 	return try_to_wake_up(p, 0);
 }
 
+#ifdef CONFIG_MOSIX
+/* wake up a process only if it is interested in MOSIX events */
+void
+wake_up_mosix(struct task_struct *p)
+{
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&runqueue_lock, flags);
+	if(mosix_wakeable(p))
+	{
+		write_lock(&p->mosix.state_lock);	/* not irq! */
+		if(p->mosix.bstate != TASK_SAME)
+			p->state = TASK_RUNNING;
+		write_unlock(&p->mosix.state_lock);
+		if (!task_on_runqueue(p))
+		{
+			add_to_runqueue(p);
+			reschedule_idle(p);
+		}
+	}
+	spin_unlock_irqrestore(&runqueue_lock, flags);
+}
+#endif /* CONFIG_MOSIX */
+
 static void process_timeout(unsigned long __data)
 {
 	struct task_struct * p = (struct task_struct *) __data;
@@ -383,7 +451,7 @@
  * delivered to the current task. In this case the remaining time
  * in jiffies will be returned, or 0 if the timer expired in time
  *
- * The current task state is guaranteed to be TASK_RUNNING when this 
+ * The current task state is guaranteed to be TASK_RUNNING when this
  * routine returns.
  *
  * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule
@@ -431,6 +499,11 @@
 
 	init_timer(&timer);
 	timer.expires = expire;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DINSCHED)
+		timer.data = (unsigned long)MOSIX_CONTEXT(current);
+	else
+#endif /* CONFIG_MOSIX */
 	timer.data = (unsigned long) current;
 	timer.function = process_timeout;
 
@@ -537,6 +610,13 @@
 	struct task_struct *prev, *next, *p;
 	struct list_head *tmp;
 	int this_cpu, c;
+#ifdef CONFIG_MOSIX
+	auto volatile int handle_interim =
+		(current->state & (TASK_INTERRUPTIBLE|TASK_STOPPED)) &&
+		!(current->mosix.dflags & DINSCHED);
+
+	restart:
+#endif /* CONFIG_MOSIX */
 
 
 	spin_lock_prefetch(&runqueue_lock);
@@ -546,6 +626,9 @@
 	prev = current;
 	this_cpu = prev->processor;
 
+#ifdef CONFIG_MOSIX_UDB
+	if(!udb_booting)
+#endif /* CONFIG_MOSIX_UDB */
 	if (unlikely(in_interrupt())) {
 		printk("Scheduling in interrupt\n");
 		BUG();
@@ -568,8 +651,42 @@
 			move_last_runqueue(prev);
 		}
 
+#ifdef CONFIG_MOSIX
+	if(handle_interim && need_interim_while_asleep())
+	{
+		int prev_kernel_lock_depth, prev_mosix_lock_depth;
+
+		do_interim_first:
+		write_lock(&prev->mosix.state_lock);	/* not irq! */
+		prev->mosix.bstate = prev->state;
+		prev->state = TASK_RUNNING;
+		write_unlock(&prev->mosix.state_lock);
+		prev->mosix.dflags |= DINSCHED;
+		spin_unlock_irq(&runqueue_lock);
+		prev_kernel_lock_depth = prev->lock_depth;
+		prev_mosix_lock_depth = prev->mosix.lock_depth;
+		prev->lock_depth = -1;
+		prev->mosix.lock_depth = -1;
+		run_interim_while_asleep();
+		prev->lock_depth = prev_kernel_lock_depth;
+		prev->mosix.lock_depth = prev_mosix_lock_depth;
+		if(prev_kernel_lock_depth != -1 || prev_mosix_lock_depth != -1)
+			reacquire_kernel_lock(prev);
+		spin_lock_irq(&runqueue_lock);
+		write_lock(&prev->mosix.state_lock);
+		prev->state = prev->mosix.bstate;
+		prev->mosix.bstate = TASK_SAME;
+		write_unlock(&prev->mosix.state_lock);
+		prev->mosix.dflags &= ~DINSCHED;
+		spin_unlock_irq(&runqueue_lock);
+		goto restart;
+	}
+#endif /* CONFIG_MOSIX */
 	switch (prev->state) {
 		case TASK_INTERRUPTIBLE:
+#ifdef CONFIG_MOSIX
+			if (!(prev->mosix.dflags & (DREMOTE|DINSCHED)))
+#endif /* CONFIG_MOSIX */
 			if (signal_pending(prev)) {
 				prev->state = TASK_RUNNING;
 				break;
@@ -619,6 +736,14 @@
 	 */
 	sched_data->curr = next;
 	task_set_cpu(next, this_cpu);
+#ifdef CONFIG_MOSIX
+	if(prev != next)
+		active_cpus += (next->pid != 0) - (prev->pid != 0);
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DIAG
+	if(active_cpus < 0 || active_cpus > smp_num_cpus)
+		mosix_panic("active_cpus got out of range");
+#endif /* CONFIG_MOSIX_DIAG */
 	spin_unlock_irq(&runqueue_lock);
 
 	if (unlikely(prev == next)) {
@@ -681,8 +806,32 @@
 	 */
 	switch_to(prev, next, prev);
 	__schedule_tail(prev);
+#ifdef CONFIG_MOSIX
+	prev = current;	/* we still use it */
+#endif /* CONFIG_MOSIX */
 
 same_process:
+
+#ifdef CONFIG_MOSIX
+	if(handle_interim)
+	{
+		spin_lock_irq(&runqueue_lock);
+		if(need_interim_while_asleep())
+			goto do_interim_first;
+		spin_unlock_irq(&runqueue_lock);
+	}
+	if(prev->state != TASK_RUNNING)
+	{
+		reacquire_kernel_lock(prev);
+		mosix_panic("Sched-Race: MOSIX awakened too late.\n");
+		goto restart;
+	}
+#endif /* CONFIG_MOSIX */
+
+#ifdef CONFIG_MOSIX_UDB
+	if(prev->mosix.catchme)
+		mosix_debugger("catch");
+#endif /* CONFIG_MOSIX_UDB */
 	reacquire_kernel_lock(current);
 	if (current->need_resched)
 		goto need_resched_back;
@@ -703,17 +852,38 @@
 {
 	struct list_head *tmp;
 	struct task_struct *p;
+#ifdef CONFIG_MOSIX
+	struct task_struct *realp;
+#endif /* CONFIG_MOSIX */
 
 	CHECK_MAGIC_WQHEAD(q);
 	WQ_CHECK_LIST_HEAD(&q->task_list);
-	
+
 	list_for_each(tmp,&q->task_list) {
 		unsigned int state;
                 wait_queue_t *curr = list_entry(tmp, wait_queue_t, task_list);
 
 		CHECK_MAGIC(curr->__magic);
 		p = curr->task;
+#ifdef CONFIG_MOSIX
+		realp = NORMAL_CONTEXT(p);
+		if(realp != p)
+		{
+			read_lock(&realp->mosix.state_lock);
+			if(realp->mosix.bstate == TASK_SAME)
+			{
+				/* no longer in MOSIX */
+				read_unlock(&realp->mosix.state_lock);
+				continue;
+			}
+			state = realp->state;
+			read_unlock(&realp->mosix.state_lock);
+		}
+		else
+			state = LOGICAL_STATE(p);
+#else
 		state = p->state;
+#endif /* CONFIG_MOSIX */
 		if (state & mode) {
 			WQ_NOTE_WAKER(curr);
 			if (try_to_wake_up(p, sync) && (curr->flags&WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
@@ -772,6 +942,35 @@
 	spin_unlock_irq(&x->wait.lock);
 }
 
+#ifdef CONFIG_MOSIX
+void wait_for_completion_half_interruptible(struct completion *x)
+{
+	struct task_struct *p = current;
+
+	spin_lock_irq(&x->wait.lock);
+	if (!x->done) {
+		DECLARE_WAITQUEUE(wait, current);
+
+		wait.flags |= WQ_FLAG_EXCLUSIVE;
+		__add_wait_queue_tail(&x->wait, &wait);
+		do {
+			__set_current_state(TASK_INTERRUPTIBLE);
+			spin_unlock_irq(&x->wait.lock);
+			spin_lock_irq(&p->sigmask_lock);
+			p->mosix.ignoreoldsigs = 1;
+			p->sigpending = 0;
+			spin_unlock_irq(&p->sigmask_lock);
+			schedule();
+			spin_lock_irq(&x->wait.lock);
+		} while (!x->done);
+		__remove_wait_queue(&x->wait, &wait);
+	}
+	x->done--;
+	spin_unlock_irq(&x->wait.lock);
+	recalc_sigpending(p);
+}
+#endif /* CONFIG_MOSIX */
+
 #define	SLEEP_ON_VAR				\
 	unsigned long flags;			\
 	wait_queue_t wait;			\
@@ -814,7 +1013,7 @@
 void sleep_on(wait_queue_head_t *q)
 {
 	SLEEP_ON_VAR
-	
+
 	current->state = TASK_UNINTERRUPTIBLE;
 
 	SLEEP_ON_HEAD
@@ -825,7 +1024,7 @@
 long sleep_on_timeout(wait_queue_head_t *q, long timeout)
 {
 	SLEEP_ON_VAR
-	
+
 	current->state = TASK_UNINTERRUPTIBLE;
 
 	SLEEP_ON_HEAD
@@ -869,6 +1068,10 @@
 	if (newprio > 19)
 		newprio = 19;
 	current->nice = newprio;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		mosix_inform_remote_of_nice();
+#endif /* CONFIG_MOSIX */
 	return 0;
 }
 
@@ -883,7 +1086,7 @@
 	return tsk;
 }
 
-static int setscheduler(pid_t pid, int policy, 
+static int setscheduler(pid_t pid, int policy,
 			struct sched_param *param)
 {
 	struct sched_param lp;
@@ -909,7 +1112,7 @@
 	retval = -ESRCH;
 	if (!p)
 		goto out_unlock;
-			
+
 	if (policy < 0)
 		policy = p->policy;
 	else {
@@ -918,7 +1121,7 @@
 				policy != SCHED_OTHER)
 			goto out_unlock;
 	}
-	
+
 	/*
 	 * Valid priorities for SCHED_FIFO and SCHED_RR are 1..99, valid
 	 * priority for SCHED_OTHER is 0.
@@ -930,13 +1133,38 @@
 		goto out_unlock;
 
 	retval = -EPERM;
-	if ((policy == SCHED_FIFO || policy == SCHED_RR) && 
+	if ((policy == SCHED_FIFO || policy == SCHED_RR) &&
 	    !capable(CAP_SYS_NICE))
 		goto out_unlock;
 	if ((current->euid != p->euid) && (current->euid != p->uid) &&
 	    !capable(CAP_SYS_NICE))
 		goto out_unlock;
 
+#ifdef CONFIG_MOSIX
+	spin_unlock(&runqueue_lock);
+	if(policy != SCHED_OTHER)
+	{
+		while(p->mosix.dflags & DDEPUTY)
+		{
+			get_task_struct(p);
+			read_unlock_irq(&tasklist_lock);
+			if((retval = mosix_send_back_home(p)))
+				return(retval);
+			read_lock(&tasklist_lock);
+			free_task_struct(p);
+		}
+		task_lock(p);
+		p->mosix.stay |= DSTAY_FOR_RT;
+		task_unlock(p);
+	}
+	else
+	{
+		task_lock(p);
+		p->mosix.stay &= ~DSTAY_FOR_RT;
+		task_unlock(p);
+	}
+	spin_lock(&runqueue_lock);
+#endif /* CONFIG_MOSIX */
 	retval = 0;
 	p->policy = policy;
 	p->rt_priority = lp.sched_priority;
@@ -953,7 +1181,7 @@
 	return retval;
 }
 
-asmlinkage long sys_sched_setscheduler(pid_t pid, int policy, 
+asmlinkage long sys_sched_setscheduler(pid_t pid, int policy,
 				      struct sched_param *param)
 {
 	return setscheduler(pid, policy, param);
@@ -1018,7 +1246,7 @@
 asmlinkage long sys_sched_yield(void)
 {
 	/*
-	 * Trick. sched_yield() first counts the number of truly 
+	 * Trick. sched_yield() first counts the number of truly
 	 * 'pending' runnable processes, then returns if it's
 	 * only the current processes. (This test does not have
 	 * to be atomic.) In threaded applications this optimization
@@ -1280,6 +1508,10 @@
  	exit_files(current);
 	current->files = init_task.files;
 	atomic_inc(&current->files->count);
+#ifdef CONFIG_MOSIX_DFSA
+	atomic_inc(&current->files->users);
+	atomic_inc(&fs->users);
+#endif /* CONFIG_MOSIX_DFSA */
 }
 
 extern unsigned long wait_init_idle;
diff -ruN linux-2.4.16/kernel/signal.c linux-2.4.16-mosix/kernel/signal.c
--- linux-2.4.16/kernel/signal.c	Thu Nov 22 02:26:27 2001
+++ linux-2.4.16-mosix/kernel/signal.c	Sun Dec 23 13:56:53 2001
@@ -14,6 +14,11 @@
 #include <linux/init.h>
 #include <linux/sched.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#include <linux/interrupt.h>
+#endif /* CONFIG_MOSIX */
+
 #include <asm/uaccess.h>
 
 /*
@@ -105,6 +110,9 @@
 void
 flush_signals(struct task_struct *t)
 {
+#ifdef CONFIG_MOSIX
+	if(!(t->mosix.dflags & DFAKESIGNAL))
+#endif /* CONFIG_MOSIX */
 	t->sigpending = 0;
 	flush_sigqueue(&t->pending);
 }
@@ -119,6 +127,9 @@
 		if (atomic_dec_and_test(&sig->count))
 			kmem_cache_free(sigact_cachep, sig);
 	}
+#ifdef CONFIG_MOSIX
+	if(!(tsk->mosix.dflags & DFAKESIGNAL))
+#endif /* CONFIG_MOSIX */
 	tsk->sigpending = 0;
 	flush_sigqueue(&tsk->pending);
 	spin_unlock_irq(&tsk->sigmask_lock);
@@ -246,6 +257,9 @@
 		if (current->notifier) {
 			if (sigismember(current->notifier_mask, sig)) {
 				if (!(current->notifier)(current->notifier_data)) {
+#ifdef CONFIG_MOSIX
+					if(!(current->mosix.dflags&DFAKESIGNAL))
+#endif /* CONFIG_MOSIX */
 					current->sigpending = 0;
 					return 0;
 				}
@@ -382,7 +396,11 @@
 	switch (sig) {
 	case SIGKILL: case SIGCONT:
 		/* Wake up the process if stopped.  */
+#ifdef CONFIG_MOSIX
+		if (LOGICAL_STATE(t) == TASK_STOPPED)
+#else
 		if (t->state == TASK_STOPPED)
+#endif /* CONFIG_MOSIX */
 			wake_up_process(t);
 		t->exit_code = 0;
 		rm_sig_from_queue(SIGSTOP, t);
@@ -465,6 +483,11 @@
  */
 static inline void signal_wake_up(struct task_struct *t)
 {
+#ifdef CONFIG_MOSIX
+	t->mosix.ignoreoldsigs = 0;
+	if(t->mosix.dflags & DHEAVYSLEEP)
+		return;
+#endif /* CONFIG_MOSIX */
 	t->sigpending = 1;
 
 #ifdef CONFIG_SMP
@@ -484,7 +507,11 @@
 	spin_unlock(&runqueue_lock);
 #endif /* CONFIG_SMP */
 
+#ifdef CONFIG_MOSIX
+	if (LOGICAL_STATE(t) & TASK_INTERRUPTIBLE) {
+#else
 	if (t->state & TASK_INTERRUPTIBLE) {
+#endif /* CONFIG_MOSIX */
 		wake_up_process(t);
 		return;
 	}
@@ -562,6 +589,42 @@
 {
 	unsigned long int flags;
 
+#ifdef CONFIG_MOSIX
+	if(t->mosix.dflags & DREMOTE)
+	{
+		int n;
+		siginfo_t *x;
+
+		if(!info || ((long)info) == 1)
+			panic("remote force_sig_info");
+		info->si_signo = sig;
+		/* (should be anyway, but some callers are mindless about it) */
+		if(in_interrupt())
+			panic("remote force_sig_info in interrupt");
+		repeat:
+		n = t->mosix.nforced_sigs;
+		if(!(x = kmalloc((n + 1) * sizeof(siginfo_t), GFP_KERNEL)))
+		{
+			/* just do our best */
+			send_sig(sig, t, 0);
+			return(0);
+		}
+		spin_lock_irqsave(&t->sigmask_lock, flags);
+		if(t->mosix.nforced_sigs != n)
+		{
+			spin_unlock_irqrestore(&t->sigmask_lock, flags);
+			kfree(x);
+			goto repeat;
+		}
+		if(n)
+			memcpy(x, t->mosix.forced_sigs, sizeof(siginfo_t) * n);
+		x[n] = *info;
+		t->mosix.forced_sigs = x;
+		t->mosix.nforced_sigs++;
+		spin_unlock_irqrestore(&t->sigmask_lock, flags);
+		return(0);
+	}
+#endif /* CONFIG_MOSIX */
 	spin_lock_irqsave(&t->sigmask_lock, flags);
 	if (t->sig == NULL) {
 		spin_unlock_irqrestore(&t->sigmask_lock, flags);
@@ -591,7 +654,11 @@
 
 		retval = -ESRCH;
 		read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+		for_each_local_task(p) {
+#else
 		for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 			if (p->pgrp == pgrp) {
 				int err = send_sig_info(sig, info, p);
 				if (retval)
@@ -618,7 +685,11 @@
 
 		retval = -ESRCH;
 		read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+		for_each_local_task(p) {
+#else
 		for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 			if (p->leader && p->session == sess) {
 				int err = send_sig_info(sig, info, p);
 				if (retval)
@@ -662,7 +733,11 @@
 		struct task_struct * p;
 
 		read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+		for_each_local_task(p) {
+#else
 		for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 			if (p->pid > 1 && p != current) {
 				int err = send_sig_info(sig, info, p);
 				++count;
@@ -686,12 +761,34 @@
 int
 send_sig(int sig, struct task_struct *p, int priv)
 {
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DREMOTE)
+	{
+		unsigned long flags;
+
+		spin_lock_irqsave(&p->sigmask_lock, flags);
+		p->mosix.asig |= (1 << (sig-1));
+		spin_unlock_irqrestore(&p->sigmask_lock, flags);
+		if(p == current)
+			current->need_resched = 1;
+		return(0);
+	}
+#endif /* CONFIG_MOSIX */
 	return send_sig_info(sig, (void*)(long)(priv != 0), p);
 }
 
 void
 force_sig(int sig, struct task_struct *p)
 {
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DREMOTE)
+	{
+		if(sig == SIGSEGV)
+			sig = FATAL_SIGSEGV;
+		send_sig(sig, p, 0);
+		return;
+	}
+#endif /* CONFIG_MOSIX */
 	force_sig_info(sig, (void*)1L, p);
 }
 
@@ -747,7 +844,11 @@
 
 	status = tsk->exit_code & 0x7f;
 	why = SI_KERNEL;	/* shouldn't happen */
+#ifdef CONFIG_MOSIX
+	switch (LOGICAL_STATE(tsk)) {
+#else
 	switch (tsk->state) {
+#endif /* CONFIG_MOSIX */
 	case TASK_STOPPED:
 		/* FIXME -- can we deduce CLD_TRAPPED or CLD_CONTINUED? */
 		if (tsk->ptrace & PT_PTRACED)
diff -ruN linux-2.4.16/kernel/sys.c linux-2.4.16-mosix/kernel/sys.c
--- linux-2.4.16/kernel/sys.c	Wed Sep 19 00:10:43 2001
+++ linux-2.4.16-mosix/kernel/sys.c	Sun Dec 23 13:56:53 2001
@@ -18,6 +18,13 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * this is where the system-wide overflow UID and GID are defined, for
  * architectures that now have 32-bit UID/GID but didn't in the past
@@ -174,6 +181,10 @@
 
 static int proc_sel(struct task_struct *p, int which, int who)
 {
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DREMOTE)
+		return(0);
+#endif /* CONFIG_MOSIX */
 	if(p->pid)
 	{
 		switch (which) {
@@ -210,7 +221,11 @@
 		niceval = 19;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if (!proc_sel(p, which, who))
 			continue;
 		if (p->uid != current->euid &&
@@ -223,7 +238,18 @@
 		if (niceval < p->nice && !capable(CAP_SYS_NICE))
 			error = -EACCES;
 		else
+#ifdef CONFIG_MOSIX
+		{
+#endif /* CONFIG_MOSIX */
 			p->nice = niceval;
+#ifdef CONFIG_MOSIX
+			if(p->mosix.dflags & DDEPUTY)
+			{
+				tell_process(p, DREQ_NICECNG);
+				wake_up_mosix(p);
+			}
+		}
+#endif /* CONFIG_MOSIX */
 	}
 	read_unlock(&tasklist_lock);
 
@@ -400,7 +426,11 @@
 	}
 	if (new_egid != old_egid)
 	{
+#ifdef CONFIG_MOSIX
+		set_me_dumpable(0);
+#else
 		current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 		wmb();
 	}
 	if (rgid != (gid_t) -1 ||
@@ -409,6 +439,12 @@
 	current->fsgid = new_egid;
 	current->egid = new_egid;
 	current->gid = new_rgid;
+#ifdef CONFIG_MOSIX
+	tell_process(current, DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	return 0;
 }
 
@@ -421,11 +457,21 @@
 {
 	int old_egid = current->egid;
 
+#ifdef CONFIG_MOSIX
+	tell_process(current, DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	if (capable(CAP_SETGID))
 	{
 		if(old_egid != gid)
 		{
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(0);
+#else
 			current->mm->dumpable=0;
+#endif /* CONFIG_MOSIX */
 			wmb();
 		}
 		current->gid = current->egid = current->sgid = current->fsgid = gid;
@@ -434,7 +480,11 @@
 	{
 		if(old_egid != gid)
 		{
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(0);
+#else
 			current->mm->dumpable=0;
+#endif /* CONFIG_MOSIX */
 			wmb();
 		}
 		current->egid = current->fsgid = gid;
@@ -508,12 +558,19 @@
 
 	if(dumpclear)
 	{
+#ifdef CONFIG_MOSIX
+		set_me_dumpable(0);
+#else
 		current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 		wmb();
 	}
 	current->uid = new_ruid;
 	current->user = new_user;
 	free_uid(old_user);
+#ifdef CONFIG_MOSIX
+	tell_process(current, DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
 	return 0;
 }
 
@@ -548,6 +605,9 @@
 			return -EPERM;
 	}
 
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	if (euid != (uid_t) -1) {
 		new_euid = euid;
 		if ((old_ruid != euid) &&
@@ -562,7 +622,11 @@
 
 	if (new_euid != old_euid)
 	{
+#ifdef CONFIG_MOSIX
+		set_me_dumpable(0);
+#else
 		current->mm->dumpable=0;
+#endif /* CONFIG_MOSIX */
 		wmb();
 	}
 	current->fsuid = current->euid = new_euid;
@@ -596,6 +660,9 @@
 	int old_euid = current->euid;
 	int old_ruid, old_suid, new_ruid, new_suid;
 
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	old_ruid = new_ruid = current->uid;
 	old_suid = current->suid;
 	new_suid = old_suid;
@@ -609,7 +676,11 @@
 
 	if (old_euid != uid)
 	{
+#ifdef CONFIG_MOSIX
+		set_me_dumpable(0);
+#else
 		current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 		wmb();
 	}
 	current->fsuid = current->euid = uid;
@@ -644,6 +715,9 @@
 		    (suid != current->euid) && (suid != current->suid))
 			return -EPERM;
 	}
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	if (ruid != (uid_t) -1) {
 		if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
 			return -EAGAIN;
@@ -651,7 +725,11 @@
 	if (euid != (uid_t) -1) {
 		if (euid != current->euid)
 		{
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(0);
+#else
 			current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 			wmb();
 		}
 		current->euid = euid;
@@ -694,10 +772,17 @@
 		    (sgid != current->egid) && (sgid != current->sgid))
 			return -EPERM;
 	}
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	if (egid != (gid_t) -1) {
 		if (egid != current->egid)
 		{
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(0);
+#else
 			current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 			wmb();
 		}
 		current->egid = egid;
@@ -707,6 +792,9 @@
 		current->gid = rgid;
 	if (sgid != (gid_t) -1)
 		current->sgid = sgid;
+#ifdef CONFIG_MOSIX
+	tell_process(current, DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
 	return 0;
 }
 
@@ -732,6 +820,9 @@
 {
 	int old_fsuid;
 
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	old_fsuid = current->fsuid;
 	if (uid == current->uid || uid == current->euid ||
 	    uid == current->suid || uid == current->fsuid || 
@@ -739,7 +830,11 @@
 	{
 		if (uid != old_fsuid)
 		{
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(0);
+#else
 			current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 			wmb();
 		}
 		current->fsuid = uid;
@@ -774,6 +869,9 @@
 {
 	int old_fsgid;
 
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	old_fsgid = current->fsgid;
 	if (gid == current->gid || gid == current->egid ||
 	    gid == current->sgid || gid == current->fsgid || 
@@ -781,7 +879,11 @@
 	{
 		if (gid != old_fsgid)
 		{
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(0);
+#else
 			current->mm->dumpable = 0;
+#endif /* CONFIG_MOSIX */
 			wmb();
 		}
 		current->fsgid = gid;
@@ -797,6 +899,10 @@
 	 *	atomically safe type this is just fine. Conceptually its
 	 *	as if the syscall took an instant longer to occur.
 	 */
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		mosix_deputy_rusage(0);
+#endif /* CONFIG_MOSIX */
 	if (tbuf)
 		if (copy_to_user(tbuf, &current->times, sizeof(struct tms)))
 			return -EFAULT;
@@ -852,7 +958,11 @@
 		goto out;
 	if (pgid != pid) {
 		struct task_struct * tmp;
+#ifdef CONFIG_MOSIX
+		for_each_local_task (tmp) {
+#else
 		for_each_task (tmp) {
+#endif /* CONFIG_MOSIX */
 			if (tmp->pgrp == pgid &&
 			    tmp->session == current->session)
 				goto ok_pgid;
@@ -866,6 +976,13 @@
 out:
 	/* All paths lead to here, thus we are safe. -DaveM */
 	read_unlock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	if(!err)
+	{
+		tell_process(p, DREQ_INFOCNG);
+		wake_up_mosix(p);
+	}
+#endif /* CONFIG_MOSIX */
 	return err;
 }
 
@@ -919,7 +1036,11 @@
 	int err = -EPERM;
 
 	read_lock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	for_each_local_task(p) {
+#else
 	for_each_task(p) {
+#endif /* CONFIG_MOSIX */
 		if (p->pgrp == current->pid)
 			goto out;
 	}
@@ -931,6 +1052,10 @@
 	err = current->pgrp;
 out:
 	read_unlock(&tasklist_lock);
+#ifdef CONFIG_MOSIX
+	if(err == current->pid)
+		tell_process(current, DREQ_INFOCNG);
+#endif /* CONFIG_MOSIX */
 	return err;
 }
 
@@ -969,6 +1094,9 @@
 		return -EPERM;
 	if ((unsigned) gidsetsize > NGROUPS)
 		return -EINVAL;
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDCRED;
+#endif /* CONFIG_MOSIX_DFSA */
 	if(copy_from_user(current->groups, grouplist, gidsetsize * sizeof(gid_t)))
 		return -EFAULT;
 	current->ngroups = gidsetsize;
@@ -1130,6 +1258,22 @@
 			return -EPERM;
 	}
 	*old_rlim = new_rlim;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+	switch(resource)
+	{
+		case RLIMIT_CPU:
+		case RLIMIT_DATA:
+		case RLIMIT_STACK:
+		case RLIMIT_RSS:
+		case RLIMIT_AS:
+#ifdef CONFIG_MOSIX_DFSA
+		case RLIMIT_NOFILE:
+		case RLIMIT_FSIZE:
+#endif /* CONFIG_MOSIX_DFSA */
+			mosix_deputy_rlimit(resource, new_rlim);
+	}
+#endif /* CONFIG_MOSIX */
 	return 0;
 }
 
@@ -1191,12 +1335,19 @@
 {
 	if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
 		return -EINVAL;
+#ifdef CONFIG_MOSIX
+	if(who == RUSAGE_SELF && (current->mosix.dflags & DDEPUTY))
+		mosix_deputy_rusage(0);
+#endif /* CONFIG_MOSIX */
 	return getrusage(current, who, ru);
 }
 
 asmlinkage long sys_umask(int mask)
 {
 	mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
+#ifdef CONFIG_MOSIX_DFSA
+	current->mosix.dupdates |= DFSA_UPDUMASK;
+#endif /* CONFIG_MOSIX_DFSA */
 	return mask;
 }
     
@@ -1219,7 +1370,11 @@
 			error = put_user(current->pdeath_signal, (int *)arg2);
 			break;
 		case PR_GET_DUMPABLE:
+#ifdef CONFIG_MOSIX
+			if (i_am_dumpable())
+#else
 			if (current->mm->dumpable)
+#endif /* CONFIG_MOSIX */
 				error = 1;
 			break;
 		case PR_SET_DUMPABLE:
@@ -1227,7 +1382,11 @@
 				error = -EINVAL;
 				break;
 			}
+#ifdef CONFIG_MOSIX
+			set_me_dumpable(arg2 != 0);
+#else
 			current->mm->dumpable = arg2;
+#endif /* CONFIG_MOSIX */
 			break;
 	        case PR_SET_UNALIGN:
 #ifdef SET_UNALIGN_CTL
diff -ruN linux-2.4.16/kernel/sysctl.c linux-2.4.16-mosix/kernel/sysctl.c
--- linux-2.4.16/kernel/sysctl.c	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/kernel/sysctl.c	Sun Dec 23 13:56:53 2001
@@ -398,11 +398,23 @@
 		       ctl_table *table, void **context)
 {
 	int n;
+#ifdef CONFIG_MOSIX
+	/* single "get_user" calls are expensive: */
+	int udata[CTL_MAXNAME];
+	int *nextu = udata;
+
+	if(copy_from_user(udata, name, nlen * sizeof(int)))
+		return(-EFAULT);
+#endif /* CONFIG_MOSIX */
 repeat:
 	if (!nlen)
 		return -ENOTDIR;
+#ifdef CONFIG_MOSIX
+	n = *nextu++;
+#else
 	if (get_user(n, name))
 		return -EFAULT;
+#endif /* CONFIG_MOSIX */
 	for ( ; table->ctl_name; table++) {
 		if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
 			int error;
@@ -832,10 +844,27 @@
 	
 	for (; left && vleft--; i++, first=0) {
 		if (write) {
+#ifdef CONFIG_MOSIX
+			/* "get_user" is expensive - need better optimization */
+			int nex = TMPBUFLEN;
+#endif /* CONFIG_MOSIX */
 			while (left) {
 				char c;
+#ifdef CONFIG_MOSIX
+				if(nex == TMPBUFLEN)
+				{
+					len = left;
+					if(len > TMPBUFLEN)
+						len = TMPBUFLEN;
+					if(copy_from_user(buf, buffer, len))
+						return(-EFAULT);
+					nex = 0;
+				}
+				c = buf[nex++];
+#else
 				if(get_user(c,(char *) buffer))
 					return -EFAULT;
+#endif /* CONFIG_MOSIX */
 				if (!isspace(c))
 					break;
 				left--;
@@ -897,11 +926,29 @@
 		left--, buffer++;
 	}
 	if (write) {
+#ifdef CONFIG_MOSIX
+		/* "get_user" is expensive - need higher optimization */
+		int nex = TMPBUFLEN;
+#endif /* CONFIG_MOSIX */
 		p = (char *) buffer;
 		while (left) {
 			char c;
+#ifdef CONFIG_MOSIX
+			if(nex == TMPBUFLEN)
+			{
+				len = left;
+				if(len > TMPBUFLEN)
+					len = TMPBUFLEN;
+				if(copy_from_user(buf, p, len))
+					return(-EFAULT);
+				nex = 0;
+			}
+			c = buf[nex++];
+			p++;
+#else
 			if(get_user(c, p++))
 				return -EFAULT;
+#endif /* CONFIG_MOSIX */
 			if (!isspace(c))
 				break;
 			left--;
@@ -985,10 +1032,27 @@
 	
 	for (; left && vleft--; i++, first=0) {
 		if (write) {
+#ifdef CONFIG_MOSIX
+			/* "get_user" is expensive - need higher optimization */
+			int nex = TMPBUFLEN;
+#endif /* CONFIG_MOSIX */
 			while (left) {
 				char c;
+#ifdef CONFIG_MOSIX
+				if(nex == TMPBUFLEN)
+				{
+					len = left;
+					if(len > TMPBUFLEN)
+						len = TMPBUFLEN;
+					if(copy_from_user(buf, buffer, len))
+						return(-EFAULT);
+					nex = 0;
+				}
+				c = buf[nex++];
+#else
 				if(get_user(c, (char *) buffer))
 					return -EFAULT;
+#endif /* CONFIG_MOSIX */
 				if (!isspace(c))
 					break;
 				left--;
@@ -1045,11 +1109,29 @@
 		left--, buffer++;
 	}
 	if (write) {
+#ifdef CONFIG_MOSIX
+		/* "get_user" is expensive - need higher optimization */
+		int nex = TMPBUFLEN;
+#endif /* CONFIG_MOSIX */
 		p = (char *) buffer;
 		while (left) {
 			char c;
+#ifdef CONFIG_MOSIX
+			if(nex == TMPBUFLEN)
+			{
+				len = left;
+				if(len > TMPBUFLEN)
+					len = TMPBUFLEN;
+				if(copy_from_user(buf, p, len))
+					return(-EFAULT);
+				nex = 0;
+			}
+			c = buf[nex++];
+			p++;
+#else
 			if(get_user(c, p++))
 				return -EFAULT;
+#endif /* CONFIG_MOSIX */
 			if (!isspace(c))
 				break;
 			left--;
@@ -1088,10 +1170,27 @@
 	
 	for (; left && vleft--; i++, first=0) {
 		if (write) {
+#ifdef CONFIG_MOSIX
+			/* "get_user" is expensive - need better optimization */
+			int nex = TMPBUFLEN;
+#endif /* CONFIG_MOSIX */
 			while (left) {
 				char c;
+#ifdef CONFIG_MOSIX
+				if(nex == TMPBUFLEN)
+				{
+					len = left;
+					if(len > TMPBUFLEN)
+						len = TMPBUFLEN;
+					if(copy_from_user(buf, buffer, len))
+						return(-EFAULT);
+					nex = 0;
+				}
+				c = buf[nex++];
+#else
 				if(get_user(c, (char *) buffer))
 					return -EFAULT;
+#endif /* CONFIG_MOSIX */
 				if (!isspace(c))
 					break;
 				left--;
@@ -1150,11 +1249,29 @@
 		left--, buffer++;
 	}
 	if (write) {
+#ifdef CONFIG_MOSIX
+		/* "get_user" is expensive - need higher optimization */
+		int nex = TMPBUFLEN;
+#endif /* CONFIG_MOSIX */
 		p = (char *) buffer;
 		while (left) {
 			char c;
+#ifdef CONFIG_MOSIX
+			if(nex == TMPBUFLEN)
+			{
+				len = left;
+				if(len > TMPBUFLEN)
+					len = TMPBUFLEN;
+				if(copy_from_user(buf, p, len))
+					return(-EFAULT);
+				nex = 0;
+			}
+			c = buf[nex++];
+			p++;
+#else
 			if(get_user(c, p++))
 				return -EFAULT;
+#endif /* CONFIG_MOSIX */
 			if (!isspace(c))
 				break;
 			left--;
diff -ruN linux-2.4.16/kernel/timer.c linux-2.4.16-mosix/kernel/timer.c
--- linux-2.4.16/kernel/timer.c	Mon Oct  8 19:41:41 2001
+++ linux-2.4.16-mosix/kernel/timer.c	Sun Dec 23 13:56:53 2001
@@ -25,6 +25,10 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /*
  * Timekeeping variables
  */
@@ -522,12 +526,26 @@
 	unsigned long user, unsigned long system)
 {
 	unsigned long psecs;
+#ifdef CONFIG_MOSIX
+	int i;
+#endif /* CONFIG_MOSIX */
 
 	psecs = (p->times.tms_utime += user);
 	psecs += (p->times.tms_stime += system);
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DREMOTE)
+		psecs += p->mosix.passedtime;
+	if(!(p->mosix.dflags & DDEPUTY))
+#endif /* CONFIG_MOSIX */
 	if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_cur) {
 		/* Send SIGXCPU every second.. */
+#ifdef CONFIG_MOSIX
+		i = p->mosix.last_sigxcpu ? : p->rlim[RLIMIT_CPU].rlim_cur;
+		p->mosix.last_sigxcpu = psecs / HZ;
+		for(; i < p->mosix.last_sigxcpu ; i++)
+#else
 		if (!(psecs % HZ))
+#endif /* CONFIG_MOSIX */
 			send_sig(SIGXCPU, p, 1);
 		/* and SIGKILL when we go over max.. */
 		if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_max)
@@ -535,7 +553,11 @@
 	}
 }
 
+#ifdef CONFIG_MOSIX
+inline void do_it_virt(struct task_struct * p, unsigned long ticks)
+#else
 static inline void do_it_virt(struct task_struct * p, unsigned long ticks)
+#endif /* CONFIG_MOSIX */
 {
 	unsigned long it_virt = p->it_virt_value;
 
@@ -553,6 +575,11 @@
 {
 	unsigned long it_prof = p->it_prof_value;
 
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DDEPUTY)
+		p->mosix.deputytime++;
+	else
+#endif /* CONFIG_MOSIX */
 	if (it_prof) {
 		if (--it_prof == 0) {
 			it_prof = p->it_prof_incr;
@@ -627,6 +654,9 @@
 	unsigned long active_tasks; /* fixed-point */
 	static int count = LOAD_FREQ;
 
+#ifdef CONFIG_MOSIX
+	mosix_snap_load(ticks);
+#endif /* CONFIG_MOSIX */
 	count -= ticks;
 	if (count < 0) {
 		count += LOAD_FREQ;
diff -ruN linux-2.4.16/kernel/user.c linux-2.4.16-mosix/kernel/user.c
--- linux-2.4.16/kernel/user.c	Wed Nov 29 08:43:39 2000
+++ linux-2.4.16-mosix/kernel/user.c	Sun Dec 23 13:56:53 2001
@@ -87,6 +87,10 @@
 	struct user_struct **hashent = uidhashentry(uid);
 	struct user_struct *up;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DREMOTE)
+		panic("REMOTE allocating uid");
+#endif /* CONFIG_MOSIX_DIAG */
 	spin_lock(&uidhash_lock);
 	up = uid_hash_find(uid, hashent);
 	spin_unlock(&uidhash_lock);
@@ -134,4 +138,46 @@
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+
+extern int max_threads;
+
+struct user_struct remote_guests =
+{
+	__count:	ATOMIC_INIT(1),
+	processes:	ATOMIC_INIT(1),
+	files:		ATOMIC_INIT(0)
+};
+
+void
+init_guest_user_struct(void)
+{
+	struct task_struct *p = current;
+
+	free_uid(p->user);
+	p->user = &remote_guests;
+	p->rlim[RLIMIT_NPROC].rlim_cur = max_threads / 6;
+}
+
+int
+get_free_guest_slots(void)
+{
+	int a, b;
+
+	write_lock_irq(&tasklist_lock);
+	a = max_threads/6 - atomic_read(&remote_guests.__count);
+	b = max_threads - nr_threads;
+	write_unlock_irq(&tasklist_lock);
+	if(a < 0)	/* a little paranoidic */
+		a = 0;
+	return(a < b ? a : b);
+}
+
+int
+count_guests(void)
+{
+	return(atomic_read(&remote_guests.__count) - 1);
+}
+#endif /* CONFIG_MOSIX */
+
 module_init(uid_cache_init);
diff -ruN linux-2.4.16/less linux-2.4.16-mosix/less
--- linux-2.4.16/less	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/less	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,307 @@
+patching file Documentation/Configure.help
+Hunk #1 succeeded at 73 with fuzz 1 (offset 9 lines).
+patching file Documentation/DFSA
+patching file Documentation/filesystems/00-INDEX
+patching file Documentation/filesystems/mfs.txt
+patching file Makefile
+Hunk #4 succeeded at 227 (offset 1 line).
+patching file arch/i386/Makefile
+patching file arch/i386/config.in
+patching file arch/i386/defconfig
+patching file arch/i386/kernel/Makefile
+patching file arch/i386/kernel/entry.S
+patching file arch/i386/kernel/i387.c
+patching file arch/i386/kernel/ioport.c
+patching file arch/i386/kernel/irq.c
+patching file arch/i386/kernel/nmi.c
+patching file arch/i386/kernel/offset.c
+patching file arch/i386/kernel/process.c
+patching file arch/i386/kernel/ptrace.c
+Hunk #7 FAILED at 276.
+Hunk #8 succeeded at 306 (offset -4 lines).
+Hunk #10 succeeded at 376 (offset -4 lines).
+Hunk #12 succeeded at 439 (offset -4 lines).
+Hunk #14 succeeded at 496 (offset -4 lines).
+Hunk #16 succeeded at 581 (offset -4 lines).
+Hunk #18 succeeded at 617 (offset -4 lines).
+Hunk #20 succeeded at 653 (offset -4 lines).
+1 out of 21 hunks FAILED -- saving rejects to file arch/i386/kernel/ptrace.c.rej
+patching file arch/i386/kernel/signal.c
+patching file arch/i386/kernel/sys_i386.c
+patching file arch/i386/kernel/traps.c
+patching file arch/i386/kernel/vm86.c
+patching file arch/i386/lib/usercopy.c
+Hunk #5 succeeded at 182 with fuzz 2.
+patching file arch/i386/mm/fault.c
+patching file drivers/char/Makefile
+Hunk #1 succeeded at 137 (offset 1 line).
+patching file drivers/char/console.c
+patching file drivers/char/drm/i810_dma.c
+patching file drivers/char/keyboard.c
+patching file drivers/char/mem.c
+patching file drivers/char/pc_keyb.c
+Hunk #1 succeeded at 525 (offset 4 lines).
+patching file drivers/char/serial.c
+Hunk #1 succeeded at 231 (offset 9 lines).
+Hunk #3 succeeded at 900 (offset 9 lines).
+Hunk #5 succeeded at 5874 (offset 20 lines).
+patching file drivers/char/sysrq.c
+patching file drivers/char/tty_io.c
+patching file drivers/char/vt.c
+Hunk #1 succeeded at 221 (offset -1 lines).
+patching file drivers/scsi/cpqfcTSworker.c
+patching file drivers/sgi/char/graphics.c
+patching file drivers/sgi/char/shmiq.c
+patching file drivers/usb/storage/usb.c
+Hunk #1 succeeded at 317 (offset 12 lines).
+patching file fs/Makefile
+Hunk #1 succeeded at 67 (offset 3 lines).
+patching file fs/binfmt_aout.c
+patching file fs/binfmt_elf.c
+patching file fs/buffer.c
+Hunk #1 succeeded at 53 (offset 1 line).
+Hunk #3 succeeded at 442 (offset 1 line).
+patching file fs/dcache.c
+patching file fs/dnotify.c
+patching file fs/exec.c
+patching file fs/fcntl.c
+patching file fs/file.c
+patching file fs/file_table.c
+patching file fs/inode.c
+Hunk #2 succeeded at 792 (offset 1 line).
+Hunk #4 succeeded at 867 (offset 1 line).
+patching file fs/ioctl.c
+patching file fs/lockd/svc.c
+patching file fs/mfs/Makefile
+patching file fs/mfs/ccontact.c
+patching file fs/mfs/client.c
+patching file fs/mfs/complete.c
+patching file fs/mfs/convert.c
+patching file fs/mfs/count.c
+patching file fs/mfs/file.c
+patching file fs/mfs/scontact.c
+patching file fs/mfs/server.c
+patching file fs/mfs/socket.c
+patching file fs/namei.c
+patching file fs/namespace.c
+Hunk #1 succeeded at 24 with fuzz 2 (offset 1 line).
+Hunk #2 FAILED at 318.
+Hunk #3 succeeded at 390 (offset -28 lines).
+Hunk #4 succeeded at 605 (offset 1 line).
+Hunk #5 succeeded at 613 (offset -28 lines).
+Hunk #6 succeeded at 655 (offset 1 line).
+Hunk #7 succeeded at 665 (offset -28 lines).
+Hunk #8 succeeded at 773 (offset 1 line).
+Hunk #9 succeeded at 782 (offset -28 lines).
+Hunk #10 succeeded at 878 (offset 1 line).
+Hunk #11 succeeded at 871 (offset -28 lines).
+Hunk #12 succeeded at 949 (offset 1 line).
+Hunk #13 succeeded at 955 (offset -28 lines).
+Hunk #14 succeeded at 1000 (offset 1 line).
+Hunk #15 succeeded at 1007 (offset -28 lines).
+Hunk #16 succeeded at 1052 (offset 1 line).
+1 out of 16 hunks FAILED -- saving rejects to file fs/namespace.c.rej
+patching file fs/nfsd/auth.c
+patching file fs/nfsd/export.c
+patching file fs/nfsd/vfs.c
+patching file fs/open.c
+patching file fs/pipe.c
+patching file fs/proc/array.c
+patching file fs/proc/base.c
+patching file fs/proc/generic.c
+patching file fs/proc/inode.c
+Hunk #1 succeeded at 194 (offset -2 lines).
+patching file fs/proc/root.c
+patching file fs/read_write.c
+patching file fs/readdir.c
+patching file fs/stat.c
+patching file fs/super.c
+Hunk #1 succeeded at 495 (offset 1 line).
+Hunk #3 succeeded at 652 (offset 2 lines).
+patching file fs/umsdos/ioctl.c
+patching file include/asm-generic/smplock.h
+patching file include/asm-i386/a.out.h
+patching file include/asm-i386/checksum.h
+patching file include/asm-i386/cpufeature.h
+patching file include/asm-i386/elf.h
+patching file include/asm-i386/fcntl.h
+patching file include/asm-i386/i387.h
+patching file include/asm-i386/processor.h
+patching file include/asm-i386/semaphore.h
+patching file include/asm-i386/siginfo.h
+patching file include/asm-i386/smplock.h
+patching file include/asm-i386/spinlock.h
+patching file include/asm-i386/stat.h
+patching file include/asm-i386/uaccess.h
+patching file include/linux/binfmts.h
+patching file include/linux/capability.h
+Hunk #1 succeeded at 348 (offset 2 lines).
+patching file include/linux/completion.h
+patching file include/linux/dcache.h
+patching file include/linux/dfsa_interface.h
+patching file include/linux/elf.h
+patching file include/linux/errno.h
+patching file include/linux/file.h
+patching file include/linux/fs.h
+Hunk #1 succeeded at 150 (offset 1 line).
+Hunk #2 succeeded at 319 (offset 2 lines).
+Hunk #3 succeeded at 515 (offset 8 lines).
+Hunk #4 succeeded at 655 (offset 2 lines).
+Hunk #5 succeeded at 909 (offset 10 lines).
+Hunk #6 succeeded at 960 (offset 2 lines).
+Hunk #7 succeeded at 1342 (offset 12 lines).
+Hunk #8 succeeded at 1677 (offset 5 lines).
+patching file include/linux/fs_struct.h
+patching file include/linux/iobuf.h
+patching file include/linux/keyboard.h
+patching file include/linux/linkage.h
+patching file include/linux/mfs.h
+patching file include/linux/mfs_fs_i.h
+patching file include/linux/mfs_socket.h
+patching file include/linux/mm.h
+Hunk #1 succeeded at 165 (offset 5 lines).
+Hunk #2 succeeded at 505 (offset -3 lines).
+patching file include/linux/mosctl.h
+patching file include/linux/mosix.h
+patching file include/linux/mount.h
+patching file include/linux/net.h
+patching file include/linux/personality.h
+patching file include/linux/pipe_fs_i.h
+patching file include/linux/proc_fs.h
+patching file include/linux/remote_fs_i.h
+patching file include/linux/sched.h
+Hunk #7 FAILED at 443.
+Hunk #8 FAILED at 534.
+Hunk #9 succeeded at 594 with fuzz 2 (offset 13 lines).
+Hunk #10 succeeded at 718 (offset 13 lines).
+Hunk #11 succeeded at 929 (offset 13 lines).
+Hunk #12 succeeded at 998 (offset 13 lines).
+2 out of 12 hunks FAILED -- saving rejects to file include/linux/sched.h.rej
+patching file include/linux/smp_lock.h
+patching file include/linux/spinlock.h
+patching file include/linux/wait.h
+patching file include/mos/balance.h
+patching file include/mos/comm.h
+patching file include/mos/debug.h
+patching file include/mos/defs.h
+patching file include/mos/dfsa.h
+patching file include/mos/dscosts.h
+patching file include/mos/log.h
+patching file include/mos/mfscosts.h
+patching file include/mos/mosctl.h
+patching file include/mos/mosixtask.h
+patching file include/mos/protocol.h
+patching file include/mos/request.h
+patching file include/mos/routines.h
+patching file include/mos/version.h
+patching file include/net/sock.h
+patching file init/main.c
+patching file ipc/shm.c
+patching file kernel/acct.c
+patching file kernel/capability.c
+patching file kernel/exec_domain.c
+Hunk #3 succeeded at 177 (offset 2 lines).
+Hunk #5 succeeded at 207 (offset 2 lines).
+patching file kernel/exit.c
+Hunk #2 succeeded at 87 (offset 1 line).
+Hunk #4 succeeded at 152 (offset 1 line).
+Hunk #6 succeeded at 233 (offset 1 line).
+Hunk #8 succeeded at 286 (offset 1 line).
+Hunk #10 succeeded at 353 (offset 1 line).
+Hunk #12 succeeded at 443 (offset 1 line).
+Hunk #14 succeeded at 494 (offset 1 line).
+Hunk #16 succeeded at 528 (offset 1 line).
+patching file kernel/fork.c
+patching file kernel/module.c
+Hunk #1 succeeded at 1066 (offset 1 line).
+patching file kernel/panic.c
+patching file kernel/ptrace.c
+Hunk #1 succeeded at 52 with fuzz 2 (offset 36 lines).
+Hunk #3 succeeded at 77 (offset 36 lines).
+Hunk #5 succeeded at 119 (offset 36 lines).
+patching file kernel/sched.c
+Hunk #1 succeeded at 37 (offset 1 line).
+Hunk #3 succeeded at 174 (offset 1 line).
+Hunk #5 succeeded at 358 (offset 1 line).
+Hunk #7 succeeded at 499 (offset 1 line).
+Hunk #9 FAILED at 625.
+Hunk #10 succeeded at 651 with fuzz 2 (offset 5 lines).
+Hunk #11 FAILED at 733.
+Hunk #12 succeeded at 801 (offset 3 lines).
+Hunk #13 succeeded at 849 (offset -27 lines).
+Hunk #14 succeeded at 892 (offset 3 lines).
+Hunk #15 succeeded at 939 (offset -27 lines).
+Hunk #16 succeeded at 1095 (offset 3 lines).
+Hunk #17 succeeded at 1137 (offset -27 lines).
+Hunk #18 succeeded at 1535 (offset -1 lines).
+2 out of 18 hunks FAILED -- saving rejects to file kernel/sched.c.rej
+patching file kernel/signal.c
+patching file kernel/sys.c
+patching file kernel/sysctl.c
+Hunk #1 succeeded at 398 (offset 4 lines).
+Hunk #3 succeeded at 926 (offset 4 lines).
+Hunk #5 succeeded at 1109 (offset 4 lines).
+Hunk #7 succeeded at 1249 (offset 4 lines).
+patching file kernel/timer.c
+patching file kernel/user.c
+patching file lib/rwsem-spinlock.c
+patching file lib/rwsem.c
+patching file mm/filemap.c
+Hunk #2 succeeded at 140 (offset 6 lines).
+Hunk #3 succeeded at 1691 (offset 118 lines).
+Hunk #4 succeeded at 2066 (offset 6 lines).
+Hunk #5 succeeded at 3021 (offset 122 lines).
+patching file mm/memory.c
+Hunk #20 succeeded at 623 with fuzz 1.
+patching file mm/mlock.c
+patching file mm/mmap.c
+patching file mm/mprotect.c
+patching file mm/mremap.c
+patching file mm/oom_kill.c
+patching file mm/page_alloc.c
+Hunk #1 succeeded at 370 (offset 2 lines).
+patching file mm/vmscan.c
+Hunk #1 succeeded at 47 (offset -1 lines).
+Hunk #2 succeeded at 176 (offset 8 lines).
+Hunk #3 succeeded at 209 (offset -1 lines).
+Hunk #4 succeeded at 269 (offset 8 lines).
+Hunk #5 succeeded at 690 (offset 1 line).
+Hunk #6 succeeded at 716 (offset 8 lines).
+Hunk #7 succeeded at 743 (offset 1 line).
+patching file mos/Makefile
+patching file mos/badops.c
+patching file mos/balance.c
+patching file mos/comm.c
+patching file mos/config.c
+patching file mos/copy_unconf
+patching file mos/decay.c
+patching file mos/deputy.c
+patching file mos/dfsa.c
+patching file mos/div.c
+patching file mos/export.c
+patching file mos/freemem.c
+patching file mos/info.c
+patching file mos/init.c
+patching file mos/kernel.c
+patching file mos/load.c
+patching file mos/log.c
+patching file mos/mig.c
+patching file mos/mkdefcalls.c
+patching file mos/mosadmin.c
+patching file mos/mosproc.c
+patching file mos/prequest.c
+patching file mos/remote.c
+patching file mos/rinode.c
+patching file mos/service.c
+patching file mos/syscalls.c
+patching file mos/ucache.c
+patching file net/core/scm.c
+patching file net/core/skbuff.c
+patching file net/core/sock.c
+patching file net/ipv4/af_inet.c
+patching file net/ipv4/tcp_input.c
+patching file net/sunrpc/sched.c
+patching file net/sunrpc/svc.c
+patching file udb/Makefile
+patching file udb/symtab.c
+patching file udb/udb.c
diff -ruN linux-2.4.16/lib/rwsem-spinlock.c linux-2.4.16-mosix/lib/rwsem-spinlock.c
--- linux-2.4.16/lib/rwsem-spinlock.c	Wed Apr 25 23:31:03 2001
+++ linux-2.4.16-mosix/lib/rwsem-spinlock.c	Sun Dec 23 13:56:53 2001
@@ -127,6 +127,9 @@
 
 	/* set up my own style of waitqueue */
 	waiter.task = tsk;
+#ifdef CONFIG_MOSIX
+	adjust_task_mosix_context(&waiter.task);
+#endif /* CONFIG_MOSIX */
 	waiter.flags = RWSEM_WAITING_FOR_READ;
 
 	list_add_tail(&waiter.list,&sem->wait_list);
@@ -173,6 +176,9 @@
 
 	/* set up my own style of waitqueue */
 	waiter.task = tsk;
+#ifdef CONFIG_MOSIX
+	adjust_task_mosix_context(&waiter.task);
+#endif /* CONFIG_MOSIX */
 	waiter.flags = RWSEM_WAITING_FOR_WRITE;
 
 	list_add_tail(&waiter.list,&sem->wait_list);
diff -ruN linux-2.4.16/lib/rwsem.c linux-2.4.16-mosix/lib/rwsem.c
--- linux-2.4.16/lib/rwsem.c	Wed Jul 11 06:08:51 2001
+++ linux-2.4.16-mosix/lib/rwsem.c	Sun Dec 23 13:56:53 2001
@@ -122,6 +122,9 @@
 	/* set up my own style of waitqueue */
 	spin_lock(&sem->wait_lock);
 	waiter->task = tsk;
+#ifdef CONFIG_MOSIX
+	adjust_task_mosix_context(&waiter->task);
+#endif /* CONFIG_MOSIX */
 
 	list_add_tail(&waiter->list,&sem->wait_list);
 
diff -ruN linux-2.4.16/mm/filemap.c linux-2.4.16-mosix/mm/filemap.c
--- linux-2.4.16/mm/filemap.c	Mon Nov 26 15:29:17 2001
+++ linux-2.4.16-mosix/mm/filemap.c	Tue Dec 25 18:46:57 2001
@@ -31,6 +31,13 @@
 
 #include <linux/highmem.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 /*
  * Shared mappings implemented 30.11.1994. It's not fully working yet,
  * though.
@@ -55,7 +62,7 @@
 
 spinlock_t pagecache_lock ____cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
 /*
- * NOTE: to avoid deadlocking you must never acquire the pagemap_lru_lock 
+ * NOTE: to avoid deadlocking you must never acquire the pagemap_lru_lock
  *	with the pagecache_lock held.
  *
  * Ordering:
@@ -213,6 +220,9 @@
 
 	spin_unlock(&pagecache_lock);
 	spin_unlock(&pagemap_lru_lock);
+#ifdef CONFIG_MOSIX
+	VMODIFIED(inode);
+#endif /* CONFIG_MOSIX */
 }
 
 static int do_flushpage(struct page *page, unsigned long offset)
@@ -242,7 +252,7 @@
 	 * destroyed all buffer-cache references to it. Otherwise some
 	 * other process might think this inode page is not in the
 	 * page cache and creates a buffer-cache alias to it causing
-	 * all sorts of fun problems ...  
+	 * all sorts of fun problems ...
 	 */
 	ClearPageDirty(page);
 	ClearPageUptodate(page);
@@ -287,7 +297,7 @@
 				if (*partial && (offset + 1) == start) {
 					truncate_partial_page(page, *partial);
 					*partial = 0;
-				} else 
+				} else
 					truncate_complete_page(page);
 
 				UnlockPage(page);
@@ -319,7 +329,7 @@
  * that are beyond that offset (and zeroing out partial pages).
  * If any page is locked we wait for it to become unlocked.
  */
-void truncate_inode_pages(struct address_space * mapping, loff_t lstart) 
+void truncate_inode_pages(struct address_space * mapping, loff_t lstart)
 {
 	unsigned long start = (lstart + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
 	unsigned partial = lstart & (PAGE_CACHE_SIZE - 1);
@@ -470,7 +480,7 @@
 			continue;
 
 		bh->b_flushtime = jiffies;
-		ll_rw_block(WRITE, 1, &bh);	
+		ll_rw_block(WRITE, 1, &bh);
 	} while ((bh = bh->b_this_page) != head);
 	return 0;
 }
@@ -578,7 +588,7 @@
 /**
  *      filemap_fdatasync - walk the list of dirty pages of the given address space
  *     	and writepage() all of them.
- * 
+ *
  *      @mapping: address space structure to write
  *
  */
@@ -617,7 +627,7 @@
 /**
  *      filemap_fdatawait - walk the list of locked pages of the given address space
  *     	and wait for all of them.
- * 
+ *
  *      @mapping: address space structure to wait for
  *
  */
@@ -648,7 +658,7 @@
 /*
  * Add a page to the inode page cache.
  *
- * The caller must have locked the page and 
+ * The caller must have locked the page and
  * set all the page flags correctly..
  */
 void add_to_page_cache_locked(struct page * page, struct address_space *mapping, unsigned long index)
@@ -723,7 +733,7 @@
 {
 	struct address_space *mapping = file->f_dentry->d_inode->i_mapping;
 	struct page **hash = page_hash(mapping, offset);
-	struct page *page; 
+	struct page *page;
 
 	spin_lock(&pagecache_lock);
 	page = __find_page_nolock(mapping, offset, *hash);
@@ -741,7 +751,7 @@
 		return error;
 	}
 	/*
-	 * We arrive here in the unlikely event that someone 
+	 * We arrive here in the unlikely event that someone
 	 * raced with us and added our page to the cache first.
 	 */
 	page_cache_release(page);
@@ -770,7 +780,7 @@
 	return 0;
 }
 
-/* 
+/*
  * Wait for a page to get unlocked.
  *
  * This must be called with the caller "holding" the page,
@@ -800,7 +810,7 @@
 	smp_mb__before_clear_bit();
 	if (!test_and_clear_bit(PG_locked, &(page)->flags))
 		BUG();
-	smp_mb__after_clear_bit(); 
+	smp_mb__after_clear_bit();
 	if (waitqueue_active(&(page)->wait))
 	wake_up(&(page)->wait);
 }
@@ -827,7 +837,7 @@
 	tsk->state = TASK_RUNNING;
 	remove_wait_queue(&page->wait, &wait);
 }
-	
+
 
 /*
  * Get an exclusive lock on the page, optimistically
@@ -953,11 +963,11 @@
 			spin_unlock(&pagecache_lock);
 			if (newpage == NULL)
 				lru_cache_add(page);
-			else 
+			else
 				page_cache_release(newpage);
 		}
 	}
-	return page;	
+	return page;
 }
 
 /*
@@ -1022,11 +1032,11 @@
 /*
  * Read-ahead profiling information
  * --------------------------------
- * Every PROFILE_MAXREADCOUNT, the following information is written 
+ * Every PROFILE_MAXREADCOUNT, the following information is written
  * to the syslog:
  *   Percentage of asynchronous read-ahead.
  *   Average of read-ahead fields context value.
- * If DEBUG_READAHEAD is defined, a snapshot of these fields is written 
+ * If DEBUG_READAHEAD is defined, a snapshot of these fields is written
  * to the syslog.
  */
 
@@ -1102,7 +1112,7 @@
  *
  * Synchronous read-ahead benefits:
  * --------------------------------
- * Using reasonable IO xfer length from peripheral devices increase system 
+ * Using reasonable IO xfer length from peripheral devices increase system
  * performances.
  * Reasonable means, in this context, not too large but not too small.
  * The actual maximum value is:
@@ -1111,22 +1121,22 @@
  *
  * Asynchronous read-ahead benefits:
  * ---------------------------------
- * Overlapping next read request and user process execution increase system 
+ * Overlapping next read request and user process execution increase system
  * performance.
  *
  * Read-ahead risks:
  * -----------------
  * We have to guess which further data are needed by the user process.
- * If these data are often not really needed, it's bad for system 
+ * If these data are often not really needed, it's bad for system
  * performances.
- * However, we know that files are often accessed sequentially by 
- * application programs and it seems that it is possible to have some good 
+ * However, we know that files are often accessed sequentially by
+ * application programs and it seems that it is possible to have some good
  * strategy in that guessing.
  * We only try to read-ahead files that seems to be read sequentially.
  *
  * Asynchronous read-ahead risks:
  * ------------------------------
- * In order to maximize overlapping, we must start some asynchronous read 
+ * In order to maximize overlapping, we must start some asynchronous read
  * request from the device, as soon as possible.
  * We must be very careful about:
  * - The number of effective pending IO read requests.
@@ -1164,7 +1174,7 @@
  * If the current position is inside the previous read IO request, do not
  * try to reread previously read ahead pages.
  * Otherwise decide or not to read ahead some pages synchronously.
- * If we are not going to read ahead, set the read ahead context for this 
+ * If we are not going to read ahead, set the read ahead context for this
  * page only.
  */
 	if (PageLocked(page)) {
@@ -1193,7 +1203,7 @@
 /*
  * Add ONE page to max_ahead in order to try to have about the same IO max size
  * as synchronous read-ahead (MAX_READAHEAD + 1)*PAGE_CACHE_SIZE.
- * Compute the position of the last page we have tried to read in order to 
+ * Compute the position of the last page we have tried to read in order to
  * begin to read ahead just at the next page.
  */
 		raend -= 1;
@@ -1291,7 +1301,7 @@
 	offset = *ppos & ~PAGE_CACHE_MASK;
 
 /*
- * If the current position is outside the previous read-ahead window, 
+ * If the current position is outside the previous read-ahead window,
  * we reset the current read-ahead context and set read ahead max to zero
  * (will be set to just needed value later),
  * otherwise, we assume that the file accesses are sequential enough to
@@ -1334,7 +1344,7 @@
 		unsigned long end_index, nr, ret;
 
 		end_index = inode->i_size >> PAGE_CACHE_SHIFT;
-			
+
 		if (index > end_index)
 			break;
 		nr = PAGE_CACHE_SIZE;
@@ -1474,7 +1484,7 @@
 		page = cached_page;
 		__add_to_page_cache(page, mapping, index, hash);
 		spin_unlock(&pagecache_lock);
-		lru_cache_add(page);		
+		lru_cache_add(page);
 		cached_page = NULL;
 
 		goto readpage;
@@ -1543,7 +1553,7 @@
 
 		if (rw == READ && retval > 0)
 			mark_dirty_kiobuf(iobuf, retval);
-		
+
 		if (retval >= 0) {
 			count -= retval;
 			buf += retval;
@@ -1564,7 +1574,7 @@
 		clear_bit(0, &filp->f_iobuf_lock);
 	else
 		free_kiovec(1, &iobuf);
- out:	
+ out:
 	return retval;
 }
 
@@ -1579,7 +1589,7 @@
 	kaddr = kmap(page);
 	left = __copy_to_user(desc->buf, kaddr + offset, size);
 	kunmap(page);
-	
+
 	if (left) {
 		size -= left;
 		desc->error = -EFAULT;
@@ -1687,6 +1697,10 @@
 	struct file * in_file, * out_file;
 	struct inode * in_inode, * out_inode;
 
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_touch_file(in_fd);
+	dfsa_touch_file(out_fd);
+#endif /* CONFIG_MOSIX_DFSA */
 	/*
 	 * Get input file, and verify that it is ok..
 	 */
@@ -1925,7 +1939,7 @@
 
 no_cached_page:
 	/*
-	 * If the requested offset is within our file, try to read a whole 
+	 * If the requested offset is within our file, try to read a whole
 	 * cluster of pages at once.
 	 *
 	 * Otherwise, we're off the end of a privately mapped file,
@@ -2029,7 +2043,7 @@
 }
 
 static inline int filemap_sync_pte_range(pmd_t * pmd,
-	unsigned long address, unsigned long size, 
+	unsigned long address, unsigned long size,
 	struct vm_area_struct *vma, unsigned long offset, unsigned int flags)
 {
 	pte_t * pte;
@@ -2059,7 +2073,7 @@
 }
 
 static inline int filemap_sync_pmd_range(pgd_t * pgd,
-	unsigned long address, unsigned long size, 
+	unsigned long address, unsigned long size,
 	struct vm_area_struct *vma, unsigned int flags)
 {
 	pmd_t * pmd;
@@ -2170,6 +2184,10 @@
 	struct vm_area_struct * vma;
 	int unmapped_error, error = -EINVAL;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DDEPUTY)
+		panic("sys_msync: DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
 	down_read(&current->mm->mmap_sem);
 	if (start & ~PAGE_MASK)
 		goto out;
@@ -2471,7 +2489,7 @@
 		error = -EINVAL;
 		break;
 	}
-		
+
 	return error;
 }
 
@@ -2832,7 +2850,7 @@
 }
 
 /*
- * Write to a file through the page cache. 
+ * Write to a file through the page cache.
  *
  * We currently put everything into the page cache prior to writing it.
  * This is not a problem when writing full pages. With partial pages,
@@ -2890,7 +2908,7 @@
 	 * Check whether we've reached the file size limit.
 	 */
 	err = -EFBIG;
-	
+
 	if (limit != RLIM_INFINITY) {
 		if (pos >= limit) {
 			send_sig(SIGXFSZ, current, 0);
@@ -2903,7 +2921,7 @@
 	}
 
 	/*
-	 *	LFS rule 
+	 *	LFS rule
 	 */
 	if ( pos + count > MAX_NON_LFS && !(file->f_flags&O_LARGEFILE)) {
 		if (pos >= MAX_NON_LFS) {
@@ -2925,7 +2943,7 @@
 	 *
 	 *	Linus frestrict idea will clean these up nicely..
 	 */
-	 
+
 	if (!S_ISBLK(inode->i_mode)) {
 		if (pos >= inode->i_sb->s_maxbytes)
 		{
@@ -3009,6 +3027,9 @@
 		page_fault = __copy_from_user(kaddr+offset, buf, bytes);
 		flush_dcache_page(page);
 		status = mapping->a_ops->commit_write(file, page, offset, offset+bytes);
+#ifdef CONFIG_MOSIX
+		VMODIFIED(inode);
+#endif /* CONFIG_MOSIX */
 		if (page_fault)
 			goto fail_write;
 		if (!status)
@@ -3041,8 +3062,8 @@
 		if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
 			status = generic_osync_inode(inode, OSYNC_METADATA|OSYNC_DATA);
 	}
-	
-out_status:	
+
+out_status:
 	err = written ? written : status;
 out:
 
diff -ruN linux-2.4.16/mm/memory.c linux-2.4.16-mosix/mm/memory.c
--- linux-2.4.16/mm/memory.c	Thu Nov 15 20:03:06 2001
+++ linux-2.4.16-mosix/mm/memory.c	Sun Dec 23 13:56:53 2001
@@ -49,6 +49,10 @@
 #include <asm/uaccess.h>
 #include <asm/tlb.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 unsigned long max_mapnr;
 unsigned long num_physpages;
 void * high_memory;
@@ -71,7 +75,7 @@
 mem_map_t * mem_map;
 
 /*
- * Called by TLB shootdown 
+ * Called by TLB shootdown
  */
 void __free_pte(pte_t pte)
 {
@@ -79,7 +83,7 @@
 	if ((!VALID_PAGE(page)) || PageReserved(page))
 		return;
 	if (pte_dirty(pte))
-		set_page_dirty(page);		
+		set_page_dirty(page);
 	free_page_and_swap_cache(page);
 }
 
@@ -186,9 +190,9 @@
 		pmd_t * src_pmd, * dst_pmd;
 
 		src_pgd++; dst_pgd++;
-		
+
 		/* copy_pmd_range */
-		
+
 		if (pgd_none(*src_pgd))
 			goto skip_copy_pmd_range;
 		if (pgd_bad(*src_pgd)) {
@@ -207,9 +211,9 @@
 
 		do {
 			pte_t * src_pte, * dst_pte;
-		
+
 			/* copy_pte_range */
-		
+
 			if (pmd_none(*src_pmd))
 				goto skip_copy_pte_range;
 			if (pmd_bad(*src_pmd)) {
@@ -226,11 +230,11 @@
 			if (!dst_pte)
 				goto nomem;
 
-			spin_lock(&src->page_table_lock);			
+			spin_lock(&src->page_table_lock);
 			do {
 				pte_t pte = *src_pte;
 				struct page *ptepage;
-				
+
 				/* copy_one_pte */
 
 				if (pte_none(pte))
@@ -240,7 +244,7 @@
 					goto cont_copy_pte_range;
 				}
 				ptepage = pte_page(pte);
-				if ((!VALID_PAGE(ptepage)) || 
+				if ((!VALID_PAGE(ptepage)) ||
 				    PageReserved(ptepage))
 					goto cont_copy_pte_range;
 
@@ -265,7 +269,7 @@
 				dst_pte++;
 			} while ((unsigned long)src_pte & PTE_TABLE_MASK);
 			spin_unlock(&src->page_table_lock);
-		
+
 cont_copy_pmd_range:	src_pmd++;
 			dst_pmd++;
 		} while ((unsigned long)src_pmd & PMD_TABLE_MASK);
@@ -346,7 +350,7 @@
 	freed = 0;
 	do {
 		freed += zap_pte_range(tlb, pmd, address, end - address);
-		address = (address + PMD_SIZE) & PMD_MASK; 
+		address = (address + PMD_SIZE) & PMD_MASK;
 		pmd++;
 	} while (address < end);
 	return freed;
@@ -399,9 +403,9 @@
 
 
 /*
- * Do a quick page-table lookup for a single page. 
+ * Do a quick page-table lookup for a single page.
  */
-static struct page * follow_page(unsigned long address, int write) 
+static struct page * follow_page(unsigned long address, int write)
 {
 	pgd_t *pgd;
 	pmd_t *pmd;
@@ -430,7 +434,7 @@
 	return 0;
 }
 
-/* 
+/*
  * Given a physical address, is there a useful struct page pointing to
  * it?  This may become more complex in the future if we start dealing
  * with IO-aperture pages in kiobufs.
@@ -445,7 +449,7 @@
 
 /*
  * Force in an entire range of pages from the current process's user VA,
- * and pin them in physical memory.  
+ * and pin them in physical memory.
  */
 
 #define dprintk(x...)
@@ -458,14 +462,18 @@
 	struct page *		map;
 	int			i;
 	int			datain = (rw == READ);
-	
+
 	/* Make sure the iobuf is not already mapped somewhere. */
 	if (iobuf->nr_pages)
 		return -EINVAL;
 
+#ifdef CONFIG_MOSIX
+	if(stay_me_and_my_clones(DSTAY_FOR_KIOBUF))
+		return(-ENOMEM);
+#endif /* CONFIG_MOSIX */
 	mm = current->mm;
 	dprintk ("map_user_kiobuf: begin\n");
-	
+
 	ptr = va & PAGE_MASK;
 	end = (va + len + PAGE_SIZE - 1) & PAGE_MASK;
 	err = expand_kiobuf(iobuf, (end - ptr) >> PAGE_SHIFT);
@@ -473,21 +481,39 @@
 		return err;
 
 	down_read(&mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	write_lock_irq(&tasklist_lock);
+	if(iobuf->mm)
+	{
+		printk("map_user_kiobuf: double use\n");
+#ifdef CONFIG_MOSIX_UDB
+		mosix_debugger("kiobuf");
+#endif /* CONFIG_MOSIX_UDB */
+		write_unlock_irq(&tasklist_lock);
+		up_read(&mm->mmap_sem);
+		unstay_mm(mm);
+		return(-EINVAL);
+	}
+	atomic_inc(&mm->mm_count);
+	atomic_inc(&mm->mm_kiocount);
+	iobuf->mm = mm;
+	write_unlock_irq(&tasklist_lock);
+#endif /* CONFIG_MOSIX */
 
 	err = -EFAULT;
 	iobuf->locked = 0;
 	iobuf->offset = va & ~PAGE_MASK;
 	iobuf->length = len;
-	
+
 	i = 0;
-	
-	/* 
+
+	/*
 	 * First of all, try to fault in all of the necessary pages
 	 */
 	while (ptr < end) {
 		if (!vma || ptr >= vma->vm_end) {
 			vma = find_vma(current->mm, ptr);
-			if (!vma) 
+			if (!vma)
 				goto out_unlock;
 			if (vma->vm_start > ptr) {
 				if (!(vma->vm_flags & VM_GROWSDOWN))
@@ -516,7 +542,7 @@
 				}
 			}
 			spin_lock(&mm->page_table_lock);
-		}			
+		}
 		map = get_page_map(map);
 		if (map) {
 			flush_dcache_page(map);
@@ -526,7 +552,7 @@
 		spin_unlock(&mm->page_table_lock);
 		iobuf->maplist[i] = map;
 		iobuf->nr_pages = ++i;
-		
+
 		ptr += PAGE_SIZE;
 	}
 
@@ -538,11 +564,14 @@
 	up_read(&mm->mmap_sem);
 	unmap_kiobuf(iobuf);
 	dprintk ("map_user_kiobuf: end %d\n", err);
+#ifdef CONFIG_MOSIX
+	unstay_mm(mm);
+#endif /* CONFIG_MOSIX */
 	return err;
 }
 
 /*
- * Mark all of the pages in a kiobuf as dirty 
+ * Mark all of the pages in a kiobuf as dirty
  *
  * We need to be able to deal with short reads from disk: if an IO error
  * occurs, the number of bytes read into memory may be less than the
@@ -554,16 +583,16 @@
 {
 	int index, offset, remaining;
 	struct page *page;
-	
+
 	index = iobuf->offset >> PAGE_SHIFT;
 	offset = iobuf->offset & ~PAGE_MASK;
 	remaining = bytes;
 	if (remaining > iobuf->length)
 		remaining = iobuf->length;
-	
+
 	while (remaining > 0 && index < iobuf->nr_pages) {
 		page = iobuf->maplist[index];
-		
+
 		if (!PageReserved(page))
 			SetPageDirty(page);
 
@@ -575,14 +604,17 @@
 
 /*
  * Unmap all of the pages referenced by a kiobuf.  We release the pages,
- * and unlock them if they were locked. 
+ * and unlock them if they were locked.
  */
 
-void unmap_kiobuf (struct kiobuf *iobuf) 
+void unmap_kiobuf (struct kiobuf *iobuf)
 {
 	int i;
 	struct page *map;
-	
+#ifdef CONFIG_MOSIX
+	struct mm_struct *mm;
+#endif /* CONFIG_MOSIX */
+
 	for (i = 0; i < iobuf->nr_pages; i++) {
 		map = iobuf->maplist[i];
 		if (map) {
@@ -591,9 +623,26 @@
 			page_cache_release(map);
 		}
 	}
-	
+
 	iobuf->nr_pages = 0;
 	iobuf->locked = 0;
+#ifdef CONFIG_MOSIX
+	write_lock_irq(&tasklist_lock);
+	mm = iobuf->mm;
+	iobuf->mm = NULL;
+	write_unlock_irq(&tasklist_lock);
+	if(!mm)
+	{
+		printk("unmap_kiobuf: no mm!\n");
+#ifdef CONFIG_MOSIX_UDB
+		mosix_debugger("unmap_kiobuf");
+#endif /* CONFIG_MOSIX_UDB */
+		return;
+	}
+	if(atomic_dec_and_test(&mm->mm_kiocount))
+		unstay_mm(mm);
+	mmdrop(mm);
+#endif /* CONFIG_MOSIX */
 }
 
 
@@ -614,9 +663,9 @@
 	struct page *page, **ppage;
 	int doublepage = 0;
 	int repeat = 0;
-	
+
  repeat:
-	
+
 	for (i = 0; i < nr; i++) {
 		iobuf = iovec[i];
 
@@ -628,7 +677,7 @@
 			page = *ppage;
 			if (!page)
 				continue;
-			
+
 			if (TryLockPage(page)) {
 				while (j--) {
 					struct page *tmp = *--ppage;
@@ -642,36 +691,36 @@
 	}
 
 	return 0;
-	
+
  retry:
-	
-	/* 
+
+	/*
 	 * We couldn't lock one of the pages.  Undo the locking so far,
-	 * wait on the page we got to, and try again.  
+	 * wait on the page we got to, and try again.
 	 */
-	
+
 	unlock_kiovec(nr, iovec);
 	if (!wait)
 		return -EAGAIN;
-	
-	/* 
+
+	/*
 	 * Did the release also unlock the page we got stuck on?
 	 */
 	if (!PageLocked(page)) {
-		/* 
+		/*
 		 * If so, we may well have the page mapped twice
 		 * in the IO address range.  Bad news.  Of
 		 * course, it _might_ just be a coincidence,
 		 * but if it happens more than once, chances
-		 * are we have a double-mapped page. 
+		 * are we have a double-mapped page.
 		 */
-		if (++doublepage >= 3) 
+		if (++doublepage >= 3)
 			return -EINVAL;
-		
+
 		/* Try again...  */
 		wait_on_page(page);
 	}
-	
+
 	if (++repeat < 16)
 		goto repeat;
 	return -EAGAIN;
@@ -686,14 +735,14 @@
 	struct kiobuf *iobuf;
 	int i, j;
 	struct page *page, **ppage;
-	
+
 	for (i = 0; i < nr; i++) {
 		iobuf = iovec[i];
 
 		if (!iobuf->locked)
 			continue;
 		iobuf->locked = 0;
-		
+
 		ppage = iobuf->maplist;
 		for (j = 0; j < iobuf->nr_pages; ppage++, j++) {
 			page = *ppage;
@@ -874,7 +923,7 @@
 /*
  * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock
  */
-static inline void break_cow(struct vm_area_struct * vma, struct page * new_page, unsigned long address, 
+static inline void break_cow(struct vm_area_struct * vma, struct page * new_page, unsigned long address,
 		pte_t *page_table)
 {
 	flush_page_to_ram(new_page);
@@ -949,6 +998,11 @@
 	spin_unlock(&mm->page_table_lock);
 	page_cache_release(new_page);
 	page_cache_release(old_page);
+#ifdef CONFIG_MOSIX
+	/* patch conflict mini-fix - <danny@qlusters.com> */
+	old_page->young = 0;
+	old_page->last_young = jiffies;
+#endif /* CONFIG_MOSIX */
 	return 1;	/* Minor fault */
 
 bad_wp_page:
@@ -1014,6 +1068,9 @@
 		vmtruncate_list(mapping->i_mmap, pgoff);
 	if (mapping->i_mmap_shared != NULL)
 		vmtruncate_list(mapping->i_mmap_shared, pgoff);
+#ifdef CONFIG_MOSIX
+	VMODIFIED(inode);
+#endif /* CONFIG_MOSIX */
 
 out_unlock:
 	spin_unlock(&mapping->i_shared_lock);
@@ -1044,11 +1101,11 @@
 	return 0;
 }
 
-/* 
+/*
  * Primitive swap readahead code. We simply read an aligned block of
  * (1 << page_cluster) entries in the swap area. This method is chosen
  * because it doesn't cost us any seek time.  We also make sure to queue
- * the 'original' request together with the readahead ones...  
+ * the 'original' request together with the readahead ones...
  */
 void swapin_readahead(swp_entry_t entry)
 {
@@ -1082,8 +1139,18 @@
 	swp_entry_t entry = pte_to_swp_entry(orig_pte);
 	pte_t pte;
 	int ret = 1;
+#ifdef CONFIG_MOSIX
+	/* patch conflict resolution
+	   no swap readahead conflict here - Qlusters */
+	int dpagein = (current->mosix.dflags & DPAGEIN) ^ DPAGEIN;
+#endif /* CONFIG_MOSIX */
 
 	spin_unlock(&mm->page_table_lock);
+#ifdef CONFIG_MOSIX /* comment as before - Qlusters */
+	spin_lock_irq(&runqueue_lock);
+	current->mosix.dflags |= dpagein;
+	spin_unlock_irq(&runqueue_lock);
+#endif /* CONFIG_MOSIX */
 	page = lookup_swap_cache(entry);
 	if (!page) {
 		swapin_readahead(entry);
@@ -1094,6 +1161,12 @@
 			 * we released the page table lock.
 			 */
 			int retval;
+#ifdef CONFIG_MOSIX /* comment as before - Qlusters */
+			spin_lock_irq(&runqueue_lock);
+			current->mosix.dflags &= ~dpagein;
+			spin_unlock_irq(&runqueue_lock);
+#endif /* CONFIG_MOSIX */
+
 			spin_lock(&mm->page_table_lock);
 			retval = pte_same(*page_table, orig_pte) ? -1 : 1;
 			spin_unlock(&mm->page_table_lock);
@@ -1105,6 +1178,11 @@
 	}
 
 	lock_page(page);
+#ifdef CONFIG_MOSIX
+	spin_lock_irq(&runqueue_lock);
+	current->mosix.dflags &= ~dpagein;
+	spin_unlock_irq(&runqueue_lock);
+#endif /* CONFIG_MOSIX */
 
 	/*
 	 * Back out if somebody else faulted in this pte while we
@@ -1119,7 +1197,7 @@
 	}
 
 	/* The page isn't present yet, go ahead with the fault. */
-		
+
 	swap_free(entry);
 	if (vm_swap_full())
 		remove_exclusive_swap_page(page);
@@ -1143,7 +1221,7 @@
 /*
  * We are called with the MM semaphore and page_table_lock
  * spinlock held to protect against concurrent faults in
- * multithreaded programs. 
+ * multithreaded programs.
  */
 static int do_anonymous_page(struct mm_struct * mm, struct vm_area_struct * vma, pte_t *page_table, int write_access, unsigned long addr)
 {
@@ -1308,6 +1386,14 @@
 		entry = pte_mkdirty(entry);
 	}
 	entry = pte_mkyoung(entry);
+#ifdef CONFIG_MOSIX
+	{
+		struct page *page = pte_page(entry);
+
+		page->young = 0;
+		page->last_young = jiffies;
+	}
+#endif /* CONFIG_MOSIX */
 	establish_pte(vma, address, pte, entry);
 	spin_unlock(&mm->page_table_lock);
 	return 1;
diff -ruN linux-2.4.16/mm/mlock.c linux-2.4.16-mosix/mm/mlock.c
--- linux-2.4.16/mm/mlock.c	Tue Sep 18 01:30:23 2001
+++ linux-2.4.16-mosix/mm/mlock.c	Sun Dec 23 13:56:53 2001
@@ -12,6 +12,10 @@
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 static inline int mlock_fixup_all(struct vm_area_struct * vma, int newflags)
 {
 	spin_lock(&vma->vm_mm->page_table_lock);
@@ -198,6 +202,10 @@
 	unsigned long lock_limit;
 	int error = -ENOMEM;
 
+#ifdef CONFIG_MOSIX
+	if(stay_me_and_my_clones(DSTAY_FOR_MLOCK))
+		return(-ENOMEM);
+#endif /* CONFIG_MOSIX */
 	down_write(&current->mm->mmap_sem);
 	len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
 	start &= PAGE_MASK;
@@ -220,6 +228,10 @@
 	error = do_mlock(start, len, 1);
 out:
 	up_write(&current->mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	if(error)
+		unstay_mm(current->mm);
+#endif /* CONFIG_MOSIX */
 	return error;
 }
 
@@ -227,11 +239,18 @@
 {
 	int ret;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DDEPUTY)
+		panic("sys_munlock -- DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
 	down_write(&current->mm->mmap_sem);
 	len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
 	start &= PAGE_MASK;
 	ret = do_mlock(start, len, 0);
 	up_write(&current->mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	unstay_mm(current->mm);
+#endif /* CONFIG_MOSIX */
 	return ret;
 }
 
@@ -268,6 +287,10 @@
 	unsigned long lock_limit;
 	int ret = -EINVAL;
 
+#ifdef CONFIG_MOSIX
+	if(stay_me_and_my_clones(DSTAY_FOR_MLOCK))
+		return(-ENOMEM);
+#endif /* CONFIG_MOSIX */
 	down_write(&current->mm->mmap_sem);
 	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE)))
 		goto out;
@@ -287,6 +310,10 @@
 	ret = do_mlockall(flags);
 out:
 	up_write(&current->mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	if(ret < 0)
+		unstay_mm(current->mm);
+#endif /* CONFIG_MOSIX */
 	return ret;
 }
 
@@ -294,8 +321,15 @@
 {
 	int ret;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DDEPUTY)
+		panic("sys_munlock -- DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
 	down_write(&current->mm->mmap_sem);
 	ret = do_mlockall(0);
 	up_write(&current->mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	unstay_mm(current->mm);
+#endif /* CONFIG_MOSIX */
 	return ret;
 }
diff -ruN linux-2.4.16/mm/mmap.c linux-2.4.16-mosix/mm/mmap.c
--- linux-2.4.16/mm/mmap.c	Sun Nov  4 20:17:20 2001
+++ linux-2.4.16-mosix/mm/mmap.c	Sun Dec 23 13:56:53 2001
@@ -24,6 +24,16 @@
  */
 #undef DEBUG_MM_RB
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
 /* description of effects of mapping type and prot in current implementation.
  * this is due to the limited x86 page protection hardware.  The expected
  * behavior is in parens:
@@ -66,6 +76,10 @@
         /* Sometimes we want to use more memory than we have. */
 	if (sysctl_overcommit_memory)
 	    return 1;
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY) /* never fail coming back home */
+		return(1);
+#endif /* CONFIG_MOSIX */
 
 	/* The page cache contains buffer pages these days.. */
 	free = atomic_read(&page_cache_size);
@@ -99,12 +113,31 @@
 
 	if (file) {
 		struct inode *inode = file->f_dentry->d_inode;
+#ifdef CONFIG_MOSIX
+		int was_shared = (inode->i_mapping->i_mmap_shared != NULL);
+#endif /* CONFIG_MOSIX */
 		if (vma->vm_flags & VM_DENYWRITE)
 			atomic_inc(&inode->i_writecount);
 		if(vma->vm_next_share)
 			vma->vm_next_share->vm_pprev_share = vma->vm_pprev_share;
 		*vma->vm_pprev_share = vma->vm_next_share;
+#ifdef CONFIG_MOSIX
+		if(was_shared && !inode->i_mapping->i_mmap_shared)
+			mosix_no_longer_monkey(inode);
+		if(current->mosix.dflags & DREMOTE)
+		{
+			spin_lock_irq(&current->sigmask_lock);
+			current->mosix.asig |= (1 << (REMOTE_FILE_RELEASED-1));
+			spin_unlock_irq(&current->sigmask_lock);
+		}
+		else
+			tell_process(current, DREQ_FILEUNMAP);
+#endif /* CONFIG_MOSIX */
 	}
+#ifdef CONFIG_MOSIX
+	if(current->mosix.stay & DSTAY_PER_MM)
+		unstay_mm(current->mm);
+#endif /* CONFIG_MOSIX */
 }
 
 static inline void remove_shared_vm_struct(struct vm_area_struct *vma)
@@ -149,6 +182,10 @@
 	unsigned long newbrk, oldbrk;
 	struct mm_struct *mm = current->mm;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DDEPUTY)
+		panic("sys_brk: DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
 	down_write(&mm->mmap_sem);
 
 	if (brk < mm->end_code)
@@ -162,6 +199,13 @@
 	if (brk <= mm->brk) {
 		if (!do_munmap(mm, newbrk, oldbrk-newbrk))
 			goto set_brk;
+#ifdef CONFIG_MOSIX
+		if(process_told(current, DREQ_FILEUNMAP))
+		{
+			process_ack(current, DREQ_FILEUNMAP);
+			mosix_rebuild_file_list();
+		}
+#endif /* CONFIG_MOSIX */
 		goto out;
 	}
 
@@ -389,6 +433,65 @@
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+#define	MMAP_REMOTELY	((current->mosix.dflags&(DDEPUTY|DINCOMING)) == DDEPUTY)
+#endif /* CONFIG_MOSIX */
+
+#ifdef CONFIG_MOSIX_FS
+unsigned long
+mmap_read_instead(struct file *file, unsigned long addr, unsigned long len,
+	unsigned long prot, unsigned long flags, unsigned long pgoff)
+{
+	extern asmlinkage long sys_mprotect(unsigned long,size_t,unsigned long);
+	extern asmlinkage long sys_munmap(unsigned long, size_t);
+	int mm_downed = (current->mosix.dirty_bits & MMAP_MMDOWNED);
+	loff_t loff = pgoff << PAGE_SHIFT;
+	mm_segment_t oldfs;
+	int error;
+
+	if((flags & MAP_TYPE) != MAP_PRIVATE)
+		return(-EPERM);
+	if(!(file->f_mode & 1))
+		return(-EACCES);
+	len = PAGE_ALIGN(len);
+	addr = do_mmap_pgoff(NULL, addr, len, prot | PROT_WRITE,
+				flags & ~MAP_DENYWRITE, pgoff);
+	if(IS_ERR((const void *)addr))
+		return(addr);
+	oldfs = get_fs();
+	set_fs(USER_DS);
+	if(mm_downed)
+		up_write(&current->mm->mmap_sem);
+#ifdef CONFIG_MOSIX_DFSA
+	error = dfsa_optimized_read(file, loff, addr, len);
+#else
+	error = file->f_op->read(file, (char *)addr, len, &loff);
+#endif /* CONFIG_MOSIX_DFSA */
+	if(error < 0)
+	{
+		set_fs(oldfs);
+		sys_munmap(addr, len);
+		if(mm_downed)
+			down_write(&current->mm->mmap_sem);
+		return(error);
+	}
+	if(error < len)
+		clear_user((void *)addr + error, len - error);
+	set_fs(oldfs);
+	if(!(prot & PROT_WRITE))
+	{
+		prot &= (PROT_READ|PROT_EXEC);
+		if(MMAP_REMOTELY)
+			deputy_mprotect(addr, len, prot);
+		else
+			sys_mprotect(addr, len, prot);
+	}
+	if(mm_downed)
+		down_write(&current->mm->mmap_sem);
+	return(addr);
+}
+#endif /* CONFIG_MOSIX_FS */
+
 unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, unsigned long len,
 	unsigned long prot, unsigned long flags, unsigned long pgoff)
 {
@@ -398,9 +501,26 @@
 	int correct_wcount = 0;
 	int error;
 	rb_node_t ** rb_link, * rb_parent;
+#ifdef CONFIG_MOSIX
+	uint32_t reason_to_come_back = 0;
+	int registration_result = 0;
+#endif /* CONFIG_MOSIX */
 
 	if (file && (!file->f_op || !file->f_op->mmap))
 		return -ENODEV;
+#ifdef CONFIG_MOSIX_DIAG
+	/* a remote mapping is unreadable! */
+	if ((current->mosix.dflags & DREMOTE) && ((file && file->f_op->read) ||
+		((flags & MAP_TYPE) != MAP_PRIVATE)))
+		panic("Remote map");
+#endif /* CONFIG_MOSIX_DIAG */
+#ifdef CONFIG_MOSIX_FS
+	if(file && file_is_mfs(file))
+		return(mmap_read_instead(file, addr, len, prot, flags, pgoff));
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX
+	repeat_after_migrating_back:
+#endif /* CONFIG_MOSIX */
 
 	if ((len = PAGE_ALIGN(len)) == 0)
 		return addr;
@@ -412,6 +532,9 @@
 	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
 		return -EINVAL;
 
+#ifdef CONFIG_MOSIX
+	if (!MMAP_REMOTELY)	/* "mm" NULL on deputy */
+#endif /* CONFIG_MOSIX */
 	/* Too many mappings? */
 	if (mm->map_count > MAX_MAP_COUNT)
 		return -ENOMEM;
@@ -427,9 +550,17 @@
 	 * to. we assume access permissions have been handled by the open
 	 * of the memory object, so we don't do any here.
 	 */
+#ifdef CONFIG_MOSIX
+	vm_flags = calc_vm_flags(prot,flags) | (mm ? mm->def_flags : 0) |
+					VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
+#else
 	vm_flags = calc_vm_flags(prot,flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
+#endif /* CONFIG_MOSIX */
 
 	/* mlock MCL_FUTURE? */
+#ifdef CONFIG_MOSIX
+	if (mm)
+#endif /* CONFIG_MOSIX */
 	if (vm_flags & VM_LOCKED) {
 		unsigned long locked = mm->locked_vm << PAGE_SHIFT;
 		locked += len;
@@ -454,9 +585,31 @@
 			vm_flags |= VM_SHARED | VM_MAYSHARE;
 			if (!(file->f_mode & FMODE_WRITE))
 				vm_flags &= ~(VM_MAYWRITE | VM_SHARED);
+#ifdef CONFIG_MOSIX
+			if(file->f_mode & FMODE_WRITE)
+				reason_to_come_back |= DSTAY_FOR_MONKEY;
+#endif /* CONFIG_MOSIX */
 
 			/* fall through */
 		case MAP_PRIVATE:
+#ifdef CONFIG_MOSIX
+			if(file->f_dentry->d_inode->i_mapping->i_mmap_shared)
+				reason_to_come_back |= DSTAY_FOR_MONKEY;
+			if(S_ISCHR(file->f_dentry->d_inode->i_mode))
+				reason_to_come_back |= DSTAY_FOR_DEV;
+#ifdef CONFIG_MOSIX_DIAG
+			else if(file->f_op && file->f_op->get_unmapped_area)
+			{
+				printk("get_unmapped_area on non-chr file "
+					"(mode 0%o, rdev 0x%x): "
+					"please inform the MOSIX team!\n",
+					file->f_dentry->d_inode->i_mode,
+					file->f_dentry->d_inode->i_rdev);
+				reason_to_come_back |= DSTAY_FOR_DEV;
+			}
+#endif /* CONFIG_MOSIX_DIAG */
+			if (!(current->mosix.dflags & DINCOMING))
+#endif /* CONFIG_MOSIX */
 			if (!(file->f_mode & FMODE_READ))
 				return -EACCES;
 			break;
@@ -476,6 +629,20 @@
 			break;
 		}
 	}
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dirty_bits & MMAP_MAYSHARE)
+		vm_flags |= VM_MAYSHARE;
+	if(MMAP_REMOTELY)
+	{
+		if(reason_to_come_back)
+		{
+			if(!mosix_go_home(1))
+				return(-EAGAIN);
+			goto again_locally;
+		}
+		goto prepare_vma;
+	}
+#endif /* CONFIG_MOSIX */
 
 	/* Clear old maps */
 	error = -ENOMEM;
@@ -484,6 +651,13 @@
 	if (vma && vma->vm_start < addr + len) {
 		if (do_munmap(mm, addr, len))
 			return -ENOMEM;
+#ifdef CONFIG_MOSIX
+		if(process_told(current, DREQ_FILEUNMAP))
+		{
+			process_ack(current, DREQ_FILEUNMAP);
+			mosix_rebuild_file_list();
+		}
+#endif /* CONFIG_MOSIX */
 		goto munmap_back;
 	}
 
@@ -493,6 +667,9 @@
 		return -ENOMEM;
 
 	/* Private writable mapping? Check memory availability.. */
+#ifdef CONFIG_MOSIX
+	if(!(current->mosix.dflags & DINCOMING))
+#endif /* CONFIG_MOSIX */
 	if ((vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE &&
 	    !(flags & MAP_NORESERVE)				 &&
 	    !vm_enough_memory(len >> PAGE_SHIFT))
@@ -507,6 +684,9 @@
 	 * specific mapper. the address has already been validated, but
 	 * not unmapped, but the maps are removed from the list.
 	 */
+#ifdef CONFIG_MOSIX
+	prepare_vma:
+#endif /* CONFIG_MOSIX */
 	vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
 	if (!vma)
 		return -ENOMEM;
@@ -522,6 +702,53 @@
 	vma->vm_private_data = NULL;
 	vma->vm_raend = 0;
 
+#ifdef CONFIG_MOSIX
+	if(file && !(current->mosix.dflags & DREMOTE) && (registration_result =
+		mosix_register_a_file(file, (flags & MAP_DENYWRITE) != 0)) < 0)
+	{
+		error = registration_result;
+		goto free_vma;
+	}
+	/*
+	 * even if we don't end up mapping locally, perform a dummy mapping,
+	 * only to check for fs-specific errors, so we do not fail if and when
+	 * we ever come home:
+	 */
+	if(MMAP_REMOTELY)
+	{
+		vma->vm_file = file;
+		if(file && (error = file->f_op->mmap(file, vma)))
+			goto free_vma;
+		/* did the mapping itself cause us to arrive back home
+		 * (perhaps we were mapping /proc/nnnn/mem)? */
+		if(!MMAP_REMOTELY)
+			goto again_locally_with_vma;
+		addr = mosix_deputy_mmap(file, addr, (flags & MAP_FIXED) != 0,
+			len, vma->vm_flags, pgoff,
+			file ? file->f_dentry->d_inode->i_size : 0,
+			file ? vma->vm_ops->nopage : NULL);
+		if(IS_ERR((const void *)addr))
+		{
+			error = addr;
+			if(error == -EDOITATHOME)
+			/* remote resource shortage: don't despair, come back */
+			if(mosix_go_home(1))
+				goto again_locally_with_vma;
+			goto free_vma;
+		}
+		/* we did not really want that vma... only to check */
+		kmem_cache_free(vm_area_cachep, vma);
+		/* meanwhile someone else could map the same file shared, so: */
+		if(file && file->f_dentry->d_inode->i_mapping->i_mmap_shared)
+		{
+			if(!mosix_go_home(0))
+				return(-EAGAIN);
+			stay_me_and_my_clones(DSTAY_FOR_MONKEY);
+		}
+		return(addr);
+	}
+
+#endif /* CONFIG_MOSIX */
 	if (file) {
 		error = -EINVAL;
 		if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
@@ -560,6 +787,12 @@
 		mm->locked_vm += len >> PAGE_SHIFT;
 		make_pages_present(addr, addr + len);
 	}
+#ifdef CONFIG_MOSIX
+	if(reason_to_come_back)
+		stay_me_and_my_clones(reason_to_come_back);
+	if(file && (vm_flags & VM_SHARED))
+		mosix_bring_monkey_users_back(file->f_dentry->d_inode);
+#endif /* CONFIG_MOSIX */
 	return addr;
 
 unmap_and_free_vma:
@@ -572,7 +805,22 @@
 	zap_page_range(mm, vma->vm_start, vma->vm_end - vma->vm_start);
 free_vma:
 	kmem_cache_free(vm_area_cachep, vma);
+#ifdef CONFIG_MOSIX
+	if(registration_result > 0)
+		mosix_undo_last_file_registration(file, registration_result);
+#endif /* CONFIG_MOSIX */
 	return error;
+#ifdef CONFIG_MOSIX
+again_locally_with_vma:
+	kmem_cache_free(vm_area_cachep, vma);
+	if(registration_result > 0)
+		mosix_undo_last_file_registration(file, registration_result);
+	registration_result = 0;
+again_locally:
+	mm = current->mm;
+	reason_to_come_back = 0;
+	goto repeat_after_migrating_back;
+#endif /* CONFIG_MOSIX */
 }
 
 /* Get an address range which is currently unmapped.
@@ -618,6 +866,10 @@
 
 unsigned long get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
 {
+#ifdef CONFIG_MOSIX
+	if(MMAP_REMOTELY && !(flags & MAP_FIXED))
+		return(PAGE_ALIGN(addr));
+#endif /* CONFIG_MOSIX */
 	if (flags & MAP_FIXED) {
 		if (addr > TASK_SIZE - len)
 			return -EINVAL;
@@ -992,9 +1244,20 @@
 	int ret;
 	struct mm_struct *mm = current->mm;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		return(deputy_munmap(addr, len));
+#endif /* CONFIG_MOSIX */
 	down_write(&mm->mmap_sem);
 	ret = do_munmap(mm, addr, len);
 	up_write(&mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	if(process_told(current, DREQ_FILEUNMAP))
+	{
+		process_ack(current, DREQ_FILEUNMAP);
+		mosix_rebuild_file_list();
+	}
+#endif /* CONFIG_MOSIX */
 	return ret;
 }
 
@@ -1014,6 +1277,10 @@
 	if (!len)
 		return addr;
 
+#ifdef CONFIG_MOSIX
+	if(current->mosix.dflags & DDEPUTY)
+		return(mosix_deputy_brk(addr, len));
+#endif /* CONFIG_MOSIX */
 	/*
 	 * mlock MCL_FUTURE?
 	 */
diff -ruN linux-2.4.16/mm/mprotect.c linux-2.4.16-mosix/mm/mprotect.c
--- linux-2.4.16/mm/mprotect.c	Tue Sep 18 01:30:23 2001
+++ linux-2.4.16-mosix/mm/mprotect.c	Sun Dec 23 13:56:53 2001
@@ -270,6 +270,10 @@
 	struct vm_area_struct * vma, * next, * prev;
 	int error = -EINVAL;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DDEPUTY)
+		panic("sys_mprotect: DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
 	if (start & ~PAGE_MASK)
 		return -EINVAL;
 	len = PAGE_ALIGN(len);
diff -ruN linux-2.4.16/mm/mremap.c linux-2.4.16-mosix/mm/mremap.c
--- linux-2.4.16/mm/mremap.c	Fri Sep 21 06:31:26 2001
+++ linux-2.4.16-mosix/mm/mremap.c	Sun Dec 23 13:56:53 2001
@@ -13,6 +13,10 @@
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 extern int vm_enough_memory(long pages);
 
 static inline pte_t *get_one_pte(struct mm_struct *mm, unsigned long addr)
@@ -218,6 +222,10 @@
 	struct vm_area_struct *vma;
 	unsigned long ret = -EINVAL;
 
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DDEPUTY)
+		panic("sys_mremap: DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
 	if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
 		goto out;
 
@@ -348,5 +356,12 @@
 	down_write(&current->mm->mmap_sem);
 	ret = do_mremap(addr, old_len, new_len, flags, new_addr);
 	up_write(&current->mm->mmap_sem);
+#ifdef CONFIG_MOSIX
+	if(process_told(current, DREQ_FILEUNMAP))
+	{
+		process_ack(current, DREQ_FILEUNMAP);
+		mosix_rebuild_file_list();
+	}
+#endif /* CONFIG_MOSIX */
 	return ret;
 }
diff -ruN linux-2.4.16/mm/oom_kill.c linux-2.4.16-mosix/mm/oom_kill.c
--- linux-2.4.16/mm/oom_kill.c	Sun Nov  4 03:05:25 2001
+++ linux-2.4.16-mosix/mm/oom_kill.c	Sun Dec 23 13:56:53 2001
@@ -89,6 +89,11 @@
 	 * Superuser processes are usually more important, so we make it
 	 * less likely that we kill those.
 	 */
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DREMOTE)
+		points *= 2;
+	else
+#endif /* CONFIG_MOSIX */
 	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) ||
 				p->uid == 0 || p->euid == 0)
 		points /= 4;
@@ -99,6 +104,9 @@
 	 * tend to only have this flag set on applications they think
 	 * of as important.
 	 */
+#ifdef CONFIG_MOSIX
+	if(!(p->mosix.dflags & DREMOTE))
+#endif /* CONFIG_MOSIX */
 	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO))
 		points /= 4;
 #ifdef DEBUG
@@ -153,6 +161,11 @@
 	p->flags |= PF_MEMALLOC | PF_MEMDIE;
 
 	/* This process has hardware access, be more careful. */
+#ifdef CONFIG_MOSIX
+	if(p->mosix.dflags & DREMOTE)
+		send_sig(SIGTERM, p, 1);
+	else
+#endif /* CONFIG_MOSIX */
 	if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO)) {
 		force_sig(SIGTERM, p);
 	} else {
diff -ruN linux-2.4.16/mm/page_alloc.c linux-2.4.16-mosix/mm/page_alloc.c
--- linux-2.4.16/mm/page_alloc.c	Tue Nov 20 02:35:40 2001
+++ linux-2.4.16-mosix/mm/page_alloc.c	Sun Dec 23 13:56:53 2001
@@ -370,7 +370,20 @@
 	if (!(gfp_mask & __GFP_WAIT))
 		return NULL;
 
+#ifdef CONFIG_MOSIX
+	{
+		__typeof__(jiffies)before = jiffies;
+#endif /* CONFIG_MOSIX */
 	page = balance_classzone(classzone, gfp_mask, order, &freed);
+#ifdef CONFIG_MOSIX
+		if((before = jiffies - before))
+#if 1000000 % HZ == 0
+			current->mosix.pagetime += before * (1000000 / HZ);
+#else
+			current->mosix.pagetime += before * 1000000 / HZ;
+#endif
+	}
+#endif /* CONFIG_MOSIX */
 	if (page)
 		return page;
 
diff -ruN linux-2.4.16/mm/vmscan.c linux-2.4.16-mosix/mm/vmscan.c
--- linux-2.4.16/mm/vmscan.c	Sun Nov 18 05:18:17 2001
+++ linux-2.4.16-mosix/mm/vmscan.c	Sun Dec 23 13:56:53 2001
@@ -47,6 +47,16 @@
 	pte_t pte;
 	swp_entry_t entry;
 
+#ifdef CONFIG_MOSIX
+	/* patch conflict resolution
+	   no swap_out conflict here - Qlusters */
+	if(page->young)
+	{
+		page->young = 0;
+		return(0);
+	}
+#endif /* CONFIG_MOSIX */
+
 	/* Don't look at this pte if it's been accessed recently. */
 	if ((vma->vm_flags & VM_LOCKED) || ptep_test_and_clear_young(page_table)) {
 		mark_page_accessed(page);
@@ -165,9 +175,9 @@
 		pmd_clear(dir);
 		return count;
 	}
-	
+
 	pte = pte_offset(dir, address);
-	
+
 	pmd_end = (address + PMD_SIZE) & PMD_MASK;
 	if (end > pmd_end)
 		end = pmd_end;
@@ -207,10 +217,10 @@
 
 	pmd = pmd_offset(dir, address);
 
-	pgd_end = (address + PGDIR_SIZE) & PGDIR_MASK;	
+	pgd_end = (address + PGDIR_SIZE) & PGDIR_MASK;
 	if (pgd_end && (end > pgd_end))
 		end = pgd_end;
-	
+
 	do {
 		count = swap_out_pmd(mm, vma, pmd, address, end, count, classzone);
 		if (!count)
@@ -258,7 +268,7 @@
 	struct vm_area_struct* vma;
 
 	/*
-	 * Find the proper vm-area after freezing the vma chain 
+	 * Find the proper vm-area after freezing the vma chain
 	 * and ptes.
 	 */
 	spin_lock(&mm->page_table_lock);
@@ -688,7 +698,7 @@
 
 /*
  * The background pageout daemon, started as a kernel thread
- * from the init process. 
+ * from the init process.
  *
  * This basically trickles out pages so that we have _some_
  * free memory available even if there is no other activity
@@ -707,7 +717,7 @@
 	daemonize();
 	strcpy(tsk->comm, "kswapd");
 	sigfillset(&tsk->blocked);
-	
+
 	/*
 	 * Tell the memory management that we're a "memory allocator",
 	 * and that if we need more memory we should get access to it
@@ -741,6 +751,9 @@
 		 * the processes needing more memory will wake us
 		 * up on a more timely basis.
 		 */
+#ifdef CONFIG_MOSIX
+		refill_inactive((nr_active_pages + 63) >> 6);
+#endif /* CONFIG_MOSIX */
 		kswapd_balance();
 		run_task_queue(&tq_disk);
 	}
diff -ruN linux-2.4.16/mos/Makefile linux-2.4.16-mosix/mos/Makefile
--- linux-2.4.16/mos/Makefile	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/Makefile	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+#
+# Permission to use this software is hereby granted under the terms of the
+# GNU General Public License, as published by the Free Software Foundation.
+#
+# THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+# WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+# FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+#
+#
+# Makefile for MOS permanent interface.
+#
+# Note! Dependencies are done automagically by 'make dep', which also
+# removes any old dependencies. DON'T put your own dependencies here
+# unless it's something special (ie not a .c file).
+#
+
+O_TARGET := mos.o
+obj-y    := alternate.o auto_syscalls.o balance.o comm.o config.o decay.o \
+	    deputy.o div.o export.o freemem.o init.o info.o kernel.o load.o \
+	    log.o mig.o mosadmin.o mosproc.o prequest.o remote.o rinode.o \
+	    service.o syscalls.o ucache.o
+
+obj-$(CONFIG_MOSIX_DFSA) += badops.o dfsa.o
+
+export-objs = export.o
+
+include $(TOPDIR)/Rules.make
+
+auto_syscalls.c: mkdefcalls $(TOPDIR)/arch/i386/kernel/entry.S syscalls.c
+	./mkdefcalls
+
+mkdefcalls: mkdefcalls.c $(TOPDIR)/include/linux/config.h $(TOPDIR)/include/linux/types.h $(TOPDIR)/include/linux/sched.h $(TOPDIR)/include/linux/signal.h $(TOPDIR)/include/linux/sys.h $(TOPDIR)/include/linux/kernel.h
+	$(HOSTCC) $(HOSTCFLAGS) -I$(HPATH) -o mkdefcalls -DENTRY_IN=\"$(TOPDIR)/arch/i386/kernel/entry.S\" -DSYSCALLS_IN=\"$(TOPDIR)/mos/syscalls.c\" -DSYSCALLS_OUT=\"$(TOPDIR)/mos/auto_syscalls.c\" mkdefcalls.c
+
+alternate.c: copy_unconf $(TOPDIR)/fs/binfmt_aout.c $(TOPDIR)/.config
+	/bin/sh ./copy_unconf "$(CONFIG_BINFMT_AOUT)" $(TOPDIR)/fs/binfmt_aout.c > alternate.c
diff -ruN linux-2.4.16/mos/badops.c linux-2.4.16-mosix/mos/badops.c
--- linux-2.4.16/mos/badops.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/badops.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#include <linux/mosctl.h>
+#include <linux/mosix.h>
+#include <net/tcp.h>
+#include <mos/protocol.h>
+#include <linux/mm.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/stddef.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/version.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+#include <linux/fs.h>
+
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+
+static int
+bad_result(void)
+{
+	printk("%s: Tried using a DFSA 'failed_to_reopen' file -- killed!\n",
+		desc_mostask(NULL));
+	force_sig(SIGKILL, current);
+	return(-EBADF);
+}
+
+loff_t
+all_bad_llseek(struct file *f, loff_t x, int y)
+{
+	return(bad_result());
+}
+
+ssize_t
+all_bad_read(struct file *f, char *x, size_t y, loff_t *z)
+{
+	return(bad_result());
+}
+
+ssize_t
+all_bad_write(struct file *f, const char *x, size_t y, loff_t *z)
+{
+	return(bad_result());
+}
+
+unsigned int
+all_bad_poll(struct file *f, struct poll_table_struct *x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_ioctl(struct inode *i, struct file *x, unsigned int y, unsigned long z)
+{
+	return(bad_result());
+}
+
+int
+all_bad_mmap(struct file *f, struct vm_area_struct *x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_open(struct inode *i, struct file *x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_fsync(struct file *f, struct dentry *d, int datasync)
+{
+	return(bad_result());
+}
+
+int
+all_bad_fasync(int x, struct file *f, int y)
+{
+	return(bad_result());
+}
+
+int
+all_bad_lock(struct file *f, int x, struct file_lock *y)
+{
+	return(bad_result());
+}
+
+struct file_operations all_bad_file_operations =
+{
+	llseek: all_bad_llseek,
+	read: all_bad_read,
+	write: all_bad_write,
+	poll: all_bad_poll,
+	ioctl: all_bad_ioctl,
+	mmap: all_bad_mmap,
+	open: all_bad_open,
+	fsync: all_bad_fsync,
+	fasync: all_bad_fasync,
+	lock: all_bad_lock
+};
+
+int
+all_bad_create(struct inode *i, struct dentry *x, int y)
+{
+	return(bad_result());
+}
+
+struct dentry *
+all_bad_lookup(struct inode *i, struct dentry *x)
+{
+	return((struct dentry *)bad_result());
+}
+
+int
+all_bad_link(struct dentry *d, struct inode *i, struct dentry *e)
+{
+	return(bad_result());
+}
+
+int
+all_bad_unlink(struct inode *i, struct dentry *d)
+{
+	return(bad_result());
+}
+
+int
+all_bad_symlink(struct inode *i, struct dentry *d, const char *a)
+{
+	return(bad_result());
+}
+
+int
+all_bad_follow_link(struct dentry *dp, struct nameidata *nd)
+{
+	return(bad_result());
+}
+
+int
+all_bad_get_block(struct inode *f, struct buffer_head *x, int y)
+{
+	return(bad_result());
+}
+
+int
+all_bad_readpage(struct file *f, struct page *x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_writepage(struct file *f, struct page *x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_bmap(struct inode *i, int x)
+{
+	return(bad_result());
+}
+
+void
+all_bad_truncate(struct inode *i)
+{
+	bad_result();
+}
+
+int
+all_bad_permission(struct inode *i, int x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_smap(struct inode *i, int x)
+{
+	return(bad_result());
+}
+
+int
+all_bad_revalidate(struct dentry *d)
+{
+	return(bad_result());
+}
+
+int
+all_bad_setattr(struct dentry *d, struct iattr *attr)
+{
+	return(bad_result());
+}
+
+struct inode_operations all_bad_inode_operations = {
+        create: all_bad_create,
+        lookup: all_bad_lookup,
+        link: all_bad_link,
+        unlink: all_bad_unlink,
+        symlink: all_bad_symlink,
+        follow_link: all_bad_follow_link,
+        truncate: all_bad_truncate,
+        permission: all_bad_permission,
+        revalidate: all_bad_revalidate,
+	setattr: all_bad_setattr,
+};
+
+#endif /* CONFIG_MOSIX_DFSA */
diff -ruN linux-2.4.16/mos/balance.c linux-2.4.16-mosix/mos/balance.c
--- linux-2.4.16/mos/balance.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/balance.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1240 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Amnon Barak.
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/mosctl.h>
+#include <net/sock.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <mos/protocol.h>
+#include <linux/mosix.h>
+#include <asm/uaccess.h>
+#include <asm/i387.h>
+#include <linux/smp_lock.h>
+#include <linux/swap.h>
+#include <linux/stddef.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+#include <mos/version.h>
+#include <mos/balance.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
+struct opcost remote_here_adjusted[MAX_MOSIX_TOPOLOGY];
+#ifndef CONFIG_MOSIX_TOPOLOGY
+struct opcost remote_here;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+
+static int load_balancing_counter;
+static int memory_balancing_counter;
+
+#ifdef CONFIG_MOSIX_DEBUG
+char *
+fformat(char *buf, double v)
+{
+	char *p = buf;
+	int started = 0;
+	double tens;
+	int exp = 0;
+	int n;
+
+	if(v == 0.0)
+		return("0");
+	if(v < 0.0)
+	{
+		v = -v;
+		*p++ = '-';
+	}
+	if(v > 1e20)
+	while(v >= 10.0)
+	{
+		exp++;
+		v /= 10;
+	}
+	else if(v < 1e-20)
+	while(v < 1.0)
+	{
+		exp--;
+		v *= 10;
+	}
+	for(tens = 1e20 ; tens >= 1.0 ; tens /= 10.0)
+	if(started || v > tens)
+	{
+		n = v / tens;
+		v -= tens * n;
+		*p++ = '0' + n;
+		started++;
+	}
+	if(started < 8)
+	{
+		*p++ = '.';
+		for(tens = 0.1 ; started++ < 8 ; tens /= 10.0)
+		{
+			n = v / tens;
+			v -= tens *n;
+			*p++ = '0' + n;
+		}
+		while(*(p-1) == '0')
+			p--;
+		if(*(p-1) == '.')
+			p--;
+	}
+	if(exp)
+	{
+		*p++ = 'E';
+		if(exp < 0)
+		{
+			exp = -exp;
+			*p++ = '-';
+		}
+		if(exp >= 100)
+		{
+			*p++ = exp / 100 + '0';
+			exp %= 100;
+		}
+		if(exp >= 10)
+			*p++ = exp / 10 + '0';
+		*p++ = exp % 10 + '0';
+	}
+	*p = '\0';
+	return(buf);
+}
+#endif /* CONFIG_MOSIX_DEBUG */
+
+void
+age_balancing(void)
+{
+	spin_lock_irq(&whereto_lock);
+	if(load_balancing_counter-- == 0 && chosen_for_balance)
+	{
+		free_task_struct(chosen_for_balance);
+		chosen_for_balance = NULL;
+	}
+	if(memory_balancing_counter-- == 0 && chosen_for_mdp)
+	{
+		free_task_struct(chosen_for_mdp);
+		chosen_for_mdp = NULL;
+	}
+	spin_unlock_irq(&whereto_lock);
+}
+
+void
+mosix_clear_statistics(void)
+{
+	register struct mosix_task *m = &current->mosix;
+
+	m->ndemandpages = 0;
+	m->nsyscalls = 0;
+	m->ncopyouts = 0;
+	m->copyoutbytes = 0;
+	m->ncopyins = 0;
+	m->copyinbytes = 0;
+	m->iocounter = 0;
+	m->cutime = 0;
+	m->dctime = 0;
+	m->pagetime = 0;
+	read_lock(&tasklist_lock);
+	m->decsecs = 0;
+	read_unlock(&tasklist_lock);
+	spin_lock_irq(&whereto_lock);
+	m->last_consider = 0;
+	m->last_mconsider = time_now();
+	spin_unlock_irq(&whereto_lock);
+	if(m->dflags & (DREMOTE|DDEPUTY))
+		m->uttime = 0;
+	else
+		m->uttime = -current->times.tms_utime;
+#ifdef CONFIG_MOSIX_DFSA
+	m->copy_ins = 0;
+	m->bytes_in = 0;
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	if(m->mfs_stats)
+		m->mfs_stats->nnodes = 0;
+#endif /* CONFIG_MOSIX_FS */
+}
+
+#ifdef CONFIG_MOSIX_TOPOLOGY
+#define sel_routine(routine, struct_name)				\
+static int								\
+routine(struct struct_name *costs, int with)				\
+{									\
+	register int i;							\
+									\
+	for(i = 0 ; i < MAX_MOSIX_TOPOLOGY ; i++ , costs++)		\
+	{								\
+		if(!costs->first)					\
+			return(i);					\
+		if(!costs->last)					\
+		{							\
+			if(with != costs->first)			\
+				return(i);				\
+		}							\
+		else if((costs->last >= costs->first) ?			\
+			(with >= costs->first && with <= costs->last) :	\
+			(with > costs->first || with < costs->last))	\
+				return(i);				\
+	}								\
+	return(0);							\
+}
+
+sel_routine(select_cost, opcost)
+#ifdef CONFIG_MOSIX_FS
+sel_routine(select_mfscost, mfs_cost)
+#endif /* CONFIG_MOSIX_FS */
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+
+int64_t
+#ifdef CONFIG_MOSIX_TOPOLOGY
+io_cost(struct mosix_task *m, struct opcost *costs, int with)
+#else
+io_cost(struct mosix_task *m, struct opcost *costs)
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+{
+	int64_t b, e;
+
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	costs += select_cost(costs, with);
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	b = m->copyoutbytes * costs->outkb + m->copyinbytes * costs->inkb;
+	e = m->ndemandpages * costs->page + m->nsyscalls * costs->syscall;
+	if(costs->out || costs->in)	/* they are usually 0, so save time */
+#if COPY_COUNTER_MULTIPLIER != EVENT_COUNTER_VALUE
+#warning no reason they should not be the same, but inefficient code provided:
+		return((b >> 10) + (e >> EVENT_COUNTER_SHIFT) +
+			(m->ncopyouts * costs->out + m->ncopyins * costs->in) /
+						COPY_COUNTER_MULTIPLIER);
+#else
+		e += m->ncopyouts * costs->out + m->ncopyins * costs->in;
+#endif
+#if EVENT_COUNTER_SHIFT == 10
+	/* we are lucky that the cost of a system call is the same
+	 * order of magnitude as copying 1KB to/from user-space
+	 */
+	return((b + e) >> 10);
+#else
+	return((b >> 10) + (e >> EVENT_COUNTER_SHIFT));
+#endif
+}
+
+int64_t
+remote_costs_in_ms(struct mosix_task *m)
+{
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	return(io_cost(m, m->depcost, PE) * STD_SPD / m->depspeed +
+				io_cost(m, remote_here_adjusted, m->deppe));
+#else
+	return(io_cost(m, m->depcost) * STD_SPD / m->depspeed +
+				io_cost(m, remote_here_adjusted));
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+}
+
+#ifdef CONFIG_MOSIX_FS
+
+enum mfs_where {MFS_CLIENT, MFS_SERVER};
+
+int64_t
+#ifdef CONFIG_MOSIX_TOPOLOGY
+mfs_cos(int64_t conns, int64_t inbytes, int64_t outbytes,
+			struct mfs_cost *costs, enum mfs_where type, int with)
+#else
+mfs_cos(int64_t conns, int64_t inbytes, int64_t outbytes, enum mfs_where type)
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+{
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	if(with == 0)
+		with = PE;
+	costs += select_mfscost(costs, with);
+#else
+	struct mfs_cost *costs = mfs_cost;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	if(type == MFS_CLIENT)
+		return(conns * costs->MFS_CONN_C + ((inbytes*costs->MFS_INKB_C +
+					outbytes * costs->MFS_OUTKB_C) >> 10));
+	else
+		return(conns * costs->MFS_CONN_S + ((inbytes*costs->MFS_INKB_S +
+					outbytes * costs->MFS_OUTKB_S) >> 10));
+}
+#endif /* CONFIG_MOSIX_FS */
+
+void
+add_statistics_to_ancesstor(struct task_struct *p, struct task_struct *pp)
+{
+	struct mosix_task *m = &p->mosix;
+	struct mosix_task *mm = &pp->mosix;
+	int remote = (m->dflags & DREMOTE);
+	int64_t ut, age;
+	unsigned long newcounter;
+
+	lock_mosix();
+	age = ticks_to_ms(p->times.tms_utime + m->uttime) + m->cutime;
+	ut = age - m->dctime;
+	if(remote)
+		age += remote_costs_in_ms(m);
+	if(age > 4 * MILLION)
+	/* over 4 seconds, son is too old and not dependent any more */
+	{
+#ifdef	CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_ANCESSTOR)
+		{
+			printk("addstatistics: %s to ", desc_mostask(m));
+			printk("%s: independent, age=%d:%06d\n",
+				desc_mostask(mm), (int)(age/MILLION),
+				(int)(age-age/MILLION*MILLION));
+		}
+#endif
+		unlock_mosix();
+		return;
+	}
+	mm->cutime += ut;
+	mm->nsyscalls += m->nsyscalls;
+	mm->ncopyouts += m->ncopyouts;
+	mm->copyoutbytes += m->copyoutbytes;
+	mm->ncopyins += m->ncopyins;
+	mm->copyinbytes += m->copyinbytes;
+	mm->ndemandpages += m->ndemandpages;
+	if(remote)
+	{
+		newcounter = mm->iocounter + m->ndemandpages + m->nsyscalls +
+				m->ncopyouts + m->copyoutbytes +
+				m->ncopyins + m->copyinbytes;
+		if((newcounter ^ mm->iocounter) & 0xfff00000)
+		{
+			mosix_add_to_whereto(pp, IOBALANCE);
+			mm->iocounter = 0;
+		}
+		else
+			mm->iocounter = newcounter;
+	}
+	mm->pagetime += m->pagetime;
+#ifdef CONFIG_MOSIX_FS
+	if(mfs_add_stats(m->mfs_stats, mm->mfs_stats, mm))
+		mosix_add_to_whereto(pp, MFSBALANCE);
+#endif /* CONFIG_MOSIX_FS */
+	unlock_mosix();
+}
+
+/*
+ * produce statistics at the end of local system-calls:
+ */
+void
+mosix_local_syscall(void)
+{
+	register struct mosix_task *m = &current->mosix;
+
+#ifdef CONFIG_MOSIX_DFSA
+	if(m->dflags & (DDEPUTY|DREMOTE|DSTATSDOWN))
+	{
+		m->copy_ins = m->bytes_in = 0;
+		m->dflags &= ~DSTATSDOWN;
+		return;
+	}
+	if(m->copy_ins)
+	{
+		m->ncopyins += m->copy_ins * COPY_COUNTER_MULTIPLIER;
+		m->copyinbytes += m->bytes_in;
+		m->copy_ins = m->bytes_in = 0;
+	}
+#else
+	if(!(m->dflags & (DDEPUTY|DREMOTE)))
+#endif /* CONFIG_MOSIX_DFSA */
+		m->nsyscalls += EVENT_COUNTER_VALUE;
+}
+
+/*
+ * altruistic load:
+ * this function takes into account the cost of a load not only on a given
+ * process, but also on the other processes in its environment.
+ * When there are enough processors to take the load, a process gets served as
+ * soon as practicable, as fast as the processor can run, eg. by the threshold.
+ * Otherwise, there is a cost which is:
+ * given L=load, N=ncpus:
+ * For the process itself: the cost is L.
+ * For the other (N*L-1) processes:
+ *	Without the extra process, they would each need (N*L-1)/N units of time
+ *		to complete.
+ *	With the extra process, they will need L units of time to complete.
+ * the loss is therefore (N*L-1)*(L-(N*L-1)/N) = (N*L-1)*(L-L+1/N) = L - 1/N.
+ */
+inline int
+altload(int load, int speed, int ncpus)
+{
+	int threshold = MF * STD_SPD / speed;
+
+	if(load <= threshold)
+		return(threshold);
+	if(load <= threshold + threshold/ncpus)
+		return(threshold + ncpus * load * (load-threshold) / threshold);
+	return(2 * load - threshold / ncpus);
+}
+
+int
+send_local_aload(int type)
+{
+	struct aload_h a;
+
+	read_lock_bh(&loadinfo_lock);
+	a.aload = altload(export_load, loadinfo[0].speed, loadinfo[0].ncpus);
+	read_unlock_bh(&loadinfo_lock);
+	a.freepages = export_mem();
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	memcpy(a.mfscosts, mfs_cost, sizeof(mfs_cost));
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	return(comm_send(type, &a, sizeof(a), NULL, 0, 0));
+}
+
+void
+choose(void)
+{
+        int64_t priority, lastpri = 0;
+	int pri, bestpri;
+        register int load, bestload;
+	struct task_struct *p, *sel = NULL;
+	register struct mosix_task *m;
+        int mintime, very_mintime;
+	int minload;
+
+	mintime = MILLION * acpuse / (smp_num_cpus * MF);
+	very_mintime = mintime / 3;
+	minload = 4 * acpuse / smp_num_cpus;	/* normally 4*MF */
+        bestpri = mintime;
+        bestload = -1;
+	read_lock(&tasklist_lock);
+	if(!chosen_for_balance)
+	for_each_task(p)
+        if(!((m = &p->mosix)->dflags & (DDEPUTY|DFINISHED|DPASSING)) &&
+		!m->stay && !m->whereto && p != chosen_for_mdp &&
+		(!mosadmin_mode_lstay || (m->dflags & DREMOTE)))
+        {
+#ifdef CONFIG_MOSIX_DIAG
+		if(LOGICAL_STATE(p) == TASK_ZOMBIE)
+		{
+			mosix_panic("ZOMBIE without DFINISHED");
+			continue;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		priority = ticks_to_ms(p->times.tms_utime + m->uttime) +
+								m->cutime;
+		/* (note: m->dctime deliberately not taken into account:
+		 * otherwise if statistics decay too quickly, there may never
+		 * be a process chosen for migration) */
+		if(m->dflags & DREMOTE)
+#ifdef CONFIG_MOSIX_TOPOLOGY
+			priority += io_cost(m, remote_here_adjusted, m->deppe);
+#else
+			priority += io_cost(m, remote_here_adjusted);
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+		priority -= m->last_consider;
+		if(priority < 0)
+		/* it "should not" happen, but some operating systems (BSDI)
+		   can have user-time go back due to rounding... */
+			continue;
+		pri = (priority > 4*MILLION) ? 4*MILLION : priority; /*4 secs*/
+                if(pri < bestpri)
+                {
+                        if(bestpri == mintime &&
+				/* (thrashing, or (m->load <= minload)) */
+				m->load > minload && pri >= very_mintime)
+                                pri = mintime;
+                        else
+                                continue;
+                }
+                load = m->load;
+                if(pri > bestpri || load > bestload)
+                {
+                        bestload = load;
+			if(sel)
+				free_task_struct(sel);
+			get_task_struct(p);
+                        sel = p;
+                        bestpri = pri;
+			lastpri = priority;
+                }
+        }
+	read_unlock(&tasklist_lock);
+        if(!sel)
+		return;
+	spin_lock_irq(&whereto_lock);
+	if(chosen_for_balance)
+	{
+		free_task_struct(sel);
+		spin_unlock_irq(&whereto_lock);
+		return;
+	}
+        sel->mosix.last_consider += lastpri;
+	chosen_for_balance = sel;
+	mosix_do_add_to_whereto(sel, BALANCE);
+	load_balancing_counter = BALANCING_TIMEOUT;
+	if(sel->mosix.whereto != BALANCE)
+	{
+		free_task_struct(chosen_for_balance);
+		chosen_for_balance = NULL;
+	}
+	spin_unlock_irq(&whereto_lock);
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_LOAD|DSDEB_CONSIDER))
+		printk("selected %s for load-balancing, pri=%d, load=%d, priority=%d\n",
+			desc_mostask(&sel->mosix), (int)bestpri, bestload,
+			(int)lastpri);
+#endif /* CONFIG_MOSIX_DEBUG */
+}
+
+void
+load_balance(void)
+{
+	register int load;
+	register struct loadinfo *l;
+	int doit = 0;
+
+	if(mosadmin_mode_stay)
+		return;
+
+	read_lock_bh(&loadinfo_lock);
+	load = altload(loadinfo[0].load, loadinfo[0].speed, loadinfo[0].ncpus);
+	for(l = &loadinfo[1]; l < &loadinfo[INFO_WIN] ; l++)
+	if(l->pe && l->mem > 0 && altload(l->load, l->speed, l->ncpus) <= load)
+	{
+		doit = 1;
+		break;
+	}
+	read_unlock_bh(&loadinfo_lock);
+	if(doit)
+		choose();
+}
+
+void
+mchoose(int need)
+{
+	int quality, bestquality = 0;
+	int df, diff = MIN_MCHOOSE_AGAIN;
+	now_t dff;
+	struct task_struct *p, *sel = NULL;
+	register struct mosix_task *m;
+
+	read_lock(&tasklist_lock);
+	if(!chosen_for_mdp)
+	for_each_task(p)
+        if(!((m = &p->mosix)->dflags & (DDEPUTY|DFINISHED|DPASSING)) &&
+		!m->stay && !m->whereto && p != chosen_for_balance &&
+		(!mosadmin_mode_lstay || (m->dflags & DREMOTE)))
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		if(LOGICAL_STATE(p) == TASK_ZOMBIE)
+		{
+			mosix_panic("ZOMBIE without DFINISHED");
+			continue;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		dff = time_since(m->last_mconsider);
+		if(dff > MAX_MCHOOSE_AGAIN)
+			df = MAX_MCHOOSE_AGAIN;
+		else
+			df = dff;
+		if(df < diff)
+			continue;
+		quality = memory_relief_quality(p, need);
+		if(quality > bestquality || (quality > 0 && df > diff))
+                {
+			if(sel)
+				free_task_struct(sel);
+			get_task_struct(p);
+                        sel = p;
+                        bestquality = quality;
+			diff = df;
+                }
+        }
+	read_unlock(&tasklist_lock);
+        if(!sel)
+		return;
+	spin_lock_irq(&whereto_lock);
+	if(chosen_for_mdp)
+	{
+		free_task_struct(sel);
+		spin_unlock_irq(&whereto_lock);
+		return;
+	}
+	sel->mosix.page_allocs = 0;
+	sel->mosix.last_mconsider = time_now();
+	chosen_for_mdp = sel;
+	mosix_do_add_to_whereto(sel, MEMBALANCE);
+	memory_balancing_counter = BALANCING_TIMEOUT;
+	if(sel->mosix.whereto != MEMBALANCE)
+	{
+		free_task_struct(chosen_for_mdp);
+		chosen_for_mdp = NULL;
+	}
+	spin_unlock_irq(&whereto_lock);
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+		printk("selected %s for memory-balancing, quality=%d\n",
+			desc_mostask(&sel->mosix), bestquality);
+#endif
+}
+
+void
+memory_balance(void)
+{
+	register struct loadinfo *l;
+	int need;
+	int doit = 0;
+
+	if(mosadmin_mode_stay || mosadmin_mode_quiet ||
+		(need = memory_badly_required()) <= 0)
+		return;
+	read_lock_bh(&loadinfo_lock);
+	for(l = &loadinfo[1]; l < &loadinfo[INFO_WIN] ; l++)
+	if(l->pe && l->mem > MIN_EXPECTED_PROC_SIZE)
+	{
+		doit = 1;
+		break;
+	}
+	read_unlock_bh(&loadinfo_lock);
+	if(doit)
+		mchoose(need);
+}
+
+void
+changed_my_mind_and_staying(void)
+{
+	current->mosix.pages_i_bring = 0;
+}
+
+void
+ask_deputy_to_goto(int where)
+{
+	void *head;
+	int hlen;
+
+	if(comm_send(DEP_CONSIDER|REPLY, &where, sizeof(int), NULL, 0, 0) ||
+		(where && remote_wait(DEP_CONSIDER, &head, &hlen)))
+		remote_disappear();
+	if(where)
+		comm_free(head);
+}
+
+struct sonstats
+{
+	int64_t utime;		/* ms */
+	int64_t ndemandpages;
+	int64_t nsyscalls;
+	int64_t ncopyouts;
+	int64_t copyoutbytes;
+	int64_t ncopyins;
+	int64_t copyinbytes;
+	int64_t pagetime;	/* ms */
+#ifdef CONFIG_MOSIX_FS
+	struct mfs_stats mfs;
+#endif /* CONFIG_MOSIX_FS */
+};
+
+void
+consider(int reason, struct sonstats *sons)
+{
+#define	INFLOAD 0x8000000
+#define	MAX_CONSIDERED	(INFO_WIN+1+MAX_MFS_STATNODES)
+#if MAX_CONSIDERED > 127
+#error char is not enough for map
+#endif /*MAX_CONSIDERED*/
+	struct task_struct *p = current;
+	register struct mosix_task *m = &p->mosix;
+	int mach[MAX_CONSIDERED], aload[MAX_CONSIDERED];
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	struct costinfo
+	{
+		struct opcost opcost[MAX_MOSIX_TOPOLOGY];
+#ifdef CONFIG_MOSIX_FS
+		struct mfs_cost mfscost[MAX_MOSIX_TOPOLOGY];
+#endif /* CONFIG_MOSIX_FS */
+	} *costinfo = NULL;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+#ifdef CONFIG_MOSIX_FS
+	struct mfs_stats *mfs_tot;
+	char map[MAX_MFS_STATNODES];
+	int orig_n;
+#endif /* CONFIG_MOSIX_FS */
+	double costs[MAX_CONSIDERED];
+	register int i, n = 0, j, k;
+	int depmach = -1;
+	double tim, dtim, rtim;
+	int remote = (m->dflags & DREMOTE) ? 1 : 0;
+	int64_t ms;
+	struct aload_h a;
+#ifdef CONFIG_MOSIX_DEBUG
+	char fbuf1[40], fbuf2[40];
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if((m->stay & DSTAY) || !PE || mosadmin_mode_quiet)
+		goto out;
+	if(reason && (m->stay || mosadmin_mode_stay ||
+		(mosadmin_mode_lstay && !(m->dflags & DREMOTE))))
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & (DSDEB_CONSIDER|DSDEB_MIG))
+			printk("%s-not considering, reason=%d\n",
+				desc_mostask(NULL), reason);
+#endif
+		goto out;
+	}
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_CONSIDER|DSDEB_MIG))
+		printk("%s-considering, reason=%d:\n", desc_mostask(m), reason);
+#endif
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	if(!(costinfo = (struct costinfo *)
+		kmalloc(sizeof(struct costinfo) * MAX_CONSIDERED, GFP_KERNEL)))
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		printk("%s-no memory for considering\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		goto out;
+	}
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	m->migpages = count_migrating_pages();
+#ifdef CONFIG_MOSIX_FS
+	if(sons && sons->mfs.nnodes)
+	{
+		mfs_tot = &sons->mfs;
+		mfs_add_stats(m->mfs_stats, mfs_tot, NULL);
+	}
+	else
+		mfs_tot = m->mfs_stats;
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+		printk("Aloads: ");
+#endif /* CONFIG_MOSIX_DEBUG */
+	if(remote)
+	{
+		if(remote_request(REM_GETALOAD, NULL, 0, NULL, 0, 0,
+			(void **)&a, -sizeof(a)))
+		{
+			printk("%s: failed to send getaload - exiting\n",
+				desc_mostask(m));
+			remote_disappear();
+		}
+		depmach = m->deppe;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("HOME=%d, ", a.aload);
+#endif /* CONFIG_MOSIX_DEBUG */
+		aload[0] = a.aload;
+		if(reason != IOBALANCE && a.freepages < m->migpages)
+			aload[0] += INFLOAD;
+		/* deliberately leave costinfo[0].opcost undefined! */
+#if defined(CONFIG_MOSIX_FS) && defined(CONFIG_MOSIX_TOPOLOGY)
+		memcpy(costinfo[0].mfscost, a.mfscosts, sizeof(a.mfscosts));
+#endif /* CONFIG_MOSIX_FS && CONFIG_MOSIX_TOPOLOGY */
+		mach[n++] = GOBACKHOME;
+	}
+	read_lock_bh(&loadinfo_lock);
+	for(i = 0 ; i < INFO_WIN ; i++)
+#ifdef CONFIG_MOSIX_CHEAT_MIGSELF
+	if(loadinfo[i].pe && (!i || loadinfo[i].pe != depmach)
+#else
+	if(loadinfo[i].pe && loadinfo[i].pe != depmach
+#endif /* CONFIG_MOSIX_CHEAT_MIGSELF */
+		&& (i == 0 || (loadinfo[i].mem >= m->migpages &&
+						loadinfo[i].free_slots)))
+	{
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		memcpy(costinfo[n].opcost, loadinfo[i].costs,
+						sizeof(loadinfo[i].costs));
+#ifdef CONFIG_MOSIX_FS
+		memcpy(costinfo[n].mfscost, loadinfo[i].mfscosts,
+						sizeof(loadinfo[i].mfscosts));
+#endif /* CONFIG_MOSIX_FS */
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+		aload[n] = altload(loadinfo[i].load, loadinfo[i].speed,
+				loadinfo[i].ncpus);
+		if(i)
+			mach[n] = loadinfo[i].pe;
+		else
+		{
+			mach[n] = 0;
+			if(reason == MEMBALANCE)
+			{
+				if(remote)
+					continue;
+				aload[n] += INFLOAD;
+			}
+		}
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("%d=%d==>%d, ", loadinfo[i].pe,
+					(int)loadinfo[i].load, aload[n]);
+#endif /* CONFIG_MOSIX_DEBUG */
+		n++;
+	}
+	read_unlock_bh(&loadinfo_lock);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+		printk("\n");
+#endif /* CONFIG_MOSIX_DEBUG */
+#ifdef CONFIG_MOSIX_FS
+	/* collect info on MFS nodes */
+	orig_n = n;
+	if(mfs_tot)
+	for(i = 0 ; i < mfs_tot->nnodes ; i++)
+	{
+		struct loadinfo info;
+
+		if(mfs_tot->conns[i] < 10 &&
+			(mfs_tot->inbytes[i] + mfs_tot->outbytes[i]) < 1000000)
+			continue;
+		k = mfs_tot->nodes[i];
+		if(k == PE || k == depmach)
+			continue;
+		for(j = 1 ; j < orig_n ; j++)
+		if(mach[j] == k)
+			goto not_this_one;
+		if(balance_get_load(k, &info))
+			continue;
+		if (info.mem < m->migpages || !info.free_slots)
+			continue;
+		mach[n] = k;
+		aload[n] = altload(info.load, info.speed, info.ncpus);
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		memcpy(costinfo[n].opcost, info.costs, sizeof(info.costs));
+		memcpy(costinfo[n].mfscost, info.mfscosts,
+							sizeof(info.mfscosts));
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("%d=%d=>>%d, ", k, (int)info.load, aload[n]);
+#endif /* CONFIG_MOSIX_DEBUG */
+		n++;
+		not_this_one:;
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+		printk("\n");
+#endif /* CONFIG_MOSIX_DEBUG */
+#endif /* CONFIG_MOSIX_FS */
+	if(n == 0 || (n == 1 && mach[0] == 0))
+		goto out;	/* save time */
+#ifdef CONFIG_MOSIX_FS
+	/* prepare the MFS mapping */
+	if(mfs_tot)
+	for(i = mfs_tot->nnodes - 1 ; i >= 0 ; i--)
+	{
+		k = mfs_tot->nodes[i];
+		if(k == PE)
+			map[i] = remote;
+		else if(remote && k == m->deppe)
+			map[i] = 0;
+		else
+		{
+			map[i] = -1;
+			for(j = n - 1 ; j > 0 ; j--)
+			if(mach[j] == k)
+			{
+				map[i] = j;
+				break;
+			}
+		}
+	}
+#endif /* CONFIG_MOSIX_FS */
+	/* we must NOT sleep throughout the following FP calculations:*/
+	kernel_fpu_begin();
+	ms = ticks_to_ms(p->times.tms_utime+m->uttime) + m->cutime - m->dctime;
+	if(sons)
+		ms += sons->utime;
+	if((m->dpolicy & DADV_POLICY) == DADV_NOCPU)
+		tim = 0.0;
+	else
+		/* secs on a std. machine */
+		tim = ms / DMILLION * cpuspeed / STD_SPD;
+	if(reason == MEMBALANCE)
+		tim += (m->pagetime + (sons ? sons->pagetime : 0)) / DMILLION;
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONSIDER)
+		printk("tim=%s\n", fformat(fbuf1, tim));
+#endif /* CONFIG_MOSIX_DEBUG */
+	for(i = 0 ; i < n ; i++)
+		costs[i] = tim * aload[i] / MF;
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+	{
+		printk("%s-initial mach:costs:", desc_mostask(m));
+		for(i = 0 ; i < n ; i++)
+			printk(" %d:%s", mach[i], fformat(fbuf1, costs[i]));
+		printk("\n");
+	}
+#endif
+	if((m->dpolicy & DADV_POLICY) == DADV_CPU)
+		goto skip_comm;
+	if(sons)	/* temporarily add */
+	{
+		lock_mosix();
+		m->ndemandpages += sons->ndemandpages;
+		m->nsyscalls += sons->nsyscalls;
+		m->ncopyouts += sons->ncopyouts;
+		m->copyoutbytes += sons->copyoutbytes;
+		m->ncopyins += sons->ncopyins;
+		m->copyinbytes += sons->copyinbytes;
+		unlock_mosix();
+	}
+	for(i = 1 ; i < n ; i++)
+	{
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		dtim = io_cost(m, remote ? m->depcost : deputy_here, mach[i]);
+		rtim = io_cost(m, costinfo[i].opcost, m->deppe);
+#else
+		dtim = io_cost(m, remote ? m->depcost : deputy_here);
+		rtim = io_cost(m, &remote_here);
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("dtim[%d]=%s, rtim[%d]=%s, ",
+				mach[i], fformat(fbuf1, dtim/DMILLION),
+				mach[i], fformat(fbuf2, rtim/DMILLION));
+#endif /* CONFIG_MOSIX_DEBUG */
+		costs[i] += (dtim * aload[0] + rtim * aload[i]) / (DMILLION*MF);
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+	{
+		printk("\n+I/O Overheads:   ");
+		for(i = 0 ; i < n ; i++)
+			printk(" %d:%s", mach[i], fformat(fbuf1, costs[i]));
+		printk("\n");
+	}
+#endif
+	if(sons)	/* restore */
+	{
+		lock_mosix();
+		m->ndemandpages -= sons->ndemandpages;
+		m->nsyscalls -= sons->nsyscalls;
+		m->ncopyouts -= sons->ncopyouts;
+		m->copyoutbytes -= sons->copyoutbytes;
+		m->ncopyins -= sons->ncopyins;
+		m->copyinbytes -= sons->copyinbytes;
+		unlock_mosix();
+	}
+#ifdef CONFIG_MOSIX_FS
+	if(!mfs_tot)
+		goto skip_comm;
+	for(i = 0 ; i < n ; i++)
+	for(j = 0 ; j < mfs_tot->nnodes ; j++)
+	if((k = map[j]) != -1 && k != i)
+	{
+		int c = mfs_tot->conns[j];
+		int in = mfs_tot->inbytes[j];
+		int out = mfs_tot->outbytes[j];
+
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		dtim = mfs_cos(c, in, out, costinfo[k].mfscost, MFS_SERVER,
+								mach[i]);
+		rtim = mfs_cos(c, in, out, costinfo[i].mfscost, MFS_CLIENT,
+								mach[k]);
+#else
+		dtim = mfs_cos(c, in, out, MFS_SERVER);
+		rtim = mfs_cos(c, in, out, MFS_CLIENT);
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("stim[%d,%d]=%s, rtim[%d,%d]=%s, ",
+				mach[i], mach[k], fformat(fbuf1,dtim/DMILLION),
+				mach[i], mach[k], fformat(fbuf2,rtim/DMILLION));
+#endif /* CONFIG_MOSIX_DEBUG */
+		costs[i] += (dtim * aload[k] + rtim * aload[i]) / (DMILLION*MF);
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+	{
+		printk("\n+MFS Overheads:   ");
+		for(i = 0 ; i < n ; i++)
+			printk(" %d:%s", mach[i], fformat(fbuf1, costs[i]));
+		printk("\n");
+	}
+#endif /* CONFIG_MOSIX_DEBUG */
+#endif /* CONFIG_MOSIX_FS */
+	skip_comm:
+	if (reason != MEMBALANCE)
+	{
+		/* migration cost: */
+		double decay_factor;
+
+		if(m->dctime > 0)	/* decay occured */
+		{
+			ms = ticks_to_ms(p->times.tms_utime + m->uttime);
+			if(ms)
+				decay_factor = ((double)(ms - m->dctime)) / ms;
+			else
+			{
+#ifdef CONFIG_MOSIX_UDB
+				mosix_panic("dctime without time");
+#endif /* CONFIG_MOSIX_UDB */
+				decay_factor = 1.0;
+			}
+		}
+		else
+			decay_factor = 1.0;
+		decay_factor /= DMILLION; /* to save multiple divisions later */
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		for(i = 0 ; i < n ; i++)
+		if(i != remote)
+		{
+			j = select_cost(deputy_here, i ? mach[i] : m->deppe);
+			costs[i] += decay_factor *
+				(mosix_cost[j].MIGRATION_BASIC +
+				m->migpages * mosix_cost[j].MIGRATION_PER_PAGE);
+		}
+#else
+		tim = decay_factor * (mosix_cost[0].MIGRATION_BASIC +
+			m->migpages * mosix_cost[0].MIGRATION_PER_PAGE);
+		for(i = 0 ; i < n ; i++)
+		if(i != remote)
+			costs[i] += tim;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+#ifdef	CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+		{
+			printk("+Migration costs:   ");
+			for(i = 0 ; i < n ; i++)
+				printk(" %d:%s", mach[i],
+						fformat(fbuf1, costs[i]));
+			printk("\n");
+		}
+#endif
+	}
+	/* sort by least cost */
+	for(i = 0 ; i < n-1 ; i++)
+	for(j = i+1 ; j < n ; j++)
+	if(costs[i] > costs[j])
+	{
+		tim = costs[i];
+		costs[i] = costs[j];
+		costs[j] = tim;
+		k = mach[i];
+		mach[i] = mach[j];
+		mach[j] = k;
+	}
+	kernel_fpu_end();
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+	{
+		printk("Consider Preferences:");
+		for(i = 0 ; i < n ; i++)
+			printk(" %d", mach[i]);
+		printk("\n");
+	}
+#endif
+	m->loadhere = aload[remote];
+	for(i = 0 ; i < n ; i++)
+	{
+		if((k = mach[i]) == 0)
+			goto out;
+		if(remote)
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_MIG)
+				printk("%s: Telling DEPUTY We Want to "
+					"Go to %d\n", desc_mostask(m), k);
+#endif /* CONFIG_MOSIX_DEBUG */
+			ask_deputy_to_goto(k);
+		}
+		else if(passto(k, reason) == 0)
+			goto out;
+		/* conditions changed meanwhile? */
+		if(mosadmin_mode_quiet || (reason && (mosadmin_mode_stay ||
+			(mosadmin_mode_lstay && !(m->dflags & DREMOTE)))))
+			goto out;
+	}
+	out:
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	if(costinfo)
+		kfree(costinfo);
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	m->migpages = 0;
+	unchoose_me();
+	if(m->dflags & DREMOTE)
+		ask_deputy_to_goto(0);
+}
+
+void
+unchoose_me(void)
+{
+	struct task_struct *p = current;
+	int l = 0, m = 0;
+
+	spin_lock_irq(&whereto_lock);
+	if(p == chosen_for_balance)
+	{
+		free_task_struct(p);
+		chosen_for_balance = NULL;
+		l = 1;
+	}
+	else if(p == chosen_for_mdp)
+	{
+		free_task_struct(p);
+		chosen_for_mdp = NULL;
+		m = 1;
+	}
+	spin_unlock_irq(&whereto_lock);
+	if(l)
+		load_balance();
+	else if(m)
+		memory_balance();
+}
+
+int
+mosix_forkmigrate(void)
+{
+	struct task_struct *me = current;
+	struct task_struct *p, *a;
+        register struct mosix_task *q;
+	struct sonstats s;
+	register int remote;
+	int64_t age;
+	int any = 0;
+
+	if(me->mosix.dflags & DDEPUTY)
+		panic("forkmigrate: DEPUTY");
+	if(me->mosix.stay || !PE)
+		return(0);
+	remote = (me->mosix.dflags & DREMOTE) != 0;
+	lock_mosix();
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	for(a = p->mosix.ancesstor ; a ; a = a->mosix.ancesstor)
+        if(a == me)
+	{
+		q = &p->mosix;
+		age = ticks_to_ms(p->times.tms_utime + q->uttime) + q->cutime;
+		if(remote)
+			age += remote_costs_in_ms(q);
+		else
+			age += ticks_to_ms(p->times.tms_stime);
+		if(age > 4 * MILLION)
+		/* over 4 seconds, descendant is no longer dependent */
+		{
+#ifdef	CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_ANCESSTOR)
+			{
+				printk("%s-forkmigrate: ", desc_mostask(NULL));
+				printk("%s no longer dependent: age=%d:%06d\n",
+					desc_mostask(q),
+					(int)(age/MILLION),
+					(int)(age-age/MILLION*MILLION));
+			}
+#endif
+			q->ancesstor = NULL;
+			break;
+		}
+		if(!any)
+		{
+			any = 1;
+			memset(&s, 0, sizeof s);
+		}
+		s.utime += ticks_to_ms(p->times.tms_utime + q->uttime) +
+							q->cutime - q->dctime;
+		/* we need not worry about the "q->uttime" part of q->dctime
+		   on a local process: if the process ever migrated, it would
+		   not be dependent and we would never reach here!
+		*/
+		s.nsyscalls += q->nsyscalls;
+		s.ncopyouts += q->ncopyouts;
+		s.copyoutbytes += q->copyoutbytes;
+		s.ncopyins += q->ncopyins;
+		s.copyinbytes += q->copyinbytes;
+		s.pagetime += q->pagetime;
+#ifdef CONFIG_MOSIX_FS
+		mfs_add_stats(q->mfs_stats, &s.mfs, NULL);
+#endif /* CONFIG_MOSIX_FS */
+		break;
+	}
+	read_unlock(&tasklist_lock);
+	unlock_mosix();
+	if(!any)
+		return(0);
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_CONSIDER|DSDEB_ANCESSTOR))
+		printk("%s-forkmigrate: son utime=%d.%06d, pages=%d, "
+			"syscalls=%d, copyouts=%d/%d, copyins=%d/%d\n",
+			desc_mostask(NULL), (int)(s.utime/MILLION),
+			(int)(s.utime-s.utime/MILLION*MILLION),
+			(int)(s.ndemandpages>>EVENT_COUNTER_SHIFT),
+			(int)(s.nsyscalls>>EVENT_COUNTER_SHIFT),
+			(int)(s.ncopyouts>>EVENT_COUNTER_SHIFT),
+			(int)s.copyoutbytes,
+			(int)(s.ncopyins>>EVENT_COUNTER_SHIFT),
+			(int)s.copyinbytes);
+#endif
+	if(remote && comm_send(REM_CONSIDERING, NULL, 0, NULL, 0, 0))
+		remote_disappear();
+        consider(BALANCE, &s);
+	return(me->mosix.dflags & DDEPUTY);
+	/* for local processes, DDEPUTY means we moved,
+	 * and REMOTE processes do not care for result -
+	 * for they would never reach here if migrated.
+	 */
+}
+
+int
+send_with_miginfo(int type, void *header, int hdsz)
+{
+	struct miginfo mi;
+	register struct mosix_task *m = &current->mosix;
+
+	mi.aload = m->loadhere;
+	mi.pages = m->migpages ? : count_migrating_pages();
+	return(comm_send(type, header, hdsz, (char *)&mi, sizeof(mi), 0));
+}
+
+int
+balance_commit_mig(int reason, int pages_i_bring)
+{
+	int me, him;
+	struct miginfo mi;
+
+	if(comm_copydata(&mi, sizeof(mi) | COMM_ZEROCOPYOK, 0))
+		goto commit;	/* no MOSIX on other side! */
+	switch(reason)
+	{
+		case 0:
+		case IOBALANCE:
+		case MFSBALANCE:
+			goto commit;
+		default:
+			read_lock_bh(&loadinfo_lock);
+			me = altload(export_load, loadinfo[0].speed,
+				loadinfo[0].ncpus);
+			read_unlock_bh(&loadinfo_lock);
+			him = mi.aload;
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_CONSIDER)
+				printk("balance_commit_mig: me=%d, him=%d, result=%d\n", me, him, me <= him);
+#endif /* CONFIG_MOSIX_DEBUG */
+			if(me > him)
+				break;
+			/* fall through - check memory as well */
+		case MEMBALANCE:
+			me = export_mem();
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_CONSIDER)
+				printk("balance_commit_mig: I have %d pages, asked for %d, reply=%s\n",
+					me, (int)mi.pages,
+					mi.pages <= me ? "YES" : "NO");
+#endif /* CONFIG_MOSIX_DEBUG */
+			if(me >= mi.pages)
+				goto commit;
+			break;
+	}
+	return(0);	/* NO! */
+	commit:
+	info_someone_came_in();
+	return(1);
+}
diff -ruN linux-2.4.16/mos/comm.c linux-2.4.16-mosix/mos/comm.c
--- linux-2.4.16/mos/comm.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/comm.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,2713 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan.
+ */
+#include <linux/sched.h>
+#include <linux/socket.h>
+#include <linux/poll.h>
+#include <net/sock.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <linux/mosix.h>
+#include <linux/mosctl.h>
+#include <linux/mm.h>
+#include <linux/stddef.h>
+#include <linux/smp_lock.h>
+#include <asm/pgtable.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <mos/log.h>
+#include <mos/debug.h>
+#include <asm/uaccess.h>
+
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#include <linux/mfs_socket.h>
+#endif /* CONFIG_MOSIX_FS */
+
+#define MIG_DAEMON_PORT		0x3412
+#define INFO_DAEMON_PORT	0x3415
+
+/*
+ * mosix specific data per contact
+ */
+#define COMM_DEF_HEADSIZE	256
+
+struct mosix_link {
+	/* the first 2 elements are common to both types and must stay there */
+	struct socket *sock;	/* socket for communications */
+	int flags;		/* status flags */
+	int dlen;		/* length of pending data */
+	int peer;		/* mosix # of peer */
+	char *hideptr;		/* pointer to hidden data (current) */
+	char *hidebuf;		/* pointer to start of hidden data buffer */
+	int hidelen;		/* dlen of hidden data */
+	char head[COMM_DEF_HEADSIZE];
+#ifdef CONFIG_MOSIX_DEBUG
+	int cntmem;
+	int count;
+#endif /* CONFIG_MOSIX_DEBUG */
+};
+
+spinlock_t skown_lock = SPIN_LOCK_UNLOCKED;
+
+#define COMM_HEADINUSE		0x01
+#define COMM_WAITACCEPT		0x02
+#define COMM_HIDEDATA		0x04
+#define COMM_FULLLINK		0x08
+#define COMM_INFOLINK		0x10
+
+#define	COMM_MAX_MULTIWAIT	10
+
+#define COMM_SOCKET_SPARE	2048
+#define COMM_SOCKET_DATA	16384
+/*#define COMM_SOCKET_BUFFER	(COMM_SOCKET_SPARE + COMM_SOCKET_DATA)*/
+#define	COMM_SOCKET_BUFFER	131072
+
+
+#ifdef CONFIG_MOSIX_UDB
+
+#define COMM_REMOTE_TIMO	((unsigned long) 300*HZ)
+#define COMM_CONNECT_TIMO	((unsigned long) 60*HZ)
+#define COMM_RECONN_TIMO	((unsigned long) 180*HZ)
+
+#else
+
+#define COMM_REMOTE_TIMO	((unsigned long) 300*HZ)
+#define COMM_CONNECT_TIMO	((unsigned long) 5*HZ)
+#define COMM_RECONN_TIMO	((unsigned long) 10*HZ)
+
+#endif /* CONFIG_MOSIX_UDB */
+
+#ifdef CONFIG_MOSIX_DFSA
+#define	DISABLE_FLAGS	(DDEPUTY|DREMOTEDFSA)
+#else
+#define	DISABLE_FLAGS	DDEPUTY
+#endif /* CONFIG_MOSIX_DFSA */
+
+#define	DISABLE_EVENTS()	do {if(current->mosix.dflags & DISABLE_FLAGS) deeper_sleep();} while(0)
+#define	ENABLE_EVENTS()		do {if(current->mosix.dflags & DISABLE_FLAGS) lighter_sleep();} while(0)
+
+int comm_type;
+unsigned long comm_remote_timo = COMM_REMOTE_TIMO;	/* for remote accept */
+unsigned long comm_connect_timo = COMM_CONNECT_TIMO;	/* for connection */
+unsigned long comm_reconn_timo = COMM_RECONN_TIMO;	/* for reconnection */
+
+/*
+ * make sure that all pages in range cause no remote page-fault requests later.
+ * Once we find a page that would cause a page-fault, we may either report it
+ * by returning 0 (normal return is 1) or fix it and make it dirty.
+ */
+int
+dirty_all_remote_pages(unsigned long start, unsigned long size, int doit)
+{
+	struct mm_struct *mm = current->mm;
+	struct vm_area_struct * vma;
+	unsigned long addr, lastaddr;
+	unsigned long limit = (start + size + PAGE_SIZE - 1) & ~(PAGE_SIZE-1);
+	pgd_t *pgd;
+	pmd_t *pmd;
+	pte_t *pte;
+	int hidedata = 0;
+	int ret = 1;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!(current->mosix.dflags & DREMOTE))
+		panic("dirty_all_remote_pages: not remote");
+#endif /* CONFIG_MOSIX_DIAG */
+	if(size == 0)
+		return(1);
+	down_write(&mm->mmap_sem);
+	if(!(vma = find_vma(mm, start)))
+		goto unlock;
+	for(addr = start & ~(PAGE_SIZE-1) ; addr < limit ; addr += PAGE_SIZE)
+	{
+		while(!vma->vm_file || addr >= vma->vm_end ||
+			(doit && !(vma->vm_flags & VM_WRITE)))
+			/* (the last condition will cause a SIGSEGV,
+					   which we don't want here) */
+		{
+			lastaddr = vma->vm_end;
+			if(!(vma = vma->vm_next))
+				goto unlock;
+			if(vma->vm_file && (vma->vm_flags & VM_GROWSDOWN))
+			/* (a mad-hatter is permitted use sys_mmap this way) */
+			{
+				if((addr = lastaddr) >= limit)
+					goto unlock;
+			}
+			else if((addr = vma->vm_start) >= limit)
+				goto unlock;
+			addr = vma->vm_start;
+		}
+		if(vma->vm_flags & VM_GROWSDOWN)
+		  /* Hmmm... will any executable file-format ever allow this? */
+			panic("dirty_all_remote_pages: stack mapped to file");
+
+		/* Dirty pages (including swap) are OK - all others are not */
+		pgd = pgd_offset(current->mm, addr);
+		if(pgd_none(*pgd) || pgd_bad(*pgd) ||
+			pmd_none(*(pmd = pmd_offset(pgd, addr))) ||
+			pmd_none(*pmd) || pmd_bad(*pmd) ||
+			(pte_present(*(pte = pte_offset(pmd, addr))) ?
+				!pte_dirty(*pte) : pte_none(*pte)))
+		{
+			if(!doit)
+			{
+				ret = 0;
+				goto unlock;
+			}
+			if (!hidedata) {
+				hidedata = 1;
+				if(comm_hidedata())
+				{
+					ret = 0;
+					goto unlock;
+				}
+			}
+			handle_mm_fault(mm, vma, addr, 1);
+		}
+	}
+	unlock:
+	up_write(&mm->mmap_sem);
+	return(ret);
+}
+
+/*
+ * internal communication routines
+ */
+
+static void *comm_mkhead(int);
+static inline void comm_setup_link(mosix_link *, int);
+static inline void comm_unset_link(mosix_link *);
+static inline int comm_setup_socket(struct socket *, int);
+static inline void comm_unset_socket(struct socket *);
+static void *comm_malloc(int);
+static int comm_dorecv(struct socket *, struct msghdr *, int);
+static int comm_packregs(struct comm_header *, char *);
+static int comm_unpackregs(struct comm_header *, char *);
+static int comm_packident(char *);
+static int comm_unpackident(char *);
+static int comm_waitaccept(void);
+static int comm_poll(int, int, unsigned long);
+static void comm_data_ready(struct sock *, int);
+static int comm_getname(struct socket *, struct sockaddr *);
+static void comm_shutdown(mosix_link *);
+
+static inline struct socket *comm_set_address(int, struct sockaddr *, int);
+static inline struct socket *comm_ip_set_addr(int, struct sockaddr *, int);
+static inline int comm_ip_getname(struct socket *, struct sockaddr *);
+static inline int comm_ip_setup_socket(struct socket *, int);
+static void comm_ip_migration_mode(int);
+
+void
+comm_report_violation(char *desire, struct sockaddr *addr)
+{
+	unsigned int a = htonl(((struct sockaddr_in *)addr)->sin_addr.s_addr);
+
+	printk("Received an unauthorized %s request from %d.%d.%d.%d\n", desire,
+		(a & 0xff000000) >> 24, (a & 0xff0000) >> 16,
+		(a & 0xff00) >> 8, a & 0xff);
+}
+
+static inline struct task_struct *
+find_task_by_sock(struct socket *sock)
+{
+	struct task_struct *p = NULL;
+	struct sock *sk;
+
+	spin_lock(&skown_lock);
+	if((sk = sock->sk) && (p = sk->owner))
+		get_task_struct(p);
+	else
+		spin_unlock(&skown_lock);
+	return(p);
+}
+
+static inline void
+comm_setup_link(mosix_link *mlink, int peer)
+{
+#ifdef CONFIG_MOSIX_DIAG
+	if (!(mlink->flags & COMM_FULLLINK))
+		panic("comm_setup_link: not FULLLINK");
+#endif /* CONFIG_MOSIX_DIAG */
+	mlink->dlen = 0;
+	mlink->peer = peer;
+	mlink->hideptr = NULL;
+	mlink->hidebuf = NULL;
+	mlink->hidelen = 0;
+#ifdef CONFIG_MOSIX_DEBUG
+	mlink->cntmem = 0;
+	mlink->count = 0;
+#endif /* CONFIG_MOSIX_DEBUG */
+}	
+
+static inline void
+comm_unset_link(mosix_link *mlink)
+{
+	if (mlink->flags & COMM_FULLLINK) {
+		if (mlink->hidebuf) {
+			kfree(mlink->hidebuf);
+			mlink->hidebuf = NULL;
+			mlink->hideptr = NULL;
+			mlink->hidelen = 0;
+		}
+		mlink->dlen = 0;
+	}
+	mlink->flags &= ~(COMM_WAITACCEPT | COMM_HIDEDATA);
+}
+
+static void *
+comm_malloc(int size)
+{
+	void *mem;
+
+	while(1)
+	{
+		if((mem = kmalloc(size, GFP_KERNEL)))
+			return(mem);
+	}
+}
+
+static int
+comm_packregs(struct comm_header *header, char *ptr)
+{
+	int regs;
+	int bit;
+	int size = 0;
+	int *regptr = (int *)ptr;
+	struct task_struct *p = current;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_packregs: h 0x%x p 0x%x\n",
+			desc_mostask(NULL), (int) header, (int) ptr);
+#endif /* CONFIG_MOSIX_DEBUG */
+	
+	regs = which_regs_to_send();
+	if (header)
+		header->regs = regs;
+	if (!regs)
+		return (0);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_packregs: mask 0x%x\n", desc_mostask(NULL),
+									regs);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	regs = ~regs;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (regptr) {
+		if (ds_debug & DSDEB_COMMFLAGS)
+			printk("%s-comm_packregs(): packing regs = 0x%x\n",
+				desc_mostask(NULL), regs);
+	}
+#endif /* CONFIG_MOSIX_DEBUG */
+	while (regs != 0xffffffff) {
+		bit = ffz(regs);
+		if (ptr)
+			*(regptr++) = ((int *)p->mosix.altregs)[bit];
+		regs |= (1 << bit);
+		size++;
+	}
+	return (size << 2);	/* size * sizeof(int) */
+}
+
+
+static int
+comm_unpackregs(struct comm_header *header, char *ptr)
+{
+	int regs;
+	int bit;
+	int size = 0;
+	int *regptr = (int *)ptr;
+	struct task_struct *p = current;
+
+	regs = header->regs;
+#ifdef CONFIG_MOSIX_DIAG
+	if ((regs & (p->mosix.dflags & DDEPUTY ? ~p->mosix.deputy_regs :
+					p->mosix.deputy_regs)) != regs) {
+		printk("%s-comm_unpackregs: inconsistent (regs=%x, ptr=0x%x)\n",
+			desc_mostask(NULL), regs, (int) ptr);
+		panic("comm_unpackregs(): inconsistent regs\n");
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	p->mosix.deputy_regs ^= regs;
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_unpackregs(): unpacking regs = 0x%x\n",
+			desc_mostask(NULL), ~regs);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	regs = ~regs;
+	while (regs != 0xffffffff) {
+		bit = ffz(regs);
+		((int *)p->mosix.altregs)[bit] = *(regptr++);
+		regs |= (1 << bit);
+		size++;
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_unpackregs: size << 2 = %d\n",
+			desc_mostask(NULL), size << 2);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	return (size << 2);	/* size * sizeof(int) */
+}
+
+
+static int
+comm_packident(char *ptr)
+{
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_packident: ptr 0x%x\n", desc_mostask(NULL),
+								(int) ptr);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if (ptr) {
+		((int *)ptr)[0] = PE;
+		((int *)ptr)[1] = comm_getpeer(current->mosix.contact);
+
+		/*
+		 * if this is the first migration to a node,
+		 * tell them, so they flush any of our old cached files,
+		 */
+		if (!config_get_status(((int *)ptr)[1]))
+			((int *)ptr)[0] |= 0x80000000;
+
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMMFLAGS)
+			printk("%s-comm_packident: me=%d  him=%d\n",
+				desc_mostask(NULL), PE, ((int *)ptr)[1]);
+#endif /* CONFIG_MOSIX_DEBUG */
+	}
+	return (2 * sizeof(int));
+}
+
+
+static int
+comm_unpackident(char *ptr)
+{
+	int ret = -1;
+	int him, me;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_unpackident: him=%d me=%d\n",
+			desc_mostask(NULL), ((int *)ptr)[0], ((int *)ptr)[1]);
+#endif /* CONFIG_MOSIX_DEBUG */
+	him = ((int *)ptr)[0];
+	me = ((int *)ptr)[1];
+	
+	if (him & 0x80000000)
+		rinode_flush_files(him & ~0x80000000);
+	if (comm_getpeer(current->mosix.contact) == (him & 0x7fffffff)
+								 && PE == me)
+		ret = 2 * sizeof(int);
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMFLAGS)
+		printk("%s-comm_unpackident: mismatch \n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	return (ret);
+}
+
+
+/*
+ * comm_startup() - initialize communication layer
+ */
+void
+comm_startup(void)
+{
+	/* nothing to do */
+}
+
+/*
+ * comm_setup_socket() - setup socket parameters (specific to its type)
+ */
+static inline int
+comm_setup_socket(struct socket *sock, int mos)
+{
+	int val;
+	int error;
+	int connect = 0;
+	mm_segment_t oldfs;
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	/*
+	 * socket parameters:
+	 * - SO_SNDBUF, SO_RCVBUF 
+	 * - SO_KEEPALIVE (for connection-oriented sockets)
+	 */
+
+	val = COMM_SOCKET_BUFFER;
+	if ((error = sock_setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
+						(char *) &val, sizeof(val))) ||
+	    (error = sock_setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
+	    					(char *) &val, sizeof(val))))
+		goto failed;
+/*
+	val = IPTOS_LOWDELAY;
+	if ((error = sock_setsockopt(sock, SOL_IP, IP_TOS, (char *)&val,
+								sizeof(val))))
+		goto failed;
+*/
+
+	switch (mos) {
+		case COMM_INFO:
+			sock->sk->data_ready = comm_data_ready;
+			break;
+		case COMM_LOOSE:
+			/* 
+			 * set "sk->bsdism" (SO_BSDCOMPAT) to prevent ICMP
+			 * errors from being reflected in the UDP socket,
+			 * thus receiving old errors on new calls.
+			 */
+			val = 1;
+			if ((error = sock_setsockopt(sock, SOL_SOCKET,
+					SO_BSDCOMPAT, (char*)&val,sizeof(val))))
+				goto failed;
+		case COMM_ACCEPT:
+		case COMM_TOADDR:
+		default:
+			set_bit(SOCK_INTER_MOSIX, &sock->flags);
+			if (mos == COMM_LOOSE) /* UDP - we're done */
+				break;
+			val = 1;
+			if ((error = sock_setsockopt(sock, SOL_SOCKET,
+				SO_KEEPALIVE, (char *) &val, sizeof(val))))
+				goto failed;
+			/* fall through */
+		case COMM_MIGD:
+			connect = 1;
+			val = 1;
+			break;
+	}
+
+	switch (comm_type) {
+		case AF_INET:
+			error = comm_ip_setup_socket(sock, connect);
+			break;
+		default:
+			panic("comm_setup_socket: unknown comm_type");
+	}
+
+failed:
+#ifdef CONFIG_MOSIX_DEBUG
+	if (error && (ds_debug & DSDEB_ERROR))
+		printk("%s-comm_setup_socket: error %d\n", desc_mostask(NULL),
+									error);
+#endif /* CONFIG_MOSIX_DEBUG */
+	set_fs(oldfs);
+	return (error);
+}
+
+static inline void
+comm_unset_socket(struct socket *sock)
+{
+	spin_lock_irq(&skown_lock);
+	sock->sk->owner = NULL;
+	clear_bit(SOCK_INTER_MOSIX, &sock->flags);
+	spin_unlock_irq(&skown_lock);
+}
+
+
+static inline int
+comm_ip_setup_socket(struct socket *sock, int connect)
+{
+	int val;
+	int error;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMOPEN)
+		printk("%s-comm_ip_setup_socket: connect=%d\n",
+			desc_mostask(NULL), connect);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	/* NOTE: at this point set_fs(KERNEL_DS) is on */
+
+	if (connect) {
+		mm_segment_t oldfs = get_fs();
+		set_fs(KERNEL_DS);
+		val = MOSIX_CONNECTION_KEEPALIVE_INTERVAL;
+		if ((error = sock->ops->setsockopt(sock, IPPROTO_TCP,
+			TCP_KEEPINTVL, (char *) &val, sizeof(val))))
+		{
+			resume:
+			set_fs(oldfs);
+			return(error);
+		}
+		val = MOSIX_CONNECTION_KEEPALIVE_MAXTRIES;
+		if ((error = sock->ops->setsockopt(sock, IPPROTO_TCP,
+			TCP_KEEPCNT, (char *) &val, sizeof(val))))
+			goto resume;
+		val = MOSIX_CONNECTION_KEEPALIVE_TOTAL;
+		if ((error = sock->ops->setsockopt(sock, IPPROTO_TCP,
+			TCP_KEEPIDLE, (char *) &val, sizeof(val))))
+			goto resume;
+		val = 1;
+		if ((error = sock->ops->setsockopt(sock, IPPROTO_TCP,
+			TCP_NODELAY, (char *) &val, sizeof(val))))
+			goto resume;
+		set_fs(oldfs);
+	}
+	return (0);
+}
+
+/*
+ * comm_open() - open a socket for MOSIX communications
+ * 
+ * mos > 0: 		connect to migdaemon on node #mos
+ * mos = COMM_TOADDR:	connect to address given in maddr->saddr
+ * mos = COMM_ACCEPT:	set up a socket and prepare to accept
+ * mos = COMM_MIGD:	set up a socket for mig-daemon
+ * mos = COMM_INFOD:	set up a socket for info-daemon
+ * mos = COMM_LOOSE	connect to multiple daemons
+ */
+mosix_link *
+comm_open(int mos, mosix_addr *maddr, unsigned long timo)
+{
+	int error = -EDIST;
+	struct socket *sock = NULL;
+	mosix_link *mlink = NULL;
+	struct sockaddr sa;
+	int connect = 1, bind = 1, need_comm = 1, listen = 1, peer = 0;
+	struct sockaddr *saddr = &(maddr->saddr);
+	DECLARE_WAITQUEUE(wait, current);
+
+	/*
+	 * COMM_INFO:	connect = 0, need_comm = 0, listen = 0, bind = 1
+	 * COMM_MIGD:	connect = 0, need_comm = 1, listen = 1, bind = 1
+	 * COMM_ACCEPT:	connect = 0, need_comm = 1, listen = 1, bind = 1
+	 * COMM_TOADDR: connect = 1, need_comm = 1, listen = 0, bind = 1
+	 * COMM_LOOSE:  connect = 0, need_comm = 0, listen = 0, bind = 0
+	 * deafult:     connect = 1, need_comm = 1, listen = 1, bind = 1
+	 */
+	switch (mos) {
+	case COMM_LOOSE:
+		bind = 0;
+		/* fall through */
+	case COMM_INFO:
+		listen = 0;
+		/* fall through */
+	case COMM_MIGD:
+		need_comm = 0;
+		/* fall through */
+	case COMM_ACCEPT:
+		connect = 0;
+		if(!saddr)
+			saddr = &sa;
+		break;
+	case COMM_TOADDR:
+		if(saddr->sa_family != AF_INET)
+			return(NULL);
+		break;
+	default:
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMMOPEN)
+			printk("%s-comm_open to mos#%d\n", desc_mostask(NULL),
+									mos);
+#endif /* CONFIG_MOSIX_DEBUG */
+#ifdef CONFIG_MOSIX_DIAG
+		if (mos <= 0 || mos > MOSIX_MAX)
+			panic("comm_open: incorrent mos#");
+#endif /* CONFIG_MOSIX_DIAG */
+		peer = mos;
+		saddr = &sa;
+		break;
+	}
+#ifdef CONFIG_MOSIX_DIAG
+	if (!saddr)
+		panic("comm_open: NULL saddr");
+#endif /* CONFIG_MOSIX_DIAG */
+	DISABLE_EVENTS();
+	/* fill in socket address and allocate a socket */
+	if (!(sock = comm_set_address(mos, saddr, 1)))
+		goto failed;
+
+	if (need_comm) {	 	/* mosix_link required ? */
+		mlink = kmalloc(sizeof(mosix_link), GFP_KERNEL);
+		if (!mlink) {
+		no_memory:
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_COMMOPEN)
+				printk("%s-comm_open:  insufficient memory\n",
+					desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+			goto failed;
+		}
+		mlink->flags = COMM_FULLLINK;
+		comm_setup_link(mlink, peer);
+	} else {
+		mlink = kmalloc(sizeof(struct socket *) + sizeof(int),
+								GFP_KERNEL);
+		if (!mlink)
+			goto no_memory;
+		mlink->flags = COMM_INFOLINK;
+	}
+	mlink->sock = sock;
+	
+	if ((error = comm_setup_socket(sock, mos)))
+		goto failed;
+
+	if (!connect) { 			/* setup server - listen */
+		if(bind)
+		{
+			error = sock->ops->bind(sock, saddr, sizeof(*saddr));
+			if (error) {
+				if(error == -EADDRINUSE && mos == COMM_MIGD)
+					printk("Migration port (%d) Already in use\n", ntohs(MIG_DAEMON_PORT));
+#ifdef CONFIG_MOSIX_DEBUG
+				if (ds_debug & DSDEB_COMMOPEN)
+					printk("bind() in ");
+#endif /* CONFIG_MOSIX_DEBUG */
+				goto failed;
+			}
+		}
+		if (listen) {			/* connection required ? */
+			error = sock->ops->listen(sock, SOMAXCONN);
+			if (error) {
+#ifdef CONFIG_MOSIX_DEBUG
+				if (ds_debug & DSDEB_COMMOPEN)
+					printk("listen() in ");
+#endif /* CONFIG_MOSIX_DEBUG */
+				goto failed;
+			}
+		}
+
+		if (mos == COMM_ACCEPT) {
+			mlink->flags |= COMM_WAITACCEPT;
+			if ((error = comm_getname(sock, saddr))) {
+#ifdef CONFIG_MOSIX_DEBUG
+				if (ds_debug & DSDEB_COMMOPEN)
+					printk("comm_getname() in ");
+#endif /* CONFIG_MOSIX_DEBUG */
+				goto failed;
+			}
+		}
+	} else {		/* setup client - connect */
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMMOPEN)
+			printk("%s-comm_open: connecting...\n",
+				desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		if (!timo)
+			timo = MAX_SCHEDULE_TIMEOUT;
+		error = sock->ops->connect(sock, saddr, sizeof(*saddr),
+								O_NONBLOCK);
+		add_wait_queue(sock->sk->sleep, &wait);
+		while (sock->state != SS_CONNECTED) {
+			set_current_state(TASK_INTERRUPTIBLE);
+			error = sock->ops->connect(sock, saddr, sizeof(*saddr),
+								O_NONBLOCK);
+#ifdef CONFIG_MOSIX_DIAG
+			if (error == -EISCONN || error == -EINVAL) {
+				printk("%s-comm_open: error %d\n",
+					desc_mostask(NULL), error);
+				panic("comm_open while connect");
+			}
+#endif /* CONFIG_MOSIX_DIAG */
+			if (error != -EALREADY || (error=sock_error(sock->sk)))
+				break;
+
+			timo = schedule_timeout(timo);
+			if (timo <= 0) {
+				error = -EAGAIN;
+				break;
+			}
+		}
+		remove_wait_queue(sock->sk->sleep, &wait);
+		set_current_state(TASK_RUNNING);
+
+		if (error) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_COMMOPEN)
+				printk("connect() in ");
+#endif /* CONFIG_MOSIX_DEBUG */
+			goto failed;
+		}
+		if (sock->sk->err) {
+			error = sock_error(sock->sk);	/* cleans error.. */
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_COMMOPEN)
+				printk("sock_error in ");
+#endif /* CONFIG_MOSIX_DEBUG */
+			goto failed;
+		}
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMMOPEN)
+			printk("%s-comm_open: SUCCESS connection...\n",
+				desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		/* client socket ready */
+	}
+	ENABLE_EVENTS();
+
+	return (mlink);
+
+failed:
+	ENABLE_EVENTS();
+	if (sock)
+		sock_release(sock);
+	if (mlink)
+		kfree(mlink);
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_COMMOPEN|DSDEB_ERROR))
+		printk("%s: comm_open: failed err=%d\n", desc_mostask(NULL),
+									error);
+#endif /* CONFIG_MOSIX_DEBUG */
+	return (0);
+}
+
+/*
+ * comm_use() - set new "contact" for a process (and get the old one)
+ */
+mosix_link *
+comm_use(struct task_struct *p, mosix_link *mlink)
+{
+	mosix_link *oldmlink;
+
+	spin_lock_irq(&skown_lock);
+	if ((oldmlink = p->mosix.contact))
+		oldmlink->sock->sk->owner = NULL;
+	p->mosix.contact = NULL;
+	if (mlink)
+	{
+		p->mosix.contact = mlink;
+		mlink->sock->sk->owner = p;
+	}
+	spin_unlock_irq(&skown_lock);
+	if(test_bit(SOCK_OOB_IN, &mlink->sock->flags))
+		tell_process(p, DREQ_URGENT);
+	return (oldmlink);
+}
+
+
+/*
+ * comm_close() - close a MOSIX communication socket
+ *   if called with NULL argument, close our contact and nullify it
+ */
+void
+comm_close(mosix_link *mlink)
+{
+	int ours = 0;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMM)
+		printk("%s-comm_close: closing%s socket\n",
+			desc_mostask(NULL), mlink ? "" : " my"); 
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if (!mlink) {
+		ours = 1;
+		mlink = current->mosix.contact;
+#ifdef CONFIG_MOSIX_DIAG
+		if (!mlink)
+			panic("comm_close: no contact");
+#endif /* CONFIG_MOSIX_DIAG */
+	}
+#ifdef CONFIG_MOSIX_DIAG
+	else if (mlink == current->mosix.contact)
+		panic("comm_close: closing my socket explicitly");
+#endif /* CONFIG_MOSIX_DIAG */
+
+	comm_shutdown(mlink);
+	sock_release(mlink->sock);
+
+	if (ours)
+		current->mosix.contact = NULL;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (mlink->flags & COMM_FULLLINK) {
+		if (mlink->flags & COMM_HEADINUSE)
+			mosix_panic("comm_close: comm->head still in use !");
+#ifdef CONFIG_MOSIX_DEBUG
+		if (mlink->cntmem || mlink->count) {
+			printk("cntmem=%d, count=%d\n",
+				mlink->cntmem, mlink->count);
+			mosix_panic("comm_close: count not zero");
+		}
+#endif /* CONFIG_MOSIX_DEBUG */
+	} else if (!(mlink->flags & COMM_INFOLINK))
+	  	mosix_panic("comm_close: nor FULL neither LINK");
+#endif /* CONFIG_MOSIX_DIAG */
+
+	kfree(mlink);
+}
+
+
+/*
+ * comm_accept() - accept a connection on MOSIX socket
+ */
+int
+comm_accept(mosix_link *ml, mosix_link **mlp, mosix_addr *ma, unsigned long t)
+{
+	int error = 0;
+	struct socket *sock;
+	struct sockaddr *saddr = &(ma->saddr);
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (current->mosix.dflags & DDEPUTY)
+		panic("comm_accept called by DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMACPT)
+		printk("%s-comm_accept: accepting connection\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if ((*mlp = kmalloc(sizeof(mosix_link), GFP_KERNEL)) == 0)
+		return (-ENOMEM);
+
+	sock = sock_alloc();
+	if (!sock) {
+		kfree(*mlp);
+		return (-EMFILE);
+	}
+	sock->type = ml->sock->type;
+	sock->ops = ml->sock->ops;
+
+	if (t && !comm_poll(POLLIN | POLLRDNORM, 0, t))
+		error = -EAGAIN;
+
+	if (!error)
+		error = ml->sock->ops->accept(ml->sock, sock, 0);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (error && (ds_debug & DSDEB_COMMACPT))
+		printk("%s-comm_accept: error1 %d\n", desc_mostask(NULL),error);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if (!error && saddr)
+		error = comm_getname(sock, saddr);
+
+	if (error) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMMACPT)
+			printk("%s-comm_accept: error %d\n", desc_mostask(NULL),
+									error);
+#endif /* CONFIG_MOSIX_DEBUG */
+	failed:
+		kfree(*mlp);
+		sock_release(sock);
+		*mlp = NULL;
+	} else {
+		struct sockaddr saddr;
+		int val;
+
+		if (sock->ops->getname(sock, &saddr, &val, 1)) {
+#ifdef CONFIG_MOSIX_DIAG
+			printk("%s-comm_accept: strange, not connected\n",
+				desc_mostask(NULL));
+			mosix_panic("comm_accept disconnected ?!");
+#endif /* CONFIG_MOSIX_DIAG */
+			error = -ENOTCONN;
+			goto failed;
+		}
+		if (!(val = net_to_mos((mosix_addr *)&saddr))) {
+			comm_report_violation("migration", &saddr);
+			error = -EDIST;
+			goto failed;
+		}
+		(*mlp)->sock = sock;
+		(*mlp)->flags = COMM_FULLLINK;
+		comm_setup_link(*mlp, val);
+
+		if ((error = comm_setup_socket(sock, PE)))
+			goto failed;	
+	}
+	return (error);
+}
+
+/*
+ * comm_waitaccept() - accept a connection on MOSIX socket
+ */
+static int
+comm_waitaccept()
+{
+	struct task_struct *p = current;
+	mosix_link *mlink;
+	int error;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_COMMACPT|DSDEB_COMMOPEN))
+		printk("%s-comm_waitaccept: accepting .\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((error = comm_accept(p->mosix.contact, &mlink, 0, comm_remote_timo)))
+		return (error);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_COMMACPT|DSDEB_COMMOPEN))
+		printk("%s-comm_waitaccept: accepted\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	comm_close(comm_use(p, mlink));
+	return (0);
+}
+
+
+/*
+ * comm_free() - free a head/data which is no longer used
+ */
+void
+comm_free(void *head)
+{
+	mosix_link *mlink;
+	struct task_struct *p = current;
+
+	if(!head)
+		return;
+
+	mlink = p->mosix.contact;
+	if (mlink->flags & COMM_INFOLINK) {
+		kfree(head);
+		return;
+	}
+
+	if (head == &mlink->head + COMM_HLEN) {
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-comm_free(): shift (sk=0x%x, comm=0x%x)\n", 
+			desc_mostask(NULL), (int) mlink->sock->sk, 
+			(int) mlink);
+		goto debug;
+#endif /* CONFIG_MOSIX_DIAG */
+		mlink->flags &= ~COMM_HEADINUSE;
+		goto out;
+	} else if (head == &(mlink->head)) {
+		/* default head is (supposedly) in use */
+
+#ifdef CONFIG_MOSIX_DIAG
+		if (!(mlink->flags & COMM_HEADINUSE)) {
+			printk("%s-comm_free(): inuse (sk=0x%x, comm=0x%x)\n", 
+				desc_mostask(NULL), (int) mlink->sock->sk,
+				(int) mlink);
+			goto debug;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		mlink->flags &= ~COMM_HEADINUSE;
+		goto out;
+	} else {
+		/* must be a head we previously allocated */
+#ifdef CONFIG_MOSIX_DEBUG
+		mlink->cntmem--;
+		if (mlink->cntmem < 0)
+			mosix_panic("comm_free: cntmem < 0");
+#endif /* CONFIG_MOSIX_DEBUG */
+		kfree(head);
+		return;
+	}
+
+#ifdef CONFIG_MOSIX_DIAG
+debug:
+#endif /* CONFIG_MOSIX_DIAG */
+	mosix_panic("comm_free() # 1");
+
+out:
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (!mlink->count) {
+		printk("%s-comm_free: count==0 (sk=0x%x, comm=0x%x)\n",
+			desc_mostask(NULL), (int) mlink->sock->sk, (int) mlink);
+		mosix_panic("comm_free() #2");
+		return;
+	}
+	mlink->count--;
+#endif /* CONFIG_MOSIX_DEBUG */
+}
+
+
+/*
+ * comm_mkhead() - prepares a head of size hlen
+ */
+void *
+comm_mkhead(int hlen)
+{
+	mosix_link *mlink;
+	void *head;
+
+	mlink = current->mosix.contact;
+
+	if ((mlink->flags & COMM_HEADINUSE) || hlen > COMM_DEF_HEADSIZE) {
+		head = kmalloc(hlen, GFP_KERNEL);
+		if(!head)
+			return(NULL);
+#ifdef CONFIG_MOSIX_DEBUG
+		mlink->cntmem++;
+		if (mlink->cntmem > 2)
+			mosix_panic("comm_mkhead: cntmem > 2");
+#endif /* CONFIG_MOSIX_DEBUG */
+		return (head);
+	}
+
+	head = &mlink->head;
+	mlink->flags |= COMM_HEADINUSE;
+#ifdef CONFIG_MOSIX_DEBUG
+	mlink->count++;
+#endif /* CONFIG_MOSIX_DEBUG */
+	return (head);
+}
+
+#define CMHDR(x)		((struct comm_header *)x)
+
+static char bigbuf[PAGE_SIZE], midbuf[512], smallbuf[128];
+static int bigtaken, midtaken, smalltaken;
+
+/*
+ * comm_send() - send a message (head + data)
+ */
+int
+comm_send(int type, void *head, int hlen, void *data, int dlen, int uspace)
+{
+	mosix_link *mlink;
+#ifdef CONFIG_MOSIX_DFSA
+	struct comm_header header = { 0, 0, 0, 0, 0, 0 };
+	struct iovec iov[4];
+	int dfsalen = 0;
+	char *dfsadata = NULL;
+#else
+	struct comm_header header = { 0, 0, 0, 0, 0, 0 };
+	struct iovec iov[3];
+#endif /* CONFIG_MOSIX_DFSA */
+	struct msghdr msg = { NULL, 0, iov, 0, NULL, 0, MSG_NOSIGNAL };
+	mm_segment_t oldfs = { 0 };
+	int niov = 1;
+	int size = 0;
+	void *free_head = 0;
+	int error = -ENOMEM;
+	void *tofree = NULL;
+	int *tozero = NULL;
+	void *kerdat;
+
+	if(uspace && !dirty_all_remote_pages((unsigned long)data, dlen, 0))
+	{
+		if(!smalltaken && dlen <= sizeof(smallbuf))
+		{
+			kerdat = smallbuf;
+			smalltaken = 1;
+			tozero = &smalltaken;
+		}
+		else if(!midtaken && dlen <= sizeof(midbuf))
+		{
+			kerdat = midbuf;
+			midtaken = 1;
+			tozero = &midtaken;
+		}
+		else if(!bigtaken && dlen <= sizeof(bigbuf))
+		{
+			kerdat = bigbuf;
+			bigtaken = 1;
+			tozero = &bigtaken;
+		}
+		else if(!(kerdat = tofree = kmalloc(dlen, GFP_KERNEL)))
+			return(-ENOMEM);
+		if(copy_from_user(kerdat, data, dlen))
+		{
+			if(tofree)
+				kfree(tofree);
+			return(-EFAULT);
+		}
+		uspace = 0;
+		data = kerdat;
+	}
+	DISABLE_EVENTS();
+
+	if(current->mosix.pass_regs)
+		type |= COMM_MFREGS;
+
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_check_comm_send(&type, &dfsadata, &dfsalen);
+	if(dfsalen < 0)
+	{
+		error = dfsalen;
+		goto failed;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+
+	if (current->mosix.dflags & DREMOTE)
+		current->mosix.dflags |= DPSYNC;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMSEND)
+		printk("%s-comm_send: type=%x hd=0x%x (%d) dt=0x%x (%d) %c\n",
+			desc_mostask(NULL), type, (int)head, hlen, (int)data,
+			dlen, uspace ? 'U' : 'K');
+#endif /* CONFIG_MOSIX_DEBUG */
+	mlink = current->mosix.contact;
+
+	/* validate address range if in user-space (EFAULT ?) */
+	/*if (data && uspace && !access_ok(VERIFY_READ, data, dlen)) {*/
+	if (data && uspace && !ucache_ok((unsigned long)data, dlen, VM_READ)) {
+		error = -EFAULT;
+		goto failed;
+	}
+
+	if (type & COMM_MFREGS)
+	{
+		if (!(size = comm_packregs(0, 0))) {
+			type &= ~COMM_MFREGS;
+			regs_were_sent();
+		}
+	}
+	if (type & COMM_MFIDENT)
+		size += comm_packident(0);
+	if (!size) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_COMMDOSEND)
+			printk("%s-comm_send: REGULAR\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		header.type = type;
+		header.hlen = (u_short) hlen;
+		iov[0].iov_base = &header;
+		iov[0].iov_len  = COMM_HLEN;
+		iov[1].iov_base = head;
+		iov[1].iov_len  = hlen;
+		niov++;
+	} else {
+		char *options;
+
+		/* allocate space for options - use default buffer if free */
+		size += COMM_HLEN;
+		iov[0].iov_len = size;
+		if ((mlink->flags & COMM_HEADINUSE) || size>COMM_DEF_HEADSIZE){
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_COMMDOSEND)
+				printk("%s-comm_send: 1.3  size = %d\n",
+					desc_mostask(NULL), size - COMM_HLEN);
+#endif /* CONFIG_MOSIX_DEBUG */
+			free_head = iov->iov_base = kmalloc(size, GFP_KERNEL);
+			if (!iov->iov_base)
+				goto failed;	/* xxx - error set above */
+#ifdef CONFIG_MOSIX_DEBUG
+			mlink->cntmem++;
+			if (mlink->cntmem > 2)
+				mosix_panic("comm_send: cntmem > 2");
+#endif /* CONFIG_MOSIX_DEBUG */
+		} else {
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_COMMDOSEND)
+				printk("%s-comm_send: 1.4  size = %d\n",
+					desc_mostask(NULL), size);
+#endif /* CONFIG_MOSIX_DEBUG */
+			free_head = iov->iov_base = mlink->head;
+			mlink->flags |= COMM_HEADINUSE;
+#ifdef CONFIG_MOSIX_DEBUG
+			mlink->count++;
+			if (mlink->count > 2)
+				mosix_panic("comm_send: count > 2");
+#endif /* CONFIG_MOSIX_DEBUG */
+		}
+		options = iov->iov_base + COMM_HLEN;
+		size = 0;
+		if (type & COMM_MFREGS)
+			size += comm_packregs(CMHDR(iov->iov_base), options);
+		if (type & COMM_MFIDENT)
+			size += comm_packident(options + size);
+		CMHDR(iov->iov_base)->type = type;
+		CMHDR(iov->iov_base)->hlen = (u_short) hlen;
+		iov[1].iov_base = head;
+		iov[1].iov_len  = hlen;
+		niov++;
+	}
+	CMHDR(iov->iov_base)->olen = size;
+	CMHDR(iov->iov_base)->dlen = 0;
+	size += COMM_HLEN + hlen;
+#ifdef CONFIG_MOSIX_DFSA
+	CMHDR(iov->iov_base)->dfsalen = dfsalen;
+	if(dfsalen)
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_COMMDOSEND)
+			printk("%s-comm_send: dfsadata = %d\n",
+				desc_mostask(NULL), dfsalen);
+#endif /* CONFIG_MOSIX_DEBUG */
+		iov[niov].iov_base = dfsadata;
+		iov[niov].iov_len = dfsalen;
+		size += dfsalen;
+		niov++;
+	}
+#else
+	CMHDR(iov->iov_base)->dfsalen = 0;
+#endif /* CONFIG_MOSIX_DFSA */
+	if (data) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_COMMDOSEND)
+			printk("%s-comm_send: 2  data = %d\n",
+				desc_mostask(NULL), dlen);
+#endif /* CONFIG_MOSIX_DEBUG */
+		CMHDR(iov->iov_base)->type |= COMM_MFDATA;
+		CMHDR(iov->iov_base)->dlen = dlen;
+		iov[niov].iov_base = data;
+		iov[niov].iov_len  = dlen;
+		size += dlen;
+		niov++;
+	}
+
+	msg.msg_iovlen = niov;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMDOSEND)
+		printk("%s-comm_send: totsize=%d niov=%d (hlen=%d olen=%d)\n",
+			desc_mostask(NULL), size, niov,
+			CMHDR(iov->iov_base)->hlen, CMHDR(iov->iov_base)->olen);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	add_mosix_log(current, MOSIX_LOG_SENDTYPE, type);
+	add_mosix_log_hdr(current, MOSIX_LOG_SENDHDR,
+		CMHDR(iov->iov_base)->hlen, CMHDR(iov->iov_base)->olen);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_COMMDOSEND)
+		printk("sock=0x%x  msg=0x%x  size=%d\n",
+			(int)current->mosix.contact, (int)&msg,size);
+#ifdef CONFIG_MOSIX_UDB
+	if ((ds_debug & DSDEB_COMMSEND) && ds_debug != -1 &&
+		(ds_debug & DSDEB_DEBUGSEND)) mosix_debugger("after sending..");
+#endif /* CONFIG_MOSIX_UDB */
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	error = mlink->sock->ops->sendmsg(mlink->sock, &msg, size, NULL);
+	set_fs(oldfs);
+
+	add_mosix_log_ret(current, error);
+
+	if (free_head)
+		comm_free(free_head);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if ((ds_debug & DSDEB_COMMDOSEND) ||
+		(error < 0 && (ds_debug & DSDEB_ERROR)))
+		printk("%s-comm_send: result %d\n", desc_mostask(NULL), error);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if((type & COMM_MFREGS) && error >= 0)
+		regs_were_sent();
+failed:
+	ENABLE_EVENTS();
+#ifdef CONFIG_MOSIX_DFSA
+	if (dfsadata)
+		kfree(dfsadata);
+#endif /* CONFIG_MOSIX_DFSA */
+	if(tofree)
+		kfree(tofree);
+	if(tozero)
+		*tozero = 0;
+	return (error < 0 ? error : 0);
+}
+
+
+/*
+ * comm_dorecv() - reliably read data from socket
+ *   on success, or if error == -EFAULT: returns number of bytes received
+ *   otherwise (any other error): returns negative error.
+ */
+static int
+comm_dorecv(struct socket *sock, struct msghdr *msg, int len)
+{
+	int n = 0;
+	int left = len;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMDORECV)
+		printk("%s-comm_dorecv: sock 0x%x, msg 0x%x, len %d\n",
+			desc_mostask(NULL), (int)sock, (int)msg, len);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	do {
+		current->mosix.commpri = 1;
+		n = sock->ops->recvmsg(sock, msg, left, msg->msg_flags, 0);
+		current->mosix.commpri = 0;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_COMMDORECV)
+			printk("%s-comm_dorecv: n=%d\n", desc_mostask(NULL), n);
+#endif /* CONFIG_MOSIX_DEBUG */
+#ifdef CONFIG_MOSIX_DIAG
+		if (n == -EINTR || n == -EAGAIN || n == -ERESTARTSYS) {
+			printk("%s-comm_dorecv: EINTR,EAGAIN,ERESTARTSYS %d\n",
+				desc_mostask(NULL), n);
+#ifdef CONFIG_MOSIX_UDB
+			mosix_panic("comm_dorecv() - 1");
+			return (-EINTR);   /* never mind data: this is fatal */
+#else
+			panic("comm_dorecv() - 1");
+#endif /* CONFIG_MOSIX_UDB */
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		if (n <= 0) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & (DSDEB_ERROR))
+				printk("%s-comm_dorecv: error %d\n",
+					desc_mostask(NULL), n);
+#endif /* CONFIG_MOSIX_DEBUG */
+			/* if we already got -EFAULT, we must report */
+			if (n == -EFAULT) {
+				for ( ; msg->msg_iovlen; msg->msg_iov++,
+							 msg->msg_iovlen--)
+					 len -= msg->msg_iov->iov_len;
+				return (len);
+			}
+
+			/* .. otherwise - it is fatal - return error */
+			if (n < 0) 
+				return (n);
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & (DSDEB_COMM | DSDEB_ERROR))
+				printk("%s-comm_dorecv: EOF\n",
+					desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+			return (-EPIPE);
+		}
+
+		left -= n;
+		if (left) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_COMMRECV)
+				printk("%s-comm_dorecv: read %d out of %d\n",
+					desc_mostask(NULL), n, left + n);
+#endif /* CONFIG_MOSIX_DEBUG */
+			/* ...->recvmsg() updated iovec, we update msg */
+			while (!msg->msg_iov->iov_len) {
+				msg->msg_iov++;
+				msg->msg_iovlen--;
+			}
+		}
+	} while (left);
+	return (len);
+}
+				
+
+/*
+ * comm_recv() - receive a message head
+ */
+int
+comm_recv(void **headp, int *hlen)
+{
+	struct comm_header header;
+	mosix_link *mlink = current->mosix.contact;
+	char *head = 0, *options = 0;
+	struct iovec iov[2];
+	struct msghdr msg =
+		{ NULL, 0, iov, 1, NULL, 0, MSG_WAITALL | MSG_NOSIGNAL };
+	mm_segment_t oldfs;
+	int niov = 0;
+	int size;
+	int error = -EDIST;
+#ifdef CONFIG_MOSIX_DFSA
+	char *dfsadata = NULL;
+#endif /* CONFIG_MOSIX_DFSA */
+
+	if (!mlink)
+	{
+		if (current->mosix.dflags & (DDEPUTY|DREMOTE))
+			panic("comm_recv: null contact\n");
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMM)
+			printk("%s-comm_recv: EX-deputy\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		return(-EDIST);
+	}
+	DISABLE_EVENTS();
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (mlink->dlen)
+		panic("comm_recv: there is data in the socket");
+#endif /* CONFIG_MOSIX_DIAG */
+		
+	/* if we're not connected yet we should first accept a connection */
+	if (mlink->flags & COMM_WAITACCEPT) {
+		if (comm_waitaccept())
+			goto edist;
+		mlink = current->mosix.contact;
+	}
+	
+	iov[0].iov_base = &header;
+	iov[0].iov_len  = COMM_HLEN;
+
+	add_mosix_log(current, MOSIX_LOG_RECEIVE, 0);
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	if ((error = comm_dorecv(mlink->sock, &msg, COMM_HLEN)) != COMM_HLEN) {
+		if (error >= 0)
+			error = -EFAULT;
+		goto failed;
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMRECV)
+		printk("%s-comm_recv: type=0x%x olen=%d hlen=%d dlen=%d\n",
+			desc_mostask(NULL), header.type, header.olen,
+			header.hlen, header.dlen);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	size = header.hlen + header.olen;
+	if (size && !(head = comm_mkhead(size)))
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-comm_recv: comm_mkhead failed!", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DIAG */
+		error = -ENOMEM;
+		goto failed;
+	}
+
+	if (header.olen || (header.type & COMM_MFHEADOPTS)) {
+#ifdef CONFIG_MOSIX_DIAG
+		if ((header.type & COMM_MFHEADOPTS) == 0 || !header.olen) {
+			printk("%s-comm_recv(): olen mismatch 0x%x\n",
+				desc_mostask(NULL), (int) &header);
+			mosix_panic("olen mismatch");
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+
+		/* the options will be placed after the message head */
+		options = head + header.hlen;
+		iov[0].iov_base = options;
+		iov[0].iov_len  = header.olen;
+		niov++;
+	}
+	if (header.hlen) {
+		iov[niov].iov_base = head;
+		iov[niov].iov_len  = header.hlen;
+		niov++;
+	}
+	
+	msg.msg_iovlen = niov;
+	if (niov && (error = comm_dorecv(mlink->sock, &msg, size)) != size) {
+		if (error >= 0)
+			error = -EFAULT;
+		goto failed;
+	}
+
+#ifdef CONFIG_MOSIX_DFSA
+	if (header.dfsalen)
+	{
+		if(!(dfsadata = kmalloc(header.dfsalen, GFP_KERNEL)))
+		{
+			printk("%s-comm_recv: failed to allocate DFSA space\n",
+				desc_mostask(NULL));
+			error = -ENOMEM;
+			goto failed;
+		}
+		iov[0].iov_base = dfsadata;
+		iov[0].iov_len = header.dfsalen;
+		msg.msg_iovlen = 1;
+		if ((error = comm_dorecv(mlink->sock, &msg, header.dfsalen)) !=
+								header.dfsalen)
+		{
+			kfree(dfsadata);
+			if (error >= 0)
+				error = -EFAULT;
+			goto failed;
+		}
+	}
+	if(header.type & COMM_MFDFSAOPTS)
+		dfsa_comm_recv(header.type, dfsadata);
+#ifdef CONFIG_MOSIX_DIAG
+	else if(dfsadata)
+		mosix_panic("dfsadata, but no flags");
+#endif /* CONFIG_MOSIX_DIAG */
+#endif /* CONFIG_MOSIX_DFSA */
+	if (header.type & COMM_MFDATA)
+		mlink->dlen = header.dlen;
+
+	size = 0;
+	if ((header.type & COMM_MFREGS) &&
+			(size = comm_unpackregs(&header, options)) < 0) {
+		goto edist;
+	}
+	options += size;
+	if ((header.type & COMM_MFIDENT) &&
+			(size = comm_unpackident(options)) < 0) {
+		goto edist;
+	}
+	options += size;
+	error = header.type & ~COMM_MFOPTIONS;	/* return value :-) */
+	if (hlen)
+		*hlen = header.hlen;
+
+	add_mosix_log(current, MOSIX_LOG_RECVTYPE, error);
+	goto done;
+
+edist:
+	error = -EDIST;
+failed:
+	if (head)
+		comm_free(head);
+#ifdef CONFIG_MOSIX_DIAG
+	if (error == -EINTR || error == -EAGAIN || error == -ERESTARTSYS)
+		panic("comm_recv: invalid error");
+	if (error == -EFAULT) {
+		printk("%s-comm_recv: got error -EFAULT\n", desc_mostask(NULL));
+		mosix_panic("EFAULT(1)");
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_ERROR | DSDEB_COMMRECV))
+		printk("%s-comm_recv: failed error=%d\n", desc_mostask(NULL),
+									error);
+#endif /* CONFIG_MOSIX_DEBUG */
+	comm_shutdown(mlink);
+	head = NULL;
+done:
+	/* the caller knows what she wants; from the type she knows the
+	   message is empty, and will not free it -> we do it ourselves */
+	if (!header.hlen) {
+		comm_free(head);
+		head = NULL;
+	}
+
+	add_mosix_log_ret(current, error);
+	ENABLE_EVENTS();
+	set_fs(oldfs);
+	*headp = head;
+	return (error);
+}
+
+/*
+ * comm_copydata() - copy data from the message (possibly to USPACE)
+ *   if 'uspace': returns 0 on success or result from comm_dorecv()
+ *   else: returns 0 on success, error otherwise (partial read -> panic)
+ */
+int
+comm_copydata(void *data, int len, int uspace)
+{
+	mosix_link *mlink;
+	struct iovec iov;
+	struct msghdr msg =
+		{ NULL, 0, &iov, 1, NULL, 0, MSG_WAITALL | MSG_NOSIGNAL };
+	int error = 0;
+	mm_segment_t oldfs = { 0 };
+#ifdef CONFIG_MOSIX_DIAG
+	int zero_ok = 0;
+#endif /* CONFIG_MOSIX_DIAG */
+
+	if(uspace && !dirty_all_remote_pages((unsigned long)data, len, 1))
+		return(-ENOMEM);
+	DISABLE_EVENTS();
+
+	mlink = current->mosix.contact;
+	if(mlink->dlen == 0 && mlink->hidebuf)
+	{
+		mlink->flags |= COMM_HIDEDATA;
+		mlink->dlen = mlink->hidelen;
+		mlink->hidelen = 0;
+	}
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(len & COMM_ZEROCOPYOK)
+	{
+		len &= ~COMM_ZEROCOPYOK;
+		zero_ok = 1;
+	}
+	if (len <= 0) {
+		printk("%s-comm_copydata(): invalid length %d\n",
+			desc_mostask(NULL), len);
+		panic("comm_copydata(): invalid length");
+	} else if (mlink->dlen < len) {
+		if (!mlink->dlen)
+		{
+			if(zero_ok)
+				goto out;
+			printk("%s-comm_copydata(): no data (mlink=0x%x)\n",
+				desc_mostask(NULL), (int) mlink);
+		}
+		else
+			printk("%s-comm_copydata(): not enough (mlink=0x%x)\n",
+				desc_mostask(NULL), (int) mlink);
+		panic("comm_copydata(): mlink->dlen < len");
+	}
+#else
+	if(!mlink->dlen)
+		goto out;
+	len &= ~COMM_ZEROCOPYOK;
+#endif /* CONFIG_MOSIX_DIAG */
+
+	if (mlink->flags & COMM_HIDEDATA) {
+		if (uspace)
+			error = copy_to_user(data, mlink->hideptr, len);
+		else
+			memcpy(data, mlink->hideptr, len);
+		
+		/* NOTE: at this point page-fault *cannot* happen */
+		mlink->dlen -= len;
+		mlink->hideptr += len;
+		if (!mlink->dlen) {
+			kfree(mlink->hidebuf);
+			mlink->hideptr = NULL;
+			mlink->hidebuf = NULL;
+			mlink->flags &= ~COMM_HIDEDATA;
+		}
+		if (error) {
+			error = -EFAULT;
+			goto do_error;
+		}
+		goto out;
+	}
+
+	if (!uspace) {			/* switch to (KSPACE) */
+		oldfs = get_fs();
+		set_fs(KERNEL_DS);
+	}
+
+	iov.iov_base = data;
+	iov.iov_len  = len;
+
+	error = comm_dorecv(mlink->sock, &msg, len);
+
+	if (error == len) {
+		error = 0;
+		mlink->dlen -= len;
+	} else if (error < 0) {
+
+	do_error:
+#ifdef CONFIG_MOSIX_DIAG
+		if (error == -EFAULT && !uspace)
+			panic("comm_copydata: (2) got -EFAULT not in uspace");
+#endif /* CONFIG_MOSIX_DIAG */
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug)
+			printk("comm_copydata: wanted %d bytes, got %d\n",
+				len, error);
+#endif /* CONFIG_MOSIX_DEBUG */
+		if (error != -EFAULT)
+			comm_shutdown(mlink);
+	} else {
+#ifdef CONFIG_MOSIX_DIAG
+		if (!uspace)
+			panic("comm_copydata: (1) got -EFAULT not in uspace");
+#endif /* CONFIG_MOSIX_DIAG */
+		mlink->dlen -= error;
+		error = len - error;
+	}
+
+	if (!uspace)
+		set_fs(oldfs);
+
+out:
+	ENABLE_EVENTS();
+	return (error);
+}
+
+
+/*
+ * comm_recvdata() - receive entire data to an allocated buffer 
+ */
+int
+comm_recvdata(void **data)
+{
+	mosix_link *mlink;
+	char *buf;
+	struct iovec iov;
+	struct msghdr msg =
+		{ NULL, 0, &iov, 1, NULL, 0, MSG_WAITALL | MSG_NOSIGNAL};
+	mm_segment_t oldfs;
+	int error = 0;
+
+	DISABLE_EVENTS();
+
+	mlink = current->mosix.contact;
+	if(mlink->dlen == 0 && mlink->hidebuf)
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		/* while this should be OK, we have no reason to reach here */
+		printk("comm_recvdata of previously hidden?");
+#endif /* CONFIG_MOSIX_DIAG */
+		mlink->flags |= COMM_HIDEDATA;
+		mlink->dlen = mlink->hidelen;
+		mlink->hidelen = 0;
+	}
+#ifdef CONFIG_MOSIX_DIAG
+	if (!mlink->dlen) {
+		printk("%s-comm_recvdata(): no data (mlink = 0x%x)\n",
+			desc_mostask(NULL), (int) mlink);
+		panic("comm_recvdata(): mlink->dlen < len");
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	/* data was hidden: simply hand the hidden data to the caller */
+	if (mlink->flags & COMM_HIDEDATA) {
+		/* actually, we never reach here in real-life */
+
+		*data = mlink->hidebuf;
+
+		/* test for the pathologic case of calling comm_recvdata()
+		   after a partial call to comm_copydata() ...*/
+		if (mlink->hidebuf != mlink->hideptr)
+			panic("comm_recvdata: hide pathology");
+
+		mlink->hideptr = NULL;
+		mlink->hidebuf = NULL;
+
+#ifdef CONFIG_MOSIX_DEBUG
+		mlink->cntmem++;
+		if (mlink->cntmem > 2)
+			mosix_panic("comm_recvdata: cntmem > 2");
+#endif /* CONFIG_MOSIX_DEBUG */
+		goto out;
+	}
+
+	buf = comm_malloc(mlink->dlen);
+#ifdef CONFIG_MOSIX_DEBUG
+	mlink->cntmem++;
+	if (mlink->cntmem > 2)
+		mosix_panic("comm_recvdata: cntmem > 2");
+#endif /* CONFIG_MOSIX_DEBUG */
+	iov.iov_base = buf;
+	iov.iov_len  = mlink->dlen;
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	error = comm_dorecv(mlink->sock, &msg, mlink->dlen);
+	set_fs(oldfs);
+	if (error != mlink->dlen) {
+		if (error >= 0)
+			error = -EFAULT;
+		kfree(buf);
+#ifdef CONFIG_MOSIX_DEBUG
+		mlink->cntmem--;
+#endif /* CONFIG_MOSIX_DEBUG */
+		comm_shutdown(mlink);
+		*data = 0;
+	} else {
+		error = 0;
+		*data = buf;
+	}
+
+out:
+	mlink->dlen = 0;
+	ENABLE_EVENTS();
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (error == -EFAULT) {
+		printk("%s-comm_recvdata: got error -EFAULT\n",
+			desc_mostask(NULL));
+		mosix_panic("EFAULT(1)");
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	return (error);
+}
+
+
+/*
+ * comm_hidedata() - hide data (possibly exisiting) in the socket,
+ * to allow the socket to be used for a page-fault. The data is put
+ * in a buffer pointed to by comm->hide.
+ */
+int
+comm_hidedata()
+{
+	mosix_link *mlink;
+	struct iovec iov;
+	struct msghdr msg =
+		{ NULL, 0, &iov, 1, NULL, 0, MSG_WAITALL | MSG_NOSIGNAL};
+	mm_segment_t oldfs;
+	int error = 0;
+
+	mlink = current->mosix.contact;
+
+	/* if already hidden, or no data - return */
+	if (mlink->hidebuf || !mlink->dlen)
+		return(0);
+
+	DISABLE_EVENTS();
+
+	mlink->hideptr = mlink->hidebuf = comm_malloc(mlink->dlen);
+
+	iov.iov_base = mlink->hidebuf;
+	iov.iov_len  = mlink->dlen;
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	error = comm_dorecv(mlink->sock, &msg, mlink->dlen);
+	set_fs(oldfs);
+	if (error != mlink->dlen) {
+		comm_shutdown(mlink);
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_ERROR)
+			printk("%s-comm_hidedata: error %d\n",
+				desc_mostask(NULL), error);
+#endif /* CONFIG_MOSIX_DEBUG */
+	} else
+		error = 0;
+	mlink->hidelen = mlink->dlen;
+	mlink->dlen = 0;
+	ENABLE_EVENTS();
+
+	return (error);
+}
+
+/*
+ * comm_flushdata() - flush remaining data from previous message
+ */
+void
+comm_flushdata(int dlen)
+{
+	mosix_link *mlink;
+	struct iovec iov;
+	struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0, 0 };
+	mm_segment_t oldfs;
+	int n = 0;
+#define COMM_FLUSH_BUF_SIZE	256
+	static char comm_flush_buffer[COMM_FLUSH_BUF_SIZE];	/* global bin */
+
+	mlink = current->mosix.contact;
+	if(mlink->dlen == 0 && mlink->hidebuf)
+	{
+		mlink->flags |= COMM_HIDEDATA;
+		mlink->dlen = mlink->hidelen;
+		mlink->hidelen = 0;
+	}
+	if (dlen == COMM_ALLDATA && !(dlen = mlink->dlen))
+		return;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_COMMRECV | DSDEB_COMMSEND))
+		printk("%s-comm_flushdata:  dlen = %d\n",
+			desc_mostask(NULL), dlen);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (mlink->dlen < dlen) {
+		printk("%s-comm_flushdata(): no data (mlink = 0x%x)\n",
+			desc_mostask(NULL), (int) mlink);
+		panic("comm_flushdata(): mlink->dlen < len");
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	if (mlink->flags & COMM_HIDEDATA) {
+		mlink->hideptr += mlink->dlen;
+		mlink->dlen -= dlen;
+		if (!mlink->dlen) {
+			kfree(mlink->hidebuf);
+			mlink->hidebuf = NULL;
+			mlink->hideptr = NULL;
+			mlink->flags &= ~COMM_HIDEDATA;
+		}
+		return;
+	}
+
+	DISABLE_EVENTS();
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	while (dlen)
+	{
+		iov.iov_base = comm_flush_buffer;
+		iov.iov_len = (dlen < COMM_FLUSH_BUF_SIZE) ? dlen :
+							COMM_FLUSH_BUF_SIZE;
+		msg.msg_flags = MSG_WAITALL | MSG_NOSIGNAL;
+		if ((n = comm_dorecv(mlink->sock, &msg, iov.iov_len)) <= 0)
+			break;
+		dlen -= n;
+		mlink->dlen -= n;
+	}
+	set_fs(oldfs);
+	if (n <= 0) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & (DSDEB_ERROR | DSDEB_COMMSEND | DSDEB_COMMRECV))
+			printk("%s-comm_flushdata: err %d\n",
+				desc_mostask(NULL), n);
+#endif /* CONFIG_MOSIX_DEBUG */
+		comm_shutdown(current->mosix.contact);
+	}
+	ENABLE_EVENTS();
+}
+
+
+#define POLLIN_SET	(POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
+
+/*
+ * comm_peek() - peek the socket looking for data pending 
+ */
+int
+comm_peek(void)
+{
+	struct socket *sock;
+	int mask;
+
+	sock = current->mosix.contact->sock;
+#ifdef CONFIG_MOSIX_DIAG
+	if (!sock) {
+		mosix_panic("comm_peek: no sock");
+		return (-EDIST);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+		
+	mask = sock->ops->poll(NULL, sock, NULL);
+	return ((mask & POLLIN_SET) ? 1 : 0);
+}
+
+
+/*
+ * comm_poll() - wait for a communication event, interrupt or MOSIX event
+ * returns 1 on communication events, and 0 otherwise
+ */
+static int
+comm_poll(int mask, int interruptible, unsigned long timo)
+{
+	struct socket *sock;
+	int pollmask;
+	static struct file sighfile = {f_count: ATOMIC_INIT(1)};
+	DECLARE_WAITQUEUE(wait, current);
+
+	/*
+	 * sighfile: we are required to supply a file to "hold" while we poll.
+	 * a bit ridiculous in this context, but nobody will notice because
+	 * f_count will never drop to 0
+	 */
+	sock = current->mosix.contact->sock;
+	if(!timo)
+		timo = MAX_SCHEDULE_TIMEOUT;
+	add_wait_queue(sock->sk->sleep, &wait);
+	for (;;) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		pollmask = sock->ops->poll(&sighfile, sock, NULL);
+		if ((pollmask & mask) ||
+		    (interruptible && signal_pending(current)))
+			break;
+		current->mosix.commpri = 1;
+		timo = schedule_timeout(timo);
+		current->mosix.commpri = 0;
+		if (timo <= 0)
+			break;
+	}
+	remove_wait_queue(sock->sk->sleep, &wait);
+	set_current_state(TASK_RUNNING);
+	return ((pollmask & mask) ? 1 : 0);
+}
+
+
+/*
+ * comm_wait() - wait for a message, or some other MOSIX event
+ * return 1 if there is a message, 0 if another event occured first.
+ */
+int
+comm_wait(void)
+{
+	return (comm_poll(POLLIN_SET, 1, 0UL));
+}
+
+/*
+ * comm_send_urgent() - send notification using urgent data (OOB)
+ */
+int
+comm_send_urgent(void)
+{
+	struct iovec iov;
+	struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0, MSG_OOB|MSG_NOSIGNAL };
+	mm_segment_t oldfs;
+	int error;
+	unsigned char dummy;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (!(current->mosix.dflags & DREMOTE))
+		panic("comm_send_urgent: not REMOTE");
+#endif /* CONFIG_MOSIX_DIAG */
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_COMMSEND | DSDEB_WHERETO))
+		printk("%s-comm_send_urgent: notifying\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	dummy = 0xdb;
+	iov.iov_base = &dummy;
+	iov.iov_len  = 1;
+
+	add_mosix_log(current, MOSIX_LOG_SENDURG, 0xffff);
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	error = current->mosix.contact->sock->ops->
+			sendmsg(current->mosix.contact->sock, &msg, 1, 0);
+
+	set_fs(oldfs);
+
+	add_mosix_log_ret(current, error);
+
+	return(0);
+}
+
+/*
+ * comm_test_urgent() - test if urgent data is pending (OOB)
+ */
+int
+comm_test_urgent(void)
+{
+#ifdef CONFIG_MOSIX_DIAG
+	if (!(current->mosix.dflags & DDEPUTY))
+		panic("comm_test_urgent: not DEPUTY");
+#endif /* CONFIG_MOSIX_DIAG */
+
+	return(test_bit(SOCK_OOB_IN, &current->mosix.contact->sock->flags));
+}
+
+/*
+ * comm_take_urgent() - take the pending OOB out of the stream,
+ *   preventing it from turning into a normal byte.
+ *   Caller must make sure that there is no other data in the stream.
+ */
+void
+comm_take_urgent(void)
+{
+	int was = test_and_clear_bit(SOCK_OOB_IN,
+					&current->mosix.contact->sock->flags);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(!was && (ds_debug & DSDEB_WHERETO))
+		printk("%s-comm_take_urgent: was not there!\n",
+			desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	add_mosix_log(current, MOSIX_LOG_RECVURG, was);
+}
+
+void
+mosix_notify_urgent(struct socket *sock)
+{
+	struct task_struct *p;
+
+	set_bit(SOCK_OOB_IN, &sock->flags);
+	if (!(p = find_task_by_sock(sock)))
+		return;
+	spin_unlock(&skown_lock);
+	if (p->mosix.dflags & DDEPUTY)
+	{
+		tell_process(p, DREQ_URGENT);
+		wake_up_mosix(p);
+		add_mosix_log(p, MOSIX_LOG_RECVURG, 0xffff);
+	}
+	free_task_struct(p);
+}
+
+void
+mosix_notify_receive(struct socket *sock)
+{
+	struct task_struct *p = find_task_by_sock(sock);
+
+	if(!p)
+		return;
+#ifdef CONFIG_MOSIX_FS
+	if(p == mfs_main_server_task)
+	{
+		spin_unlock(&skown_lock);
+		mfs_new_request_arrived();
+		goto free_task;
+	}
+	if(test_bit(SOCK_WAIT_MFSDATA, &sock->flags))
+	{
+		spin_unlock(&skown_lock);
+		wake_up_process(p);
+		goto free_task;
+	}
+#endif /* CONFIG_MOSIX_FS */
+	spin_unlock(&skown_lock);
+
+	if(!(p->mosix.dflags & DREMOTE))
+	{
+		if (!(p->mosix.dflags & (DDEPUTY|DREMOTEDAEMON|DFINISHED)))
+			printk("mosix_notify_receive: pid = %d, "
+				"not DEPUTY or REMOTE\n", p->pid);
+		goto free_task;
+	}
+
+	p->mosix.commpri = 1;
+	current->need_resched = 1;
+	wake_up_mosix(p);
+	free_task:
+	free_task_struct(p);
+}
+
+/*
+ * comm_sendto() - send a datagram to someone
+ */
+int
+comm_sendto(int mos, void *data, int len, mosix_link *mlink, mosix_addr *to)
+{
+	struct iovec iov = {data, len};
+	struct sockaddr sa;
+	struct msghdr msg = {NULL, 0, &iov, 1, NULL, 0, MSG_NOSIGNAL};
+	mm_segment_t oldfs;
+	int error = -EDIST;
+
+	if (to)
+		sa = to->saddr;
+	else if (!comm_set_address(-mos, &sa, 0))
+		return (error);
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (len <= 0) {
+		mosix_panic("comm_sendto: zero size message");
+		return(-EDIST);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	msg.msg_name = &sa;
+	msg.msg_namelen = sizeof(sa);
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	error = mlink->sock->ops->sendmsg(mlink->sock, &msg, len, NULL);
+
+	set_fs(oldfs);
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!error) {
+		mosix_panic("comm_sendto: sendmsg returned zero");
+		return(-EDIST);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	return (error);
+}
+
+
+/*
+ * comm_recvfrom() - receive a datagram from someone
+ * NOTE NOTE NOTE:  the timeout is in microseconds -- NOT ticks!
+ */
+int
+comm_recvfrom(void *data, int len, mosix_link *mlink, mosix_addr *from,
+	unsigned long timo)
+{
+	struct iovec iov = {data, len};
+	struct msghdr msg = { &from->saddr, sizeof(struct sockaddr),
+			      &iov, 1, NULL, 0, 0 };
+	mm_segment_t oldfs;
+	int error;
+	int nrecv = len, msgflg = 0;
+	DECLARE_WAITQUEUE(wait, current);
+
+	if(timo)
+	{
+#if MILLION % HZ
+		timo = timo * HZ / MILLION;
+#else
+		timo = timo / (MILLION/HZ);
+#endif
+	}
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	if (timo)
+		msgflg |= MSG_DONTWAIT;
+	else
+		timo = MAX_SCHEDULE_TIMEOUT;
+
+	add_wait_queue(mlink->sock->sk->sleep, &wait);
+	while (1) {
+		set_current_state(
+			msgflg ? TASK_UNINTERRUPTIBLE : TASK_INTERRUPTIBLE);
+
+		error = mlink->sock->ops->recvmsg(mlink->sock, &msg,
+							nrecv, msgflg, 0);
+		if(error >= 0 && !net_to_mos((mosix_addr *)&from->saddr))
+		{
+			comm_report_violation("information", &from->saddr);
+			error = -EPERM;
+			break;
+		}
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_INFO)
+			printk("comm_recvfrom: recvmsg=%d\n", error);
+		if (error == 0)	/* zero-size attack */
+			error = -ERESTART;
+#endif /* CONFIG_MOSIX_DEBUG */
+		if (error > 0)
+			break;
+
+		if (msgflg && timo <= 0) {
+			error = -EWOULDBLOCK;
+			break;
+		}
+
+		timo = schedule_timeout(timo);
+
+		if (signal_pending(current)) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_INFO)
+				printk("%s: comm_recvfrom interrupted\n",
+					desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+			error = -EINTR;
+			break;
+		}
+	}
+	remove_wait_queue(mlink->sock->sk->sleep, &wait);
+	set_current_state(TASK_RUNNING);
+	set_fs(oldfs);
+	
+	if (msg.msg_flags & MSG_TRUNC) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_INFO)
+			printk("%s-comm_recvfrom: message truncated\n",
+				desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		error = -EDIST;
+	}
+	
+	return (error);
+}
+
+
+/*
+ * comm_recvfrompe() - wrapper for comm_recvfrom, fills in mosix id
+ * instead of source address.
+ * NOTE NOTE NOTE:  the timeout is in microseconds -- NOT ticks!
+ */
+int
+comm_recvfrompe(void *data, int len, mosix_link *mlink,
+				  int *from, unsigned long timo)
+{
+	int error;
+	struct mosix_addr maddr;
+
+	error = comm_recvfrom(data, len, mlink, from ? &maddr : NULL, timo);
+	if (from)
+		*from = net_to_mos(&maddr);
+	return (error);
+}
+
+
+/*
+ * routines for debugging (can call from debugger)
+ */
+inline void
+comm_invalidate_address(mosix_addr *ma)
+{
+	ma->saddr.sa_family = AF_UNSPEC;
+}
+
+
+static inline struct socket *
+comm_set_address(int mos, struct sockaddr *sa, int makesock)
+{
+	switch (comm_type) {
+		case AF_INET:
+			return (comm_ip_set_addr(mos, sa, makesock));
+			/* NOT REACHED */
+		case AF_UNSPEC:
+			if (mos == COMM_TOADDR)
+				return (0);
+			/* FALL THROUGH */	
+		default:
+			panic("comm_set_address: unknown comm_type");
+			return(0);
+	}
+}
+
+
+/*
+ * comm_getname: fill in our name
+ */
+static int
+comm_getname(struct socket *sock, struct sockaddr *saddr)
+{
+	switch (comm_type) {
+		case AF_INET:
+			return (comm_ip_getname(sock, saddr));
+			break;
+		default:
+			panic("comm_getname: invalid comm_type");
+	}
+}
+
+/*
+ * comm_shutdown: shutdown socket
+ */
+static void
+comm_shutdown(mosix_link *mlink)
+{
+	struct socket *sock;
+	if (!mlink)
+		return;
+	sock = mlink->sock;
+#ifdef CONFIG_MOSIX_DIAG
+	if(!sock)
+	{
+		mosix_panic("comm_shutdown: no sock");
+		return;
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	spin_lock_irq(&skown_lock);
+	sock->sk->owner = NULL;
+	clear_bit(SOCK_INTER_MOSIX, &sock->flags);
+	spin_unlock_irq(&skown_lock);
+	if (mlink->flags & COMM_FULLLINK) {
+		if (mlink->hidebuf) {
+			kfree(mlink->hidebuf);
+			mlink->hidebuf = NULL;
+			mlink->hideptr = NULL;
+			mlink->hidelen = 0;
+		}
+		mlink->dlen = 0;
+	}
+	mlink->flags &= ~(COMM_WAITACCEPT | COMM_HIDEDATA);
+	if (sock->ops)
+		sock->ops->shutdown(sock, SEND_SHUTDOWN);
+}
+
+static inline struct socket *
+comm_ip_set_addr(int mos, struct sockaddr *saddr, int makesock)
+{
+	struct sockaddr_in *sa;
+	struct socket *sock = (struct socket *) 1;	/* xxx - not NULL */
+	int proto = IPPROTO_TCP;
+	int type = SOCK_STREAM;
+	unsigned short port = MIG_DAEMON_PORT;
+
+	sa = (struct sockaddr_in *) saddr;
+	switch (mos) {
+	case COMM_LOOSE:
+		type = SOCK_DGRAM;
+		proto = IPPROTO_UDP;
+		port = INFO_DAEMON_PORT;
+		break;
+	case COMM_TOADDR:
+		/* address was set by the caller */
+		break;
+	case COMM_INFO:
+		proto = IPPROTO_UDP;
+		type = SOCK_DGRAM;
+		/* fall through */
+	case COMM_MIGD:
+		memset((void *)sa, 0, sizeof(struct sockaddr_in));
+	        sa->sin_family = AF_INET;
+		sa->sin_addr.s_addr = INADDR_ANY;
+		if (mos == COMM_MIGD)
+			sa->sin_port = MIG_DAEMON_PORT;
+		else
+			sa->sin_port = INFO_DAEMON_PORT;
+		break;
+	case COMM_ACCEPT:
+		memset((void *)sa, 0, sizeof(struct sockaddr_in));
+	        sa->sin_family = AF_INET;
+		sa->sin_addr.s_addr = INADDR_ANY;
+		sa->sin_port = 0;
+		break;
+	default:
+		if (mos < 0) {
+			type = SOCK_DGRAM;
+			proto = IPPROTO_UDP;
+			port = INFO_DAEMON_PORT;
+			mos = -mos;
+		}
+
+		if (!mos_to_net(mos, saddr)) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug)
+				printk("comm_ip_set_addr, mos=%d: error1\n",
+									mos);
+#endif /* CONFIG_MOSIX_DEBUG */
+			return (0);
+		}
+		sa->sin_port = port;
+		break;
+	}
+
+	if (makesock && sock_create(AF_INET, type, proto, &sock)) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_COMMOPEN)
+			printk("%s-comm_ip_set_addr: sock_create failed\n",
+				desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		return (0);
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_COMMADDR)
+		printk("%s-comm_ip_set_addr: m=%d, ip=%x, t=%d, s=%x, p=%d \n",
+			desc_mostask(NULL), mos, sa->sin_addr.s_addr, type,
+			(int) sock, sa->sin_port);
+#endif /* CONFIG_MOSIX_DEBUG */
+	
+	return (sock);
+}
+
+
+/*
+ * comm_ip_getname: fill in our name
+ */
+static inline int
+comm_ip_getname(struct socket *sock, struct sockaddr *saddr)
+{
+	int val;
+	struct sockaddr_in sa;
+	int error;
+
+	val = sizeof(sa);
+	error = sock->ops->getname(sock, (struct sockaddr *)&sa, &val, 0);
+	if(!error)
+	{
+		error = mymos_to_net((void *)saddr);
+		((struct sockaddr_in *)saddr)->sin_port = sa.sin_port;
+	}
+	return (error);
+}
+
+
+/*
+ * comm_migration_mode() - setup parameters for migration mode (on/off)
+ */
+void
+comm_migration_mode(int on)
+{
+	switch (comm_type) {
+		case AF_INET:
+			comm_ip_migration_mode(on);
+			break;
+		default:
+			panic("comm_setup_socket: unknown comm_type");
+	}
+}
+
+
+/*
+ * comm_ip_migration_mode() - setup parameters for migration mode (on/off)
+ */
+void
+comm_ip_migration_mode(int on)
+{
+	int val = on ? 0 : 1;
+	mm_segment_t oldfs;
+	int error;
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	error = current->mosix.contact->sock->ops->setsockopt(
+		current->mosix.contact->sock, IPPROTO_TCP,
+		TCP_NODELAY, (char *) &val, sizeof(val));
+#ifdef CONFIG_MOSIX_DEBUG
+	if (error & (ds_debug & DSDEB_ERROR)) {
+		printk("%s-comm_ip_migration_mode: failed (%d)\n",
+			desc_mostask(NULL), error);
+	}
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	set_fs(oldfs);
+}
+
+
+void
+comm_data_ready(struct sock *sk, int len)
+{
+#ifdef CONFIG_MOSIX_DIAG
+	if (sk->dead)
+		panic("comm_data_ready: sk->dead !\n");
+#endif /* CONFIG_MOSIX_DIAG */
+	wake_up_interruptible(sk->sleep);
+}
+
+
+int
+comm_getpeer(mosix_link *mlink)
+{
+	return (mlink->peer);
+}
+
+
+#define MAX_LINK_POOL	30
+#define MIN_LINK_POOL	2
+#define LINK_POOL_AGE	60
+
+static int link_pool_age = LINK_POOL_AGE;
+
+static struct {
+	mosix_link *mlink;
+	int age;
+} link_pool[MAX_LINK_POOL];
+
+spinlock_t linkpool_lock = SPIN_LOCK_UNLOCKED;
+static atomic_t link_pool_used = ATOMIC_INIT(0);
+static int link_pool_next = 0;
+static int linkpool_closed = 1;
+DECLARE_WAIT_QUEUE_HEAD(wait_for_link_pool_used);
+
+void
+comm_init_linkpool(void)
+{
+	int i;
+
+	for(i = 0 ; i < MIN_LINK_POOL ; i++)
+	if (!(link_pool[i].mlink = comm_open(COMM_LOOSE, NULL, 0)))
+		break;
+	link_pool_next = i;
+	linkpool_closed = 0;
+}
+
+void
+comm_free_linkpool(void)
+{
+	int i;
+
+	spin_lock(&linkpool_lock);
+	linkpool_closed = 1;
+	spin_unlock(&linkpool_lock);
+	wake_up(&wait_for_link_pool_used);
+	for (i = 0 ; i < link_pool_next ; i++)
+		comm_close(link_pool[i].mlink);
+	link_pool_next = 0;
+}
+
+mosix_link *
+comm_borrow_linkpool()
+{
+	mosix_link *mlink;
+
+	while(1)
+	{
+		spin_lock(&linkpool_lock);
+		if(linkpool_closed)
+		{
+			spin_unlock(&linkpool_lock);
+			return(NULL);
+		}
+		if(link_pool_next)
+		{
+			mlink = link_pool[--link_pool_next].mlink;
+			atomic_inc(&link_pool_used);
+			spin_unlock(&linkpool_lock);
+			return(mlink);
+		}
+		if(atomic_read(&link_pool_used) <= MAX_LINK_POOL)
+		{
+			spin_unlock(&linkpool_lock);
+			atomic_inc(&link_pool_used);
+			if(!(mlink = comm_open(COMM_LOOSE, NULL, 0)))
+			{
+				atomic_dec(&link_pool_used);
+				wake_up(&wait_for_link_pool_used);
+			}
+			return(mlink);
+		}
+		spin_unlock(&linkpool_lock);
+		sleep_on_timeout(&wait_for_link_pool_used, HZ/10);
+		if (signal_pending(current))
+			return(NULL);
+	}
+}
+
+
+void
+comm_return_linkpool(mosix_link *mlink)
+{
+	atomic_dec(&link_pool_used);
+	spin_lock(&linkpool_lock);
+	if (!linkpool_closed &&
+		link_pool_next + atomic_read(&link_pool_used) <= MAX_LINK_POOL)
+	{
+		link_pool[link_pool_next].mlink = mlink;
+		link_pool[link_pool_next].age = link_pool_age;
+		link_pool_next++;
+		spin_unlock(&linkpool_lock);
+	}
+	else
+	{
+		spin_unlock(&linkpool_lock);
+		comm_close(mlink);
+	}
+	wake_up(&wait_for_link_pool_used);
+}
+
+
+void
+comm_age_linkpool()
+{
+	register int i;
+	struct mosix_link *mlink;
+
+	spin_lock(&linkpool_lock);
+	for(i = MIN_LINK_POOL ; i < link_pool_next ; )
+	if(--link_pool[i].age <= 0)
+	{
+		mlink = link_pool[i].mlink;
+		link_pool[i] = link_pool[--link_pool_next];
+		spin_unlock(&linkpool_lock);
+		comm_close(mlink);
+		spin_lock(&linkpool_lock);
+	}
+	else
+		i++;
+	spin_unlock(&linkpool_lock);
+}
+
+int
+reserved_mosix_address(struct sockaddr *addr)
+{
+	int port = ((struct sockaddr_in *)addr)->sin_port;
+
+	if(port != MIG_DAEMON_PORT && port != INFO_DAEMON_PORT)
+#ifdef CONFIG_MOSIX_FS
+	if(port != MFS_MAIN_PORT)
+#endif /* CONFIG_MOSIX_FS */
+		return(0);
+	if(current->mosix.dflags & (DPASSING|DHEAVYSLEEP))
+		return(0);
+#ifdef CONFIG_MOSIX_SECUREPORTS
+	if(!capable(CAP_NET_RAW))
+		return(1);
+#endif /* CONFIG_MOSIX_SECUREPORTS */
+	if (!net_to_mos((mosix_addr *)addr))
+		return(0);
+#ifndef CONFIG_MOSIX_SECUREPORTS
+	if(!capable(CAP_NET_RAW))
+		return(1);
+#endif /* CONFIG_MOSIX_SECUREPORTS */
+	printk("The Super-User is allowed to access MOSIX ports -- "
+						"but it is not a good idea!\n");
+	return(0);
+}
+
+void
+debug_commdump(int pid)
+{
+	struct task_struct *p = 0;
+	struct socket *sock = 0 ;
+	mosix_link *mlink = 0;
+
+	if (pid == -1)
+		p = current;
+	else for_each_task(p)
+		if (p->pid == pid)
+			break;
+	if (p) {
+		mlink = p->mosix.contact;
+		if (mlink)
+			sock = mlink->sock;
+		else
+			sock = NULL;
+		printk("task=0x%x, socket=0x%x, sock=0x%x, mlink=0x%x\n",
+			(int)p, (int)sock, sock ? (int)sock->sk : 0,(int)mlink);
+		if (sock)
+			printk("socket-flags=0x%x, owner=%x\n",
+				(int)sock->flags, (int)sock->sk->owner);
+		if (mlink) {
+			printk("mlink:  dlen=%d  flags=0x%x  peer=0x%x",
+				mlink->dlen, mlink->flags, (int)mlink->peer);
+#ifdef CONFIG_MOSIX_DEBUG
+			printk("  count=%d cntmem=%d",mlink->count,mlink->cntmem);
+#endif /* CONFIG_MOSIX_DEBUG */
+			printk("\n");
+		}
+	} else
+		printk("X: %s\n", current ? "no such pid" : "no current task");
+}
diff -ruN linux-2.4.16/mos/config.c linux-2.4.16-mosix/mos/config.c
--- linux-2.4.16/mos/config.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/config.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1062 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan, Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/reboot.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <mos/debug.h>
+#include <linux/mosix.h>
+#include <linux/mosctl.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/stddef.h>
+#include <linux/socket.h>
+#include <linux/in.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
+static int
+mosix_notify_reboot(struct notifier_block *this, unsigned long code, void *x)
+{
+	if(code == SYS_DOWN || code == SYS_HALT || code == SYS_POWER_OFF ||
+		code == SYS_RESTART)
+		expel(1);
+	return(NOTIFY_DONE);
+}
+
+struct notifier_block mosix_notifier =
+{
+	notifier_call: mosix_notify_reboot,
+	priority: 10,	/* Higher than drivers, so network still goes */
+};
+
+int PE;
+int NPE;
+int MAXPE;
+struct sockaddr my_mosix_net_address;
+
+#ifdef CONFIG_SMP
+static spinlock_t modifying = SPIN_LOCK_UNLOCKED;	/* use only TRYLOCK! */
+#endif /* CONFIG_SMP */
+
+static int pe_ready;
+
+int nmosnet;
+struct mosixnet *mosnet;
+static char *mosnetstat;
+rwlock_t mosnetstat_lock = RW_LOCK_UNLOCKED; 
+
+DECLARE_WAIT_QUEUE_HEAD(wait_for_mosix_config);
+DECLARE_WAIT_QUEUE_HEAD(wait_for_all_to_adjust);
+
+/* local subroutines */
+static int config_validate(void);
+static int config_reduce_to_common(struct mosixnet *, int);
+static int config_shutdown(void);
+
+
+/* hooks for IP network */
+static int ip_to_mosix(struct sockaddr *);
+static int ip_consistent(int, struct mosixnet *, int, int);
+static void ip_showconf(int, struct mosixnet *, int);
+static void ip_mos_to_net(int, int, struct sockaddr *);
+static int ip_addr_to_ascii(struct sockaddr *, char *, int);
+static struct mosixnet *ip_reduce_to_common(struct mosixnet *, int *);
+
+int
+config_get_status(int pe)
+{
+	int ret;
+
+	if (!mos_to_net(pe, NULL))
+		return (-ENXIO);
+	pe--;
+	read_lock(&mosnetstat_lock);
+	ret = mosnetstat[pe >> 3] & (1 << (pe & 7));
+	read_unlock(&mosnetstat_lock);
+	return(ret);
+}
+
+int
+config_set_status(int pe)
+{
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("set_status: setting for %d\n", pe);
+#endif
+	pe--;
+	write_lock(&mosnetstat_lock);
+	mosnetstat[pe >> 3] |= (1 << (pe & 7));
+	write_unlock(&mosnetstat_lock);
+	return (0);
+}
+
+static int
+config_shutdown(void)
+{
+	struct mosixnet *svmton;
+	int svnmton, svpe, svnpe, svmaxpe;
+	int error;
+	struct task_struct *t1, *t2;
+
+	/* temporarily change configuration */
+	lock_mosix();
+	svpe = PE;
+	svnpe = NPE;
+	svmaxpe = MAXPE;
+	svmton = mosnet;
+	svnmton = nmosnet;
+	mosnet = NULL;
+	nmosnet = 0;
+	NPE = MAXPE = 0;
+	unlock_mosix();
+
+	/* bring back our processes, and expel foreign */
+	if ((error = config_validate()))
+		goto fail;
+	lock_mosix();
+	PE = 0;
+	unlock_mosix();
+	info_reconfig();
+
+	/* wakeup our daemons */
+	lock_mosix();
+	if((t1 = info_proc))
+		get_task_struct(t1);
+	if((t2 = mig_proc))
+		get_task_struct(t2);
+	unlock_mosix();
+	if(t1)
+	{
+		send_sig(SIGALRM, t1, 1);
+		free_task_struct(t1);
+	}
+	if(t2)
+	{
+		send_sig(SIGALRM, t2, 1);
+		free_task_struct(t2);
+	}
+
+	lock_mosix();
+	while ((mig_daemon_active || info_daemon_active) &&
+						!signal_pending(current))
+	{
+		unlock_mosix();
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(HZ/10);
+		lock_mosix();
+	}
+	unlock_mosix();
+	set_current_state(TASK_RUNNING);
+	if (signal_pending(current))
+	{
+		error = -ERESTART;
+		goto fail;
+	}
+
+	printk(KERN_NOTICE "MOSIX configuration disabled\n");
+	unregister_reboot_notifier(&mosix_notifier);
+
+	if (svnmton) {
+		kfree(svmton);
+		kfree(mosnetstat);
+	}
+	
+	lock_mosix();
+	pe_ready = 0;
+	unlock_mosix();
+#ifdef CONFIG_MOSIX_FS
+	mfs_change_pe();
+#endif /* CONFIG_MOSIX_FS */
+
+	return (0);
+
+fail:
+	lock_mosix();
+	PE = svpe;
+	NPE = svnpe;
+	MAXPE = svmaxpe;
+	mosnet = svmton;
+	nmosnet = svnmton;
+	unlock_mosix();
+	wake_up(&wait_for_mosix_config);
+	return (error);
+}
+
+void
+wait_for_mosix_configuration(int *active)
+{
+	struct task_struct *p = current;
+	DECLARE_WAITQUEUE(wait, current);
+
+	if(active)
+	{
+		lock_mosix();
+		*active = 0;
+		unlock_mosix();
+	}
+	add_wait_queue(&wait_for_mosix_config, &wait);
+	while(1)
+	{
+		if(p->sigpending)
+			flush_signals(p);
+		set_current_state(TASK_INTERRUPTIBLE);
+		if(PE)
+			break;
+		schedule();
+	}
+	remove_wait_queue(&wait_for_mosix_config, &wait);
+	set_current_state(TASK_RUNNING);
+	if(signal_pending(p))
+	{
+		spin_lock_irq(&p->sigmask_lock);
+		flush_signals(p);
+		spin_unlock_irq(&p->sigmask_lock);
+	}
+	if(active)
+	{
+		lock_mosix();
+		*active = 1;
+		unlock_mosix();
+	}
+}
+
+int
+mosix_config_get_table(struct mosixnet **mos, int start, int count)
+{
+	int copy;
+
+	if (count > MAX_MOSNET_ENTS)
+		count = MAX_MOSNET_ENTS;
+	if(!count)
+		count = nmosnet - start;
+	if(!PE || count < 0)
+		return(-ENXIO);
+	if(count == 0)
+		return(0);
+	*mos = (struct mosixnet *)
+		kmalloc(sizeof(struct mosixnet) * count, GFP_USER);
+	if(!*mos)
+		return(-ENOMEM);
+	lock_mosix();
+	if(!PE || !nmosnet || nmosnet < start)
+	{
+		unlock_mosix();
+		kfree(*mos);
+		return(-ENXIO);
+	}
+	if(nmosnet == start)
+	{
+		unlock_mosix();
+		kfree(*mos);
+		return(0);
+	}
+
+	/* create a private copy */
+	copy = nmosnet - start;
+	if (copy > count)
+		copy = count;
+	memcpy(*mos, &mosnet[start], sizeof(struct mosixnet) * copy);
+	unlock_mosix();
+	return (copy);
+}
+
+int
+mosix_config_set_table(struct mosixnet *m, int nents, int newpe)
+{
+	register int i, j;
+	register struct mosixnet *t, *q;
+	char *mstat = NULL;
+	char foundme = 0;
+	int maxpe = 1;
+	int numpe = 0;
+	int error = 0;
+
+	if (!boot_cpu_data.hard_math)
+	{
+		printk("Sorry, MOSIX requires a math-unit.\n");
+		return(-ENODEV);
+	}
+	if(!spin_trylock(&modifying))
+		return(-EBUSY);
+	error = -E2BIG;
+	if (nents > MAX_MOSNET_ENTS)
+		goto out;
+
+	/*
+	 * PE == 0: (1)	newpe == 0 || nents == 0  =>  return (0)
+	 * 	    (2)	newpe > 0 && nents != 0   =>  (regular)
+	 * PE != 0: (3) newpe == PE		  =>  (regular)
+	 *	    (4)	newpe == 0 || nents == 0  =>  (shutdown)
+	 *          (5) newpe > 0 (nmosnet == 1)  =>  change PE, (regular)
+	 */
+
+	if(!newpe || !nents)
+	{
+		if(m)
+			kfree(m);
+		error = PE ? config_shutdown() : 0;
+		goto out;
+	}
+
+	error = -EBUSY;
+	if(PE && newpe != PE &&
+		(nmosnet != 1 || m->cnt != 1 || m->base != newpe))
+		goto out;
+
+	if(newpe == PE && nents == nmosnet &&
+		!memcmp(m, mosnet, nmosnet * sizeof(struct mosixnet)))
+	{
+		/* no change */
+		error = 0;
+		kfree(m);
+		goto out;
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("%s-config_set_table: stage 1\n",
+			desc_mostask(NULL));
+#endif
+
+	/* convention: first entry must hold the network type (AF_xxx) */
+	error = -EINVAL;
+	if (m->saddr.sa_family != AF_INET)
+		goto out;
+	comm_type = m->saddr.sa_family;
+
+	/* consistency checks */
+
+	for (t = m, i = 0; i < nents; i++, t++) {
+		t->saddr.sa_family = comm_type;
+
+		if (t->cnt < 0 || t->base < 1 || t->base + t->cnt < 0 ||
+			t->base + t->cnt - 1 > MOSIX_MAX)
+			goto out;
+
+		if (t->cnt == 0)
+		{
+			for (q = m, j = 0 ; j < nents ; j++ , q++)
+			if (q->cnt > 0 && q->base <= t->base &&
+				q->base + q->cnt > t->base)
+				break;
+			if(j == nents)
+			{
+				error = -ESRCH;
+				goto out;
+			}
+		}
+		else
+		{
+			for (q = m, j = 0; j < i; j++, q++)
+			if (q->cnt && (
+			    (q->base < t->base && q->base + q->cnt > t->base) ||
+			    (q->base >= t->base && q->base < t->base + t->cnt)))
+			{
+				error = -EXDEV;
+				goto out;
+			}
+
+			if (t->base + t->cnt - 1 > maxpe)
+				maxpe = t->base + t->cnt - 1;
+
+			if (newpe >= t->base && newpe < t->base + t->cnt)
+				foundme = 1;
+
+			numpe += t->cnt;
+		}
+	}
+	switch (comm_type) {
+		case AF_INET:
+			error = ip_consistent(newpe, m, nents, numpe);
+			break;
+		default:
+			error = 0;
+	}
+	if (error)
+		goto out;
+	error = -ESRCH;
+	if (!foundme)
+		goto out;
+	error = -ENOMEM;
+	i = (maxpe + 7) >> 3;
+	if (!(mstat = (char *) kmalloc(i, GFP_KERNEL)))
+		goto out;
+	memset(mstat, 0, i);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("%s-config_set_table: stage 2\n",
+			desc_mostask(NULL));
+#endif
+
+	if(PE && (error = config_reduce_to_common(m, nents)))
+	{
+		kfree(mstat);
+		goto out;
+	}
+
+	/* COMMIT POINT */
+
+	lock_mosix();
+	write_lock(&mosnetstat_lock);
+	if (PE) {
+		int i, j, n;
+
+		if(newpe == PE)
+		for (i = 0; i < nents; i++)
+		for (n = m[i].base - 1 , j = 0 ; j < m[i].cnt ; j++ , n++)
+			mstat[n >> 3] |= (mosnetstat[n >> 3] & (1 << (n & 7)));
+		kfree(mosnetstat);
+		kfree(mosnet);
+	}
+
+	mosnetstat = mstat;
+	NPE = numpe;
+	MAXPE = maxpe;
+	nmosnet = nents;
+	mosnet = m;
+	write_unlock(&mosnetstat_lock);
+
+	pe_ready = newpe;
+	if(newpe != PE)
+	{
+		i = PE;
+		PE = newpe;
+		mos_to_net(PE, (void *)&my_mosix_net_address);
+		unlock_mosix();
+		info_startup();
+		if (!i)
+		{
+			comm_startup();
+			register_reboot_notifier(&mosix_notifier);
+			wake_up(&wait_for_mosix_config);
+		}
+	}
+	else
+		unlock_mosix();
+#ifdef CONFIG_MOSIX_FS
+	mfs_change_pe();
+#endif /* CONFIG_MOSIX_FS */
+	printk(KERN_NOTICE "MOSIX configuration %s: This is MOSIX #%d "
+		"(of %d configured)\n", PE ? "changed" : "set", newpe, NPE);
+	switch (comm_type)
+	{
+		case AF_INET:
+			ip_showconf(newpe, mosnet, nmosnet);
+			break;
+	}
+	error = 0;
+
+	out:
+	spin_unlock(&modifying);
+	return(error);
+}
+
+/* nth_node: n starts at 0 and does not count the local node */
+int
+nth_node(int n)
+{
+	register int i;
+	struct mosixnet *t;
+
+	MOSIX_LOCKED;
+	for(t = mosnet , i = 0 ; i < nmosnet ; i++ , t++)
+	{
+		if(t->base <= PE && t->base + t->cnt > PE)
+		{
+			if(t->base + n < PE)
+				return(t->base + n);
+			n++;
+		}
+		if(t->cnt <= n)
+			n -= t->cnt;
+		else
+			return(t->base + n);
+	}
+	panic("nth_node");
+}
+
+int
+mosix_config_get_pe(void)
+{
+	return (PE);
+}
+
+int
+mosix_config_get_tentative_pe(void)
+{
+	int ret;
+
+	lock_mosix();
+	ret = pe_ready;
+	unlock_mosix();
+	return(ret);
+}
+
+int
+mosix_config_get_limit(void)
+{
+	int ret;
+
+	lock_mosix();
+	ret = PE ? MAXPE : 0;
+	unlock_mosix();
+	return(ret);
+}
+
+int
+mosix_config_set_pe(int newpe)
+{
+	int error = 0;
+
+	if (newpe < 0 || newpe > MOSIX_MAX)
+		return (-EINVAL);
+	if(!spin_trylock(&modifying))
+		return(-EBUSY);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("setting PE from %d to %d\n", PE, newpe);
+#endif
+
+	if (!PE) {
+		lock_mosix();
+		pe_ready = newpe;
+		unlock_mosix();
+		goto out;
+	}
+
+	if (newpe == PE)
+		goto out;
+	
+	error = -EBUSY;
+	if (newpe && (nmosnet > 1 || mosnet->cnt != 1))
+		goto out;
+
+	if (newpe)
+	{
+		struct mosixnet m = *mosnet;
+
+		spin_unlock(&modifying);
+		m.base = newpe;
+		m.cnt = 1;
+		error = mosix_config_set_table(&m, 1, newpe);
+	}
+	else
+	{
+		spin_unlock(&modifying);
+		error = mosix_config_set_table(NULL, 0, 0);
+	}
+	return(error);
+	out:
+	spin_unlock(&modifying);
+	return (error);
+}
+
+/*
+ * mos_to_net:  return 1 if mos# exists (possibly fill sockaddr)
+ */
+int
+mos_to_net(int mos, void *sa)
+{
+	int n;
+	int ret = 0;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(mos == COMM_TOADDR) {
+		mosix_panic("COMM_TOADDR in mos_to_net");
+		return (1);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	lock_mosix();
+	for (n = 0; n < nmosnet; n++)
+	if (mos >= mosnet[n].base && mos < mosnet[n].base + mosnet[n].cnt)
+	{
+		if(sa)
+		switch (comm_type) {
+			case AF_INET:
+				ip_mos_to_net(mos, n, (struct sockaddr *)sa);
+				break;
+			case AF_INET6:
+				panic("mos_to_net: AF_INET6 unsupported");
+				/* NOT REACHED */
+			default:
+				panic("mos_to_net: unknown type");
+		}
+		ret = 1;
+	}
+	unlock_mosix();
+	return(ret);
+}
+
+int
+mymos_to_net(void *sa)
+{
+	int ret = 0;
+
+	lock_mosix();
+	if(PE)
+		*(struct sockaddr *)sa = my_mosix_net_address;
+	else
+		ret = -ENETDOWN;
+	unlock_mosix();
+	return(ret);
+}
+
+int
+count_mosix_nodes(void)
+{
+	int i, n = 0;
+
+	lock_mosix();
+	for(i = 0 ; i < nmosnet ; i++)
+		n += mosnet[i].cnt;
+	unlock_mosix();
+	return(n);
+}
+
+#ifdef CONFIG_MOSIX_FS
+int
+scan_mosix_nodes(int start, int *first, int *last)
+{
+	int i;
+	int max = MOSIX_MAX + 1;
+
+	lock_mosix();
+	for(i = 0 ; i < nmosnet ; i++)
+	if(mosnet[i].cnt && mosnet[i].base < max &&
+		mosnet[i].base + mosnet[i].cnt > start)
+	{
+		*last = mosnet[i].base + mosnet[i].cnt - 1;
+		if(mosnet[i].base <= start)
+		{
+			*first = start;
+			max = 0;	/* eg. return(1) */
+			break;
+		}
+		*first = mosnet[i].base;
+		max = mosnet[i].base;
+	}
+	unlock_mosix();
+	return(max != MOSIX_MAX+1);
+}
+#endif /* CONFIG_MOSIX_FS */
+
+int
+mos_to_ascii(int mos, char *str, int len)
+{
+	struct sockaddr sa;
+
+	if (!mos_to_net(mos, &sa))
+		return (-EDIST);
+	switch (comm_type) {
+		case AF_INET:
+			return (ip_addr_to_ascii(&sa, str, len));
+		case AF_INET6:
+			panic("mos_to_ascii: AF_INET6 unsupported");
+		default:
+			panic("mos_to_ascii: unknown type");
+	}
+}
+
+
+int
+net_to_mos(mosix_addr *sa)
+{
+	switch (comm_type) {
+		case AF_INET:
+			return (ip_to_mosix(&sa->saddr));
+			/* NOT REACHED */
+		case AF_INET6:
+			panic("net_to_mos: AF_INET6 unsupported");
+			/* NOT REACHED */
+		default:
+			return(0);
+	}
+}
+
+int
+config_validate(void)
+{
+	register struct task_struct *p;
+	DECLARE_WAITQUEUE(wait, current);
+	int err = 0;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if((p->mm || (p->mosix.dflags & (DDEPUTY|DREMOTE))) &&
+		!(p->mosix.dflags & DFINISHED))
+	{
+		tell_process(p, DREQ_CHECKCONF);
+		wake_up_mosix(p);
+	}
+	read_unlock(&tasklist_lock);
+	add_wait_queue(&wait_for_all_to_adjust, &wait);
+	while(1)
+	{
+		set_current_state(TASK_INTERRUPTIBLE);
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if(process_told(p, DREQ_CHECKCONF))
+			break;
+		read_unlock(&tasklist_lock);
+		if(p == &init_task)
+			break;
+		schedule();
+		if (signal_pending(current))
+		{
+			err = -ERESTARTSYS;
+			break;
+		}
+	}
+	remove_wait_queue(&wait_for_all_to_adjust, &wait);
+	set_current_state(TASK_RUNNING);
+	return(err);
+}
+
+static int
+config_reduce_to_common(struct mosixnet *nm, int nmn)
+{
+	struct mosixnet *mt, *svmton;
+	int svnmton;
+	int error;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("%s-config_reduce_to_common: stage 1\n",
+			desc_mostask(NULL));
+#endif
+
+	switch (comm_type) {
+		case AF_INET:
+			mt = ip_reduce_to_common(nm, &nmn);
+			break;
+		case AF_INET6:
+			panic("config_reduce_to_common: AF_INET6 unsupported");
+			/* NOT REACHED */
+		default:
+			panic("config_reduce_to_common: unknown type");
+	}
+
+	if (!mt)
+		return (-ENOMEM);
+
+	svmton = mosnet;
+	svnmton = nmosnet;
+	lock_mosix();
+	mosnet = mt;
+	nmosnet = nmn;
+	unlock_mosix();
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("%s-config_reduce_to_common: stage 2\n",
+			desc_mostask(NULL));
+#endif
+
+	info_reconfig();
+
+	if ((error = config_validate())) {
+		lock_mosix();
+		mosnet = svmton;
+		nmosnet = svnmton;
+		unlock_mosix();
+		kfree(mt);
+		return (error);
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_CONFIG)
+		printk("%s-config_reduce_to_common: stage 3 (done)\n",
+			desc_mostask(NULL));
+#endif
+
+	kfree(svmton);
+	return(0);
+}
+
+int
+i_am_in_a_wrong_place(void)
+{
+	register struct task_struct *p = current;
+
+	if(p->mosix.dflags & (DPASSING|DINCOMING))
+		return(0);	/* not time to hit yet */
+	switch(p->mosix.dflags & (DDEPUTY|DREMOTE))
+	{
+		case DREMOTE:
+			if (mos_to_net(p->mosix.deppe, 0) == 0)
+			{
+#ifdef CONFIG_MOSIX_DEBUG
+				if(ds_debug & DSDEB_EXPEL)
+					printk("%s:my home (%d) no longer recognised!\n",
+					    desc_mostask(NULL), p->mosix.deppe);
+#endif /* CONFIG_MOSIX_DEBUG */
+				return(1);
+			}
+			break;
+		case DDEPUTY:
+			if (mos_to_net(p->mosix.whereami, 0) == 0)
+			{
+#ifdef CONFIG_MOSIX_DEBUG
+				if(ds_debug & DSDEB_EXPEL)
+					printk("%s: where I am (%d) is no longer recognised\n",
+						desc_mostask(NULL),
+						p->mosix.whereami);
+#endif /* CONFIG_MOSIX_DEBUG */
+				return(1);
+			}
+	}
+	done_checking_conf();
+	return(0);
+}
+
+void
+done_checking_conf(void)
+{
+	register struct task_struct *p;
+
+	read_lock(&tasklist_lock);
+	process_ack(current, DREQ_CHECKCONF);
+	for_each_task(p)
+		if(process_told(p, DREQ_CHECKCONF))
+			break;
+	read_unlock(&tasklist_lock);
+	if(p == &init_task)	/* we were last to check */
+		wake_up(&wait_for_all_to_adjust);
+}
+
+
+
+/*
+ * Network dependent part of config:
+ * current implementation support only IP (not including v6).
+ */
+
+#define NET_TO_IP(sa)	(((struct sockaddr_in *) &(sa))->sin_addr.s_addr)
+#define NET_TO_IP_H(sa)	(ntohl(NET_TO_IP(sa)))
+
+static void
+ip_mos_to_net(int mos, int n, struct sockaddr *sa)
+{
+	*sa = mosnet[n].saddr;
+	NET_TO_IP(*sa) = htonl(NET_TO_IP_H(*sa) + mos - mosnet[n].base);
+}
+
+
+static int
+ip_to_mosix(struct sockaddr *sa)
+{
+	int i, ip, mip, c, ret = 0;
+
+	ip = NET_TO_IP_H(*sa);
+
+	lock_mosix();
+	for (i = 0 ; i < nmosnet ; i++)
+	{
+		mip = NET_TO_IP_H(mosnet[i].saddr);
+		c = mosnet[i].cnt ? : 1;
+		if(ip >= mip && ip < mip + c)
+		{
+			ret = mosnet[i].base + ip - mip;
+			break;
+		}
+	}
+	unlock_mosix();
+	return(ret);
+}
+
+static struct mosixnet *
+ip_reduce_to_common(struct mosixnet *nm, int *nmn)
+{
+	struct mosixnet *mt;
+	register int i, j, n = 0;
+	int b1, e1, b2, e2;
+
+	/* 2*MAX_MOSNET_ENTS should cover the worst-case intersection */
+
+	mt = kmalloc(2 * MAX_MOSNET_ENTS * sizeof(struct mosixnet), GFP_KERNEL);
+	if (!mt)
+		return (0);
+	for (i = 0; i < *nmn; i++)
+	for (j = 0; j < nmosnet; j++)
+	if (NET_TO_IP_H(mosnet[j].saddr) - mosnet[j].base ==
+					NET_TO_IP_H(nm[i].saddr) - nm[i].base)
+	{
+		if ((nm[i].cnt != 0) != (mosnet[j].cnt != 0))
+			continue;
+		b1 = nm[i].base;
+		e1 = nm[i].base + nm[i].cnt - 1;
+		b2 = mosnet[j].base;
+		e2 = mosnet[j].base + mosnet[j].cnt - 1;
+
+		if (b2 > b1)
+			b1 = b2;
+		if (e2 < e1)
+			e1 = e2;
+		if (e1 >= b1) {
+#ifdef CONFIG_MOSIX_DIAG
+			if (n >= 2*MAX_MOSNET_ENTS)
+				panic("ip_reduce_to_common: algorithm failed");
+#endif
+			mt[n].base = b1;
+			mt[n].cnt = e1 - b1 + 1;
+			mt[n].saddr.sa_family = AF_INET;
+			NET_TO_IP(mt[n].saddr) = htonl(NET_TO_IP_H(nm[i].saddr)
+							+ b1 - nm[i].base);
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug)
+				printk("setpe: common chunk=%d/%x/%d\n",
+					mt[n].base, (int)NET_TO_IP(mt[n].saddr),
+					mt[n].cnt);
+#endif /* CONFIG_MOSIX_DEBUG */
+			n++;
+		}
+	}
+	*nmn = n;
+	return (mt);
+}
+
+static int
+ip_consistent(int pe, struct mosixnet *m, int nents, int numpe)
+{
+	int i, j;
+	struct mosixnet *t, *q;
+
+	for (t = m, i = 0; i < nents; i++, t++)
+	if (t->cnt == 0)		/* an ALIAS address */
+	for (q = m , j = 0 ; j < i ; j++ , q++)
+	{
+		/* check if this IP appears more than once */
+		if (q->cnt == 0 &&
+			NET_TO_IP_H(q->saddr) == NET_TO_IP_H(t->saddr))
+		{
+			if (q->base != t->base)
+				return (-EXDEV);
+		}
+		else if (q->cnt != 0 &&
+			NET_TO_IP_H(q->saddr) <= NET_TO_IP_H(t->saddr) &&
+			NET_TO_IP_H(q->saddr) + q->cnt > NET_TO_IP_H(t->saddr)
+			&& q->base + NET_TO_IP_H(t->saddr) -
+				NET_TO_IP_H(q->saddr) != t->base)
+				return (-EXDEV);
+	}
+	else				/* a normal range */
+	{
+		if (NET_TO_IP_H(t->saddr) + t->cnt <= NET_TO_IP_H(t->saddr))
+			return (-EINVAL);
+
+		for (q = m , j = 0 ; j < i ; j++ , q++)
+		if (q->cnt == 0 &&
+		    NET_TO_IP_H(t->saddr) <= NET_TO_IP_H(q->saddr) &&
+		    NET_TO_IP_H(t->saddr)+t->cnt > NET_TO_IP_H(q->saddr)
+		    && t->base + NET_TO_IP_H(q->saddr) - NET_TO_IP_H(t->saddr)
+		       != q->base)
+			return (-EXDEV);
+		else if (q->cnt != 0 && (
+		    (NET_TO_IP_H(q->saddr) < NET_TO_IP_H(t->saddr) &&
+		     NET_TO_IP_H(q->saddr) + q->cnt > NET_TO_IP_H(t->saddr)) ||
+		    (NET_TO_IP_H(q->saddr) >= NET_TO_IP_H(t->saddr) &&
+		     NET_TO_IP_H(q->saddr) < NET_TO_IP_H(t->saddr) + t->cnt)))
+			return (-EXDEV);
+	}
+
+	if (PE && numpe > 1)
+	/* allow change of address only if PE remains alone */
+	for (t = m, i = 0; i < nents; i++, t++)
+	{
+		struct sockaddr sa;
+
+		if (t->cnt != 0 && pe >= t->base && pe < t->base + t->cnt &&
+			(!mos_to_net(pe, &sa) || NET_TO_IP_H(sa) !=
+				NET_TO_IP_H(t->saddr) + (pe - t->base)))
+				return (-EBUSY);
+	}
+
+	return (0);
+}
+
+
+static int
+ip_addr_to_ascii(struct sockaddr *sa, char *buf, int len)
+{
+	int a, b, c, d;
+	char tmp[20];	/* should be enough for ALL inet addresses */
+	unsigned long ipaddr;
+	
+	ipaddr = htonl(((struct sockaddr_in *) sa)->sin_addr.s_addr);
+
+	a = (ipaddr & 0xff000000) >> 24;
+	b = (ipaddr & 0x00ff0000) >> 16;
+	c = (ipaddr & 0x0000ff00) >> 8;
+	d = (ipaddr & 0x000000ff);
+
+	sprintf(tmp, "%d.%d.%d.%d", a, b, c, d);
+	strncpy(buf, tmp, len - 1);
+	buf[len - 1] = '\0';
+	return (strlen(tmp));
+}
+
+
+static void
+ip_showconf(int pe, struct mosixnet *m, int nents)
+{
+	int i;
+	int a, b, c, d;
+	long ipaddr;
+
+	for(i = 0 ; i < nents ; i++, m++)
+	{
+		ipaddr = ntohl(NET_TO_IP(m->saddr));
+		a = (ipaddr & 0xff000000) >> 24;
+		b = (ipaddr & 0x00ff0000) >> 16;
+		c = (ipaddr & 0x0000ff00) >> 8;
+		d = ipaddr & 0xff;
+		if (m->cnt == 0)
+			printk(KERN_NOTICE "MOSIX #%d is aliased to IP address "
+					"%d.%d.%d.%d\n", m->base, a, b, c, d);
+		else if (m->cnt == 1)
+			printk(KERN_NOTICE "MOSIX #%d is at IP address "
+					"%d.%d.%d.%d\n", m->base, a, b, c, d);
+		else
+			printk(KERN_NOTICE "MOSIX range: %d-%d begins at "
+					"%d.%d.%d.%d\n", m->base,
+					m->base + m->cnt - 1, a, b, c, d);
+	}
+}
+
+#ifdef CONFIG_MOSIX_DEBUG
+void
+ip_config_dump(void)
+{
+	int i, a, b, c, d;
+	long ipaddr;
+
+	for (i = 0; i < nmosnet; i++) {
+		ipaddr = NET_TO_IP(mosnet[i].saddr);
+		a = (ipaddr & 0xff000000) >> 24;
+		b = (ipaddr & 0x00ff0000) >> 16;
+		c = (ipaddr & 0x0000ff00) >> 8;
+		d = (ipaddr & 0x000000ff);
+		printk("%-8d-%8d  %d.%d.%d.%d  (%d)\n",
+			mosnet[i].base, mosnet[i].base+mosnet[i].cnt - 1,
+			a, b, c, d, mosnet[i].saddr.sa_family);
+	}
+}
+#endif /* CONFIG_MOSIX_DEBUG */
diff -ruN linux-2.4.16/mos/copy_unconf linux-2.4.16-mosix/mos/copy_unconf
--- linux-2.4.16/mos/copy_unconf	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/copy_unconf	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,14 @@
+#!/bin/sh -
+echo "/* alternate.c: automatically generated with copy of unconfigured routines */"
+echo
+if [ "$1" != y ]
+then
+	awk ' \
+		/^#include/ {print $0; next; } \
+		/^aout_remote_init_mm\(/ { on=1 ; print "\nvoid" ; } \
+		/^unsigned long .*create_aout_tables\(/ { on=1 ; print "\n#ifdef CONFIG_MOSIX"; } \
+		/^static void set_brk/ { on=1; print ""; }
+		/^}/ { if(on) print "}" ; on=0; next; } \
+		on == 1  { print $0; }
+		' < $2
+fi
diff -ruN linux-2.4.16/mos/decay.c linux-2.4.16-mosix/mos/decay.c
--- linux-2.4.16/mos/decay.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/decay.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,257 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/config.h>
+#include <linux/sched.h>
+#include <linux/mosix.h>
+#include <linux/mosctl.h>
+#include <linux/smp_lock.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <mos/balance.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+
+int slow_alpha = DEFAULT_SLOW_ALPHA;
+int fast_alpha = DEFAULT_FAST_ALPHA;
+int decay_interval = DEFAULT_DECAY_INTERVAL;
+
+void
+mosix_decay_exec(void)
+{
+	register typeof (current->mosix.dpolicy) *p = &current->mosix.dpolicy;
+
+	if(!(*p & (DADV_EXEC|DADV_EXECONCE)))
+		*p = (*p & ~DADV_POLICY) | DADV_DEFAULT;
+	*p &= ~DADV_EXECONCE;
+}
+
+int
+decay_modify_bit(int on, int bit)
+{
+	if(on == -1)
+		return((current->mosix.dpolicy & bit) != 0);
+	if((on != 0) == ((current->mosix.dpolicy & bit) != 0))
+		return(0);
+	if(on)
+		current->mosix.dpolicy |= bit;
+	else
+		current->mosix.dpolicy &= ~bit;
+	if(current->mosix.dflags & DDEPUTY)
+		deputy_update_remote_decay();
+	return(0);
+}
+
+int
+decay_inherit(int on)
+{
+	return(decay_modify_bit(on, DADV_INHERIT));
+}
+
+int
+decay_exec(int on)
+{
+	return(decay_modify_bit(on, DADV_EXEC));
+}
+
+int
+decay_execonce(int on)
+{
+	return(decay_modify_bit(on, DADV_EXECONCE));
+}
+
+int
+decay_set(int policy, int quotient, int seconds)
+{
+	register struct task_struct *p = current;
+	int prev;
+
+	if(policy == (p->mosix.dpolicy & DADV_POLICY) &&
+		(policy != DADV_OWNDECAY || (quotient == p->mosix.decay &&
+			seconds == p->mosix.deccycle)))
+		return(0);
+	if(seconds < 1 || seconds > 65535 ||
+		quotient < 0 || quotient > DECAY_QUOTIENT)
+		return(-EINVAL);
+	if(policy == DADV_CPU || policy == DADV_NOCPU ||
+		(prev = (p->mosix.dpolicy & DADV_POLICY)) == DADV_CPU ||
+			prev == DADV_NOCPU)
+			mosix_clear_statistics();
+	p->mosix.dpolicy = (p->mosix.dpolicy & ~DADV_POLICY) | policy;
+	p->mosix.decay = quotient;
+	p->mosix.deccycle = seconds;
+	if(p->mosix.dflags & DDEPUTY)
+		deputy_update_remote_decay();
+	return(0);
+}
+
+int
+decay_get(int policy)
+{
+	return((current->mosix.dpolicy & DADV_POLICY) == policy);
+}
+
+void
+decay_clear(void)
+{
+	struct decay_h d;
+
+	d.policy = DADV_CLEAR;
+	if(current->mosix.dflags & DDEPUTY)
+		deputy_request(DEP_UPDATE_DECAY, &d, sizeof(d), NULL, 0, 0, NULL, 0);
+	else
+		mosix_clear_statistics();
+}
+
+void
+deputy_update_remote_decay(void)
+{
+	struct decay_h d;
+	struct mosix_task *m = &current->mosix;
+
+	d.policy = m->dpolicy;
+	d.deccycle = m->deccycle;
+	d.decay = m->decay;
+	deputy_request(DEP_UPDATE_DECAY, &d, sizeof(d), NULL, 0, 0, NULL, 0);
+}
+
+int
+remote_setdecay(struct decay_h *d)
+{
+	int prev, new;
+	struct mosix_task *m = &current->mosix;
+
+	if(d->policy == DADV_CLEAR)
+		mosix_clear_statistics();
+	else
+	{
+		prev = m->dpolicy & DADV_POLICY;
+		new = d->policy & DADV_POLICY;
+		if(prev == DADV_CPU || prev == DADV_NOCPU
+			|| new == DADV_CPU || new == DADV_NOCPU)
+			mosix_clear_statistics();
+		m->dpolicy = d->policy;
+		m->deccycle = d->deccycle;
+		m->decay = d->decay;
+	}
+	comm_free(d);
+	return(comm_send(DEP_UPDATE_DECAY|REPLY, NULL, 0, NULL, 0, 0));
+}
+ 
+void
+inc_decays(void)
+{
+	struct task_struct *p;
+	register struct mosix_task *m;
+	register unsigned char policy;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	{
+		m = &p->mosix;
+		if(!(m->dflags & DDEPUTY) &&
+			((policy = m->dpolicy & DADV_POLICY) == DADV_SLOWDECAY
+				|| policy == DADV_FASTDECAY ||
+				policy == DADV_OWNDECAY) &&
+			m->decsecs != 0xffff)
+			m->decsecs++;
+	}
+	read_unlock(&tasklist_lock);
+}
+
+void
+do_decay(void)
+{
+	register struct mosix_task *m = &current->mosix;
+	int d;
+	int64_t ms;
+#ifdef CONFIG_MOSIX_FS
+	int i;
+#endif /* CONFIG_MOSIX_FS */
+	/* an expensive 64-bit-division saving macro: */
+#define	proportionate(fld) if(m->fld > (0xffffffffUL/DECAY_QUOTIENT)) \
+	m->fld = m->fld * d / DECAY_QUOTIENT; \
+	else m->fld = ((unsigned long)m->fld) * d / DECAY_QUOTIENT
+
+	switch(m->dpolicy & DADV_POLICY)
+	{
+		case DADV_SLOWDECAY:
+			if(m->decsecs < decay_interval)
+				return;
+			d = slow_alpha;
+			break;
+		case DADV_FASTDECAY:
+			if(m->decsecs < decay_interval)
+				return;
+			d = fast_alpha;
+			break;
+		case DADV_OWNDECAY:
+			if(m->decsecs < m->deccycle)
+				return;
+			d = m->decay;
+			break;
+		default:
+			return;
+	}
+#ifdef CONFIG_MOSIX_DIAG
+	if(m->dflags & DDEPUTY)
+		mosix_panic("decay on deputy");
+#endif /* CONFIG_MOSIX_DIAG */
+	read_lock(&tasklist_lock);
+	m->decsecs = 0;
+	read_unlock(&tasklist_lock);
+	lock_mosix();
+	proportionate(cutime);
+	proportionate(ndemandpages);
+	proportionate(nsyscalls);
+	proportionate(ncopyins);
+	proportionate(copyinbytes);
+	proportionate(ncopyouts);
+	proportionate(copyoutbytes);
+	proportionate(pagetime);
+#ifdef CONFIG_MOSIX_FS
+	if(m->mfs_stats)
+	for(i = m->mfs_stats->nnodes-1 ; i >= 0 ; i--)
+	{
+		proportionate(mfs_stats->conns[i]);
+		proportionate(mfs_stats->inbytes[i]);
+		proportionate(mfs_stats->outbytes[i]);
+		if(m->mfs_stats->conns[i] == 0)
+		{
+			int last = --m->mfs_stats->nnodes;
+
+			if(i == last)
+				continue;
+			m->mfs_stats->nodes[i] = m->mfs_stats->nodes[last];
+			m->mfs_stats->conns[i] = m->mfs_stats->conns[last];
+			m->mfs_stats->inbytes[i] = m->mfs_stats->inbytes[last];
+			m->mfs_stats->outbytes[i] = m->mfs_stats->outbytes[last];
+			if(m->mfs_stats->hint == last)
+				m->mfs_stats->hint = i;
+		}
+	}
+#endif /* CONFIG_MOSIX_FS */
+
+	ms = ticks_to_ms(current->times.tms_utime + m->uttime) - m->dctime;
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_DECAY)
+		printk("decaying %s by adding %d/%d of %d to %d\n",
+			desc_mostask(m), DECAY_QUOTIENT - d, DECAY_QUOTIENT,
+			(int)ms, (int)m->dctime);
+#endif /* CONFIG_MOSIX_DEBUG */
+	if(ms > 0)
+		m->dctime += ms * (DECAY_QUOTIENT - d) / DECAY_QUOTIENT;
+	unlock_mosix();
+}
diff -ruN linux-2.4.16/mos/deputy.c linux-2.4.16-mosix/mos/deputy.c
--- linux-2.4.16/mos/deputy.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/deputy.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1477 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <linux/mosix.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+#include <asm/unistd.h>
+#include <linux/slab.h>
+#include <asm/uaccess.h>
+#include <linux/in6.h>
+#include <asm/checksum.h>
+#include <asm/pgtable.h>
+#include <asm/mmu_context.h>
+#include <linux/smp_lock.h>
+#include <linux/highmem.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+static inline int
+HAS_ASYNC(struct task_struct *p)
+{
+	process_ack(p, DREQ_CHECKSTAY);
+	return(p->mosix.prequest || p->mosix.whereto ||
+		process_told(p, (DREQ_CAPCNG|DREQ_DFSASYNC|DREQ_NICECNG|
+				DREQ_INFOCNG|DREQ_UPDOVERHEADS|DREQ_URGENT)) ||
+	(p->mosix.stay & DSTAY) ||
+	(process_told(p, DREQ_CHECKCONF) && i_am_in_a_wrong_place())
+	);
+}
+
+void
+mosix_inform_remote_of_info(void)
+{
+	struct disclosure_h d;
+	struct task_struct *p = current;
+
+	d.disclosure = p->mosix.disclosure;
+	d.uid = p->uid;
+	d.gid = p->gid;
+	d.pgrp = p->pgrp;
+	d.session = p->session;
+	d.tgid = p->tgid;
+	memcpy(d.comm, p->comm, sizeof(d.comm));
+	if(deputy_request(DEP_INFO, &d, sizeof(d), NULL, 0, 0, NULL, 0))
+		deputy_die_on_communication();
+}
+
+void
+deputy_async_requests(void)
+{
+	register struct task_struct *p = current;
+	register struct mosix_task *m = &p->mosix;
+	int w;
+
+	check_again:
+	process_ack(p, DREQ_CHECKSTAY);
+	while(m->prequest)
+		process_requests();
+	if(process_told(p, DREQ_URGENT))
+	{
+		process_ack(p, DREQ_URGENT);
+		comm_take_urgent();
+		if(deputy_request(DEP_TAKEURGENT, NULL, 0, NULL, 0, 0,
+			(void **)&w, -sizeof(w)))
+			goto check_again;
+		if(w)
+			mosix_add_to_whereto(p, w);
+	}
+	if(m->whereto)
+	{
+		follow_whereto();
+		if(!(m->dflags & DDEPUTY))
+			return;
+		goto check_again;
+	}
+	if(process_told(p, DREQ_CAPCNG))
+		sync_caps();
+#ifdef CONFIG_MOSIX_DFSA
+	if(process_told(p, DREQ_DFSASYNC))
+		deputy_resync_dfsa();
+#endif /* CONFIG_MOSIX_DFSA */
+	if(process_told(p, DREQ_NICECNG))
+	{
+		process_ack(p, DREQ_NICECNG);
+		mosix_inform_remote_of_nice();
+		goto check_again;
+	}
+	if(process_told(p, DREQ_INFOCNG))
+	{
+		process_ack(p, DREQ_INFOCNG);
+		mosix_inform_remote_of_info();
+		goto check_again;
+	}
+	if(process_told(p, DREQ_UPDOVERHEADS))
+	{
+		process_ack(p, DREQ_UPDOVERHEADS);
+		deputy_inform_remote_of_overheads();
+		goto check_again;
+	}
+	if((m->stay & DSTAY) ||
+		((process_told(p, DREQ_CHECKCONF)) && i_am_in_a_wrong_place()))
+	{
+		if(!mosix_go_home(1))
+		{
+			printk("Process %s, uid=%d, killed because it failed to migrate back here\n",
+				desc_mostask(m), p->uid);
+			printk("(possible reasons are exhaustion of swap-space, or network disconnection)\n");
+			send_sig(SIGKILL, p, 1);
+		}
+		done_checking_conf();
+		return;
+	}
+}
+
+static inline void
+deputy_communication_failed_msg(void)
+{
+	printk("Process %s, uid=%d, killed because it lost communication\n"
+		"with the remote site where it was running\n",
+		desc_mostask(NULL), current->uid);
+}
+
+void
+deputy_communication_failed(void)
+{
+	deputy_communication_failed_msg();
+	force_sig(SIGKILL, current);
+}
+
+NORET_TYPE void
+deputy_die_on_communication(void)
+{
+	deputy_communication_failed_msg();
+	do_exit(SIGKILL);
+#ifdef CONFIG_MOSIX_DIAG
+	panic("do_exit returned");
+#endif /* CONFIG_MOSIX_DIAG */
+}
+
+extern asmlinkage int FASTCALL(do_signal(struct pt_regs *, sigset_t *));
+
+void
+deputy_main_loop()
+{
+	register struct task_struct *p = current;
+	extern asmlinkage void do_syscall_trace(void);
+	void *head;
+	int hlen, type = 0;	/* compiler bug requires the =0 */
+	int delay_sigs = (p->mosix.dflags & (DTRACESYS1|DTRACESYS2)) != 0;
+	int has;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!(p->mosix.dflags & DSYNC))
+		panic("deputy start unsynced");
+#endif /* CONFIG_MOSIX_DIAG */
+	p->mosix.dflags &= ~(DTRACESYS1|DTRACESYS2);
+	while(p->mosix.dflags & DDEPUTY)
+	if(p->mosix.dflags & DSYNC)
+	{
+		if(HAS_ASYNC(p))
+			deputy_async_requests();
+		else if(!delay_sigs && signal_pending(p))
+			do_signal(mos_to_regs(&p->mosix), 0);
+		else
+		{
+			p->mosix.pass_regs = ALL_REGISTERS;
+			comm_send(DEP_USERMODE|USERMODE, NULL, 0, NULL, 0, 0);
+			p->mosix.dflags &= ~DSYNC;
+		}
+	}
+	else
+	{
+		has = comm_wait();
+		if(p->mosix.dflags & DFAKESIGNAL)
+		{
+			p->mosix.dflags &= ~DFAKESIGNAL;
+			evaluate_pending_signals_in_mosix_context();
+		}
+		if(!has)
+		{
+#ifdef CONFIG_MOSIX_DIAG
+			int was_checkconf = process_told(p, DREQ_CHECKCONF);
+#endif /* CONFIG_MOSIX_DIAG */
+			if(!HAS_ASYNC(p))
+			{
+				if(!signal_pending(p))
+				{
+					/* so why did we wake?
+					 * the only good reason would
+					 * be a DREQ_CHECKCONF while
+					 * we are NOT in a wrong place */
+#ifdef CONFIG_MOSIX_DIAG
+					if(was_checkconf)
+						continue;
+					printk("%s: no packet and no event\n",
+						desc_mostask(NULL));
+					mosix_panic("no packet+no event");
+#endif /* CONFIG_MOSIX_DIAG */
+					continue;
+				}
+				if(delay_sigs)
+				{
+					spin_lock_irq(&p->sigmask_lock);
+					p->sigpending = 0;
+					spin_unlock_irq(&p->sigmask_lock);
+					continue;	/* back to sleep */
+				}
+			}
+			p->mosix.dflags |= DSYNC;
+			if(comm_send(DEP_SYNC, NULL, 0, NULL, 0, 0))
+				deputy_die_on_communication();
+		}
+		p->mosix.dflags |= DSYNC;
+		if(delay_sigs)
+			evaluate_pending_signals_in_mosix_context();
+		if((type = comm_recv(&head, &hlen)) < 0)
+			deputy_die_on_communication();
+		if(type & ANYTIME)
+		{
+			if(deputy_handle_interim_request(type, head, hlen))
+				deputy_die_on_communication();
+		}
+		else switch(type)
+		{
+		case REM_NULLMSG:
+			comm_free(head);
+			continue;
+		case REM_ASIG:
+			deputy_analyse_remote_signals((struct asig_h *)head);
+			continue;
+		case REM_SYSCALL_TRACE:
+			delay_sigs ^= 1;
+			deputy_add_rusage((struct rusage *)head);
+			comm_free(head);
+			do_syscall_trace();
+			if(!(p->mosix.dflags & DDEPUTY))
+				break;
+			if(deputy_reply(REM_SYSCALL_TRACE, NULL, 0, NULL, 0, 0,
+				delay_sigs))
+				deputy_die_on_communication();
+			continue;
+		case REM_SYSCALL:
+			deputy_syscall(head, delay_sigs);
+			p = current;	/* for "fork" son */
+			continue;
+		case REM_BRING_ME_HOME:
+		case REM_MUST_COME_HOME:
+			mosix_go_home(type == REM_MUST_COME_HOME ? 2 : 1);
+			if((p->mosix.dflags & DDEPUTY) &&
+				comm_send(type|REPLY, NULL, 0, NULL, 0, 0))
+				deputy_die_on_communication();
+			continue;
+		default:
+			printk("Process %s, uid=%d, killed because it received"
+				" an unrecognized\n" "message type (0x%x) from"
+				" the remote site where it was running\n",
+				desc_mostask(NULL), current->uid, type);
+			do_exit(SIGKILL);
+		}
+	}
+}
+
+int
+deputy_reply(int type, void *hd, int hlen, void *dat, int dlen, int um, int delay_sigs)
+{
+	register struct task_struct *p = current;
+	int err;
+
+	type |= REPLY;
+	if(!(p->mosix.dflags & DNESTED) && (delay_sigs == 2 ||
+		(!HAS_ASYNC(p) && (delay_sigs || !signal_pending(p)))))
+	{
+		p->mosix.pass_regs = ALL_REGISTERS;
+		type |= USERMODE;
+	}
+	err = comm_send(type, hd, hlen, dat, dlen, um);
+	if(type & USERMODE)
+		p->mosix.dflags &= ~DSYNC;
+	return(err);
+}
+
+void
+mosix_inform_remote_of_nice(void)
+{
+	if(deputy_request(DEP_NICE, &current->nice, sizeof(current->nice),
+							NULL, 0, 0, NULL, 0))
+		deputy_die_on_communication();
+}
+
+void
+deputy_inform_remote_of_overheads(void)
+{
+	if(deputy_request(DEP_OPCOSTS, (caddr_t)deputy_here,
+		sizeof(deputy_here), NULL, 0, 0, NULL, 0))
+		deputy_die_on_communication();
+}
+
+void
+mosix_deputy_rusage(int final)
+{
+	struct rusage *r;
+
+	if(deputy_request(DEP_RUSAGE, &final, sizeof(final), NULL, 0, 0,
+						(void **)&r, sizeof(*r)))
+	{
+		if(!(current->mosix.dflags & DFINISHED))
+			deputy_communication_failed();
+		return;
+	}
+	deputy_add_rusage(r);
+	if(final)
+		current->mosix.exit_mem = r->ru_maxrss;
+	comm_free(r);
+}
+
+int
+mosix_deputy_restore_sigcontext(struct sigcontext *frame, int *eax)
+{
+	struct restore_sigcontext_ret_h r;
+
+	current->mosix.pass_regs = ALL_REGISTERS;
+	if(deputy_request(DEP_RESTORESIGCONTEXT, &frame, sizeof(frame), NULL,
+		0, 0, (void **)&r, -sizeof(r)))
+		r.result = 1;
+	*eax = r.eax;
+	return(r.result);
+}
+
+void
+mosix_deputy_setup_frame(unsigned long sig, struct k_sigaction *ka,
+	siginfo_t info, sigset_t *oldset)
+{
+	struct setupframe_parameters_h s;
+
+	s.sig = sig;
+	s.flags = ka->sa.sa_flags;
+	s.handler = ka->sa.sa_handler;
+	s.restorer = ka->sa.sa_restorer;
+	s.set = *oldset;
+	s.ss_sp = current->sas_ss_sp;
+	s.ss_size = current->sas_ss_size;
+	if(ka->sa.sa_flags & SA_SIGINFO)
+		s.info = info;
+	current->mosix.pass_regs = ALL_REGISTERS;
+	if(deputy_request(DEP_SETUPFRAME, &s, sizeof(s), NULL, 0, 0, NULL, 0))
+		deputy_die_on_communication();
+}
+
+int
+deputy_handle_interim_request(int type, void *head, int hlen)
+{
+	switch(type)
+	{
+		case REM_NOTHING:
+			comm_free(head);
+			return(comm_send(REM_NOTHING|REPLY, NULL, 0, NULL, 0, 0));
+		case REM_PAGE:
+			return(deputy_bring_page((struct bring_page_h *)head));
+		case REM_GETTSC:
+			return(deputy_tsc());
+		case REM_MORESTRINGS:
+			return(deputy_more_strings((struct execve_more_strings_h *)head));
+		case REM_BRING_ME_REGS:
+			return(deputy_bring_me_regs((unsigned long *)head));
+		case REM_GETALOAD:
+			return(send_local_aload(REM_GETALOAD|REPLY));
+		default:
+			printk("Process %s, uid=%d, received an unexpected "
+				"urgent request\n" "(type 0x%x) from the "
+				"remote site where it was running\n",
+				desc_mostask(NULL), current->uid, type);
+#ifdef CONFIG_MOSIX_UDB
+			mosix_panic("deputy_handle_interim_request");
+#endif /* CONFIG_MOSIX_UDB */
+			comm_free(head);
+			return(-EDIST);
+	}
+}
+
+int
+deputy_wait(int expect, void **head, int *hlen)
+{
+	int type, err;
+
+	while((type = comm_recv(head, hlen)) != expect)
+	if(type < 0)
+		return(type);
+	else if(type & ANYTIME)
+	{
+		if((err = deputy_handle_interim_request(type, *head, *hlen)))
+			return(err);
+	}
+	else
+	{
+		printk("DEPUTY: Unexpected non-urgent request type %x\n", type);
+		mosix_panic("deputy_wait");
+		comm_free(*head);
+		comm_flushdata(COMM_ALLDATA);
+	}
+	return(0);
+}
+
+int
+deputy_request(int type, void *header, int hlen, void *data, int dlen,
+	int uspace, void **result, int reslen)
+{
+	register struct task_struct *p = current;
+	int wasnested = (p->mosix.dflags & DNESTED);
+	int error;
+	void *head;
+	int rhlen;
+
+	p->mosix.dflags |= DNESTED;
+	if((error = comm_send(type, header, hlen, data, dlen, uspace)))
+		goto out;
+	if((error = deputy_wait(type|REPLY, &head, &rhlen)))
+		goto out;
+	if(reslen > 0)
+	{
+		if(rhlen > reslen)
+			goto lenerr;
+		if(result)
+			*result = head;
+	}
+	else
+	{
+		if(rhlen > -reslen && reslen)
+		{
+			comm_free(head);
+			lenerr:
+			printk("deputy_request type %x: %d instead of %d\n",
+				type, rhlen, reslen);
+			error = -EDIST;
+			goto out;
+		}
+		if(reslen)
+			memcpy(result, head, rhlen);
+		comm_free(head);
+	}
+	out:
+	if(!wasnested)
+		p->mosix.dflags &= ~DNESTED;
+	return(error);
+}
+
+unsigned long
+mosix_deputy_mmap(struct file *fp, unsigned long addr, int fixed,
+	unsigned long len, unsigned long flags, unsigned long off, off_t isize,
+	nopage_t nopage)
+{
+	struct mmap_parameters_h mp;
+	int error;
+	unsigned long result;
+
+	mp.addr = addr;
+	mp.fixed = fixed;
+	mp.len = len;
+	mp.flags = flags;
+	mp.pgoff = off;
+	mp.origin = PE;
+	if((mp.fp = fp))
+	{
+		mp.dp = fp->f_dentry;
+		mp.uniq = mp.fp->f_dentry->d_inode->i_unique;
+		mp.isize = mp.fp->f_dentry->d_inode->i_size;
+	}
+	mp.nopage = nopage;
+	if((error = deputy_request(DEP_MMAP, &mp, sizeof(mp), NULL, 0, 0,
+					(void **)&result, -sizeof(result))))
+		return(error);
+	return(result);
+}
+
+long
+mosix_deputy_brk(unsigned long addr, unsigned long len)
+{
+	struct brk_parameters_h b;
+	long error;
+	long result;
+
+	b.addr = addr;
+	b.len = len;
+	if((error = deputy_request(DEP_BRK, &b, sizeof(b), NULL, 0, 0,
+		(void **)&result, -sizeof(result))))
+		result = error;
+	return(result);
+}
+
+int
+deputy_munmap(unsigned long addr, size_t len)
+{
+	struct munmap_parameters_h mp;
+	int error;
+	int result;
+
+	mp.addr = addr;
+	mp.len = len;
+	if((error = deputy_request(DEP_MUNMAP, &mp, sizeof(mp), NULL, 0, 0,
+					(void **)&result, -sizeof(result))))
+		result = error;
+	return(result);
+}
+
+int
+deputy_mprotect(unsigned long addr, size_t len, unsigned long prot)
+{
+	struct mprotect_parameters_h mp;
+	int error;
+	int result;
+
+	mp.addr = addr;
+	mp.len = len;
+	mp.prot = prot;
+	if((error = deputy_request(DEP_MPROTECT, &mp, sizeof(mp), NULL, 0, 0,
+					(void **)&result, -sizeof(result))))
+		result = error;
+	return(result);
+}
+
+void
+deputy_analyse_remote_signals(struct asig_h *s)
+{
+	register int i;
+	siginfo_t info;
+	int back = 0;
+
+	while(s->nforced--)
+	{
+		if(comm_copydata(&info, sizeof(info), 0))
+			deputy_die_on_communication();
+		force_sig_info(info.si_signo, &info, current);
+	}
+	while(s->sigs)
+	{
+		switch(i = ffz(~s->sigs) + 1)
+		{
+			case FATAL_SIGSEGV:
+				force_sig(SIGSEGV, current);
+				break;
+			case REMOTE_FILE_RELEASED:
+				mosix_rebuild_file_list();
+				break;
+			case SIGSEGV:
+			case SIGKILL:
+			case SIGVTALRM:
+			case SIGPROF:
+			case SIGBUS:
+			case SIGIOT:
+			case SIGFPE:
+			case SIGILL:
+			case SIGXCPU:
+			case SIGXFSZ:
+			case SIGPWR:
+			case SIGTRAP:
+				send_sig(i, current, 1);
+				break;
+			case SIGTERM:
+				back = 1;
+				break;
+			default:
+				printk("%s - How did signal #%d arrive at REMOTE???\n",
+					desc_mostask(NULL), i);
+		}
+		s->sigs &= ~(1 << (i-1));
+	}
+	if(current->mosix.dflags & DINCOMING)
+		return;
+	comm_free(s);
+	if(back)
+		mosix_go_home(2);
+}
+
+#define	MAX_COPY_FROM_USER	(PAGE_SIZE)
+
+unsigned long
+deputy_copy_from_user(void *to, void *from, unsigned long size, int verify)
+{
+	struct user_copy_h u;
+	int result, non_cache;
+
+	while(size > 0)
+	{
+		if((result = copy_from_cache(to, (unsigned long)from, size,
+								&non_cache)))
+		{
+			if(!(size -= result))
+				break;
+			((char *)from) += result;
+			((char *)to) += result;
+			if(!non_cache)
+				continue;
+		}
+		u.addr = from;
+		u.size = non_cache > MAX_COPY_FROM_USER ? MAX_COPY_FROM_USER : non_cache;
+		u.verify = verify;
+		if(deputy_request(DEP_COPY_FROM_USER, &u, sizeof(u), NULL, 0, 0,
+			(void **)&result, -sizeof(result)))
+			break;
+		if(result)
+		{
+			if(result < u.size &&
+				comm_copydata(to, u.size - result, 0))
+				result = u.size;
+			size += result - u.size;
+			break;
+		}
+		if(comm_copydata(to, u.size, 0))
+			break;
+		size -= u.size;
+		((char *)from) += u.size;
+		((char *)to) += u.size;
+	}
+	return(size);
+}
+
+#define	MAX_COPY_TO_USER	(2*PAGE_SIZE)
+
+unsigned long
+deputy_copy_to_user(void *to, void *from, unsigned long size, int verify)
+{
+	struct user_copy_h u;
+	int result;
+	int non_cache;
+
+	while(size > 0)
+	{
+		if((result = copy_to_cache((unsigned long)to, from, size,
+								&non_cache)))
+		{
+			if(!(size -= result))
+				break;
+			((char *)from) += result;
+			((char *)to) += result;
+			if(!non_cache)
+				continue;
+		}
+		u.addr = to;
+		u.size = non_cache > MAX_COPY_TO_USER ? MAX_COPY_TO_USER : non_cache;
+		u.verify = verify;
+		if(deputy_request(DEP_COPY_TO_USER, &u, sizeof(u),
+			from, u.size, 0, (void **)&result, -sizeof(result)))
+			break;
+		if(result)
+		{
+			size += result - u.size;
+			break;
+		}
+		size -= u.size;
+		((char *)from) += u.size;
+		((char *)to) += u.size;
+	}
+	return(size);
+}
+
+unsigned long
+deputy_clear_user(void *to, int size, int verify)
+{
+	struct user_copy_h u;
+	int result;
+	int non_cache;
+
+	while(size > 0)
+	{
+		if((result = zero_cache(to, size, &non_cache)))
+		{
+			if(!(size -= result))
+				break;
+			((char *)to) += u.size;
+			if(!non_cache)
+				continue;
+		}
+		u.addr = to;
+		u.size = non_cache;
+		u.verify = verify;
+		if(deputy_request(DEP_CLEAR_USER, &u, sizeof(u), NULL, 0, 0,
+			(void **)&result, -sizeof(result)))
+			break;
+		if(result < 0)
+		{
+			size = result;
+			break;
+		}
+		size -= non_cache;
+		if(result)
+		{
+			size += result;
+			break;
+		}
+	}
+	return(size);
+}
+
+long
+deputy_strncpy_from_user(char *to, char *from, int max, int verify)
+{
+	struct user_copy_h u;
+	int result;
+	int non_cache;
+	int read = 0;
+	char *oto = to;
+	int omax = max;
+
+	while(max > 0)
+	{
+		if((result = copy_from_cache(to, (unsigned long)from, -max,
+								&non_cache)))
+		{
+			if(non_cache == -1)
+				result--;
+			read += result;
+			if(!(max -= result))
+				break;
+			to += result;
+			from += result;
+			if(!non_cache)
+				continue;
+		}
+		if(non_cache == -1)	/* 0 encountered */
+			break;
+		u.addr = from;
+		u.size = non_cache;
+		u.verify = verify;
+		if(deputy_request(DEP_STRNCPY_FROM_USER, &u, sizeof(u), NULL, 0, 0,
+			(void **)&result, -sizeof(result)))
+		{
+			result = -EFAULT;
+			break;
+		}
+#ifdef CONFIG_MOSIX_DIAG
+		if(result > non_cache)
+		{
+			printk("%s: deputy_strncpy_from_user: %d > %d\n",
+				desc_mostask(NULL), result, max);
+			result = -EFAULT;
+			break;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		if(result < 0)
+			break;
+		if(result && comm_copydata(to, result, 0))
+		{
+			result = -EFAULT;
+			break;
+		}
+		from += result;
+		to += result;
+		read += result;
+		max -= result;
+		if(result != non_cache)
+			break;
+	}
+	if(result >= 0)
+	{
+		result = read;
+		if(omax && read < omax)
+			oto[read] = '\0';
+	}
+	return(result);
+}
+
+long
+deputy_strnlen_user(char *from, long len)
+{
+	long result;
+	long read = 0;
+	int non_cache;
+	struct strnlen_user_h h;
+	int error = 0;
+
+	while(1)
+	{
+		result = strlen_cache(from, &non_cache);
+		read += result;
+		if(non_cache == -1)	/* 0 encountered */
+			break;
+		from += result;
+		if(read > len)
+			break;
+		if(!non_cache)
+			continue;
+		h.addr = from;
+		h.len = len - read;
+		if(deputy_request(DEP_STRNLEN_USER, (void *)&h, sizeof(h),
+			NULL, 0, 0, (void **)&result, -sizeof(result)) ||
+				result == 0)
+		{
+			error = 1;
+			break;
+		}
+		if(result > non_cache)
+			result = non_cache;
+		read += result;
+		if(read > len)
+			break;
+		from += result;
+	}
+	result = error ? 0 : (read > len ? len+1 : read);
+	return(result);
+}
+
+int
+deputy_verify_write(void *addr, unsigned long size)
+{
+	struct user_copy_h u;
+	int result;
+
+	u.addr = addr;
+	u.size = size;
+	if(all_in_cache((unsigned long)addr, size, 1))
+		result = 1;
+	else if(deputy_request(DEP_VERIFY_WRITE, &u, sizeof(u), NULL, 0, 0,
+		(void **)&result, -sizeof(result)))
+		result = 0;
+	return(result);
+}
+
+unsigned int
+deputy_csum_partial_copy_from_user(const char *src, char *dst, int len, int sum,
+							int *err_ptr)
+{
+	struct user_csum_copy_h u;
+	struct user_csum_copy_ret_h r;
+
+	/* must not play around with partial results, because unlike
+	 * "deputy_copy_from_user", we may not break the buffer
+	 * (at least not into non-4-byte-aligned segments, for now).
+	 */
+	if(any_in_cache((unsigned long)src, len))
+	{
+		if(deputy_copy_from_user(dst, (char *)src, len, 1))
+		{
+			*err_ptr |= 1;
+			return(sum);
+		}
+		return(csum_partial(dst, len, sum));
+	}
+	while(len > 0)
+	{
+		u.addr = (void *)src;
+		u.len = len > MAX_COPY_FROM_USER ? MAX_COPY_FROM_USER : len;
+		u.sum = sum;
+		if(deputy_request(DEP_CSUM_COPY_FROM_USER, &u, sizeof(u),
+			NULL, 0, 0, (void **)&r, -sizeof(r)))
+		{
+			*err_ptr |= 1;
+			return(0);
+		}
+		sum = r.newsum;
+		if(r.error || comm_copydata(dst, len, 0))
+		{
+			*err_ptr |= 1;
+			return(sum);
+		}
+		len -= u.len;
+		((char *)src) += u.len;
+		dst += u.len;
+	}
+	return(sum);
+}
+
+unsigned int
+deputy_csum_partial_copy_to_user(const char *src, char *dst, int len, int sum,
+							int *err_ptr)
+{
+	unsigned int newsum = csum_partial(src, len, sum);
+
+	if(deputy_copy_to_user(dst, (char *)src, len, 1))
+		*err_ptr = -EINVAL;
+	return(newsum);
+}
+
+struct int6 {int x[6];};
+
+void
+deputy_syscall(struct syscall_h *s, int delay_sigs)
+{
+	register struct task_struct *p = current;
+	extern void *sys_call_table[];
+	long (*func)(struct int6);
+	struct syscall_ret_h r;
+	int n = s->n;
+	struct pt_regs regs;
+	char *cdata, *tofree;
+	int l;
+
+	if(p->mosix.deputy_regs)
+		regs = *(mos_to_regs(&p->mosix));
+	memcpy((caddr_t)&regs, (caddr_t)s->args, sizeof(s->args));
+	open_ucache_envelope(s);
+	comm_free(s);
+	switch(n)
+	{
+		/* Add to this list all machine-dependent system-calls that
+		 * take the parameters' address, assuming it is the process'
+		 * registers: Such routines are all in "arch/i386/ * / *"
+		 */
+		case __NR_fork:
+		case __NR_vfork:
+		case __NR_clone:
+		case __NR_execve:
+		case __NR_iopl:
+		case __NR_ioperm:
+		case __NR_sigsuspend:
+		case __NR_rt_sigsuspend:
+		case __NR_sigreturn:
+		case __NR_rt_sigreturn:
+		case __NR_sigaltstack:
+		case __NR_vm86old:
+		case __NR_vm86:
+			if(delay_sigs)
+				p->mosix.dflags |= DTRACESYS1;
+				/* (for the son to set "delay_sigs") */
+			r.ret = call_with_regs((void *)sys_call_table[n],
+								&regs, &regs);
+			p->mosix.dflags &= ~DTRACESYS1;
+			if(p->mosix.deputy_regs ||
+					!(current->mosix.dflags & DDEPUTY))
+			/* sorry, cannot keep it in "regs" after we return */
+				*(mos_to_regs(&p->mosix)) = regs;
+			break;
+		default:
+			func = (__typeof__(func)) sys_call_table[n];
+			r.ret = func(*((struct int6 *)&regs));
+			p = current;
+			break;
+	}
+	if(!(p->mosix.dflags & DDEPUTY))
+	{
+		mos_to_regs(&current->mosix)->eax = r.ret;
+		return;
+	}
+	cdata = deputy_pack_read_cache_data(&l, &r, &tofree);
+	cli();
+	r.deputytime = p->mosix.deputytime;
+	p->mosix.deputytime = 0;
+	sti();
+	if(deputy_reply(REM_SYSCALL, &r, sizeof(r), cdata, l, 0, delay_sigs))
+	{
+		if(tofree)
+			kfree(tofree);
+		deputy_die_on_communication();
+	}
+	if(tofree)
+		kfree(tofree);
+}
+
+void
+mosix_deputy_rlimit(int resource, struct rlimit r)
+{
+	struct rlimit_h l;
+
+	l.resource = resource;
+	l.limit = r;
+	deputy_request(DEP_RLIMIT, &l, sizeof(l), NULL, 0, 0, NULL, 0);
+}
+
+int
+deputy_bring_page(struct bring_page_h *b)
+{
+	struct file *fp = b->fp;
+	struct vm_area_struct v;
+	struct page_ret_h r;
+	int err;
+	int address = b->offset;
+	struct page *page;
+	register struct task_struct *p = current;
+
+	v.vm_start = v.vm_pgoff = 0;
+	v.vm_end = address + PAGE_SIZE;
+	v.vm_mm = p->mm;	/* (eg. NULL) */
+	v.vm_file = fp;
+	v.vm_flags = 0;		/* anything really, but VM_SHARED */
+
+	deeper_sleep();
+	page = b->nopage(&v, address, 0);
+	lighter_sleep();
+	if(page == NOPAGE_OOM)
+	{
+		r.ret = -ENOMEM;
+		page = 0;
+	}
+	else
+		r.ret = page ? 0 : -EFBIG;
+	comm_free(b);
+	cli();
+	r.deputytime = p->mosix.deputytime;
+	p->mosix.deputytime = 0;
+	sti();
+	err = deputy_reply(REM_PAGE, &r, sizeof(r),
+		page ? kmap(page) : NULL, page ? PAGE_SIZE : 0, 0, 2);
+	if(page)
+	{
+		kunmap(page);
+		__free_page(page);
+	}
+	return(err);
+}
+
+int
+deputy_tsc(void)
+{
+	u64 r;
+
+	rdtsc(*((unsigned long *)&r), *(((unsigned long *)&r) + 1));
+	return(deputy_reply(REM_GETTSC|REPLY, &r, sizeof(r), NULL, 0, 0, 2));
+}
+
+void
+deputy_add_rusage(struct rusage *r)
+{
+	register struct task_struct *p = current;
+	int64_t ut = r->ru_utime.tv_sec * (int64_t)HZ +
+						r->ru_utime.tv_usec*HZ/MILLION;
+	int64_t st = r->ru_stime.tv_sec * (int64_t)HZ +
+						r->ru_stime.tv_usec*HZ/MILLION;
+
+	cli();
+	p->times.tms_utime += ut;
+	p->times.tms_stime += st;
+	sti();
+	p->min_flt += r->ru_minflt;
+	p->maj_flt += r->ru_majflt;
+	p->nswap += r->ru_nswap;
+}
+
+void
+mosix_deputy_count_args(char **argp, char **envp, int *argc, int *envc)
+{
+	struct execve_counts_h e;
+	struct execve_counts_ret_h r;
+
+	e.argp = argp;
+	e.envp = envp;
+	if(deputy_request(DEP_EXECVE_COUNTS, &e, sizeof(e), NULL, 0, 0,
+		(void **)&r, -sizeof(r)))
+		*argc = -EFAULT;
+	else
+	{
+		*argc = r.argc;
+		*envc = r.envc;
+	}
+}
+
+static inline int
+fill_strings_page(int pgno, int len)
+{
+	struct linux_binprm *bprm;
+	struct page *page;
+	char *kaddr;
+	int ret;
+
+	if(!pgno || len == 0)
+		return(0);
+	if(!(bprm = current->mosix.inexec) || pgno < 0 ||
+		pgno > MAX_ARG_PAGES ||
+		len < 0 || len > PAGE_SIZE || bprm->page[pgno-1])
+	{
+		printk("%s - Improper strings-page(%d:%d)\n",
+			desc_mostask(NULL), pgno, len);
+		comm_flushdata(COMM_ALLDATA);
+		return(-EFAULT);
+	}
+	if(!(page = alloc_page(GFP_HIGHUSER)))
+	{
+		comm_flushdata(COMM_ALLDATA);
+		return(0); /* error will be detected by missing the page */
+	}
+	bprm->page[pgno-1] = page;
+	kaddr = kmap(page);
+	ret = comm_copydata(kaddr + (PAGE_SIZE - len), len, 0);
+	kunmap(page);
+	return(ret);
+}
+
+int
+mosix_deputy_bring_strings(struct linux_binprm *bprm, char *filename,
+						char **envp, char **argp)
+{
+	struct execve_bring_strings_h b;
+	struct execve_bring_strings_ret_h r;
+	int i;
+
+	b.p = bprm->p;
+	b.filename = filename;
+	b.envp = envp;
+	b.envc = bprm->envc;
+	b.argp = argp;
+	b.argc = bprm->argc;
+	if(deputy_request(DEP_BRING_STRINGS, &b, sizeof(b), NULL, 0, 0,
+		(void **)&r, -sizeof(r)))
+		return(-ENOMEM);
+	if(r.result)
+	{
+		comm_flushdata(COMM_ALLDATA);
+		return(r.result);
+	}
+	bprm->p = r.p;
+	bprm->exec = r.exec;
+	fill_strings_page(r.pgno, r.len);
+	for(i = r.p / PAGE_SIZE ; i < MAX_ARG_PAGES ; i++)
+	if(!bprm->page[i])
+	  /* "fill_strings_page" or one of the "deputy_more_strings" failed */
+		return(-EAGAIN);
+	return(0);
+}
+
+int
+deputy_more_strings(struct execve_more_strings_h *m)
+{
+	int result = fill_strings_page(m->pgno, m->len);
+
+	comm_free(m);
+	if(result == -EAGAIN)
+		result = 0;
+	return(result);
+}
+
+int
+deputy_bring_me_regs(unsigned long *bring)
+{
+	current->mosix.pass_regs |= *bring & current->mosix.deputy_regs;
+	comm_free(bring);
+	return(comm_send(REM_BRING_ME_REGS|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+mosix_deputy_setup_args(int how, unsigned long *start_stack_p)
+{
+	struct execve_setup_args_h e;
+	struct execve_setup_args_ret_h r;
+	register struct linux_binprm *bprm = current->mosix.inexec;
+	int i, err;
+	struct page *page;
+	char *kaddr = NULL;
+
+	e.create = 1;
+	for(i = 0 ; i < MAX_ARG_PAGES-1 ; i++)
+	if((page = bprm->page[i]))
+	{
+		e.how = SETUP_ARGS_NOTYET;
+		e.pgno = i+1;
+		e.len = (i+1) * PAGE_SIZE - bprm->p;
+		if(e.len > PAGE_SIZE)
+			e.len = PAGE_SIZE;
+		kaddr = kmap(page);
+		err = comm_send(DEP_SETUP_ARGS, &e, sizeof(e),
+					kaddr + (PAGE_SIZE - e.len), e.len, 0);
+		kunmap(page);
+		if(err)
+			return(-EDIST);
+		e.create = 0;
+	}
+	e.exec = bprm->exec;
+	e.argc = bprm->argc;
+	e.envc = bprm->envc;
+	e.personality = current->personality;
+	e.how = how;
+	if((page = bprm->page[MAX_ARG_PAGES-1]))
+	{
+		e.pgno = MAX_ARG_PAGES;
+		e.len = MAX_ARG_PAGES * PAGE_SIZE - bprm->p;
+		if(e.len > PAGE_SIZE)
+			e.len = PAGE_SIZE;
+		kaddr = kmap(page);
+	}
+	else
+		e.len = e.pgno = 0;
+	e.p = bprm->p;
+	err = deputy_request(DEP_SETUP_ARGS, &e, sizeof(e),
+		e.len ? kaddr + (PAGE_SIZE - e.len) : NULL, e.len, 0,
+						(void **)&r, -sizeof(r));
+	if(page)
+		kunmap(page);
+	if(err)
+		return(-EDIST);
+	bprm->loader = r.loader;
+	bprm->exec = r.exec;
+	bprm->p = r.p;
+	for(i = 0 ; i < MAX_ARG_PAGES ; i++)
+	if(bprm->page[i])
+	{
+		__free_page(bprm->page[i]);
+		bprm->page[i] = 0;
+	}
+	if(start_stack_p)
+		*start_stack_p = r.start_stack;
+	return(r.reply);
+}
+
+int
+mosix_deputy_exec_mmap(char *filename)
+{
+	int r;
+
+	flush_ucache();
+	if(deputy_request(DEP_EXEC_MMAP, NULL, 0, NULL, 0, 0,
+						(void **)&r, -sizeof(r)))
+		return(-ENOMEM);
+	if(!r)
+		mosix_clear_all_held_files(current);
+	return(r);
+}
+
+int
+mosix_deputy_dump_thread(struct user *u)
+{
+	return(deputy_request(DEP_DUMP_THREAD, NULL, 0, NULL, 0, 0,
+		(void **)u, -sizeof(struct user)));
+}
+
+void
+mosix_deputy_init_aout_mm(struct exec *ex)
+{
+	deputy_request(DEP_INIT_AOUT_MM, ex, sizeof(*ex), NULL, 0, 0, NULL, 0);
+}
+
+unsigned long
+mosix_deputy_elf_setup(char *p, int argc, int envc, struct elfhdr *exec,
+	unsigned long addr, unsigned long load_bias,
+	unsigned long interp_load_addr, int ibcs,
+	int add_arg_start, unsigned long elf_brk, unsigned long end_code,
+	unsigned long start_code, unsigned long start_data,
+	unsigned long end_data, unsigned long elf_bss,
+	unsigned long personality, struct elf_tables_extras *extras)
+{
+	struct execve_elf_setup_h e;
+	unsigned long r;
+
+	e.p = p;
+	e.argc = argc;
+	e.envc = envc;
+	if((e.hasexec = (exec != NULL)))
+	{
+		e.exec_e_phoff = exec->e_phoff;
+		e.exec_e_phnum = exec->e_phnum;
+		e.exec_e_entry = exec->e_entry;
+	}
+	e.addr = addr;
+	e.load_bias = load_bias;
+	e.interp_load_addr = interp_load_addr;
+	e.ibcs = ibcs;
+	e.extras = *extras;
+	e.add_arg_start = add_arg_start,
+	e.elf_brk = elf_brk;
+	e.end_code = end_code;
+	e.start_code = start_code;
+	e.end_data = end_data;
+	e.start_data = start_data;
+	e.elf_bss = elf_bss;
+	e.personality = personality;
+
+	if(deputy_request(DEP_ELF_SETUP, &e, sizeof(e), NULL, 0, 0,
+		(void **)&r, -sizeof(r)))
+	{
+		if(current->mosix.dflags & DDEPUTY)
+			deputy_communication_failed();
+		r = (unsigned long)e.p;	/* we did nothing, keep same */
+	}
+	return(r);
+}
+
+void
+mosix_deputy_fix_elf_aout_interp(unsigned bss, unsigned data, unsigned text)
+{
+	struct execve_fix_elf_aout_h f;
+
+	f.bss = bss;
+	f.data = data;
+	f.text = text;
+	deputy_request(DEP_FIX_ELF_AOUT, &f, sizeof(f), NULL, 0, 0, NULL, 0);
+}
+
+int
+mosix_deputy_list_vmas(struct vmalist **vmasp, unsigned long *argstartp,
+	unsigned long *argendp)
+{
+	struct list_vmas_ret_h r;
+
+	if(deputy_request(DEP_LIST_VMAS, NULL, 0, NULL, 0, 0, (void **)&r,
+		-sizeof(r)) || r.n < 0)
+		return(-1);
+	if(r.n == 0)
+		*vmasp = NULL;
+	else
+	{
+		if(!(*vmasp = kmalloc(r.n*sizeof(struct vmalist), GFP_KERNEL)))
+			return(-1);
+		if(comm_copydata(*vmasp, r.n * sizeof(struct vmalist), 0))
+			return(-1);
+	}
+	*argstartp = r.argstart;
+	*argendp = r.argend;
+	return(r.n);
+}
+
+/*
+ * migrated away - shed memory etc.
+ */
+void
+deputy_startup(void)
+{
+	register struct task_struct *p = current;
+
+	exit_mm(p);
+	p->mosix.pages_i_bring = 0;
+	read_lock(&tasklist_lock);
+	p->mosix.ancesstor = NULL;
+	read_unlock(&tasklist_lock);
+#ifdef CONFIG_MOSIX_DFSA
+	tell_process(p, DREQ_NOTUPTODATE);
+#endif /* CONFIG_MOSIX_DFSA */
+}
+
+int
+mosix_deputy_personality(unsigned long personality)
+{
+	int result;
+
+	if(deputy_request(DEP_PERSONALITY, &personality, sizeof(personality),
+		NULL, 0, 0, (void **)&result, -sizeof(result)))
+		return(-1);
+	return(result);
+}
+
+int
+mosix_deputy_dump_fpu(struct user_i387_struct *f)
+{
+	int r;
+
+	if(deputy_request(DEP_DUMP_FPU, NULL, 0, NULL, 0, 0,
+		(void **)&r, -sizeof(r)))
+		return(0);
+	if(r && comm_copydata(f, sizeof(*f), 0))
+		return(0);
+	return(r);
+}
+
+int
+mosix_deputy_fork(struct task_struct *son, int migrated, unsigned long usp)
+{
+	struct mosix_task *m = &current->mosix;
+	void *head;
+	int hlen;
+	int type;
+	int where;
+	mosix_link *sonsock = NULL;
+	struct fork_h f;
+	int n;
+
+	f.usp = usp;
+	f.do_forkmigrate = !migrated;
+	f.pid = son->pid;
+	resend:
+	m->pass_regs = ALL_REGISTERS & ~BIT_OF_REGISTER(eax);
+	if(comm_send(DEP_PLEASE_FORK, &f, sizeof(f), NULL, 0, 0))
+	{
+		bad:
+		if(sonsock)
+			comm_close(sonsock);
+		deputy_communication_failed();
+		return(-EDIST);
+	}
+	son->mosix.deputy_regs = m->deputy_regs;
+	while(1)
+	switch(type = comm_recv(&head, &hlen))
+	{
+		default:
+			if(type < 0)
+				goto bad;
+			if(!(type & ANYTIME))
+			{
+				printk("Unexpected reply (0x%x) to fork request"
+					"\n", type);
+				goto bad;
+			}
+			if(deputy_handle_interim_request(type, head, hlen))
+				goto bad;
+			break;
+		case REM_MUST_COME_HOME:
+		case REM_BRING_ME_HOME:
+			/* comm_free(head); not needed - it's empty */ 
+			go_home_first:
+			if(sonsock)
+			{
+				comm_close(sonsock);
+				sonsock = NULL;
+			}
+			if(passto((type == REM_MUST_COME_HOME) ?
+				MUSTGOHOME : GOBACKHOME, 0))
+				return(-EAGAIN);
+			came_home:
+			if(sonsock)
+			{
+				comm_close(sonsock);
+				sonsock = NULL;
+			}
+			son->mosix.whereami = 0;
+			undeputy(son);
+			return(0);
+		case REM_BRING_ME_TO:
+			where = *((int *)head);
+			comm_free(head);
+			if(sonsock)
+			{
+				comm_close(sonsock);
+				sonsock = NULL;
+			}
+			if(!passto(where, 0))
+			{
+				if(!(m->dflags & DDEPUTY))
+					goto came_home;
+				son->mosix.whereami = m->whereami;
+				f.do_forkmigrate = 0;
+				goto resend;
+			}
+			if(comm_send(REM_BRING_ME_TO|REPLY, NULL, 0, NULL, 0,0))
+				goto bad;
+			break;
+		case REM_CONSIDERING:
+			/* comm_free(head); not needed - it's empty */ 
+			if(sonsock)
+			{
+				comm_close(sonsock);
+				sonsock = NULL;
+			}
+			n = m->nmigs;
+			coordinate(BALANCE, 1);
+			f.do_forkmigrate = 0;	/* once only */
+			if(!(m->dflags & DDEPUTY))
+				goto came_home;
+			son->mosix.whereami = m->whereami;
+			if(m->nmigs != n)
+				goto resend;
+			break;
+		case REM_CONNECT_TO:
+			if(sonsock)
+				mosix_panic("Dup REM_CONNECT_TO");
+			sonsock = comm_open(COMM_TOADDR, (mosix_addr *)head,
+				comm_connect_timo);
+			comm_free(head);
+			n = (sonsock != NULL);
+			if(comm_send(REM_CONNECT_TO|REPLY, &n, sizeof(n),
+								NULL, 0, 0))
+				goto bad;
+			break;
+		case DEP_PLEASE_FORK|REPLY:
+			n = *((int *)head);
+			comm_free(head);
+			if(n)
+				goto go_home_first;
+			if(!sonsock)
+			{
+				mosix_panic("deputy_fork: no sonsock");
+				goto go_home_first;
+			}
+			son->mosix.dflags |= (DDEPUTY|DSYNC|
+						(m->dflags & DDUMPABLE));
+			comm_use(son, sonsock);
+			return(0);
+	}
+}
diff -ruN linux-2.4.16/mos/dfsa.c linux-2.4.16-mosix/mos/dfsa.c
--- linux-2.4.16/mos/dfsa.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/dfsa.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,2803 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#include <asm/uaccess.h>
+#include <linux/mosix.h>
+#include <mos/protocol.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/stddef.h>
+#include <linux/module.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/proc_fs.h>
+
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+
+#define	CLEAR_ALL(fls,fld)	memset(fls->fld, 0, fls->max_fdset/8)
+
+struct dfsatab *dfsatab;
+struct vfsmount *dfsa_mounts[MAXDFSAFS];
+struct
+{
+	struct vfsmount *mnt;
+	struct dentry *dentry;
+} dfsa_links[MAXDFSALINKS];
+char dfsa_being_cancelled[MAXDFSAFS];
+char dfsa_recheck_mount[MAXDFSAFS];
+struct dentry *bad_deputy_dfsaentry;
+int dfsa_disabled = 1;
+DECLARE_MUTEX(dfsa_modify_lock);
+
+extern struct inode_operations all_bad_inode_operations;
+extern struct file_operations all_bad_file_operations;
+
+void
+dfsa_init(void)
+{
+	struct inode *ip;
+
+	if(!(dfsatab = kmalloc(sizeof(struct dfsatab), GFP_KERNEL)))
+		panic("dfsa_init");
+	dfsatab->len = sizeof(struct dfsatab);
+	dfsatab->ndefs = 0;
+	if(!(bad_deputy_dfsaentry =
+			d_alloc(NULL, &(const struct qstr) { "/", 1, 0 })))
+		panic("dfsa_init: d_alloc");
+	if(!(ip = get_empty_inode()))
+		panic("dfsa_init: empty inode");
+	ip->i_mode = S_IFREG;
+	ip->i_op = &all_bad_inode_operations;
+	ip->i_fop = &all_bad_file_operations;
+	bad_deputy_dfsaentry->d_inode = ip;
+	bad_deputy_dfsaentry->d_parent = bad_deputy_dfsaentry;
+	dfsa_disabled = 0;
+}
+
+int
+dfsa_option(char *data, int *result)
+{
+	int n;
+	int has = 0;
+
+	if(!data)
+		return(0);
+	while(1)
+	{
+		while(*data && (*data != 'd' || *(data+1) != 'f' ||
+			*(data+2) != 's' || *(data+3) != 'a' ||
+			*(data+4) != '='))
+			data++;
+		if(!*data)
+			return(has);
+		data += 5;
+		if(*data < '0' || *data > '9')
+		{
+			printk("WARNING: Invalid 'dfsa=' value <%s>\n", data);
+			continue;
+		}
+		for(n = 0 ; *data >= '0' && *data <= '9' ; data++)
+		{
+			n = n * 10 + *data - '0';
+			if(n > 32767)
+				break;
+		}
+		if(n <= 32767)
+		{
+			has = 1;
+			*result = n;
+		}
+		else
+			printk("DFSA-number option overflow!\n");
+	}
+	return(has);
+}
+
+void
+dfsa_is_not_up_to_date(void)
+{
+	tell_process(current, DREQ_NOTUPTODATE);
+}
+
+void
+dfsa_pwd_changed(void)
+{
+	current->mosix.dupdates |= DFSA_UPDCDIR;
+}
+
+#define	DFSA_MOUNT_MOUNTED	1
+#define	DFSA_MOUNT_RDONLY	2
+#define	DFSA_MOUNT_SYNC		4
+#define	DFSA_MOUNT_NOATIME	8
+#define	DFSA_MOUNT_NODIRATIME	16
+#define	DFSA_MOUNT_SYMLINK	32
+
+int
+important_fs_flags(unsigned long flags)
+{
+	int f = DFSA_MOUNT_MOUNTED;
+
+	if(flags & MS_RDONLY)
+		f |= DFSA_MOUNT_RDONLY;
+	if(flags & MS_SYNCHRONOUS)
+		f |= DFSA_MOUNT_SYNC;
+	if(flags & MS_NOATIME)
+		f |= DFSA_MOUNT_NOATIME;
+	if(flags & MS_NODIRATIME)
+		f |= DFSA_MOUNT_NODIRATIME;
+	return(f);
+}
+
+/*
+ * 0 = same
+ * 1 = first string comes first
+ * -1 = second string comes first
+ * normally sorted alphabetically -
+ * but if one string begins with the other, the LONGER comes first.
+ */
+static inline int
+dfsa_name_compare(char *n1, char *n2)
+{
+	register unsigned char *u1, *u2;
+	int a, b;
+
+	for(u1 = n1 , u2 = n2 ; *u1 && *u1 == *u2 ; u1++ , u2++)
+		;
+	a = *u1;
+	b = *u2;
+	if(!a)
+		return(b ? -1 : 0);
+	if(!b || a < b)
+		return(1);
+	return(-1);
+}
+
+static inline char *
+mntpath(struct vfsmount *mnt)
+{
+	char *page = (char *)__get_free_page(GFP_KERNEL);
+	struct vfsmount *rootmnt;
+	struct dentry *root;
+
+	if(!page)
+		return(NULL);
+	read_lock(&init_task.fs->lock);
+	rootmnt = mntget(init_task.fs->rootmnt);
+	root = dget(init_task.fs->root);
+	read_unlock(&init_task.fs->lock);
+	spin_lock(&dcache_lock);
+	page = __d_path(mnt->mnt_root, mnt, root, rootmnt, page, PAGE_SIZE);
+	spin_unlock(&dcache_lock);
+	dput(root);
+	mntput(rootmnt);
+	return(page);
+}
+
+static inline void
+dfsa_set_dfsa(struct vfsmount *mnt, int now, int prev)
+{
+	int differ = (mnt->mnt_dfsano != now);
+
+	MOSIX_LOCKED;
+	mnt->mnt_dfsaprev = prev;
+	mnt->mnt_dfsano = now;
+	if(differ && mnt->mnt_sb->s_op->dfsa_changed)
+		mnt->mnt_sb->s_op->dfsa_changed(mnt, now);
+}
+
+int
+dfsa_setmnt(struct vfsmount *mnt, int num, unsigned long flags)
+{
+	int ind, sz, oldnum = 0;
+	register int i, j;
+	char *x, *y;
+	struct dfsatab *new, *old;
+	int error = 0;
+	int c, done;
+	char *dir;
+	struct super_block *sb;
+
+	if(num < 0 || num > MAXDFSAFS)
+	{
+		printk("Invalid DFSA index (%d), range is 1-%d "
+			"(or 0 to cancel)\n", num, MAXDFSAFS);
+		return(-EINVAL);
+	}
+	sb = mnt->mnt_sb;
+	if(num && (!sb->s_op || !sb->s_op->identify || !sb->s_op->reconstruct))
+	{
+		printk("%s: Not a DFSA-compatible file-system\n",
+							sb->s_type->name);
+		return(-EPERM);
+	}
+	if(!(dir = mntpath(mnt)))
+		return(-ENOMEM);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_DFSA)
+		printk("dfsa_setmnt(<%s>,%d)\n", dir, num);
+#endif /* CONFIG_MOSIX_DEBUG */
+	error = -EBUSY;
+	if(down_interruptible(&dfsa_modify_lock))
+		goto freedir;
+	lock_mosix();
+	if(dfsa_disabled)
+	{
+		if(num == 0)
+			error = 0;
+		goto out;
+	}
+	sz = sizeof(struct dfsatab);
+	ind = -1;
+	for(i = 0 ; i < dfsatab->ndefs ; i++)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		if(!strcmp(dir, x))
+		{
+			oldnum = dfsatab->dfsdef[i].defno;
+			if(oldnum == num && dfsatab->dfsdef[i].mounted ==
+						important_fs_flags(flags))
+			{
+				error = 0;	/* nothing to do */
+				goto out;
+			} 
+			if(oldnum > MAXDFSAFS)
+			{
+				printk("Conflict: mount-point <%s> is declared "
+					"as a DFSA symbolic link\n", dir);
+				error = -EBUSY;
+				goto out;
+			}
+			ind = i;
+		}
+		else if(dfsatab->dfsdef[i].defno == num)
+		{
+			printk("DFSA entry #%d already held for <%s>\n",num, x);
+			error = -EBUSY;
+			goto out;
+		}
+		else
+			sz += sizeof(struct dfsdef) + strlen(x) + 1;
+	}
+	if(ind == -1 && num == 0)
+	{
+		error = 0;	/* nothing to do */
+		goto out;
+	}
+	if(num)
+		sz += sizeof(struct dfsdef) + strlen(dir) + 1;
+	unlock_mosix();
+	new = (sz >= 65535) ? NULL : kmalloc(sz, GFP_KERNEL);
+	lock_mosix();
+	if(!new)
+	{
+		error = -ENOMEM;
+		goto out;
+	}
+	if(ind != -1)
+	{
+		if(num)
+			printk("Changing DFSA index of <%s> from %d to %d\n",
+				dir, oldnum, num);
+		else
+			printk("Cancelling DFSA entry #%d (was <%s>)\n",
+				oldnum, dir);
+		dfsa_being_cancelled[oldnum-1] = 1;
+		dfsa_set_dfsa(mnt, 0, mnt->mnt_dfsano);
+		unlock_mosix();
+		error = dfsa_sync(1);
+		lock_mosix();
+		if(error)
+		{
+			printk("DFSA interrupted: not %s <%s>\n",
+				num ? "Changing" : "Cancelling", dir);
+			dfsa_set_dfsa(mnt, mnt->mnt_dfsaprev, 0);
+			dfsa_being_cancelled[oldnum-1] = 0;
+			dfsa_sync(0);
+			kfree(new);
+			goto out;
+		}
+		mntput(dfsa_mounts[oldnum-1]);
+		dfsa_mounts[oldnum-1] = NULL;
+		dfsa_set_dfsa(mnt, num, 0);
+		dfsa_being_cancelled[oldnum-1] = 0;
+	}
+	else
+	{
+		printk("Adding <%s> as DFSA entry #%d\n", dir, num);
+		dfsa_set_dfsa(mnt, num, 0);
+	}
+	/* compile the new table */
+	new->len = sz;
+	new->ndefs = dfsatab->ndefs - (ind != -1) + (num != 0);
+	y = (char *)&new->dfsdef[(int)new->ndefs];
+	done = 0;
+	for(j = i = 0 ; i < dfsatab->ndefs ; i++)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		if(!done && (c = dfsa_name_compare(dir, x)) <= 0)
+		{
+			done = 1;
+			if(num)
+			{
+				new->dfsdef[j].defno = num;
+				new->dfsdef[j].mounted =
+						important_fs_flags(flags);
+				new->dfsdef[j].offset = y - (char *)new;
+				strcpy(y, dir);
+				while(*y++)
+					;
+				j++;
+			}
+			if(c == 0)
+				continue;
+		}
+		new->dfsdef[j] = dfsatab->dfsdef[i];
+		new->dfsdef[j].offset = y - (char *)new;
+		while(*x)
+			*y++ = *x++;
+		*y++ = '\0';
+		j++;
+	}
+	if(num && !done)
+	{
+		new->dfsdef[j].defno = num;
+		new->dfsdef[j].mounted = important_fs_flags(flags);
+		new->dfsdef[j].offset = y - (char *)new;
+		strcpy(y, dir);
+	}
+	old = dfsatab;
+	dfsatab = new;
+	if(num)
+		dfsa_mounts[num-1] = mntget(mnt);
+	kfree(old);
+	dfsa_sync(0);
+	error = 0;
+	out:
+	unlock_mosix();
+	up(&dfsa_modify_lock);
+	freedir:
+	free_page(((unsigned long)dir) & PAGE_MASK);
+	return(error);
+}
+
+int
+dfsa_addlink(char *link)
+{
+	int i = strlen(link), j;
+	char *x, *y;
+	int ret;
+	struct nameidata nd;
+	struct vfsmount *mnt;
+	struct dentry *dp;
+	struct dfsatab *new, *old;
+	int sz = sizeof(struct dfsatab) + sizeof(struct dfsdef) + i + 1;
+	int linkno;
+	int added = 0;
+	umode_t mode;
+
+	if(i > MAXDFSALINKLEN)
+		return(-ENAMETOOLONG);
+	if(*link != '/')
+	{
+		printk("DFSA: <%s> must be an absolute path-name.\n", link);
+		return(-EINVAL);
+	}
+	if (path_init(link, LOOKUP_POSITIVE, &nd) && (ret=path_walk(link, &nd)))
+		return(ret);
+	ret = -EINVAL;
+	if(!S_ISLNK(nd.dentry->d_inode->i_mode))
+	{
+		printk("DFSA: <%s> is not a link!\n", link);
+		goto release;
+	}
+	path_release(&nd);
+	if (path_init(link, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd) &&
+		(ret = path_walk(link, &nd)))
+	{
+		printk("DFSA: <%s> symlink is loose (errno=%d)\n", link, ret);
+		return(-EINVAL);
+	}
+	mode = nd.dentry->d_inode->i_mode;
+	if(!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
+	{
+		printk("DFSA: <%s> points to a special file!\n", link);
+		goto release;
+	}
+	if(!nd.mnt->mnt_sb->s_op->identify)
+	{
+		printk("<%s> points to a file-system not supported by DFSA.\n",
+									link);
+		goto release;
+	}
+	ret = -EINTR;
+	if(down_interruptible(&dfsa_modify_lock))
+		goto release;
+	lock_mosix();
+	for(i = 0 ; i < dfsatab->ndefs ; i++)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		if(!strcmp(x, link))
+		{
+			if(dfsatab->dfsdef[i].defno <= MAXDFSAFS)
+			{
+				printk("Conflict: DFSA link <%s> is declared "
+					"as a mount-point\n", link);
+				ret = -EBUSY;
+				goto out;
+			}
+			linkno = dfsatab->dfsdef[i].defno - (MAXDFSAFS+1);
+			mnt = dfsa_links[linkno].mnt;
+			dp = dfsa_links[linkno].dentry;
+			ret = 0;
+			if(mnt == nd.mnt && dp->d_inode == nd.dentry->d_inode)
+				goto out;
+			printk("Updating DFSA link <%s>\n", link);
+			printk("[But please, next time delete the DFSA-link "
+				"BEFORE changing the symbolic-link]!\n");
+			dfsa_links[linkno].mnt = mntget(nd.mnt);
+			dfsa_links[linkno].dentry = dget(nd.dentry);
+			unlock_mosix();
+			mntput(mnt);
+			dput(dp);
+			lock_mosix();
+			goto sync;
+		}
+		sz += sizeof(struct dfsdef) + strlen(x) + 1;
+	}
+	ret = -EMLINK;
+	for(linkno = 0 ; linkno < MAXDFSALINKS ; linkno++)
+	if(!dfsa_links[linkno].mnt)
+		break;
+	if(linkno == MAXDFSALINKS)
+		goto out;
+	unlock_mosix();
+	new = (struct dfsatab *)kmalloc(sz, GFP_KERNEL);
+	lock_mosix();
+	ret = -ENOMEM;
+	if(!new)
+		goto out;
+	printk("Adding DFSA link <%s>\n", link);
+	dfsa_links[linkno].mnt = mntget(nd.mnt);
+	dfsa_links[linkno].dentry = dget(nd.dentry);
+	ret = 0;
+	new->len = sz;
+	new->ndefs = dfsatab->ndefs + 1;
+	y = (char *)&new->dfsdef[(int)new->ndefs];
+	for(j = i = 0 ; i < dfsatab->ndefs ; i++)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		if(!added && dfsa_name_compare(link, x) == 1)
+		{
+			added = 1;
+			new->dfsdef[j].defno = linkno + MAXDFSAFS + 1;
+			new->dfsdef[j].mounted = 0;
+			new->dfsdef[j].offset = y - (char *)new;
+			strcpy(y, link);
+			while(*y++)
+				;
+			j++;
+		}
+		new->dfsdef[j] = dfsatab->dfsdef[i];
+		new->dfsdef[j].offset = y - (char *)new;
+		while(*x)
+			*y++ = *x++;
+		*y++ = '\0';
+		j++;
+	}
+	if(!added)
+	{
+		new->dfsdef[j].defno = linkno + MAXDFSAFS + 1;
+		new->dfsdef[j].mounted = 0;
+		new->dfsdef[j].offset = y - (char *)new;
+		strcpy(y, link);
+		while(*y++)
+			;
+	}
+	old = dfsatab;
+	dfsatab = new;
+	kfree(old);
+	sync:
+	dfsa_sync(0);
+	out:
+	unlock_mosix();
+	up(&dfsa_modify_lock);
+	release:
+	path_release(&nd);
+	return(ret);
+}
+
+int
+dfsa_dellink(char *link)
+{
+	int i, j;
+	char *x, *y;
+	int ret;
+	struct vfsmount *mnt;
+	struct dentry *dp;
+	struct dfsatab *new, *old;
+	int sz = sizeof(struct dfsatab);
+	int ind = -1;
+	int linkno = 0;
+
+	if(down_interruptible(&dfsa_modify_lock))
+		return(-EINTR);
+	lock_mosix();
+	for(i = 0 ; i < dfsatab->ndefs ; i++)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		if(dfsatab->dfsdef[i].defno <= MAXDFSAFS || strcmp(x, link))
+			sz += sizeof(struct dfsdef) + strlen(x) + 1;
+		else
+		{
+			ind = i;
+			linkno = dfsatab->dfsdef[i].defno - MAXDFSAFS - 1;
+		}
+	}
+	ret = -EINVAL;
+	if(ind == -1)
+		goto out;
+	unlock_mosix();
+	new = (struct dfsatab *)kmalloc(sz, GFP_KERNEL);
+	lock_mosix();
+	ret = -ENOMEM;
+	if(!new)
+		goto out;
+	ret = 0;
+	printk("Deleting DFSA link <%s>\n", link);
+	new->len = sz;
+	new->ndefs = dfsatab->ndefs - 1;
+	y = (char *)&new->dfsdef[(int)new->ndefs];
+	for(j = i = 0 ; i < dfsatab->ndefs ; i++)
+	if(i != ind)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		new->dfsdef[j] = dfsatab->dfsdef[i];
+		new->dfsdef[j].offset = y - (char *)new;
+		while(*x)
+			*y++ = *x++;
+		*y++ = '\0';
+		j++;
+	}
+	old = dfsatab;
+	dfsatab = new;
+	unlock_mosix();
+	i = dfsa_sync(1);
+	lock_mosix();
+	if(i)
+	{
+		printk("Clearing of DFSA links interrupted!\n");
+		dfsatab = old;
+		kfree(new);
+		ret = -EINTR;
+		goto out;
+	}
+	kfree(old);
+	mnt = dfsa_links[linkno].mnt;
+	dfsa_links[linkno].mnt = NULL;
+	dp = dfsa_links[linkno].dentry;
+	dfsa_links[linkno].dentry = NULL;
+	unlock_mosix();
+	mntput(mnt);
+	dput(dp);
+	lock_mosix();
+	out:
+	unlock_mosix();
+	up(&dfsa_modify_lock);
+	return(ret);
+}
+
+int
+dfsa_clearlinks(void)
+{
+	int i, j;
+	char *x, *y;
+	int ret;
+	struct vfsmount *mnt;
+	struct dentry *dp;
+	struct dfsatab *new = NULL, *old;
+	int sz = sizeof(struct dfsatab);
+	int found = 0;
+
+	if(down_interruptible(&dfsa_modify_lock))
+		return(-EINTR);
+	lock_mosix();
+	for(i = 0 ; i < dfsatab->ndefs ; i++)
+	{
+		if(dfsatab->dfsdef[i].defno <= MAXDFSAFS)
+		{
+			x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+			sz += sizeof(struct dfsdef) + strlen(x) + 1;
+		}
+		else
+			found++;
+	}
+	if(!found)
+	{
+		printk("No DFSA links to clear\n");
+		ret = 0;
+		goto out;
+	}
+	ret = -ENOMEM;
+	unlock_mosix();
+	new = (struct dfsatab *)kmalloc(sz, GFP_KERNEL);
+	lock_mosix();
+	if(!new)
+		goto out;
+	printk("Clearing all DFSA links\n");
+	ret = 0;
+	new->len = sz;
+	new->ndefs = dfsatab->ndefs - found;
+	y = (char *)&new->dfsdef[(int)new->ndefs];
+	for(j = i = 0 ; i < dfsatab->ndefs ; i++)
+	if(dfsatab->dfsdef[i].defno <= MAXDFSAFS)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		new->dfsdef[j] = dfsatab->dfsdef[i];
+		new->dfsdef[j].offset = y - (char *)new;
+		while(*x)
+			*y++ = *x++;
+		*y++ = '\0';
+		j++;
+	}
+	old = dfsatab;
+	dfsatab = new;
+	unlock_mosix();
+	i = dfsa_sync(1);
+	lock_mosix();
+	if(i)
+	{
+		printk("Clearing of DFSA links interrupted!\n");
+		dfsatab = old;
+		kfree(new);
+		ret = -EINTR;
+		goto out;
+	}
+	kfree(old);
+	for(i = 0 ; i < MAXDFSALINKS ; i++)
+	if((mnt = dfsa_links[i].mnt))
+	{
+		dp = dfsa_links[i].dentry;
+		dfsa_links[i].mnt = NULL;
+		dfsa_links[i].dentry = NULL;
+		unlock_mosix();
+		mntput(mnt);
+		dput(dp);
+		lock_mosix();
+	}
+	out:
+	unlock_mosix();
+	up(&dfsa_modify_lock);
+	return(ret);
+}
+
+char *
+dfsa_showlinks(void)
+{
+	int i, sz;
+	char *x;
+	char *links = NULL, *p;
+
+	lock_mosix();
+	again:
+	for(sz = 1 , i = 0 ; i < dfsatab->ndefs ; i++)
+	if(dfsatab->dfsdef[i].defno > MAXDFSAFS)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		sz += strlen(x) + 1;
+	}
+	unlock_mosix();
+	if(!(links = kmalloc(sz, GFP_KERNEL)))
+		return(NULL);
+	lock_mosix();
+	p = links;
+	for(i = 0 ; i < dfsatab->ndefs ; i++)
+	if(dfsatab->dfsdef[i].defno > MAXDFSAFS)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		while(*x)
+		{
+			*p++ = *x++;
+			if(--sz < 2)
+			{
+				kfree(links);
+				goto again;
+			}
+		}
+		*p++ = '\n';
+		sz--;
+	}
+	*p = '\0';
+	unlock_mosix();
+	return(links);
+}
+
+int
+disable_dfsa(void)
+{
+	int i;
+	int ret;
+	struct vfsmount *mnt;
+	struct dentry *dp;
+
+	if(down_interruptible(&dfsa_modify_lock))
+		return(-EINTR);
+	lock_mosix();
+	ret = 0;
+	if(dfsa_disabled++)
+		goto out;
+	printk("Disabling DFSA\n");
+	for(i = 0 ; i < MAXDFSAFS ; i++)
+	{
+		dfsa_being_cancelled[i] = 1;
+		if((mnt = dfsa_mounts[i]))
+			dfsa_set_dfsa(mnt, 0, mnt->mnt_dfsa);
+	}
+	if((ret = dfsa_sync(1)))
+	{
+		printk("Disabling DFSA interrupted\n");
+		for(i = 0 ; i < MAXDFSAFS ; i++)
+		if((mnt = dfsa_mounts[i]))
+			dfsa_set_dfsa(mnt, mnt->mnt_dfsaprev, 0);
+		unlock_mosix();
+		enable_dfsa();
+		goto out2;
+	}
+	dfsatab->ndefs = 0;
+	dfsatab->len = sizeof(struct dfsatab);
+	for(i = 0 ; i < MAXDFSAFS ; i++)
+	if((mnt = dfsa_mounts[i-1]))
+	{
+		dfsa_mounts[i-1] = NULL;
+		dfsa_set_dfsa(mnt, 0, 0);
+		unlock_mosix();
+		mntput(mnt);
+		lock_mosix();
+	}
+	for(i = 0 ; i < MAXDFSALINKS ; i++)
+	if((mnt = dfsa_links[i].mnt))
+	{
+		dp = dfsa_links[i].dentry;
+		dfsa_links[i].mnt = NULL;
+		dfsa_links[i].dentry = NULL;
+		unlock_mosix();
+		mntput(mnt);
+		dput(dp);
+		lock_mosix();
+	}
+	out:
+	unlock_mosix();
+	out2:
+	up(&dfsa_modify_lock);
+	return(ret);
+}
+
+void
+enable_dfsa()
+{
+	int i;
+
+	lock_mosix();
+	if(--dfsa_disabled == 0)
+	{
+		for(i = 0 ; i < MAXDFSAFS ; i++)
+			dfsa_being_cancelled[i] = 0;
+		dfsa_sync(0);
+	}
+	unlock_mosix();
+}
+
+char *
+dfsa_getdir(int num, int *tofree)
+{
+	register int i, l;
+	char *x, *copy;
+	char *ret;
+
+	*tofree = 0;
+	lock_mosix();
+	again:
+	ret = "\n";
+	for(i = 0 ; i < dfsatab->ndefs ; i++)
+	if(dfsatab->dfsdef[i].defno == num)
+	{
+		x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset];
+		/* try to copy - just in case of changes during copy_to_user: */
+		l = strlen(x);
+		unlock_mosix();
+		copy = kmalloc(l+2, GFP_KERNEL);
+		lock_mosix();
+		if(!copy)
+		{
+			ret = "Sorry: no memory\n";
+			break;
+		}
+		/* paranoid test - did the table change? */
+		if((dfsatab) ||
+			i >= dfsatab->ndefs || dfsatab->dfsdef[i].defno != num ||
+			strlen(x = &((char *)dfsatab)[dfsatab->dfsdef[i].offset]) > l)
+		{
+			kfree(copy);
+			goto again;
+		}
+		sprintf(copy, "%s\n", x);
+		ret = copy;
+		*tofree = 1;
+		break;
+	}
+	unlock_mosix();
+	return(ret);
+}
+
+DECLARE_WAIT_QUEUE_HEAD(wait_for_all_to_dfsasync);
+
+int
+dfsa_all_know(void)
+{
+	register struct task_struct *p;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if(process_told(p, DREQ_DFSASYNC))
+		break;
+	read_unlock(&tasklist_lock);
+	return(p == &init_task);
+}
+
+int
+dfsa_sync(int wait)
+{
+	struct task_struct *p;
+	int any = 0;
+	int ret = 0;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if((p->mosix.dflags&(DDEPUTY|DREMOTE)) && !(p->mosix.dflags&DFINISHED))
+	{
+		any = 1;
+		tell_process(p, DREQ_DFSASYNC);
+		wake_up_mosix(p);
+	}
+	read_unlock(&tasklist_lock);
+	if(!any)
+		wake_up(&wait_for_all_to_dfsasync);
+	if(wait)
+	{
+		DECLARE_WAITQUEUE(wait, current);
+
+		add_wait_queue(&wait_for_all_to_dfsasync, &wait);
+		while(1)
+		{
+			set_current_state(TASK_INTERRUPTIBLE);
+			if(dfsa_all_know())
+				break;
+			schedule();
+			if(signal_pending(current))
+			{
+				ret = -EINTR;
+				break;
+			}
+		}
+		remove_wait_queue(&wait_for_all_to_dfsasync, &wait);
+		set_current_state(TASK_RUNNING);
+	}
+	return(ret);
+}
+
+void
+clear_dfsasync(void)
+{
+	if(process_told(current, DREQ_DFSASYNC))
+	{
+		process_ack(current, DREQ_DFSASYNC);
+		if(dfsa_all_know())	/* we were the last to ack */
+			wake_up(&wait_for_all_to_dfsasync);
+		tell_process(current, DREQ_NOTUPTODATE);
+	}
+}
+
+/*
+ * keep only those entries in "*tab" that also appear in our main "dfsatab"
+ * and have the same [important] mount-flags.
+ * both tables are already sorted.
+ */
+void
+dfsa_adapt(struct dfsatab *tab)
+{
+	int i, j = 0, k = 0, n1 = tab->ndefs, n2;
+	struct dfsdef *def1, *def2;
+	char *x, *y;
+
+	lock_mosix();
+	n2 = dfsatab->ndefs;
+	def2 = &dfsatab->dfsdef[0];
+	if(n2)
+	for(def1 = tab->dfsdef , i = 0 ; i < n1 ; i++ , def1++)
+	{
+		x = &((char *)tab)[def1->offset];
+		next2:
+		y = &((char *)dfsatab)[def2->offset];
+		switch(dfsa_name_compare(x, y))
+		{
+			case 0:
+				if(def1->mounted == def2->mounted)
+				{
+					if(k != i)
+						tab->dfsdef[k] = tab->dfsdef[i];
+					k++;
+					j++;
+					def2++;
+				}
+			case -1:
+				continue;
+			case 1:
+				j++;
+				def2++;
+				if(j == n2)
+					break;
+				goto next2;
+		}
+	}
+	unlock_mosix();
+	tab->ndefs = k;
+}
+
+int
+name_starts_in_dfsa(char **nam, struct nameidata *nd)
+{
+	register struct dfsatab *tab;
+	register int i;
+	char *n, *x;
+	struct vfsmount *mnt;
+	int ind;
+
+	lock_mosix();
+	tab = (current->mosix.dflags & DREMOTE) ? current->mosix.ttab : dfsatab;
+	if(tab && !dfsa_disabled)
+	for(i = 0 ; i < tab->ndefs ; i++)
+	{
+		n = *nam;
+		x = &((char *)tab)[tab->dfsdef[i].offset];
+		while(*n && *n == *x)
+		{
+			if(*n == '/')
+			{
+				while(*x == '/')
+					x++;
+				if(*x == '\0')
+					break;
+				while(*n == '/')
+				{
+					n++;
+					if(*n == '.' && (*(n+1) == '\0' ||
+								*(n+1) == '/'))
+						n++;
+				}
+			}
+			else
+			{
+				n++;
+				x++;
+			}
+		}
+		if(*x || (*n && *n != '/'))
+			continue;
+		if((nd->flags & LOOKUP_PARENT) || (!tab->dfsdef[i].mounted &&
+			 !*n && !(nd->flags & LOOKUP_FOLLOW)))
+		{
+			while(*n == '/')
+				n++;
+			if(!*n)
+				continue;
+		}
+		else while(*n == '/')
+			n++;
+		ind = tab->dfsdef[i].defno - 1;
+		if(ind < MAXDFSAFS)
+		{
+			if(dfsa_being_cancelled[ind] ||
+						!(mnt = dfsa_mounts[ind]))
+				break;
+			nd->mnt = mntget(mnt);
+			nd->dentry = dget(mnt->mnt_root); 
+		}
+		else
+		{
+			ind -= MAXDFSAFS;
+			if(!(mnt = dfsa_links[ind].mnt))
+				break;
+			if(!mnt->mnt_dfsano)
+				break;
+			nd->mnt = mntget(mnt);
+			nd->dentry = dget(dfsa_links[ind].dentry);
+		}
+		*nam = n;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_DFSA)
+			printk("%s: Found a DFSA base: %s|%s\n",
+				desc_mostask(NULL),
+				&((char *)tab)[tab->dfsdef[i].offset], n);
+#endif /* CONFIG_MOSIX_DEBUG */
+		unlock_mosix();
+		return(1);
+	}
+	unlock_mosix();
+	return(0);
+}
+
+int
+within_dfsa(struct nameidata *nd)
+{
+	int dfsano;
+	struct dfsatab *tab;
+	struct dfsdef *def;
+	int i;
+	int ret;
+
+	lock_mosix();
+	if(dfsa_disabled || !(dfsano = nd->mnt->mnt_dfsano) ||
+		dfsa_being_cancelled[dfsano-1] || !(dfsa_mounts[dfsano-1]))
+		ret = 0;
+	else if(!(current->mosix.dflags & DREMOTE))
+		ret = 1;
+	else if(!(tab = current->mosix.ttab) || nd->mnt->mnt_dfsaprev)
+		ret = 0;
+	else
+	{
+		ret = 0;
+		for(def = tab->dfsdef , i = tab->ndefs ; i > 0 ; i-- , def++)
+		if(def->defno == dfsano)
+		{
+			ret = 1;
+			break;
+		}
+	}
+	unlock_mosix();
+	return(ret);
+}
+
+void
+dfsa_close_file(int fd)
+{
+	register struct task_struct *p = current;
+	register struct files_struct *files = current->files;
+
+	if(atomic_read(&files->users) > 1)
+	{
+		tell_process(p, DREQ_NOTUPTODATE);
+		return;
+	}
+	if(fd >= files->maxclosed)
+		files->maxclosed = fd + 1;
+	FD_SET(fd, files->closed);
+	p->mosix.dupdates |= DFSA_UPDCLOSE;
+}
+
+void
+dfsa_open_file(int fd)
+{
+	struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	struct file *f;
+	int n;
+
+	if(atomic_read(&files->users) > 1)
+	{
+		tell_process(p, DREQ_NOTUPTODATE);
+		return;
+	}
+	/* since nobody shares our files, no locking is necessary */
+	if(!can_dfsa_file(fd))
+	{
+		p->mosix.dupdates |= DFSA_UPDUSED;
+		return;
+	}
+	p->mosix.dupdates |= DFSA_UPDOPEN;
+	f = files->fd[fd];
+	if((n = file_count(f)) > 1)
+	{
+		/* must find all DUPs: */
+		register int i, l, li;
+		struct file **dups = files->fd;
+		unsigned long *bits = files->open_fds->fds_bits;
+		int lim = files->max_fds, llim;
+
+		if(lim > files->max_fdset)
+			lim = files->max_fdset;
+		llim = (lim + BITS_PER_LONG - 1) / BITS_PER_LONG;
+		for(i = l = 0 ; l < llim ; l++)
+		if(*bits++)
+		{
+			li = i + BITS_PER_LONG;
+			if(li > lim)
+				li = lim;
+			for(; i < li ; i++)
+			if(dups[i] == f)
+			{
+				if(i >= files->maxopened)
+					files->maxopened = i + 1;
+				FD_SET(i, files->opened);
+				FD_CLR(i, files->modified);
+#ifdef CONFIG_MOSIX_DEBUG
+				if(ds_debug & DSDEB_DFSA)
+					printk("%s-dfsa_open_file(%d): "
+						"opened %d\n",
+						desc_mostask(NULL), fd, i);
+#endif /* CONFIG_MOSIX_DEBUG */
+				if(--n == 0)
+					return;
+			}
+		}
+		else
+			i += BITS_PER_LONG;
+	}
+	else
+	{
+		if(fd >= files->maxopened)
+			files->maxopened = fd + 1;
+		FD_SET(fd, files->opened);
+		FD_CLR(fd, files->modified);
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_DFSA)
+			printk("%s-dfsa_open_file(%d): opened\n"
+				, desc_mostask(NULL), fd);
+#endif /* CONFIG_MOSIX_DEBUG */
+	}
+}
+
+void
+dfsa_touch_file(int fd)
+{
+	struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	struct file *f;
+	int n;
+
+	if(atomic_read(&files->users) > 1)
+	{
+		tell_process(p, DREQ_NOTUPTODATE);
+		return;
+	}
+	/* since nobody shares our files, no locking is necessary */
+	if(!can_dfsa_file(fd))
+		return;
+	p->mosix.dupdates |= DFSA_UPDMODS;
+	f = files->fd[fd];
+	if((n = file_count(f)) > 1)
+	{
+		/* must find all DUPs: */
+		register int i, l, li;
+		struct file **dups = files->fd;
+		unsigned long *bits = files->open_fds->fds_bits;
+		int lim = files->max_fds;
+		int llim;
+
+		if(lim > files->max_fdset)
+			lim = files->max_fdset;
+		llim = (lim + BITS_PER_LONG - 1) / BITS_PER_LONG;
+		for(i = l = 0 ; l < llim ; l++)
+		if(*bits++)
+		{
+			li = i + BITS_PER_LONG;
+			if(li > lim)
+				li = lim;
+			for(; i < li ; i++)
+			if(dups[i] == f)
+			{
+#ifdef CONFIG_MOSIX_DEBUG
+				if(ds_debug & DSDEB_DFSA)
+					printk("%s-dfsa_touch_file(%d): "
+						"touched %d\n",
+						desc_mostask(NULL), fd, i);
+#endif /* CONFIG_MOSIX_DEBUG */
+				if(FD_ISSET(i, files->opened))
+					continue;
+				if(i >= files->maxmod)
+					files->maxmod = i + 1;
+				FD_SET(i, files->modified);
+				if(--n == 0)
+					return;
+			}
+		}
+		else
+			i += BITS_PER_LONG;
+	}
+	else
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_DFSA)
+			printk("%s-dfsa_touch_file(%d): touched\n",
+							desc_mostask(NULL), fd);
+#endif /* CONFIG_MOSIX_DEBUG */
+		if(FD_ISSET(fd, files->opened))
+			return;
+		if(fd >= files->maxmod)
+			files->maxmod = fd + 1;
+		FD_SET(fd, files->modified);
+	}
+}
+
+/*
+ * callers to "can_dfsa_file" must first make sure (perhaps with "CAN_DFSA")
+ * that their files_struct is not shared with clones:
+ * hence, neither the caller nor "can_dfsa_file" need to lock the files
+ * (which could deadlock the mosix-lock)
+ */
+int
+can_dfsa_file(int fd)
+{
+	register int i, l, li;
+	struct file *file = fcheck(fd);
+	struct vfsmount *mnt;
+	int fs, mode, n;
+
+	if(!file)
+		return(0);
+	mnt = file->f_vfsmnt;
+	lock_mosix();
+	if(current->mosix.dflags & DREMOTE)
+	{
+		/* well, since it is open, it MUST be a DFSA file! */
+		if(!(fs = mnt->mnt_dfsaprev) && !(fs = mnt->mnt_dfsano))
+			panic("remote loose DFSA fd");
+		unlock_mosix();
+		return(fs);
+	}
+	if(!(fs = mnt->mnt_dfsano) || dfsa_being_cancelled[fs-1])
+	{
+		unlock_mosix();
+		return(0);
+	}
+	unlock_mosix();
+	mode = file->f_dentry->d_inode->i_mode;
+	if(!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
+		return(0);
+	n = file_count(file);
+	if(n != 1)
+	{
+		/* Are all links merily our own DUPs? */
+		struct file **files = current->files->fd;
+		unsigned long *bits = current->files->open_fds->fds_bits;
+		int lim = current->files->max_fds;
+		int llim;
+
+		if(lim > current->files->max_fdset)
+			lim = current->files->max_fdset;
+		llim = (lim + BITS_PER_LONG - 1) / BITS_PER_LONG;
+		for(i = l = 0 ; l < llim ; l++)
+		if(*bits++)
+		{
+			li = i + BITS_PER_LONG;
+			if(li > lim)
+				li = lim;
+			for(; i < li ; i++)
+			if(files[i] == file && --n == 0)
+				return(fs);
+		}
+		else
+			i += BITS_PER_LONG;
+		return(0);
+	}
+	return(fs);
+}
+
+void
+dfsa_tinit(void)
+{
+	struct task_struct *p = current;
+	struct files_struct *files = p->files;
+
+	CLEAR_ALL(files, closed);
+	files->maxclosed = 0;
+	CLEAR_ALL(files, modified);
+	files->maxmod = 0;
+	p->mosix.dupdates = 0;
+	p->fs->pwd_changed = 0;
+	p->mosix.ttab = NULL;
+}
+
+/*
+ * Is it OK to accept and open a file/directory opened on the other side?
+ * A DEPUTY must always accept.
+ * A REMOTE is more reserved.
+ */
+int
+ok_to_accept_in_dfsa(int dfsano)
+{
+	struct task_struct *p = current;
+	struct vfsmount *mnt;
+	struct dfsatab *tab;
+	struct dfsdef *def;
+	int i;
+
+	MOSIX_LOCKED;
+	if(dfsano < 1 || dfsano > MAXDFSAFS || !(mnt = dfsa_mounts[dfsano-1]))
+		return(0);
+	if(!(p->mosix.dflags & DREMOTE))
+		return(1);
+	if(dfsa_disabled)
+		return(0);
+	if(!(tab = p->mosix.ttab))
+		return(0);
+	if(dfsa_being_cancelled[dfsano-1])
+		return(0);
+	if(mnt->mnt_dfsaprev)
+		return(0);
+	for(def = tab->dfsdef , i = 0 ; i < tab->ndefs ; i++ , def++)
+	if(def->defno == dfsano)
+		return(1);
+	return(0);
+}
+
+void
+reconstruct(int dfsano, void *info, int infolen, struct vfsmount **mnt,
+							struct dentry **dp)
+{
+	char comma;
+
+	lock_mosix();
+	if(!ok_to_accept_in_dfsa(dfsano))
+	{
+		unlock_mosix();
+		goto bad;
+	}
+	*mnt = mntget(dfsa_mounts[dfsano-1]);
+	unlock_mosix();
+	*dp = (*mnt)->mnt_sb->s_op->reconstruct(*mnt, info, infolen);
+	if(*dp)
+		return;
+	mntput(*mnt);
+	bad:
+	if(current->mosix.dflags & DREMOTE)
+	{
+		*mnt = NULL;
+		*dp = NULL;
+		return;
+	}
+	printk("%s: Failed to reopen DFSA file (dfsano=%d, info",
+						desc_mostask(NULL), dfsano);
+	comma = '=';
+	while(infolen >= sizeof(int))
+	{
+		printk("%c%X", comma, *((int *)info++));
+		infolen -= sizeof(int);
+		comma=',';
+	}
+	printk(")\n");
+	*mnt = mntget(current->fs->rootmnt);
+	*dp = dget(bad_deputy_dfsaentry);
+}
+
+void
+dfsa_file_install(int fd, mode_t mode, loff_t pos, unsigned int flags,
+					int dfsano, void *info, int infolen)
+{
+	struct vfsmount *mnt;
+	struct dentry *dp;
+	register struct file *fp;
+	register struct inode *ip;
+	struct files_struct *files = current->files;
+	int failure;
+
+	reconstruct(dfsano, info, infolen, &mnt, &dp);
+	if(!dp)	/* (can only happen on REMOTE) */
+		return;
+	if(atomic_read(&files->users) != 1)
+		panic("dfsa_file_install: sharing");
+	write_lock(&files->file_lock);
+	failure = (fd >= files->max_fdset && expand_fdset(files, fd));
+	write_unlock(&files->file_lock);
+	if(failure)
+		goto bad1;
+	if((fp = get_empty_filp()))
+	{
+		fp->f_dentry = dp;
+		fp->f_vfsmnt = mnt;
+		ip = dp->d_inode;
+		fp->f_op = fops_get(ip->i_fop);
+		if((fp->f_op && fp->f_op->open && fp->f_op->open(ip, fp)))
+		{
+			fput(fp);
+			goto bad;
+		}
+		flags &= ~O_NOWRITEACCESS;
+		if(mode & FMODE_WRITE)
+		{
+			if(get_write_access(ip))
+				flags |= O_NOWRITEACCESS;
+		}
+		fp->f_flags = flags;
+		fp->f_pos = pos;
+		fp->f_mode = mode;
+		fp->f_reada = 0;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_DFSA)
+			printk("%s: Installed fd #%d, pos=%d, mode=%d, flags=0x%x\n",
+				desc_mostask(NULL), fd, (int)pos, mode, flags);
+#endif /* CONFIG_MOSIX_DEBUG */
+		write_lock(&files->file_lock);
+		files->fd[fd] = fp;
+		FD_SET(fd, files->open_fds);
+		FD_CLR(fd, files->close_on_exec);
+		write_unlock(&files->file_lock);
+		/* the following "should not" happen, but it could due to an
+		 * inconsistency in the file-system - at least we must now
+		 * instruct our REMOTE to stop using that file!
+		 */
+		if((current->mosix.dflags & DDEPUTY) && !can_dfsa_file(fd))
+			dfsa_close_file(fd);
+	}
+	else
+	{
+		bad1:
+		dput(dp);
+		mntput(mnt);
+		bad:
+		if(!(current->mosix.dflags & DREMOTE))
+			printk("%s: Failed to allocate DFSA file for reopen\n",
+				desc_mostask(NULL));
+	}
+}
+
+void
+deputy_resync_dfsa(void)
+{
+	register struct task_struct *p = current;
+	char *update;
+	int sz;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!(p->mosix.dflags & DSYNC))
+		panic("deputy_resync_dfsa: not synced");
+#endif /* CONFIG_MOSIX_DIAG */
+	again:
+	p->mosix.dupdates |= DFSA_UPDATE;
+	clear_dfsasync();
+	if(CAN_DFSA(p) && (update = deputy_pack_dfsa_changes(&sz)))
+	{
+		if(deputy_request(DEP_DFSA_CHANGES, &sz, sizeof(sz),
+							update, sz, 0, NULL, 0))
+			deputy_communication_failed();
+		kfree(update);
+		if(process_told(p, DREQ_DFSASYNC)) /* a new one (race) */
+			goto again;
+	}
+	else if(deputy_request(DEP_DFSA_CLEAR, NULL, 0, NULL, 0, 0, NULL, 0))
+		deputy_communication_failed();
+}
+
+void
+remote_clear_dfsa(void)
+{
+	register struct task_struct *p = current;
+	extern void close_files(struct files_struct *);
+
+	if(p->mosix.ttab)
+	{
+		kfree(p->mosix.ttab);
+		p->mosix.ttab = NULL;
+	}
+	close_files(p->files);
+	CLEAR_ALL(p->files, open_fds);
+	p->files->next_fd = 0;
+	if(p->fs->pwd)
+	{
+		dput(p->fs->pwd);
+		p->fs->pwd = NULL;
+		mntput(p->fs->pwdmnt);
+		p->fs->pwdmnt = NULL;
+	}
+}
+
+int
+dfsa_optimized_read(struct file *f, loff_t off, unsigned long addr,
+							unsigned long len)
+{
+	struct task_struct *p = current;
+	struct read_yourself_h r;
+	struct vfsmount *mnt;
+	char data[MAX_IDENT_RECORD_LEN];
+	int result;
+
+	if(!(p->mosix.dflags & DDEPUTY) || !CAN_DFSA(p))
+		goto read;
+	mnt = f->f_vfsmnt;
+	lock_mosix();
+	if(!(r.dfsano = mnt->mnt_dfsano) || dfsa_being_cancelled[r.dfsano-1])
+	{
+		unlock_mosix();
+		goto read;
+	}
+	unlock_mosix();
+	if(!(r.infolen = mnt->mnt_sb->s_op->identify(f->f_dentry, data)))
+		goto read;
+	r.off = off;
+	r.addr = addr;
+	r.len = len;
+	if(deputy_request(DEP_READ_YOURSELF, &r, sizeof(r), data, r.infolen, 0,
+		(void **)&result, -sizeof(result)))
+	{
+		deputy_communication_failed();
+		return(-EIO);
+	}
+	if(result == -ENOENT)
+	{
+		read:
+		return(f->f_op->read(f, (char *)addr, len, &off));
+	}
+	return(result);
+}
+
+int
+remote_read_yourself(struct read_yourself_h *r)
+{
+	int result = -ENOENT;
+	char data[MAX_IDENT_RECORD_LEN];
+	struct dentry *dp;
+	struct vfsmount *mnt;
+	struct file file;
+	struct inode *ip;
+
+	if(r->infolen > MAX_IDENT_RECORD_LEN ||
+		verify_area(VERIFY_WRITE, (char *)r->addr, r->len))
+	{
+		comm_flushdata(COMM_ALLDATA);
+		goto reply;
+	}
+	if(comm_copydata(data, r->infolen, 0))
+		goto reply;
+	reconstruct(r->dfsano, data, r->infolen, &mnt, &dp);
+	if(!dp)
+		goto reply;
+	ip = dp->d_inode;
+	if(ip->i_fop && ip->i_fop->read && !init_private_file(&file, dp, 1))
+	{
+		result = file.f_op->read(&file, (char *)r->addr, r->len,
+								&r->off);
+		if(file.f_op->release)
+			file.f_op->release(ip, &file);
+	}
+	dput(dp);
+	mntput(mnt);
+	reply:
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_DFSA)
+		printk("remote_read_yourself: off=%ld, addr=0x%lx, len=0x%lx, "
+			"result=%d\n", (long)r->off, r->addr, r->len, result);
+#endif /* CONFIG_MOSIX_DEBUG */
+	comm_free(r);
+	result = comm_send(DEP_READ_YOURSELF|REPLY, &result, sizeof(int),
+								NULL, 0, 0);
+	return(result);
+}
+
+int
+enter_remote_dfsa_mode(void)
+{
+	struct task_struct *p = current;
+
+	if(!p->mosix.ttab)
+		return(0);
+	spin_lock_irq(&runqueue_lock);	/* ensures DREQ_EXITDFSA not lost */
+	p->mosix.dflags |= DREMOTEDFSA;
+	spin_unlock_irq(&runqueue_lock);
+	if(remote_deputy_has_something_for_us(p) ||
+		remote_need_while_asleep(p) ||
+		(process_told(p, (DREQ_DFSASYNC|DREQ_NOTUPTODATE))) ||
+		(p->mosix.dflags & DFAKESIGNAL))
+	{
+		leave_remote_dfsa_mode();
+		return(0);
+	}
+	return(1);
+}
+
+void
+leave_remote_dfsa_mode(void)
+{
+	register struct task_struct *p = current;
+
+	spin_lock_irq(&runqueue_lock);	/* ensures no new "DREQ_EXITDFSA" */
+	p->mosix.dflags &= ~(DREMOTEDFSA|DFAKESIGNAL);
+	spin_unlock_irq(&runqueue_lock);
+	process_ack(p, DREQ_EXITDFSA);
+	spin_lock_irq(&p->sigmask_lock);
+	p->sigpending = 0;
+	spin_unlock_irq(&p->sigmask_lock);
+}
+
+void
+dfsa_syscall_on_file(int fd, int touching)
+{
+	register struct task_struct *p = current;
+	static unsigned char rand;
+
+	if(!(p->mosix.dflags & (DDEPUTY|DREMOTE)) && CAN_DFSA(p) &&
+				(fd >= p->files->max_fds || can_dfsa_file(fd)))
+		p->mosix.dflags |= DSTATSDOWN;
+
+	/* consider a remote process that with regard to this file only runs a
+	 * combination of fstat(), fcntl(F_GETFL), fchdir(), fchmod(), fchown(),
+	 * fsync() and ftrunc() - but does lots of the above: if its parent
+	 * initially held the file open, but not any more, there is no other
+	 * way that the son will become aware of the fact that it may now do
+	 * all those things remotely.  Adding a file-flag on close is not very
+	 * helpful because a chain of relatives may be constantly closing this
+	 * file (or simply exiting).  On the other hand, running CAN_DFSA +
+	 * can_dfsa_file + dfsa_touch_file (including its communication
+	 * overhead) is expensive.
+	 * The compromise is to run them at random, once in about 256 times,
+	 * and eventually the process will come to know.
+	 */
+	if(touching || ((p->mosix.dflags & DDEPUTY) && !rand++ &&
+		CAN_DFSA(p) && can_dfsa_file(fd)))
+		dfsa_touch_file(fd);
+}
+
+void
+dfsa_exit(void)
+{
+	struct task_struct *p = current;
+
+	if(process_told(p, DREQ_DFSASYNC))
+		clear_dfsasync();
+	if(p->mosix.ttab)
+	{
+		kfree(p->mosix.ttab);
+		p->mosix.ttab = NULL;
+	}
+}
+
+/*** PACKING/UNPACKING UPDATES SECTION ***/
+
+enum
+{
+	/* general info: */
+	REC_CREDITS, REC_UMASK, REC_SELECT, REC_DFSATAB,
+	/* current directory */
+	REC_CDIR,
+	/* file table */
+	REC_MAX, REC_USED,
+	/* individual files */
+	REC_CLOSED, REC_NONDFSA, REC_FILE, REC_MOD, REC_DUP
+};
+
+struct credits_rec
+{
+	uid_t uid, euid, suid, fsuid;
+	gid_t gid, egid, sgid, fsgid;
+	int ngroups;
+	gid_t groups[NGROUPS];
+};
+
+/* the following is defined even if MFS is not configured,
+ * because it may possibly be configured by the peer node! */
+struct select_rec
+{
+	int selected;
+	int lastexec;
+	int lastmagic;
+};
+
+struct cdir_rec
+{
+	int dfsano;
+	int infolen;
+};
+
+struct max_rec
+{
+	int max_fds;
+	int max_fdset;
+};
+
+struct file_rec
+{
+	short fd;
+	mode_t mode;
+	loff_t pos;
+	unsigned int flags;
+	int dfsano;
+	int infolen;
+};
+
+struct mod_rec
+{
+	short fd;
+	mode_t mode;
+	loff_t pos;
+	unsigned int flags;
+};
+
+struct dup_rec
+{
+	short fd;
+	short orig;
+};
+
+static char *
+add_changes_record(char *old, char type, void *add, int addlen)
+{
+	char *rec;
+	int sz, minsz;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_DFSA)
+		printk("%s: adding DFSA changes-record type %d, len %d\n",
+					desc_mostask(NULL), type, addlen);
+#endif /* CONFIG_MOSIX_DEBUG */
+	again:
+	if(old)
+	{
+		minsz = ((int *)old)[1] + sizeof(type) + addlen;
+		if(((int *)old)[0] < minsz)
+		{
+			sz = 2 * minsz;
+			if((sz & PAGE_MASK) >= minsz)
+				sz &= PAGE_MASK;
+			if(!(rec = kmalloc(sz, GFP_KERNEL)))
+			{
+				sz = minsz;
+				if(!(rec = kmalloc(sz, GFP_KERNEL)))
+				{
+					kfree(old);
+					return(NULL);
+				}
+			}
+			memcpy(rec, old, ((int *)old)[1]);
+			((int *)rec)[0] = sz;
+			kfree(old);
+			old = rec;
+			if(type == REC_DFSATAB)/* make sure it is still valid */
+			{
+				if(addlen < dfsatab->len)
+					goto again;
+				add = dfsatab;
+				addlen = dfsatab->len;
+			}
+		}
+		old[((int *)old)[1]] = type;
+		memcpy(old+((int *)old)[1] + sizeof(type), (char *)add, addlen);
+		((int *)old)[1] += addlen + sizeof(type);
+		return(old);
+	}
+	else
+	{
+		minsz = 2 * sizeof(int) + sizeof(type) + addlen;
+		sz = 2 * sizeof(int) + 3 * (addlen + sizeof(type));
+		if((sz & PAGE_MASK) >= minsz)
+			sz &= PAGE_MASK;
+		if(!(rec = kmalloc(sz, GFP_KERNEL)))
+		{
+			sz = minsz;
+			if(!(rec = kmalloc(sz, GFP_KERNEL)))
+				return(NULL);
+		}
+		((int *)rec)[0] = sz;
+		if(type == REC_DFSATAB)	/* make sure it is still valid */
+		{
+			if(addlen < dfsatab->len)
+			{
+				kfree(rec);
+				goto again;
+			}
+			add = dfsatab;
+			addlen = dfsatab->len;
+		}
+		((int *)rec)[1] = 2 * sizeof(int) + sizeof(type) + addlen;
+		rec[2*sizeof(int)] = type;
+		memcpy(rec+2*sizeof(int) + sizeof(type), (char *)add, addlen);
+		return(rec);
+	}
+}
+
+static void *
+get_record(char *buf, int *type)
+{
+	int pos = ((int *)buf)[0];
+	int tot = ((int *)buf)[1];
+	void *ret;
+
+	if(pos == 0)		/* "all done" mark */
+	{
+		all_done:
+		kfree(buf);
+		return(NULL);
+	}
+	if(pos >= tot)		/* first call */
+		pos = 2 * sizeof(int);
+	*type = buf[pos++];
+	ret = buf + pos;
+	switch(*type)
+	{
+		case REC_CREDITS:
+			pos += sizeof(struct credits_rec);
+			break;
+		case REC_UMASK:
+			pos += sizeof(int);
+			break;
+		case REC_SELECT:
+			pos += sizeof(struct select_rec);
+			break;
+		case REC_DFSATAB:
+			pos += ((struct dfsatab *)ret)->len;
+			break;
+		case REC_CDIR:
+			pos += sizeof(struct cdir_rec) +
+				((struct cdir_rec *)ret)->infolen;
+			break;
+		case REC_MAX:
+			pos += sizeof(struct max_rec);
+			break;
+		case REC_CLOSED:
+		case REC_NONDFSA:
+			pos += sizeof(int);
+			break;
+		case REC_FILE:
+			pos += sizeof(struct file_rec) +
+				((struct file_rec *)ret)->infolen;
+			break;
+		case REC_MOD:
+			pos += sizeof(struct mod_rec);
+			break;
+		case REC_DUP:
+			pos += sizeof(struct dup_rec);
+			break;
+		case REC_USED:
+			if((current->mosix.dflags & DDEPUTY) ||
+							current->mosix.ttab)
+				pos += current->files->max_fdset / 8;
+			else
+			/* we can't be sure about size - and it does not matter
+			   anyway: an expansion must have failed earlier */
+				goto all_done;
+			break;
+		default:
+			printk("buf = 0x%x, type=%d\n", (int)buf, *type);
+			panic("get_record");
+	}
+	((int *)buf)[0] = (pos >= tot) ? 0 : pos;
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_DFSA)
+		printk("%s-get_record: type=%d, len=%d\n",
+			desc_mostask(NULL), *type, (buf+pos) - (char *)ret);
+#endif /* CONFIG_MOSIX_DEBUG */
+	return(ret);
+}
+
+int
+add_closed_files(char **bufp)
+{
+	int i;
+	unsigned long bit = 1;
+	register struct files_struct *files = current->files;
+	unsigned long *mask = files->closed->fds_bits;
+	unsigned long bits = *mask;
+	char *buf = *bufp;
+
+	*mask = 0;
+	for(i = 0 ; i < files->maxclosed ; i++)
+	{
+		if((bits & bit) && !(buf =
+			add_changes_record(buf, REC_CLOSED, &i, sizeof(i))))
+		{
+			*bufp = NULL;
+			return(-ENOMEM);
+		}
+		bits &= ~bit;
+		if(bits)
+			bit <<= 1;
+		else
+		{
+			i = (i + __NFDBITS) & ~(__NFDBITS-1);
+			bit = 1;
+			while(1)
+			{
+				if(i >= files->maxclosed - 1)
+					break;
+				bits = *(++mask);
+				*mask = 0;
+				if(bits)
+					break;
+				i += __NFDBITS;
+			}
+		}
+	}
+	files->maxclosed = 0;
+	*bufp = buf;
+	return(0);
+}
+
+int
+add_opened_files(char **bufp)
+{
+	int i, j, dfsano;
+	struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	unsigned long *mask = files->opened->fds_bits;
+	unsigned long bits = *mask;
+	unsigned long bit = 1;
+	struct
+	{
+		struct file_rec f;
+		char info[MAX_IDENT_RECORD_LEN];
+	} fplus;
+	struct dup_rec d;
+	struct file **fds = files->fd;
+	char *buf = *bufp;
+	struct dentry *dp;
+
+	*mask = 0;
+	for(i = 0 ; i < files->maxopened ; i++)
+	{
+		if(!(bits & bit))
+			goto file_done;
+		if(!fds[i])
+		{
+			if(p->mosix.dflags & DREMOTE)
+			/* tell DEPUTY that REMOTE needs full file-info */
+				goto non_dfsa;
+			goto file_done;
+		}
+		if(!(dfsano = can_dfsa_file(i)))
+		{
+			non_dfsa:
+			if(!(buf = add_changes_record(buf, REC_NONDFSA, &i,
+								sizeof(i))))
+			{
+				fail:
+				return(-ENOMEM);
+			}
+			goto file_done;
+		}
+		if(file_count(fds[i]) > 1)
+		for(j = 0 ; j < i ; j++)
+		if(fds[j] == fds[i])
+		{
+			d.fd = i;
+			d.orig = j;
+			buf = add_changes_record(buf, REC_DUP, &d, sizeof(d));
+			if(!buf)
+				goto fail;
+			goto file_done;
+		}
+		dp = fds[i]->f_dentry;
+		fplus.f.infolen = fds[i]->f_vfsmnt->mnt_sb->s_op->identify(
+						fds[i]->f_dentry, &fplus.info);
+		if(!fplus.f.infolen)
+			goto fail;
+		fplus.f.fd = i;
+		fplus.f.mode = fds[i]->f_mode;
+		fplus.f.pos = fds[i]->f_pos;
+		fplus.f.flags = fds[i]->f_flags;
+		fplus.f.dfsano = dfsano;
+		if(!(buf = add_changes_record(buf, REC_FILE, &fplus,
+				sizeof(struct file_rec) + fplus.f.infolen)))
+			goto fail;
+		file_done:
+		bits &= ~bit;
+		if(bits)
+			bit <<= 1;
+		else
+		{
+			i = (i + __NFDBITS) & ~(__NFDBITS-1);
+			bit = 1;
+			while(1)
+			{
+				if(i >= files->maxmod - 1)
+					break;
+				bits = *(++mask);
+				*mask = 0;
+				if(bits)
+					break;
+				i += __NFDBITS;
+			}
+		}
+	}
+	files->maxmod = 0;
+	*bufp = buf;
+	return(0);
+}
+
+int
+add_modified_files(char **bufp)
+{
+	int i, j;
+	struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	unsigned long *mask = files->modified->fds_bits;
+	unsigned long bits = *mask;
+	unsigned long bit = 1;
+	struct mod_rec m;
+	struct file **fds = files->fd;
+	char *buf = *bufp;
+
+	*mask = 0;
+	for(i = 0 ; i < files->maxmod ; i++)
+	{
+		if(!(bits & bit) || !fds[i])
+			goto file_done;
+		if(!can_dfsa_file(i))
+		{
+			if(!(buf = add_changes_record(buf, REC_NONDFSA,
+							&i, sizeof(i))))
+			{
+				fail:
+				return(-ENOMEM);
+			}
+			goto file_done;
+		}
+		if(file_count(fds[i]) > 1)
+		for(j = 0 ; j < i ; j++)
+		if(fds[j] == fds[i])	/* touched one - touched all! */
+			goto file_done;
+		m.fd = i;
+		m.mode = fds[i]->f_mode;
+		m.pos = fds[i]->f_pos;
+		m.flags = fds[i]->f_flags;
+		if(!(buf = add_changes_record(buf, REC_MOD, &m, sizeof(m))))
+			goto fail;
+		file_done:
+		bits &= ~bit;
+		if(bits)
+			bit <<= 1;
+		else
+		{
+			i = (i + __NFDBITS) & ~(__NFDBITS-1);
+			bit = 1;
+			while(1)
+			{
+				if(i >= files->maxmod - 1)
+					break;
+				bits = *(++mask);
+				*mask = 0;
+				if(bits)
+					break;
+				i += __NFDBITS;
+			}
+		}
+	}
+	files->maxmod = 0;
+	*bufp = buf;
+	return(0);
+}
+
+char *
+deputy_pack_dfsa_changes(int *retsz)
+{
+	char *buf = NULL;
+	register struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	register int i;
+	register uint32_t updates;
+
+	if(files->count_dropped_to_one || current->fs->count_dropped_to_one ||
+		(process_told(p, DREQ_NOTUPTODATE)))
+	{
+		/* so this is the first time after a while that CAN_DFSA */
+		/* was TRUE: changes might have occured by our "partners" */
+		/* so we must assume that our REMOTE does not know anything */
+		/* (or its knowledge is obsolete) */
+		
+		files->count_dropped_to_one = 0;
+		p->fs->count_dropped_to_one = 0;
+		process_ack(p, DREQ_NOTUPTODATE);
+		p->mosix.dupdates |= DFSA_UPDATE;
+	}
+	if(!(updates = (p->mosix.dupdates & DFSA_UPDATE)))
+		goto out;
+	if(updates & DFSA_UPDCRED)
+	{
+		struct credits_rec c;
+
+		c.uid = p->uid;
+		c.euid = p->euid;
+		c.suid = p->suid;
+		c.fsuid = p->fsuid;
+		c.gid = p->gid;
+		c.egid = p->egid;
+		c.sgid = p->sgid;
+		c.fsgid = p->fsgid;
+		/* dirty compatibility-keeper: */
+		c.ngroups = p->ngroups;
+		for(i = 0 ; i < c.ngroups ; i++)
+			c.groups[i] = p->groups[i];
+		if(!(buf = add_changes_record(buf, REC_CREDITS, &c, sizeof(c))))
+		{
+			fail:
+			*retsz = -ENOMEM;
+			return(NULL);
+		}
+	}
+	if(updates & DFSA_UPDUMASK)
+	{
+		if(!(buf = add_changes_record(buf, REC_UMASK, &p->fs->umask,
+								sizeof(int))))
+			goto fail;
+	}
+#ifdef CONFIG_MOSIX_FS
+	if(updates & DFSA_UPDSEL)
+	{
+		struct select_rec s;
+
+		s.selected = p->mosix.selected;
+		s.lastexec = p->mosix.lastexec;
+		s.lastmagic = p->mosix.lastmagic;
+		if(!(buf = add_changes_record(buf, REC_SELECT, &s, sizeof(s))))
+			goto fail;
+	}
+#endif /* CONFIG_MOSIX_FS */
+	if(updates & DFSA_UPDTABLE)
+	{
+		if(!(buf = add_changes_record(buf, REC_DFSATAB, dfsatab,
+								dfsatab->len)))
+			goto fail;
+		/* this causes the REMOTE to flush all it knows, so: */
+		updates |= (DFSA_UPDCDIR|DFSA_UPDMAX|DFSA_UPDMODS|DFSA_UPDUSED);
+		memcpy(files->modified, files->open_fds, files->max_fdset / 8);
+		files->maxmod = (files->max_fds > files->max_fdset) ?
+					files->max_fdset : files->max_fds;
+		updates &= ~DFSA_UPDCLOSE;	/* all will be closed anyway */
+		CLEAR_ALL(files, closed);
+		files->maxclosed = 0;
+	}
+	if(updates & DFSA_UPDCDIR)
+	{
+		struct
+		{
+			struct cdir_rec c;
+			char info[MAX_IDENT_RECORD_LEN];
+		} cplus;
+		struct vfsmount *mnt = p->fs->pwdmnt;
+
+		if((cplus.c.dfsano = mnt->mnt_dfsano))
+			cplus.c.infolen = mnt->mnt_sb->s_op->identify(
+							p->fs->pwd, cplus.info);
+		else
+			cplus.c.infolen = 0;
+		buf = add_changes_record(buf, REC_CDIR, &cplus,
+					sizeof(cplus.c) + cplus.c.infolen);
+		if(!buf)
+			goto fail;
+	}
+	if(updates & DFSA_UPDMAX)
+	{
+		struct max_rec m;
+
+		m.max_fds = files->max_fds;
+		m.max_fdset = files->max_fdset;
+		if(!(buf = add_changes_record(buf, REC_MAX, &m, sizeof(m))))
+			goto fail;
+	}
+	if(updates & DFSA_UPDCLOSE)
+	{
+		if(add_closed_files(&buf))
+			goto fail;
+	}
+	if(updates & DFSA_UPDOPEN)
+	{
+		if(add_opened_files(&buf))
+			goto fail;
+	}
+	if(updates & DFSA_UPDMODS)
+	{
+		if(add_modified_files(&buf))
+			goto fail;
+	}
+	if(updates & DFSA_UPDUSED)
+	{
+		if(!(buf = add_changes_record(buf, REC_USED,
+			files->open_fds, files->max_fdset / 8)))
+			goto fail;
+	}
+	current->mosix.dupdates &= ~DFSA_UPDATE;
+	out:
+	*retsz = buf ? ((int *)buf)[1] : 0;
+	return(buf);
+}
+
+static void
+close_remote_fd(int fd, int code)
+{
+	register struct files_struct *files = current->files;
+	register struct file *fp = files->fd[fd];
+
+	/* no locking is required, since files->users is always 1 */
+	if(fp)
+	{
+		files->fd[fd] = NULL;
+		filp_close(fp, files);
+	}
+	if(code == REC_CLOSED)
+	{
+		FD_CLR(fd, files->open_fds);
+		if(fd < files->next_fd)
+			files->next_fd = fd;
+	}
+	else
+		FD_SET(fd, files->open_fds);
+}
+
+void
+remote_unpack_dfsa_changes(char *changes)
+{
+	int type;
+	void *rec;
+	register struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	register int i, j;
+	int dfsano;
+	struct file *fp;
+	struct dfsatab *tab;
+	mode_t mode;
+	loff_t pos;
+	unsigned int flags;
+	void *info;
+	int infolen;
+	gid_t *grp;
+
+	deeper_sleep();
+#ifdef CONFIG_MOSIX_DIAG
+	if(p->mosix.dupdates & DFSA_UPDATE)
+		mosix_panic("remote_unpack: has update(s)");
+#endif /* CONFIG_MOSIX_DIAG */
+	while((rec = get_record(changes, &type)))
+	switch(type)
+	{
+		case REC_CREDITS:
+			p->uid = ((struct credits_rec *)rec)->uid;
+			p->euid = ((struct credits_rec *)rec)->euid;
+			p->suid = ((struct credits_rec *)rec)->suid;
+			p->fsuid = ((struct credits_rec *)rec)->fsuid;
+			p->gid = ((struct credits_rec *)rec)->gid;
+			p->egid = ((struct credits_rec *)rec)->egid;
+			p->sgid = ((struct credits_rec *)rec)->sgid;
+			p->fsgid = ((struct credits_rec *)rec)->fsgid;
+			p->ngroups = ((struct credits_rec *)rec)->ngroups;
+			grp = ((struct credits_rec *)rec)->groups;
+			for(i = 0 ; i < p->ngroups ; i++)
+				p->groups[i] = *grp++;
+			break;
+		case REC_UMASK:
+			p->fs->umask = *((int *)rec);
+			break;
+		case REC_SELECT:
+#ifdef CONFIG_MOSIX_FS
+			p->mosix.selected =
+					((struct select_rec *)rec)->selected;
+			p->mosix.lastexec =
+					((struct select_rec *)rec)->lastexec;
+			p->mosix.lastmagic =
+					((struct select_rec *)rec)->lastmagic;
+#endif /* CONFIG_MOSIX_FS */
+			break;
+		case REC_DFSATAB:
+			remote_clear_dfsa();
+			i = ((struct dfsatab *)rec)->len;
+			if(!(tab = kmalloc(i, GFP_KERNEL)))
+				break;
+			memcpy((caddr_t)tab, (caddr_t)rec, i);
+			dfsa_adapt(tab);
+			p->mosix.ttab = tab;
+			process_ack(p, DREQ_NOTUPTODATE);
+			break;
+		case REC_CDIR:
+			if(p->fs->pwd)
+			{
+				dput(p->fs->pwd);
+				p->fs->pwd = NULL;
+				mntput(p->fs->pwdmnt);
+				p->fs->pwdmnt = NULL;
+			}
+			if(!(dfsano = ((struct cdir_rec *)rec)->dfsano))
+				break;
+			info = (void *)(((char *)rec)+sizeof(struct cdir_rec));
+			infolen = ((struct cdir_rec *)rec)->infolen;
+			reconstruct(dfsano, info, infolen, &p->fs->pwdmnt,
+								&p->fs->pwd);
+			break;
+		case REC_MAX:
+			i = ((struct max_rec *)rec)->max_fdset;
+			j = ((struct max_rec *)rec)->max_fds;
+			write_lock(&files->file_lock);
+			i = ((i > files->max_fdset && expand_fdset(files, i-1))
+				||
+			   (j > files->max_fds && expand_fd_array(files, j-1)));
+			write_unlock(&files->file_lock);
+			if(i)
+			{
+				remote_clear_dfsa();
+				tell_process(p, DREQ_NOTUPTODATE);
+			}
+			break;
+		case REC_CLOSED:
+		case REC_NONDFSA:
+			if(current->mosix.ttab)
+				close_remote_fd(*((int *)rec), type);
+			break;
+		case REC_FILE:
+			if(!current->mosix.ttab)
+				break;
+			i = ((struct file_rec *)rec)->fd;
+			mode = ((struct file_rec *)rec)->mode;
+			pos = ((struct file_rec *)rec)->pos;
+			flags = ((struct file_rec *)rec)->flags;
+			if(p->files->fd[i])
+			{
+				close_remote_fd(i, REC_FILE);
+#ifdef CONFIG_MOSIX_DEBUG
+				if(ds_debug & DSDEB_DFSA)
+					printk("%s: FD %d found already open "
+						"(closing it first)\n",
+						desc_mostask(NULL), i);
+#endif /* CONFIG_MOSIX_DEBUG */
+			}
+			dfsano = ((struct file_rec *)rec)->dfsano;
+			info = (void *)(((char *)rec)+sizeof(struct file_rec));
+			infolen = ((struct file_rec *)rec)->infolen;
+			dfsa_file_install(i, mode, pos, flags, dfsano, info,
+								infolen);
+			/* even if we failed, file was still opened on DEPUTY */
+			FD_SET(i, files->open_fds);
+			break;
+		case REC_MOD:
+			if(!current->mosix.ttab)
+				break;
+			i = ((struct file_rec *)rec)->fd;
+			if(!(fp = p->files->fd[i]))
+			{
+				/* asking DEPUTY to send REC_FILE */
+				p->mosix.dupdates |= DFSA_UPDOPEN;
+				if(i >= files->maxopened)
+					files->maxopened = i + 1;
+				FD_SET(i, files->opened);
+				break;
+			}
+			mode = ((struct file_rec *)rec)->mode;
+			pos = ((struct file_rec *)rec)->pos;
+			flags = ((struct file_rec *)rec)->flags;
+			fp->f_mode = mode;
+			fp->f_pos = pos;
+			fp->f_flags = flags;
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_DFSA)
+				printk("%s: Updated fd #%d, pos=%d, mode=%d, "
+					"flags=0x%x\n", desc_mostask(NULL), i,
+					(int)pos, mode, flags);
+#endif /* CONFIG_MOSIX_DEBUG */
+			break;
+		case REC_DUP:
+			if(!current->mosix.ttab)
+				break;	/* previous expanding-failure */
+			i = ((struct dup_rec *)rec)->fd;
+			close_remote_fd(i, REC_DUP);
+			if((fp = files->fd[((struct dup_rec *)rec)->orig]))
+			{
+				get_file(fp);
+				current->files->fd[i] = fp;
+			}
+			break;
+		case REC_USED:
+			if(!current->mosix.ttab)
+				break;	/* previous expanding-failure */
+			memcpy((caddr_t)files->open_fds, (caddr_t)rec,
+							files->max_fdset / 8);
+			break;
+#ifdef CONFIG_MOSIX_DIAG
+		default:
+			printk("record type = %d\n", type);
+			panic("remote_unpack_dfsa_changes");
+#endif /* CONFIG_MOSIX_DIAG */
+	}
+	lighter_sleep();
+}
+
+char *
+remote_pack_dfsa_changes(int *retsz)
+{
+	char *buf = NULL;
+	register struct task_struct *p = current;
+	register uint32_t updates;
+
+	if(!(updates = (p->mosix.dupdates & DFSA_UPDATE)))
+		goto out;
+	/* NOTE: we do not allow max_fds or max_fdset to grow REMOTELY,
+	 * so we do not act on this flag here */
+#ifdef CONFIG_MOSIX_FS
+	if(updates & DFSA_UPDSEL)
+	{
+		struct select_rec s;
+
+		s.selected = p->mosix.selected;
+		s.lastexec = p->mosix.lastexec;
+		s.lastmagic = p->mosix.lastmagic;
+		if(!(buf = add_changes_record(buf, REC_SELECT, &s, sizeof(s))))
+			goto fail;
+	}
+#endif /* CONFIG_MOSIX_FS */
+	if((updates & DFSA_UPDCDIR) && p->fs->pwd)
+	{
+		struct
+		{
+			struct cdir_rec c;
+			char info[MAX_IDENT_RECORD_LEN];
+		} cplus;
+		struct vfsmount *mnt = p->fs->pwdmnt;
+
+		lock_mosix();
+		if(!(cplus.c.dfsano = mnt->mnt_dfsaprev ? : mnt->mnt_dfsano))
+			panic("REMOTE non-DFSA cdir");
+		unlock_mosix();
+		cplus.c.infolen = mnt->mnt_sb->s_op->identify(p->fs->pwd,
+								cplus.info);
+		buf = add_changes_record(buf, REC_CDIR, &cplus,
+					sizeof(cplus.c) + cplus.c.infolen);
+		if(!buf)
+			goto fail;
+	}
+	if(updates & DFSA_UPDCLOSE)
+	{
+		if(add_closed_files(&buf))
+		{
+			fail:
+			*retsz = -ENOMEM;
+			return(NULL);
+		}
+	}
+	if(updates & DFSA_UPDOPEN)
+	{
+		if(add_opened_files(&buf))
+			goto fail;
+	}
+	if(updates & DFSA_UPDMODS)
+	{
+		if(add_modified_files(&buf))
+			goto fail;
+	}
+	p->mosix.dupdates &= ~DFSA_UPDATE;
+	out:
+	*retsz = buf ? ((int *)buf)[1] : 0;
+	return(buf);
+}
+
+static void
+close_deputy_fd(int fd)
+{
+	register struct files_struct *files = current->files;
+	register struct file *fp;
+
+	/* files->users must be 1, but we lock against /proc/{mypid}/fd */
+	write_lock(&files->file_lock);
+	if((fp = files->fd[fd]))
+	{
+		files->fd[fd] = NULL;
+		FD_CLR(fd, files->open_fds);
+		FD_CLR(fd, files->close_on_exec);
+		if(fd < files->next_fd)
+			files->next_fd = fd;
+		filp_close(fp, files);
+	}
+	write_unlock(&files->file_lock);
+}
+
+void
+deputy_unpack_dfsa_changes(char *changes)
+{
+	int type;
+	void *rec;
+	register struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	register int i;
+	int dfsano;
+	struct file *fp;
+	void *info;
+	int infolen;
+	mode_t mode;
+	loff_t pos;
+	unsigned int flags;
+
+	deeper_sleep();
+	while((rec = get_record(changes, &type)))
+	switch(type)
+	{
+		case REC_SELECT:
+#ifdef CONFIG_MOSIX_FS
+			p->mosix.selected =
+					((struct select_rec *)rec)->selected;
+			p->mosix.lastexec =
+					((struct select_rec *)rec)->lastexec;
+			p->mosix.lastmagic =
+					((struct select_rec *)rec)->lastmagic;
+#endif /* CONFIG_MOSIX_FS */
+			break;
+		case REC_CDIR:
+			dfsano = ((struct cdir_rec *)rec)->dfsano;
+			info = (void *)(((char *)rec)+sizeof(struct cdir_rec));
+			infolen = ((struct cdir_rec *)rec)->infolen;
+			write_lock(&p->fs->lock);
+			dput(p->fs->pwd);
+			p->fs->pwd = NULL;
+			mntput(p->fs->pwdmnt);
+			p->fs->pwdmnt = NULL;
+			reconstruct(dfsano, info, infolen, &p->fs->pwdmnt,
+								&p->fs->pwd);
+			write_unlock(&p->fs->lock);
+			break;
+		case REC_CLOSED:
+			i = *((int *)rec);
+			close_deputy_fd(i);
+			break;
+		case REC_FILE:
+			i = ((struct file_rec *)rec)->fd;
+			mode = ((struct file_rec *)rec)->mode;
+			pos = ((struct file_rec *)rec)->pos;
+			flags = ((struct file_rec *)rec)->flags;
+			if((fp = files->fd[i]))
+			/* only a change (or we would have to close first!) */
+			{
+#ifdef CONFIG_MOSIX_DIAG
+				if((fp->f_mode ^ mode) & FMODE_WRITE)
+					panic("how did FMODE_WRITE change REMOTELY?");
+#endif /* CONFIG_MOSIX_DIAG */
+				close_deputy_fd(i);
+#ifdef CONFIG_MOSIX_DEBUG
+				if(ds_debug & DSDEB_DFSA)
+					printk("%s: FD %d found already open "
+						"(closing it first)\n",
+						desc_mostask(NULL), i);
+#endif /* CONFIG_MOSIX_DEBUG */
+			}
+			dfsano = ((struct file_rec *)rec)->dfsano;
+			info = (void *)(((char *)rec)+sizeof(struct file_rec));
+			infolen = ((struct file_rec *)rec)->infolen;
+			dfsa_file_install(i, mode, pos, flags, dfsano, info,
+								infolen);
+			break;
+		case REC_NONDFSA:
+			/* this is a request for fuller info */
+			i = *((int *)rec);
+			p->mosix.dupdates |= DFSA_UPDOPEN;
+			if(i >= files->maxopened)
+				files->maxopened = i + 1;
+			FD_SET(i, files->opened);
+			FD_CLR(i, files->modified);
+			break;
+		case REC_MOD:
+			i = ((struct file_rec *)rec)->fd;
+			mode = ((struct file_rec *)rec)->mode;
+			pos = ((struct file_rec *)rec)->pos;
+			flags = ((struct file_rec *)rec)->flags;
+			if(!(fp = files->fd[i]))
+				break;
+#ifdef CONFIG_MOSIX_DIAG
+			if((fp->f_mode ^ mode) & FMODE_WRITE)
+				panic("how did FMODE_WRITE change REMOTELY?");
+#endif /* CONFIG_MOSIX_DIAG */
+			fp->f_mode = mode;
+			fp->f_pos = pos;
+			fp->f_flags = flags;
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_DFSA)
+				printk("%s: Updated fd #%d, pos=%d, mode=%d, "
+					"flags=0x%x\n", desc_mostask(NULL), i,
+					(int)pos, mode, flags);
+#endif /* CONFIG_MOSIX_DEBUG */
+			break;
+		case REC_DUP:
+			i = ((struct dup_rec *)rec)->fd;
+			close_deputy_fd(i);
+			if((fp = files->fd[((struct dup_rec *)rec)->orig]))
+			{
+				write_lock(&files->file_lock);
+				FD_SET(i, files->open_fds);
+				get_file(fp);
+				files->fd[i] = fp;
+				write_unlock(&files->file_lock);
+			}
+			else
+			{
+				printk("%s: DFSA told that FD #%d is a DUP "
+					"of FD #%d... which is NULL\n",
+					desc_mostask(NULL), i,
+					((struct dup_rec *)rec)->orig);
+				dfsa_file_install(i, 0, 0, 0, 0, NULL, 0);
+			}
+			break;
+		default:
+			printk("record type = %d\n", type);
+			panic("deputy_unpack_dfsa_changes");
+	}
+	lighter_sleep();
+}
+
+void
+dfsa_check_comm_send(int *type, char **result, int *reslen)
+{
+	register struct task_struct *p = current;
+	register struct mosix_task *m = &p->mosix;
+
+	if(*type & DFSA_NOUPDATE)
+	{
+		*result = NULL;
+		*reslen = 0;
+		return;
+	}
+	if((m->dflags & (DREMOTE|DPSYNC|DINCOMING)) == DREMOTE)
+	{
+		if((*result = remote_pack_dfsa_changes(reslen)))
+			*type |= COMM_MFDFSA;
+		if(!m->ttab || (process_told(p, DREQ_NOTUPTODATE)))
+			*type |= COMM_MFNODFSA;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(*reslen < 0)
+			printk("dfsa_check_comm_send: result=%d\n", *reslen);
+#endif /* CONFIG_MOSIX_DEBUG */
+		return;
+	}
+	*result = NULL;
+	*reslen = 0;
+	if(!(*type & USERMODE))
+		return;
+#ifdef CONFIG_MOSIX_DIAG
+	if((m->dflags & (DDEPUTY|DSYNC)) != (DDEPUTY|DSYNC))
+		mosix_panic("dfsa_check_comm_send: not DEPUTY|DSYNC");
+#endif /* CONFIG_MOSIX_DIAG */
+	if(process_told(p, DREQ_DFSASYNC))
+		clear_dfsasync();
+	if(process_told(p, DREQ_NOTUPTODATE))
+		m->dupdates |= DFSA_UPDATE;
+	if(!(m->dupdates & DFSA_UPDATE))
+		return;
+	again:
+	if(!CAN_DFSA(p))
+		goto no_dfsa;
+	*result = deputy_pack_dfsa_changes(reslen);
+	if(process_told(p, DREQ_DFSASYNC))	/* a new one (race) */
+	{
+		clear_dfsasync();
+		m->dupdates |= DFSA_UPDATE;
+		if(*result)
+			kfree(*result);
+		goto again;
+	}
+	if(*result)
+	{
+		*type |= COMM_MFDFSA;
+		return;
+	}
+	if(*reslen == 0)
+		return;
+	no_dfsa:
+	*type |= COMM_MFNODFSA;
+	*reslen = 0;
+}
+
+void
+dfsa_comm_recv(int type, char *changes)
+{
+	register struct task_struct *p = current;
+#ifdef CONFIG_MOSIX_DIAG
+	if(type & DFSA_NOUPDATE)
+	{
+		mosix_panic("dfsa_comm_recv: inhibited-type got through");
+		tell_process(p, DREQ_NOTUPTODATE);
+		return;
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	if(type & COMM_MFNODFSA)
+	{
+		if(p->mosix.dflags & DREMOTE)
+			remote_clear_dfsa();
+		tell_process(p, DREQ_NOTUPTODATE);
+	}
+	if(type & COMM_MFDFSA)
+	{
+		if(p->mosix.dflags & DREMOTE)
+			remote_unpack_dfsa_changes(changes);
+		else
+			deputy_unpack_dfsa_changes(changes);
+	}
+}
+
+static void printset(char *title, int max, fd_set *set)
+{
+	register int i;
+
+	printk("%s (max=%d): ", title, max);
+	for(i = 0 ; i < max ; i++)
+	if(FD_ISSET(i, set))
+		printk(" %d", i);
+	printk("\n");
+}
+
+void
+dfsa_dump(int pid)
+{
+	register struct task_struct *p = current;
+	register struct files_struct *files = p->files;
+	register int i, fs;
+	struct file *f;
+
+	if(pid)
+	{
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if(p->pid == pid || (int)p == pid)
+			break;
+		read_unlock(&tasklist_lock);
+		if(p == &init_task)
+		{
+			printk("Pid %d not found.\n", pid);
+			return;
+		}
+		files = p->files;
+	}
+	printk("%s : CAN_DFSA=%d\n", desc_mostask(&p->mosix), CAN_DFSA(p));
+	printk("Update flags:");
+	if(p->mosix.dupdates & DFSA_UPDCRED)
+		printk(" UPDCRED");
+	if(p->mosix.dupdates & DFSA_UPDSEL)
+		printk(" UPDSEL");
+	if(p->mosix.dupdates & DFSA_UPDTABLE)
+		printk(" UPDTABLE");
+	if(p->mosix.dupdates & DFSA_UPDCDIR)
+		printk(" UPDCDIR");
+	if(p->mosix.dupdates & DFSA_UPDCDIR)
+		printk(" UPDCDIR");
+	if(p->mosix.dupdates & DFSA_UPDCLOSE)
+		printk(" UPDCLOSE");
+	if(p->mosix.dupdates & DFSA_UPDMODS)
+		printk(" UPDMODS");
+	if(p->mosix.dupdates & DFSA_UPDUSED)
+		printk(" UPDUSED");
+	printk("\n");
+	printset("Files to close", files->maxclosed, files->closed);
+	printset("Files to modify", files->maxmod, files->modified);
+	if(p->mosix.ttab)
+		printk("DFSA table at 0x%x of size %d\n",
+			(int)p->mosix.ttab, p->mosix.ttab->len);
+	else
+		printk("No DFSA table.\n");
+	printset("Open files", p->files->max_fdset, p->files->open_fds);
+	if(p == current)
+	{
+		printk("DFSA files:\n");
+		for(i = 0 ; i < files->max_fds ; i++)
+		if((fs = can_dfsa_file(i)))
+		{
+			printk("%d: #%d/%d\n", i, fs,
+				(int)files->fd[i]->f_dentry->d_inode->i_ino);
+		}
+	}
+	else
+	{
+		printk("file/count/dfsano/ino:");
+		for(i = 0 ; i < files->max_fds ; i++)
+		if((f = files->fd[i]))
+		{
+			printk(" %d:%d/#%d/%d", i, file_count(f),
+				f->f_vfsmnt->mnt_dfsano ? : -9,
+				(int)f->f_dentry->d_inode->i_ino);
+		}
+		printk("\n");
+	}
+}
+
+#endif /* CONFIG_MOSIX_DFSA */
diff -ruN linux-2.4.16/mos/div.c linux-2.4.16-mosix/mos/div.c
--- linux-2.4.16/mos/div.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/div.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#define	low(x)	(((unsigned int *)&x)[0])
+#define	high(x)	(((unsigned int *)&x)[1])
+
+/* the slow, division by 64-bit is only provided for copleteness */
+/* but is not expected to be actually ever required by the kernel*/
+unsigned long long
+__slowdivdi3(unsigned long long a, unsigned long long b)
+{
+	long long result = 0;
+	long long bit = 1;
+
+	while((b << 1) < a)
+	{
+		b <<= 1;
+		bit <<= 1;
+	}
+	while(bit)
+	{
+		if(a > b)
+		{
+			a -= b;
+			result |= bit;
+		}
+		b >>= 1;
+		bit >>= 1;
+	}
+	return(result);
+}
+
+long long
+__divdi3(long long a, long long b)
+{
+	int sign;
+	long long result;
+	unsigned int al, ah, dl, dh;
+	int hd;
+	long long bit;
+	int i;
+
+	if(!high(b) && !high(a))	/* by far the most common case */
+		return(low(a) / low(b));
+	sign = 1;
+	if(high(b) & 0x80000000)
+	{
+		b = -b;
+		if(!high(b) && !high(a))
+			return(-low(a) / low(b));
+		sign = -1;
+	}
+	if(high(a) & 0x80000000)
+	{
+		sign = -sign;
+		a = -a;
+		if(!high(a) && !high(b))
+			return(sign * low(a) / low(b));
+	}
+	dh = high(b);
+	if(dh)
+		return(sign * __slowdivdi3(a, b));
+	dl = low(b);
+	if(!dl)
+		dh /= dl;	/* divide by 0! */
+	al = low(a);
+	ah = high(a);
+	for(i = 0 ; dh < ah || (dh == ah && dl <= al) ; i++)
+	{
+		dh += dh;
+		if(dl & 0x80000000)
+			dh++;
+		dl += dl;
+		if(i)
+		{
+			high(b) <<= 1;
+			if(low(b) & 0x80000000)
+				high(b)++;
+			low(b) <<= 1;
+		}
+	}
+	if(i == 0)
+		return(0);
+	if(i <= 32)
+	{
+		low(bit) = 1 << (i-1);
+		high(bit) = 0;
+	}
+	else
+	{
+		low(bit) = 0;
+		high(bit) = 1 << (i-33);
+	}
+	result = 0;
+	while(i--)
+	{
+		hd = high(a) - high(b);
+		if((hd = high(a) - high(b)) >= 0 &&
+			(low(a) >= low(b) || hd--))
+		{
+			high(a) = hd;
+			low(a) = low(a) - low(b);
+			result |= bit;
+		}
+		low(bit) >>= 1;
+		if(high(bit) == 1)
+			low(bit) = 0x80000000;
+		high(bit) >>= 1;
+		low(b) >>= 1;
+		if(high(b) & 1)
+			low(b) |= 0x80000000;
+		high(b) >>= 1;
+	}
+	if(sign < 0)
+		result = -result;
+	return(result);
+}
diff -ruN linux-2.4.16/mos/export.c linux-2.4.16-mosix/mos/export.c
--- linux-2.4.16/mos/export.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/export.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <asm/uaccess.h>
+#include <linux/mosix.h>
+#include <mos/routines.h>
+
+EXPORT_SYMBOL(deputy_copy_to_user);
+EXPORT_SYMBOL(deputy_copy_from_user);
+EXPORT_SYMBOL(deputy_clear_user);
+EXPORT_SYMBOL(deputy_strncpy_from_user);
+EXPORT_SYMBOL(deputy_strnlen_user);
+EXPORT_SYMBOL(deputy_verify_write);
+EXPORT_SYMBOL(mosix_deputy_init_aout_mm);
+EXPORT_SYMBOL(mosix_obtain_registers);
+EXPORT_SYMBOL(mosix_deputy_setup_args);
+EXPORT_SYMBOL(mosix_deputy_dump_thread);
+EXPORT_SYMBOL(mosix_config_get_table);
+EXPORT_SYMBOL(adjust_task_mosix_context);
+
+#ifdef CONFIG_MOSIX_DFSA
+EXPORT_SYMBOL(dfsa_open_file);
+EXPORT_SYMBOL(dfsa_touch_file);
+EXPORT_SYMBOL(dfsa_close_file);
+#endif /* CONFIG_MOSIX_DFSA */
+
+#ifdef CONFIG_MOSIX_UDB
+EXPORT_SYMBOL(mosix_debugger);
+#endif /* CONFIG_MOSIX_UDB */
+
+#if !defined(DO_NOT_FIX_LINUX_BUGS)
+#include <linux/personality.h>
+EXPORT_SYMBOL(lookup_exec_domain);
+#endif
+
+#ifdef CONFIG_DRM_I810_MODULE
+extern asmlinkage long sys_munmap(unsigned long,size_t);
+EXPORT_SYMBOL(mosix_go_home);
+EXPORT_SYMBOL(sys_munmap);
+#endif /* CONFIG_DRM_I810_MODULE */
diff -ruN linux-2.4.16/mos/freemem.c linux-2.4.16-mosix/mos/freemem.c
--- linux-2.4.16/mos/freemem.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/freemem.c	Tue Dec 25 19:01:26 2001
@@ -0,0 +1,461 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/pagemap.h>
+#include <linux/swap.h>
+#include <linux/swapctl.h>
+#include <linux/smp_lock.h>
+#include <linux/delay.h>
+#include <linux/mosix.h>
+#include <linux/slab.h>
+#include <asm/pgtable.h>
+#include <mos/routines.h>
+#include <mos/debug.h>
+#include <mos/defs.h>
+#include <mos/balance.h>
+
+int pages_to_keep_free;
+int latest_free_mem;
+static int sort_age_maxchunk;
+static int marker;
+
+static inline int
+current_free_mem(void)
+{
+	return(latest_free_mem);
+}
+
+int
+export_mem(void)
+{
+	register int i, n;
+	struct task_struct *p;
+
+	n = current_free_mem() - pages_to_keep_free;
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if((i = p->mosix.pages_i_bring) > 0)
+		n -= i;
+	read_unlock(&tasklist_lock);
+	if(n < 0)
+		n = 0;
+	return(n);
+}
+
+int
+memory_badly_required(void)
+{
+	register int n, s = 0;
+	struct task_struct *p;
+	struct mm_struct *mm;
+
+	n = current_free_mem() - pages_to_keep_free;
+	write_lock_irq(&tasklist_lock);
+	++marker;
+	for_each_task(p)
+	{
+		n -= p->mosix.pages_i_bring;
+		task_lock(p);
+		if((mm = p->mm) && mm->mark != marker && mm->last_memsort)
+		{
+			s += mm->swapped;
+			mm->mark = marker;
+		}
+		task_unlock(p);
+	}
+	write_unlock_irq(&tasklist_lock);
+	if(n < 0 && n > -MIN_EXPECTED_PROC_SIZE)
+		n = -MIN_EXPECTED_PROC_SIZE;
+	if(n < 0)
+		n -= s;
+	return(-n);
+}
+
+#define	MDP_HIGHEST_QUALITY	(MIN_EXPECTED_PROC_SIZE * 10)
+
+/* "memory_relief_quality" is called with tasklist_lock read-locked */
+int
+memory_relief_quality(struct task_struct *p, int need)
+{
+	int q;
+	int used, unused, swapped;	/* (dirty pages only) */
+	struct mm_struct *mm;
+
+	read_lock(&tasklist_lock);
+	task_lock(p);
+	if(!(mm = p->mm) || !mm->last_memsort)
+	{
+		task_unlock(p);
+		read_unlock(&tasklist_lock);
+		return(0);
+	}
+	used = mm->used;
+	unused = mm->unused;
+	swapped = mm->swapped;
+	task_unlock(p);
+	read_unlock(&tasklist_lock);
+	if (used >= need && used < 2 * need)
+		q = MDP_HIGHEST_QUALITY * (150 - used * 50 / need) / 100;
+	else if(used >= need)
+		q = MDP_HIGHEST_QUALITY * need / (1 + used - need);
+	else if (used < need)
+	{
+		if(need > MDP_HIGHEST_QUALITY/2)
+			q = MDP_HIGHEST_QUALITY / 2 * used / need;
+		else
+			q = used;
+	}
+	if(swapped)
+		q = q * used / (used + swapped);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MEM)
+		printk("relief_quality(need=%d,used=%d,unused=%d,swapped=%d)"
+			"=%d\n", need, used, unused, swapped, q);
+#endif /* CONFIG_MOSIX_DEBUG */
+	return(q);
+}
+
+/*
+ * The memory-sorting daemon is only loosely connected with MOSIX:
+ * it should have been part of Linux, but Linux does not age pages
+ * belonging to processes (unless memory is under pressure) and in
+ * MOSIX we do need to know how much memory is really free ALL THE TIME.
+ * The code here is largely stolen from "mm/vmscan.c".
+ */
+
+void
+compute_freemem(void)
+{
+	int count;
+	static int trouble_time;
+	int kernel, inactive, tasked;
+
+	if(acpuse < MF * smp_num_cpus * UTIL_TOLLERANCE)
+		trouble_time = 11;
+	tasked = 0;
+	if(trouble_time && --trouble_time > 0)
+		kernel = inactive = 0;
+	else
+	{
+		struct task_struct *p;
+		struct mm_struct *mm;
+
+		kernel = (dentry_stat.nr_unused * sizeof(struct dentry) +
+			  inodes_stat.nr_unused * sizeof(struct inode))
+			  >> PAGE_SHIFT;
+		inactive = nr_inactive_pages;
+		write_lock_irq(&tasklist_lock);
+		++marker;
+		for_each_task(p)
+		{
+			task_lock(p);
+			if((mm = p->mm) && mm->mark != marker &&
+				time_before(jiffies, mm->last_memsort + 15*HZ))
+			{
+				tasked += mm->private_unused;
+				mm->mark = marker;
+			}
+			task_unlock(p);
+		}
+		write_unlock_irq(&tasklist_lock);
+	}
+	count = nr_free_pages() + kernel + inactive + tasked;
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MEM)
+		printk("free=%d,ker=%d,inac=%d,tasked=%d,count=%d/%lu\n",
+			nr_free_pages(), kernel, inactive, tasked, count,
+			num_physpages);
+#endif /* CONFIG_MOSIX_DEBUG */
+	if(count >= num_physpages)	/* whatever went wrong... */
+		count = num_physpages - 1;
+	if(count < 0)
+		count = 0;
+	latest_free_mem = count;
+}
+
+static inline int
+sort_interval(int initial)
+{
+	if(latest_free_mem < pages_to_keep_free)
+		return(initial ? 0 : 3*HZ);
+	else if(latest_free_mem < 2 * pages_to_keep_free)
+		return(initial ? 2*HZ : 4*HZ);
+	else if(latest_free_mem < 4 * pages_to_keep_free)
+		return(initial ? 4*HZ : 8*HZ);
+	else
+		return(10*HZ);
+}
+
+/*
+ * sort pages into 3 piles: "used", "unused" and "swapped"
+ * plus another distinction for unused pages not otherwise accounted for
+ */
+void
+sort_and_age_pages(struct mm_struct *mm)
+{
+	int used = 0, unused = 0, swapped = 0, private_unused = 0;
+	int need_flush = 0;
+	register struct vm_area_struct *vma;
+	pgd_t *pgdir;
+	pmd_t *pmdir;
+	pte_t *pte;
+	struct page *page;
+	unsigned long addr, start, pgd_end, pmd_end;
+	static int let_go = -1;
+	int interval = sort_interval(1);
+
+	if(!mm->last_memsort && interval)
+	{
+		if(!mm->used)
+			mm->used = (jiffies & 0xffff) ? : 0xffff;
+		if((u16)((jiffies & 0xffff) - mm->used) < interval)
+			return;
+	}
+	addr = 0;
+	loop:
+	if(let_go == -1)
+		let_go = sort_age_maxchunk;
+	spin_lock(&mm->page_table_lock);
+	for(vma = mm->mmap ; vma != NULL ; vma = vma->vm_next)
+	if(addr < vma->vm_end)
+	{
+		start = vma->vm_start;
+		if(start < addr)
+			start = addr;
+		pgdir = pgd_offset(mm, start);
+		for(addr = start ; addr < vma->vm_end ;
+			addr = pgd_end , pgdir++)
+		{
+			if(let_go-- == 0)
+			{
+				spin_unlock(&mm->page_table_lock);
+				current->policy |= SCHED_YIELD;
+				schedule();
+				goto loop;
+			}
+			pgd_end = (addr + PGDIR_SIZE) & PGDIR_MASK;
+			if(pgd_end > vma->vm_end)
+				pgd_end = vma->vm_end;
+			if(pgd_none(*pgdir) || pgd_bad(*pgdir))
+				continue;
+			pmdir = pmd_offset(pgdir, addr);
+			for(; addr < pgd_end ; addr = pmd_end , pmdir++)
+			{
+				pmd_end = (addr + PMD_SIZE) & PMD_MASK;
+				if(pmd_end > pgd_end)
+					pmd_end = pgd_end;
+				if(pmd_none(*pmdir) || pmd_bad(*pmdir))
+					continue;
+				pte = pte_offset(pmdir, addr);
+					page = pte_page(*pte);
+				for(; addr < pmd_end ; addr += PAGE_SIZE, pte++)
+	{
+		if(pte_none(*pte))
+			continue;
+		if(!pte_present(*pte))
+		{
+			swapped++;
+			continue;
+		}
+		page = pte_page(*pte);
+		if(!VALID_PAGE(page) || PageReserved(page))
+			continue;
+		if(PageActive(page))
+		{
+			used++;
+			continue;
+		}
+		if(!PageActive(page))
+		{
+			unused++;
+			continue;
+		}
+		if(time_before(jiffies, page->last_young + OLD_SECONDS * HZ))
+		{
+			used++;
+			continue;
+		}
+		if(ptep_test_and_clear_young(pte))
+		{
+			page->young = 1;
+			page->last_young = jiffies;
+			need_flush = 1;
+			used++;
+			continue;
+		}
+		unused++;
+		private_unused++;
+	}
+			}
+		}
+	}
+	if(need_flush)
+		flush_tlb_mm(mm);
+	spin_unlock(&mm->page_table_lock);
+	write_lock_irq(&tasklist_lock);
+	mm->used = used;
+	mm->unused = unused;
+	mm->swapped = swapped;
+	mm->private_unused = private_unused;
+	mm->last_memsort = jiffies ? : 1;
+	write_unlock_irq(&tasklist_lock);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_SUPERMEM)
+		printk("memory: used=%d, unused=%d (%d private), swapped=%d\n",
+					used, unused, private_unused, swapped);
+#endif /* CONFIG_MOSIX_DEBUG */
+}
+
+#define	SORT_AGE_MAGIC		2490368
+
+int
+mosix_mem_daemon(void *nothing)
+{
+	struct task_struct *p;
+	struct mm_struct *mm;
+	struct mm_struct **mms, **newmms;
+	int i, n, mmno = 100, need_increase = 0;
+	int interval;
+
+	common_daemon_setup("memsorter", 0);
+	neutralize_my_load(1);
+	if(!(mms = (struct mm_struct **)kmalloc(mmno * sizeof(mms[0]),
+								GFP_KERNEL)))
+		panic("no mem for mms");
+	pages_to_keep_free = num_physpages / KEEP_FREE_PORTION;
+	if(pages_to_keep_free > MAX_PAGES_TO_KEEP_FREE)
+		pages_to_keep_free = MAX_PAGES_TO_KEEP_FREE;
+	compute_freemem();
+
+	/* "sort_and_age_pages" can take very long for large memories:
+	 * we must therefore allow other processes to take over at least
+	 * about every millisecond.
+	 */
+	sort_age_maxchunk = loops_per_jiffy / SORT_AGE_MAGIC;
+	if(!sort_age_maxchunk)	/* very slow processors */
+		sort_age_maxchunk = 1;
+	while (1)
+	{
+		current->state = TASK_INTERRUPTIBLE;
+		schedule_timeout(mosadmin_mode_quiet ? 100 * HZ : HZ);
+		if(current->sigpending)
+			flush_signals(current);
+		loop:
+                if (!PE)
+			wait_for_mosix_configuration(NULL);
+		if(mosadmin_mode_quiet)
+			continue;
+		compute_freemem();
+		interval = sort_interval(0);
+		n = 0;
+		write_lock_irq(&tasklist_lock);
+		++marker;
+		for_each_task(p)
+		if(!(p->mosix.stay & DSTAY_PER_MM))
+		{
+			task_lock(p);
+			mm = p->mm;
+			if((mm = p->mm) && mm != &init_mm && mm->mark != marker
+				&& time_before(mm->last_memsort + interval,
+								jiffies))
+			{
+				if(n >= mmno)
+					need_increase = 1;
+				else
+				{
+					atomic_inc(&mm->mm_users);
+					mms[n++] = mm;
+					mm->mark = marker;
+				}
+			}
+			task_unlock(p);
+		}
+		write_unlock_irq(&tasklist_lock);
+		for(i = 0 ; i < n ; i++)
+		{
+			mm = mms[i];
+			if(atomic_read(&mm->mm_realusers) > 0)
+				sort_and_age_pages(mm);
+			mmput(mm);
+		}
+		if(need_increase)
+		{
+			if((newmms = (struct mm_struct **)kmalloc(
+				(mmno + 50) * sizeof(mms[0]), GFP_KERNEL)))
+			{
+				kfree(mms);
+				mms = newmms;
+				mmno += 50;
+			}
+			need_increase = 0;
+			goto loop;
+		}
+		wake_up_interruptible(&kswapd_wait);
+	}
+}
+
+#if 0
+/* needed once-only to calibrate the "sort_age_maxchunk" calculation */
+/* not bothering using locks here, since we are only called from the debugger */
+int
+calibrate_sort_age(int pid)
+{
+	int sv = sort_age_maxchunk;
+	struct task_struct *p = find_task_by_pid(pid);
+	struct mm_struct *mm;
+	int chunks = 0;
+	register struct vm_area_struct *vma;
+	unsigned long addr, pgd_end;
+	__typeof__ (jiffies) before;
+	int milli, magic;
+	int i;
+
+	if(!p || !(mm = p->mm))
+	{
+		printk("No PID %d\n", pid);
+		return(0);
+	}
+
+	for(vma = mm->mmap ; vma != NULL ; vma = vma->vm_next)
+	for(addr = vma->vm_start ; addr < vma->vm_end ; addr = pgd_end)
+	{
+		chunks++;
+		pgd_end = (addr + PGDIR_SIZE) & PGDIR_MASK;
+		if(pgd_end > vma->vm_end)
+			pgd_end = vma->vm_end;
+	}
+	printk("%d chunks: starting 1000 times...", chunks);
+	sort_age_maxchunk = 0x7fffffff;	/* unlimit */
+	if(!mm->last_memsort)
+		mm->last_memsort = 1;
+	sti();
+	before = jiffies;
+	for(i = 0 ; i < 1000 ; i++)
+		sort_and_age_pages(mm);
+	milli = (jiffies - before) * 1000 / HZ;
+	printk("%d miliseconds, ", milli);
+	sort_age_maxchunk = sv;
+	if(milli < 100)
+	{
+		printk("That was too quick -- try a larger process!\n");
+		return((int)milli);
+	}
+	magic = loops_per_jiffy / (chunks * 1000 / milli);
+	printk("SORT_AGE_MAGIC=%d\n", magic);
+	return(magic);
+}
+#endif /* MOSIX_ONCE_ONLY */
diff -ruN linux-2.4.16/mos/info.c linux-2.4.16-mosix/mos/info.c
--- linux-2.4.16/mos/info.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/info.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1029 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Amnon Barak, Oren Laadan.
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/mosctl.h>
+#include <net/sock.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <mos/protocol.h>
+#include <linux/mosix.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/swap.h>
+#include <linux/stddef.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+#include <mos/version.h>
+#include <mos/balance.h>
+
+static int info_seed1, info_seed2;
+
+rwlock_t loadinfo_lock = RW_LOCK_UNLOCKED;
+spinlock_t uplist_lock = SPIN_LOCK_UNLOCKED;
+
+struct uplist {
+	struct uplist *next;
+	unsigned short pe;
+	short age;
+};
+
+static struct uplist uplist[MAXKNOWNUP];
+static struct uplist *uphead, *upfree;
+static int info_nup;		/* number of processes in uplist */
+
+struct loadinfo loadinfo[INFO_WIN];
+
+static int info_recv_message(struct infomsg *, int);
+static int info_send_message(int, struct infomsg *);
+static void update_uplist(struct loadinfo *);
+static void update_window(struct loadinfo *);
+static void inform(void);
+static void not_responding(int);
+static void age_uplist(void);
+static int rand(int, int);
+
+static char INFODSTR[] = "infodaemon";
+
+#define INFO_BUFSIZE	8192
+
+int
+mosix_info_daemon(void *nothing)
+{
+	struct task_struct *p = current;
+	struct loadinfo *load;
+	struct infomsg *msg;
+	static char info_buf[INFO_BUFSIZE]; /* (large) buffer for info load */
+
+	common_daemon_setup(INFODSTR, 1);
+	lock_mosix();
+	info_proc = current;
+	unlock_mosix();
+
+restart:
+	wait_for_mosix_configuration(&info_daemon_active);
+	comm_init_linkpool();
+	if (!p->mosix.contact) {
+		comm_use(p, comm_open(COMM_INFO, 0, 0UL));
+		if (!p->mosix.contact)
+		{
+			printk("%s: failed comm_open - exiting\n", INFODSTR);
+			comm_free_linkpool();
+			if(p->mosix.contact)
+				comm_close(NULL);
+			lock_mosix();
+			info_daemon_active = 0;
+			info_proc = NULL;
+			unlock_mosix();
+			do_exit(0);
+		}
+	}
+
+	msg = (struct infomsg *) info_buf;
+	load = (struct loadinfo *) &msg->load;
+
+	while (1) {
+		comm_wait();
+
+		/* if MOSIX was shut down - restart everything */
+                if (!PE) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_INFO)
+				printk("%s: sleeping after MOSIX shutdown\n",
+								INFODSTR);
+#endif
+                        comm_close(NULL);
+			comm_free_linkpool();
+                        goto restart;
+                }
+
+		while (info_recv_message(msg, INFO_BUFSIZE))
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_INFO)
+				printk("INFO arrived from %d\n", load->pe);
+#endif
+			update_uplist(load);
+			update_window(load);
+			if (!mosadmin_mode_quiet) {
+				load_balance();
+				memory_balance();
+			}
+		}
+
+		if(sigismember(&p->pending.signal, SIGALRM))
+		{
+			spin_lock_irq(&p->sigmask_lock);
+			flush_signals(p);
+			spin_unlock_irq(&p->sigmask_lock);
+
+			if(mosadmin_mode_quiet)
+				continue;
+
+			if(PE)
+				inform();
+			inc_decays();
+			comm_age_linkpool();
+			age_uplist();
+			loadinfo[0].mem = latest_free_mem;
+			loadinfo[0].rmem = nr_free_pages();
+			age_balancing();
+		}
+	}
+}
+
+static void
+age_uplist(void)
+{
+	struct uplist *up, *prev, *cutpoint;
+	int old = 10 * (NPE-1);
+	/* (the more nodes around, the less often they are
+	 * likely to come up again, so we hold them longer) */
+
+	if(old > 32767)
+		old = 32767;
+	spin_lock(&uplist_lock);
+	for (prev = NULL, up = uphead; up; prev = up , up = up->next)
+	if (++up->age >= old)
+	{
+		/* the list is sorted by age, so all the rest are too old! */
+		if (prev)
+			prev->next = NULL;
+		else
+			uphead = NULL;
+		cutpoint = up;
+		while(1)
+		{
+			info_nup--;
+			if(up->next)
+				up = up->next;
+			else
+				break;
+		}
+		prev = upfree;
+		upfree = cutpoint;
+		up->next = prev;
+		break;
+	}
+	spin_unlock(&uplist_lock);
+}
+
+static void
+update_uplist(struct loadinfo *load)
+{
+	struct uplist *up, *prev;
+
+	spin_lock(&uplist_lock);
+	for (prev = NULL , up = uphead ; up ; prev = up , up = up->next)
+	if (up->pe == load->pe)
+	{
+		up->age = 0;
+		if (prev)	/* put it first */
+		{
+			prev->next = up->next;
+			up->next = uphead;
+			uphead = up;
+		}
+		break;
+	}
+	if (!up) {
+		if (upfree) {
+			up = upfree;
+			upfree = upfree->next;
+			info_nup++;
+		} else {
+			for (prev = uphead ; prev->next->next ;
+				prev = prev->next)
+				; /* nothing */
+			up = prev->next;
+			prev->next = NULL;
+		}
+		up->pe = load->pe;
+		up->age = 0;
+		up->next = uphead;
+		uphead = up;
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_INFO) {
+		printk("UPLIST:");
+		for (up = uphead; up; up = up->next)
+			printk(" %d/%d", up->pe, up->age);
+		printk("\n");
+	}
+#endif /* CONFIG_MOSIX_DEBUG */
+	spin_unlock(&uplist_lock);
+}
+
+
+static void
+update_window(struct loadinfo *load)
+{
+	static int info_slot; /* pointer to next information to fill */
+	int i;
+
+	info_slot = (info_slot % (INFO_WIN - 1)) + 1;
+	loadinfo[info_slot] = *load;
+
+	for (i = 1 ; i < INFO_WIN ; i++)
+	if (i != info_slot && loadinfo[i].pe == load->pe)
+	{
+		write_lock_bh(&loadinfo_lock);
+		loadinfo[i].pe = 0;
+		write_unlock_bh(&loadinfo_lock);
+		break;
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_INFO) {
+		printk("INFODATA:");
+		for (i = 0; i < INFO_WIN; i++)
+			if (loadinfo[i].pe)
+				printk(", %d=%d",
+					loadinfo[i].pe, (int)loadinfo[i].load);
+		printk("\n");
+	}
+#endif
+}
+
+#define	speed_adjust(x)		((x) * ((int64_t)STD_SPD) / loadinfo[0].speed)
+void
+info_update_costs(void)
+{
+	register int i;
+
+	write_lock_bh(&loadinfo_lock);
+	for(i = 0 ; i < MAX_MOSIX_TOPOLOGY ; i++)
+	{
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		loadinfo[0].costs[i].page = mosix_cost[i].PAGE_R;
+		loadinfo[0].costs[i].syscall = mosix_cost[i].SYSCALL_R;
+		loadinfo[0].costs[i].out = mosix_cost[i].COPYOUT_BASE_R;
+		loadinfo[0].costs[i].outkb = mosix_cost[i].COPYOUT_PER_KB_R;
+		loadinfo[0].costs[i].in = mosix_cost[i].COPYIN_BASE_R;
+		loadinfo[0].costs[i].inkb = mosix_cost[i].COPYIN_PER_KB_R;
+		loadinfo[0].costs[i].first = mosix_cost[i].first;
+		loadinfo[0].costs[i].last = mosix_cost[i].last;
+#else
+		remote_here.page = mosix_cost[i].PAGE_R;
+		remote_here.syscall = mosix_cost[i].SYSCALL_R;
+		remote_here.out = mosix_cost[i].COPYOUT_BASE_R;
+		remote_here.outkb = mosix_cost[i].COPYOUT_PER_KB_R;
+		remote_here.in = mosix_cost[i].COPYIN_BASE_R;
+		remote_here.inkb = mosix_cost[i].COPYIN_PER_KB_R;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+		remote_here_adjusted[i].page =
+					speed_adjust(mosix_cost[i].PAGE_R);
+		remote_here_adjusted[i].syscall =
+					speed_adjust(mosix_cost[i].SYSCALL_R);
+		remote_here_adjusted[i].out =
+				speed_adjust(mosix_cost[i].COPYOUT_BASE_R);
+		remote_here_adjusted[i].outkb =
+				speed_adjust(mosix_cost[i].COPYOUT_PER_KB_R);
+		remote_here_adjusted[i].in =
+				speed_adjust(mosix_cost[i].COPYIN_BASE_R);
+		remote_here_adjusted[i].inkb =
+				speed_adjust(mosix_cost[i].COPYIN_PER_KB_R);
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		remote_here_adjusted[i].first = mosix_cost[i].first;
+		remote_here_adjusted[i].last = mosix_cost[i].last;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	}
+	write_unlock_bh(&loadinfo_lock);
+}
+
+void
+info_update_mfscosts(void)
+{
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	memcpy(loadinfo[0].mfscosts, mfs_cost, sizeof(mfs_cost));
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+}
+
+void
+set_my_cpuspeed(void)
+{
+	int s = cpuspeed;
+
+	if(sizeof(loadinfo[0].speed) < 4 && s > 65535)
+	{
+		printk("Computer Too Fast!  Time to Update Standard-Speed.\n");
+		s = 65535;
+	}
+	stable_export = (MF+2) * STD_SPD / (s * smp_num_cpus);
+	if(stable_export == MF * STD_SPD / (s * smp_num_cpus))
+		stable_export++;
+	write_lock_bh(&loadinfo_lock);
+	loadinfo[0].speed = s;
+	write_unlock_bh(&loadinfo_lock);
+	info_update_costs();
+	info_update_mfscosts();
+}
+
+void
+info_init(void)
+{
+	loadinfo[0].ncpus = smp_num_cpus;
+	loadinfo[0].tmem = num_physpages;
+	set_my_cpuspeed();
+}
+
+void
+info_startup(void)
+{
+	int i;
+
+	info_seed1 = PE;
+	info_seed2 = PE*PE*PE*PE;
+	write_lock_bh(&loadinfo_lock);
+	loadinfo[0].pe = PE;
+	for (i = 1 ; i < INFO_WIN ; i++) {
+		loadinfo[i].pe = 0;
+		loadinfo[i].load = 0xffffffff;
+	}
+	write_unlock_bh(&loadinfo_lock);
+
+	spin_lock(&uplist_lock);
+	upfree = uphead = NULL;
+	info_nup = 0;
+
+	memset(uplist, 0, sizeof(struct uplist) * MAXKNOWNUP);
+	for (i = 0; i < MAXKNOWNUP; i++) {
+		uplist[i].next = upfree;
+		upfree = &uplist[i];
+	}
+	spin_unlock(&uplist_lock);
+}
+
+void
+info_reconfig()
+{
+	int i;
+	struct uplist *up, *prev;
+
+	lock_mosix();	/* because "mos_to_net" does! */
+	spin_lock(&uplist_lock);
+recheck:
+	prev = NULL;
+	for (up = uphead ; up ; prev = up, up = up->next)
+	if (!mos_to_net(up->pe, NULL)) {
+		if (prev)
+			prev->next = up->next;
+		else
+			uphead = up->next;
+		up->next = upfree;
+		upfree = up;
+		info_nup--;
+		goto recheck;
+	}
+	spin_unlock(&uplist_lock);
+	write_lock_bh(&loadinfo_lock);
+	for (i = 1; i < INFO_WIN; i++)
+		if (loadinfo[i].pe && !mos_to_net(loadinfo[i].pe, NULL))
+			loadinfo[i].pe = 0;
+	write_unlock_bh(&loadinfo_lock);
+	unlock_mosix();
+}
+
+static int
+info_recv_message(struct infomsg *info, int bufsize)
+{
+	static mosix_addr ra;		/* reply address */
+	struct mosix_link *l = current->mosix.contact;
+	struct loadinfo *load = &(info->load);
+	int n;
+	int sender;
+
+	while (1) {
+		n = comm_recvfrom(info, bufsize, l, &ra, 0);
+#ifdef CONFIG_MOSIX_DIAG
+		if (!n)
+			mosix_panic("comm_recvfrom: n == 0");
+#endif
+
+		if (n == -EDIST)
+			continue;	/* message > bufsize */
+
+		if (n < 0)
+			return (0);
+
+		if (n < sizeof(*info)) {
+#ifdef CONFIG_MOSIX_DEBUG
+			printk("%s-info_recv_message: data too short\n",
+				desc_mostask(NULL));
+#endif
+			continue;
+		}
+
+		if (info->version != MOSIX_BALANCE_VERSION) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_INFO)
+				printk("%s-info_recv_message: wrong MOSIX "
+					"version (expect %ld, got %ld)\n",
+					desc_mostask(NULL),
+					MOSIX_BALANCE_VERSION, info->version);
+#endif /* CONFIG_MOSIX_DEBUG */
+			continue;
+		}
+		if (info->topology != MAX_MOSIX_TOPOLOGY) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_INFO)
+				printk("%s-info_recv_message: wrong MOSIX "
+					"topology: we have %d, they have %d",
+					desc_mostask(NULL), MAX_MOSIX_TOPOLOGY,
+					info->topology);
+#endif /* CONFIG_MOSIX_DEBUG */
+			continue;
+		}
+
+		sender = load->pe ? : load->speed;
+		if (sender > MAXPE || sender != net_to_mos(&ra)) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_INFO)
+				printk("%s-info_recv_message: discarded "
+					"load from extra-cluster machine #%d\n",
+					desc_mostask(NULL), sender);
+#endif
+			continue;
+		}
+
+		if (sender == PE)
+		{
+			printk("WARNING: Another computer is masquerading as same MOSIX node as this (%d)!\n", PE);
+			continue;
+		}
+	
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_LOADS)
+			printk("recv: load at 0x%x : (%d,%d,%d,%d)\n",
+				(int)load,load->pe,(int)load->load,load->speed,
+				load->ncpus);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+		if (load->pe)
+			return (1);
+
+		/*
+		 * Ugly convention: !load->pe ==> this is a GETLOAD request
+		 */
+
+		lock_mosix();
+		write_lock_bh(&loadinfo_lock);
+		loadinfo[0].status = my_mosix_status();
+		loadinfo[0].free_slots = get_free_guest_slots();
+		unlock_mosix();
+		loadinfo[0].mem = latest_free_mem;
+		loadinfo[0].rmem = nr_free_pages();
+		loadinfo[0].util = acpuse;
+#ifdef CONFIG_MOSIX_RESEARCH
+		loadinfo[0].rio = io_read_rate;
+ 		loadinfo[0].wio = io_write_rate;
+#endif /* CONFIG_MOSIX_RESEARCH */
+		*load = loadinfo[0];
+		write_unlock_bh(&loadinfo_lock);
+
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_INFO)
+			printk("%s-info_recv_message: reply query of %d\n",
+				desc_mostask(NULL), load->pe);
+#endif
+		
+		comm_sendto(COMM_TOADDR, info, sizeof(*info), l, &ra);
+	}
+	return(0);
+}
+
+static int
+info_send_message(int mos, struct infomsg *info)
+{
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_INFO)
+		printk("%s-info_send_message to %d\n", desc_mostask(NULL), mos);
+
+	if(ds_debug & DSDEB_LOADS)
+		printk("send: load at 0x%x (%d,%d,%d,%d)\n", (int)&info->load,
+		info->load.pe, (int)info->load.load, info->load.speed,
+		info->load.ncpus);
+#endif
+
+	return(comm_sendto(mos, info, sizeof(*info), current->mosix.contact,
+								NULL) < 0);
+}
+
+int
+load_to_mosix_info(struct loadinfo l, struct mosix_info *info, int touser)
+{
+	struct mosix_info tmp, *uaddr;
+	int error;
+
+	if(touser)
+	{
+		uaddr = info;
+		info = &tmp;
+	}
+	else
+		uaddr = NULL;	/* pacify angry stupid gcc */
+	info->load = ((int64_t)l.load) * standard_speed / STD_SPD;
+	info->speed = l.speed;
+	info->ncpus = l.ncpus;
+	info->mem = l.mem * PAGE_SIZE;
+	info->rmem = l.rmem * PAGE_SIZE;
+	info->tmem = l.tmem * PAGE_SIZE;
+	info->util = l.util;
+#ifdef CONFIG_MOSIX_RESEARCH
+	info->rio = l.rio;
+	info->wio = l.wio;
+#endif /* CONFIG_MOSIX_RESEARCH */
+
+	info->status = l.status;
+	if(touser && (error = copy_to_user((char *)uaddr, (char *)info,
+								sizeof(*info))))
+		return(-EFAULT);
+	return(0);
+}
+
+static int info_serialno = 0;
+static int info_timo;
+static int info_retry;
+static int info_retry_cnt;
+
+#define	INFO_TIMO 50000		/* ms */
+#define	INFO_RETRY 20000	/* after 20 & 40 ms */
+
+#define	SIMULTANEOUS_QUERIES		10
+
+void
+mosinfo_update_gateways(void)
+{
+	/* the following may be further optimized in the future: */
+	info_timo = INFO_TIMO * (mosadmin_gateways + 1);
+#if INFO_RETRY * 3 > 65535
+#error: "timtosend" below must be made "unsigned int".
+#endif
+	info_retry = INFO_RETRY * (mosadmin_gateways + 1);
+	info_retry_cnt = (info_timo + info_retry - 1) / info_retry;
+}
+
+int
+balance_get_infos(int first, int num, struct mosix_info *info, int touser)
+{
+	char *donebits, fewbits[20]; /* 20*8=160 seems to cover most cases */
+	struct progress
+	{
+		unsigned short node;
+		unsigned short timtosend;
+		unsigned int timo;
+		int serialno;
+	} progress[SIMULTANEOUS_QUERIES];
+	int hint = 0;
+	int ntaken = 0;
+	int ndone = 0;
+	int inpot = 0;
+	int node, from, i, n;
+	int error = 0;
+	int timo;
+	now_t before;
+	mosix_link *mlink;
+	struct loadinfo l;
+	struct infomsg infomsg;
+
+	if(num <= 8*sizeof(fewbits))
+		donebits = fewbits;
+	else if(!(donebits = (char *)kmalloc((num+7)/8, GFP_KERNEL)))
+		return(-ENOMEM);
+	memset(donebits, 0, (num+7)/8);
+	if (!(mlink = comm_borrow_linkpool()))
+		error = -EDIST;
+	loop:
+	while(!error && ndone < num)
+	{
+		while(inpot < SIMULTANEOUS_QUERIES && ntaken < num)
+		{
+			while(donebits[hint/8] & (1 << (hint%8)))
+			if(++hint == num)
+				hint = 0;
+			donebits[hint/8] |= (1 << (hint%8));
+			ntaken++;
+			node = first + hint;
+			if (node == PE)
+			{
+				read_lock_bh(&loadinfo_lock);
+				l = loadinfo[0];
+				read_unlock_bh(&loadinfo_lock);
+				l.status = my_mosix_status();
+				l.util = acpuse;
+#ifdef CONFIG_MOSIX_RESEARCH 
+				l.rio = io_read_rate;
+				l.wio = io_write_rate;
+#endif /* CONFIG_MOSIX_RESEARCH  */
+				ready_immediate:
+				ndone++;
+				if((error = load_to_mosix_info(l, &info[hint],
+								touser)))
+					break;
+				continue;
+			}
+			if (!mos_to_net(node, NULL))
+			{
+				l.status = 0;
+				goto ready_immediate;
+			}
+			progress[inpot].node = node;
+			progress[inpot].timo = info_timo;
+			progress[inpot].timtosend = 0;
+			progress[inpot].serialno = info_serialno++;
+			inpot++;
+		}
+		if(error || ndone == num)
+			break;
+		timo = info_retry;
+		for(i = 0 ; i < inpot ; i++)
+		{
+			if(progress[i].timo < timo)
+				timo = progress[i].timo;
+			if(progress[i].timo && progress[i].timtosend <= 0)
+			{
+				progress[i].timtosend = info_retry;
+				infomsg.version = MOSIX_BALANCE_VERSION;
+				infomsg.serialno = progress[i].serialno;
+				infomsg.topology = MAX_MOSIX_TOPOLOGY;
+				infomsg.load.pe = 0;	/* eg. GETLOAD */
+				infomsg.load.speed = PE;
+				if(comm_sendto(progress[i].node, &infomsg,
+					sizeof(infomsg), mlink, NULL) <= 0)
+				{
+					node = progress[i].node;
+					progress[i] = progress[--inpot];
+					ndone++;
+					l.status = DS_MOSIX_DEF;
+					error = load_to_mosix_info(l,
+						&info[node - first], touser);
+					goto loop;
+				}
+			}
+			if(progress[i].timtosend < timo)
+				timo = progress[i].timtosend;
+		}
+		before = time_now();
+		n = comm_recvfrompe(&infomsg, sizeof(infomsg), mlink, &from,
+								info_retry);
+		if (n == sizeof(infomsg))
+		for (i = 0; i < inpot; i++) {
+			if (from == progress[i].node &&
+			    infomsg.load.pe == progress[i].node &&
+			    infomsg.serialno == progress[i].serialno) {
+			    	ndone++;
+				node = progress[i].node;
+				progress[i] = progress[--inpot];
+				error = load_to_mosix_info(infomsg.load,
+						&info[node - first], touser);
+				break;
+			}
+		} else if (signal_pending(current))
+			error = -EINTR;
+		if (error)
+			break;
+
+		before = time_since(before);
+		if(before > timo)
+			before = timo;
+		if(before)
+		for(i = 0 ; i < inpot ; i++)
+		{
+			progress[i].timo -= before;
+			if(progress[i].timtosend < before)
+				progress[i].timtosend = 0;
+			else
+				progress[i].timtosend -= before;
+		}
+		if(n <= 0)
+		for(i = 0 ; i < inpot ; i++)
+		if(progress[i].timo <= 0)	/* cannot realy be < */
+		{
+			node = progress[i].node;
+			progress[i] = progress[--inpot];
+			ndone++;
+			l.status = DS_MOSIX_DEF;
+			if((error = load_to_mosix_info(l,
+				&info[node - first], touser)))
+				break;
+			i--;
+		}
+	}
+	if (mlink)
+		comm_return_linkpool(mlink);
+	if(num > 8*sizeof(fewbits))
+		kfree(donebits);
+	return(error);
+}
+
+int
+balance_ask_node(int node, struct infomsg *info)
+{
+	mosix_link *mlink = NULL;
+	int from, n, error = 0;
+	int serialno;
+	int tries;
+	now_t before;
+	int timo;
+
+	if (!(mlink = comm_borrow_linkpool()))
+		error = -EDIST;
+	serialno = info_serialno++;
+	tries = info_retry_cnt;
+	timo = info_retry;
+	while (!error && tries--) {
+		info->version = MOSIX_BALANCE_VERSION;
+		info->serialno = serialno;
+		info->topology = MAX_MOSIX_TOPOLOGY;
+		info->load.pe = 0;	/* eg. GETLOAD */
+		info->load.speed = PE;
+		error = comm_sendto(node, info, sizeof(*info), mlink, NULL);
+		if (error < sizeof(*info))
+		{
+			if(error >= 0)
+				error = -EDIST;
+			goto out;
+		}
+		error = 0;
+		before = time_now();
+		n = comm_recvfrompe(info, sizeof(*info), mlink, &from, timo);
+		if (n == sizeof(*info) && from == node &&
+			info->load.pe == node && info->serialno == serialno)
+			goto out;
+		before = time_since(before);
+		if(before < timo)
+		{
+			timo -= before;
+			tries++;
+		}
+		else
+			timo = info_retry;
+	}
+	error = -EAGAIN;
+out:
+	if (mlink)
+		comm_return_linkpool(mlink);
+	return (error);
+}
+
+int
+balance_get_info(int node, struct mosix_info *info)
+{
+	struct infomsg infomsg;
+	int error;
+
+	if (node == PE || node == 0) 		/* local info */
+	{
+		read_lock_bh(&loadinfo_lock);
+		infomsg.load = loadinfo[0];
+		read_unlock_bh(&loadinfo_lock);
+		infomsg.load.status = my_mosix_status();
+		infomsg.load.util = acpuse;
+#ifdef CONFIG_MOSIX_RESEARCH
+		infomsg.load.rio  = io_read_rate;
+ 		infomsg.load.wio  = io_write_rate;
+#endif /* CONFIG_MOSIX_RESEARCH */
+
+		load_to_mosix_info(infomsg.load, info, 0);
+	}
+	else if (!mos_to_net(node, NULL))
+		info->status = 0;
+	else if((error = balance_ask_node(node, &infomsg)))
+	{
+		info->status = DS_MOSIX_DEF;
+		return(error);
+	}
+	else
+		load_to_mosix_info(infomsg.load, info, 0);
+	return(0);
+}
+
+int
+balance_get_load(int node, struct loadinfo *l)
+{
+	struct infomsg infomsg;
+
+	if (node == PE || node == 0)
+	{
+		*l = loadinfo[0];
+		return(0);
+	}
+	else if (!mos_to_net(node, NULL))
+		return(-1);
+	else if(balance_ask_node(node, &infomsg))
+		return(-1);
+	*l = infomsg.load;
+	return(0);
+}
+
+static void
+inform()
+{
+	int to;
+	int i;
+	struct uplist *up;
+	struct infomsg info;
+
+	info.version = MOSIX_BALANCE_VERSION;
+	info.topology = MAX_MOSIX_TOPOLOGY;
+	info.serialno = 0;		/* meaning no serial number */
+	write_lock_bh(&loadinfo_lock);
+	loadinfo[0].free_slots = get_free_guest_slots();
+	info.load = loadinfo[0];
+	write_unlock_bh(&loadinfo_lock);
+	info.load.load = export_load;
+
+	/* first select any node, and send the load */
+	lock_mosix();
+	to = (NPE > 1) ? nth_node(rand(NPE-1, 1)) : 0;
+	unlock_mosix();
+	if(to && info_send_message(to, &info))
+		not_responding(to);
+
+	/* then select a node that seems to be up */
+	spin_lock(&uplist_lock);
+	if (info_nup)
+	{
+		for (up = uphead , i = rand(info_nup, 0) ; i-- ; up = up->next)
+			; /* just stop at random element */
+		to = (up->pe == to) ? 0 : up->pe;
+	}
+	else
+		to = 0;
+	spin_unlock(&uplist_lock);
+	if (to && info_send_message(to, &info))
+		not_responding(to);
+}
+
+void
+not_responding(int pe)
+{
+	int i;
+	struct uplist *up, *prev;
+
+	spin_lock(&uplist_lock);
+	prev = NULL;
+	for (up = uphead ; up ; prev = up , up = up->next)
+	if (up->pe == pe)
+	{
+		if (prev)
+			prev->next = up->next;
+		else
+			uphead = up->next;
+		up->next = upfree;
+		upfree = up;
+		info_nup--;
+		break;
+	}
+	spin_unlock(&uplist_lock);
+	write_lock_bh(&loadinfo_lock);
+	for (i = 1; i < INFO_WIN; i++)
+	if (loadinfo[i].pe == pe)
+		loadinfo[i].pe = 0;
+	write_unlock_bh(&loadinfo_lock);
+}
+
+void
+this_machine_is_favourite(int which)
+{
+	register struct uplist *up;
+
+	spin_lock(&uplist_lock);
+	for(up = uphead ; up ; up = up->next)
+		if(up->pe == which)
+			break;
+	if(!up && upfree)
+#ifdef CONFIG_MOSIX_CHEAT_MIGSELF
+	if(which != PE)
+#endif /* CONFIG_MOSIX_CHEAT_MIGSELF */
+	{
+		up = upfree;
+		upfree = upfree->next;
+		up->next = uphead;
+		up->pe = which;
+		up->age = 0;
+		uphead = up;
+		info_nup++;
+	}
+	spin_unlock(&uplist_lock);
+}
+
+static int
+rand(int modulo, int regen)
+{
+	if(regen)
+	{
+		info_seed2++;
+		/* alternating even/odd values: */
+		info_seed1 = info_seed1*info_seed2 + 1;
+		return((info_seed1 & 0x7fffffff) % modulo);
+	}
+	else
+		return((((info_seed2+1)*info_seed1+1) & 0x7fffffff) % modulo);
+}
+
+/*
+ * we are 99.99% going to migrate and let other processes be migrated,
+ * but not before we adjust the local and remote loads to discourage
+ * further migrations.
+ */
+void
+release_migrations(int whereto)
+{
+	register struct mosix_task *m = &current->mosix;
+	register int load, i;
+	int pages = m->migpages ? : count_migrating_pages();
+
+	this_machine_is_favourite(whereto);
+
+	/* Decrease the local load by the load caused by this process,
+	 * to avoid over-migration.
+	 */
+	write_lock_bh(&loadinfo_lock);
+	spin_lock_irq(&runqueue_lock);
+	load = m->load * STD_SPD / 4 / cpuspeed;
+	load /= smp_num_cpus;
+	  /* It is ON PURPOSE that `acpuse' is not taken into account */
+	if(loadinfo[0].load < load)   /* should not happen, but ... */
+		load = loadinfo[0].load;
+	load_left += load;
+	spin_unlock_irq(&runqueue_lock);
+
+	loadinfo[0].load -= load;
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_LOADS|DSDEB_CONSIDER))
+		printk("local load down by %d to %d due to leaving (to %d)\n",
+					load, (int)loadinfo[0].load, whereto);
+#endif
+
+	/* increase the receiver's-load */
+	for(i = 1 ; i < INFO_WIN ; i++)
+	if(loadinfo[i].pe == whereto)
+	{
+		/* add slightly more than 1 process worth of load */
+		loadinfo[i].load += MF * 102 * STD_SPD/
+			(loadinfo[i].speed * loadinfo[i].ncpus * 100);
+		loadinfo[i].mem -= pages;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(loadinfo[i].free_slots)
+			loadinfo[i].free_slots--;
+		if(ds_debug & (DSDEB_LOADS|DSDEB_CONSIDER))
+			printk("loadinfo[%d], pe=%d increased to %d due to "
+				"migration; mem decreased to %d\n",
+				i, whereto, (int)loadinfo[i].load,
+				(int)loadinfo[i].mem);
+#endif
+		break;
+	}
+	write_unlock_bh(&loadinfo_lock);
+#ifdef CONFIG_MOSIX_DEBUG
+	if((ds_debug & (DSDEB_LOADS|DSDEB_CONSIDER)) && i == INFO_WIN)
+		printk("release_migrations: Could not adjust machine #%d (not in list)\n", whereto);
+#endif /* CONFIG_MOSIX_DEBUG */
+	m->pages_i_bring = -pages; /* discourage 'memory_badly_required' */
+	unchoose_me();
+}
+
+void
+info_someone_came_in(void)
+{
+	write_lock_bh(&loadinfo_lock);
+	coming_in++;
+	came_lately4 += 4;
+	export_load += MF * STD_SPD / (smp_num_cpus * cpuspeed);
+	write_unlock_bh(&loadinfo_lock);
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_LOADS)
+		printk("someone_came_in: coming_in=%d, came_lately4=%d, export_load now %d\n",
+			coming_in, came_lately4, export_load);
+#endif
+}
+
+void
+end_coming_in(int error)
+{
+	write_lock_bh(&loadinfo_lock);
+	coming_in--;
+	if(error)
+	{
+		if((int)(came_lately4 -= 4) < 0)
+			came_lately4 = 0;
+	}
+	write_unlock_bh(&loadinfo_lock);
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_LOADS)
+		printk("end_coming_in: coming_in=%d, came_lately4=%d\n",
+			coming_in, came_lately4);
+#endif
+}
diff -ruN linux-2.4.16/mos/init.c linux-2.4.16-mosix/mos/init.c
--- linux-2.4.16/mos/init.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/init.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/mm.h>
+#include <linux/smp_lock.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <mos/version.h>
+#include <mos/balance.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+#define	STD_LOOPS	9961472  /* loops per jiffy on standard processor */
+
+void
+init_mosix(void)
+{
+	extern int x86_udelay_tsc;
+#ifdef CONFIG_MOSIX_UDB
+	extern void config_udb(void);
+
+	config_udb();
+#endif /* CONFIG_MOSIX_UDB */
+	cpuspeed = ((int64_t)loops_per_jiffy) * STD_SPD / STD_LOOPS;
+	if(!x86_udelay_tsc)
+		cpuspeed *= 2;
+	info_init();
+	proc_update_costs();
+#ifdef CONFIG_MOSIX_FS
+	init_mfs();
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_init();
+#endif /* CONFIG_MOSIX_DFSA */
+	kernel_thread(mosix_mig_daemon, NULL, 0);
+	info_startup();
+	mosix_load_init();
+	mosinfo_update_gateways();
+	kernel_thread(mosix_info_daemon, NULL, 0);
+	kernel_thread(mosix_mem_daemon, NULL, 0);
+}
diff -ruN linux-2.4.16/mos/kernel.c linux-2.4.16-mosix/mos/kernel.c
--- linux-2.4.16/mos/kernel.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/kernel.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1115 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/mosctl.h>
+#include <linux/mosix.h>
+#include <net/tcp.h>
+#include <mos/dscosts.h>
+#include <mos/mfscosts.h>
+#include <mos/protocol.h>
+#include <linux/mm.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/stddef.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/version.h>
+#include <mos/comm.h>
+#include <mos/balance.h>
+#include <mos/debug.h>
+#include <asm/ptrace.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+/************* some MOSIX global variables: *************/
+
+spinlock_t mosix_flag = SPIN_LOCK_UNLOCKED;
+spinlock_t whereto_lock = SPIN_LOCK_UNLOCKED;
+int active_cpus;
+int cpuspeed = STD_SPD;
+int standard_speed = STD_SPD;
+int mosix_running;
+struct task_struct *chosen_for_balance, *chosen_for_mdp;
+
+#ifdef CONFIG_MOSIX_DEBUG
+unsigned long ds_debug;		/* generic debug mask */
+#endif /* CONFIG_MOSIX_DEBUG */
+
+struct mosix_cost mosix_cost[MAX_MOSIX_TOPOLOGY] =
+{{
+	PAGE_COST_D, PAGE_COST_R,
+	SYSCALL_COST_D, SYSCALL_COST_R,
+	COPYOUT_COST_BASE_D, COPYOUT_COST_PER_KB_D,
+	COPYOUT_COST_BASE_R, COPYOUT_COST_PER_KB_R,
+	COPYIN_COST_BASE_D, COPYIN_COST_PER_KB_D,
+	COPYIN_COST_BASE_R, COPYIN_COST_PER_KB_R,
+	MIGRATION_COST_BASIC, MIGRATION_COST_PER_PAGE
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	, 0, 0
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+}};
+
+struct mfs_cost mfs_cost[MAX_MOSIX_TOPOLOGY] =
+{{
+	MFS_COST_CONN_S, MFS_COST_CONN_C,
+	MFS_COST_INKB_S, MFS_COST_INKB_C,
+	MFS_COST_OUTKB_S, MFS_COST_OUTKB_C,
+}};
+
+struct opcost deputy_here[MAX_MOSIX_TOPOLOGY];
+struct task_struct *info_proc;
+int info_daemon_active = 0;
+
+/**************************************************/
+
+int
+balpriority(int w)
+{
+        switch(w)
+        {
+                case MUSTGOHOME:
+                        return(7);
+                case GOBACKHOME:
+                        return(6);
+                default:
+                        return(5);
+		case MFSBALANCE:
+			return(4);
+                case IOBALANCE:
+                        return(3);
+                case MEMBALANCE:
+                        return(2);
+                case BALANCE:
+                        return(1);
+                case 0:
+                        return(0);
+        }
+        /*NOTREACHED*/
+}
+
+inline void
+mosix_do_add_to_whereto(struct task_struct *p, int w)
+{
+	if(balpriority(p->mosix.whereto) >= balpriority(w))
+		return;
+	p->mosix.whereto = w;
+	if(w != BALANCE && p == chosen_for_balance)
+	{
+		free_task_struct(p);
+		chosen_for_balance = NULL;
+	}
+	if(w != MEMBALANCE && p == chosen_for_mdp)
+	{
+		free_task_struct(p);
+		chosen_for_mdp = NULL;
+	}
+	if((p->mosix.dflags & (DREMOTE|DSENTURGENT)) != (DREMOTE|DSENTURGENT))
+		wake_up_mosix(p);
+}
+
+void
+mosix_add_to_whereto(struct task_struct *p, int w)
+{
+	spin_lock_irq(&whereto_lock);
+	mosix_do_add_to_whereto(p, w);
+	spin_unlock_irq(&whereto_lock);
+}
+
+/*
+ * must = 0: normal priority - if it fails, return.
+ * must = 1: high priority - but still return if it fails.
+ * must = 2: high priority and die (never return) on failure.
+ * otherwise, return 1 on success, 0 on failure.
+ * WARNING: do not call with "must==2" where resources were allocated.
+ */
+int
+mosix_go_home(int must)
+{
+	register struct task_struct *p = current;
+
+	if(p->mosix.dflags & DDEPUTY)
+	{
+		if(current->mosix.dflags & DINCOMING)
+			/* (eg. within do_mmap while migrating back) */
+			return(1);
+		passto(must ? MUSTGOHOME : GOBACKHOME, 0);
+	}
+	else if(p->mosix.dflags & DREMOTE)
+	{
+		remote_request(must ? REM_MUST_COME_HOME : REM_BRING_ME_HOME,
+			NULL, 0, NULL, 0, 0, NULL, 0);
+		/* should not return, but */
+	}
+	if(p->mosix.dflags & (DDEPUTY|DREMOTE))
+	{
+		printk("%s: Failed to Go Back Home.\n", desc_mostask(NULL));
+		if(must < 2)
+			return(0);
+		if(p->mosix.dflags & DDEPUTY)
+		{
+			printk("Process %s, uid=%d, killed because it failed to migrate back here\n",
+				desc_mostask(NULL), p->uid);
+			printk("(possible reasons are exhaustion of swap-space, or network disconnection)\n");
+			do_exit(SIGKILL);
+		}
+		else
+			remote_disappear();
+	}
+	return(1);
+}
+
+int
+mosix_go_home_for_reason(int must, int reason)
+{
+	struct task_struct *p = current;
+	int ret;
+
+	task_lock(p);
+	if((p->mosix.stay & reason) && (p->mosix.dflags & (DDEPUTY|DREMOTE)))
+		panic("mosix_go_home_for_reason - why not earlier?");
+	p->mosix.stay |= reason;
+	task_unlock(p);
+	if(!(ret = mosix_go_home(must)))
+	{
+		task_lock(p);
+		p->mosix.stay &= ~reason;
+		task_unlock(p);
+	}
+	return(ret);
+}
+
+int
+stay_me_and_my_clones(uint32_t reasons)
+{
+	struct task_struct *p, *me = current;
+	struct mm_struct *mm = me->mm;
+
+	if(me->mosix.dflags & DDEPUTY)
+		return(!mosix_go_home(1));	/* there are no clones! */
+	task_lock(me);
+	me->mosix.stay |= reasons;
+	task_unlock(me);
+	if(atomic_read(&mm->mm_realusers) > 1)
+	{
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if(p->mm == mm && p != me)
+		{
+			task_lock(p);
+			if(p->mm == mm)
+				p->mosix.stay |= reasons;
+			task_unlock(p);
+		}
+		read_unlock(&tasklist_lock);
+	}
+	return(0);
+}
+
+void
+unstay_mm(struct mm_struct *mm)
+{
+	struct task_struct *p;
+
+	if(atomic_read(&mm->mm_realusers) == 1 && mm == current->mm)
+	{
+		if(!(current->mosix.dflags & DREMOTE))
+			tell_process(current, DREQ_CHECKSTAY);
+		return;
+	}
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if(p->mm == mm)
+		tell_process(p, DREQ_CHECKSTAY);
+	read_unlock(&tasklist_lock);
+}
+
+int
+mosix_wakeable(struct task_struct *p)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	/* the following side-effect of this boolean function is allowed
+	 * because it is only called by "wake_up_mosix" and it is a good
+	 * practice to hide such MOSIX details from "wake_up_mosix".
+	 * note that we are already protected by runqueue_lock,
+	 * making DREMOTEDFSA, DINSCHED and DHEAVYSLEEP stable.
+	 */
+	if(p->mosix.dflags & DREMOTEDFSA)
+	{
+		tell_process(p, DREQ_EXITDFSA);
+		return(!(p->state & TASK_UNINTERRUPTIBLE) &&
+			!(p->mosix.dflags & (DINSCHED|DHEAVYSLEEP)));
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	if(p->mosix.dflags & (DINSCHED|DFAKESIGNAL|DHEAVYSLEEP|DFINISHED))
+		return(0);
+	if(p->state & TASK_UNINTERRUPTIBLE)
+		return(0);
+	if(p->mosix.dflags & DREMOTE)
+	{
+		if(!remote_need_while_asleep(p))
+			return(0);
+	}
+	return(1);
+}
+
+/*
+ * the following two boolean routines are very sensitive,
+ * it may not even lock the kernel or mosix, so if there is any need to do so,
+ * it must return 1.
+ */
+
+int
+remote_need_while_asleep(struct task_struct *p)
+{
+	/* if DREQ_CHECKCONF is set, we can't even call
+	 * "i_am_in_a_wrong_place()", since it uses locks
+	 */
+	return((process_told(p, DREQ_CHECKCONF) &&
+			p->mosix.whereto != MUSTGOHOME) ||
+		process_told(p, DREQ_EXITDFSA) ||
+		(URGENT_REMOTE_CONDITIONS(p) &&
+		!(p->mosix.dflags & (DSENTURGENT|DPASSING|DINCOMING))));
+}
+
+/*
+ * called from schedule() with the runqueue_lock locked.
+ */
+int
+mosix_need_while_asleep(void)
+{
+	register struct task_struct *p = current;
+	register struct mosix_task *m = &p->mosix;
+
+#ifdef CONFIG_MOSIX_DFSA
+	if((m->dflags & DREMOTEDFSA) && (process_told(p, DREQ_EXITDFSA)))
+	{
+		process_ack(p, DREQ_EXITDFSA);
+		spin_lock_irq(&p->sigmask_lock);
+		m->dflags |= DFAKESIGNAL;
+		if(!(m->dflags & DHEAVYSLEEP))
+		{
+			p->sigpending = 1;
+			set_current_state(TASK_RUNNING);
+		}
+		spin_unlock_irq(&p->sigmask_lock);
+		return(0);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	if(m->dflags & (DINSCHED|DFAKESIGNAL|DHEAVYSLEEP))
+		return(0);
+	if(m->dflags & DREMOTE)
+		return(remote_need_while_asleep(p));
+	if(m->dirty_bits & MMAP_MMDOWNED)
+		return(0);
+	if(m->prequest)
+		return(1);
+	if(process_told(p, (DREQ_NICECNG|DREQ_UPDOVERHEADS|DREQ_CHECKCONF|
+		DREQ_INFOCNG|DREQ_DFSASYNC|DREQ_CAPCNG|DREQ_CHECKSTAY|
+		DREQ_URGENT)))
+		return(1);
+	if(m->whereto)
+		return(1);
+	if((m->dflags & DDEPUTY) && (m->stay & DSTAY))
+		return(1);
+	return(0);
+}
+
+void
+remote_run_while_asleep(void)
+{
+	struct task_struct *p = current;
+
+	if(process_told(p, DREQ_CHECKCONF))
+	{
+		if(i_am_in_a_wrong_place())
+			mosix_add_to_whereto(current, MUSTGOHOME);
+		/* else DREQ_CHECKCONF is cleared */
+	}
+	if(URGENT_REMOTE_CONDITIONS(p) &&
+			!(p->mosix.dflags & (DSENTURGENT|DPASSING|DINCOMING)))
+		inform_deputy_of_urgent();
+}
+
+void
+deputy_run_while_asleep(void)
+{
+	register struct task_struct *p = current;
+
+	if(p->mosix.dflags & DSYNC)
+		deputy_async_requests();
+	else
+	{
+		p->mosix.dflags |= DFAKESIGNAL;
+		evaluate_pending_signals_in_mosix_context();
+	}
+}
+
+void
+mosix_run_while_asleep(void)
+{
+	register struct task_struct *p = current;
+	register struct mosix_task *m = &p->mosix;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!(m->dflags & DINSCHED))
+		panic("mosix_run_while_asleep: dflags=%x\n", m->dflags);
+#endif /* CONFIG_MOSIX_DIAG */
+	if(m->dflags & DREMOTE)
+	{
+		remote_run_while_asleep();
+		return;
+	}
+	scan:
+	if(m->dflags & DDEPUTY)
+	{
+		deputy_run_while_asleep();
+		if(mosix_need_while_asleep())
+			goto scan;
+		return;
+	}
+	/* LOCAL PROCESSES */
+	if(m->prequest)
+	{
+		process_requests();
+		goto scan;
+	}
+	process_ack(p, DREQ_NICECNG|DREQ_INFOCNG|DREQ_UPDOVERHEADS|DREQ_URGENT);
+	if(m->whereto)
+	{
+		follow_whereto();
+		goto scan;
+	}
+	if(process_told(p, DREQ_CHECKCONF))
+	{
+		done_checking_conf();
+		goto scan;
+	}
+	if(process_told(p, DREQ_CHECKSTAY))
+	{
+		if(p->mm)
+			down_read(&p->mm->mmap_sem);
+		mosix_check_for_freedom_to_move();
+		if(p->mm)
+			up_read(&p->mm->mmap_sem);
+		goto scan;
+	}
+	if(process_told(p, DREQ_CAPCNG))
+	{
+		sync_caps();
+		goto scan;
+	}
+#ifdef CONFIG_MOSIX_DFSA
+	if(process_told(p, DREQ_DFSASYNC))
+	{
+		clear_dfsasync();
+		goto scan;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+}
+
+int
+remote_pre_usermode_actions(void)
+{
+	struct task_struct *p = current;
+	struct mosix_task *m = &p->mosix;
+	int i, nfsigs;
+	siginfo_t *fsigs;
+
+	loop:
+	do_decay();
+	if(remote_deputy_has_something_for_us(p))
+	{
+		wait_for_permission_to_continue();
+		goto loop;
+	}
+	if(process_told(p, DREQ_CHECKCONF) && i_am_in_a_wrong_place())
+		mosix_add_to_whereto(p, MUSTGOHOME);
+	if(URGENT_REMOTE_CONDITIONS(p) && !(m->dflags & DSENTURGENT))
+	{
+		inform_deputy_of_urgent();
+		goto loop;
+	}
+	if(m->asig || m->nforced_sigs)
+	{
+		spin_lock_irq(&p->sigmask_lock);
+		i = m->asig;
+		m->asig = 0;
+		fsigs = m->forced_sigs;
+		nfsigs = m->nforced_sigs;
+		m->forced_sigs = NULL;
+		m->nforced_sigs = 0;
+		spin_unlock_irq(&p->sigmask_lock);
+		transfer_signals_to_deputy((unsigned int) i, fsigs, nfsigs);
+		if(fsigs)
+			kfree(fsigs);
+		goto loop;
+	}
+	return(0);
+}
+
+int
+local_pre_usermode_actions(void)
+{
+	struct task_struct *p = current;
+	int any = 0;
+
+	while(1)
+	{
+		do_decay();
+		if(p->mosix.whereto)
+		{
+			follow_whereto();
+			any = 1;
+			if(p->mosix.dflags & DDEPUTY)
+				return(1);
+			continue;
+		}
+		if(process_told(p, DREQ_CHECKCONF))
+		{
+			done_checking_conf();
+			any = 1;
+			continue;
+		}
+		if(process_told(p, DREQ_CAPCNG))
+		{
+			sync_caps();
+			any = 1;
+			continue;
+		}
+#ifdef CONFIG_MOSIX_DFSA
+		if(process_told(p, DREQ_DFSASYNC))
+		{
+			clear_dfsasync();
+			any = 1;
+			continue;
+		}
+#endif /* CONFIG_MOSIX_DFSA */
+		if(process_told(p, DREQ_CHECKSTAY))
+		{
+			down_read(&p->mm->mmap_sem);
+			mosix_check_for_freedom_to_move();
+			up_read(&p->mm->mmap_sem);
+			any = 1;
+			continue;
+		}
+		process_ack(p, DREQ_NICECNG|DREQ_INFOCNG|DREQ_UPDOVERHEADS|
+								DREQ_URGENT);
+		return(any);
+	}
+}
+
+int
+mosix_pre_usermode_actions(struct pt_regs regs)
+{
+	register struct task_struct *p = current;
+	int any = 0;
+
+	if((regs.xcs & 3) != 3)	/* going back to kernel -- not to user mode */
+		return(0);
+	__sti();		/* could be called after an interrupt */
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.altregs != (uint32_t *)&regs)
+	{
+		task_lock(current);
+		current->mosix.altregs = (uint32_t *)&regs;
+		task_unlock(current);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+
+	if(p->mosix.dflags & DREMOTE)
+		return(remote_pre_usermode_actions());
+
+	while(1)
+	{
+		if(p->mosix.dflags & DDEPUTY)
+		{
+			deputy_main_loop();
+			p = current;	/* fork? */
+			any = 1;
+			continue;
+		}
+		if(local_pre_usermode_actions())
+		{
+			any = 1;
+			continue;
+		}
+		if(p->mosix.prequest)
+		{
+			process_requests();
+			any = 1;
+			continue;
+		}
+		return(any);
+	}
+}
+
+int
+mosix_fork_init_fields(struct task_struct *p)
+{
+	struct mosix_task *m = &p->mosix;
+	struct task_struct *parent = current;
+
+#ifdef CONFIG_MOSIX_DFSA
+	tell_process(parent, DREQ_NOTUPTODATE);
+	tell_process(p, DREQ_NOTUPTODATE);
+	if(parent->mosix.dflags & (DREMOTEDAEMON|DREMOTE))
+		dfsa_tinit();
+	m->ttab = NULL;
+#endif /* CONFIG_MOSIX_DFSA */
+	if(!(parent->mosix.dflags & DDEPUTY))
+		tell_process(p, DREQ_CHECKSTAY);
+	m->dflags = parent->mosix.dflags & ~(DREMOTEDAEMON|DSENTURGENT);
+	process_ack(p, DREQ_HOMEWAKE|DREQ_URGENT);
+	m->commpri = 0;
+	if(parent->mosix.dflags & DREMOTEDAEMON)
+	{
+		m->dflags |= DREMOTE|DHEAVYSLEEP;
+		m->hsleep_count = 1;
+	}
+	else if(parent->mosix.dflags & DREMOTE)
+		sprintf(p->comm, "remote(%d)", m->mypid = m->sonpid);
+	if(parent->mosix.dflags & DDEPUTY)
+		m->dflags &= ~(DDEPUTY|DSYNC);
+	if(!(parent->mosix.dpolicy & DADV_INHERIT))
+	{
+		m->dpolicy = DADV_DEFAULT;
+#if DADV_DEFAULT == DADV_OWNDECAY
+		m->decay = DECAY_QUOTIENT;
+		m->deccycle = DEFAULT_DECAY_INTERVAL;
+#endif
+	}
+	if(p->pid == 1)
+		m->stay |= DSTAY_ITS_INIT;
+	else
+		m->stay &= ~DSTAY_ITS_INIT;
+	m->held_files = NULL;
+	m->held_allocated = 0;
+	rwlock_init(&m->state_lock);
+	m->contact = 0;
+	m->ucache = NULL;
+	m->prequest = NULL;
+	if(parent->mm == &init_mm || !parent->mm ||
+		(parent->mosix.dflags & DDEPUTY) ||
+		(parent->mosix.stay & DSTAY_ITS_DAEMON))
+		m->ancesstor = NULL;
+	else
+		m->ancesstor = parent;
+	m->last_sigxcpu = 0;
+	m->deputytime = 0;
+	m->passedtime = 0;
+	m->uttime = 0;
+	m->dctime = 0;
+	m->ndemandpages = 0;
+	m->nsyscalls = 0;
+	m->ncopyouts = 0;
+	m->copyoutbytes = 0;
+	m->ncopyins = 0;
+	m->copyinbytes = 0;
+	m->iocounter = 0;
+	m->cutime = 0;
+	m->last_consider = 0;
+	m->last_mconsider = 0;
+	m->decsecs = 0;
+	memset((caddr_t)&m->asig, 0, sizeof(m->asig));
+	m->forced_sigs = 0;
+	m->nforced_sigs = 0;
+	m->pages_i_bring = 0;
+	m->page_allocs = 0;
+	m->ran = 0;
+	m->runstart = 0;
+	m->load = 0;
+	m->inexec = NULL;
+	m->nmigs = 0;
+	m->pass_regs = 0;
+	init_waitqueue_head(mos_to_waitp(m));
+	m->mosix_log = NULL;
+	init_mosix_log(p);
+	m->dirty_bits = 0;
+#ifdef CONFIG_MOSIX_FS
+	m->mfs_stats = NULL;
+#endif /* CONFIG_MOSIX_FS */
+	return(fork_mosix_remote_files(p));
+}
+
+void
+mosix_fork_free_fields(struct task_struct *p)
+{
+	if(p->mosix.dflags & DDEPUTY)
+		undeputy(p);
+	clear_mosix_log(p);
+}
+
+void
+mosix_exit(void)
+{
+	struct task_struct *p = current;
+	struct mosix_task *m = &p->mosix;
+	int i;
+	struct linux_binprm *bprm = m->inexec;
+
+	lock_mosix();
+	write_lock_irq(&tasklist_lock);
+	spin_lock(&runqueue_lock);
+	m->dflags |= DFINISHED;
+	m->bstate = TASK_SAME;/* we are not going back to original sleep/stop */
+	spin_unlock(&runqueue_lock);
+	write_unlock_irq(&tasklist_lock);
+	unlock_mosix();
+	m->pages_i_bring = 0;
+	unchoose_me();
+	free_ucache();
+	if(m->dflags & DDEPUTY)
+		mosix_deputy_rusage(1); /* (includes setting "m->exit_mem") */
+	if(m->dflags & DREMOTE)
+		expel_progress = 1;
+	if(m->dflags & (DDEPUTY|DREMOTE))
+		comm_close(NULL); /* for a DEPUTY, this will kill our REMOTE */
+	if(m->dflags & DDEPUTY)
+		undeputy(p);
+	clear_mosix_log(p);
+	if(process_told(p, DREQ_CHECKCONF))
+		done_checking_conf();
+#ifdef CONFIG_MOSIX_DFSA
+	dfsa_exit();
+#endif /* CONFIG_MOSIX_DFSA */
+	if(bprm)
+	{
+		for(i = 0 ; i < MAX_ARG_PAGES ; i++)
+		if(bprm->page[i])
+			__free_page(bprm->page[i]);
+		if(m->dflags & DREMOTE)
+			kfree(bprm);
+	}
+	if(m->prequest)
+		discard_requests();
+}
+
+void
+mosix_very_exit(void)
+{
+	struct task_struct *p = current, *a;
+	struct mosix_task *m = &p->mosix;
+	struct task_struct *q;
+#ifdef CONFIG_MOSIX_FS
+	struct mfs_stats *mfst;
+#endif /* CONFIG_MOSIX_FS */
+
+#ifdef CONFIG_MOSIX_FS
+	lock_mosix();
+	mfst = m->mfs_stats;
+	m->mfs_stats = NULL;
+	unlock_mosix();
+	if(mfst)
+		kfree(mfst);
+#endif /* CONFIG_MOSIX_FS */
+	read_lock(&tasklist_lock);
+	if((a = m->ancesstor))
+		get_task_struct(a);
+	for_each_task(q)
+	if(q->mosix.ancesstor == p)
+		q->mosix.ancesstor = a;
+	read_unlock(&tasklist_lock);
+	if(a)
+	{
+		add_statistics_to_ancesstor(p, a);
+		free_task_struct(a);
+	}
+	if(m->forced_sigs)
+	{
+		kfree(m->forced_sigs);
+		m->nforced_sigs = 0;
+	}
+}
+
+void
+mosix_obtain_registers(unsigned long mask)
+{
+	register struct mosix_task *m = &current->mosix;
+	unsigned int bringme;
+
+	if(mask & ~ALL_REGISTERS)
+		panic("mosix_obtain_registers, mask=0x%x", (int)mask);
+	if(m->dflags & DDEPUTY)
+	{
+		if((bringme = mask & ~m->deputy_regs))
+		{
+			if(deputy_request(DEP_BRING_ME_REGS, &bringme,
+				sizeof(bringme), NULL, 0, 0, NULL, 0))
+				deputy_communication_failed();
+			else if((m->deputy_regs & mask) != mask)
+			{
+#ifdef CONFIG_MOSIX_DIAG
+				printk("%s: Asked for regs(%x), but has only %x\n",
+					desc_mostask(NULL),
+					(int)mask, m->deputy_regs);
+#endif /* CONFIG_MOSIX_DIAG */
+				send_sig(SIGKILL, current, 1);
+			}
+		}
+	}
+	else if(m->dflags & DREMOTE)
+	{
+		if((bringme = mask & m->deputy_regs))
+		{
+			if(remote_request(REM_BRING_ME_REGS, &bringme,
+				sizeof(bringme), NULL, 0, 0, NULL, 0))
+				send_sig(SIGKILL, current, 1);
+			else if((~m->deputy_regs & mask) != mask)
+			{
+#ifdef CONFIG_MOSIX_DIAG
+				printk("%s: Asked for regs(%x), but has only %x\n",
+					desc_mostask(NULL), (int)mask,
+					ALL_REGISTERS & ~m->deputy_regs);
+#endif /* CONFIG_MOSIX_DIAG */
+				send_sig(SIGKILL, current, 1);
+				mosix_panic("remote-regs");
+			}
+		}
+	}
+}
+
+unsigned int
+which_regs_to_send()
+{
+	register struct mosix_task *m = &current->mosix;
+
+	if(!m->pass_regs)
+		return(0);
+	return(m->pass_regs &
+		((m->dflags & DDEPUTY) ? m->deputy_regs : ~m->deputy_regs));
+}
+
+void
+regs_were_sent(void)
+{
+	register struct mosix_task *m = &current->mosix;
+
+	if(m->dflags & DDEPUTY)
+		m->deputy_regs &= ~m->pass_regs;
+	else
+		m->deputy_regs |= m->pass_regs; 
+	m->pass_regs = 0;
+}
+
+void
+mosix_bring_monkey_users_back(struct inode *ip)
+{
+	register struct task_struct *p, *found, *me = current;
+	DECLARE_WAITQUEUE(wait, me);
+
+	while(1)
+	{
+		found = NULL;
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if(p != me && !(p->mosix.dflags & DREMOTE) &&
+			task_maps_ip(p, ip))
+		{
+			task_lock(p);
+			p->mosix.stay |= DSTAY_FOR_MONKEY;
+			task_unlock(p);
+			if(p->mosix.dflags & DDEPUTY)
+			{
+				tell_process(p, DREQ_HOMEWAKE);
+				wake_up_mosix(p);
+				if(!found)
+				{
+					found = p;
+					get_task_struct(p);
+				}
+			}
+		}
+		if(!found)
+		{
+			read_unlock(&tasklist_lock);
+			/* VMODIFIED is needed against a nearly-impossible
+			 * REMOTE race, when ip is modified, then unmonkied
+			 * and a process migrates there even before the
+			 * previous completed exiting:
+			 */
+			VMODIFIED(ip);
+			return;
+		}
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		add_wait_queue(mos_to_waitp(&found->mosix), &wait);
+		read_unlock(&tasklist_lock);
+		schedule();
+		remove_wait_queue(mos_to_waitp(&found->mosix), &wait);
+		set_current_state(TASK_RUNNING);
+		free_task_struct(found);
+	}
+}
+
+void
+mosix_no_longer_monkey(struct inode *ip)
+{
+	register struct task_struct *p;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if(!(p->mosix.dflags & (DREMOTE|DDEPUTY)) && task_maps_ip(p, ip))
+	{
+		tell_process(p, DREQ_CHECKSTAY);
+		wake_up_mosix(p);
+	}
+	read_unlock(&tasklist_lock);
+}
+
+/*
+ * caller is responsible to down_[read|write](&current->mm->mmap_sem)
+ * (unless deemed unnecessary - as in "exec" or after migrating back,
+ * when we are sure to have no clones.
+ */
+void
+mosix_check_for_freedom_to_move(void)
+{
+	struct task_struct *p = current;
+	register struct vm_area_struct *mpnt;
+	register struct inode *ip;
+	int stay;
+	struct mm_struct *mm;
+
+	if(p->mosix.dflags & DDEPUTY)
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		if(p->mosix.stay & (DSTAY & ~(DSTAY_FOR_MONKEY|DSTAY_FOR_RT)))
+			panic("DEPUTY with STAY");
+#endif /* CONFIG_MOSIX_DIAG */
+		return;
+	}
+	process_ack(p, DREQ_CHECKSTAY);
+	if(!(p->mosix.stay & (DSTAY_PER_MM|DSTAY_FOR_CLONE)))
+		return;
+	task_lock(p);
+	stay = p->mosix.stay & ~(DSTAY_PER_MM|DSTAY_FOR_CLONE);
+	if(!(mm = current->mm))
+		stay |= DSTAY_FOR_CLONE;
+	else
+	{
+		if(atomic_read(&mm->mm_kiocount))
+			stay |= DSTAY_FOR_KIOBUF;
+		if(atomic_read(&mm->mm_realusers) > 1)
+			stay |= DSTAY_FOR_CLONE;
+		if(mm->def_flags & VM_LOCKED)
+			stay |= DSTAY_FOR_MLOCK;
+		for(mpnt = mm->mmap ; mpnt ; mpnt = mpnt->vm_next)
+		{
+			if(mpnt->vm_file)
+			{
+				mode_t mode;
+
+				ip = mpnt->vm_file->f_dentry->d_inode;
+				mode = ip->i_mode;
+				if(ip->i_mapping->i_mmap_shared)
+					stay |= DSTAY_FOR_MONKEY;
+				if(S_ISCHR(mode) || S_ISFIFO(mode) ||
+								S_ISSOCK(mode))
+					stay |= DSTAY_FOR_DEV;
+			}
+			if(mpnt->vm_flags & VM_LOCKED)
+				stay |= DSTAY_FOR_MLOCK;
+		}
+	}
+	p->mosix.stay = stay;
+	task_unlock(p);
+}
+
+/*
+ * caller must use 'get_task_struct(p)'
+ */
+int
+mosix_send_back_home(struct task_struct *p)
+{
+	struct task_struct *me = current;
+	int timeout = 20 * HZ;
+	DECLARE_WAITQUEUE(wait, me);
+
+	if(p == me)
+		return(mosix_go_home(1) ? 0 : -ENOMEM);
+
+	/* there is a paranoidic possibility of a tricky deadlock: if two
+	 * (or more) remote processes send each other home simultaneously:
+	 * we want to sleep interruptibly, so we can migrate, but no signals
+	 * should stop us - unless the other process failed to migrate for a
+	 * very long time.  e.g. we are to give up only with the combination
+	 * of a signal + timeout.
+	 */
+	add_wait_queue(mos_to_waitp(&p->mosix), &wait);
+	while(p->mosix.dflags & DDEPUTY)
+	{
+		tell_process(p, DREQ_HOMEWAKE);
+		mosix_add_to_whereto(p, MUSTGOHOME);
+		spin_lock_irq(&me->sigmask_lock);
+		me->mosix.ignoreoldsigs = 1;
+		me->sigpending = 0;
+		spin_unlock_irq(&me->sigmask_lock);
+		set_current_state(TASK_INTERRUPTIBLE);
+		task_lock(p);
+		if(!(p->mosix.dflags & DDEPUTY))
+			set_current_state(TASK_RUNNING);
+		task_unlock(p);
+		timeout = schedule_timeout(timeout);
+		if(timeout <= 0)
+		{
+			spin_lock_irq(&me->sigmask_lock);
+			recalc_sigpending(me);
+			spin_unlock_irq(&me->sigmask_lock);
+			if(signal_pending(current))
+			{
+				remove_wait_queue(mos_to_waitp(&p->mosix),
+									&wait);
+				free_task_struct(p);
+				return(-EINTR);
+			}
+			timeout = HZ;
+		}
+	}
+	set_current_state(TASK_RUNNING);
+	remove_wait_queue(mos_to_waitp(&p->mosix), &wait);
+	spin_lock_irq(&me->sigmask_lock);
+	recalc_sigpending(me);
+	spin_unlock_irq(&me->sigmask_lock);
+	return(0);
+}
+
+void
+mosix_pre_dropping_mm(struct task_struct *myself, struct mm_struct *mm)
+{
+	register struct task_struct *p;
+
+	if(!mm)
+		return;
+	atomic_dec(&mm->mm_realusers);
+	if(atomic_read(&mm->mm_realusers) == 1)
+	{
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if(p != myself && p->mm == mm)
+		{
+			tell_process(p, DREQ_CHECKSTAY);
+			break;
+		}
+		read_unlock(&tasklist_lock);
+	}
+}
+
+void
+mosix_exit_mm(struct task_struct *p)
+{
+	if((p->mosix.dflags & (DPASSING|DREMOTE)) == DPASSING)
+		return;
+	if(p->mosix.held_files)
+		mosix_clear_all_held_files(p);
+	if(!(p->mosix.dflags & DDEPUTY))
+		mosix_pre_dropping_mm(p, p->mm);
+	task_lock(p);
+	p->mosix.stay = (p->mosix.stay | DSTAY_FOR_CLONE) & ~DSTAY_PER_MM;
+	task_unlock(p);
+	p->mosix.pages_i_bring = 0;
+}
+
+void
+mosix_exec_mmap(struct mm_struct *old_mm)
+{
+	struct task_struct *p = current;
+
+	if(p->mosix.dflags & DDEPUTY)
+		return;
+		
+	mosix_pre_dropping_mm(p, old_mm);
+	task_lock(p);
+	p->mosix.stay &= ~(DSTAY_PER_MM|DSTAY_FOR_CLONE);
+	task_unlock(p);
+	p->mosix.pages_i_bring = 0;
+	if(p->mosix.held_files)
+		mosix_clear_all_held_files(p);
+}
+
+int
+mosix_pre_clone(void)
+{
+	struct task_struct *p = current;
+
+	if(!mosix_go_home(0))
+		return(-ENOMEM);
+	
+	/* prevent race with "mosix_pre_dropping_mm" */
+	if(p->mm)
+		atomic_inc(&p->mm->mm_realusers);
+	read_lock(&tasklist_lock);
+	task_lock(p);
+	p->mosix.stay |= DSTAY_FOR_CLONE;
+	task_unlock(p);
+	read_unlock(&tasklist_lock);
+	return(0);
+}
+
+void
+mosix_post_clone(void)
+{
+	struct task_struct *p = current;
+	struct mm_struct *mm = p->mm;
+
+	if(mm)
+	{
+		atomic_dec(&mm->mm_realusers);
+		read_lock(&tasklist_lock);
+		if(atomic_read(&mm->mm_realusers) == 1)
+		{
+			task_lock(p);
+			p->mosix.stay &= ~DSTAY_FOR_CLONE;
+			task_unlock(p);
+		}
+		read_unlock(&tasklist_lock);
+	}
+}
+
+/* 'run_on' and 'run_off' must be called with the runqueue_lock! */
+void
+run_on(struct task_struct *p)
+{
+	if(!(p->mosix.dflags & DPAGEIN))
+	{
+		mosix_running++;
+		p->mosix.runstart = load_ticks + 1;
+	}
+}
+
+void
+run_off(struct task_struct *p)
+{
+	if(!(p->mosix.dflags & DPAGEIN))
+	{
+		mosix_running--;
+		p->mosix.ran += load_ticks + 1 - p->mosix.runstart;
+		p->mosix.runstart = 0;
+	}
+}
+
+void
+down_half_interruptible(struct semaphore *sem)
+{
+	struct task_struct *p = current;
+
+	do
+	{
+		spin_lock_irq(&p->sigmask_lock);
+		p->mosix.ignoreoldsigs = 1;
+		p->sigpending = 0;
+		spin_unlock_irq(&p->sigmask_lock);
+	}
+	while(down_interruptible(sem) == -EINTR);
+	recalc_sigpending(p);
+}
diff -ruN linux-2.4.16/mos/load.c linux-2.4.16-mosix/mos/load.c
--- linux-2.4.16/mos/load.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/load.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Amnon Barak.
+ */
+#include <linux/sched.h>
+#include <linux/mosctl.h>
+#include <net/sock.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <mos/protocol.h>
+#include <linux/mosix.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/swap.h>
+#include <linux/stddef.h>
+#include <mos/balance.h>
+#include <linux/kernel_stat.h>
+
+#define VV1     5
+#define VV2     8
+#define DECAY   VV1/VV2         /* decay of load */
+#define NEWDATA (VV2-VV1)/VV2   /* weight of new load data */
+
+unsigned load_adder;    /* accumulator of `running' every clock tick */
+unsigned load_ticks;    /* # of ticks included in load_adder */
+unsigned cpuse;         /* # of ticks when CPU was not thrashing */
+unsigned acpuse = MF;   /* long term non-trashing (start value = non-0) */
+unsigned coming_in;     /* number of arriving processes */
+unsigned came_lately4;  /* processes that arrived lately (*4) */
+unsigned load_left;     /* load of processes that just left */
+
+int export_load;	/* load reported to other processors */
+int stable_export;	/* machine dependent stabilizing factor */
+
+int Tvis;
+int Tload;
+
+#ifdef CONFIG_MOSIX_RESEARCH
+unsigned int io_read_rate;
+unsigned int io_write_rate;
+unsigned int old_io_read;
+unsigned int old_io_write;
+#endif /* CONFIG_MOSIX_RESEARCH */
+
+
+void
+mosix_calc_load(unsigned long unused)
+{
+	struct task_struct *p;
+	register struct mosix_task *m;
+	register int ladd, cpu, ticks;
+	unsigned long flags;
+	unsigned long newload;
+	int new_expload;
+	unsigned new_cpuse;
+	unsigned new_came;
+	static unsigned upper_load;    /* over estimated load */
+	static unsigned accload;       /* accumulated load (*128) */
+	static int display_counter = 0;
+#ifdef CONFIG_MOSIX_RESEARCH
+	unsigned int new_io_read;
+	unsigned int new_io_write;
+	int major,disk;
+#endif /* CONFIG_MOSIX_RESEARCH */
+
+
+	ticks = load_ticks;
+	cpu = cpuse;
+	ladd = load_adder;
+	cpuse = load_adder = load_ticks = 0;
+
+	ladd = ladd * ((long long)(MF * STD_SPD)) /
+		(ticks * cpuspeed * smp_num_cpus);
+	if(ladd * 128 > accload)	/* slowly up */
+		accload = accload * DECAY + ladd * 128 * NEWDATA;
+	else				/* quickly down */
+		accload = ladd * 128;
+	if(ladd >= upper_load)		/* quickly up */
+		upper_load = ladd;
+	else				/* very slowly down */
+		upper_load = (upper_load * 7 + ladd) / 8;
+	new_cpuse = (acpuse * 3 + cpu * MF / ticks + 3) / 4;
+	newload = (accload+64) / 128;
+	new_expload = (upper_load + stable_export +
+		came_lately4 * MF * STD_SPD /
+			(4 * cpuspeed * smp_num_cpus)) *
+			MF * smp_num_cpus / new_cpuse;
+	if(newload < load_left)
+		newload = 0;
+	else
+		newload -= load_left;
+	newload = newload * MF * smp_num_cpus / new_cpuse;
+	new_came = came_lately4 * DECAY + coming_in * 4 * NEWDATA;
+	spin_lock_irqsave(&runqueue_lock, flags);
+	for_each_task(p)
+	{
+		m = &p->mosix;
+		if(m->runstart)
+		{
+			m->ran += ticks + 1 - m->runstart;
+			m->runstart = 1;
+		}
+		m->load = m->load * DECAY + m->ran * MF * 4*NEWDATA/ticks;
+		m->ran = 0;
+		m->page_allocs >>= 1;	/* decay in time */
+	}
+	spin_unlock_irqrestore(&runqueue_lock, flags);
+
+	if(Tvis)
+		printk("\0337\033[22;55HL=%d,E=%d,R=%d,U=%d  \0338",
+			(int)newload, new_expload, mosix_running,
+			new_cpuse);
+	if(Tload) {
+		if (!(display_counter = (display_counter + 1) & 0xf))
+			printk("\naccload upper_load\tload_adder\tload_ticks\n");
+		printk("%7d\t%10d\t%10d\t%d\n",
+			accload, upper_load, ladd, ticks);
+	}
+	write_lock(&loadinfo_lock);
+	loadinfo[0].load = newload;
+	export_load = new_expload;
+	acpuse = new_cpuse;
+	came_lately4 = new_came;
+	load_left = 0;
+
+#ifdef CONFIG_MOSIX_RESEARCH
+        new_io_read = new_io_write = 0;
+        for (major = 0; major < DK_MAX_MAJOR; major++) {
+                for (disk = 0; disk < DK_MAX_DISK; disk++) {
+			new_io_read += kstat.dk_drive_rblk[major][disk];                                new_io_write += kstat.dk_drive_wblk[major][disk];
+	}
+        }      
+
+        /* the sectors are 512 bytes size */
+	
+        new_io_read = new_io_read >> 1;
+        new_io_write = new_io_write >> 1;
+        io_read_rate  = (new_io_read - old_io_read);
+        io_write_rate = (new_io_write - old_io_write);
+        old_io_read  = new_io_read;
+        old_io_write = new_io_write;
+#endif /* CONFIG_MOSIX_RESEARCH */
+
+	write_unlock(&loadinfo_lock);
+
+	if((p = (struct task_struct *)info_proc))
+		send_sig(SIGALRM, p, 1);
+}
+
+void
+mosix_load_init(void)
+{
+	acpuse = MF * smp_num_cpus;
+	load_ticks = MF;	/* fake it to begin with (must be non-zero) */
+	cpuse = MF * smp_num_cpus;
+	load_adder = mosix_running * MF;
+	mosix_calc_load(0);
+#ifdef CONFIG_MOSIX_RESEARCH
+	io_read_rate = io_write_rate = old_io_read = old_io_write = 0;
+#endif /* CONFIG_MOSIX_RESEARCH */
+}
+
+void
+mosix_snap_load(int ticks)
+{
+	unsigned long flags;
+	extern struct list_head runqueue_head;
+
+	load_adder += mosix_running;
+	if(mosix_running <= active_cpus)
+		cpuse += ticks * smp_num_cpus;
+	else
+	{
+		/* a possible race between the time of making a process runable
+		 * and actual picking up by a processor: so count runable
+		 * processes as if already occupying a processor:
+		 */
+		int n;
+		register struct task_struct *p;
+		struct list_head *tmp;
+
+		spin_lock_irqsave(&runqueue_lock, flags);
+		if((n = active_cpus) < smp_num_cpus)
+		for(tmp = runqueue_head.next ; tmp != &runqueue_head ;
+								tmp = tmp->next)
+		{
+			p = list_entry(tmp, struct task_struct, run_list);
+			if(p->mosix.runstart && ++n == smp_num_cpus)
+				break;
+		}
+		spin_unlock_irqrestore(&runqueue_lock, flags);
+		cpuse += ticks * n;
+	}
+	load_ticks += ticks;
+	if(load_ticks >= MF)
+		mosix_calc_load(0);
+}
diff -ruN linux-2.4.16/mos/log.c linux-2.4.16-mosix/mos/log.c
--- linux-2.4.16/mos/log.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/log.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan.
+ */
+#include <linux/sched.h>
+#include <mos/routines.h>
+#include <mos/log.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+#ifdef CONFIG_MOSIX_DEBUG
+spinlock_t mosixlog_lock = SPIN_LOCK_UNLOCKED;
+
+static char *log_type_str[] = {
+	"nothing",
+	"SENDTYPE",
+	"RECVTYPE",
+	"RECEIVE",
+	"SENDHDR",
+	"RECVHDR",
+	"SENDDATA",
+	"RECVDATA",
+	"SENDURG",
+	"RECVURG",
+	"RETVAL"
+};
+
+int log_mask = 0x1ff;	/* for now: only 32 bits. default: first 9 bits */
+
+
+void
+init_mosix_log(struct task_struct *p)
+{
+	int *log;
+
+	if(!p->mosix.mosix_log && (log =
+		(int *)kmalloc((MOSIX_LOG_LEN+1) * sizeof(int), GFP_KERNEL)))
+	{
+		memset(log, 0, sizeof(int) * (MOSIX_LOG_LEN + 1));
+		MOSIX_LOG_POS(log) = 0;
+		spin_lock_irq(&mosixlog_lock);
+		p->mosix.mosix_log = (void *)log;
+		spin_unlock_irq(&mosixlog_lock);
+	}
+}
+
+
+void
+clear_mosix_log(struct task_struct *p)
+{
+	void *log;
+
+	if ((log = (void *)p->mosix.mosix_log))
+	{
+		spin_lock_irq(&mosixlog_lock);
+		p->mosix.mosix_log = NULL;
+		spin_unlock_irq(&mosixlog_lock);
+		kfree(log);
+	}
+}
+
+
+void
+add_mosix_log(struct task_struct *p, int type, int val)
+{
+	int *log;
+	unsigned long flags;
+
+	spin_lock_irqsave(&mosixlog_lock, flags);
+	if(p && (log = (int *)p->mosix.mosix_log) &&
+		((1 << (type - 1)) & log_mask))
+	{
+		log[MOSIX_LOG_POS(log)] = (val & 0x00ffffff) | (type << 24);
+		if (++MOSIX_LOG_POS(log) == MOSIX_LOG_LEN)
+			MOSIX_LOG_POS(log) = 0;
+	}
+	spin_unlock_irqrestore(&mosixlog_lock, flags);
+}
+
+void
+dump_mosix_log(struct task_struct *p)
+{
+	int i, n;
+	int *log;
+	int type, val;
+
+	if (!p)
+		p = current;
+	else if(((unsigned int)p) < 65536)
+		p = find_any_task_by_pid((int)p);
+	if (!p)
+		return;
+
+	log = p->mosix.mosix_log;
+	if(!log)
+	{
+		printk("No MOSIX log for %s\n", desc_mostask(&p->mosix));
+		return;
+	}
+	n = MOSIX_LOG_POS(log);
+	printk("MOSIX event log for %s:\n", desc_mostask(&p->mosix));
+	for (i = (n+1)%MOSIX_LOG_LEN; i != n; i = (i+1)%MOSIX_LOG_LEN) {
+		type = log[i] >> 24;
+		val = log[i] & 0x00ffffff;
+		if (type < sizeof(log_type_str) / sizeof(char *))
+			printk("%s:   ", log_type_str[type]);
+		else
+			printk("????(%d):   ", type);
+		switch (type) {
+		case MOSIX_LOG_SENDTYPE:
+		case MOSIX_LOG_RECVTYPE:
+			printk("type of %s msg: 0x%x\n",
+				(type == MOSIX_LOG_SENDTYPE ? "SEND" : "RECV"),
+				val);
+			break;
+		case MOSIX_LOG_RECEIVE:
+			break;
+		case MOSIX_LOG_SENDHDR:
+		case MOSIX_LOG_RECVHDR:
+			printk("%s header size:  hlen = %d  olen = %d\n",
+				(type == MOSIX_LOG_SENDHDR ? "SEND" : "RECV"),
+				val & 0xffff, val >> 16);
+			break;
+		case MOSIX_LOG_SENDDATA:
+		case MOSIX_LOG_RECVDATA:
+			printk("%s data size: %d (0x%x)\n",
+				(type == MOSIX_LOG_SENDDATA ? "SEND" : "RECV"),
+				val, val);
+			break;
+		case MOSIX_LOG_SENDURG:
+		case MOSIX_LOG_RECVURG:
+			printk("urgent signal %s\n",
+				type == MOSIX_LOG_SENDURG ? "SENT" : "ARRIVED");
+			break;
+		case MOSIX_LOG_RETURNVAL:
+			printk(!val ? "zero\n" : "value %d (0x%x)\n", val, val);
+			break;
+		default:
+			printk("with value: 0x%x (%d)\n", val, val);
+			break;
+		}
+	}
+	printk("\n");
+}
+#endif /* CONFIG_MOSIX_DEBUG */
diff -ruN linux-2.4.16/mos/mig.c linux-2.4.16-mosix/mos/mig.c
--- linux-2.4.16/mos/mig.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/mig.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1816 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan, Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <mos/routines.h>
+#include <linux/mosix.h>
+#include <linux/personality.h>
+#include <linux/mosctl.h>
+#include <linux/mm.h>
+#include <linux/swap.h>
+#include <linux/swapctl.h>
+#include <linux/highmem.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+#include <mos/log.h>
+#include <mos/defs.h>
+#include <mos/version.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/stddef.h>
+#include <asm/softirq.h>
+#include <asm/mman.h>
+#include <asm/mmu_context.h>
+#include <asm/ldt.h>
+#include <linux/vmalloc.h>
+#include <asm/desc.h>
+#include <linux/module.h>
+#include <asm/processor.h>
+#include <asm/i387.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+static int mig_remote_receive_proc(void *);
+static int mig_local_passto_remote(int, int);
+static int mig_remote_passto_remote(int, int);
+static int mig_remote_passto_local(int, int);
+
+#define MIGDSTR "migdaemon"
+static char REMOTESTR[] = "remote";
+static char REMOTESTR2[] = "remote(%d)";
+
+int mig_daemon_active = 0;
+struct task_struct *mig_proc = NULL;
+#ifdef CONFIG_MOSIX_UDB
+#define	SHOW_MIGRATIONS	do_weeeeeeeee
+#ifdef CONFIG_MOSIX_WEEEEEEEEE
+static int do_weeeeeeeee = 1;
+#else
+static int do_weeeeeeeee = 0;
+#endif /* CONFIG_MOSIX_WEEEEEEEEE */
+#else
+#ifdef CONFIG_MOSIX_WEEEEEEEEE
+#define	SHOW_MIGRATIONS	1
+#endif /* CONFIG_MOSIX_WEEEEEEEEE */
+#endif /* CONFIG_MOSIX_UDB */
+
+int
+mosix_mig_daemon(void *dummy)
+{
+	struct task_struct *p = current;
+	mosix_link *mlink;
+	mosix_addr saddr;
+	int error;
+
+	common_daemon_setup(MIGDSTR, 0);
+	p->mosix.dflags |= DREMOTEDAEMON;
+	init_guest_user_struct();
+	p->rlim[RLIMIT_STACK].rlim_cur = p->rlim[RLIMIT_STACK].rlim_max;
+	lock_mosix();
+	mig_proc = p;
+	unlock_mosix();
+
+restart:
+	wait_for_mosix_configuration(&mig_daemon_active);
+	error = 0;
+	if (!p->mosix.contact &&
+		!(p->mosix.contact = comm_open(COMM_MIGD, 0, 0)))
+	{
+		if(PE)
+			printk(MIGDSTR ": failed opening migration service"
+							" -- retrying\n");
+		spin_lock_irq(&p->sigmask_lock);
+		flush_signals(p);
+		spin_unlock_irq(&p->sigmask_lock);
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(HZ);
+		goto restart;
+	}
+
+	while (1)
+	{
+		if(!PE)
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug)
+				printk(MIGDSTR ": MOSIX shutdown\n");
+#endif
+			comm_close(NULL);
+			goto restart;
+		}
+
+		error = comm_accept(p->mosix.contact, &mlink, &saddr, 0UL);
+		if (error == -EINTR || error == -ERESTART || error == -EAGAIN
+			 || error == -ERESTARTSYS || error == -EDIST)
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if(error != -EDIST && PE)
+				printk(MIGDSTR
+					": error.. retrying (%d)\n", error);
+#endif
+			spin_lock_irq(&p->sigmask_lock);
+			flush_signals(p);
+			spin_unlock_irq(&p->sigmask_lock);
+			continue;
+		}
+		else if (error)
+		{
+			printk("%s: failed to accept connection (err = %d)"
+				" - re-initializing service\n", MIGDSTR, error);
+			comm_close(NULL);
+			goto restart;
+		}
+
+		if(!PE || mosadmin_mode_block)
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & (DSDEB_MIG | DSDEB_ERROR))
+				printk(MIGDSTR ": not accepting right now\n");
+#endif /* CONFIG_MOSIX_DEBUG */
+			comm_close(mlink);
+			continue;
+		}
+
+		current->mosix.deppe = comm_getpeer(mlink);
+		error = user_thread(mig_remote_receive_proc, (void *)mlink, 0);
+		if (error < 0)
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & DSDEB_MIG)
+				printk(MIGDSTR ": fork failed %d\n", error);
+#endif
+			comm_close(mlink);
+			continue;
+		}
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & DSDEB_MIG)
+			printk(MIGDSTR ": forked a child pid = %d\n", error);
+#endif
+	}
+}
+
+static int
+mig_remote_receive_proc(void *ptr)
+{
+	struct mosix_link *contact = (struct mosix_link *)ptr;
+	struct mosix_link *remlink = NULL;
+	struct task_struct *p = current;
+	struct mosix_task *m = &p->mosix;
+	struct mig_request_h *mrp;
+	int type;
+	int error;
+	int reply = 0;
+	int load_came_in = 0;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_MIG)
+		printk("%s-mig_remote_receive_proc: BORN\n", desc_mostask(m));
+#endif
+	memcpy(p->comm, REMOTESTR, sizeof(REMOTESTR));
+	p->mosix.stay = 0;
+	comm_use(p, contact);
+
+	lighter_sleep();
+	if((error = obtain_mm()))
+		goto failed;
+
+	if (p->mosix.dflags & DREMOTE)
+		p->mosix.dflags |= DPSYNC;
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 1\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((error = mig_recv_request(&mrp)))
+		goto failed;
+	type = mrp->request_type;
+	if(type != DEPUTY_PROBE)
+		load_came_in = 1;
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 2\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if(mrp->wp_works_ok && !boot_cpu_data.wp_works_ok)
+		reply = -ENOEXEC;
+
+	set_personality(mrp->personality);
+	if(current->personality != mrp->personality)
+		reply = -EDIST;
+	comm_free((void *) mrp);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 3\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if (type == DEPUTY_PROBE && reply == 0) {
+		mosix_addr sa;
+
+		/*
+		 * prepare another mosix_link for the REMOTE and send its
+		 * address through the DEPUTY.
+		 */
+
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_MIGSTAGE)
+			printk("%s-migrating: 3.1\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		remlink = comm_open(COMM_ACCEPT, &sa, comm_remote_timo);
+		if (!remlink) {
+#ifdef CONFIG_MOSIX_DEBUG
+			if (ds_debug & (DSDEB_MIG | DSDEB_ERROR))
+				printk("%s-mig_remote_receive_proc:"
+					"error new link\n", desc_mostask(NULL));
+#endif
+			reply = -EDIST;
+			goto send_reply;
+		}
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_MIGSTAGE)
+			printk("%s-migrating: 3.2\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+		if ((error = comm_send(MIG_REQUEST|REPLY, (void *)&reply,
+				sizeof(int), (void *)&sa, sizeof(sa), 0)))
+			goto failed;
+		comm_use(p, remlink);
+		reply = mig_recv_request(&mrp);
+
+		/* 'remlink' was possibly switched by comm_recv(): */
+		remlink = p->mosix.contact;
+
+		if (reply)
+			goto failed;
+		load_came_in = 1;
+		comm_free((void *) mrp);
+		goto send_reply;
+	} else {
+		send_reply:
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_MIGSTAGE)
+			printk("%s-migrating: 3.3 (ack = %d)\n",
+						desc_mostask(NULL), reply);
+#endif /* CONFIG_MOSIX_DEBUG */
+		if ((error = comm_send(MIG_REQUEST|REPLY, (void *)&reply,
+						sizeof(int), NULL, 0, 0)))
+			goto failed;
+	}
+				
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 4\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if (reply)
+		goto failed;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 5 (type %d)\n", desc_mostask(NULL), type);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	error = mig_do_receive();
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 7\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if (remlink) {
+		comm_use(p, contact);
+		comm_close(remlink);
+	}
+	if (error)
+	{
+		end_coming_in(error);
+		m->pages_i_bring = 0;
+		remote_disappear();
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-migrating: 8 (kickstart !)\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	mosix_clear_statistics();
+	end_coming_in(0);
+	m->pages_i_bring = 0;
+#ifdef CONFIG_MOSIX_DFSA
+	tell_process(p, DREQ_NOTUPTODATE);
+	dfsa_tinit();
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef SHOW_MIGRATIONS
+	if(SHOW_MIGRATIONS)
+		printk("Weeeeeeeee.....\n");
+#endif /* SHOW_MIGRATIONS */
+	kickstart();
+	panic("kickstart returned");
+	/*NOTREACHED*/
+
+failed:
+	if(load_came_in)
+	{
+		end_coming_in(-EDIST);	/* any error would do */
+		m->pages_i_bring = 0;
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_MIG|DSDEB_MIGSTAGE))
+		printk("%s-migrating: failed, error = %d, reply = %d\n",
+			desc_mostask(NULL), error, reply);
+#endif /* CONFIG_MOSIX_DEBUG */
+	if (remlink) {
+		comm_use(p, contact);
+		comm_close(remlink);
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_MIG | DSDEB_MIGSTAGE | DSDEB_ERROR))
+		printk("%s-mig_remote_receive_proc: aborting\n",
+							desc_mostask(NULL));
+#endif
+	do_exit(SIGKILL);
+	/*NOTREACHED*/
+}
+
+void
+follow_whereto()
+{
+	int t;
+	register struct task_struct *p = current;
+
+	spin_lock_irq(&whereto_lock);
+	t = p->mosix.whereto;
+	p->mosix.whereto = 0;
+	spin_unlock_irq(&whereto_lock);
+	if(!t)
+		return;
+	if(t > 0 || t == GOBACKHOME || t == MUSTGOHOME)
+		passto(t, 0);
+	else if(p->mosix.dflags & DDEPUTY)
+		coordinate(t, 0);
+	else
+		consider(t, NULL);
+}
+
+int
+passto(int whereto, int reason)
+{
+	register struct task_struct *p = current;
+	int error;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_MIG|DSDEB_MIGSTAGE))
+		printk("%s-passto: %d %d\n",
+			desc_mostask(NULL), whereto, reason);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (p->mosix.dflags & DREMOTE)
+		panic("REMOTE passto");
+#endif /* CONFIG_MOSIX_DIAG */
+	if (!PE)
+		return (whereto && whereto != GOBACKHOME &&
+			whereto != MUSTGOHOME ? -EDIST : 0);
+	if (whereto == MUSTGOHOME)
+	{
+		whereto = GOBACKHOME;
+		p->mosix.dflags |= DMUSTBEBACK;
+	}
+#ifdef CONFIG_MOSIX_CHEAT_MIGSELF
+	if (whereto == GOBACKHOME)
+	{
+		if(!p->mosix.whereami)
+		{
+			p->mosix.dflags &= ~DMUSTBEBACK;
+			return(0);
+		}
+		whereto = 0;
+	}
+#else
+	if (whereto == GOBACKHOME || whereto == PE)
+		whereto = 0;
+	if (whereto == p->mosix.whereami)
+	{
+		p->mosix.dflags &= ~DMUSTBEBACK;
+		return(0);
+	}
+#endif /* CONFIG_MOSIX_CHEAT_MIGSELF */
+	if (whereto && ((p->mosix.stay & DSTAY) || !mos_to_net(whereto, 0)))
+		return (-EDIST);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_MIG|DSDEB_MIGSTAGE))
+		printk("%s Passing to %d!\n", desc_mostask(NULL), whereto);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	spin_lock_irq(&runqueue_lock);
+	p->mosix.dflags |= DPASSING;
+	spin_unlock_irq(&runqueue_lock);
+	store_common_ps_info();
+
+	if (!p->mosix.whereami)
+		error = mig_local_passto_remote(whereto, reason);
+	else if (!whereto)
+		error = mig_remote_passto_local(whereto, reason);
+	else
+		error = mig_remote_passto_remote(whereto, reason);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-passto: handler returned %d\n",
+			desc_mostask(NULL), error);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	stop_storing_common_ps_info();
+	spin_lock_irq(&runqueue_lock);	/* for DPASSING (not for DMUSTBEBACK) */
+	p->mosix.dflags &= ~(DPASSING|DMUSTBEBACK);
+	spin_unlock_irq(&runqueue_lock);
+
+	if(error)
+		return (-EDIST);
+
+	task_lock(p);
+	p->mosix.whereami = whereto;
+	p->mosix.nmigs++;
+	task_unlock(p);
+	if(p->mosix.sigmig)
+	{
+		struct siginfo info;
+
+		info.si_signo = p->mosix.sigmig;
+		info.si_errno = 0;
+		info.si_code = SI_MIGRATED;
+		info.si_newplace = whereto;
+		info.si_reason = reason;
+		send_sig_info(p->mosix.sigmig, &info, p);
+	}
+	mosix_clear_statistics();
+	return(0);
+}
+
+void
+coordinate(int reason, int already_in)
+{
+	struct mosix_task *m = &current->mosix;
+	void *head;
+	int hdln;
+	int where;
+
+#ifdef	CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_CONSIDER)
+		printk("%s-coordinate\n", desc_mostask(NULL));
+#endif
+	while(1)
+	{
+		if(already_in)
+		{
+			if(deputy_wait(DEP_CONSIDER|REPLY, &head, &hdln))
+				goto die;
+			where = *((int *)head);
+			comm_free(head);
+			already_in = 0;
+		}
+		else if(deputy_request(DEP_CONSIDER, &reason, sizeof(reason),
+			NULL, 0, 0, (void *)&where, -sizeof(where)))
+		{
+			die:
+			deputy_communication_failed();
+			return;
+		}
+#ifdef	CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("coordinate: where=%d\n", where);
+#endif
+		if(!where)
+			return;
+		if(reason && where != GOBACKHOME &&
+			(m->whereto == GOBACKHOME || m->whereto == MUSTGOHOME))
+		{
+			where = m->whereto;
+			reason = 0;
+		}
+		if(!passto((where == GOBACKHOME || where == MUSTGOHOME) ? 0 :
+								where, reason))
+			return;
+#ifdef	CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("coordinate: did not pass to %d - next one please\n", where);
+#endif
+	}
+}
+
+int
+mig_send_request(int reason, int type)
+{
+	struct mig_request_h mrp;
+	int *nack;
+	int mfident = (current->mosix.dflags & DDEPUTY) ? COMM_MFIDENT : 0;
+	int command = MIG_REQUEST | mfident;
+	int error;
+	int len;
+
+	mrp.version = MOSIX_MIGRATION_VERSION;
+	mrp.topology = MAX_MOSIX_TOPOLOGY;
+	mrp.reason = reason;
+	mrp.personality = current->personality;
+	mrp.wp_works_ok = boot_cpu_data.wp_works_ok;
+	mrp.request_type = type;
+#ifdef CONFIG_MOSIX_DFSA
+	mrp.has_dfsa = 1;
+#else
+	mrp.has_dfsa = 0;
+#endif /* CONFIG_MOSIX_DFSA */
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-send_request 1\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if(type == DEPUTY_PROBE)
+		error = comm_send(command, &mrp, sizeof(mrp), NULL, 0, 0);
+	else
+	{
+		mrp.pages_sent =
+			current->mosix.migpages ? : count_migrating_pages();
+		error = send_with_miginfo(command, &mrp, sizeof(mrp));
+	}
+	if(error)
+		return (error);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-send_request 2\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((error = comm_recv((void **)&nack, &len)) < 0)
+		return (error);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-send_request 3\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if (error != (MIG_REQUEST|REPLY)) {
+		error = -EDIST;
+		goto out;
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-send_request 4\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+#ifdef CONFIG_MOSIX_DIAG
+	if (len != sizeof(int))
+		panic("mig_send_request: bad reply length");
+#endif
+
+	/* at this point the other party *knows* us */
+	if (mfident)
+		config_set_status(comm_getpeer(current->mosix.contact));
+
+	error = *nack;		/* should be: 0 or -EDIST */
+out:
+	comm_free((void *) nack);
+	return (error);
+}
+
+int
+mig_recv_request(struct mig_request_h **mrp)
+{
+	int type, hlen;
+	int reply = -EDIST;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-recv_request 1\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((type = comm_recv((void **) mrp, &hlen)) < 0)
+		return (type);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_recv_request: type 0x%x head 0x%x len %d\n",
+			desc_mostask(NULL), type, (int)mrp, hlen);
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if (type != MIG_REQUEST || hlen != sizeof(struct mig_request_h)) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (ds_debug & (DSDEB_ERROR | DSDEB_MIG | DSDEB_MIGSTAGE))
+			printk("%s-mig_recv_request: bad MIG_REQUEST type=%d "
+				" head=0x%x len=%d\n",
+				desc_mostask(NULL), type, (int)mrp, hlen);
+#endif
+		goto failed;
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-recv_request 2\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((*mrp)->version != MOSIX_MIGRATION_VERSION)
+	{
+		static int complained;
+
+		if(++complained < 10 || complained % 10000 == 0)
+			printk("Migration request denied: "
+				"Incompatible versions of MOSIX.\n");
+		goto failed;
+	}
+	if ((*mrp)->topology != MAX_MOSIX_TOPOLOGY)
+	{
+		static int complained;
+
+		if(++complained < 10 || complained % 10000 == 0)
+			printk("Migration request denied: Incompatible topology"
+				" (here=%d, there=%d)\n", MAX_MOSIX_TOPOLOGY,
+				(*mrp)->topology);
+		goto failed;
+	}
+#ifdef CONFIG_MOSIX_DFSA
+	if(!(*mrp)->has_dfsa)
+#else
+	if((*mrp)->has_dfsa)
+#endif /* CONFIG_MOSIX_DFSA */
+	{
+		static int complained;
+
+		if(++complained < 10 || complained % 10000 == 0)
+			printk("Migration request denied: "
+				"Cannot mix DFSA and NON-DFSA kernels\n");
+		goto failed;
+	}
+
+	if ((*mrp)->request_type != DEPUTY_PROBE)
+	{
+		if (!balance_commit_mig((*mrp)->reason, (*mrp)->pages_sent))
+			goto failed;
+		current->mosix.pages_i_bring = (*mrp)->pages_sent;
+	}
+
+	return (0);
+
+failed:
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_ERROR|DSDEB_MIGSTAGE))
+		printk("%s-recv_request 3 (failed)\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	comm_flushdata(COMM_ALLDATA);
+	comm_free(*mrp);
+	*mrp = NULL;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_ERROR|DSDEB_MIG|DSDEB_MIGSTAGE))
+		printk("%s-mig_recv_request: nacking with %d\n",
+			desc_mostask(NULL), reply);
+#endif
+
+	comm_send(MIG_REQUEST|REPLY, (void *) &reply, sizeof(int), NULL, 0, 0);
+	return (reply);
+}
+
+/*
+ * mig_local_passto_remote:  migrate local -> remote
+ */
+
+static int
+mig_local_passto_remote(int whereto, int reason) 
+{
+	struct task_struct *p = current;
+	struct mosix_link *mlink;
+	int error;
+	int omigpages;
+
+	if(!p->mosix.held_files && (error = mosix_rebuild_file_list()))
+		return(error);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-local_passto_remote: 1\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	lock_mosix();
+	write_lock_irq(&tasklist_lock);
+	p->mosix.remote_caps = current->cap_effective;
+	task_lock(p);
+	spin_lock(&runqueue_lock);
+	if(p->mm->dumpable)
+		p->mosix.dflags |= DDUMPABLE;
+	else
+		p->mosix.dflags &= ~DDUMPABLE;
+	p->mosix.dflags |= (DDEPUTY | DSYNC);
+	spin_unlock(&runqueue_lock);
+	task_unlock(p);
+	write_unlock_irq(&tasklist_lock);
+	unlock_mosix();
+	p->mosix.deputy_regs = ALL_REGISTERS;
+	p->mosix.pass_regs = 0;
+
+	if (!(mlink = comm_open(whereto, 0, comm_connect_timo))) {
+		error = -EDIST;
+		goto failed;
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-local_passto_remote: 2\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if (comm_use(p, mlink))
+		panic("local_passto_remote: previous contact not null");
+	
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-local_passto_remote: 3\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if(!(omigpages = p->mosix.migpages))
+		p->mosix.migpages = count_migrating_pages();
+	if ((error = mig_send_request(reason, FROM_DEPUTY)))
+	{
+		p->mosix.migpages = omigpages;
+		goto failed;
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-local_passto_remote: returning...\n",
+							desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	release_migrations(whereto);
+	if (mig_do_send()) {
+		error = -EDIST;
+		p->mosix.migpages = omigpages;
+		goto failed;
+	}
+	p->mosix.migpages = omigpages;
+
+	deputy_startup();
+	return (0);
+
+failed:
+	if(mlink)
+		comm_close(NULL);
+	undeputy(current);
+	return (error);
+}
+
+
+/*
+ * mig_remote_passto_local:  migrate remote -> local
+ */
+
+static int
+mig_remote_passto_local(int whereto, int reason) 
+{
+	struct task_struct *p = current;
+	struct mig_request_h *mrp;
+	int error = 0;
+	long orlim_as;
+	long orlim_rss;
+	long orlim_stack;
+	int load_came_in = 0;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 1\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	mosix_deputy_rusage(0);
+	if(obtain_mm())
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-remote_passto_local: mm allocation failed\n",
+			desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DIAG */
+		return(-EDIST);
+	}
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 2\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	/* rlimits are no excuse to prevent coming back home: */
+	/* save old values for the case of failure */
+	orlim_as = p->rlim[RLIMIT_AS].rlim_cur;
+	orlim_rss = p->rlim[RLIMIT_RSS].rlim_cur;
+	orlim_stack = p->rlim[RLIMIT_STACK].rlim_cur;
+	p->rlim[RLIMIT_AS].rlim_cur = RLIM_INFINITY;
+	p->rlim[RLIMIT_RSS].rlim_cur = RLIM_INFINITY;
+	p->rlim[RLIMIT_STACK].rlim_cur = RLIM_INFINITY;
+
+	if ((error = comm_send(DEP_COME_BACK, (void *) &reason, sizeof(reason),
+								NULL, 0, 0))) {
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-remote_passto_local: error DEP_COME_BACK\n",
+			desc_mostask(NULL));
+#endif
+		end_coming_in(error);
+		current->mosix.pages_i_bring = 0;
+		deputy_die_on_communication();
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 3\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((error = mig_recv_request(&mrp)))
+		goto fail;
+	load_came_in = 1;
+	comm_free((void *) mrp);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 4\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if ((error = comm_send(MIG_REQUEST|REPLY, (void *)&error, sizeof(int),
+								NULL, 0, 0))) {
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-remote_passto_local: error %d (MIG_REQUEST)\n",
+			desc_mostask(NULL), error);
+#endif
+		end_coming_in(error);
+		current->mosix.pages_i_bring = 0;
+		deputy_die_on_communication();
+		/*NOTREACHED*/
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 5\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+	if (!(error = mig_do_receive())) {
+		comm_close(NULL);
+		undeputy(p);
+		mosix_clear_statistics();
+#ifdef SHOW_MIGRATIONS
+		if(SHOW_MIGRATIONS)
+			printk("Wooooooooo.....\n");
+#endif /*SHOW_MIGRATIONS*/
+		end_coming_in(0);
+		current->mosix.pages_i_bring = 0;
+		if(p->mosix.dflags & DDELAYHELD)
+		{
+			p->mosix.dflags &= ~DDELAYHELD;
+			mosix_rebuild_file_list();
+		}
+		return(0);
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 6\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+fail:
+	p->rlim[RLIMIT_AS].rlim_cur = orlim_as;
+	p->rlim[RLIMIT_RSS].rlim_cur = orlim_rss;
+	p->rlim[RLIMIT_STACK].rlim_cur = orlim_stack;
+	exit_mm(p);
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_local: 7 (err = %d)\n",
+			desc_mostask(NULL), error);
+#endif /* CONFIG_MOSIX_DEBUG */
+	if(load_came_in)
+	{
+		end_coming_in(error);
+		current->mosix.pages_i_bring = 0;
+	}
+
+	return (error);
+}
+
+
+/*
+ * mig_remote_passto_remote:  migrate remote -> remote
+ *
+ * (1) open mosix_link to mig-daemon at new remote site (and use it)
+ * (2) send migration request, obtain remote's mosix_link address.
+ * (3) send DEP_PLEASE_MIGRATE request to old remote site, with "reason"
+ *     and the mosix_link address to which it should connect
+ * (4) if the reply is zero - close old mosix_link and use the new one (SUCCESS)
+ * FAILURE: if not fatal - close new connection and return error
+ *          if fatal - close connection and call deputy_die_on_communication()
+ */
+
+static int
+mig_remote_passto_remote(int whereto, int reason) 
+{
+	struct task_struct *p = current;
+	struct mosix_link *newmlink = 0, *oldmlink = 0;
+	struct please_migrate_h pm;
+	int status;
+	int error;
+
+	/* connect to remote mig daemon */
+
+#ifdef CONFIG_MOSIX_DIAG
+	if (!(p->mosix.dflags & DSYNC))
+		panic("remote_passto_remote: deputy not synced");
+#endif
+
+	p->mosix.pass_regs = 0;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_remote: 0\n", desc_mostask(NULL));
+#endif
+
+	if (!(newmlink = comm_open(whereto, 0, comm_connect_timo)))
+		return (-EDIST);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_remote: 1\n", desc_mostask(NULL));
+#endif
+
+	if (!(oldmlink = comm_use(p, newmlink)))
+		panic("remote_passto_remote: no previous contact");
+	
+	if ((error = mig_send_request(reason, DEPUTY_PROBE)))
+		goto failed;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_remote: 2 \n", desc_mostask(NULL));
+#endif
+
+	if ((error = comm_copydata((void *)&pm.ma, sizeof(pm.ma), 0)))
+		goto failed;
+
+	comm_use(p, oldmlink);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_remote: 3 \n", desc_mostask(NULL));
+#endif
+
+	pm.reason = reason;
+	pm.to = whereto;
+	mosix_deputy_rusage(0);
+	if ((error = deputy_request(DEP_PLEASE_MIGRATE, &pm, sizeof(pm),
+				NULL, 0, 0, (void **)&status, -sizeof(status))))
+		goto fatal;
+	if ((error = status))
+		goto failed;
+	
+	comm_use(p, newmlink);
+	comm_close(oldmlink);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIGSTAGE)
+		printk("%s-mig_remote_to_remote: 4 (DONE) \n",
+							desc_mostask(NULL));
+#endif
+	
+	return (0);
+
+failed:
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_ERROR | DSDEB_MIG | DSDEB_MIGSTAGE))
+		printk("%s-remote_passto_remote: failed %d\n",
+						desc_mostask(NULL), error);
+#endif
+	comm_use(p, oldmlink);
+	comm_close(newmlink);
+	return (error);
+
+fatal:
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_ERROR | DSDEB_MIG | DSDEB_MIGSTAGE))
+		printk("%s-remote_passto_remote: fatal %d\n",
+						desc_mostask(NULL), error);
+#endif
+	comm_use(p, oldmlink);
+	comm_close(newmlink);
+#ifdef CONFIG_MOSIX_DIAG
+	printk("%s-remote_passto_remote: fatal error %d\n", desc_mostask(NULL),
+									error);
+#endif
+	deputy_die_on_communication();
+	/* NOTREACHED */
+}
+
+
+void
+undeputy(struct task_struct *p)
+{
+	struct mosix_task *m = &p->mosix;
+	int myself = (p == current);/* else it is a new-son, not yet on lists */
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & DSDEB_MIG)
+	{
+		printk("%s-undepty: ", desc_mostask(NULL));
+		printk("undeputy'ing process %s\n", desc_mostask(m));
+	}
+#endif
+
+	if(myself)
+	{
+		spin_lock_irq(&p->sigmask_lock);
+		m->dflags &= ~DFAKESIGNAL;
+		spin_unlock_irq(&p->sigmask_lock);
+		lock_mosix();
+		write_lock_irq(&tasklist_lock);
+		task_lock(p);
+		spin_lock(&runqueue_lock);
+	}
+	if(p->mm)
+		p->mm->dumpable = (m->dflags & DDUMPABLE) != 0;
+	m->dflags &= ~(DDEPUTY|DSYNC|DDUMPABLE);
+	if(myself)
+	{
+		spin_unlock(&runqueue_lock);
+		task_unlock(p);
+		write_unlock_irq(&tasklist_lock);
+		if(process_told(p, DREQ_HOMEWAKE))
+		{
+			process_ack(p, DREQ_HOMEWAKE);
+			wake_up(mos_to_waitp(m));
+		}
+		unlock_mosix();
+		evaluate_pending_signals_in_mosix_context();
+		absorb_deptime(m->deputytime);
+		m->deputytime = 0;
+		stop_storing_common_ps_info();
+		flush_read_cache();
+		free_ucache();
+		if(m->stay & DSTAY_FOR_MONKEY)
+			mosix_check_for_freedom_to_move();
+	}
+	else
+	{
+		if(m->contact)
+		{
+			comm_close(m->contact);
+			m->contact = NULL;
+		}
+	}
+	m->commpri = 0;
+	m->pages_i_bring = 0;
+}
+
+int
+mig_send_mm_stats(void)
+{
+	struct mm_stats_h s;
+
+	if(sizeof(struct mm_stats_h) !=
+		offsetof(struct mm_struct, env_end) -
+		offsetof(struct mm_struct, start_code) + sizeof(long))
+		/* something changed in the Linux header - need to fix! */
+			panic("mig_send_mm_stats");
+	memcpy((caddr_t)&s, (caddr_t)&current->mm->start_code, sizeof(s));
+	expel_progress = 1;
+	return(comm_send(MIG_MM_STATS, &s, sizeof(s), NULL, 0, 0));
+}
+
+int
+mig_send_mm_areas(void)
+{
+	struct task_struct *p = current;
+	register struct vm_area_struct *vma;
+	struct file *fp;
+	struct mmap_parameters_h m;
+
+	m.origin = (p->mosix.dflags & DDEPUTY) ? PE : p->mosix.deppe;
+	m.fixed = 1;
+	for(vma = p->mm->mmap ; vma != NULL ; vma = vma->vm_next)
+	{
+		m.addr = vma->vm_start;
+		m.len = vma->vm_end - vma->vm_start;
+		m.flags = vma->vm_flags;
+		if((fp = vma->vm_file))
+		{
+			struct inode *ip = fp->f_dentry->d_inode;
+
+			m.pgoff = vma->vm_pgoff;
+			if(p->mosix.dflags & DREMOTE)
+			{
+				m.fp = home_file(fp);
+				m.dp = ip->u.remote_i.dp;
+				m.uniq = ip->u.remote_i.unique;
+				m.isize = ip->i_size;
+				m.nopage = ip->u.remote_i.nopage;
+			}
+			else
+			{
+				m.fp = vma->vm_file;
+				m.dp = m.fp->f_dentry;
+				m.uniq = ip->i_unique;
+				m.isize = ip->i_size;
+				m.nopage = vma->vm_ops->nopage;
+			}
+		}
+		else
+		{
+			m.fp = NULL;
+			m.pgoff = 0;
+		}
+		if(comm_send(MIG_MM_AREA, &m, sizeof(m), NULL, 0, 0))
+			return(-1);
+	}
+	expel_progress = 1;
+	return(0);
+}
+
+int
+mig_send_page(unsigned long addr, int size)
+{
+#ifdef CONFIG_MOSIX_DIAG
+	if(--current->mosix.mig_page_count == -1)
+	{
+		printk("Here I am sending too many pages, was sending %d "
+			"and current recount is %d\n",
+			current->mosix.migpages, count_migrating_pages());
+#ifdef CONFIG_MOSIX_UDB
+		mosix_debugger("pages increased");
+#endif /* CONFIG_MOSIX_UDB */
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	expel_progress = 1;
+	/*
+	 * Although the page is in user-space, we deliberately send it from
+	 * kernel-space to prevent requesting it from the "REMOTE"
+	 * (because we are already marked as DEPUTY...)
+	 * This is safe since we just checked that the page is there.
+	 */
+	return(comm_send(MIG_PAGE, &addr, sizeof(addr), (void *)addr, size, 0));
+}
+
+int
+mig_send_pages(void)
+{
+	int credit;
+
+#ifdef CONFIG_MOSIX_DIAG
+	current->mosix.mig_page_count = current->mosix.migpages;
+#endif /* CONFIG_MOSIX_DIAG */
+	credit = run_over_dirty_pages(mig_send_page, 1);
+#ifdef CONFIG_MOSIX_DIAG
+	if(credit >= 0 && current->mosix.mig_page_count > 0)
+	    printk("not all pages sent: was sending %d, left %d, recount=%d\n",
+		-current->mosix.pages_i_bring, current->mosix.mig_page_count,
+		count_migrating_pages());
+#endif /* CONFIG_MOSIX_DIAG */
+	return(credit);
+}
+
+int
+mig_send_fp(void)
+{
+	unlazy_fpu(current);
+	expel_progress = 1;
+	return(comm_send(has_fxsr() ? MIG_XFP : MIG_FP, &current->thread.i387,
+				sizeof(current->thread.i387), NULL, 0, 0));
+}
+
+int
+mig_send_ldt(void)
+{
+	expel_progress = 1;
+	return(comm_send(MIG_LDT, NULL, 0,
+		current->mm->context.segments, LDT_ENTRIES*LDT_ENTRY_SIZE, 0));
+}
+
+int
+mig_send_misc(int credit)
+{
+	struct mig_misc_h m;
+	clock_t utime, stime;
+	extern unsigned long do_it_virt(struct task_struct *, unsigned long);
+	void *hd;
+	int hdln;
+	register struct task_struct *p = current;
+	siginfo_t *forced_sigs;
+
+	m.ptrace = p->ptrace;
+	m.dflags = p->mosix.dflags & (DTRACESYS1|DTRACESYS2);
+	memcpy((caddr_t)m.debugreg, (caddr_t)p->thread.debugreg,
+							sizeof(m.debugreg));
+	m.nice = p->nice;
+	m.caps = p->cap_effective;
+	p->mosix.remote_caps = m.caps;
+	m.it_prof_incr = p->it_prof_incr;
+	m.it_virt_incr = p->it_virt_incr;
+	if(((p->mosix.dflags & DDEPUTY) && p->mosix.deputy_regs) || 
+		((p->mosix.dflags & DREMOTE) &&
+					p->mosix.deputy_regs != ALL_REGISTERS))
+		memcpy((caddr_t)&m.regs, (caddr_t)p->mosix.altregs, sizeof(m.regs));
+		/* else do not bother - DEPUTY will bring */
+	m.rlim_cpu = p->rlim[RLIMIT_CPU];
+	m.rlim_data = p->rlim[RLIMIT_DATA];
+	m.rlim_stack = p->rlim[RLIMIT_STACK];
+	m.rlim_rss = p->rlim[RLIMIT_RSS];
+	m.rlim_as = p->rlim[RLIMIT_AS];
+#ifdef CONFIG_MOSIX_DFSA
+	m.rlim_nofile = p->rlim[RLIMIT_NOFILE];
+	m.rlim_fsz = p->rlim[RLIMIT_FSIZE];
+#endif /* CONFIG_MOSIX_DFSA */
+	m.stay = (p->mosix.stay & DNOMIGRATE) != 0;
+	if(p->mosix.dflags & DDEPUTY)
+	{
+		m.deppe = PE;
+		m.mypid = p->pid;
+		memcpy(m.features, boot_cpu_data.x86_capability,
+							sizeof(m.features));
+	}
+	else
+	{
+		m.deppe = p->mosix.deppe;
+		m.mypid = p->mosix.mypid;
+		memcpy(m.features, p->mosix.features, sizeof(m.features));
+		m.passedtime = p->mosix.passedtime;
+	}
+	m.deputy_regs = p->mosix.deputy_regs;
+	m.deccycle = p->mosix.deccycle;
+	m.decay = p->mosix.decay;
+	m.dpolicy = p->mosix.dpolicy;
+	memcpy(m.depcost, deputy_here, sizeof(deputy_here));
+	m.depspeed = cpuspeed;
+	m.nmigs = p->mosix.nmigs + 1;
+	m.info.disclosure = p->mosix.disclosure;
+	m.info.uid = p->uid;
+	m.info.gid = p->gid;
+	m.info.pgrp = p->pgrp;
+	m.info.session = p->session;
+	memcpy(m.info.comm, p->comm, sizeof(m.info.comm));
+	m.info.tgid = p->tgid;
+	cli();
+	m.it_virt_value = p->it_virt_value;
+	m.it_prof_value = p->it_prof_value;
+	p->it_prof_value = 0;
+	p->it_virt_value = 0;
+	if(p->mosix.dflags & DDEPUTY)
+		m.passedtime = p->times.tms_utime + p->times.tms_stime;
+	utime = p->times.tms_utime;
+	stime = p->times.tms_stime;
+	m.asig.sigs = p->mosix.asig;
+	m.asig.nforced = p->mosix.nforced_sigs;
+	forced_sigs = p->mosix.forced_sigs;
+	m.pagecredit = credit;
+	m.lastxcpu = p->mosix.last_sigxcpu;
+	sti();
+	if(comm_send(MIG_MISC, &m, sizeof(m), forced_sigs,
+					m.asig.nforced * sizeof(siginfo_t), 0))
+		goto fail;
+	comm_migration_mode(0);
+	expel_progress = 1;
+	if(comm_recv(&hd, &hdln) == (MIG_MISC|REPLY))
+		return(0); /* commit point */
+
+	fail:
+	cli();
+	p->it_prof_value = m.it_prof_value;
+	p->it_virt_value = m.it_virt_value;
+	/* maintain accurate correlation between process-times and timers: */
+	utime = p->times.tms_utime - utime;
+	stime = p->times.tms_stime - stime;
+	sti();
+	if(utime > 0)
+	{
+		extern rwlock_t xtime_lock;
+
+		write_lock_irq(&xtime_lock);
+		do_it_virt(p, utime);
+		write_unlock_irq(&xtime_lock);
+	}
+	if(!(p->mosix.dflags & DDEPUTY) && /* (DEPUTY gets it in "depticks") */
+		utime + stime > 0)
+		absorb_deptime(utime + stime);
+	return(-1);
+}
+
+void
+neutralize_my_load(int neut)
+{
+	struct task_struct *p = current;
+
+	spin_lock_irq(&runqueue_lock);
+	if(neut)
+	{
+		run_off(p);
+		p->mosix.dflags |= DPAGEIN;	/* disabling run_on/off */
+	}
+	else if(p->mosix.dflags & DPAGEIN)
+	{
+		p->mosix.dflags &= ~DPAGEIN;
+		run_on(p);
+	}
+	spin_unlock_irq(&runqueue_lock);
+}
+
+int
+mig_do_send(void)
+{
+	int credit;	/* # of clean demand-pages */
+
+	comm_migration_mode(1);
+	neutralize_my_load(1); /* don't count me: I'm going to disappear */
+	if(mig_send_mm_stats() || mig_send_mm_areas() ||
+		(credit = mig_send_pages()) < 0 ||
+		(current->used_math && mig_send_fp()) ||
+		(current->mm->context.segments && mig_send_ldt()) ||
+		mig_send_misc(credit))
+	{
+		comm_send(MIG_NOT_COMING, NULL, 0, NULL, 0, 0);
+		comm_migration_mode(0);
+		neutralize_my_load(0);
+		changed_my_mind_and_staying();
+		return(-1);
+	}
+	/* "comm_migration_mode(0);" was done by "mig_send_misc" */
+	neutralize_my_load(0);
+	return(0);
+}
+
+void
+mig_do_receive_mm_stats(struct mm_stats_h *s)
+{
+	if(sizeof(struct mm_stats_h) !=
+		offsetof(struct mm_struct, env_end) -
+		offsetof(struct mm_struct, start_code) + sizeof(long))
+		/* something changed in the Linux header - need to fix! */
+			panic("mig_do_receive_mm_stats");
+	memcpy((caddr_t)&current->mm->start_code, (caddr_t)s, sizeof(*s));
+	current->mosix.rfreepages = 0;
+}
+
+int
+deputy_remmap(struct mmap_parameters_h *m, int dummy)
+{
+	unsigned long result;
+	unsigned long prot, flags;
+	extern asmlinkage long sys_madvise(unsigned long, size_t, int);
+
+	/* unconvert prot+flags: */
+	flags = MAP_FIXED|MAP_PRIVATE;
+	prot = 0;
+	if(m->flags & VM_GROWSDOWN)
+		flags |= MAP_GROWSDOWN;
+	if(m->flags & VM_DENYWRITE)
+		flags |= MAP_DENYWRITE;
+	if(m->flags & VM_EXECUTABLE)
+		flags |= MAP_EXECUTABLE;
+	if(m->flags & VM_READ)
+		prot |= VM_READ;
+	if(m->flags & VM_WRITE)
+		prot |= VM_WRITE;
+	if(m->flags & VM_EXEC)
+		prot |= VM_EXEC;
+	if(m->flags & VM_MAYSHARE)
+		current->mosix.dirty_bits |= MMAP_MAYSHARE;
+	deeper_sleep();
+	result = do_mmap_pgoff(m->fp, m->addr, m->len, prot, flags, m->pgoff);
+	lighter_sleep();
+	if(m->flags & VM_MAYSHARE)
+		current->mosix.dirty_bits &= ~MMAP_MAYSHARE;
+	if(m->flags & VM_READHINTMASK)
+		sys_madvise(m->addr, m->len, (m->flags & VM_SEQ_READ) ?
+						MADV_RANDOM : MADV_SEQUENTIAL);
+	return(IS_ERR((const void *)result));
+}
+
+#define	AVAILABLE_PAGES	(nr_free_pages() + atomic_read(&page_cache_size) + \
+			nr_swap_pages + swapper_space.nrpages)
+#define	VERY_LOW_ON_MEMORY (nr_swap_pages < p->mosix.pages_i_bring && \
+					AVAILABLE_PAGES <= num_physpages / 30)
+#define	I_CAN_FIT	(AVAILABLE_PAGES > p->mosix.pages_i_bring)
+
+int
+mig_do_receive_page(unsigned long addr)
+{
+	pgd_t * pgd;
+	pmd_t * pmd;
+	pte_t * pte;
+	struct page *page = NULL;
+	struct vm_area_struct *vma;
+	static int stuck_here;
+	int tries = 0;
+	long pri, mypri;
+	struct task_struct *p = current, *pp;
+	struct mm_struct *mm = p->mm;
+	int must = (p->mosix.dflags & DMUSTBEBACK);
+	static DECLARE_WAIT_QUEUE_HEAD(wait_for_someone_to_give_up);
+
+	if(!(vma = find_vma(mm, addr)))
+	{
+		comm_flushdata(COMM_ALLDATA);
+		return(-1);
+	}
+	while(VERY_LOW_ON_MEMORY)
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_MIG)
+			printk("%s: Caution taken with page, previous attempts=%d/%d\n", desc_mostask(NULL), tries, stuck_here);
+#endif /* CONFIG_MOSIX_DEBUG */
+		stuck_here++;
+		tries++;
+		if(must ? (tries > 200 && stuck_here >= 300) :
+			(tries > 5 && stuck_here >= 100))
+		{
+			give_up:
+			stuck_here = 0;
+			wake_up(&wait_for_someone_to_give_up);
+			printk("%s: Arrival rejected due to severe memory "
+				"shortage.\n", desc_mostask(NULL));
+			comm_flushdata(COMM_ALLDATA);
+			return(-1);
+		}
+		mypri = ((p->mosix.dflags & DREMOTE) ? 0x20000000 : 0) +
+			(must ? 0 : 0x40000000) +
+			p->mosix.pages_i_bring + mm->rss;
+		pri = 0;
+		read_lock(&tasklist_lock);
+		for_each_task(pp)
+		if(pp != p && (pp->mosix.dflags & DINCOMING))
+		{
+			pri = ((pp->mosix.dflags & DREMOTE) ? 0x20000000 : 0) +
+			  ((pp->mosix.dflags & DMUSTBEBACK) ? 0 : 0x40000000) +
+				pp->mosix.pages_i_bring + pp->mm->rss;
+			if(pri >= mypri)
+				break;
+		}
+		if(must && tries > 5)
+		for_each_task(pp)
+		if((pp->mosix.dflags & (DREMOTE | DREMOTEDAEMON)) == DREMOTE &&
+			(tries < 50 || !pp->mosix.stay))
+		{
+			mosix_add_to_whereto(pp, GOBACKHOME);
+			pri = mypri + 1;
+		}
+		read_unlock(&tasklist_lock);
+		if(pri >= mypri || (must ? (tries < 50 || stuck_here < 100) :
+			(stuck_here < 2 ||
+				((p->mosix.dflags & DDEPUTY) && tries < 3))))
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			if(ds_debug & DSDEB_MIG)
+				printk("%s: %s\n", desc_mostask(NULL),
+					pri >= mypri ?
+					"I am not the worst, so I wait" :
+					"waiting a bit longer");
+#endif /* CONFIG_MOSIX_DEBUG */
+			sleep_on_timeout(&wait_for_someone_to_give_up, HZ/20);
+			continue;
+		}
+		if(must && I_CAN_FIT && (page = alloc_page(GFP_HIGHUSER)))
+			break;
+		goto give_up;
+	}
+	if(stuck_here)
+	{
+		wake_up(&wait_for_someone_to_give_up);
+		stuck_here = 0;
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_MIG)
+			printk("%s: got through to continue arriving%s\n",
+				desc_mostask(NULL),
+				page ? " (also got a page)" : "");
+#endif /* CONFIG_MOSIX_DEBUG */
+	}
+	if(--p->mosix.pages_i_bring < 0)
+		mosix_panic("too many pages arrived");
+	p->mosix.rfreepages--;
+	if(!page && !(page = alloc_page(GFP_HIGHUSER)))
+	{
+		comm_flushdata(COMM_ALLDATA);
+		return(-1);
+	}
+	if(comm_copydata(kmap(page), PAGE_SIZE, 0))
+	{
+		kunmap(page);
+		__free_page(page);
+		return(-1);
+	}
+	kunmap(page);
+	pgd = pgd_offset(mm, addr);
+	spin_lock(&mm->page_table_lock);
+	if (!(pmd = pmd_alloc(mm, pgd, addr)))
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-mig_do_receive_page: failed allocating pmd for addr 0x%x\n",
+			desc_mostask(NULL), (int)addr);
+#endif /* CONFIG_MOSIX_DIAG */
+		spin_unlock(&mm->page_table_lock);
+		__free_page(page);
+		return(-1);
+	}
+	if (!(pte = pte_alloc(mm, pmd, addr)))
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%s-mig_do_receive_page: failed allocating pte for addr 0x%x\n",
+			desc_mostask(NULL), (int)addr);
+#endif /* CONFIG_MOSIX_DIAG */
+		__free_page(page);
+		spin_unlock(&mm->page_table_lock);
+		return(-1);
+	}
+	if (!pte_none(*pte)) {
+		printk("%s-mig_do_receive_page: double page at addr 0x%x\n",
+			desc_mostask(NULL), (int)addr);
+		__free_page(page);
+		spin_unlock(&mm->page_table_lock);
+		return(-1);
+	}
+	set_pte(pte, pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
+	mm->rss++;
+	spin_unlock(&mm->page_table_lock);
+	flush_page_to_ram(page);
+	return(0);
+}
+
+void
+mig_do_receive_fp(union i387_union *i)
+{
+	current->used_math = 1;
+	unlazy_fpu(current);
+	if(has_fxsr())
+		fsave_to_fxsave(i, &current->thread.i387);
+	else
+		memcpy((caddr_t)&current->thread.i387, (caddr_t)i, sizeof(*i));
+}
+
+void
+mig_do_receive_xfp(union i387_union *i)
+{
+	current->used_math = 1;
+	unlazy_fpu(current);
+	if(has_fxsr())
+		memcpy((caddr_t)&current->thread.i387, (caddr_t)i, sizeof(*i));
+	else
+		fxsave_to_fsave(i, &current->thread.i387);
+}
+
+int
+mig_do_receive_ldt(void)
+{
+	struct mm_struct *mm = current->mm;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(mm->context.segments)
+		panic("mig_do_receive_ldt: double");
+#endif /* CONFIG_MOSIX_DIAG */
+	if (!(mm->context.segments = vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE)))
+		return(-1);
+	if(comm_copydata(current->mm->context.segments,
+						LDT_ENTRIES*LDT_ENTRY_SIZE, 0))
+	{
+		vfree(current->mm->context.segments);
+		mm->context.segments = NULL;
+		return(-1);
+	}
+	mm->context.cpuvalid = 1UL << smp_processor_id();
+	load_LDT(mm);
+	return(0);
+}
+
+void
+mig_do_receive_misc(struct mig_misc_h *m)
+{
+	int i, bit;
+	register struct task_struct *p = current;
+
+	if(p->mosix.dflags & DREMOTE)
+	{
+		p->ptrace |= m->ptrace;
+		p->nice = m->nice;
+		p->cap_effective = (p->cap_effective & ~REMOTE_CAPS) |
+							(m->caps & REMOTE_CAPS);
+		memcpy(p->mosix.features, m->features, sizeof(m->features));
+		task_lock(p);
+		if(m->stay)
+			p->mosix.stay |= DNOMIGRATE;
+		else
+			p->mosix.stay &= ~DNOMIGRATE;
+		task_unlock(p);
+		p->mosix.nmigs = m->nmigs;
+		remote_do_updinfo(&m->info);
+	}
+	else
+	{
+		p->ptrace &= ~PT_TRACESYS;
+		p->ptrace |= (m->ptrace & PT_TRACESYS);
+	}
+	p->mosix.dflags &= ~(DTRACESYS1|DTRACESYS2);
+	p->mosix.dflags |= m->dflags;
+	memcpy((caddr_t)p->thread.debugreg, (caddr_t)m->debugreg,
+		sizeof(m->debugreg));
+	p->it_prof_incr = m->it_prof_incr;
+	p->it_virt_incr = m->it_virt_incr;
+	p->mosix.deputy_regs = m->deputy_regs;
+	for(bit = 1, i = 0 ; i < sizeof(struct pt_regs) / sizeof(int) ;
+								i++ , bit <<= 1)
+	if(!(m->deputy_regs & bit))
+		((int *)p->mosix.altregs)[i] = ((int *)&m->regs)[i];
+	p->rlim[RLIMIT_CPU] = m->rlim_cpu;
+	p->rlim[RLIMIT_DATA] = m->rlim_data;
+	p->rlim[RLIMIT_STACK] = m->rlim_stack;
+	p->rlim[RLIMIT_RSS] = m->rlim_rss;
+	p->rlim[RLIMIT_AS] = m->rlim_as;
+#ifdef CONFIG_MOSIX_DFSA
+	p->rlim[RLIMIT_NOFILE] = m->rlim_nofile;
+	p->rlim[RLIMIT_FSIZE] = m->rlim_fsz;
+#endif /* CONFIG_MOSIX_DFSA */
+	if((p->mosix.deppe = m->deppe) != PE)
+		this_machine_is_favourite(p->mosix.deppe);
+	p->mosix.deccycle = m->deccycle;
+	p->mosix.decay = m->decay;
+	p->mosix.dpolicy = m->dpolicy;
+	p->mosix.mypid = m->mypid;
+	memcpy(p->mosix.depcost, m->depcost, sizeof(m->depcost));
+	p->mosix.depspeed = m->depspeed;
+	if(p->mosix.dflags & DREMOTE)
+		p->mosix.passedtime = m->passedtime;
+	else
+		p->mosix.passedtime = 0;
+	p->mosix.rpagecredit = m->pagecredit;
+	if(p->mosix.dflags & DREMOTE)
+	{
+		sprintf(p->comm, REMOTESTR2, m->mypid);
+		spin_lock_irq(&p->sigmask_lock);
+		p->mosix.asig |= m->asig.sigs;
+		spin_unlock_irq(&p->sigmask_lock);
+		while(m->asig.nforced--)
+		{
+			siginfo_t info;
+
+			comm_copydata(&info, sizeof(info), 0);
+			force_sig_info(info.si_signo, &info, p);
+		}
+	}
+	cli();
+	p->it_virt_value = m->it_virt_value;
+	p->it_prof_value = m->it_prof_value;
+	p->mosix.last_sigxcpu = m->lastxcpu;
+	sti();
+	if(p->mosix.dflags & DDEPUTY)
+		deputy_analyse_remote_signals(&m->asig);
+}
+
+int
+mig_do_receive(void)
+{
+	struct mosix_task *m = &current->mosix;
+	int type;
+	void *head;
+	int hlen;
+	int (*mmap_func)(struct mmap_parameters_h *, int);
+	int got_not_coming = 0;
+
+	spin_lock_irq(&runqueue_lock);
+	m->dflags |= DINCOMING;
+	spin_unlock_irq(&runqueue_lock);
+	current->used_math = 0;
+	while(1)
+	{
+		switch(type = comm_recv(&head, &hlen))
+		{
+			case MIG_MM_STATS:
+				mig_do_receive_mm_stats((struct mm_stats_h *)head);
+				break;
+			case MIG_MM_AREA:
+				if(m->dflags & DREMOTE)
+					mmap_func = remote_mmap;
+				else
+					mmap_func = deputy_remmap;
+				if(mmap_func((struct mmap_parameters_h *)head, 1))
+				{
+#ifdef CONFIG_MOSIX_DEBUG
+					if(ds_debug & DSDEB_MIG)
+						printk("%s-mig_receive: map_area failed\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+					comm_free(head);
+					goto fail;
+				}
+				break;
+			case MIG_PAGE:
+				if(mig_do_receive_page(*((unsigned long *)head)))
+				{
+#ifdef CONFIG_MOSIX_DEBUG
+					if(ds_debug & DSDEB_MIG)
+						printk("%s-mig_receive: page failed\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+					comm_free(head);
+					goto fail;
+				}
+				break;
+			case MIG_FP:
+				mig_do_receive_fp((union i387_union *)head);
+				break;
+			case MIG_XFP:
+				mig_do_receive_xfp((union i387_union *)head);
+				break;
+			case MIG_LDT:
+				if(mig_do_receive_ldt())
+				{
+#ifdef CONFIG_MOSIX_DEBUG
+					if(ds_debug & DSDEB_MIG)
+						printk("%s-mig_receive: ldt failed\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+					comm_free(head);
+					goto fail;
+				}
+				break;
+			case MIG_MISC:
+				mig_do_receive_misc((struct mig_misc_h *)head);
+				comm_free(head);
+				spin_lock_irq(&runqueue_lock);
+				m->dflags &= ~DINCOMING;
+				spin_unlock_irq(&runqueue_lock);
+				flush_tlb();	/* for all the new pages */
+				comm_send(MIG_MISC|REPLY, NULL, 0, NULL, 0, 0);
+				return(0);
+			case MIG_NOT_COMING:
+				got_not_coming = 1;
+				goto fail;
+			default:
+				if(m->dflags & DDEPUTY)
+					deputy_communication_failed();
+#ifdef CONFIG_MOSIX_DEBUG
+				printk("%s - Bad Message Type (0x%x) on mig_do_receive\n",
+					desc_mostask(NULL), type);
+#endif /* CONFIG_MOSIX_DEBUG */
+				comm_free(head);
+				goto fail;
+		}
+		comm_free(head);
+		if((m->dflags & DREMOTE) && (mosadmin_mode_block || !NPE))
+			goto fail;
+	}
+	fail:
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & DSDEB_MIG)
+		printk("%s: Arrival Failed\n", desc_mostask(NULL));
+#endif /* CONFIG_MOSIX_DEBUG */
+
+	if(type >= 0)
+		comm_flushdata(COMM_ALLDATA);
+	spin_lock_irq(&runqueue_lock);
+	m->dflags &= ~DINCOMING;
+	spin_unlock_irq(&runqueue_lock);
+	if((m->dflags & DDEPUTY) && !got_not_coming)
+	{
+		/* receiving all the debris can take time and
+		   someone may need the memory meanwhile! */
+		current->mosix.pages_i_bring = 0;
+		do_munmap(current->mm, 0, PAGE_OFFSET);
+		while((type = comm_recv(&head, &hlen)) >= 0 &&
+			type != MIG_NOT_COMING)
+		{
+			comm_free(head);
+			comm_flushdata(COMM_ALLDATA);
+			if(type == MIG_MISC)
+				/* send anything but MIG_MISC|REPLY: */
+				/* they will then send MIG_NOT_COMING! */
+				comm_send(DEP_SYNC, NULL, 0, NULL, 0, 0);
+		}
+	}
+	return(-1);
+}
+
+void
+mig_set_lock(int lock)
+{
+	struct task_struct *p = current;
+
+	task_lock(p);
+	if (lock)
+		p->mosix.stay |= DNOMIGRATE;
+	else    
+		p->mosix.stay &= ~DNOMIGRATE;
+	task_unlock(p);
+	if(current->mosix.dflags & DDEPUTY)
+		deputy_request(DEP_UPDATE_LOCK, &lock, sizeof(int), NULL, 0, 0,
+								NULL, 0);
+}
+
+int
+remote_set_lock(int *lockp)
+{
+	mig_set_lock(*lockp);
+	comm_free(lockp);
+	return(comm_send(DEP_UPDATE_LOCK|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+mig_migrate(int to)
+{
+	if (to > 0)
+		return(passto(to, 0) ?
+			(mos_to_net(to, NULL) ? -ENETUNREACH : -ENXIO) : 0);
+
+	switch(to)
+	{
+		case DM_GOBACKHOME:
+			return(passto(GOBACKHOME, 0) ? -EDIST : 0);
+		case DM_BALANCE:
+			if(current->mosix.dflags & DDEPUTY)
+				coordinate(0, 0);
+			else
+				consider(0, NULL);
+			return(0);
+	}
+	return(-EINVAL);
+}
+
+int
+count_migrating_pages(void)
+{
+	return(run_over_dirty_pages(NULL, 0));
+}
diff -ruN linux-2.4.16/mos/mkdefcalls.c linux-2.4.16-mosix/mos/mkdefcalls.c
--- linux-2.4.16/mos/mkdefcalls.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/mkdefcalls.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sys.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct file;
+#define FILE	struct file
+
+extern int fprintf(FILE *, char *, ...);
+extern int fgets(char *, int, FILE *);
+extern int perror(char *);
+extern FILE *fopen(char *, char *);
+
+char line[2048];
+char sys_name[NR_syscalls][60];
+
+FILE *
+myopen(char *file, char *mode)
+{
+	FILE *ret = fopen(file, mode);
+
+	if(!ret)
+		perror(file);
+	return(ret);
+}
+
+int
+main(void)
+{
+	FILE *entry = myopen(ENTRY_IN, "r");
+	FILE *sysin = myopen(SYSCALLS_IN, "r");
+	FILE *sysout = myopen(SYSCALLS_OUT, "w");
+	register char *c;
+	register int i;
+	long t, time(long *);
+	char *ctime(long *);
+
+	time(&t);
+	while(fgets(line, 2048, entry) &&
+		strcmp(line, "ENTRY(sys_call_table)\n"))
+			;
+	for(i = 0 ; i < NR_syscalls && fgets(line, 2048, entry) ; i++)
+	if(!strncmp(line, "\t.long SYMBOL_NAME(", 19))
+	{
+		for(c = &line[19] ; *c && *c != ')' ; c++);
+		*c = '\0';
+		if(strcmp(&line[19], "sys_ni_syscall"))
+			strcpy(sys_name[i], &line[19]);
+	}
+	while(fgets(line, 2048, sysin))
+	if(!strncmp(line, "remote_sys_", 11) ||
+		!strncmp(line, "remote_old_", 11))
+	for(i = 0 ; i < NR_syscalls ; i++)
+	if(!strncmp(&line[7], sys_name[i], strlen(sys_name[i])) &&
+		line[7+strlen(sys_name[i])] == '(')
+	{
+		sys_name[i][0] = '\0';
+		break;
+	}
+	fprintf(sysout, "/* Please do not edit -- this file is created automatically */\n");
+	fprintf(sysout, "/* %.24s */\n\n", ctime(&t));
+	fprintf(sysout, "#include <linux/sched.h>\n");
+	fprintf(sysout, "#include <asm/ptrace.h>\n");
+	fprintf(sysout, "#include <mos/routines.h>\n\n");
+	for(i = 0 ; i < NR_syscalls ; i++)
+	if(sys_name[i][0])
+	{
+		fprintf(sysout, "long remote_%s(int n, struct pt_regs regs){\n", sys_name[i]);
+		fprintf(sysout, "return(remote_standard_system_call(n, &regs));\n}\n");
+	}
+	exit(0);
+}
diff -ruN linux-2.4.16/mos/mosadmin.c linux-2.4.16-mosix/mos/mosadmin.c
--- linux-2.4.16/mos/mosadmin.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/mosadmin.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/config.h>
+#include <linux/mosctl.h>
+#include <linux/mosix.h>
+#include <asm/hardirq.h>
+#include <asm/softirq.h>
+#include <linux/interrupt.h>
+#include <linux/smp_lock.h>
+#include <linux/mm.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/debug.h>
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
+int mosadmin_mode_stay;
+int mosadmin_mode_lstay;
+int mosadmin_mode_block;
+int mosadmin_mode_quiet;
+int mosadmin_mode_nomfs;
+int mosadmin_gateways;
+
+int backed_block;
+int backed_lstay;
+
+char bootexpel, expel_progress;
+static int in_bring, in_expel;
+
+int
+admin_set_mode(int mode, int on)
+{
+	int *m;
+
+	lock_mosix();
+	switch(mode)
+	{
+		case DS_STAY:
+			m = &mosadmin_mode_stay;
+			break;
+		case DS_LSTAY:
+			m = in_bring ? &backed_lstay : &mosadmin_mode_lstay;
+			break;
+		case DS_BLOCK:
+			m = in_expel ? &backed_block : &mosadmin_mode_block;
+			break;
+		case DS_QUIET:
+			m = &mosadmin_mode_quiet;
+			break;
+		case DS_NOMFS:
+			m = &mosadmin_mode_nomfs;
+			break;
+		default:
+			panic("admin_set_unknown_mode");
+			/*NOTREACHED*/
+	}
+	on = (on != 0);	/* sanity */
+	if(on == *m)
+	{
+		unlock_mosix();
+		return(0);
+	}
+	if(on)
+	switch (mode)
+	{
+		case DS_STAY:
+			printk(KERN_NOTICE "MOSIX: Automatic process-migration from this node disabled.\n");
+			break;
+		case DS_LSTAY:
+			printk(KERN_NOTICE "MOSIX: Auto-migration of local-processes from this node disabled.\n");
+			break;
+		case DS_BLOCK:
+			printk(KERN_NOTICE "MOSIX: This node will not accept further guest-processes.\n");
+			break;
+		case DS_QUIET:
+			printk(KERN_NOTICE "MOSIX: Automatic load-dissemination stopped.\n");
+			break;
+		case DS_NOMFS:
+			printk(KERN_NOTICE "MOSIX: This node will stop providing MFS services.\n");
+			break;
+	}
+	else
+	{
+		switch(mode)
+		{
+			case DS_STAY:
+				if(in_bring ? backed_lstay:mosadmin_mode_lstay)
+					printk(KERN_NOTICE "MOSIX: Auto-migration of guest-processes from this node re-enabled.\n");
+				else
+					printk(KERN_NOTICE "MOSIX: Auto-migration from this node re-enabled.\n");
+				break;
+			case DS_LSTAY:
+				if(mosadmin_mode_stay)
+					printk(KERN_NOTICE "MOSIX: Once auto-migration is enabled, local-processes may migrate as well.\n");
+				else
+					printk(KERN_NOTICE "MOSIX: Auto-migration of local-processes from this node re-enabled.\n");
+			break;
+			case DS_BLOCK:
+				printk(KERN_NOTICE "MOSIX: guest-processes now accepted again.\n");
+				break;
+			case DS_QUIET:
+				printk(KERN_NOTICE "MOSIX: Automatic load-dissemination resumed.\n");
+				break;
+			case DS_NOMFS:
+				printk(KERN_NOTICE "MOSIX: This node will may now provide MFS services.\n");
+				break;
+		}
+	}
+	*m = on;
+	unlock_mosix();
+#ifdef CONFIG_MOSIX_FS
+	if(mode == DS_NOMFS)
+		mfs_change_pe();
+#endif /* CONFIG_MOSIX_FS */
+	return (0);
+}
+
+int
+admin_get_mode(int mode)
+{
+	int ret;
+
+	switch(mode)
+	{
+		case DS_STAY:
+			return(mosadmin_mode_stay);
+		case DS_LSTAY:
+			lock_mosix();
+			ret = in_bring ? backed_lstay : mosadmin_mode_lstay;
+			unlock_mosix();
+			return(ret);
+		case DS_BLOCK:
+			lock_mosix();
+			ret = in_expel ? backed_block : mosadmin_mode_block;
+			unlock_mosix();
+			return(ret);
+		case DS_QUIET:
+			return(mosadmin_mode_quiet);
+		case DS_NOMFS:
+			return(mosadmin_mode_nomfs);
+	}
+	return (-EINVAL);
+}
+
+int
+my_mosix_status(void)
+{
+	int s = DS_MOSIX_UP;
+
+	if(mosix_config_get_pe())
+		s |= DS_MOSIX_DEF;
+	if(mosadmin_mode_stay)
+		s |= DS_STAY;
+	lock_mosix();
+	if(in_bring ? backed_lstay : mosadmin_mode_lstay)
+		s |= DS_LSTAY;
+	if(in_expel ? backed_block : mosadmin_mode_block)
+		s |= DS_BLOCK;
+	unlock_mosix();
+	if(mosadmin_mode_quiet)
+		s |= DS_QUIET;
+	if(mosadmin_mode_nomfs)
+		s |= DS_NOMFS;
+	return(s);
+}
+
+int
+expel(int boot)
+{
+	int left = 0, oleft;
+	int round = 0;
+	struct task_struct *p;
+	int err = 0;
+
+	if(boot)
+	{
+		if(current->mosix.dflags & DREMOTE)
+			printk("Foops: cannot expel myself.\n");
+
+		tasklist_lock = RW_LOCK_UNLOCKED;
+	}
+	else
+	{
+		lock_mosix();
+		if(in_expel)
+		{
+			unlock_mosix();
+			return(-EBUSY);
+		}
+		in_expel = 1;
+	}
+	backed_block = mosadmin_mode_block;
+	mosadmin_mode_block = 1;
+	if(!boot)
+		unlock_mosix();
+	while(1)
+	{
+		oleft = left;
+		left = 0;
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if((p->mosix.dflags & DREMOTE) && p != current &&
+			!(p->mosix.dflags & DFINISHED))
+		{
+			if(boot)
+				mosix_do_add_to_whereto(p, MUSTGOHOME);
+			else
+				mosix_add_to_whereto(p, MUSTGOHOME);
+			if(p->mosix.deppe != PE) /* don't count cheaters */
+				left++;
+		}
+		read_unlock(&tasklist_lock);
+		if(!left)
+		{
+			if(boot && round)
+				printk("Done. ");
+			else if(!backed_block)
+				printk(KERN_NOTICE "MOSIX: "
+					"All guest processes evacuated and"
+					" no further guests allowed in\n");
+			break;
+		}
+		if(boot && round++ == 0)
+		{
+			int this_cpu = smp_processor_id();
+
+			printk("Expelling...");
+			bootexpel = 1;
+			cli();
+			if(local_irq_count(this_cpu))
+			{
+				local_irq_count(this_cpu)--;
+#ifdef CONFIG_SMP
+				release_irqlock(this_cpu);
+#endif /* CONFIG_SMP */
+			}
+			while(in_softirq())
+				local_bh_enable();
+			sti();
+		}
+		if(boot)
+			printk("%d ", left);
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_EXPEL)
+			printk("expel sleep for %d left\n", left);
+#endif /* CONFIG_MOSIX_DEBUG */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(HZ);
+		if(signal_pending(current))
+		{
+			if(boot) /* do not worry about locking */
+				flush_signals(current);
+			else
+			{
+				lock_mosix();
+				mosadmin_mode_block = backed_block;
+				unlock_mosix();
+				in_expel = 0;
+				return(-EINTR);
+			}
+		}
+		if((boot && expel_progress) || left < oleft)
+			round = 1;
+		expel_progress = 0;
+		if(round == 100)
+		{
+			printk("Giving up\n");
+			lock_mosix();
+			mosadmin_mode_block = backed_block;
+			unlock_mosix();
+			err = -EINTR;
+			break;
+		}
+	}
+	if(!boot)
+	{
+		lock_mosix();
+		in_expel = 0;
+		unlock_mosix();
+	}
+	return(err);
+}
+
+int
+bring(void)
+{
+	register struct task_struct *p, *w = NULL;
+	int left;
+	int err = -EBUSY;
+
+	lock_mosix();
+	if(in_bring)
+	{
+		unlock_mosix();
+		return(-EBUSY);
+	}
+	in_bring = 1;
+	backed_lstay = mosadmin_mode_lstay;
+	mosadmin_mode_lstay = 1;
+	unlock_mosix();
+	while(1)
+	{
+		left = 0;
+		w = NULL;
+		read_lock(&tasklist_lock);
+		for_each_task(p)
+		if((p->mosix.dflags & DDEPUTY) ||
+			(p->mosix.whereto && !(p->mosix.dflags & DREMOTE)))
+		{
+			mosix_add_to_whereto(p, MUSTGOHOME);
+			if(p->mosix.deppe != PE) /* don't count cheating_for_test */
+			{
+				left++;
+				if(!w)
+				{
+					w = p;
+					get_task_struct(w);
+				}
+			}
+		}
+		read_unlock(&tasklist_lock);
+		if(!left)
+		{
+			if(!backed_lstay)
+				printk(KERN_NOTICE "MOSIX: "
+					"All local processes brought home"
+					" and will not auto-migrate away\n");
+			err = 0;
+			break;
+		}
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_EXPEL)
+			printk("bring sleep for %d left\n", left);
+#endif /* CONFIG_MOSIX_DEBUG */
+		tell_process(w, DREQ_HOMEWAKE);
+		interruptible_sleep_on_timeout(mos_to_waitp(&w->mosix), HZ);
+		free_task_struct(w);
+		if(signal_pending(current))
+		{
+			lock_mosix();
+			mosadmin_mode_lstay = backed_lstay;
+			unlock_mosix();
+			err = -EINTR;
+			break;
+		}
+	}
+	lock_mosix();
+	in_bring = 0;
+	unlock_mosix();
+	return(err);
+}
diff -ruN linux-2.4.16/mos/mosproc.c linux-2.4.16-mosix/mos/mosproc.c
--- linux-2.4.16/mos/mosproc.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/mosproc.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,2250 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Oren Laadan, Amnon Shiloh.
+ * Some stuff 'borrowed' from "fs/proc".
+ */
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+#include <linux/proc_fs.h>
+#include <linux/mosix.h>
+#include <linux/mosctl.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/version.h>
+#include <linux/swap.h>
+#include <mos/protocol.h>
+#include <mos/debug.h>
+#include <mos/request.h>
+#include <linux/mosix.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+#include <linux/mfs.h>
+#endif /* CONFIG_MOSIX_FS */
+
+#ifdef CONFIG_MOSIX_DEBUG
+static int debug_proc;
+#endif /* CONFIG_MOSIX_DEBUG */
+
+/* general interface */
+
+static int zero = 0;
+static int one = 1;
+static int uintmax = 0x7fffffff;
+
+typedef struct ctl_mosix ctl_mosix;
+
+typedef ssize_t ctl_mosix_t (ctl_mosix *, int, struct file *, void *, size_t *);
+
+struct ctl_mosix {
+	int ctl_name;
+	const char *procname;
+	void *data;
+	int maxlen;
+	mode_t mode;
+	ctl_mosix_t *handler;
+	struct inode_operations *alt_iops;
+	struct file_operations *alt_fops;
+	void *extra[2];
+};
+
+/* values of 'do_intarr' 'write' argument: */
+#define CTLF_SIMPLE	0x01	/* nothing special */
+#define CTLF_UNSIGNED	0x02	/* use unsigned semantics */
+#define CTLF_MINMAXP	0x04	/* use min/max (via pointer) */
+#define CTLF_MINMAXV	0x08	/* use min/max (via values) */
+#define CTLF_BOOLEAN	0x10	/* boolean values (0/1) */
+#define	CTLF_POSITIVE	0x20	/* > 1 */
+
+static void proc_mosix_register(struct proc_dir_entry *de, ctl_mosix *table);
+
+static ssize_t do_intarr(ctl_mosix *, int, struct file*, void *, size_t *, int);
+static inline ssize_t get_intarr(struct file *, const char *, size_t,
+				 struct ctl_mosix *);
+static inline ssize_t put_intarr(struct file *, const char *, size_t,
+				 struct ctl_mosix *);
+
+static inline ctl_mosix_t ctl_boolean;
+static inline ctl_mosix_t ctl_uintarr;
+static inline ctl_mosix_t ctl_positive;
+static inline ctl_mosix_t ctl_minmaxv;
+
+/* dynamic directories: */
+/* the following are Or'ed with the pid/node << 16 */
+enum
+{
+	PROC_REMPID_INO = PROC_MOSIX_USE_START,
+	PROC_REMPID_FROM,
+	PROC_REMPID_GOTO,
+	PROC_REMPID_STATM,
+	PROC_REMPID_STATS,
+	PROC_REMPID_IDENT,
+	PROC_NODEID_INO,
+	PROC_NODEID_CPUS,
+	PROC_NODEID_INFO,
+	PROC_NODEID_LOAD,
+	PROC_NODEID_MEM,
+	PROC_NODEID_RMEM,
+	PROC_NODEID_SPEED,
+	PROC_NODEID_TMEM,
+	PROC_NODEID_STATUS,
+	PROC_NODEID_UTIL,
+#ifdef CONFIG_MOSIX_RESEARCH
+	PROC_NODEID_RIO,
+ 	PROC_NODEID_WIO,
+#endif /* CONFIG_MOSIX_RESEARCH */
+};
+
+struct subnames
+{
+	int id;
+	char *name;
+	int namelen;
+};
+
+struct subnames rempid_subs[] =
+{
+	{PROC_REMPID_FROM, "from", 4},
+	{PROC_REMPID_GOTO, "goto", 4},
+	{PROC_REMPID_STATM, "statm", 5},
+	{PROC_REMPID_STATS, "stats", 5},
+	{PROC_REMPID_IDENT, "identity", 8},
+	{}
+}, nodeid_subs[] =
+{
+	{PROC_NODEID_CPUS, "cpus", 4},
+	{PROC_NODEID_LOAD, "load", 4},
+	{PROC_NODEID_MEM, "mem", 3},
+	{PROC_NODEID_RMEM, "rmem", 4},
+	{PROC_NODEID_SPEED, "speed", 5},
+	{PROC_NODEID_TMEM, "tmem", 4},
+	{PROC_NODEID_STATUS, "status", 6},
+	{PROC_NODEID_UTIL, "util", 4},
+#ifdef CONFIG_MOSIX_RESEARCH
+	{PROC_NODEID_RIO, "rio", 3},
+ 	{PROC_NODEID_WIO, "wio", 3},
+#endif /* CONFIG_MOSIX_RESEARCH */
+	{}
+};
+
+static ssize_t proc_mosix_sub_read(struct file *, char *, size_t, loff_t *);
+static ssize_t proc_mosix_sub_write(struct file *, const char *, size_t, loff_t *);
+
+static struct file_operations proc_mosix_sub_file_operations =
+{
+	read:	proc_mosix_sub_read,
+	write:	proc_mosix_sub_write,
+};
+
+static struct inode_operations proc_mosix_sub_inode_operations =
+{
+};
+
+static int proc_mosix_sub_readdir(struct file *, void *, filldir_t);
+static struct dentry *proc_mosix_sub_lookup(struct inode *, struct dentry *);
+
+static struct file_operations proc_mosix_subdir_file_operations =
+{
+	readdir: proc_mosix_sub_readdir,
+};
+
+static struct inode_operations proc_mosix_subdir_inode_operations =
+{
+	lookup: proc_mosix_sub_lookup,
+};
+
+static int proc_mosix_nodes_readdir(struct file *, void *, filldir_t);
+static struct dentry *proc_mosix_nodes_lookup(struct inode *,struct dentry *);
+
+static struct file_operations proc_mosix_nodes_file_operations =
+{
+	readdir: proc_mosix_nodes_readdir,
+};
+
+static struct inode_operations proc_mosix_nodes_inode_operations =
+{
+	lookup: proc_mosix_nodes_lookup,
+};
+
+static int proc_mosix_remote_readdir(struct file *, void *, filldir_t);
+static struct dentry *proc_mosix_remote_lookup(struct inode *,struct dentry *);
+
+static struct file_operations proc_mosix_remote_file_operations =
+{
+	readdir: proc_mosix_remote_readdir,
+};
+
+static struct inode_operations proc_mosix_remote_inode_operations =
+{
+	lookup:	proc_mosix_remote_lookup,
+};
+
+static struct proc_dir_entry proc_mosix_nodes = {
+        0, 5, "nodes",
+        S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
+        0, &proc_mosix_nodes_inode_operations,
+	&proc_mosix_nodes_file_operations
+};
+
+static struct proc_dir_entry proc_mosix_remote = {
+        0, 6, "remote",
+        S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
+        0, &proc_mosix_remote_inode_operations,
+	&proc_mosix_remote_file_operations
+};
+
+static ssize_t proc_mosix_set_remote_goto(struct file*,int,const char*,size_t);
+static int proc_mosix_get_remote_from(struct task_struct *, char *);
+static int proc_mosix_get_remote_stats(struct task_struct *, char *);
+static int proc_mosix_get_remote_identity(struct task_struct *, char *);
+
+static int
+proc_mosix_delete_dentry(struct dentry *dentry)
+{
+	return(1);
+}
+
+static struct dentry_operations proc_mosix_dynamic_dentry_operations =
+{
+	d_delete: proc_mosix_delete_dentry
+};
+
+/* static directories: */
+
+static inline ssize_t proc_readmosix(struct file*,char*,size_t,loff_t*);
+static inline ssize_t proc_writemosix(struct file*,const char*,size_t,loff_t*);
+
+static struct file_operations proc_mosix_file_operations =
+{
+	read: proc_readmosix,
+	write: proc_writemosix,
+};
+
+static loff_t proc_lseekmosixinfo(struct file *, long long, int);
+
+static struct file_operations proc_mosix_info_file_operations =
+{
+	llseek:	proc_lseekmosixinfo,
+	read:	proc_readmosix,
+	write:	proc_writemosix,
+};
+
+/* /proc/mosix/admin: */
+
+enum {
+	ADMIN_CONFIG = 1, ADMIN_STAY, ADMIN_LSTAY, ADMIN_BLOCK, ADMIN_QUIET,
+	ADMIN_NOMFS, ADMIN_EXPEL, ADMIN_BRING, ADMIN_SPEED, ADMIN_SSPEED,
+	ADMIN_OVERHEADS, ADMIN_SLOWDECAY, ADMIN_FASTDECAY, ADMIN_DECAYINTERVAL,
+	ADMIN_GATEWAYS, ADMIN_MOSPE, ADMIN_VERSION,
+#ifdef CONFIG_MOSIX_DFSA
+	ADMIN_DFSALINKS,
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	ADMIN_MFSCOSTS, ADMIN_MFS_TUNEINFO, ADMIN_MFSKILL,
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_UDB
+	ADMIN_DEBUGGER, ADMIN_INSMOD, ADMIN_INSUDB,
+#endif /* CONFIG_MOSIX_UDB */
+};
+
+static ctl_mosix_t ctl_admin_gateways;
+static ctl_mosix_t ctl_admin_mospe;
+static ctl_mosix_t ctl_admin_config;
+static ctl_mosix_t ctl_admin_expel;
+static ctl_mosix_t ctl_admin_bring;
+static ctl_mosix_t ctl_admin_speed;
+static ctl_mosix_t ctl_admin_mode;
+static ctl_mosix_t ctl_admin_slowdecay;
+static ctl_mosix_t ctl_admin_fastdecay;
+static ctl_mosix_t ctl_admin_decayinterval;
+static ctl_mosix_t ctl_admin_overheads;
+static ctl_mosix_t ctl_admin_version;
+#ifdef CONFIG_MOSIX_UDB
+static ctl_mosix_t ctl_admin_debugger;
+static ctl_mosix_t ctl_admin_insmod;
+#endif /* CONFIG_MOSIX_UDB */
+#ifdef CONFIG_MOSIX_DFSA
+static ctl_mosix_t ctl_admin_dfsalinks;
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+static ctl_mosix_t ctl_admin_mfskill;
+static ctl_mosix_t ctl_admin_mfscosts;
+#endif /* CONFIG_MOSIX_FS */
+
+static struct ctl_mosix admin_ctl[] = {
+	{ ADMIN_CONFIG, "config", NULL, 0, 0644, ctl_admin_config },
+	{ ADMIN_STAY, "stay", NULL, sizeof(int), 0644, ctl_admin_mode },
+	{ ADMIN_LSTAY, "lstay", NULL, sizeof(int), 0644, ctl_admin_mode },
+	{ ADMIN_BLOCK, "block", NULL, sizeof(int), 0644, ctl_admin_mode },
+	{ ADMIN_QUIET, "quiet", NULL, sizeof(int), 0644, ctl_admin_mode },
+	{ ADMIN_NOMFS, "nomfs", NULL, sizeof(int), 0644, ctl_admin_mode },
+	{ ADMIN_EXPEL, "expel", NULL, 0, 0200, ctl_admin_expel },
+	{ ADMIN_BRING, "bring", NULL, 0, 0200, ctl_admin_bring },
+	{ ADMIN_SPEED, "speed", NULL, sizeof(int), 0644, ctl_admin_speed },
+	{ ADMIN_SSPEED, "sspeed", &standard_speed, sizeof(int), 0644,
+		ctl_positive },
+	{ ADMIN_OVERHEADS, "overheads", mosix_cost, sizeof(mosix_cost), 0644,
+		ctl_admin_overheads },
+	{ ADMIN_SLOWDECAY, "slowdecay", NULL, sizeof(int), 0644,
+		ctl_admin_slowdecay },
+	{ ADMIN_FASTDECAY, "fastdecay", NULL, sizeof(int), 0644,
+		ctl_admin_fastdecay },
+	{ ADMIN_DECAYINTERVAL, "decayinterval", NULL, sizeof(int), 0644,
+		ctl_admin_decayinterval },
+	{ ADMIN_GATEWAYS, "gateways", NULL, 0, 0644, ctl_admin_gateways },
+	{ ADMIN_MOSPE, "mospe", NULL, 0, 0644, ctl_admin_mospe },
+	{ ADMIN_VERSION, "version", NULL, 0, 0444, ctl_admin_version },
+#ifdef CONFIG_MOSIX_DFSA
+	{ ADMIN_DFSALINKS, "dfsalinks", NULL, 0, 0644, ctl_admin_dfsalinks },
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_FS
+	{ ADMIN_MFSCOSTS, "mfscosts", mfs_cost, sizeof(mfs_cost), 0644,
+		ctl_admin_mfscosts },
+	{ ADMIN_MFSKILL, "mfskill", NULL, 0, 0200, ctl_admin_mfskill },
+#endif /* CONFIG_MOSIX_FS */
+#ifdef CONFIG_MOSIX_UDB
+	{ ADMIN_DEBUGGER, "debugger", NULL, 0, 0200, ctl_admin_debugger },
+	{ ADMIN_INSMOD, "insmod", NULL, 0, 0200, ctl_admin_insmod },
+#endif /* CONFIG_MOSIX_UDB */
+	{ 0 }
+};
+
+enum {
+	DECAY_CPUJOB = 1, DECAY_IOJOB, DECAY_SLOW, DECAY_FAST, DECAY_OWN,
+	DECAY_INHERIT, DECAY_EXEC, DECAY_EXECONCE, DECAY_CLEAR
+};
+
+/* /proc/mosix/decay: */
+
+static ctl_mosix_t ctl_decay;
+
+static struct ctl_mosix decay_ctl[] = {
+	{ DECAY_CPUJOB,	   "cpujob",   NULL, 0, 0666, ctl_decay },
+	{ DECAY_IOJOB,	   "iojob",    NULL, 0, 0666, ctl_decay },
+	{ DECAY_SLOW,	   "slow",     NULL, 0, 0666, ctl_decay },
+	{ DECAY_FAST,	   "fast",     NULL, 0, 0666, ctl_decay },
+	{ DECAY_OWN,	   "own",      NULL, 0, 0666, ctl_decay },
+	{ DECAY_INHERIT,   "inherit",  NULL, 0, 0666, ctl_decay },
+	{ DECAY_EXEC,	   "exec",     NULL, 0, 0666, ctl_decay },
+	{ DECAY_EXECONCE,  "execonce", NULL, 0, 0666, ctl_decay },
+	{ DECAY_CLEAR,	   "clear",    NULL, 0, 0222, ctl_decay },
+	{ 0 }
+};
+
+/* /proc/mosix/info: */
+
+enum
+{
+	INFO_CPUS = 1, INFO_INFOS, INFO_LOADS, INFO_MEMS, INFO_RMEMS,
+	INFO_SPEEDS, INFO_TMEMS, INFO_STATA, INFO_UTILS,
+#ifdef CONFIG_MOSIX_RESEARCH
+	INFO_RIO, INFO_WIO,
+#endif /* CONFIG_MOSIX_RESEARCH */
+};
+
+static ctl_mosix_t ctl_info_fill;
+static ctl_mosix_t ctl_info_infos;
+
+static struct ctl_mosix info_ctl[] = {
+	{ INFO_LOADS,	"loads",  NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_SPEEDS,	"speeds", NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_CPUS,	"cpus",   NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_MEMS,	"mems",   NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_RMEMS,	"rmems",  NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_TMEMS,	"tmems",  NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_UTILS,	"utils",  NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_STATA,	"stata",  NULL, 0, 0444, ctl_info_fill,
+		NULL, &proc_mosix_info_file_operations },
+	{ INFO_INFOS,	"infos",  NULL, 0, 0444, ctl_info_infos,
+		NULL, &proc_mosix_info_file_operations },
+#ifdef CONFIG_MOSIX_RESEARCH
+	{ INFO_RIO,	"rios",  NULL, 0, 0444, ctl_info_fill,
+ 		NULL, &proc_mosix_info_file_operations },
+ 	{ INFO_WIO,	"wios",  NULL, 0, 0444, ctl_info_fill,
+ 		NULL, &proc_mosix_info_file_operations },
+#endif /* CONFIG_MOSIX_RESEARCH */
+	{ 0 }
+};
+
+#ifdef CONFIG_MOSIX_DFSA
+static ssize_t
+ctl_admin_dfsalinks(ctl_mosix *ctl, int write, struct file *filp,
+	       void *buf, size_t *len)
+{
+	ssize_t error = 0;
+	int l;
+	char *filename = NULL, c, *e;
+	loff_t pos = filp->f_pos;
+	int done = 0;
+	int more = 1;
+
+	while(write)
+	{
+		if(!filename && !(filename = __getname()))
+			return(done ? : -ENOMEM);
+		for(e = filename , l = 0 ; l < *len ; l++)
+		if(get_user(c, ((char *)buf)++))
+		{
+			putname(filename);
+			return(done ? : -EFAULT);
+		}
+		else if(c == '\0')
+		{
+			more = 0;
+			*e++ = '\0';
+			break;
+		}
+		else if(c == '\n')
+		{
+			*e++ = '\0';
+			break;
+		}
+		else if(l == PAGE_SIZE-1)
+		{
+			putname(filename);
+			return(done ? : -ENAMETOOLONG);
+		}
+		else
+			*e++ = c;
+		if(l == *len)
+		{
+			putname(filename);
+			return(done ? : -EINVAL);
+		}
+		l = e - filename;
+		if(filename[0] == '-')
+		{
+			if(filename[1])
+				error = dfsa_dellink(&filename[1]);
+			else
+				error = dfsa_clearlinks();
+		}
+		else
+			error = dfsa_addlink(&filename[filename[0] == '+']);
+		putname(filename);
+		if(error)
+			return(done ? : error);
+		pos += l;
+		filp->f_pos = pos;
+		done += l;
+		if(!more || !(*len -= l))
+			return(done);
+	}
+	/* READ */
+	if(!*len)
+		return(0);
+	if(!(filename = dfsa_showlinks()))
+		error = -ENOMEM;
+	else if(pos < (l = strlen(filename)))
+	{
+		filename += pos;
+		l -= pos;
+		if(l > *len)
+			l = *len;
+		if(copy_to_user(buf, filename, l))
+			error = -EFAULT;
+		else
+			*len = l;
+	}
+	else
+		*len = 0;
+	if(filename)
+		kfree(filename);
+	if(!error)
+		filp->f_pos = pos + *len;
+	return (error ? : 0);
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
+void
+mosix_proc_init(void)
+{
+	struct proc_dir_entry *parent;
+
+	proc_register(proc_mosix, &proc_mosix_remote);
+
+	proc_register(proc_mosix, &proc_mosix_nodes);
+
+	parent = proc_mkdir("mosix/info", NULL);
+	proc_mosix_register(parent, info_ctl);
+
+	parent = proc_mkdir("mosix/decay", NULL);
+	proc_mosix_register(parent, decay_ctl);
+
+	parent = proc_mkdir("mosix/admin", NULL);
+	proc_mosix_register(parent, admin_ctl);
+}
+
+static void
+proc_mosix_register(struct proc_dir_entry *root, ctl_mosix *table)
+{
+	int mode;
+	struct proc_dir_entry *de;
+
+	for ( ; table->procname ; table++)
+	{
+		mode = table->mode | S_IFREG;
+		de = create_proc_entry(table->procname, mode, root);
+		if (!de) {
+			printk("proc_mosix_register: create_proc_entry"
+				" failed for %s!\n", table->procname);
+			mosix_panic("proc_mosix_register: null de");
+			continue;
+		}
+		de->data = (void *) table;
+		de->proc_iops = table->alt_iops ? : NULL;
+		de->proc_fops = table->alt_fops ? : &proc_mosix_file_operations;
+	}
+}
+
+static ssize_t
+do_rw_mosix(int write, struct file *file, char *buf, size_t count, loff_t *ppos)
+{
+	struct proc_dir_entry *de;
+	struct ctl_mosix *ctl;
+	ssize_t res;
+	ssize_t error;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("%d(%s)-do_rw_mosix: 1\n", current->pid, current->comm);
+#endif
+
+	de = (struct proc_dir_entry *) file->f_dentry->d_inode->u.generic_ip;
+	if (!de || !de->data)
+		return (-ENOTDIR);
+	ctl = (struct ctl_mosix *) de->data;
+	if (!ctl || !ctl->handler)
+		return (-ENOTDIR);
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("%d(%s)-do_rw_mosix: 2\n", current->pid, current->comm);
+#endif
+	
+	res = count;
+	if((error = (*ctl->handler) (ctl, write, file, buf, &res)))
+		res = error;
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("%d(%s)-do_rw_mosix: error = %d\n",
+			current->pid, current->comm, error);
+#endif
+	return (res);
+}
+
+static inline ssize_t
+proc_readmosix(struct file *file, char *buf, size_t count, loff_t *ppos)
+{
+	return (do_rw_mosix(0, file, buf, count, ppos));
+}
+
+static inline ssize_t
+proc_writemosix(struct file *file, const char *buf, size_t count, loff_t *ppos)
+{
+	return(do_rw_mosix(1, file, (char *) buf, count, ppos));
+}
+
+#define TMPBUFLEN 20
+
+static ssize_t
+do_intarr(ctl_mosix *ctl, int write, struct file *filp,
+	  void *buffer, size_t *lenp, int scale)
+{
+	int *datap, vleft, first=1, len, left, neg, val;
+	int *min = NULL, *max = NULL;
+	char buf[TMPBUFLEN], *p;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("%d(%s)-do_intarr: 1\n", current->pid, current->comm);
+#endif
+
+	if (!ctl->data || !ctl->maxlen || !*lenp ||
+	    (filp->f_pos && !write)) {
+		*lenp = 0;
+		return 0;
+	}
+	
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("%d(%s)-do_intarr: 2\n", current->pid, current->comm);
+#endif
+
+	datap = (int *) ctl->data;
+	if (write & CTLF_BOOLEAN) {
+		min = &zero;
+		max = &one;
+	} else if(write & CTLF_POSITIVE) {
+		min = &one;
+		max = &uintmax;
+	} else if (write & CTLF_UNSIGNED) {
+		min = &zero;
+		max = &uintmax;
+	} else if (write & CTLF_MINMAXP) {
+		min = ((int *) ctl->extra[0]) - 1;
+		max = ((int *) ctl->extra[1]) - 1;
+	} else if (write & CTLF_MINMAXV) {
+		min = (int *) &(ctl->extra[0]);
+		max = (int *) &(ctl->extra[1]);
+	}
+		
+	vleft = ctl->maxlen / sizeof(int);
+	left = *lenp;
+	
+	for (; left && vleft--; datap++, first=0) {
+
+#ifdef CONFIG_MOSIX_DEBUG
+		if (debug_proc)
+			printk("%d(%s)-do_intarr: left=%d, vleft=%d, wrt=%d\n",
+				current->pid,current->comm,left,vleft, write);
+#endif
+
+		if (write) {
+			
+			int nex = TMPBUFLEN;
+			while (left) {
+				char c;
+				if(nex == TMPBUFLEN)
+				{
+					len = left;
+					if(len > TMPBUFLEN)
+						len = TMPBUFLEN;
+					if(copy_from_user(buf, buffer, len))
+						return(-EFAULT);
+					nex = 0;
+				}
+				c = buf[nex++];
+				if (!isspace(c))
+					break;
+				left--;
+				((char *) buffer)++;
+			}
+			if (!left)
+				break;
+			neg = 0;
+			len = left;
+			if (len > TMPBUFLEN-1)
+				len = TMPBUFLEN-1;
+			if(copy_from_user(buf, buffer, len))
+				return -EFAULT;
+			buf[len] = 0;
+			p = buf;
+			if (*p == '-' && left > 1) {
+				neg = 1;
+				left--, p++;
+			}
+			if (*p < '0' || *p > '9')
+				break;
+			val = simple_strtoul(p, &p, 0) * scale;
+			len = p-buf;
+			if ((len < left) && *p && !isspace(*p))
+				break;
+			if (neg)
+				val = -val;
+			buffer += len;
+			left -= len;
+
+			if (write & CTLF_MINMAXP) {
+				min++;
+				max++;
+			}
+
+#ifdef CONFIG_MOSIX_DEBUG
+			if (debug_proc) {
+				printk("%d(%s)-do_intarr: val = %d ",
+					current->pid, current->comm, val);
+				if (min)
+					printk("min = %d ", *min);
+				if (max)
+					printk("max = %d ", *max);
+				printk("\n");
+			}
+#endif
+
+			if (min && val < *min)
+				continue;
+			if (max && val > *max)
+				continue;
+
+#ifdef CONFIG_MOSIX_DEBUG
+			if (debug_proc)
+				printk("%d(%s)-do_intarr: setting val\n",
+					current->pid, current->comm);
+#endif
+
+			*datap = val;
+		} else {
+			p = buf;
+			if (!first)
+				*p++ = '\t';
+			sprintf(p, "%d", (*datap) / scale);
+			len = strlen(buf);
+			if (len > left)
+				len = left;
+			if(copy_to_user(buffer, buf, len))
+				return -EFAULT;
+			left -= len;
+			buffer += len;
+		}
+	}
+
+	if (!write && !first && left) {
+		if(put_user('\n', (char *) buffer))
+			return -EFAULT;
+		left--, buffer++;
+	}
+
+	if (write) {
+		int nex = TMPBUFLEN;
+
+		p = (char *) buffer;
+		while (left) {
+			char c;
+
+			if(nex == TMPBUFLEN)
+			{
+				len = left;
+				if(len > TMPBUFLEN)
+					len = TMPBUFLEN;
+				if(copy_from_user(buf, p, len))
+					return(-EFAULT);
+				nex = 0;
+			}
+			c = buf[nex++];
+			p++;
+			if (!isspace(c))
+				break;
+			left--;
+		}
+	}
+	if (write && first)
+		return -EINVAL;
+	*lenp -= left;
+	filp->f_pos += *lenp;
+	return 0;
+}
+
+static inline ssize_t
+get_intarr(struct file *file,const char *buf,size_t count,struct ctl_mosix *ctl)
+{
+	ssize_t res;
+	ssize_t error;
+
+	res = count;
+	error = (*ctl->handler) (ctl, 1, file, (char *)buf, &res);
+
+	if (error)
+		return (error);
+	return (res);
+}
+
+static inline ssize_t
+put_intarr(struct file *file,const char *buf,size_t count,struct ctl_mosix *ctl)
+{
+	ssize_t res;
+	ssize_t error;
+
+	res = count;
+	error = (*ctl->handler) (ctl, 0, file, (char *)buf, &res);
+
+	if (error)
+		return (error);
+	return (res);
+}
+
+static inline ssize_t
+ctl_boolean(ctl_mosix *ctl,int write,struct file *filp,void *buf,size_t *len)
+{
+	return (do_intarr(ctl, write ? CTLF_BOOLEAN : 0, filp, buf, len, 1));
+}
+
+static inline ssize_t
+ctl_uintarr(ctl_mosix *ctl,int write,struct file *filp,void *buf,size_t *len)
+{
+	return (do_intarr(ctl, write ? CTLF_UNSIGNED : 0, filp, buf, len, 1));
+}
+
+static inline ssize_t
+ctl_positive(ctl_mosix *ctl,int write,struct file *filp,void *buf,size_t *len)
+{
+	return (do_intarr(ctl, write ? CTLF_POSITIVE : 0, filp, buf, len, 1));
+}
+
+static inline ssize_t
+ctl_minmaxv(ctl_mosix *ctl,int write,struct file *filp,void *buf,size_t *len)
+{
+	return (do_intarr(ctl, write ? CTLF_MINMAXV : 0, filp, buf, len, 1));
+}
+
+static ssize_t
+ctl_admin_gateways(ctl_mosix *ctl, int write, struct file *filp,
+		   void *buf, size_t *len)
+{
+	int val = mosadmin_gateways;
+	int error;
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_minmaxv};
+
+	tmpctl.data = &val;
+	tmpctl.extra[0] = (void *)0;
+	tmpctl.extra[1] = (void *)2;
+
+	if (write)
+		error = get_intarr(filp, buf, *len, &tmpctl);
+	else
+		error = put_intarr(filp, buf, *len, &tmpctl);
+	if (error < 0)
+		return (error);
+	*len = error;
+	if(write)
+	{
+		lock_mosix();
+		mosadmin_gateways = val;
+		mosinfo_update_gateways();
+		unlock_mosix();
+	}
+	return (0);
+}
+
+static ssize_t
+ctl_admin_mospe(ctl_mosix *ctl, int write, struct file *filp,
+		void *buf, size_t *len)
+{
+	int this, tent;
+
+	if (!*len || (filp->f_pos && !write)) {
+		*len = 0;
+		return 0;
+	}
+	if (write) {
+		int pe, error;
+		struct ctl_mosix tmpctl =
+			{ 0, "goto", NULL, sizeof(int), 0, ctl_minmaxv };
+
+		tmpctl.data = &pe;
+		tmpctl.extra[0] = (void *) 0;
+		tmpctl.extra[1] = (void *) MOSIX_MAX;
+
+		error = get_intarr(filp, buf, *len, &tmpctl);
+		if (error < 0)
+			return (error);
+		if(pe < 0)
+			return(-ENOSYS);
+		return (mosix_config_set_pe(pe));
+	} else {
+		int n;
+		char tmpbuf[20];
+
+		if (filp->f_pos)
+			return (0);
+		this = mosix_config_get_pe();
+		tent = mosix_config_get_tentative_pe();
+		if (this == tent)
+			sprintf(tmpbuf, "%d\n", this);
+		else
+			sprintf(tmpbuf, "%d (%d)\n", this, tent);
+		n = strlen(tmpbuf);
+		if(n > *len)
+			n = *len;
+		if (copy_to_user(buf, tmpbuf, n))
+			return(-EFAULT);
+		*len = n;
+		filp->f_pos += n;
+		return (0);
+	}
+}
+
+#ifdef CONFIG_MOSIX_FS
+static ssize_t
+ctl_admin_mfscosts(ctl_mosix *ctl, int write, struct file *filp,
+			void *buf, size_t *len)
+{
+	ssize_t result = ctl_uintarr(ctl, write, filp, buf, len);
+
+#ifdef CONFIG_MOSIX_TOPOLOGY
+	if(write)
+		info_update_mfscosts();
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	return(result);
+}
+
+static ssize_t
+ctl_admin_mfskill(ctl_mosix *ctl, int write, struct file *filp,
+	       void *buf, size_t *len)
+{
+	ssize_t error = 0;
+	int l;
+	char *filename;
+
+	if(!write)
+		return(-EPERM);
+	if(filp->f_pos)
+		return(0);
+	filename = getname(buf);
+	if(IS_ERR(filename))
+		return((int)filename);
+	l = strlen(filename);
+	if(l > *len)
+	{
+		filename[*len] = '\0';
+		l = *len;
+	}
+	if(l && filename[l-1] == '\n')
+		filename[--l] = '\0';
+	if(strchr(filename, '\n') || l >= *len)
+		error = -EINVAL;
+	else
+		error = mfs_kill(filename);
+	putname(filename);
+	if(!error)
+		filp->f_pos += *len;
+	return (error ? : 0);
+}
+#endif /* CONFIG_MOSIX_FS */
+
+static ssize_t
+ctl_admin_version(ctl_mosix *ctl, int write, struct file *filp,
+		  void *buf, size_t *len)
+{
+	int n, left;
+	char tmpbuf[100];
+
+	if ((filp->f_pos) || !*len) {
+		*len = 0;
+		return (0);
+	}
+
+	left = *len;
+	*len = 0;
+
+	sprintf(tmpbuf, "Mosix Version %d.%d.%d\nDFSA is %sabled\n"
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		"Maximum network topology = %d\n"
+#else
+		"Simple network topology\n"
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+		, MOSIX_VERSION_PARTS(MOSIX_KERNEL_VERSION),
+#ifdef CONFIG_MOSIX_DFSA
+		"en"
+#else
+		"dis"
+#endif /* CONFIG_MOSIX_DFSA */
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		, MAX_MOSIX_TOPOLOGY
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+		);
+	n = strlen(tmpbuf);
+	if(n > left)
+		n = left;
+	if (copy_to_user(buf, tmpbuf, n))
+		return (-EFAULT);
+	*len += n;
+	filp->f_pos += *len;
+	return (0);
+}
+
+#ifdef CONFIG_MOSIX_UDB
+static ssize_t
+ctl_admin_debugger(ctl_mosix *ctl, int write, struct file *filp,
+		   void *buf, size_t *len)
+{
+	int error, val;
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_boolean};
+
+	tmpctl.data = &val;
+
+	if (!write)
+		return (-EPERM);
+	error = get_intarr(filp, buf, *len, &tmpctl);
+	if (error < 0)
+		return (error);
+	if (val != 1)
+		return (-EINVAL);
+	mosix_debugger("/proc/mosix/admin/debugger");
+	return(0);
+}
+
+static ssize_t
+ctl_admin_insmod(ctl_mosix *ctl, int write, struct file *filp,
+		 void *buf, size_t *len)
+{
+	int copy = *len;
+	int error = 0;
+
+#ifdef CONFIG_MODULES
+	extern int udb_proc_insmod(char *buf, int copy);
+#else
+
+#define udb_proc_insmod(a,b)	(-ENXIO) 
+
+#endif /* CONFIG_MODULES */
+
+	if (!write)
+		return (-EPERM);
+	else if (filp->f_pos || !copy) {
+		*len = 0;
+		return (0);
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("ctl_admin_insmod: calling udb_proc_insmod()\n");
+#endif
+
+	error = udb_proc_insmod(buf, copy);
+
+	if (error < 0)
+		return (error);
+	*len = copy;
+	filp->f_pos += copy;
+	return (0);
+}
+#endif /* CONFIG_MOSIX_UDB */
+
+static ssize_t
+ctl_admin_config(ctl_mosix *ctl, int write, struct file *filp,
+		 void *buf, size_t *len)
+{
+	struct mosixnet *mos;
+	int copy = *len;
+	int pos = copy / sizeof(struct mosixnet);
+	int fpos = filp->f_pos / sizeof(struct mosixnet);
+	int error = 0;
+
+	/* position in this file is entry # in the config */
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("ctl_admin_config: 1\n");
+#endif
+
+	/* truncate read/write to multiples of sizeof(strcut mosixnet) */
+	if (*len % sizeof(struct mosixnet))
+		*len -= *len % sizeof(struct mosixnet);
+
+	if ((write && filp->f_pos) || !*len) {
+		*len = 0;
+		return (0);
+	}
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (debug_proc)
+		printk("ctl_admin_config: 2\n");
+#endif
+
+	if (write) {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (debug_proc)
+			printk("ctl_admin_config: 3\n");
+#endif
+		pos = copy / sizeof(struct mosixnet);
+		if(pos <= 0)
+		{
+			*len = 0;
+			return(0);
+		}
+		if (!(mos = (struct mosixnet *) kmalloc(copy, GFP_USER)))
+			return (-ENOMEM);
+		if (copy_from_user((char *) mos, buf, copy))
+		{
+			kfree(mos);
+			return (-EFAULT);
+		}
+		error = mosix_config_set_table(mos, pos,
+					mosix_config_get_tentative_pe());
+		if (error)
+			kfree((void *) mos);
+	} else {
+#ifdef CONFIG_MOSIX_DEBUG
+		if (debug_proc)
+			printk("ctl_admin_config: 4\n");
+#endif
+		pos = mosix_config_get_table(&mos, fpos, pos);
+		if (pos < 0)
+			return (pos);
+		copy = pos * sizeof(struct mosixnet);
+		if (copy)
+		{
+			if(copy_to_user(buf, (char *) mos, copy))
+				error = -EFAULT;
+			kfree((void *) mos);
+		}
+	}
+
+	if (error < 0)
+		return (error);
+	*len = copy;
+	filp->f_pos += copy;
+	return (0);
+}
+
+static ssize_t
+ctl_admin_expel(ctl_mosix *ctl, int write, struct file *filp,
+		void *buf, size_t *len)
+{
+	int val = 0;
+	int error;
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_boolean};
+
+	if (!write)
+		return (-EPERM);
+	
+	tmpctl.data = &val;
+	error = get_intarr(filp, buf, *len, &tmpctl);
+	if (error < 0)
+		return (error);
+	*len = error;
+	return (val ? expel(0) : 0);
+}
+
+static ssize_t
+ctl_admin_bring(ctl_mosix *ctl, int write, struct file *filp,
+		void *buf, size_t *len)
+{
+	int val = 0;
+	int error;
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_boolean};
+
+	if (!write)
+		return (-EPERM);
+	
+	tmpctl.data = &val;
+	error = get_intarr(filp, buf, *len, &tmpctl);
+	if (error < 0)
+		return (error);
+	*len = error;
+	return (val ? bring() : 0);
+}
+
+static ssize_t
+ctl_admin_speed(ctl_mosix *ctl, int write, struct file *filp,
+		void *buf, size_t *len)
+{
+	int val = cpuspeed;
+	int error;
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_minmaxv};
+
+	tmpctl.data = &val;
+	tmpctl.extra[0] = (void *)1;
+	tmpctl.extra[1] = (void *)65535;
+
+	if (write)
+		error = get_intarr(filp, buf, *len, &tmpctl);
+	else
+		error = put_intarr(filp, buf, *len, &tmpctl);
+	if (error < 0)
+		return (error);
+	*len = error;
+	if(write)
+	{
+		lock_mosix();
+		cpuspeed = val;
+		set_my_cpuspeed();
+		unlock_mosix();
+	}
+	return (0);
+}
+
+static ssize_t
+ctl_admin_mode(ctl_mosix *ctl, int write, struct file *filp,
+	       void *buf, size_t *len)
+{
+	int val, mode;
+	int error;
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_boolean};
+
+	tmpctl.data = &val;
+
+	switch (ctl->ctl_name) {
+		case ADMIN_STAY:
+			mode = DS_STAY;
+			break;
+		case ADMIN_LSTAY:
+			mode = DS_LSTAY;
+			break;
+		case ADMIN_BLOCK:
+			mode = DS_BLOCK;
+			break;
+		case ADMIN_QUIET:
+			mode = DS_QUIET;
+			break;
+		case ADMIN_NOMFS:
+			mode = DS_NOMFS;
+			break;
+		default:
+			panic("ctl_admin_mode: invalid ctl_name");
+	}
+
+	if (write) {
+		error = get_intarr(filp, buf, *len, &tmpctl);
+		if (error < 0)
+			return (error);
+		*len = error;
+		return (admin_set_mode(mode, val));
+	} else {
+		val = admin_get_mode(mode);
+		error = put_intarr(filp, buf, *len, &tmpctl);
+		if (error < 0)
+			return (error);
+		*len = error;
+		return (0);
+	}
+}
+
+static ssize_t
+ctl_admin_slowdecay(ctl_mosix *ctl, int write, struct file *filp,
+		    void *buf, size_t *len)
+{
+	ctl->data = (void *) &slow_alpha;
+	ctl->extra[0] = (void *) fast_alpha;
+	ctl->extra[1] = (void *) DECAY_QUOTIENT;
+	return (do_intarr(ctl, write ? CTLF_MINMAXV : 0, filp, buf, len, 1));
+}
+
+static ssize_t
+ctl_admin_fastdecay(ctl_mosix *ctl, int write, struct file *filp,
+		    void *buf, size_t *len)
+{
+	ctl->data = (void *) &fast_alpha;
+	ctl->extra[0] = (void *) 0;
+	ctl->extra[1] = (void *) slow_alpha;
+	return (do_intarr(ctl, write ? CTLF_MINMAXV : 0, filp, buf, len, 1));
+}
+
+static ssize_t
+ctl_admin_decayinterval(ctl_mosix *ctl, int write, struct file *filp,
+		        void *buf, size_t *len)
+{
+	ctl->data = (void *) &decay_interval;
+	ctl->extra[0] = (void *) 1;
+	ctl->extra[1] = (void *) 65535;
+	return (do_intarr(ctl, write ? CTLF_MINMAXV : 0, filp, buf, len, 1));
+}
+
+void
+proc_update_costs(void)
+{
+	register int i;
+	register struct task_struct *p;
+
+	lock_mosix();
+	for(i = 0 ; i < MAX_MOSIX_TOPOLOGY ; i++)
+	{
+		deputy_here[i].page = mosix_cost[i].PAGE_D;
+		deputy_here[i].syscall = mosix_cost[i].SYSCALL_D;
+		deputy_here[i].out = mosix_cost[i].COPYOUT_BASE_D;
+		deputy_here[i].outkb = mosix_cost[i].COPYOUT_PER_KB_D;
+		deputy_here[i].in = mosix_cost[i].COPYIN_BASE_D;
+		deputy_here[i].inkb = mosix_cost[i].COPYIN_PER_KB_D;
+#ifdef CONFIG_MOSIX_TOPOLOGY
+		deputy_here[i].first = mosix_cost[i].first;
+		deputy_here[i].last = mosix_cost[i].last;
+#endif /* CONFIG_MOSIX_TOPOLOGY */
+	}
+	info_update_costs();
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if(p->mosix.dflags & DDEPUTY)
+	{
+		tell_process(p, DREQ_UPDOVERHEADS);
+		wake_up_mosix(p);
+	}
+	read_unlock(&tasklist_lock);
+	unlock_mosix();
+}
+
+static ssize_t
+ctl_admin_overheads(ctl_mosix *ctl, int write, struct file *filp,
+			void *buf, size_t *len)
+{
+	ssize_t result = ctl_uintarr(ctl, write, filp, buf, len);
+
+	if(write)
+		proc_update_costs();
+	return(result);
+}
+
+static loff_t
+proc_lseekmosixinfo(struct file *filp, loff_t offset, int orig)
+{
+	switch (orig) {
+		case 0:
+			break;
+		case 1:
+			offset += filp->f_pos;
+			break;
+		case 2:
+			offset += mosix_config_get_limit();
+			break;
+		default:
+			return (-EINVAL);
+        }
+	if(offset < 0 || offset > MOSIX_MAX)
+		return(-EINVAL);
+	filp->f_pos = offset;
+	return (offset);
+}
+
+static ssize_t
+ctl_info_infos(ctl_mosix *ctl, int write, struct file *filp,
+	       void *buf, size_t *len)
+{
+	int end;
+	int n, err;
+
+	end = (*len / sizeof(struct mosix_info)) + filp->f_pos;
+	if(end > (n = mosix_config_get_limit()))
+		end = n;
+	*len = 0;
+	if((n = end - filp->f_pos) > 0)
+	{
+		if((err = balance_get_infos(filp->f_pos + 1, n,
+						(struct mosix_info *)buf, 1)))
+			return(err);
+		filp->f_pos += n;
+		*len = n * sizeof(struct mosix_info);
+	}
+
+	return (0);
+}
+
+#define	get_item(x, node, undef, notup) ( { \
+		struct mosix_info info; \
+		(void) balance_get_info(node, &info); \
+		(info.status & DS_MOSIX_UP) ? info.x : \
+		(info.status & DS_MOSIX_DEF) ? notup : undef; } )
+
+static ssize_t
+ctl_info_fill(ctl_mosix *ctl, int write, struct file *filp,
+	      void *buf, size_t *len)
+{
+	int i, end;
+	int val, total = 0;
+
+	end = (*len / sizeof(int)) + filp->f_pos;
+	if(end > (i = mosix_config_get_limit()))
+		end = i;
+	for (i = filp->f_pos + 1; i <= end; i++) {
+		switch (ctl->ctl_name) {
+			case INFO_LOADS:
+				val = get_item(load, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_SPEEDS:
+				val = get_item(speed, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_CPUS:
+				val = get_item(ncpus, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_MEMS:
+				val = get_item(mem, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_RMEMS:
+				val = get_item(rmem, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_TMEMS:
+				val = get_item(tmem, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_UTILS:
+				val = get_item(util, i, -ENXIO, -ENETUNREACH);
+				break;
+			case INFO_STATA:
+				val = get_item(status, i, 0, DS_MOSIX_DEF);
+				break;
+#ifdef CONFIG_MOSIX_RESEARCH
+ 			case INFO_RIO:
+ 				val = get_item(rio, i, -ENXIO, -ENETUNREACH);
+ 				break;
+ 			case INFO_WIO:
+ 				val = get_item(wio, i, -ENXIO, -ENETUNREACH);
+ 				break;
+#endif /* CONFIG_MOSIX_RESEARCH */
+			default:
+				mosix_panic("ctl_info_fill - bad name");
+				return (-EDIST);
+		}
+		if (copy_to_user(buf, (char *) &val, sizeof(int)))
+			return (-EFAULT);
+		filp->f_pos++;
+		buf += sizeof(int);
+		total += sizeof(int);
+	}
+	*len = total;
+	return (0);
+}
+
+static ssize_t
+ctl_decay(ctl_mosix *ctl, int write, struct file *filp, void *buf, size_t *len)
+{
+	int val, policy;
+	int error;
+	int (*func)(int);
+	int decay[2];
+	struct ctl_mosix tmpctl = {0, NULL, NULL, sizeof(int), 0, ctl_boolean};
+
+	tmpctl.data = &val;
+
+	switch (ctl->ctl_name) {
+		case DECAY_INHERIT:
+			func = decay_inherit;
+			goto r01w01;
+		case DECAY_EXEC:
+			func = decay_exec;
+			goto r01w01;
+		case DECAY_EXECONCE:
+			func = decay_execonce;
+		r01w01:
+			if (write) {
+				error = get_intarr(filp, buf, *len, &tmpctl);
+				if (error < 0)
+					return (error);
+				(*func)(val);
+			} else {
+				val = (*func)(-1);
+				error = put_intarr(filp, buf, *len, &tmpctl);
+				if (error < 0)
+					return (error);
+			}
+			break;
+
+		case DECAY_CPUJOB:
+			policy = DADV_CPU;
+			goto r01w1;
+		case DECAY_IOJOB:
+			policy = DADV_NOCPU;
+			goto r01w1;
+		case DECAY_SLOW:
+			policy = DADV_SLOWDECAY;
+			goto r01w1;
+		case DECAY_FAST:
+			policy = DADV_FASTDECAY;
+		r01w1:
+			if (write) {
+				error = get_intarr(filp, buf, *len, &tmpctl);
+				if (error < 0)
+					return (error);
+				if (val != 1)
+					return (-EINVAL);
+				decay_set(policy, 0, 1);
+			} else {
+				val = decay_get(policy);
+				error = put_intarr(filp, buf, *len, &tmpctl);
+				if (error < 0)
+					return (error);
+			}
+			break;
+
+		case DECAY_OWN:
+			tmpctl.data = (void *) decay;
+			tmpctl.maxlen = 2 * sizeof(int);
+			tmpctl.handler = ctl_uintarr;
+
+			/* to force an error in case of partial data */
+			decay[0] = decay[1] = 0;
+
+			if (write) {
+				error = get_intarr(filp, buf, *len, &tmpctl);
+				if (error < 0)
+					return (error);
+				if (decay[0] < 0 || decay[0] > DECAY_QUOTIENT
+					|| decay[1] < 1 || decay[1] > 65535)
+					return (-EINVAL);
+				decay_set(DADV_OWNDECAY, decay[0], decay[1]);
+			} else {
+				if (decay_get(DADV_OWNDECAY)) {
+					decay[0] = current->mosix.decay;
+					decay[1] = current->mosix.deccycle;
+				} else
+					tmpctl.maxlen = sizeof(int);
+				error = put_intarr(filp, buf, *len, &tmpctl);
+				if (error < 0)
+					return (error);
+			}
+			break;
+
+		case DECAY_CLEAR:
+			if (!write)
+				return (-EPERM);
+			error = get_intarr(filp, buf, *len, &tmpctl);
+			if (error < 0)
+				return (error);
+			if (val != 1)
+				return (-EINVAL);
+			decay_clear();
+			break;
+		default:
+			return (-EBADF);
+	}
+	*len = error;
+	return (0);
+}
+
+
+#define for_each_remote_task(p) \
+        for (p = &init_task ; (p = p->next_task) != &init_task ; ) \
+	        if(p->mosix.dflags & DREMOTE)
+
+
+#define NUMBUF	10
+
+static int
+proc_mosix_remote_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+	struct task_struct *p;
+	char buf[NUMBUF];
+	unsigned int nr = filp->f_pos;
+	pid_t *pids;
+	int k, n = 0;
+
+	if(filp->f_pos == 0)
+	{
+		if(filldir(dirent, ".", 1, 0, filp->f_dentry->d_inode->i_ino,
+								DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 1;
+	}
+	if(filp->f_pos == 1)
+	{
+		if(filldir(dirent, "..", 2, 1,
+			filp->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 2;
+	}
+
+	n = 1;
+	while(1)
+	{
+		k = count_guests(); /* usually correct, but not 100% reliable */
+		if(k > n)
+			n = k;
+		if(!(pids = (pid_t *)kmalloc(n * sizeof(pid_t), GFP_KERNEL)))
+			return(-ENOMEM);
+		read_lock(&tasklist_lock);
+		/* new guest(s) could come in while we waited for memory! */
+		k = 0;
+		for_each_remote_task(p)
+		{
+			if(k < n)
+				pids[k++] = p->pid;
+			else
+				k++;
+		}
+		read_unlock(&tasklist_lock);
+		if(k <= n)
+		{
+			n = k;
+			break;
+		}
+		n = k + 1;
+	}
+	nr = 2;
+	for(k = 0 ; k < n ; k++) {
+		unsigned int pid;
+		unsigned long i, j;
+
+		if(nr++ < filp->f_pos)
+			continue;
+		pid = pids[k];
+
+		for (j = NUMBUF, i = pid; i; i /= 10) {
+			j--;
+			buf[j] = '0' + (i % 10);
+		}
+		if (filldir(dirent, buf+j, NUMBUF-j, filp->f_pos,
+				(pid << 16) + PROC_REMPID_INO, DT_DIR) < 0)
+			break;
+		filp->f_pos++;
+	}
+	kfree(pids);
+	return(0);
+}
+
+static int
+proc_mosix_sub_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+	struct dentry *dp = filp->f_dentry;
+	int id = dp->d_inode->i_ino & ~0xffff;
+	struct subnames *s;
+	int i;
+
+	switch(dp->d_inode->i_ino & 0xffff)
+	{
+		case PROC_REMPID_INO:
+			s = rempid_subs;
+			break;
+		case PROC_NODEID_INO:
+			s = nodeid_subs;
+			break;
+		default:
+			printk("ino=0x%lx\n", dp->d_inode->i_ino);
+			panic("proc_mosix_sub_readdir");
+	}
+	if(filp->f_pos == 0)
+	{
+		if(filldir(dirent, ".", 1, 0, dp->d_inode->i_ino, DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 1;
+	}
+	if(filp->f_pos == 1)
+	{
+		if(filldir(dirent, "..", 2, 1, dp->d_parent->d_inode->i_ino,
+								DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 2;
+	}
+	for(i = 2 ; i < filp->f_pos ; i++)
+	if(s->name)
+		s++;
+	else
+		return(0);
+	while(s->name && filldir(dirent, s->name, strlen(s->name), filp->f_pos,
+						id | s->id, DT_REG) >= 0)
+	{
+		filp->f_pos++;
+		s++;
+	}
+	return(0);
+}
+
+static struct dentry *
+proc_mosix_sub_lookup(struct inode *dir, struct dentry *dentry)
+{
+	unsigned long dino = dir->i_ino;
+	struct subnames *s;
+	const char *name = dentry->d_name.name;
+	int len = dentry->d_name.len;
+	struct inode *inode = NULL;
+
+	switch(dino & 0xffff)
+	{
+		case PROC_REMPID_INO:
+			s = rempid_subs;
+			break;
+		case PROC_NODEID_INO:
+			s = nodeid_subs;
+			break;
+		default:
+			printk("ino=0x%lx\n", dino);
+			panic("proc_mosix_sub_lookup");
+	}
+	while(s->name)
+	if(s->namelen == len && !strncmp(s->name, name, len))
+	{
+		inode = proc_get_inode(dir->i_sb, (dino & ~0xffff)|s->id, NULL);
+		if(!inode)
+			return(ERR_PTR(-EINVAL));
+		switch(s->id)
+		{
+			case PROC_REMPID_GOTO:
+				inode->i_mode = S_IFREG | 0222;
+				break;
+			default:
+				inode->i_mode = S_IFREG | 0444;
+				break;
+		}
+		inode->i_op = &proc_mosix_sub_inode_operations;
+		inode->i_fop = &proc_mosix_sub_file_operations;
+		break;
+	}
+	else
+		s++;
+	dentry->d_op = &proc_mosix_dynamic_dentry_operations;
+	d_add(dentry, inode);
+	return(NULL);
+}
+
+int
+atoi16(const char *num, int len)
+{
+	int n = 0;
+	char c;
+
+	while(len-- > 0)
+	{
+		c = *num++;
+		if(c < '0' || c > '9')
+			return(0);
+		n = n * 10 + c - '0';
+		if(n & 0xffff0000)
+			return(0);
+	}
+	return(n);
+}
+
+static struct dentry *
+proc_mosix_remote_lookup(struct inode *dir, struct dentry *dentry)
+{
+	unsigned int pid, n;
+	struct task_struct *p;
+	struct inode *inode = NULL;
+
+	n = proc_mosix_remote.nlink;
+	read_lock(&tasklist_lock);
+	for_each_remote_task(p)
+		n++;
+	read_unlock(&tasklist_lock);
+	dir->i_nlink = n;
+
+	pid = atoi16(dentry->d_name.name, dentry->d_name.len);
+	if(!pid)
+		goto out;
+
+	read_lock(&tasklist_lock);
+	p = find_any_task_by_pid(pid);
+	if (p && !(p->mosix.dflags & DREMOTE))
+		p = NULL;
+	read_unlock(&tasklist_lock);
+
+	inode = NULL;
+	if (pid && p) {
+		inode = proc_get_inode(dir->i_sb,
+			(pid << 16) | PROC_REMPID_INO, NULL);
+		if (!inode)
+			return ERR_PTR(-EINVAL);
+		inode->i_mode = S_IFDIR | 0555;
+		inode->i_op = &proc_mosix_subdir_inode_operations;
+		inode->i_fop = &proc_mosix_subdir_file_operations;
+	}
+
+	out:
+	dentry->d_op = &proc_mosix_dynamic_dentry_operations;
+	d_add(dentry, inode);
+	return(NULL);
+}
+
+static int
+proc_mosix_nodes_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+	struct mosixnet *mos;
+	char buf[NUMBUF];
+	unsigned int nr = filp->f_pos;
+	int nmos, k, l, node;
+
+	if(filp->f_pos == 0)
+	{
+		if(filldir(dirent, ".", 1, 0, filp->f_dentry->d_inode->i_ino,
+								DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 1;
+	}
+	if(filp->f_pos == 1)
+	{
+		if(filldir(dirent, "..", 2, 1,
+				filp->f_dentry->d_parent->d_inode->i_ino,
+								DT_DIR) < 0)
+			return(0);
+		filp->f_pos = 2;
+	}
+
+	if((nmos = mosix_config_get_table(&mos, 0, 0)) <= 0)
+		return (nmos);
+	
+	nr = 2;
+	for(k = 0 ; k < nmos ; k++)
+		for (l = 0; l < mos[k].cnt; l++) {
+			unsigned long i, j;
+
+			if(nr++ < filp->f_pos)
+				continue;
+
+			node = mos[k].base + l;
+			for (j = NUMBUF, i = node; i; i /= 10) {
+				j--;
+				buf[j] = '0' + (i % 10);
+			}
+			if (filldir(dirent, buf+j, NUMBUF-j, filp->f_pos,
+				(node << 16)+PROC_NODEID_INO, DT_REG) < 0)
+				goto out;
+			filp->f_pos++;
+		}
+out:
+	if(nmos)
+		kfree(mos);
+	return (0);
+}
+
+static struct dentry *
+proc_mosix_nodes_lookup(struct inode *dir, struct dentry *dentry)
+{
+	unsigned int node;
+	struct inode *inode = NULL;
+
+	dir->i_nlink = proc_mosix_nodes.nlink + count_mosix_nodes();
+
+	node = atoi16(dentry->d_name.name, dentry->d_name.len);
+
+	if(!mos_to_net(node, NULL))
+		node = 0;
+	if (node)
+	{
+		inode = proc_get_inode(dir->i_sb,
+			(node << 16) | PROC_NODEID_INO, NULL);
+		if (!inode)
+			return ERR_PTR(-EINVAL);
+		inode->i_mode = S_IFDIR | 0555;
+		inode->i_op = &proc_mosix_subdir_inode_operations;
+		inode->i_fop = &proc_mosix_subdir_file_operations;
+	}
+
+	dentry->d_op = &proc_mosix_dynamic_dentry_operations;
+	d_add(dentry, inode);
+	return(NULL);
+}
+
+ssize_t
+proc_mosix_sub_read(struct file *filp, char *buf, size_t count, loff_t *ppos)
+{
+	struct task_struct *r;
+	char *page;
+	unsigned long rino = filp->f_dentry->d_inode->i_ino;
+	unsigned long ino = rino & 0xffff;
+	int pid_or_node = rino >> 16;
+	int result;
+	int (*func)(struct task_struct *, char *);
+
+	if(!(page = (char *)__get_free_page(GFP_KERNEL)))
+		return(-ENOMEM);
+	switch(ino)
+	{
+		case PROC_REMPID_FROM:
+			func = proc_mosix_get_remote_from;
+			break;
+		case PROC_REMPID_STATM:
+			func = proc_pid_statm;
+			break;
+		case PROC_REMPID_STATS:
+			func = proc_mosix_get_remote_stats;
+			break;
+		case PROC_REMPID_IDENT:
+			func = proc_mosix_get_remote_identity;
+			break;
+		case PROC_NODEID_CPUS:
+			result = sprintf(page, "%d\n", (int)get_item(ncpus,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+		case PROC_NODEID_LOAD:
+			result = sprintf(page, "%d\n", (int)get_item(load,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+		case PROC_NODEID_MEM:
+			result = sprintf(page, "%d\n", (int)get_item(mem,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+		case PROC_NODEID_RMEM:
+			result = sprintf(page, "%d\n", (int)get_item(rmem,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+		case PROC_NODEID_SPEED:
+			result = sprintf(page, "%d\n", (int)get_item(speed,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+		case PROC_NODEID_TMEM:
+			result = sprintf(page, "%d\n", (int)get_item(tmem,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+		case PROC_NODEID_STATUS:
+			result = sprintf(page, "%d\n", (int)get_item(status,
+						pid_or_node, 0, DS_MOSIX_DEF));
+			goto copy;
+		case PROC_NODEID_UTIL:
+			result = sprintf(page, "%d\n", (int)get_item(util,
+					pid_or_node, -ENXIO, -ENETUNREACH));
+			goto copy;
+#ifdef CONFIG_MOSIX_RESEARCH
+                case PROC_NODEID_RIO:
+                        result = sprintf(page, "%d\n", (int)get_item(rio,
+                                        pid_or_node, -ENXIO, -ENETUNREACH));
+                        goto copy;
+                case PROC_NODEID_WIO:
+                        result = sprintf(page, "%d\n", (int)get_item(wio,
+                                        pid_or_node, -ENXIO, -ENETUNREACH));
+                        goto copy;
+#endif /* CONFIG_MOSIX_RESEARCH */
+		default:
+			result = -EPERM;	/* write-only */
+			goto out;
+	}
+	result = -EBADF;
+	read_lock(&tasklist_lock);
+	r = find_any_task_by_pid(pid_or_node);
+	if(r && !(r->mosix.dflags & DREMOTE))
+		r = NULL;
+	if(r)
+		get_task_struct(r);
+	read_unlock(&tasklist_lock);
+	if(!r)
+		goto out;
+	result = (*func)(r, page);
+	free_task_struct(r);
+	copy:
+	if(result > 0)
+	{
+		if(*ppos + count > result)
+		{
+			count = result - *ppos;
+			if(count < 0)
+				count = 0;
+		}
+		if(count && copy_to_user(buf, page, count))
+			return(-EFAULT);
+		*ppos += count;
+		result = count;
+	}
+	out:
+	free_page((unsigned long)page);
+	return(result);
+}
+
+ssize_t
+proc_mosix_sub_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
+{
+	unsigned long ino = filp->f_dentry->d_inode->i_ino & 0xffff;
+	int pid_or_node = ino >> 16;
+
+	switch(ino & 0xffff)
+	{
+		case PROC_REMPID_GOTO:
+			return(proc_mosix_set_remote_goto(filp, pid_or_node,
+				buf, count));
+		default:
+			return(-EPERM);		/* read-only */
+	}
+}
+
+ssize_t
+proc_mosix_pid_set_migrate(struct file *filp, struct task_struct *task,
+						const char *buf, size_t cnt)
+{
+	int mig, error, len;
+	struct ctl_mosix tmpctl =
+		{ 0, "migrate", NULL, sizeof(int), 0, ctl_minmaxv };
+
+	if(task != current)
+		return(-EPERM);
+
+	tmpctl.data = &mig;
+	tmpctl.extra[0] = (void *) DM_BALANCE;
+	tmpctl.extra[1] = (void *) MOSIX_MAX;
+	error = get_intarr(filp, buf, cnt, &tmpctl);
+	if (error < 0)
+		return (error);
+	len = error;
+
+	if ((error = mig_migrate(mig)))
+		return (error);
+	else
+		return (len);
+}
+
+ssize_t
+proc_mosix_pid_set_goto(struct file *filp, struct task_struct *task,
+						const char *buf, size_t cnt)
+{
+	int whereto, error;
+	struct ctl_mosix tmpctl =
+		{ 0, "goto", NULL, sizeof(int), 0, ctl_minmaxv };
+
+	/* the rule is: if you can send it a signal, you may also migrate it: */
+	/* so keep looking for changes in "kernel/signal.c" */
+	if ((current->euid ^ task->suid) && (current->euid ^ task->uid) &&
+		(current->uid ^ task->suid) && (current->uid ^ task->uid) &&
+		!capable(CAP_KILL))
+		return(-EPERM);
+
+	tmpctl.data = &whereto;
+	tmpctl.extra[0] = (void *) DM_BALANCE;
+	tmpctl.extra[1] = (void *) MOSIX_MAX;
+	error = get_intarr(filp, buf, cnt, &tmpctl);
+	if (error < 0)
+		return (error);
+	if(whereto > 0 && !mos_to_net(whereto, NULL))
+		return(-ENODEV);
+
+	if (whereto <= 0) {
+		switch (whereto) {
+			case DM_GOBACKHOME:
+				whereto = GOBACKHOME;
+				break;
+			case DM_BALANCE:
+				whereto = BALANCE;
+				break;
+
+			default:
+				return(-EINVAL);
+		}
+	}
+	if (task->mosix.stay & DSTAY)
+		return (-EROFS);
+	mosix_add_to_whereto(task, whereto);
+	return (error);
+}
+
+ssize_t
+proc_mosix_pid_set_lock(struct file *filp, struct task_struct *task,
+						const char *buf, size_t cnt)
+{
+	int lock, len;
+	struct ctl_mosix ctl =
+		{ 0, "lock", NULL, sizeof(int), 0, ctl_boolean };
+
+	ctl.data = (void *)&lock;
+
+	if(task == current)
+	{
+		len = get_intarr(filp, buf, cnt, &ctl);
+		if (len < 0)
+			return (len);
+		mig_set_lock(lock);
+		return (len);
+	}
+	if(!suser())
+		return(-EPERM);
+	/* The SU has the special privillege of unlocking local processes */
+	len = get_intarr(filp, buf, cnt, &ctl);
+	if(len < 0)
+		return(len);
+	if(lock)
+		return(-EINVAL);
+	task_lock(task);
+	if (task->mosix.dflags & (DDEPUTY|DFINISHED))
+		len = -EACCES;
+	else
+		task->mosix.stay &= ~DNOMIGRATE;
+	task_unlock(task);
+	return(len);
+}
+
+ssize_t
+proc_mosix_pid_set_disclosure(struct file *filp, struct task_struct *task,
+						const char *buf, size_t cnt)
+{
+	int disclosure, len;
+	struct ctl_mosix ctl =
+		{ 0, "disclosure", NULL, sizeof(int), 0, ctl_minmaxv };
+
+	ctl.data = (void *)&disclosure;
+	ctl.extra[0] = (void *) 0;
+	ctl.extra[1] = (void *) 3;
+
+	if(task != current)
+		return(-EPERM);
+	len = get_intarr(filp, buf, cnt, &ctl);
+	if (len < 0)
+		return (len);
+	current->mosix.disclosure = disclosure;
+	tell_process(current, DREQ_INFOCNG);
+	return(len);
+}
+
+ssize_t
+proc_mosix_pid_set_sigmig(struct file *filp, struct task_struct *task,
+						const char *buf, size_t cnt)
+{
+	int sig = current->mosix.sigmig, len;
+	struct ctl_mosix tmpctl =
+		{ 0, "sigmig", NULL, sizeof(int), 0, ctl_minmaxv };
+
+	if(task != current)
+		return(-EPERM);
+
+	tmpctl.data = &sig;
+	tmpctl.extra[0] = (void *) 0;
+	tmpctl.extra[1] = (void *) _NSIG;
+	len = get_intarr(filp, buf, cnt, &tmpctl);
+	if(len >= 0)
+		current->mosix.sigmig = sig;
+	return (len);
+}
+
+#ifdef CONFIG_MOSIX_FS
+ssize_t
+proc_mosix_pid_set_selected(struct file *filp, struct task_struct *task,
+						const char *buf, size_t cnt)
+{
+	int sel, len;
+	struct ctl_mosix ctl =
+		{ 0, "lock", NULL, sizeof(int), 0, ctl_minmaxv };
+
+	if(task != current)
+		return(-EPERM);
+
+	ctl.data = (void *) &sel;
+	ctl.extra[0] = (void *) 0;
+	ctl.extra[1] = (void *) MOSIX_MAX;
+	sel = current->mosix.selected;
+	len = get_intarr(filp, buf, cnt, &ctl);
+	if (len >= 0 && sel != current->mosix.selected)
+	{
+		current->mosix.selected = sel;
+#ifdef CONFIG_MOSIX_DFSA
+		current->mosix.dupdates |= DFSA_UPDSEL;
+#endif /* CONFIG_MOSIX_DFSA */
+	}
+	return (len);
+}
+#endif /* CONFIG_MOSIX_FS */
+
+static ssize_t
+proc_mosix_set_remote_goto(struct file *filp, int pid,
+			   const char *buf, size_t cnt)
+{
+	struct task_struct *task;
+	int error, whereto;
+	struct ctl_mosix tmpctl =
+		{ 0, "goto", NULL, sizeof(int), 0, ctl_minmaxv };
+
+	if(!suser())
+		return(-EACCES);
+	read_lock(&tasklist_lock);
+	task = find_any_task_by_pid(pid);
+	if(task && !(task->mosix.dflags & DREMOTE))
+		task = NULL;
+	if(task)
+		get_task_struct(task);
+	read_unlock(&tasklist_lock);
+	if (!task)
+		return(-EBADF);
+
+	tmpctl.data = &whereto;
+	tmpctl.extra[0] = (void *) DM_BALANCE;
+	tmpctl.extra[1] = (void *) MOSIX_MAX;
+	error = get_intarr(filp, buf, cnt, &tmpctl);
+	if (error < 0)
+		goto free;
+	if(whereto > 0)
+	{
+		error = -ENODEV;
+		if(!mos_to_net(whereto, NULL))
+			goto free;
+	}
+	else switch(whereto)
+	{
+		case DM_GOBACKHOME:
+			whereto = GOBACKHOME;
+			break;
+		case DM_BALANCE:
+			whereto = BALANCE;
+			break;
+		default:
+			mosix_panic("remote_goto: invalid negative");
+	}
+
+	lock_mosix();
+	if(!(task->mosix.dflags & DFINISHED))
+		mosix_add_to_whereto(task, whereto);
+	unlock_mosix();
+	error = 0;
+	free:
+	free_task_struct(task);
+	return (error);
+}
+
+static int
+proc_mosix_get_remote_from(struct task_struct *task, char *buf)
+{
+	int node;
+	int len;
+
+	node = task->mosix.deppe;
+#ifdef CONFIG_MOSIX_DIAG
+	if (!node) {
+		mosix_panic("get_remote_from: deppe is zero");
+		node = mosix_config_get_pe();
+	}
+#endif
+	sprintf(buf, "%-6d", node);
+	if (mos_to_ascii(node, buf + 6, 1000) < 0) {
+#ifdef CONFIG_MOSIX_DIAG
+		printk("%d(%s)-proc_mosix_get_remote_from: mos_to_ascii failed"
+			" for %d\n", current->pid, current->comm, node);
+#endif
+		return (-EDIST);
+	}
+	len = strlen(buf);
+	buf[len++] = '\n';
+	return (len);
+}
+
+static int
+proc_mosix_get_remote_stats(struct task_struct *tsk, char *buf)
+{
+	struct mm_struct *mm;
+	struct vm_area_struct *vma;
+	unsigned long vsize;
+	unsigned long s = LOGICAL_STATE(tsk);
+	char state;
+
+	if(s == TASK_RUNNING)
+		state = 'R';
+	else if(s & TASK_INTERRUPTIBLE)
+		state = 'S';
+	else if(s & TASK_UNINTERRUPTIBLE)
+		state = 'D';
+	else
+	{
+		printk("Oops, remote-status = 0x%lx\n", s);
+		state = '?';
+	}
+	vsize = 0;
+	mm = tsk->mm;
+	if (mm && mm != &init_mm)
+	{
+		down_read(&mm->mmap_sem);
+		for(vma = mm->mmap ; vma ; vma = vma->vm_next)
+			vsize += vma->vm_end - vma->vm_start;
+		up_read(&mm->mmap_sem);
+	}
+
+	return(sprintf(buf, "utime=%lu\ncutime=%lu\n"
+			"nice=%ld\nstate=%c\nvsize=%lu\nrss=%lu\n"
+			"nswap=%lu\ncnswap=%lu\n",
+		(unsigned long)(tsk->times.tms_utime + tsk->mosix.uttime),
+		(unsigned long)(tsk->times.tms_cutime + tsk->mosix.cutime),
+		tsk->nice,
+		state,
+		vsize,
+		tsk->mm ? tsk->mm->rss : 0,
+		tsk->nswap,
+		tsk->cnswap) + 1);
+}
+
+static int
+proc_mosix_get_remote_identity(struct task_struct *tsk, char *buf)
+{
+	char *obuf = buf;
+
+	buf[0] = '\0';
+	if(tsk->mosix.disclosure)
+	{
+		buf += sprintf(buf, "pid=%d\n", tsk->mosix.mypid);
+		if(tsk->mosix.depinfo.tgid != tsk->mosix.mypid)
+			buf += sprintf(buf, "tgid=%d\n",
+						tsk->mosix.depinfo.tgid);
+	}
+	if(tsk->mosix.disclosure > 1)
+		buf += sprintf(buf, "uid=%d\ngid=%d\n", tsk->uid, tsk->gid);
+	if(tsk->mosix.disclosure > 2)
+		buf += sprintf(buf, "pgrp=%d\nsession=%d\nnmigs=%d\ncommand=%.16s\n",
+			tsk->mosix.depinfo.pgrp, tsk->mosix.depinfo.session,
+			tsk->mosix.nmigs, tsk->mosix.depinfo.comm);
+	return(buf - obuf);
+}
diff -ruN linux-2.4.16/mos/prequest.c linux-2.4.16-mosix/mos/prequest.c
--- linux-2.4.16/mos/prequest.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/prequest.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,818 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/mosix.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/file.h>
+#include <asm/uaccess.h>
+#include <mos/request.h>
+#include <mos/routines.h>
+#include <mos/protocol.h>
+#include <mos/defs.h>
+#include <mos/comm.h>
+#include <mos/debug.h>
+
+int request_on_remote(struct prequest *);
+
+static inline void
+issue_request(struct prequest *pr, struct task_struct *to)
+{
+	sigset_t blocked;
+	register struct task_struct *p = current;
+	unsigned long flags;
+	DECLARE_WAITQUEUE(wait, p);
+
+	if(to->mosix.dflags & DFINISHED)
+	{
+		pr->rflags = PR_ERROR;
+		goto out;
+	}
+	pr->rflags = PR_WAITING;
+	init_waitqueue_head(&pr->waitq);
+	pr->rnext = to->mosix.prequest;
+	to->mosix.prequest = pr;
+	wake_up_mosix(to);
+	if(!p->sig)	/* can happen when calling from EXIT */
+	{
+		pr->rflags &= ~PR_WAITING;
+		goto out;
+	}
+	spin_lock_irqsave(&p->sigmask_lock, flags);
+	blocked = p->blocked;
+	siginitsetinv(&p->blocked, sigmask(SIGKILL));
+	if(p->sig->action[SIGTERM-1].sa.sa_handler == SIG_DFL)
+		p->blocked.sig[0] &= ~sigmask(SIGTERM);
+	if(p->sig->action[SIGINT-1].sa.sa_handler == SIG_DFL)
+		p->blocked.sig[0] &= ~sigmask(SIGINT);
+	if(p->sig->action[SIGQUIT-1].sa.sa_handler == SIG_DFL)
+		p->blocked.sig[0] &= ~sigmask(SIGQUIT);
+	if(p->sig->action[SIGHUP-1].sa.sa_handler == SIG_DFL)
+		p->blocked.sig[0] &= ~sigmask(SIGHUP);
+	recalc_sigpending(p);
+	spin_unlock_irqrestore(&p->sigmask_lock, flags);
+	add_wait_queue(&pr->waitq, &wait);
+	set_current_state(TASK_INTERRUPTIBLE);
+	while((pr->rflags == PR_WAITING) && !signal_pending(p))
+	{
+		unlock_mosix();
+		schedule();
+		set_current_state(TASK_INTERRUPTIBLE);
+		lock_mosix();
+	}
+	remove_wait_queue(&pr->waitq, &wait);
+	set_current_state(TASK_RUNNING);
+	spin_lock_irqsave(&p->sigmask_lock, flags);
+	p->blocked = blocked;
+	recalc_sigpending(p);
+	spin_unlock_irqrestore(&p->sigmask_lock, flags);
+	pr->rflags &= ~PR_WAITING;
+	out:
+	free_task_struct(to);
+}
+
+char *
+request_process_to_buf_arg(struct task_struct *p, char *buffer, int command, int arg)
+{
+	struct prequest *pr;
+	char *reply = buffer;
+
+	get_task_struct(p);
+	if(!(pr = kmalloc(sizeof(struct prequest), GFP_KERNEL)))
+	{
+		free_task_struct(p);
+		return(reply);
+	}
+	pr->command = command;
+	pr->param = arg;
+	pr->ereply = buffer;
+	pr->len = 0;
+	pr->reply = 0;
+	if(command == PR_PROCFS_TASK_MEM && pick_ps(p, pr))
+	{
+		reply = (char *)pr->reply;
+		kfree(pr);
+		free_task_struct(p);
+		return(reply);
+	}
+	lock_mosix();
+	issue_request(pr, p);
+	if(pr->rflags == PR_DONE)
+		reply = (char *)pr->reply;
+	if(pr->rflags & (PR_DONE|PR_ERROR))
+		kfree(pr);
+	unlock_mosix();
+	return(reply);
+}
+
+int
+request_process_arg2(struct task_struct *p, void *indata, int command, int arg, int arg2)
+{
+	struct prequest *pr;
+	int reply = -ENOMEM;
+
+	get_task_struct(p);
+	if(!(pr = kmalloc(sizeof(struct prequest), GFP_KERNEL)))
+	{
+		free_task_struct(p);
+		return(reply);
+	}
+	reply = -EIO;
+	pr->command = command;
+	pr->param = arg;
+	pr->param2 = arg2;
+	pr->ereply = indata;
+	pr->len = 0;
+	pr->reply = 0;
+	switch(command)
+	{
+		case PR_PROCFS_GET_ARG:
+		case PR_PROCFS_GET_ENV:
+		case PR_PROCFS_GET_STAT_PARTS:
+		case PR_PROCFS_GET_STATM:
+			if(pick_ps(p, pr))
+			{
+				reply = pr->reply;
+				kfree(pr);
+				free_task_struct(p);
+				return(reply);
+			}
+			break;
+#ifdef CONFIG_MOSIX_DFSA
+		case PR_DFSA_SYNCHRONIZE:
+			if(p->mosix.ps)
+			{
+				kfree(pr);
+				free_task_struct(p);
+				return(0);
+			}
+#endif /* CONFIG_MOSIX_DFSA */
+	}
+	lock_mosix();
+	issue_request(pr, p);
+	if(pr->rflags == PR_DONE)
+		reply = pr->reply;
+	if(pr->rflags & (PR_DONE|PR_ERROR))
+		kfree(pr);
+	else
+		reply = -EINTR;
+	unlock_mosix();
+	return(reply);
+}
+
+int
+request_on_local(struct prequest *pr)
+{
+	switch(pr->command)
+	{
+		case PR_PROCFS_TASK_MEM:
+			pr->reply = (long)(current->mm ?
+				task_mem(current->mm, pr->ereply) : pr->ereply);
+			break;
+		case PR_PROCFS_GET_ENV:
+			pr->reply = proc_pid_environ(current, pr->ereply);
+			break;
+		case PR_PROCFS_GET_ARG:
+			pr->reply = proc_pid_cmdline(current, pr->ereply);
+			break;
+		case PR_PROCFS_GET_STAT_PARTS:
+			proc_get_stat_parts(current, current->mm,
+				(struct proc_remote_stat_parts *)pr->ereply);
+			pr->reply = 0;
+			break;
+		case PR_PROCFS_GET_STATM:
+			pr->reply = proc_pid_statm(current, pr->ereply);
+			break;
+		case PR_PROCFS_GET_EXE:
+			pr->reply = (int)first_executable();
+			break;
+		case PR_PROCFS_MAP_INFO:
+			pr->reply = proc_list_maps((struct vmamaps *)pr->ereply,
+								pr->param);
+			ref_mapped_files((struct vmamaps *)pr->ereply,
+								pr->reply);
+			break;
+		case PR_PROCFS_MEM_READ:
+			pr->reply = access_process_vm(current,
+				(unsigned long)pr->param, pr->ereply,
+				pr->param2, 0);
+			break;
+		case PR_PROCFS_MEM_WRITE:
+			pr->reply = access_process_vm(current,
+				(unsigned long)pr->param, pr->ereply,
+				pr->param2, 1);
+			break;
+#ifdef CONFIG_MOSIX_DFSA
+		case PR_DFSA_SYNCHRONIZE:
+#endif /* CONFIG_MOSIX_DFSA */
+		case PR_PTRACE_NOT_TRACED:
+		case PR_PROCFS_UPDATE_TIMES:
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_GET_STACK_LONG:
+			pr->reply = get_stack_long(current, pr->param);
+			break;
+		case PR_PTRACE_PUT_STACK_LONG:
+			pr->reply = put_stack_long(current, pr->param,
+				(unsigned long)pr->param2);
+			break;
+		case PR_PTRACE_GETREGS:
+			ptrace_getregs((unsigned long *)pr->ereply);
+			break;
+		case PR_PTRACE_SETREGS:
+			ptrace_putregs((unsigned long *)pr->ereply);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_PEEKUSER:
+			*((unsigned long *)pr->ereply) =
+				ptrace_peekuser(pr->param);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_POKEUSER:
+			ptrace_pokeuser(pr->param, pr->param2);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_CONT:
+			ptrace_cont(pr->param);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_SINGLE_STEP:
+			ptrace_single_step();
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_GETFPREGS:
+			ptrace_getfpregs((struct user_i387_struct *)pr->ereply);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_SETFPREGS:
+			ptrace_setfpregs((struct user_i387_struct *)pr->ereply);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_GETFPXREGS:
+			ptrace_getfpxregs(
+					(struct user_fxsr_struct *)pr->ereply);
+			pr->reply = 0;
+			break;
+		case PR_PTRACE_SETFPXREGS:
+			ptrace_setfpxregs(
+					(struct user_fxsr_struct *)pr->ereply);
+			pr->reply = 0;
+			break;
+	}
+	return(PR_DONE);
+}
+
+void
+free_unwanted_request(struct prequest *pr)
+{
+	struct file *filp;
+
+	if((pr->rflags & (PR_WAITING|PR_DONE|PR_ERROR)) == PR_DONE)
+	switch(pr->command)
+	{
+		case PR_PROCFS_GET_EXE:
+			filp = (struct file *)pr->reply;
+			if(filp)
+				fput(filp);
+			break;
+	}
+	kfree(pr);
+}
+
+void
+process_requests(void)
+{
+	register struct prequest *pr;
+	int res;
+
+	lock_mosix();
+	while((pr = current->mosix.prequest))
+	{
+		current->mosix.prequest = pr->rnext;
+		if(!(pr->rflags & PR_WAITING))
+		{
+			kfree(pr);
+			continue;
+		}
+		unlock_mosix();
+		pr->reply = 0;
+		if(current->mosix.dflags & DDEPUTY)
+			res = request_on_remote(pr);
+		else
+			res = request_on_local(pr);
+		lock_mosix();
+		pr->rflags |= res;
+		if(pr->rflags & PR_WAITING)
+			wake_up(&pr->waitq);
+		else
+		{
+			unlock_mosix();
+			free_unwanted_request(pr);
+			lock_mosix();
+		}
+	}
+	unlock_mosix();
+}
+
+void
+discard_requests(void)
+{
+	register struct prequest *pr;
+
+	lock_mosix();
+	while((pr = current->mosix.prequest))
+	{
+		current->mosix.prequest = pr->rnext;
+		if(pr->rflags & PR_WAITING)
+		{
+			pr->rflags |= PR_ERROR;
+			wake_up(&pr->waitq);
+		}
+		else
+		{
+			unlock_mosix();
+			free_unwanted_request(pr);
+			lock_mosix();
+		}
+	}
+	unlock_mosix();
+}
+
+int
+request_on_remote(struct prequest *pr)
+{
+	struct prequest_h p;
+	struct prequest_reply_h r;
+	void *snd;
+	int sndlen;
+	int err = 0;
+
+	p.command = pr->command;
+	p.param = pr->param;
+	p.param2 = pr->param2;
+	p.len = pr->len;
+	snd = NULL;
+	sndlen = 0;
+	switch(pr->command)
+	{
+		case PR_PROCFS_MEM_READ:
+			flush_read_cache();
+			break;
+		case PR_PROCFS_MEM_WRITE:
+			flush_ucache();
+			snd = pr->ereply;
+			sndlen = pr->param2;
+			break;
+#ifdef CONFIG_MOSIX_DFSA
+		case PR_DFSA_SYNCHRONIZE:
+			/* once we are here - we have already achieved
+			 * the purpose of synchronization!
+			 */
+			pr->reply = 0;
+			goto done;
+#endif /* CONFIG_MOSIX_DFSA */
+		case PR_PTRACE_SETREGS:
+			snd = pr->ereply;
+			sndlen = 17 * sizeof(long);
+			break;
+		case PR_PTRACE_SETFPREGS:
+			snd = pr->ereply;
+			sndlen = sizeof(struct user_i387_struct);
+			break;
+		case PR_PTRACE_SETFPXREGS:
+			snd = pr->ereply;
+			sndlen = sizeof(struct user_fxsr_struct);
+			break;
+			/* the following may be done locally */
+		case PR_PROCFS_GET_STAT_PARTS:
+		case PR_PROCFS_GET_STATM:
+		case PR_PROCFS_TASK_MEM:
+			if(pick_ps(current, pr))
+				goto done;
+			break;
+			/* the following read from user: */
+		case PR_PROCFS_GET_ARG:
+		case PR_PROCFS_GET_ENV:
+			if(pick_ps(current, pr))
+				goto done;
+			flush_read_cache();
+			break;
+		case PR_PROCFS_UPDATE_TIMES:
+			mosix_deputy_rusage(0);
+			pr->reply = 0;
+			goto done;
+	}
+	if(deputy_request(DEP_PREQUEST, &p, sizeof(p), snd, sndlen, 0,
+					(void **)&r, -sizeof(r)) || r.error)
+	{
+		err = PR_ERROR;
+		goto done;
+	}
+	pr->reply = r.reply;
+	if(r.datalen > 0 && comm_copydata(pr->ereply, r.datalen, 0))
+		err = PR_ERROR;
+	else
+	switch(pr->command)
+	{
+		case PR_PROCFS_TASK_MEM:
+			pr->reply = (int)(pr->ereply + r.reply);
+			break;
+		case PR_PROCFS_GET_STAT_PARTS:
+			mosix_deputy_rusage(0);
+			break;
+		case PR_PROCFS_GET_ENV:
+		case PR_PROCFS_GET_ARG:
+		case PR_PROCFS_GET_STATM:
+		case PR_PTRACE_GET_STACK_LONG:
+		case PR_PTRACE_PUT_STACK_LONG:
+		case PR_PTRACE_GETREGS:
+		case PR_PTRACE_SETREGS:
+		case PR_PTRACE_PEEKUSER:
+		case PR_PTRACE_POKEUSER:
+		case PR_PTRACE_CONT:
+		case PR_PTRACE_SINGLE_STEP:
+		case PR_PTRACE_GETFPREGS:
+		case PR_PTRACE_SETFPREGS:
+		case PR_PTRACE_GETFPXREGS:
+		case PR_PTRACE_SETFPXREGS:
+		case PR_PROCFS_MEM_READ:
+		case PR_PROCFS_MEM_WRITE:
+			break;
+		case PR_PROCFS_MAP_INFO:
+			ref_mapped_files((struct vmamaps *)pr->ereply,
+								pr->reply);
+			break;
+		case PR_PROCFS_GET_EXE:
+			{
+				struct file *filp = (struct file *)pr->reply;
+				if(filp)
+					get_file(filp);
+			}
+			break;
+		default:
+			printk("request on remote - unknown code\n");
+	}
+	done:
+	return(PR_DONE|err);
+}
+
+int
+remote_prequest(struct prequest_h *p)
+{
+	struct prequest_reply_h r;
+	char *buffer;
+	int err;
+	unsigned long data[17];
+	int allocated = 0;
+
+	r.error = r.datalen = 0;
+	switch(p->command)
+	{
+		case PR_PROCFS_TASK_MEM:
+		case PR_PROCFS_GET_ENV:
+		case PR_PROCFS_GET_ARG:
+		case PR_PROCFS_GET_STAT_PARTS:
+		case PR_PROCFS_GET_STATM:
+		case PR_PROCFS_MAP_INFO:
+		case PR_PROCFS_MEM_READ:
+		case PR_PTRACE_GETFPREGS:
+		case PR_PTRACE_GETFPXREGS:
+			if((buffer = (char *)__get_free_page(GFP_KERNEL)))
+				allocated = 1;
+			else
+			{
+				r.error = -ENOMEM;
+				buffer = NULL;
+			}
+			break;
+		case PR_PTRACE_GETREGS:
+		case PR_PTRACE_PEEKUSER:
+			buffer = (char *)data;
+			break;
+		default:
+			buffer = NULL;
+			break;
+	}
+	if(!r.error)
+	switch(p->command)
+	{
+		case PR_PROCFS_TASK_MEM:
+			r.datalen = r.reply = current->mm ?
+				task_mem(current->mm, buffer) - buffer : 0;
+			break;
+		case PR_PROCFS_GET_ENV:
+			r.datalen = r.reply = proc_pid_environ(current, buffer);
+			break;
+		case PR_PROCFS_GET_ARG:
+			r.datalen = r.reply = proc_pid_cmdline(current, buffer);
+			break;
+		case PR_PROCFS_GET_STAT_PARTS:
+			proc_get_stat_parts(current, current->mm,
+				(struct proc_remote_stat_parts *)buffer);
+			r.reply = 0;
+			r.datalen = sizeof(struct proc_remote_stat_parts);
+			break;
+		case PR_PROCFS_GET_STATM:
+			r.datalen = r.reply = proc_pid_statm(current, buffer);
+			break;
+		case PR_PROCFS_GET_EXE:
+			r.reply = (int)first_executable();
+			break;
+		case PR_PROCFS_MAP_INFO:
+			r.datalen = r.reply = proc_list_maps(
+					(struct vmamaps *)buffer, p->param);
+			break;
+		case PR_PROCFS_MEM_READ:
+			r.datalen = r.reply = access_process_vm(current,
+				p->param, (void *)buffer, p->param2, 0);
+			break;
+		case PR_PROCFS_MEM_WRITE:
+			if(comm_recvdata((void **)&buffer))
+				r.reply = 0;
+			else
+			{
+				r.reply = access_process_vm(current, p->param,
+					(void *)buffer, p->param2, 1);
+				comm_free(buffer);
+			}
+			break;
+		case PR_PTRACE_GET_STACK_LONG:
+			r.reply = get_stack_long(current, p->param);
+			break;
+		case PR_PTRACE_PUT_STACK_LONG:
+			r.reply = put_stack_long(current, p->param,
+				(unsigned long)p->param2);
+			break;
+		case PR_PTRACE_GETREGS:
+			ptrace_getregs((unsigned long *)buffer);
+			r.datalen = 17 * sizeof(unsigned long);
+			r.reply = 0;
+			break;
+		case PR_PTRACE_SETREGS:
+			r.reply = 0;
+			if(!comm_recvdata((void **)&buffer))
+			{
+				ptrace_putregs((unsigned long *)buffer);
+				comm_free(buffer);
+			}
+			break;
+		case PR_PTRACE_PEEKUSER:
+			data[0] = ptrace_peekuser(p->param);
+			r.datalen = sizeof(unsigned long);
+			r.reply = 0;
+			break;
+		case PR_PTRACE_POKEUSER:
+			ptrace_pokeuser(p->param, p->param2);
+			r.datalen = r.reply = 0;
+			break;
+		case PR_PTRACE_CONT:
+			ptrace_cont(p->param);
+			r.datalen = r.reply = 0;
+			break;
+		case PR_PTRACE_NOT_TRACED:
+			current->ptrace = 0;
+			r.datalen = r.reply = 0;
+			break;
+		case PR_PTRACE_SINGLE_STEP:
+			ptrace_single_step();
+			r.datalen = r.reply = 0;
+			break;
+		case PR_PTRACE_GETFPREGS:
+			ptrace_getfpregs((struct user_i387_struct *)buffer);
+			r.datalen = sizeof(struct user_i387_struct);
+			r.reply = 0;
+			break;
+		case PR_PTRACE_SETFPREGS:
+			r.reply = 0;
+			if(!comm_recvdata((void **)&buffer))
+			{
+				ptrace_setfpregs(
+					(struct user_i387_struct *)buffer);
+				comm_free(buffer);
+			}
+			break;
+		case PR_PTRACE_GETFPXREGS:
+			ptrace_getfpxregs((struct user_fxsr_struct *)buffer);
+			r.datalen = sizeof(struct user_fxsr_struct);
+			r.reply = 0;
+			break;
+		case PR_PTRACE_SETFPXREGS:
+			r.reply = 0;
+			if(!comm_recvdata((void **)&buffer))
+			{
+				ptrace_setfpxregs(
+					(struct user_fxsr_struct *)buffer);
+				comm_free(buffer);
+			}
+			break;
+	}
+	err = comm_send(DEP_PREQUEST|REPLY, &r, sizeof(r),
+		r.datalen ? buffer : NULL, r.datalen, 0);
+	if(allocated)
+		free_page((unsigned long)buffer);
+	comm_free(p);
+	return(err);
+}
+
+void
+process_only_easy_requests(void)
+{
+	register struct prequest *pr, *prev, *next;
+
+	if(!current->mosix.ps)
+		return;
+	lock_mosix();
+	for(prev = NULL, pr = current->mosix.prequest ; pr ; )
+	switch(pr->command)
+	{
+#ifdef CONFIG_MOSIX_DFSA
+		case PR_DFSA_SYNCHRONIZE:
+			pr->reply = 0;
+			pr->rflags |= PR_DONE;
+			goto next_one;
+#endif /* CONFIG_MOSIX_DFSA */
+		case PR_PROCFS_GET_ARG:
+		case PR_PROCFS_GET_ENV:
+		case PR_PROCFS_TASK_MEM:
+		case PR_PROCFS_GET_STAT_PARTS:
+		case PR_PROCFS_GET_STATM:
+			pick_ps(current, pr);
+#ifdef CONFIG_MOSIX_DFSA
+			next_one:
+#endif /* CONFIG_MOSIX_DFSA */
+			next = pr->rnext;
+			if(prev)
+				prev->rnext = next;
+			else
+				current->mosix.prequest = next;
+			if(pr->rflags & PR_WAITING)
+				wake_up(&pr->waitq);
+			else
+				kfree(pr);
+			pr = next;
+			break;
+		default:
+			prev = pr;
+			pr = pr->rnext;
+	}
+	unlock_mosix();
+}
+
+/* Saved record structure:
+ * 1: args (null terminated)
+ * 2: env (null terminated)
+ * 3: task_mem (null terminated)
+ * 4: struct proc_remote_stat_parts (32 bytes at the moment)
+ * 5: statm output (null terminated)
+ * Below is an overkill estimate of 3+4+5:
+ */
+#define	MAX_REQ_FOR_STATS	350
+
+char *
+fill_common_ps_info(int *n)
+{
+	char *buffer = kmalloc(2*PAGE_SIZE+MAX_REQ_FOR_STATS, GFP_KERNEL);
+	char *e, *p;
+	struct task_struct *t = current;
+	int l1, l2, l3;
+
+	if(n)
+		*n = 0;
+	if(!buffer)
+		return(NULL);
+	e = buffer + (l1 = proc_pid_cmdline(t, buffer));
+	e += (l2 = proc_pid_environ(t, e));
+	e += (l3 = task_mem(t->mm, e) - e);
+	proc_get_stat_parts(t, t->mm, (struct proc_remote_stat_parts *)e);
+	e += sizeof(struct proc_remote_stat_parts);
+	e += proc_pid_statm(t, e);
+	*e++ = '\0';
+	if((p = kmalloc(e - buffer + 3*sizeof(short), GFP_KERNEL)))
+	{
+		((short *)p)[0] = l1;
+		((short *)p)[1] = l2;
+		((short *)p)[2] = l3;
+		memcpy(p + 3 * sizeof(short), buffer, l1 = e - buffer);
+	}
+	kfree(buffer);
+	if(n)
+		*n = p ? l1 + 3*sizeof(short) : 0;
+	return(p);
+}
+void
+store_common_ps_info(void)
+{
+	int n;
+	char *p;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.ps)
+	{
+		mosix_panic("already has ps");
+		return;
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	if(current->mosix.dflags & DDEPUTY)
+	{
+		flush_read_cache();
+		if(deputy_request(DEP_PSINFO, NULL, 0, NULL, 0, 0,
+			(void **)&n, -sizeof(n)) || n <= 0)
+			return;
+		if(!(p = kmalloc(n, GFP_KERNEL)))
+		{
+			comm_flushdata(COMM_ALLDATA);
+			return;
+		}
+		if(comm_copydata(p, n, 0))
+			kfree(p);
+		else
+		{
+			lock_mosix();
+			current->mosix.ps = p;
+			unlock_mosix();
+		}
+	}
+	else
+	{
+		p = fill_common_ps_info(NULL);
+		lock_mosix();
+		current->mosix.ps = p;
+		unlock_mosix();
+	}
+	if(current->mosix.prequest)
+		process_only_easy_requests();
+}
+
+void
+stop_storing_common_ps_info(void)
+{
+	char *ps;
+
+	lock_mosix();
+	ps = current->mosix.ps;
+	current->mosix.ps = NULL;
+	unlock_mosix();
+	if(ps)
+		kfree(ps);
+}
+
+int
+pick_ps(struct task_struct *task, struct prequest *pr)
+{
+	register char *p, *t;
+	int l1, l2, l3;
+
+	lock_mosix();
+	if(!(p = task->mosix.ps))
+	{
+		unlock_mosix();
+		return(0);
+	}
+	l1 = *((short *)p)++;
+	l2 = *((short *)p)++;
+	l3 = *((short *)p)++;
+	switch(pr->command)
+	{
+		case PR_PROCFS_GET_STATM:
+			p += l1+l2+l3 + sizeof(struct proc_remote_stat_parts);
+			t = pr->ereply;
+			while(*p)
+				*t++ = *p++;
+			pr->reply = t - pr->ereply;
+			break;
+		case PR_PROCFS_GET_STAT_PARTS:
+			p += l1 + l2 + l3;
+			memcpy(pr->ereply, p,
+				sizeof(struct proc_remote_stat_parts));
+			pr->reply = sizeof(struct proc_remote_stat_parts);
+			break;
+		case PR_PROCFS_TASK_MEM:
+			memcpy(pr->ereply, p + l1 + l2, l3);
+			pr->reply = (int)(pr->ereply + l3);
+			break;
+		case PR_PROCFS_GET_ENV:
+			memcpy(pr->ereply, p + l1, l2);
+			pr->reply = l2;
+			break;
+		case PR_PROCFS_GET_ARG:
+			memcpy(pr->ereply, p, l1);
+			pr->reply = l1;
+			break;
+		default:
+			panic("pick_ps: command");
+	}
+	pr->rflags |= PR_DONE;
+	unlock_mosix();
+	return(1);
+}
diff -ruN linux-2.4.16/mos/remote.c linux-2.4.16-mosix/mos/remote.c
--- linux-2.4.16/mos/remote.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/remote.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1492 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/mosix.h>
+#include <linux/personality.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <mos/routines.h>
+#include <mos/defs.h>
+#include <mos/debug.h>
+#include <asm/processor.h>
+#include <linux/smp_lock.h>
+#include <linux/mm.h>
+#include <linux/pagemap.h>
+#include <asm/uaccess.h>
+#include <linux/in6.h>
+#include <asm/checksum.h>
+#include <linux/slab.h>
+#include <linux/elf.h>
+#include <asm/mman.h>
+#include <linux/unistd.h>
+#include <linux/module.h>
+#include <linux/file.h>
+#include <mos/balance.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+int
+remote_wait(int expect, void **head, int *hlen)
+{
+	int type, error = 0;
+	register struct task_struct *p = current;
+	struct syscall_ret_h *rp;
+	char has_ret_value = 0;
+	int ret_value = 0;	/* value set only to pacify compiler */
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!(p->mosix.dflags & DPSYNC))
+		mosix_panic("remote_wait: not synced");
+#endif /* CONFIG_MOSIX_DIAG */
+	while(1)
+	{
+		if(URGENT_REMOTE_CONDITIONS(p) &&
+					!(p->mosix.dflags & DSENTURGENT))
+			inform_deputy_of_urgent();
+		if((type = comm_recv(head, hlen)) < 0)	/* an error */
+			return(type);
+		if(expect == DEP_USERMODE)
+		/* after migration from REMOTE to REMOTE, certain "replies"
+		 * can arrive as a result from the original call.
+		 * Fortunately, there are not too many of them:
+		 */
+		switch(type & ~USERMODE)
+		{
+			case REM_SYSCALL|REPLY:
+				rp = *head;
+				absorb_deptime(rp->deputytime);
+				remote_unpack_read_cache_data(rp);
+				has_ret_value = 1;
+				ret_value = rp->ret;
+				/* fall through */
+			case REM_SYSCALL_TRACE|REPLY:
+				if(!(type & USERMODE))
+				{
+					comm_free(*head);
+					*head = NULL;
+					continue;
+				}
+		}
+		if(type & USERMODE)
+		{
+			p->mosix.dflags &= ~DPSYNC;
+			if(expect == DEP_USERMODE)
+			{
+				if(has_ret_value)
+					mos_to_regs(&p->mosix)->eax = ret_value;
+				return(0);
+			}
+			if(type != (expect | USERMODE))
+			{
+				printk("REMOTE-%d: Unexected USERMODE while waiting for 0x%x\n",
+					p->pid, expect);
+				mosix_panic("Unexpected USERMODE");
+				return(-EINVAL);
+			}
+		}
+		if((type & ~USERMODE) == expect)
+			return(0);
+		switch(type & ~USERMODE)
+		{
+			case DEP_SYNC:
+				comm_free(*head);
+				break;
+			case DEP_NOTHING:
+				comm_free(*head);
+				error = comm_send(DEP_NOTHING|REPLY, NULL, 0,
+					NULL, 0, 0);
+				break;
+			case DEP_MMAP:
+				error = remote_mmap((struct mmap_parameters_h *)*head, 0);
+				break;
+			case DEP_BRK:
+				error = remote_brk((struct brk_parameters_h *)*head);
+				break;
+			case DEP_MUNMAP:
+				error = remote_munmap((struct munmap_parameters_h *)*head);
+				break;
+			case DEP_MPROTECT:
+				error = remote_mprotect((struct mprotect_parameters_h *)*head);
+				break;
+			case DEP_LISTHOLD:
+				comm_free(*head);
+				error = remote_report_files();
+				break;
+			case DEP_SETUPFRAME:
+				error = remote_setup_frame((struct setupframe_parameters_h *)*head);
+				break;
+			case DEP_NICE:
+				error = remote_nice((long *)*head);
+				break;
+			case DEP_INFO:
+				error = remote_updinfo((struct disclosure_h *)*head);
+				break;
+			case DEP_CAPS:
+				error = remote_caps((kernel_cap_t *)*head);
+				break;
+			case DEP_OPCOSTS:
+				error = remote_depcosts(*head);
+				break;
+			case DEP_RESTORESIGCONTEXT:
+				error = remote_restore_sigcontext((struct sigcontext **)*head);
+				break;
+			case DEP_PREQUEST:
+				error = remote_prequest((struct prequest_h *)*head);
+				break;
+			case DEP_COPY_FROM_USER:
+				error = remote_copy_from_user((struct user_copy_h *)*head);
+				break;
+			case DEP_COPY_TO_USER:
+				error = remote_copy_to_user((struct user_copy_h *)*head);
+				break;
+			case DEP_DATA_TO_USER:
+				error = remote_data_to_user((struct user_copy_h *)*head);
+				break;
+			case DEP_CLEAR_USER:
+				error = remote_clear_user((struct user_copy_h *)*head);
+				break;
+			case DEP_STRNCPY_FROM_USER:
+				error = remote_strncpy_from_user((struct user_copy_h *)*head);
+				break;
+			case DEP_STRNLEN_USER:
+				error = remote_strnlen_user((struct strnlen_user_h *)*head);
+				break;
+			case DEP_VERIFY_WRITE:
+				error = remote_verify_write((struct user_copy_h *)*head);
+				break;
+			case DEP_CSUM_COPY_FROM_USER:
+				error = remote_csum_copy_from_user((struct user_csum_copy_h *)*head);
+				break;
+			case DEP_CACHE_READ_DATA:
+				error = remote_unpack_read_cache_data(NULL);
+				/* NO REPLY! */
+				break;
+			case DEP_RLIMIT:
+				error = remote_rlimit((struct rlimit_h *)*head);
+				break;
+			case DEP_TAKEURGENT:
+				comm_free(*head);
+				error = remote_urgent();
+				break;
+			case DEP_RUSAGE:
+				error = remote_rusage((int *)*head);
+				break;
+			case DEP_PERSONALITY:
+				error = remote_personality((unsigned long *)*head);
+				break;
+			case DEP_EXECVE_COUNTS:
+				error = remote_execve_counts((struct execve_counts_h *)*head);
+				break;
+			case DEP_BRING_STRINGS:
+				error = remote_bring_strings((struct execve_bring_strings_h *)*head);
+				break;
+			case DEP_SETUP_ARGS:
+				error = remote_setup_args((struct execve_setup_args_h *)*head);
+				break;
+			case DEP_EXEC_MMAP:
+				error = remote_exec_mmap();
+				break;
+			case DEP_INIT_AOUT_MM:
+				error = remote_init_aout_mm((struct exec *)*head);
+				break;
+			case DEP_ELF_SETUP:
+				error = remote_elf_setup((struct execve_elf_setup_h *)*head);
+				break;
+			case DEP_FIX_ELF_AOUT:
+				error = remote_fix_elf_aout((struct execve_fix_elf_aout_h *)*head);
+				break;
+			case DEP_DUMP_THREAD:
+				/* comm_free(*head); is not needed (NULL) */
+				error = remote_dump_thread();
+				break;
+			case DEP_LIST_VMAS:
+				/* comm_free(*head); is not needed (NULL) */
+				error = remote_list_vmas();
+				break;
+			case DEP_PLEASE_FORK:
+				error = remote_fork((struct fork_h *)*head);
+				break;
+			case DEP_BRING_ME_REGS:
+				error = remote_bring_me_regs((unsigned long *)*head);
+				break;
+			case DEP_DUMP_FPU:
+				/* comm_free(*head); is not needed (NULL) */
+				error = remote_dump_fpu();
+				break;
+			case DEP_COME_BACK:
+				if (!remote_come_back(*head) || bootexpel)
+					remote_disappear();
+				break;
+			case DEP_PLEASE_MIGRATE:
+				error = remote_goto_remote(*head);
+				break;
+			case DEP_CONSIDER:
+				error = remote_consider((int *)*head);
+				break;
+			case DEP_UPDATE_DECAY:
+				error = remote_setdecay((struct decay_h *)*head);
+				break;
+			case DEP_UPDATE_LOCK:
+				error = remote_set_lock((int *)*head);
+				break;
+			case DEP_PSINFO:
+				/* comm_free(*head); is not needed (NULL) */
+				error = remote_psinfo();
+				break;
+#ifdef CONFIG_MOSIX_DFSA
+			case DEP_DFSA_CLEAR:
+				remote_clear_dfsa();
+				error = comm_send(DEP_DFSA_CLEAR|REPLY, NULL, 0,
+								NULL, 0, 0);
+				break;
+			case DEP_DFSA_CHANGES:
+				error = remote_receive_dfsachanges((int *)*head);
+				break;
+			case DEP_READ_YOURSELF:
+				error = remote_read_yourself(
+					(struct read_yourself_h *)*head);
+				break;
+#endif /* CONFIG_MOSIX_DFSA */
+			default:
+				printk("REMOTE: Unexpected request type %x\n", type);
+				if(type != MIG_REQUEST)
+					mosix_panic("deputy_wait");
+				return(-EINVAL);
+		}
+		if(error)
+		{
+#ifdef CONFIG_MOSIX_DEBUG
+			printk("%d-remote_wait: Error %d\n", p->pid, error);
+#endif /* CONFIG_MOSIX_DEBUG */
+			return(error);
+		}
+	}
+}
+
+int
+remote_request(int type, void *header, int hlen, void *data, int dlen,
+	int uspace, void **result, int reslen)
+{
+	void *head;
+	int rhlen;
+	int error;
+
+	if((error = comm_send(type, header, hlen, data, dlen, uspace)))
+		return(error);
+	if((error = remote_wait(type|REPLY, &head, &rhlen)))
+		return(error);
+	if(reslen > 0)
+	{
+		if(rhlen > reslen)
+			goto lenerr;
+		if(result)
+			*result = head;
+	}
+	else
+	{
+		if(rhlen > -reslen)
+		{
+			comm_free(head);
+			lenerr:
+			printk("remote_request type %x: %d instead of %d\n",
+				type, rhlen, reslen);
+			return(-EDIST);
+		}
+		if(reslen)
+			memcpy(result, head, rhlen);
+		comm_free(head);
+	}
+	return(error);
+}
+
+int
+remote_deputy_has_something_for_us(struct task_struct *p)
+{
+	return((p->mosix.dflags & DPSYNC) || comm_peek());
+}
+
+void
+wait_for_permission_to_continue()
+{
+	struct task_struct *p = current;
+	void *head;
+	int hlen;
+
+	if(!p->mosix.contact)
+	{
+		DECLARE_WAITQUEUE(wait, current);
+
+		add_wait_queue(mos_to_waitp(&p->mosix), &wait);
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		while(!p->mosix.contact)
+		{
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			if(p->mosix.contact)
+				break;
+			schedule();
+		}
+		remove_wait_queue(mos_to_waitp(&p->mosix), &wait);
+		set_current_state(TASK_RUNNING);
+	}
+	if(!(p->mosix.dflags & DPSYNC))
+	{
+		if(!comm_peek())
+			return;
+		if(URGENT_REMOTE_CONDITIONS(p) &&
+					!(p->mosix.dflags & DSENTURGENT))
+			inform_deputy_of_urgent();
+		if(comm_send(REM_NULLMSG, NULL, 0, NULL, 0, 0))
+			remote_disappear();
+	}
+	if(remote_wait(DEP_USERMODE, &head, &hlen))
+		remote_disappear();
+	comm_free(head);
+	if(p->mosix.deputy_regs)
+	{
+		printk("%s: Missing registers on User-Mode",desc_mostask(NULL));
+		mosix_panic("missing regs");
+		remote_disappear();
+	}
+}
+
+void
+inform_deputy_of_urgent(void)
+{
+	struct mosix_task *m = &current->mosix;
+
+	if(m->dflags & (DPASSING|DINCOMING))
+		return;
+#ifdef CONFIG_MOSIX_DIAG
+	if (m->dflags & DSENTURGENT)
+		mosix_panic("urgent already sent");
+#endif /* CONFIG_MOSIX_DIAG */
+
+	spin_lock_irq(&runqueue_lock);
+	m->dflags |= DSENTURGENT;
+	spin_unlock_irq(&runqueue_lock);
+	comm_send_urgent();
+	/* (any errors will be detected by a later communication failure) */
+}
+
+void
+transfer_signals_to_deputy(unsigned int sigs, siginfo_t *info, int ninfo)
+{
+	struct asig_h a;
+
+	a.sigs = sigs;
+	a.nforced = ninfo;
+	comm_send(REM_ASIG, &a, sizeof(a), info, ninfo * sizeof(siginfo_t), 0);
+}
+
+NORET_TYPE void
+remote_disappear(void)
+{
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug)	/* any */
+		printk("%d-disappear\n", current->pid);
+#endif /* CONFIG_MOSIX_DEBUG */
+	do_exit(SIGKILL);
+	/*NOTREACHED*/
+}
+
+long
+remote_standard_system_call(int n, struct pt_regs *regs)
+{
+	struct syscall_h s;
+	struct syscall_ret_h r;
+	char *p, *tofree;
+	int l;
+	int data_from_user;
+	void *head;
+	int rhlen;
+	int error;
+
+	s.n = n;
+	memcpy((caddr_t)s.args, (caddr_t)regs, sizeof(s.args));
+	switch(n)
+	{
+		/* the following system-calls are supposed to ask for the
+		 * following registers - but why wait for them to ask?
+		 */
+		case __NR_fork:
+		case __NR_vfork:
+		case __NR_clone:
+		case __NR_sigaltstack:
+			current->mosix.pass_regs |= BIT_OF_REGISTER(esp);
+			break;
+		case __NR_execve:
+			current->mosix.pass_regs |= BIT_OF_REGISTER(edx);
+			break;
+		case __NR_sigsuspend:
+		case __NR_rt_sigsuspend:
+			current->mosix.pass_regs |= BIT_OF_REGISTER(orig_eax) |
+				BIT_OF_REGISTER(eax) | BIT_OF_REGISTER(eip);
+			break;
+		case __NR_sigreturn:
+		case __NR_rt_sigreturn:
+			current->mosix.pass_regs = ALL_REGISTERS;
+			break;
+	}
+	p = construct_ucache_envelope(&l, &data_from_user, &s, &tofree);
+	bump_syscalls();
+	if(p)
+		bump_copyin(l);
+	/* Cannot use "remote_request" here, because we MUST free "tofree" */
+	error = comm_send(REM_SYSCALL, &s, sizeof(s), p, l, data_from_user);
+	if(tofree)
+		kfree(tofree);
+	if(error || remote_wait(REM_SYSCALL|REPLY, &head, &rhlen))
+		remote_disappear();
+	memcpy(&r, head, sizeof(r));
+	comm_free(head);
+	absorb_deptime(r.deputytime);
+	remote_unpack_read_cache_data(&r);
+	return(r.ret);
+}
+
+void
+mosix_remote_syscall_trace(void)
+{
+	struct rusage r;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(current->mosix.dflags & DPSYNC)
+		panic("mosix_remote_syscall_trace: synced");
+#endif /* CONFIG_MOSIX_DIAG */
+	remote_fill_rusage(&r, 0);
+	if(remote_request(REM_SYSCALL_TRACE, &r, sizeof(r), NULL, 0, 0,
+								NULL, 0))
+		remote_disappear();
+	bump_syscalls();	/* no accurate numbers, but it costs! */
+	wait_for_permission_to_continue();
+}
+
+int
+remote_readpage(struct file *fp, struct page *page)
+{
+	int error;
+	char *buffer = kmap(page);
+	struct bring_page_h b;
+	struct page_ret_h r;
+	int dpagein = (current->mosix.dflags & DPAGEIN) ^ DPAGEIN;
+	register struct task_struct *p = current;
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(p->mosix.dflags & DINCOMING)
+		panic("remote_readpage while migrating\n");
+#endif /* CONFIG_MOSIX_DIAG */
+	if(!PageLocked(page))
+		PAGE_BUG(page);
+	b.fp = home_file(fp);
+	b.offset = page->index << PAGE_CACHE_SHIFT;
+	b.nopage = fp->f_dentry->d_inode->u.remote_i.nopage;
+	if(p->mosix.rfreepages > 0)
+		p->mosix.rfreepages--;
+	else
+		bump_demandpages();
+	if(p->mosix.rpagecredit > 0)
+		p->mosix.rpagecredit--;
+	else
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_CONSIDER)
+			printk("%d: credit is over\n", p->pid);
+#endif /* CONFIG_MOSIX_DEBUG */
+		spin_lock_irq(&runqueue_lock);
+		p->mosix.dflags |= dpagein;
+		spin_unlock_irq(&runqueue_lock);
+	}
+	if(!b.nopage)	/* home rebooted, we should be dead anyway */
+		error = -EIO;
+	else if(!(error = remote_request(REM_PAGE, &b, sizeof(b), NULL, 0, 0,
+		(void **)&r, -sizeof(r))))
+		error = r.ret;
+	if(!error)
+		error = comm_copydata(buffer, PAGE_SIZE, 0);
+	else if(error == -EFBIG)
+	{
+		memset(buffer, 0, PAGE_SIZE);
+		error = 0;
+	}
+	if(error)
+	{
+		ClearPageUptodate(page);
+		SetPageError(page);
+	}
+	else
+		SetPageUptodate(page);
+	UnlockPage(page);
+	kunmap(page);
+	spin_lock_irq(&runqueue_lock);
+	p->mosix.dflags &= ~dpagein;
+	spin_unlock_irq(&runqueue_lock);
+	absorb_deptime(r.deputytime);
+	return(error);
+}
+
+u64
+mosix_remote_tsc(void)
+{
+	u64 r;
+
+	if(remote_request(REM_GETTSC, NULL, 0, NULL, 0, 0,
+						(void **)&r, -sizeof(r)))
+		force_sig(SIGSEGV, current);
+	bump_syscalls();
+	return(r);
+}
+
+int
+remote_setup_frame(struct setupframe_parameters_h *s)
+{
+	struct k_sigaction ka;
+	extern void setup_frame(int, struct k_sigaction *,
+						sigset_t *, struct pt_regs *);
+	extern void setup_rt_frame(int, struct k_sigaction *, siginfo_t *,
+						sigset_t *, struct pt_regs *);
+
+	ka.sa.sa_flags = s->flags;
+	ka.sa.sa_handler = s->handler;
+	ka.sa.sa_restorer = s->restorer;
+	current->sas_ss_sp = s->ss_sp;
+	current->sas_ss_size = s->ss_size;
+	if(s->flags & SA_SIGINFO)
+		setup_rt_frame(s->sig, &ka, &s->info, &s->set, mos_to_regs(&current->mosix));
+	else
+		setup_frame(s->sig, &ka, &s->set, mos_to_regs(&current->mosix));
+	comm_free(s);
+	return(comm_send(DEP_SETUPFRAME|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_nice(long *n)
+{
+	current->nice = *n;
+	comm_free(n);
+	return(comm_send(DEP_NICE|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+void
+remote_do_updinfo(struct disclosure_h *info)
+{
+	int i, j;
+	struct task_struct *p = current;
+
+	p->mosix.disclosure = info->disclosure;
+	p->uid = info->uid;
+	p->gid = info->gid;
+	p->mosix.depinfo.pgrp = info->pgrp;
+	p->mosix.depinfo.session = info->session;
+	p->mosix.depinfo.tgid = info->tgid;
+	for(i = j = 0 ; j < 16 ; i++)
+	switch(info->comm[i])
+	{
+		case '\0':
+			p->mosix.depinfo.comm[j] = '\0';
+			return;
+		case '\n':
+			if(j == 15)
+				p->mosix.depinfo.comm[j] = '\0';
+			p->mosix.depinfo.comm[j++] = '\\';
+			p->mosix.depinfo.comm[j++] = 'n';
+			break;
+		default:
+			p->mosix.depinfo.comm[j++] = info->comm[i];
+	}
+}
+
+int
+remote_updinfo(struct disclosure_h *info)
+{
+	remote_do_updinfo(info);
+	comm_free(info);
+	return(comm_send(DEP_INFO|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_caps(kernel_cap_t *caps)
+{
+	kernel_cap_t effective = *caps & REMOTE_CAPS;
+
+	comm_free(caps);
+	current->cap_effective &= ~REMOTE_CAPS;
+	current->cap_effective |= effective;
+	return(comm_send(DEP_CAPS|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_depcosts(void *info)
+{
+	memcpy((caddr_t)current->mosix.depcost, info,
+		sizeof(current->mosix.depcost));
+	comm_free(info);
+	return(comm_send(DEP_OPCOSTS|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_restore_sigcontext(struct sigcontext **frame)
+{
+	extern int restore_sigcontext(struct pt_regs *, struct sigcontext *,
+									int *);
+	struct restore_sigcontext_ret_h r;
+
+	r.result = restore_sigcontext(mos_to_regs(&current->mosix), *frame,
+									&r.eax);
+
+	comm_free(frame);
+	current->mosix.pass_regs |= BIT_OF_REGISTER(esp);
+	return(comm_send(DEP_RESTORESIGCONTEXT|REPLY, &r, sizeof(r),
+								NULL, 0, 0));
+}
+
+/*
+ * the following routine, if called within process-migration,
+ * returns the fact of an error, rather than sends back a reply:
+ */
+int
+remote_mmap(struct mmap_parameters_h *m, int inmig)
+{
+	unsigned long result;
+	struct file *rf;
+	unsigned long prot, flags;
+	extern asmlinkage long sys_madvise(unsigned long, size_t, int);
+
+	if(m->fp)
+	{
+		if(!(rf = get_remote_file(m->origin, m->fp, m->dp, m->uniq,
+							m->isize, m->nopage)))
+		{
+			result = -EDOITATHOME;
+			goto err;
+		}
+	}
+	else
+		rf = NULL;
+	/* unconvert prot+flags: */
+	prot = 0;
+	flags = MAP_PRIVATE;
+	if(m->fixed)
+		flags |= MAP_FIXED;
+	if(m->flags & VM_GROWSDOWN)
+		flags |= MAP_GROWSDOWN;
+	if(m->flags & VM_DENYWRITE)
+		flags |= MAP_DENYWRITE;
+	if(m->flags & VM_EXECUTABLE)
+		flags |= MAP_EXECUTABLE;
+	if(m->flags & VM_READ)
+		prot |= VM_READ;
+	if(m->flags & VM_WRITE)
+		prot |= VM_WRITE;
+	if(m->flags & VM_EXEC)
+		prot |= VM_EXEC;
+	if(m->flags & VM_MAYSHARE)
+		current->mosix.dirty_bits |= MMAP_MAYSHARE;
+	result = do_mmap_pgoff(rf, m->addr, m->len, prot, flags, m->pgoff);
+	if(m->flags & VM_MAYSHARE)
+		current->mosix.dirty_bits &= ~MMAP_MAYSHARE;
+	if(rf && !IS_ERR((const void *)result))
+	{
+		int pages = (m->len + PAGE_SIZE - 1) / PAGE_SIZE;
+
+		current->mosix.rpagecredit += pages;
+		if(current->mosix.dflags & DINCOMING)
+			current->mosix.rfreepages += pages;
+	}
+	if(m->flags & VM_READHINTMASK)
+		sys_madvise(m->addr, m->len, (m->flags & VM_SEQ_READ) ?
+						MADV_RANDOM : MADV_SEQUENTIAL);
+	err:
+	if(rf)
+		fput(rf);
+	if(inmig)
+		return(IS_ERR((const void *)result));
+	comm_free(m);
+	return(comm_send(DEP_MMAP|REPLY, &result, sizeof(result), NULL, 0, 0));
+}
+
+int
+remote_brk(struct brk_parameters_h *b)
+{
+	long result = do_brk(b->addr, b->len);
+
+	comm_free(b);
+	return(comm_send(DEP_BRK|REPLY, &result, sizeof(result), NULL, 0, 0));
+}
+
+int
+remote_munmap(struct munmap_parameters_h *m)
+{
+	int result = do_munmap(current->mm, m->addr, m->len);
+
+	comm_free(m);
+	return(comm_send(DEP_MUNMAP|REPLY, &result, sizeof(result), NULL, 0, 0));
+}
+
+int
+remote_mprotect(struct mprotect_parameters_h *m)
+{
+	extern asmlinkage int sys_mprotect(unsigned long,size_t,unsigned long);
+	int result = sys_mprotect(m->addr, m->len, m->prot);
+
+	comm_free(m);
+	return(comm_send(DEP_MPROTECT|REPLY, &result, sizeof(result), NULL, 0, 0));
+}
+
+int
+remote_copy_from_user(struct user_copy_h *u)
+{
+	int result;
+	void *to;
+	int direct = ucache_ok((unsigned long)u->addr, (unsigned long)u->size,
+								VM_READ);
+
+	if(direct)
+	{
+		result = 0;
+		to = u->addr;
+	}
+	else
+	{
+		if(!(to = kmalloc(u->size, GFP_KERNEL)))
+			result = u->size;
+		else if(u->verify)
+			result = copy_from_user(to, u->addr, u->size);
+		else
+			result = __copy_from_user(to, u->addr, u->size);
+	}
+	result = comm_send(DEP_COPY_FROM_USER|REPLY, &result, sizeof(result),
+		(result == u->size) ? NULL : to, u->size - result, direct);
+	bump_copyin(u->size);
+	comm_free(u);
+	if(!direct && to)
+		kfree(to);
+	return(result);
+}
+
+int
+remote_copy_to_user(struct user_copy_h *u)
+{
+	int result;
+
+	if(u->verify && !access_ok(VERIFY_WRITE, u->addr, u->size))
+		result = u->size;
+	else
+	{
+		result = comm_copydata(u->addr, u->size, 1);
+		if(result < 0)
+			result = u->size;
+	}
+	if(result)
+		comm_flushdata(COMM_ALLDATA);
+	bump_copyout(u->size);
+	comm_free(u);
+	return(comm_send(DEP_COPY_TO_USER|REPLY, &result, sizeof(result),
+		NULL, 0, 0));
+}
+
+int
+remote_data_to_user(struct user_copy_h *u)
+{
+	int error = (comm_copydata(u->addr, u->size, 1) != 0);
+
+	bump_copyout(u->size);
+	comm_free(u);
+	if(error)
+		comm_flushdata(COMM_ALLDATA);
+	/* No Reply! */
+	return(error);
+}
+
+int
+remote_clear_user(struct user_copy_h *u)
+{
+	int result = u->verify ? clear_user(u->addr, u->size) :
+				__clear_user(u->addr, u->size);
+
+	comm_free(u);
+	return(comm_send(DEP_CLEAR_USER|REPLY, &result, sizeof(result),
+		NULL, 0, 0));
+}
+
+int
+remote_strncpy_from_user(struct user_copy_h *u)
+{
+	int result;
+	void *to = kmalloc(u->size, GFP_KERNEL);
+
+	if(!to)
+		result = -ENOMEM;
+	else if(u->verify)
+		result = strncpy_from_user(to, u->addr, u->size);
+	else
+		result = __strncpy_from_user(to, u->addr, u->size);
+	comm_free(u);
+	result = comm_send(DEP_STRNCPY_FROM_USER|REPLY, &result, sizeof(result),
+		result > 0 ? to : NULL, result > 0 ? result : 0, 0);
+	if(to)
+		kfree(to);
+	if(result > 0)
+		bump_copyin(result);
+	return(result);
+}
+
+int
+remote_strnlen_user(struct strnlen_user_h *u)
+{
+	long result;
+	char c;
+
+	if(u->len)
+		result = strnlen_user(u->addr, u->len);
+	else  /* "strnlen_user" does not handle "0 bytes remaining" correctly */
+		result = !copy_from_user(&c, u->addr, 1);
+	comm_free(u);
+	return(comm_send(DEP_STRNLEN_USER|REPLY, &result, sizeof(result),
+		NULL, 0, 0));
+}
+
+int
+remote_verify_write(struct user_copy_h *u)
+{
+	int result = __verify_write(u->addr, u->size);
+
+	comm_free(u);
+	return(comm_send(DEP_VERIFY_WRITE|REPLY, &result, sizeof(result),
+		NULL, 0, 0));
+}
+
+int
+remote_csum_copy_from_user(struct user_csum_copy_h *u)
+{
+	struct user_csum_copy_ret_h r;
+	void *to = kmalloc(u->len, GFP_KERNEL);
+	int result;
+
+	r.error = 0;
+	if(!to)
+		r.error = -ENOMEM;
+	else
+		r.newsum = csum_partial_copy_from_user(u->addr, to, u->len,
+			u->sum, &r.error);
+	result = comm_send(DEP_CSUM_COPY_FROM_USER|REPLY, &r, sizeof(r),
+		r.error ? NULL : to, r.error ? 0 : u->len, 0);
+	bump_copyin(u->len);
+	comm_free(u);
+	if(to)
+		kfree(to);
+	return(result);
+}
+
+int
+remote_rlimit(struct rlimit_h *l)
+{
+	current->rlim[l->resource] = l->limit;
+	comm_free(l);
+	return(comm_send(DEP_RLIMIT|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_urgent(void)
+{
+	register struct task_struct *p = current;
+	int w;
+
+	spin_lock_irq(&runqueue_lock);
+	p->mosix.dflags &= ~DSENTURGENT;
+	spin_unlock_irq(&runqueue_lock);
+	spin_lock_irq(&whereto_lock);
+	w = p->mosix.whereto;
+	p->mosix.whereto = 0;
+	spin_unlock_irq(&whereto_lock);
+#ifdef CONFIG_MOSIX_DFSA
+	if(process_told(p, DREQ_DFSASYNC))
+	{
+		remote_clear_dfsa();
+		clear_dfsasync();
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(comm_send(DEP_TAKEURGENT|REPLY, &w, sizeof(w), NULL, 0, 0));
+}
+
+int
+remote_rusage(int *finalp)
+{
+	struct rusage r;
+
+	/* "*finalp" just means that calculation of "exit_mem" is required */
+	remote_fill_rusage(&r, *finalp);
+	comm_free(finalp);
+	return(comm_send(DEP_RUSAGE|REPLY, &r, sizeof(r), NULL, 0, 0));
+}
+
+void
+remote_fill_rusage(struct rusage *r, int final)
+{
+	register struct task_struct *p = current;
+	struct vm_area_struct *vma;
+	clock_t ut, st;
+
+	cli();
+	ut = p->times.tms_utime;
+	st = p->times.tms_stime;
+	p->times.tms_utime = 0;
+	p->times.tms_stime = 0;
+	sti();
+	r->ru_utime.tv_sec = CT_TO_SECS(ut);
+	r->ru_utime.tv_usec = CT_TO_USECS(ut);
+	p->mosix.passedtime += ut;
+	p->mosix.uttime += ut;
+	r->ru_stime.tv_sec = CT_TO_SECS(st);
+	r->ru_stime.tv_usec = CT_TO_USECS(st);
+	p->mosix.passedtime += st;
+	r->ru_minflt = p->min_flt;
+	p->min_flt = 0;
+	r->ru_majflt = p->maj_flt;
+	p->maj_flt = 0;
+	r->ru_nswap = p->nswap;
+	p->nswap = 0;
+	if(final)
+	{
+		r->ru_maxrss = 0;
+		if (current->mm)
+		for(vma = current->mm->mmap ; vma ; vma = vma->vm_next)
+			r->ru_maxrss += vma->vm_end - vma->vm_start;
+	}
+}
+
+int
+remote_execve_counts(struct execve_counts_h *e)
+{
+	struct execve_counts_ret_h r;
+
+	execve_remote_counts(e->argp, e->envp, &r.argc, &r.envc);
+	comm_free(e);
+	return(comm_send(DEP_EXECVE_COUNTS|REPLY, &r, sizeof(r), NULL, 0, 0));
+}
+
+int
+remote_bring_strings(struct execve_bring_strings_h *b)
+{
+	struct linux_binprm bprm;
+	struct execve_bring_strings_ret_h r;
+	struct execve_more_strings_h m;
+	int i;
+	int err = 0;
+	char *kaddr;
+
+	bprm.p = b->p;
+	bprm.filename = b->filename;
+	bprm.envc = b->envc;
+	bprm.argc = b->argc;
+	memset(bprm.page, 0, MAX_ARG_PAGES * sizeof(bprm.page[0]));
+	current->mosix.inexec = &bprm;
+	r.result = execve_remote_bring_strings(&bprm, b->envp, b->argp);
+	r.p = bprm.p;
+	r.exec = bprm.exec;
+	comm_free(b);
+	if(r.result == 0)
+	{
+		for(i = r.p / PAGE_SIZE ; i < MAX_ARG_PAGES - 1 ; i++)
+		if(bprm.page[i])
+		{
+			m.pgno = i + 1;
+			m.len = (i + 1) * PAGE_SIZE - r.p;
+			if(m.len > PAGE_SIZE)
+				m.len = PAGE_SIZE;
+			if(!err)
+			{
+				kaddr = kmap(bprm.page[i]);
+				err = comm_send(REM_MORESTRINGS, &m, sizeof(m),
+				      kaddr + (PAGE_SIZE - m.len), m.len, 0);
+				kunmap(bprm.page[i]);
+			}
+			__free_page(bprm.page[i]);
+			bprm.page[i] = 0;
+		}
+	}
+	if(!err)
+	{
+		if(r.result == 0 && bprm.page[MAX_ARG_PAGES-1])
+		{
+			r.pgno = MAX_ARG_PAGES;
+			r.len = MAX_ARG_PAGES * PAGE_SIZE - r.p;
+			if(r.len > PAGE_SIZE)
+				r.len = PAGE_SIZE;
+			kaddr = kmap(bprm.page[MAX_ARG_PAGES-1]);
+		}
+		else
+		{
+			r.pgno = 0;
+			kaddr = NULL;	/* only to pacify the compiler */
+		}
+		err = comm_send(DEP_BRING_STRINGS|REPLY, &r, sizeof(r), r.pgno ?
+			(kaddr + (PAGE_SIZE-r.len)) : 0, r.pgno ? r.len : 0, 0);
+		if(r.pgno)
+			kunmap(bprm.page[MAX_ARG_PAGES-1]);
+	}
+	for(i = 0 ; i < MAX_ARG_PAGES ; i++)
+	if(bprm.page[i])
+		__free_page(bprm.page[i]);
+	current->mosix.inexec = NULL;
+	return(err);
+}
+
+int
+remote_setup_args(struct execve_setup_args_h *e)
+{
+	int i;
+	struct task_struct *p = current;
+	register struct linux_binprm *bprm = p->mosix.inexec;
+	struct execve_setup_args_ret_h r;
+	int err = 0;
+	struct page *page;
+	char *kaddr;
+
+	if(e->create)
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		if(p->mosix.inexec)
+		{
+			printk("%d-Dup create in remote_setup_args!\n", p->pid);
+			err = -EDIST;
+			goto out;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		if((bprm = p->mosix.inexec = kmalloc(sizeof(*bprm),GFP_KERNEL)))
+			memset(bprm->page, 0,
+					MAX_ARG_PAGES * sizeof(bprm->page[0]));
+	}
+	if(bprm && e->pgno)
+	{
+		if(!(page = alloc_page(GFP_HIGHUSER)))
+		{
+			comm_flushdata(e->len);
+			goto fail;
+		}
+		bprm->page[e->pgno-1] = page;
+		kaddr = kmap(page);
+		i = comm_copydata(kaddr + (PAGE_SIZE - e->len), e->len, 0);
+		if(e->len < PAGE_SIZE)
+			memset(kaddr, 0, PAGE_SIZE - e->len);
+		kunmap(page);
+		if(i)
+		{
+			fail:
+			for(i = 0 ; i < MAX_ARG_PAGES ; i++)
+			if(bprm->page[i])
+				__free_page(bprm->page[i]);
+			kfree(bprm);
+			bprm = p->mosix.inexec = NULL;
+		}
+	}
+	else if(e->pgno)
+		comm_flushdata(e->len);
+	if(e->how == SETUP_ARGS_NOTYET)
+		goto out;
+	if(!p->mosix.inexec)	/* one of the allocations failed */
+		r.reply = -ENOMEM;
+	else
+	{
+		if(e->how == SETUP_ARGS_AS_ELF)
+		{
+			p->mm->start_data = 0;
+			p->mm->end_data = 0;
+			p->mm->end_code = 0;
+			p->mm->rss = 0;
+			p->mm->mmap = NULL;
+		}
+		bprm->p = e->p;
+		bprm->loader = e->loader;
+		bprm->exec = e->exec;
+		bprm->argc = e->argc;
+		bprm->envc = e->envc;
+		p->personality = e->personality;
+		r.reply = setup_arg_pages(bprm);
+		if(e->how == SETUP_ARGS_AS_AOUT)
+		{
+			if(r.reply == 0)
+				p->mm->start_stack = (unsigned long)
+				create_aout_tables((char *)bprm->p, bprm);
+		}
+		else
+			p->mm->start_stack = bprm->p;
+		r.p = bprm->p;
+		r.loader = bprm->loader;
+		r.exec = bprm->exec;
+		if(r.reply == 0)
+			p->ptrace &= ~PT_DTRACE;
+		r.start_stack = p->mm->start_stack;
+	}
+	p->mosix.pass_regs |= BIT_OF_REGISTER(xds)|BIT_OF_REGISTER(xes)|
+		BIT_OF_REGISTER(xss)|BIT_OF_REGISTER(xcs)|BIT_OF_REGISTER(eip)|
+		BIT_OF_REGISTER(esp);
+	err = comm_send(DEP_SETUP_ARGS|REPLY, &r, sizeof(r), NULL, 0, 0);
+	mosix_decay_exec();
+	out:
+	if(e->how != SETUP_ARGS_NOTYET && bprm)
+	{
+		kfree(bprm);
+		p->mosix.inexec = NULL;
+	}
+	comm_free(e);
+	return(err);
+}
+
+int
+remote_exec_mmap(void)
+{
+	int r;
+
+	if(!(r = exec_mmap()))
+	{
+		flush_thread();
+		mosix_clear_statistics();
+		current->mosix.rpagecredit = 0;
+		current->mosix.rfreepages = 0;
+		current->sas_ss_sp = current->sas_ss_size = 0;
+	}
+	return(comm_send(DEP_EXEC_MMAP|REPLY, &r, sizeof(r), NULL, 0, 0));
+}
+
+int
+remote_dump_thread(void)
+{
+	extern void dump_thread(struct pt_regs *, struct user *);
+	struct user u;
+	/* (size == 286 bytes -- should be OK while allocation can fail) */
+
+	dump_thread(mos_to_regs(&current->mosix), &u);
+	return(comm_send(DEP_DUMP_THREAD|REPLY, &u, sizeof(u), NULL, 0, 0));
+}
+
+int
+remote_init_aout_mm(struct exec *ex)
+{
+	aout_remote_init_mm(ex);
+	comm_free(ex);
+	return(comm_send(DEP_INIT_AOUT_MM|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_elf_setup(struct execve_elf_setup_h *e)
+{
+	unsigned long r;
+	struct elfhdr h;
+
+	h.e_phoff = e->exec_e_phoff;
+	h.e_phnum = e->exec_e_phnum;
+	h.e_entry = e->exec_e_entry;
+	r = elf_remote_setup(e->p, e->argc, e->envc, e->hasexec ? &h : NULL,
+		e->addr, e->load_bias, e->interp_load_addr, e->ibcs,
+		e->add_arg_start, e->elf_brk, e->end_code,
+		e->start_code, e->start_data, e->end_data, e->elf_bss,
+		e->personality, &e->extras);
+	comm_free(e);
+	return(comm_send(DEP_ELF_SETUP|REPLY, &r, sizeof(r), NULL, 0, 0));
+}
+
+int
+remote_fix_elf_aout(struct execve_fix_elf_aout_h *f)
+{
+	current->mm->brk = f->bss +
+		(current->mm->end_data = f->data +
+			(current->mm->end_code = f->text));
+	comm_free(f);
+	return(comm_send(DEP_FIX_ELF_AOUT|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_list_vmas(void)
+{
+	register int i;
+	register struct vm_area_struct *vma;
+	struct mm_struct *mm = current->mm;
+	struct vmalist *lis = NULL;
+	struct list_vmas_ret_h r;
+	int error;
+
+	if(!mm)
+		mosix_panic("remote_list_vmas: no mm");
+	r.argstart = current->mm->arg_start;
+	r.argend = current->mm->arg_end;
+	for(i = 0 , vma = mm->mmap ; vma ; vma = vma->vm_next)
+		i++;
+	if(i && !(lis = kmalloc(i * sizeof(struct vmalist), GFP_KERNEL)))
+		i = -1;
+	if((r.n = i) <= 0)
+		return(comm_send(DEP_LIST_VMAS|REPLY, &r, sizeof(r), NULL,0,0));
+	for(i = 0 , vma = mm->mmap ; vma && i < r.n ; vma = vma->vm_next , i++)
+	{
+		lis[i].vmstart = vma->vm_start;
+		lis[i].vmend = vma->vm_end;
+		lis[i].vmflags = vma->vm_flags;
+		lis[i].maydump = elf_maydump(vma);
+	}
+	error = comm_send(DEP_LIST_VMAS|REPLY, &r, sizeof(r),
+		lis, i * sizeof(struct vmalist), 0);
+	kfree(lis);
+	return(error);
+}
+
+int
+remote_fork(struct fork_h *f)
+{
+	struct mosix_task *me = &current->mosix;
+	struct fork_h lf = *f;
+	mosix_addr a;
+	mosix_link *sonsock;
+	int pid;
+	register struct task_struct *son;
+	int err;
+	int tries;
+	int done, ret;
+
+	comm_free(f);
+	mosix_obtain_registers(ALL_REGISTERS & ~BIT_OF_REGISTER(eax));
+	if(lf.do_forkmigrate)
+		mosix_forkmigrate();	/* may not return */
+	ret = -EAGAIN;
+	for(tries = 0 ; ; tries++)
+	{
+		if(tries >= 100 || !(sonsock =
+				comm_open(COMM_ACCEPT, &a, comm_remote_timo)))
+			goto out;
+		if((err = remote_request(REM_CONNECT_TO, &a, sizeof(a),
+				NULL, 0, 0, (void **)&done, -sizeof(done))))
+		{
+			comm_close(sonsock);
+			return(err);
+		}
+		if(done)
+			break;
+		comm_close(sonsock);
+	}
+	me->sonpid = lf.pid;
+	if((pid = do_fork(SIGCHLD|CLONE_SIGHAND
+#ifndef CONFIG_MOSIX_DFSA
+		|CLONE_FS|CLONE_FILES
+#endif /* CONFIG_MOSIX_DFSA */
+		, lf.usp, mos_to_regs(me), 0)) < 0)
+	{
+		comm_close(sonsock);
+		goto out;
+	}
+	read_lock(&tasklist_lock);
+	for_each_task(son)
+	if(son->pid == pid)
+		break;
+	read_unlock(&tasklist_lock);
+	comm_use(son, sonsock);
+	wake_up(mos_to_waitp(&son->mosix));
+	ret = 0;
+	out:
+	return(comm_send(DEP_PLEASE_FORK|REPLY, &ret, sizeof(ret), NULL, 0, 0));
+}
+
+int
+remote_personality(unsigned long *pp)
+{
+	int res;
+	unsigned long personality = *pp;
+
+	comm_free(pp);
+	set_personality(personality);
+	res = (current->personality == personality) ? 0 : -1;
+	return(comm_send(DEP_PERSONALITY|REPLY, &res, sizeof(res), NULL, 0, 0));
+}
+
+int
+remote_bring_me_regs(unsigned long *bring)
+{
+	struct mosix_task *m = &current->mosix;
+
+	m->pass_regs |= *bring & ~m->deputy_regs;
+	comm_free(bring);
+	return(comm_send(DEP_BRING_ME_REGS|REPLY, NULL, 0, NULL, 0, 0));
+}
+
+int
+remote_dump_fpu(void)
+{
+	extern int dump_fpu (struct pt_regs *, struct user_i387_struct *);
+	struct user_i387_struct f;
+	int r = dump_fpu(mos_to_regs(&current->mosix), &f);
+
+	return(comm_send(DEP_DUMP_FPU|REPLY, &r, sizeof(r),
+		r ? &f : NULL, r ? sizeof(f) : 0, 0));
+}
+
+int
+remote_come_back(void *head)
+{
+	struct mosix_task *m = &current->mosix;
+	int reason = *((int *) head);
+	int reply;
+	int omigpages;
+
+	comm_free(head);
+	if(!(omigpages = current->mosix.migpages))
+		m->migpages = count_migrating_pages();
+	if (mig_send_request(reason, FROM_REMOTE))
+	{
+		m->migpages = omigpages;
+		return (-EDIST);
+	}
+	spin_lock_irq(&runqueue_lock);
+	m->dflags |= DPASSING;
+	spin_unlock_irq(&runqueue_lock);
+	
+#ifdef CONFIG_MOSIX_DEBUG
+	if(ds_debug & (DSDEB_MIG|DSDEB_MIGSTAGE))
+		printk("%d-remote_come_back: 2\n", current->pid);
+#endif /* CONFIG_MOSIX_DEBUG */
+	release_migrations(m->deppe);
+	reply = mig_do_send();
+	m->migpages = omigpages;
+	spin_lock_irq(&runqueue_lock);
+	m->dflags &= ~DPASSING;
+	spin_unlock_irq(&runqueue_lock);
+	return(reply);
+}
+
+int
+remote_goto_remote(void *head)
+{
+	struct task_struct *p = current;
+	mosix_link *remsock = NULL;
+	mosix_link *depsock;
+	struct please_migrate_h *pm = (struct please_migrate_h *)head;
+	int reason = pm->reason;
+	int status = 1;
+	int error;
+	int whereto = pm->to;
+	int omigpages;
+
+	spin_lock_irq(&runqueue_lock);
+	p->mosix.dflags |= DPASSING;
+	spin_unlock_irq(&runqueue_lock);
+	remsock = comm_open(COMM_TOADDR, &pm->ma, comm_reconn_timo);
+	comm_free(head);
+	if (!remsock)
+		goto reply;
+
+	depsock = comm_use(p, remsock);
+	if(!(omigpages = p->mosix.migpages))
+		current->mosix.migpages = count_migrating_pages();
+	if ((error = mig_send_request(reason, FROM_REMOTE)))
+		goto cont;
+
+	release_migrations(whereto);
+	if (!mig_do_send())
+		status = 0;
+cont:
+	p->mosix.migpages = omigpages;
+	comm_use(p, depsock);
+	comm_close(remsock);
+
+reply:
+	error = comm_send(DEP_PLEASE_MIGRATE | REPLY, (void *)&status,
+						sizeof(status), NULL, 0, 0);
+	if (!(status || error))
+		remote_disappear();
+	spin_lock_irq(&runqueue_lock);
+	p->mosix.dflags &= ~DPASSING;
+	spin_unlock_irq(&runqueue_lock);
+	return (error);
+}
+
+int
+remote_consider(int *reasonp)
+{
+	int reason = *reasonp;
+
+	comm_free(reasonp);
+	consider(reason, NULL);
+	return(0);
+}
+
+int
+remote_psinfo(void)
+{
+	int n;
+	char *p = fill_common_ps_info(&n);
+	int err;
+
+	if(!p)
+		return(comm_send(DEP_PSINFO|REPLY, &n, sizeof(n), NULL, 0, 0));
+	err = comm_send(DEP_PSINFO|REPLY, &n, sizeof(n), p, n, 0);
+	kfree(p);
+	return(err);
+}
+
+#ifdef CONFIG_MOSIX_DFSA
+int
+remote_receive_dfsachanges(int *head)
+{
+	int len = *head;
+	char *changes;
+	int error = 0;
+
+	comm_free(head);
+#ifdef CONFIG_MOSIX_DIAG
+	if(len <= 0)
+	{
+		printk("%s: remote_receive_dfschanges: len=%d\n",
+						desc_mostask(NULL), len);
+		return(-EINVAL);
+	}
+#endif /* CONFIG_MOSIX_DIAG */
+	if((changes = kmalloc(len, GFP_KERNEL)))
+	{
+		if((error = comm_copydata(changes, len, 0)))
+		{
+			remote_clear_dfsa();
+			kfree(changes);
+		}
+		else
+			remote_unpack_dfsa_changes(changes);
+	}
+	else
+		remote_clear_dfsa();
+	
+	if(!error)
+		error = comm_send(DEP_DFSA_CHANGES|REPLY, NULL, 0, NULL, 0, 0);
+	return(error);
+}
+#endif /* CONFIG_MOSIX_DFSA */
+
+void
+absorb_deptime(unsigned long ticks)
+{
+	register struct task_struct *p = current;
+	unsigned long it_prof = p->it_prof_value;
+
+	if(it_prof)
+	{
+		cli();
+		if(it_prof > ticks)
+		{
+			p->it_prof_value -= ticks;
+			sti();
+		}
+		else
+		{
+			p->it_prof_value = p->it_prof_incr;
+			sti();
+			send_sig(SIGPROF, p, 1);
+		}
+	}
+}
diff -ruN linux-2.4.16/mos/rinode.c linux-2.4.16-mosix/mos/rinode.c
--- linux-2.4.16/mos/rinode.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/rinode.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,688 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <linux/mosix.h>
+#include <linux/smp_lock.h>
+#include <linux/file.h>
+#include <linux/dcache.h>
+#include <linux/slab.h>
+#include <mos/routines.h>
+#include <mos/debug.h>
+
+/* REMOTE section: */
+
+spinlock_t rinode_list_lock = SPIN_LOCK_UNLOCKED;
+
+#ifdef CONFIG_MOSIX_UDB
+void
+count_files(void)
+{
+	struct mm_struct *mm = current->mm;
+	struct vm_area_struct *vma;
+	struct file *f;
+
+	if(!mm) { printk("no MM\n"); return; }
+	for(vma = mm->mmap ; vma ; vma = vma->vm_next)
+	if((f = vma->vm_file))
+		printk("File %x, count=%d\n", (int)f, file_count(f));
+}
+#endif /* CONFIG_MOSIX_UDB */
+
+#define	next_entry(dp)	((struct dentry *)(dp)->d_fsdata)
+
+static struct dentry *rinode_list = NULL;
+
+static int remote_dentry_delete(struct dentry *);
+static void remote_dentry_iput(struct dentry *, struct inode *);
+static int mosix_remote_file_mmap(struct file *, struct vm_area_struct *);
+
+static struct dentry_operations remote_dentry_ops =
+{
+	d_delete: remote_dentry_delete,
+	d_iput: remote_dentry_iput
+};
+
+static struct file_operations remote_file_operations =
+{
+	mmap: mosix_remote_file_mmap,
+};
+
+struct address_space_operations remote_aops =
+{
+	readpage: remote_readpage,
+};
+
+void
+invalidate_old_remote_pages(struct inode *ip)
+{
+	down(&ip->i_sem);
+	/* we prefer "invalidate_inode_pages",
+	   but it does not work on locked pages */
+	truncate_inode_pages(ip->i_mapping, 0);
+	up(&ip->i_sem);
+}
+
+struct file *
+get_remote_file(int origin, struct file *fpr, struct dentry *dpr, uint64_t uniq, off_t isize,
+								nopage_t nopage)
+{
+	register struct file *f;
+	register struct dentry *d, *d2;
+	register struct inode *ip, *i2;
+	struct vm_area_struct *vma;
+	int cng;
+	struct dentry *to_dput = NULL;
+	struct inode *to_iput = NULL;
+
+	for(vma = current->mm->mmap ; vma ; vma = vma->vm_next)
+	if((f = vma->vm_file) && home_file(f) == fpr)
+	{
+		ip = f->f_dentry->d_inode;
+		if(ip->u.remote_i.origin == origin && ip->u.remote_i.dp == dpr
+			&& ip->u.remote_i.unique == uniq && ip->i_size == isize
+			&& ip->u.remote_i.nopage == nopage)
+		{
+			get_file(f);
+			return(f);
+		}
+	}
+	if(!(f = get_empty_filp()))
+		return(NULL);
+	spin_lock(&dcache_lock);
+	spin_lock(&rinode_list_lock);
+	for(d = rinode_list ; d ; d = next_entry(d))
+	{
+		ip = d->d_inode;
+#ifdef CONFIG_MOSIX_DIAG
+		if(!ip)
+		{
+			mosix_panic("get_remote_file: dcache race");
+			break;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		if(ip->u.remote_i.origin == origin && ip->u.remote_i.dp == dpr)
+		{
+			join_in:
+			cng = (ip->u.remote_i.unique != uniq) ||
+				(ip->u.remote_i.nopage != nopage) ||
+				(isize < ip->i_size);
+			ip->i_size = isize;
+			if(cng)
+			{
+				ip->u.remote_i.unique = uniq;
+				ip->u.remote_i.nopage = nopage;
+			}
+			dget(d);
+			spin_unlock(&rinode_list_lock);
+			spin_unlock(&dcache_lock);
+			if(to_iput)
+				iput(to_iput);
+			if(to_dput)
+				dput(to_dput);
+			if(cng)
+				invalidate_old_remote_pages(ip);
+			f->f_dentry = d;
+			f->f_op = &remote_file_operations;
+			f->f_mode = FMODE_READ;
+			home_file(f) = fpr;
+			return(f);
+		}
+	}
+	spin_unlock(&rinode_list_lock);
+	spin_unlock(&dcache_lock);
+	if(!(ip = get_empty_inode()))
+	{
+		put_filp(f);
+		return(NULL);
+	}
+	ip->i_mode = S_IFREG;
+	ip->u.remote_i.origin = origin;
+	ip->u.remote_i.dp = dpr;
+	ip->u.remote_i.unique = uniq;
+	ip->u.remote_i.nopage = nopage;
+	ip->i_size = isize;
+	ip->i_fop = &remote_file_operations;
+	ip->i_mapping->a_ops = &remote_aops;
+	if(!(d = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 })))
+	{
+		put_filp(f);
+		iput(ip);
+		return(NULL);
+	}
+	d->d_parent = d;
+	/* any copy created while we slept? */
+	spin_lock(&dcache_lock);
+	spin_lock(&rinode_list_lock);
+	for(d2 = rinode_list ; d2 ; d2 = next_entry(d2))
+	{
+		i2 = d2->d_inode;
+#ifdef CONFIG_MOSIX_DIAG
+		if(!i2)
+		{
+			mosix_panic("get_remote_file: dcache race (2)");
+			break;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		if(i2->u.remote_i.origin == origin && i2->u.remote_i.dp == dpr)
+		{
+			to_iput = ip;
+			to_dput = d;
+			d = d2;
+			ip = i2;
+			goto join_in;
+		}
+	}
+	d->d_op = &remote_dentry_ops;
+	d->d_inode = ip;
+	next_entry(d) = rinode_list;
+	rinode_list = d;
+	f->f_dentry = d;
+	f->f_op = &remote_file_operations;
+	f->f_mode = 1;
+	home_file(f) = fpr;
+	spin_unlock(&rinode_list_lock);
+	spin_unlock(&dcache_lock);
+	return(f);
+}
+
+/*
+ * called by fput(fd) ==> dput(d)
+ */
+
+static int
+remote_dentry_delete(struct dentry *del)
+{
+	register struct dentry *dp;
+
+	spin_lock(&rinode_list_lock);
+	if(del == rinode_list)
+		rinode_list = next_entry(del);
+	else
+	{
+		for(dp = rinode_list ; dp && next_entry(dp) != del ;
+							dp = next_entry(dp))
+		if(!dp)
+			panic("remote dentry not listed");
+		next_entry(dp) = next_entry(del);
+	}
+	spin_unlock(&rinode_list_lock);
+	return(1);
+}
+
+static void
+remote_dentry_iput(struct dentry *dp, struct inode *ip)
+{
+	invalidate_old_remote_pages(ip);
+	iput(ip);
+}
+
+struct vm_operations_struct rinode_mmap =
+{
+	nopage: filemap_nopage,
+};
+
+static int
+mosix_remote_file_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	if (vma->vm_flags & VM_SHARED)
+		panic("REMOTE VM_SHARED mmap");
+	vma->vm_ops = &rinode_mmap;
+	return(0);
+}
+
+int
+remote_report_files(void)
+{
+	register struct vm_area_struct *vma, *vmb;
+	struct mm_struct *mm = current->mm;
+	struct file **fp = NULL;
+	int n = 0;
+	int result;
+
+	down_read(&mm->mmap_sem);
+	for(vma = mm->mmap ; vma ; vma = vma->vm_next)
+	if(vma->vm_file)
+	{
+		for(vmb = mm->mmap ; vmb != vma ; vmb = vmb->vm_next)
+		if(vmb->vm_file == vma->vm_file)
+			break;
+		if(vmb == vma)
+			n++;
+	}
+	up_read(&mm->mmap_sem);
+	if(n && !(fp = kmalloc(n * sizeof(struct file *), GFP_KERNEL)))
+		n = -EAGAIN;
+	else
+	{
+		down_read(&mm->mmap_sem);
+		for(n = 0 , vma = mm->mmap ; vma ; vma = vma->vm_next)
+		if(vma->vm_file)
+		{
+			for(vmb = mm->mmap ; vmb != vma ; vmb = vmb->vm_next)
+			if(vmb->vm_file == vma->vm_file)
+				break;
+			if(vmb == vma)
+				fp[n++] = home_file(vma->vm_file);
+		}
+		up_read(&mm->mmap_sem);
+	}
+	result = comm_send(DEP_LISTHOLD|REPLY, &n, sizeof(int),
+		fp, n > 0 ? n * sizeof(struct file *) : 0, 0);
+	if(n > 0)
+		kfree(fp);
+	return(result);
+}
+
+void
+rinode_flush_files(int pe)
+{
+	register struct dentry *dp;
+	register struct inode *ip;
+
+#ifdef CONFIG_MOSIX_DEBUG
+	if (ds_debug & (DSDEB_CONFIG|DSDEB_MIG))
+		printk("%s-rinode_flush_files: for pe %d\n",
+							desc_mostask(NULL), pe);
+#endif
+
+	loop:
+	spin_lock(&rinode_list_lock);
+	for(dp = rinode_list ; dp ; dp = next_entry(dp))
+	{
+		ip = dp->d_inode;
+#ifdef CONFIG_MOSIX_DIAG
+		if(!ip)
+		{
+			mosix_panic("rinode_flush_files: dcache race");
+			break;
+		}
+#endif /* CONFIG_MOSIX_DIAG */
+		if(ip->u.remote_i.origin == pe && ip->u.remote_i.nopage)
+		{
+			ip->u.remote_i.dp = NULL;
+			/* (the pointer is no good and any process
+			 * still using this inode is doomed anyway) */
+			ip->u.remote_i.unique = 0xffffffffffffffffULL;
+			ip->u.remote_i.nopage = NULL;
+			spin_unlock(&rinode_list_lock);
+			invalidate_old_remote_pages(ip);
+			goto loop;
+		}
+	}
+	spin_unlock(&rinode_list_lock);
+}
+
+/* DEPUTY section: */
+
+#define DEFAULT_ALLOCATION	10
+
+#define	ALLOCATED_NEW		1
+#define	ALLOCATED_NEW_AND_DENY	2
+#define	ADDED_A_DENY		3
+#define	FOUND_OLD		4
+
+int
+mosix_register_a_file(struct file *fp, int denywrite)
+{
+	struct task_struct *p = current;
+	register int i, new;
+	struct held_files *nh, *oh;
+	struct mm_struct *mm;
+
+	if(!p->mosix.held_allocated)
+	{
+		if((mm = p->mm) && atomic_read(&mm->mm_realusers) > 1)
+			return(0);
+		nh = NULL;	/* COMPILER BUG -- hope it is optimized out */
+		for(i = DEFAULT_ALLOCATION ; i > 0 ; i >>= 1)
+		if((nh = (struct held_files *)
+			kmalloc(i * sizeof(struct held_files), GFP_KERNEL)))
+			break;
+		if(!nh)
+			return(-ENOMEM);
+		memset(nh, 0, i * sizeof(struct held_files));
+		task_lock(p);
+		p->mosix.held_files = nh;
+		p->mosix.held_allocated = i;
+		task_unlock(p);
+		new = 0;
+	}
+	else
+	{
+		new = -1;
+		for(i = 0 ; i < p->mosix.held_allocated ; i++)
+		if((struct file *)p->mosix.held_files[i].f == fp)
+		{
+			if(!denywrite || p->mosix.held_files[i].denywrite)
+				return(FOUND_OLD);
+			if(deny_write_access(fp))
+				return(-ETXTBSY);
+			p->mosix.held_files[i].denywrite = 1;
+			return(ADDED_A_DENY);
+		}
+		else if(new == -1 && !p->mosix.held_files[i].f)
+			new = i;
+		if(new == -1)
+		{
+			nh = NULL;/* COMPILER BUG -- hope it is optimized out */
+			for(i = DEFAULT_ALLOCATION ; i > 0 ; i >>= 1)
+			if((nh = kmalloc((i + p->mosix.held_allocated) *
+				sizeof(struct held_files), GFP_KERNEL)))
+				break;
+			if(!i)
+				return(-ENOMEM);
+			for(new = p->mosix.held_allocated + i - 1 ;
+				new >= p->mosix.held_allocated ; new--)
+				nh[new].f = NULL;
+			for(new = 0 ; new < p->mosix.held_allocated ; new++)
+				nh[new] = p->mosix.held_files[new];
+			oh = p->mosix.held_files;
+			task_lock(p);
+			p->mosix.held_files = nh;
+			p->mosix.held_allocated += i;
+			task_unlock(p);
+			kfree(oh);
+		}
+	}
+	get_file(fp);
+	task_lock(p);
+	p->mosix.held_files[new].f = fp;
+	task_unlock(p);
+	if((p->mosix.held_files[new].denywrite = denywrite))
+	{
+		if(deny_write_access(fp))
+		{
+			task_lock(p);
+			p->mosix.held_files[new].f = NULL;
+			task_unlock(p);
+			return(-ETXTBSY);
+		}
+		return(ALLOCATED_NEW_AND_DENY);
+	}
+	else
+		return(ALLOCATED_NEW);
+}
+
+void
+mosix_undo_last_file_registration(struct file *fp, int result)
+{
+	register int i;
+	struct mosix_task *m = &current->mosix;
+
+	if(result == FOUND_OLD)
+		return;
+	for(i = 0 ; i < m->held_allocated ; i++)
+	if((struct file *)m->held_files[i].f == fp)
+	{
+		switch(result)
+		{
+			case ADDED_A_DENY:
+			case ALLOCATED_NEW_AND_DENY:
+				if(!m->held_files[i].denywrite)
+					printk("%s: mosix_undo_last_file_registration - no denywrite\n",
+						desc_mostask(m));
+				else
+					allow_write_access(fp);
+				if(result == ADDED_A_DENY)
+					break;
+			case ALLOCATED_NEW:
+				fput(fp);
+				task_lock(current);
+				m->held_files[i].f = NULL;
+				task_unlock(current);
+				break;
+		}
+		return;
+	}
+	printk("%s: mosix_undo_last_file_registration - not found\n",
+		desc_mostask(m));
+}
+
+void
+mosix_update_remote_files(void)
+{
+	struct task_struct *p = current;
+	register struct held_files *h = p->mosix.held_files;
+	register int i, j;
+	int op, np;
+	struct file **rf;
+	struct file *fp;
+
+	if(!(op = p->mosix.held_allocated))
+		return;
+	if(deputy_request(DEP_LISTHOLD, NULL, 0, NULL, 0, 0,
+						(void **)&np, -sizeof(int)))
+		deputy_die_on_communication();
+	if(np < 0 || (np && comm_recvdata((void **)&rf) < 0))
+		deputy_die_on_communication();
+	for(j = 0 ; j < op ; j++)
+		h[j].denywrite = (h[j].denywrite != 0) | 2;
+	for(i = 0 ; i < np ; i++)
+	{
+		for(j = 0 ; j < op ; j++)
+		if(h[j].f == rf[i])
+		{
+			h[j].denywrite &= ~2;
+			break;
+		}
+		if(j == op)
+			panic("mosix_update_remote_files: not listed");
+	}
+	for(j = 0 ; j < op ; j++)
+	if((fp = h[j].f) && (h[j].denywrite & 2))
+	{
+#ifdef CONFIG_MOSIX_DEBUG
+		if(ds_debug & DSDEB_HOLD)
+			printk("%s-mosix_update_remote_files: freeing %x\n",
+				desc_mostask(NULL), (int)fp);
+#endif /* CONFIG_MOSIX_DEBUG */
+		task_lock(p);
+		h[j].f = NULL;
+		task_unlock(p);
+		if(h[j].denywrite & 1)
+			allow_write_access(fp);
+		fput(fp);
+	}
+	if(np)
+		comm_free(rf);
+}
+
+int
+mosix_rebuild_file_list(void)
+{
+	struct task_struct *p = current;
+	register struct vm_area_struct *vma, *vmb;
+	struct mm_struct *mm = p->mm;
+	struct held_files *hf = NULL, *old;
+	int i, n, oldn;
+	int denywrite;
+	struct file *this;
+
+	if(p->mosix.dflags & DDEPUTY)
+	{
+		if(p->mosix.dflags & DINCOMING)
+			p->mosix.dflags |= DDELAYHELD;
+		else
+			mosix_update_remote_files();
+		return(0);
+	}
+	if(atomic_read(&mm->mm_realusers) > 1)
+	{
+		mosix_clear_all_held_files(p);	/* discard old */
+		return(-EBUSY);	/* thread */
+	}
+	/* because we are the only clone, no MM lock is needed */
+	/* and the initial count cannot change */
+
+	for(n = 0 , vma = mm->mmap ; vma ; vma = vma->vm_next)
+	if((this = vma->vm_file))
+	{
+		for(vmb = mm->mmap ; vmb != vma ; vmb = vmb->vm_next)
+		if(vmb->vm_file == vma->vm_file)
+			break;
+		if(vmb == vma)
+		{
+			if(this->f_dentry->d_inode->i_mapping->i_mmap_shared)
+			{
+				monkey:
+				mosix_clear_all_held_files(p);
+				tell_process(p, DREQ_CHECKSTAY);
+				return(-EDIST);
+			}
+			n++;
+		}
+	}
+	if(n && !(hf = kmalloc(n*sizeof(struct held_files), GFP_KERNEL)))
+	{
+		mosix_clear_all_held_files(p);	/* discard old */
+		return(-ENOMEM);
+	}
+	for(n = 0 , vma = mm->mmap ; vma ; vma = vma->vm_next)
+	if((this = vma->vm_file))
+	{
+		for(vmb = mm->mmap ; vmb != vma ; vmb = vmb->vm_next)
+		if(vmb->vm_file == this)
+			goto already_placed;
+		denywrite = 0;
+		for(; vmb ; vmb = vmb->vm_next)
+		if(vmb->vm_file == this && (vmb->vm_flags & VM_DENYWRITE))
+		{
+			denywrite = 1;
+			atomic_dec(&this->f_dentry->d_inode->i_writecount);
+			break;
+		}
+		get_file(this);
+		hf[n].f = this;
+		hf[n++].denywrite = denywrite;
+		already_placed:;
+	}
+	/* must not use "mosix_clear_all_held_files" because it could sleep */
+	/* in 'fput' when another held file becomes VMONKEY */
+	oldn = p->mosix.held_allocated;
+	old = p->mosix.held_files;
+	task_lock(p);
+	p->mosix.held_files = hf;
+	p->mosix.held_allocated = n;
+	task_unlock(p);
+	if(old)
+	{
+		for(i = 0 ; i < oldn ; i++)
+		if((this = old[i].f))
+		{
+			if(old[i].denywrite)
+				allow_write_access(this);
+			fput(this);
+		}
+		kfree(old);
+	}
+	/* final race check: has any file been made monkey meanwhile? */
+	for(i = 0 ; i < n ; i++)
+	if(hf[i].f->f_dentry->d_inode->i_mapping->i_mmap_shared)
+		goto monkey;
+	return(0);
+}
+
+int
+fork_mosix_remote_files(struct task_struct *p)
+{
+	register int i;
+	register struct file *fp;
+
+	if(!(p->mosix.held_allocated = current->mosix.held_allocated))
+		return(0);
+	if(!(p->mosix.held_files = kmalloc(p->mosix.held_allocated *
+		sizeof(struct held_files), GFP_KERNEL)))
+	{
+		p->mosix.held_allocated = 0;
+		return(-ENOMEM);
+	}
+	for(i = 0 ; i < current->mosix.held_allocated ; i++)
+	if((fp = (struct file *)current->mosix.held_files[i].f))
+	{
+		get_file(fp);
+		p->mosix.held_files[i].f = fp;
+		if((p->mosix.held_files[i].denywrite =
+			current->mosix.held_files[i].denywrite))
+			atomic_dec(&fp->f_dentry->d_inode->i_writecount);
+	}
+	else
+		p->mosix.held_files[i].f = NULL;
+	return(0);
+}
+
+void
+mosix_clear_all_held_files(struct task_struct *p)
+{
+	register int i, n;
+	struct held_files *h;
+
+	if(!(n = p->mosix.held_allocated))
+		return;
+	h = p->mosix.held_files;
+	task_lock(p);
+	p->mosix.held_files = NULL;
+	p->mosix.held_allocated = 0;
+	task_unlock(p);
+	for(i = 0 ; i < n ; i++)
+	if(h[i].f)
+	{
+		if(h[i].denywrite)
+			allow_write_access(h[i].f);
+		fput(h[i].f);
+	}
+	kfree(h);
+}
+
+int
+task_maps_ip(struct task_struct *p, struct inode *ip)
+{
+	register int i, n;
+	int ret = 0;
+	struct held_files *h;
+
+	task_lock(p);
+	if((n = p->mosix.held_allocated))
+	for(h = p->mosix.held_files , i = 0 ; i < n ; i++)
+	if(h[i].f && (h[i].f)->f_dentry->d_inode == ip)
+	{
+		ret = 1;
+		break;
+	}
+	task_unlock(p);
+	return(ret);
+}
+
+#ifdef CONFIG_MOSIX_DEBUG
+void
+mosix_print_remote_files(struct mosix_task *m)
+{
+	register int i;
+	struct file *f;
+
+	if(!m)
+		m = &current->mosix;
+	printk("%s -- REMOTE FILES: Allocated=%d\n", desc_mostask(m),
+							m->held_allocated);
+	for(i = 0 ; i < m->held_allocated ; i++)
+	if((f = m->held_files[i].f))
+		printk("%d:%x: inode=%x, d_ino=%x, count=%x, deny=%d\n", i,
+			(int)f->f_dentry,
+			(int)f->f_dentry->d_inode,
+			(int)f->f_dentry->d_inode->i_ino,
+			atomic_read(&f->f_dentry->d_inode->i_count),
+			m->held_files[i].denywrite);
+}
+#endif /* CONFIG_MOSIX_DEBUG */
diff -ruN linux-2.4.16/mos/service.c linux-2.4.16-mosix/mos/service.c
--- linux-2.4.16/mos/service.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/service.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,481 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/mosctl.h>
+#include <net/sock.h>
+#include <mos/defs.h>
+#include <mos/routines.h>
+#include <mos/debug.h>
+#include <mos/protocol.h>
+#include <linux/mosix.h>
+#include <asm/uaccess.h>
+#include <asm/mmu_context.h>
+#include <linux/smp_lock.h>
+#include <linux/swap.h>
+#include <linux/stddef.h>
+#include <linux/mm.h>
+#include <linux/delay.h>
+#include <asm/pgtable.h>
+
+/* all sorts of operating-system dependent mob */
+
+void
+common_daemon_setup(char *name, int highpri)
+{
+	register struct task_struct *p = current;
+	struct fs_struct *fs;
+	struct files_struct *fl;
+
+	strcpy(p->comm, name);
+	exit_mm(p);
+	exit_files(p);
+	fl = init_task.files;
+	p->files = fl;
+	atomic_inc(&fl->count);
+	exit_fs(p);
+	fs = init_task.fs;
+	p->fs = fs;
+	atomic_inc(&fs->count);
+#ifdef CONFIG_MOSIX_DFSA
+	atomic_inc(&fs->users);
+#endif /* CONFIG_MOSIX_DFSA */
+	
+	p->pgrp = 1;
+	p->session = 1;
+	p->tty = NULL;
+	reparent_to_init();
+	p->it_real_incr = 0;
+	p->it_prof_incr = 0;
+	p->it_virt_incr = 0;
+	p->it_real_value = 0;
+	p->it_prof_value = 0;
+	p->it_virt_value = 0;
+	if(p->uid)
+	{
+		free_uid(p->user);
+		p->uid = 0;
+		alloc_uid(0);
+	}
+	p->euid = 0;
+	p->suid = 0;
+	p->gid = 0;
+	p->ngroups = 0;
+	spin_lock_irq(&p->sigmask_lock);
+	sigemptyset(&p->blocked);
+	recalc_sigpending(p);
+	spin_unlock_irq(&p->sigmask_lock);
+	memcpy(p->rlim, init_task.rlim, sizeof(p->rlim));
+	task_lock(p);
+	if(highpri)
+	{
+		p->policy = SCHED_FIFO;
+		p->mosix.stay |= DSTAY_FOR_RT;
+		p->rt_priority = 0;
+	}
+	else
+	{
+		p->policy = SCHED_OTHER;
+		p->mosix.stay &= ~DSTAY_FOR_RT;
+		p->nice = DEF_NICE;
+	}
+	p->mosix.stay |= DSTAY_ITS_DAEMON;
+	task_unlock(p);
+}
+
+char *
+desc_mostask(struct mosix_task *m)
+{
+	register struct task_struct *p = m ? MOSIX_TO_TASK(m) : current;
+	/* paranoid: save space for each SMP + interrupts */
+	static char descbuf[NR_CPUS+2][14+sizeof(p->comm)];
+	static int ind;
+	static spinlock_t desc_lock = SPIN_LOCK_UNLOCKED;
+	int i;
+
+	spin_lock_irq(&desc_lock);
+	i = ind;
+	ind = (i + 1) % (NR_CPUS+2);
+	spin_unlock_irq(&desc_lock);
+	
+	sprintf(descbuf[i], "%d(%s)", p->pid, p->comm);
+	return(descbuf[i]);
+}
+
+asmlinkage void ret_from_kickstart(void) __asm__("ret_from_kickstart");
+
+#define loaddebug(tsk,register) \
+		__asm__("movl %0,%%db" #register  \
+			: /* no output */ \
+			:"r" (tsk->thread.debugreg[register]))
+
+void
+kickstart(void)
+{
+	register struct task_struct *p = current;
+	struct pt_regs *regs, *curegs = mos_to_regs(&p->mosix);
+
+	set_fs(USER_DS);
+	regs = ((struct pt_regs *) (2*PAGE_SIZE + (unsigned long)p)) - 1;
+	if(regs != curegs)
+	{
+		task_lock(current);
+		*regs = *(curegs);
+		p->mosix.altregs = (uint32_t *)regs;
+		task_unlock(current);
+	}
+	/* the contents of our registers may at this stage still be held
+	 * by our DEPUTY, hence our registers contain junk.
+	 * (which is OK - we are not going to user-mode yet)
+	 * the silly thing about it is that we may get to "ret_from_intr"
+	 * via "do_bottom_half", which might then believe we had a kernel-mode
+	 * interrupt and avoid returning via ret_with_reschedule...
+	 * the remedy is:
+	 */
+	regs->xcs |= 3;
+
+	if(current->thread.debugreg[7])
+	{
+		loaddebug(current,0);
+		loaddebug(current,1);
+		loaddebug(current,2);
+		loaddebug(current,3);
+		loaddebug(current,6);
+		loaddebug(current,7);
+	}
+	release_kernel_lock(current, smp_processor_id());
+	current->lock_depth = -1;
+	/*current->mosix.lock_depth = -1;*/
+	asm("movl %0,%%esp ; jmp ret_from_kickstart" : : "r" (regs));
+	/*NOTREACHED*/
+}
+
+/*
+ * a page on the swap-cache is dirty: even if it happens to be clean relative
+ * to the swap-page, it is NOT clean relative to the original file.
+ */
+static inline int
+pte_really_dirty(pte_t entry)
+{
+	struct page *page;
+
+	if(pte_dirty(entry))
+		return(1);	/* the simple case */
+	page = pte_page(entry);
+	if(!VALID_PAGE(page))
+	{
+#ifdef CONFIG_MOSIX_DIAG
+		mosix_panic("scanning a process with physical map");
+#endif /* CONFIG_MOSIX_DIAG */
+		return(1);
+	}
+	return(PageDirty(page) || PageSwapCache(page));
+}
+
+#define	RUN_OVER_MAGIC	126094
+
+static int run_over_maxchunk;
+
+int
+run_over_dirty_pages(int (*func)(unsigned long, int), int count_in_file)
+{
+	struct task_struct *p = current;
+	struct mm_struct *mm = p->mm;
+	struct vm_area_struct *vma;
+	int count = 0;
+	int isfile;
+	unsigned long start, addr, pgd_end, pmd_end, pte_end;
+	pgd_t *pgdir;
+	pmd_t *pmdir;
+	pte_t *pte;
+	int err;
+	int let_go;
+
+	if(!run_over_maxchunk)
+	{
+		/* this routine can take very long for huge processes:
+		 * we must allow other processes to take over at least
+		 * about every millisecond.
+		 */
+		run_over_maxchunk = loops_per_jiffy / RUN_OVER_MAGIC;
+		if(!run_over_maxchunk)	/* slow processors */
+			run_over_maxchunk = 1;
+	}
+
+#ifdef CONFIG_MOSIX_DIAG
+	if(!mm || mm == &init_mm)
+	{
+		printk("run_over_dirty_pages: no MM!\n");
+		return(0);
+	}
+	if(atomic_read(&mm->mm_realusers) != 1)
+	{
+		printk("run_over_dirty_pages: SHARED! (by %d)\n",
+						atomic_read(&mm->mm_realusers));
+		mosix_panic("SHARED");
+		return(0);
+	}
+	/* so now there is no need to lock mmap_sem! */
+#endif /* CONFIG_MOSIX_DIAG */
+	addr = 0;
+	loop:
+	let_go = run_over_maxchunk;
+	for(vma = mm->mmap ; vma != NULL ; vma = vma->vm_next)
+	if(addr < vma->vm_end)
+	{
+	    start = vma->vm_start;
+	    if(start < addr)
+		start = addr;
+	    pgdir = pgd_offset(mm, start);
+	    isfile = (vma->vm_file != NULL);
+	    for(addr = start ; addr < vma->vm_end ; addr = pgd_end , pgdir++)
+	    {
+		if(let_go-- == 0)
+		{
+			p->policy |= SCHED_YIELD;
+			schedule();
+			goto loop;
+		}
+		pgd_end = (addr + PGDIR_SIZE) & PGDIR_MASK;	
+		if(pgd_end > vma->vm_end)
+			pgd_end = vma->vm_end;
+		if(pgd_none(*pgdir) || pgd_bad(*pgdir))
+			continue;
+		spin_lock(&mm->page_table_lock);
+		pmdir = pmd_offset(pgdir, addr);
+		for(; addr < pgd_end ; addr = pmd_end , pmdir++)
+		{
+		    pmd_end = (addr + PMD_SIZE) & PMD_MASK;
+		    if(pmd_end > pgd_end)
+			    pmd_end = pgd_end;
+		    if(pmd_none(*pmdir) || pmd_bad(*pmdir))
+			    continue;
+		    pte = pte_offset(pmdir, addr);
+		    for(; addr < pmd_end ; addr = pte_end , pte++)
+		    {
+			pte_end = addr + PAGE_SIZE;
+			if(pte_end > pmd_end)
+				pte_end = pmd_end;
+			if(pte_present(*pte) ?
+				(isfile && !pte_really_dirty(*pte)) :
+				pte_none(*pte))
+			{
+				if(isfile && count_in_file)
+					count++;
+				continue;
+			}
+			if(!count_in_file)
+				count++;
+			if(func)
+			{
+				spin_unlock(&mm->page_table_lock);
+				if((err = (*func)(addr, PAGE_SIZE)))
+					return(err);
+				spin_lock(&mm->page_table_lock);
+			}
+		    }
+		}
+		spin_unlock(&mm->page_table_lock);
+	    }
+	}
+	return(count);
+}
+
+#if 0
+/* needed once-only to calibrate the "run_over_maxchunk" calculation */
+/* not bothering using locks here, since we are only called from the debugger */
+int
+calibrate_run_over(void)
+{
+	int sv = run_over_maxchunk;
+	struct mm_struct *mm = current->mm;
+	int chunks = 0;
+	register struct vm_area_struct *vma;
+	unsigned long addr, pgd_end;
+	__typeof__ (jiffies) before;
+	int milli, magic;
+	int i;
+
+	if(!mm)
+	{
+		printk("No MM\n");
+		return(0);
+	}
+
+	for(vma = mm->mmap ; vma != NULL ; vma = vma->vm_next)
+	for(addr = vma->vm_start ; addr < vma->vm_end ; addr = pgd_end)
+	{
+		chunks++;
+		pgd_end = (addr + PGDIR_SIZE) & PGDIR_MASK;	
+		if(pgd_end > vma->vm_end)
+			pgd_end = vma->vm_end;
+	}
+	printk("%d chunks: starting 1000 times...", chunks);
+	run_over_maxchunk = 0x7fffffff;	/* unlimit */
+	sti();
+	before = jiffies;
+	for(i = 0 ; i < 1000 ; i++)
+		run_over_dirty_pages(NULL, 0);
+	milli = (jiffies - before) * 1000 / HZ;
+	printk("%d miliseconds, ", milli);
+	run_over_maxchunk = sv;
+	if(milli < 100)
+	{
+		printk("That was too quick -- try a larger process!\n");
+		return((int)milli);
+	}
+	magic = loops_per_jiffy / (chunks * 1000 / milli);
+	printk("RUN_OVER_MAGIC=%d\n", magic);
+	return(magic);
+}
+#endif /* MOSIX_ONCE_ONLY */
+
+/* provide accurate time in microseconds, even when jiffies wraps around */
+now_t
+time_now(void)
+{
+	static int64_t cycles;
+	static typeof(jiffies) lastj;
+	now_t now;
+	typeof(jiffies) prev;
+	static spinlock_t time_lock = SPIN_LOCK_UNLOCKED;
+
+	if(jiffies == 0 && cycles == 0)
+		return(1);
+	spin_lock_irq(&time_lock);
+	prev = lastj;
+	lastj = jiffies;
+	if(lastj < prev)
+		cycles += 0x100000000LL * MILLION / HZ;
+	now = ticks_to_ms(lastj) + cycles;
+	spin_unlock_irq(&time_lock);
+	return(now);
+}
+
+void
+adjust_task_mosix_context(struct task_struct **tp)
+{
+	struct task_struct *t = *tp;
+
+	if(t->mosix.dflags & DINSCHED)
+		*tp = MOSIX_CONTEXT(t);
+}
+
+int
+obtain_mm(void)
+{
+	struct mm_struct *mm, *active_mm;
+	struct task_struct *p = current;
+	int err;
+
+	if(p->mm)
+		panic("obtain_mm: had already");
+	if(!(mm = mm_alloc()))
+		return(-ENOMEM);
+	if((err = init_new_context(p, mm)))
+	{
+		task_unlock(p);
+		mmdrop(mm);
+		return(err);
+	}
+	spin_lock(&mmlist_lock);
+	list_add(&mm->mmlist, &init_mm.mmlist);
+	mmlist_nr++;
+	spin_unlock(&mmlist_lock);
+	task_lock(p);
+	active_mm = p->active_mm;
+	p->mm = mm;
+	p->active_mm = mm;
+	task_unlock(p);
+	activate_mm(active_mm, mm);
+	mmdrop(active_mm);
+	return(0);
+}
+
+DECLARE_WAIT_QUEUE_HEAD(wait_for_capsync);
+
+void
+sync_caps(void)
+{
+	struct task_struct *p = current;
+	kernel_cap_t prev;
+
+	if(process_told(p, DREQ_CAPCNG))
+	{
+		write_lock_irq(&tasklist_lock);
+		prev = p->mosix.remote_caps;
+		p->mosix.remote_caps = p->cap_effective;
+		process_ack(p, DREQ_CAPCNG);
+		write_unlock_irq(&tasklist_lock);
+		wake_up(&wait_for_capsync);
+		if((p->mosix.dflags & DDEPUTY) &&
+			((prev ^ p->mosix.remote_caps) & REMOTE_CAPS))
+			deputy_request(DEP_CAPS, &p->mosix.remote_caps,
+				sizeof(p->mosix.remote_caps), NULL, 0, 0,
+				NULL, 0);
+	}
+}
+
+int
+mosix_sync_caps(kernel_cap_t effective)
+{
+	int any = 0;
+	struct task_struct *p;
+	DECLARE_WAITQUEUE(wait, current);
+
+	write_lock_irq(&tasklist_lock);
+	for_each_task(p)
+	if((p->mosix.dflags & (DDEPUTY|DFINISHED)) == DDEPUTY &&
+		p->cap_effective == effective &&
+		((p->mosix.remote_caps ^ effective) & REMOTE_CAPS))
+	{
+		tell_process(p, DREQ_CAPCNG);
+		if(p != current)
+		{
+			any = 1;
+			wake_up_mosix(p);
+		}
+	}
+	write_unlock_irq(&tasklist_lock);
+	sync_caps();	/* affecting ourselves is the most common case */
+	if(!any)
+		return(0);
+	add_wait_queue(&wait_for_capsync, &wait);
+	loop:
+	set_current_state(TASK_INTERRUPTIBLE);
+	any = 0;
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	if((p->mosix.dflags & (DDEPUTY|DFINISHED)) == DDEPUTY &&
+		p->cap_effective == effective &&
+		(process_told(p, DREQ_CAPCNG)) &&
+		((p->mosix.remote_caps ^ effective) & REMOTE_CAPS))
+	{
+		any = 1;
+		break;
+	}
+	read_unlock(&tasklist_lock);
+	if(any)
+	{
+		schedule();
+		set_current_state(TASK_RUNNING);
+		if(signal_pending(current))
+		{
+			remove_wait_queue(&wait_for_capsync, &wait);
+			return(-EINTR);
+		}
+		goto loop;
+	}
+	remove_wait_queue(&wait_for_capsync, &wait);
+	return(0);
+}
diff -ruN linux-2.4.16/mos/syscalls.c linux-2.4.16-mosix/mos/syscalls.c
--- linux-2.4.16/mos/syscalls.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/syscalls.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,2461 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/mosix.h>
+#include <linux/timex.h>
+#include <linux/utime.h>
+#include <linux/utsname.h>
+#include <linux/serial.h>
+#include <linux/serialP.h>
+#include <linux/random.h>
+#include <linux/quota.h>
+#include <linux/mm.h>
+#include <linux/sysctl.h>
+#include <linux/socket.h>
+#include <linux/nfs.h>
+#include <linux/net.h>
+#include <linux/sunrpc/svc.h>
+#include <linux/nfsd/nfsd.h>
+#include <linux/nfsd/syscall.h>
+#include <mos/protocol.h>
+#include <mos/routines.h>
+#include <asm/processor.h>
+#include <linux/smp_lock.h>
+#include <asm/uaccess.h>
+#include <asm/ipc.h>
+#include <asm/poll.h>
+#include <linux/sem.h>
+#include <linux/msg.h>
+#include <linux/shm.h>
+#include <linux/hdreg.h>
+#include <linux/capability.h>
+#include <linux/module.h>
+#ifdef CONFIG_MOSIX_DFSA
+#include <mos/dfsa.h>
+#endif /* CONFIG_MOSIX_DFSA */
+
+extern caddr_t sys_call_table[];
+
+#define	set_file_name(x)	do { \
+				unsigned long fn = ((int *)&regs)[x]; \
+				set_write_region(fn, strlen_user((char *)fn)); \
+				} while(0);
+#define	ARG(x)			(((int *)&regs)[x])
+#if BITS_PER_LONG == 32
+#define	LARG(x)			(*((long long *)(((int *)&regs)+(x))))
+#else
+#define	LARG(x)			(*((long *)(((int *)&regs)+(x))))
+#endif
+
+#ifdef CONFIG_MOSIX_DFSA
+#define	RESULT_IS_FINAL(result)	((result) >= 0 || ( \
+	(result) != -EDOITATHOME && (result) != -EINTR && \
+	(result) != -ERESTARTSYS && (result) != -ERESTARTNOINTR && \
+	(result) != -ERESTARTNOHAND && (result) != -EAGAIN))
+#endif /* CONFIG_MOSIX_DFSA */
+
+int
+remote_sys_getpid(int n, struct pt_regs regs)
+{
+	return(current->mosix.depinfo.tgid);
+}
+
+int
+remote_sys_gettid(int n, struct pt_regs regs)
+{
+	return(current->mosix.mypid);
+}
+
+long
+remote_sys_getitimer(int n, struct pt_regs regs)
+{
+	extern asmlinkage long sys_getitimer(int, struct itimerval *);
+
+	if(*((int *)&regs) == ITIMER_REAL)
+	{
+		set_read_region(ARG(1), sizeof(struct itimerval));
+		return(remote_standard_system_call(n, &regs));
+	}
+	return(sys_getitimer(ARG(0), (struct itimerval *)ARG(1)));
+}
+
+long
+remote_sys_setitimer(int n, struct pt_regs regs)
+{
+	extern asmlinkage long sys_setitimer(int, struct itimerval *,
+							struct itimerval *);
+
+	if(*((int *)&regs) == ITIMER_REAL)
+	{
+		if(ARG(1))
+			set_write_region(ARG(1), sizeof(struct itimerval));
+		if(ARG(2))
+			set_read_region(ARG(2), sizeof(struct itimerval));
+		return(remote_standard_system_call(n, &regs));
+	}
+	return(sys_setitimer(ARG(0), (struct itimerval *)ARG(1),
+		(struct itimerval *)ARG(2)));
+}
+
+unsigned long
+remote_sys_brk(int n, struct pt_regs regs)
+{
+	extern asmlinkage unsigned long sys_brk(unsigned long);
+
+	return(sys_brk((unsigned long)ARG(0)));
+}
+
+long
+remote_sys_mprotect(int n, struct pt_regs regs)
+{
+	extern asmlinkage long sys_mprotect(unsigned long, size_t,
+								unsigned long);
+
+	return(sys_mprotect((unsigned long)ARG(0), (size_t)ARG(1),
+		(unsigned long)ARG(2)));
+}
+
+long
+remote_sys_msync(int n, struct pt_regs regs)
+{
+	return(0);	/* no writeable file-mapping allowed remotely! */
+}
+
+long
+remote_sys_munlock(int n, struct pt_regs regs)
+{
+	/* since remote mlocking is not allowed, but we are still here,
+	 * this must only be a "make-sure" call */
+	return(0);
+}
+
+long
+remote_sys_munlockall(int n, struct pt_regs regs)
+{
+	/* since remote mlocking is not allowed, but we are still here,
+	 * this must only be a "make-sure" call */
+	return(0);
+}
+
+unsigned long
+remote_sys_mremap(int n, struct pt_regs regs)
+{
+	extern asmlinkage unsigned long sys_mremap(unsigned long, unsigned long,
+				 unsigned long, unsigned long, unsigned long);
+
+	return(sys_mremap((unsigned long)ARG(0), (unsigned long)ARG(1),
+		(unsigned long)ARG(2), (unsigned long)ARG(3),
+		(unsigned long)ARG(4)));
+}
+
+int
+remote_sys_modify_ldt(int n, int func, void *ptr, unsigned long bytecount)
+{
+	extern asmlinkage int sys_modify_ldt(int, void *, unsigned long);
+
+	return(sys_modify_ldt(func, ptr, bytecount));
+}
+
+long
+remote_sys_sched_yield(void)
+{
+	extern asmlinkage long sys_sched_yield(void);
+
+	return(sys_sched_yield());
+}
+
+long
+remote_sys_mincore(int n, struct pt_regs regs)
+{
+	extern asmlinkage long sys_mincore(unsigned long, size_t,
+							unsigned char *);
+
+	return(sys_mincore((unsigned long)ARG(0), (size_t)ARG(1),
+		(unsigned char *)ARG(2)));
+}
+
+long
+remote_sys_madvise(int n, struct pt_regs regs)
+{
+	extern asmlinkage long sys_madvise(unsigned long, size_t, int);
+
+	return(sys_madvise((unsigned long)ARG(0), (size_t)ARG(1), (int)ARG(2)));
+}
+
+long
+#ifdef CONFIG_MOSIX_DFSA
+remote_sys_close_syscall(int n, struct pt_regs regs)
+#else
+remote_sys_close(int n, struct pt_regs regs)
+#endif /* CONFIG_MOSIX_DFSA */
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_close(unsigned int);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if((p->files->fd[fd] ||
+		(p->mosix.ttab && !FD_ISSET(fd, p->files->open_fds))) &&
+		enter_remote_dfsa_mode())
+	{
+		result = sys_close((unsigned int)ARG(0));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fchdir(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fchdir(unsigned int);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->fs->pwd && p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fchdir(fd);
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_ftruncate(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_ftruncate(unsigned int, unsigned long);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_ftruncate(fd, (unsigned long)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_ftruncate64(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_ftruncate64(unsigned int, loff_t);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_ftruncate64(fd, (loff_t)LARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fchmod(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fchmod(unsigned int, mode_t);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fchmod(fd, (mode_t)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fchown(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fchown(unsigned int, uid_t, gid_t);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fchown(fd, (uid_t)ARG(1), (gid_t)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fchown16(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fchown16(unsigned int, old_uid_t, old_gid_t);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fchown16(fd, (old_uid_t)ARG(1), (old_gid_t)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_dup(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_dup(unsigned int);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_dup(fd);
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_dup2(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_dup2(unsigned int, unsigned int);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_dup2(fd, (unsigned int)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fsync(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fsync(unsigned int);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fsync(fd);
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fdatasync(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fdatasync(unsigned int);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fdatasync(fd);
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_write(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	ssize_t result;
+	extern asmlinkage ssize_t sys_write(unsigned int, char *, size_t);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_write(fd, (char *)ARG(1), ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_write_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_read(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	ssize_t result;
+	extern asmlinkage ssize_t sys_read(unsigned int, char *, size_t);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_read(fd, (char *)ARG(1), ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_open(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_open((char *)ARG(0), ARG(1), ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_waitpid(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(int));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_creat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_creat(char *, int);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_creat((char *)ARG(0), ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_link(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_link(const char *, const char *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_link((const char *)ARG(0), (const char *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_file_name(1);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_unlink(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_unlink(const char *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_unlink((const char *)ARG(0));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_execve(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_chdir(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_chdir(char *);
+
+	if(current->fs->pwd && current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_chdir((char *)ARG(0));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_time(int n, struct pt_regs regs)
+{
+	if(ARG(0))
+		set_read_region(ARG(0), sizeof(int));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_mknod(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_chmod(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_chmod(const char *, mode_t);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_chmod((const char *)ARG(0), (mode_t)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_lchown(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_lchown(const char *, uid_t, gid_t);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_lchown((const char *)ARG(0), (uid_t)ARG(1),
+								(gid_t)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_lchown16(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_lchown16(const char *, old_uid_t, old_gid_t);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_lchown16((const char *)ARG(0), (old_uid_t)ARG(1),
+							(old_gid_t)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_stat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_stat(char *, struct __old_kernel_stat *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_stat((char *)ARG(0),
+					(struct __old_kernel_stat *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct __old_kernel_stat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_stat64(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_stat64(char *, struct stat64 *, long);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_stat64((char *)ARG(0), (struct stat64 *)ARG(1),
+								(long)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct stat64));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_mount(int n, struct pt_regs regs)
+{
+	unsigned long arg, len;
+	set_file_name(0);
+	set_file_name(1);
+	if((arg = ARG(2)))
+	{
+		len = TASK_SIZE - arg;
+		if(len > PAGE_SIZE-1)
+			len = PAGE_SIZE-1;
+		set_write_region(ARG(2), len);
+	}
+	if((arg = ARG(4)))
+	{
+		len = TASK_SIZE - arg;
+		if(len > PAGE_SIZE-1)
+			len = PAGE_SIZE-1;
+		set_write_region(ARG(4), PAGE_SIZE-1);
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_oldumount(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_stime(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(int));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fstat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fstat(unsigned int,
+						struct __old_kernel_stat *);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fstat(fd, (struct __old_kernel_stat *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), sizeof(struct __old_kernel_stat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fstat64(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_fstat64(unsigned int, struct stat64 *, long);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_fstat64(fd, (struct stat64 *)ARG(1), (long)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), sizeof(struct stat64));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_utime(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_utime(char *, struct utimbuf *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_utime((char *)ARG(0), (struct utimbuf *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	if(ARG(1))
+		set_read_region(ARG(1), sizeof(struct utimbuf));
+	return(remote_standard_system_call(n, &regs));
+}
+
+/* NOTE: sys_utimes is not supported for i386,
+ * but should be implemented for Alpha/Sparc */
+
+long
+remote_sys_access(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_access(const char *, int);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_access((const char *)ARG(0), (int)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rename(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_rename(const char *, const char *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_rename((const char *)ARG(0), (const char *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_file_name(1);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_mkdir(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_mkdir(const char *, int);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_mkdir((const char *)ARG(0), ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rmdir(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_rmdir(const char *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_rmdir((const char *)ARG(0));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_pipe(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), 2 * sizeof(long));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_times(int n, struct pt_regs regs)
+{
+	if(ARG(0))
+		set_read_region(ARG(0), sizeof(struct tms));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_acct(int n, struct pt_regs regs)
+{
+	if(ARG(0))
+		set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_umount(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_ioctl(int n, struct pt_regs regs)
+{
+	switch(ARG(1))
+	{
+		/* so many more -- feel free to add: */
+		/* if ambiguous -- add both! */
+		/* but do not include ioctls whose definitions is configurable*/
+		/* also, it is better to not include rare non-tty ioctls,
+		   because it would slow-down the other's performance */
+		case TCGETS:
+		case TIOCGLCKTRMIOS:
+			set_read_region(ARG(2), sizeof(struct termios));
+			break;
+		case TCSETS:
+		case TCSETSF:
+		case TCSETSW:
+		case TIOCSLCKTRMIOS:
+			set_write_region(ARG(2), sizeof(struct termios));
+			break;
+		case TCGETA:
+			set_read_region(ARG(2), sizeof(struct termio));
+			break;
+		case TCSETA:
+		case TCSETAW:
+		case TCSETAF:
+			set_write_region(ARG(2), sizeof(struct termio));
+			break;
+		case TIOCOUTQ:
+		case TIOCGSOFTCAR:
+		case FIONREAD:
+		case FIGETBSZ:
+		case TIOCGETD:
+		case TIOCMGET:
+		case TIOCSERGWILD:
+		case TIOCSERGETLSR:
+		case RNDGETENTCNT:
+			set_read_region(ARG(2), sizeof(int));
+			break;
+		case FIBMAP:
+			set_write_region(ARG(2), sizeof(int));
+			set_read_region(ARG(2), sizeof(int));
+			break;
+		case TIOCPKT:
+		case TIOCSETD:
+		case TIOCSSOFTCAR:
+		case FIONBIO:
+		case TIOCMSET:
+		case TIOCSERSWILD:
+			set_write_region(ARG(2), sizeof(int));
+			break;
+		case TIOCSTI:
+			set_write_region(ARG(2), sizeof(char));
+			break;
+		case TIOCGWINSZ:
+			set_read_region(ARG(2), sizeof(struct winsize));
+			break;
+		case TIOCSWINSZ:
+			set_write_region(ARG(2), sizeof(struct winsize));
+			break;
+		case TIOCGPGRP:
+		case TIOCGSID:
+			set_read_region(ARG(2), sizeof(pid_t));
+			break;
+		case TIOCSPGRP:
+			set_write_region(ARG(2), sizeof(pid_t));
+			break;
+		case TIOCLINUX:
+			/* there are many cases - use the extreme ones: */
+			set_read_region(ARG(2), 1);
+			set_write_region(ARG(2), 36);
+			break;
+		case TIOCTTYGSTRUCT:
+			set_read_region(ARG(2), sizeof(struct tty_struct));
+			break;
+		case TIOCGSERIAL:
+			set_read_region(ARG(2), sizeof(struct serial_struct));
+			break;
+		case TIOCSSERIAL:
+			set_write_region(ARG(2), sizeof(struct serial_struct));
+			break;
+		case TIOCSERGSTRUCT:
+			set_read_region(ARG(2), sizeof(struct async_struct));
+			break;
+		case TIOCGICOUNT:
+			set_read_region(ARG(2), sizeof(struct serial_icounter_struct));
+			break;
+		case HDIO_GETGEO:
+			set_read_region(ARG(2), sizeof(struct hd_geometry));
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fcntl(int n, struct pt_regs regs)
+{
+	unsigned long f = ARG(1);
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+	long result;
+	extern asmlinkage long sys_fcntl(unsigned int, unsigned int,
+								unsigned long);
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(FD_ISSET(fd, p->files->open_fds) && p->files->fd[fd])
+	switch(f)
+	{
+		case F_DUPFD:
+		case F_GETFL:
+		case F_SETFL:
+			if(!enter_remote_dfsa_mode())
+				break;
+			result = sys_fcntl(fd, f, (unsigned long)ARG(2));
+			leave_remote_dfsa_mode();
+			if(RESULT_IS_FINAL(result))
+				return(result);
+			break;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	switch(f)
+	{
+		case F_GETLK:
+			set_read_region(ARG(2), sizeof(struct flock));
+			break;
+		case F_SETLK:
+		case F_SETLKW:
+			set_write_region(ARG(2), sizeof(struct flock));
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fcntl64(int n, struct pt_regs regs)
+{
+	unsigned long f = ARG(1);
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+	long result;
+	extern asmlinkage long sys_fcntl64(unsigned int, unsigned int,
+								unsigned long);
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(FD_ISSET(fd, p->files->open_fds) && p->files->fd[fd])
+	switch(f)
+	{
+		case F_DUPFD:
+		case F_GETFD:
+		case F_SETFD:
+		case F_GETFL:
+		case F_SETFL:
+			if(!enter_remote_dfsa_mode())
+				break;
+			result = sys_fcntl64(fd, f, (unsigned long)ARG(2));
+			leave_remote_dfsa_mode();
+			if(RESULT_IS_FINAL(result))
+				return(result);
+			break;
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	switch(f)
+	{
+		case F_GETLK:
+			set_read_region(ARG(2), sizeof(struct flock));
+			break;
+		case F_SETLK:
+		case F_SETLKW:
+			set_write_region(ARG(2), sizeof(struct flock));
+			break;
+		case F_GETLK64:
+			set_read_region(ARG(2), sizeof(struct flock64));
+			break;
+		case F_SETLK64:
+		case F_SETLKW64:
+			set_write_region(ARG(2), sizeof(struct flock64));
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_olduname(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(struct oldold_utsname));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_chroot(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_ustat(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct ustat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sigpending(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(old_sigset_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_sigaction(int n, struct pt_regs regs)
+{
+	if(ARG(1))
+		set_write_region(ARG(1), sizeof(struct old_sigaction));
+	if(ARG(2))
+		set_read_region(ARG(2), sizeof(struct old_sigaction));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_setrlimit(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(1), sizeof(struct rlimit));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getrlimit(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct rlimit));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_old_getrlimit(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct rlimit));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getrusage(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct rusage));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_gettimeofday(int n, struct pt_regs regs)
+{
+	if(ARG(0))
+		set_read_region(ARG(0), sizeof(struct timeval));
+	if(ARG(1))
+		set_read_region(ARG(1), sizeof(struct timezone));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_settimeofday(int n, struct pt_regs regs)
+{
+	if(ARG(0))
+		set_write_region(ARG(0), sizeof(struct timeval));
+	if(ARG(1))
+		set_write_region(ARG(1), sizeof(struct timezone));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getgroups(int n, struct pt_regs regs)
+{
+	int ng = ARG(0);
+
+	if(ng > 0 && ARG(1))
+		set_read_region(ARG(1), ng * sizeof(gid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getgroups16(int n, struct pt_regs regs)
+{
+	int ng = ARG(0);
+
+	if(ng > 0 && ARG(1))
+		set_read_region(ARG(1), ng * sizeof(old_gid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_setgroups(int n, struct pt_regs regs)
+{
+	int ng = ARG(0);
+
+	if(ng > 0)
+		set_write_region(ARG(1), ng * sizeof(gid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_setgroups16(int n, struct pt_regs regs)
+{
+	int ng = ARG(0);
+
+	if(ng > 0)
+		set_write_region(ARG(1), ng * sizeof(old_gid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+void
+set_select_regions(int n, unsigned long inp, unsigned long outp,
+					unsigned long exp, unsigned long tvp)
+{
+	n = (n + 8*sizeof(long) - 1) / (8*sizeof(long)) * sizeof(long);
+	if(inp)
+	{
+		set_read_region(inp, n);
+		set_write_region(inp, n);
+	}
+	if(outp)
+	{
+		set_read_region(outp, n);
+		set_write_region(outp, n);
+	}
+	if(exp)
+	{
+		set_read_region(exp, n);
+		set_write_region(exp, n);
+	}
+	if(tvp)
+	{
+		set_read_region(tvp, sizeof(struct timeval));
+		set_write_region(tvp, sizeof(struct timeval));
+	}
+}
+
+int
+remote_old_select(int n, struct pt_regs regs)
+{
+	unsigned long a[5];
+
+	if(copy_from_user(a, (char *)ARG(0), sizeof(a)))
+		return(-EFAULT);
+
+	set_write_region(ARG(0), sizeof(a));
+	set_select_regions(a[0], a[1], a[2], a[3], a[4]);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_symlink(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_symlink(const char *, const char *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_symlink((const char *)ARG(0),
+							(const char *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_file_name(1);
+	return(remote_standard_system_call(n, &regs));
+}
+
+
+long
+remote_sys_lstat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_lstat(char *, struct __old_kernel_stat *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_lstat((char *)ARG(0),
+					(struct __old_kernel_stat *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct __old_kernel_stat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_lstat64(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_lstat64(char *, struct stat64 *, long);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_lstat64((char *)ARG(0), (struct stat64 *)ARG(1),
+								(long)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct stat64));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_readlink(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_readlink(const char *, char *, int);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_readlink((const char *)ARG(0), (char *)ARG(1),
+								(int)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_uselib(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_swapon(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_old_readdir(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	int result;
+	extern asmlinkage int old_readdir(unsigned int, void *, unsigned int);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = old_readdir(fd, (void *)ARG(1), (unsigned int)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_old_mmap(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), 6 * sizeof(int));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_truncate(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_truncate(const char *, unsigned long);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_truncate((const char *)ARG(0),
+							(unsigned long)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_truncate64(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_truncate64(const char *, loff_t);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_truncate64((const char *)ARG(0), (loff_t)LARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_statfs(int n, struct pt_regs regs)
+{
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct statfs));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_fstatfs(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct statfs));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_socketcall(int n, struct pt_regs regs)
+{
+	unsigned long a[6];
+	unsigned long alen;
+	struct msghdr hdr;
+	int i;
+	struct iovec io;
+
+	set_write_region(ARG(1), 6 * sizeof(int));
+	if(!copy_from_user(a, (char *)ARG(1), 6 * sizeof(int)))
+	switch(ARG(0))
+	{
+		case SYS_BIND:
+		case SYS_CONNECT:
+			set_write_region(a[1], a[2]);
+			break;
+		case SYS_ACCEPT:
+		case SYS_GETSOCKNAME:
+		case SYS_GETPEERNAME:
+			if(!get_user(alen, (int *)a[2]))
+			{
+				set_write_region(a[2], sizeof(int));
+				set_read_region(a[2], sizeof(int));
+				set_read_region(a[1], alen);
+			}
+			break;
+		case SYS_SOCKETPAIR:
+			set_read_region(a[3], 2 * sizeof(int));
+			break;
+		case SYS_SEND:
+			set_write_region(a[1], a[2]);
+			break;
+		case SYS_SENDTO:
+			set_write_region(a[1], a[2]);
+			set_write_region(a[4], a[5]);
+			break;
+		case SYS_RECV:
+			set_read_region(a[1], a[2]);
+			break;
+		case SYS_RECVFROM:
+			set_read_region(a[1], a[2]);
+			if(a[4] && !get_user(alen, (int *)a[5]))
+			{
+				set_write_region(a[5], sizeof(int));
+				set_read_region(a[5], sizeof(int));
+				set_read_region(a[4], alen);
+			}
+			break;
+		case SYS_SETSOCKOPT:
+			set_write_region(a[3], a[4]);
+			break;
+		case SYS_GETSOCKOPT:
+			if(!get_user(alen, (int *)a[4]))
+			{
+				set_write_region(a[4], sizeof(int));
+				set_read_region(a[4], sizeof(int));
+				set_read_region(a[3], alen);
+			}
+			break;
+		case SYS_SENDMSG:
+			if(copy_from_user(&hdr, (char *)a[1], sizeof(hdr)))
+				break;
+			set_write_region(a[1], sizeof(hdr));
+			if(hdr.msg_name)
+				set_write_region((unsigned long)hdr.msg_name, hdr.msg_namelen);
+			if(hdr.msg_controllen)
+				set_write_region((unsigned long)hdr.msg_control, hdr.msg_controllen);
+			if(hdr.msg_iovlen > 0)
+			{
+				set_write_region((unsigned long)hdr.msg_iov, hdr.msg_iovlen * sizeof(struct iovec));
+				if(hdr.msg_iovlen > 100)
+					hdr.msg_iovlen = 100;
+				for(i = 0 ; i < hdr.msg_iovlen &&
+					!copy_from_user(&io, hdr.msg_iov + i,
+						sizeof(io)) ; i++)
+					set_write_region((unsigned long)io.iov_base, io.iov_len);
+			}
+			break;
+		case SYS_RECVMSG:
+			if(copy_from_user(&hdr, (char *)a[1], sizeof(hdr)))
+				break;
+			set_write_region(a[1], sizeof(hdr));
+			set_read_region(a[1], sizeof(hdr));
+			if(hdr.msg_name)
+				set_read_region((unsigned long)hdr.msg_name, hdr.msg_namelen);
+			if(hdr.msg_control)
+				set_read_region((unsigned long)hdr.msg_control, hdr.msg_controllen);
+			if(hdr.msg_iovlen > 0)
+			{
+				set_write_region((unsigned long)hdr.msg_iov, hdr.msg_iovlen * sizeof(struct iovec));
+				if(hdr.msg_iovlen > 100)
+					hdr.msg_iovlen = 100;
+				for(i = 0 ; i < hdr.msg_iovlen &&
+					!copy_from_user(&io, hdr.msg_iov + i,
+						sizeof(io)) ; i++)
+					set_read_region((unsigned long)io.iov_base, io.iov_len);
+			}
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_syslog(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_newstat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_newstat(char *, struct stat *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_newstat((char *)ARG(0), (struct stat *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct stat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_newlstat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_newlstat(char *, struct stat *);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_newlstat((char *)ARG(0),
+					(struct stat *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	set_read_region(ARG(1), sizeof(struct stat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_newfstat(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_newfstat(unsigned int, struct stat *);
+	unsigned int fd = ARG(0);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_newfstat(fd, (struct stat *)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), sizeof(struct stat));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_uname(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(struct old_utsname));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_wait4(int n, struct pt_regs regs)
+{
+	if(ARG(1))
+		set_read_region(ARG(1), sizeof(int));
+	if(ARG(3))
+		set_read_region(ARG(3), sizeof(struct rusage));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sysinfo(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(struct sysinfo));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_ipc(int n, struct pt_regs regs)
+{
+	int call = ARG(0) & 0xffff;
+	int version = ARG(0) >> 16;
+
+	switch (call)
+	{
+		case SEMOP:
+			set_write_region(ARG(4), ARG(2)*sizeof(struct sembuf));
+			break;
+		case SEMCTL: 
+		{
+			unsigned long fourth;
+
+			if(get_user(fourth, (unsigned long *)ARG(4)))
+				break;
+			set_read_region(ARG(4), sizeof(long));
+			switch(ARG(3))
+			{
+				case IPC_INFO:
+				case SEM_INFO:
+					set_read_region(fourth,
+							sizeof(struct seminfo));
+					break;
+				case IPC_STAT:
+				case SEM_STAT:
+					set_read_region(fourth,
+						sizeof(struct semid_ds));
+					break;
+				case IPC_SET:
+					set_write_region(fourth,
+						sizeof(struct semid_ds));
+				case GETALL:
+					set_read_region(fourth,
+						SEMMNS * sizeof(ushort));
+					break;
+				case SETALL:
+					set_write_region(fourth,
+						SEMMNS * sizeof(ushort));
+					break;
+			}
+			break;
+		}
+		case MSGSND:
+			set_write_region(ARG(4), sizeof(long) + ARG(2));
+			break;
+		case MSGRCV:
+			switch (version) {
+			case 0: {
+				struct ipc_kludge tmp;
+
+				if (!ARG(4))
+					break;
+				if (copy_from_user(&tmp,(struct ipc_kludge *)
+					ARG(4), sizeof (tmp)))
+					break;
+				set_read_region(ARG(4), sizeof(tmp));
+				set_read_region((unsigned long)tmp.msgp,
+							sizeof(long) + ARG(2));
+				}
+				break;
+			case 1: default:
+				set_read_region(ARG(4), sizeof(long) + ARG(2));
+				break;
+			}
+			break;
+		case MSGCTL:
+			switch(ARG(2))
+			{
+				case IPC_INFO:
+				case MSG_INFO:
+					set_read_region(ARG(4),
+							sizeof(struct msginfo));
+					break;
+				case IPC_STAT:
+				case MSG_STAT:
+					set_read_region(ARG(4),
+						sizeof(struct msqid_ds));
+					break;
+				case IPC_SET:
+					set_write_region(ARG(4),
+						sizeof(struct msqid_ds));
+					break;
+			}
+			break;
+		case SHMCTL:
+			switch(ARG(2))
+			{
+				case IPC_SET:
+					set_write_region(ARG(4),
+						sizeof(struct shmid_ds));
+					break;
+				case IPC_INFO:
+					set_read_region(ARG(4),
+						sizeof(struct shminfo));
+					break;
+				case SHM_INFO:
+					set_read_region(ARG(4),
+						sizeof(struct shm_info));
+					break;
+				case SHM_STAT:
+					set_read_region(ARG(4),
+						sizeof(struct shmid_ds));
+					break;
+				case IPC_STAT:
+					set_read_region(ARG(4),
+						sizeof(struct shmid_ds));
+			}
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_sigreturn(int n, struct pt_regs regs)
+{
+	set_write_region(regs.esp - 8, 732);
+	/* Eek, struct sigframe not defined outside arch/i386/kernel/signal.c */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_setdomainname(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), ARG(1));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_newuname(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(struct new_utsname));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_adjtimex(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(struct timex));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sigprocmask(int n, struct pt_regs regs)
+{
+	if(ARG(1))
+		set_write_region(ARG(1), sizeof(old_sigset_t));
+	if(ARG(2))
+		set_read_region(ARG(2), sizeof(old_sigset_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+unsigned long
+remote_sys_create_module(int n, struct pt_regs regs)
+{
+	set_file_name(0);	/* not really a file, but still a string */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_init_module(int n, struct pt_regs regs)
+{
+	set_file_name(0);	/* not really a file, but still a string */
+	set_write_region(ARG(1), sizeof(struct module) + 64);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_delete_module(int n, struct pt_regs regs)
+{
+	set_file_name(0);	/* not really a file, but still a string */
+	return(remote_standard_system_call(n, &regs));
+}
+
+void
+set_max_readable(unsigned long addr)
+{
+	struct vm_area_struct * vma;
+
+	vma = find_vma(current->mm, addr);
+	if (vma && (vma->vm_flags & VM_WRITE) && addr >= vma->vm_start)
+		set_read_region(addr, vma->vm_end - addr);
+}
+
+long
+remote_sys_get_kernel_syms(int n, struct pt_regs regs)
+{
+	set_max_readable(ARG(0));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_quotactl(int n, struct pt_regs regs)
+{
+	set_file_name(1);
+	switch(ARG(0))
+	{
+		case Q_QUOTAON:
+			set_file_name(3);
+			break;
+		case Q_GETQUOTA:
+			set_read_region(ARG(3), sizeof(struct dqblk));
+			break;
+		case Q_GETSTATS:
+			set_read_region(ARG(3), sizeof(struct dqstats));
+			break;
+		case Q_SETQUOTA:
+		case Q_SETUSE:
+		case Q_SETQLIM:
+			set_write_region(ARG(3), sizeof(struct dqblk));
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_bdflush(int n, struct pt_regs regs)
+{
+	if(ARG(0) >= 2 && !(ARG(0) & 1))
+		set_read_region(ARG(1), sizeof(int));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sysfs(int n, struct pt_regs regs)
+{
+	switch(ARG(0))
+	{
+		case 1:
+			set_file_name(1);
+			break;
+		case 2:
+			set_max_readable(2);
+			break;
+	}
+	return(remote_standard_system_call(n, &regs));
+}
+
+off_t
+remote_sys_lseek(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	off_t result;
+	extern asmlinkage off_t sys_lseek(unsigned int, off_t, unsigned int);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_lseek(fd, ARG(1), ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_llseek(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	long result;
+	extern long sys_llseek(unsigned int, unsigned long, unsigned long,
+		loff_t *, int);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_llseek(fd, ARG(1), ARG(2), (loff_t *)ARG(3),
+									ARG(4));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(3), sizeof(loff_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getdents(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	long result;
+	extern asmlinkage long sys_getdents(unsigned int, void *, unsigned int);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_getdents(fd, (void *)ARG(1), (unsigned int)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getdents64(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	long result;
+	extern asmlinkage long sys_getdents64(unsigned int, void *,
+								unsigned int);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_getdents64(fd, (void *)ARG(1),
+							(unsigned int)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_select(int n, struct pt_regs regs)
+{
+	set_select_regions(ARG(0), ARG(1), ARG(2), ARG(3), ARG(4));
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_readv(int n, struct pt_regs regs)
+{
+	int i, l = ARG(2);
+	struct iovec io;
+
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	ssize_t result;
+	extern asmlinkage ssize_t sys_readv(unsigned int, struct iovec*,
+								unsigned long);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_readv(fd, (struct iovec *)ARG(1),
+							(unsigned long)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	if(l > 0)
+		set_read_region(ARG(1), l * sizeof(struct iovec));
+	if(l > 100)
+		l = 100;	/* do not loop forever here */
+	for(i = 0 ; i < l &&
+		!copy_from_user(&io, ((struct iovec *)ARG(1)) + i, sizeof(io)) ;
+									i++)
+		set_read_region((unsigned long)io.iov_base, io.iov_len);
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_writev(int n, struct pt_regs regs)
+{
+	int i, l = ARG(2);
+	struct iovec io;
+
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	ssize_t result;
+	extern asmlinkage ssize_t sys_writev(unsigned int, struct iovec *,
+								unsigned long);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_writev(fd, (struct iovec *)ARG(1),
+							(unsigned long)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	if(l > 0)
+		set_read_region(ARG(1), l * sizeof(struct iovec));
+	if(l > 100)
+		l = 100;	/* do not loop forever here */
+	for(i = 0 ; i < l &&
+		!copy_from_user(&io, ((struct iovec *)ARG(1)) + i, sizeof(io)) ;
+									i++)
+		set_write_region((unsigned long)io.iov_base, io.iov_len);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sysctl(int n, struct pt_regs regs)
+{
+	struct __sysctl_args args;
+	int oldlen;
+
+	if(copy_from_user((char *)&args, (char *)ARG(0), sizeof(args)))
+		return(-EFAULT);
+	set_read_region(ARG(0), sizeof(args));
+	set_write_region((unsigned long)args.name, args.nlen);
+	if(args.oldval && args.oldlenp && !get_user(oldlen, args.oldlenp))
+	{
+		set_write_region((unsigned long)args.oldlenp, sizeof(int));
+		if(oldlen)
+		{
+			set_read_region((unsigned long)args.oldlenp, sizeof(int));
+			set_read_region((unsigned long)args.oldval, oldlen);
+		}
+	}
+	if(args.newval)
+		set_write_region((unsigned long)args.newval, args.newlen);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sched_setparam(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(1), sizeof(struct sched_param));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sched_getparam(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct sched_param));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sched_setscheduler(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(2), sizeof(struct sched_param));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sched_getscheduler(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(2), sizeof(struct sched_param));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_sched_rr_get_interval(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), sizeof(struct timespec));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_nanosleep(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(struct timespec));
+	set_read_region(ARG(1), sizeof(struct timespec));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getresuid(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(uid_t));
+	set_read_region(ARG(1), sizeof(uid_t));
+	set_read_region(ARG(2), sizeof(uid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getresuid16(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(old_uid_t));
+	set_read_region(ARG(1), sizeof(old_uid_t));
+	set_read_region(ARG(2), sizeof(old_uid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_query_module(int n, struct pt_regs regs)
+{
+	if(ARG(0))
+		set_file_name(0); /* not really a file, but still a string */
+	if(ARG(2))
+		set_read_region(ARG(2), ARG(3));
+	set_read_region(ARG(4), sizeof(size_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_poll(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), ARG(1) * sizeof(struct pollfd));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_nfsservctl(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(1), sizeof(struct nfsctl_arg));
+	set_write_region(ARG(2), sizeof(union nfsctl_res));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_getresgid(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(gid_t));
+	set_read_region(ARG(1), sizeof(gid_t));
+	set_read_region(ARG(2), sizeof(gid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_getresgid16(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(old_gid_t));
+	set_read_region(ARG(1), sizeof(old_gid_t));
+	set_read_region(ARG(2), sizeof(old_gid_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_rt_sigreturn(int n, struct pt_regs regs)
+{
+	set_write_region(regs.esp - 8, 892);
+	/*Eek,struct rt_sigframe not defined outside arch/i386/kernel/signal.c*/
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rt_sigaction(int n, struct pt_regs regs)
+{
+	if(ARG(1))
+		set_write_region(ARG(1), sizeof(struct k_sigaction));
+	if(ARG(2))
+		set_read_region(ARG(2), sizeof(struct k_sigaction));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rt_sigprocmask(int n, struct pt_regs regs)
+{
+	if(ARG(1))
+		set_write_region(ARG(1), sizeof(sigset_t));
+	if(ARG(2))
+		set_read_region(ARG(2), sizeof(sigset_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rt_sigpending(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(0), sizeof(sigset_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rt_sigtimewait(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(sigset_t));
+	if(ARG(1))
+		set_read_region(ARG(1), sizeof(siginfo_t));
+	if(ARG(2))
+		set_write_region(ARG(2), sizeof(struct timespec));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_rt_sigqueueinfo(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(2), sizeof(siginfo_t));
+	if(ARG(1))
+		set_read_region(ARG(1), sizeof(siginfo_t));
+	if(ARG(2))
+		set_write_region(ARG(2), sizeof(struct timespec));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_rt_sigsuspend(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(siginfo_t));
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_pread(int n, struct pt_regs regs)
+{
+	set_read_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_pwrite(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(1), ARG(2));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_chown(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_chown(const char *, uid_t, gid_t);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_chown((const char *)ARG(0), (uid_t)ARG(1),
+								(gid_t)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_chown16(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_chown16(const char *, old_uid_t, old_gid_t);
+
+	if(current->mosix.ttab && enter_remote_dfsa_mode())
+	{
+		result = sys_chown16((const char *)ARG(0), (uid_t)ARG(1),
+								(gid_t)ARG(2));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_file_name(0);
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_getcwd(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	long result;
+	extern asmlinkage long sys_getcwd(char *, unsigned long);
+
+	if(current->mosix.ttab && current->fs->pwd && enter_remote_dfsa_mode())
+	{
+		result = sys_getcwd((char *)ARG(0), (unsigned long)ARG(1));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	set_read_region(ARG(0), ARG(1));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_capget(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(struct __user_cap_header_struct));
+	set_read_region(ARG(1), sizeof(struct __user_cap_data_struct));
+	return(remote_standard_system_call(n, &regs));
+}
+
+long
+remote_sys_capset(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(struct __user_cap_header_struct));
+	set_write_region(ARG(1), sizeof(struct __user_cap_data_struct));
+	return(remote_standard_system_call(n, &regs));
+}
+
+int
+remote_sys_sigaltstack(int n, struct pt_regs regs)
+{
+	set_write_region(ARG(0), sizeof(struct sigaltstack));
+	set_read_region(ARG(1), sizeof(struct sigaltstack));
+	return(remote_standard_system_call(n, &regs));
+}
+
+ssize_t
+remote_sys_readahead(int n, struct pt_regs regs)
+{
+#ifdef CONFIG_MOSIX_DFSA
+	unsigned int fd = ARG(0);
+	ssize_t result;
+	extern asmlinkage ssize_t sys_readahead(unsigned int, loff_t, size_t);
+	struct task_struct *p = current;
+
+	if(fd >= p->files->max_fds)
+	{
+		if(p->mosix.ttab)
+			return(-EBADF);
+	}
+	else if(p->files->fd[fd] && enter_remote_dfsa_mode())
+	{
+		result = sys_readahead(fd, (loff_t)LARG(1), (size_t)ARG(3));
+		leave_remote_dfsa_mode();
+		if(RESULT_IS_FINAL(result))
+			return(result);
+	}
+#endif /* CONFIG_MOSIX_DFSA */
+	return(remote_standard_system_call(n, &regs));
+}
diff -ruN linux-2.4.16/mos/ucache.c linux-2.4.16-mosix/mos/ucache.c
--- linux-2.4.16/mos/ucache.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/mos/ucache.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1527 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <linux/sched.h>
+#include <linux/mosix.h>
+#include <mos/defs.h>
+#include <mos/protocol.h>
+#include <mos/comm.h>
+#include <linux/smp_lock.h>
+#include <linux/mm.h>
+#include <linux/pagemap.h>
+#include <asm/uaccess.h>
+#include <linux/slab.h>
+#include <linux/stddef.h>
+#include <mos/debug.h>
+#include <mos/routines.h>
+#include <mos/balance.h>
+
+#ifdef CONFIG_MOSIX_DEBUG
+#define	WHY_NOT_CACHED
+
+extern void print_ucache(void);
+
+void
+breakpoint1(char *str, int arg)
+{
+	if(ds_debug & DSDEB_CACHE)
+	{
+		printk("%s-Cache: ", desc_mostask(NULL));
+		printk(str, arg);
+		printk("\n");
+		print_ucache();
+#ifdef CONFIG_MOSIX_UDB
+		if(ds_debug & DSDEB_CACHESTOP)
+			mosix_panic("cache_stop");
+#endif /* CONFIG_MOSIX_UDB */
+	}
+}
+
+
+#else
+#define	breakpoint1(x,a)	do {} while(0)
+#endif /* CONFIG_MOSIX_DEBUG */
+
+#define	breakpoint(x)	breakpoint1(x, 0)
+
+#define	CACHE_ENTRIES	10
+
+struct cblock
+{
+	/*
+	 * DIRTY but useful NOTE: we actually rely on having at least 3
+	 * longwords before the data! (so don't make it less)
+	 */
+	unsigned long offset;
+	int len;
+	int count;
+	char data[1];
+};
+
+struct data_cache
+{
+	short first;			/* first entry in list, -1 = NONE */
+	short free;			/* first entry in freelist, -1 = NONE */
+	short next[CACHE_ENTRIES];	/* next on list of entries, -1=none */
+	short prev[CACHE_ENTRIES];	/* prev on list of entries, -1=none */
+	char type[CACHE_ENTRIES];	/* see below */
+	unsigned long addr[CACHE_ENTRIES];	/* start address */
+	unsigned long len[CACHE_ENTRIES];	/* end address */
+	struct cblock *bp[CACHE_ENTRIES]; /* where data (if any) is held */
+};
+
+/* types: */
+
+#define	WRITEABLE	1	/* data available from user to kernel */
+#define	WRITEDATA	2	/* data in cache from user to kernel */
+#define WRITE_STATUS	(WRITEABLE|WRITEDATA)	/* user ==> kernel */
+#define	READABLE	4	/* user address valid for reading */
+#define	READDATA	8	/* data for user cached */
+#define	READ_STATUS	(READABLE|READDATA)	/* kernel ==> user */
+#define	SKIP_MARK	16
+
+#define	END_MARK	(-1)
+
+#define	MAX_POSITIVE	0x7ffffffe	/* max value to return in *non_cache */
+#define	MAX_SEGMENT	32768
+#define	READ_SEND_THRESHOLD	MAX_SEGMENT
+
+extern char *pack_read_cache_data(int *);
+
+struct cblock *
+cblock_alloc(unsigned long offset, int len)
+{
+	struct cblock *cb;
+
+	if((cb = kmalloc(len + offsetof(struct cblock, data[0]), GFP_NOIO)))
+	{
+		cb->offset = offset;
+		cb->len = len;
+		cb->count = 1;
+	}
+	return(cb);
+}
+
+int
+alloc_ucache(void)
+{
+	struct mosix_task *m = &current->mosix;
+	register struct data_cache *d;
+	register int i;
+
+	if(!(d = m->ucache))
+	{
+		m->ucache = kmalloc(sizeof (struct data_cache), GFP_NOIO);
+		if(!(d = m->ucache))
+			return(0);
+	}
+#ifdef CONFIG_MOSIX_DIAG
+	else if(d->first != END_MARK)
+		mosix_panic("alloc_ucache: cache was not cleared");
+#endif /* CONFIG_MOSIX_DIAG */
+	/* on free list */
+	d->first = END_MARK;
+	d->free = 0;
+	for(i = 0 ; i < CACHE_ENTRIES ; i++)
+	{
+		d->next[i] = i+1;
+		d->prev[i] = i-1;
+		d->bp[i] = NULL;
+	}
+	d->next[CACHE_ENTRIES-1] = END_MARK;
+	d->prev[0] = END_MARK;
+	breakpoint("ucache allocated");
+	return(1);
+}
+
+inline void
+write_read_cache(struct data_cache *d, int ent)
+{
+	struct user_copy_h u;
+	register struct cblock *bp = d->bp[ent];
+	caddr_t from = &bp->data[d->addr[ent] - bp->offset];
+	int dflags = current->mosix.dflags;
+
+	breakpoint1("write_read_cache, entry %d", ent);
+	u.addr = (char *)d->addr[ent];
+	u.size = d->len[ent];
+	if(dflags & DDEPUTY)
+		comm_send(DEP_DATA_TO_USER, &u, sizeof(u), from, u.size, 0);
+	else if(!(dflags & DFINISHED))
+		copy_to_user(u.addr, from, u.size);
+}
+
+void
+free_ucache(void)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	struct cblock *cb;
+
+	if(d)
+	{
+		breakpoint("free ucache");
+		for(i = d->first ; i != END_MARK ; i = d->next[i])
+		if((cb = d->bp[i]))
+		{
+			if(d->type[i] & READDATA)
+				write_read_cache(d, i);
+			if(--cb->count == 0)
+				kfree(cb);
+		}
+		kfree(d);
+		current->mosix.ucache = NULL;
+	}
+}
+
+int
+alloc_ucache_entry(struct data_cache *d, int after, int type,
+						unsigned long addr, int len)
+{
+	int ent = d->free;
+	int nex;
+
+	if(ent == END_MARK)
+		return(END_MARK);
+	d->free = d->next[ent];
+	if(d->free != END_MARK)
+		d->prev[d->free] = END_MARK;
+	d->type[ent] = type;
+	d->addr[ent] = addr;
+	d->len[ent] = len;
+	d->bp[ent] = NULL;
+	d->prev[ent] = after;
+	nex = d->next[ent] = (after == END_MARK) ? d->first : d->next[after];
+	if(after == END_MARK)
+		d->first = ent;
+	else
+		d->next[after] = ent;
+	if(nex != END_MARK)
+		d->prev[nex] = ent;
+	d->next[ent] = nex;
+	breakpoint1("allocated entry #%d", ent);
+	return(ent);
+}
+
+void
+free_ucache_entry(struct data_cache *d, int ent)
+{
+	struct cblock *cb;
+
+	if(ent == END_MARK)
+		return;
+	if(d->type[ent] & READDATA)
+		write_read_cache(d, ent);
+	if((cb = d->bp[ent]) && --cb->count == 0)
+		kfree(cb);
+	d->bp[ent] = NULL;
+
+	if(d->next[ent] != END_MARK)
+		d->prev[d->next[ent]] = d->prev[ent];
+	if(d->prev[ent] == END_MARK)
+		d->first = d->next[ent];
+	else
+		d->next[d->prev[ent]] = d->next[ent];
+	d->prev[ent] = END_MARK;
+	d->next[ent] = d->free;
+	d->free = ent;
+	breakpoint1("freed entry #%d", ent);
+}
+
+void
+data_was_read(struct data_cache *d, int ent)
+{
+	unsigned long beg, end;
+	int prev, next;
+	unsigned int newlen;
+	/*
+	 * The data from this entry was read and brought back to the REMOTE,
+	 * so it can be discarded - however, if this entry can bridge its
+	 * neighbours on both sides (a common case), it is even better to
+	 * do it and save 2 entries rather than 1!
+	 */
+	d->type[ent] &= ~(READDATA|WRITEDATA);
+	d->type[ent] |= READABLE;
+	if((prev = d->prev[ent]) != END_MARK &&
+		(next = d->next[ent]) != END_MARK &&
+		(d->type[prev] & ~SKIP_MARK) == d->type[ent] &&
+		(d->type[next] & ~SKIP_MARK) == d->type[ent] &&
+		d->bp[prev] == d->bp[ent] &&
+		d->bp[next] == d->bp[ent] &&
+		(beg = d->addr[ent]) == d->addr[prev] + d->len[prev] &&
+		(end = beg + d->len[ent]) == d->addr[next] &&
+		(newlen = end + d->len[next] - d->addr[prev]) <= MAX_POSITIVE)
+	{
+		breakpoint1("data_was_read: Joining around %d", ent);
+		free_ucache_entry(d, ent);
+		/* mostly one non-READDATA entry can have a SKIP_MARK */
+		if(d->type[next] & SKIP_MARK)
+		{
+			d->addr[next] = d->addr[prev];
+			d->len[next] = newlen;
+			free_ucache_entry(d, prev);
+		}
+		else
+		{
+			d->len[prev] = newlen;
+			free_ucache_entry(d, next);
+		}
+	}
+	else if(!(d->type[ent] & WRITEABLE))	/* still of a value... */
+		free_ucache_entry(d, ent);
+}
+
+/*
+ * Flush only the read-cache:
+ * 
+ * mostly, there is no more than one entry involved, so we use
+ * "write_read_cache" to send it back, but if there is more than one entry,
+ * all entries must be packed to minimize the number of communication packets
+ * (unless we are no longer DEPUTY - then we also use "write_read_cache").
+ *
+ * Any entry(ies) marked SKIP_MARK are not flushed.
+ */
+void
+flush_read_cache(void)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	int j = 0;		/* only for the compiler's sake */
+	int n;
+	char *p;
+
+	if(!d)
+		return;
+	breakpoint("flushing read_cache");
+	if(!(current->mosix.dflags & DDEPUTY))
+	{
+		one_by_one:
+		for(i = d->first ; i != END_MARK ; i = d->next[i])
+		if((d->type[i] & (READDATA|SKIP_MARK)) == READDATA)
+		{
+			write_read_cache(d, i);
+			data_was_read(d, i);
+			goto one_by_one;	/* list may be scrambled */
+		}
+		breakpoint("read cache flushed one by one");
+		return;
+	}
+	for(n = 0 , i = d->first ; i != END_MARK ; i = d->next[i])
+	if((d->type[i] & (READDATA|SKIP_MARK)) == READDATA)
+	{
+		if(!n++)
+			j = i;
+	}
+	if(!n)
+	{
+		breakpoint("there was no read-cache to free");
+		return;
+	}
+	if(n == 1)
+	{
+		write_read_cache(d, j);
+		data_was_read(d, j);
+		breakpoint("there was only one read-cache to free");
+		return;
+	}
+	if((p = pack_read_cache_data(&n)))
+	{
+		comm_send(DEP_CACHE_READ_DATA, NULL, 0, p, n, 0);
+		kfree(p);
+		breakpoint("freed multiple read-cache entries");
+	}
+	else	/* no memory -- too bad: */
+		goto one_by_one;
+}
+
+/*
+ * free some entry except the one we are dealing with,
+ * obtaining at least one free entry.
+ * Because CACHE_ENTRIES > 1, there is ALWAYS SOMETHING to free,
+ * but priorities may apply
+ * (the lower, the dearer; the higher, the more disposable).
+ */
+void
+free_some_entry_except(struct data_cache *d, int not_this)
+{
+	register int i;
+	int pri = -1, p;
+	int e = END_MARK;
+	struct cblock *cb;
+	int n = 0;
+	int m = 0;
+
+	breakpoint1("free_some_entry_except #%d", not_this);
+	/*
+	 * first try to flush all complete READDATA entries:
+	 * if all the cblock was filled, all operations on that region were
+	 * very likely completed:
+	 */
+	for(i = d->first ; i != END_MARK ; i = d->next[i])
+	if(d->type[i] & READDATA)
+	{
+		m++;
+		if(i == not_this || d->addr[i] != (cb = d->bp[i])->offset ||
+			d->len[i] != cb->len)
+			d->type[i] |= SKIP_MARK;
+		else if(!n++)
+			e = i;
+	}
+	if(n == 1)
+	{
+		write_read_cache(d, e);
+		d->type[not_this] |= SKIP_MARK;	/* (even if not READDATA) */
+		data_was_read(d, e);
+	}
+	else if(n)	/* should be pretty rare, but still save on packets */
+		flush_read_cache();
+	if(m)
+	for(i = d->first ; i != END_MARK ; i = d->next[i])
+		d->type[i] &= ~SKIP_MARK;
+	if(d->free != END_MARK)
+		return;
+	again:
+	for(e = END_MARK , i = d->first ; i != END_MARK ; i = d->next[i])
+	if(i != not_this)
+	{
+		/* PRIORITY POLICY:
+		 * generally, WRITEDATA is dearer than READDATA because it would
+		 * be a pity to lose the already existing data.
+		 * In both cases, the SHORTER the data the dearer, because
+		 * the extra communication would cost more per-byte.
+		 * (remember that the data is incomplete within its cblock -
+		 * when complete, it can be joined with other entries)
+		 * Also, READABLE is dearer than WRITEABLE because more
+		 * system-calls bring data to the user in tiny parts.
+		 * In both cases, the LONGER the data the dearer, because we
+		 * have more helpful information.
+		 * Data segments are between 1-MAX_SEGMENT size
+		 * (READABLE|WRITEABLE can be more)
+		 * In the mixed cases (both data and pure information),
+		 * there is no easy way to evaluate, so we provide fixed values.
+		 */
+		switch(d->type[i])
+		{
+			/* throwing data - the shorter the dearer */
+			case READDATA:
+				p = MAX_SEGMENT/2 + 40 + d->len[i] / (MAX_SEGMENT / 10);
+				break;
+			case WRITEDATA:
+				p = MAX_SEGMENT/2 + 30 + d->len[i] / (MAX_SEGMENT / 10);
+				break;
+			case WRITEDATA|READDATA:
+				p = MAX_SEGMENT/2 + 20 + d->len[i] / (MAX_SEGMENT / 10);
+				break;
+			/* mixed case: hard, so just a fixed value: */
+			case READDATA|WRITEABLE:
+				p = MAX_SEGMENT/2 + 39;
+				break;
+			case WRITEDATA|READABLE:
+				p = MAX_SEGMENT/2 + 29;
+				break;
+			/* declaration only - the longer the dearer: */
+			case WRITEABLE:
+				p = MAX_SEGMENT / d->len[i];
+				break;
+			case READABLE:
+				p = MAX_SEGMENT / (2 * d->len[i]);
+				break;
+			case READABLE|WRITEABLE:
+				p = MAX_SEGMENT * 2 / (3 * d->len[i]);
+				break;
+			default:
+				printk("free_some_entry_except: type %d encountered\n", d->type[i]);
+				p = 1;
+		}
+		if(!d->bp[i] || d->bp[i] != d->bp[not_this] ||
+			d->addr[i] < d->addr[not_this])
+			p++;
+		if(p > pri)
+		{
+			pri = p;
+			e = i;
+		}
+	}
+	if(e == END_MARK)
+		panic("free_some_entry_except: none found");
+	if(d->type[e] & READDATA)
+	{
+		write_read_cache(d, e);
+		d->type[not_this] |= SKIP_MARK;
+		data_was_read(d, e);
+		d->type[not_this] &= ~SKIP_MARK;
+		if(d->free == END_MARK)
+			goto again;
+	}
+	else
+		free_ucache_entry(d, e);
+}	
+
+void
+split_ucache(int ent, unsigned long at, int back)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	int e2;
+	struct cblock *cb;
+
+	breakpoint1("split entry at %X", at);
+#ifdef CONFIG_MOSIX_DIAG
+	if(at <= d->addr[ent] || at >= d->addr[ent] + d->len[ent])
+		panic("split_ucache: point not inside");
+#endif /* CONFIG_MOSIX_DIAG */
+	if(d->free == END_MARK)
+		free_some_entry_except(d, ent);
+	if(back)
+	{
+		e2 = alloc_ucache_entry(d, d->prev[ent], d->type[ent],
+			d->addr[ent], at - d->addr[ent]);
+		d->len[ent] = d->addr[ent] + d->len[ent] - at;
+		d->addr[ent] = at;
+	}
+	else
+	{
+		e2 = alloc_ucache_entry(d, ent, d->type[ent], at,
+			d->addr[ent] + d->len[ent] - at);
+		d->len[ent] = at - d->addr[ent];
+	}
+	if((cb = d->bp[ent]))
+	{
+		d->bp[e2] = cb;
+		cb->count++;
+	}
+	breakpoint1("Split of Entry #%d Complete", ent);
+}
+
+int
+obtain_ucache_block(struct data_cache *d, int ent, unsigned long at)
+{
+	if(d->len[ent] > MAX_SEGMENT)
+	{
+		if(at - d->addr[ent] < MAX_SEGMENT)
+			split_ucache(ent, d->addr[ent] + MAX_SEGMENT, 0);
+		else if(at + MAX_SEGMENT <= d->addr[ent] + d->len[ent])
+			split_ucache(ent, (d->type[ent] & READABLE) ? at :
+				d->addr[ent] + d->len[ent] - MAX_SEGMENT, 1);
+		else
+		{
+			split_ucache(ent, at, 1);
+			split_ucache(ent, at + MAX_SEGMENT, 0);
+		}
+	}
+	return((d->bp[ent] = cblock_alloc(d->addr[ent], d->len[ent])) != NULL);
+}
+
+void
+flush_ucache(void)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	struct cblock *cb;
+
+	if(!d || d->first == END_MARK)
+		return;
+	breakpoint("flush_ucache");
+	if(!(current->mosix.dflags & DREMOTE)) /* save time - no READDATA */
+		flush_read_cache();
+	for(i = 0 ; i < CACHE_ENTRIES ; i++)
+	if((cb = d->bp[i]))
+	{
+		if(--cb->count == 0)
+			kfree(cb);
+		d->bp[i] = NULL;
+	}
+	for(i = 0 ; i < CACHE_ENTRIES ; i++)
+	{
+		d->next[i] = i+1;
+		d->prev[i] = i-1;
+	}
+	d->first = END_MARK;
+	d->free = 0;
+	d->next[CACHE_ENTRIES-1] = END_MARK;
+	d->prev[0] = END_MARK;
+}
+
+int
+ask_for_write_data(int ent)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	struct cblock *cb = d->bp[ent];
+	struct user_copy_h u;
+	int result;
+
+	breakpoint1("ask_for_write_data on entry #%d", ent);
+	u.addr = (char *)d->addr[ent];
+	u.size = d->len[ent];
+	u.verify = 0;	/* we wouldn't ask if we had no WRITEABLE! */
+	if(deputy_request(DEP_COPY_FROM_USER, &u, sizeof(u), NULL, 0, 0,
+		(void **)&result, -sizeof(result)))
+		return(0);
+	if(result)
+	{
+		comm_flushdata(COMM_ALLDATA);
+		return(0);
+	}
+	if(comm_copydata(&cb->data[d->addr[ent] - cb->offset], u.size, 0))
+		return(0);
+	d->type[ent] &= ~WRITE_STATUS;
+	d->type[ent] |= WRITEDATA;
+	return(1);
+}
+
+void
+try_to_merge_ucache(int ent)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	int o;
+	int t = d->type[ent];
+	struct cblock *cb = d->bp[ent];
+
+	if((o = d->prev[ent]) != END_MARK &&
+		d->type[o] == t && d->bp[o] == cb &&
+		d->addr[o] + d->len[o] == d->addr[ent] &&
+		d->len[ent] + d->len[o] <= MAX_POSITIVE)
+	{
+		d->addr[ent] = d->addr[o];
+		d->len[ent] += d->len[o];
+		d->type[o] &= ~READDATA;
+		free_ucache_entry(d, o);
+		breakpoint1("Merged #%d with previous", ent);
+	}
+	if((o = d->next[ent]) != END_MARK &&
+		d->type[o] == t && d->bp[o] == cb &&
+		d->addr[ent] + d->len[ent] == d->addr[o] &&
+		d->len[ent] + d->len[o] <= MAX_POSITIVE)
+	{
+		d->len[ent] += d->len[o];
+		d->type[o] &= ~READDATA;
+		free_ucache_entry(d, o);
+		breakpoint1("Merged #%d with next", ent);
+	}
+}
+
+inline int
+find_non_cached(struct data_cache *d, int types, unsigned int addr, int max)
+{
+	register int i;
+	int nc;
+
+	if(!max)
+		return(0);
+	breakpoint1("Finding non-cached from address %X", addr);
+	for(i = d->first ; i != END_MARK &&
+		(!(d->type[i] & types) || d->addr[i] + d->len[i] <= addr) ;
+		i = d->next[i])
+		;
+	if(i == END_MARK)
+		return(max);
+	if((nc = d->addr[i] - addr) > MAX_POSITIVE)
+		return(MAX_POSITIVE);
+	if(nc > max)
+		nc = max;
+	breakpoint1("non-cached=0x%X", nc);
+	return(nc);
+}
+
+int
+copy_from_cache(char *to, unsigned long from, int len, int *non_cache)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	int rlen = (len < 0 ? -len : len);
+	unsigned int orlen = rlen;
+	register int i;
+	struct cblock *cb;
+	char *cp;
+	int n;
+	int zero_found = 0;
+
+	if(!d)
+	{
+		none:
+		*non_cache = rlen;
+#ifdef WHY_NOT_CACHED
+if(ds_debug & DSDEB_NOTCACHED){printk("%X(%x) not in cache!",(int)from,rlen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+		return(0);
+	}
+	for(i = d->first ; i != END_MARK &&
+		(!(d->type[i] & (WRITE_STATUS|READDATA)) ||
+			d->addr[i] + d->len[i] <= from) ;
+		i = d->next[i])
+		;
+	if(i == END_MARK)
+		goto none;
+	if(d->addr[i] > from)
+	{
+		n = d->addr[i] - from;
+		if(((unsigned int)n) > orlen)
+			n = orlen;
+		*non_cache = n;
+		breakpoint1("copy_from_cache from 0x%X - way before cache", from);
+#ifdef WHY_NOT_CACHED
+if(ds_debug & DSDEB_NOTCACHED){printk("%X(%x) not in cache!",(int)from,rlen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+		return(0);
+	}
+	breakpoint1("copy_from_cache from 0x%X - something relevant", from);
+	if(!d->bp[i] && !obtain_ucache_block(d, i, from))
+	{
+		breakpoint("copy_from_cache: failed allocating a cblock");
+		free_ucache_entry(d, i);
+		*non_cache = find_non_cached(d, WRITE_STATUS|READDATA,
+								from, orlen);
+#ifdef WHY_NOT_CACHED
+if(ds_debug & DSDEB_NOTCACHED){printk("%X(%x) not in cache!",(int)from,rlen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+		return(0);
+	}
+	if(d->addr[i] + d->len[i] < from + rlen)
+		rlen = d->addr[i] + d->len[i] - from;
+	if(!(d->type[i] & (READDATA|WRITEDATA)) && !ask_for_write_data(i))
+	{
+		breakpoint1("Failed obtaining write-data for entry #%d", i);
+		free_ucache_entry(d, i);
+		rlen = 0;
+	}
+	else
+	{
+		breakpoint1("Fetching 0x%x bytes from cache", rlen);
+		cb = d->bp[i];
+		cp = &cb->data[from - cb->offset];
+		if(len > 0)
+			memcpy(to, cp, rlen);
+		else if(to) /* stop at 0, but include it */
+		{
+			for(n = 0 ; n < rlen ; n++)
+			if((*to++ = *cp++) == '\0')
+			{
+				n++;
+				zero_found = 1;
+				break;
+			}
+			rlen = n;
+		}
+		else	/* called from "strlen_cache" */
+		{
+			for(n = 0 ; n < rlen ; n++)
+			if(*cp++ == '\0')
+			{
+				n++;
+				zero_found = 1;
+				break;
+			}
+			rlen = n;
+		}
+		/* finally, can we rid or shorten this entry? */
+		if(d->type[i] == WRITEDATA &&
+			d->first == i && d->next[i] == END_MARK)
+			/* leave the poor single-entry alone -nothing to lose */
+			/* (some tty routines read TWICE) */
+				;
+		else if(d->type[i] & READ_STATUS)
+		{
+			if(from != d->addr[i])
+				split_ucache(i, from, 1);
+			if(len < d->len[i])
+				split_ucache(i, from + len, 0);
+			d->type[i] &= ~WRITEDATA;
+			if(!(d->type[i] & READDATA))
+			{
+				if(cb && --cb->count == 0)
+					kfree(cb);
+				d->bp[i] = NULL;
+			}
+			try_to_merge_ucache(i);
+			breakpoint1("some (or all) of block #%d was only left for reading", i);
+		}
+		else if(from == d->addr[i] && d->len[i] == rlen)
+		{
+			free_ucache_entry(d, i);
+			breakpoint1("All block #%d was consumed", i);
+		}
+		else
+		{
+			if(from == d->addr[i])
+			{
+				d->addr[i] += rlen;
+				d->len[i] -= rlen;
+			}
+			else if(from + rlen == d->addr[i] + d->len[i])
+				d->len[i] = from - d->addr[i];
+			breakpoint1("some of block #%d was consumed", i);
+		}
+	}
+	if(zero_found)
+	{
+		breakpoint("zero found");
+		*non_cache = -1;
+	}
+	else
+		*non_cache = find_non_cached(d, WRITE_STATUS|READDATA,
+						from+rlen, orlen - rlen);
+#ifdef WHY_NOT_CACHED
+if(*non_cache && !zero_found && (ds_debug & DSDEB_NOTCACHED)){printk("from %X(%x) not in cache!",(int)(from+rlen),orlen-rlen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+	return(rlen);
+}
+
+void
+check_whether_to_read_flush(void)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	int l = 0, n = 0;
+	register struct cblock *cb;
+
+	for(i = d->first ; i != END_MARK ; i = d->next[i])
+	if(d->type[i] & READDATA)
+	{
+		cb = d->bp[i];
+		if(d->len[i] == cb->len && d->addr[i] == cb->offset)
+			l += cb->len;
+		else
+			n += cb->len;
+	}
+	else if(d->type[i] & READABLE)
+		n += d->len[i];
+	if(l >= READ_SEND_THRESHOLD && n >= READ_SEND_THRESHOLD)
+		flush_read_cache();
+}
+
+int
+copy_to_cache(unsigned long to, char *from, int len, int *non_cache)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	unsigned int olen = len;
+	register int i;
+	unsigned int lim;
+	struct cblock *cb;
+
+	if(!d)
+	{
+		none:
+		*non_cache = len;
+#ifdef WHY_NOT_CACHED
+if(ds_debug & DSDEB_NOTCACHED){printk("%X(%x) not in cache!",(int)to,olen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+		return(0);
+	}
+	for(i = d->first ; i != END_MARK &&
+		(!(d->type[i] & (READ_STATUS|WRITEDATA)) ||
+			d->addr[i] + d->len[i] <= to) ;
+		i = d->next[i])
+		;
+	if(i == END_MARK)
+		goto none;
+	if(d->addr[i] > to)
+	{
+		if(d->addr[i] - to > olen)
+			*non_cache = olen;
+		else
+			*non_cache = d->addr[i] - to;
+#ifdef WHY_NOT_CACHED
+if(ds_debug & DSDEB_NOTCACHED){printk("%X(%x) not in cache!",(int)to,olen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+		return(0);
+	}
+	breakpoint1("copy_to_cache from 0x%X - something relevant", to);
+	if(!d->bp[i] && !obtain_ucache_block(d, i, to))
+	{
+		breakpoint("copy_to_cache: failed allocating a cblock");
+		cant_do_it:
+		free_ucache_entry(d, i);
+		*non_cache = find_non_cached(d, READ_STATUS|WRITEDATA,
+								to, olen);
+		breakpoint1("cant_do_it: *non_cache=%d", *non_cache);
+#ifdef WHY_NOT_CACHED
+if(ds_debug & DSDEB_NOTCACHED){printk("%X(%x) not in cache!",(int)to,olen);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+		return(0);
+	}
+	if(d->addr[i] != to && !(d->type[i] & READDATA))
+		split_ucache(i, to, 1);
+	lim = d->addr[i] + d->len[i];
+	if(lim != to + len)
+	{
+		if(lim < to + len)
+			len = d->addr[i] + d->len[i] - to;
+		else if(!(d->type[i] & READDATA))
+			split_ucache(i, to + len, 0);
+	}
+	if(!(d->type[i] & READ_STATUS))
+	/* we have user-read permission but not user-write:
+	 * we did need to get thus far to minimize the data-loss,
+	 * but now we must discard this entry.
+	 */
+	{
+		breakpoint("copy_to_cache: Sorry Only read-permission");
+		goto cant_do_it;
+	}
+	breakpoint1("copy_to_cache: copying %d bytes", len);
+	cb = d->bp[i];
+	if(from)
+		memcpy(&cb->data[to - cb->offset], from, len);
+	else	/* called from zero_cache() */
+		memset(&cb->data[to - cb->offset], 0, len);
+	d->type[i] &= ~READ_STATUS;
+	d->type[i] |= READDATA;
+	try_to_merge_ucache(i);
+	if(d->addr[i] == cb->offset && d->len[i] == cb->len)
+		check_whether_to_read_flush();
+	*non_cache = find_non_cached(d, READ_STATUS|WRITEDATA, to + len,
+								olen - len);
+	breakpoint1("copy_to_cache: success, non_cache=%d", *non_cache);
+#ifdef WHY_NOT_CACHED
+if(*non_cache && (ds_debug & DSDEB_NOTCACHED)){printk("%X(%x) not in cache!",(int)(to+len),olen-len);mosix_panic("Why");}
+#endif /* WHY_NOT_CACHED */
+	return(len);
+}
+
+int
+zero_cache(char *to, int len, int *non_cache)
+{
+	return(copy_to_cache((unsigned long)to, NULL, len, non_cache));
+}
+
+int
+strlen_cache(char *addr, int *non_cache)
+{
+	return(copy_from_cache(NULL, (unsigned long)addr, -MAX_POSITIVE,
+								non_cache));
+}
+
+int
+all_in_cache(unsigned long addr, unsigned int size, int writeable)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	unsigned int limit;
+
+	if(!d || addr + size < addr)	/* no cache or overflow */
+		return(0);
+	for(i = d->first ; i != END_MARK && d->addr[i] + d->len[i] < addr ;
+		i = d->next[i])
+			;
+	limit = addr + size;
+	for(; i != END_MARK ; i = d->next[i])
+	if(d->addr[i] > addr || (writeable && !(d->type[i] & READ_STATUS)))
+		return(0);
+	else if((addr = d->addr[i] + d->len[i]) >= limit)
+		return(1);
+	return(0);
+}
+
+int
+any_in_cache(unsigned long addr, unsigned int size)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+
+	if(!d || addr + size < addr)	/* no cache or overflow */
+		return(0);
+	for(i = d->first ; i != END_MARK && d->addr[i] < addr+size ;
+		i = d->next[i])
+	if(d->addr[i] + d->len[i] > addr &&
+		(d->type[i] & (READDATA|WRITEDATA)))
+		return(1);
+	return(0);
+}
+
+/*
+ * the following routine is only used in the first stage of preparing
+ * a cache, therefore "type" may only be "READABLE", "WRITEABLE", or both
+ * and so must be all entries already in the cache before the call.
+ * this is because its complexity is already enough as it is.
+ * If at some time in the future, new entries are to be produced after
+ * initialization, another routine must be used (or this one expanded).
+ *
+ * Also, note that for simplicity-sake, one of the entries, though very
+ * rare, could be merged to become over the size of MAX_POSITIVE,
+ * so this must be weeded-out later.
+ */
+void
+add_ucache_entry(unsigned long addr, int len, int type)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	int n;
+	int prev;
+	unsigned long next_addr = 0;
+	unsigned long next_len = 0;
+	char msg[50];
+
+	sprintf(msg, "add_ucache_entry at 0x%X, len=0x%X", (int)addr, len);
+	breakpoint(msg);
+	if(len <= 0 || len > MAX_POSITIVE || addr + len < addr)
+		return;
+	if(!d)
+	{
+		if(alloc_ucache())
+			d = current->mosix.ucache;
+		else
+			return;
+	}
+	next_part:
+	for(prev = END_MARK , i = d->first ;
+		i != END_MARK && d->addr[i] + d->len[i] <= addr ;
+		prev = i , i = d->next[i])
+		;
+	if(i == END_MARK || d->addr[i] > addr + len)
+	{
+		/* no overlap, or even touching */
+		if(prev != END_MARK && d->type[prev] == type &&
+			d->addr[prev] + d->len[prev] == addr)
+			d->len[prev] += len;
+		else
+			alloc_ucache_entry(d, prev, type, addr, len);
+		goto all_done;
+	}
+	if(i != END_MARK && addr + len > d->addr[i] + d->len[i])
+	{
+		/* do some now, the rest later */
+		next_len = addr + len - (d->addr[i] + d->len[i]);
+		next_addr = d->addr[i] + d->len[i];
+		len = next_addr - addr;
+	}
+	if(prev != END_MARK && d->type[prev] == type &&
+		d->addr[prev] + d->len[prev] == addr)
+	{
+		/* increase previous entry */
+		if(i != END_MARK && addr + len >= d->addr[i])
+		{
+			n = d->addr[i] - addr;
+			addr = d->addr[i];
+			len -= n;
+			d->len[prev] += n;
+			try_to_merge_ucache(i);
+		}
+		else
+		{
+			d->len[prev] += len;
+			goto all_done;
+		}
+	}
+	if(i == END_MARK || d->addr[i] > addr + len)
+		alloc_ucache_entry(d, prev, type, addr, len);
+	else if(d->type[i] == type)
+	{
+		if(d->addr[i] > addr)
+		{
+			d->len[i] += d->addr[i] - addr;
+			d->addr[i] = addr;
+		}
+		/* else -- already included, nothing to do */
+	}
+	else if(d->type[i] == (READABLE|WRITEABLE) && d->addr[i] <= addr)
+		; /* nothing to do - already included */
+	else if(d->addr[i] == addr && d->len[i] == len)
+	{
+		d->type[i] |= type;
+		try_to_merge_ucache(i);
+	}
+	else if(d->addr[i] == addr)
+	{
+		split_ucache(i, addr + len, 0);	/* now "i"=new entry */
+		d->type[i] |= type;
+	}
+	else if(d->addr[i] > addr)
+	{
+		alloc_ucache_entry(d, prev, type, addr, d->addr[i] - addr);
+		if(d->addr[i] < addr + len)
+		{
+			if(addr + len < d->addr[i] + d->len[i])
+				split_ucache(i, addr + len, 0);
+			d->type[i] |= type;
+		}
+	}
+	else
+	{
+		split_ucache(i, addr, 1);
+		if(d->addr[i] + d->len[i] != addr + len)
+			split_ucache(i, addr + len, 0);
+		d->type[i] |= type;
+	}
+	if(next_len)
+	{
+		breakpoint1("adding split next segment of %d", next_len);
+		len = next_len;
+		addr = next_addr;
+		next_len = 0;
+		goto next_part;
+	}
+	all_done:
+	breakpoint("after add_ucache_entry");
+}
+
+int
+ucache_ok(unsigned long addr, unsigned long size, int mode)
+{
+	struct vm_area_struct * vma;
+	unsigned long pages;
+	int ok = 0;
+	unsigned int need;
+
+	if (!size || addr+size >= TASK_SIZE || addr+size < addr)
+		return(0);
+
+	down_read(&current->mm->mmap_sem);
+	if (!(vma = find_extend_vma(current->mm, addr)) ||
+							!(vma->vm_flags & mode))
+		goto out;
+	need = ((addr & ~PAGE_MASK) + size + PAGE_SIZE-1) >> PAGE_SHIFT;
+	addr &= PAGE_MASK;
+
+	while(1)
+	{
+		pages = (vma->vm_end - addr) >> PAGE_SHIFT;
+		if(need <= pages)
+			break;
+		need -= pages;
+		addr = vma->vm_end;
+		vma = vma->vm_next;
+		if (!vma || vma->vm_start != addr)
+			goto out;
+		if (!(vma->vm_flags & mode))
+			goto out;
+	}
+	ok = 1;
+	out:
+	up_read(&current->mm->mmap_sem);
+	return(ok);
+}
+
+#ifdef CONFIG_MOSIX_DIAG
+int no_ucache, no_write_cache, no_read_cache;
+#endif /* CONFIG_MOSIX_DIAG */
+
+void
+set_read_region(unsigned long addr, unsigned int len)
+{
+#ifdef CONFIG_MOSIX_DIAG
+	if(no_ucache || no_read_cache)
+		return;
+#endif /* CONFIG_MOSIX_DIAG */
+	if(!ucache_ok(addr, len, VM_WRITE))
+		return;
+	add_ucache_entry(addr, len, READABLE);
+}
+
+void
+set_write_region(unsigned long addr, unsigned int len)
+{
+#ifdef CONFIG_MOSIX_DIAG
+	if(no_ucache || no_write_cache)
+		return;
+#endif /* CONFIG_MOSIX_DIAG */
+	if(!ucache_ok(addr, len, VM_READ))
+		return;
+	add_ucache_entry(addr, len, WRITEABLE);
+}
+
+struct ucache_envelope_entry
+{
+	unsigned long addr;
+	unsigned int len;
+	short type;
+#if MAX_SEGMENT < 65536
+	unsigned short actual_len;
+#else
+	int actual_len;
+#endif
+};
+
+char *
+construct_ucache_envelope(int *len, int *from_user, struct syscall_h *s, char **tofree)
+{
+	int l, n;
+	register struct data_cache *d = current->mosix.ucache;
+	struct ucache_envelope_entry e[CACHE_ENTRIES];
+	register int i;
+	char *envelope, *ep;
+	int ent = END_MARK;	/* only to shut-up the compiler */
+	
+	*tofree = NULL;
+	*len = *from_user = s->simple_data_len = 0;
+	if(!d)
+		return(NULL);
+	rare_again:
+	for(l = n = 0 , i = d->first ; i != END_MARK ; i = d->next[i])
+	{
+		if(d->len[i] > MAX_POSITIVE)	/* rare indeed, but check */
+		{
+			split_ucache(i, d->addr[i] + MAX_POSITIVE, 0);
+			goto rare_again; /* because an entry could be lost */
+		}
+		l += sizeof(struct ucache_envelope_entry);
+		e[n].addr = d->addr[i];
+		e[n].len = d->len[i];
+		if((e[n].type = d->type[i]) & WRITEABLE)
+		{
+			e[n].actual_len = (d->len[i] > MAX_SEGMENT ?
+						MAX_SEGMENT : d->len[i]);
+			l += e[n].actual_len;
+		}
+		else
+			e[n].actual_len = 0;
+		if(!n++)
+		{
+			ent = i;
+			l += sizeof(int);
+		}
+	}
+	if(n == 1)
+	{
+		/* no need for package */
+		breakpoint1("construct_ucache_envelope: only one", l);
+		s->simple_data_addr = d->addr[ent];
+		s->simple_data_len = d->len[ent];
+		s->simple_data_type = d->type[ent];
+		if(d->type[ent] & WRITEABLE)
+		{
+			*from_user = 1;
+			if(s->simple_data_len >= MAX_SEGMENT)
+				*len = MAX_SEGMENT;
+			else
+				*len = s->simple_data_len;
+			s->simple_data_actual = *len;
+			ep = (char *)d->addr[ent];
+		}
+		else
+		{
+			ep = NULL;
+			s->simple_data_actual = 0;
+		}
+		flush_ucache();
+		return(ep);
+	}
+	if(!n || !(envelope = kmalloc(l, GFP_NOIO)))
+	{
+		if(n)
+			breakpoint1("construct_ucache_envelope: could not allocate %d bytes", l);
+		flush_ucache();
+		return(NULL);
+	}
+	*((int *)envelope) = n;
+	memcpy(envelope + sizeof(int), (caddr_t)e, n * sizeof(e[0]));
+	ep = envelope + sizeof(int) + n * sizeof(e[0]);
+	for(i = 0 ; i < n ; i++)
+	if(e[i].actual_len)
+	{
+		if(copy_from_user(ep, (char *)e[i].addr, e[i].actual_len))
+		{
+			/* must be a very serious problem, because area was
+			 * already checked, but could happen on a bad page,
+			 * or if disconnected from DEPUTY, anyway:
+			 */
+			kfree(envelope);
+			flush_ucache();
+			return(NULL);
+		}
+		ep += e[i].actual_len;
+	}
+	breakpoint1("construct_ucache_envelope: made %d bytes", l);
+	flush_ucache();
+	*len = l;
+	*tofree = envelope;
+	s->simple_data_len = -1;
+	return(envelope);
+}
+
+int
+open_ucache_envelope(struct syscall_h *s)
+{
+	int n;
+	register int i, j;
+	int ent;
+	struct ucache_envelope_entry e[CACHE_ENTRIES];
+	struct cblock *cb;
+	register struct data_cache *d;
+	struct mosix_task *m = &current->mosix;
+
+	if(!s->simple_data_len)
+		return(0);
+	if(!(d = m->ucache) && !(alloc_ucache()))
+	{
+		comm_flushdata(COMM_ALLDATA);
+		return(-ENOMEM);
+	}
+	d = m->ucache;
+	if(s->simple_data_len == -1)	/* complex */
+	{
+		if(comm_copydata(&n, sizeof(int), 0))
+		{
+			mosix_panic("open_ucache_envelope: no total");
+			return(-EDIST);
+		}
+		if(n < 1 || n > CACHE_ENTRIES)
+		{
+			printk("n in envelope = %d\n", n);
+			mosix_panic("bad n in envelope");
+			comm_flushdata(COMM_ALLDATA);
+			return(-EDIST);
+		}
+		if(comm_copydata(e, n * sizeof(e[0]), 0))
+		{
+			mosix_panic("open_ucache_envelope: non header");
+			return(-EDIST);
+		}
+	}
+	else
+	{
+		n = 1;
+		e[0].type = s->simple_data_type;
+		e[0].addr = s->simple_data_addr;
+		e[0].len = s->simple_data_len;
+		e[0].actual_len = s->simple_data_actual;
+	}
+	for(ent = END_MARK , i = 0 ; i < n ; i++)
+	       ent = alloc_ucache_entry(d, ent, e[i].type, e[i].addr, e[i].len);
+	for(i = 0 ; i < n ; i++)
+	if(e[i].actual_len)
+	{
+		if(!(cb = cblock_alloc(e[i].addr, e[i].actual_len)))
+		{
+			comm_flushdata(COMM_ALLDATA);
+			return(-ENOMEM);
+		}
+		if(comm_copydata(cb->data, e[i].actual_len, 0))
+		{
+			printk("open_ucache_envelope: copy failed\n");
+			kfree(cb);
+			return(-EDIST);
+		}
+		/* find all entries to share the block: */
+		for(j = d->first ; j != END_MARK ; j = d->next[j])
+		if(d->type[j] & WRITEABLE)
+		{
+			if(d->addr[j] >= e[i].addr + e[i].actual_len ||
+				d->addr[j] + d->len[j] <= e[i].addr)
+				continue;
+			if(d->addr[j] < e[i].addr)
+				split_ucache(j, e[i].addr, 1);
+			if(d->addr[j] + d->len[j] > e[i].addr + e[i].actual_len)
+				split_ucache(j, e[i].addr + e[i].actual_len, 0);
+			d->bp[j] = cb;
+			cb->count++;
+			d->type[j] &= ~WRITEABLE;
+			d->type[j] |= WRITEDATA;
+		}
+		if(--cb->count == 0)
+			kfree(cb);
+	}
+	breakpoint("opened_ucache_envelope");
+	return(0);
+}
+
+struct read_cache_header
+{
+	unsigned long addr;
+	unsigned int len;
+};
+
+/*
+ * Attempt to send the data directly whenever there is only one entry.
+ */
+char *
+deputy_pack_read_cache_data(int *len, struct syscall_ret_h *r, char **tofree)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	int f = END_MARK;
+	char *result;
+	struct cblock *cb;
+
+	*tofree = NULL;
+	*len = r->simple_data_len = 0;
+	if(!d || d->first == END_MARK)
+		return(NULL);
+	for(i = d->first ; i != END_MARK ; i = d->next[i])
+	if((d->type[i] & (READDATA|SKIP_MARK)) == READDATA)
+	{
+		if(f != END_MARK)
+		{
+			/* more than one entry - do it the long way */
+			result = pack_read_cache_data(len);
+			if(result)	/* (could still fail on memory) */
+			{
+				r->simple_data_len = -1;
+				*tofree = result;
+			}
+			flush_ucache();
+			return(result);
+		}
+		else
+			f = i;
+	}
+	if(f == END_MARK)
+	{
+		flush_ucache();
+		return(NULL);
+	}
+	/* OK: Just one READDATA entry "f" */
+	r->simple_data_addr = d->addr[f];
+	*len = r->simple_data_len = d->len[f];
+	cb = d->bp[f];
+	result = &cb->data[r->simple_data_addr - cb->offset];
+	d->bp[f] = NULL;
+	*tofree = (char *)cb;
+	d->type[f] &= ~(READDATA|WRITEDATA);
+	if(!(d->type[f] & WRITEABLE))
+		free_ucache_entry(d, f);
+	breakpoint1("deputy_pack_read_cache_data: One entry found/used (%d)",f);
+	flush_ucache();
+	return(result);
+}
+
+char *
+pack_read_cache_data(int *len)
+{
+	int l, n;
+	register struct data_cache *d = current->mosix.ucache;
+	struct read_cache_header e[CACHE_ENTRIES];
+	caddr_t from[CACHE_ENTRIES];
+	register int i;
+	char *package, *ep;
+	struct cblock *cb;
+	
+	if(!d || d->first == END_MARK)
+	{
+		*len = 0;
+		return(NULL);
+	}
+	for(l = n = 0 , i = d->first ; i != END_MARK ; i = d->next[i])
+	if((d->type[i] & (READDATA|SKIP_MARK)) == READDATA)
+	{
+		cb = d->bp[i];
+#ifdef CONFIG_MOSIX_DIAG
+		if(!cb)
+			panic("pack_read_cache_data: no cb");
+#endif /* CONFIG_MOSIX_DIAG */
+		from[n] = &cb->data[d->addr[i] - cb->offset];
+		e[n].addr = d->addr[i];
+		l += sizeof(e[0]) + (e[n].len = d->len[i]);
+		if(!n++)
+			l += sizeof(int);
+	}
+#ifdef CONFIG_MOSIX_DIAG
+	if(n < 2)
+		printk("pack_read_cache_data, why got here if (n=%d) < 2?\n",n);
+#endif /* CONFIG_MOSIX_DIAG */
+	if(!n || !(package = kmalloc(l, GFP_NOIO)))
+	{
+		breakpoint1("pack_read_cache_data: could not allocate %d bytes", l);
+		*len = 0;
+		return(NULL);
+	}
+	*((int *)package) = n;
+	memcpy(package + sizeof(int), (caddr_t)e, n * sizeof(e[0]));
+	ep = package + sizeof(int) + n * sizeof(e[0]);
+	for(i = 0 ; i < n ; i++)
+	{
+		memcpy(ep, from[i], e[i].len);
+		ep += e[i].len;
+	}
+	*len = l;
+	clear_readdata:
+	for(i = d->first ; i != END_MARK ; i = d->next[i])
+	if((d->type[i] & (READDATA|SKIP_MARK)) == READDATA)
+	{
+		data_was_read(d, i);
+		goto clear_readdata;	/* list may be scrambled */
+	}
+	breakpoint1("pack_read_cache_data: packed %d bytes", *len);
+	return(package);
+}
+
+int
+remote_unpack_read_cache_data(struct syscall_ret_h *r)
+{
+	register int i;
+	int l = 0, n;
+	struct read_cache_header e[CACHE_ENTRIES];
+
+	if(r && !r->simple_data_len)
+		return(0);
+	if(!r || r->simple_data_len == -1)
+	{
+		if(comm_copydata(&n, sizeof(int), 0))
+		{
+			mosix_panic("unpack_read_cache_data: no total");
+			return(-EDIST);
+		}
+		if(n < 1 || n > CACHE_ENTRIES)
+		{
+			printk("n in package = %d\n", n);
+			mosix_panic("bad n in package");
+			comm_flushdata(COMM_ALLDATA);
+			return(-EDIST);
+		}
+		if(comm_copydata(e, n * sizeof(e[0]), 0))
+		{
+			mosix_panic("open_ucache_envelope: non header");
+			return(-EDIST);
+		}
+		l = sizeof(int) + n * sizeof(e[0]);
+	}
+	else
+	{
+		n = 1;
+		e[0].addr = r->simple_data_addr;
+		e[0].len = r->simple_data_len;
+	}
+	for(i = 0 ; i < n ; i++)
+	if(comm_copydata((char *)e[i].addr, e[i].len, 1))
+	{
+		printk("unpack_cache_read_data: copy to user failed\n");
+		comm_flushdata(COMM_ALLDATA);
+		return(-EDIST);
+	}
+	else
+		l += e[i].len;
+	bump_copyout(l);
+	return(0);
+}
+
+#ifdef CONFIG_MOSIX_DEBUG
+void
+print_ucache(void)
+{
+	register struct data_cache *d = current->mosix.ucache;
+	register int i;
+	struct cblock *cb;
+
+	if(!d)
+	{
+		printk("No data-cache allocated.\n");
+		return;
+	}
+	printk(" n    addr  len (hex)  type   block\n");
+	printk("===========================================================\n");
+	for(i = d->first ; i != END_MARK ; i = d->next[i])
+	{
+		printk("%2d %08X  %8X ", i, (int)d->addr[i], (int)d->len[i]);
+		printk("%c", (d->type[i] & SKIP_MARK) ? 'S' : ' ');
+		printk("%c", (d->type[i] & READABLE) ? 'r' : '-');
+		printk("%c", (d->type[i] & READDATA) ? 'R' : '-');
+		printk("%c", (d->type[i] & WRITEABLE) ? 'w' : '-');
+		printk("%c", (d->type[i] & WRITEDATA) ? 'W' : '-');
+		if((cb = d->bp[i]))
+			printk(" %08X,o=%X,l=%X,n=%d", (int)cb, (int)cb->offset,
+							cb->len, cb->count);
+		printk("\n");
+	}
+	printk("Free list:");
+	for(i = d->free ; i != END_MARK ; i = d->next[i])
+		printk(" %d", i);
+	printk("\n");
+}
+#endif /* CONFIG_MOSIX_DEBUG */
diff -ruN linux-2.4.16/net/core/scm.c linux-2.4.16-mosix/net/core/scm.c
--- linux-2.4.16/net/core/scm.c	Fri Nov 10 01:57:53 2000
+++ linux-2.4.16-mosix/net/core/scm.c	Sun Dec 23 13:56:53 2001
@@ -35,6 +35,9 @@
 #include <net/sock.h>
 #include <net/scm.h>
 
+#ifdef CONFIG_MOSIX_DFSA
+#include <linux/dfsa_interface.h>
+#endif /* CONFIG_MOSIX_DFSA */
 
 /*
  *	Only allow a user to send credentials, that they could set with 
@@ -85,6 +88,12 @@
 	 *	Verify the descriptors and increment the usage count.
 	 */
 	 
+#ifdef CONFIG_MOSIX_DFSA
+	/* this is massive and rare, so rather than make special cases: */
+	if(current->mosix.dflags & DREMOTE)
+		return(-EDOITATHOME);
+	dfsa_is_not_up_to_date();
+#endif /* CONFIG_MOSIX_DFSA */
 	for (i=0; i< num; i++)
 	{
 		int fd = fdp[i];
@@ -210,6 +219,10 @@
 	int *cmfptr;
 	int err = 0, i;
 
+#ifdef CONFIG_MOSIX_DFSA
+	if(current->mosix.dflags & DREMOTE)
+		panic("scm_detach_fds: REMOTE");
+#endif /* CONFIG_MOSIX_DFSA */
 	if (msg->msg_controllen > sizeof(struct cmsghdr))
 		fdmax = ((msg->msg_controllen - sizeof(struct cmsghdr))
 			 / sizeof(int));
diff -ruN linux-2.4.16/net/core/skbuff.c linux-2.4.16-mosix/net/core/skbuff.c
--- linux-2.4.16/net/core/skbuff.c	Tue Aug  7 18:30:50 2001
+++ linux-2.4.16-mosix/net/core/skbuff.c	Sun Dec 23 13:56:53 2001
@@ -62,6 +62,10 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 int sysctl_hot_list_len = 128;
 
 static kmem_cache_t *skbuff_head_cache;
@@ -167,6 +171,9 @@
 	struct sk_buff *skb;
 	u8 *data;
 
+#ifdef CONFIG_MOSIX_UDB
+	if(!udb_booting)
+#endif /* CONFIG_MOSIX_UDB */
 	if (in_interrupt() && (gfp_mask & __GFP_WAIT)) {
 		static int count = 0;
 		if (++count < 5) {
diff -ruN linux-2.4.16/net/core/sock.c linux-2.4.16-mosix/net/core/sock.c
--- linux-2.4.16/net/core/sock.c	Sat Jul 28 22:12:38 2001
+++ linux-2.4.16-mosix/net/core/sock.c	Sun Dec 23 13:56:53 2001
@@ -131,6 +131,10 @@
 #include <linux/filter.h>
 #endif
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 /* Run time adjustable parameters. */
 __u32 sysctl_wmem_max = SK_WMEM_MAX;
 __u32 sysctl_rmem_max = SK_RMEM_MAX;
@@ -1120,6 +1124,10 @@
 	if (sk->sleep && waitqueue_active(sk->sleep))
 		wake_up_interruptible(sk->sleep);
 	sk_wake_async(sk,1,POLL_IN);
+#ifdef CONFIG_MOSIX
+	if (sk->socket && test_bit(SOCK_INTER_MOSIX, &sk->socket->flags))
+		mosix_notify_receive(sk->socket);
+#endif /* CONFIG_MOSIX */
 	read_unlock(&sk->callback_lock);
 }
 
diff -ruN linux-2.4.16/net/ipv4/af_inet.c linux-2.4.16-mosix/net/ipv4/af_inet.c
--- linux-2.4.16/net/ipv4/af_inet.c	Mon Nov  5 19:46:12 2001
+++ linux-2.4.16-mosix/net/ipv4/af_inet.c	Sun Dec 23 13:56:53 2001
@@ -117,6 +117,10 @@
 #include <linux/wireless.h>		/* Note : will define WIRELESS_EXT */
 #endif	/* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
+
 struct linux_mib net_statistics[NR_CPUS*2];
 
 #ifdef INET_REFCNT_DEBUG
@@ -556,6 +560,10 @@
 
 	if (sk->num==0 && inet_autobind(sk) != 0)
 		return -EAGAIN;
+#ifdef CONFIG_MOSIX
+	if(reserved_mosix_address(uaddr))
+		return(-EACCES);
+#endif /* CONFIG_MOSIX */
 	return sk->prot->connect(sk, (struct sockaddr *)uaddr, addr_len);
 }
 
@@ -627,6 +635,11 @@
 			sk->sport = htons(sk->num);
 		}
 
+#ifdef CONFIG_MOSIX
+		err = -EACCES;
+		if(reserved_mosix_address(uaddr))
+			goto out;
+#endif /* CONFIG_MOSIX */
 		err = sk->prot->connect(sk, uaddr, addr_len);
 		if (err < 0)
 			goto out;
diff -ruN linux-2.4.16/net/ipv4/tcp_input.c linux-2.4.16-mosix/net/ipv4/tcp_input.c
--- linux-2.4.16/net/ipv4/tcp_input.c	Wed Nov 14 07:04:15 2001
+++ linux-2.4.16-mosix/net/ipv4/tcp_input.c	Sun Dec 23 13:56:53 2001
@@ -1987,6 +1987,9 @@
 	return 0;
 }
 
+#ifdef CONFIG_MOSIX
+#include <linux/mosix.h>
+#endif /* CONFIG_MOSIX */
 
 /* Look for tcp options. Normally only called on SYN and SYNACK packets.
  * But, this can also be called on packets in the established flow when
@@ -3054,7 +3057,13 @@
 	struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 	u32 ptr = ntohs(th->urg_ptr);
 
+#ifdef CONFIG_MOSIX
+	/* MOSIX sockets always use BSD style regardless of sysctl_tcp_stdurg */
+	if (ptr && (!sysctl_tcp_stdurg ||
+		(sk->socket && test_bit(SOCK_INTER_MOSIX, &sk->socket->flags))))
+#else
 	if (ptr && !sysctl_tcp_stdurg)
+#endif /* CONFIG_MOSIX */
 		ptr--;
 	ptr += ntohl(th->seq);
 
@@ -3081,6 +3090,17 @@
 
 	/* Tell the world about our new urgent pointer. */
 	if (sk->proc != 0) {
+#ifdef CONFIG_MOSIX
+		if (!sk->socket)
+#ifdef CONFIG_MOSIX_DEBUG
+			printk("tcp_check_urg: funny, no socket, sk=0x%x",
+									(int)sk)
+#endif /* CONFIG_MOSIX_DEBUG */
+				;
+		else if (test_bit(SOCK_INTER_MOSIX, &sk->socket->flags))
+			/*mosix_notify_urgent(sk->socket)*/ ;
+		else
+#endif /* CONFIG_MOSIX */
 		if (sk->proc > 0)
 			kill_proc(sk->proc, SIGURG, 1);
 		else
@@ -3142,6 +3162,15 @@
 			tp->urg_data = TCP_URG_VALID | tmp;
 			if (!sk->dead)
 				sk->data_ready(sk,0);
+#ifdef CONFIG_MOSIX
+			if (sk->socket &&
+				test_bit(SOCK_INTER_MOSIX, &sk->socket->flags))
+			{
+				if(tmp != 0xdb)
+					printk("tcp_urg: not 0xdb (%x)\n", tmp);
+				mosix_notify_urgent(sk->socket);
+			}
+#endif /* CONFIG_MOSIX */
 		}
 	}
 }
diff -ruN linux-2.4.16/net/sunrpc/sched.c linux-2.4.16-mosix/net/sunrpc/sched.c
--- linux-2.4.16/net/sunrpc/sched.c	Thu Oct 11 17:12:52 2001
+++ linux-2.4.16-mosix/net/sunrpc/sched.c	Sun Dec 23 13:56:53 2001
@@ -1109,6 +1109,9 @@
 	unsigned long flags;
 
 	while (all_tasks) {
+#ifdef CONFIG_MOSIX
+		current->mosix.ignoreoldsigs = 1;
+#endif /* CONFIG_MOSIX */
 		current->sigpending = 0;
 		rpc_killall_tasks(NULL);
 		__rpc_schedule();
@@ -1184,6 +1187,9 @@
 	 * Usually rpciod will exit very quickly, so we
 	 * wait briefly before checking the process id.
 	 */
+#ifdef CONFIG_MOSIX
+	current->mosix.ignoreoldsigs = 1;
+#endif /* CONFIG_MOSIX */
 	current->sigpending = 0;
 	current->policy |= SCHED_YIELD;
 	schedule();
diff -ruN linux-2.4.16/net/sunrpc/svc.c linux-2.4.16-mosix/net/sunrpc/svc.c
--- linux-2.4.16/net/sunrpc/svc.c	Fri Sep  7 20:48:39 2001
+++ linux-2.4.16-mosix/net/sunrpc/svc.c	Sun Dec 23 13:56:53 2001
@@ -185,6 +185,9 @@
 		progp->pg_name, proto == IPPROTO_UDP? "udp" : "tcp", port);
 
 	if (!port)
+#ifdef CONFIG_MOSIX
+		current->mosix.ignoreoldsigs = 1,
+#endif /* CONFIG_MOSIX */
 		current->sigpending = 0;
 
 	for (i = 0; i < progp->pg_nvers; i++) {
diff -ruN linux-2.4.16/udb/Makefile linux-2.4.16-mosix/udb/Makefile
--- linux-2.4.16/udb/Makefile	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/udb/Makefile	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+#
+# Permission to use this software is hereby granted under the terms of the
+# GNU General Public License, as published by the Free Software Foundation.
+#
+# THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+# WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+# FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+#
+#
+# Makefile for MOSIX debugger.
+#
+# Note! Dependencies are done automagically by 'make dep', which also
+# removes any old dependencies. DON'T put your own dependencies here
+# unless it's something special (ie not a .c file).
+#
+
+O_TARGET := debugger.o
+obj-y    := udb.o
+
+include $(TOPDIR)/Rules.make
+
+all_targets: symtab
+
+symtab:	symtab.o
+	$(HOSTCC) $(HOSTCFLAGS) $< -o $@
+
diff -ruN linux-2.4.16/udb/symtab.c linux-2.4.16-mosix/udb/symtab.c
--- linux-2.4.16/udb/symtab.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/udb/symtab.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh.
+ */
+#include <stdio.h>
+#include <malloc.h>
+#include <string.h>
+
+int
+main(void)
+{
+	int addr;
+	char typ;
+	char name[100];
+	char lin[120];
+	char *out = malloc(200000);
+	char *o = out, *m;
+	int a = 200000;
+	unsigned long *l;
+	int off;
+	static unsigned int Edata, End, oi, ni;
+	int fixup, nfixup = 0;
+
+	while(fgets(lin,120,stdin))
+	if(sscanf(lin, "%x %c %99s", &addr, &typ, name) == 3)
+	{
+		if(!strcmp(name, "_edata"))
+			Edata = addr;
+		if(!strcmp(name, "_end"))
+			End = addr;
+		if((off = o - out) > a - 110)
+		{
+			if(!(out = realloc(out, a += 100000)))
+			{
+				perror("realloc");
+				return(1);
+			}
+			o = out + off;
+		}
+		*o++ = typ;
+		*((long *)o) = addr;
+		o += sizeof(long);
+		strcpy(o, name);
+		while(*o)
+			o++;
+		o++;
+	}
+	*o++ = '\0';
+	while((o - out) % 4)
+		*o++ = '\0';
+	fixup = (o - out) + sizeof(long);
+	fprintf(stderr, "Symbol table size = %d\n", fixup);
+	*((long *)o) = fixup;
+	o += sizeof(long);
+	if(Edata)
+	{
+		oi = (Edata + 8191) & ~8191;
+		ni = (Edata + fixup + 8191) & ~8191;
+		nfixup = ni - oi;
+	}
+	printf("int mosix_symbols[] =\n{");
+	if(Edata && End)
+	{
+		for(m = out ; *m ; )
+		{
+			m++;
+			if(*((unsigned long *)m) == Edata)
+				*((unsigned long *)m) += fixup;
+			else if(*((unsigned long *)m) >= Edata &&
+				*((unsigned long *)m) <= End)
+				*((unsigned long *)m) += nfixup;
+			m += sizeof(long);
+			while(*m)
+				m++;
+			m++;
+		}
+	}
+	for(off = 0 , l = (unsigned long *)out ; ((char *)l) < o ; l++ , off++)
+	{
+		if(off)
+			printf(",");
+		if(off % 7 == 0)
+			printf("\n");
+		printf("0x%X", (int)*l);
+	}
+	printf("\n};\n");
+	return(0);
+}
diff -ruN linux-2.4.16/udb/udb.c linux-2.4.16-mosix/udb/udb.c
--- linux-2.4.16/udb/udb.c	Thu Jan  1 02:00:00 1970
+++ linux-2.4.16-mosix/udb/udb.c	Sun Dec 23 13:56:53 2001
@@ -0,0 +1,1891 @@
+/*
+ * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il)
+ *
+ * Permission to use this software is hereby granted under the terms of the
+ * GNU General Public License, as published by the Free Software Foundation.
+ *
+ * THIS  SOFTWARE  IS  PROVIDED IN ITS  "AS IS"  CONDITION, WITH NO WARRANTY
+ * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED.
+ */
+/*
+ * Author(s): Amnon Shiloh, Oren Laadan.
+ */
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/console.h>
+#include <linux/string.h>
+#include <linux/sched.h>
+#include <linux/sysrq.h>
+#include <linux/reboot.h>
+#include <linux/ptrace.h>
+#include <asm/hardirq.h>
+#include <asm/softirq.h>
+#include <linux/sched.h>
+#include <asm/delay.h>
+#include <linux/sys.h>
+#include <asm/uaccess.h>
+#include <linux/slab.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/mosix.h>
+#include <linux/interrupt.h>
+
+spinlock_t udb_lock = SPIN_LOCK_UNLOCKED;
+int udb_processor = -1;
+
+int nmi_debugger;
+extern struct task_struct *child_reaper;
+
+#ifdef CONFIG_MOSIX_UDB
+
+#define	MAXARGS	12
+#define	MAXBPT	100
+#define	CODE1		0x55
+#define	ORIGCODE2	0xe589
+#define	BPTCODE		0xe5cc
+
+struct udb_symtab {
+	char *module;
+	char *symtab;
+	struct udb_symtab *next;
+};
+
+struct udb_symtab symtab = { NULL, NULL, NULL };
+
+static char did_quit;
+static unsigned int set_bpt, this_bpt;
+static char dbbuf[512], argbuf[MAXARGS][100];
+static char isval[MAXARGS];
+static unsigned arg[MAXARGS];
+static unsigned long start_addr;
+static unsigned long bpts[MAXBPT];
+static unsigned char bpt_off[MAXBPT];
+static int read_from_serial = 1;
+int udb_booting;
+int udb_noesc;
+
+char on_syscall[NR_syscalls+1];
+
+void
+udbinit(void)
+{
+	extern char _edata, _etext;
+	int len = *(((int *)&_edata) - 1);
+
+	if(len > 0 && len < (&_edata - &_etext))
+	{
+		symtab.symtab = &_edata - len;
+		printk(KERN_NOTICE "MOSIX Debugger: symtab size = %d\n", len);
+	}
+	else
+		printk(KERN_ERR "MOSIX Debugger: No symbol-Table\n");
+}
+
+void
+config_udb(void)
+{
+	extern int sys_access(char *, int);
+
+	if(!sys_access("/etc/.noesc", 0))
+		udb_noesc = 1;
+}
+
+#if defined(CONFIG_PROC_FS) && defined(CONFIG_MODULES)
+
+void
+udb_proc_rmmod(char *name, struct module *m)
+{
+	struct udb_symtab *st, *prev;
+	int b;
+
+	for(b = 0 ; b < MAXBPT ; b++)
+	if(bpts[b] >= (unsigned int)m && bpts[b] < ((unsigned int)m + m->size))
+	{
+		*((unsigned short *)(bpts[b]+bpt_off[b])) = ORIGCODE2;
+		bpts[b] = 0;
+	}
+
+	for (prev = &symtab, st = symtab.next; st; st = st->next)
+		if (!strcmp(st->module, name))
+			break;
+
+	if (!st)
+		return;
+
+	prev->next = st->next;
+	kfree((void *) st->module);
+	kfree((void *) st->symtab);
+	kfree((void *) st);
+}
+
+#define TMPBUFLEN	50	/* no symbols longer than this ? */
+
+int
+udb_proc_insmod(char *buf, int len)
+{
+	struct udb_symtab *st;
+	char *p, *x, *s;
+	unsigned long addr;
+	int nex, n, pass = 0;
+	int error = -EFAULT;
+	static char tmpbuf[TMPBUFLEN];
+
+	extern struct module *find_module(char *name);
+
+	n = len;
+	if (n > TMPBUFLEN - 1)
+		n = TMPBUFLEN - 1;
+	if (copy_from_user(tmpbuf, buf, n))
+		return (-EFAULT);
+	for (nex = 0; nex < n; nex++)
+		if (isspace(tmpbuf[nex]))
+			break;
+	tmpbuf[nex] = '\0';
+	if (nex == 0) {
+		printk("udb_proc_insmod: empty module name (%s)\n", tmpbuf);
+		return (-EINVAL);
+	}
+	if (nex == TMPBUFLEN - 1) {
+		printk("udb_proc_insmod: module name too long (%s)\n", tmpbuf);
+		return (-EINVAL);
+	}
+
+	st = (struct udb_symtab *)kmalloc(sizeof(struct udb_symtab), GFP_USER);
+	if (!st)
+		return (-ENOMEM);
+	st->module = (char *) kmalloc(nex + 1, GFP_USER);
+	if (!st->module) {
+		kfree((void *) st);
+		return (-ENOMEM);
+	}
+	strcpy(st->module, tmpbuf);
+	buf += nex + 1;
+	len -= nex + 1;
+
+	x = s = (char *) kmalloc(len, GFP_USER);
+	if (!s) {
+		error = -ENOMEM;
+		goto free_st;
+	}
+
+	while (len) {
+		nex = TMPBUFLEN;
+
+		/* eat white space */
+		while (len) {
+			char c;
+
+			if (nex == TMPBUFLEN) {
+				if (n > TMPBUFLEN)
+					n = TMPBUFLEN;
+				if (copy_from_user(tmpbuf, buf, n))
+					goto free_s;
+				nex = 0;
+			}
+			c = tmpbuf[nex++];
+			if (!isspace(c))
+				break;
+			len--;
+			buf++;
+		}
+
+		if (!len)
+			break;
+
+		n = len;
+		if (n > TMPBUFLEN - 1)
+			n = TMPBUFLEN - 1;
+		if (copy_from_user(tmpbuf, buf, n))
+			goto free_s;
+		for (nex = 0; nex < n; nex++)
+			if (isspace(tmpbuf[nex]))
+				break;
+		tmpbuf[nex] = '\0';
+		if (nex == 0) {
+			printk("udb_proc_insmod: pass %d, string empty (%s)\n",
+				pass, tmpbuf);
+			error = -EINVAL;
+			goto free_s;
+		} else if (nex == n) {
+			printk("udb_proc_insmod: pass %d, too long (%s)\n",
+				pass, tmpbuf);
+			error = -EINVAL;
+			goto free_s;
+		}
+
+		if (pass == 0) {
+			/* get the address */
+			p = tmpbuf;
+			addr = simple_strtoul(p, &p, 16);
+			if (addr == 0) {
+				error = -EINVAL;
+				goto free_s;
+			}
+			*x++ = 't';	/* type is irrelevant anyway ;-) */
+			*((unsigned long *) x) = addr;
+			x += sizeof(unsigned long);
+			n = p - tmpbuf;
+			if (n < len && *p && !isspace(*p))
+				break;
+			n++;
+			pass = 1;
+
+		} else {
+			/* get the symbols string */
+			n = nex + 1;
+			memcpy(x, tmpbuf, n);
+			x += n;
+			pass = 0;
+
+		}
+		buf += n;
+		len -= n;
+	}
+	if (x == s || pass == 1 || len) {
+
+printk("udb_proc_insmod: error: x = 0x%x, s = 0x%x, pass = %d, len = %d\n",
+(int)x, (int)s, pass, len);
+
+		error = -EINVAL;
+		goto free_s;
+	}
+
+	error = -ENOMEM;
+	*((unsigned long *) x) = 0;
+	x += sizeof(unsigned long);
+	n = x - s + 1;
+	st->symtab = (char *) kmalloc(n, GFP_USER);
+	if (!st->symtab)
+		goto free_s;
+
+	/* this test in intentionally here: if done earlier, then
+	   the module may be removed while we sleep for memory */
+	if (!find_module(st->module)) {
+		error = -ENOENT;
+		kfree((void *) st->symtab);
+		goto free_s;
+	}
+
+	memcpy(st->symtab, s, n);
+	st->next = symtab.next;
+	symtab.next = st;
+
+	error = 0;
+
+free_s:
+	kfree((void *) s);
+	if (!error)
+		return (0);
+free_st:
+	kfree((void *) st->module);
+	kfree((void *) st);
+
+if(error)printk("udb_proc_insmod: error = %d !\n", error);
+
+	return (error);
+}
+
+#endif /* CONFIG_PROC_FS && CONFIG_MODULES */
+
+
+void do_hello(void), do_help(void), do_quit(void);
+void do_what(void), do_stk(void), do_boot(void);
+void do_addbpt(void), do_delbpt(void), do_listbpt(void), do_rmbpt(void);
+void do_see(void), do_set(void), do_dump(void), do_call(void);
+void do_udb_string(void);
+void do_syson(void), do_sysoff(void);
+void do_kill(void), do_send(void), do_procinfo(void), do_proc(void);
+void do_wake(void), do_regs(void), do_catch(void), do_uncatch(void);
+void do_lock(void), do_release(void);
+
+static struct
+{
+	char *name;
+	char *shown;
+	void (*fn)(void);
+	char *desc;
+} commands[] =
+{
+	{"?", NULL, do_help, ""},
+	{"help", "help/?", do_help, "produce this list"},
+	{"hello", "hello", do_hello, "say hello"},
+	{"stk", "stk", do_stk, "kernel stack trace"},
+	{"quit", "quit", do_quit, "quit the debugger"},
+	{"what", "what {address}", do_what, "what is in that address"},
+	{"add", "add/del {routine}", do_addbpt, "add/delete breakpoint at given routine"},
+	{"del", NULL, do_delbpt, ""},
+	{"list", "list", do_listbpt, "list breakpoints"},
+	{"rm", "rm {index}", do_rmbpt, "delete breakpoint by index"},
+	{"see", "see {addr|var}", do_see, "see value of address or variable"},
+	{"set", "set {addr|var},{value}[,b|w]", do_set, "set value of address or variable"},
+	{"string", "string {addr}[,len]", do_udb_string, "show address as string"},
+	{"dump", "dump {addr|var}", do_dump, "dump value from address or variable"},
+	{"call", "call {func}[,arg]...", do_call, "call a kernel routine"},
+	{"on", "on/off [syscall-no]", do_syson, "show/stop occurences of syscall"},
+	{"off", NULL, do_sysoff, ""},
+	{"kill", "kill [pid]", do_kill, "kill process[es]"},
+	{"send", "send [pid[,to]]", do_send, "send process[es]"},
+	{"wake", "wake [pid]", do_wake, "wake-up process[es]"},
+	{"regs", "regs [pid]", do_regs, "show registers"},
+	{"info", "info [pid]", do_procinfo, "find information about a process"},
+	{"catch", "[un]catch [pid]", do_catch, "breakpoint when process is scheduled"},
+	{"uncatch", NULL, do_uncatch, ""},
+	{"proc", "proc", do_proc, "list processes"},
+	{"boot", "boot [keep_dirty]", do_boot, "reboot"},
+	{"lock", "lock", do_lock, "lock the console"},
+	{"release", "release", do_release, "allow the other SMP(s) into the debugger"},
+};
+
+int udb_dbread;
+char
+getchar(void)
+{
+	struct console *c, *use = NULL;
+	char x;
+
+	for(c = console_drivers ; c ; c = c->next)
+	if((c->flags & CON_ENABLED) && c->read)
+	{
+		use = c;
+		if(read_from_serial)
+			break;
+	}
+	if(use)
+	{
+		if(udb_dbread) printk("*");
+		use->read(c, &x, 1);
+		if(udb_dbread) printk("#");
+		return(x);
+	}
+	printk("getchar: no console reader\n");
+	return('\33');
+}
+
+void
+udb_backspace(char *p, int silent)
+{
+	printk("\b \b");
+	*p = '\0';
+}
+
+static void
+getline(char *line, int len, int silent)
+{
+	int n = 0;
+	register int i;
+
+	while(1)
+	switch(line[n] = getchar())
+	{
+		case '\025':
+			while(n)
+				udb_backspace(&line[--n], silent);
+			break;
+		case '\b':
+			if(n)
+				udb_backspace(&line[--n], silent);
+			break;
+		case '\27':
+			while(n && (line[n-1] == ' ' || line[n-1] == '\t'))
+				udb_backspace(&line[--n], silent);
+			while(n && line[n-1] != ' ' && line[n-1] != '\t')
+				udb_backspace(&line[--n], silent);
+			break;
+		case '\n':
+		case '\r':
+		case '\0':
+			line[n] = '\0';
+			printk("\n");
+			return;
+		case '\33':
+			if(!n && !udb_noesc)
+			{
+				strcpy(line, "quit");
+				printk(line == dbbuf ? line : "\n");
+				return;
+			}
+			if(silent)
+			{
+				printk("*");
+				n++;
+			}
+			else
+			{
+				printk("<ESC>\n");
+				n = 0;
+			}
+			break;
+		default:
+			if(n == len - 1)
+				break;
+			if(line[n] >= 'A' && line[n] <= 'Z')
+			{
+				for(i = n-1 ; i >= 0 ; i--)
+				if(line[i] == ' ' || line[i] == '\t' || line[i] == ',')
+					break;
+				if(i < 0)
+					line[n] += 'a' - 'A';
+			}
+			printk("%c", silent ? '*' : line[n]);
+			n++;
+	}
+	line[n] = '\0';
+	return;
+}
+
+int
+is_an_int(char *buf, int *value)
+{
+	int num = 0, minus = 0, success = 0;
+
+	if(*buf == '-')
+	{
+		minus = 1;
+		buf++;
+	}
+	if((success = (*buf >= '0' && *buf <= '9')))
+	{
+		do
+			num = num * 10 + *buf++ - '0';
+		while(*buf >= '0' && *buf <= '9');
+		while(*buf == ' ' || *buf == '\t' || *buf == '\n')
+			buf++;
+		if(*buf)
+			success = 0;
+		if(minus)
+			num = -num;
+		*value = num;
+	}
+	return(success);
+}
+
+char
+press_to_continue(char *msg)
+{
+	char c;
+	char *e;
+
+	printk("%s: ", msg);
+	c = getchar();
+	printk("\b\b \b");
+	for(e = msg ; *e ; e++)
+		printk("\b \b");
+	return(c);
+}
+
+void
+breakdown(void)
+{
+	register int a;
+	register char *b, *t;
+	int num;
+	int minus;
+
+	for(b = dbbuf ; *b == ' ' || *b == '\t' ; b++);
+	if(b != dbbuf)
+		strcpy(dbbuf, b);
+	for(a = 0 ; a < MAXARGS ; a++)
+	{
+		isval[a] = 0;
+		argbuf[a][0] = '\0';
+	}
+	b = dbbuf;
+	while(*b && *b != ' ' && *b != ',' && *b != '\t')
+		b++;
+	while(*b && (*b == ' ' || *b == ',' || *b == '\t'))
+		*b++ = '\0';
+	for(a = 0 ; *b && a < MAXARGS ; a++)
+	{
+		t = argbuf[a];
+		while(*b && *b != ' ' && *b != ',' && *b != '\t')
+			*t++ = *b++;
+		while(*b && (*b == ' ' || *b == ',' || *b == '\t'))
+			*b++ = '\0';
+		*t++ = '\0';
+		t = argbuf[a];
+		num = 0;
+		if(*t == '0' && *(t+1) == 'x')
+		{
+			t += 2;
+			isval[a] = 1;
+			while(*t)
+			{
+				if(*t >= '0' && *t <= '9')
+					num = (num << 4) | (*t++ - '0');
+				else if(*t >= 'a' && *t <= 'f')
+					num = (num << 4) | (*t++ - 'a' + 10);
+				else if(*t >= 'A' && *t <= 'A')
+					num = (num << 4) | (*t++ - 'A' + 10);
+				else
+				{
+					isval[a] = 0;
+					break;
+				}
+			}
+		}
+		else
+		{
+			if(*t == '-')
+			{
+				t++;
+				minus = 1;
+			}
+			else minus = 0;
+			if(*t >= '0' && *t <= '9')
+			{
+				isval[a] = 1;
+				while(*t)
+				if(*t >= '0' && *t <= '9')
+					num = num * 10 + (*t++ - '0');
+				else
+				{
+					isval[a] = 0;
+					break;
+				}
+			}
+			if(minus)
+				num = -num;
+		}
+		arg[a] = num;
+	}
+}
+
+void
+runcmd(void)
+{
+	register int i;
+
+	for(i = 0 ; i < sizeof(commands) / sizeof(commands[0]) ; i++)
+	if(!strcmp(dbbuf, commands[i].name))
+	{
+		commands[i].fn();
+		return;
+	}
+	printk("Command (%s) Not Recognized!\n", dbbuf);
+}
+
+void
+mosix_debugger(char *msg)
+{
+	extern int keyboard_wait_for_keypress(void *);
+	unsigned int sv_this_bpt = this_bpt;
+	extern int console_loglevel;
+	int prid = smp_processor_id();
+
+	atomic_inc((atomic_t *)&nmi_debugger);
+	if(udb_processor != prid)
+	{
+		if(spin_is_locked(&udb_lock))
+			printk("Processor #%d waiting for debugger (%s)\n",
+				smp_processor_id(), msg);
+		spin_lock(&udb_lock);
+		udb_processor = prid;
+	}
+
+	this_bpt = set_bpt;
+	set_bpt = 0;
+	did_quit = 0;
+	if(udb_booting && !strcmp(msg, "catch"))
+	if(current == child_reaper)
+		do_boot();
+	if(console_loglevel < 7)
+		console_loglevel = 7;
+	printk("Debugger: %s\n", msg);
+	if(!strcmp(msg, "Keyboard"))
+		read_from_serial = 0;
+	else if(!strncmp(msg, "user request", 12))
+		read_from_serial = 1;
+	while(!did_quit)
+	{
+		printk("> ");
+		getline(dbbuf, sizeof(dbbuf), 0);
+		breakdown();
+		if(dbbuf[0])
+			runcmd();
+	}
+	did_quit = 0;
+	this_bpt = sv_this_bpt;
+	udb_processor = -1;
+	if(spin_is_locked(&udb_lock))
+		spin_unlock(&udb_lock);
+	atomic_dec((atomic_t *)&nmi_debugger);
+}
+
+void
+do_help()
+{
+	register int i;
+
+	printk("Debugger Commands:\n\n");
+	for(i = 0 ; i < sizeof(commands) / sizeof(commands[0]) ; i++)
+	if(commands[i].shown)
+	printk("%-28s - %s\n", commands[i].shown, commands[i].desc);
+}
+
+void
+do_hello(void)
+{
+	printk("hello from the debugger\n");
+}
+
+char *
+whatfunc(unsigned long a)
+{
+	struct udb_symtab *st;
+	char *x, *closest = "Null";
+	unsigned long addr, aa = 0;
+
+	for (st = &symtab; st; st = st->next)
+		for (x = st->symtab ; *x ; x += strlen(x) + 1) {
+			x++;
+			addr = *((unsigned long *)x);
+			x += sizeof(unsigned long *);
+			if (!closest || (addr <= a && addr > aa)) {
+				aa = addr;
+				closest = x;
+				start_addr = addr;
+			}
+		}
+	return(closest);
+}
+
+unsigned int
+wherefunc(char *s)
+{
+	struct udb_symtab *st;
+	char *x;
+
+	for (st = &symtab; st; st = st->next)
+		for (x = st->symtab ; *x ; x += strlen(x) + 1) {
+			x += sizeof(char) + sizeof(unsigned long);
+			if(!strcmp(s, x))
+				return(*((unsigned long *)
+						(x - sizeof(unsigned long))));
+		}
+	return(0xffffffff);
+}
+
+int
+in_text_region(unsigned int a)
+{
+	struct udb_symtab *st;
+	extern char _stext, __bss_start;
+	char *x;
+
+	if(a >= (unsigned long)&_stext && a < (unsigned long)&__bss_start)
+		return(1);
+
+	for (st = &symtab; st; st = st->next)
+	for (x = st->symtab ; *x ; x += strlen(x) + 1)
+	{
+		if(*x != 't' && *x != 'T')
+		{
+			x += sizeof(char) + sizeof(unsigned long);
+			continue;
+		}
+		x++;
+		if(*((unsigned long *)x) == a)
+			return(1);
+		x += sizeof(unsigned long);
+	}
+	return(0);
+}
+
+int
+in_kernel_mem(unsigned int a)
+{
+#if defined(CONFIG_MODULES) && defined(CONFIG_PROC_FS)
+	extern struct module *find_module(char *name);
+	struct module *m;
+#endif /* CONFIG_MODULES && CONFIG_PROC_FS */
+	extern char _stext, __bss_start;
+	struct udb_symtab *st;
+
+	if (a >= (unsigned long)&_stext && a < (unsigned long)&__bss_start)
+		return(1);
+#if defined(CONFIG_MODULES) && defined(CONFIG_PROC_FS)
+	for (st = &symtab; st; st = st->next)
+	if(st != &symtab && (m = find_module(st->module)) &&
+		a >= (unsigned int)m && a < ((unsigned int)m + m->size))
+		return(1);
+#endif /* CONFIG_MODULES && CONFIG_PROC_FS */
+	return(0);
+}
+
+void
+do_what(void)
+{
+	char *w;
+
+	if(!argbuf[0][0])
+		printk("Argument required.\n");
+	else if(!isval[0])
+		printk("argument is not a number.\n");
+	else
+	{
+		w = whatfunc(arg[0]);
+		printk("%8X: %s (starts at %X)\n", arg[0], w, (int)start_addr);
+	}
+}
+
+void
+do_stk(void)
+{
+	unsigned int ebp, eip;
+	unsigned int stack_area = (unsigned long)current;
+	int go = 0;
+	char *what;
+	char skip_one;
+
+again:
+	skip_one = 0;
+	__asm__("movl %%ebp,%0" : "=r" (ebp));
+	for(; ebp >= stack_area && ebp < 8188+stack_area ;
+		ebp = skip_one ? ebp : *(unsigned long *) ebp , skip_one = 0)
+	{
+		eip = *(unsigned long *) (ebp+4);
+		if (!in_kernel_mem(eip))
+		{
+			printk("EIP (%X) is out for EBP=%08X!\n", eip, ebp);
+			continue;
+		}
+		what = whatfunc(eip);
+		if(!strcmp(what, "error_code"))
+		{
+			eip = *((unsigned long *) (ebp + 14*4));
+			what = whatfunc(eip);
+			skip_one = 1;
+		}
+		if((go || (this_bpt ? eip == this_bpt :
+			!strcmp(what, "mosix_debugger"))) && ++go)
+		{
+			if(go == 1)
+				printk("   EBP     EIP       Offset  Function\n"
+			   "===============================================\n");
+			if(go > 1 || this_bpt)
+			{
+				printk("%08x %08x  %8lx  %s\n", ebp, eip,
+					eip - start_addr, what);
+				if(go % 20 == 0 &&
+					press_to_continue("Press Any Key to Continue (<Esc> to Abort)") == '\33')
+					return;
+			}
+		}
+		if(skip_one)
+			ebp = *((unsigned long *) (ebp + 9*4));
+	}
+if(!go && this_bpt){printk("again:\n");this_bpt=0;goto again;}
+}
+
+void
+do_boot(void)
+{
+	asmlinkage void sys_sync(void);	/* it's really int */
+	static char was_here = 0;
+	extern void set_fastest_reboot(void);
+
+	if(spin_is_locked(&udb_lock))
+		spin_unlock(&udb_lock);
+	set_fastest_reboot();
+	current->mosix.catchme = 0;
+	if(!udb_booting++ &&
+		(current->pid == 0 || (current->mosix.dflags & DREMOTE)))
+	{
+		int this_cpu = smp_processor_id();
+		/* process 0 may not sleep -- so process 1 will do it! */
+		/* a remote process cannot migrate back without losing thread */
+
+		cli();
+		while(local_irq_count(this_cpu))
+		{
+			local_irq_count(this_cpu)--;
+#ifdef CONFIG_SMP
+			release_irqlock(this_cpu);
+#endif /* CONFIG_SMP */
+		}
+		while(in_softirq())
+			local_bh_enable();
+		sti();
+		wake_up_process(child_reaper);
+		child_reaper->mosix.catchme = 1;
+		while(1)
+			schedule();
+	}
+	if(current->pid)
+		sys_sync();
+	if(!was_here)
+	{
+		was_here = 1;
+		emergency_sync_scheduled =
+			argbuf[0][0] ? EMERG_SYNC : EMERG_REMOUNT;
+		do_emergency_sync();
+	}
+	if(was_here < 2)
+	{
+		extern int C_A_D;
+		extern void ctrl_alt_del(void);
+
+		was_here = 2;
+		C_A_D = 1;
+		ctrl_alt_del();
+	}
+	machine_restart(NULL);
+}
+
+void
+do_quit(void)
+{
+	did_quit = 1;
+}
+
+int
+udb_breakpoint(struct pt_regs *regs)
+{
+	unsigned long eip = (unsigned long)regs->eip;
+	register int b;
+	static char msg[100];
+
+	if(!eip)
+		return(0);
+	for(b = 0 ; b < MAXBPT ; b++)
+	if(bpts[b] && eip == bpts[b] + bpt_off[b] + 1)
+		break;
+	if(b == MAXBPT)
+		return(0);
+	sprintf(msg, "Breakpoint #%d: %s", b, whatfunc(bpts[b]));
+
+	/* emulate the "movl %esp,%ebp" command: */
+	regs->ebp = (long)&regs->esp;
+	regs->eip++;
+
+	set_bpt = regs->eip;
+	mosix_debugger(msg);
+	return(1);
+}
+
+void
+do_addbpt(void)
+{
+	register int b;
+	int n = -1;
+	int i;
+
+	if(!argbuf[0][0])
+	{
+		printk("Argument required.\n");
+		return;
+	}
+	if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+	{
+		printk("No Such Function (%s)\n", argbuf[0]);
+		return;
+	}
+	if(!arg[0])
+	{
+		printk("Cannot Place Breakpoint at Address 0!\n");
+		return;
+	}
+	for(b = 0 ; b < MAXBPT ; b++)
+	if(n == -1 && !bpts[b])
+		n = b;
+	else if(bpts[b] == arg[0])
+	{
+		printk("But there ALREADY Is a Breakpoint at %s!\n", argbuf[0]);
+		return;
+	}
+	if(n == -1)
+	{
+		printk("Sorry, No More than %d Breakpoints.\n", MAXBPT);
+		return;
+	}
+	if(!in_text_region(arg[0]))
+	{
+		printk("Sorry, %s Is Not in the Text-Region.\n", argbuf[0]);
+		return;
+	}
+	if(*((unsigned char *)arg[0]) != CODE1)
+	{
+		nope:
+		printk("Sorry: %s Is Not a C Routine.\n", argbuf[0]);
+		return;
+	}
+	for(i = 1 ; i < 10 ; i++)
+	if(*((unsigned short *)(arg[0]+i)) == ORIGCODE2)
+		break;
+	if(i == 10)
+		goto nope;
+	bpts[n] = arg[0];
+	bpt_off[n] = i;
+	*((unsigned short *)(bpts[n]+bpt_off[n])) = BPTCODE;
+	printk("Added Breakpoint #%d at %s\n", n, argbuf[0]);
+}
+
+void
+do_delbpt(void)
+{
+	register int b;
+
+	if(!argbuf[0][0])
+	{
+		printk("Argument required.\n");
+		return;
+	}
+	if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+	{
+		printk("No Such Function (%s)\n", argbuf[0]);
+		return;
+	}
+	if(arg[0])
+	for(b = 0 ; b < MAXBPT ; b++)
+	if(bpts[b] == arg[0])
+	{
+		printk("Removed %s\n", argbuf[0]);
+		*((unsigned short *)(bpts[b]+bpt_off[b])) = ORIGCODE2;
+		bpts[b] = 0;
+		return;
+	}
+	printk("There Was No Breakpoint at %s!\n", argbuf[0]);
+}
+
+void
+do_listbpt(void)
+{
+	register int b;
+	int any = 0;
+
+	for(b = 0 ; b < MAXBPT ; b++)
+	if(bpts[b])
+	{
+		if(!any++)
+			printk("Current Brekpoints:\n");
+		printk("%2d: %08x  %s\n", b, (int)bpts[b], whatfunc(bpts[b]));
+	}
+	if(!any)
+		printk("No Breakpoints Are Currently Defined.\n");
+}
+
+void
+do_rmbpt(void)
+{
+	int b = arg[0];
+
+	if(!argbuf[0][0])
+		printk("Argument required.\n");
+	else if(!isval[0])
+		printk("argument is not a number.\n");
+	else if(b >= MAXBPT || !bpts[b])
+		printk("No Breakpoint #%d.\n", b);
+	else
+	{
+		printk("Removed %s\n", whatfunc(bpts[b]));
+		*((unsigned short *)(bpts[b]+bpt_off[b])) = ORIGCODE2;
+		bpts[arg[0]] = 0;
+	}
+}
+
+void
+do_see(void)
+{
+	char *s;
+
+	if(!argbuf[0][0])
+		printk("Argument required.\n");
+	if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+		printk("No Such Variable (%s).\n", argbuf[0]);
+	else
+	{
+		s = whatfunc(arg[0]);
+		if(strcmp(s, "Null") && start_addr == arg[0])
+			printk("<%s>: ", s);
+		printk("%x=%d (0x%x)\n", arg[0], *((int *)arg[0]),
+			*((int *)arg[0]));
+	}
+}
+
+void
+do_udb_string(void)
+{
+	char *s;
+	unsigned char *p;
+	int len = (isval[1] ? arg[1] : -1);
+
+	if(!argbuf[0][0])
+		printk("Argument required.\n");
+	if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+		printk("No Such Variable (%s).\n", argbuf[0]);
+	else
+	{
+		s = whatfunc(arg[0]);
+		if(strcmp(s, "Null") && start_addr == arg[0])
+			printk("<%s>: ", s);
+		printk("%x=<", arg[0]);
+		for(p = (unsigned char *)arg[0] ; len != 0 && (*p || len > 0) ;
+			p++ , len--)
+		{
+			if(*p & 0x80)
+				printk("[%02X]", *p & 0xff);
+			else if(*p >= ' ')
+				printk("%c", *p);
+			else switch(*p)
+			{
+				case '\n':
+					printk("\\n");
+					break;
+				case '\r':
+					printk("\\r");
+					break;
+				case '\t':
+					printk("[TAB]");
+					break;
+				case '\33':
+					printk("<ESC>");
+					break;
+				case '\0':
+					printk("<NUL>");
+					break;
+				default:
+					printk("^%c", *p + ' ');
+			}
+		}
+		printk(">\n");
+	}
+}
+
+void
+do_set(void)
+{
+	if(!argbuf[0][0] || !argbuf[1][0])
+		printk("2 Arguments required.\n");
+	else if(argbuf[2][0] && argbuf[2][0] != 'b' && argbuf[2][0] != 'w')
+		printk("3rd argument may only be 'b' or 'w'\n");
+	else if(!isval[1])
+		printk("2nd Argument must be a value.\n");
+	else if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+		printk("No Such Variable (%s).\n", argbuf[0]);
+	else if(argbuf[2][0] == 'b')
+		*((unsigned char *)arg[0]) = arg[1];
+	else if(argbuf[2][0] == 'w')
+		*((unsigned short *)arg[0]) = arg[1];
+	else
+		*((unsigned long *)arg[0]) = arg[1];
+}
+
+void
+do_dump(void)
+{
+	register int i, more = 1;
+
+	if(!argbuf[0][0])
+		printk("Argument required.\n");
+	else if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+		printk("No Such Variable (%s).\n", argbuf[0]);
+	else while(1)
+	{
+		printk("%08X:", arg[0]);
+		for(i = arg[0] ; i < arg[0] + 32 ; i += 4)
+			printk("%s%08x", i == arg[0] ? "" : " ", *((int *)i));
+		printk("\n");
+		arg[0] += 32;
+		if(--more == 0)
+		switch(press_to_continue("Press <Enter> for Next Line, <space> for More, or <Esc>"))
+		{
+			case ' ':
+				more = 16;
+				break;
+			case 'd':
+				more = 8;
+				break;
+			default:
+				more = 1;
+				break;
+			case 'q':
+			case 'Q':
+			case '\33':
+				return;
+		}
+	}
+}
+
+void
+do_call(void)
+{
+	register int a, i;
+	int (*func)(int x,...);
+	int result;
+
+	if(!argbuf[0][0])
+		printk("Routine Name required.\n");
+	else if(!isval[0] && (arg[0] = wherefunc(argbuf[0])) == 0xffffffff)
+		printk("No Such Routine (%s).\n", argbuf[0]);
+	else
+	{
+		*((unsigned int *)&func) = arg[0];
+		for(a = 1 ; a < MAXARGS ; a++)
+		if(!argbuf[a][0])
+			break;
+		else if(!isval[a])
+		{
+			printk("Argument #%d (%s) is NOT a Number!\n", a,
+				argbuf[a]);
+			return;
+		}
+		switch(a)
+		{
+			case 1:
+				result = (*func)(0);
+				break;
+			case 2:
+				result = (*func)(arg[1]);
+				break;
+			case 3:
+				result = (*func)(arg[1], arg[2]);
+				break;
+			case 4:
+				result = (*func)(arg[1], arg[2], arg[3]);
+				break;
+			case 5:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4]);
+				break;
+			case 6:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5]);
+				break;
+			case 7:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5], arg[6]);
+				break;
+			case 8:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5], arg[6], arg[7]);
+				break;
+			case 9:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5], arg[6], arg[7], arg[8]);
+				break;
+			case 10:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5], arg[6], arg[7], arg[8],
+					arg[9]);
+				break;
+			case 11:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5], arg[6], arg[7], arg[8],
+					arg[9], arg[10]);
+			case 12:
+				result = (*func)(arg[1], arg[2], arg[3],
+					arg[4], arg[5], arg[6], arg[7], arg[8],
+					arg[9], arg[10], arg[11]);
+			default:
+				printk("Debugger needs more cases here...\n");
+				return;
+		}
+		printk("Result of calling %s(", argbuf[0]);
+		for(i = 1 ; i < a ; i++)
+			printk("%s%s", i == 1 ? "\0" : ",", argbuf[i]);
+		printk(") = %d (0x%x)\n", result, result);
+	}
+}
+
+int
+get_the_proc_lock(void)
+{
+	register int i;
+	char resp;
+
+	for(i = 0 ; i < 100000 ; i++)
+	if(can_read_lock(&tasklist_lock))
+		break;
+	if(i < 100000)
+	{
+		read_lock(&tasklist_lock);
+		return(1);
+	}
+	printk("The Process-List-Lock Is Write-Locked: Proceed Anyway [y/N]? ");
+	resp = getchar();
+	if(resp == 'y' || resp == 'Y')
+	{
+		printk("Yes.\n");
+		return(0);
+	}
+	printk("No.\n");
+	return(-1);
+}
+
+char
+stat_to_let(int stat)
+{
+	switch(stat)
+	{
+		case TASK_RUNNING:
+			return('R');
+		case TASK_INTERRUPTIBLE:
+			return('S');
+		case TASK_UNINTERRUPTIBLE:
+			return('T');
+		case TASK_ZOMBIE:
+			return('Z');
+		case TASK_STOPPED:
+			return('T');
+		case TASK_SAME:
+			return('=');
+		default:
+			return('?');
+	}
+}
+
+void
+do_proc(void)
+{
+	register struct task_struct *p;
+	int could_lock = get_the_proc_lock();
+	int more = 22;
+
+	if(could_lock == -1)
+		return;
+	printk("*  PID NAME             sS  PPID flags    dflag       reqs     stay    \n");
+	printk("=======================================================================\n");
+	for_each_task(p)
+	{
+		printk("%c%5d %-16s %c%c", (p == current) ? '*' : ' ',
+			p->pid, p->comm,
+			stat_to_let(p->state), stat_to_let(p->mosix.bstate));
+		printk(" %5d", p->p_pptr->pid);
+		printk(" %08X %08X%c%c%c %08X %08X", (int)p->flags, (int)p->mosix.dflags,
+			p->mosix.commpri ? 'P' : ' ',
+			p->mosix.ignoreoldsigs ? 'I' : ' ',
+			p->mosix.catchme ? 'C' : ' ',
+			atomic_read(&p->mosix.dreqs), (int)p->mosix.stay);
+		printk("\n");
+		if(--more == 0)
+		switch(press_to_continue("Press <Enter> for Next Line, <space> for More, or <Esc>"))
+		{
+			case ' ':
+				more = 24;
+				break;
+			case 'd':
+				more = 12;
+				break;
+			default:
+				more = 1;
+				break;
+			case 'q':
+			case 'Q':
+			case '\33':
+				if(could_lock)
+					read_unlock(&tasklist_lock);
+				return;
+		}
+	}
+	if(could_lock)
+		read_unlock(&tasklist_lock);
+}
+
+int
+eqcmd(char *comm, char *str)
+{
+	if(!strcmp(comm, str))
+		return(1);
+	if(!strcmp(str, "remote") && !strncmp(comm, "remote(", 7))
+		return(1);
+	return(0);
+}
+
+void
+proc_command(void (*func)(struct task_struct *, char *), char *action, int yesno)
+{
+	int could_lock = get_the_proc_lock();
+	int any = 0;
+	char buf[10];
+	register struct task_struct *p;
+
+	for_each_task(p)
+	{
+		if(isval[0] && p->pid == arg[0])
+		{
+			(*func)(p, "");
+			goto out;
+		}
+		if(argbuf[0][0] && eqcmd(p->comm, argbuf[0]))
+			any++;
+	}
+	if(isval[0])
+	{
+		printk("%d: No Such Process\n", arg[0]);
+		goto out;
+	}
+	if(any == 1)
+	for_each_task(p)
+	if(eqcmd(p->comm, argbuf[0]))
+	{
+		(*func)(p, "");
+		goto out;
+	}
+	if(any > 1)
+		printk("There are %d '%s' Processes:\n", any, argbuf[0]);
+	if(argbuf[0][0] && !any)
+	{
+		printk("%s: No Such Process\n", argbuf[0]);
+		goto out;
+	}
+	for_each_task(p)
+	{
+		if(argbuf[0][0] && !eqcmd(p->comm, argbuf[0]))
+			continue;
+		printk("%s %d(%s)? ", action, p->pid, p->comm);
+		if(yesno)
+		{
+			buf[0] = getchar();
+			printk("%c", buf[0]);
+			if(buf[0] == 'y' || buf[0] == 'Y')
+				(*func)(p, buf);
+			printk("\n");
+			if(buf[0] == 'q' || buf[0] == 'Q' || buf[0] == '\33')
+				goto out;
+		}
+		else
+		{
+			getline(buf, sizeof(buf), 0);
+			if(!strcmp(buf, "quit"))
+				goto out;
+			if(buf[0])
+				(*func)(p, buf);
+		}
+	}
+	out:
+	if(could_lock)
+		read_unlock(&tasklist_lock);
+}
+
+void
+low_do_kill(struct task_struct *p, char *num)
+{
+	int sig = 0;
+	char buf[10];
+
+	if(isval[1])
+		sig = arg[1];
+	else if(!is_an_int(num, &sig))
+	{
+		printk("What Signal to Send? ");
+		getline(buf, sizeof(buf), 0);
+		if(!is_an_int(buf, &sig))
+			return;
+	}
+	if(sig <= 0 || sig > _NSIG)
+	{
+		printk("Invalid Signal Number: (range is 1-%d)\n", _NSIG);
+		return;
+	}
+#ifdef CONFIG_SMP
+	if(p->sigmask_lock.lock & 0x80000000)
+	{
+		printk("Sorry, sigmask_lock = %x -- would block!\n",
+			p->sigmask_lock.lock);
+		return;
+	}
+#endif /* CONFIG_SMP */
+	send_sig(sig, p, 1);
+}
+
+void
+do_kill(void)
+{
+	proc_command(low_do_kill,
+		isval[1] ? (arg[1] == SIGKILL ? "kill" : "signal") :
+			"What Signal to Send", isval[1]);
+}
+
+void
+low_do_send(struct task_struct *p, char *num)
+{
+	int where = 0;
+	char buf[10];
+
+	if(isval[1])
+		where = arg[1];
+	else if(!is_an_int(num, &where))
+	{
+		printk("Where to Send? ");
+		getline(buf, sizeof(buf), 0);
+		if(!is_an_int(buf, &where))
+			return;
+	}
+	mosix_do_add_to_whereto(p, where);
+}
+
+void
+do_send(void)
+{
+	proc_command(low_do_send, isval[1] ? "Send" : "Where to Send",
+		isval[1]);
+}
+
+void
+low_do_procinfo(struct task_struct *p, char *num)
+{
+	register struct mosix_task *m = &p->mosix;
+	printk("process %d(%s) at 0x%x, mm at 0x%x, MOSIX at 0x%x:\n", p->pid,
+		p->comm, (int)p, (int)p->mm, (int)m);
+	printk("state=%ld, bstate=%ld, lock_depth=%d+%d, altregs=%x, deputy_regs=%x, where=%d\n",
+		p->state, m->bstate, p->lock_depth, p->mosix.lock_depth,
+		(int)m->altregs, (int)m->deputy_regs, m->whereami);
+	printk("from=%d, pass_regs=0x%x, used_math=%d, swappable=%d, rss=%d\n",
+		m->deppe, m->pass_regs, p->used_math, p->swappable,
+		p->mm ? (int)p->mm->rss : 0);
+	printk("&dflags=0x%x, whereto=%d,load=%d,migpages=%d,pages_i_bring=%d,disclosure=%d\n", (int)&m->dflags,
+		m->whereto, m->load, m->migpages, m->pages_i_bring, m->disclosure);
+}
+
+void
+do_procinfo(void)
+{
+	proc_command(low_do_procinfo, "Information on", 1);
+}
+
+static void
+printreg(struct task_struct *p, char *name, int bit)
+{
+	register int i;
+	register char *c;
+	unsigned mask = (p->mosix.dflags & DDEPUTY) ? p->mosix.deputy_regs :
+		(p->mosix.dflags & DREMOTE) ?
+			(ALL_REGISTERS & ~p->mosix.deputy_regs) : ALL_REGISTERS;
+	int here = mask & bit;
+
+	printk("  ");
+	if(here)
+	for(c = name ; *c ; c++)
+		printk("%c", (*c == '_') ? '_' : *c + 'A' - 'a');
+	else
+		printk("%s", name);
+	printk("=");
+	for(i = 0 ; !(bit & (1 << i)) ; i++);
+	printk(name[0] == 'x' ? (here ? "%02X" : "%02x") :
+		(here ? "%08X" : "%08x"), ((int *)p->mosix.altregs)[i]);
+}
+
+void
+low_do_regs(struct task_struct *p, char *num)
+{
+	printk("%d(%s):", p->pid, p->comm);
+	printreg(p, "eip", BIT_OF_REGISTER(eip));
+	printreg(p, "esp", BIT_OF_REGISTER(esp));
+	printreg(p, "eax", BIT_OF_REGISTER(eax));
+	printreg(p, "orig_eax", BIT_OF_REGISTER(orig_eax));
+	printk("\n");
+	printreg(p, "ebx", BIT_OF_REGISTER(ebx));
+	printreg(p, "ecx", BIT_OF_REGISTER(ecx));
+	printreg(p, "edx", BIT_OF_REGISTER(edx));
+	printreg(p, "ebp", BIT_OF_REGISTER(ebp));
+	printreg(p, "eflags", BIT_OF_REGISTER(eflags));
+	printk("\n");
+	printreg(p, "esi", BIT_OF_REGISTER(esi));
+	printreg(p, "edi", BIT_OF_REGISTER(edi));
+	printreg(p, "xcs", BIT_OF_REGISTER(xcs));
+	printreg(p, "xds", BIT_OF_REGISTER(xds));
+	printreg(p, "xes", BIT_OF_REGISTER(xes));
+	printreg(p, "xss", BIT_OF_REGISTER(xss));
+	printk("\n");
+}
+
+void
+do_regs(void)
+{
+	proc_command(low_do_regs, "Registers of", 1);
+}
+
+void
+low_do_wake(struct task_struct *p, char *num)
+{
+	wake_up_process(p);
+}
+
+void
+do_wake(void)
+{
+	proc_command(low_do_wake, "Wake up", 1);
+}
+
+void
+low_do_catch(struct task_struct *p, char *num)
+{
+	p->mosix.catchme = (!isval[1] || arg[1]);
+}
+
+void
+do_catch(void)
+{
+	proc_command(low_do_catch, "Catch", 1);
+}
+
+void
+do_uncatch(void)
+{
+	arg[1] = 0;
+	isval[1] = 1;
+	proc_command(low_do_catch, "Uncatch", 1);
+}
+
+void
+do_lock(void)
+{
+	char buf1[20], buf2[20];
+
+	printk("Password: ");
+	getline(buf1, 20, 1);
+	printk("Locked...\n");
+	while(1)
+	{
+		printk("Password: ");
+		getline(buf2, 20, 1);
+		if(strcmp(buf1, buf2))
+			printk("Incorrect!\n");
+		else
+			return;
+	}
+}
+
+void
+do_release(void)
+{
+	int prid = smp_processor_id();
+	volatile int i;
+
+	udb_processor = -1;
+	if(spin_is_locked(&udb_lock))
+		spin_unlock(&udb_lock);
+	for(i = 0 ; i < 10000 ; i++)
+		;
+	spin_lock(&udb_lock);
+	udb_processor = prid;
+	printk("Debugger back to processor #%d\n", prid);
+}
+
+int sys_trc;
+int only_remote;
+
+char *syscallname[NR_syscalls+1] =
+{
+	"setup",
+	"exit",
+	"fork",
+	"read",
+	"write",
+	"open",
+	"close",
+	"waitpid",
+	"creat",
+	"link",
+	"unlink",
+	"execve",
+	"chdir",
+	"time",
+	"mknod",
+	"chmod",
+	"lchown16",
+	"ni_syscall",
+	"stat",
+	"lseek",
+	"getpid",
+	"mount",
+	"oldumount",
+	"setuid16",
+	"getuid16",
+	"stime",
+	"ptrace",
+	"alarm",
+	"fstat",
+	"pause",
+	"utime",
+	"ni_syscall",
+	"ni_syscall",
+	"access",
+	"nice",
+	"ni_syscall",
+	"sync",
+	"kill",
+	"rename",
+	"mkdir",
+	"rmdir",
+	"dup",
+	"pipe",
+	"times",
+	"ni_syscall",
+	"brk",
+	"setgid16",
+	"getgid16",
+	"signal",
+	"geteuid16",
+	"getegid16",
+	"acct",
+	"umount",
+	"ni_syscall",
+	"ioctl",
+	"fcntl",
+	"ni_syscall",
+	"setpgid",
+	"ni_syscall",
+	"olduname",
+	"umask",
+	"chroot",
+	"ustat",
+	"dup2",
+	"getppid",
+	"getpgrp",
+	"setsid",
+	"sigaction",
+	"sgetmask",
+	"ssetmask",
+	"setreuid16",
+	"setregid16",
+	"sigsuspend",
+	"sigpending",
+	"sethostname",
+	"setrlimit",
+	"old_getrlimit",
+	"getrusage",
+	"gettimeofday",
+	"settimeofday",
+	"getgroups16",
+	"setgroups16",
+	"old_select",
+	"symlink",
+	"lstat",
+	"readlink",
+	"uselib",
+	"swapon",
+	"reboot",
+	"old_readdir",
+	"old_mmap",
+	"munmap",
+	"truncate",
+	"ftruncate",
+	"fchmod",
+	"fchown16",
+	"getpriority",
+	"setpriority",
+	"ni_syscall",
+	"statfs",
+	"fstatfs",
+	"ioperm",
+	"socketcall",
+	"syslog",
+	"setitimer",
+	"getitimer",
+	"newstat",
+	"newlstat",
+	"newfstat",
+	"uname",
+	"iopl",
+	"vhangup",
+	"ni_syscall",
+	"vm86old",
+	"wait4",
+	"swapoff",
+	"sysinfo",
+	"ipc",
+	"fsync",
+	"sigreturn",
+	"clone",
+	"setdomainname",
+	"newuname",
+	"modify_ldt",
+	"adjtimex",
+	"mprotect",
+	"sigprocmask",
+	"create_module",
+	"init_module",
+	"delete_module",
+	"get_kernel_syms",
+	"quotactl",
+	"getpgid",
+	"fchdir",
+	"bdflush",
+	"sysfs",
+	"personality",
+	"ni_syscall",
+	"setfsuid16",
+	"setfsgid16",
+	"llseek",
+	"getdents",
+	"select",
+	"flock",
+	"msync",
+	"readv",
+	"writev",
+	"getsid",
+	"fdatasync",
+	"sysctl",
+	"mlock",
+	"munlock",
+	"mlockall",
+	"munlockall",
+	"sched_setparam",
+	"sched_getparam",
+	"sched_setscheduler",
+	"sched_getscheduler",
+	"sched_yield",
+	"sched_get_priority_max",
+	"sched_get_priority_min",
+	"sched_rr_get_interval",
+	"nanosleep",
+	"mremap",
+	"setresuid16",
+	"getresuid16",
+	"vm86",
+	"query_module",
+	"poll",
+	"nfsservctl",
+	"setresgid16",
+	"getresgid16",
+	"prctl",
+	"rt_sigreturn",
+	"rt_sigaction",
+	"rt_sigprocmask",
+	"rt_sigpending",
+	"rt_sigtimedwait",
+	"rt_sigqueueinfo",
+	"rt_sigsuspend",
+	"pread",
+	"pwrite",
+	"chown16",
+	"getcwd",
+	"capget",
+	"capset",
+	"sigaltstack",
+	"sendfile",
+	"ni_syscall",
+	"ni_syscall",
+	"vfork",
+	"getrlimit",
+	"mmap2",
+	"truncate64",
+	"ftruncate64",
+	"stat64",
+	"lstat64",
+	"fstat64",
+	"lchown",
+	"getuid",
+	"getgid",
+	"geteuid",
+	"getegid",
+	"setreuid",
+	"setregid",
+	"getgroups",
+	"setgroups",
+	"fchown",
+	"setresuid",
+	"getresuid",
+	"setresgid",
+	"getresgid",
+	"chown",
+	"setuid",
+	"setgid",
+	"setfsuid",
+	"setfsgid",
+	"pivot_root",
+	"mincore",
+	"madvise",
+	"getdents64",
+	"fcntl64",
+	NULL,
+	NULL,
+	"gettid",
+	"readahead"
+};
+
+void
+sys_call_trace(int n, int a, int b, int c, int d, int e)
+{
+	int nargs;
+
+	if(only_remote && !(current->mosix.dflags & DREMOTE))
+		return;
+	if(n < 0 || n > NR_syscalls)
+	{
+		if(sys_trc)
+			printk("Syscall #%d (out of range!)\n", n);
+		return;
+	}
+	if(sys_trc || on_syscall[n])
+	{
+		printk("Syscall ");
+		if(syscallname[n])
+			printk(syscallname[n]);
+		else
+			printk("#%d", n);
+		if((nargs = (on_syscall[n] ? on_syscall[n] : sys_trc) - 1) > 0)
+		{
+			printk("(%x", a);
+			if(nargs > 1)
+				printk(",%x", b);
+			if(nargs > 2)
+				printk(",%x", c);
+			if(nargs > 3)
+				printk(",%x", d);
+			if(nargs > 4)
+				printk(",%x", e);
+			printk(")");
+		}
+		printk(" by %d(%s)\n", current->pid, current->comm);
+	}
+}
+
+void
+sys_call_etrace(struct pt_regs *regs)
+{
+}
+
+void
+do_sysonoff(int on)
+{
+	register int i;
+
+	if(isval[0])
+	{
+		if(arg[0] == 0)
+			sys_trc = on;
+		else if(arg[0] <= NR_syscalls)
+			on_syscall[arg[0]] = on;
+		else
+			printk("Syscall #%d???\n", arg[0]);
+	}
+	else if(argbuf[0][0])
+	{
+		for(i = 0 ; i <= NR_syscalls ; i++)
+		if(syscallname[i] && !strcmp(argbuf[0], syscallname[i]))
+		{
+			on_syscall[i] = on;
+			return;
+		}
+		printk("No system call \"%s\"!\n", argbuf[0]);
+	}
+	else
+		sys_trc = on;
+}
+
+void
+do_syson(void)
+{
+	do_sysonoff(isval[1] ? arg[1]+1 : 1);
+}
+
+void
+do_sysoff(void)
+{
+	do_sysonoff(0);
+}
+
+int
+Signal_pending(struct task_struct *p)
+{
+	if(!p)
+		p = current;
+	return(signal_pending(p));
+}
+
+#endif /* CONFIG_MOSIX_UDB */