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
|
/* $Id: sysirix.c,v 1.5 1997/08/10 22:24:11 shaver Exp $
* sysirix.c: IRIX system call emulation.
*
* Copyright (C) 1996 David S. Miller
*/
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/pagemap.h>
#include <linux/mm.h>
#include <linux/mman.h>
#include <linux/malloc.h>
#include <linux/swap.h>
#include <linux/errno.h>
#include <linux/timex.h>
#include <linux/times.h>
#include <linux/elf.h>
#include <linux/msg.h>
#include <linux/shm.h>
#include <linux/smp.h>
#include <linux/smp_lock.h>
#include <linux/utsname.h>
#include <asm/ptrace.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/uaccess.h>
#include <asm/sgialib.h>
/* 2,300 lines of complete and utter shit coming up... */
/* The sysmp commands supported thus far. */
#define MP_NPROCS 1 /* # processor in complex */
#define MP_NAPROCS 2 /* # active processors in complex */
#define MP_PGSIZE 14 /* Return system page size in v1. */
asmlinkage int irix_sysmp(struct pt_regs *regs)
{
unsigned long cmd;
int base = 0;
int error = 0;
lock_kernel();
if(regs->regs[2] == 1000)
base = 1;
cmd = regs->regs[base + 4];
switch(cmd) {
case MP_PGSIZE:
error = PAGE_SIZE;
break;
case MP_NPROCS:
error = NR_CPUS;
break;
case MP_NAPROCS:
error = NR_CPUS;
break;
default:
printk("SYSMP[%s:%d]: Unsupported opcode %d\n",
current->comm, current->pid, (int)cmd);
error = -EINVAL;
break;
}
unlock_kernel();
return error;
}
/* The prctl commands. */
#define PR_MAXPROCS 1 /* Tasks/user. */
#define PR_ISBLOCKED 2 /* If blocked, return 1. */
#define PR_SETSTACKSIZE 3 /* Set largest task stack size. */
#define PR_GETSTACKSIZE 4 /* Get largest task stack size. */
#define PR_MAXPPROCS 5 /* Num parallel tasks. */
#define PR_UNBLKONEXEC 6 /* When task exec/exit's, unblock. */
#define PR_SETEXITSIG 8 /* When task exit's, set signal. */
#define PR_RESIDENT 9 /* Make task unswappable. */
#define PR_ATTACHADDR 10 /* (Re-)Connect a vma to a task. */
#define PR_DETACHADDR 11 /* Disconnect a vma from a task. */
#define PR_TERMCHILD 12 /* When parent sleeps with fishes, kill child. */
#define PR_GETSHMASK 13 /* Get the sproc() share mask. */
#define PR_GETNSHARE 14 /* Number of share group members. */
#define PR_COREPID 15 /* Add task pid to name when it core. */
#define PR_ATTACHADDRPERM 16 /* (Re-)Connect vma, with specified prot. */
#define PR_PTHREADEXIT 17 /* Kill a pthread without prejudice. */
asmlinkage int irix_prctl(struct pt_regs *regs)
{
unsigned long cmd;
int error = 0, base = 0;
lock_kernel();
if(regs->regs[2] == 1000)
base = 1;
cmd = regs->regs[base + 4];
switch(cmd) {
case PR_MAXPROCS:
printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
current->comm, current->pid);
error = NR_TASKS;
break;
case PR_ISBLOCKED: {
struct task_struct *task;
printk("irix_prctl[%s:%d]: Wants PR_ISBLOCKED\n",
current->comm, current->pid);
task = find_task_by_pid(regs->regs[base + 5]);
if(!task) {
error = -ESRCH;
break;
}
error = (task->next_run ? 0 : 1);
/* Can _your_ OS find this out that fast? */
break;
}
case PR_SETSTACKSIZE: {
long value = regs->regs[base + 5];
printk("irix_prctl[%s:%d]: Wants PR_SETSTACKSIZE<%08lx>\n",
current->comm, current->pid, (unsigned long) value);
if(value > RLIM_INFINITY)
value = RLIM_INFINITY;
if(suser()) {
current->rlim[RLIMIT_STACK].rlim_max =
current->rlim[RLIMIT_STACK].rlim_cur = value;
error = value;
break;
}
if(value > current->rlim[RLIMIT_STACK].rlim_max) {
error = -EINVAL;
break;
}
current->rlim[RLIMIT_STACK].rlim_cur = value;
error = value;
break;
}
case PR_GETSTACKSIZE:
printk("irix_prctl[%s:%d]: Wants PR_GETSTACKSIZE\n",
current->comm, current->pid);
error = current->rlim[RLIMIT_STACK].rlim_cur;
break;
case PR_MAXPPROCS:
printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
current->comm, current->pid);
error = 1;
break;
case PR_UNBLKONEXEC:
printk("irix_prctl[%s:%d]: Wants PR_UNBLKONEXEC\n",
current->comm, current->pid);
error = -EINVAL;
break;
case PR_SETEXITSIG:
printk("irix_prctl[%s:%d]: Wants PR_SETEXITSIG\n",
current->comm, current->pid);
/* We can probably play some game where we set the task
* exit_code to some non-zero value when this is requested,
* and check whether exit_code is already set in do_exit().
*/
error = -EINVAL;
break;
case PR_RESIDENT:
printk("irix_prctl[%s:%d]: Wants PR_RESIDENT\n",
current->comm, current->pid);
error = 0; /* Compatability indeed. */
break;
case PR_ATTACHADDR:
printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDR\n",
current->comm, current->pid);
error = -EINVAL;
break;
case PR_DETACHADDR:
printk("irix_prctl[%s:%d]: Wants PR_DETACHADDR\n",
current->comm, current->pid);
error = -EINVAL;
break;
case PR_TERMCHILD:
printk("irix_prctl[%s:%d]: Wants PR_TERMCHILD\n",
current->comm, current->pid);
error = -EINVAL;
break;
case PR_GETSHMASK:
printk("irix_prctl[%s:%d]: Wants PR_GETSHMASK\n",
current->comm, current->pid);
error = -EINVAL; /* Until I have the sproc() stuff in. */
break;
case PR_GETNSHARE:
error = 0; /* Until I have the sproc() stuff in. */
break;
case PR_COREPID:
printk("irix_prctl[%s:%d]: Wants PR_COREPID\n",
current->comm, current->pid);
error = -EINVAL;
break;
case PR_ATTACHADDRPERM:
printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDRPERM\n",
current->comm, current->pid);
error = -EINVAL;
break;
case PR_PTHREADEXIT:
printk("irix_prctl[%s:%d]: Wants PR_PTHREADEXIT\n",
current->comm, current->pid);
do_exit(regs->regs[base + 5]);
default:
printk("irix_prctl[%s:%d]: Non-existant opcode %d\n",
current->comm, current->pid, (int)cmd);
error = -EINVAL;
break;
}
unlock_kernel();
return error;
}
#undef DEBUG_PROCGRPS
extern unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt);
extern asmlinkage int sys_setpgid(pid_t pid, pid_t pgid);
extern void sys_sync(void);
extern asmlinkage int sys_getsid(pid_t pid);
extern asmlinkage int sys_getgroups(int gidsetsize, gid_t *grouplist);
extern asmlinkage int sys_setgroups(int gidsetsize, gid_t *grouplist);
extern int getrusage(struct task_struct *p, int who, struct rusage *ru);
extern char *prom_getenv(char *name);
extern long prom_setenv(char *name, char *value);
/* The syssgi commands supported thus far. */
#define SGI_SYSID 1 /* Return unique per-machine identifier. */
#define SGI_RDNAME 6 /* Return string name of a process. */
#define SGI_SETNVRAM 8 /* Set PROM variable. */
#define SGI_GETNVRAM 9 /* Get PROM variable. */
#define SGI_SETPGID 21 /* Set process group id. */
#define SGI_SYSCONF 22 /* POSIX sysconf garbage. */
#define SGI_PATHCONF 24 /* POSIX sysconf garbage. */
#define SGI_SETGROUPS 40 /* POSIX sysconf garbage. */
#define SGI_GETGROUPS 41 /* POSIX sysconf garbage. */
#define SGI_RUSAGE 56 /* BSD style rusage(). */
#define SGI_SSYNC 62 /* Synchronous fs sync. */
#define SGI_GETSID 65 /* SysVr4 get session id. */
#define SGI_ELFMAP 68 /* Map an elf image. */
#define SGI_TOSSTSAVE 108 /* Toss saved vma's. */
#define SGI_FP_BCOPY 129 /* Should FPU bcopy be used on this machine? */
#define SGI_PHYSP 1011 /* Translate virtual into physical page. */
asmlinkage int irix_syssgi(struct pt_regs *regs)
{
unsigned long cmd;
int retval, base = 0;
lock_kernel();
if(regs->regs[2] == 1000)
base = 1;
cmd = regs->regs[base + 4];
switch(cmd) {
case SGI_SYSID: {
char *buf = (char *) regs->regs[base + 5];
/* XXX Use ethernet addr.... */
retval = clear_user(buf, 64);
break;
}
case SGI_RDNAME: {
int pid = (int) regs->regs[base + 5];
char *buf = (char *) regs->regs[base + 6];
struct task_struct *p;
retval = verify_area(VERIFY_WRITE, buf, 16);
if(retval)
break;
for_each_task(p) {
if(p->pid == pid)
goto found0;
}
retval = -ESRCH;
found0:
/* XXX Need to check sizes. */
copy_to_user(buf, p->comm, 16);
retval = 0;
break;
}
case SGI_GETNVRAM: {
char *name = (char *) regs->regs[base+5];
char *buf = (char *) regs->regs[base+6];
char *value;
return -EINVAL; /* til I fix it */
retval = verify_area(VERIFY_WRITE, buf, 128);
if (retval)
break;
value = prom_getenv(name);
if (!value) {
retval = -EINVAL;
break;
}
/* Do I strlen() for the length? */
copy_to_user(buf, value, 128);
retval = 0;
break;
}
case SGI_SETNVRAM: {
char *name = (char *) regs->regs[base+5];
char *value = (char *) regs->regs[base+6];
return -EINVAL; /* til I fix it */
retval = prom_setenv(name, value);
/* XXX make sure retval conforms to syssgi(2) */
printk("[%s:%d] setnvram(\"%s\", \"%s\"): retval %d",
current->comm, current->pid,
name, value, retval);
if (retval == PROM_ENOENT)
retval = -ENOENT;
break;
}
case SGI_SETPGID: {
#ifdef DEBUG_PROCGRPS
printk("[%s:%d] setpgid(%d, %d) ",
current->comm, current->pid,
(int) regs->regs[base + 5], (int)regs->regs[base + 6]);
#endif
retval = sys_setpgid(regs->regs[base + 5], regs->regs[base + 6]);
#ifdef DEBUG_PROCGRPS
printk("retval=%d\n", retval);
#endif
}
case SGI_SYSCONF: {
switch(regs->regs[base + 5]) {
case 1:
retval = (MAX_ARG_PAGES >> 4); /* XXX estimate... */
goto out;
case 2:
retval = NR_TASKS;
goto out;
case 3:
retval = HZ;
goto out;
case 4:
retval = NGROUPS;
goto out;
case 5:
retval = NR_OPEN;
goto out;
case 6:
retval = 1;
goto out;
case 7:
retval = 1;
goto out;
case 8:
retval = 199009;
goto out;
case 11:
retval = PAGE_SIZE;
goto out;
case 12:
retval = 4;
goto out;
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
retval = 0;
goto out;
case 31:
retval = 32;
goto out;
default:
retval = -EINVAL;
goto out;
};
}
case SGI_SETGROUPS:
retval = sys_setgroups((int) regs->regs[base + 5],
(gid_t *) regs->regs[base + 6]);
break;
case SGI_GETGROUPS:
retval = sys_getgroups((int) regs->regs[base + 5],
(gid_t *) regs->regs[base + 6]);
break;
case SGI_RUSAGE: {
struct rusage *ru = (struct rusage *) regs->regs[base + 6];
switch((int) regs->regs[base + 5]) {
case 0:
/* rusage self */
retval = getrusage(current, RUSAGE_SELF, ru);
goto out;
case -1:
/* rusage children */
retval = getrusage(current, RUSAGE_CHILDREN, ru);
goto out;
default:
retval = -EINVAL;
goto out;
};
}
case SGI_SSYNC:
sys_sync();
retval = 0;
break;
case SGI_GETSID:
#ifdef DEBUG_PROCGRPS
printk("[%s:%d] getsid(%d) ", current->comm, current->pid,
(int) regs->regs[base + 5]);
#endif
retval = sys_getsid(regs->regs[base + 5]);
#ifdef DEBUG_PROCGRPS
printk("retval=%d\n", retval);
#endif
break;
case SGI_ELFMAP:
retval = irix_mapelf((int) regs->regs[base + 5],
(struct elf_phdr *) regs->regs[base + 6],
(int) regs->regs[base + 7]);
break;
case SGI_TOSSTSAVE:
/* XXX We don't need to do anything? */
retval = 0;
break;
case SGI_FP_BCOPY:
retval = 0;
break;
case SGI_PHYSP: {
pgd_t *pgdp;
pmd_t *pmdp;
pte_t *ptep;
unsigned long addr = regs->regs[base + 5];
int *pageno = (int *) (regs->regs[base + 6]);
retval = verify_area(VERIFY_WRITE, pageno, sizeof(int));
if(retval)
return retval;
pgdp = pgd_offset(current->mm, addr);
pmdp = pmd_offset(pgdp, addr);
ptep = pte_offset(pmdp, addr);
if(ptep) {
if(pte_val(*ptep) & (_PAGE_VALID | _PAGE_PRESENT)) {
return put_user((pte_val(*ptep) & PAGE_MASK)>>PAGE_SHIFT, pageno);
return 0;
}
}
retval = -EINVAL;
break;
}
default:
printk("irix_syssgi: Unsupported command %d\n", (int)cmd);
retval = -EINVAL;
break;
};
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_gtime(struct pt_regs *regs)
{
return CURRENT_TIME;
}
int vm_enough_memory(long pages);
/*
* IRIX is completely broken... it returns 0 on success, otherwise
* ENOMEM.
*/
asmlinkage int irix_brk(unsigned long brk)
{
unsigned long rlim;
unsigned long newbrk, oldbrk;
struct mm_struct *mm = current->mm;
int ret;
lock_kernel();
if (brk < current->mm->end_code) {
ret = -ENOMEM;
goto out;
}
newbrk = PAGE_ALIGN(brk);
oldbrk = PAGE_ALIGN(mm->brk);
if (oldbrk == newbrk) {
mm->brk = brk;
ret = 0;
goto out;
}
/*
* Always allow shrinking brk
*/
if (brk <= current->mm->brk) {
mm->brk = brk;
do_munmap(newbrk, oldbrk-newbrk);
ret = 0;
goto out;
}
/*
* Check against rlimit and stack..
*/
rlim = current->rlim[RLIMIT_DATA].rlim_cur;
if (rlim >= RLIM_INFINITY)
rlim = ~0;
if (brk - mm->end_code > rlim) {
ret = -ENOMEM;
goto out;
}
/*
* Check against existing mmap mappings.
*/
if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE)) {
return -ENOMEM;
goto out;
}
/*
* Check if we have enough memory..
*/
if (!vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT)) {
return -ENOMEM;
goto out;
}
/*
* Ok, looks good - let it rip.
*/
mm->brk = brk;
do_mmap(NULL, oldbrk, newbrk-oldbrk,
PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_FIXED|MAP_PRIVATE, 0);
ret = 0;
out:
unlock_kernel();
return ret;
}
asmlinkage int irix_getpid(struct pt_regs *regs)
{
regs->regs[3] = current->p_opptr->pid;
return current->pid;
}
asmlinkage int irix_getuid(struct pt_regs *regs)
{
regs->regs[3] = current->euid;
return current->uid;
}
asmlinkage int irix_getgid(struct pt_regs *regs)
{
regs->regs[3] = current->egid;
return current->gid;
}
asmlinkage int irix_stime(int value)
{
int ret;
lock_kernel();
if(!suser()) {
ret = -EPERM;
goto out;
}
cli();
xtime.tv_sec = value;
xtime.tv_usec = 0;
time_state = TIME_ERROR;
time_maxerror = MAXPHASE;
time_esterror = MAXPHASE;
sti();
ret = 0;
out:
unlock_kernel();
return ret;
}
extern int _setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
static inline void jiffiestotv(unsigned long jiffies, struct timeval *value)
{
value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
value->tv_sec = jiffies / HZ;
return;
}
static inline void getitimer_real(struct itimerval *value)
{
register unsigned long val, interval;
interval = current->it_real_incr;
val = 0;
if (del_timer(¤t->real_timer)) {
unsigned long now = jiffies;
val = current->real_timer.expires;
add_timer(¤t->real_timer);
/* look out for negative/zero itimer.. */
if (val <= now)
val = now+1;
val -= now;
}
jiffiestotv(val, &value->it_value);
jiffiestotv(interval, &value->it_interval);
}
asmlinkage unsigned int irix_alarm(unsigned int seconds)
{
struct itimerval it_new, it_old;
unsigned int oldalarm;
lock_kernel();
if(!seconds) {
getitimer_real(&it_old);
del_timer(¤t->real_timer);
} else {
it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
it_new.it_value.tv_sec = seconds;
it_new.it_value.tv_usec = 0;
_setitimer(ITIMER_REAL, &it_new, &it_old);
}
oldalarm = it_old.it_value.tv_sec;
/* ehhh.. We can't return 0 if we have an alarm pending.. */
/* And we'd better return too much than too little anyway */
if (it_old.it_value.tv_usec)
oldalarm++;
unlock_kernel();
return oldalarm;
}
asmlinkage int irix_pause(void)
{
lock_kernel();
current->state = TASK_INTERRUPTIBLE;
schedule();
unlock_kernel();
return -EINTR;
}
extern asmlinkage int sys_mount(char * dev_name, char * dir_name, char * type,
unsigned long new_flags, void * data);
/* XXX need more than this... */
asmlinkage int irix_mount(char *dev_name, char *dir_name, unsigned long flags,
char *type, void *data, int datalen)
{
int ret;
lock_kernel();
printk("[%s:%d] irix_mount(%p,%p,%08lx,%p,%p,%d)\n",
current->comm, current->pid,
dev_name, dir_name, flags, type, data, datalen);
ret = sys_mount(dev_name, dir_name, type, flags, data);
unlock_kernel();
return ret;
}
struct irix_statfs {
short f_type;
long f_bsize, f_frsize, f_blocks, f_bfree, f_files, f_ffree;
char f_fname[6], f_fpack[6];
};
asmlinkage int irix_statfs(const char *path, struct irix_statfs *buf,
int len, int fs_type)
{
struct dentry *dentry;
struct inode *inode;
struct statfs kbuf;
int error, old_fs, i;
/* We don't support this feature yet. */
if(fs_type) {
error = -EINVAL;
goto out;
}
error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
if (error)
goto out;
dentry = namei(path);
error = PTR_ERR(dentry);
if (IS_ERR(dentry))
goto out;
inode = dentry->d_inode;
old_fs = get_fs(); set_fs(get_ds());
error = inode->i_sb->s_op->statfs(inode->i_sb, &kbuf,
sizeof(struct statfs));
set_fs(old_fs);
if (error)
goto dput_and_out;
__put_user(kbuf.f_type, &buf->f_type);
__put_user(kbuf.f_bsize, &buf->f_bsize);
__put_user(kbuf.f_frsize, &buf->f_frsize);
__put_user(kbuf.f_blocks, &buf->f_blocks);
__put_user(kbuf.f_bfree, &buf->f_bfree);
__put_user(kbuf.f_files, &buf->f_files);
__put_user(kbuf.f_ffree, &buf->f_ffree);
for(i = 0; i < 6; i++) {
__put_user(0, &buf->f_fname[i]);
__put_user(0, &buf->f_fpack[i]);
}
error = 0;
dput_and_out:
dput(dentry);
out:
unlock_kernel();
return error;
}
asmlinkage int irix_fstatfs(unsigned int fd, struct irix_statfs *buf)
{
struct dentry *dentry;
struct inode *inode;
struct statfs kbuf;
struct file *file;
int error, old_fs, i;
lock_kernel();
error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
if (error)
goto out;
if (fd >= NR_OPEN || !(file = current->files->fd[fd])) {
error = -EBADF;
goto out;
}
if (!(dentry = file->f_dentry)) {
error = -ENOENT;
goto out;
}
if (!(inode = dentry->d_inode)) {
error = -ENOENT;
goto out;
}
if (!inode->i_sb) {
error = -ENODEV;
goto out;
}
if (!inode->i_sb->s_op->statfs) {
error = -ENOSYS;
goto out;
}
old_fs = get_fs(); set_fs(get_ds());
error = inode->i_sb->s_op->statfs(inode->i_sb, &kbuf,
sizeof(struct statfs));
set_fs(old_fs);
if (error)
goto out;
__put_user(kbuf.f_type, &buf->f_type);
__put_user(kbuf.f_bsize, &buf->f_bsize);
__put_user(kbuf.f_frsize, &buf->f_frsize);
__put_user(kbuf.f_blocks, &buf->f_blocks);
__put_user(kbuf.f_bfree, &buf->f_bfree);
__put_user(kbuf.f_files, &buf->f_files);
__put_user(kbuf.f_ffree, &buf->f_ffree);
for(i = 0; i < 6; i++) {
__put_user(0, &buf->f_fname[i]);
__put_user(0, &buf->f_fpack[i]);
}
error = 0;
dput_and_out:
dput(dentry);
out:
unlock_kernel();
return error;
}
extern asmlinkage int sys_setpgid(pid_t pid, pid_t pgid);
extern asmlinkage int sys_setsid(void);
asmlinkage int irix_setpgrp(int flags)
{
int error;
lock_kernel();
#ifdef DEBUG_PROCGRPS
printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
#endif
if(!flags)
error = current->pgrp;
else
error = sys_setsid();
#ifdef DEBUG_PROCGRPS
printk("returning %d\n", current->pgrp);
#endif
unlock_kernel();
return error;
}
asmlinkage int irix_times(struct tms * tbuf)
{
int error;
lock_kernel();
if (tbuf) {
error = verify_area(VERIFY_WRITE,tbuf,sizeof *tbuf);
if (error)
goto out;
__put_user(current->times.tms_utime,&tbuf->tms_utime);
__put_user(current->times.tms_stime,&tbuf->tms_stime);
__put_user(current->times.tms_cutime,&tbuf->tms_cutime);
__put_user(current->times.tms_cstime,&tbuf->tms_cstime);
}
error = 0;
out:
unlock_kernel();
return error;
}
asmlinkage int irix_exec(struct pt_regs *regs)
{
int error, base = 0;
char *filename;
lock_kernel();
if(regs->regs[2] == 1000)
base = 1;
filename = getname((char *) (long)regs->regs[base + 4]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename, (char **) (long)regs->regs[base + 5],
(char **) 0, regs);
putname(filename);
out:
unlock_kernel();
return error;
}
asmlinkage int irix_exece(struct pt_regs *regs)
{
int error, base = 0;
char *filename;
lock_kernel();
if(regs->regs[2] == 1000)
base = 1;
filename = getname((char *) (long)regs->regs[base + 4]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename, (char **) (long)regs->regs[base + 5],
(char **) (long)regs->regs[base + 6], regs);
putname(filename);
out:
unlock_kernel();
return error;
}
asmlinkage unsigned long irix_gethostid(void)
{
lock_kernel();
printk("[%s:%d]: irix_gethostid() called...\n",
current->comm, current->pid);
unlock_kernel();
return -EINVAL;
}
asmlinkage unsigned long irix_sethostid(unsigned long val)
{
lock_kernel();
printk("[%s:%d]: irix_sethostid(%08lx) called...\n",
current->comm, current->pid, val);
unlock_kernel();
return -EINVAL;
}
extern asmlinkage int sys_socket(int family, int type, int protocol);
asmlinkage int irix_socket(int family, int type, int protocol)
{
switch(type) {
case 1:
type = SOCK_DGRAM;
break;
case 2:
type = SOCK_STREAM;
break;
case 3:
type = 9; /* Invalid... */
break;
case 4:
type = SOCK_RAW;
break;
case 5:
type = SOCK_RDM;
break;
case 6:
type = SOCK_SEQPACKET;
break;
default:
break;
}
return sys_socket(family, type, protocol);
}
asmlinkage int irix_getdomainname(char *name, int len)
{
int error;
lock_kernel();
if(len > (__NEW_UTS_LEN - 1))
len = __NEW_UTS_LEN - 1;
error = verify_area(VERIFY_WRITE, name, len);
if(error)
goto out;
if(copy_to_user(name, system_utsname.domainname, len)) {
error = -EFAULT;
goto out;
}
error = 0;
out:
unlock_kernel();
return error;
}
asmlinkage unsigned long irix_getpagesize(void)
{
return PAGE_SIZE;
}
asmlinkage int irix_msgsys(int opcode, unsigned long arg0, unsigned long arg1,
unsigned long arg2, unsigned long arg3,
unsigned long arg4)
{
switch(opcode) {
case 0:
return sys_msgget((key_t) arg0, (int) arg1);
case 1:
return sys_msgctl((int) arg0, (int) arg1, (struct msqid_ds *)arg2);
case 2:
return sys_msgrcv((int) arg0, (struct msgbuf *) arg1,
(size_t) arg2, (long) arg3, (int) arg4);
case 3:
return sys_msgsnd((int) arg0, (struct msgbuf *) arg1,
(size_t) arg2, (int) arg3);
default:
return -EINVAL;
}
}
asmlinkage int irix_shmsys(int opcode, unsigned long arg0, unsigned long arg1,
unsigned long arg2, unsigned long arg3)
{
switch(opcode) {
case 0:
return sys_shmat((int) arg0, (char *)arg1, (int) arg2,
(unsigned long *) arg3);
case 1:
return sys_shmctl((int)arg0, (int)arg1, (struct shmid_ds *)arg2);
case 2:
return sys_shmdt((char *)arg0);
case 3:
return sys_shmget((key_t) arg0, (int) arg1, (int) arg2);
default:
return -EINVAL;
}
}
asmlinkage int irix_semsys(int opcode, unsigned long arg0, unsigned long arg1,
unsigned long arg2, int arg3)
{
switch(opcode) {
case 0:
return sys_semctl((int) arg0, (int) arg1, (int) arg2,
(union semun) arg3);
case 1:
return sys_semget((key_t) arg0, (int) arg1, (int) arg2);
case 2:
return sys_semop((int) arg0, (struct sembuf *)arg1,
(unsigned int) arg2);
default:
return -EINVAL;
}
}
extern asmlinkage int sys_llseek(unsigned int fd, unsigned long offset_high,
unsigned long offset_low, loff_t * result,
unsigned int origin);
asmlinkage int irix_lseek64(int fd, int _unused, int offhi, int offlow, int base)
{
loff_t junk;
int old_fs, error;
lock_kernel();
old_fs = get_fs(); set_fs(get_ds());
error = sys_llseek(fd, offhi, offlow, &junk, base);
set_fs(old_fs);
if(error)
goto out;
error = (int) junk;
out:
unlock_kernel();
return error;
}
asmlinkage int irix_sginap(int ticks)
{
lock_kernel();
if(ticks) {
current->timeout = ticks + jiffies;
current->state = TASK_INTERRUPTIBLE;
}
schedule();
unlock_kernel();
return 0;
}
asmlinkage int irix_sgikopt(char *istring, char *ostring, int len)
{
return -EINVAL;
}
asmlinkage int irix_gettimeofday(struct timeval *tv)
{
int retval;
lock_kernel();
retval = copy_to_user(tv, &xtime, sizeof(*tv)) ? -EFAULT : 0;
unlock_kernel();
return retval;
}
asmlinkage unsigned long irix_mmap32(unsigned long addr, size_t len, int prot,
int flags, int fd, off_t offset)
{
struct file *file = NULL;
unsigned long retval;
lock_kernel();
if(!(flags & MAP_ANONYMOUS)) {
if(fd >= NR_OPEN || !(file = current->files->fd[fd])) {
retval = -EBADF;
goto out;
}
}
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
retval = do_mmap(file, addr, len, prot, flags, offset);
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_madvise(unsigned long addr, int len, int behavior)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_madvise(%08lx,%d,%d)\n",
current->comm, current->pid, addr, len, behavior);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_pagelock(char *addr, int len, int op)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_pagelock(%p,%d,%d)\n",
current->comm, current->pid, addr, len, op);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_quotactl(struct pt_regs *regs)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_quotactl()\n",
current->comm, current->pid);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_BSDsetpgrp(int pid, int pgrp)
{
int error;
lock_kernel();
#ifdef DEBUG_PROCGRPS
printk("[%s:%d] BSDsetpgrp(%d, %d) ", current->comm, current->pid,
pid, pgrp);
#endif
if(!pid)
pid = current->pid;
/* Wheee, weird sysv thing... */
if((pgrp == 0) && (pid == current->pid))
error = sys_setsid();
else
error = sys_setpgid(pid, pgrp);
#ifdef DEBUG_PROCGRPS
printk("error = %d\n", error);
#endif
unlock_kernel();
return error;
}
asmlinkage int irix_systeminfo(int cmd, char *buf, int cnt)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_systeminfo(%d,%p,%d)\n",
current->comm, current->pid, cmd, buf, cnt);
unlock_kernel();
return -EINVAL;
}
struct iuname {
char sysname[257], nodename[257], release[257];
char version[257], machine[257];
char m_type[257], base_rel[257];
char _unused0[257], _unused1[257], _unused2[257];
char _unused3[257], _unused4[257], _unused5[257];
};
asmlinkage int irix_uname(struct iuname *buf)
{
int retval;
lock_kernel();
if(copy_to_user(system_utsname.sysname, buf->sysname, 65)
|| copy_to_user(system_utsname.nodename, buf->nodename, 65)
|| copy_to_user(system_utsname.release, buf->release, 65)
|| copy_to_user(system_utsname.version, buf->version, 65)
|| copy_to_user(system_utsname.machine, buf->machine, 65)) {
retval = -EFAULT;
goto out;
}
retval = 1;
out:
unlock_kernel();
return retval;
}
#undef DEBUG_XSTAT
static inline int irix_xstat32_xlate(struct stat *kb, struct stat *ubuf)
{
struct xstat32 {
u32 st_dev, st_pad1[3], st_ino, st_mode, st_nlink, st_uid, st_gid;
u32 st_rdev, st_pad2[2], st_size, st_pad3;
u32 st_atime0, st_atime1;
u32 st_mtime0, st_mtime1;
u32 st_ctime0, st_ctime1;
u32 st_blksize, st_blocks;
char st_fstype[16];
u32 st_pad4[8];
} *ub = (struct xstat32 *) ubuf;
return copy_to_user(ub, kb, sizeof(*ub)) ? -EFAULT : 0;
}
static inline void irix_xstat64_xlate(struct stat *sb)
{
struct xstat64 {
u32 st_dev; s32 st_pad1[3];
unsigned long long st_ino;
u32 st_mode;
u32 st_nlink; s32 st_uid; s32 st_gid; u32 st_rdev;
s32 st_pad2[2];
long long st_size;
s32 st_pad3;
struct { s32 tv_sec, tv_nsec; } st_atime, st_mtime, st_ctime;
s32 st_blksize;
long long st_blocks;
char st_fstype[16];
s32 st_pad4[8];
} ks;
ks.st_dev = (u32) sb->st_dev;
ks.st_pad1[0] = ks.st_pad1[1] = ks.st_pad1[2] = 0;
ks.st_ino = (unsigned long long) sb->st_ino;
ks.st_mode = (u32) sb->st_mode;
ks.st_nlink = (u32) sb->st_nlink;
ks.st_uid = (s32) sb->st_uid;
ks.st_gid = (s32) sb->st_gid;
ks.st_rdev = (u32) sb->st_rdev;
ks.st_pad2[0] = ks.st_pad2[1] = 0;
ks.st_size = (long long) sb->st_size;
ks.st_pad3 = 0;
/* XXX hackety hack... */
ks.st_atime.tv_sec = (s32) sb->st_atime; ks.st_atime.tv_nsec = 0;
ks.st_mtime.tv_sec = (s32) sb->st_atime; ks.st_mtime.tv_nsec = 0;
ks.st_ctime.tv_sec = (s32) sb->st_atime; ks.st_ctime.tv_nsec = 0;
ks.st_blksize = (s32) sb->st_blksize;
ks.st_blocks = (long long) sb->st_blocks;
memcpy(&ks.st_fstype[0], &sb->st_fstype[0], 16);
ks.st_pad4[0] = ks.st_pad4[1] = ks.st_pad4[2] = ks.st_pad4[3] =
ks.st_pad4[4] = ks.st_pad4[5] = ks.st_pad4[6] = ks.st_pad4[7] = 0;
/* Now write it all back. */
copy_to_user(sb, &ks, sizeof(struct xstat64));
}
extern asmlinkage int sys_newstat(char * filename, struct stat * statbuf);
asmlinkage int irix_xstat(int version, char *filename, struct stat *statbuf)
{
int retval;
lock_kernel();
#ifdef DEBUG_XSTAT
printk("[%s:%d] Wheee.. irix_xstat(%d,%s,%p) ",
current->comm, current->pid, version, filename, statbuf);
#endif
switch(version) {
case 2: {
struct stat kb;
int old_fs;
old_fs = get_fs(); set_fs(get_ds());
retval = sys_newstat(filename, &kb);
set_fs(old_fs);
#ifdef DEBUG_XSTAT
printk("retval[%d]\n", retval);
#endif
if(retval)
goto out;
retval = irix_xstat32_xlate(&kb, statbuf);
goto out;
}
case 3: {
retval = sys_newstat(filename, statbuf);
#ifdef DEBUG_XSTAT
printk("retval[%d]\n", retval);
#endif
if(retval)
goto out;
irix_xstat64_xlate(statbuf);
retval = 0;
break;
}
default:
retval = -EINVAL;
break;
}
out:
unlock_kernel();
return retval;
}
extern asmlinkage int sys_newlstat(char * filename, struct stat * statbuf);
asmlinkage int irix_lxstat(int version, char *filename, struct stat *statbuf)
{
int error;
lock_kernel();
#ifdef DEBUG_XSTAT
printk("[%s:%d] Wheee.. irix_lxstat(%d,%s,%p) ",
current->comm, current->pid, version, filename, statbuf);
#endif
switch(version) {
case 2: {
struct stat kb;
int old_fs;
old_fs = get_fs(); set_fs(get_ds());
error = sys_newlstat(filename, &kb);
set_fs(old_fs);
#ifdef DEBUG_XSTAT
printk("error[%d]\n", error);
#endif
if(error)
goto out;
error = irix_xstat32_xlate(&kb, statbuf);
goto out;
}
case 3: {
error = sys_newlstat(filename, statbuf);
#ifdef DEBUG_XSTAT
printk("error[%d]\n", error);
#endif
if(error)
goto out;
irix_xstat64_xlate(statbuf);
error = 0;
goto out;
}
default:
error = -EINVAL;
goto out;
}
out:
unlock_kernel();
return error;
}
extern asmlinkage int sys_newfstat(unsigned int fd, struct stat * statbuf);
asmlinkage int irix_fxstat(int version, int fd, struct stat *statbuf)
{
int error;
lock_kernel();
#ifdef DEBUG_XSTAT
printk("[%s:%d] Wheee.. irix_fxstat(%d,%d,%p) ",
current->comm, current->pid, version, fd, statbuf);
#endif
switch(version) {
case 2: {
struct stat kb;
int old_fs;
old_fs = get_fs(); set_fs(get_ds());
error = sys_newfstat(fd, &kb);
set_fs(old_fs);
#ifdef DEBUG_XSTAT
printk("error[%d]\n", error);
#endif
if(error)
goto out;
error = irix_xstat32_xlate(&kb, statbuf);
goto out;
}
case 3: {
error = sys_newfstat(fd, statbuf);
#ifdef DEBUG_XSTAT
printk("error[%d]\n", error);
#endif
if(error)
goto out;
irix_xstat64_xlate(statbuf);
error = 0;
goto out;
}
default:
error = -EINVAL;
goto out;
}
out:
unlock_kernel();
return error;
}
extern asmlinkage int sys_mknod(const char * filename, int mode, dev_t dev);
asmlinkage int irix_xmknod(int ver, char *filename, int mode, dev_t dev)
{
int retval;
lock_kernel();
printk("[%s:%d] Wheee.. irix_xmknod(%d,%s,%x,%x)\n",
current->comm, current->pid, ver, filename, mode, (int) dev);
switch(ver) {
case 2:
retval = sys_mknod(filename, mode, dev);
goto out;
default:
retval = -EINVAL;
goto out;
};
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_swapctl(int cmd, char *arg)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_swapctl(%d,%p)\n",
current->comm, current->pid, cmd, arg);
unlock_kernel();
return -EINVAL;
}
struct irix_statvfs {
u32 f_bsize; u32 f_frsize; u32 f_blocks;
u32 f_bfree; u32 f_bavail; u32 f_files; u32 f_ffree; u32 f_favail;
u32 f_fsid; char f_basetype[16];
u32 f_flag; u32 f_namemax;
char f_fstr[32]; u32 f_filler[16];
};
asmlinkage int irix_statvfs(char *fname, struct irix_statvfs *buf)
{
struct dentry *dentry;
struct inode *inode;
struct statfs kbuf;
int error, old_fs, i;
lock_kernel();
printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
current->comm, current->pid, fname, buf);
error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
if(error)
goto out;
dentry = namei(fname);
error = PTR_ERR(dentry);
if(!IS_ERR(dentry))
goto out;
inode = dentry->d_inode;
error = -ENOSYS;
if(!inode->i_sb->s_op->statfs)
goto dput_and_out;
old_fs = get_fs(); set_fs(get_ds());
error = inode->i_sb->s_op->statfs(inode->i_sb, &kbuf,
sizeof(struct statfs));
set_fs(old_fs);
if (error)
goto dput_and_out;
__put_user(kbuf.f_bsize, &buf->f_bsize);
__put_user(kbuf.f_frsize, &buf->f_frsize);
__put_user(kbuf.f_blocks, &buf->f_blocks);
__put_user(kbuf.f_bfree, &buf->f_bfree);
__put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
__put_user(kbuf.f_files, &buf->f_files);
__put_user(kbuf.f_ffree, &buf->f_ffree);
__put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
#ifdef __MIPSEB__
__put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
#else
__put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
#endif
for(i = 0; i < 16; i++)
__put_user(0, &buf->f_basetype[i]);
__put_user(0, &buf->f_flag);
__put_user(kbuf.f_namelen, &buf->f_namemax);
for(i = 0; i < 32; i++)
__put_user(0, &buf->f_fstr[i]);
error = 0;
dput_and_out:
dput(dentry);
out:
unlock_kernel();
return error;
}
asmlinkage int irix_fstatvfs(int fd, struct irix_statvfs *buf)
{
struct dentry *dentry;
struct inode *inode;
struct statfs kbuf;
struct file *file;
int error, old_fs, i;
lock_kernel();
printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
current->comm, current->pid, fd, buf);
error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
if (error)
goto out;
if (fd >= NR_OPEN || !(file = current->files->fd[fd])) {
error = -EBADF;
goto out;
}
if (!(dentry = file->f_dentry)) {
error = -ENOENT;
goto out;
}
if (!(inode = dentry->d_inode)) {
error = -ENOENT;
goto out;
}
if (!inode->i_sb->s_op->statfs) {
error = -ENOSYS;
goto out;
}
old_fs = get_fs(); set_fs(get_ds());
error = inode->i_sb->s_op->statfs(inode->i_sb, &kbuf,
sizeof(struct statfs));
set_fs(old_fs);
if (error)
goto out;
__put_user(kbuf.f_bsize, &buf->f_bsize);
__put_user(kbuf.f_frsize, &buf->f_frsize);
__put_user(kbuf.f_blocks, &buf->f_blocks);
__put_user(kbuf.f_bfree, &buf->f_bfree);
__put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
__put_user(kbuf.f_files, &buf->f_files);
__put_user(kbuf.f_ffree, &buf->f_ffree);
__put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
#ifdef __MIPSEB__
__put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
#else
__put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
#endif
for(i = 0; i < 16; i++)
__put_user(0, &buf->f_basetype[i]);
__put_user(0, &buf->f_flag);
__put_user(kbuf.f_namelen, &buf->f_namemax);
for(i = 0; i < 32; i++)
__put_user(0, &buf->f_fstr[i]);
error = 0;
dput_and_out:
dput(dentry);
out:
unlock_kernel();
return error;
}
#define NOFOLLOW_LINKS 0
#define FOLLOW_LINKS 1
static inline int chown_common(uid_t user, gid_t group, struct dentry *dentry)
{
struct inode * inode;
int error;
struct iattr newattrs;
error = PTR_ERR(dentry);
if (IS_ERR(dentry))
goto out;
inode = dentry->d_inode;
error = -EROFS;
if (IS_RDONLY(inode))
goto dput_and_out;
error = -EPERM;
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
goto dput_and_out;
if (user == (uid_t) -1)
user = inode->i_uid;
if (group == (gid_t) -1)
group = inode->i_gid;
newattrs.ia_mode = inode->i_mode;
newattrs.ia_uid = user;
newattrs.ia_gid = group;
newattrs.ia_valid = ATTR_UID | ATTR_GID | ATTR_CTIME;
/*
* If the owner has been changed, remove the setuid bit
*/
if (inode->i_mode & S_ISUID) {
newattrs.ia_mode &= ~S_ISUID;
newattrs.ia_valid |= ATTR_MODE;
}
/*
* If the group has been changed, remove the setgid bit
*
* Don't remove the setgid bit if no group execute bit.
* This is a file marked for mandatory locking.
*/
if (((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) {
newattrs.ia_mode &= ~S_ISGID;
newattrs.ia_valid |= ATTR_MODE;
}
if (inode->i_sb->dq_op) {
inode->i_sb->dq_op->initialize(inode, -1);
error = -EDQUOT;
if (inode->i_sb->dq_op->transfer(inode, &newattrs, 0))
goto dput_and_out;
error = notify_change(inode, &newattrs);
if (error)
inode->i_sb->dq_op->transfer(inode, &newattrs, 1);
} else
error = notify_change(inode, &newattrs);
dput_and_out:
dput(dentry);
out:
return error;
}
asmlinkage int irix_chown(const char *filename, int uid, int gid)
{
int retval;
struct dentry *dentry;
lock_kernel();
/* Do follow any and all links... */
dentry = namei(filename);
retval = chown_common(uid, gid, dentry);
unlock_kernel();
return retval;
}
asmlinkage int irix_lchown(const char *filename, int uid, int gid)
{
int retval;
struct dentry *dentry;
lock_kernel();
/* Do _not_ follow any links... */
dentry = lnamei(filename);
retval = chown_common(uid, gid, dentry);
unlock_kernel();
return retval;
}
asmlinkage int irix_priocntl(struct pt_regs *regs)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_priocntl()\n",
current->comm, current->pid);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_sigqueue(int pid, int sig, int code, int val)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_sigqueue(%d,%d,%d,%d)\n",
current->comm, current->pid, pid, sig, code, val);
unlock_kernel();
return -EINVAL;
}
extern asmlinkage int sys_truncate(const char * path, unsigned long length);
extern asmlinkage int sys_ftruncate(unsigned int fd, unsigned long length);
asmlinkage int irix_truncate64(char *name, int pad, int size1, int size2)
{
int retval;
lock_kernel();
if(size1) {
retval = -EINVAL;
goto out;
}
retval = sys_truncate(name, size2);
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_ftruncate64(int fd, int pad, int size1, int size2)
{
int retval;
lock_kernel();
if(size1) {
retval = -EINVAL;
goto out;
}
retval = sys_ftruncate(fd, size2);
out:
unlock_kernel();
return retval;
}
extern asmlinkage unsigned long sys_mmap(unsigned long addr, size_t len, int prot,
int flags, int fd, off_t offset);
asmlinkage int irix_mmap64(struct pt_regs *regs)
{
unsigned long addr, *sp;
int len, prot, flags, fd, off1, off2, base = 0;
int error;
lock_kernel();
if(regs->regs[2] == 1000)
base = 1;
sp = (unsigned long *) (regs->regs[29] + 16);
addr = regs->regs[base + 4];
len = regs->regs[base + 5];
prot = regs->regs[base + 6];
if(!base) {
flags = regs->regs[base + 7];
error = verify_area(VERIFY_READ, sp, (4 * sizeof(unsigned long)));
if(error)
goto out;
fd = sp[0];
__get_user(off1, &sp[1]);
__get_user(off2, &sp[2]);
} else {
error = verify_area(VERIFY_READ, sp, (5 * sizeof(unsigned long)));
if(error)
goto out;
__get_user(flags, &sp[0]);
__get_user(fd, &sp[1]);
__get_user(off1, &sp[2]);
__get_user(off2, &sp[3]);
}
if(off1) {
error = -EINVAL;
goto out;
}
error = sys_mmap(addr, (size_t) len, prot, flags, fd, off2);
out:
unlock_kernel();
return error;
}
asmlinkage int irix_dmi(struct pt_regs *regs)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_dmi()\n",
current->comm, current->pid);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_pread(int fd, char *buf, int cnt, int off64,
int off1, int off2)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_pread(%d,%p,%d,%d,%d,%d)\n",
current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_pwrite(int fd, char *buf, int cnt, int off64,
int off1, int off2)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_pwrite(%d,%p,%d,%d,%d,%d)\n",
current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
unlock_kernel();
return -EINVAL;
}
asmlinkage int irix_sgifastpath(int cmd, unsigned long arg0, unsigned long arg1,
unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_fastpath(%d,%08lx,%08lx,%08lx,%08lx,"
"%08lx,%08lx)\n",
current->comm, current->pid, cmd, arg0, arg1, arg2,
arg3, arg4, arg5);
unlock_kernel();
return -EINVAL;
}
struct irix_statvfs64 {
u32 f_bsize; u32 f_frsize;
u64 f_blocks; u64 f_bfree; u64 f_bavail;
u64 f_files; u64 f_ffree; u64 f_favail;
u32 f_fsid;
char f_basetype[16];
u32 f_flag; u32 f_namemax;
char f_fstr[32];
u32 f_filler[16];
};
asmlinkage int irix_statvfs64(char *fname, struct irix_statvfs64 *buf)
{
struct dentry *dentry;
struct inode *inode;
struct statfs kbuf;
int error, old_fs, i;
printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
current->comm, current->pid, fname, buf);
error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
if(error)
goto out;
dentry = namei(fname);
error = PTR_ERR(dentry);
if(IS_ERR(dentry))
goto out;
error = -ENOSYS;
inode = dentry->d_inode;
if(!inode->i_sb->s_op->statfs)
goto dput_and_out;
old_fs = get_fs(); set_fs(get_ds());
error = inode->i_sb->s_op->statfs(inode->i_sb, &kbuf,
sizeof(struct statfs));
set_fs(old_fs);
if (error)
goto dput_and_out;
__put_user(kbuf.f_bsize, &buf->f_bsize);
__put_user(kbuf.f_frsize, &buf->f_frsize);
__put_user(kbuf.f_blocks, &buf->f_blocks);
__put_user(kbuf.f_bfree, &buf->f_bfree);
__put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
__put_user(kbuf.f_files, &buf->f_files);
__put_user(kbuf.f_ffree, &buf->f_ffree);
__put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
#ifdef __MIPSEB__
__put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
#else
__put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
#endif
for(i = 0; i < 16; i++)
__put_user(0, &buf->f_basetype[i]);
__put_user(0, &buf->f_flag);
__put_user(kbuf.f_namelen, &buf->f_namemax);
for(i = 0; i < 32; i++)
__put_user(0, &buf->f_fstr[i]);
error = 0;
dput_and_out:
dput(dentry);
out:
unlock_kernel();
return error;
}
asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs *buf)
{
struct dentry *dentry;
struct inode *inode;
struct statfs kbuf;
struct file *file;
int error, old_fs, i;
lock_kernel();
printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
current->comm, current->pid, fd, buf);
error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
if (error)
goto out;
if (fd >= NR_OPEN || !(file = current->files->fd[fd])) {
error = -EBADF;
goto out;
}
if (!(dentry = file->f_dentry)) {
error = -ENOENT;
goto out;
}
if (!(inode = dentry->d_inode)) {
error = -ENOENT;
goto out;
}
if (!inode->i_sb->s_op->statfs) {
error = -ENOSYS;
goto out;
}
old_fs = get_fs(); set_fs(get_ds());
error = inode->i_sb->s_op->statfs(inode->i_sb, &kbuf,
sizeof(struct statfs));
set_fs(old_fs);
if (error)
goto out;
__put_user(kbuf.f_bsize, &buf->f_bsize);
__put_user(kbuf.f_frsize, &buf->f_frsize);
__put_user(kbuf.f_blocks, &buf->f_blocks);
__put_user(kbuf.f_bfree, &buf->f_bfree);
__put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
__put_user(kbuf.f_files, &buf->f_files);
__put_user(kbuf.f_ffree, &buf->f_ffree);
__put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
#ifdef __MIPSEB__
__put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
#else
__put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
#endif
for(i = 0; i < 16; i++)
__put_user(0, &buf->f_basetype[i]);
__put_user(0, &buf->f_flag);
__put_user(kbuf.f_namelen, &buf->f_namemax);
for(i = 0; i < 32; i++)
__put_user(0, &buf->f_fstr[i]);
error = 0;
dput_and_out:
dput(dentry);
out:
unlock_kernel();
return error;
}
asmlinkage int irix_getmountid(char *fname, unsigned long *midbuf)
{
int error;
lock_kernel();
printk("[%s:%d] irix_getmountid(%s, %p)\n",
current->comm, current->pid, fname, midbuf);
error = verify_area(VERIFY_WRITE, midbuf, (sizeof(unsigned long) * 4));
if(error)
goto out;
/*
* The idea with this system call is that when trying to determine
* 'pwd' and it's a toss-up for some reason, userland can use the
* fsid of the filesystem to try and make the right decision, but
* we don't have this so for now. XXX
*/
__put_user(0, &midbuf[0]);
__put_user(0, &midbuf[1]);
__put_user(0, &midbuf[2]);
__put_user(0, &midbuf[3]);
error = 0;
out:
unlock_kernel();
return error;
}
asmlinkage int irix_nsproc(unsigned long entry, unsigned long mask,
unsigned long arg, unsigned long sp, int slen)
{
lock_kernel();
printk("[%s:%d] Wheee.. irix_nsproc(%08lx,%08lx,%08lx,%08lx,%d)\n",
current->comm, current->pid, entry, mask, arg, sp, slen);
unlock_kernel();
return -EINVAL;
}
#undef DEBUG_GETDENTS
struct irix_dirent32 {
u32 d_ino;
u32 d_off;
unsigned short d_reclen;
char d_name[1];
};
struct irix_dirent32_callback {
struct irix_dirent32 *current_dir;
struct irix_dirent32 *previous;
int count;
int error;
};
#define NAME_OFFSET32(de) ((int) ((de)->d_name - (char *) (de)))
#define ROUND_UP32(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
static int irix_filldir32(void *__buf, const char *name, int namlen, off_t offset, ino_t ino)
{
struct irix_dirent32 *dirent;
struct irix_dirent32_callback *buf = (struct irix_dirent32_callback *)__buf;
unsigned short reclen = ROUND_UP32(NAME_OFFSET32(dirent) + namlen + 1);
int retval;
lock_kernel();
#ifdef DEBUG_GETDENTS
printk("\nirix_filldir32[reclen<%d>namlen<%d>count<%d>]",
reclen, namlen, buf->count);
#endif
buf->error = -EINVAL; /* only used if we fail.. */
if (reclen > buf->count) {
retval = -EINVAL;
goto out;
}
dirent = buf->previous;
if (dirent)
__put_user(offset, &dirent->d_off);
dirent = buf->current_dir;
buf->previous = dirent;
__put_user(ino, &dirent->d_ino);
__put_user(reclen, &dirent->d_reclen);
copy_to_user(dirent->d_name, name, namlen);
__put_user(0, &dirent->d_name[namlen]);
((char *) dirent) += reclen;
buf->current_dir = dirent;
buf->count -= reclen;
retval = 0;
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_ngetdents(unsigned int fd, void * dirent, unsigned int count, int *eob)
{
struct file *file;
struct dentry *dentry;
struct inode *inode;
struct irix_dirent32 *lastdirent;
struct irix_dirent32_callback buf;
int error;
lock_kernel();
#ifdef DEBUG_GETDENTS
printk("[%s:%d] ngetdents(%d, %p, %d, %p) ", current->comm,
current->pid, fd, dirent, count, eob);
#endif
error = -EBADF;
if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
goto out;
dentry = file->f_dentry;
if (!dentry)
goto out;
inode = dentry->d_inode;
if (!inode)
goto out;
error = -ENOTDIR;
if (!file->f_op || !file->f_op->readdir)
goto out;
error = -EFAULT;
if(!access_ok(VERIFY_WRITE, dirent, count) ||
!access_ok(VERIFY_WRITE, eob, sizeof(*eob)))
goto out;
__put_user(0, eob);
buf.current_dir = (struct irix_dirent32 *) dirent;
buf.previous = NULL;
buf.count = count;
buf.error = 0;
error = file->f_op->readdir(inode, file, &buf, irix_filldir32);
if (error < 0)
goto out;
lastdirent = buf.previous;
if (!lastdirent) {
error = buf.error;
goto out;
}
lastdirent->d_off = (u32) file->f_pos;
#ifdef DEBUG_GETDENTS
printk("eob=%d returning %d\n", *eob, count - buf.count);
#endif
error = count - buf.count;
out:
unlock_kernel();
return error;
}
struct irix_dirent64 {
u64 d_ino;
u64 d_off;
unsigned short d_reclen;
char d_name[1];
};
struct irix_dirent64_callback {
struct irix_dirent64 *curr;
struct irix_dirent64 *previous;
int count;
int error;
};
#define NAME_OFFSET64(de) ((int) ((de)->d_name - (char *) (de)))
#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
static int irix_filldir64(void * __buf, const char * name, int namlen,
off_t offset, ino_t ino)
{
struct irix_dirent64 *dirent;
struct irix_dirent64_callback * buf =
(struct irix_dirent64_callback *) __buf;
unsigned short reclen = ROUND_UP64(NAME_OFFSET64(dirent) + namlen + 1);
int retval;
lock_kernel();
buf->error = -EINVAL; /* only used if we fail.. */
if (reclen > buf->count) {
retval = -EINVAL;
goto out;
}
dirent = buf->previous;
if (dirent)
__put_user(offset, &dirent->d_off);
dirent = buf->curr;
buf->previous = dirent;
__put_user(ino, &dirent->d_ino);
__put_user(reclen, &dirent->d_reclen);
copy_to_user(dirent->d_name, name, namlen);
__put_user(0, &dirent->d_name[namlen]);
((char *) dirent) += reclen;
buf->curr = dirent;
buf->count -= reclen;
retval = 0;
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_getdents64(int fd, void *dirent, int cnt)
{
struct file *file;
struct dentry *dentry;
struct inode *inode;
struct irix_dirent64 *lastdirent;
struct irix_dirent64_callback buf;
int error;
lock_kernel();
#ifdef DEBUG_GETDENTS
printk("[%s:%d] getdents64(%d, %p, %d) ", current->comm,
current->pid, fd, dirent, cnt);
#endif
error = -EBADF;
if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
goto out;
dentry = file->f_dentry;
if (!dentry)
goto out;
inode = dentry->d_inode;
if (!inode)
goto out;
error = -ENOTDIR;
if (!file->f_op || !file->f_op->readdir)
goto out;
error = -EFAULT;
if(!access_ok(VERIFY_WRITE, dirent, cnt))
goto out;
error = -EINVAL;
if(cnt < (sizeof(struct irix_dirent64) + 255))
goto out;
buf.curr = (struct irix_dirent64 *) dirent;
buf.previous = NULL;
buf.count = cnt;
buf.error = 0;
error = file->f_op->readdir(inode, file, &buf, irix_filldir64);
if (error < 0)
goto out;
lastdirent = buf.previous;
if (!lastdirent) {
error = buf.error;
goto out;
}
lastdirent->d_off = (u64) file->f_pos;
#ifdef DEBUG_GETDENTS
printk("returning %d\n", cnt - buf.count);
#endif
error = cnt - buf.count;
out:
unlock_kernel();
return error;
}
asmlinkage int irix_ngetdents64(int fd, void *dirent, int cnt, int *eob)
{
struct file *file;
struct dentry *dentry;
struct inode *inode;
struct irix_dirent64 *lastdirent;
struct irix_dirent64_callback buf;
int error;
lock_kernel();
#ifdef DEBUG_GETDENTS
printk("[%s:%d] ngetdents64(%d, %p, %d) ", current->comm,
current->pid, fd, dirent, cnt);
#endif
error = -EBADF;
if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
goto out;
dentry = file->f_dentry;
if (!dentry)
goto out;
inode = dentry->d_inode;
if (!inode)
goto out;
error = -ENOTDIR;
if (!file->f_op || !file->f_op->readdir)
goto out;
error = -EFAULT;
if(!access_ok(VERIFY_WRITE, dirent, cnt) ||
!access_ok(VERIFY_WRITE, eob, sizeof(*eob)))
goto out;
error = -EINVAL;
if(cnt < (sizeof(struct irix_dirent64) + 255))
goto out;
*eob = 0;
buf.curr = (struct irix_dirent64 *) dirent;
buf.previous = NULL;
buf.count = cnt;
buf.error = 0;
error = file->f_op->readdir(inode, file, &buf, irix_filldir64);
if (error < 0)
goto out;
lastdirent = buf.previous;
if (!lastdirent) {
error = buf.error;
goto out;
}
lastdirent->d_off = (u64) file->f_pos;
#ifdef DEBUG_GETDENTS
printk("eob=%d returning %d\n", *eob, cnt - buf.count);
#endif
error = cnt - buf.count;
out:
unlock_kernel();
return error;
}
asmlinkage int irix_uadmin(unsigned long op, unsigned long func, unsigned long arg)
{
int retval;
lock_kernel();
switch(op) {
case 1:
/* Reboot */
printk("[%s:%d] irix_uadmin: Wants to reboot...\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 2:
/* Shutdown */
printk("[%s:%d] irix_uadmin: Wants to shutdown...\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 4:
/* Remount-root */
printk("[%s:%d] irix_uadmin: Wants to remount root...\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 8:
/* Kill all tasks. */
printk("[%s:%d] irix_uadmin: Wants to kill all tasks...\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 256:
/* Set magic mushrooms... */
printk("[%s:%d] irix_uadmin: Wants to set magic mushroom[%d]...\n",
current->comm, current->pid, (int) func);
retval = -EINVAL;
goto out;
default:
printk("[%s:%d] irix_uadmin: Unknown operation [%d]...\n",
current->comm, current->pid, (int) op);
retval = -EINVAL;
goto out;
};
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_utssys(char *inbuf, int arg, int type, char *outbuf)
{
int retval;
lock_kernel();
switch(type) {
case 0:
/* uname() */
retval = irix_uname((struct iuname *)inbuf);
goto out;
case 2:
/* ustat() */
printk("[%s:%d] irix_utssys: Wants to do ustat()\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 3:
/* fusers() */
printk("[%s:%d] irix_utssys: Wants to do fusers()\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
default:
printk("[%s:%d] irix_utssys: Wants to do unknown type[%d]\n",
current->comm, current->pid, (int) type);
retval = -EINVAL;
goto out;
}
out:
unlock_kernel();
return retval;
}
#undef DEBUG_FCNTL
extern asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd,
unsigned long arg);
asmlinkage int irix_fcntl(int fd, int cmd, int arg)
{
int retval;
lock_kernel();
#ifdef DEBUG_FCNTL
printk("[%s:%d] irix_fcntl(%d, %d, %d) ", current->comm,
current->pid, fd, cmd, arg);
#endif
retval = sys_fcntl(fd, cmd, arg);
#ifdef DEBUG_FCNTL
printk("%d\n", retval);
#endif
unlock_kernel();
return retval;
}
asmlinkage int irix_ulimit(int cmd, int arg)
{
int retval;
lock_kernel();
switch(cmd) {
case 1:
printk("[%s:%d] irix_ulimit: Wants to get file size limit.\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 2:
printk("[%s:%d] irix_ulimit: Wants to set file size limit.\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 3:
printk("[%s:%d] irix_ulimit: Wants to get brk limit.\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
case 4:
#if 0
printk("[%s:%d] irix_ulimit: Wants to get fd limit.\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
#endif
retval = current->rlim[RLIMIT_NOFILE].rlim_cur;
goto out;
case 5:
printk("[%s:%d] irix_ulimit: Wants to get txt offset.\n",
current->comm, current->pid);
retval = -EINVAL;
goto out;
default:
printk("[%s:%d] irix_ulimit: Unknown command [%d].\n",
current->comm, current->pid, cmd);
retval = -EINVAL;
goto out;
}
out:
unlock_kernel();
return retval;
}
asmlinkage int irix_unimp(struct pt_regs *regs)
{
lock_kernel();
printk("irix_unimp [%s:%d] v0=%d v1=%d a0=%08lx a1=%08lx a2=%08lx "
"a3=%08lx\n", current->comm, current->pid,
(int) regs->regs[2], (int) regs->regs[3],
regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);
unlock_kernel();
return -ENOSYS;
}
|