blob: 6e6b30670e3d33efbe37ecc009e9837b7cadd5d5 [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};
Roland McGrath6d1a65c2004-07-12 07:44:08 +000069#if defined(SPARC64)
70struct stat_sparc64 {
71 unsigned int st_dev;
72 unsigned long st_ino;
73 unsigned int st_mode;
74 unsigned int st_nlink;
75 unsigned int st_uid;
76 unsigned int st_gid;
77 unsigned int st_rdev;
78 long st_size;
79 long st_atime;
80 long st_mtime;
81 long st_ctime;
82 long st_blksize;
83 long st_blocks;
84 unsigned long __unused4[2];
85};
86#endif /* SPARC64 */
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000087# define stat kernel_stat
88# include <asm/stat.h>
89# undef stat
90# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000091# undef dev_t
92# undef ino_t
93# undef mode_t
94# undef nlink_t
95# undef uid_t
96# undef gid_t
97# undef off_t
98# undef loff_t
99
Wichert Akkermana6013701999-07-08 14:00:58 +0000100# define dev_t __kernel_dev_t
101# define ino_t __kernel_ino_t
102# define mode_t __kernel_mode_t
103# define nlink_t __kernel_nlink_t
104# define uid_t __kernel_uid_t
105# define gid_t __kernel_gid_t
106# define off_t __kernel_off_t
107# define loff_t __kernel_loff_t
108
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000109# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000110
111# undef dev_t
112# undef ino_t
113# undef mode_t
114# undef nlink_t
115# undef uid_t
116# undef gid_t
117# undef off_t
118# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000119
120# define dev_t dev_t
121# define ino_t ino_t
122# define mode_t mode_t
123# define nlink_t nlink_t
124# define uid_t uid_t
125# define gid_t gid_t
126# define off_t off_t
127# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000128# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000129# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
130# undef stat64
131# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000132# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000133# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000134# include <sys/stat.h>
135# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000136# undef stat64
Roland McGrathca16a402003-01-09 06:53:22 +0000137 /* These might be macros. */
138# undef st_atime
139# undef st_mtime
140# undef st_ctime
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000141# ifdef HPPA
142# define stat64 hpux_stat64
143# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000144#else
145# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000146#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000147
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#include <fcntl.h>
149
150#ifdef SVR4
151# include <sys/cred.h>
152#endif /* SVR4 */
153
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000154#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000156#endif
157
Roland McGrath186c5ac2002-12-15 23:58:23 +0000158#ifdef HAVE_LINUX_XATTR_H
159#include <linux/xattr.h>
160#elif defined linux
161#define XATTR_CREATE 1
162#define XATTR_REPLACE 2
163#endif
164
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000165#ifdef FREEBSD
166#include <sys/param.h>
167#include <sys/mount.h>
168#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000169#endif
170
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000171#if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
172# ifdef HAVE_INTTYPES_H
173# include <inttypes.h>
174# else
175# define PRId64 "lld"
176# define PRIu64 "llu"
177# endif
178#endif
179
John Hughes70623be2001-03-08 13:59:00 +0000180#if HAVE_LONG_LONG_OFF_T
181/*
182 * Ugly hacks for systems that have typedef long long off_t
183 */
John Hughesb8c9f772001-03-07 16:53:07 +0000184
185#define stat64 stat
186#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000187
188#define sys_stat64 sys_stat
189#define sys_fstat64 sys_fstat
190#define sys_lstat64 sys_lstat
191#define sys_lseek64 sys_lseek
192#define sys_truncate64 sys_truncate
193#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195
196#ifdef MAJOR_IN_SYSMACROS
197#include <sys/sysmacros.h>
198#endif
199
200#ifdef MAJOR_IN_MKDEV
201#include <sys/mkdev.h>
202#endif
203
204#ifdef HAVE_SYS_ASYNCH_H
205#include <sys/asynch.h>
206#endif
207
208#ifdef SUNOS4
209#include <ustat.h>
210#endif
211
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000212const struct xlat open_access_modes[] = {
213 { O_RDONLY, "O_RDONLY" },
214 { O_WRONLY, "O_WRONLY" },
215 { O_RDWR, "O_RDWR" },
216#ifdef O_ACCMODE
217 { O_ACCMODE, "O_ACCMODE" },
218#endif
219 { 0, NULL },
220};
221
222const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 { O_EXCL, "O_EXCL" },
225 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000226 { O_TRUNC, "O_TRUNC" },
227 { O_APPEND, "O_APPEND" },
228 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229#ifdef O_SYNC
230 { O_SYNC, "O_SYNC" },
231#endif
232#ifdef O_ASYNC
233 { O_ASYNC, "O_ASYNC" },
234#endif
235#ifdef O_DSYNC
236 { O_DSYNC, "O_DSYNC" },
237#endif
238#ifdef O_RSYNC
239 { O_RSYNC, "O_RSYNC" },
240#endif
241#ifdef O_NDELAY
242 { O_NDELAY, "O_NDELAY" },
243#endif
244#ifdef O_PRIV
245 { O_PRIV, "O_PRIV" },
246#endif
247#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000248 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000249#endif
250#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000251# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
252# undef O_LARGEFILE
253# ifdef SPARC64
254# define O_LARGEFILE 0x40000
255# elif defined X86_64 || defined S390X
256# define O_LARGEFILE 0100000
257# endif
258# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000259# ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000260 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000261# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262#endif
263#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000264 { O_DIRECTORY, "O_DIRECTORY" },
265#endif
266#ifdef O_NOFOLLOW
267 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000269#ifdef O_NOATIME
270 { O_NOATIME, "O_NOATIME" },
271#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000272#ifdef O_CLOEXEC
273 { O_CLOEXEC, "O_CLOEXEC" },
274#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275
276#ifdef FNDELAY
277 { FNDELAY, "FNDELAY" },
278#endif
279#ifdef FAPPEND
280 { FAPPEND, "FAPPEND" },
281#endif
282#ifdef FMARK
283 { FMARK, "FMARK" },
284#endif
285#ifdef FDEFER
286 { FDEFER, "FDEFER" },
287#endif
288#ifdef FASYNC
289 { FASYNC, "FASYNC" },
290#endif
291#ifdef FSHLOCK
292 { FSHLOCK, "FSHLOCK" },
293#endif
294#ifdef FEXLOCK
295 { FEXLOCK, "FEXLOCK" },
296#endif
297#ifdef FCREAT
298 { FCREAT, "FCREAT" },
299#endif
300#ifdef FTRUNC
301 { FTRUNC, "FTRUNC" },
302#endif
303#ifdef FEXCL
304 { FEXCL, "FEXCL" },
305#endif
306#ifdef FNBIO
307 { FNBIO, "FNBIO" },
308#endif
309#ifdef FSYNC
310 { FSYNC, "FSYNC" },
311#endif
312#ifdef FNOCTTY
313 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000314#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000315#ifdef O_SHLOCK
316 { O_SHLOCK, "O_SHLOCK" },
317#endif
318#ifdef O_EXLOCK
319 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320#endif
321 { 0, NULL },
322};
323
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000324#ifdef LINUX
325
326#ifndef AT_FDCWD
327# define AT_FDCWD -100
328#endif
329
330static void
331print_dirfd(long fd)
332{
333 if (fd == AT_FDCWD)
334 tprintf("AT_FDCWD, ");
335 else
336 tprintf("%ld, ", fd);
337}
338#endif
339
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000340/*
341 * low bits of the open(2) flags define access mode,
342 * other bits are real flags.
343 */
344void
345tprint_open_modes(struct tcb *tcp, mode_t flags)
346{
347 const char *str = xlookup(open_access_modes, flags & 3);
348
349 if (str)
350 {
351 tprintf("%s", str);
352 flags &= ~3;
353 if (!flags)
354 return;
355 tprintf("|");
356 }
357 printflags(open_mode_flags, flags, "O_???");
358}
359
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000360static int
361decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362{
363 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000364 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365 tprintf(", ");
366 /* flags */
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000367 tprint_open_modes(tcp, tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000368 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000370 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371 }
372 }
373 return 0;
374}
375
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000376int
377sys_open(struct tcb *tcp)
378{
379 return decode_open(tcp, 0);
380}
381
382#ifdef LINUX
383int
384sys_openat(struct tcb *tcp)
385{
386 if (entering(tcp))
387 print_dirfd(tcp->u_arg[0]);
388 return decode_open(tcp, 1);
389}
390#endif
391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000393static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394 { 0, "O_RDWR" },
395 { 1, "O_RDONLY" },
396 { 2, "O_WRONLY" },
397 { 0x80, "O_NONBLOCK" },
398 { 8, "O_APPEND" },
399 { 0x100, "O_CREAT" },
400 { 0x200, "O_TRUNC" },
401 { 0x400, "O_EXCL" },
402 { 0x800, "O_NOCTTY" },
403 { 0x10, "O_SYNC" },
404 { 0x40, "O_DSYNC" },
405 { 0x8000, "O_RSYNC" },
406 { 4, "O_NDELAY" },
407 { 0x1000, "O_PRIV" },
408 { 0, NULL },
409};
410
411int
412solaris_open(tcp)
413struct tcb *tcp;
414{
415 if (entering(tcp)) {
416 printpath(tcp, tcp->u_arg[0]);
417 tprintf(", ");
418 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000419 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 if (tcp->u_arg[1] & 0x100) {
421 /* mode */
422 tprintf(", %#lo", tcp->u_arg[2]);
423 }
424 }
425 return 0;
426}
427
428#endif
429
430int
431sys_creat(tcp)
432struct tcb *tcp;
433{
434 if (entering(tcp)) {
435 printpath(tcp, tcp->u_arg[0]);
436 tprintf(", %#lo", tcp->u_arg[1]);
437 }
438 return 0;
439}
440
Roland McGrathd9f816f2004-09-04 03:39:20 +0000441static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 { F_OK, "F_OK", },
443 { R_OK, "R_OK" },
444 { W_OK, "W_OK" },
445 { X_OK, "X_OK" },
446#ifdef EFF_ONLY_OK
447 { EFF_ONLY_OK, "EFF_ONLY_OK" },
448#endif
449#ifdef EX_OK
450 { EX_OK, "EX_OK" },
451#endif
452 { 0, NULL },
453};
454
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000455static int
456decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457{
458 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000459 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000461 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 }
463 return 0;
464}
465
466int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000467sys_access(struct tcb *tcp)
468{
469 return decode_access(tcp, 0);
470}
471
472#ifdef LINUX
473int
474sys_faccessat(struct tcb *tcp)
475{
476 if (entering(tcp))
477 print_dirfd(tcp->u_arg[0]);
478 return decode_access(tcp, 1);
479}
480#endif
481
482int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483sys_umask(tcp)
484struct tcb *tcp;
485{
486 if (entering(tcp)) {
487 tprintf("%#lo", tcp->u_arg[0]);
488 }
489 return RVAL_OCTAL;
490}
491
Roland McGrathd9f816f2004-09-04 03:39:20 +0000492static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493 { SEEK_SET, "SEEK_SET" },
494 { SEEK_CUR, "SEEK_CUR" },
495 { SEEK_END, "SEEK_END" },
496 { 0, NULL },
497};
498
John Hughes70623be2001-03-08 13:59:00 +0000499#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500int
501sys_lseek(tcp)
502struct tcb *tcp;
503{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000504 off_t offset;
505 int _whence;
506
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507 if (entering(tcp)) {
508 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000509 offset = tcp->u_arg[1];
510 _whence = tcp->u_arg[2];
511 if (_whence == SEEK_SET)
512 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000514 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000515 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000516 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 return RVAL_UDECIMAL;
518}
John Hughes5a826b82001-03-07 13:21:24 +0000519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520
Michal Ludvig53b320f2002-09-23 13:30:09 +0000521#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522int
523sys_llseek (tcp)
524struct tcb *tcp;
525{
526 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000527 /*
528 * This one call takes explicitly two 32-bit arguments hi, lo,
529 * rather than one 64-bit argument for which LONG_LONG works
530 * appropriate for the native byte order.
531 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 if (tcp->u_arg[4] == SEEK_SET)
533 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000534 (((long long int) tcp->u_arg[1]) << 32
535 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 else
537 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000538 (((long long int) tcp->u_arg[1]) << 32
539 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 }
541 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000542 long long int off;
543 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000545 else
546 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547 printxval(whence, tcp->u_arg[4], "SEEK_???");
548 }
549 return 0;
550}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000551
552int
553sys_readahead (tcp)
554struct tcb *tcp;
555{
556 if (entering(tcp)) {
557 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
558# if defined IA64 || defined X86_64 || defined ALPHA
559 (long long int) tcp->u_arg[1], tcp->u_arg[2]
560# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000561 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000562# endif
563 );
564 }
565 return 0;
566}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567#endif
568
John Hughes70623be2001-03-08 13:59:00 +0000569#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000570int
571sys_lseek64 (tcp)
572struct tcb *tcp;
573{
574 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000575 long long offset;
576 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000577 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000578 if (tcp->u_arg[3] == SEEK_SET)
579 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
580 else
581 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
582 printxval(whence, tcp->u_arg[3], "SEEK_???");
583 }
584 return RVAL_LUDECIMAL;
585}
586#endif
587
John Hughes70623be2001-03-08 13:59:00 +0000588#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589int
590sys_truncate(tcp)
591struct tcb *tcp;
592{
593 if (entering(tcp)) {
594 printpath(tcp, tcp->u_arg[0]);
595 tprintf(", %lu", tcp->u_arg[1]);
596 }
597 return 0;
598}
John Hughes5a826b82001-03-07 13:21:24 +0000599#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600
John Hughes70623be2001-03-08 13:59:00 +0000601#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000602int
603sys_truncate64(tcp)
604struct tcb *tcp;
605{
606 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000607 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000608 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000609 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000610 }
611 return 0;
612}
613#endif
614
John Hughes70623be2001-03-08 13:59:00 +0000615#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616int
617sys_ftruncate(tcp)
618struct tcb *tcp;
619{
620 if (entering(tcp)) {
621 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
622 }
623 return 0;
624}
John Hughes5a826b82001-03-07 13:21:24 +0000625#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626
John Hughes70623be2001-03-08 13:59:00 +0000627#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000628int
629sys_ftruncate64(tcp)
630struct tcb *tcp;
631{
632 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000633 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000634 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000635 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000636 }
637 return 0;
638}
639#endif
640
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641/* several stats */
642
Roland McGrathd9f816f2004-09-04 03:39:20 +0000643static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644 { S_IFREG, "S_IFREG" },
645 { S_IFSOCK, "S_IFSOCK" },
646 { S_IFIFO, "S_IFIFO" },
647 { S_IFLNK, "S_IFLNK" },
648 { S_IFDIR, "S_IFDIR" },
649 { S_IFBLK, "S_IFBLK" },
650 { S_IFCHR, "S_IFCHR" },
651 { 0, NULL },
652};
653
Roland McGrathf9c49b22004-10-06 22:11:54 +0000654static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655sprintmode(mode)
656int mode;
657{
658 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000659 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660
661 if ((mode & S_IFMT) == 0)
662 s = "";
663 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
664 sprintf(buf, "%#o", mode);
665 return buf;
666 }
667 sprintf(buf, "%s%s%s%s", s,
668 (mode & S_ISUID) ? "|S_ISUID" : "",
669 (mode & S_ISGID) ? "|S_ISGID" : "",
670 (mode & S_ISVTX) ? "|S_ISVTX" : "");
671 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
672 if (mode)
673 sprintf(buf + strlen(buf), "|%#o", mode);
674 s = (*buf == '|') ? buf + 1 : buf;
675 return *s ? s : "0";
676}
677
678static char *
679sprinttime(t)
680time_t t;
681{
682 struct tm *tmp;
683 static char buf[32];
684
685 if (t == 0) {
686 sprintf(buf, "0");
687 return buf;
688 }
689 tmp = localtime(&t);
690 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000691 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
693 return buf;
694}
695
696#ifdef LINUXSPARC
697typedef struct {
698 int tv_sec;
699 int tv_nsec;
700} timestruct_t;
701
702struct solstat {
703 unsigned st_dev;
704 int st_pad1[3]; /* network id */
705 unsigned st_ino;
706 unsigned st_mode;
707 unsigned st_nlink;
708 unsigned st_uid;
709 unsigned st_gid;
710 unsigned st_rdev;
711 int st_pad2[2];
712 int st_size;
713 int st_pad3; /* st_size, off_t expansion */
714 timestruct_t st_atime;
715 timestruct_t st_mtime;
716 timestruct_t st_ctime;
717 int st_blksize;
718 int st_blocks;
719 char st_fstype[16];
720 int st_pad4[8]; /* expansion area */
721};
722
723static void
724printstatsol(tcp, addr)
725struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000726long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727{
728 struct solstat statbuf;
729
730 if (!addr) {
731 tprintf("NULL");
732 return;
733 }
734 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000735 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736 return;
737 }
738 if (umove(tcp, addr, &statbuf) < 0) {
739 tprintf("{...}");
740 return;
741 }
742 if (!abbrev(tcp)) {
743 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
744 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
745 (unsigned long) (statbuf.st_dev & 0x3ffff),
746 (unsigned long) statbuf.st_ino,
747 sprintmode(statbuf.st_mode));
748 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
749 (unsigned long) statbuf.st_nlink,
750 (unsigned long) statbuf.st_uid,
751 (unsigned long) statbuf.st_gid);
752 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
753 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
754 }
755 else
756 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
757 switch (statbuf.st_mode & S_IFMT) {
758 case S_IFCHR: case S_IFBLK:
759 tprintf("st_rdev=makedev(%lu, %lu), ",
760 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
761 (unsigned long) (statbuf.st_rdev & 0x3ffff));
762 break;
763 default:
764 tprintf("st_size=%u, ", statbuf.st_size);
765 break;
766 }
767 if (!abbrev(tcp)) {
768 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
769 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
770 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
771 }
772 else
773 tprintf("...}");
774}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000775
776#if defined (SPARC64)
777static void
778printstat_sparc64(tcp, addr)
779struct tcb *tcp;
780long addr;
781{
782 struct stat_sparc64 statbuf;
783
784 if (!addr) {
785 tprintf("NULL");
786 return;
787 }
788 if (syserror(tcp) || !verbose(tcp)) {
789 tprintf("%#lx", addr);
790 return;
791 }
792 if (umove(tcp, addr, &statbuf) < 0) {
793 tprintf("{...}");
794 return;
795 }
796
797 if (!abbrev(tcp)) {
798 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
799 (unsigned long) major(statbuf.st_dev),
800 (unsigned long) minor(statbuf.st_dev),
801 (unsigned long) statbuf.st_ino,
802 sprintmode(statbuf.st_mode));
803 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
804 (unsigned long) statbuf.st_nlink,
805 (unsigned long) statbuf.st_uid,
806 (unsigned long) statbuf.st_gid);
807 tprintf("st_blksize=%lu, ",
808 (unsigned long) statbuf.st_blksize);
809 tprintf("st_blocks=%lu, ",
810 (unsigned long) statbuf.st_blocks);
811 }
812 else
813 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
814 switch (statbuf.st_mode & S_IFMT) {
815 case S_IFCHR: case S_IFBLK:
816 tprintf("st_rdev=makedev(%lu, %lu), ",
817 (unsigned long) major(statbuf.st_rdev),
818 (unsigned long) minor(statbuf.st_rdev));
819 break;
820 default:
821 tprintf("st_size=%lu, ", statbuf.st_size);
822 break;
823 }
824 if (!abbrev(tcp)) {
825 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
826 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
827 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
828 tprintf("}");
829 }
830 else
831 tprintf("...}");
832}
833#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000834#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835
Roland McGratha4d48532005-06-08 20:45:28 +0000836static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000837#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000838 { UF_NODUMP, "UF_NODUMP" },
839 { UF_IMMUTABLE, "UF_IMMUTABLE" },
840 { UF_APPEND, "UF_APPEND" },
841 { UF_OPAQUE, "UF_OPAQUE" },
842 { UF_NOUNLINK, "UF_NOUNLINK" },
843 { SF_ARCHIVED, "SF_ARCHIVED" },
844 { SF_IMMUTABLE, "SF_IMMUTABLE" },
845 { SF_APPEND, "SF_APPEND" },
846 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000847#elif UNIXWARE >= 2
848#ifdef _S_ISMLD
849 { _S_ISMLD, "_S_ISMLD" },
850#endif
851#ifdef _S_ISMOUNTED
852 { _S_ISMOUNTED, "_S_ISMOUNTED" },
853#endif
854#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000855 { 0, NULL },
856};
857
John Hughesc0fc3fd2001-03-08 16:10:40 +0000858#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000859int
860sys_chflags(tcp)
861struct tcb *tcp;
862{
863 if (entering(tcp)) {
864 printpath(tcp, tcp->u_arg[0]);
865 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000866 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000867 }
868 return 0;
869}
870
871int
872sys_fchflags(tcp)
873struct tcb *tcp;
874{
875 if (entering(tcp)) {
876 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000877 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000878 }
879 return 0;
880}
881#endif
882
John Hughes70623be2001-03-08 13:59:00 +0000883#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000884static void
885realprintstat(tcp, statbuf)
886struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000887struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000888{
889 if (!abbrev(tcp)) {
890 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
891 (unsigned long) major(statbuf->st_dev),
892 (unsigned long) minor(statbuf->st_dev),
893 (unsigned long) statbuf->st_ino,
894 sprintmode(statbuf->st_mode));
895 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
896 (unsigned long) statbuf->st_nlink,
897 (unsigned long) statbuf->st_uid,
898 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000899#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000900 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000901#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
902#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000903 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000904#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000905 }
906 else
907 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
908 switch (statbuf->st_mode & S_IFMT) {
909 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000910#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000911 tprintf("st_rdev=makedev(%lu, %lu), ",
912 (unsigned long) major(statbuf->st_rdev),
913 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000914#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000915 tprintf("st_size=makedev(%lu, %lu), ",
916 (unsigned long) major(statbuf->st_size),
917 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000918#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000919 break;
920 default:
921 tprintf("st_size=%lu, ", statbuf->st_size);
922 break;
923 }
924 if (!abbrev(tcp)) {
925 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
926 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000927 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000928#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000929 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000930 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000931#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000932#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000933 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
934#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000935#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000936 tprintf(", st_level=%ld", statbuf->st_level);
937#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000938#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000939 tprintf(", st_fstype=%.*s",
940 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
941#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000942#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000943 tprintf(", st_gen=%u", statbuf->st_gen);
944#endif
945 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000946 }
947 else
948 tprintf("...}");
949}
950
Nate Sammons771a6ff1999-04-05 22:39:31 +0000951
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952static void
953printstat(tcp, addr)
954struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000955long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000957 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958
959#ifdef LINUXSPARC
960 if (current_personality == 1) {
961 printstatsol(tcp, addr);
962 return;
963 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000964#ifdef SPARC64
965 else if (current_personality == 2) {
966 printstat_sparc64(tcp, addr);
967 return;
968 }
969#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970#endif /* LINUXSPARC */
971
972 if (!addr) {
973 tprintf("NULL");
974 return;
975 }
976 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000977 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978 return;
979 }
980 if (umove(tcp, addr, &statbuf) < 0) {
981 tprintf("{...}");
982 return;
983 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000984
985 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986}
John Hughes70623be2001-03-08 13:59:00 +0000987#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988
Wichert Akkermanc7926982000-04-10 22:22:31 +0000989#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000990static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991printstat64(tcp, addr)
992struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000993long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000994{
995 struct stat64 statbuf;
996
997#ifdef LINUXSPARC
998 if (current_personality == 1) {
999 printstatsol(tcp, addr);
1000 return;
1001 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001002#ifdef SPARC64
1003 else if (current_personality == 2) {
1004 printstat_sparc64(tcp, addr);
1005 return;
1006 }
1007#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001008#endif /* LINUXSPARC */
1009
1010 if (!addr) {
1011 tprintf("NULL");
1012 return;
1013 }
1014 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001015 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001016 return;
1017 }
1018 if (umove(tcp, addr, &statbuf) < 0) {
1019 tprintf("{...}");
1020 return;
1021 }
1022
1023 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001024#ifdef HAVE_LONG_LONG
1025 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1026#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001027 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001028#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001029 (unsigned long) major(statbuf.st_dev),
1030 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001031#ifdef HAVE_LONG_LONG
1032 (unsigned long long) statbuf.st_ino,
1033#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001034 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001035#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001036 sprintmode(statbuf.st_mode));
1037 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1038 (unsigned long) statbuf.st_nlink,
1039 (unsigned long) statbuf.st_uid,
1040 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001041#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001042 tprintf("st_blksize=%lu, ",
1043 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001044#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1045#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001046 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001047#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001048 }
1049 else
1050 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1051 switch (statbuf.st_mode & S_IFMT) {
1052 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001053#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001054 tprintf("st_rdev=makedev(%lu, %lu), ",
1055 (unsigned long) major(statbuf.st_rdev),
1056 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001057#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001058 tprintf("st_size=makedev(%lu, %lu), ",
1059 (unsigned long) major(statbuf.st_size),
1060 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001061#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001062 break;
1063 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001064#ifdef HAVE_LONG_LONG
1065 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1066#else
1067 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1068#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001069 break;
1070 }
1071 if (!abbrev(tcp)) {
1072 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1073 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001074 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001075#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001076 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001077 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001078#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001079#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001080 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1081#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001082#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001083 tprintf(", st_level=%ld", statbuf.st_level);
1084#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001085#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001086 tprintf(", st_fstype=%.*s",
1087 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1088#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001089#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001090 tprintf(", st_gen=%u", statbuf.st_gen);
1091#endif
1092 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001093 }
1094 else
1095 tprintf("...}");
1096}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001097#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001098
Roland McGrath79db8af2003-06-27 21:20:09 +00001099#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001101convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001102const struct __old_kernel_stat *oldbuf;
1103struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001104{
1105 newbuf->st_dev=oldbuf->st_dev;
1106 newbuf->st_ino=oldbuf->st_ino;
1107 newbuf->st_mode=oldbuf->st_mode;
1108 newbuf->st_nlink=oldbuf->st_nlink;
1109 newbuf->st_uid=oldbuf->st_uid;
1110 newbuf->st_gid=oldbuf->st_gid;
1111 newbuf->st_rdev=oldbuf->st_rdev;
1112 newbuf->st_size=oldbuf->st_size;
1113 newbuf->st_atime=oldbuf->st_atime;
1114 newbuf->st_mtime=oldbuf->st_mtime;
1115 newbuf->st_ctime=oldbuf->st_ctime;
1116 newbuf->st_blksize=0; /* not supported in old_stat */
1117 newbuf->st_blocks=0; /* not supported in old_stat */
1118}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001119
1120
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001121static void
1122printoldstat(tcp, addr)
1123struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001124long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001125{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001126 struct __old_kernel_stat statbuf;
1127 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001128
1129#ifdef LINUXSPARC
1130 if (current_personality == 1) {
1131 printstatsol(tcp, addr);
1132 return;
1133 }
1134#endif /* LINUXSPARC */
1135
1136 if (!addr) {
1137 tprintf("NULL");
1138 return;
1139 }
1140 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001141 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001142 return;
1143 }
1144 if (umove(tcp, addr, &statbuf) < 0) {
1145 tprintf("{...}");
1146 return;
1147 }
1148
1149 convertoldstat(&statbuf, &newstatbuf);
1150 realprintstat(tcp, &newstatbuf);
1151}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001152#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001153
John Hughes70623be2001-03-08 13:59:00 +00001154#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155int
1156sys_stat(tcp)
1157struct tcb *tcp;
1158{
1159 if (entering(tcp)) {
1160 printpath(tcp, tcp->u_arg[0]);
1161 tprintf(", ");
1162 } else {
1163 printstat(tcp, tcp->u_arg[1]);
1164 }
1165 return 0;
1166}
John Hughesb8c9f772001-03-07 16:53:07 +00001167#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001168
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001169int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001170sys_stat64(tcp)
1171struct tcb *tcp;
1172{
1173#ifdef HAVE_STAT64
1174 if (entering(tcp)) {
1175 printpath(tcp, tcp->u_arg[0]);
1176 tprintf(", ");
1177 } else {
1178 printstat64(tcp, tcp->u_arg[1]);
1179 }
1180 return 0;
1181#else
1182 return printargs(tcp);
1183#endif
1184}
1185
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001186#ifdef LINUX
1187static const struct xlat fstatatflags[] = {
1188#ifndef AT_SYMLINK_NOFOLLOW
1189# define AT_SYMLINK_NOFOLLOW 0x100
1190#endif
1191 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1192 { 0, NULL },
1193};
Roland McGrath6afc5652007-07-24 01:57:11 +00001194#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001195
1196int
1197sys_newfstatat(struct tcb *tcp)
1198{
1199 if (entering(tcp)) {
1200 print_dirfd(tcp->u_arg[0]);
1201 printpath(tcp, tcp->u_arg[1]);
1202 tprintf(", ");
1203 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001204#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001205 printstat64(tcp, tcp->u_arg[2]);
1206#else
1207 printstat(tcp, tcp->u_arg[2]);
1208#endif
1209 tprintf(", ");
1210 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1211 }
1212 return 0;
1213}
1214#endif
1215
Roland McGrath79db8af2003-06-27 21:20:09 +00001216#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001217int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001218sys_oldstat(tcp)
1219struct tcb *tcp;
1220{
1221 if (entering(tcp)) {
1222 printpath(tcp, tcp->u_arg[0]);
1223 tprintf(", ");
1224 } else {
1225 printoldstat(tcp, tcp->u_arg[1]);
1226 }
1227 return 0;
1228}
Roland McGrath79db8af2003-06-27 21:20:09 +00001229#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001230
John Hughes70623be2001-03-08 13:59:00 +00001231#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001232int
1233sys_fstat(tcp)
1234struct tcb *tcp;
1235{
1236 if (entering(tcp))
1237 tprintf("%ld, ", tcp->u_arg[0]);
1238 else {
1239 printstat(tcp, tcp->u_arg[1]);
1240 }
1241 return 0;
1242}
John Hughesb8c9f772001-03-07 16:53:07 +00001243#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001245int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001246sys_fstat64(tcp)
1247struct tcb *tcp;
1248{
1249#ifdef HAVE_STAT64
1250 if (entering(tcp))
1251 tprintf("%ld, ", tcp->u_arg[0]);
1252 else {
1253 printstat64(tcp, tcp->u_arg[1]);
1254 }
1255 return 0;
1256#else
1257 return printargs(tcp);
1258#endif
1259}
1260
Roland McGrath79db8af2003-06-27 21:20:09 +00001261#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001262int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001263sys_oldfstat(tcp)
1264struct tcb *tcp;
1265{
1266 if (entering(tcp))
1267 tprintf("%ld, ", tcp->u_arg[0]);
1268 else {
1269 printoldstat(tcp, tcp->u_arg[1]);
1270 }
1271 return 0;
1272}
Roland McGrath79db8af2003-06-27 21:20:09 +00001273#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001274
John Hughes70623be2001-03-08 13:59:00 +00001275#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276int
1277sys_lstat(tcp)
1278struct tcb *tcp;
1279{
1280 if (entering(tcp)) {
1281 printpath(tcp, tcp->u_arg[0]);
1282 tprintf(", ");
1283 } else {
1284 printstat(tcp, tcp->u_arg[1]);
1285 }
1286 return 0;
1287}
John Hughesb8c9f772001-03-07 16:53:07 +00001288#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001289
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001290int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001291sys_lstat64(tcp)
1292struct tcb *tcp;
1293{
1294#ifdef HAVE_STAT64
1295 if (entering(tcp)) {
1296 printpath(tcp, tcp->u_arg[0]);
1297 tprintf(", ");
1298 } else {
1299 printstat64(tcp, tcp->u_arg[1]);
1300 }
1301 return 0;
1302#else
1303 return printargs(tcp);
1304#endif
1305}
1306
Roland McGrath79db8af2003-06-27 21:20:09 +00001307#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001308int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001309sys_oldlstat(tcp)
1310struct tcb *tcp;
1311{
1312 if (entering(tcp)) {
1313 printpath(tcp, tcp->u_arg[0]);
1314 tprintf(", ");
1315 } else {
1316 printoldstat(tcp, tcp->u_arg[1]);
1317 }
1318 return 0;
1319}
Roland McGrath79db8af2003-06-27 21:20:09 +00001320#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001321
1322
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323#if defined(SVR4) || defined(LINUXSPARC)
1324
1325int
1326sys_xstat(tcp)
1327struct tcb *tcp;
1328{
1329 if (entering(tcp)) {
1330 tprintf("%ld, ", tcp->u_arg[0]);
1331 printpath(tcp, tcp->u_arg[1]);
1332 tprintf(", ");
1333 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001334#ifdef _STAT64_VER
1335 if (tcp->u_arg[0] == _STAT64_VER)
1336 printstat64 (tcp, tcp->u_arg[2]);
1337 else
1338#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001339 printstat(tcp, tcp->u_arg[2]);
1340 }
1341 return 0;
1342}
1343
1344int
1345sys_fxstat(tcp)
1346struct tcb *tcp;
1347{
1348 if (entering(tcp))
1349 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1350 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001351#ifdef _STAT64_VER
1352 if (tcp->u_arg[0] == _STAT64_VER)
1353 printstat64 (tcp, tcp->u_arg[2]);
1354 else
1355#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356 printstat(tcp, tcp->u_arg[2]);
1357 }
1358 return 0;
1359}
1360
1361int
1362sys_lxstat(tcp)
1363struct tcb *tcp;
1364{
1365 if (entering(tcp)) {
1366 tprintf("%ld, ", tcp->u_arg[0]);
1367 printpath(tcp, tcp->u_arg[1]);
1368 tprintf(", ");
1369 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001370#ifdef _STAT64_VER
1371 if (tcp->u_arg[0] == _STAT64_VER)
1372 printstat64 (tcp, tcp->u_arg[2]);
1373 else
1374#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 printstat(tcp, tcp->u_arg[2]);
1376 }
1377 return 0;
1378}
1379
1380int
1381sys_xmknod(tcp)
1382struct tcb *tcp;
1383{
1384 int mode = tcp->u_arg[2];
1385
1386 if (entering(tcp)) {
1387 tprintf("%ld, ", tcp->u_arg[0]);
1388 printpath(tcp, tcp->u_arg[1]);
1389 tprintf(", %s", sprintmode(mode));
1390 switch (mode & S_IFMT) {
1391 case S_IFCHR: case S_IFBLK:
1392#ifdef LINUXSPARC
1393 tprintf(", makedev(%lu, %lu)",
1394 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1395 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001396#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 tprintf(", makedev(%lu, %lu)",
1398 (unsigned long) major(tcp->u_arg[3]),
1399 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001400#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 break;
1402 default:
1403 break;
1404 }
1405 }
1406 return 0;
1407}
1408
Wichert Akkerman8829a551999-06-11 13:18:40 +00001409#ifdef HAVE_SYS_ACL_H
1410
1411#include <sys/acl.h>
1412
Roland McGratha4d48532005-06-08 20:45:28 +00001413static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001414#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001415 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001416#endif
1417#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001418 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001419#endif
1420#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001421 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001422#endif
1423#ifdef ACL_GET
1424 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001425#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001426#ifdef ACL_SET
1427 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001428#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001429#ifdef ACL_CNT
1430 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001431#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001432 { 0, NULL },
1433};
1434
1435int
1436sys_acl(tcp)
1437struct tcb *tcp;
1438{
1439 if (entering(tcp)) {
1440 printpath(tcp, tcp->u_arg[0]);
1441 tprintf(", ");
1442 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1443 tprintf(", %ld", tcp->u_arg[2]);
1444 /*
1445 * FIXME - dump out the list of aclent_t's pointed to
1446 * by "tcp->u_arg[3]" if it's not NULL.
1447 */
1448 if (tcp->u_arg[3])
1449 tprintf(", %#lx", tcp->u_arg[3]);
1450 else
1451 tprintf(", NULL");
1452 }
1453 return 0;
1454}
1455
1456
1457int
1458sys_facl(tcp)
1459struct tcb *tcp;
1460{
1461 if (entering(tcp)) {
1462 tprintf("%ld, ", tcp->u_arg[0]);
1463 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1464 tprintf(", %ld", tcp->u_arg[2]);
1465 /*
1466 * FIXME - dump out the list of aclent_t's pointed to
1467 * by "tcp->u_arg[3]" if it's not NULL.
1468 */
1469 if (tcp->u_arg[3])
1470 tprintf(", %#lx", tcp->u_arg[3]);
1471 else
1472 tprintf(", NULL");
1473 }
1474 return 0;
1475}
1476
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001477
Roland McGratha4d48532005-06-08 20:45:28 +00001478static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001479#ifdef IPC_SHM
1480 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001481#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001482#ifdef IPC_SEM
1483 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001484#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001485#ifdef IPC_MSG
1486 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001487#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001488 { 0, NULL },
1489};
1490
1491
1492int
1493sys_aclipc(tcp)
1494struct tcb *tcp;
1495{
1496 if (entering(tcp)) {
1497 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1498 tprintf(", %#lx, ", tcp->u_arg[1]);
1499 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1500 tprintf(", %ld", tcp->u_arg[3]);
1501 /*
1502 * FIXME - dump out the list of aclent_t's pointed to
1503 * by "tcp->u_arg[4]" if it's not NULL.
1504 */
1505 if (tcp->u_arg[4])
1506 tprintf(", %#lx", tcp->u_arg[4]);
1507 else
1508 tprintf(", NULL");
1509 }
1510 return 0;
1511}
1512
1513
1514
Wichert Akkerman8829a551999-06-11 13:18:40 +00001515#endif /* HAVE_SYS_ACL_H */
1516
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001517#endif /* SVR4 || LINUXSPARC */
1518
Michal Ludvig53b320f2002-09-23 13:30:09 +00001519#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520
Roland McGrathd9f816f2004-09-04 03:39:20 +00001521static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001522 { 0x73757245, "CODA_SUPER_MAGIC" },
1523 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1524 { 0x1373, "DEVFS_SUPER_MAGIC" },
1525 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1526 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1528 { 0xef53, "EXT2_SUPER_MAGIC" },
1529 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001530 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531 { 0x9660, "ISOFS_SUPER_MAGIC" },
1532 { 0x137f, "MINIX_SUPER_MAGIC" },
1533 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001534 { 0x2468, "MINIX2_SUPER_MAGIC" },
1535 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001536 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001537 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001538 { 0x6969, "NFS_SUPER_MAGIC" },
1539 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001540 { 0x002f, "QNX4_SUPER_MAGIC" },
1541 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1542 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1543 { 0x517b, "SMB_SUPER_MAGIC" },
1544 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1545 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1546 { 0x00011954, "UFS_MAGIC" },
1547 { 0x54190100, "UFS_CIGAM" },
1548 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001549 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001550 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551 { 0, NULL },
1552};
1553
Michal Ludvig53b320f2002-09-23 13:30:09 +00001554#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001555
1556#ifndef SVR4
1557
Roland McGrathf9c49b22004-10-06 22:11:54 +00001558static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001559sprintfstype(magic)
1560int magic;
1561{
1562 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001563#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001564 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565
1566 s = xlookup(fsmagic, magic);
1567 if (s) {
1568 sprintf(buf, "\"%s\"", s);
1569 return buf;
1570 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001571#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 sprintf(buf, "%#x", magic);
1573 return buf;
1574}
1575
1576static void
1577printstatfs(tcp, addr)
1578struct tcb *tcp;
1579long addr;
1580{
1581 struct statfs statbuf;
1582
1583 if (syserror(tcp) || !verbose(tcp)) {
1584 tprintf("%#lx", addr);
1585 return;
1586 }
1587 if (umove(tcp, addr, &statbuf) < 0) {
1588 tprintf("{...}");
1589 return;
1590 }
1591#ifdef ALPHA
1592
1593 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1594 sprintfstype(statbuf.f_type),
1595 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001596 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1597 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1598 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1599 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001600#else /* !ALPHA */
1601 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1602 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001603 (unsigned long)statbuf.f_bsize,
1604 (unsigned long)statbuf.f_blocks,
1605 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001606 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1607 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001608 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001609 (unsigned long)statbuf.f_ffree,
1610 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001611#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001612 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001613#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001615#ifdef _STATFS_F_FRSIZE
1616 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1617#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618 tprintf("}");
1619}
1620
1621int
1622sys_statfs(tcp)
1623struct tcb *tcp;
1624{
1625 if (entering(tcp)) {
1626 printpath(tcp, tcp->u_arg[0]);
1627 tprintf(", ");
1628 } else {
1629 printstatfs(tcp, tcp->u_arg[1]);
1630 }
1631 return 0;
1632}
1633
1634int
1635sys_fstatfs(tcp)
1636struct tcb *tcp;
1637{
1638 if (entering(tcp)) {
1639 tprintf("%lu, ", tcp->u_arg[0]);
1640 } else {
1641 printstatfs(tcp, tcp->u_arg[1]);
1642 }
1643 return 0;
1644}
1645
Roland McGrathab147c52003-07-17 09:03:02 +00001646#ifdef LINUX
1647static void
1648printstatfs64(tcp, addr)
1649struct tcb *tcp;
1650long addr;
1651{
1652 struct statfs64 statbuf;
1653
1654 if (syserror(tcp) || !verbose(tcp)) {
1655 tprintf("%#lx", addr);
1656 return;
1657 }
1658 if (umove(tcp, addr, &statbuf) < 0) {
1659 tprintf("{...}");
1660 return;
1661 }
Roland McGrath08738432005-06-03 02:40:39 +00001662 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001663 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001664 (unsigned long long)statbuf.f_bsize,
1665 (unsigned long long)statbuf.f_blocks,
1666 (unsigned long long)statbuf.f_bfree);
1667 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1668 (unsigned long long)statbuf.f_bavail,
1669 (unsigned long long)statbuf.f_files,
1670 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001671 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1672 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001673#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001674 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001675#endif
1676 tprintf("}");
1677}
1678
1679int
1680sys_statfs64(tcp)
1681struct tcb *tcp;
1682{
1683 if (entering(tcp)) {
1684 printpath(tcp, tcp->u_arg[0]);
1685 tprintf(", %lu, ", tcp->u_arg[1]);
1686 } else {
1687 if (tcp->u_arg[1] == sizeof (struct statfs64))
1688 printstatfs64(tcp, tcp->u_arg[2]);
1689 else
1690 tprintf("{???}");
1691 }
1692 return 0;
1693}
1694
1695int
1696sys_fstatfs64(tcp)
1697struct tcb *tcp;
1698{
1699 if (entering(tcp)) {
1700 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1701 } else {
1702 if (tcp->u_arg[1] == sizeof (struct statfs64))
1703 printstatfs64(tcp, tcp->u_arg[2]);
1704 else
1705 tprintf("{???}");
1706 }
1707 return 0;
1708}
1709#endif
1710
Michal Ludvig53b320f2002-09-23 13:30:09 +00001711#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712
1713int
1714osf_statfs(tcp)
1715struct tcb *tcp;
1716{
1717 if (entering(tcp)) {
1718 printpath(tcp, tcp->u_arg[0]);
1719 tprintf(", ");
1720 } else {
1721 printstatfs(tcp, tcp->u_arg[1]);
1722 tprintf(", %lu", tcp->u_arg[2]);
1723 }
1724 return 0;
1725}
1726
1727int
1728osf_fstatfs(tcp)
1729struct tcb *tcp;
1730{
1731 if (entering(tcp)) {
1732 tprintf("%lu, ", tcp->u_arg[0]);
1733 } else {
1734 printstatfs(tcp, tcp->u_arg[1]);
1735 tprintf(", %lu", tcp->u_arg[2]);
1736 }
1737 return 0;
1738}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001739#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740
1741#endif /* !SVR4 */
1742
1743#ifdef SUNOS4
1744
1745int
1746sys_ustat(tcp)
1747struct tcb *tcp;
1748{
1749 struct ustat statbuf;
1750
1751 if (entering(tcp)) {
1752 tprintf("makedev(%lu, %lu), ",
1753 (long) major(tcp->u_arg[0]),
1754 (long) minor(tcp->u_arg[0]));
1755 }
1756 else {
1757 if (syserror(tcp) || !verbose(tcp))
1758 tprintf("%#lx", tcp->u_arg[1]);
1759 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1760 tprintf("{...}");
1761 else {
1762 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1763 statbuf.f_tfree, statbuf.f_tinode);
1764 tprintf("f_fname=\"%.*s\", ",
1765 (int) sizeof(statbuf.f_fname),
1766 statbuf.f_fname);
1767 tprintf("f_fpack=\"%.*s\"}",
1768 (int) sizeof(statbuf.f_fpack),
1769 statbuf.f_fpack);
1770 }
1771 }
1772 return 0;
1773}
1774
1775#endif /* SUNOS4 */
1776
Wichert Akkermanc7926982000-04-10 22:22:31 +00001777int
1778sys_pivotroot(tcp)
1779struct tcb *tcp;
1780{
1781 if (entering(tcp)) {
1782 printpath(tcp, tcp->u_arg[0]);
1783 tprintf(", ");
1784 printpath(tcp, tcp->u_arg[1]);
1785 }
1786 return 0;
1787}
1788
1789
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790/* directory */
1791int
1792sys_chdir(tcp)
1793struct tcb *tcp;
1794{
1795 if (entering(tcp)) {
1796 printpath(tcp, tcp->u_arg[0]);
1797 }
1798 return 0;
1799}
1800
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001801static int
1802decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803{
1804 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001805 printpath(tcp, tcp->u_arg[offset]);
1806 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001807 }
1808 return 0;
1809}
1810
1811int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001812sys_mkdir(struct tcb *tcp)
1813{
1814 return decode_mkdir(tcp, 0);
1815}
1816
1817#ifdef LINUX
1818int
1819sys_mkdirat(struct tcb *tcp)
1820{
1821 if (entering(tcp))
1822 print_dirfd(tcp->u_arg[0]);
1823 return decode_mkdir(tcp, 1);
1824}
1825#endif
1826
1827int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828sys_rmdir(tcp)
1829struct tcb *tcp;
1830{
1831 if (entering(tcp)) {
1832 printpath(tcp, tcp->u_arg[0]);
1833 }
1834 return 0;
1835}
1836
1837int
1838sys_fchdir(tcp)
1839struct tcb *tcp;
1840{
1841 if (entering(tcp)) {
1842 tprintf("%ld", tcp->u_arg[0]);
1843 }
1844 return 0;
1845}
1846
1847int
1848sys_chroot(tcp)
1849struct tcb *tcp;
1850{
1851 if (entering(tcp)) {
1852 printpath(tcp, tcp->u_arg[0]);
1853 }
1854 return 0;
1855}
1856
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001857#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858int
1859sys_fchroot(tcp)
1860struct tcb *tcp;
1861{
1862 if (entering(tcp)) {
1863 tprintf("%ld", tcp->u_arg[0]);
1864 }
1865 return 0;
1866}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001867#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868
1869int
1870sys_link(tcp)
1871struct tcb *tcp;
1872{
1873 if (entering(tcp)) {
1874 printpath(tcp, tcp->u_arg[0]);
1875 tprintf(", ");
1876 printpath(tcp, tcp->u_arg[1]);
1877 }
1878 return 0;
1879}
1880
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001881#ifdef LINUX
1882int
1883sys_linkat(struct tcb *tcp)
1884{
1885 if (entering(tcp)) {
1886 print_dirfd(tcp->u_arg[0]);
1887 printpath(tcp, tcp->u_arg[1]);
1888 tprintf(", ");
1889 print_dirfd(tcp->u_arg[2]);
1890 printpath(tcp, tcp->u_arg[3]);
1891 tprintf(", %ld", tcp->u_arg[4]);
1892 }
1893 return 0;
1894}
1895#endif
1896
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897int
1898sys_unlink(tcp)
1899struct tcb *tcp;
1900{
1901 if (entering(tcp)) {
1902 printpath(tcp, tcp->u_arg[0]);
1903 }
1904 return 0;
1905}
1906
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001907#ifdef LINUX
1908static const struct xlat unlinkatflags[] = {
1909#ifndef AT_REMOVEDIR
1910# define AT_REMOVEDIR 0x200
1911#endif
1912 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1913 { 0, NULL },
1914};
1915
1916int
1917sys_unlinkat(struct tcb *tcp)
1918{
1919 if (entering(tcp)) {
1920 print_dirfd(tcp->u_arg[0]);
1921 printpath(tcp, tcp->u_arg[1]);
1922 tprintf(", ");
1923 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1924 }
1925 return 0;
1926}
1927#endif
1928
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929int
1930sys_symlink(tcp)
1931struct tcb *tcp;
1932{
1933 if (entering(tcp)) {
1934 printpath(tcp, tcp->u_arg[0]);
1935 tprintf(", ");
1936 printpath(tcp, tcp->u_arg[1]);
1937 }
1938 return 0;
1939}
1940
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001941#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001943sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944{
1945 if (entering(tcp)) {
1946 printpath(tcp, tcp->u_arg[0]);
1947 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001948 print_dirfd(tcp->u_arg[1]);
1949 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950 }
1951 return 0;
1952}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001953#endif
1954
1955static int
1956decode_readlink(struct tcb *tcp, int offset)
1957{
1958 if (entering(tcp)) {
1959 printpath(tcp, tcp->u_arg[offset]);
1960 tprintf(", ");
1961 } else {
1962 if (syserror(tcp))
1963 tprintf("%#lx", tcp->u_arg[offset + 1]);
1964 else
1965 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1966 tprintf(", %lu", tcp->u_arg[offset + 2]);
1967 }
1968 return 0;
1969}
1970
1971int
1972sys_readlink(struct tcb *tcp)
1973{
1974 return decode_readlink(tcp, 0);
1975}
1976
1977#ifdef LINUX
1978int
1979sys_readlinkat(struct tcb *tcp)
1980{
1981 if (entering(tcp))
1982 print_dirfd(tcp->u_arg[0]);
1983 return decode_readlink(tcp, 1);
1984}
1985#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986
1987int
1988sys_rename(tcp)
1989struct tcb *tcp;
1990{
1991 if (entering(tcp)) {
1992 printpath(tcp, tcp->u_arg[0]);
1993 tprintf(", ");
1994 printpath(tcp, tcp->u_arg[1]);
1995 }
1996 return 0;
1997}
1998
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001999#ifdef LINUX
2000int
2001sys_renameat(struct tcb *tcp)
2002{
2003 if (entering(tcp)) {
2004 print_dirfd(tcp->u_arg[0]);
2005 printpath(tcp, tcp->u_arg[1]);
2006 tprintf(", ");
2007 print_dirfd(tcp->u_arg[2]);
2008 printpath(tcp, tcp->u_arg[3]);
2009 }
2010 return 0;
2011}
2012#endif
2013
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014int
2015sys_chown(tcp)
2016struct tcb *tcp;
2017{
2018 if (entering(tcp)) {
2019 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002020 printuid(", ", tcp->u_arg[1]);
2021 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002022 }
2023 return 0;
2024}
2025
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002026#ifdef LINUX
2027int
2028sys_fchownat(struct tcb *tcp)
2029{
2030 if (entering(tcp)) {
2031 print_dirfd(tcp->u_arg[0]);
2032 printpath(tcp, tcp->u_arg[1]);
2033 printuid(", ", tcp->u_arg[2]);
2034 printuid(", ", tcp->u_arg[3]);
2035 tprintf(", ");
2036 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2037 }
2038 return 0;
2039}
2040#endif
2041
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002042int
2043sys_fchown(tcp)
2044struct tcb *tcp;
2045{
2046 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002047 tprintf("%ld", tcp->u_arg[0]);
2048 printuid(", ", tcp->u_arg[1]);
2049 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050 }
2051 return 0;
2052}
2053
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054static int
2055decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056{
2057 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002058 printpath(tcp, tcp->u_arg[offset]);
2059 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002060 }
2061 return 0;
2062}
2063
2064int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002065sys_chmod(struct tcb *tcp)
2066{
2067 return decode_chmod(tcp, 0);
2068}
2069
2070#ifdef LINUX
2071int
2072sys_fchmodat(struct tcb *tcp)
2073{
2074 if (entering(tcp))
2075 print_dirfd(tcp->u_arg[0]);
2076 return decode_chmod(tcp, 1);
2077}
2078#endif
2079
2080int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081sys_fchmod(tcp)
2082struct tcb *tcp;
2083{
2084 if (entering(tcp)) {
2085 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2086 }
2087 return 0;
2088}
2089
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002090#ifdef ALPHA
2091int
2092sys_osf_utimes(tcp)
2093struct tcb *tcp;
2094{
2095 if (entering(tcp)) {
2096 printpath(tcp, tcp->u_arg[0]);
2097 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002098 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002099 }
2100 return 0;
2101}
2102#endif
2103
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002104static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002105decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002106{
2107 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002108 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002109 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002110 if (tcp->u_arg[offset + 1] == 0)
2111 tprintf("NULL");
2112 else {
2113 tprintf("{");
2114 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2115 BITNESS_CURRENT, special);
2116 tprintf(", ");
2117 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2118 + sizeof (struct timeval),
2119 BITNESS_CURRENT, special);
2120 tprintf("}");
2121 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002122 }
2123 return 0;
2124}
2125
2126int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002127sys_utimes(struct tcb *tcp)
2128{
Roland McGrath6afc5652007-07-24 01:57:11 +00002129 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002130}
2131
2132#ifdef LINUX
2133int
2134sys_futimesat(struct tcb *tcp)
2135{
2136 if (entering(tcp))
2137 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002138 return decode_utimes(tcp, 1, 0);
2139}
2140
2141int
2142sys_utimensat(struct tcb *tcp)
2143{
2144 if (entering(tcp)) {
2145 print_dirfd(tcp->u_arg[0]);
2146 decode_utimes(tcp, 1, 1);
2147 tprintf(", ");
2148 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2149 }
2150 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002151}
2152#endif
2153
2154int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002155sys_utime(tcp)
2156struct tcb *tcp;
2157{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002158 union {
2159 long utl[2];
2160 int uti[2];
2161 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162
2163 if (entering(tcp)) {
2164 printpath(tcp, tcp->u_arg[0]);
2165 tprintf(", ");
2166 if (!tcp->u_arg[1])
2167 tprintf("NULL");
2168 else if (!verbose(tcp))
2169 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002170 else if (umoven(tcp, tcp->u_arg[1],
2171 2 * personality_wordsize[current_personality],
2172 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002173 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002174 else if (personality_wordsize[current_personality]
2175 == sizeof u.utl[0]) {
2176 tprintf("[%s,", sprinttime(u.utl[0]));
2177 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002179 else if (personality_wordsize[current_personality]
2180 == sizeof u.uti[0]) {
2181 tprintf("[%s,", sprinttime(u.uti[0]));
2182 tprintf(" %s]", sprinttime(u.uti[1]));
2183 }
2184 else
2185 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002186 }
2187 return 0;
2188}
2189
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002190static int
2191decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002192{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002193 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002194
2195 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002196 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002197 tprintf(", %s", sprintmode(mode));
2198 switch (mode & S_IFMT) {
2199 case S_IFCHR: case S_IFBLK:
2200#ifdef LINUXSPARC
2201 if (current_personality == 1)
2202 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002203 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2204 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002206#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002207 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002208 (unsigned long) major(tcp->u_arg[offset + 2]),
2209 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210 break;
2211 default:
2212 break;
2213 }
2214 }
2215 return 0;
2216}
2217
2218int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002219sys_mknod(struct tcb *tcp)
2220{
2221 return decode_mknod(tcp, 0);
2222}
2223
2224#ifdef LINUX
2225int
2226sys_mknodat(struct tcb *tcp)
2227{
2228 if (entering(tcp))
2229 print_dirfd(tcp->u_arg[0]);
2230 return decode_mknod(tcp, 1);
2231}
2232#endif
2233
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002234#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002235int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002236sys_mkfifo(tcp)
2237struct tcb *tcp;
2238{
2239 if (entering(tcp)) {
2240 printpath(tcp, tcp->u_arg[0]);
2241 tprintf(", %#lo", tcp->u_arg[1]);
2242 }
2243 return 0;
2244}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002245#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246
2247int
2248sys_fsync(tcp)
2249struct tcb *tcp;
2250{
2251 if (entering(tcp)) {
2252 tprintf("%ld", tcp->u_arg[0]);
2253 }
2254 return 0;
2255}
2256
Michal Ludvig53b320f2002-09-23 13:30:09 +00002257#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002258
2259static void
2260printdir(tcp, addr)
2261struct tcb *tcp;
2262long addr;
2263{
2264 struct dirent d;
2265
2266 if (!verbose(tcp)) {
2267 tprintf("%#lx", addr);
2268 return;
2269 }
2270 if (umove(tcp, addr, &d) < 0) {
2271 tprintf("{...}");
2272 return;
2273 }
2274 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002275 tprintf("d_name=");
2276 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2277 tprintf("}");
2278}
2279
2280int
2281sys_readdir(tcp)
2282struct tcb *tcp;
2283{
2284 if (entering(tcp)) {
2285 tprintf("%lu, ", tcp->u_arg[0]);
2286 } else {
2287 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2288 tprintf("%#lx", tcp->u_arg[1]);
2289 else
2290 printdir(tcp, tcp->u_arg[1]);
2291 /* Not much point in printing this out, it is always 1. */
2292 if (tcp->u_arg[2] != 1)
2293 tprintf(", %lu", tcp->u_arg[2]);
2294 }
2295 return 0;
2296}
2297
Michal Ludvig53b320f2002-09-23 13:30:09 +00002298#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002299
Roland McGrath40542842004-01-13 09:47:49 +00002300#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002301static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002302 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002303 { DT_FIFO, "DT_FIFO" },
2304 { DT_CHR, "DT_CHR" },
2305 { DT_DIR, "DT_DIR" },
2306 { DT_BLK, "DT_BLK" },
2307 { DT_REG, "DT_REG" },
2308 { DT_LNK, "DT_LNK" },
2309 { DT_SOCK, "DT_SOCK" },
2310 { DT_WHT, "DT_WHT" },
2311 { 0, NULL },
2312};
2313
2314#endif
2315
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002316int
2317sys_getdents(tcp)
2318struct tcb *tcp;
2319{
2320 int i, len, dents = 0;
2321 char *buf;
2322
2323 if (entering(tcp)) {
2324 tprintf("%lu, ", tcp->u_arg[0]);
2325 return 0;
2326 }
2327 if (syserror(tcp) || !verbose(tcp)) {
2328 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2329 return 0;
2330 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002331 len = tcp->u_rval;
2332 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002333 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2334 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002335 return 0;
2336 }
2337 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002338 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002339 free(buf);
2340 return 0;
2341 }
2342 if (!abbrev(tcp))
2343 tprintf("{");
2344 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002345 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002346#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002347 if (!abbrev(tcp)) {
2348 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2349 i ? " " : "", d->d_ino, d->d_off);
2350 tprintf("d_reclen=%u, d_name=\"%s\"}",
2351 d->d_reclen, d->d_name);
2352 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002353#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002354#ifdef SVR4
2355 if (!abbrev(tcp)) {
2356 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002357 i ? " " : "",
2358 (unsigned long) d->d_ino,
2359 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002360 tprintf("d_reclen=%u, d_name=\"%s\"}",
2361 d->d_reclen, d->d_name);
2362 }
2363#endif /* SVR4 */
2364#ifdef SUNOS4
2365 if (!abbrev(tcp)) {
2366 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2367 i ? " " : "", d->d_off, d->d_fileno,
2368 d->d_reclen);
2369 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2370 d->d_namlen, d->d_namlen, d->d_name);
2371 }
2372#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002373#ifdef FREEBSD
2374 if (!abbrev(tcp)) {
2375 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2376 i ? " " : "", d->d_fileno, d->d_reclen);
2377 printxval(direnttypes, d->d_type, "DT_???");
2378 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2379 d->d_namlen, d->d_namlen, d->d_name);
2380 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002381#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002382 if (!d->d_reclen) {
2383 tprintf("/* d_reclen == 0, problem here */");
2384 break;
2385 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002386 i += d->d_reclen;
2387 dents++;
2388 }
2389 if (!abbrev(tcp))
2390 tprintf("}");
2391 else
2392 tprintf("/* %u entries */", dents);
2393 tprintf(", %lu", tcp->u_arg[2]);
2394 free(buf);
2395 return 0;
2396}
2397
John Hughesbdf48f52001-03-06 15:08:09 +00002398
2399#if _LFS64_LARGEFILE
2400int
2401sys_getdents64(tcp)
2402struct tcb *tcp;
2403{
2404 int i, len, dents = 0;
2405 char *buf;
2406
2407 if (entering(tcp)) {
2408 tprintf("%lu, ", tcp->u_arg[0]);
2409 return 0;
2410 }
2411 if (syserror(tcp) || !verbose(tcp)) {
2412 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2413 return 0;
2414 }
2415 len = tcp->u_rval;
2416 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002417 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2418 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002419 return 0;
2420 }
2421 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002422 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002423 free(buf);
2424 return 0;
2425 }
2426 if (!abbrev(tcp))
2427 tprintf("{");
2428 for (i = 0; i < len;) {
2429 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002430#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002431 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002432 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002433 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002434 d->d_ino,
2435 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002436#ifdef LINUX
2437 tprintf("d_type=");
2438 printxval(direnttypes, d->d_type, "DT_???");
2439 tprintf(", ");
2440#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002441 tprintf("d_reclen=%u, d_name=\"%s\"}",
2442 d->d_reclen, d->d_name);
2443 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002444#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002445#ifdef SUNOS4
2446 if (!abbrev(tcp)) {
2447 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2448 i ? " " : "", d->d_off, d->d_fileno,
2449 d->d_reclen);
2450 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2451 d->d_namlen, d->d_namlen, d->d_name);
2452 }
2453#endif /* SUNOS4 */
2454 i += d->d_reclen;
2455 dents++;
2456 }
2457 if (!abbrev(tcp))
2458 tprintf("}");
2459 else
2460 tprintf("/* %u entries */", dents);
2461 tprintf(", %lu", tcp->u_arg[2]);
2462 free(buf);
2463 return 0;
2464}
2465#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002466
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002467#ifdef FREEBSD
2468int
2469sys_getdirentries(tcp)
2470struct tcb * tcp;
2471{
2472 int i, len, dents = 0;
2473 long basep;
2474 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002475
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002476 if (entering(tcp)) {
2477 tprintf("%lu, ", tcp->u_arg[0]);
2478 return 0;
2479 }
2480 if (syserror(tcp) || !verbose(tcp)) {
2481 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2482 return 0;
2483 }
2484 len = tcp->u_rval;
2485 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002486 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2487 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002488 return 0;
2489 }
2490 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002491 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002492 free(buf);
2493 return 0;
2494 }
2495 if (!abbrev(tcp))
2496 tprintf("{");
2497 for (i = 0; i < len;) {
2498 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2499 if (!abbrev(tcp)) {
2500 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2501 i ? " " : "", d->d_fileno, d->d_reclen);
2502 printxval(direnttypes, d->d_type, "DT_???");
2503 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2504 d->d_namlen, d->d_namlen, d->d_name);
2505 }
2506 i += d->d_reclen;
2507 dents++;
2508 }
2509 if (!abbrev(tcp))
2510 tprintf("}");
2511 else
2512 tprintf("/* %u entries */", dents);
2513 free(buf);
2514 tprintf(", %lu", tcp->u_arg[2]);
2515 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2516 tprintf(", %#lx", tcp->u_arg[3]);
2517 else
2518 tprintf(", [%lu]", basep);
2519 return 0;
2520}
2521#endif
2522
Michal Ludvig53b320f2002-09-23 13:30:09 +00002523#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002524int
2525sys_getcwd(tcp)
2526struct tcb *tcp;
2527{
2528 if (exiting(tcp)) {
2529 if (syserror(tcp))
2530 tprintf("%#lx", tcp->u_arg[0]);
2531 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002532 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002533 tprintf(", %lu", tcp->u_arg[1]);
2534 }
2535 return 0;
2536}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002537#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002538
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002539#ifdef FREEBSD
2540int
2541sys___getcwd(tcp)
2542struct tcb *tcp;
2543{
2544 if (exiting(tcp)) {
2545 if (syserror(tcp))
2546 tprintf("%#lx", tcp->u_arg[0]);
2547 else
2548 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2549 tprintf(", %lu", tcp->u_arg[1]);
2550 }
2551 return 0;
2552}
2553#endif
2554
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002555#ifdef HAVE_SYS_ASYNCH_H
2556
2557int
2558sys_aioread(tcp)
2559struct tcb *tcp;
2560{
2561 struct aio_result_t res;
2562
2563 if (entering(tcp)) {
2564 tprintf("%lu, ", tcp->u_arg[0]);
2565 } else {
2566 if (syserror(tcp))
2567 tprintf("%#lx", tcp->u_arg[1]);
2568 else
2569 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2570 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2571 printxval(whence, tcp->u_arg[4], "L_???");
2572 if (syserror(tcp) || tcp->u_arg[5] == 0
2573 || umove(tcp, tcp->u_arg[5], &res) < 0)
2574 tprintf(", %#lx", tcp->u_arg[5]);
2575 else
2576 tprintf(", {aio_return %d aio_errno %d}",
2577 res.aio_return, res.aio_errno);
2578 }
2579 return 0;
2580}
2581
2582int
2583sys_aiowrite(tcp)
2584struct tcb *tcp;
2585{
2586 struct aio_result_t res;
2587
2588 if (entering(tcp)) {
2589 tprintf("%lu, ", tcp->u_arg[0]);
2590 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2591 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2592 printxval(whence, tcp->u_arg[4], "L_???");
2593 }
2594 else {
2595 if (tcp->u_arg[5] == 0)
2596 tprintf(", NULL");
2597 else if (syserror(tcp)
2598 || umove(tcp, tcp->u_arg[5], &res) < 0)
2599 tprintf(", %#lx", tcp->u_arg[5]);
2600 else
2601 tprintf(", {aio_return %d aio_errno %d}",
2602 res.aio_return, res.aio_errno);
2603 }
2604 return 0;
2605}
2606
2607int
2608sys_aiowait(tcp)
2609struct tcb *tcp;
2610{
2611 if (entering(tcp))
2612 printtv(tcp, tcp->u_arg[0]);
2613 return 0;
2614}
2615
2616int
2617sys_aiocancel(tcp)
2618struct tcb *tcp;
2619{
2620 struct aio_result_t res;
2621
2622 if (exiting(tcp)) {
2623 if (tcp->u_arg[0] == 0)
2624 tprintf("NULL");
2625 else if (syserror(tcp)
2626 || umove(tcp, tcp->u_arg[0], &res) < 0)
2627 tprintf("%#lx", tcp->u_arg[0]);
2628 else
2629 tprintf("{aio_return %d aio_errno %d}",
2630 res.aio_return, res.aio_errno);
2631 }
2632 return 0;
2633}
2634
2635#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002636
Roland McGratha4d48532005-06-08 20:45:28 +00002637static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002638#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002639 { XATTR_CREATE, "XATTR_CREATE" },
2640 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002641#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002642 { 0, NULL }
2643};
2644
Roland McGrath3292e222004-08-31 06:30:48 +00002645static void
2646print_xattr_val(tcp, failed, arg, insize, size)
2647struct tcb *tcp;
2648int failed;
2649unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002650unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002651{
Roland McGrath883567c2005-02-02 03:38:32 +00002652 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002653 unsigned long capacity = 4 * size + 1;
2654 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002655 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002656 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002657 failed = 1;
2658 }
2659 else {
2660 unsigned char *out = buf;
2661 unsigned char *in = &buf[3 * size];
2662 size_t i;
2663 for (i = 0; i < size; ++i)
2664 if (isprint(in[i]))
2665 *out++ = in[i];
2666 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002667#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002668 *out++ = '\\';
2669 *out++ = 'x';
2670 *out++ = tohex(in[i] / 16);
2671 *out++ = tohex(in[i] % 16);
2672 }
2673 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002674 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002675 out -= 4;
2676 *out = '\0';
2677 tprintf(", \"%s\", %ld", buf, insize);
2678 }
2679 free(buf);
2680 }
2681 if (failed)
2682 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002683}
2684
Roland McGrath186c5ac2002-12-15 23:58:23 +00002685int
2686sys_setxattr(tcp)
2687struct tcb *tcp;
2688{
2689 if (entering(tcp)) {
2690 printpath(tcp, tcp->u_arg[0]);
2691 tprintf(", ");
2692 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002693 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2694 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002695 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002696 }
2697 return 0;
2698}
2699
2700int
2701sys_fsetxattr(tcp)
2702struct tcb *tcp;
2703{
2704 if (entering(tcp)) {
2705 tprintf("%ld, ", tcp->u_arg[0]);
2706 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002707 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2708 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002709 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002710 }
2711 return 0;
2712}
2713
2714int
2715sys_getxattr(tcp)
2716struct tcb *tcp;
2717{
2718 if (entering(tcp)) {
2719 printpath(tcp, tcp->u_arg[0]);
2720 tprintf(", ");
2721 printstr(tcp, tcp->u_arg[1], -1);
2722 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002723 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2724 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002725 }
2726 return 0;
2727}
2728
2729int
2730sys_fgetxattr(tcp)
2731struct tcb *tcp;
2732{
2733 if (entering(tcp)) {
2734 tprintf("%ld, ", tcp->u_arg[0]);
2735 printstr(tcp, tcp->u_arg[1], -1);
2736 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002737 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2738 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002739 }
2740 return 0;
2741}
2742
2743int
2744sys_listxattr(tcp)
2745struct tcb *tcp;
2746{
2747 if (entering(tcp)) {
2748 printpath(tcp, tcp->u_arg[0]);
2749 } else {
2750 /* XXX Print value in format */
2751 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2752 }
2753 return 0;
2754}
2755
2756int
2757sys_flistxattr(tcp)
2758struct tcb *tcp;
2759{
2760 if (entering(tcp)) {
2761 tprintf("%ld", tcp->u_arg[0]);
2762 } else {
2763 /* XXX Print value in format */
2764 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2765 }
2766 return 0;
2767}
2768
2769int
2770sys_removexattr(tcp)
2771struct tcb *tcp;
2772{
2773 if (entering(tcp)) {
2774 printpath(tcp, tcp->u_arg[0]);
2775 tprintf(", ");
2776 printstr(tcp, tcp->u_arg[1], -1);
2777 }
2778 return 0;
2779}
2780
2781int
2782sys_fremovexattr(tcp)
2783struct tcb *tcp;
2784{
2785 if (entering(tcp)) {
2786 tprintf("%ld, ", tcp->u_arg[0]);
2787 printstr(tcp, tcp->u_arg[1], -1);
2788 }
2789 return 0;
2790}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002791
2792
2793static const struct xlat advise[] = {
2794 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2795 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2796 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2797 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2798 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2799 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2800 { 0, NULL }
2801};
2802
2803
Roland McGrathe27ed342004-10-20 02:24:19 +00002804#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002805int
2806sys_fadvise64(tcp)
2807struct tcb *tcp;
2808{
2809 if (entering(tcp)) {
2810 tprintf("%ld, %lld, %ld, ",
2811 tcp->u_arg[0],
2812# if defined IA64 || defined X86_64 || defined ALPHA
2813 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2814 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2815#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002816 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2817 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002818#endif
2819 }
2820 return 0;
2821}
2822#endif
2823
2824
2825int
2826sys_fadvise64_64(tcp)
2827struct tcb *tcp;
2828{
2829 if (entering(tcp)) {
2830 tprintf("%ld, %lld, %lld, ",
2831 tcp->u_arg[0],
2832# if defined IA64 || defined X86_64 || defined ALPHA
2833 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2834 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2835#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002836 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2837 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002838 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2839#endif
2840 }
2841 return 0;
2842}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002843
2844#ifdef LINUX
2845static const struct xlat inotify_modes[] = {
2846 { 0x00000001, "IN_ACCESS" },
2847 { 0x00000002, "IN_MODIFY" },
2848 { 0x00000004, "IN_ATTRIB" },
2849 { 0x00000008, "IN_CLOSE_WRITE" },
2850 { 0x00000010, "IN_CLOSE_NOWRITE" },
2851 { 0x00000020, "IN_OPEN" },
2852 { 0x00000040, "IN_MOVED_FROM" },
2853 { 0x00000080, "IN_MOVED_TO" },
2854 { 0x00000100, "IN_CREATE" },
2855 { 0x00000200, "IN_DELETE" },
2856 { 0x00000400, "IN_DELETE_SELF" },
2857 { 0x00000800, "IN_MOVE_SELF" },
2858 { 0x00002000, "IN_UNMOUNT" },
2859 { 0x00004000, "IN_Q_OVERFLOW" },
2860 { 0x00008000, "IN_IGNORED" },
2861 { 0x01000000, "IN_ONLYDIR" },
2862 { 0x02000000, "IN_DONT_FOLLOW" },
2863 { 0x20000000, "IN_MASK_ADD" },
2864 { 0x40000000, "IN_ISDIR" },
2865 { 0x80000000, "IN_ONESHOT" }
2866};
2867
2868int
2869sys_inotify_add_watch(struct tcb *tcp)
2870{
2871 if (entering(tcp)) {
2872 tprintf("%ld, ", tcp->u_arg[0]);
2873 printpath(tcp, tcp->u_arg[1]);
2874 tprintf(", ");
2875 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2876 }
2877 return 0;
2878}
2879
2880int
2881sys_inotify_rm_watch(struct tcb *tcp)
2882{
2883 if (entering(tcp)) {
2884 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2885 }
2886 return 0;
2887}
2888#endif