summaryrefslogtreecommitdiff
path: root/file.c
blob: 090d78d05d694db3e447a4be7f43e9f164290d73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
/*
 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *	$Id$
 */

#include "defs.h"

#include <dirent.h>
#ifdef linux
#define dirent kernel_dirent
#define dirent64 kernel_dirent64
#include <linux/types.h>
#include <linux/dirent.h>
#undef dirent
#else
#define kernel_dirent dirent
#endif

#ifdef linux
#  ifdef LINUXSPARC
struct stat {
	unsigned short	st_dev;
	unsigned int	st_ino;
	unsigned short	st_mode;
	short		st_nlink;
	unsigned short	st_uid;
	unsigned short	st_gid;
	unsigned short	st_rdev;
	unsigned int	st_size;
	int		st_atime;
	unsigned int	__unused1;
	int		st_mtime;
	unsigned int	__unused2;
	int		st_ctime;
	unsigned int	__unused3;
	int		st_blksize;
	int		st_blocks;
	unsigned int	__unused4[2];
};
#    define stat kernel_stat
#    include <asm/stat.h>
#    undef stat
#  else
#    undef dev_t
#    undef ino_t
#    undef mode_t
#    undef nlink_t
#    undef uid_t
#    undef gid_t
#    undef off_t
#    undef loff_t

#    define dev_t __kernel_dev_t
#    define ino_t __kernel_ino_t
#    define mode_t __kernel_mode_t
#    define nlink_t __kernel_nlink_t
#    define uid_t __kernel_uid_t
#    define gid_t __kernel_gid_t
#    define off_t __kernel_off_t
#    define loff_t __kernel_loff_t

#    include <asm/stat.h>

#    undef dev_t
#    undef ino_t
#    undef mode_t
#    undef nlink_t
#    undef uid_t
#    undef gid_t
#    undef off_t
#    undef loff_t

#    define dev_t dev_t
#    define ino_t ino_t
#    define mode_t mode_t
#    define nlink_t nlink_t
#    define uid_t uid_t
#    define gid_t gid_t
#    define off_t off_t
#    define loff_t loff_t
#  endif
#  define stat libc_stat
#  define stat64 libc_stat64
#  include <sys/stat.h>
#  undef stat
#  undef stat64
#else
#  include <sys/stat.h>
#endif

#include <fcntl.h>

#ifdef SVR4
#  include <sys/cred.h>
#endif /* SVR4 */

#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif

#ifdef FREEBSD
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#endif

#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
#endif

#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif

#ifdef HAVE_SYS_ASYNCH_H
#include <sys/asynch.h>
#endif

#ifdef SUNOS4
#include <ustat.h>
#endif

/*
 * This is a really dirty trick but it should always work.  Traditional
 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
 * adding 1.  Just remember to add 1 to any arg decoded with openmodes.
 */
struct xlat openmodes[] = {
	{ O_RDWR+1,	"O_RDWR"	},
	{ O_RDONLY+1,	"O_RDONLY"	},
	{ O_WRONLY+1,	"O_WRONLY"	},
	{ O_NONBLOCK,	"O_NONBLOCK"	},
	{ O_APPEND,	"O_APPEND"	},
	{ O_CREAT,	"O_CREAT"	},
	{ O_TRUNC,	"O_TRUNC"	},
	{ O_EXCL,	"O_EXCL"	},
	{ O_NOCTTY,	"O_NOCTTY"	},
#ifdef O_SYNC
	{ O_SYNC,	"O_SYNC"	},
#endif
#ifdef O_ASYNC
	{ O_ASYNC,	"O_ASYNC"	},
#endif
#ifdef O_DSYNC
	{ O_DSYNC,	"O_DSYNC"	},
#endif
#ifdef O_RSYNC
	{ O_RSYNC,	"O_RSYNC"	},
#endif
#ifdef O_NDELAY
	{ O_NDELAY,	"O_NDELAY"	},
#endif
#ifdef O_PRIV
	{ O_PRIV,	"O_PRIV"	},
#endif
#ifdef O_DIRECT
	{ O_DIRECT,	"O_DIRECT"	},
#endif
#ifdef O_LARGEFILE
	{ O_LARGEFILE,	"O_LARGEFILE"   },
#endif
#ifdef O_DIRECTORY
	{ O_DIRECTORY,	"O_DIRECTORY"   },
#endif
#ifdef O_NOFOLLOW
	{ O_NOFOLLOW, 	"O_NOFOLLOW"	},
#endif

#ifdef FNDELAY
	{ FNDELAY,	"FNDELAY"	},
#endif
#ifdef FAPPEND
	{ FAPPEND,	"FAPPEND"	},
#endif
#ifdef FMARK
	{ FMARK,	"FMARK"		},
#endif
#ifdef FDEFER
	{ FDEFER,	"FDEFER"	},
#endif
#ifdef FASYNC
	{ FASYNC,	"FASYNC"	},
#endif
#ifdef FSHLOCK
	{ FSHLOCK,	"FSHLOCK"	},
#endif
#ifdef FEXLOCK
	{ FEXLOCK,	"FEXLOCK"	},
#endif
#ifdef FCREAT
	{ FCREAT,	"FCREAT"	},
#endif
#ifdef FTRUNC
	{ FTRUNC,	"FTRUNC"	},
#endif
#ifdef FEXCL
	{ FEXCL,	"FEXCL"		},
#endif
#ifdef FNBIO
	{ FNBIO,	"FNBIO"		},
#endif
#ifdef FSYNC
	{ FSYNC,	"FSYNC"		},
#endif
#ifdef FNOCTTY
	{ FNOCTTY,	"FNOCTTY"	},
#endif	
#ifdef O_SHLOCK
	{ O_SHLOCK,	"O_SHLOCK"	},
#endif
#ifdef O_EXLOCK
	{ O_EXLOCK,	"O_EXLOCK"	},
#endif
	{ 0,		NULL		},
};

