blob: 5b30eba72d4b0568b4a40d2c9c992e6befa8d515 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
Michal Ludvig53b320f2002-09-23 13:30:09 +00002#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
4 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
5 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00006 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * $Id$
32 */
33
34#include "defs.h"
35
36#include <dirent.h>
Michal Ludvig53b320f2002-09-23 13:30:09 +000037#ifdef LINUX
Wichert Akkerman9524bb91999-05-25 23:11:18 +000038#define dirent kernel_dirent
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +000039#define dirent64 kernel_dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000040#include <linux/types.h>
41#include <linux/dirent.h>
42#undef dirent
Michal Ludvig10a88d02002-10-07 14:31:00 +000043#undef dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000044#else
45#define kernel_dirent dirent
46#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047
Michal Ludvig53b320f2002-09-23 13:30:09 +000048#ifdef LINUX
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000049# ifdef LINUXSPARC
50struct stat {
51 unsigned short st_dev;
52 unsigned int st_ino;
53 unsigned short st_mode;
54 short st_nlink;
55 unsigned short st_uid;
56 unsigned short st_gid;
57 unsigned short st_rdev;
58 unsigned int st_size;
59 int st_atime;
60 unsigned int __unused1;
61 int st_mtime;
62 unsigned int __unused2;
63 int st_ctime;
64 unsigned int __unused3;
65 int st_blksize;
66 int st_blocks;
67 unsigned int __unused4[2];
68};
69# define stat kernel_stat
70# include <asm/stat.h>
71# undef stat
72# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000073# undef dev_t
74# undef ino_t
75# undef mode_t
76# undef nlink_t
77# undef uid_t
78# undef gid_t
79# undef off_t
80# undef loff_t
81
Wichert Akkermana6013701999-07-08 14:00:58 +000082# define dev_t __kernel_dev_t
83# define ino_t __kernel_ino_t
84# define mode_t __kernel_mode_t
85# define nlink_t __kernel_nlink_t
86# define uid_t __kernel_uid_t
87# define gid_t __kernel_gid_t
88# define off_t __kernel_off_t
89# define loff_t __kernel_loff_t
90
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000091# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000092
93# undef dev_t
94# undef ino_t
95# undef mode_t
96# undef nlink_t
97# undef uid_t
98# undef gid_t
99# undef off_t
100# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000101
102# define dev_t dev_t
103# define ino_t ino_t
104# define mode_t mode_t
105# define nlink_t nlink_t
106# define uid_t uid_t
107# define gid_t gid_t
108# define off_t off_t
109# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000110# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000111# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
112# undef stat64
113# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000114# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000115# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000116# include <sys/stat.h>
117# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000118# undef stat64
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000119# ifdef HPPA
120# define stat64 hpux_stat64
121# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000122#else
123# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000124#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000125
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126#include <fcntl.h>
127
128#ifdef SVR4
129# include <sys/cred.h>
130#endif /* SVR4 */
131
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000132#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000134#endif
135
136#ifdef FREEBSD
137#include <sys/param.h>
138#include <sys/mount.h>
139#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000140#endif
141
142#if HAVE_LONG_LONG_OFF_T
143/*
144 * Ugly hacks for systems that have typedef long long off_t
145 */
John Hughesb8c9f772001-03-07 16:53:07 +0000146
147#define stat64 stat
148#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000149
150#define sys_stat64 sys_stat
151#define sys_fstat64 sys_fstat
152#define sys_lstat64 sys_lstat
153#define sys_lseek64 sys_lseek
154#define sys_truncate64 sys_truncate
155#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000156#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157
158#ifdef MAJOR_IN_SYSMACROS
159#include <sys/sysmacros.h>
160#endif
161
162#ifdef MAJOR_IN_MKDEV
163#include <sys/mkdev.h>
164#endif
165
166#ifdef HAVE_SYS_ASYNCH_H
167#include <sys/asynch.h>
168#endif
169
170#ifdef SUNOS4
171#include <ustat.h>
172#endif
173
174/*
175 * This is a really dirty trick but it should always work. Traditional
176 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
177 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
178 */
179struct xlat openmodes[] = {
180 { O_RDWR+1, "O_RDWR" },
181 { O_RDONLY+1, "O_RDONLY" },
182 { O_WRONLY+1, "O_WRONLY" },
183 { O_NONBLOCK, "O_NONBLOCK" },
184 { O_APPEND, "O_APPEND" },
185 { O_CREAT, "O_CREAT" },
186 { O_TRUNC, "O_TRUNC" },
187 { O_EXCL, "O_EXCL" },
188 { O_NOCTTY, "O_NOCTTY" },
189#ifdef O_SYNC
190 { O_SYNC, "O_SYNC" },
191#endif
192#ifdef O_ASYNC
193 { O_ASYNC, "O_ASYNC" },
194#endif
195#ifdef O_DSYNC
196 { O_DSYNC, "O_DSYNC" },
197#endif
198#ifdef O_RSYNC
199 { O_RSYNC, "O_RSYNC" },
200#endif
201#ifdef O_NDELAY
202 { O_NDELAY, "O_NDELAY" },
203#endif
204#ifdef O_PRIV
205 { O_PRIV, "O_PRIV" },
206#endif
207#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000208 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209#endif
210#ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000211 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212#endif
213#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000214 { O_DIRECTORY, "O_DIRECTORY" },
215#endif
216#ifdef O_NOFOLLOW
217 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218#endif
219
220#ifdef FNDELAY
221 { FNDELAY, "FNDELAY" },
222#endif
223#ifdef FAPPEND
224 { FAPPEND, "FAPPEND" },
225#endif
226#ifdef FMARK
227 { FMARK, "FMARK" },
228#endif
229#ifdef FDEFER
230 { FDEFER, "FDEFER" },
231#endif
232#ifdef FASYNC
233 { FASYNC, "FASYNC" },
234#endif
235#ifdef FSHLOCK
236 { FSHLOCK, "FSHLOCK" },
237#endif
238#ifdef FEXLOCK
239 { FEXLOCK, "FEXLOCK" },
240#endif
241#ifdef FCREAT
242 { FCREAT, "FCREAT" },
243#endif
244#ifdef FTRUNC
245 { FTRUNC, "FTRUNC" },
246#endif
247#ifdef FEXCL
248 { FEXCL, "FEXCL" },
249#endif
250#ifdef FNBIO
251 { FNBIO, "FNBIO" },
252#endif
253#ifdef FSYNC
254 { FSYNC, "FSYNC" },
255#endif
256#ifdef FNOCTTY
257 { FNOCTTY, "FNOCTTY" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000258#endif
259#ifdef O_SHLOCK
260 { O_SHLOCK, "O_SHLOCK" },
261#endif
262#ifdef O_EXLOCK
263 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264#endif
265 { 0, NULL },
266};
267
268int
269sys_open(tcp)
270struct tcb *tcp;
271{
272 if (entering(tcp)) {
273 printpath(tcp, tcp->u_arg[0]);
274 tprintf(", ");
275 /* flags */
276 printflags(openmodes, tcp->u_arg[1] + 1);
277 if (tcp->u_arg[1] & O_CREAT) {
278 /* mode */
279 tprintf(", %#lo", tcp->u_arg[2]);
280 }
281 }
282 return 0;
283}
284
285#ifdef LINUXSPARC
286struct xlat openmodessol[] = {
287 { 0, "O_RDWR" },
288 { 1, "O_RDONLY" },
289 { 2, "O_WRONLY" },
290 { 0x80, "O_NONBLOCK" },
291 { 8, "O_APPEND" },
292 { 0x100, "O_CREAT" },
293 { 0x200, "O_TRUNC" },
294 { 0x400, "O_EXCL" },
295 { 0x800, "O_NOCTTY" },
296 { 0x10, "O_SYNC" },
297 { 0x40, "O_DSYNC" },
298 { 0x8000, "O_RSYNC" },
299 { 4, "O_NDELAY" },
300 { 0x1000, "O_PRIV" },
301 { 0, NULL },
302};
303
304int
305solaris_open(tcp)
306struct tcb *tcp;
307{
308 if (entering(tcp)) {
309 printpath(tcp, tcp->u_arg[0]);
310 tprintf(", ");
311 /* flags */
312 printflags(openmodessol, tcp->u_arg[1] + 1);
313 if (tcp->u_arg[1] & 0x100) {
314 /* mode */
315 tprintf(", %#lo", tcp->u_arg[2]);
316 }
317 }
318 return 0;
319}
320
321#endif
322
323int
324sys_creat(tcp)
325struct tcb *tcp;
326{
327 if (entering(tcp)) {
328 printpath(tcp, tcp->u_arg[0]);
329 tprintf(", %#lo", tcp->u_arg[1]);
330 }
331 return 0;
332}
333
334static struct xlat access_flags[] = {
335 { F_OK, "F_OK", },
336 { R_OK, "R_OK" },
337 { W_OK, "W_OK" },
338 { X_OK, "X_OK" },
339#ifdef EFF_ONLY_OK
340 { EFF_ONLY_OK, "EFF_ONLY_OK" },
341#endif
342#ifdef EX_OK
343 { EX_OK, "EX_OK" },
344#endif
345 { 0, NULL },
346};
347
348int
349sys_access(tcp)
350struct tcb *tcp;
351{
352 if (entering(tcp)) {
353 printpath(tcp, tcp->u_arg[0]);
354 tprintf(", ");
355 printflags(access_flags, tcp->u_arg[1]);
356 }
357 return 0;
358}
359
360int
361sys_umask(tcp)
362struct tcb *tcp;
363{
364 if (entering(tcp)) {
365 tprintf("%#lo", tcp->u_arg[0]);
366 }
367 return RVAL_OCTAL;
368}
369
370static struct xlat whence[] = {
371 { SEEK_SET, "SEEK_SET" },
372 { SEEK_CUR, "SEEK_CUR" },
373 { SEEK_END, "SEEK_END" },
374 { 0, NULL },
375};
376
John Hughes70623be2001-03-08 13:59:00 +0000377#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378int
379sys_lseek(tcp)
380struct tcb *tcp;
381{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000382 off_t offset;
383 int _whence;
384
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385 if (entering(tcp)) {
386 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000387 offset = tcp->u_arg[1];
388 _whence = tcp->u_arg[2];
389 if (_whence == SEEK_SET)
390 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000392 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000393 printxval(whence, _whence, "SEEK_???");
394 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395 return RVAL_UDECIMAL;
396}
John Hughes5a826b82001-03-07 13:21:24 +0000397#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398
Michal Ludvig53b320f2002-09-23 13:30:09 +0000399#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400int
401sys_llseek (tcp)
402struct tcb *tcp;
403{
404 if (entering(tcp)) {
405 if (tcp->u_arg[4] == SEEK_SET)
406 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000407 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000408 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409 else
410 tprintf("%ld, %lld, ", tcp->u_arg[0],
411 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000412 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413 }
414 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000415 long long int off;
416 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000418 else
419 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 printxval(whence, tcp->u_arg[4], "SEEK_???");
421 }
422 return 0;
423}
424#endif
425
John Hughes70623be2001-03-08 13:59:00 +0000426#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000427int
428sys_lseek64 (tcp)
429struct tcb *tcp;
430{
431 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000432 long long offset;
433 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000434 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000435 if (tcp->u_arg[3] == SEEK_SET)
436 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
437 else
438 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
439 printxval(whence, tcp->u_arg[3], "SEEK_???");
440 }
441 return RVAL_LUDECIMAL;
442}
443#endif
444
John Hughes70623be2001-03-08 13:59:00 +0000445#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446int
447sys_truncate(tcp)
448struct tcb *tcp;
449{
450 if (entering(tcp)) {
451 printpath(tcp, tcp->u_arg[0]);
452 tprintf(", %lu", tcp->u_arg[1]);
453 }
454 return 0;
455}
John Hughes5a826b82001-03-07 13:21:24 +0000456#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457
John Hughes70623be2001-03-08 13:59:00 +0000458#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000459int
460sys_truncate64(tcp)
461struct tcb *tcp;
462{
463 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000464 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000465 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000466 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000467 }
468 return 0;
469}
470#endif
471
John Hughes70623be2001-03-08 13:59:00 +0000472#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473int
474sys_ftruncate(tcp)
475struct tcb *tcp;
476{
477 if (entering(tcp)) {
478 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
479 }
480 return 0;
481}
John Hughes5a826b82001-03-07 13:21:24 +0000482#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483
John Hughes70623be2001-03-08 13:59:00 +0000484#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000485int
486sys_ftruncate64(tcp)
487struct tcb *tcp;
488{
489 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000490 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000491 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000492 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000493 }
494 return 0;
495}
496#endif
497
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498/* several stats */
499
500static struct xlat modetypes[] = {
501 { S_IFREG, "S_IFREG" },
502 { S_IFSOCK, "S_IFSOCK" },
503 { S_IFIFO, "S_IFIFO" },
504 { S_IFLNK, "S_IFLNK" },
505 { S_IFDIR, "S_IFDIR" },
506 { S_IFBLK, "S_IFBLK" },
507 { S_IFCHR, "S_IFCHR" },
508 { 0, NULL },
509};
510
511static char *
512sprintmode(mode)
513int mode;
514{
515 static char buf[64];
516 char *s;
517
518 if ((mode & S_IFMT) == 0)
519 s = "";
520 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
521 sprintf(buf, "%#o", mode);
522 return buf;
523 }
524 sprintf(buf, "%s%s%s%s", s,
525 (mode & S_ISUID) ? "|S_ISUID" : "",
526 (mode & S_ISGID) ? "|S_ISGID" : "",
527 (mode & S_ISVTX) ? "|S_ISVTX" : "");
528 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
529 if (mode)
530 sprintf(buf + strlen(buf), "|%#o", mode);
531 s = (*buf == '|') ? buf + 1 : buf;
532 return *s ? s : "0";
533}
534
535static char *
536sprinttime(t)
537time_t t;
538{
539 struct tm *tmp;
540 static char buf[32];
541
542 if (t == 0) {
543 sprintf(buf, "0");
544 return buf;
545 }
546 tmp = localtime(&t);
547 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000548 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
550 return buf;
551}
552
553#ifdef LINUXSPARC
554typedef struct {
555 int tv_sec;
556 int tv_nsec;
557} timestruct_t;
558
559struct solstat {
560 unsigned st_dev;
561 int st_pad1[3]; /* network id */
562 unsigned st_ino;
563 unsigned st_mode;
564 unsigned st_nlink;
565 unsigned st_uid;
566 unsigned st_gid;
567 unsigned st_rdev;
568 int st_pad2[2];
569 int st_size;
570 int st_pad3; /* st_size, off_t expansion */
571 timestruct_t st_atime;
572 timestruct_t st_mtime;
573 timestruct_t st_ctime;
574 int st_blksize;
575 int st_blocks;
576 char st_fstype[16];
577 int st_pad4[8]; /* expansion area */
578};
579
580static void
581printstatsol(tcp, addr)
582struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000583long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584{
585 struct solstat statbuf;
586
587 if (!addr) {
588 tprintf("NULL");
589 return;
590 }
591 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000592 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593 return;
594 }
595 if (umove(tcp, addr, &statbuf) < 0) {
596 tprintf("{...}");
597 return;
598 }
599 if (!abbrev(tcp)) {
600 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
601 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
602 (unsigned long) (statbuf.st_dev & 0x3ffff),
603 (unsigned long) statbuf.st_ino,
604 sprintmode(statbuf.st_mode));
605 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
606 (unsigned long) statbuf.st_nlink,
607 (unsigned long) statbuf.st_uid,
608 (unsigned long) statbuf.st_gid);
609 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
610 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
611 }
612 else
613 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
614 switch (statbuf.st_mode & S_IFMT) {
615 case S_IFCHR: case S_IFBLK:
616 tprintf("st_rdev=makedev(%lu, %lu), ",
617 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
618 (unsigned long) (statbuf.st_rdev & 0x3ffff));
619 break;
620 default:
621 tprintf("st_size=%u, ", statbuf.st_size);
622 break;
623 }
624 if (!abbrev(tcp)) {
625 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
626 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
627 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
628 }
629 else
630 tprintf("...}");
631}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000632#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633
Michal Ludvig53b320f2002-09-23 13:30:09 +0000634struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000635#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000636 { UF_NODUMP, "UF_NODUMP" },
637 { UF_IMMUTABLE, "UF_IMMUTABLE" },
638 { UF_APPEND, "UF_APPEND" },
639 { UF_OPAQUE, "UF_OPAQUE" },
640 { UF_NOUNLINK, "UF_NOUNLINK" },
641 { SF_ARCHIVED, "SF_ARCHIVED" },
642 { SF_IMMUTABLE, "SF_IMMUTABLE" },
643 { SF_APPEND, "SF_APPEND" },
644 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000645#elif UNIXWARE >= 2
646#ifdef _S_ISMLD
647 { _S_ISMLD, "_S_ISMLD" },
648#endif
649#ifdef _S_ISMOUNTED
650 { _S_ISMOUNTED, "_S_ISMOUNTED" },
651#endif
652#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000653 { 0, NULL },
654};
655
John Hughesc0fc3fd2001-03-08 16:10:40 +0000656#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000657int
658sys_chflags(tcp)
659struct tcb *tcp;
660{
661 if (entering(tcp)) {
662 printpath(tcp, tcp->u_arg[0]);
663 tprintf(", ");
664 if (tcp->u_arg[1])
665 printflags(fileflags, tcp->u_arg[1]);
666 else
667 tprintf("0");
668 }
669 return 0;
670}
671
672int
673sys_fchflags(tcp)
674struct tcb *tcp;
675{
676 if (entering(tcp)) {
677 tprintf("%ld, ", tcp->u_arg[0]);
678 if (tcp->u_arg[1])
679 printflags(fileflags, tcp->u_arg[1]);
680 else
681 tprintf("0");
682 }
683 return 0;
684}
685#endif
686
John Hughes70623be2001-03-08 13:59:00 +0000687#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000688static void
689realprintstat(tcp, statbuf)
690struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000691struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000692{
693 if (!abbrev(tcp)) {
694 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
695 (unsigned long) major(statbuf->st_dev),
696 (unsigned long) minor(statbuf->st_dev),
697 (unsigned long) statbuf->st_ino,
698 sprintmode(statbuf->st_mode));
699 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
700 (unsigned long) statbuf->st_nlink,
701 (unsigned long) statbuf->st_uid,
702 (unsigned long) statbuf->st_gid);
703#ifdef HAVE_ST_BLKSIZE
704 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
705#endif /* HAVE_ST_BLKSIZE */
706#ifdef HAVE_ST_BLOCKS
707 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
708#endif /* HAVE_ST_BLOCKS */
709 }
710 else
711 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
712 switch (statbuf->st_mode & S_IFMT) {
713 case S_IFCHR: case S_IFBLK:
714#ifdef HAVE_ST_RDEV
715 tprintf("st_rdev=makedev(%lu, %lu), ",
716 (unsigned long) major(statbuf->st_rdev),
717 (unsigned long) minor(statbuf->st_rdev));
718#else /* !HAVE_ST_RDEV */
719 tprintf("st_size=makedev(%lu, %lu), ",
720 (unsigned long) major(statbuf->st_size),
721 (unsigned long) minor(statbuf->st_size));
722#endif /* !HAVE_ST_RDEV */
723 break;
724 default:
725 tprintf("st_size=%lu, ", statbuf->st_size);
726 break;
727 }
728 if (!abbrev(tcp)) {
729 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
730 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000731 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
732#if HAVE_ST_FLAGS
733 tprintf(", st_flags=");
734 if (statbuf->st_flags) {
735 printflags(fileflags, statbuf->st_flags);
736 } else
737 tprintf("0");
738#endif
739#if HAVE_ST_ACLCNT
740 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
741#endif
742#if HAVE_ST_LEVEL
743 tprintf(", st_level=%ld", statbuf->st_level);
744#endif
745#if HAVE_ST_FSTYPE
746 tprintf(", st_fstype=%.*s",
747 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
748#endif
749#if HAVE_ST_GEN
750 tprintf(", st_gen=%u", statbuf->st_gen);
751#endif
752 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000753 }
754 else
755 tprintf("...}");
756}
757
Nate Sammons771a6ff1999-04-05 22:39:31 +0000758
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759static void
760printstat(tcp, addr)
761struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000762long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000764 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765
766#ifdef LINUXSPARC
767 if (current_personality == 1) {
768 printstatsol(tcp, addr);
769 return;
770 }
771#endif /* LINUXSPARC */
772
773 if (!addr) {
774 tprintf("NULL");
775 return;
776 }
777 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000778 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779 return;
780 }
781 if (umove(tcp, addr, &statbuf) < 0) {
782 tprintf("{...}");
783 return;
784 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000785
786 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000787}
John Hughes70623be2001-03-08 13:59:00 +0000788#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789
Wichert Akkermanc7926982000-04-10 22:22:31 +0000790#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000791static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000792printstat64(tcp, addr)
793struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000794long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000795{
796 struct stat64 statbuf;
797
798#ifdef LINUXSPARC
799 if (current_personality == 1) {
800 printstatsol(tcp, addr);
801 return;
802 }
803#endif /* LINUXSPARC */
804
805 if (!addr) {
806 tprintf("NULL");
807 return;
808 }
809 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000810 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000811 return;
812 }
813 if (umove(tcp, addr, &statbuf) < 0) {
814 tprintf("{...}");
815 return;
816 }
817
818 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000819#ifdef HAVE_LONG_LONG
820 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
821#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000822 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000823#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000824 (unsigned long) major(statbuf.st_dev),
825 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000826#ifdef HAVE_LONG_LONG
827 (unsigned long long) statbuf.st_ino,
828#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000829 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000830#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000831 sprintmode(statbuf.st_mode));
832 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
833 (unsigned long) statbuf.st_nlink,
834 (unsigned long) statbuf.st_uid,
835 (unsigned long) statbuf.st_gid);
836#ifdef HAVE_ST_BLKSIZE
837 tprintf("st_blksize=%lu, ",
838 (unsigned long) statbuf.st_blksize);
839#endif /* HAVE_ST_BLKSIZE */
840#ifdef HAVE_ST_BLOCKS
841 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
842#endif /* HAVE_ST_BLOCKS */
843 }
844 else
845 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
846 switch (statbuf.st_mode & S_IFMT) {
847 case S_IFCHR: case S_IFBLK:
848#ifdef HAVE_ST_RDEV
849 tprintf("st_rdev=makedev(%lu, %lu), ",
850 (unsigned long) major(statbuf.st_rdev),
851 (unsigned long) minor(statbuf.st_rdev));
852#else /* !HAVE_ST_RDEV */
853 tprintf("st_size=makedev(%lu, %lu), ",
854 (unsigned long) major(statbuf.st_size),
855 (unsigned long) minor(statbuf.st_size));
856#endif /* !HAVE_ST_RDEV */
857 break;
858 default:
859 tprintf("st_size=%llu, ", statbuf.st_size);
860 break;
861 }
862 if (!abbrev(tcp)) {
863 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
864 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000865 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
866#if HAVE_ST_FLAGS
867 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000868 if (statbuf.st_flags) {
869 printflags(fileflags, statbuf.st_flags);
870 } else
871 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000872#endif
873#if HAVE_ST_ACLCNT
874 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
875#endif
876#if HAVE_ST_LEVEL
877 tprintf(", st_level=%ld", statbuf.st_level);
878#endif
879#if HAVE_ST_FSTYPE
880 tprintf(", st_fstype=%.*s",
881 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
882#endif
883#if HAVE_ST_GEN
884 tprintf(", st_gen=%u", statbuf.st_gen);
885#endif
886 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000887 }
888 else
889 tprintf("...}");
890}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000891#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000892
Michal Ludvig10a88d02002-10-07 14:31:00 +0000893#if defined(LINUX) && !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
894 && !defined(S390) && !defined(S390X)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000895static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000896convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000897const struct __old_kernel_stat *oldbuf;
898struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000899{
900 newbuf->st_dev=oldbuf->st_dev;
901 newbuf->st_ino=oldbuf->st_ino;
902 newbuf->st_mode=oldbuf->st_mode;
903 newbuf->st_nlink=oldbuf->st_nlink;
904 newbuf->st_uid=oldbuf->st_uid;
905 newbuf->st_gid=oldbuf->st_gid;
906 newbuf->st_rdev=oldbuf->st_rdev;
907 newbuf->st_size=oldbuf->st_size;
908 newbuf->st_atime=oldbuf->st_atime;
909 newbuf->st_mtime=oldbuf->st_mtime;
910 newbuf->st_ctime=oldbuf->st_ctime;
911 newbuf->st_blksize=0; /* not supported in old_stat */
912 newbuf->st_blocks=0; /* not supported in old_stat */
913}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000914
915
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000916static void
917printoldstat(tcp, addr)
918struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000919long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000920{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000921 struct __old_kernel_stat statbuf;
922 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000923
924#ifdef LINUXSPARC
925 if (current_personality == 1) {
926 printstatsol(tcp, addr);
927 return;
928 }
929#endif /* LINUXSPARC */
930
931 if (!addr) {
932 tprintf("NULL");
933 return;
934 }
935 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000936 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000937 return;
938 }
939 if (umove(tcp, addr, &statbuf) < 0) {
940 tprintf("{...}");
941 return;
942 }
943
944 convertoldstat(&statbuf, &newstatbuf);
945 realprintstat(tcp, &newstatbuf);
946}
Michal Ludvig10a88d02002-10-07 14:31:00 +0000947#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000948
John Hughes70623be2001-03-08 13:59:00 +0000949#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950int
951sys_stat(tcp)
952struct tcb *tcp;
953{
954 if (entering(tcp)) {
955 printpath(tcp, tcp->u_arg[0]);
956 tprintf(", ");
957 } else {
958 printstat(tcp, tcp->u_arg[1]);
959 }
960 return 0;
961}
John Hughesb8c9f772001-03-07 16:53:07 +0000962#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000964int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000965sys_stat64(tcp)
966struct tcb *tcp;
967{
968#ifdef HAVE_STAT64
969 if (entering(tcp)) {
970 printpath(tcp, tcp->u_arg[0]);
971 tprintf(", ");
972 } else {
973 printstat64(tcp, tcp->u_arg[1]);
974 }
975 return 0;
976#else
977 return printargs(tcp);
978#endif
979}
980
Michal Ludvig53b320f2002-09-23 13:30:09 +0000981#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +0000982# if !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
983 && !defined(S390) && !defined(S390X)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000984int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000985sys_oldstat(tcp)
986struct tcb *tcp;
987{
988 if (entering(tcp)) {
989 printpath(tcp, tcp->u_arg[0]);
990 tprintf(", ");
991 } else {
992 printoldstat(tcp, tcp->u_arg[1]);
993 }
994 return 0;
995}
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000996# endif /* !IA64 && !HPPA*/
Michal Ludvig53b320f2002-09-23 13:30:09 +0000997#endif /* LINUX */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000998
John Hughes70623be2001-03-08 13:59:00 +0000999#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000int
1001sys_fstat(tcp)
1002struct tcb *tcp;
1003{
1004 if (entering(tcp))
1005 tprintf("%ld, ", tcp->u_arg[0]);
1006 else {
1007 printstat(tcp, tcp->u_arg[1]);
1008 }
1009 return 0;
1010}
John Hughesb8c9f772001-03-07 16:53:07 +00001011#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001013int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001014sys_fstat64(tcp)
1015struct tcb *tcp;
1016{
1017#ifdef HAVE_STAT64
1018 if (entering(tcp))
1019 tprintf("%ld, ", tcp->u_arg[0]);
1020 else {
1021 printstat64(tcp, tcp->u_arg[1]);
1022 }
1023 return 0;
1024#else
1025 return printargs(tcp);
1026#endif
1027}
1028
Michal Ludvig53b320f2002-09-23 13:30:09 +00001029#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00001030# if !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
1031 && !defined(S390) && !defined(S390X)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001032int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001033sys_oldfstat(tcp)
1034struct tcb *tcp;
1035{
1036 if (entering(tcp))
1037 tprintf("%ld, ", tcp->u_arg[0]);
1038 else {
1039 printoldstat(tcp, tcp->u_arg[1]);
1040 }
1041 return 0;
1042}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001043# endif /* !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001044#endif
1045
John Hughes70623be2001-03-08 13:59:00 +00001046#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047int
1048sys_lstat(tcp)
1049struct tcb *tcp;
1050{
1051 if (entering(tcp)) {
1052 printpath(tcp, tcp->u_arg[0]);
1053 tprintf(", ");
1054 } else {
1055 printstat(tcp, tcp->u_arg[1]);
1056 }
1057 return 0;
1058}
John Hughesb8c9f772001-03-07 16:53:07 +00001059#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001061int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001062sys_lstat64(tcp)
1063struct tcb *tcp;
1064{
1065#ifdef HAVE_STAT64
1066 if (entering(tcp)) {
1067 printpath(tcp, tcp->u_arg[0]);
1068 tprintf(", ");
1069 } else {
1070 printstat64(tcp, tcp->u_arg[1]);
1071 }
1072 return 0;
1073#else
1074 return printargs(tcp);
1075#endif
1076}
1077
Michal Ludvig53b320f2002-09-23 13:30:09 +00001078#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00001079# if !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
1080 && !defined(S390) && !defined(S390X)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001081int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001082sys_oldlstat(tcp)
1083struct tcb *tcp;
1084{
1085 if (entering(tcp)) {
1086 printpath(tcp, tcp->u_arg[0]);
1087 tprintf(", ");
1088 } else {
1089 printoldstat(tcp, tcp->u_arg[1]);
1090 }
1091 return 0;
1092}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001093# endif /* !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001094#endif
1095
1096
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001097#if defined(SVR4) || defined(LINUXSPARC)
1098
1099int
1100sys_xstat(tcp)
1101struct tcb *tcp;
1102{
1103 if (entering(tcp)) {
1104 tprintf("%ld, ", tcp->u_arg[0]);
1105 printpath(tcp, tcp->u_arg[1]);
1106 tprintf(", ");
1107 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001108#ifdef _STAT64_VER
1109 if (tcp->u_arg[0] == _STAT64_VER)
1110 printstat64 (tcp, tcp->u_arg[2]);
1111 else
1112#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001113 printstat(tcp, tcp->u_arg[2]);
1114 }
1115 return 0;
1116}
1117
1118int
1119sys_fxstat(tcp)
1120struct tcb *tcp;
1121{
1122 if (entering(tcp))
1123 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1124 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001125#ifdef _STAT64_VER
1126 if (tcp->u_arg[0] == _STAT64_VER)
1127 printstat64 (tcp, tcp->u_arg[2]);
1128 else
1129#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130 printstat(tcp, tcp->u_arg[2]);
1131 }
1132 return 0;
1133}
1134
1135int
1136sys_lxstat(tcp)
1137struct tcb *tcp;
1138{
1139 if (entering(tcp)) {
1140 tprintf("%ld, ", tcp->u_arg[0]);
1141 printpath(tcp, tcp->u_arg[1]);
1142 tprintf(", ");
1143 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001144#ifdef _STAT64_VER
1145 if (tcp->u_arg[0] == _STAT64_VER)
1146 printstat64 (tcp, tcp->u_arg[2]);
1147 else
1148#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001149 printstat(tcp, tcp->u_arg[2]);
1150 }
1151 return 0;
1152}
1153
1154int
1155sys_xmknod(tcp)
1156struct tcb *tcp;
1157{
1158 int mode = tcp->u_arg[2];
1159
1160 if (entering(tcp)) {
1161 tprintf("%ld, ", tcp->u_arg[0]);
1162 printpath(tcp, tcp->u_arg[1]);
1163 tprintf(", %s", sprintmode(mode));
1164 switch (mode & S_IFMT) {
1165 case S_IFCHR: case S_IFBLK:
1166#ifdef LINUXSPARC
1167 tprintf(", makedev(%lu, %lu)",
1168 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1169 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1170#else
1171 tprintf(", makedev(%lu, %lu)",
1172 (unsigned long) major(tcp->u_arg[3]),
1173 (unsigned long) minor(tcp->u_arg[3]));
1174#endif
1175 break;
1176 default:
1177 break;
1178 }
1179 }
1180 return 0;
1181}
1182
Wichert Akkerman8829a551999-06-11 13:18:40 +00001183#ifdef HAVE_SYS_ACL_H
1184
1185#include <sys/acl.h>
1186
1187struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001188#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001189 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001190#endif
1191#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001192 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001193#endif
1194#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001195 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001196#endif
1197#ifdef ACL_GET
1198 { ACL_GET, "ACL_GET" },
1199#endif
1200#ifdef ACL_SET
1201 { ACL_SET, "ACL_SET" },
1202#endif
1203#ifdef ACL_CNT
1204 { ACL_CNT, "ACL_CNT" },
1205#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001206 { 0, NULL },
1207};
1208
1209int
1210sys_acl(tcp)
1211struct tcb *tcp;
1212{
1213 if (entering(tcp)) {
1214 printpath(tcp, tcp->u_arg[0]);
1215 tprintf(", ");
1216 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1217 tprintf(", %ld", tcp->u_arg[2]);
1218 /*
1219 * FIXME - dump out the list of aclent_t's pointed to
1220 * by "tcp->u_arg[3]" if it's not NULL.
1221 */
1222 if (tcp->u_arg[3])
1223 tprintf(", %#lx", tcp->u_arg[3]);
1224 else
1225 tprintf(", NULL");
1226 }
1227 return 0;
1228}
1229
1230
1231int
1232sys_facl(tcp)
1233struct tcb *tcp;
1234{
1235 if (entering(tcp)) {
1236 tprintf("%ld, ", tcp->u_arg[0]);
1237 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1238 tprintf(", %ld", tcp->u_arg[2]);
1239 /*
1240 * FIXME - dump out the list of aclent_t's pointed to
1241 * by "tcp->u_arg[3]" if it's not NULL.
1242 */
1243 if (tcp->u_arg[3])
1244 tprintf(", %#lx", tcp->u_arg[3]);
1245 else
1246 tprintf(", NULL");
1247 }
1248 return 0;
1249}
1250
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001251
1252struct xlat aclipc[] = {
1253#ifdef IPC_SHM
1254 { IPC_SHM, "IPC_SHM" },
1255#endif
1256#ifdef IPC_SEM
1257 { IPC_SEM, "IPC_SEM" },
1258#endif
1259#ifdef IPC_MSG
1260 { IPC_MSG, "IPC_MSG" },
1261#endif
1262 { 0, NULL },
1263};
1264
1265
1266int
1267sys_aclipc(tcp)
1268struct tcb *tcp;
1269{
1270 if (entering(tcp)) {
1271 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1272 tprintf(", %#lx, ", tcp->u_arg[1]);
1273 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1274 tprintf(", %ld", tcp->u_arg[3]);
1275 /*
1276 * FIXME - dump out the list of aclent_t's pointed to
1277 * by "tcp->u_arg[4]" if it's not NULL.
1278 */
1279 if (tcp->u_arg[4])
1280 tprintf(", %#lx", tcp->u_arg[4]);
1281 else
1282 tprintf(", NULL");
1283 }
1284 return 0;
1285}
1286
1287
1288
Wichert Akkerman8829a551999-06-11 13:18:40 +00001289#endif /* HAVE_SYS_ACL_H */
1290
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001291#endif /* SVR4 || LINUXSPARC */
1292
Michal Ludvig53b320f2002-09-23 13:30:09 +00001293#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294
1295static struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001296 { 0x73757245, "CODA_SUPER_MAGIC" },
1297 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1298 { 0x1373, "DEVFS_SUPER_MAGIC" },
1299 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1300 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1302 { 0xef53, "EXT2_SUPER_MAGIC" },
1303 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001304 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 { 0x9660, "ISOFS_SUPER_MAGIC" },
1306 { 0x137f, "MINIX_SUPER_MAGIC" },
1307 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001308 { 0x2468, "MINIX2_SUPER_MAGIC" },
1309 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001310 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001311 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312 { 0x6969, "NFS_SUPER_MAGIC" },
1313 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001314 { 0x002f, "QNX4_SUPER_MAGIC" },
1315 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1316 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1317 { 0x517b, "SMB_SUPER_MAGIC" },
1318 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1319 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1320 { 0x00011954, "UFS_MAGIC" },
1321 { 0x54190100, "UFS_CIGAM" },
1322 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1324 { 0, NULL },
1325};
1326
Michal Ludvig53b320f2002-09-23 13:30:09 +00001327#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328
1329#ifndef SVR4
1330
1331static char *
1332sprintfstype(magic)
1333int magic;
1334{
1335 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001336#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001337 char *s;
1338
1339 s = xlookup(fsmagic, magic);
1340 if (s) {
1341 sprintf(buf, "\"%s\"", s);
1342 return buf;
1343 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001344#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001345 sprintf(buf, "%#x", magic);
1346 return buf;
1347}
1348
1349static void
1350printstatfs(tcp, addr)
1351struct tcb *tcp;
1352long addr;
1353{
1354 struct statfs statbuf;
1355
1356 if (syserror(tcp) || !verbose(tcp)) {
1357 tprintf("%#lx", addr);
1358 return;
1359 }
1360 if (umove(tcp, addr, &statbuf) < 0) {
1361 tprintf("{...}");
1362 return;
1363 }
1364#ifdef ALPHA
1365
1366 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1367 sprintfstype(statbuf.f_type),
1368 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001369 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001370 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1371#else /* !ALPHA */
1372 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1373 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001374 (unsigned long)statbuf.f_bsize,
1375 (unsigned long)statbuf.f_blocks,
1376 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001378 (unsigned long)statbuf.f_files,
1379 (unsigned long)statbuf.f_ffree);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001380#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001381 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001382#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383#endif /* !ALPHA */
1384 tprintf("}");
1385}
1386
1387int
1388sys_statfs(tcp)
1389struct tcb *tcp;
1390{
1391 if (entering(tcp)) {
1392 printpath(tcp, tcp->u_arg[0]);
1393 tprintf(", ");
1394 } else {
1395 printstatfs(tcp, tcp->u_arg[1]);
1396 }
1397 return 0;
1398}
1399
1400int
1401sys_fstatfs(tcp)
1402struct tcb *tcp;
1403{
1404 if (entering(tcp)) {
1405 tprintf("%lu, ", tcp->u_arg[0]);
1406 } else {
1407 printstatfs(tcp, tcp->u_arg[1]);
1408 }
1409 return 0;
1410}
1411
Michal Ludvig53b320f2002-09-23 13:30:09 +00001412#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413
1414int
1415osf_statfs(tcp)
1416struct tcb *tcp;
1417{
1418 if (entering(tcp)) {
1419 printpath(tcp, tcp->u_arg[0]);
1420 tprintf(", ");
1421 } else {
1422 printstatfs(tcp, tcp->u_arg[1]);
1423 tprintf(", %lu", tcp->u_arg[2]);
1424 }
1425 return 0;
1426}
1427
1428int
1429osf_fstatfs(tcp)
1430struct tcb *tcp;
1431{
1432 if (entering(tcp)) {
1433 tprintf("%lu, ", tcp->u_arg[0]);
1434 } else {
1435 printstatfs(tcp, tcp->u_arg[1]);
1436 tprintf(", %lu", tcp->u_arg[2]);
1437 }
1438 return 0;
1439}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001440#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441
1442#endif /* !SVR4 */
1443
1444#ifdef SUNOS4
1445
1446int
1447sys_ustat(tcp)
1448struct tcb *tcp;
1449{
1450 struct ustat statbuf;
1451
1452 if (entering(tcp)) {
1453 tprintf("makedev(%lu, %lu), ",
1454 (long) major(tcp->u_arg[0]),
1455 (long) minor(tcp->u_arg[0]));
1456 }
1457 else {
1458 if (syserror(tcp) || !verbose(tcp))
1459 tprintf("%#lx", tcp->u_arg[1]);
1460 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1461 tprintf("{...}");
1462 else {
1463 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1464 statbuf.f_tfree, statbuf.f_tinode);
1465 tprintf("f_fname=\"%.*s\", ",
1466 (int) sizeof(statbuf.f_fname),
1467 statbuf.f_fname);
1468 tprintf("f_fpack=\"%.*s\"}",
1469 (int) sizeof(statbuf.f_fpack),
1470 statbuf.f_fpack);
1471 }
1472 }
1473 return 0;
1474}
1475
1476#endif /* SUNOS4 */
1477
Wichert Akkermanc7926982000-04-10 22:22:31 +00001478int
1479sys_pivotroot(tcp)
1480struct tcb *tcp;
1481{
1482 if (entering(tcp)) {
1483 printpath(tcp, tcp->u_arg[0]);
1484 tprintf(", ");
1485 printpath(tcp, tcp->u_arg[1]);
1486 }
1487 return 0;
1488}
1489
1490
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001491/* directory */
1492int
1493sys_chdir(tcp)
1494struct tcb *tcp;
1495{
1496 if (entering(tcp)) {
1497 printpath(tcp, tcp->u_arg[0]);
1498 }
1499 return 0;
1500}
1501
1502int
1503sys_mkdir(tcp)
1504struct tcb *tcp;
1505{
1506 if (entering(tcp)) {
1507 printpath(tcp, tcp->u_arg[0]);
1508 tprintf(", %#lo", tcp->u_arg[1]);
1509 }
1510 return 0;
1511}
1512
1513int
1514sys_rmdir(tcp)
1515struct tcb *tcp;
1516{
1517 if (entering(tcp)) {
1518 printpath(tcp, tcp->u_arg[0]);
1519 }
1520 return 0;
1521}
1522
1523int
1524sys_fchdir(tcp)
1525struct tcb *tcp;
1526{
1527 if (entering(tcp)) {
1528 tprintf("%ld", tcp->u_arg[0]);
1529 }
1530 return 0;
1531}
1532
1533int
1534sys_chroot(tcp)
1535struct tcb *tcp;
1536{
1537 if (entering(tcp)) {
1538 printpath(tcp, tcp->u_arg[0]);
1539 }
1540 return 0;
1541}
1542
1543int
1544sys_fchroot(tcp)
1545struct tcb *tcp;
1546{
1547 if (entering(tcp)) {
1548 tprintf("%ld", tcp->u_arg[0]);
1549 }
1550 return 0;
1551}
1552
1553int
1554sys_link(tcp)
1555struct tcb *tcp;
1556{
1557 if (entering(tcp)) {
1558 printpath(tcp, tcp->u_arg[0]);
1559 tprintf(", ");
1560 printpath(tcp, tcp->u_arg[1]);
1561 }
1562 return 0;
1563}
1564
1565int
1566sys_unlink(tcp)
1567struct tcb *tcp;
1568{
1569 if (entering(tcp)) {
1570 printpath(tcp, tcp->u_arg[0]);
1571 }
1572 return 0;
1573}
1574
1575int
1576sys_symlink(tcp)
1577struct tcb *tcp;
1578{
1579 if (entering(tcp)) {
1580 printpath(tcp, tcp->u_arg[0]);
1581 tprintf(", ");
1582 printpath(tcp, tcp->u_arg[1]);
1583 }
1584 return 0;
1585}
1586
1587int
1588sys_readlink(tcp)
1589struct tcb *tcp;
1590{
1591 if (entering(tcp)) {
1592 printpath(tcp, tcp->u_arg[0]);
1593 tprintf(", ");
1594 } else {
1595 if (syserror(tcp))
1596 tprintf("%#lx", tcp->u_arg[1]);
1597 else
1598 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1599 tprintf(", %lu", tcp->u_arg[2]);
1600 }
1601 return 0;
1602}
1603
1604int
1605sys_rename(tcp)
1606struct tcb *tcp;
1607{
1608 if (entering(tcp)) {
1609 printpath(tcp, tcp->u_arg[0]);
1610 tprintf(", ");
1611 printpath(tcp, tcp->u_arg[1]);
1612 }
1613 return 0;
1614}
1615
1616int
1617sys_chown(tcp)
1618struct tcb *tcp;
1619{
1620 if (entering(tcp)) {
1621 printpath(tcp, tcp->u_arg[0]);
1622 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1623 }
1624 return 0;
1625}
1626
1627int
1628sys_fchown(tcp)
1629struct tcb *tcp;
1630{
1631 if (entering(tcp)) {
1632 tprintf("%ld, %lu, %lu",
1633 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1634 }
1635 return 0;
1636}
1637
1638int
1639sys_chmod(tcp)
1640struct tcb *tcp;
1641{
1642 if (entering(tcp)) {
1643 printpath(tcp, tcp->u_arg[0]);
1644 tprintf(", %#lo", tcp->u_arg[1]);
1645 }
1646 return 0;
1647}
1648
1649int
1650sys_fchmod(tcp)
1651struct tcb *tcp;
1652{
1653 if (entering(tcp)) {
1654 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1655 }
1656 return 0;
1657}
1658
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001659#ifdef ALPHA
1660int
1661sys_osf_utimes(tcp)
1662struct tcb *tcp;
1663{
1664 if (entering(tcp)) {
1665 printpath(tcp, tcp->u_arg[0]);
1666 tprintf(", ");
1667 printtv32(tcp, tcp->u_arg[1]);
1668 }
1669 return 0;
1670}
1671#endif
1672
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673int
1674sys_utimes(tcp)
1675struct tcb *tcp;
1676{
1677 if (entering(tcp)) {
1678 printpath(tcp, tcp->u_arg[0]);
1679 tprintf(", ");
1680 printtv(tcp, tcp->u_arg[1]);
1681 }
1682 return 0;
1683}
1684
1685int
1686sys_utime(tcp)
1687struct tcb *tcp;
1688{
1689 long ut[2];
1690
1691 if (entering(tcp)) {
1692 printpath(tcp, tcp->u_arg[0]);
1693 tprintf(", ");
1694 if (!tcp->u_arg[1])
1695 tprintf("NULL");
1696 else if (!verbose(tcp))
1697 tprintf("%#lx", tcp->u_arg[1]);
1698 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1699 (char *) ut) < 0)
1700 tprintf("[?, ?]");
1701 else {
1702 tprintf("[%s,", sprinttime(ut[0]));
1703 tprintf(" %s]", sprinttime(ut[1]));
1704 }
1705 }
1706 return 0;
1707}
1708
1709int
1710sys_mknod(tcp)
1711struct tcb *tcp;
1712{
1713 int mode = tcp->u_arg[1];
1714
1715 if (entering(tcp)) {
1716 printpath(tcp, tcp->u_arg[0]);
1717 tprintf(", %s", sprintmode(mode));
1718 switch (mode & S_IFMT) {
1719 case S_IFCHR: case S_IFBLK:
1720#ifdef LINUXSPARC
1721 if (current_personality == 1)
1722 tprintf(", makedev(%lu, %lu)",
1723 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1724 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1725 else
1726#endif
1727 tprintf(", makedev(%lu, %lu)",
1728 (unsigned long) major(tcp->u_arg[2]),
1729 (unsigned long) minor(tcp->u_arg[2]));
1730 break;
1731 default:
1732 break;
1733 }
1734 }
1735 return 0;
1736}
1737
1738int
1739sys_mkfifo(tcp)
1740struct tcb *tcp;
1741{
1742 if (entering(tcp)) {
1743 printpath(tcp, tcp->u_arg[0]);
1744 tprintf(", %#lo", tcp->u_arg[1]);
1745 }
1746 return 0;
1747}
1748
1749int
1750sys_fsync(tcp)
1751struct tcb *tcp;
1752{
1753 if (entering(tcp)) {
1754 tprintf("%ld", tcp->u_arg[0]);
1755 }
1756 return 0;
1757}
1758
Michal Ludvig53b320f2002-09-23 13:30:09 +00001759#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760
1761static void
1762printdir(tcp, addr)
1763struct tcb *tcp;
1764long addr;
1765{
1766 struct dirent d;
1767
1768 if (!verbose(tcp)) {
1769 tprintf("%#lx", addr);
1770 return;
1771 }
1772 if (umove(tcp, addr, &d) < 0) {
1773 tprintf("{...}");
1774 return;
1775 }
1776 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777 tprintf("d_name=");
1778 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1779 tprintf("}");
1780}
1781
1782int
1783sys_readdir(tcp)
1784struct tcb *tcp;
1785{
1786 if (entering(tcp)) {
1787 tprintf("%lu, ", tcp->u_arg[0]);
1788 } else {
1789 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1790 tprintf("%#lx", tcp->u_arg[1]);
1791 else
1792 printdir(tcp, tcp->u_arg[1]);
1793 /* Not much point in printing this out, it is always 1. */
1794 if (tcp->u_arg[2] != 1)
1795 tprintf(", %lu", tcp->u_arg[2]);
1796 }
1797 return 0;
1798}
1799
Michal Ludvig53b320f2002-09-23 13:30:09 +00001800#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001802#ifdef FREEBSD
1803struct xlat direnttypes[] = {
1804 { DT_FIFO, "DT_FIFO" },
1805 { DT_CHR, "DT_CHR" },
1806 { DT_DIR, "DT_DIR" },
1807 { DT_BLK, "DT_BLK" },
1808 { DT_REG, "DT_REG" },
1809 { DT_LNK, "DT_LNK" },
1810 { DT_SOCK, "DT_SOCK" },
1811 { DT_WHT, "DT_WHT" },
1812 { 0, NULL },
1813};
1814
1815#endif
1816
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817int
1818sys_getdents(tcp)
1819struct tcb *tcp;
1820{
1821 int i, len, dents = 0;
1822 char *buf;
1823
1824 if (entering(tcp)) {
1825 tprintf("%lu, ", tcp->u_arg[0]);
1826 return 0;
1827 }
1828 if (syserror(tcp) || !verbose(tcp)) {
1829 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1830 return 0;
1831 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832 len = tcp->u_rval;
1833 if ((buf = malloc(len)) == NULL) {
1834 tprintf("out of memory\n");
1835 return 0;
1836 }
1837 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1838 tprintf("{...}, %lu", tcp->u_arg[2]);
1839 free(buf);
1840 return 0;
1841 }
1842 if (!abbrev(tcp))
1843 tprintf("{");
1844 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001845 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001846#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847 if (!abbrev(tcp)) {
1848 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1849 i ? " " : "", d->d_ino, d->d_off);
1850 tprintf("d_reclen=%u, d_name=\"%s\"}",
1851 d->d_reclen, d->d_name);
1852 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001853#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001854#ifdef SVR4
1855 if (!abbrev(tcp)) {
1856 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1857 i ? " " : "", d->d_ino, d->d_off);
1858 tprintf("d_reclen=%u, d_name=\"%s\"}",
1859 d->d_reclen, d->d_name);
1860 }
1861#endif /* SVR4 */
1862#ifdef SUNOS4
1863 if (!abbrev(tcp)) {
1864 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1865 i ? " " : "", d->d_off, d->d_fileno,
1866 d->d_reclen);
1867 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1868 d->d_namlen, d->d_namlen, d->d_name);
1869 }
1870#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001871#ifdef FREEBSD
1872 if (!abbrev(tcp)) {
1873 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1874 i ? " " : "", d->d_fileno, d->d_reclen);
1875 printxval(direnttypes, d->d_type, "DT_???");
1876 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1877 d->d_namlen, d->d_namlen, d->d_name);
1878 }
1879#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001880 if (!d->d_reclen) {
1881 tprintf("/* d_reclen == 0, problem here */");
1882 break;
1883 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884 i += d->d_reclen;
1885 dents++;
1886 }
1887 if (!abbrev(tcp))
1888 tprintf("}");
1889 else
1890 tprintf("/* %u entries */", dents);
1891 tprintf(", %lu", tcp->u_arg[2]);
1892 free(buf);
1893 return 0;
1894}
1895
John Hughesbdf48f52001-03-06 15:08:09 +00001896
1897#if _LFS64_LARGEFILE
1898int
1899sys_getdents64(tcp)
1900struct tcb *tcp;
1901{
1902 int i, len, dents = 0;
1903 char *buf;
1904
1905 if (entering(tcp)) {
1906 tprintf("%lu, ", tcp->u_arg[0]);
1907 return 0;
1908 }
1909 if (syserror(tcp) || !verbose(tcp)) {
1910 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1911 return 0;
1912 }
1913 len = tcp->u_rval;
1914 if ((buf = malloc(len)) == NULL) {
1915 tprintf("out of memory\n");
1916 return 0;
1917 }
1918 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1919 tprintf("{...}, %lu", tcp->u_arg[2]);
1920 free(buf);
1921 return 0;
1922 }
1923 if (!abbrev(tcp))
1924 tprintf("{");
1925 for (i = 0; i < len;) {
1926 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001927#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00001928 if (!abbrev(tcp)) {
1929 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Michal Ludvig53b320f2002-09-23 13:30:09 +00001930 i ? " " : "",
1931 (unsigned long)d->d_ino,
1932 (unsigned long)d->d_off);
John Hughesbdf48f52001-03-06 15:08:09 +00001933 tprintf("d_reclen=%u, d_name=\"%s\"}",
1934 d->d_reclen, d->d_name);
1935 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001936#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001937#ifdef SUNOS4
1938 if (!abbrev(tcp)) {
1939 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1940 i ? " " : "", d->d_off, d->d_fileno,
1941 d->d_reclen);
1942 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1943 d->d_namlen, d->d_namlen, d->d_name);
1944 }
1945#endif /* SUNOS4 */
1946 i += d->d_reclen;
1947 dents++;
1948 }
1949 if (!abbrev(tcp))
1950 tprintf("}");
1951 else
1952 tprintf("/* %u entries */", dents);
1953 tprintf(", %lu", tcp->u_arg[2]);
1954 free(buf);
1955 return 0;
1956}
1957#endif
1958
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001959#ifdef FREEBSD
1960int
1961sys_getdirentries(tcp)
1962struct tcb * tcp;
1963{
1964 int i, len, dents = 0;
1965 long basep;
1966 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001968 if (entering(tcp)) {
1969 tprintf("%lu, ", tcp->u_arg[0]);
1970 return 0;
1971 }
1972 if (syserror(tcp) || !verbose(tcp)) {
1973 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
1974 return 0;
1975 }
1976 len = tcp->u_rval;
1977 if ((buf = malloc(len)) == NULL) {
1978 tprintf("out of memory\n");
1979 return 0;
1980 }
1981 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1982 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
1983 free(buf);
1984 return 0;
1985 }
1986 if (!abbrev(tcp))
1987 tprintf("{");
1988 for (i = 0; i < len;) {
1989 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1990 if (!abbrev(tcp)) {
1991 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1992 i ? " " : "", d->d_fileno, d->d_reclen);
1993 printxval(direnttypes, d->d_type, "DT_???");
1994 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1995 d->d_namlen, d->d_namlen, d->d_name);
1996 }
1997 i += d->d_reclen;
1998 dents++;
1999 }
2000 if (!abbrev(tcp))
2001 tprintf("}");
2002 else
2003 tprintf("/* %u entries */", dents);
2004 free(buf);
2005 tprintf(", %lu", tcp->u_arg[2]);
2006 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2007 tprintf(", %#lx", tcp->u_arg[3]);
2008 else
2009 tprintf(", [%lu]", basep);
2010 return 0;
2011}
2012#endif
2013
Michal Ludvig53b320f2002-09-23 13:30:09 +00002014#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002015int
2016sys_getcwd(tcp)
2017struct tcb *tcp;
2018{
2019 if (exiting(tcp)) {
2020 if (syserror(tcp))
2021 tprintf("%#lx", tcp->u_arg[0]);
2022 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002023 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024 tprintf(", %lu", tcp->u_arg[1]);
2025 }
2026 return 0;
2027}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002028#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002029
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002030#ifdef FREEBSD
2031int
2032sys___getcwd(tcp)
2033struct tcb *tcp;
2034{
2035 if (exiting(tcp)) {
2036 if (syserror(tcp))
2037 tprintf("%#lx", tcp->u_arg[0]);
2038 else
2039 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2040 tprintf(", %lu", tcp->u_arg[1]);
2041 }
2042 return 0;
2043}
2044#endif
2045
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046#ifdef HAVE_SYS_ASYNCH_H
2047
2048int
2049sys_aioread(tcp)
2050struct tcb *tcp;
2051{
2052 struct aio_result_t res;
2053
2054 if (entering(tcp)) {
2055 tprintf("%lu, ", tcp->u_arg[0]);
2056 } else {
2057 if (syserror(tcp))
2058 tprintf("%#lx", tcp->u_arg[1]);
2059 else
2060 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2061 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2062 printxval(whence, tcp->u_arg[4], "L_???");
2063 if (syserror(tcp) || tcp->u_arg[5] == 0
2064 || umove(tcp, tcp->u_arg[5], &res) < 0)
2065 tprintf(", %#lx", tcp->u_arg[5]);
2066 else
2067 tprintf(", {aio_return %d aio_errno %d}",
2068 res.aio_return, res.aio_errno);
2069 }
2070 return 0;
2071}
2072
2073int
2074sys_aiowrite(tcp)
2075struct tcb *tcp;
2076{
2077 struct aio_result_t res;
2078
2079 if (entering(tcp)) {
2080 tprintf("%lu, ", tcp->u_arg[0]);
2081 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2082 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2083 printxval(whence, tcp->u_arg[4], "L_???");
2084 }
2085 else {
2086 if (tcp->u_arg[5] == 0)
2087 tprintf(", NULL");
2088 else if (syserror(tcp)
2089 || umove(tcp, tcp->u_arg[5], &res) < 0)
2090 tprintf(", %#lx", tcp->u_arg[5]);
2091 else
2092 tprintf(", {aio_return %d aio_errno %d}",
2093 res.aio_return, res.aio_errno);
2094 }
2095 return 0;
2096}
2097
2098int
2099sys_aiowait(tcp)
2100struct tcb *tcp;
2101{
2102 if (entering(tcp))
2103 printtv(tcp, tcp->u_arg[0]);
2104 return 0;
2105}
2106
2107int
2108sys_aiocancel(tcp)
2109struct tcb *tcp;
2110{
2111 struct aio_result_t res;
2112
2113 if (exiting(tcp)) {
2114 if (tcp->u_arg[0] == 0)
2115 tprintf("NULL");
2116 else if (syserror(tcp)
2117 || umove(tcp, tcp->u_arg[0], &res) < 0)
2118 tprintf("%#lx", tcp->u_arg[0]);
2119 else
2120 tprintf("{aio_return %d aio_errno %d}",
2121 res.aio_return, res.aio_errno);
2122 }
2123 return 0;
2124}
2125
2126#endif /* HAVE_SYS_ASYNCH_H */