int
sys_open(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		/* flags */
		printflags(openmodes, tcp->u_arg[1] + 1);
		if (tcp->u_arg[1] & O_CREAT) {
			/* mode */
			tprintf(", %#lo", tcp->u_arg[2]);
		}
	}
	return 0;
}

#ifdef LINUXSPARC
struct xlat openmodessol[] = {
	{ 0,		"O_RDWR"	},
	{ 1,		"O_RDONLY"	},
	{ 2,		"O_WRONLY"	},
	{ 0x80,		"O_NONBLOCK"	},
	{ 8,		"O_APPEND"	},
	{ 0x100,	"O_CREAT"	},
	{ 0x200,	"O_TRUNC"	},
	{ 0x400,	"O_EXCL"	},
	{ 0x800,	"O_NOCTTY"	},
	{ 0x10,		"O_SYNC"	},
	{ 0x40,		"O_DSYNC"	},
	{ 0x8000,	"O_RSYNC"	},
	{ 4,		"O_NDELAY"	},
	{ 0x1000,	"O_PRIV"	},
	{ 0,		NULL		},
};

int
solaris_open(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		/* flags */
		printflags(openmodessol, tcp->u_arg[1] + 1);
		if (tcp->u_arg[1] & 0x100) {
			/* mode */
			tprintf(", %#lo", tcp->u_arg[2]);
		}
	}
	return 0;
}

#endif

int
sys_creat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %#lo", tcp->u_arg[1]);
	}
	return 0;
}

static struct xlat access_flags[] = {
	{ F_OK,		"F_OK",		},
	{ R_OK,		"R_OK"		},
	{ W_OK,		"W_OK"		},
	{ X_OK,		"X_OK"		},
#ifdef EFF_ONLY_OK
	{ EFF_ONLY_OK,	"EFF_ONLY_OK"	},
#endif
#ifdef EX_OK
	{ EX_OK,	"EX_OK"		},
#endif
	{ 0,		NULL		},
};

int
sys_access(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printflags(access_flags, tcp->u_arg[1]);
	}
	return 0;
}

int
sys_umask(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%#lo", tcp->u_arg[0]);
	}
	return RVAL_OCTAL;
}

static struct xlat whence[] = {
	{ SEEK_SET,	"SEEK_SET"	},
	{ SEEK_CUR,	"SEEK_CUR"	},
	{ SEEK_END,	"SEEK_END"	},
	{ 0,		NULL		},
};

int
sys_lseek(tcp)
struct tcb *tcp;
{
	off_t offset;
	int _whence;

	if (entering(tcp)) {
		tprintf("%ld, ", tcp->u_arg[0]);
#ifndef FREEBSD
		offset = tcp->u_arg[1];
		_whence = tcp->u_arg[2];
		if (_whence == SEEK_SET)
			tprintf("%lu, ", offset);
		else
			tprintf("%ld, ", offset);		
#else /* FREEBSD */
		offset = ((off_t) tcp->u_arg[1] << 32) +  tcp->u_arg[2];
		_whence = tcp->u_arg[4];
		if (_whence == SEEK_SET)
			tprintf("%llu, ", offset);
		else
			tprintf("%lld, ", offset);		
#endif		
		printxval(whence, _whence, "SEEK_???");
	} 
#ifdef FREEBSD
	else
		if (!syserror(tcp))
			return RVAL_LUDECIMAL;
#endif /* FREEBSD */
	return RVAL_UDECIMAL;
}

#ifdef linux
int
sys_llseek (tcp)
struct tcb *tcp;
{
    if (entering(tcp)) {
	if (tcp->u_arg[4] == SEEK_SET)
	    tprintf("%ld, %llu, ", tcp->u_arg[0],
		    (((long long int) tcp->u_arg[1]) << 32
		     | (unsigned long long) tcp->u_arg[2]));
	else
	    tprintf("%ld, %lld, ", tcp->u_arg[0],
		    (((long long int) tcp->u_arg[1]) << 32
		     | (unsigned long long) tcp->u_arg[2]));
    }
    else {
	long long int off;
	if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
	    tprintf("%#lx, ", tcp->u_arg[3]);
	else
	    tprintf("[%llu], ", off);
	printxval(whence, tcp->u_arg[4], "SEEK_???");
    }
    return 0;
}
#endif

#if _LFS64_LARGEFILE
int
sys_lseek64 (tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		long long offset = get64(tcp->u_arg [1], tcp->u_arg[2]);
		if (tcp->u_arg[3] == SEEK_SET)
			tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
		else
			tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
		printxval(whence, tcp->u_arg[3], "SEEK_???");
	}
	return RVAL_LUDECIMAL;
}
#endif

int
sys_truncate(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
#ifndef FREEBSD
		tprintf(", %lu", tcp->u_arg[1]);
#else
		tprintf(", %llu", ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
#endif		
	}
	return 0;
}

#if _LFS64_LARGEFILE
int
sys_truncate64(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %llu", get64(tcp->u_arg[1],tcp->u_arg[2]));
	}
	return 0;
}
#endif

int
sys_ftruncate(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
#ifndef FREEBSD
		tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
#else
		tprintf("%ld, %llu", tcp->u_arg[0],
			((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
#endif		
	}
	return 0;
}

#if _LFS64_LARGEFILE
int
sys_ftruncate64(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, %llu", tcp->u_arg[0],
			get64(tcp->u_arg[1] ,tcp->u_arg[2]));
	}
	return 0;
}
#endif

/* several stats */

static struct xlat modetypes[] = {
	{ S_IFREG,	"S_IFREG"	},
	{ S_IFSOCK,	"S_IFSOCK"	},
	{ S_IFIFO,	"S_IFIFO"	},
	{ S_IFLNK,	"S_IFLNK"	},
	{ S_IFDIR,	"S_IFDIR"	},
	{ S_IFBLK,	"S_IFBLK"	},
	{ S_IFCHR,	"S_IFCHR"	},
	{ 0,		NULL		},
};

static char *
sprintmode(mode)
int mode;
{
	static char buf[64];
	char *s;

	if ((mode & S_IFMT) == 0)
		s = "";
	else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
		sprintf(buf, "%#o", mode);
		return buf;
	}
	sprintf(buf, "%s%s%s%s", s,
		(mode & S_ISUID) ? "|S_ISUID" : "",
		(mode & S_ISGID) ? "|S_ISGID" : "",
		(mode & S_ISVTX) ? "|S_ISVTX" : "");
	mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
	if (mode)
		sprintf(buf + strlen(buf), "|%#o", mode);
	s = (*buf == '|') ? buf + 1 : buf;
	return *s ? s : "0";
}

static char *
sprinttime(t)
time_t t;
{
	struct tm *tmp;
	static char buf[32];

	if (t == 0) {
		sprintf(buf, "0");
		return buf;
	}
	tmp = localtime(&t);
	sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
		tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
		tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
	return buf;
}

#ifdef LINUXSPARC
typedef struct {
        int     tv_sec;
        int     tv_nsec;
} timestruct_t;

struct solstat {
        unsigned        st_dev;
        int             st_pad1[3];     /* network id */
        unsigned        st_ino;
        unsigned        st_mode;
        unsigned        st_nlink;
        unsigned        st_uid;
        unsigned        st_gid;
        unsigned        st_rdev;
        int             st_pad2[2];
        int             st_size;
        int             st_pad3;        /* st_size, off_t expansion */
        timestruct_t    st_atime;
        timestruct_t    st_mtime;
        timestruct_t    st_ctime;
        int             st_blksize;
        int             st_blocks;
        char            st_fstype[16];
        int             st_pad4[8];     /* expansion area */
};

static void
printstatsol(tcp, addr)
struct tcb *tcp;
long addr;
{
	struct solstat statbuf;

	if (!addr) {
		tprintf("NULL");
		return;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx", addr);
		return;
	}
	if (umove(tcp, addr, &statbuf) < 0) {
		tprintf("{...}");
		return;
	}
	if (!abbrev(tcp)) {
		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
			(unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
			(unsigned long) (statbuf.st_dev & 0x3ffff),
			(unsigned long) statbuf.st_ino,
			sprintmode(statbuf.st_mode));
		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
			(unsigned long) statbuf.st_nlink,
			(unsigned long) statbuf.st_uid,
			(unsigned long) statbuf.st_gid);
		tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
		tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
	}
	else
		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
	switch (statbuf.st_mode & S_IFMT) {
	case S_IFCHR: case S_IFBLK:
		tprintf("st_rdev=makedev(%lu, %lu), ",
			(unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
			(unsigned long) (statbuf.st_rdev & 0x3ffff));
		break;
	default:
		tprintf("st_size=%u, ", statbuf.st_size);
		break;
	}
	if (!abbrev(tcp)) {
		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
		tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
	}
	else
		tprintf("...}");
}
#endif /* LINUXSPARC */

#ifdef FREEBSD
static struct xlat fileflags[] = {
	{ UF_NODUMP,	"UF_NODUMP"	},
	{ UF_IMMUTABLE,	"UF_IMMUTABLE"	},
	{ UF_APPEND,	"UF_APPEND"	},
	{ UF_OPAQUE,	"UF_OPAQUE"	},
	{ UF_NOUNLINK,	"UF_NOUNLINK"	},
	{ SF_ARCHIVED,	"SF_ARCHIVED"	},
	{ SF_IMMUTABLE,	"SF_IMMUTABLE"	},
	{ SF_APPEND,	"SF_APPEND"	},
	{ SF_NOUNLINK,	"SF_NOUNLINK"	},
	{ 0,		NULL		},
};

int
sys_chflags(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		if (tcp->u_arg[1])
			printflags(fileflags, tcp->u_arg[1]);
		else
			tprintf("0");
	}
	return 0;
}

int
sys_fchflags(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, ", tcp->u_arg[0]);
		if (tcp->u_arg[1])
			printflags(fileflags, tcp->u_arg[1]);
		else
			tprintf("0");
	}
	return 0;
}
#endif

static void
realprintstat(tcp, statbuf)
struct tcb *tcp;
struct stat *statbuf;
{
    if (!abbrev(tcp)) {
	    tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
		    (unsigned long) major(statbuf->st_dev),
		    (unsigned long) minor(statbuf->st_dev),
		    (unsigned long) statbuf->st_ino,
		    sprintmode(statbuf->st_mode));
	    tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
		    (unsigned long) statbuf->st_nlink,
		    (unsigned long) statbuf->st_uid,
		    (unsigned long) statbuf->st_gid);
#ifdef HAVE_ST_BLKSIZE
	    tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
#endif /* HAVE_ST_BLKSIZE */
#ifdef HAVE_ST_BLOCKS
	    tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
#endif /* HAVE_ST_BLOCKS */
    }
    else
	    tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
    switch (statbuf->st_mode & S_IFMT) {
    case S_IFCHR: case S_IFBLK:
#ifdef HAVE_ST_RDEV
	    tprintf("st_rdev=makedev(%lu, %lu), ",
		    (unsigned long) major(statbuf->st_rdev),
		    (unsigned long) minor(statbuf->st_rdev));
#else /* !HAVE_ST_RDEV */
	    tprintf("st_size=makedev(%lu, %lu), ",
		    (unsigned long) major(statbuf->st_size),
		    (unsigned long) minor(statbuf->st_size));
#endif /* !HAVE_ST_RDEV */
	    break;
    default:
	    tprintf("st_size=%lu, ", statbuf->st_size);
	    break;
    }
    if (!abbrev(tcp)) {
	    tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
	    tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
#ifndef FREEBSD
	    tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
#else /* FREEBSD */
	    tprintf("st_ctime=%s, ", sprinttime(statbuf->st_ctime));
	    tprintf("st_flags=");
	    if (statbuf->st_flags) {
		    printflags(fileflags, statbuf->st_flags);
	    } else
		    tprintf("0");
	    tprintf(", st_gen=%u}", statbuf->st_gen);
#endif /* FREEBSD */
    }
    else
	    tprintf("...}");
}


static void
printstat(tcp, addr)
struct tcb *tcp;
long addr;
{
	struct stat statbuf;

#ifdef LINUXSPARC
 	if (current_personality == 1) {
 		printstatsol(tcp, addr);
 		return;
 	}
#endif /* LINUXSPARC */

	if (!addr) {
		tprintf("NULL");
		return;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx", addr);
		return;
	}
	if (umove(tcp, addr, &statbuf) < 0) {
		tprintf("{...}");
		return;
	}

	realprintstat(tcp, &statbuf);
}

#ifdef HAVE_STAT64
static void
printstat64(tcp, addr)
struct tcb *tcp;
long addr;
{
	struct stat64 statbuf;

#ifdef LINUXSPARC
 	if (current_personality == 1) {
 		printstatsol(tcp, addr);
 		return;
 	}
#endif /* LINUXSPARC */

	if (!addr) {
		tprintf("NULL");
		return;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx", addr);
		return;
	}
	if (umove(tcp, addr, &statbuf) < 0) {
		tprintf("{...}");
		return;
	}

	if (!abbrev(tcp)) {
#ifdef HAVE_LONG_LONG
		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
#else
		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
#endif
			(unsigned long) major(statbuf.st_dev),
			(unsigned long) minor(statbuf.st_dev),
#ifdef HAVE_LONG_LONG
			(unsigned long long) statbuf.st_ino,
#else
			(unsigned long) statbuf.st_ino,
#endif
			sprintmode(statbuf.st_mode));
		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
			(unsigned long) statbuf.st_nlink,
			(unsigned long) statbuf.st_uid,
			(unsigned long) statbuf.st_gid);
#ifdef HAVE_ST_BLKSIZE
		tprintf("st_blksize=%lu, ",
			(unsigned long) statbuf.st_blksize);
#endif /* HAVE_ST_BLKSIZE */
#ifdef HAVE_ST_BLOCKS
		tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
#endif /* HAVE_ST_BLOCKS */
	}
	else
		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
	switch (statbuf.st_mode & S_IFMT) {
	case S_IFCHR: case S_IFBLK:
#ifdef HAVE_ST_RDEV
		tprintf("st_rdev=makedev(%lu, %lu), ",
			(unsigned long) major(statbuf.st_rdev),
			(unsigned long) minor(statbuf.st_rdev));
#else /* !HAVE_ST_RDEV */
		tprintf("st_size=makedev(%lu, %lu), ",
			(unsigned long) major(statbuf.st_size),
			(unsigned long) minor(statbuf.st_size));
#endif /* !HAVE_ST_RDEV */
		break;
	default:
		tprintf("st_size=%llu, ", statbuf.st_size);
		break;
	}
	if (!abbrev(tcp)) {
		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
		tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
	}
	else
		tprintf("...}");
}
#endif /* HAVE_STAT64 */

#if defined(linux) && !defined(IA64)
static void
convertoldstat(oldbuf, newbuf)
const struct __old_kernel_stat *oldbuf;
struct stat *newbuf;
{
    newbuf->st_dev=oldbuf->st_dev;
    newbuf->st_ino=oldbuf->st_ino;
    newbuf->st_mode=oldbuf->st_mode;
    newbuf->st_nlink=oldbuf->st_nlink;
    newbuf->st_uid=oldbuf->st_uid;
    newbuf->st_gid=oldbuf->st_gid;
    newbuf->st_rdev=oldbuf->st_rdev;
    newbuf->st_size=oldbuf->st_size;
    newbuf->st_atime=oldbuf->st_atime;
    newbuf->st_mtime=oldbuf->st_mtime;
    newbuf->st_ctime=oldbuf->st_ctime;
    newbuf->st_blksize=0;	/* not supported in old_stat */
    newbuf->st_blocks=0;		/* not supported in old_stat */
}


static void
printoldstat(tcp, addr)
struct tcb *tcp;
long addr;
{
	struct __old_kernel_stat statbuf;
	struct stat newstatbuf;

#ifdef LINUXSPARC
 	if (current_personality == 1) {
 		printstatsol(tcp, addr);
 		return;
 	}
#endif /* LINUXSPARC */

	if (!addr) {
		tprintf("NULL");
		return;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx", addr);
		return;
	}
	if (umove(tcp, addr, &statbuf) < 0) {
		tprintf("{...}");
		return;
	}

	convertoldstat(&statbuf, &newstatbuf);
	realprintstat(tcp, &newstatbuf);
}
#endif /* linux && !IA64 */


int
sys_stat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printstat(tcp, tcp->u_arg[1]);
	}
	return 0;
}

#ifdef linux
int
sys_stat64(tcp)
struct tcb *tcp;
{
#ifdef HAVE_STAT64
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printstat64(tcp, tcp->u_arg[1]);
	}
	return 0;
#else
	return printargs(tcp);
#endif
}

# if !defined(IA64)
int
sys_oldstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printoldstat(tcp, tcp->u_arg[1]);
	}
	return 0;
}
# endif /* !IA64 */
#endif /* linux */

int
sys_fstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp))
		tprintf("%ld, ", tcp->u_arg[0]);
	else {
		printstat(tcp, tcp->u_arg[1]);
	}
	return 0;
}

#ifdef linux
int
sys_fstat64(tcp)
struct tcb *tcp;
{
#ifdef HAVE_STAT64
	if (entering(tcp))
		tprintf("%ld, ", tcp->u_arg[0]);
	else {
		printstat64(tcp, tcp->u_arg[1]);
	}
	return 0;
#else
	return printargs(tcp);
#endif
}

# if !defined(IA64)
int
sys_oldfstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp))
		tprintf("%ld, ", tcp->u_arg[0]);
	else {
		printoldstat(tcp, tcp->u_arg[1]);
	}
	return 0;
}
# endif /* !IA64 */
#endif

int
sys_lstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printstat(tcp, tcp->u_arg[1]);
	}
	return 0;
}

#ifdef linux
int
sys_lstat64(tcp)
struct tcb *tcp;
{
#ifdef HAVE_STAT64
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printstat64(tcp, tcp->u_arg[1]);
	}
	return 0;
#else
	return printargs(tcp);
#endif
}

# if !defined(IA64)
int
sys_oldlstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printoldstat(tcp, tcp->u_arg[1]);
	}
	return 0;
}
# endif /* !IA64 */
#endif


#if defined(SVR4) || defined(LINUXSPARC)

int
sys_xstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, ", tcp->u_arg[0]);
		printpath(tcp, tcp->u_arg[1]);
		tprintf(", ");
	} else {
#ifdef _STAT64_VER
		if (tcp->u_arg[0] == _STAT64_VER)
			printstat64 (tcp, tcp->u_arg[2]);
		else
#endif
		printstat(tcp, tcp->u_arg[2]);
	}
	return 0;
}

int
sys_fxstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp))
		tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
	else {
#ifdef _STAT64_VER
		if (tcp->u_arg[0] == _STAT64_VER)
			printstat64 (tcp, tcp->u_arg[2]);
		else
#endif
		printstat(tcp, tcp->u_arg[2]);
	}
	return 0;
}

int
sys_lxstat(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, ", tcp->u_arg[0]);
		printpath(tcp, tcp->u_arg[1]);
		tprintf(", ");
	} else {
#ifdef _STAT64_VER
		if (tcp->u_arg[0] == _STAT64_VER)
			printstat64 (tcp, tcp->u_arg[2]);
		else
#endif
		printstat(tcp, tcp->u_arg[2]);
	}
	return 0;
}

int
sys_xmknod(tcp)
struct tcb *tcp;
{
	int mode = tcp->u_arg[2];

	if (entering(tcp)) {
		tprintf("%ld, ", tcp->u_arg[0]);
		printpath(tcp, tcp->u_arg[1]);
		tprintf(", %s", sprintmode(mode));
		switch (mode & S_IFMT) {
		case S_IFCHR: case S_IFBLK:
#ifdef LINUXSPARC
			tprintf(", makedev(%lu, %lu)",
				(unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
				(unsigned long) (tcp->u_arg[3] & 0x3ffff));
#else		
			tprintf(", makedev(%lu, %lu)",
				(unsigned long) major(tcp->u_arg[3]),
				(unsigned long) minor(tcp->u_arg[3]));
#endif				
			break;
		default:
			break;
		}
	}
	return 0;
}

#ifdef HAVE_SYS_ACL_H

#include <sys/acl.h>

struct xlat aclcmds[] = {
#ifdef SETACL
	{ SETACL,	"SETACL"	},
#endif
#ifdef GETACL
	{ GETACL,	"GETACL"	},
#endif
#ifdef GETACLCNT
	{ GETACLCNT,	"GETACLCNT"	},
#endif
#ifdef ACL_GET
	{ ACL_GET,	"ACL_GET"	},
#endif	
#ifdef ACL_SET
	{ ACL_SET,	"ACL_SET"	},
#endif	
#ifdef ACL_CNT
	{ ACL_CNT,	"ACL_CNT"	},
#endif	
	{ 0,		NULL		},
};

int
sys_acl(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printxval(aclcmds, tcp->u_arg[1], "???ACL???");
		tprintf(", %ld", tcp->u_arg[2]);
		/*
		 * FIXME - dump out the list of aclent_t's pointed to
		 * by "tcp->u_arg[3]" if it's not NULL.
		 */
		if (tcp->u_arg[3])
			tprintf(", %#lx", tcp->u_arg[3]);
		else
			tprintf(", NULL");
	}
	return 0;
}


int
sys_facl(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, ", tcp->u_arg[0]);
		printxval(aclcmds, tcp->u_arg[1], "???ACL???");
		tprintf(", %ld", tcp->u_arg[2]);
		/*
		 * FIXME - dump out the list of aclent_t's pointed to
		 * by "tcp->u_arg[3]" if it's not NULL.
		 */
		if (tcp->u_arg[3])
			tprintf(", %#lx", tcp->u_arg[3]);
		else
			tprintf(", NULL");
	}
	return 0;
}


struct xlat aclipc[] = {
#ifdef IPC_SHM
	{ IPC_SHM,	"IPC_SHM"	},
#endif	
#ifdef IPC_SEM
	{ IPC_SEM,	"IPC_SEM"	},
#endif	
#ifdef IPC_MSG
	{ IPC_MSG,	"IPC_MSG"	},
#endif	
	{ 0,		NULL		},
};


int
sys_aclipc(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printxval(aclipc, tcp->u_arg[0], "???IPC???");
		tprintf(", %#lx, ", tcp->u_arg[1]);
		printxval(aclcmds, tcp->u_arg[2], "???ACL???");
		tprintf(", %ld", tcp->u_arg[3]);
		/*
		 * FIXME - dump out the list of aclent_t's pointed to
		 * by "tcp->u_arg[4]" if it's not NULL.
		 */
		if (tcp->u_arg[4])
			tprintf(", %#lx", tcp->u_arg[4]);
		else
			tprintf(", NULL");
	}
	return 0;
}



#endif /* HAVE_SYS_ACL_H */

#endif /* SVR4 || LINUXSPARC */

#ifdef linux

static struct xlat fsmagic[] = {
	{ 0x73757245,	"CODA_SUPER_MAGIC"	},
	{ 0x012ff7b7,	"COH_SUPER_MAGIC"	},
	{ 0x1373,	"DEVFS_SUPER_MAGIC"	},
	{ 0x1cd1,	"DEVPTS_SUPER_MAGIC"	},
	{ 0x414A53,	"EFS_SUPER_MAGIC"	},
	{ 0xef51,	"EXT2_OLD_SUPER_MAGIC"	},
	{ 0xef53,	"EXT2_SUPER_MAGIC"	},
	{ 0x137d,	"EXT_SUPER_MAGIC"	},
	{ 0xf995e849,	"HPFS_SUPER_MAGIC"	},
	{ 0x9660,	"ISOFS_SUPER_MAGIC"	},
	{ 0x137f,	"MINIX_SUPER_MAGIC"	},
	{ 0x138f,	"MINIX_SUPER_MAGIC2"	},
	{ 0x2468,	"MINIX2_SUPER_MAGIC"	},
	{ 0x2478,	"MINIX2_SUPER_MAGIC2"	},
	{ 0x4d44,	"MSDOS_SUPER_MAGIC"	},
	{ 0x564c,	"NCP_SUPER_MAGIC"	},
	{ 0x6969,	"NFS_SUPER_MAGIC"	},
	{ 0x9fa0,	"PROC_SUPER_MAGIC"	},
	{ 0x002f,	"QNX4_SUPER_MAGIC"	},
	{ 0x52654973,	"REISERFS_SUPER_MAGIC"	},
	{ 0x02011994,	"SHMFS_SUPER_MAGIC"	},
	{ 0x517b,	"SMB_SUPER_MAGIC"	},
	{ 0x012ff7b6,	"SYSV2_SUPER_MAGIC"	},
	{ 0x012ff7b5,	"SYSV4_SUPER_MAGIC"	},
	{ 0x00011954,	"UFS_MAGIC"		},
	{ 0x54190100,	"UFS_CIGAM"		},
	{ 0x012ff7b4,	"XENIX_SUPER_MAGIC"	},
	{ 0x012fd16d,	"XIAFS_SUPER_MAGIC"	},
	{ 0,		NULL			},
};

#endif /* linux */

#ifndef SVR4

static char *
sprintfstype(magic)
int magic;
{
	static char buf[32];
#ifdef linux
	char *s;

	s = xlookup(fsmagic, magic);
	if (s) {
		sprintf(buf, "\"%s\"", s);
		return buf;
	}
#endif /* linux */
	sprintf(buf, "%#x", magic);
	return buf;
}

static void
printstatfs(tcp, addr)
struct tcb *tcp;
long addr;
{
	struct statfs statbuf;

	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx", addr);
		return;
	}
	if (umove(tcp, addr, &statbuf) < 0) {
		tprintf("{...}");
		return;
	}
#ifdef ALPHA

	tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
		sprintfstype(statbuf.f_type),
		statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
	tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
		statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
#else /* !ALPHA */
	tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
		sprintfstype(statbuf.f_type),
		(unsigned long)statbuf.f_bsize,
		(unsigned long)statbuf.f_blocks,
		(unsigned long)statbuf.f_bfree);
	tprintf("f_files=%lu, f_ffree=%lu",
		(unsigned long)statbuf.f_files,
		(unsigned long)statbuf.f_ffree);
#ifdef linux
	tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
#endif /* linux */
#endif /* !ALPHA */
	tprintf("}");
}

int
sys_statfs(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printstatfs(tcp, tcp->u_arg[1]);
	}
	return 0;
}

int
sys_fstatfs(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
	} else {
		printstatfs(tcp, tcp->u_arg[1]);
	}
	return 0;
}

#if defined(linux) && defined(__alpha)

int
osf_statfs(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		printstatfs(tcp, tcp->u_arg[1]);
		tprintf(", %lu", tcp->u_arg[2]);
	}
	return 0;
}

int
osf_fstatfs(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
	} else {
		printstatfs(tcp, tcp->u_arg[1]);
		tprintf(", %lu", tcp->u_arg[2]);
	}
	return 0;
}
#endif /* linux && __alpha */

#endif /* !SVR4 */

#ifdef SUNOS4

int
sys_ustat(tcp)
struct tcb *tcp;
{
	struct ustat statbuf;

	if (entering(tcp)) {
		tprintf("makedev(%lu, %lu), ",
				(long) major(tcp->u_arg[0]),
				(long) minor(tcp->u_arg[0]));
	}
	else {
		if (syserror(tcp) || !verbose(tcp))
			tprintf("%#lx", tcp->u_arg[1]);
		else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
			tprintf("{...}");
		else {
			tprintf("{f_tfree=%lu, f_tinode=%lu, ",
				statbuf.f_tfree, statbuf.f_tinode);
			tprintf("f_fname=\"%.*s\", ",
				(int) sizeof(statbuf.f_fname),
				statbuf.f_fname);
			tprintf("f_fpack=\"%.*s\"}",
				(int) sizeof(statbuf.f_fpack),
				statbuf.f_fpack);
		}
	}
	return 0;
}

#endif /* SUNOS4 */

int
sys_pivotroot(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printpath(tcp, tcp->u_arg[1]);
	}
	return 0;
}


/* directory */
int
sys_chdir(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
	}
	return 0;
}

int
sys_mkdir(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %#lo", tcp->u_arg[1]);
	}
	return 0;
}

int
sys_rmdir(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
	}
	return 0;
}

int
sys_fchdir(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld", tcp->u_arg[0]);
	}
	return 0;
}

int
sys_chroot(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
	}
	return 0;
}

int
sys_fchroot(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld", tcp->u_arg[0]);
	}
	return 0;
}

int
sys_link(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printpath(tcp, tcp->u_arg[1]);
	}
	return 0;
}

int
sys_unlink(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
	}
	return 0;
}

int
sys_symlink(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printpath(tcp, tcp->u_arg[1]);
	}
	return 0;
}

int
sys_readlink(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
	} else {
		if (syserror(tcp))
			tprintf("%#lx", tcp->u_arg[1]);
		else
			printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
		tprintf(", %lu", tcp->u_arg[2]);
	}
	return 0;
}

int
sys_rename(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printpath(tcp, tcp->u_arg[1]);
	}
	return 0;
}

int
sys_chown(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
	}
	return 0;
}

int
sys_fchown(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, %lu, %lu",
			tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
	}
	return 0;
}

int
sys_chmod(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %#lo", tcp->u_arg[1]);
	}
	return 0;
}

int
sys_fchmod(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
	}
	return 0;
}

#ifdef ALPHA
int
sys_osf_utimes(tcp)
struct tcb *tcp;
{
    if (entering(tcp)) {
	printpath(tcp, tcp->u_arg[0]);
	tprintf(", ");
	printtv32(tcp, tcp->u_arg[1]);
    }
    return 0;
}
#endif

int
sys_utimes(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		printtv(tcp, tcp->u_arg[1]);
	}
	return 0;
}

int
sys_utime(tcp)
struct tcb *tcp;
{
	long ut[2];

	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", ");
		if (!tcp->u_arg[1])
			tprintf("NULL");
		else if (!verbose(tcp))
			tprintf("%#lx", tcp->u_arg[1]);
		else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
		    (char *) ut) < 0)
			tprintf("[?, ?]");
		else {
			tprintf("[%s,", sprinttime(ut[0]));
			tprintf(" %s]", sprinttime(ut[1]));
		}
	}
	return 0;
}

int
sys_mknod(tcp)
struct tcb *tcp;
{
	int mode = tcp->u_arg[1];

	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %s", sprintmode(mode));
		switch (mode & S_IFMT) {
		case S_IFCHR: case S_IFBLK:
#ifdef LINUXSPARC
			if (current_personality == 1)
			tprintf(", makedev(%lu, %lu)",
				(unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
				(unsigned long) (tcp->u_arg[2] & 0x3ffff));
			else
#endif	
			tprintf(", makedev(%lu, %lu)",
				(unsigned long) major(tcp->u_arg[2]),
				(unsigned long) minor(tcp->u_arg[2]));
			break;
		default:
			break;
		}
	}
	return 0;
}

int
sys_mkfifo(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %#lo", tcp->u_arg[1]);
	}
	return 0;
}

int
sys_fsync(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%ld", tcp->u_arg[0]);
	}
	return 0;
}

#ifdef linux

static void
printdir(tcp, addr)
struct tcb *tcp;
long addr;
{
	struct dirent d;

	if (!verbose(tcp)) {
		tprintf("%#lx", addr);
		return;
	}
	if (umove(tcp, addr, &d) < 0) {
		tprintf("{...}");
		return;
	}
	tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
	tprintf("d_name=");
	printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
	tprintf("}");
}

int
sys_readdir(tcp)
struct tcb *tcp;
{
	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
	} else {
		if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
			tprintf("%#lx", tcp->u_arg[1]);
		else
			printdir(tcp, tcp->u_arg[1]);
		/* Not much point in printing this out, it is always 1. */
		if (tcp->u_arg[2] != 1)
			tprintf(", %lu", tcp->u_arg[2]);
	}
	return 0;
}

#endif /* linux */

#ifdef FREEBSD
struct xlat direnttypes[] = {
	{ DT_FIFO,	"DT_FIFO" 	},
	{ DT_CHR,	"DT_CHR" 	},
	{ DT_DIR,	"DT_DIR" 	},
	{ DT_BLK,	"DT_BLK" 	},
	{ DT_REG,	"DT_REG" 	},
	{ DT_LNK,	"DT_LNK" 	},
	{ DT_SOCK,	"DT_SOCK" 	},
	{ DT_WHT,	"DT_WHT" 	},
	{ 0,		NULL		},
};

#endif

int
sys_getdents(tcp)
struct tcb *tcp;
{
	int i, len, dents = 0;
	char *buf;

	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
		return 0;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
		return 0;
	}
	len = tcp->u_rval;
	if ((buf = malloc(len)) == NULL) {
		tprintf("out of memory\n");
		return 0;
	}
	if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
		tprintf("{...}, %lu", tcp->u_arg[2]);
		free(buf);
		return 0;
	}
	if (!abbrev(tcp))
		tprintf("{");
	for (i = 0; i < len;) {
		struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
#ifdef linux
		if (!abbrev(tcp)) {
			tprintf("%s{d_ino=%lu, d_off=%lu, ",
				i ? " " : "", d->d_ino, d->d_off);
			tprintf("d_reclen=%u, d_name=\"%s\"}",
				d->d_reclen, d->d_name);
		}
#endif /* linux */
#ifdef SVR4
		if (!abbrev(tcp)) {
			tprintf("%s{d_ino=%lu, d_off=%lu, ",
				i ? " " : "", d->d_ino, d->d_off);
			tprintf("d_reclen=%u, d_name=\"%s\"}",
				d->d_reclen, d->d_name);
		}
#endif /* SVR4 */
#ifdef SUNOS4
		if (!abbrev(tcp)) {
			tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
				i ? " " : "", d->d_off, d->d_fileno,
				d->d_reclen);
			tprintf("d_namlen=%u, d_name=\"%.*s\"}",
				d->d_namlen, d->d_namlen, d->d_name);
		}
#endif /* SUNOS4 */
#ifdef FREEBSD
		if (!abbrev(tcp)) {
			tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
				i ? " " : "", d->d_fileno, d->d_reclen);
			printxval(direnttypes, d->d_type, "DT_???");
			tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
				d->d_namlen, d->d_namlen, d->d_name);
		}
#endif /* FREEBSD */		
		if (!d->d_reclen) {
			tprintf("/* d_reclen == 0, problem here */");
			break;
		}
		i += d->d_reclen;
		dents++;
	}
	if (!abbrev(tcp))
		tprintf("}");
	else
		tprintf("/* %u entries */", dents);
	tprintf(", %lu", tcp->u_arg[2]);
	free(buf);
	return 0;
}


#if _LFS64_LARGEFILE
int
sys_getdents64(tcp)
struct tcb *tcp;
{
	int i, len, dents = 0;
	char *buf;

	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
		return 0;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
		return 0;
	}
	len = tcp->u_rval;
	if ((buf = malloc(len)) == NULL) {
		tprintf("out of memory\n");
		return 0;
	}
	if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
		tprintf("{...}, %lu", tcp->u_arg[2]);
		free(buf);
		return 0;
	}
	if (!abbrev(tcp))
		tprintf("{");
	for (i = 0; i < len;) {
		struct dirent64 *d = (struct dirent64 *) &buf[i];
#ifdef linux
		if (!abbrev(tcp)) {
			tprintf("%s{d_ino=%lu, d_off=%lu, ",
				i ? " " : "", d->d_ino, d->d_off);
			tprintf("d_reclen=%u, d_name=\"%s\"}",
				d->d_reclen, d->d_name);
		}
#endif /* linux */
#ifdef SVR4
		if (!abbrev(tcp)) {
			tprintf("%s{d_ino=%llu, d_off=%llu, ",
				i ? " " : "", d->d_ino, d->d_off);
			tprintf("d_reclen=%u, d_name=\"%s\"}",
				d->d_reclen, d->d_name);
		}
#endif /* SVR4 */
#ifdef SUNOS4
		if (!abbrev(tcp)) {
			tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
				i ? " " : "", d->d_off, d->d_fileno,
				d->d_reclen);
			tprintf("d_namlen=%u, d_name=\"%.*s\"}",
				d->d_namlen, d->d_namlen, d->d_name);
		}
#endif /* SUNOS4 */
		i += d->d_reclen;
		dents++;
	}
	if (!abbrev(tcp))
		tprintf("}");
	else
		tprintf("/* %u entries */", dents);
	tprintf(", %lu", tcp->u_arg[2]);
	free(buf);
	return 0;
}
#endif
 
#ifdef FREEBSD
int
sys_getdirentries(tcp)
struct tcb * tcp;
{
	int i, len, dents = 0;
	long basep;
	char *buf;

	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
		return 0;
	}
	if (syserror(tcp) || !verbose(tcp)) {
		tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
		return 0;
	}
	len = tcp->u_rval;
	if ((buf = malloc(len)) == NULL) {
		tprintf("out of memory\n");
		return 0;
	}
	if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
		tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
		free(buf);
		return 0;
	}
	if (!abbrev(tcp))
		tprintf("{");
	for (i = 0; i < len;) {
		struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
		if (!abbrev(tcp)) {
			tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
				i ? " " : "", d->d_fileno, d->d_reclen);
			printxval(direnttypes, d->d_type, "DT_???");
			tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
				d->d_namlen, d->d_namlen, d->d_name);
		}
		i += d->d_reclen;
		dents++;
	}
	if (!abbrev(tcp))
		tprintf("}");
	else
		tprintf("/* %u entries */", dents);
	free(buf);
	tprintf(", %lu", tcp->u_arg[2]);
	if (umove(tcp, tcp->u_arg[3], &basep) < 0)
		tprintf(", %#lx", tcp->u_arg[3]);
	else
		tprintf(", [%lu]", basep);
	return 0;
}
#endif

#ifdef linux
int
sys_getcwd(tcp)
struct tcb *tcp;
{
    if (exiting(tcp)) {
	if (syserror(tcp))
	    tprintf("%#lx", tcp->u_arg[0]);
	else
	    printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
	tprintf(", %lu", tcp->u_arg[1]);
    }
    return 0;
}
#endif /* linux */

#ifdef FREEBSD
int
sys___getcwd(tcp)
struct tcb *tcp;
{
    if (exiting(tcp)) {
	if (syserror(tcp))
	    tprintf("%#lx", tcp->u_arg[0]);
	else
	    printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
	tprintf(", %lu", tcp->u_arg[1]);
    }
    return 0;
}
#endif

#ifdef HAVE_SYS_ASYNCH_H

int
sys_aioread(tcp)
struct tcb *tcp;
{
	struct aio_result_t res;

	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
	} else {
		if (syserror(tcp))
			tprintf("%#lx", tcp->u_arg[1]);
		else
			printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
		printxval(whence, tcp->u_arg[4], "L_???");
		if (syserror(tcp) || tcp->u_arg[5] == 0
		    || umove(tcp, tcp->u_arg[5], &res) < 0)
			tprintf(", %#lx", tcp->u_arg[5]);
		else
			tprintf(", {aio_return %d aio_errno %d}",
				res.aio_return, res.aio_errno);
	}
	return 0;
}

int
sys_aiowrite(tcp)
struct tcb *tcp;
{
	struct aio_result_t res;

	if (entering(tcp)) {
		tprintf("%lu, ", tcp->u_arg[0]);
		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
		printxval(whence, tcp->u_arg[4], "L_???");
	}
	else {
		if (tcp->u_arg[5] == 0)
			tprintf(", NULL");
		else if (syserror(tcp)
		    || umove(tcp, tcp->u_arg[5], &res) < 0)
			tprintf(", %#lx", tcp->u_arg[5]);
		else
			tprintf(", {aio_return %d aio_errno %d}",
				res.aio_return, res.aio_errno);
	}
	return 0;
}

int
sys_aiowait(tcp)
struct tcb *tcp;
{
	if (entering(tcp))
		printtv(tcp, tcp->u_arg[0]);
	return 0;
}

int
sys_aiocancel(tcp)
struct tcb *tcp;
{
	struct aio_result_t res;

	if (exiting(tcp)) {
		if (tcp->u_arg[0] == 0)
			tprintf("NULL");
		else if (syserror(tcp)
		    || umove(tcp, tcp->u_arg[0], &res) < 0)
			tprintf("%#lx", tcp->u_arg[0]);
		else
			tprintf("{aio_return %d aio_errno %d}",
				res.aio_return, res.aio_errno);
	}
	return 0;
}

#endif /* HAVE_SYS_ASYNCH_H */